Annotation of loncom/interface/londocs.pm, revision 1.627
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.627 ! raeburn 4: # $Id: londocs.pm,v 1.626 2017/05/08 14:20:20 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:
1.617 raeburn 145: sub default_folderpath {
146: my ($coursenum,$coursedom,$navmapref) = @_;
147: return unless ($coursenum && $coursedom && ref($navmapref));
148: # Check if entire course is hidden and/or encrypted
149: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
150: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
151: unless (ref($$navmapref)) {
152: $$navmapref = Apache::lonnavmaps::navmap->new();
153: }
154: if (ref($$navmapref)) {
155: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
156: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
157: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
158: unless (@resources) {
159: $hiddenmap = 1;
160: unless ($env{'request.role.adv'}) {
161: $hiddentop = 1;
162: if ($env{'form.folder'}) {
163: undef($env{'form.folder'});
164: }
165: }
166: }
167: }
168: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
169: $encryptmap = 1;
170: }
171: }
172: unless ($hiddentop) {
173: $folderpath='default&'.&escape(&mt('Main Content')).
174: '::'.$hiddenmap.':'.$encryptmap.'::';
175: }
176: if (wantarray) {
177: return ($folderpath,$hiddentop);
178: } else {
179: return $folderpath;
180: }
181: }
1.329 droeschl 182:
183: sub dumpcourse {
184: my ($r) = @_;
1.408 raeburn 185: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 186: my ($starthash,$js);
187: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
188: $js = <<"ENDJS";
189: <script type="text/javascript">
190: // <![CDATA[
191:
192: function hide_searching() {
193: if (document.getElementById('searching')) {
194: document.getElementById('searching').style.display = 'none';
195: }
196: return;
197: }
198:
199: // ]]>
200: </script>
201: ENDJS
202: $starthash = {
203: add_entries => {'onload' => "hide_searching();"},
204: };
205: }
1.568 raeburn 206: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
207: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 208: $r->print(&startContentScreen('tools'));
1.329 droeschl 209: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 210: unless ($home) {
211: $r->print(&endContentScreen());
212: return '';
213: }
1.329 droeschl 214: my $origcrsid=$env{'request.course.id'};
215: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
216: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
217: # Do the dumping
1.484 raeburn 218: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
219: $r->print(&endContentScreen());
220: return '';
221: }
1.531 raeburn 222: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 223: $r->print('<h3>'.&mt('Copying Files').'</h3>');
224: my $title=$env{'form.authorfolder'};
225: $title=&clean($title);
1.567 raeburn 226: my ($navmap,$errormsg) =
227: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
228: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
229: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
230: my (%maps,%resources,%titles);
231: if (!ref($navmap)) {
232: $r->print($errormsg.
233: &endContentScreen());
234: return '';
235: } else {
236: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
237: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 238: }
1.567 raeburn 239: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
240: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
241: %newcontent,%has_simpleprobs);
242: foreach my $item (sort {$a <=> $b} (@todump)) {
243: my $name = $env{'form.namefor_'.$item};
244: if ($resources{$item}) {
245: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
246: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
247: $tocopy{$1} = $name;
248: $display{$item} = $1;
249: $lookup{$1} = $item;
250: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
251: $simpleproblems{$item} = {
252: symb => $resources{$item},
253: name => $name,
254: };
255: $display{$item} = 'simpleproblem_'.$name;
256: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
257: $has_simpleprobs{$1}{$id} = $item;
258: }
259: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
260: my $marker = $1;
261: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
262: $simplepages{$item} = {
263: res => $res,
264: title => $titles{$item},
265: db => $db_name,
266: marker => $marker,
267: symb => $resources{$item},
268: name => $name,
269: };
270: $display{$item} = '/'.$res;
271: }
272: } elsif ($maps{$item}) {
273: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
274: $tocopy{$1} = $name;
275: $display{$item} = $1;
276: $lookup{$1} = $item;
277: }
278: } else {
279: next;
280: }
281: }
1.329 droeschl 282: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
283: $crs=~s/\_/\//g;
1.567 raeburn 284: my $mm = new File::MMagic;
285: my $prefix = "/uploaded/$cdom/$cnum/";
286: %replacehash = %tocopy;
287: foreach my $item (sort(keys(%simpleproblems))) {
288: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
289: $newcontent{$display{$item}} = $content;
290: }
291: my $gateway = Apache::lonhtmlgateway->new('web');
292: foreach my $item (sort(keys(%simplepages))) {
293: if (ref($simplepages{$item}) eq 'HASH') {
294: my $pagetitle = $simplepages{$item}{'title'};
295: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
296: my %contents;
297: foreach my $field (keys(%fields)) {
298: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
299: my $name = $1;
300: my $msg = $fields{$field};
301: if ($name eq 'webreferences') {
302: if ($msg =~ m{^https?://}) {
303: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
304: }
305: } else {
306: $msg = &Encode::decode('utf8',$msg);
307: $msg = $gateway->process_outgoing_html($msg,1);
308: $contents{$name} = $msg;
309: }
310: } elsif ($field eq 'uploaded.photourl') {
311: my $marker = $simplepages{$item}{marker};
312: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
313: my $filepath = $1;
314: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
315: if ($fname ne '') {
316: $fname=~s/\.(\w+)$//;
317: my $ext=$1;
318: $fname = &clean($fname);
319: $fname.='.'.$ext;
320: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
321: $replacehash{$filepath} = $relpath.$fname;
322: $deps{$item}{$filepath} = 1;
323: }
324: }
325: }
326: }
327: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
328: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
329: my $content = '
330: <html>
331: <head>
332: <title>'.$pagetitle.'</title>
333: </head>
334: <body bgcolor="#ffffff">';
335: if ($contents{title}) {
336: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
337: }
338: if ($contents{image}) {
339: $content .= "\n".$contents{image};
340: }
341: if ($contents{content}) {
342: $content .= '
343: <div class="LC_Box">
1.577 bisitz 344: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 345: $contents{content}.'
346: </div>';
347: }
348: if ($contents{webreferences}) {
349: $content .= '
350: <div class="LC_Box">
1.577 bisitz 351: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 352: $contents{webreferences}.'
353: </div>';
354: }
355: $content .= '
356: </body>
357: </html>
358: ';
359: $newcontent{'/'.$simplepages{$item}{res}} = $content;
360: }
361: }
362: foreach my $item (keys(%tocopy)) {
363: unless ($item=~/\.(sequence|page)$/) {
364: my $currurlpath = $prefix.$item;
365: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
366: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
367: }
368: }
369: foreach my $num (sort {$a <=> $b} (@todump)) {
370: my $src = $display{$num};
371: next if ($src eq '');
372: my @needcopy = ();
373: if ($replacehash{$src}) {
374: push(@needcopy,$src);
375: if (ref($deps{$num}) eq 'HASH') {
376: foreach my $dep (sort(keys(%{$deps{$num}}))) {
377: if ($replacehash{$dep}) {
378: push(@needcopy,$dep);
379: }
380: }
381: }
382: } elsif ($src =~ /^simpleproblem_/) {
383: push(@needcopy,$src);
384: }
385: next if (@needcopy == 0);
386: my ($result,$depresult);
387: for (my $i=0; $i<@needcopy; $i++) {
388: my $item = $needcopy[$i];
389: my $newfilename;
390: if ($simpleproblems{$num}) {
391: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
392: } else {
393: $newfilename=$title.'/'.$replacehash{$item};
394: }
395: $newfilename=~s/\.(\w+)$//;
396: my $ext=$1;
397: $newfilename=&clean($newfilename);
398: $newfilename.='.'.$ext;
399: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
400: if ($newrelpath ne $replacehash{$item}) {
401: $replacehash{$item} = $newrelpath;
402: }
403: my @dirs=split(/\//,$newfilename);
404: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
405: my $makepath=$path;
406: my $fail;
407: my $origin;
408: for (my $i=0;$i<$#dirs;$i++) {
409: $makepath.='/'.$dirs[$i];
410: unless (-e $makepath) {
411: unless(mkdir($makepath,0755)) {
412: $fail = &mt('Directory creation failed.');
413: }
414: }
415: }
416: if ($i == 0) {
417: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
418: } else {
419: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
420: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
421: &mt('(dependency)').'</span>: ';
422: }
423: if (-e $path.'/'.$newfilename) {
424: $fail = &mt('Destination already exists -- not overwriting.');
425: } else {
426: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
427: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
428: ($item =~ /^simpleproblem_/)) {
429: print $fh $newcontent{$item};
430: } else {
431: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
432: if (-e $fileloc) {
433: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
434: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
435: (ref($has_simpleprobs{$item}) eq 'HASH')) {
436: my %changes = %{$has_simpleprobs{$item}};
437: my $content = &Apache::lonclonecourse::rewritefile(
438: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
439: (%replacehash,$crs => '')
440: );
441: my $updatedcontent = '';
442: my $parser = HTML::TokeParser->new(\$content);
443: $parser->attr_encoded(1);
444: while (my $token = $parser->get_token) {
445: if ($token->[0] eq 'S') {
446: if (($token->[1] eq 'resource') &&
447: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
448: ($changes{$token->[2]->{'id'}})) {
449: my $id = $token->[2]->{'id'};
450: $updatedcontent .= '<'.$token->[1];
451: foreach my $attrib (@{$token->[3]}) {
452: next unless ($attrib =~ /^(src|type|title|id)$/);
453: if ($attrib eq 'src') {
454: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
455: if ($file) {
456: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: } else {
461: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
462: }
463: }
464: $updatedcontent .= ' />'."\n";
465: } else {
466: $updatedcontent .= $token->[4]."\n";
467: }
468: } else {
469: $updatedcontent .= $token->[2];
470: }
471: }
472: print $fh $updatedcontent;
473: } else {
474: print $fh &Apache::lonclonecourse::rewritefile(
475: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
476: (%replacehash,$crs => '')
477: );
478: }
479: } else {
480: print $fh
481: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
482: }
483: } else {
484: $fail = &mt('Source does not exist.');
485: }
486: }
487: $fh->close();
488: } else {
489: $fail = &mt('Could not write to destination.');
490: }
491: }
492: my $text;
493: if ($fail) {
494: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
495: } else {
496: $text = '<span class="LC_success">'.&mt('ok').'</span>';
497: }
498: if ($i == 0) {
499: $result .= $text;
500: } else {
501: $depresult .= $text.'</li>';
502: }
503: }
504: $r->print($result);
505: if ($depresult) {
506: $r->print('<ul>'.$depresult.'</ul>');
507: }
508: }
509: } else {
510: my ($navmap,$errormsg) =
511: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
512: if (!ref($navmap)) {
513: $r->print($errormsg);
514: } else {
515: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
516: $r->rflush();
517: my ($preamble,$formname);
518: $formname = 'dumpdoc';
519: unless ($home==1) {
520: $preamble = '<div class="LC_left_float">'.
521: '<fieldset><legend>'.
522: &mt('Select the Authoring Space').
523: '</legend><select name="authorspace">';
1.329 droeschl 524: }
1.567 raeburn 525: my @orderspaces = ();
526: foreach my $key (sort(keys(%outhash))) {
527: if ($key=~/^home_(.+)$/) {
528: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
529: unshift(@orderspaces,$1);
530: } else {
531: push(@orderspaces,$1);
532: }
533: }
534: }
1.569 raeburn 535: if ($home>1) {
536: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
537: }
1.567 raeburn 538: foreach my $user (@orderspaces) {
1.329 droeschl 539: if ($home==1) {
1.567 raeburn 540: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 541: } else {
1.567 raeburn 542: $preamble .= '<option value="'.$user.'">'.$user.' - '.
543: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
544: }
1.329 droeschl 545: }
1.567 raeburn 546: unless ($home==1) {
547: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 548: }
1.567 raeburn 549: my $title=$origcrsdata{'description'};
550: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 551: $title=&clean($title);
1.567 raeburn 552: $preamble .= '<div class="LC_left_float">'.
553: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
554: '<input type="text" size="50" name="authorfolder" value="'.
555: $title.'" />'.
556: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
557: my %uploadedfiles;
558: &tiehash();
559: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
560: my ($ext)=($file=~/\.(\w+)$/);
561: # FIXME Check supplemental here
562: my $title=$hash{'title_'.$hash{
563: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
564: if (!$title) {
565: $title=$file;
566: } else {
567: $title=~s|/|_|g;
568: }
569: $title=~s/\.(\w+)$//;
570: $title=&clean($title);
571: $title.='.'.$ext;
572: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
573: $uploadedfiles{$file} = $title;
574: }
575: &untiehash();
576: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
577: undef,undef,$preamble,$home,\%uploadedfiles));
578: }
1.329 droeschl 579: }
1.484 raeburn 580: $r->print(&endContentScreen());
1.329 droeschl 581: }
582:
1.567 raeburn 583: sub recurse_html {
584: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
585: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
586: my (%allfiles,%codebase);
587: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
588: if (keys(%allfiles)) {
589: foreach my $dependency (keys(%allfiles)) {
590: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
591: my ($depurl,$relfile,$newcontainer);
592: if ($dependency =~ m{^/}) {
593: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
594: $relfile = $1;
595: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
596: $newcontainer = $1;
597: next if ($replacehash->{$newcontainer});
598: }
599: $depurl = $dependency;
600: } else {
601: next;
602: }
603: } else {
604: $relfile = $dependency;
605: $depurl = $currurlpath;
606: $depurl =~ s{[^/]+$}{};
607: $depurl .= $dependency;
608: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
609: }
610: next if ($relfile eq '');
611: my $newname = $replacehash->{$container};
612: $newname =~ s{[^/]+$}{};
613: $replacehash->{$newcontainer} = $newname.$relfile;
614: $deps->{$item}{$newcontainer} = 1;
615: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
616: my $depfile = &Apache::lonnet::filelocation('',$depurl);
617: my $type = $mm->checktype_filename($depfile);
618: if ($type eq 'text/html') {
619: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
620: }
621: }
622: }
623: }
624: return;
625: }
626:
1.329 droeschl 627: sub group_import {
1.598 raeburn 628: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 629: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
630: %removeparam,$importuploaded,$fixuperrors);
631: $allmaps = {};
1.329 droeschl 632: while (@files) {
633: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 634: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 635: && ($caller eq 'londocs')
636: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 637:
1.329 droeschl 638: my $errtext = '';
639: my $fatal = 0;
640: my $newmapstr = '<map>'."\n".
641: '<resource id="1" src="" type="start"></resource>'."\n".
642: '<link from="1" to="2" index="1"></link>'."\n".
643: '<resource id="2" src="" type="finish"></resource>'."\n".
644: '</map>';
645: $env{'form.output'}=$newmapstr;
646: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
647: 'output',$1.$2);
1.534 raeburn 648: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 649: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
650: $fatal = 2;
651: }
652: if ($fatal) {
653: return ($errtext,$fatal);
654: }
655: }
656: if ($url) {
1.626 raeburn 657: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 658: $url = $1;
659: my $marker = $2;
660: my $info = $3;
1.604 raeburn 661: my ($toolid,%toolhash,%toolsettings);
1.624 raeburn 662: my @extras = ('linktext','explanation','crslabel','crstitle');
1.598 raeburn 663: my @toolinfo = split(/:/,$info);
664: if ($residx) {
1.604 raeburn 665: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 666: $toolid = $toolsettings{'id'};
667: } else {
1.604 raeburn 668: $toolid = shift(@toolinfo);
1.598 raeburn 669: }
670: $toolid =~ s/\D//g;
1.604 raeburn 671: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.624 raeburn 672: $toolhash{'linktext'},$toolhash{'explanation'},
1.604 raeburn 673: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
1.624 raeburn 674: foreach my $item (@extras) {
675: $toolhash{$item} = &unescape($toolhash{$item});
676: }
1.598 raeburn 677: if (ref($ltitoolsref) eq 'HASH') {
1.604 raeburn 678: my @deleted;
1.598 raeburn 679: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
680: $toolhash{'id'} = $toolid;
1.604 raeburn 681: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
682: if ($toolhash{'target'} eq 'window') {
683: foreach my $item ('width','height') {
684: $toolhash{$item} =~ s/^\s+//;
685: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 686: if ($toolhash{$item} =~ /\D/) {
687: delete($toolhash{$item});
688: if ($residx) {
689: if ($toolsettings{$item}) {
690: push(@deleted,$item);
691: }
692: }
693: }
1.604 raeburn 694: }
695: }
696: } elsif ($residx) {
697: $toolhash{'target'} = $toolsettings{'target'};
698: if ($toolhash{'target'} eq 'window') {
1.624 raeburn 699: foreach my $item ('width','height') {
700: $toolhash{$item} = $toolsettings{$item};
701: }
1.604 raeburn 702: }
703: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
704: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
705: if ($toolhash{'target'} eq 'window') {
706: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
707: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
708: }
709: }
1.598 raeburn 710: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 711: foreach my $item ('width','height','linktext','explanation') {
712: delete($toolhash{$item});
713: if ($residx) {
714: if ($toolsettings{$item}) {
715: push(@deleted,$item);
716: }
1.604 raeburn 717: }
718: }
719: }
720: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 721: foreach my $item ('label','title','linktext','explanation') {
722: my $crsitem;
723: if (($item eq 'label') || ($item eq 'title')) {
724: $crsitem = 'crs'.$item;
725: } else {
726: $crsitem = $item;
727: }
1.604 raeburn 728: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 729: $toolhash{$crsitem} =~ s/^\s+//;
730: $toolhash{$crsitem} =~ s/\s+$//;
731: if ($toolhash{$crsitem} eq '') {
732: delete($toolhash{$crsitem});
1.604 raeburn 733: }
734: } else {
1.624 raeburn 735: delete($toolhash{$crsitem});
1.604 raeburn 736: }
1.624 raeburn 737: if (($residx) && (exists($toolsettings{$crsitem}))) {
738: unless (exists($toolhash{$crsitem})) {
739: push(@deleted,$crsitem);
1.604 raeburn 740: }
741: }
1.598 raeburn 742: }
743: }
744: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 745: if ($putres eq 'ok') {
746: if (@deleted) {
747: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
748: }
749: }
1.598 raeburn 750: }
751: }
752: }
1.529 raeburn 753: if (($caller eq 'londocs') &&
754: ($folder =~ /^default/)) {
1.534 raeburn 755: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 756: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
757: my $cid = $coursedom.'_'.$coursenum;
758: $allmaps =
759: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
760: $chome,$cid);
761: $donechk = 1;
762: }
763: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 ! raeburn 764: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
! 765: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 766: $importuploaded = 1;
767: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
768: next if ($allmaps->{$url});
769: }
770: }
1.344 bisitz 771: if (!$residx
1.329 droeschl 772: || defined($LONCAPA::map::zombies[$residx])) {
773: $residx = &LONCAPA::map::getresidx($url,$residx);
774: push(@LONCAPA::map::order, $residx);
775: }
776: my $ext = 'false';
777: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
778: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 779: if ($name eq '') {
1.538 raeburn 780: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 781: }
782: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
783: my $filepath = $1;
784: my $fname = $name;
785: if ($fname =~ /^\W+$/) {
786: $fname = 'web';
787: } else {
788: $fname =~ s/\W/_/g;
789: }
1.599 damieng 790: if (length($fname) > 15) {
1.534 raeburn 791: $fname = substr($fname,0,14);
792: }
793: my $initialtext = &mt('Replace with your own content.');
794: my $newhtml = <<END;
1.545 raeburn 795: <html>
1.534 raeburn 796: <head>
797: <title>$name</title>
798: </head>
799: <body bgcolor="#ffffff">
800: $initialtext
801: </body>
802: </html>
803: END
804: $env{'form.output'}=$newhtml;
805: my $result =
806: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
807: 'output',
808: "$filepath/$residx/$fname.html");
809: if ($result =~ m{^/uploaded/}) {
810: $url = $result;
811: if ($filepath =~ /^supplemental/) {
812: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
813: $env{'user.domain'}.'___&&&___'.$name;
814: }
815: } else {
816: return (&mt('Failed to save new web page.'),1);
817: }
818: }
1.538 raeburn 819: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 820: $LONCAPA::map::resources[$residx] =
1.329 droeschl 821: join(':', ($name, $url, $ext, 'normal', 'res'));
822: }
823: }
1.529 raeburn 824: if ($importuploaded) {
825: my %import_errors;
826: my %updated = (
827: removefrommap => \%removefrommap,
828: removeparam => \%removeparam,
829: );
1.533 raeburn 830: my ($result,$msgsarray,$lockerror) =
831: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 832: if (keys(%import_errors) > 0) {
1.530 raeburn 833: $fixuperrors =
1.529 raeburn 834: '<p span class="LC_warning">'."\n".
835: &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".
836: '<ul>'."\n";
837: foreach my $key (sort(keys(%import_errors))) {
838: $fixuperrors .= '<li>'.$key.'</li>'."\n";
839: }
840: $fixuperrors .= '</ul></p>'."\n";
841: }
1.533 raeburn 842: if (ref($msgsarray) eq 'ARRAY') {
843: if (@{$msgsarray} > 0) {
844: $fixuperrors .= '<p class="LC_info">'.
845: join('<br />',@{$msgsarray}).
846: '</p>';
847: }
848: }
849: if ($lockerror) {
850: $fixuperrors .= '<p class="LC_error">'.
851: $lockerror.
852: '</p>';
853: }
1.529 raeburn 854: }
855: my ($errtext,$fatal) =
856: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 857: unless ($fatal) {
858: if ($folder =~ /^supplemental/) {
859: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 860: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
861: $folder.'.'.$container);
1.557 raeburn 862: }
863: }
1.529 raeburn 864: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 865: }
866:
867: sub log_docs {
1.494 raeburn 868: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 869: }
870:
871: {
872: my @oldresources=();
873: my @oldorder=();
874: my $parmidx;
875: my %parmaction=();
876: my %parmvalue=();
877: my $changedflag;
878:
879: sub snapshotbefore {
880: @oldresources=@LONCAPA::map::resources;
881: @oldorder=@LONCAPA::map::order;
882: $parmidx=undef;
883: %parmaction=();
884: %parmvalue=();
885: $changedflag=0;
886: }
887:
888: sub remember_parms {
889: my ($idx,$parameter,$action,$value)=@_;
890: $parmidx=$idx;
891: $parmaction{$parameter}=$action;
892: $parmvalue{$parameter}=$value;
893: $changedflag=1;
894: }
895:
896: sub log_differences {
897: my ($plain)=@_;
898: my %storehash=('folder' => $plain,
899: 'currentfolder' => $env{'form.folder'});
900: if ($parmidx) {
901: $storehash{'parameter_res'}=$oldresources[$parmidx];
902: foreach my $parm (keys(%parmaction)) {
903: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
904: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
905: }
906: }
907: my $maxidx=$#oldresources;
908: if ($#LONCAPA::map::resources>$#oldresources) {
909: $maxidx=$#LONCAPA::map::resources;
910: }
911: for (my $idx=0; $idx<=$maxidx; $idx++) {
912: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
913: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
914: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
915: $changedflag=1;
916: }
917: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
918: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
919: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
920: $changedflag=1;
921: }
922: }
923: $storehash{'maxidx'}=$maxidx;
924: if ($changedflag) { &log_docs(\%storehash); }
925: }
926: }
927:
928: sub docs_change_log {
1.611 raeburn 929: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 930: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 931: my $navmap;
1.483 raeburn 932: my $js = '<script type="text/javascript">'."\n".
933: '// <![CDATA['."\n".
934: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 935: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 936: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 937: &history_tab_js()."\n".
1.484 raeburn 938: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 939: '// ]]>'."\n".
940: '</script>'."\n";
1.484 raeburn 941: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
942: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 943: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 944: my %orderhash;
945: my $container='sequence';
946: my $pathitem;
1.519 raeburn 947: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 948: $container='page';
949: }
1.519 raeburn 950: my $folderpath=$env{'form.folderpath'};
951: if ($folderpath eq '') {
1.617 raeburn 952: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 953: }
1.617 raeburn 954: undef($navmap);
1.519 raeburn 955: $pathitem = '<input type="hidden" name="folderpath" value="'.
956: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 957: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
958: my $jumpto = $readfile;
959: $jumpto =~ s{^/}{};
960: my $tid = 1;
1.489 raeburn 961: if ($supplementalflag) {
962: $tid = 2;
963: }
1.509 raeburn 964: my ($breadcrumbtrail) =
965: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 966: $r->print($breadcrumbtrail.
967: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
968: $readfile));
1.329 droeschl 969: my %docslog=&Apache::lonnet::dump('nohist_docslog',
970: $env{'course.'.$env{'request.course.id'}.'.domain'},
971: $env{'course.'.$env{'request.course.id'}.'.num'});
972:
973: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
974:
975: my %saveable_parameters = ('show' => 'scalar',);
976: &Apache::loncommon::store_course_settings('docs_log',
977: \%saveable_parameters);
978: &Apache::loncommon::restore_course_settings('docs_log',
979: \%saveable_parameters);
980: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 981: # FIXME: internationalization seems wrong here
1.329 droeschl 982: my %lt=('hiddenresource' => 'Resources hidden',
983: 'encrypturl' => 'URL hidden',
984: 'randompick' => 'Randomly pick',
985: 'randomorder' => 'Randomly ordered',
986: 'set' => 'set to',
987: 'del' => 'deleted');
1.484 raeburn 988: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
989: $pathitem."\n".
990: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
991: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
992: $r->print('<div class="LC_left_float">'.
993: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
994: &makedocslogform($filter,1).
995: '</fieldset></div><br clear="all" />');
1.329 droeschl 996: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
997: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
998: &mt('After').'</th>'.
999: &Apache::loncommon::end_data_table_header_row());
1000: my $shown=0;
1001: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1002: if ($env{'form.displayfilter'} eq 'currentfolder') {
1003: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1004: }
1005: my @changes=keys(%{$docslog{$id}{'logentry'}});
1006: if ($env{'form.displayfilter'} eq 'containing') {
1007: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1008: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1009: foreach my $key (@changes) {
1010: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1011: }
1.344 bisitz 1012: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1013: }
1014: my $count = 0;
1015: my $time =
1016: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1017: my $plainname =
1018: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1019: $docslog{$id}{'exe_udom'});
1020: my $about_me_link =
1021: &Apache::loncommon::aboutmewrapper($plainname,
1022: $docslog{$id}{'exe_uname'},
1023: $docslog{$id}{'exe_udom'});
1024: my $send_msg_link='';
1025: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1026: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1027: $send_msg_link ='<br />'.
1028: &Apache::loncommon::messagewrapper(&mt('Send message'),
1029: $docslog{$id}{'exe_uname'},
1030: $docslog{$id}{'exe_udom'});
1031: }
1032: $r->print(&Apache::loncommon::start_data_table_row());
1033: $r->print('<td>'.$time.'</td>
1034: <td>'.$about_me_link.
1035: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1036: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1037: $send_msg_link.'</td><td>'.
1038: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1039: my $is_supp = 0;
1040: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1041: $is_supp = 1;
1042: }
1.329 droeschl 1043: # Before
1044: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1045: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1046: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1047: if ($oldname ne $newname) {
1.488 raeburn 1048: my $shown = &LONCAPA::map::qtescape($oldname);
1049: if ($is_supp) {
1050: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1051: }
1052: $r->print($shown);
1.329 droeschl 1053: }
1054: }
1055: $r->print('<ul>');
1056: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1057: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1058: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1059: if ($is_supp) {
1060: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1061: }
1062: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1063: }
1064: }
1065: $r->print('</ul>');
1066: # After
1067: $r->print('</td><td>');
1068:
1069: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1070: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1071: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1072: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1073: my $shown = &LONCAPA::map::qtescape($newname);
1074: if ($is_supp) {
1075: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1076: }
1077: $r->print($shown);
1.329 droeschl 1078: }
1.364 bisitz 1079: }
1.329 droeschl 1080: $r->print('<ul>');
1081: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1082: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1083: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1084: if ($is_supp) {
1085: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1086: }
1087: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1088: }
1089: }
1090: $r->print('</ul>');
1091: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1092: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1093: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1094: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1095: # FIXME: internationalization seems wrong here
1.329 droeschl 1096: $r->print('<li>'.
1097: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1098: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1099: .'</li>');
1100: }
1101: }
1102: $r->print('</ul>');
1103: }
1104: # End
1105: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1106: $shown++;
1107: if (!($env{'form.show'} eq &mt('all')
1108: || $shown<=$env{'form.show'})) { last; }
1109: }
1.484 raeburn 1110: $r->print(&Apache::loncommon::end_data_table()."\n".
1111: &makesimpleeditform($pathitem)."\n".
1112: '</div></div>');
1113: $r->print(&endContentScreen());
1.329 droeschl 1114: }
1115:
1116: sub update_paste_buffer {
1.492 raeburn 1117: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1118: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1119: if ($env{'form.multiremove'}) {
1120: $env{'form.multiremove'} =~ s/,$//;
1121: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1122: }
1123: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1124: if ($env{'form.multicut'}) {
1125: $env{'form.multicut'} =~ s/,$//;
1126: foreach my $item (split(/,/,$env{'form.multicut'})) {
1127: unless ($removals{$item}) {
1128: $cuts{$item} = 1;
1129: push(@possibles,$item.':cut');
1130: }
1131: }
1132: }
1133: if ($env{'form.multicopy'}) {
1134: $env{'form.multicopy'} =~ s/,$//;
1135: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1136: unless ($removals{$item} || $cuts{$item}) {
1137: push(@possibles,$item.':copy');
1138: }
1139: }
1140: }
1141: } elsif ($env{'form.markcopy'}) {
1142: @possibles = split(/,/,$env{'form.markcopy'});
1143: }
1.329 droeschl 1144:
1.538 raeburn 1145: return if (@possibles == 0);
1.329 droeschl 1146: return if (!defined($env{'form.copyfolder'}));
1147:
1148: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1149: $env{'form.copyfolder'});
1.538 raeburn 1150: return if ($fatal);
1151:
1152: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1153:
1.538 raeburn 1154: # Retrieve current paste buffer suffixes.
1155: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1156: my (%pasteurls,@newpaste);
1157:
1158: # Construct identifiers for current contents of user's paste buffer
1159: if (@currpaste) {
1160: foreach my $suffix (@currpaste) {
1161: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1162: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1163: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1164: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1165: ($url ne '')) {
1.597 raeburn 1166: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1167: }
1168: }
1169: }
1170:
1171: # Mark items for copying (skip any items already in user's paste buffer)
1172: my %addtoenv;
1.597 raeburn 1173:
1174: my @pathitems = split(/\&/,$env{'form.folderpath'});
1175: my @folderconf = split(/\:/,$pathitems[-1]);
1176: my $ispage = $folderconf[4];
1177:
1.538 raeburn 1178: foreach my $item (@possibles) {
1179: my ($orderidx,$cmd) = split(/:/,$item);
1180: next if ($orderidx =~ /\D/);
1181: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1182: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1183: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1184: my %denied = &action_restrictions($coursenum,$coursedom,
1185: &LONCAPA::map::qtescape($url),
1186: $env{'form.folderpath'},\%curr_groups);
1187: next if ($denied{'copy'});
1188: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1189: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1190: my ($suffix,$errortxt,$locknotfreed) =
1191: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1192: if ($suffix ne '') {
1193: push(@newpaste,$suffix);
1194: } else {
1195: if ($locknotfreed) {
1196: return $locknotfreed;
1197: }
1.538 raeburn 1198: }
1199: if (&is_supplemental_title($title)) {
1200: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1201: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1202: }
1.329 droeschl 1203:
1.538 raeburn 1204: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1205: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1206: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1207: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1208: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1209: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1210: my $prefix = $1;
1211: my $subdir =$2;
1212: if ($subdir eq '') {
1213: $subdir = $prefix;
1.492 raeburn 1214: }
1.538 raeburn 1215: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 ! raeburn 1216: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
! 1217: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1218: if (ref($hierarchy{$url}) eq 'HASH') {
1219: my ($nested,$nestednames);
1220: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1221: $nested =~ s/\&$//;
1222: $nestednames =~ s/\Q___&&&___\E$//;
1223: if ($nested ne '') {
1224: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1225: }
1226: if ($nestednames ne '') {
1227: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1228: }
1.492 raeburn 1229: }
1230: }
1.591 raeburn 1231: if ($locknotfreed) {
1232: $output = $locknotfreed;
1233: last;
1234: }
1.492 raeburn 1235: }
1.538 raeburn 1236: if (@newpaste) {
1237: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1238: }
1.492 raeburn 1239: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1240: delete($env{'form.markcopy'});
1.591 raeburn 1241: return $output;
1.329 droeschl 1242: }
1243:
1.492 raeburn 1244: sub recurse_uploaded_maps {
1245: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1246: if (ref($hierarchy->{$url}) eq 'HASH') {
1247: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1248: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1249: my (@uploaded,@names,%shorter);
1250: for (my $i=0; $i<@maps; $i++) {
1251: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1252: if ($inner ne '') {
1253: push(@uploaded,$inner);
1254: push(@names,&escape($titles[$i]));
1255: $shorter{$maps[$i]} = $inner;
1256: }
1257: }
1258: $$nestref .= "$dir:".join(',',@uploaded).'&';
1259: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1260: foreach my $map (@maps) {
1261: if ($shorter{$map} ne '') {
1262: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1263: }
1264: }
1265: }
1266: return;
1267: }
1268:
1.329 droeschl 1269: sub print_paste_buffer {
1.492 raeburn 1270: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1271: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1272:
1.538 raeburn 1273: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1274: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1275: }
1276:
1.538 raeburn 1277: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1278: my ($pasteitems,@pasteable);
1.575 raeburn 1279: my $clipboardcount = 0;
1.488 raeburn 1280:
1.538 raeburn 1281: # Construct identifiers for current contents of user's paste buffer
1282: foreach my $suffix (@currpaste) {
1283: next if ($suffix =~ /\D/);
1284: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1285: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1286: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1287: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1288: ($url ne '')) {
1.575 raeburn 1289: $clipboardcount ++;
1.538 raeburn 1290: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1291: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1292: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1293: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1294: $is_external = 1;
1.626 raeburn 1295: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1296: $is_exttool = 1;
1.538 raeburn 1297: }
1298: if ($folder =~ /^supplemental/) {
1299: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1300: unless ($canpaste) {
1301: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1302: }
1303: } else {
1304: $canpaste = 1;
1305: }
1306: if ($canpaste) {
1307: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1308: my $srcdom = $1;
1309: my $srcnum = $2;
1310: my $rem = $3;
1311: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1312: $othercourse = 1;
1313: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1314: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1315: } else {
1316: $canpaste = 0;
1317: $nopaste = &mt('Paste from another course unavailable.');
1318: }
1319: }
1320: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1321: my $prefix = $1;
1322: $parent = $2;
1323: if ($folder !~ /^\Q$prefix\E/) {
1324: $areachange = 1;
1325: }
1326: $is_uploaded_map = 1;
1.492 raeburn 1327: }
1.597 raeburn 1328: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 ! raeburn 1329: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1330: if ($cid ne $env{'request.course.id'}) {
1331: my ($srcdom,$srcnum) = split(/_/,$cid);
1332: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 ! raeburn 1333: if (($is_exttool) && ($srcdom ne $coursedom)) {
! 1334: $canpaste = 0;
! 1335: $nopaste = &mt('Paste from another domain unavailable.');
! 1336: } else {
! 1337: $othercrs = '<br />'.&mt('(from another course)');
! 1338: }
1.596 raeburn 1339: } else {
1340: $canpaste = 0;
1341: $nopaste = &mt('Paste from another course unavailable.');
1342: }
1343: }
1.492 raeburn 1344: }
1.596 raeburn 1345: if ($canpaste) {
1346: push(@pasteable,$suffix);
1347: }
1.538 raeburn 1348: }
1349: my $buffer;
1.627 ! raeburn 1350: if ($is_external) {
1.538 raeburn 1351: $buffer = &mt('External Resource').': '.
1352: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1353: &LONCAPA::map::qtescape($url).')';
1.627 ! raeburn 1354: } elsif ($is_exttool) {
! 1355: $buffer = &mt('External Tool').': '.
! 1356: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1357: } else {
1358: my $icon = &Apache::loncommon::icon($extension);
1359: if ($extension eq 'sequence' &&
1360: $url =~ m{/default_\d+\.sequence$}x) {
1361: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1362: $icon .= '/navmap.folder.closed.gif';
1363: }
1.589 raeburn 1364: my $title = $env{'docs.markedcopy_title_'.$suffix};
1365: if ($title eq '') {
1366: ($title) = ($url =~ m{/([^/]+)$});
1367: }
1.538 raeburn 1368: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1369: ': '.
1370: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1371: &LONCAPA::map::qtescape($title));
1.538 raeburn 1372: }
1373: $pasteitems .= '<div class="LC_left_float">';
1374: my ($options,$onclick);
1375: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1376: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1377: if (($is_uploaded_map) ||
1378: ($url =~ /(bulletinboard|smppg)$/) ||
1379: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1380: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1381: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1382: }
1383: }
1384: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1385: if ($nopaste) {
1386: $pasteitems .= $nopaste;
1387: } else {
1388: if ($othercrs) {
1389: $pasteitems .= $othercrs;
1390: }
1391: if ($options) {
1392: $pasteitems .= $options;
1.492 raeburn 1393: }
1394: }
1.538 raeburn 1395: $pasteitems .= '</div>';
1396: }
1397: }
1398: if ($pasteitems eq '') {
1399: &Apache::lonnet::delenv('docs.markedcopies');
1400: }
1401: my ($pasteform,$form_start,$buttons,$form_end);
1402: if ($pasteitems) {
1403: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1404: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1405: if (@pasteable) {
1.575 raeburn 1406: my $value = &mt('Paste to current folder');
1407: if ($container eq 'page') {
1408: $value = &mt('Paste to current page');
1409: }
1410: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1411: }
1412: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1413: if ($clipboardcount > 1) {
1414: $buttons .=
1415: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1416: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1417: (' 'x2).
1418: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1419: (' 'x2);
1.492 raeburn 1420: }
1.575 raeburn 1421: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1422: '</form>';
1.538 raeburn 1423: } else {
1424: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1425: }
1.538 raeburn 1426: $r->print($form_start
1427: .'<fieldset>'
1428: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1429: .$pasteitems
1430: .'</fieldset>'
1431: .$form_end);
1432: }
1433:
1434: sub paste_options {
1435: my ($suffix,$is_uploaded_map,$parent) = @_;
1436: my ($copytext,$movetext);
1437: if ($is_uploaded_map) {
1438: $copytext = &mt('Copy to new folder');
1439: $movetext = &mt('Move old');
1440: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1441: $copytext = &mt('Copy to new board');
1442: $movetext = &mt('Move (not posts)');
1443: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1444: $copytext = &mt('Copy to new page');
1445: $movetext = &mt('Move');
1.533 raeburn 1446: } else {
1.538 raeburn 1447: $copytext = &mt('Copy to new file');
1448: $movetext = &mt('Move');
1449: }
1450: my $output = '<br />'.
1451: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1452: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1453: '<label>'.
1454: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1455: $copytext.'</label></span>'.(' 'x2).' '.
1456: '<span class="LC_nobreak"><label>'.
1457: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1458: $movetext.'</label></span>';
1459: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1460: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1461: '</legend><table border="0">';
1462: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1463: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1464: my $lastdir = $parent;
1465: my %depths = (
1466: $lastdir => 0,
1467: );
1468: my (%display,%deps);
1469: for (my $i=0; $i<@pastemaps; $i++) {
1470: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1471: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1472: my @subfolders = split(/,/,$subfolderstr);
1473: $deps{$lastdir} = \@subfolders;
1474: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1475: my $depth = $depths{$lastdir} + 1;
1476: my $offset = int($depth * 4);
1477: my $indent = (' ' x $offset);
1478: for (my $j=0; $j<@subfolders; $j++) {
1479: $depths{$subfolders[$j]} = $depth;
1480: $display{$subfolders[$j]} =
1481: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1482: '<td><label>'.
1483: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1484: '<label>'.
1485: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1486: &mt('Move old').'</label>'.
1487: '</td></tr>';
1488: }
1.492 raeburn 1489: }
1.538 raeburn 1490: &recurse_print(\$output,$parent,\%deps,\%display);
1491: $output .= '</table></fieldset>';
1.329 droeschl 1492: }
1.538 raeburn 1493: $output .= '</div>';
1494: return $output;
1.488 raeburn 1495: }
1496:
1.492 raeburn 1497: sub recurse_print {
1.538 raeburn 1498: my ($outputref,$dir,$deps,$display) = @_;
1499: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1500: if (ref($deps->{$dir}) eq 'ARRAY') {
1501: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1502: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1503: }
1504: }
1505: }
1506:
1.488 raeburn 1507: sub supp_pasteable {
1508: my ($url) = @_;
1509: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1510: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1511: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1512: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1513: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1514: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1515: return 1;
1516: }
1517: return;
1.329 droeschl 1518: }
1519:
1.492 raeburn 1520: sub paste_popup_js {
1.594 damieng 1521: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1522: show => 'Show Options',
1523: hide => 'Hide Options',
1.594 damieng 1524: );
1525: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1526: none => 'No items selected from clipboard.',
1.492 raeburn 1527: );
1.594 damieng 1528: &html_escape(\%html_js_lt);
1529: &js_escape(\%html_js_lt);
1530: &js_escape(\%js_lt);
1.492 raeburn 1531: return <<"END";
1532:
1.538 raeburn 1533: function showPasteOptions(suffix) {
1534: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1535: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1536: return;
1537: }
1538:
1.538 raeburn 1539: function hidePasteOptions(suffix) {
1540: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1541: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1542: return;
1543: }
1544:
1545: function showOptions(caller,suffix) {
1546: if (document.getElementById('pasteoptionstext_'+suffix)) {
1547: if (caller.checked) {
1.594 damieng 1548: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1549: } else {
1550: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1551: }
1552: if (document.getElementById('pasteoptions_'+suffix)) {
1553: document.getElementById('pasteoptions_'+suffix).style.display='none';
1554: }
1555: }
1.492 raeburn 1556: return;
1557: }
1558:
1.541 raeburn 1559: function validateClipboard() {
1560: var numchk = 0;
1561: if (document.pasteform.pasting.length > 1) {
1562: for (var i=0; i<document.pasteform.pasting.length; i++) {
1563: if (document.pasteform.pasting[i].checked) {
1564: numchk ++;
1565: }
1566: }
1567: } else {
1568: if (document.pasteform.pasting.type == 'checkbox') {
1569: if (document.pasteform.pasting.checked) {
1570: numchk ++;
1571: }
1572: }
1573: }
1574: if (numchk > 0) {
1575: return true;
1576: } else {
1.594 damieng 1577: alert("$js_lt{'none'}");
1.541 raeburn 1578: return false;
1579: }
1580: }
1581:
1.575 raeburn 1582: function checkClipboard() {
1583: if (document.pasteform.pasting.length > 1) {
1584: for (var i=0; i<document.pasteform.pasting.length; i++) {
1585: document.pasteform.pasting[i].checked = true;
1586: }
1587: }
1588: return;
1589: }
1590:
1591: function uncheckClipboard() {
1592: if (document.pasteform.pasting.length >1) {
1593: for (var i=0; i<document.pasteform.pasting.length; i++) {
1594: document.pasteform.pasting[i].checked = false;
1595: }
1596: }
1597: return;
1598: }
1599:
1.492 raeburn 1600: END
1601:
1602: }
1603:
1.329 droeschl 1604: sub do_paste_from_buffer {
1.492 raeburn 1605: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1606:
1.538 raeburn 1607: # Array of items in paste buffer
1608: my (@currpaste,%pastebuffer,%allerrors);
1609: @currpaste = split(/,/,$env{'docs.markedcopies'});
1610:
1.492 raeburn 1611: # Early out if paste buffer is empty
1.538 raeburn 1612: if (@currpaste == 0) {
1.492 raeburn 1613: return ();
1.538 raeburn 1614: }
1615: map { $pastebuffer{$_} = 1; } @currpaste;
1616:
1617: # Array of items selected items to paste
1618: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1619:
1620: # Early out if nothing selected to paste
1621: if (@reqpaste == 0) {
1622: return();
1623: }
1624: my @topaste;
1625: foreach my $suffix (@reqpaste) {
1626: next if ($suffix =~ /\D/);
1627: next unless (exists($pastebuffer{$suffix}));
1628: push(@topaste,$suffix);
1629: }
1630:
1631: # Early out if nothing available to paste
1632: if (@topaste == 0) {
1633: return();
1.329 droeschl 1634: }
1635:
1.627 ! raeburn 1636: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1637: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1638:
1639: foreach my $suffix (@topaste) {
1640: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1641: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1642: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1643: # Supplemental content may only include certain types of content
1644: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1645: if ($folder =~ /^supplemental/) {
1646: unless (&supp_pasteable($url)) {
1647: $notinsupp{$suffix} = 1;
1648: next;
1649: }
1.492 raeburn 1650: }
1.538 raeburn 1651: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1652: my $srcd = $1;
1653: my $srcn = $2;
1.492 raeburn 1654: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1655: # check for mdc privilege in the course from which the resource was pasted
1656: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1657: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1658: $notincrs{$suffix} = 1;
1659: next;
1660: }
1.491 raeburn 1661: }
1.538 raeburn 1662: $srcdom{$suffix} = $srcd;
1663: $srcnum{$suffix} = $srcn;
1.597 raeburn 1664: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 ! raeburn 1665: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg|ext\.tool)$})) {
! 1666: my $srctype= $1;
1.596 raeburn 1667: my ($srcd,$srcn) = split(/_/,$cid);
1668: # When paste buffer was populated using an active role in a different course
1669: # check for mdc privilege in the course from which the resource was pasted
1670: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1671: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1672: $notincrs{$suffix} = 1;
1673: next;
1674: }
1675: }
1.627 ! raeburn 1676: if (($srctype eq 'ext.tool') && ($srcd ne $coursedom)) {
! 1677: $notindom{$suffix} = 1;
! 1678: next;
! 1679: }
1.596 raeburn 1680: $srcdom{$suffix} = $srcd;
1681: $srcnum{$suffix} = $srcn;
1.491 raeburn 1682: }
1.597 raeburn 1683: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1684: push(@dopaste,$suffix);
1685: if ($url=~/\.(page|sequence)$/) {
1686: $is_map{$suffix} = 1;
1687: }
1688: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1689: my $oldprefix = $1;
1.492 raeburn 1690: # When pasting content from Main Content to Supplemental Content and vice versa
1691: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1692: # a folder/page or a document).
1.538 raeburn 1693: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1694: $prefixchg{$suffix} = 'docstosupp';
1695: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1696: $prefixchg{$suffix} = 'supptodocs';
1697: }
1.491 raeburn 1698:
1.492 raeburn 1699: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1700: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1701: my @nested;
1702: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1703: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1704: my @deps = map { /\d+:([\d,]+$)/ } @items;
1705: foreach my $dep (@deps) {
1706: if ($dep =~ /,/) {
1707: push(@nested,split(/,/,$dep));
1708: } else {
1709: push(@nested,$dep);
1710: }
1.492 raeburn 1711: }
1.538 raeburn 1712: foreach my $item (@nested) {
1713: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1714: push(@{$marktomove{$suffix}},$type.'_'.$item);
1715: }
1.492 raeburn 1716: }
1717: }
1.488 raeburn 1718: }
1719: }
1720:
1.538 raeburn 1721: # Early out if nothing available to paste
1722: if (@dopaste == 0) {
1723: return ();
1724: }
1725:
1726: # Populate message hash and hashes used for main content <=> supplemental content
1727: # changes
1728:
1729: %msgs = &Apache::lonlocal::texthash (
1730: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1731: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.627 ! raeburn 1732: notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.538 raeburn 1733: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1734: );
1735:
1736: %before = (
1737: docstosupp => {
1738: map => 'default',
1739: doc => 'docs',
1740: },
1741: supptodocs => {
1742: map => 'supplemental',
1743: doc => 'supplemental',
1744: },
1745: );
1746:
1747: %after = (
1748: docstosupp => {
1749: map => 'supplemental',
1750: doc => 'supplemental'
1751: },
1752: supptodocs => {
1753: map => 'default',
1754: doc => 'docs',
1755: },
1756: );
1757:
1758: # Retrieve information about all course maps in main content area
1759:
1760: my $allmaps = {};
1761: if ($folder =~ /^default/) {
1762: $allmaps =
1763: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1764: $env{"course.$env{'request.course.id'}.home"},
1765: $env{'request.course.id'});
1766: }
1767:
1768: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1769:
1770: # Loop over the items to paste
1771: foreach my $suffix (@dopaste) {
1.329 droeschl 1772: # Maps need to be copied first
1.538 raeburn 1773: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1774: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1775: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1776: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1777: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1778: }
1779: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1780: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1781: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1782: my $oldurl = $url;
1783: if ($is_map{$suffix}) {
1.491 raeburn 1784: # If pasting a map, check if map contains other maps
1.538 raeburn 1785: my (%hierarchy,%titles);
1.627 ! raeburn 1786: &contained_map_check($url,$folder,$coursenum,$coursedom,
! 1787: \%removefrommap,\%removeparam,\%addedmaps,
! 1788: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1789: if ($url=~ m{^/uploaded/}) {
1790: my $newurl;
1791: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1792: ($newurl,my $error) =
1793: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1794: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1795: \$title,$allmaps,\%newurls);
1796: if ($error) {
1797: $allerrors{$suffix} = $error;
1798: next;
1799: }
1800: if ($newurl ne '') {
1801: if ($newurl ne $url) {
1802: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1803: $newsubdir{$url} = $1;
1804: }
1805: $mapchanges{$url} = 1;
1.492 raeburn 1806: }
1.538 raeburn 1807: }
1808: }
1809: if (($srcdom{$suffix} ne $coursedom) ||
1810: ($srcnum{$suffix} ne $coursenum) ||
1811: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1812: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1813: $coursedom,$coursenum,$srcdom{$suffix},
1814: $srcnum{$suffix},$allmaps,\%rewrites,
1815: \%retitles,\%copies,\%dbcopies,
1816: \%zombies,\%params,\%mapmoves,
1817: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1818: \%newurls,\%resdatacopy)) {
1.538 raeburn 1819: $mapmoves{$url} = 1;
1820: }
1821: $url = $newurl;
1822: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1823: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1824: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1825: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1826: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1827: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1828: }
1829: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1830: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1831: push(@toclear,$suffix);
1832: # if pasting published map (main content area only) check map not already in course
1833: if ($folder =~ /^default/) {
1834: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1835: $duplicate{$suffix} = 1;
1836: next;
1.492 raeburn 1837: }
1.491 raeburn 1838: }
1839: }
1.538 raeburn 1840: }
1.627 ! raeburn 1841: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1842: my $prefix = $1;
1.596 raeburn 1843: my $fromothercrs;
1.538 raeburn 1844: #need to copy the db contents to a new one, unless this is a move.
1845: my %info = (
1846: src => $url,
1847: cdom => $coursedom,
1848: cnum => $coursenum,
1.596 raeburn 1849: );
1850: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1851: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1852: $fromothercrs = 1;
1853: $info{'cdom'} = $srcdom{$suffix};
1854: $info{'cnum'} = $srcnum{$suffix};
1855: }
1856: }
1857: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.538 raeburn 1858: my (%lockerr,$msg);
1859: my ($newurl,$result,$errtext) =
1860: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1861: if ($result eq 'ok') {
1862: $url = $newurl;
1863: $title=&mt('Copy of').' '.$title;
1864: } else {
1865: if ($prefix eq 'smppg') {
1866: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1867: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1868: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 ! raeburn 1869: } elsif ($prefix eq 'ext.tool') {
! 1870: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 1871: }
1872: $results{$suffix} = $result;
1873: $msgerrs{$suffix} = $msg;
1874: $lockerrs{$suffix} = $lockerr{$prefix};
1875: next;
1876: }
1877: if ($lockerr{$prefix}) {
1878: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1879: }
1.489 raeburn 1880: }
1881: }
1.538 raeburn 1882: $title = &LONCAPA::map::qtunescape($title);
1883: my $ext='false';
1884: if ($url=~m{^http(|s)://}) { $ext='true'; }
1885: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1886: if ($folder !~ /^supplemental/) {
1887: (undef,undef,$title) =
1888: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1889: }
1890: } else {
1891: if ($folder=~/^supplemental/) {
1892: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1893: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1894: }
1.533 raeburn 1895: }
1.491 raeburn 1896:
1897: # For uploaded files (excluding pages/sequences) path in copied file is changed
1898: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1899: # courses.
1900:
1.538 raeburn 1901: unless ($is_map{$suffix}) {
1902: my $newidx;
1.492 raeburn 1903: # Now insert the URL at the bottom
1.538 raeburn 1904: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1905: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1906: my $relpath = $1;
1907: if ($relpath ne '') {
1908: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1909: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1910: my $newprefix = $newloc;
1911: if ($newloc eq 'default') {
1912: $newprefix = 'docs';
1913: }
1914: if ($newdocsdir eq '') {
1915: $newdocsdir = 'default';
1916: }
1917: if (($prefixchg{$suffix}) ||
1918: ($srcdom{$suffix} ne $coursedom) ||
1919: ($srcnum{$suffix} ne $coursenum) ||
1920: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1921: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1922: $url =
1923: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1924: &Apache::lonnet::getfile($oldurl));
1925: if ($url eq '/adm/notfound.html') {
1926: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1927: next;
1928: } else {
1929: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1930: $newsubpath =~ s{/+$}{/};
1931: $docmoves{$oldurl} = $newsubpath;
1932: }
1.491 raeburn 1933: }
1934: }
1.597 raeburn 1935: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1936: my $template = $1;
1937: if ($newidx) {
1938: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1939: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1940: }
1.491 raeburn 1941: }
1.538 raeburn 1942: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1943: ':'.$ext.':normal:res';
1944: push(@LONCAPA::map::order,$newidx);
1945: # Store the result
1946: my ($errtext,$fatal) =
1947: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1948: if ($fatal) {
1949: $save_err .= $errtext;
1950: $allresult = 'fail';
1951: }
1.488 raeburn 1952: }
1.538 raeburn 1953:
1.597 raeburn 1954: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1955: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1956: unless ($allresult eq 'fail') {
1957: my %updated = (
1958: rewrites => \%rewrites,
1959: zombies => \%zombies,
1960: removefrommap => \%removefrommap,
1961: removeparam => \%removeparam,
1962: dbcopies => \%dbcopies,
1.597 raeburn 1963: resdatacopy => \%resdatacopy,
1.538 raeburn 1964: retitles => \%retitles,
1965: );
1966: my %info = (
1967: newsubdir => \%newsubdir,
1968: params => \%params,
1969: );
1970: if ($prefixchg{$suffix}) {
1971: $info{'before'} = $before{$prefixchg{$suffix}};
1972: $info{'after'} = $after{$prefixchg{$suffix}};
1973: }
1974: my %moves = (
1975: copies => \%copies,
1976: docmoves => \%docmoves,
1977: mapmoves => \%mapmoves,
1978: );
1979: (my $result,$msgs{$suffix},my $lockerror) =
1980: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1981: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1982: $url,'paste');
1983: $lockerrors .= $lockerror;
1984: if ($result eq 'ok') {
1985: if ($is_map{$suffix}) {
1986: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1987: $folder.'.'.$container);
1988: if ($fatal) {
1989: $allresult = 'failread';
1990: } else {
1991: if ($#LONCAPA::map::order<1) {
1992: my $idx=&LONCAPA::map::getresidx();
1993: if ($idx<=0) { $idx=1; }
1994: $LONCAPA::map::order[0]=$idx;
1995: $LONCAPA::map::resources[$idx]='';
1996: }
1997: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1998: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1999: ':'.$ext.':normal:res';
2000: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2001:
2002: # Store the result
1.538 raeburn 2003: my ($errtext,$fatal) =
2004: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2005: if ($fatal) {
2006: $save_err .= $errtext;
2007: $allresult = 'failstore';
2008: }
2009: }
2010: }
2011: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2012: push(@toclear,$suffix);
2013: }
2014: }
1.492 raeburn 2015: }
2016: }
1.538 raeburn 2017: &clear_from_buffer(\@toclear,\@currpaste);
2018: my $msgsarray;
2019: foreach my $suffix (keys(%msgs)) {
2020: if (ref($msgs{$suffix}) eq 'ARRAY') {
2021: $msgsarray .= join(',',@{$msgs{$suffix}});
2022: }
2023: }
2024: return ($allresult,$save_err,$msgsarray,$lockerrors);
2025: }
1.533 raeburn 2026:
1.538 raeburn 2027: sub do_buffer_empty {
2028: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2029: if (@currpaste == 0) {
2030: return &mt('Clipboard is already empty');
2031: }
2032: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2033: if (@toclear == 0) {
2034: return &mt('Nothing selected to clear from clipboard');
2035: }
2036: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2037: if ($numdel) {
2038: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2039: } else {
2040: return &mt('Clipboard unchanged');
1.492 raeburn 2041: }
1.538 raeburn 2042: return;
2043: }
2044:
2045: sub clear_from_buffer {
2046: my ($toclear,$currpaste) = @_;
2047: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2048: my %pastebuffer;
2049: map { $pastebuffer{$_} = 1; } @{$currpaste};
2050: my $numdel = 0;
2051: foreach my $suffix (@{$toclear}) {
2052: next if ($suffix =~ /\D/);
2053: next unless (exists($pastebuffer{$suffix}));
2054: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2055: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2056: delete($pastebuffer{$suffix});
2057: $numdel ++;
2058: }
2059: }
2060: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2061: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2062: return $numdel;
1.492 raeburn 2063: }
2064:
2065: sub get_newmap_url {
2066: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2067: $titleref,$allmaps,$newurls) = @_;
2068: my $newurl;
2069: if ($url=~ m{^/uploaded/}) {
2070: $$titleref=&mt('Copy of').' '.$$titleref;
2071: }
2072: my $now = time;
2073: my $suffix=$$.int(rand(100)).$now;
2074: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2075: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2076: my $path = $1;
2077: my $prefix = $2;
2078: my $ancestor = $3;
2079: if (length($ancestor) > 10) {
2080: $ancestor = substr($ancestor,-10,10);
2081: }
2082: my $newid;
2083: if ($prefixchg) {
2084: if ($folder =~ /^supplemental/) {
2085: $prefix =~ s/^default/supplemental/;
2086: } else {
2087: $prefix =~ s/^supplemental/default/;
2088: }
2089: }
2090: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2091: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2092: } else {
2093: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2094: }
2095: my $counter = 0;
2096: my $is_unique = &uniqueness_check($newurl);
2097: if ($folder =~ /^default/) {
2098: if ($allmaps->{$newurl}) {
2099: $is_unique = 0;
2100: }
2101: }
2102: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2103: $counter ++;
2104: $suffix ++;
2105: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2106: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2107: } else {
2108: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2109: }
2110: $is_unique = &uniqueness_check($newurl);
2111: }
2112: if ($is_unique) {
2113: $newurls->{$newurl} = 1;
2114: } else {
2115: if ($url=~/\.page$/) {
2116: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2117: } else {
2118: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2119: }
2120: }
1.329 droeschl 2121: }
1.492 raeburn 2122: return ($newurl);
1.329 droeschl 2123: }
2124:
1.488 raeburn 2125: sub dbcopy {
1.533 raeburn 2126: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2127: my ($url,$result,$errtext);
2128: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2129: $url = $dbref->{'src'};
1.627 ! raeburn 2130: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2131: my $prefix = $1;
1.627 ! raeburn 2132: if ($prefix eq 'ext.tool') {
! 2133: $prefix = 'exttool';
! 2134: }
1.533 raeburn 2135: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2136: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2137: my $db_name;
2138: my $marker = (split(m{/},$url))[4];
2139: $marker=~s/\D//g;
2140: if ($dbref->{'src'} =~ m{/smppg$}) {
2141: $db_name =
2142: &Apache::lonsimplepage::get_db_name($url,$marker,
2143: $dbref->{'cdom'},
2144: $dbref->{'cnum'});
1.627 ! raeburn 2145: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
! 2146: $db_name = 'exttool_'.$marker;
1.533 raeburn 2147: } else {
2148: $db_name = 'bulletinpage_'.$marker;
2149: }
2150: my ($suffix,$freedlock,$error) =
2151: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2152: $coursedom,$coursenum,
2153: 'concat');
2154: if (!$suffix) {
2155: if ($prefix eq 'smppg') {
2156: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2157: } else {
1.565 bisitz 2158: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2159: }
2160: if ($error) {
2161: $errtext .= '<br />'.$error;
2162: }
2163: } else {
2164: #need to copy the db contents to a new one.
2165: my %contents=&Apache::lonnet::dump($db_name,
2166: $dbref->{'cdom'},
2167: $dbref->{'cnum'});
2168: if (exists($contents{'uploaded.photourl'})) {
2169: my $photo = $contents{'uploaded.photourl'};
2170: my ($subdir,$fname) =
2171: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2172: my $newphoto;
1.533 raeburn 2173: if ($fname ne '') {
2174: my $content = &Apache::lonnet::getfile($photo);
2175: unless ($content eq '-1') {
2176: $env{'form.'.$suffix.'.photourl'} = $content;
2177: $newphoto =
2178: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2179: delete($env{'form.'.$suffix.'.photourl'});
2180: }
2181: }
2182: if ($newphoto =~ m{^/uploaded/}) {
2183: $contents{'uploaded.photourl'} = $newphoto;
2184: }
2185: }
2186: $db_name =~ s{_\d*$ }{_$suffix}x;
2187: $result=&Apache::lonnet::put($db_name,\%contents,
2188: $coursedom,$coursenum);
2189: if ($result eq 'ok') {
1.627 ! raeburn 2190: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2191: }
2192: }
2193: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2194: $lockerrorsref->{$prefix} =
1.533 raeburn 2195: '<div class="LC_error">'.
2196: &mt('There was a problem removing a lockfile.');
2197: if ($prefix eq 'smppg') {
1.560 raeburn 2198: $lockerrorsref->{$prefix} .=
1.559 raeburn 2199: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 ! raeburn 2200: } elsif ($prefix eq 'exttool') {
! 2201: $lockerrorsref->{$prefix} .=
! 2202: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2203: } else {
1.565 bisitz 2204: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2205: }
1.560 raeburn 2206: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2207: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2208: '</div>';
1.533 raeburn 2209: }
2210: }
2211: } elsif ($url =~ m{/syllabus$}) {
2212: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2213: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2214: if (($dbref->{'cdom'} ne $coursedom) ||
2215: ($dbref->{'cnum'} ne $coursenum)) {
2216: my %contents=&Apache::lonnet::dump('syllabus',
2217: $dbref->{'cdom'},
2218: $dbref->{'cnum'});
2219: $result=&Apache::lonnet::put('syllabus',\%contents,
2220: $coursedom,$coursenum);
2221: }
2222: }
1.488 raeburn 2223: }
2224: }
1.533 raeburn 2225: return ($url,$result,$errtext);
1.488 raeburn 2226: }
2227:
1.597 raeburn 2228: sub copy_templated_files {
2229: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2230: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2231: my $srccontainer = 'sequence';
2232: if ($srcwaspage) {
2233: $srccontainer = 'page';
2234: }
2235: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2236: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2237: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2238: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2239: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2240: $template.'.problem';
2241: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2242: if ($template eq 'simpleproblem') {
2243: $srcprefix .= '.0.';
2244: my $weightprefix = $newprefix;
2245: $newprefix .= '.0.';
2246: my @simpleprobqtypes = qw(radio option string essay numerical);
2247: my $qtype=$srcparms{$srcprefix.'questiontype'};
2248: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2249: my %newdata;
2250: foreach my $type (@simpleprobqtypes) {
2251: if ($type eq $qtype) {
2252: $newdata{"$weightprefix.$type.weight"}=1;
2253: } else {
2254: $newdata{"$weightprefix.$type.weight"}=0;
2255: }
2256: }
2257: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2258: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2259: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2260: if ($qtype eq 'numerical') {
2261: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2262: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2263: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2264: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2265: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2266: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2267: unless (defined($maxfoils)) { $maxfoils=10; }
2268: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2269: if ($maxfoils<=0) { $maxfoils=10; }
2270: my $randomize=$srcparms{$srcprefix.'randomize'};
2271: unless (defined($randomize)) { $randomize='yes'; }
2272: unless ($randomize eq 'no') { $randomize='yes'; }
2273: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2274: $newdata{$newprefix.'randomize'} = $randomize;
2275: if ($qtype eq 'option') {
2276: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2277: }
2278: for (my $i=1; $i<=10; $i++) {
2279: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2280: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2281: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2282: }
2283:
2284: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2285: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2286: unless (defined($maxfoils)) { $maxfoils=10; }
2287: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2288: if ($maxfoils<=0) { $maxfoils=10; }
2289: my $randomize=$srcparms{$srcprefix.'randomize'};
2290: unless (defined($randomize)) { $randomize='yes'; }
2291: unless ($randomize eq 'no') { $randomize='yes'; }
2292: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2293: $newdata{$newprefix.'randomize'} = $randomize;
2294: if ($qtype eq 'option') {
2295: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2296: }
2297: for (my $i=1; $i<=10; $i++) {
2298: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2299: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2300: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2301: }
2302: } elsif ($qtype eq 'string') {
2303: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2304: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2305: }
2306: if (keys(%newdata)) {
2307: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2308: $coursenum);
2309: if ($putres eq 'ok') {
2310: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2311: }
2312: }
2313: }
2314: }
2315: }
2316:
1.329 droeschl 2317: sub uniqueness_check {
2318: my ($newurl) = @_;
2319: my $unique = 1;
2320: foreach my $res (@LONCAPA::map::order) {
2321: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2322: $url=&LONCAPA::map::qtescape($url);
2323: if ($newurl eq $url) {
2324: $unique = 0;
1.344 bisitz 2325: last;
1.329 droeschl 2326: }
2327: }
2328: return $unique;
2329: }
2330:
1.488 raeburn 2331: sub contained_map_check {
1.627 ! raeburn 2332: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
! 2333: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2334: my $content = &Apache::lonnet::getfile($url);
2335: unless ($content eq '-1') {
2336: my $parser = HTML::TokeParser->new(\$content);
2337: $parser->attr_encoded(1);
2338: while (my $token = $parser->get_token) {
2339: next if ($token->[0] ne 'S');
2340: if ($token->[1] eq 'resource') {
2341: next if ($token->[2]->{'type'} eq 'zombie');
2342: my $ressrc = $token->[2]->{'src'};
1.627 ! raeburn 2343: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
! 2344: my $srcdom = $1;
! 2345: unless ($srcdom eq $coursedom) {
! 2346: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
! 2347: next;
! 2348: }
! 2349: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2350: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2351: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2352: next;
2353: }
2354: }
1.492 raeburn 2355: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2356: if ($1 eq 'uploaded') {
2357: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2358: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2359: } else {
1.492 raeburn 2360: if ($allmaps->{$ressrc}) {
1.529 raeburn 2361: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2362: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2363: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2364: } else {
2365: $addedmaps->{$ressrc} = [$url];
2366: }
1.488 raeburn 2367: }
1.627 ! raeburn 2368: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
! 2369: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2370: }
1.492 raeburn 2371: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2372: if ($folder =~ /^supplemental/) {
1.492 raeburn 2373: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2374: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2375: } else {
2376: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2377: }
1.488 raeburn 2378: }
2379: }
2380: }
2381: }
2382: return;
2383: }
2384:
2385: sub url_paste_fixups {
1.533 raeburn 2386: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2387: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2388: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2389: my $checktitle;
2390: if (($prefixchg) &&
1.492 raeburn 2391: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2392: $checktitle = 1;
2393: }
1.492 raeburn 2394: my $skip;
2395: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2396: my $mapid = $1.$2;
2397: if ($tomove->{$mapid}) {
2398: $skip = 1;
2399: }
2400: }
1.491 raeburn 2401: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2402: return if ($file eq '-1');
2403: my $parser = HTML::TokeParser->new(\$file);
2404: $parser->attr_encoded(1);
1.491 raeburn 2405: my $changed = 0;
1.488 raeburn 2406: while (my $token = $parser->get_token) {
2407: next if ($token->[0] ne 'S');
2408: if ($token->[1] eq 'resource') {
2409: my $ressrc = $token->[2]->{'src'};
2410: next if ($ressrc eq '');
1.491 raeburn 2411: my $id = $token->[2]->{'id'};
1.492 raeburn 2412: my $title = $token->[2]->{'title'};
1.491 raeburn 2413: if ($checktitle) {
2414: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2415: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2416: }
2417: }
1.488 raeburn 2418: next if ($token->[2]->{'type'} eq 'external');
2419: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2420: next if ($skip);
1.532 raeburn 2421: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2422: $changed = 1;
2423: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2424: my $srcdom = $1;
2425: my $srcnum = $2;
1.488 raeburn 2426: my $rem = $3;
1.492 raeburn 2427: my $newurl;
2428: my $mapname;
2429: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2430: my $prefix = $1;
2431: $mapname = $prefix.$2;
2432: if ($tomove->{$mapname}) {
1.533 raeburn 2433: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2434: $srcdom,$srcnum,$allmaps,$rewrites,
2435: $retitles,$copies,$dbcopies,$zombies,
2436: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2437: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2438: next;
2439: } else {
2440: ($newurl,my $error) =
2441: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2442: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2443: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2444: $newsubdir->{$ressrc} = $1;
2445: }
2446: if ($error) {
2447: next;
2448: }
2449: }
2450: }
2451: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2452: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2453:
1.488 raeburn 2454: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2455: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2456: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2457: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2458: $cnum,$srcdom,$srcnum,$allmaps,
2459: $rewrites,$retitles,$copies,$dbcopies,
2460: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2461: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2462: $mapmoves->{$ressrc} = 1;
2463: }
2464: $changed = 1;
1.488 raeburn 2465: } else {
1.532 raeburn 2466: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2467: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2468: $changed = 1;
1.488 raeburn 2469: }
2470: }
1.533 raeburn 2471: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2472: next if ($skip);
1.492 raeburn 2473: my $srcdom = $1;
2474: my $srcnum = $2;
2475: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2476: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2477: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2478: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2479: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2480: $changed = 1;
2481: }
2482: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2483: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2484: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2485: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2486: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2487: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2488: $changed = 1;
1.488 raeburn 2489: }
1.597 raeburn 2490: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2491: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2492: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2493: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2494: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2495: }
1.488 raeburn 2496: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2497: next if ($skip);
2498: my $srcdom = $1;
2499: my $srcnum = $2;
2500: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2501: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2502: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2503: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2504: $changed = 1;
1.488 raeburn 2505: }
2506: }
2507: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2508: next if ($skip);
1.488 raeburn 2509: my $to = $token->[2]->{'to'};
2510: if ($to ne '') {
2511: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2512: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2513: } else {
2514: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2515: }
2516: }
2517: }
2518: }
1.491 raeburn 2519: return $changed;
1.488 raeburn 2520: }
2521:
2522: sub apply_fixups {
1.529 raeburn 2523: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2524: $oldurl,$url,$caller) = @_;
2525: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2526: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2527: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2528: if (ref($updated) eq 'HASH') {
2529: if (ref($updated->{'rewrites'}) eq 'HASH') {
2530: %rewrites = %{$updated->{'rewrites'}};
2531: }
2532: if (ref($updated->{'zombies'}) eq 'HASH') {
2533: %zombies = %{$updated->{'zombies'}};
2534: }
2535: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2536: %removefrommap = %{$updated->{'removefrommap'}};
2537: }
2538: if (ref($updated->{'removeparam'}) eq 'HASH') {
2539: %removeparam = %{$updated->{'removeparam'}};
2540: }
2541: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2542: %dbcopies = %{$updated->{'dbcopies'}};
2543: }
2544: if (ref($updated->{'retitles'}) eq 'HASH') {
2545: %retitles = %{$updated->{'retitles'}};
2546: }
1.597 raeburn 2547: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2548: %resdatacopy = %{$updated->{'resdatacopy'}};
2549: }
1.529 raeburn 2550: }
2551: if (ref($info) eq 'HASH') {
2552: if (ref($info->{'newsubdir'}) eq 'HASH') {
2553: %newsubdir = %{$info->{'newsubdir'}};
2554: }
2555: if (ref($info->{'params'}) eq 'HASH') {
2556: %params = %{$info->{'params'}};
2557: }
2558: if (ref($info->{'before'}) eq 'HASH') {
2559: %before = %{$info->{'before'}};
2560: }
2561: if (ref($info->{'after'}) eq 'HASH') {
2562: %after = %{$info->{'after'}};
2563: }
2564: }
2565: if (ref($moves) eq 'HASH') {
2566: if (ref($moves->{'copies'}) eq 'HASH') {
2567: %copies = %{$moves->{'copies'}};
2568: }
2569: if (ref($moves->{'docmoves'}) eq 'HASH') {
2570: %docmoves = %{$moves->{'docmoves'}};
2571: }
2572: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2573: %mapmoves = %{$moves->{'mapmoves'}};
2574: }
2575: }
2576: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2577: my @allcopies;
1.529 raeburn 2578: if (exists($copies{$key})) {
2579: if (ref($copies{$key}) eq 'HASH') {
2580: my %added;
2581: foreach my $innerkey (keys(%{$copies{$key}})) {
2582: if (($innerkey ne '') && (!$added{$innerkey})) {
2583: push(@allcopies,$innerkey);
2584: $added{$innerkey} = 1;
2585: }
1.491 raeburn 2586: }
1.529 raeburn 2587: undef(%added);
1.491 raeburn 2588: }
2589: }
2590: if ($key eq $oldurl) {
1.529 raeburn 2591: if ((exists($docmoves{$key}))) {
1.532 raeburn 2592: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2593: push(@allcopies,$oldurl);
2594: }
2595: }
2596: }
2597: if (@allcopies > 0) {
2598: foreach my $item (@allcopies) {
1.492 raeburn 2599: my ($relpath,$oldsubdir,$fname) =
2600: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2601: if ($fname ne '') {
2602: my $content = &Apache::lonnet::getfile($item);
2603: unless ($content eq '-1') {
2604: my $storefn;
1.529 raeburn 2605: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2606: $storefn = $docmoves{$key};
1.491 raeburn 2607: } else {
2608: $storefn = $relpath;
2609: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2610: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2611: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2612: }
1.529 raeburn 2613: if ($newsubdir{$key}) {
1.532 raeburn 2614: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2615: }
2616: }
2617: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2618: my $copyurl =
2619: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2620: $storefn.$fname,$content);
2621: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2622: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2623: return &mt('Paste failed: an error occurred copying the file.');
2624: } elsif (ref($errors) eq 'HASH') {
2625: $errors->{$item} = 1;
1.489 raeburn 2626: }
2627: }
1.488 raeburn 2628: }
2629: }
1.491 raeburn 2630: }
2631: }
2632: }
1.529 raeburn 2633: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2634: my $storefn=$key;
2635: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2636: if ($prefixchg && $before{'map'} && $after{'map'}) {
2637: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2638: }
1.529 raeburn 2639: if ($newsubdir{$key}) {
2640: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2641: }
1.491 raeburn 2642: my $mapcontent = &Apache::lonnet::getfile($key);
2643: if ($mapcontent eq '-1') {
2644: if (ref($errors) eq 'HASH') {
2645: $errors->{$key} = 1;
2646: }
2647: } else {
2648: my $newmap =
2649: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2650: $mapcontent);
2651: if ($newmap eq '/adm/notfound.html') {
2652: if (ref($errors) eq 'HASH') {
2653: $errors->{$key} = 1;
1.489 raeburn 2654: }
1.488 raeburn 2655: }
2656: }
2657: }
1.491 raeburn 2658: my %updates;
2659: if ($is_map) {
1.529 raeburn 2660: if (ref($updated) eq 'HASH') {
2661: foreach my $type (keys(%{$updated})) {
2662: if (ref($updated->{$type}) eq 'HASH') {
2663: foreach my $key (keys(%{$updated->{$type}})) {
2664: $updates{$key} = 1;
2665: }
2666: }
2667: }
1.491 raeburn 2668: }
2669: foreach my $key (keys(%updates)) {
1.492 raeburn 2670: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2671: if (ref($rewrites{$key}) eq 'HASH') {
2672: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2673: }
1.529 raeburn 2674: if (ref($retitles{$key}) eq 'HASH') {
2675: %toretitle = %{$retitles{$key}};
1.491 raeburn 2676: }
1.529 raeburn 2677: if (ref($removefrommap{$key}) eq 'HASH') {
2678: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2679: }
1.529 raeburn 2680: if (ref($removeparam{$key}) eq 'HASH') {
2681: %remparam = %{$removeparam{$key}};
1.492 raeburn 2682: }
1.529 raeburn 2683: if (ref($zombies{$key}) eq 'HASH') {
2684: %zombie = %{$zombies{$key}};
1.491 raeburn 2685: }
1.529 raeburn 2686: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2687: foreach my $idx (keys(%{$dbcopies{$key}})) {
2688: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2689: my ($newurl,$result,$errtext) =
2690: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2691: if ($result eq 'ok') {
2692: $newdb{$idx} = $newurl;
2693: } elsif (ref($errors) eq 'HASH') {
2694: $errors->{$key} = 1;
2695: }
2696: push(@msgs,$errtext);
2697: }
1.491 raeburn 2698: }
2699: }
1.597 raeburn 2700: if (ref($resdatacopy{$key}) eq 'HASH') {
2701: if ($newsubdir{$key}) {
2702:
2703: }
2704: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2705: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2706: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2707: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2708: my $template = $1;
2709: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2710: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2711: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2712: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2713: my ($newmapname) = ($key =~ m{/([^/]+)$});
2714: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2715: my $srcmapinfo = $srcfolder.':'.$idx;
2716: if ($srccontainer eq 'page') {
2717: $srcmapinfo .= ':1';
2718: }
2719: if ($newsubdir{$key}) {
2720: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2721: }
2722: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2723: $cnum,$template,$idx,$newmapname);
2724: }
2725: }
2726: }
2727: }
2728: }
1.529 raeburn 2729: if (ref($params{$key}) eq 'HASH') {
2730: %currparam = %{$params{$key}};
1.492 raeburn 2731: }
2732: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2733: if ($fatal) {
1.533 raeburn 2734: return ($errtext);
1.492 raeburn 2735: }
2736: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2737: if (defined($LONCAPA::map::zombies[$i])) {
2738: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2739: if ($zombie{$i} eq $src) {
1.492 raeburn 2740: undef($LONCAPA::map::zombies[$i]);
2741: }
2742: }
2743: }
1.529 raeburn 2744: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2745: my $idx = $LONCAPA::map::order[$i];
2746: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2747: my $changed;
1.529 raeburn 2748: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2749: if ((exists($toremove{$idx})) &&
2750: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2751: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2752: if (ref($currparam{$idx}) eq 'ARRAY') {
2753: foreach my $name (@{$currparam{$idx}}) {
2754: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2755: }
2756: }
2757: next;
2758: }
2759: my $origsrc = $src;
1.532 raeburn 2760: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2761: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2762: $changed = 1;
1.491 raeburn 2763: }
1.492 raeburn 2764: }
1.532 raeburn 2765: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2766: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2767: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2768: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2769: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2770: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2771: } else {
1.529 raeburn 2772: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2773: }
1.491 raeburn 2774: }
1.532 raeburn 2775: if ($origsrc =~ /\.(page|sequence)$/) {
2776: if ($newsubdir{$origsrc}) {
1.529 raeburn 2777: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2778: }
1.532 raeburn 2779: } elsif ($newsubdir{$key}) {
2780: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2781: }
2782: }
1.492 raeburn 2783: $changed = 1;
1.533 raeburn 2784: } elsif ($newdb{$idx} ne '') {
2785: $src = $newdb{$idx};
1.492 raeburn 2786: $changed = 1;
2787: }
2788: if ($changed) {
1.538 raeburn 2789: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2790: }
2791: }
2792: }
2793: foreach my $idx (keys(%remparam)) {
2794: if (ref($remparam{$idx}) eq 'ARRAY') {
2795: foreach my $name (@{$remparam{$idx}}) {
2796: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2797: }
2798: }
2799: }
1.533 raeburn 2800: if (values(%lockerrors) > 0) {
2801: $lockmsg = join('<br />',values(%lockerrors));
2802: }
1.491 raeburn 2803: my $storefn;
2804: if ($key eq $oldurl) {
2805: $storefn = $url;
2806: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2807: } else {
2808: $storefn = $key;
2809: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2810: if ($prefixchg && $before{'map'} && $after{'map'}) {
2811: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2812: }
1.529 raeburn 2813: if ($newsubdir{$key}) {
2814: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2815: }
1.491 raeburn 2816: }
1.492 raeburn 2817: my $report;
2818: if ($folder !~ /^supplemental/) {
2819: $report = 1;
2820: }
1.527 raeburn 2821: (my $outtext,$errtext) =
1.492 raeburn 2822: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2823: if ($errtext) {
1.529 raeburn 2824: if ($caller eq 'paste') {
1.533 raeburn 2825: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2826: }
1.491 raeburn 2827: }
2828: }
2829: }
1.533 raeburn 2830: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2831: }
2832:
2833: sub copy_dependencies {
2834: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2835: my $content;
2836: if (ref($contentref)) {
2837: $content = $$contentref;
2838: } else {
2839: $content = &Apache::lonnet::getfile($item);
2840: }
2841: unless ($content eq '-1') {
2842: my $mm = new File::MMagic;
2843: my $mimetype = $mm->checktype_contents($content);
2844: if ($mimetype eq 'text/html') {
2845: my (%allfiles,%codebase,$state);
2846: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2847: if ($res eq 'ok') {
2848: my ($numexisting,$numpathchanges,$existing);
2849: (undef,$numexisting,$numpathchanges,$existing) =
2850: &Apache::loncommon::ask_for_embedded_content(
2851: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2852: {'error_on_invalid_names' => 1,
2853: 'ignore_remote_references' => 1,
2854: 'docs_url' => $item,
2855: 'context' => 'paste'});
2856: if ($numexisting > 0) {
2857: if (ref($existing) eq 'HASH') {
2858: foreach my $dep (keys(%{$existing})) {
2859: my $depfile = $dep;
2860: unless ($depfile =~ m{^\Q$relpath\E}) {
2861: $depfile = $relpath.$dep;
2862: }
2863: my $depcontent = &Apache::lonnet::getfile($depfile);
2864: unless ($depcontent eq '-1') {
2865: my $storedep = $dep;
2866: $storedep =~ s{^\Q$relpath\E}{};
2867: my $dep_url =
2868: &Apache::lonclonecourse::writefile(
2869: $env{'request.course.id'},
2870: $storefn.$storedep,$depcontent);
2871: if ($dep_url eq '/adm/notfound.html') {
2872: if (ref($errors) eq 'HASH') {
2873: $errors->{$depfile} = 1;
2874: }
2875: } else {
2876: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2877: }
2878: }
2879: }
1.488 raeburn 2880: }
2881: }
2882: }
2883: }
2884: }
2885: return;
2886: }
2887:
1.329 droeschl 2888: my %parameter_type = ( 'randompick' => 'int_pos',
2889: 'hiddenresource' => 'string_yesno',
2890: 'encrypturl' => 'string_yesno',
2891: 'randomorder' => 'string_yesno',);
2892: my $valid_parameters_re = join('|',keys(%parameter_type));
2893: # set parameters
2894: sub update_parameter {
1.537 raeburn 2895: if ($env{'form.changeparms'} eq 'all') {
2896: my (@allidx,@allmapidx,%allchecked,%currchecked);
2897: %allchecked = (
2898: 'hiddenresource' => {},
2899: 'encrypturl' => {},
2900: 'randompick' => {},
2901: 'randomorder' => {},
2902: );
2903: foreach my $which (keys(%allchecked)) {
2904: $env{'form.all'.$which} =~ s/,$//;
2905: if ($which eq 'randompick') {
2906: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2907: my ($res,$value) = split(/:/,$item);
2908: if ($value =~ /^\d+$/) {
2909: $allchecked{$which}{$res} = $value;
2910: }
2911: }
2912: } else {
1.539 raeburn 2913: if ($env{'form.all'.$which}) {
2914: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2915: }
1.537 raeburn 2916: }
2917: }
2918: my $haschanges = 0;
2919: foreach my $res (@LONCAPA::map::order) {
2920: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2921: $name=&LONCAPA::map::qtescape($name);
2922: $url=&LONCAPA::map::qtescape($url);
2923: next unless ($name && $url);
2924: my $is_map;
2925: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2926: $is_map = 1;
2927: }
2928: foreach my $which (keys(%allchecked)) {
2929: if (($which eq 'randompick' || $which eq 'randomorder')) {
2930: next if (!$is_map);
2931: }
2932: my $oldvalue = 0;
2933: my $newvalue = 0;
2934: if ($allchecked{$which}{$res}) {
2935: $newvalue = $allchecked{$which}{$res};
2936: }
2937: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2938: if ($which eq 'randompick') {
2939: if ($current =~ /^(\d+)$/) {
2940: $oldvalue = $1;
2941: }
2942: } else {
2943: if ($current =~ /^yes$/i) {
2944: $oldvalue = 1;
2945: }
2946: }
2947: if ($oldvalue ne $newvalue) {
2948: $haschanges = 1;
2949: if ($newvalue) {
2950: my $storeval = 'yes';
2951: if ($which eq 'randompick') {
2952: $storeval = $newvalue;
2953: }
2954: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2955: $storeval,
2956: $parameter_type{$which});
2957: &remember_parms($res,$which,'set',$storeval);
2958: } elsif ($oldvalue) {
2959: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2960: &remember_parms($res,$which,'del');
2961: }
2962: }
2963: }
2964: }
2965: return $haschanges;
2966: } else {
1.588 raeburn 2967: my $haschanges = 0;
2968: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2969:
1.537 raeburn 2970: my $which = $env{'form.changeparms'};
2971: my $idx = $env{'form.setparms'};
1.588 raeburn 2972: my $oldvalue = 0;
2973: my $newvalue = 0;
2974: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2975: if ($which eq 'randompick') {
2976: if ($current =~ /^(\d+)$/) {
2977: $oldvalue = $1;
2978: }
2979: } elsif ($current =~ /^yes$/i) {
2980: $oldvalue = 1;
2981: }
1.537 raeburn 2982: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2983: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2984: : 1;
2985: }
2986: if ($oldvalue ne $newvalue) {
2987: $haschanges = 1;
2988: if ($newvalue) {
2989: my $storeval = 'yes';
2990: if ($which eq 'randompick') {
2991: $storeval = $newvalue;
2992: }
2993: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2994: $parameter_type{$which});
2995: &remember_parms($idx,$which,'set',$storeval);
2996: } else {
2997: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2998: &remember_parms($idx,$which,'del');
2999: }
1.537 raeburn 3000: }
1.588 raeburn 3001: return $haschanges;
1.329 droeschl 3002: }
3003: }
3004:
3005: sub handle_edit_cmd {
3006: my ($coursenum,$coursedom) =@_;
1.543 raeburn 3007: if ($env{'form.cmd'} eq '') {
3008: return 0;
3009: }
1.329 droeschl 3010: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3011:
3012: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3013: my ($title, $url, @rrest) = split(':', $ratstr);
3014:
1.538 raeburn 3015: if ($cmd eq 'remove') {
1.329 droeschl 3016: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3017: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3018: &Apache::lonnet::removeuploadedurl($url);
3019: } else {
3020: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3021: }
3022: splice(@LONCAPA::map::order, $idx, 1);
3023:
3024: } elsif ($cmd eq 'cut') {
3025: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3026: splice(@LONCAPA::map::order, $idx, 1);
3027:
1.344 bisitz 3028: } elsif ($cmd eq 'up'
1.329 droeschl 3029: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3030: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3031:
3032: } elsif ($cmd eq 'down'
3033: && defined($LONCAPA::map::order[$idx+1])) {
3034: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3035:
3036: } elsif ($cmd eq 'rename') {
3037: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3038: if ($comment=~/\S/) {
3039: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3040: $comment.':'.join(':', $url, @rrest);
3041: }
3042: # Devalidate title cache
3043: my $renamed_url=&LONCAPA::map::qtescape($url);
3044: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 3045:
1.329 droeschl 3046: } else {
3047: return 0;
3048: }
3049: return 1;
3050: }
3051:
3052: sub editor {
1.458 raeburn 3053: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3054: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3055: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3056: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3057: if ($allowed) {
1.519 raeburn 3058: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3059: $is_random_order,$container) =
1.510 raeburn 3060: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3061: $r->print($breadcrumbtrail);
1.519 raeburn 3062: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3063: $container = 'page';
3064: } else {
3065: $container = 'sequence';
1.510 raeburn 3066: }
1.484 raeburn 3067:
1.525 raeburn 3068: my $jumpto;
3069:
3070: unless ($supplementalflag) {
1.546 raeburn 3071: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3072: }
1.484 raeburn 3073:
3074: unless ($allowed) {
3075: $randompick = -1;
3076: }
3077:
1.615 raeburn 3078: my ($errtext,$fatal);
3079: if (($folder eq '') && (!$supplementalflag)) {
3080: if (@LONCAPA::map::order) {
3081: undef(@LONCAPA::map::order);
3082: undef(@LONCAPA::map::resources);
3083: undef(@LONCAPA::map::resparms);
3084: undef(@LONCAPA::map::zombies);
3085: }
3086: $folder = 'default';
3087: $container = 'sequence';
3088: } else {
3089: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3090: $folder.'.'.$container);
3091: return $errtext if ($fatal);
3092: }
1.329 droeschl 3093:
3094: if ($#LONCAPA::map::order<1) {
3095: my $idx=&LONCAPA::map::getresidx();
3096: if ($idx<=0) { $idx=1; }
3097: $LONCAPA::map::order[0]=$idx;
3098: $LONCAPA::map::resources[$idx]='';
3099: }
1.364 bisitz 3100:
1.329 droeschl 3101: # ------------------------------------------------------------ Process commands
3102:
3103: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3104: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3105: # set parameters and change order
3106: &snapshotbefore();
3107:
3108: if (&update_parameter()) {
1.588 raeburn 3109: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3110: return $errtext if ($fatal);
3111: }
3112:
3113: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3114: # change order
3115: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3116: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3117:
3118: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3119: return $errtext if ($fatal);
3120: }
1.364 bisitz 3121:
1.329 droeschl 3122: if ($env{'form.pastemarked'}) {
1.491 raeburn 3123: my %paste_errors;
1.533 raeburn 3124: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3125: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3126: \%paste_errors);
1.541 raeburn 3127: if (ref($pastemsgarray) eq 'ARRAY') {
3128: if (@{$pastemsgarray} > 0) {
3129: $r->print('<p class="LC_info">'.
3130: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3131: '</p>');
3132: }
1.541 raeburn 3133: }
3134: if ($lockerror) {
3135: $r->print('<p class="LC_error">'.
3136: $lockerror.
3137: '</p>');
3138: }
3139: if ($save_error ne '') {
3140: return $save_error;
3141: }
3142: if ($paste_res) {
3143: my %errortext = &Apache::lonlocal::texthash (
3144: fail => 'Storage of folder contents failed',
3145: failread => 'Reading folder contents failed',
3146: failstore => 'Storage of folder contents failed',
3147: );
3148: if ($errortext{$paste_res}) {
3149: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3150: }
1.329 droeschl 3151: }
1.491 raeburn 3152: if (keys(%paste_errors) > 0) {
1.538 raeburn 3153: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3154: &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".
3155: '<ul>'."\n");
3156: foreach my $key (sort(keys(%paste_errors))) {
3157: $r->print('<li>'.$key.'</li>'."\n");
3158: }
3159: $r->print('</ul></p>'."\n");
3160: }
1.538 raeburn 3161: } elsif ($env{'form.clearmarked'}) {
3162: my $output = &do_buffer_empty();
3163: if ($output) {
3164: $r->print('<p class="LC_info">'.$output.'</p>');
3165: }
3166: }
1.329 droeschl 3167:
3168: $r->print($upload_output);
3169:
1.538 raeburn 3170: # Rename, cut, copy or remove a single resource
1.602 raeburn 3171: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3172: my $contentchg;
1.592 raeburn 3173: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 3174: $contentchg = 1;
3175: }
3176: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3177: return $errtext if ($fatal);
3178: }
1.538 raeburn 3179:
3180: # Cut, copy and/or remove multiple resources
3181: if ($env{'form.multichange'}) {
3182: my %allchecked = (
3183: cut => {},
3184: remove => {},
3185: );
3186: my $needsupdate;
3187: foreach my $which (keys(%allchecked)) {
3188: $env{'form.multi'.$which} =~ s/,$//;
3189: if ($env{'form.multi'.$which}) {
3190: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3191: if (ref($allchecked{$which}) eq 'HASH') {
3192: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3193: }
3194: }
3195: }
3196: if ($needsupdate) {
3197: my $haschanges = 0;
3198: my %curr_groups = &Apache::longroup::coursegroups();
3199: my $total = scalar(@LONCAPA::map::order) - 1;
3200: for (my $i=$total; $i>=0; $i--) {
3201: my $res = $LONCAPA::map::order[$i];
3202: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3203: $name=&LONCAPA::map::qtescape($name);
3204: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3205: next unless $url;
1.538 raeburn 3206: my %denied =
3207: &action_restrictions($coursenum,$coursedom,$url,
3208: $env{'form.folderpath'},\%curr_groups);
3209: foreach my $which (keys(%allchecked)) {
3210: next if ($denied{$which});
3211: next unless ($allchecked{$which}{$res});
3212: if ($which eq 'remove') {
3213: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3214: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3215: &Apache::lonnet::removeuploadedurl($url);
3216: } else {
3217: &LONCAPA::map::makezombie($res);
3218: }
3219: splice(@LONCAPA::map::order,$i,1);
3220: $haschanges ++;
3221: } elsif ($which eq 'cut') {
3222: &LONCAPA::map::makezombie($res);
3223: splice(@LONCAPA::map::order,$i,1);
3224: $haschanges ++;
3225: }
3226: }
3227: }
3228: if ($haschanges) {
3229: ($errtext,$fatal) =
3230: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3231: return $errtext if ($fatal);
3232: }
3233: }
3234: }
3235:
1.329 droeschl 3236: # Group import/search
3237: if ($env{'form.importdetail'}) {
3238: my @imports;
3239: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3240: if (defined($item)) {
3241: my ($name,$url,$residx)=
1.533 raeburn 3242: map { &unescape($_); } split(/\=/,$item);
3243: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3244: my ($suffix,$errortxt,$locknotfreed) =
3245: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3246: if ($locknotfreed) {
3247: $r->print($locknotfreed);
3248: }
3249: if ($suffix) {
3250: $url =~ s/_new\./_$suffix./;
3251: } else {
3252: return $errortxt;
3253: }
1.533 raeburn 3254: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3255: my $type = $1;
3256: my ($suffix,$errortxt,$locknotfreed) =
3257: &new_timebased_suffix($coursedom,$coursenum,$type);
3258: if ($locknotfreed) {
3259: $r->print($locknotfreed);
3260: }
3261: if ($suffix) {
3262: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3263: } else {
3264: return $errortxt;
3265: }
1.626 raeburn 3266: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3267: my ($suffix,$errortxt,$locknotfreed) =
3268: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3269: if ($locknotfreed) {
3270: $r->print($locknotfreed);
3271: }
3272: if ($suffix) {
3273: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3274: } else {
3275: return $errortxt;
3276: }
1.534 raeburn 3277: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3278: if ($supplementalflag) {
3279: next unless ($1 eq 'supplemental');
3280: if ($folder eq 'supplemental') {
3281: next unless ($2 eq 'default');
3282: } else {
3283: next unless ($folder eq 'supplemental_'.$2);
3284: }
3285: } else {
3286: next unless ($1 eq 'docs');
3287: if ($folder eq 'default') {
3288: next unless ($2 eq 'default');
3289: } else {
3290: next unless ($folder eq 'default_'.$2);
3291: }
3292: }
1.504 raeburn 3293: }
1.329 droeschl 3294: push(@imports, [$name, $url, $residx]);
3295: }
3296: }
1.530 raeburn 3297: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3298: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3299: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3300: return $errtext if ($fatal);
1.529 raeburn 3301: if ($fixuperrors) {
3302: $r->print($fixuperrors);
3303: }
1.329 droeschl 3304: }
3305: # Loading a complete map
3306: if ($env{'form.loadmap'}) {
3307: if ($env{'form.importmap'}=~/\w/) {
3308: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3309: my ($title,$url,$ext,$type)=split(/\:/,$res);
3310: my $idx=&LONCAPA::map::getresidx($url);
3311: $LONCAPA::map::resources[$idx]=$res;
3312: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3313: }
3314: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3315: $folder.'.'.$container,1);
1.329 droeschl 3316: return $errtext if ($fatal);
3317: } else {
3318: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3319:
1.329 droeschl 3320: }
3321: }
3322: &log_differences($plain);
3323: }
3324: # ---------------------------------------------------------------- End commands
3325: # ---------------------------------------------------------------- Print screen
3326: my $idx=0;
3327: my $shown=0;
3328: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3329: $r->print('<div class="LC_Box">'.
1.432 raeburn 3330: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3331: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3332: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3333: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3334: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3335: '</ol>');
1.381 bisitz 3336: if ($randompick>=0) {
3337: $r->print('<p class="LC_warning">'
3338: .&mt('Caution: this folder is set to randomly pick a subset'
3339: .' of resources. Adding or removing resources from this'
3340: .' folder will change the set of resources that the'
3341: .' students see, resulting in spurious or missing credit'
3342: .' for completed problems, not limited to ones you'
3343: .' modify. Do not modify the contents of this folder if'
3344: .' it is in active student use.')
3345: .'</p>'
3346: );
3347: }
3348: if ($is_random_order) {
3349: $r->print('<p class="LC_warning">'
3350: .&mt('Caution: this folder is set to randomly order its'
3351: .' contents. Adding or removing resources from this folder'
3352: .' will change the order of resources shown.')
3353: .'</p>'
3354: );
3355: }
3356: $r->print('</div>');
1.364 bisitz 3357: }
1.381 bisitz 3358:
1.538 raeburn 3359: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3360: %filters = (
1.543 raeburn 3361: canremove => [],
3362: cancut => [],
3363: cancopy => [],
3364: hiddenresource => [],
3365: encrypturl => [],
3366: randomorder => [],
3367: randompick => [],
1.538 raeburn 3368: );
3369: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3370: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3371: foreach my $res (@LONCAPA::map::order) {
3372: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3373: $name=&LONCAPA::map::qtescape($name);
3374: $url=&LONCAPA::map::qtescape($url);
3375: unless ($name) { $name=(split(/\//,$url))[-1]; }
3376: unless ($name) { $idx++; next; }
1.537 raeburn 3377: push(@allidx,$res);
3378: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3379: push(@allmapidx,$res);
3380: }
1.617 raeburn 3381:
1.381 bisitz 3382: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3383: $coursenum,$coursedom,$crstype,
1.538 raeburn 3384: $pathitem,$supplementalflag,$container,
1.620 raeburn 3385: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3386: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3387: $idx++;
3388: $shown++;
1.329 droeschl 3389: }
1.424 onken 3390: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3391:
1.538 raeburn 3392: my $need_save;
1.611 raeburn 3393: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3394: my $toolslink;
1.611 raeburn 3395: if ($allowed) {
1.544 raeburn 3396: $toolslink = '<table><tr><td>'
1.520 raeburn 3397: .&Apache::loncommon::help_open_menu('Navigation Screen',
3398: 'Navigation_Screen',undef,'RAT')
3399: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3400: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3401: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3402: .'id="LC_content_toolbar_edittoplevel" '
3403: .'class="LC_toolbarItem" '
3404: .'title="'.&mt('Supplemental Content Editor').'">'
3405: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3406: }
1.510 raeburn 3407: if ($shown) {
3408: if ($allowed) {
3409: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3410: .&Apache::loncommon::start_data_table(undef,'contentlist')
3411: .&Apache::loncommon::start_data_table_header_row()
3412: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3413: .'<th colspan="2">'.&mt('Actions').'</th>'
3414: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3415: if ($folder !~ /^supplemental/) {
3416: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3417: }
1.537 raeburn 3418: $to_show .= &Apache::loncommon::end_data_table_header_row();
3419: if ($folder !~ /^supplemental/) {
1.538 raeburn 3420: $lists{'canhide'} = join(',',@allidx);
3421: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3422: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3423: 'randomorder','randompick');
3424: foreach my $item (@possfilters) {
1.538 raeburn 3425: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3426: if (@{$filters{$item}} > 0) {
3427: $lists{$item} = join(',',@{$filters{$item}});
3428: }
1.538 raeburn 3429: }
3430: }
1.537 raeburn 3431: if (@allidx > 0) {
3432: my $path;
3433: if ($env{'form.folderpath'}) {
3434: $path =
3435: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3436: }
1.538 raeburn 3437: if (@allidx > 1) {
3438: $to_show .=
3439: &Apache::loncommon::continue_data_table_row().
3440: '<td colspan="2"> </td>'.
3441: '<td>'.
1.611 raeburn 3442: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3443: '</td>'.
3444: '<td> </td>'.
3445: '<td> </td>'.
3446: '<td colspan="4">'.
1.611 raeburn 3447: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3448: '</td>'.
3449: &Apache::loncommon::end_data_table_row();
3450: $need_save = 1;
3451: }
1.537 raeburn 3452: }
3453: }
3454: $to_show .= $output.' '
1.510 raeburn 3455: .&Apache::loncommon::end_data_table()
3456: .'<br style="line-height:2px;" />'
3457: .&Apache::loncommon::end_scrollbox();
3458: } else {
1.520 raeburn 3459: $to_show .= $toolslink
1.510 raeburn 3460: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3461: .$output.' '
3462: .&Apache::loncommon::end_data_table();
1.393 raeburn 3463: }
1.510 raeburn 3464: } else {
1.520 raeburn 3465: if (!$allowed) {
3466: $to_show .= $toolslink;
3467: }
1.615 raeburn 3468: my $noresmsg;
3469: if ($allowed && $hiddentop && !$supplementalflag) {
3470: $noresmsg = &mt('Main Content Hidden');
3471: } else {
3472: $noresmsg = &mt('Currently empty');
3473: }
1.510 raeburn 3474: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3475: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3476: .$noresmsg
1.510 raeburn 3477: .'</div>'
3478: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3479: }
3480: } else {
1.510 raeburn 3481: if ($shown) {
3482: $to_show = '<div>'
3483: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3484: .$output
3485: .&Apache::loncommon::end_data_table()
3486: .'</div>';
3487: } else {
3488: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3489: .&mt('Currently empty')
1.510 raeburn 3490: .'</div>'
3491: }
1.458 raeburn 3492: }
3493: my $tid = 1;
3494: if ($supplementalflag) {
3495: $tid = 2;
1.329 droeschl 3496: }
3497: if ($allowed) {
1.484 raeburn 3498: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3499: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3500: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3501: if ($canedit) {
3502: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3503: }
1.460 raeburn 3504: } else {
3505: $r->print($to_show);
1.329 droeschl 3506: }
3507: return;
3508: }
3509:
1.538 raeburn 3510: sub multiple_check_form {
1.611 raeburn 3511: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3512: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3513: my $disabled;
3514: unless ($canedit) {
3515: $disabled = 'disabled="disabled"';
3516: }
1.538 raeburn 3517: my $output =
3518: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3519: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3520: '<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>'.
3521: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3522: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3523: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3524: if ($caller eq 'settings') {
3525: $output .=
3526: '<table><tr>'.
3527: '<td class="LC_docs_entry_parameter">'.
3528: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3529: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3530: '</label></span></td>'.
3531: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3532: '<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'".');"'.$disabled.' />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
1.538 raeburn 3533: '</span></td>'.
3534: '</tr>'."\n".
3535: '<tr>'.
3536: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3537: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')"'.$disabled.' />'.&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'".')"'.$disabled.' />'.&mt('Random Order').
1.538 raeburn 3538: '</label></span>'.
3539: '</td></tr></table>'."\n";
3540: } else {
3541: $output .=
3542: '<table><tr>'.
3543: '<td class="LC_docs_entry_parameter">'.
3544: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3545: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3546: '</label></span></td>'.
3547: '<td class="LC_docs_entry_parameter">'.
3548: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3549: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3550: '</label></span></td>'."\n".
3551: '<td class="LC_docs_entry_parameter">'.
3552: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3553: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3554: '</label></span></td>'.
3555: '</tr></table>'."\n";
3556: }
3557: $output .=
3558: '</fieldset>'.
3559: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3560: if ($caller eq 'settings') {
3561: $output .=
1.543 raeburn 3562: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3563: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3564: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3565: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3566: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3567: } elsif ($caller eq 'actions') {
3568: $output .=
3569: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3570: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3571: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3572: }
3573: $output .=
3574: '</form>'.
3575: '</div>';
3576: return $output;
3577: }
3578:
1.329 droeschl 3579: sub process_file_upload {
1.552 raeburn 3580: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3581: # upload a file, if present
1.552 raeburn 3582: my $filesize = length($env{'form.uploaddoc'});
3583: if (!$filesize) {
3584: $$upload_output = '<div class="LC_error">'.
3585: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3586: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3587: $filesize).'<br />'.
3588: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3589: '</div>';
3590: return;
3591: }
3592: my $quotatype = 'unofficial';
3593: if ($crstype eq 'Community') {
1.601 raeburn 3594: $quotatype = 'community';
3595: } elsif ($crstype eq 'Placement') {
3596: $quotatype = 'placement';
1.580 raeburn 3597: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3598: $quotatype = 'official';
1.573 raeburn 3599: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3600: $quotatype = 'textbook';
1.552 raeburn 3601: }
3602: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3603: $filesize = int($filesize/1000); #expressed in kb
3604: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3605: $env{'form.uploaddoc.filename'},$filesize,
3606: 'upload',$quotatype);
1.552 raeburn 3607: return if ($$upload_output);
3608: }
1.440 raeburn 3609: my ($parseaction,$showupload,$nextphase,$mimetype);
3610: if ($env{'form.parserflag'}) {
1.329 droeschl 3611: $parseaction = 'parse';
3612: }
3613: my $folder=$env{'form.folder'};
3614: if ($folder eq '') {
3615: $folder='default';
3616: }
3617: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3618: my $errtext='';
3619: my $fatal=0;
3620: my $container='sequence';
1.519 raeburn 3621: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3622: $container='page';
3623: }
3624: ($errtext,$fatal)=
1.534 raeburn 3625: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3626: if ($#LONCAPA::map::order<1) {
3627: $LONCAPA::map::order[0]=1;
3628: $LONCAPA::map::resources[1]='';
3629: }
3630: my $destination = 'docs/';
3631: if ($folder =~ /^supplemental/) {
3632: $destination = 'supplemental/';
3633: }
3634: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3635: $destination .= 'default/';
3636: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3637: $destination .= $2.'/';
3638: }
1.534 raeburn 3639: if ($fatal) {
3640: $$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>';
3641: return;
3642: }
1.440 raeburn 3643: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3644: my $newidx=&LONCAPA::map::getresidx();
3645: $destination .= $newidx;
1.439 raeburn 3646: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3647: $parseaction,$allfiles,
1.440 raeburn 3648: $codebase,undef,undef,undef,undef,
3649: undef,undef,\$mimetype);
3650: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3651: my $stored = $1;
3652: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3653: $stored.'</span>').'</p>';
3654: } else {
3655: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3656:
1.457 raeburn 3657: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3658: return;
3659: }
1.329 droeschl 3660: my $ext='false';
3661: if ($url=~m{^http://}) { $ext='true'; }
3662: $url = &LONCAPA::map::qtunescape($url);
3663: my $comment=$env{'form.comment'};
3664: $comment = &LONCAPA::map::qtunescape($comment);
3665: if ($folder=~/^supplemental/) {
3666: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3667: $env{'user.domain'}.'___&&&___'.$comment;
3668: }
3669:
3670: $LONCAPA::map::resources[$newidx]=
3671: $comment.':'.$url.':'.$ext.':normal:res';
3672: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3673: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3674: $folder.'.'.$container,1);
1.329 droeschl 3675: if ($fatal) {
1.457 raeburn 3676: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3677: return;
1.329 droeschl 3678: } else {
1.440 raeburn 3679: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3680: $$upload_output = $showupload;
1.384 raeburn 3681: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3682: if ($total_embedded > 0) {
1.440 raeburn 3683: my $uploadphase = 'upload_embedded';
3684: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3685: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3686: my ($embedded,$num) =
3687: &Apache::loncommon::ask_for_embedded_content(
3688: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3689: if ($embedded) {
3690: if ($num) {
3691: $$upload_output .=
3692: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3693: $nextphase = $uploadphase;
3694: } else {
3695: $$upload_output .= $embedded;
3696: }
3697: } else {
3698: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3699: }
1.329 droeschl 3700: } else {
1.440 raeburn 3701: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3702: }
1.457 raeburn 3703: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3704: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3705: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3706: $nextphase = 'decompress_uploaded';
3707: my $position = scalar(@LONCAPA::map::order)-1;
3708: my $noextract = &return_to_editor();
3709: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3710: my %archiveitems = (
3711: folderpath => $env{'form.folderpath'},
3712: cmd => $nextphase,
3713: newidx => $newidx,
3714: position => $position,
3715: phase => $nextphase,
1.477 raeburn 3716: comment => $comment,
1.480 raeburn 3717: );
3718: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3719: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3720: $$upload_output = $showupload.
3721: &Apache::loncommon::decompress_form($mimetype,
3722: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3723: \%archiveitems,\@current);
1.329 droeschl 3724: }
3725: }
3726: }
1.440 raeburn 3727: return $nextphase;
1.329 droeschl 3728: }
3729:
1.480 raeburn 3730: sub get_dir_list {
3731: my ($url,$coursenum,$coursedom,$newidx) = @_;
3732: my ($destination,$dir_root) = &embedded_destination();
3733: my ($dirlistref,$listerror) =
3734: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3735: my @dir_lines;
3736: my $dirptr=16384;
3737: if (ref($dirlistref) eq 'ARRAY') {
3738: foreach my $dir_line (sort
3739: {
3740: my ($afile)=split('&',$a,2);
3741: my ($bfile)=split('&',$b,2);
3742: return (lc($afile) cmp lc($bfile));
3743: } (@{$dirlistref})) {
3744: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3745: $filename =~ s/\s+$//;
3746: next if ($filename =~ /^\.\.?$/);
3747: my $isdir = 0;
3748: if ($dirptr&$testdir) {
3749: $isdir = 1;
3750: }
3751: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3752: }
3753: }
3754: return @dir_lines;
3755: }
3756:
1.329 droeschl 3757: sub is_supplemental_title {
3758: my ($title) = @_;
3759: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3760: }
3761:
3762: # --------------------------------------------------------------- An entry line
3763:
3764: sub entryline {
1.501 raeburn 3765: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3766: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3767: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3768: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3769: if (&is_supplemental_title($title)) {
1.488 raeburn 3770: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3771: } else {
3772: $title=&HTML::Entities::encode($title,'"<>&\'');
3773: $renametitle=$title;
3774: $foldertitle=$title;
3775: }
3776:
1.611 raeburn 3777: my ($disabled,$readonly,$js_lt);
3778: unless ($canedit) {
3779: $disabled = 'disabled="disabled"';
3780: $readonly = 1;
3781: }
3782:
1.329 droeschl 3783: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3784:
1.329 droeschl 3785: $renametitle=~s/\\/\\\\/g;
3786: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3787: $renametitle=~s/"/%22/g;
1.581 raeburn 3788: $renametitle=~s/ /%20/g;
3789: $oldtitle = $renametitle;
1.576 raeburn 3790: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3791: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3792: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3793: # Edit commands
1.535 raeburn 3794: my ($esc_path, $path, $symb);
1.329 droeschl 3795: if ($env{'form.folderpath'}) {
3796: $esc_path=&escape($env{'form.folderpath'});
3797: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3798: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3799: }
1.505 raeburn 3800: my $isexternal;
1.510 raeburn 3801: if ($residx) {
1.501 raeburn 3802: my $currurl = $url;
3803: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3804: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3805: $isexternal = 1;
3806: }
1.510 raeburn 3807: if (!$supplementalflag) {
3808: my $path = 'uploaded/'.
3809: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3810: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3811: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3812: $residx,
3813: &Apache::lonnet::declutter($currurl));
3814: }
1.501 raeburn 3815: }
1.538 raeburn 3816: my ($renamelink,%lt,$ishash);
3817: if (ref($filtersref) eq 'HASH') {
3818: $ishash = 1;
3819: }
3820:
1.329 droeschl 3821: if ($allowed) {
1.538 raeburn 3822: $form_start = '
3823: <form action="/adm/coursedocs" method="post">
3824: ';
3825: $form_common=(<<END);
3826: <input type="hidden" name="folderpath" value="$path" />
3827: <input type="hidden" name="symb" value="$symb" />
3828: END
3829: $form_param=(<<END);
3830: <input type="hidden" name="setparms" value="$orderidx" />
3831: <input type="hidden" name="changeparms" value="0" />
3832: END
3833: $form_end = '</form>';
3834:
1.329 droeschl 3835: my $incindex=$index+1;
3836: my $selectbox='';
1.471 raeburn 3837: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3838: ((split(/\:/,
1.344 bisitz 3839: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3840: ne '') &&
1.329 droeschl 3841: ((split(/\:/,
1.344 bisitz 3842: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3843: ne '')) {
3844: $selectbox=
3845: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3846: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3847: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3848: if ($i==$incindex) {
1.358 bisitz 3849: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3850: } else {
3851: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3852: }
3853: }
3854: $selectbox.='</select>';
3855: }
1.501 raeburn 3856: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3857: 'up' => 'Move Up',
3858: 'dw' => 'Move Down',
3859: 'rm' => 'Remove',
3860: 'ct' => 'Cut',
3861: 'rn' => 'Rename',
1.501 raeburn 3862: 'cp' => 'Copy',
3863: 'ex' => 'External Resource',
1.598 raeburn 3864: 'et' => 'External Tool',
1.501 raeburn 3865: 'ed' => 'Edit',
3866: 'pr' => 'Preview',
3867: 'sv' => 'Save',
3868: 'ul' => 'URL',
1.611 raeburn 3869: 'ti' => 'Title',
1.618 raeburn 3870: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3871: );
1.538 raeburn 3872: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3873: $env{'form.folderpath'},
3874: $currgroups);
1.517 raeburn 3875: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3876: my $skip_confirm = 0;
1.603 raeburn 3877: my $confirm_removal = 0;
1.329 droeschl 3878: if ( $folder =~ /^supplemental/
3879: || ($url =~ m{( /smppg$
3880: |/syllabus$
3881: |/aboutme$
3882: |/navmaps$
3883: |/bulletinboard$
1.626 raeburn 3884: |/ext\.tool$
1.505 raeburn 3885: |\.html$)}x)
3886: || $isexternal) {
1.329 droeschl 3887: $skip_confirm = 1;
3888: }
1.603 raeburn 3889: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3890: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3891: $confirm_removal = 1;
3892: }
1.329 droeschl 3893:
1.538 raeburn 3894: if ($denied{'copy'}) {
1.543 raeburn 3895: $copylink=(<<ENDCOPY)
1.507 raeburn 3896: <span style="visibility: hidden;">$lt{'cp'}</span>
3897: ENDCOPY
3898: } else {
1.538 raeburn 3899: my $formname = 'edit_copy_'.$orderidx;
3900: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3901: $copylink=(<<ENDCOPY);
1.538 raeburn 3902: <form name="$formname" method="post" action="/adm/coursedocs">
3903: $form_common
1.611 raeburn 3904: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.538 raeburn 3905: $form_end
1.329 droeschl 3906: ENDCOPY
1.538 raeburn 3907: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3908: push(@{$filtersref->{'cancopy'}},$orderidx);
3909: }
1.329 droeschl 3910: }
1.538 raeburn 3911: if ($denied{'cut'}) {
1.507 raeburn 3912: $cutlink=(<<ENDCUT);
3913: <span style="visibility: hidden;">$lt{'ct'}</span>
3914: ENDCUT
3915: } else {
1.538 raeburn 3916: my $formname = 'edit_cut_'.$orderidx;
3917: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3918: $cutlink=(<<ENDCUT);
1.538 raeburn 3919: <form name="$formname" method="post" action="/adm/coursedocs">
3920: $form_common
1.542 raeburn 3921: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3922: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.538 raeburn 3923: $form_end
1.329 droeschl 3924: ENDCUT
1.538 raeburn 3925: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3926: push(@{$filtersref->{'cancut'}},$orderidx);
3927: }
1.329 droeschl 3928: }
1.538 raeburn 3929: if ($denied{'remove'}) {
1.507 raeburn 3930: $removelink=(<<ENDREM);
3931: <span style="visibility: hidden;">$lt{'rm'}</a>
3932: ENDREM
3933: } else {
1.538 raeburn 3934: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3935: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3936: $removelink=(<<ENDREM);
1.538 raeburn 3937: <form name="$formname" method="post" action="/adm/coursedocs">
3938: $form_common
1.542 raeburn 3939: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3940: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 3941: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.538 raeburn 3942: $form_end
1.497 raeburn 3943: ENDREM
1.538 raeburn 3944: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3945: push(@{$filtersref->{'canremove'}},$orderidx);
3946: }
1.497 raeburn 3947: }
1.551 raeburn 3948: $renamelink=(<<ENDREN);
1.581 raeburn 3949: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3950: ENDREN
1.611 raeburn 3951: my ($uplink,$downlink);
3952: if ($canedit) {
3953: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3954: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3955: } else {
3956: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3957: $downlink = $uplink;
3958: }
1.329 droeschl 3959: $line.=(<<END);
3960: <td>
1.379 bisitz 3961: <div class="LC_docs_entry_move">
1.611 raeburn 3962: <a href="$uplink">
1.501 raeburn 3963: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3964: </a>
3965: </div>
3966: <div class="LC_docs_entry_move">
1.611 raeburn 3967: <a href="$downlink">
1.501 raeburn 3968: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3969: </a>
3970: </div>
1.329 droeschl 3971: </td>
3972: <td>
3973: $form_start
1.538 raeburn 3974: $form_param
1.478 raeburn 3975: $form_common
1.329 droeschl 3976: $selectbox
3977: $form_end
3978: </td>
1.540 raeburn 3979: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3980: $removelink
1.329 droeschl 3981: $cutlink
3982: $copylink
3983: </td>
3984: END
3985: }
3986: # Figure out what kind of a resource this is
3987: my ($extension)=($url=~/\.(\w+)$/);
3988: my $uploaded=($url=~/^\/*uploaded\//);
3989: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3990: my $isfolder;
3991: my $ispage;
3992: my $containerarg;
1.615 raeburn 3993: my $folderurl;
1.329 droeschl 3994: if ($uploaded) {
1.472 raeburn 3995: if (($extension eq 'sequence') || ($extension eq 'page')) {
3996: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3997: $containerarg = $1;
1.472 raeburn 3998: if ($extension eq 'sequence') {
3999: $icon=$iconpath.'navmap.folder.closed.gif';
4000: $isfolder=1;
4001: } else {
4002: $icon=$iconpath.'page.gif';
4003: $ispage=1;
4004: }
1.615 raeburn 4005: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4006: if ($allowed) {
4007: $url='/adm/coursedocs?';
4008: } else {
4009: $url='/adm/supplemental?';
4010: }
1.329 droeschl 4011: } else {
4012: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4013: }
4014: }
1.364 bisitz 4015:
1.621 raeburn 4016: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4017: my $orig_url = $url;
1.340 raeburn 4018: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 4019: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 4020: if (!$supplementalflag && $residx && $symb) {
4021: if ((!$isfolder) && (!$ispage)) {
4022: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4023: $url=&Apache::lonnet::clutter($url);
4024: if ($url=~/^\/*uploaded\//) {
4025: $url=~/\.(\w+)$/;
4026: my $embstyle=&Apache::loncommon::fileembstyle($1);
4027: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4028: $url='/adm/wrapper'.$url;
4029: } elsif ($embstyle eq 'ssi') {
4030: #do nothing with these
4031: } elsif ($url!~/\.(sequence|page)$/) {
4032: $url='/adm/coursedocs/showdoc'.$url;
4033: }
1.623 raeburn 4034: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4035: my $wrapped = $1;
4036: my $exturl = $2;
4037: if ($wrapped eq '') {
4038: $url='/adm/wrapper'.$url;
4039: }
4040: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4041: $nomodal = 1;
4042: }
1.626 raeburn 4043: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4044: $url='/adm/wrapper'.$url;
1.621 raeburn 4045: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4046: if (($ENV{'SERVER_PORT'} == 443) &&
4047: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4048: $url .= '?usehttp=1';
4049: $nomodal = 1;
4050: }
1.598 raeburn 4051: }
1.501 raeburn 4052: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4053: my $shownsymb = $symb;
4054: if ($isexternal) {
4055: if ($url =~ /^([^#]+)#([^#]+)$/) {
4056: $url = $1;
4057: $anchor = $2;
4058: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4059: $shownsymb = $1.&escape('#').$anchor;
4060: }
4061: }
4062: }
1.617 raeburn 4063: unless ($env{'request.role.adv'}) {
4064: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4065: $url = '';
4066: }
4067: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4068: $url = '';
4069: $hiddenres = 1;
4070: }
4071: }
4072: if ($url ne '') {
4073: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4074: }
1.615 raeburn 4075: } elsif (!$env{'request.role.adv'}) {
4076: my $checkencrypt;
4077: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4078: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4079: $checkencrypt = 1;
1.620 raeburn 4080: } elsif (ref($navmapref)) {
1.615 raeburn 4081: unless (ref($$navmapref)) {
4082: $$navmapref = Apache::lonnavmaps::navmap->new();
4083: }
4084: if (ref($$navmapref)) {
4085: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4086: $checkencrypt = 1;
4087: }
4088: }
4089: }
4090: if ($checkencrypt) {
4091: my $shownsymb = &Apache::lonenc::encrypted($symb);
4092: my $shownurl = &Apache::lonenc::encrypted($url);
4093: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4094: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4095: if ($env{'request.enc'} ne '') {
4096: delete($env{'request.enc'});
4097: }
4098: } else {
4099: $url='';
1.613 raeburn 4100: }
1.612 raeburn 4101: } else {
4102: $url='';
4103: }
1.501 raeburn 4104: } else {
4105: $url='';
4106: }
1.329 droeschl 4107: }
1.621 raeburn 4108: } elsif ($supplementalflag) {
1.610 raeburn 4109: if ($isexternal) {
4110: if ($url =~ /^([^#]+)#([^#]+)$/) {
4111: $url = $1;
4112: $anchor = $2;
1.623 raeburn 4113: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4114: if ($hostname ne '') {
4115: $url = 'http://'.$hostname.$url;
4116: }
4117: $nomodal = 1;
4118: }
1.610 raeburn 4119: }
1.621 raeburn 4120: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4121: if (($ENV{'SERVER_PORT'} == 443) &&
4122: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.622 raeburn 4123: if ($hostname ne '') {
4124: $url = 'http://'.$hostname.$url;
4125: }
1.621 raeburn 4126: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4127: $nomodal = 1;
4128: }
1.610 raeburn 4129: }
1.329 droeschl 4130: }
1.615 raeburn 4131: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4132: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4133: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4134: my $foldername=&escape($foldertitle);
4135: my $folderpath=$env{'form.folderpath'};
4136: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4137: if (!$allowed && $supplementalflag) {
1.519 raeburn 4138: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4139: $url.='folderpath='.&escape($folderpath);
4140: } else {
1.617 raeburn 4141: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4142: 'parameter_randompick'))[0];
4143: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4144: 'parameter_randomorder'))[0]=~/^yes$/i);
4145: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4146: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4147: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4148: 'parameter_encrypturl'))[0]=~/^yes$/i);
4149: unless ($hiddenmap) {
1.620 raeburn 4150: if (ref($navmapref)) {
4151: unless (ref($$navmapref)) {
4152: $$navmapref = Apache::lonnavmaps::navmap->new();
4153: }
4154: if (ref($$navmapref)) {
4155: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4156: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4157: unless (@resources) {
4158: $hiddenmap = 1;
4159: unless ($env{'request.role.adv'}) {
4160: $url = '';
4161: $hiddenfolder = 1;
4162: }
1.617 raeburn 4163: }
1.615 raeburn 4164: }
4165: }
4166: }
4167: }
1.617 raeburn 4168: unless ($encryptmap) {
1.620 raeburn 4169: if ((ref($navmapref)) && (ref($$navmapref))) {
4170: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4171: $encryptmap = 1;
4172: }
1.617 raeburn 4173: }
4174: }
4175:
4176: # Append randompick number, hidden, and encrypted with ":" to foldername,
4177: # so it gets transferred between levels
4178: $folderpath.=$containerarg.'&'.$foldername.
4179: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4180: unless ($url eq '') {
1.612 raeburn 4181: $url.='folderpath='.&escape($folderpath);
4182: }
1.510 raeburn 4183: my $rpckchk;
4184: if ($rpicknum) {
4185: $rpckchk = ' checked="checked"';
1.543 raeburn 4186: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4187: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4188: }
1.510 raeburn 4189: }
1.537 raeburn 4190: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4191: $rand_pick_text =
1.478 raeburn 4192: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4193: $form_param."\n".
1.478 raeburn 4194: $form_common."\n".
1.611 raeburn 4195: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.$disabled.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
1.510 raeburn 4196: if ($rpicknum ne '') {
4197: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4198: }
1.537 raeburn 4199: $rand_pick_text .= '</span></span>'.
4200: $form_end;
1.543 raeburn 4201: my $ro_set;
1.617 raeburn 4202: if ($randorder) {
1.543 raeburn 4203: $ro_set = 'checked="checked"';
4204: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4205: push(@{$filtersref->{'randomorder'}},$orderidx);
4206: }
4207: }
1.564 raeburn 4208: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4209: $rand_order_text =
1.537 raeburn 4210: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4211: $form_param."\n".
1.537 raeburn 4212: $form_common."\n".
1.611 raeburn 4213: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.$disabled.' /> '.&mt('Random Order').' </label></span>'.
1.537 raeburn 4214: $form_end;
1.510 raeburn 4215: }
1.509 raeburn 4216: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4217: my $isexttool;
1.626 raeburn 4218: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4219: $url='/adm/wrapper'.$url;
4220: $isexttool = 1;
4221: }
1.510 raeburn 4222: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4223: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4224: if ($title) {
4225: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4226: }
1.598 raeburn 4227: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4228: $url .= '&idx='.$orderidx;
4229: }
1.610 raeburn 4230: if ($anchor ne '') {
4231: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4232: }
1.329 droeschl 4233: }
1.519 raeburn 4234: my ($tdalign,$tdwidth);
1.501 raeburn 4235: if ($allowed) {
4236: my $fileloc =
4237: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4238: if ($isexternal) {
1.518 raeburn 4239: ($editlink,$extresform) =
1.611 raeburn 4240: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4241: undef,undef,undef,undef,undef,undef,
4242: undef,$disabled);
1.626 raeburn 4243: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4244: ($editlink,$extresform) =
4245: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4246: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4247: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4248: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4249: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4250: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4251: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4252: my $suppanchor;
4253: if ($supplementalflag) {
4254: $suppanchor = $anchor;
4255: }
1.501 raeburn 4256: my $jscall =
4257: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4258: $switchserver,
1.503 raeburn 4259: $forceedit,
1.511 raeburn 4260: undef,$symb,
4261: &escape($env{'form.folderpath'}),
1.622 raeburn 4262: $renametitle,$hostname,
4263: '','',1,$suppanchor);
1.501 raeburn 4264: if ($jscall) {
1.518 raeburn 4265: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4266: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4267: }
4268: }
4269: }
1.519 raeburn 4270: $tdalign = ' align="right" valign="top"';
4271: $tdwidth = ' width="80%"';
1.329 droeschl 4272: }
1.408 raeburn 4273: my $reinit;
4274: if ($crstype eq 'Community') {
4275: $reinit = &mt('(re-initialize community to access)');
4276: } else {
4277: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4278: }
4279: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.621 raeburn 4280: my $link;
1.472 raeburn 4281: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4282: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4283: } elsif ($url) {
1.610 raeburn 4284: if ($anchor ne '') {
4285: if ($supplementalflag) {
4286: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4287: } else {
4288: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4289: }
4290: }
1.622 raeburn 4291: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4292: $link = 'http://'.$hostname.$url;
4293: } else {
4294: $link = $url;
4295: }
4296: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.621 raeburn 4297: (($anchor ne '')?$anchor:''));
4298: if ($nomodal) {
4299: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4300: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4301: } else {
4302: $line.=&Apache::loncommon::modal_link($link,
4303: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4304: }
1.469 www 4305: } else {
4306: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4307: }
1.519 raeburn 4308: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4309: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4310: $line.='<a href="'.$url.'">'.$title.'</a>';
4311: } elsif ($url) {
1.621 raeburn 4312: if ($nomodal) {
4313: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4314: $title.'</a>';
4315: } else {
4316: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4317: }
1.617 raeburn 4318: } elsif (($hiddenfolder) || ($hiddenres)) {
1.615 raeburn 4319: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
1.469 www 4320: } else {
4321: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4322: }
1.518 raeburn 4323: $line.="$extresform</td>";
1.478 raeburn 4324: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4325: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4326: if (($allowed) && ($folder!~/^supplemental/)) {
4327: my %lt=&Apache::lonlocal::texthash(
4328: 'hd' => 'Hidden',
4329: 'ec' => 'URL hidden');
1.543 raeburn 4330: my ($enctext,$hidtext);
4331: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4332: $enctext = ' checked="checked"';
4333: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4334: push(@{$filtersref->{'encrypturl'}},$orderidx);
4335: }
4336: }
4337: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4338: $hidtext = ' checked="checked"';
4339: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4340: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4341: }
4342: }
1.537 raeburn 4343: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4344: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4345: $line.=(<<ENDPARMS);
4346: <td class="LC_docs_entry_parameter">
1.537 raeburn 4347: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4348: $form_param
1.478 raeburn 4349: $form_common
1.611 raeburn 4350: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4351: $form_end
1.458 raeburn 4352: <br />
1.537 raeburn 4353: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4354: $form_param
1.478 raeburn 4355: $form_common
1.611 raeburn 4356: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4357: $form_end
4358: </td>
1.478 raeburn 4359: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4360: $rand_order_text</td>
1.329 droeschl 4361: ENDPARMS
4362: }
1.379 bisitz 4363: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4364: return $line;
4365: }
4366:
1.538 raeburn 4367: sub action_restrictions {
4368: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4369: my %denied = (
4370: cut => 0,
4371: copy => 0,
4372: remove => 0,
4373: );
4374: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4375: # no copy for published maps
4376: $denied{'copy'} = 1;
1.597 raeburn 4377: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4378: unless ($1 eq 'simpleproblem') {
4379: $denied{'copy'} = 1;
4380: }
4381: $denied{'cut'} = 1;
1.538 raeburn 4382: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4383: if ($folderpath =~ /^default&[^\&]+$/) {
4384: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4385: $denied{'remove'} = 1;
4386: }
4387: $denied{'cut'} = 1;
4388: $denied{'copy'} = 1;
4389: }
4390: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4391: my $group = $1;
4392: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4393: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4394: $denied{'remove'} = 1;
4395: }
4396: }
4397: $denied{'cut'} = 1;
4398: $denied{'copy'} = 1;
4399: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4400: my $group = $1;
4401: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4402: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4403: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4404: if (keys(%groupsettings) > 0) {
4405: $denied{'remove'} = 1;
4406: }
4407: $denied{'cut'} = 1;
4408: $denied{'copy'} = 1;
4409: }
4410: }
4411: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4412: my $group = $1;
4413: if ($url =~ /group_boards_\Q$group\E/) {
4414: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4415: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4416: if (keys(%groupsettings) > 0) {
4417: if (ref($groupsettings{'functions'}) eq 'HASH') {
4418: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4419: $denied{'remove'} = 1;
4420: }
4421: }
4422: }
4423: $denied{'cut'} = 1;
4424: $denied{'copy'} = 1;
4425: }
4426: }
4427: }
4428: return %denied;
4429: }
4430:
1.533 raeburn 4431: sub new_timebased_suffix {
1.538 raeburn 4432: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4433: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4434: if ($type eq 'paste') {
4435: $prefix = $type;
4436: $namespace = 'courseeditor';
1.587 raeburn 4437: $idtype = 'addcode';
1.538 raeburn 4438: } elsif ($type eq 'map') {
1.533 raeburn 4439: $prefix = 'docs';
4440: if ($area eq 'supplemental') {
4441: $prefix = 'supp';
4442: }
4443: $prefix .= $container;
4444: $namespace = 'uploadedmaps';
4445: } else {
4446: $prefix = $type;
4447: $namespace = 'templated';
1.504 raeburn 4448: }
4449: my ($suffix,$freedlock,$error) =
1.587 raeburn 4450: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4451: if (!$suffix) {
1.538 raeburn 4452: if ($type eq 'paste') {
4453: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4454: } elsif ($type eq 'map') {
1.533 raeburn 4455: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4456: } elsif ($type eq 'smppg') {
4457: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4458: } elsif ($type eq 'exttool') {
4459: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4460: } else {
1.565 bisitz 4461: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4462: }
1.504 raeburn 4463: if ($error) {
4464: $errtext .= '<br />'.$error;
4465: }
4466: }
4467: if ($freedlock ne 'ok') {
1.533 raeburn 4468: $locknotfreed =
4469: '<div class="LC_error">'.
4470: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4471: if ($type eq 'paste') {
1.591 raeburn 4472: if ($freedlock eq 'nolock') {
4473: $locknotfreed =
4474: '<div class="LC_error">'.
4475: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4476:
1.593 droeschl 4477: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4478: } else {
4479: $locknotfreed .=
4480: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4481: }
1.538 raeburn 4482: } elsif ($type eq 'map') {
1.591 raeburn 4483: $locknotfreed .=
4484: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4485: } elsif ($type eq 'smppg') {
4486: $locknotfreed .=
4487: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4488: } elsif ($type eq 'exttool') {
4489: $locknotfreed .=
4490: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4491: } else {
4492: $locknotfreed .=
1.565 bisitz 4493: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4494: }
1.538 raeburn 4495: unless ($type eq 'paste') {
4496: $locknotfreed .=
1.560 raeburn 4497: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4498: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4499: }
4500: $locknotfreed .= '</div>';
1.504 raeburn 4501: }
4502: return ($suffix,$errtext,$locknotfreed);
4503: }
4504:
1.329 droeschl 4505: =pod
4506:
4507: =item tiehash()
4508:
4509: tie the hash
4510:
4511: =cut
4512:
4513: sub tiehash {
4514: my ($mode)=@_;
4515: $hashtied=0;
4516: if ($env{'request.course.fn'}) {
4517: if ($mode eq 'write') {
4518: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4519: &GDBM_WRCREAT(),0640)) {
4520: $hashtied=2;
4521: }
4522: } else {
4523: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4524: &GDBM_READER(),0640)) {
4525: $hashtied=1;
4526: }
4527: }
1.364 bisitz 4528: }
1.329 droeschl 4529: }
4530:
4531: sub untiehash {
4532: if ($hashtied) { untie %hash; }
4533: $hashtied=0;
4534: return OK;
4535: }
4536:
4537:
4538:
4539:
4540: sub checkonthis {
4541: my ($r,$url,$level,$title)=@_;
4542: $url=&unescape($url);
4543: $alreadyseen{$url}=1;
4544: $r->rflush();
4545: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4546: $r->print("\n<br />");
4547: if ($level==0) {
4548: $r->print("<br />");
4549: }
4550: for (my $i=0;$i<=$level*5;$i++) {
4551: $r->print(' ');
4552: }
4553: $r->print('<a href="'.$url.'" target="cat">'.
4554: ($title?$title:$url).'</a> ');
4555: if ($url=~/^\/res\//) {
4556: my $result=&Apache::lonnet::repcopy(
4557: &Apache::lonnet::filelocation('',$url));
4558: if ($result eq 'ok') {
4559: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4560: $r->rflush();
4561: &Apache::lonnet::countacc($url);
4562: $url=~/\.(\w+)$/;
4563: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4564: $r->print('<br />');
4565: $r->rflush();
4566: for (my $i=0;$i<=$level*5;$i++) {
4567: $r->print(' ');
4568: }
4569: $r->print('- '.&mt('Rendering:').' ');
4570: my ($errorcount,$warningcount)=split(/:/,
4571: &Apache::lonnet::ssi_body($url,
4572: ('grade_target'=>'web',
4573: 'return_only_error_and_warning_counts' => 1)));
4574: if (($errorcount) ||
4575: ($warningcount)) {
4576: if ($errorcount) {
1.369 bisitz 4577: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4578: &mt('[quant,_1,error]',$errorcount).'</span>');
4579: }
4580: if ($warningcount) {
4581: $r->print('<span class="LC_warning">'.
4582: &mt('[quant,_1,warning]',$warningcount).'</span>');
4583: }
4584: } else {
4585: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4586: }
4587: $r->rflush();
4588: }
4589: my $dependencies=
4590: &Apache::lonnet::metadata($url,'dependencies');
4591: foreach my $dep (split(/\,/,$dependencies)) {
4592: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4593: &checkonthis($r,$dep,$level+1);
4594: }
4595: }
4596: } elsif ($result eq 'unavailable') {
4597: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4598: } elsif ($result eq 'not_found') {
4599: unless ($url=~/\$/) {
1.521 bisitz 4600: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4601: } else {
1.366 bisitz 4602: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4603: }
4604: } else {
4605: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4606: }
4607: }
4608: }
4609: }
4610:
4611:
4612:
4613: =pod
4614:
4615: =item list_symbs()
4616:
1.485 raeburn 4617: List Content Identifiers
1.329 droeschl 4618:
4619: =cut
4620:
4621: sub list_symbs {
4622: my ($r) = @_;
4623:
1.408 raeburn 4624: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4625: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4626: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4627: $r->print(&startContentScreen('tools'));
1.329 droeschl 4628: my $navmap = Apache::lonnavmaps::navmap->new();
4629: if (!defined($navmap)) {
4630: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4631: '<div class="LC_error">'.
4632: &mt('Unable to retrieve information about course contents').
4633: '</div>');
1.408 raeburn 4634: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4635: } else {
1.484 raeburn 4636: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4637: &Apache::loncommon::start_data_table().
4638: &Apache::loncommon::start_data_table_header_row().
4639: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4640: &Apache::loncommon::end_data_table_header_row()."\n");
4641: my $count;
1.329 droeschl 4642: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4643: $r->print(&Apache::loncommon::start_data_table_row().
4644: '<td>'.$res->compTitle().'</td>'.
4645: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4646: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4647: $count ++;
4648: }
4649: if (!$count) {
4650: $r->print(&Apache::loncommon::start_data_table_row().
4651: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4652: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4653: }
1.484 raeburn 4654: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4655: }
1.521 bisitz 4656: $r->print(&endContentScreen());
1.329 droeschl 4657: }
4658:
4659:
4660: sub verifycontent {
4661: my ($r) = @_;
1.408 raeburn 4662: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4663: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4664: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4665: $r->print(&startContentScreen('tools'));
4666: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4667: $hashtied=0;
4668: undef %alreadyseen;
4669: %alreadyseen=();
4670: &tiehash();
1.484 raeburn 4671:
1.329 droeschl 4672: foreach my $key (keys(%hash)) {
4673: if ($hash{$key}=~/\.(page|sequence)$/) {
4674: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4675: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4676: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4677: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4678: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4679: }
4680: }
4681: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4682: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4683: }
4684: }
4685: &untiehash();
1.442 www 4686: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4687: $r->print(&endContentScreen());
1.329 droeschl 4688: }
4689:
4690:
4691: sub devalidateversioncache {
4692: my $src=shift;
4693: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4694: &Apache::lonnet::clutter($src));
4695: }
4696:
4697: sub checkversions {
1.611 raeburn 4698: my ($r,$canedit) = @_;
1.408 raeburn 4699: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4700: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4701: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4702: $r->print(&startContentScreen('tools'));
1.442 www 4703:
1.329 droeschl 4704: my $header='';
4705: my $startsel='';
4706: my $monthsel='';
4707: my $weeksel='';
4708: my $daysel='';
4709: my $allsel='';
4710: my %changes=();
4711: my $starttime=0;
4712: my $haschanged=0;
4713: my %setversions=&Apache::lonnet::dump('resourceversions',
4714: $env{'course.'.$env{'request.course.id'}.'.domain'},
4715: $env{'course.'.$env{'request.course.id'}.'.num'});
4716:
4717: $hashtied=0;
4718: &tiehash();
1.611 raeburn 4719: if ($canedit) {
4720: my %newsetversions=();
4721: if ($env{'form.setmostrecent'}) {
4722: $haschanged=1;
4723: foreach my $key (keys(%hash)) {
4724: if ($key=~/^ids\_(\/res\/.+)$/) {
4725: $newsetversions{$1}='mostrecent';
4726: &devalidateversioncache($1);
4727: }
4728: }
4729: } elsif ($env{'form.setcurrent'}) {
4730: $haschanged=1;
4731: foreach my $key (keys(%hash)) {
4732: if ($key=~/^ids\_(\/res\/.+)$/) {
4733: my $getvers=&Apache::lonnet::getversion($1);
4734: if ($getvers>0) {
4735: $newsetversions{$1}=$getvers;
4736: &devalidateversioncache($1);
4737: }
4738: }
1.329 droeschl 4739: }
1.611 raeburn 4740: } elsif ($env{'form.setversions'}) {
4741: $haschanged=1;
4742: foreach my $key (keys(%env)) {
4743: if ($key=~/^form\.set_version_(.+)$/) {
4744: my $src=$1;
4745: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4746: $newsetversions{$src}=$env{$key};
4747: &devalidateversioncache($src);
4748: }
4749: }
1.329 droeschl 4750: }
1.611 raeburn 4751: }
4752: if ($haschanged) {
4753: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4754: $env{'course.'.$env{'request.course.id'}.'.domain'},
4755: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4756: $r->print(&Apache::loncommon::confirmwrapper(
4757: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4758: } else {
4759: $r->print(&Apache::loncommon::confirmwrapper(
4760: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4761: }
1.611 raeburn 4762: &mark_hash_old();
4763: }
4764: &changewarning($r,'');
1.329 droeschl 4765: }
4766: if ($env{'form.timerange'} eq 'all') {
4767: # show all documents
1.549 raeburn 4768: $header=&mt('All content in '.$crstype);
1.521 bisitz 4769: $allsel=' selected="selected"';
1.329 droeschl 4770: foreach my $key (keys(%hash)) {
4771: if ($key=~/^ids\_(\/res\/.+)$/) {
4772: my $src=$1;
4773: $changes{$src}=1;
4774: }
4775: }
4776: } else {
4777: # show documents which changed
4778: %changes=&Apache::lonnet::dump
4779: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4780: $env{'course.'.$env{'request.course.id'}.'.num'});
4781: my $firstkey=(keys(%changes))[0];
4782: unless ($firstkey=~/^error\:/) {
4783: unless ($env{'form.timerange'}) {
4784: $env{'form.timerange'}=604800;
4785: }
4786: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4787: .&mt('seconds');
4788: if ($env{'form.timerange'}==-1) {
4789: $seltext='since start of course';
1.521 bisitz 4790: $startsel=' selected="selected"';
1.329 droeschl 4791: $env{'form.timerange'}=time;
4792: }
4793: $starttime=time-$env{'form.timerange'};
4794: if ($env{'form.timerange'}==2592000) {
4795: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4796: $monthsel=' selected="selected"';
1.329 droeschl 4797: } elsif ($env{'form.timerange'}==604800) {
4798: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4799: $weeksel=' selected="selected"';
1.329 droeschl 4800: } elsif ($env{'form.timerange'}==86400) {
4801: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4802: $daysel=' selected="selected"';
1.329 droeschl 4803: }
4804: $header=&mt('Content changed').' '.$seltext;
4805: } else {
4806: $header=&mt('No content modifications yet.');
4807: }
4808: }
4809: %setversions=&Apache::lonnet::dump('resourceversions',
4810: $env{'course.'.$env{'request.course.id'}.'.domain'},
4811: $env{'course.'.$env{'request.course.id'}.'.num'});
4812: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4813: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4814: 'lm' => 'Version changes since last Month',
4815: 'lw' => 'Version changes since last Week',
4816: 'sy' => 'Version changes since Yesterday',
4817: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4818: 'cd' => 'Change display',
1.329 droeschl 4819: 'sd' => 'Display',
4820: 'fi' => 'File',
4821: 'md' => 'Modification Date',
4822: 'mr' => 'Most recently published Version',
1.408 raeburn 4823: 've' => 'Version used in '.$crstype,
4824: 'vu' => 'Set Version to be used in '.$crstype,
4825: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4826: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4827: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4828: 'di' => 'Differences',
1.484 raeburn 4829: 'save' => 'Save changes',
4830: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4831: 'act' => 'Actions');
1.611 raeburn 4832: my ($disabled,$readonly);
4833: unless ($canedit) {
4834: $disabled = 'disabled="disabled"';
4835: $readonly = 1;
4836: }
1.329 droeschl 4837: $r->print(<<ENDHEADERS);
1.484 raeburn 4838: <h4 class="LC_info">$header</h4>
1.329 droeschl 4839: <form action="/adm/coursedocs" method="post">
4840: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4841: <div class="LC_left_float">
1.479 golterma 4842: <fieldset>
1.484 raeburn 4843: <legend>$lt{'cd'}</legend>
1.329 droeschl 4844: <select name="timerange">
1.521 bisitz 4845: <option value='all'$allsel>$lt{'al'}</option>
4846: <option value="-1"$startsel>$lt{'st'}</option>
4847: <option value="2592000"$monthsel>$lt{'lm'}</option>
4848: <option value="604800"$weeksel>$lt{'lw'}</option>
4849: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4850: </select>
4851: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4852: </fieldset>
4853: </div>
4854: <div class="LC_left_float">
4855: <fieldset>
4856: <legend>$lt{'act'}</legend>
1.611 raeburn 4857: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4858: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4859: </fieldset>
4860: </div>
4861: <br clear="all" />
4862: <hr />
4863: <h4>$lt{'vers'}</h4>
1.329 droeschl 4864: ENDHEADERS
1.479 golterma 4865: #number of columns for version history
1.571 raeburn 4866: my %changedbytime;
4867: foreach my $key (keys(%changes)) {
4868: #excludes not versionable problems from resource version history:
4869: next if ($key =~ /^\/res\/lib\/templates/);
4870: my $chg;
4871: if ($env{'form.timerange'} eq 'all') {
4872: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4873: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4874: } else {
4875: $chg = $changes{$key};
4876: next if ($chg < $starttime);
4877: }
4878: push(@{$changedbytime{$chg}},$key);
4879: }
4880: if (keys(%changedbytime) == 0) {
4881: &untiehash();
4882: $r->print(&mt('No content changes in imported content in specified time frame').
4883: &endContentScreen());
4884: return;
4885: }
1.479 golterma 4886: $r->print(
1.611 raeburn 4887: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4888: &Apache::loncommon::start_data_table().
4889: &Apache::loncommon::start_data_table_header_row().
4890: '<th>'.&mt('Resources').'</th>'.
4891: "<th>$lt{'mr'}</th>".
4892: "<th>$lt{'ve'}</th>".
4893: "<th>$lt{'vu'}</th>".
4894: '<th>'.&mt('History').'</th>'.
4895: &Apache::loncommon::end_data_table_header_row()
4896: );
1.571 raeburn 4897: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4898: foreach my $key (sort(@{$changedbytime{$chg}})) {
4899: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4900: my $currentversion=&Apache::lonnet::getversion($key);
4901: if ($currentversion<0) {
4902: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4903: }
4904: my $linkurl=&Apache::lonnet::clutter($key);
4905: $r->print(
4906: &Apache::loncommon::start_data_table_row().
4907: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4908: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4909: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4910: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4911: '<td align="right">'
4912: );
4913: # Used in course
4914: my $usedversion=$hash{'version_'.$linkurl};
4915: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4916: if ($usedversion != $currentversion) {
1.479 golterma 4917: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4918: } else {
1.479 golterma 4919: $r->print($usedversion);
4920: }
1.329 droeschl 4921: } else {
1.521 bisitz 4922: $r->print($currentversion);
1.329 droeschl 4923: }
1.571 raeburn 4924: $r->print('</td><td title="'.$lt{'vu'}.'">');
4925: # Set version
4926: $r->print(&Apache::loncommon::select_form(
4927: $setversions{$linkurl},
4928: 'set_version_'.$linkurl,
4929: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4930: '' => '',
4931: 'mostrecent' => &mt('most recent'),
1.611 raeburn 4932: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 4933: my $lastold=1;
4934: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4935: my $url=$root.'.'.$prevvers.'.'.$extension;
4936: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4937: $lastold=$prevvers;
4938: }
4939: }
4940: $r->print('</td>');
4941: # List all available versions
4942: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4943: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4944: my $url=$root.'.'.$prevvers.'.'.$extension;
4945: $r->print(
4946: '<span class="LC_nobreak">'
4947: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4948: .&mt('Version [_1]',$prevvers).'</a>'
4949: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4950: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4951: .')');
4952: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4953: $r->print(
4954: ' <a href="/adm/diff?filename='.
4955: &Apache::lonnet::clutter($root.'.'.$extension).
4956: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4957: '" target="diffs">'.&mt('Diffs').'</a>');
4958: }
4959: $r->print('</span><br />');
1.329 droeschl 4960: }
1.571 raeburn 4961: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4962: }
1.329 droeschl 4963: }
1.521 bisitz 4964: $r->print(
4965: &Apache::loncommon::end_data_table().
1.611 raeburn 4966: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4967: '</form>'
4968: );
1.329 droeschl 4969:
4970: &untiehash();
1.521 bisitz 4971: $r->print(&endContentScreen());
1.571 raeburn 4972: return;
1.329 droeschl 4973: }
4974:
4975: sub mark_hash_old {
4976: my $retie_hash=0;
4977: if ($hashtied) {
4978: $retie_hash=1;
4979: &untiehash();
4980: }
4981: &tiehash('write');
4982: $hash{'old'}=1;
4983: &untiehash();
4984: if ($retie_hash) { &tiehash(); }
4985: }
4986:
4987: sub is_hash_old {
4988: my $untie_hash=0;
4989: if (!$hashtied) {
4990: $untie_hash=1;
4991: &tiehash();
4992: }
4993: my $return=$hash{'old'};
4994: if ($untie_hash) { &untiehash(); }
4995: return $return;
4996: }
4997:
4998: sub changewarning {
4999: my ($r,$postexec,$message,$url)=@_;
5000: if (!&is_hash_old()) { return; }
5001: my $pathvar='folderpath';
5002: my $path=&escape($env{'form.folderpath'});
5003: if (!defined($url)) {
5004: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5005: }
5006: my $course_type = &Apache::loncommon::course_type();
5007: if (!defined($message)) {
5008: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5009: }
5010: $r->print("\n\n".
1.372 bisitz 5011: '<script type="text/javascript">'."\n".
5012: '// <![CDATA['."\n".
5013: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5014: '// ]]>'."\n".
1.369 bisitz 5015: '</script>'."\n".
1.375 tempelho 5016: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5017: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5018: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5019: &mt($message,' <input type="hidden" name="'.
5020: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5021: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5022: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5023: }
5024:
5025:
5026: sub init_breadcrumbs {
1.571 raeburn 5027: my ($form,$text,$help)=@_;
1.329 droeschl 5028: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5029: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5030: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5031: faq=>273,
5032: bug=>'Instructor Interface',
1.571 raeburn 5033: help => $help});
1.329 droeschl 5034: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5035: text=>$text,
5036: faq=>273,
5037: bug=>'Instructor Interface'});
5038: }
5039:
1.441 www 5040: # subroutine to list form elements
5041: sub create_list_elements {
5042: my @formarr = @_;
5043: my $list = '';
1.501 raeburn 5044: foreach my $button (@formarr){
5045: foreach my $picture (keys(%{$button})) {
5046: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5047: }
5048: }
5049: return $list;
5050: }
1.329 droeschl 5051:
1.441 www 5052: # subroutine to create ul from list elements
5053: sub create_form_ul {
5054: my $list = shift;
5055: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5056: return $ul;
5057: }
1.329 droeschl 5058:
1.442 www 5059: #
5060: # Start tabs
5061: #
5062:
5063: sub startContentScreen {
1.484 raeburn 5064: my ($mode) = @_;
5065: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5066: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5067: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5068: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5069: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5070: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5071: } else {
1.549 raeburn 5072: $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 5073: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5074: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5075: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5076: }
5077: $output .= "\n".'</ul>'."\n";
5078: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5079: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5080: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5081: return $output;
1.442 www 5082: }
5083:
5084: #
5085: # End tabs
5086: #
5087:
5088: sub endContentScreen {
1.484 raeburn 5089: return '</div></div></div>';
1.442 www 5090: }
1.329 droeschl 5091:
1.446 www 5092: sub supplemental_base {
1.548 raeburn 5093: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5094: }
5095:
1.329 droeschl 5096: sub handler {
5097: my $r = shift;
5098: &Apache::loncommon::content_type($r,'text/html');
5099: $r->send_http_header;
5100: return OK if $r->header_only;
1.484 raeburn 5101:
5102: # get course data
1.408 raeburn 5103: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5104: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5105: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5106:
1.606 raeburn 5107: # get docroot
5108: my $londocroot = $r->dir_config('lonDocRoot');
5109:
1.484 raeburn 5110: # graphics settings
5111: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5112:
1.443 www 5113: #
1.329 droeschl 5114: # --------------------------------------------- Initialize help topics for this
5115: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 ! raeburn 5116: 'Adding_External_Resource','Adding_External_Tool',
! 5117: 'Navigate_Content','Adding_Folders','Docs_Overview',
! 5118: 'Load_Map','Supplemental','Score_Upload_Form',
! 5119: 'Adding_Pages','Importing_LON-CAPA_Resource',
! 5120: 'Importing_IMS_Course','Uploading_From_Harddrive',
! 5121: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5122: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5123: }
5124: # Composite help files
5125: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5126: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5127: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5128: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5129: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5130: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5131: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5132: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5133: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5134: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5135:
1.611 raeburn 5136: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5137: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5138: unless ($r->uri eq '/adm/supplemental') {
5139: # does this user have privileges to modify content.
1.611 raeburn 5140: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5141: $allowed = 1;
5142: $canedit = 1;
5143: $canview = 1;
5144: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5145: $allowed = 1;
5146: $canview = 1;
5147: }
5148: }
5149: unless ($canedit) {
5150: $disabled = ' disabled="disabled"';
1.472 raeburn 5151: }
1.582 raeburn 5152: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5153: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5154: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 5155: &verifycontent($r);
5156: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5157: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5158: &list_symbs($r);
5159: } elsif ($allowed && $env{'form.docslog'}) {
5160: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5161: my $folder = $env{'form.folder'};
5162: if ($folder eq '') {
5163: $folder='default';
5164: }
1.611 raeburn 5165: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5166: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5167: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5168: &checkversions($r,$canedit);
5169: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5170: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5171: &dumpcourse($r);
1.611 raeburn 5172: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5173: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5174: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5175: } else {
1.611 raeburn 5176: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5177: $noendpage = 1;
5178: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5179: if ($redirect) {
5180: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5181: my $container = 'sequence';
5182: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5183: $is_random_order,$container) =
5184: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5185: my (@folders)=split('&',$env{'form.folderpath'});
5186: $env{'form.foldername'}=&unescape(pop(@folders));
5187: my $folder=pop(@folders);
5188: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5189: $folder.'.'.$container);
5190: my $warning;
5191: if ($fatal) {
5192: if ($container eq 'page') {
5193: $warning = &mt('An error occurred retrieving the contents of the current page.');
5194: } else {
5195: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5196: }
5197: } else {
5198: my $url = $redirect;
5199: my $srcfile = $londocroot.$url;
5200: $url =~ s{^/priv/}{/res/};
5201: my $targetfile = $londocroot.$url;
5202: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5203: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5204: $env{'form.folder'} = $folder;
5205: &snapshotbefore();
5206: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5207: my $ext = 'false';
5208: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5209: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5210: ':'.$ext.':normal:res';
5211: push(@LONCAPA::map::order,$newidx);
5212: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5213: 'string_yesno');
5214: &remember_parms($newidx,'hiddenresource','set','yes');
5215: ($errtext,$fatal) =
5216: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5217: &log_differences($plain);
5218: &mark_hash_old();
5219: $r->internal_redirect($redirect);
5220: return OK;
5221: }
5222: }
5223: }
5224: }
1.445 www 5225: #
5226: # Done catching special calls
1.484 raeburn 5227: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5228: # Get the parameters that may be needed
5229: #
5230: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5231: ['folderpath',
5232: 'forcesupplement','forcestandard',
1.510 raeburn 5233: 'tools','symb','command','supppath']);
1.445 www 5234:
5235: # standard=1: this is a "new-style" course with an uploaded map as top level
5236: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5237:
5238: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5239:
1.484 raeburn 5240: # Decide whether this should display supplemental or main content or utilities
1.445 www 5241: # supplementalflag=1: show supplemental documents
5242: # supplementalflag=0: show standard documents
1.484 raeburn 5243: # toolsflag=1: show utilities
1.445 www 5244:
1.561 raeburn 5245: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5246: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5247: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5248: $supplementalflag=0;
5249: }
5250: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5251: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5252: unless ($allowed) { $supplementalflag=1; }
5253: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5254: my $toolsflag=0;
5255: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5256:
1.329 droeschl 5257: my $script='';
5258: my $showdoc=0;
1.457 raeburn 5259: my $addentries = {};
1.475 raeburn 5260: my $container;
1.329 droeschl 5261: my $containertag;
1.508 raeburn 5262: my $pathitem;
1.598 raeburn 5263: my %ltitools;
1.617 raeburn 5264: my $hiddentop;
1.615 raeburn 5265: my $navmap;
1.617 raeburn 5266: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5267:
1.464 www 5268: # Do we directly jump somewhere?
1.525 raeburn 5269: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5270: if ($env{'form.symb'} ne '') {
1.522 raeburn 5271: $env{'form.folderpath'}=
1.617 raeburn 5272: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5273: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5274: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5275: } elsif ($env{'form.supppath'} ne '') {
5276: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5277: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5278: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5279: }
1.472 raeburn 5280: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5281: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5282: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5283: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5284: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5285: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5286: } elsif ($env{'form.command'} eq 'contents') {
5287: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5288: } elsif ($env{'form.command'} eq 'home') {
5289: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5290: }
5291:
1.525 raeburn 5292:
1.445 www 5293: # Where do we store these for when we come back?
5294: my $stored_folderpath='docs_folderpath';
5295: if ($supplementalflag) {
5296: $stored_folderpath='docs_sup_folderpath';
5297: }
1.464 www 5298:
1.519 raeburn 5299: # No folderpath, and in edit mode, see if we have something stored
5300: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5301: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5302: {'folderpath' => 'scalar'});
1.615 raeburn 5303:
5304: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5305: if ($supplementalflag) {
5306: undef($env{'form.folderpath'}) if ($1 eq 'default');
5307: } else {
5308: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5309: }
5310: } else {
1.523 raeburn 5311: undef($env{'form.folderpath'});
5312: }
1.329 droeschl 5313: }
1.446 www 5314:
5315: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5316: if (!$allowed) {
1.446 www 5317: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5318: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5319: }
5320: }
1.446 www 5321: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5322: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5323: $env{'form.folderpath'} = &supplemental_base()
5324: .'&'.
1.329 droeschl 5325: $env{'form.folderpath'};
5326: }
1.615 raeburn 5327: # If allowed and user's role is not advanced check folderpath is not hidden
5328: if (($allowed) && (!$env{'request.role.adv'}) &&
5329: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5330: my $folderurl;
5331: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5332: my $folder = $pathitems[-2];
5333: if ($folder eq '') {
5334: undef($env{'form.folderpath'});
5335: } else {
5336: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5337: if ((split(/\:/,$pathitems[-1]))[4]) {
5338: $folderurl .= '.page';
5339: } else {
5340: $folderurl .= '.sequence';
5341: }
1.617 raeburn 5342: unless (ref($navmap)) {
5343: $navmap = Apache::lonnavmaps::navmap->new();
5344: }
1.615 raeburn 5345: if (ref($navmap)) {
5346: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5347: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5348: unless (@resources) {
5349: undef($env{'form.folderpath'});
5350: }
1.615 raeburn 5351: }
5352: }
5353: }
5354: }
5355:
5356:
1.446 www 5357: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5358: unless ($env{'form.folderpath'}) {
1.446 www 5359: if ($supplementalflag) {
5360: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5361: } elsif ($allowed) {
5362: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5363: }
1.472 raeburn 5364: }
1.446 www 5365:
1.445 www 5366: # Store this
1.484 raeburn 5367: unless ($toolsflag) {
1.615 raeburn 5368: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5369: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5370: {'folderpath' => 'scalar'});
1.510 raeburn 5371: }
1.519 raeburn 5372: my $folderpath;
1.484 raeburn 5373: if ($env{'form.folderpath'}) {
1.519 raeburn 5374: $folderpath = $env{'form.folderpath'};
5375: my (@folders)=split('&',$env{'form.folderpath'});
5376: $env{'form.foldername'}=&unescape(pop(@folders));
5377: if ($env{'form.foldername'} =~ /\:1$/) {
5378: $container = 'page';
5379: } else {
5380: $container = 'sequence';
5381: }
5382: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5383: } else {
1.519 raeburn 5384: if ($env{'form.folder'} eq '' ||
5385: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5386: if ($env{'form.folder'} eq 'supplemental') {
5387: $folderpath=&supplemental_base();
5388: } elsif (!$hiddentop) {
5389: $folderpath='default&'.
5390: &escape(&mt('Main Content').':::::');
5391: }
1.484 raeburn 5392: }
5393: }
1.519 raeburn 5394: $containertag = '<input type="hidden" name="folderpath" value="" />';
5395: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5396: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5397: $showdoc='/'.$1;
5398: }
5399: if ($showdoc) { # got called in sequence from course
5400: $allowed=0;
5401: } else {
1.611 raeburn 5402: if ($canedit) {
1.484 raeburn 5403: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5404: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5405: }
5406: }
1.329 droeschl 5407: }
5408:
1.344 bisitz 5409: # get personal data
1.329 droeschl 5410: my $uname=$env{'user.name'};
5411: my $udom=$env{'user.domain'};
5412: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5413:
5414: if ($allowed) {
1.484 raeburn 5415: if ($toolsflag) {
5416: $script .= &inject_data_js();
5417: my ($home,$other,%outhash)=&authorhosts();
5418: if (!$home && $other) {
5419: my @hosts;
5420: foreach my $aurole (keys(%outhash)) {
5421: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5422: push(@hosts,$outhash{$aurole});
5423: }
5424: }
5425: $script .= &dump_switchserver_js(@hosts);
5426: }
1.458 raeburn 5427: } else {
1.570 raeburn 5428: my $tid = 1;
1.484 raeburn 5429: my @tabids;
5430: if ($supplementalflag) {
5431: @tabids = ('002','ee2','ff2');
1.570 raeburn 5432: $tid = 2;
1.484 raeburn 5433: } else {
5434: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5435: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5436: unshift(@tabids,'001');
5437: push(@tabids,('dd1','ee1'));
5438: }
1.458 raeburn 5439: }
1.484 raeburn 5440: my $tabidstr = join("','",@tabids);
1.598 raeburn 5441: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5442: my $posslti = keys(%ltitools);
1.622 raeburn 5443: my $hostname = $r->hostname();
1.606 raeburn 5444: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5445: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5446: &history_tab_js().
5447: &inject_data_js().
1.570 raeburn 5448: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5449: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5450: $addentries = {
1.485 raeburn 5451: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5452: };
1.458 raeburn 5453: }
1.538 raeburn 5454: $script .= &paste_popup_js();
1.501 raeburn 5455: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5456: &mt('Switch server?');
5457:
5458:
1.329 droeschl 5459: }
5460: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5461: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5462: .'// <![CDATA['."\n"
5463: .$script."\n"
5464: .'// ]]>'."\n"
1.595 musolffc 5465: .'</script>'."\n"
5466: .'<script type="text/javascript"
5467: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5468:
5469: # Breadcrumbs
5470: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5471:
5472: if ($showdoc) {
5473: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5474: {'force_register' => $showdoc,}));
1.571 raeburn 5475: } elsif ($toolsflag) {
1.611 raeburn 5476: my ($breadtext,$breadtitle);
1.617 raeburn 5477: $breadtext = "$crstype Editor";
1.611 raeburn 5478: if ($canedit) {
5479: $breadtitle = 'Editing '.$crstype.' Contents';
5480: } else {
5481: $breadtext .= ' (View-only mode)';
5482: $breadtitle = 'Viewing '.$crstype.' Contents';
5483: }
1.571 raeburn 5484: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5485: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5486: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5487: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5488: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5489: $breadtitle)
1.571 raeburn 5490: );
1.510 raeburn 5491: } elsif ($r->uri eq '/adm/supplemental') {
5492: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5493: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5494: {'bread_crumbs' => $brcrum,}));
5495: } else {
1.611 raeburn 5496: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5497: $breadtext = "$crstype Editor";
1.611 raeburn 5498: if ($canedit) {
5499: $breadtitle = 'Editing '.$crstype.' Contents';
5500: $helpitem = 'Docs_Adding_Course_Doc';
5501: } else {
5502: $breadtext .= ' (View-only mode)';
5503: $breadtitle = 'Viewing '.$crstype.' Contents';
5504: $helpitem = 'Docs_Viewing_Course_Doc';
5505: }
1.392 raeburn 5506: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5507: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5508: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5509: {'add_entries' => $addentries}
5510: )
1.392 raeburn 5511: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5512: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5513: $breadtitle,
5514: $helpitem)
1.392 raeburn 5515: );
5516: }
1.364 bisitz 5517:
1.329 droeschl 5518: my %allfiles = ();
5519: my %codebase = ();
1.440 raeburn 5520: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5521: if ($canedit) {
1.329 droeschl 5522: if (($env{'form.uploaddoc.filename'}) &&
5523: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5524: my $context = $1;
5525: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5526: undef($hadchanges);
1.440 raeburn 5527: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5528: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5529: if ($hadchanges) {
5530: &mark_hash_old();
5531: }
1.440 raeburn 5532: $r->print($upload_output);
5533: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5534: # Process file upload - phase two - upload embedded objects
5535: $uploadphase = 'check_embedded';
5536: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5537: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5538: $env{'form.newidx'});
5539: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5540: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5541: my ($destination,$dir_root) = &embedded_destination();
5542: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5543: my $actionurl = '/adm/coursedocs';
5544: my ($result,$flag) =
5545: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5546: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5547: $actionurl);
5548: $r->print($result.&return_to_editor());
5549: } elsif ($env{'form.phase'} eq 'check_embedded') {
5550: # Process file upload - phase three - modify references in HTML file
5551: $uploadphase = 'modified_orightml';
5552: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5553: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5554: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5555: my $result =
5556: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5557: $docuname,$docudom,undef,
5558: $dir_root);
5559: $r->print($result.&return_to_editor());
1.476 raeburn 5560: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5561: $uploadphase = 'decompress_phase_one';
5562: $r->print(&decompression_phase_one().
5563: &return_to_editor());
5564: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5565: $uploadphase = 'decompress_phase_two';
5566: $r->print(&decompression_phase_two().
5567: &return_to_editor());
1.329 droeschl 5568: }
5569: }
5570:
1.484 raeburn 5571: if ($allowed && $toolsflag) {
5572: $r->print(&startContentScreen('tools'));
1.611 raeburn 5573: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5574: $r->print(&endContentScreen());
5575: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5576: # -----------------------------------------------------------------------------
5577: my %lt=&Apache::lonlocal::texthash(
5578: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5579: 'upfi' => 'Upload File',
1.553 raeburn 5580: 'upld' => 'Upload Content',
1.329 droeschl 5581: 'srch' => 'Search',
5582: 'impo' => 'Import',
1.487 raeburn 5583: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5584: 'impm' => 'Import from Assembled Map',
1.606 raeburn 5585: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5586: 'extr' => 'External Resource',
5587: 'extt' => 'External Tool',
1.329 droeschl 5588: 'selm' => 'Select Map',
5589: 'load' => 'Load Map',
5590: 'newf' => 'New Folder',
5591: 'newp' => 'New Composite Page',
5592: 'syll' => 'Syllabus',
1.425 raeburn 5593: 'navc' => 'Table of Contents',
1.343 biermanm 5594: 'sipa' => 'Simple Course Page',
1.329 droeschl 5595: 'sipr' => 'Simple Problem',
1.534 raeburn 5596: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5597: 'stpr' => 'Standard Problem',
5598: 'news' => 'New sub-directory',
5599: 'crpr' => 'Create Problem',
1.329 droeschl 5600: 'drbx' => 'Drop Box',
1.451 www 5601: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5602: 'bull' => 'Discussion Board',
1.347 weissno 5603: 'mypi' => 'My Personal Information Page',
1.353 weissno 5604: 'grpo' => 'Group Portfolio',
1.329 droeschl 5605: 'rost' => 'Course Roster',
1.528 raeburn 5606: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5607: 'imsf' => 'IMS Upload',
5608: 'imsl' => 'Upload IMS package',
1.501 raeburn 5609: 'cms' => 'Origin of IMS package',
5610: 'se' => 'Select',
1.329 droeschl 5611: 'file' => 'File',
5612: 'title' => 'Title',
1.606 raeburn 5613: 'addp' => 'Add Placeholder to course?',
5614: 'uste' => 'Use Template?',
5615: 'fnam' => 'File Name:',
5616: 'loca' => 'Location:',
5617: 'dire' => 'Directory:',
5618: 'cate' => 'Category:',
5619: 'tmpl' => 'Template:',
1.329 droeschl 5620: 'comment' => 'Comment',
1.403 raeburn 5621: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5622: 'bb5' => 'Blackboard 5',
5623: 'bb6' => 'Blackboard 6',
5624: 'angel5' => 'ANGEL 5.5',
5625: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5626: 'yes' => 'Yes',
5627: 'no' => 'No',
1.618 raeburn 5628: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5629: );
1.329 droeschl 5630: # -----------------------------------------------------------------------------
1.595 musolffc 5631:
5632: # Calculate free quota space for a user or course. A javascript function checks
5633: # file size to determine if upload should be allowed.
5634: my $quotatype = 'unofficial';
5635: if ($crstype eq 'Community') {
1.601 raeburn 5636: $quotatype = 'community';
5637: } elsif ($crstype eq 'Placement') {
5638: $quotatype = 'placement';
1.595 musolffc 5639: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5640: $quotatype = 'official';
5641: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5642: $quotatype = 'textbook';
5643: }
5644: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5645: 'course',$quotatype); # expressed in MB
5646: my $current_disk_usage = 0;
5647: foreach my $subdir ('docs','supplemental') {
5648: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5649: "userfiles/$subdir",1); # expressed in kB
5650: }
5651: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5652: my $usage = $current_disk_usage/1024; # in MB
5653: my $quota = $disk_quota;
5654: my $percent;
5655: if ($disk_quota == 0) {
5656: $percent = 100.0;
5657: } else {
1.619 raeburn 5658: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5659: }
5660: $usage = sprintf("%.2f",$usage);
5661: $quota = sprintf("%.2f",$quota);
5662: $percent = sprintf("%.0f",$percent);
5663: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5664: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5665:
1.329 droeschl 5666: my $fileupload=(<<FIUP);
1.605 raeburn 5667: $quotainfo
1.329 droeschl 5668: $lt{'file'}:<br />
1.611 raeburn 5669: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5670: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5671: FIUP
5672:
5673: my $checkbox=(<<CHBO);
5674: <!-- <label>$lt{'parse'}?
5675: <input type="checkbox" name="parserflag" />
5676: </label> -->
5677: <label>
1.611 raeburn 5678: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5679: </label>
5680: CHBO
1.501 raeburn 5681: my $imsfolder = $env{'form.folder'};
5682: if ($imsfolder eq '') {
5683: $imsfolder = 'default';
5684: }
5685: my $imspform=(<<IMSFORM);
5686: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5687: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5688: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5689: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5690: <legend>$lt{'imsf'}</legend>
5691: $fileupload
5692: <br />
5693: <p>
5694: $lt{'cms'}:
1.611 raeburn 5695: <select name="source" $disabled>
1.501 raeburn 5696: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5697: <option value="bb5">$lt{'bb5'}</option>
5698: <option value="bb6">$lt{'bb6'}</option>
5699: <option value="angel5">$lt{'angel5'}</option>
5700: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5701: </select>
5702: <input type="hidden" name="folder" value="$imsfolder" />
5703: </p>
5704: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5705: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5706: </fieldset>
5707: </form>
5708: IMSFORM
1.329 droeschl 5709:
5710: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5711: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5712: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5713: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5714: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5715: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5716: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5717: $fileupload
1.329 droeschl 5718: <br />
5719: $lt{'title'}:<br />
1.611 raeburn 5720: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5721: $pathitem
1.329 droeschl 5722: <input type="hidden" name="cmd" value="upload_default" />
5723: <br />
1.458 raeburn 5724: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5725: $checkbox
5726: </span>
1.501 raeburn 5727: <br clear="all" />
1.611 raeburn 5728: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5729: </fieldset>
5730: </form>
1.383 tempelho 5731: FUFORM
1.329 droeschl 5732:
1.611 raeburn 5733: my $mapimportjs;
5734: if ($canedit) {
5735: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5736: } else {
5737: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5738: }
1.502 raeburn 5739: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5740: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5741: $lt{'impm'}</a>$help{'Load_Map'}
5742: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5743: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5744: <legend>$lt{'impm'}</legend>
1.371 tempelho 5745: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5746: $lt{'copm'}<br />
5747: <span class="LC_nobreak">
5748: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5749: onfocus="this.blur();$mapimportjs" $disabled />
5750: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5751: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5752: </fieldset>
5753: </form>
5754:
1.383 tempelho 5755: SEDFFORM
1.606 raeburn 5756: my $importcrsresform;
1.608 raeburn 5757: my ($numdirs,$pickfile) =
5758: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5759: "resize_scrollbox('contentscroll','1','0');",
5760: undef,'res');
1.606 raeburn 5761: if ($pickfile) {
5762: $importcrsresform=(<<CRSFORM);
5763: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5764: $lt{'imcr'}</a>$help{'Course_Resources'}
5765: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5766: <fieldset id="importcrsresform" style="display: none;">
5767: <legend>$lt{'imcr'}</legend>
5768: <input type="hidden" name="active" value="bb" />
5769: $pickfile
5770: <p>
1.611 raeburn 5771: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5772: </p>
5773: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5774: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5775: </fieldset>
5776: </form>
5777: CRSFORM
5778: }
5779:
1.611 raeburn 5780: my $fromstoredjs;
5781: if ($canedit) {
5782: $fromstoredjs = 'open_StoredLinks_Import()';
5783: } else {
5784: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5785: }
5786:
1.502 raeburn 5787: my @importpubforma = (
1.508 raeburn 5788: { '<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 5789: { '<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.611 raeburn 5790: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:'.$fromstoredjs.';" />' => '<a class="LC_menubuttons_link" href="javascript:'.$fromstoredjs.';">'.$lt{'lnks'}.'</a>' },
1.606 raeburn 5791: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5792: );
5793: if ($pickfile) {
5794: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5795: }
1.502 raeburn 5796: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5797: my $extresourcesform =
5798: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5799: $help{'Adding_External_Resource'},
5800: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5801: my $exttoolform =
5802: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5803: $help{'Adding_External_Tool'},undef,
5804: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5805: \%ltitools,$disabled);
1.329 droeschl 5806: if ($allowed) {
1.492 raeburn 5807: my $folder = $env{'form.folder'};
5808: if ($folder eq '') {
5809: $folder='default';
5810: }
1.615 raeburn 5811: if ($canedit) {
5812: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5813: if ($output) {
5814: $r->print($output);
5815: }
1.538 raeburn 5816: }
1.337 ehlerst 5817: $r->print(<<HIDDENFORM);
5818: <form name="renameform" method="post" action="/adm/coursedocs">
5819: <input type="hidden" name="title" />
5820: <input type="hidden" name="cmd" />
5821: <input type="hidden" name="markcopy" />
5822: <input type="hidden" name="copyfolder" />
5823: $containertag
5824: </form>
1.484 raeburn 5825:
1.337 ehlerst 5826: HIDDENFORM
1.508 raeburn 5827: $r->print(&makesimpleeditform($pathitem)."\n".
5828: &makedocslogform($pathitem."\n".
1.484 raeburn 5829: '<input type="hidden" name="folder" value="'.
5830: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5831: }
1.442 www 5832:
5833: # Generate the tabs
1.510 raeburn 5834: my ($mode,$needs_end);
1.472 raeburn 5835: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5836: my @folders = split('&',$env{'form.folderpath'});
5837: unless (@folders > 2) {
5838: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5839: $needs_end = 1;
5840: }
1.472 raeburn 5841: } else {
1.484 raeburn 5842: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5843: $needs_end = 1;
1.472 raeburn 5844: }
1.443 www 5845:
1.442 www 5846: #
1.622 raeburn 5847: my $hostname = $r->hostname();
1.442 www 5848: my $savefolderpath;
5849:
1.395 raeburn 5850: if ($allowed) {
1.329 droeschl 5851: my $folder=$env{'form.folder'};
1.615 raeburn 5852: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5853: $folder='default';
1.356 tempelho 5854: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5855: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5856: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5857: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5858: }
5859: my $postexec='';
5860: if ($folder eq 'default') {
1.372 bisitz 5861: $r->print('<script type="text/javascript">'."\n"
5862: .'// <![CDATA['."\n"
5863: .'this.window.name="loncapaclient";'."\n"
5864: .'// ]]>'."\n"
5865: .'</script>'."\n"
1.369 bisitz 5866: );
1.329 droeschl 5867: } else {
5868: #$postexec='self.close();';
5869: }
1.504 raeburn 5870: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5871: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5872: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5873:
5874: my $newnavform=(<<NNFORM);
5875: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5876: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5877: $pathitem
1.329 droeschl 5878: <input type="hidden" name="importdetail"
5879: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 5880: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5881: $help{'Navigate_Content'}
5882: </form>
5883: NNFORM
5884: my $newsmppageform=(<<NSPFORM);
5885: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5886: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5887: $pathitem
1.329 droeschl 5888: <input type="hidden" name="importdetail" value="" />
1.423 onken 5889: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5890: $help{'Simple Page'}
1.329 droeschl 5891: </form>
5892: NSPFORM
5893:
5894: my $newsmpproblemform=(<<NSPROBFORM);
5895: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5896: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5897: $pathitem
1.329 droeschl 5898: <input type="hidden" name="importdetail" value="" />
1.423 onken 5899: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5900: $help{'Simple_Problem'}
1.329 droeschl 5901: </form>
5902:
5903: NSPROBFORM
5904:
5905: my $newdropboxform=(<<NDBFORM);
5906: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5907: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5908: $pathitem
1.329 droeschl 5909: <input type="hidden" name="importdetail" value="" />
1.423 onken 5910: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5911: $help{'Dropbox'}
1.344 bisitz 5912: </form>
1.329 droeschl 5913: NDBFORM
5914:
5915: my $newexuploadform=(<<NEXUFORM);
5916: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5917: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5918: $pathitem
1.329 droeschl 5919: <input type="hidden" name="importdetail" value="" />
1.423 onken 5920: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5921: $help{'Score_Upload_Form'}
5922: </form>
5923: NEXUFORM
5924:
5925: my $newbulform=(<<NBFORM);
5926: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5927: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5928: $pathitem
1.329 droeschl 5929: <input type="hidden" name="importdetail" value="" />
1.423 onken 5930: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5931: $help{'Bulletin Board'}
5932: </form>
5933: NBFORM
5934:
5935: my $newaboutmeform=(<<NAMFORM);
5936: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5937: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5938: $pathitem
1.329 droeschl 5939: <input type="hidden" name="importdetail"
5940: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 5941: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5942: $help{'My Personal Information Page'}
1.329 droeschl 5943: </form>
5944: NAMFORM
5945:
5946: my $newaboutsomeoneform=(<<NASOFORM);
5947: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5948: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5949: $pathitem
1.329 droeschl 5950: <input type="hidden" name="importdetail" value="" />
1.423 onken 5951: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5952: </form>
5953: NASOFORM
5954:
5955: my $newrosterform=(<<NROSTFORM);
5956: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5957: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5958: $pathitem
1.329 droeschl 5959: <input type="hidden" name="importdetail"
5960: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 5961: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 5962: $help{'Course_Roster'}
1.329 droeschl 5963: </form>
5964: NROSTFORM
5965:
1.534 raeburn 5966: my $newwebpage;
5967: if ($folder =~ /^default_?(\d*)$/) {
5968: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5969: if ($1) {
5970: $newwebpage .= $1;
5971: } else {
5972: $newwebpage .= 'default';
5973: }
5974: $newwebpage .= '/new.html';
5975: }
5976: my $newwebpageform =(<<NWEBFORM);
5977: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5978: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5979: $pathitem
5980: <input type="hidden" name="importdetail" value="$newwebpage" />
5981: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5982: $help{'Web_Page'}
1.534 raeburn 5983: </form>
5984: NWEBFORM
1.604 raeburn 5985:
1.606 raeburn 5986: my @ids=&Apache::lonnet::current_machine_ids();
5987: my %select_menus;
5988: my $numauthor = 0;
5989: my $numcrsdirs = 0;
5990: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5991: if ($env{'user.author'}) {
5992: $numauthor ++;
5993: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5994: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5995: my $is_home = 1;
5996: my %subdirs;
1.608 raeburn 5997: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5998: $select_menus{'author'}->{'default'} = '/';
5999: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6000: my @ordered = ('/');
6001: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6002: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6003: push(@ordered,$relpath);
6004: }
6005: $select_menus{'author'}->{'order'} = \@ordered;
6006: } else {
6007: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6008: $select_menus{'author'}->{'default'} = 'switch';
6009: $select_menus{'author'}->{'order'} = ['switch'];
6010: }
6011: }
6012: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6013: ['active'],['ca','aa']);
6014: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6015: my %by_roletype;
6016: if (keys(%roleshash)) {
6017: foreach my $entry (keys(%roleshash)) {
6018: my ($auname,$audom,$roletype) = split(/:/,$entry);
6019: my $key = $entry;
6020: $key =~ s/:/___/g;
6021: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6022: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6023: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6024: if (grep(/^\Q$rolehome\E$/,@ids)) {
6025: my $is_home = 1;
6026: my (%subdirs,@ordered);
6027: my $toppath="/priv/$audom/$auname";
1.608 raeburn 6028: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6029: $select_menus{$key}->{'default'} = '/';
6030: $select_menus{$key}->{'select2'}->{'/'} = '/';
6031: my @ordered = ('/');
6032: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6033: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6034: push(@ordered,$relpath);
6035: }
6036: $select_menus{$key}->{'order'} = \@ordered;
6037: } else {
6038: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6039: $select_menus{$key}->{'default'} = 'switch';
6040: $select_menus{$key}->{'order'} = ['switch'];
6041: }
6042: $numauthor ++;
6043: }
6044: }
6045: my ($pickdir,$showtitle);;
6046: if ($numauthor) {
6047: my @order;
6048: my $defrole;
6049: if ($env{'user.author'}) {
6050: push(@order,'author');
6051: $defrole = 'author';
6052: }
6053: if (keys(%by_roletype)) {
6054: foreach my $possrole ('ca','aa') {
6055: if (ref($by_roletype{$possrole}) eq 'HASH') {
6056: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6057: unless ($defrole) {
6058: $defrole = $author;
6059: }
6060: push(@order,$author.'___'.$possrole);
6061: }
6062: }
6063: }
6064: }
6065: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6066: if (grep(/^\Q$crshome\E$/,@ids)) {
6067: my $is_home = 1;
6068: my %subdirs;
6069: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6070: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6071: $numcrsdirs = keys(%subdirs);
6072: $select_menus{'course'}->{'default'} = '/';
6073: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6074: my @ordered = ('/');
6075: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6076: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6077: push(@ordered,$relpath);
6078: }
6079: $select_menus{'course'}->{'order'} = \@ordered;
6080: } else {
6081: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6082: $select_menus{'course'}->{'default'} = 'switch';
6083: $select_menus{'course'}->{'order'} = ['switch'];
6084: }
6085: push(@order,'course');
6086: $pickdir = $lt{'loca'}.
6087: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6088: $defrole,'authorrole','authorpath',
6089: \%select_menus,\@order,'toggleCrsResTitle();',
6090: '','priv').'<br />';
6091: $showtitle = 'none';
6092: } else {
6093: my $is_home;
6094: $showtitle = 'inline';
6095: if (grep(/^\Q$crshome\E$/,@ids)) {
6096: $is_home = 1;
6097: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6098: my $toppath="/priv/$coursedom/$coursenum'}";
6099: my %subdirs;
1.608 raeburn 6100: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6101: $numcrsdirs = keys(%subdirs);
6102: if ($numcrsdirs) {
6103: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6104: '<option value="/">/</option>'."\n";
6105: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6106: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6107: }
6108: $pickdir .= '</select>';
6109: } else {
6110: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6111: }
6112: }
6113: }
6114:
6115: my %seltemplate_menus;
6116: my @files = &Apache::lonhomework::get_template_list('problem');
6117: my @noexamplelink = ('blank.problem','blank.library','script.library');
6118: my $currentcategory = '';
6119: my @ordered = ('');
6120: my %templatehelp;
6121: my $defcategory = '';
6122: my @catorder = ($defcategory);
6123: $seltemplate_menus{$defcategory}->{'order'} = [''];
6124: $seltemplate_menus{$defcategory}->{'text'} = '';
6125: foreach my $file (@files) {
6126: if (ref($file) eq 'ARRAY') {
6127: my ($path,$title,$category,$help) = @{$file};
6128: next if ($title !~ /\S/);
6129: if (&js_escape($category) ne $currentcategory) {
6130: $currentcategory = &js_escape($category);
6131: push(@catorder,&js_escape($currentcategory));
6132: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6133: $seltemplate_menus{$currentcategory}->{'default'} = '';
6134: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6135: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6136: }
6137: if ($path) {
6138: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6139: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6140: if ($help) {
6141: $templatehelp{$path} = $help;
6142: }
6143: }
6144: }
6145: }
6146:
6147: my $templates = $lt{'cate'}.' '.
6148: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6149: $defcategory,'tempcategory','template',
6150: \%seltemplate_menus,\@catorder,
6151: "resize_scrollbox('contentscroll','1','0');",
6152: "toggleExampleText();",'template').'<br />';
6153: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6154: '<span id="newresexample">'.&mt('Example').'<span></a>';
6155: my $crsresform=(<<RESFORM);
6156: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6157: $lt{'stpr'}</a>$help{'Course_Resource'}
6158: <form action="/adm/coursedocs" method="post" name="courseresform">
6159: <fieldset id="crsresform" style="display:none;">
6160: <legend>$lt{'stpr'}</legend>
6161: <input type="hidden" name="active" value="ee" />
6162: <p>
6163: $pickdir
6164: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6165: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6166:
1.611 raeburn 6167: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6168: </span><span id="newsubdir"></span>
6169: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6170: </p>
6171: $lt{'fnam'}
1.611 raeburn 6172: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6173: <p>
6174: <div id="newresource" style="display:$showtitle">
6175: $lt{'addp'}
1.611 raeburn 6176: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6177: $lt{'no'}</label>
1.611 raeburn 6178: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6179: $lt{'yes'}</label>
6180: <span id="newrestitle"></span>
1.611 raeburn 6181: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6182: </div>
6183: </p>
6184: <p>
6185: $lt{'uste'}
1.611 raeburn 6186: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6187: $lt{'no'}</label>
1.611 raeburn 6188: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6189: $lt{'yes'}</label>
6190: <div id="newrestemplate" style="display:none">
6191: $templates
6192: $templatepreview
6193: </div>
6194: </p>
6195: <span class="LC_nobreak">
6196: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6197: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6198: </span>
6199: </fieldset>
6200: </form>
6201:
6202: RESFORM
1.534 raeburn 6203:
1.342 ehlerst 6204: my $specialdocumentsform;
1.383 tempelho 6205: my @specialdocumentsforma;
1.451 www 6206: my $gradingform;
6207: my @gradingforma;
6208: my $communityform;
6209: my @communityforma;
1.351 ehlerst 6210: my $newfolderform;
1.390 tempelho 6211: my $newfolderb;
1.342 ehlerst 6212:
1.451 www 6213: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6214:
1.329 droeschl 6215: my $newpageform=(<<NPFORM);
6216: <form action="/adm/coursedocs" method="post" name="newpage">
6217: <input type="hidden" name="folderpath" value="$path" />
6218: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6219: <input type="hidden" name="active" value="ee" />
1.423 onken 6220: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6221: $help{'Adding_Pages'}
1.329 droeschl 6222: </form>
6223: NPFORM
1.390 tempelho 6224:
6225:
1.351 ehlerst 6226: $newfolderform=(<<NFFORM);
1.329 droeschl 6227: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6228: $pathitem
1.329 droeschl 6229: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6230: <input type="hidden" name="active" value="" />
1.422 onken 6231: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6232: </form>
6233: NFFORM
6234:
6235: my $newsylform=(<<NSYLFORM);
6236: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6237: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6238: $pathitem
1.329 droeschl 6239: <input type="hidden" name="importdetail"
6240: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6241: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6242: $help{'Syllabus'}
1.383 tempelho 6243:
1.329 droeschl 6244: </form>
6245: NSYLFORM
1.364 bisitz 6246:
1.329 droeschl 6247: my $newgroupfileform=(<<NGFFORM);
6248: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6249: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6250: $pathitem
1.329 droeschl 6251: <input type="hidden" name="importdetail"
6252: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6253: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6254: $help{'Group Portfolio'}
1.329 droeschl 6255: </form>
6256: NGFFORM
1.383 tempelho 6257: @specialdocumentsforma=(
1.421 onken 6258: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.618 raeburn 6259: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6260: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6261: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6262: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6263: );
6264: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6265:
1.434 raeburn 6266:
6267: my @importdoc = (
1.519 raeburn 6268: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6269: );
1.598 raeburn 6270: if (keys(%ltitools)) {
6271: push(@importdoc,
1.627 ! raeburn 6272: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
1.598 raeburn 6273: );
6274: }
1.519 raeburn 6275: unless ($container eq 'page') {
6276: push(@importdoc,
6277: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6278: );
6279: }
6280: push(@importdoc,
1.558 raeburn 6281: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6282: );
1.501 raeburn 6283: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6284:
1.451 www 6285: @gradingforma=(
6286: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6287: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6288: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6289: {'<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 6290: );
6291: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6292:
6293: @communityforma=(
6294: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6295: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6296: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6297: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6298: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6299: );
6300: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6301:
1.330 tempelho 6302: my %orderhash = (
1.553 raeburn 6303: 'aa' => ['Upload',$fileuploadform],
6304: 'bb' => ['Import',$importpubform],
6305: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6306: );
1.519 raeburn 6307: unless ($container eq 'page') {
1.434 raeburn 6308: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6309: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6310: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6311: }
6312:
1.341 ehlerst 6313: $hadchanges=0;
1.484 raeburn 6314: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6315: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6316: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6317: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6318: undef($navmap);
1.443 www 6319: if ($error) {
6320: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6321: }
6322: if ($hadchanges) {
6323: &mark_hash_old();
6324: }
1.341 ehlerst 6325:
1.443 www 6326: &changewarning($r,'');
6327: }
1.458 raeburn 6328: }
1.442 www 6329:
1.443 www 6330: # Supplemental documents start here
6331:
1.329 droeschl 6332: my $folder=$env{'form.folder'};
1.443 www 6333: unless ($supplementalflag) {
1.329 droeschl 6334: $folder='supplemental';
6335: }
6336: if ($folder =~ /^supplemental$/ &&
6337: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6338: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6339: } elsif ($allowed) {
1.356 tempelho 6340: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6341: }
1.508 raeburn 6342: $pathitem = '<input type="hidden" name="folderpath" value="'.
6343: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6344: if ($allowed) {
6345: my $folderseq=
1.504 raeburn 6346: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6347:
6348: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6349: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6350: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6351: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6352: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6353: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6354: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6355: $fileupload
6356: <br />
6357: <br />
6358: <span class="LC_nobreak">
6359: $checkbox
6360: </span>
6361: <br /><br />
6362: $lt{'comment'}:<br />
1.383 tempelho 6363: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6364: <br />
1.508 raeburn 6365: $pathitem
1.329 droeschl 6366: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6367: <input type='submit' value="$lt{'upld'}" />
6368: </form>
1.329 droeschl 6369: SUPDOCFORM
6370:
6371: my $supnewfolderform=(<<SNFFORM);
6372: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6373: <input type="hidden" name="active" value="" />
1.508 raeburn 6374: $pathitem
1.329 droeschl 6375: <input type="hidden" name="importdetail" value="" />
1.423 onken 6376: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6377: $help{'Adding_Folders'}
1.329 droeschl 6378: </form>
6379: SNFFORM
1.383 tempelho 6380:
1.510 raeburn 6381: my $supextform =
6382: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6383: $help{'Adding_External_Resource'},
6384: undef,undef,undef,undef,undef,undef,
6385: $disabled);
1.329 droeschl 6386:
1.598 raeburn 6387: my $supexttoolform =
6388: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6389: $help{'Adding_External_Tool'},
6390: undef,undef,'tool',$coursedom,
1.611 raeburn 6391: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6392:
1.329 droeschl 6393: my $supnewsylform=(<<SNSFORM);
6394: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6395: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6396: $pathitem
1.329 droeschl 6397: <input type="hidden" name="importdetail"
6398: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6399: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6400: $help{'Syllabus'}
6401: </form>
6402: SNSFORM
6403:
6404: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6405: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6406: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6407: $pathitem
1.329 droeschl 6408: <input type="hidden" name="importdetail"
6409: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6410: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6411: $help{'My Personal Information Page'}
1.329 droeschl 6412: </form>
6413: SNAMFORM
6414:
1.534 raeburn 6415: my $supwebpage;
6416: if ($folder =~ /^supplemental_?(\d*)$/) {
6417: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6418: if ($1) {
6419: $supwebpage .= $1;
6420: } else {
6421: $supwebpage .= 'default';
6422: }
6423: $supwebpage .= '/new.html';
6424: }
6425: my $supwebpageform =(<<SWEBFORM);
6426: <form action="/adm/coursedocs" method="post" name="supwebpage">
6427: <input type="hidden" name="active" value="cc" />
6428: $pathitem
6429: <input type="hidden" name="importdetail" value="$supwebpage" />
6430: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6431: $help{'Web_Page'}
1.534 raeburn 6432: </form>
6433: SWEBFORM
6434:
1.333 muellerd 6435:
1.383 tempelho 6436: my @specialdocs = (
1.618 raeburn 6437: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6438: =>$supnewsylform},
1.611 raeburn 6439: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6440: =>$supnewaboutmeform},
1.534 raeburn 6441: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6442:
1.383 tempelho 6443: );
1.417 droeschl 6444: my @supimportdoc = (
1.515 raeburn 6445: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6446: =>$supextform});
6447: if (keys(%ltitools)) {
6448: push(@supimportdoc,
1.627 ! raeburn 6449: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
1.598 raeburn 6450: =>$supexttoolform});
6451: }
6452: push(@supimportdoc,
6453: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6454: =>$supupdocform},
1.598 raeburn 6455: );
1.501 raeburn 6456:
6457: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6458: my %suporderhash = (
1.390 tempelho 6459: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6460: 'ee' => ['Upload',$supupdocform],
6461: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6462: );
1.443 www 6463: if ($supplementalflag) {
1.458 raeburn 6464: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6465: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6466: \%ltitools,$canedit,$hostname);
1.443 www 6467: if ($error) {
6468: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6469: } else {
6470: if ($suppchanges) {
6471: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6472: my @ids=&Apache::lonnet::current_machine_ids();
6473: foreach my $server (keys(%servers)) {
6474: next if (grep(/^\Q$server\E$/,@ids));
6475: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6476: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6477: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6478: }
6479: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6480: undef($suppchanges);
6481: }
6482: }
1.393 raeburn 6483: }
1.443 www 6484: } elsif ($supplementalflag) {
1.458 raeburn 6485: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6486: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6487: if ($error) {
6488: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6489: }
1.393 raeburn 6490: }
1.389 tempelho 6491:
1.510 raeburn 6492: if ($needs_end) {
6493: $r->print(&endContentScreen());
6494: }
1.383 tempelho 6495:
1.329 droeschl 6496: if ($allowed) {
6497: $r->print('
6498: <form method="post" name="extimport" action="/adm/coursedocs">
6499: <input type="hidden" name="title" />
6500: <input type="hidden" name="url" />
6501: <input type="hidden" name="useform" />
6502: <input type="hidden" name="residx" />
6503: </form>');
6504: }
1.484 raeburn 6505: } elsif ($showdoc) {
1.329 droeschl 6506: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6507: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6508: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6509: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6510: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6511: }
6512: }
1.606 raeburn 6513: unless ($noendpage) {
6514: $r->print(&Apache::loncommon::end_page());
6515: }
1.329 droeschl 6516: return OK;
1.364 bisitz 6517: }
1.329 droeschl 6518:
1.440 raeburn 6519: sub embedded_form_elems {
6520: my ($phase,$primaryurl,$newidx) = @_;
6521: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6522: return <<STATE;
6523: <input type="hidden" name="folderpath" value="$folderpath" />
6524: <input type="hidden" name="cmd" value="upload_embedded" />
6525: <input type="hidden" name="newidx" value="$newidx" />
6526: <input type="hidden" name="phase" value="$phase" />
6527: <input type="hidden" name="primaryurl" value="$primaryurl" />
6528: STATE
6529: }
6530:
6531: sub embedded_destination {
6532: my $folder=$env{'form.folder'};
6533: my $destination = 'docs/';
6534: if ($folder =~ /^supplemental/) {
6535: $destination = 'supplemental/';
6536: }
6537: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6538: $destination .= 'default/';
6539: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6540: $destination .= $2.'/';
6541: }
6542: $destination .= $env{'form.newidx'};
6543: my $dir_root = '/userfiles';
6544: return ($destination,$dir_root);
6545: }
6546:
6547: sub return_to_editor {
6548: my $actionurl = '/adm/coursedocs';
6549: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6550: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6551: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6552: '</a></p>';
6553: }
6554:
1.476 raeburn 6555: sub decompression_info {
6556: my ($destination,$dir_root) = &embedded_destination();
6557: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6558: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6559: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6560: my $container='sequence';
1.480 raeburn 6561: my ($pathitem,$hiddenelem);
1.583 raeburn 6562: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6563: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6564: $container='page';
6565: }
1.480 raeburn 6566: unshift(@hiddens,$pathitem);
6567: foreach my $item (@hiddens) {
6568: if ($env{'form.'.$item}) {
6569: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6570: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6571: }
1.477 raeburn 6572: }
1.476 raeburn 6573: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6574: $hiddenelem);
6575: }
6576:
6577: sub decompression_phase_one {
6578: my ($dir,$file,$warning,$error,$output);
6579: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6580: &decompression_info();
1.490 raeburn 6581: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6582: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6583: } else {
6584: my $file = $1;
1.481 raeburn 6585: $output =
6586: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6587: $destination,$dir_root,
6588: $hiddenelem);
6589: if ($env{'form.autoextract_camtasia'}) {
6590: $output .= &remove_archive($docudom,$docuname,$container);
6591: }
1.476 raeburn 6592: }
6593: if ($error) {
6594: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6595: $error.'</p>'."\n";
6596: }
6597: if ($warning) {
6598: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6599: }
6600: return $output;
6601: }
6602:
6603: sub decompression_phase_two {
6604: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6605: &decompression_info();
1.481 raeburn 6606: my $output;
1.480 raeburn 6607: if ($env{'form.archivedelete'}) {
1.481 raeburn 6608: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6609: }
6610: $output .=
1.481 raeburn 6611: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6612: $destination,$dir_root,$hiddenelem);
6613: return $output;
6614: }
6615:
1.480 raeburn 6616: sub remove_archive {
6617: my ($docudom,$docuname,$container) = @_;
6618: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6619: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6620: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6621: if ($fatal) {
6622: if ($container eq 'page') {
6623: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6624: } else {
6625: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6626: }
1.583 raeburn 6627: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6628: } else {
6629: my $currcmd = $env{'form.cmd'};
6630: my $position = $env{'form.position'};
1.583 raeburn 6631: my $archiveidx = $position;
1.563 raeburn 6632: if ($position > 0) {
1.583 raeburn 6633: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6634: $archiveidx = $position-1;
6635: }
6636: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6637: my ($title,$url,@rrest) =
1.583 raeburn 6638: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6639: if ($url eq $env{'form.archiveurl'}) {
6640: if (&handle_edit_cmd($docuname,$docudom)) {
6641: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6642: if ($fatal) {
6643: if ($container eq 'page') {
6644: $delwarning = &mt('An error occurred updating the contents of the current page.');
6645: } else {
6646: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6647: }
1.480 raeburn 6648: } else {
1.583 raeburn 6649: $delresult = &mt('Archive file removed.');
1.480 raeburn 6650: }
6651: }
1.583 raeburn 6652: } else {
6653: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6654: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6655: }
6656: }
6657: $env{'form.cmd'} = $currcmd;
6658: }
6659: if ($delwarning) {
6660: $output = '<p class="LC_warning">'.
6661: $delwarning.
6662: '</p>';
6663: }
6664: if ($delresult) {
6665: $output .= '<p class="LC_info">'.
6666: $delresult.
6667: '</p>';
6668: }
1.481 raeburn 6669: return $output;
1.480 raeburn 6670: }
6671:
1.484 raeburn 6672: sub generate_admin_menu {
1.611 raeburn 6673: my ($crstype,$canedit) = @_;
1.484 raeburn 6674: my $lc_crstype = lc($crstype);
6675: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6676: my %lt= ( # do not translate here
1.484 raeburn 6677: 'vc' => 'Verify Content',
6678: 'cv' => 'Check/Set Resource Versions',
6679: 'ls' => 'List Resource Identifiers',
6680: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6681: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6682: );
1.484 raeburn 6683: my ($candump,$dumpurl);
6684: if ($home + $other > 0) {
6685: $candump = 'F';
6686: if ($home) {
6687: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6688: } else {
6689: my @hosts;
6690: foreach my $aurole (keys(%outhash)) {
6691: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6692: push(@hosts,$outhash{$aurole});
1.538 raeburn 6693: }
1.484 raeburn 6694: }
6695: if (@hosts == 1) {
6696: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6697: '&role='.
6698: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6699: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6700: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6701: } else {
6702: $dumpurl = "javascript:choose_switchserver_window()";
6703: }
6704: }
6705: }
6706: my @menu=
6707: ({ categorytitle=>'Administration',
6708: items =>[
6709: { linktext => $lt{'vc'},
6710: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6711: permission => 'F',
1.571 raeburn 6712: help => 'Docs_Verify_Content',
1.484 raeburn 6713: icon => 'verify.png',
6714: linktitle => 'Verify contents can be retrieved/rendered',
6715: },
6716: { linktext => $lt{'cv'},
6717: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6718: permission => 'F',
1.571 raeburn 6719: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6720: icon => 'resversion.png',
6721: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6722: },
6723: { linktext => $lt{'ls'},
6724: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6725: permission => 'F',
6726: #help => '',
6727: icon => 'symbs.png',
6728: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6729: },
6730: ]
1.611 raeburn 6731: });
6732: if ($canedit) {
6733: push(@menu,
1.484 raeburn 6734: { categorytitle=>'Export',
6735: items =>[
6736: { linktext => $lt{'imse'},
6737: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6738: permission => 'F',
6739: help => 'Docs_Export_Course_Docs',
6740: icon => 'imsexport.png',
6741: linktitle => $lt{'imse'},
6742: },
6743: { linktext => $lt{'dcd'},
6744: url => $dumpurl,
6745: permission => $candump,
1.571 raeburn 6746: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6747: icon => 'dump.png',
6748: linktitle => $lt{'dcd'},
6749: },
6750: ]
6751: });
1.611 raeburn 6752: }
1.484 raeburn 6753: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6754: '<input type="hidden" id="dummy" />'."\n".
6755: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6756: '</form>';
1.329 droeschl 6757: }
6758:
6759: sub generate_edit_table {
1.538 raeburn 6760: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6761: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6762: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6763: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6764: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6765: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6766: $activetab = $env{'form.active'};
6767: }
1.611 raeburn 6768: unless ($canedit) {
6769: $disabled = ' disabled="disabled"';
6770: }
1.472 raeburn 6771: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6772: my $backtext = &mt('Exit Editor');
1.458 raeburn 6773: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6774: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6775: '<li class="goback">'.
1.546 raeburn 6776: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6777: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6778: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6779: '<li>'.
6780: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6781: &mt('Undo Delete').'</a></li>'."\n";
6782: if ($env{'form.docslog'}) {
6783: $form .= '<li class="active">';
6784: } else {
6785: $form .= '<li>';
6786: }
6787: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6788: &mt('History').'</a></li>'."\n";
6789: if ($env{'form.docslog'}) {
6790: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6791: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6792: }
1.458 raeburn 6793: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6794: if($name ne '00'){
1.371 tempelho 6795: if($activetab eq '' || $activetab ne $name){
6796: $active = '';
6797: }elsif($activetab eq $name){
6798: $active = 'class="active"';
6799: }
1.458 raeburn 6800: $form .= '<li style="float:right" '.$active
1.484 raeburn 6801: .' 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 6802: } else {
1.570 raeburn 6803: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6804:
6805: }
1.329 droeschl 6806: }
1.484 raeburn 6807: $form .= '</ul>'."\n";
6808: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6809:
6810: if ($to_show ne '') {
1.538 raeburn 6811: my $saveform;
6812: if ($need_save) {
6813: my $button = &mt('Make changes');
6814: my $path;
6815: if ($env{'form.folderpath'}) {
6816: $path =
6817: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6818: }
6819: $saveform = <<"END";
6820: <div id="multisave" style="display:none; clear:both;" >
6821: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6822: <input type="hidden" name="folderpath" value="$path" />
6823: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6824: <input type="hidden" name="allhiddenresource" value="" />
6825: <input type="hidden" name="allencrypturl" value="" />
6826: <input type="hidden" name="allrandompick" value="" />
6827: <input type="hidden" name="allrandomorder" value="" />
6828: <input type="hidden" name="changeparms" value="" />
6829: <input type="hidden" name="multiremove" value="" />
6830: <input type="hidden" name="multicut" value="" />
6831: <input type="hidden" name="multicopy" value="" />
6832: <input type="hidden" name="multichange" value="" />
6833: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 6834: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 6835: </form>
6836: </div>
6837: END
6838: }
6839: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6840: }
1.363 ehlerst 6841: foreach my $field (keys(%orderhash)){
1.390 tempelho 6842: if($field ne '00'){
1.422 onken 6843: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6844: $active = 'style="display: none;float:left"';
1.422 onken 6845: }elsif($activetab eq $field){
1.458 raeburn 6846: $active = 'style="display:block;float:left"';
1.422 onken 6847: }
6848: $form .= '<div id="'.$field.$tid.'"'
6849: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6850: .'</div>'."\n";
1.363 ehlerst 6851: }
6852: }
1.484 raeburn 6853: unless ($env{'form.docslog'}) {
6854: $form .= '</div></div>'."\n";
6855: }
1.329 droeschl 6856: return $form;
6857: }
6858:
6859: sub editing_js {
1.622 raeburn 6860: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
6861: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 6862: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6863: p_mnf => 'Name of New Folder',
6864: t_mnf => 'New Folder',
6865: p_mnp => 'Name of New Page',
6866: t_mnp => 'New Page',
1.451 www 6867: p_mxu => 'Title for the External Score',
1.349 biermanm 6868: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6869: p_msb => 'Title for the Problem',
6870: p_mdb => 'Title for the Drop Box',
1.336 schafran 6871: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 6872: p_mwp => 'Title for Web Page',
1.606 raeburn 6873: p_mnr => 'Title for the Resource',
1.348 weissno 6874: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6875: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6876: p_mab_alrt1 => 'Not a valid user:domain',
6877: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6878: p_chn => 'New Title',
6879: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 6880: p_rmr2a => 'Remove',
6881: p_rmr2b => '?',
6882: p_rmr3a => 'Remove those',
6883: p_rmr3b => 'items?',
6884: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6885: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6886: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6887: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 6888: p_ctr2a => 'Cut',
6889: p_ctr2b => '?',
6890: p_ctr3a => 'Cut those',
6891: p_ctr3b => 'items?',
1.478 raeburn 6892: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6893: imsfile => 'You must choose an IMS package for import',
6894: imscms => 'You must select which Course Management System was the source of the IMS package',
6895: invurl => 'Invalid URL',
6896: titbl => 'Title is blank',
1.538 raeburn 6897: more => '(More ...)',
6898: less => '(Less ...)',
1.543 raeburn 6899: noor => 'No actions selected or changes to settings specified.',
6900: noch => 'No changes to settings specified.',
6901: noac => 'No actions selected.',
1.606 raeburn 6902: nofi => 'No file selected',
6903: tinc => 'Title in course',
6904: sunm => 'Sub-directory name',
1.618 raeburn 6905: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6906: );
1.594 damieng 6907: &js_escape(\%js_lt);
1.433 raeburn 6908: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6909: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6910: my $main_container_page;
1.519 raeburn 6911: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6912: $main_container_page = 1;
1.434 raeburn 6913: }
1.617 raeburn 6914: my $backtourl;
6915: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6916: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6917:
1.530 raeburn 6918: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6919: my $caller = $1;
1.525 raeburn 6920: if ($caller =~ /^supplemental/) {
6921: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6922: } else {
6923: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6924: $res = &Apache::lonnet::clutter($res);
6925: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 6926: my ($url,$anchor);
6927: if ($res =~ /^([^#]+)#([^#]+)$/) {
6928: $url = $1;
6929: $anchor = $2;
6930: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6931: $caller = $1.&escape('#').$anchor;
6932: }
1.614 raeburn 6933: } else {
6934: $url = $res;
1.609 raeburn 6935: }
6936: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 6937: &HTML::Entities::encode($caller,'<>&"');
1.622 raeburn 6938: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6939: if (($ENV{'SERVER_PORT'} == 443) &&
6940: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6941: if ($hostname ne '') {
6942: $backtourl = 'http://'.$hostname.$backtourl;
6943: }
1.627 ! raeburn 6944: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 6945: }
1.623 raeburn 6946: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6947: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6948: $backtourl = 'http://'.$hostname.$backtourl;
6949: }
1.622 raeburn 6950: }
1.609 raeburn 6951: if ($anchor ne '') {
6952: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6953: }
1.590 raeburn 6954: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6955: } else {
6956: $backtourl = '/adm/navmaps';
1.525 raeburn 6957: }
6958: }
6959: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6960: $backtourl = '/adm/menu';
6961: } elsif ($supplementalflag) {
1.472 raeburn 6962: $backtourl = '/adm/supplemental';
1.525 raeburn 6963: } else {
6964: $backtourl = '/adm/navmaps';
1.472 raeburn 6965: }
6966:
1.600 raeburn 6967: my $fieldsets = "'ext','doc'";
6968: if ($posslti) {
6969: $fieldsets .= ",'tool'";
6970: }
1.519 raeburn 6971: unless ($main_container_page) {
6972: $fieldsets .=",'ims'";
6973: }
1.501 raeburn 6974: if ($supplementalflag) {
1.600 raeburn 6975: $fieldsets = "'suppext','suppdoc'";
6976: if ($posslti) {
6977: $fieldsets .= ",'supptool'";
6978: }
1.501 raeburn 6979: }
1.611 raeburn 6980:
6981: my $jsmakefunctions;
6982: if ($canedit) {
6983: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6984: function makenewfolder(targetform,folderseq) {
1.594 damieng 6985: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6986: if (foldername) {
6987: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6988: targetform.submit();
6989: }
6990: }
6991:
6992: function makenewpage(targetform,folderseq) {
1.594 damieng 6993: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6994: if (pagename) {
6995: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6996: targetform.submit();
6997: }
6998: }
6999:
7000: function makeexamupload() {
1.594 damieng 7001: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7002: if (title) {
1.329 droeschl 7003: this.document.forms.newexamupload.importdetail.value=
7004: escape(title)+'=/res/lib/templates/examupload.problem';
7005: this.document.forms.newexamupload.submit();
7006: }
7007: }
7008:
7009: function makesmppage() {
1.594 damieng 7010: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7011: if (title) {
1.329 droeschl 7012: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 7013: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7014: this.document.forms.newsmppg.submit();
7015: }
7016: }
7017:
1.534 raeburn 7018: function makewebpage(type) {
1.594 damieng 7019: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7020: var formname;
7021: if (type == 'supp') {
7022: formname = this.document.forms.supwebpage;
7023: } else {
7024: formname = this.document.forms.newwebpage;
7025: }
7026: if (title) {
7027: var webpage = formname.importdetail.value;
7028: formname.importdetail.value = escape(title)+'='+webpage;
7029: formname.submit();
7030: }
7031: }
7032:
1.329 droeschl 7033: function makesmpproblem() {
1.594 damieng 7034: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7035: if (title) {
1.329 droeschl 7036: this.document.forms.newsmpproblem.importdetail.value=
7037: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7038: this.document.forms.newsmpproblem.submit();
7039: }
7040: }
7041:
7042: function makedropbox() {
1.594 damieng 7043: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7044: if (title) {
1.329 droeschl 7045: this.document.forms.newdropbox.importdetail.value=
7046: escape(title)+'=/res/lib/templates/DropBox.problem';
7047: this.document.forms.newdropbox.submit();
7048: }
7049: }
7050:
7051: function makebulboard() {
1.594 damieng 7052: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7053: if (title) {
7054: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7055: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7056: this.document.forms.newbul.submit();
7057: }
7058: }
7059:
7060: function makeabout() {
1.594 damieng 7061: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7062: if (user) {
7063: var comp=new Array();
7064: comp=user.split(':');
7065: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7066: if ((comp[0]) && (comp[1])) {
7067: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7068: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7069: this.document.forms.newaboutsomeone.submit();
7070: } else {
7071: alert("$js_lt{'p_mab_alrt1'}");
7072: }
7073: } else {
7074: alert("$js_lt{'p_mab_alrt2'}");
7075: }
7076: }
7077: }
7078:
7079: function makenew(targetform) {
7080: targetform.submit();
7081: }
7082:
7083: function changename(folderpath,index,oldtitle) {
7084: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7085: if (title) {
7086: this.document.forms.renameform.markcopy.value='';
7087: this.document.forms.renameform.title.value=title;
7088: this.document.forms.renameform.cmd.value='rename_'+index;
7089: this.document.forms.renameform.folderpath.value=folderpath;
7090: this.document.forms.renameform.submit();
7091: }
7092: }
7093:
7094: ENDNEWSCRIPT
7095: } else {
7096: $jsmakefunctions = <<ENDNEWSCRIPT;
7097:
7098: function makenewfolder() {
7099: alert("$js_lt{'edri'}");
7100: }
7101:
7102: function makenewpage() {
7103: alert("$js_lt{'edri'}");
7104: }
7105:
7106: function makeexamupload() {
7107: alert("$js_lt{'edri'}");
7108: }
7109:
7110: function makesmppage() {
7111: alert("$js_lt{'edri'}");
7112: }
7113:
7114: function makewebpage(type) {
7115: alert("$js_lt{'edri'}");
7116: }
7117:
7118: function makesmpproblem() {
7119: alert("$js_lt{'edri'}");
7120: }
7121:
7122: function makedropbox() {
7123: alert("$js_lt{'edri'}");
7124: }
7125:
7126: function makebulboard() {
7127: alert("$js_lt{'edri'}");
7128: }
7129:
7130: function makeabout() {
7131: alert("$js_lt{'edri'}");
7132: }
7133:
7134: function changename() {
7135: alert("$js_lt{'edri'}");
7136: }
7137:
7138: function makenew() {
7139: alert("$js_lt{'edri'}");
7140: }
7141:
7142: function groupimport() {
7143: alert("$js_lt{'edri'}");
1.335 ehlerst 7144: }
1.611 raeburn 7145:
7146: function groupsearch() {
7147: alert("$js_lt{'edri'}");
1.335 ehlerst 7148: }
1.611 raeburn 7149:
7150: function groupopen(url,recover) {
7151: var options="scrollbars=1,resizable=1,menubar=0";
7152: idxflag=1;
7153: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7154: idx.focus();
1.329 droeschl 7155: }
7156:
1.611 raeburn 7157: ENDNEWSCRIPT
7158:
7159: }
7160: return <<ENDSCRIPT;
7161:
7162: $jsmakefunctions
7163:
1.501 raeburn 7164: function toggleUpload(caller) {
7165: var blocks = Array($fieldsets);
7166: for (var i=0; i<blocks.length; i++) {
7167: var disp = 'none';
7168: if (caller == blocks[i]) {
7169: var curr = document.getElementById('upload'+caller+'form').style.display;
7170: if (curr == 'none') {
7171: disp='block';
7172: }
7173: }
7174: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7175: if ((caller == 'tool') || (caller == 'supptool')) {
7176: if (disp == 'block') {
7177: if (document.getElementById('LC_exttoolid')) {
7178: var toolselector = document.getElementById('LC_exttoolid');
7179: var suppflag = 0;
7180: if (caller == 'supptool') {
7181: suppflag = 1;
7182: }
7183: currForm = document.getElementById('new'+caller);
7184: updateExttool(toolselector,currForm,suppflag);
7185: }
7186: }
7187: }
1.501 raeburn 7188: }
1.502 raeburn 7189: resize_scrollbox('contentscroll','1','1');
7190: return;
7191: }
7192:
1.514 raeburn 7193: function toggleMap(caller) {
1.502 raeburn 7194: var disp = 'none';
1.510 raeburn 7195: if (document.getElementById('importmapform')) {
1.514 raeburn 7196: if (caller == 'map') {
7197: var curr = document.getElementById('importmapform').style.display;
7198: if (curr == 'none') {
7199: disp='block';
7200: }
1.510 raeburn 7201: }
7202: document.getElementById('importmapform').style.display=disp;
7203: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7204: }
1.501 raeburn 7205: return;
1.329 droeschl 7206: }
7207:
1.606 raeburn 7208: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7209: var disp = 'none';
7210: if (document.getElementById('crsresform')) {
7211: if (caller == 'res') {
7212: var curr = document.getElementById('crsresform').style.display;
7213: if (curr == 'none') {
7214: disp='block';
7215: numauthor = parseInt(numauthorrole);
7216: if (numauthor > 0) {
7217: document.courseresform.authorrole.selectedIndex = 0;
7218: select1priv_changed();
7219: document.courseresform.authorpath.selectedIndex = 0;
7220: document.courseresform.newresourceadd.selectedIndex = 0;
7221: toggleNewInCourse(document.courseresform);
7222: if (document.getElementById('newresource')) {
7223: document.getElementById('newresource').style.display = 'none';
7224: }
7225: } else {
7226: if (numcrsdirs) {
7227: document.courseresform.authorpath.selectedIndex = 0;
7228: }
7229: }
7230: if (document.courseresform.newresusetemp.length) {
7231: document.courseresform.newresusetemp[0].checked = true;
7232: toggleWithTemplate(document.courseresform);
7233: }
7234: document.courseresform.newresourcename.value = '';
7235: }
7236: }
7237: if (document.courseresform.newsubdir.length) {
7238: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7239: if (document.courseresform.newsubdir[j].value == 0) {
7240: document.courseresform.newsubdir[j].checked = true;
7241: }
7242: break;
7243: }
7244: if (document.getElementById('newsubdirname')) {
7245: document.getElementById('newsubdirname').type = "hidden";
7246: document.getElementById('newsubdirname').value = "";
7247: }
7248: if (document.getElementById('newsubdir')) {
7249: document.getElementById('newsubdir').innerHTML = "";
7250: }
7251: }
7252: document.getElementById('crsresform').style.display=disp;
7253: resize_scrollbox('contentscroll','1','0');
7254: }
7255: return;
7256: }
7257:
7258: function toggleNewsubdir(form) {
7259: if (form.newsubdir.length) {
7260: for (var j=0; j<form.newsubdir.length; j++) {
7261: if (form.newsubdir[j].checked) {
7262: if (document.getElementById('newsubdirname')) {
7263: if (form.newsubdir[j].value == '1') {
7264: document.getElementById('newsubdirname').type = "text";
7265: if (document.getElementById('newsubdir')) {
7266: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7267: }
7268: } else {
7269: document.getElementById('newsubdirname').type = "hidden";
7270: document.getElementById('newsubdirname').value = "";
7271: document.getElementById('newsubdir').innerHTML = "";
7272: }
7273: }
7274: break;
7275: }
7276: }
7277: }
7278: }
7279:
7280: function toggleCrsResTitle() {
7281: if (document.getElementById('newresource')) {
7282: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7283: document.getElementById('newresource').style.display = 'inline';
7284: document.courseresform.newresourceadd[0].checked = true;
7285: toggleNewInCourse(document.courseresform);
7286: } else {
7287: document.getElementById('newresource').style.display = 'none';
7288: }
7289: }
7290: }
7291:
7292: function toggleNewInCourse(form) {
7293: if (form.newresourceadd.length) {
7294: for (var i=0; i<form.newresourceadd.length; i++) {
7295: if (form.newresourceadd[i].checked) {
7296: if (document.getElementById('newresourcetitle')) {
7297: if (form.newresourceadd[i].value == '1') {
7298: document.getElementById('newresourcetitle').type = 'text';
7299: if (document.getElementById('newrestitle')) {
7300: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7301: }
7302: } else {
7303: document.getElementById('newresourcetitle').type = 'hidden';
7304: document.getElementById('newresourcetitle').value = '';
7305: if (document.getElementById('newrestitle')) {
7306: document.getElementById('newrestitle').innerHTML = '';
7307: }
7308: }
7309: }
7310: break;
7311: }
7312: }
7313: }
7314: }
7315:
7316: function toggleWithTemplate(form) {
7317: if (form.newresusetemp.length) {
7318: for (var i=0; i<form.newresusetemp.length; i++) {
7319: if (form.newresusetemp[i].checked) {
7320: if (document.getElementById('newrestemplate')) {
7321: if (form.newresusetemp[i].value == '1') {
7322: document.getElementById('newrestemplate').style.display = 'inline';
7323: toggleExampleText();
7324: } else {
7325: form.tempcategory.selectedIndex = 0;
7326: select1template_changed();
7327: document.getElementById('newrestemplate').style.display = 'none';
7328: }
7329: }
7330: }
7331: }
7332: }
7333: }
7334:
7335: function toggleExampleText() {
7336: if (document.getElementById('newresexample')) {
7337: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7338: if (url == '') {
7339: document.getElementById('newresexample').style.fontWeight = 'normal';
7340: } else {
7341: document.getElementById('newresexample').style.fontWeight = 'bold';
7342: }
7343: }
7344: }
7345:
7346: function getExample(width,height,scrolling,transparency) {
7347: var url;
7348: if (document.courseresform.newresusetemp.length) {
7349: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7350: if (document.courseresform.newresusetemp[i].checked) {
7351: if (document.courseresform.newresusetemp[i].value == '1') {
7352: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7353: if (url == '') {
7354: alert('Pick a category and template');
7355: } else {
7356: url = url.replace("$londocroot","");
7357: url += '?inhibitmenu=yes';
7358: }
7359: }
7360: break;
7361: }
7362: }
7363: }
7364: if (url != '') {
7365: openMyModal(url,width,height,scrolling,transparency,'');
7366: }
7367: }
7368:
7369: function toggleImportCrsres(caller,dircount) {
7370: var disp = 'none';
7371: if (document.getElementById('importcrsresform')) {
7372: if (caller == 'res') {
7373: var numdirs = parseInt(dircount);
7374: var curr = document.getElementById('importcrsresform').style.display;
7375: if (curr == 'none') {
7376: disp='block';
7377: if (numdirs > 1) {
7378: select1res_changed();
7379: }
7380: }
7381: }
7382: document.getElementById('importcrsresform').style.display=disp;
7383: resize_scrollbox('contentscroll','1','0');
7384: }
7385: return;
7386: }
7387:
1.501 raeburn 7388: function makeims(imsform) {
7389: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7390: alert("$js_lt{'imsfile'}");
1.501 raeburn 7391: return;
7392: }
7393: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7394: alert("$js_lt{'imscms'}");
1.501 raeburn 7395: return;
7396: }
7397: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7398: imsform.submit();
7399: }
7400:
1.478 raeburn 7401: function updatePick(targetform,index,caller) {
1.537 raeburn 7402: var pickitem;
7403: var picknumitem;
7404: var picknumtext;
7405: if (index == 'all') {
7406: pickitem = document.getElementById('randompickall');
7407: picknumitem = document.getElementById('rpicknumall');
7408: picknumtext = document.getElementById('rpicktextall');
7409: } else {
7410: pickitem = document.getElementById('randompick_'+index);
7411: picknumitem = document.getElementById('rpicknum_'+index);
7412: picknumtext = document.getElementById('randompicknum_'+index);
7413: }
1.478 raeburn 7414: if (pickitem.checked) {
1.594 damieng 7415: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7416: if (picknum == '' || picknum == null) {
7417: if (caller == 'check') {
7418: pickitem.checked=false;
1.537 raeburn 7419: if (index == 'all') {
7420: picknumtext.innerHTML = '';
7421: if (caller == 'link') {
7422: propagateState(targetform,'rpicknum');
7423: }
7424: } else {
1.538 raeburn 7425: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7426: }
1.478 raeburn 7427: }
7428: } else {
7429: picknum.toString();
7430: var regexdigit=/^\\d+\$/;
7431: if (regexdigit.test(picknum)) {
7432: picknumitem.value = picknum;
1.537 raeburn 7433: if (index == 'all') {
1.538 raeburn 7434: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7435: if (caller == 'link') {
7436: propagateState(targetform,'rpicknum');
7437: }
7438: } else {
7439: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7440: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7441: }
1.478 raeburn 7442: } else {
7443: if (caller == 'check') {
1.537 raeburn 7444: if (index == 'all') {
7445: picknumtext.innerHTML = '';
7446: if (caller == 'link') {
7447: propagateState(targetform,'rpicknum');
7448: }
7449: } else {
7450: pickitem.checked=false;
1.538 raeburn 7451: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7452: }
1.478 raeburn 7453: }
7454: return;
7455: }
7456: }
7457: } else {
1.537 raeburn 7458: picknumitem.value = '';
7459: picknumtext.innerHTML = '';
7460: if (index == 'all') {
7461: if (caller == 'link') {
7462: propagateState(targetform,'rpicknum');
7463: }
7464: } else {
1.538 raeburn 7465: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7466: }
7467: }
7468: }
7469:
7470: function propagateState(form,param) {
7471: if (document.getElementById(param+'all')) {
7472: var setcheck = 0;
7473: var rpick = 0;
7474: if (param == 'rpicknum') {
7475: if (document.getElementById('randompickall')) {
7476: if (document.getElementById('randompickall').checked) {
7477: if (document.getElementById('rpicknumall')) {
7478: rpick = document.getElementById('rpicknumall').value;
7479: }
7480: }
7481: }
7482: } else {
7483: if (document.getElementById(param+'all').checked) {
7484: setcheck = 1;
7485: }
7486: }
1.538 raeburn 7487: var allidxlist;
7488: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7489: if (document.getElementById('all'+param+'idx')) {
7490: allidxlist = document.getElementById('all'+param+'idx').value;
7491: }
7492: var actions = new Array ('remove','cut','copy');
7493: for (var i=0; i<actions.length; i++) {
7494: if (actions[i] != param) {
7495: if (document.getElementById(actions[i]+'all')) {
7496: document.getElementById(actions[i]+'all').checked = false;
7497: }
7498: }
7499: }
7500: }
1.537 raeburn 7501: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7502: allidxlist = form.allidx.value;
7503: }
7504: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7505: allidxlist = form.allmapidx.value;
7506: }
7507: if ((allidxlist != '') && (allidxlist != null)) {
7508: var allidxs = allidxlist.split(',');
7509: if (allidxs.length > 1) {
7510: for (var i=0; i<allidxs.length; i++) {
7511: if (document.getElementById(param+'_'+allidxs[i])) {
7512: if (param == 'rpicknum') {
7513: if (document.getElementById('randompick_'+allidxs[i])) {
7514: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7515: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7516: if (rpick > 0) {
7517: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7518: } else {
7519: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7520: }
7521: }
7522: }
7523: } else {
1.537 raeburn 7524: if (setcheck == 1) {
7525: document.getElementById(param+'_'+allidxs[i]).checked = true;
7526: } else {
7527: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7528: if (param == 'randompick') {
7529: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7530: }
1.537 raeburn 7531: }
7532: }
7533: }
7534: }
1.538 raeburn 7535: if (setcheck == 1) {
7536: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7537: var actions = new Array('copy','cut','remove');
7538: for (var i=0; i<actions.length; i++) {
7539: var otheractions;
7540: var otheridxs;
7541: if (actions[i] === param) {
7542: continue;
7543: } else {
7544: if (document.getElementById('all'+actions[i]+'idx')) {
7545: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7546: otheridxs = otheractions.split(',');
7547: if (otheridxs.length > 1) {
7548: for (var j=0; j<otheridxs.length; j++) {
7549: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7550: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7551: }
1.537 raeburn 7552: }
7553: }
7554: }
1.538 raeburn 7555: }
7556: }
7557: }
7558: }
7559: }
7560: }
7561: }
7562: return;
7563: }
7564:
1.603 raeburn 7565: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7566: var canedit = '$canedit';
7567: if (canedit == '') {
7568: alert("$js_lt{'edri'}");
7569: return;
7570: }
1.539 raeburn 7571: var dosettings;
7572: var doaction;
1.538 raeburn 7573: var control = document.togglemultsettings;
7574: if (context == 'actions') {
7575: control = document.togglemultactions;
1.539 raeburn 7576: doaction = 1;
7577: } else {
7578: dosettings = 1;
1.538 raeburn 7579: }
1.539 raeburn 7580: if (control) {
7581: if (control.showmultpick.length) {
7582: for (var i=0; i<control.showmultpick.length; i++) {
7583: if (control.showmultpick[i].checked) {
7584: if (control.showmultpick[i].value == 1) {
7585: if (context == 'settings') {
7586: dosettings = 0;
7587: } else {
7588: doaction = 0;
1.538 raeburn 7589: }
7590: }
7591: }
1.537 raeburn 7592: }
7593: }
1.539 raeburn 7594: }
7595: if (context == 'settings') {
7596: if (dosettings == 1) {
1.538 raeburn 7597: targetform.changeparms.value=param;
7598: targetform.submit();
7599: }
1.537 raeburn 7600: }
1.539 raeburn 7601: if (context == 'actions') {
7602: if (doaction == 1) {
7603: targetform.cmd.value=param+'_'+index;
7604: targetform.folderpath.value=folderpath;
7605: targetform.markcopy.value=idx+':'+param;
7606: targetform.copyfolder.value=folder+'.'+container;
7607: if (param == 'remove') {
1.603 raeburn 7608: var doremove = 0;
7609: if (skip_confirm) {
7610: if (confirm_removal) {
7611: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7612: doremove = 1;
7613: }
7614: } else {
7615: doremove = 1;
7616: }
7617: } else {
7618: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7619: doremove = 1;
7620: }
7621: }
7622: if (doremove) {
1.539 raeburn 7623: targetform.markcopy.value='';
7624: targetform.copyfolder.value='';
7625: targetform.submit();
7626: }
7627: }
7628: if (param == 'cut') {
1.594 damieng 7629: 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 7630: targetform.submit();
7631: return;
7632: }
7633: }
7634: if (param == 'copy') {
7635: targetform.submit();
7636: return;
7637: }
7638: targetform.markcopy.value='';
7639: targetform.copyfolder.value='';
7640: targetform.cmd.value='';
7641: targetform.folderpath.value='';
7642: return;
7643: } else {
7644: if (document.getElementById(param+'_'+idx)) {
7645: item = document.getElementById(param+'_'+idx);
7646: if (item.type == 'checkbox') {
7647: if (item.checked) {
7648: item.checked = false;
7649: } else {
7650: item.checked = true;
7651: singleCheck(item,idx,param);
7652: }
7653: }
7654: }
7655: }
7656: }
1.537 raeburn 7657: return;
7658: }
7659:
1.538 raeburn 7660: function singleCheck(caller,idx,action) {
7661: actions = new Array('cut','copy','remove');
7662: if (caller.checked) {
7663: for (var i=0; i<actions.length; i++) {
7664: if (actions[i] != action) {
7665: if (document.getElementById(actions[i]+'_'+idx)) {
7666: if (document.getElementById(actions[i]+'_'+idx).checked) {
7667: document.getElementById(actions[i]+'_'+idx).checked = false;
7668: }
1.537 raeburn 7669: }
7670: }
7671: }
1.478 raeburn 7672: }
1.537 raeburn 7673: return;
1.478 raeburn 7674: }
7675:
1.334 muellerd 7676: function unselectInactive(nav) {
1.335 ehlerst 7677: currentNav = document.getElementById(nav);
7678: currentLis = currentNav.getElementsByTagName('LI');
7679: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7680: if (currentLis[i].className == 'goback') {
7681: currentLis[i].className = 'goback';
7682: } else {
7683: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7684: currentLis[i].className = 'right';
1.472 raeburn 7685: } else {
1.374 tempelho 7686: currentLis[i].className = 'i';
1.472 raeburn 7687: }
7688: }
1.335 ehlerst 7689: }
1.332 tempelho 7690: }
7691:
1.334 muellerd 7692: function hideAll(current, nav, data) {
1.335 ehlerst 7693: unselectInactive(nav);
1.570 raeburn 7694: if (current) {
7695: if (current.className == 'right'){
7696: current.className = 'right active'
7697: } else {
7698: current.className = 'active';
7699: }
1.374 tempelho 7700: }
1.335 ehlerst 7701: currentData = document.getElementById(data);
7702: currentDivs = currentData.getElementsByTagName('DIV');
7703: for (i = 0; i < currentDivs.length; i++) {
7704: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7705: currentDivs[i].style.display = 'none';
1.330 tempelho 7706: }
7707: }
1.335 ehlerst 7708: }
1.330 tempelho 7709:
1.374 tempelho 7710: function openTabs(pageId) {
7711: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7712: if(tabnav.length > 2 ){
1.389 tempelho 7713: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7714: currentLis = currentNav.getElementsByTagName('LI');
7715: for(i = 0; i< currentLis.length; i++){
7716: if(currentLis[i].className == 'active') {
1.375 tempelho 7717: funcString = currentLis[i].onclick.toString();
7718: tab = funcString.split('"');
1.420 onken 7719: if(tab.length < 2) {
7720: tab = funcString.split("'");
7721: }
1.375 tempelho 7722: currentData = document.getElementById(tab[1]);
7723: currentData.style.display = 'block';
1.374 tempelho 7724: }
7725: }
7726: }
7727: }
7728:
1.334 muellerd 7729: function showPage(current, pageId, nav, data) {
1.570 raeburn 7730: currstate = current.className;
1.334 muellerd 7731: hideAll(current, nav, data);
1.375 tempelho 7732: openTabs(pageId);
1.334 muellerd 7733: unselectInactive(nav);
1.570 raeburn 7734: if ((currstate == 'active') || (currstate == 'right active')) {
7735: if (currstate == 'active') {
7736: current.className = '';
7737: } else {
7738: current.className = 'right';
7739: }
7740: activeTab = '';
7741: toggleUpload();
7742: toggleMap();
1.606 raeburn 7743: toggleCrsRes();
7744: toggleImportCrsres();
1.570 raeburn 7745: resize_scrollbox('contentscroll','1','0');
7746: return;
7747: } else {
7748: current.className = 'active';
7749: }
1.330 tempelho 7750: currentData = document.getElementById(pageId);
7751: currentData.style.display = 'block';
1.458 raeburn 7752: activeTab = pageId;
1.501 raeburn 7753: toggleUpload();
1.503 raeburn 7754: toggleMap();
1.606 raeburn 7755: toggleCrsRes();
7756: toggleImportCrsres();
1.433 raeburn 7757: if (nav == 'mainnav') {
7758: var storedpath = "$docs_folderpath";
1.434 raeburn 7759: var storedpage = "$main_container_page";
1.433 raeburn 7760: var reg = new RegExp("^supplemental");
7761: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7762: if (storedpage == 1) {
7763: document.simpleedit.folderpath.value = '';
7764: document.uploaddocument.folderpath.value = '';
7765: } else {
7766: if (reg.test(storedpath)) {
7767: document.simpleedit.folderpath.value = '$toplevelmain';
7768: document.uploaddocument.folderpath.value = '$toplevelmain';
7769: document.newext.folderpath.value = '$toplevelmain';
7770: } else {
7771: document.simpleedit.folderpath.value = storedpath;
7772: document.uploaddocument.folderpath.value = storedpath;
7773: document.newext.folderpath.value = storedpath;
7774: }
1.433 raeburn 7775: }
7776: } else {
1.434 raeburn 7777: if (reg.test(storedpath)) {
7778: document.simpleedit.folderpath.value = storedpath;
7779: document.supuploaddocument.folderpath.value = storedpath;
7780: document.supnewext.folderpath.value = storedpath;
7781: } else {
1.433 raeburn 7782: document.simpleedit.folderpath.value = '$toplevelsupp';
7783: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7784: document.supnewext.folderpath.value = '$toplevelsupp';
7785: }
7786: }
7787: }
1.485 raeburn 7788: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7789: return false;
7790: }
1.329 droeschl 7791:
1.472 raeburn 7792: function toContents(jumpto) {
7793: var newurl = '$backtourl';
1.525 raeburn 7794: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7795: newurl = newurl+'?postdata='+jumpto;
7796: }
7797: location.href=newurl;
7798: }
7799:
1.538 raeburn 7800: function togglePick(caller,value) {
7801: var disp = 'none';
7802: if (document.getElementById('multi'+caller)) {
7803: var curr = document.getElementById('multi'+caller).style.display;
7804: if (value == 1) {
7805: disp='block';
7806: }
7807: if (curr == disp) {
7808: return;
7809: }
7810: document.getElementById('multi'+caller).style.display=disp;
7811: if (value == 1) {
1.594 damieng 7812: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7813: } else {
7814: document.getElementById('more'+caller).innerHTML = '';
7815: }
7816: if (caller == 'actions') {
7817: setClass(value);
7818: setBoxes(value);
7819: }
7820: }
7821: var showButton = multiSettings();
7822: if (showButton != 1) {
7823: showButton = multiActions();
7824: }
7825: if (document.getElementById('multisave')) {
7826: if (showButton == 1) {
7827: document.getElementById('multisave').style.display='block';
7828: } else {
7829: document.getElementById('multisave').style.display='none';
7830: }
7831: }
7832: resize_scrollbox('contentscroll','1','1');
7833: return;
7834: }
7835:
7836: function toggleCheckUncheck(caller,more) {
7837: if (more == 1) {
1.594 damieng 7838: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 7839: document.getElementById('allfields'+caller).style.display='block';
7840: } else {
1.594 damieng 7841: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7842: document.getElementById('allfields'+caller).style.display='none';
7843: }
7844: resize_scrollbox('contentscroll','1','1');
7845: }
7846:
7847: function multiSettings() {
7848: var inuse = 0;
7849: var settingsform = document.togglemultsettings;
7850: if (settingsform.showmultpick.length > 1) {
7851: for (var i=0; i<settingsform.showmultpick.length; i++) {
7852: if (settingsform.showmultpick[i].checked) {
7853: if (settingsform.showmultpick[i].value == 1) {
7854: inuse = 1;
7855: }
7856: }
7857: }
7858: }
7859: return inuse;
7860: }
7861:
7862: function multiActions() {
7863: var inuse = 0;
7864: var actionsform = document.togglemultactions;
7865: if (actionsform.showmultpick.length > 1) {
7866: for (var i=0; i<actionsform.showmultpick.length; i++) {
7867: if (actionsform.showmultpick[i].checked) {
7868: if (actionsform.showmultpick[i].value == 1) {
7869: inuse = 1;
7870: }
7871: }
7872: }
7873: }
7874: return inuse;
7875: }
7876:
7877: function checkSubmits() {
7878: var numchanges = 0;
7879: var form = document.saveactions;
7880: var doactions = multiActions();
1.542 raeburn 7881: var cutwarnings = 0;
7882: var remwarnings = 0;
1.603 raeburn 7883: var removalinfo = 0;
1.538 raeburn 7884: if (doactions == 1) {
7885: var remidxlist = document.cumulativeactions.allremoveidx.value;
7886: if ((remidxlist != '') && (remidxlist != null)) {
7887: var remidxs = remidxlist.split(',');
7888: for (var i=0; i<remidxs.length; i++) {
7889: if (document.getElementById('remove_'+remidxs[i])) {
7890: if (document.getElementById('remove_'+remidxs[i]).checked) {
7891: form.multiremove.value += remidxs[i]+',';
7892: numchanges ++;
1.542 raeburn 7893: if (document.getElementById('skip_remove_'+remidxs[i])) {
7894: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7895: remwarnings ++;
7896: }
7897: }
1.603 raeburn 7898: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7899: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7900: removalinfo ++;
7901: }
7902: }
1.537 raeburn 7903: }
7904: }
1.538 raeburn 7905: }
7906: }
7907: var cutidxlist = document.cumulativeactions.allcutidx.value;
7908: if ((cutidxlist != '') && (cutidxlist != null)) {
7909: var cutidxs = cutidxlist.split(',');
7910: for (var i=0; i<cutidxs.length; i++) {
7911: if (document.getElementById('cut_'+cutidxs[i])) {
7912: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7913: form.multicut.value += cutidxs[i]+',';
7914: numchanges ++;
1.542 raeburn 7915: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7916: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7917: cutwarnings ++;
7918: }
7919: }
1.537 raeburn 7920: }
7921: }
7922: }
7923: }
1.538 raeburn 7924: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7925: if ((copyidxlist != '') && (copyidxlist != null)) {
7926: var copyidxs = copyidxlist.split(',');
7927: for (var i=0; i<copyidxs.length; i++) {
7928: if (document.getElementById('copy_'+copyidxs[i])) {
7929: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7930: form.multicopy.value += copyidxs[i]+',';
7931: numchanges ++;
7932: }
7933: }
7934: }
7935: }
7936: if (numchanges > 0) {
7937: form.multichange.value = numchanges;
7938: }
1.537 raeburn 7939: }
1.538 raeburn 7940: var dosettings = multiSettings();
1.543 raeburn 7941: var haschanges = 0;
1.538 raeburn 7942: if (dosettings == 1) {
7943: form.allencrypturl.value = '';
7944: form.allhiddenresource.value = '';
1.543 raeburn 7945: form.changeparms.value = 'all';
7946: var patt=new RegExp(",\$");
1.538 raeburn 7947: var allidxlist = document.cumulativesettings.allidx.value;
7948: if ((allidxlist != '') && (allidxlist != null)) {
7949: var allidxs = allidxlist.split(',');
7950: if (allidxs.length > 1) {
7951: for (var i=0; i<allidxs.length; i++) {
7952: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7953: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7954: form.allhiddenresource.value += allidxs[i]+',';
7955: }
7956: }
7957: if (document.getElementById('encrypturl_'+allidxs[i])) {
7958: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7959: form.allencrypturl.value += allidxs[i]+',';
7960: }
7961: }
7962: }
1.543 raeburn 7963: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7964: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 7965: }
1.538 raeburn 7966: }
7967: form.allrandompick.value = '';
7968: form.allrandomorder.value = '';
7969: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7970: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7971: var allmapidxs = allmapidxlist.split(',');
7972: for (var i=0; i<allmapidxs.length; i++) {
7973: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7974: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7975: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7976: if ((randompick.checked) && (rpicknum.value != '')) {
7977: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7978: }
7979: if (randorder.checked) {
7980: form.allrandomorder.value += allmapidxs[i]+',';
7981: }
1.537 raeburn 7982: }
1.543 raeburn 7983: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7984: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7985: }
7986: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7987: haschanges = 1;
7988: }
7989: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7990: haschanges = 1;
7991: }
7992: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7993: haschanges = 1;
7994: }
7995: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7996: haschanges = 1;
1.537 raeburn 7997: }
7998: }
1.543 raeburn 7999: if (doactions == 1) {
1.542 raeburn 8000: if (numchanges > 0) {
1.603 raeburn 8001: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8002: if (remwarnings > 0) {
1.594 damieng 8003: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8004: return false;
8005: }
8006: }
1.603 raeburn 8007: if (removalinfo > 0) {
8008: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8009: return false;
8010: }
8011: }
1.542 raeburn 8012: if (cutwarnings > 0) {
1.594 damieng 8013: 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 8014: return false;
8015: }
8016: }
8017: }
8018: form.submit();
8019: return true;
1.543 raeburn 8020: }
8021: }
8022: if (dosettings == 1) {
8023: if (haschanges == 1) {
1.542 raeburn 8024: form.submit();
8025: return true;
8026: }
1.543 raeburn 8027: }
8028: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8029: alert("$js_lt{'noor'}");
1.543 raeburn 8030: } else {
8031: if (dosettings == 1) {
1.594 damieng 8032: alert("$js_lt{'noch'}");
1.543 raeburn 8033: } else {
1.594 damieng 8034: alert("$js_lt{'noac'}");
1.543 raeburn 8035: }
8036: }
1.538 raeburn 8037: return false;
8038: }
8039:
8040: function setClass(value) {
8041: var cutclass = 'LC_docs_cut';
8042: var copyclass = 'LC_docs_copy';
8043: var removeclass = 'LC_docs_remove';
8044: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8045: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8046: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8047: var links = document.getElementsByTagName('a');
8048: for (var i=0; i<links.length; i++) {
8049: var classes = links[i].className;
8050: if (cutreg.test(classes)) {
8051: links[i].className = cutclass;
8052: if (value == 1) {
8053: links[i].className += " LC_menubuttons_link";
8054: }
8055: } else {
8056: if (copyreg.test(classes)) {
8057: links[i].className = copyclass;
8058: if (value == 1) {
8059: links[i].className += " LC_menubuttons_link";
8060: }
8061: } else {
8062: if (removereg.test(classes)) {
8063: links[i].className = removeclass;
8064: if (value == 1) {
8065: links[i].className += " LC_menubuttons_link";
8066: }
8067: }
8068: }
8069: }
8070: }
8071: return;
1.537 raeburn 8072: }
8073:
1.538 raeburn 8074: function setBoxes(value) {
8075: var remidxlist = document.cumulativeactions.allremoveidx.value;
8076: if ((remidxlist != '') && (remidxlist != null)) {
8077: var remidxs = remidxlist.split(',');
8078: for (var i=0; i<remidxs.length; i++) {
8079: if (document.getElementById('remove_'+remidxs[i])) {
8080: var item = document.getElementById('remove_'+remidxs[i]);
8081: if (value == 1) {
8082: item.className = 'LC_docs_remove';
8083: } else {
8084: item.className = 'LC_hidden';
8085: }
8086: }
8087: }
8088: }
8089: var cutidxlist = document.cumulativeactions.allcutidx.value;
8090: if ((cutidxlist != '') && (cutidxlist != null)) {
8091: var cutidxs = cutidxlist.split(',');
8092: for (var i=0; i<cutidxs.length; i++) {
8093: if (document.getElementById('cut_'+cutidxs[i])) {
8094: var item = document.getElementById('cut_'+cutidxs[i]);
8095: if (value == 1) {
8096: item.className = 'LC_docs_cut';
8097: } else {
8098: item.className = 'LC_hidden';
8099: }
8100: }
1.537 raeburn 8101: }
8102: }
1.538 raeburn 8103: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8104: if ((copyidxlist != '') && (copyidxlist != null)) {
8105: var copyidxs = copyidxlist.split(',');
8106: for (var i=0; i<copyidxs.length; i++) {
8107: if (document.getElementById('copy_'+copyidxs[i])) {
8108: var item = document.getElementById('copy_'+copyidxs[i]);
8109: if (value == 1) {
8110: item.className = 'LC_docs_copy';
8111: } else {
8112: item.className = 'LC_hidden';
8113: }
8114: }
1.537 raeburn 8115: }
8116: }
8117: return;
8118: }
8119:
1.606 raeburn 8120: function validImportCrsRes() {
8121: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8122: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8123: if ((fname == '') || (fname == null)) {
8124: alert("$js_lt{'nofi'}");
8125: return false;
8126: }
8127: var url = '/res/$coursedom/$coursenum/';
8128: if (path && path != '/') {
8129: url += path+'/';
8130: }
8131: if (fname != '') {
8132: url += fname;
8133: }
8134: var title = document.crsresimportform.crsrestitle.value;
8135: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8136: return true;
8137: }
8138:
8139: function validateNewRes(caller) {
8140: if (caller == 'single') {
8141: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8142: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8143: var resname = document.courseresform.newresourcename.value;
8144: }
8145: }
8146:
1.611 raeburn 8147: ENDSCRIPT
1.329 droeschl 8148: }
1.457 raeburn 8149:
1.483 raeburn 8150: sub history_tab_js {
8151: return <<"ENDHIST";
8152: function toggleHistoryDisp(choice) {
8153: document.docslogform.docslog.value = choice;
8154: document.docslogform.submit();
8155: return;
8156: }
8157:
8158: ENDHIST
8159: }
8160:
1.484 raeburn 8161: sub inject_data_js {
8162: return <<ENDINJECT;
8163:
8164: function injectData(current, hiddenField, name, value) {
8165: currentElement = document.getElementById(hiddenField);
8166: currentElement.name = name;
8167: currentElement.value = value;
8168: current.submit();
8169: }
8170:
8171: ENDINJECT
8172: }
8173:
8174: sub dump_switchserver_js {
8175: my @hosts = @_;
1.594 damieng 8176: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8177: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8178: swit => 'Switch server?',
1.594 damieng 8179: );
8180: my %html_js_lt = &Apache::lonlocal::texthash(
8181: swit => 'Switch server?',
1.568 raeburn 8182: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8183: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8184: chos => 'Choose server',
8185: );
1.594 damieng 8186: &js_escape(\%js_lt);
8187: &html_escape(\%html_js_lt);
8188: &js_escape(\%html_js_lt);
1.484 raeburn 8189: my $role = $env{'request.role'};
8190: my $js = <<"ENDSWJS";
8191: <script type="text/javascript">
8192: function write_switchserver() {
8193: var server;
8194: if (document.setserver.posshosts.length > 0) {
8195: for (var i=0; i<document.setserver.posshosts.length; i++) {
8196: if (document.setserver.posshosts[i].checked) {
8197: server = document.setserver.posshosts[i].value;
8198: }
8199: }
8200: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8201: }
8202: window.close();
8203: }
8204: </script>
8205:
8206: ENDSWJS
8207:
8208: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8209: {'only_body' => 1,
8210: 'js_ready' => 1,});
8211: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8212:
8213: my $hostpicker;
8214: my $count = 0;
8215: foreach my $host (sort(@hosts)) {
8216: my $checked;
8217: if ($count == 0) {
8218: $checked = ' checked="checked"';
8219: }
8220: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8221: $host.'"'.$checked.' />'.$host.'</label> ';
8222: $count++;
8223: }
8224:
8225: return <<"ENDSWITCHJS";
8226:
8227: function dump_needs_switchserver(url) {
8228: if (url!='' && url!= null) {
1.594 damieng 8229: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8230: go(url);
8231: }
8232: }
8233: return;
8234: }
8235:
8236: function choose_switchserver_window() {
8237: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8238: newWindow.document.open();
8239: newWindow.document.writeln('$startpage');
1.594 damieng 8240: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8241: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8242: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8243: '<form name="setserver" method="post" action="" \\/>\\n'+
8244: '$hostpicker\\n'+
8245: '<br \\/><br \\/>\\n'+
1.594 damieng 8246: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8247: 'onclick="write_switchserver();" \\/>\\n'+
8248: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8249: newWindow.document.writeln('$endpage');
8250: newWindow.document.close();
8251: newWindow.focus();
8252: }
8253:
8254: ENDSWITCHJS
8255: }
8256:
8257: sub makedocslogform {
8258: my ($formelems,$docslog) = @_;
8259: return <<"LOGSFORM";
8260: <form action="/adm/coursedocs" method="post" name="docslogform">
8261: <input type="hidden" name="docslog" value="$docslog" />
8262: $formelems
8263: </form>
8264: LOGSFORM
8265: }
8266:
8267: sub makesimpleeditform {
8268: my ($formelems) = @_;
8269: return <<"SIMPFORM";
8270: <form name="simpleedit" method="post" action="/adm/coursedocs">
8271: <input type="hidden" name="importdetail" value="" />
8272: $formelems
8273: </form>
8274: SIMPFORM
8275: }
8276:
1.606 raeburn 8277: sub makenewproblem {
8278: my ($r,$coursedom,$coursenum) = @_;
8279: # Creating a new problem
8280: my ($redirect,$error);
8281: if ($env{'form.authorrole'}) {
8282: my ($newsubdir,$filename);
8283: if ($env{'form.newsubdir'}) {
8284: if ($env{'form.newsubdirname'} ne '') {
8285: $newsubdir = $env{'form.newsubdirname'};
8286: }
8287: }
8288: if ($env{'form.newresourcename'}) {
8289: $filename = $env{'form.newresourcename'};
8290: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8291: $filename =~ s/`//g;
8292: $filename =~ s{/\.\./}{_}g;
8293: $filename =~ s/\.+/./g;
8294: $filename =~ s{/+}{_}g;
8295: if ($filename ne '') {
8296: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8297: if (($ext) && ($ext ne '.problem')) {
8298: $filename = $name.'.problem';
8299: } elsif ($ext eq '') {
8300: $filename .= '.problem';
8301: }
8302: my $docroot = $r->dir_config('lonDocRoot');
8303: my @ids=&Apache::lonnet::current_machine_ids();
8304: if ($env{'form.authorrole'} eq 'author') {
8305: if ($env{'user.author'}) {
8306: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8307: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8308: my $path = $docroot.$url;
8309: my $subdir = $env{'form.authorpath'};
8310: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8311: }
8312: }
8313: } elsif ($env{'form.authorrole'} eq 'course') {
8314: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8315: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8316: my $url = "/priv/$coursedom/$coursenum";
8317: my $path=$docroot.$url;
8318: my $subdir = $env{'form.authorpath'};
8319: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8320: if ($redirect) {
8321: my $rightsfile = 'default.rights';
8322: my $sourcerights = "$path/$rightsfile";
8323: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8324: my $now = time;
8325: if (!-e $sourcerights) {
8326: my $cid = $coursedom.'_'.$coursenum;
8327: if (open(my $fh,">$sourcerights")) {
8328: print $fh <<END;
8329: <accessrule effect="deny" realm="" type="course" role="" />
8330: <accessrule effect="allow" realm="$cid" type="course" role="" />
8331: END
8332: close($fh);
8333: }
8334: }
8335: if (!-e "$sourcerights.meta") {
8336: if (open(my $fh,">$sourcerights.meta")) {
8337: my $author=$env{'environment.firstname'}.' '.
8338: $env{'environment.middlename'}.' '.
8339: $env{'environment.lastname'}.' '.
8340: $env{'environment.generation'};
8341: $author =~ s/\s+$//;
8342: print $fh <<"END";
8343:
8344: <abstract></abstract>
8345: <author>$author</author>
8346: <authorspace>$coursenum:$coursedom</authorspace>
8347: <copyright>private</copyright>
8348: <creationdate>$now</creationdate>
8349: <customdistributionfile></customdistributionfile>
8350: <dependencies></dependencies>
8351: <domain>$coursedom</domain>
8352: <highestgradelevel>0</highestgradelevel>
8353: <keywords></keywords>
8354: <language>notset </language>
8355: <lastrevisiondate>$now</lastrevisiondate>
8356: <lowestgradelevel>0</lowestgradelevel>
8357: <mime>rights</mime>
8358: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8359: <notes></notes>
8360: <obsolete></obsolete>
8361: <obsoletereplacement></obsoletereplacement>
8362: <owner>$coursenum:$coursedom</owner>
8363: <rule>deny:::course,allow:$cid::course</rule>
8364: <sourceavail></sourceavail>
8365: <standards></standards>
8366: <subject></subject>
8367: <title></title>
8368: END
8369: close($fh);
8370: }
8371: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8372: if (!-e "$docroot/res/$coursedom") {
8373: mkdir("$docroot/res/$coursedom",0755);
8374: }
8375: if (!-e "$docroot/res/$coursedom/$coursenum") {
8376: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8377: }
8378: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8379: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8380: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8381: }
8382: }
8383: }
8384: if ($env{'form.newresourceadd'}) {
8385: my $template = $env{'form.template'};
8386: my $source = $docroot.$redirect;
8387: my $target = $redirect;
8388: $target =~ s{^/priv/}{/res/};
8389: $target = $docroot.$target;
8390: if (!-e $source) {
8391: my $copyfrom;
8392: if ($template) {
8393: my %templates;
8394: my @files = &Apache::lonhomework::get_template_list('problem');
8395: foreach my $poss (@files) {
8396: if (ref($poss) eq 'ARRAY') {
8397: if ($template eq $poss->[0]) {
8398: $templates{$template} = 1;
8399: last;
8400: }
8401: }
8402: }
8403: if ($templates{$template}) {
8404: $copyfrom = $template;
8405: }
8406: }
8407: unless ($copyfrom) {
8408: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8409: }
8410: &File::Copy::copy($copyfrom,$source);
8411: }
8412: if (!-e "$source.meta") {
8413: my $cid = $coursedom.'_'.$coursenum;
8414: my $now = time;
8415: if (open(my $fh,">$source.meta")) {
8416: my $author=$env{'environment.firstname'}.' '.
8417: $env{'environment.middlename'}.' '.
8418: $env{'environment.lastname'}.' '.
8419: $env{'environment.generation'};
8420: $author =~ s/\s+$//;
8421: my $title = $env{'form.newresourcetitle'};
8422: $title =~ s/^\s+|\s+$//g;
8423: print $fh <<END;
8424:
8425: <abstract></abstract>
8426: <author>$author</author>
8427: <authorspace>$coursenum:$coursedom</authorspace>
8428: <copyright>custom</copyright>
8429: <creationdate>$now</creationdate>
8430: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8431: <dependencies></dependencies>
8432: <domain>$coursedom</domain>
8433: <highestgradelevel>0</highestgradelevel>
8434: <keywords></keywords>
8435: <language>notset </language>
8436: <lastrevisiondate>$now</lastrevisiondate>
8437: <lowestgradelevel>0</lowestgradelevel>
8438: <mime>problem</mime>
8439: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8440: <notes></notes>
8441: <obsolete></obsolete>
8442: <obsoletereplacement></obsoletereplacement>
8443: <owner>$coursenum:$coursedom</owner>
8444: <sourceavail></sourceavail>
8445: <standards></standards>
8446: <subject></subject>
8447: <title>$title</title>
8448: END
8449: close($fh);
8450: }
8451: }
8452: }
8453: }
8454: }
8455: } else {
8456: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8457: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8458: if (grep(/^\Q$rolehome\E$/,@ids)) {
8459: my $now = time;
8460: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8461: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8462: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8463: my $url = "/priv/$audom/$auname";
8464: my $path = $r->dir_config('lonDocRoot').$url;
8465: my $subdir = $env{'form.authorpath'};
8466: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8467: }
8468: }
8469: }
8470: }
8471: }
8472: }
8473: }
8474: return ($redirect,$error);
8475: }
8476:
8477: sub finishnewprob {
8478: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8479: unless (-d $path) {
8480: unless (mkdir($path,02770)) {
8481: return;
8482: }
8483: }
1.606 raeburn 8484: my $redirect;
8485: if ($subdir ne '/') {
8486: $subdir = &cleandir($subdir);
8487: if (($subdir ne '') && (-d "$path/$subdir")) {
8488: $path .= "/$subdir";
8489: $url .= "/$subdir";
8490: }
8491: }
8492: my $dest;
8493: if ($newsubdir ne '') {
8494: $newsubdir = &cleandir($newsubdir);
8495: }
8496: if ($newsubdir ne '') {
8497: if (-d "$path/$newsubdir") {
8498: $dest = "$path/$newsubdir/$filename";
8499: } else {
8500: my $dirok;
8501: unless (-e "$path/$newsubdir") {
8502: if (mkdir("$path/$newsubdir",02770)) {
8503: if (chmod(02770,"$path/$newsubdir")) {
8504: $dirok = 1;
8505: }
8506: }
8507: }
8508: if ($dirok) {
8509: $dest = "$path/$newsubdir/$filename";
8510: }
8511: }
8512: if (($dest ne '') && (!-e $dest)) {
8513: $redirect = "$url/$newsubdir/$filename";
8514: }
8515: } else {
8516: $dest = "$path/$filename";
8517: if (($dest ne '') && (!-e $dest)) {
8518: $redirect = "$url/$filename";
8519: }
8520: }
8521: return $redirect;
8522: }
8523:
8524: sub cleandir {
8525: my ($dir) = @_;
8526: $dir =~ s/^\s+//;
8527: $dir =~ s/\s+$//;
8528: $dir =~ s/\.+//g;
8529: $dir =~ s/[\#\?&%\":]//g;
8530: return $dir;
8531: }
8532:
1.329 droeschl 8533: 1;
8534: __END__
8535:
8536:
8537: =head1 NAME
8538:
8539: Apache::londocs.pm
8540:
8541: =head1 SYNOPSIS
8542:
8543: This is part of the LearningOnline Network with CAPA project
8544: described at http://www.lon-capa.org.
8545:
8546: =head1 SUBROUTINES
8547:
8548: =over
8549:
8550: =item %help=()
8551:
8552: Available help topics
8553:
8554: =item mapread()
8555:
1.344 bisitz 8556: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8557: @order and @resources, determines status
8558: sets @order - pointer to resources in right order
8559: sets @resources - array with the resources with correct idx
8560:
8561: =item authorhosts()
8562:
8563: Return hash with valid author names
8564:
8565: =item clean()
8566:
8567: =item dumpcourse()
8568:
8569: Actually dump course
8570:
8571: =item group_import()
8572:
8573: Imports the given (name, url) resources into the course
8574: coursenum, coursedom, and folder must precede the list
8575:
8576: =item breadcrumbs()
8577:
8578: =item log_docs()
8579:
8580: =item docs_change_log()
8581:
8582: =item update_paste_buffer()
8583:
8584: =item print_paste_buffer()
8585:
8586: =item do_paste_from_buffer()
8587:
1.538 raeburn 8588: =item do_buffer_empty()
8589:
8590: =item clear_from_buffer()
8591:
1.492 raeburn 8592: =item get_newmap_url()
8593:
8594: =item dbcopy()
8595:
8596: =item uniqueness_check()
8597:
8598: =item contained_map_check()
8599:
8600: =item url_paste_fixups()
8601:
8602: =item apply_fixups()
8603:
8604: =item copy_dependencies()
8605:
1.329 droeschl 8606: =item update_parameter()
8607:
8608: =item handle_edit_cmd()
8609:
8610: =item editor()
8611:
8612: =item process_file_upload()
8613:
8614: =item process_secondary_uploads()
8615:
8616: =item is_supplemental_title()
8617:
8618: =item entryline()
8619:
8620: =item tiehash()
8621:
8622: =item untiehash()
8623:
8624: =item checkonthis()
8625:
8626: check on this
8627:
8628: =item verifycontent()
8629:
8630: Verify Content
8631:
8632: =item devalidateversioncache() & checkversions()
8633:
8634: Check Versions
8635:
8636: =item mark_hash_old()
8637:
8638: =item is_hash_old()
8639:
8640: =item changewarning()
8641:
8642: =item init_breadcrumbs()
8643:
8644: Breadcrumbs for special functions
8645:
1.484 raeburn 8646: =item create_list_elements()
8647:
8648: =item create_form_ul()
8649:
8650: =item startContentScreen()
8651:
8652: =item endContentScreen()
8653:
8654: =item supplemental_base()
8655:
8656: =item embedded_form_elems()
8657:
8658: =item embedded_destination()
8659:
8660: =item return_to_editor()
8661:
8662: =item decompression_info()
8663:
8664: =item decompression_phase_one()
8665:
8666: =item decompression_phase_two()
8667:
8668: =item remove_archive()
8669:
8670: =item generate_admin_menu()
8671:
8672: =item generate_edit_table()
8673:
8674: =item editing_js()
8675:
8676: =item history_tab_js()
8677:
8678: =item inject_data_js()
8679:
8680: =item dump_switchserver_js()
8681:
1.485 raeburn 8682: =item resize_scrollbox_js()
1.484 raeburn 8683:
8684: =item makedocslogform()
8685:
1.485 raeburn 8686: =item makesimpleeditform()
8687:
1.329 droeschl 8688: =back
8689:
8690: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>