Annotation of loncom/interface/londocs.pm, revision 1.631
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.631 ! raeburn 4: # $Id: londocs.pm,v 1.630 2017/05/10 23:34:15 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;
1.630 raeburn 606: $depurl =~ s{[^/]+$}{};
1.567 raeburn 607: $depurl .= $dependency;
1.630 raeburn 608: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 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.628 raeburn 681: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
682: ($toolhash{'target'} eq 'window')) {
1.604 raeburn 683: if ($toolhash{'target'} eq 'window') {
684: foreach my $item ('width','height') {
685: $toolhash{$item} =~ s/^\s+//;
686: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 687: if ($toolhash{$item} =~ /\D/) {
688: delete($toolhash{$item});
689: if ($residx) {
690: if ($toolsettings{$item}) {
691: push(@deleted,$item);
692: }
693: }
694: }
1.604 raeburn 695: }
696: }
697: } elsif ($residx) {
698: $toolhash{'target'} = $toolsettings{'target'};
699: if ($toolhash{'target'} eq 'window') {
1.630 raeburn 700: foreach my $item ('width','height') {
1.624 raeburn 701: $toolhash{$item} = $toolsettings{$item};
702: }
1.604 raeburn 703: }
704: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
705: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
706: if ($toolhash{'target'} eq 'window') {
707: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
708: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
709: }
710: }
1.598 raeburn 711: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 712: foreach my $item ('width','height','linktext','explanation') {
713: delete($toolhash{$item});
714: if ($residx) {
715: if ($toolsettings{$item}) {
716: push(@deleted,$item);
717: }
1.604 raeburn 718: }
719: }
1.628 raeburn 720: } elsif ($toolhash{'target'} eq 'tab') {
721: foreach my $item ('width','height') {
722: delete($toolhash{$item});
723: if ($residx) {
724: if ($toolsettings{$item}) {
725: push(@deleted,$item);
726: }
727: }
728: }
1.604 raeburn 729: }
730: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 731: foreach my $item ('label','title','linktext','explanation') {
732: my $crsitem;
733: if (($item eq 'label') || ($item eq 'title')) {
734: $crsitem = 'crs'.$item;
735: } else {
736: $crsitem = $item;
737: }
1.604 raeburn 738: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 739: $toolhash{$crsitem} =~ s/^\s+//;
740: $toolhash{$crsitem} =~ s/\s+$//;
741: if ($toolhash{$crsitem} eq '') {
742: delete($toolhash{$crsitem});
1.604 raeburn 743: }
744: } else {
1.624 raeburn 745: delete($toolhash{$crsitem});
1.604 raeburn 746: }
1.624 raeburn 747: if (($residx) && (exists($toolsettings{$crsitem}))) {
748: unless (exists($toolhash{$crsitem})) {
749: push(@deleted,$crsitem);
1.604 raeburn 750: }
751: }
1.598 raeburn 752: }
753: }
754: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 755: if ($putres eq 'ok') {
756: if (@deleted) {
757: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
758: }
759: }
1.598 raeburn 760: }
761: }
762: }
1.529 raeburn 763: if (($caller eq 'londocs') &&
764: ($folder =~ /^default/)) {
1.534 raeburn 765: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 766: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
767: my $cid = $coursedom.'_'.$coursenum;
768: $allmaps =
769: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
770: $chome,$cid);
771: $donechk = 1;
772: }
773: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 774: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
775: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 776: $importuploaded = 1;
777: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
778: next if ($allmaps->{$url});
779: }
780: }
1.344 bisitz 781: if (!$residx
1.329 droeschl 782: || defined($LONCAPA::map::zombies[$residx])) {
783: $residx = &LONCAPA::map::getresidx($url,$residx);
784: push(@LONCAPA::map::order, $residx);
785: }
786: my $ext = 'false';
787: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
788: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 789: if ($name eq '') {
1.538 raeburn 790: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 791: }
792: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
793: my $filepath = $1;
794: my $fname = $name;
795: if ($fname =~ /^\W+$/) {
796: $fname = 'web';
797: } else {
798: $fname =~ s/\W/_/g;
799: }
1.599 damieng 800: if (length($fname) > 15) {
1.534 raeburn 801: $fname = substr($fname,0,14);
802: }
803: my $initialtext = &mt('Replace with your own content.');
804: my $newhtml = <<END;
1.545 raeburn 805: <html>
1.534 raeburn 806: <head>
807: <title>$name</title>
808: </head>
809: <body bgcolor="#ffffff">
810: $initialtext
811: </body>
812: </html>
813: END
814: $env{'form.output'}=$newhtml;
1.630 raeburn 815: my $result =
1.534 raeburn 816: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
817: 'output',
818: "$filepath/$residx/$fname.html");
819: if ($result =~ m{^/uploaded/}) {
820: $url = $result;
821: if ($filepath =~ /^supplemental/) {
822: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
823: $env{'user.domain'}.'___&&&___'.$name;
824: }
825: } else {
826: return (&mt('Failed to save new web page.'),1);
827: }
828: }
1.538 raeburn 829: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 830: $LONCAPA::map::resources[$residx] =
1.329 droeschl 831: join(':', ($name, $url, $ext, 'normal', 'res'));
832: }
833: }
1.529 raeburn 834: if ($importuploaded) {
835: my %import_errors;
836: my %updated = (
837: removefrommap => \%removefrommap,
838: removeparam => \%removeparam,
839: );
1.533 raeburn 840: my ($result,$msgsarray,$lockerror) =
841: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 842: if (keys(%import_errors) > 0) {
1.530 raeburn 843: $fixuperrors =
1.529 raeburn 844: '<p span class="LC_warning">'."\n".
845: &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".
846: '<ul>'."\n";
847: foreach my $key (sort(keys(%import_errors))) {
848: $fixuperrors .= '<li>'.$key.'</li>'."\n";
849: }
850: $fixuperrors .= '</ul></p>'."\n";
851: }
1.533 raeburn 852: if (ref($msgsarray) eq 'ARRAY') {
853: if (@{$msgsarray} > 0) {
854: $fixuperrors .= '<p class="LC_info">'.
855: join('<br />',@{$msgsarray}).
856: '</p>';
857: }
858: }
859: if ($lockerror) {
860: $fixuperrors .= '<p class="LC_error">'.
861: $lockerror.
862: '</p>';
863: }
1.529 raeburn 864: }
865: my ($errtext,$fatal) =
866: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 867: unless ($fatal) {
868: if ($folder =~ /^supplemental/) {
869: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 870: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
871: $folder.'.'.$container);
1.557 raeburn 872: }
873: }
1.529 raeburn 874: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 875: }
876:
877: sub log_docs {
1.494 raeburn 878: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 879: }
880:
881: {
882: my @oldresources=();
883: my @oldorder=();
884: my $parmidx;
885: my %parmaction=();
886: my %parmvalue=();
887: my $changedflag;
888:
889: sub snapshotbefore {
890: @oldresources=@LONCAPA::map::resources;
891: @oldorder=@LONCAPA::map::order;
892: $parmidx=undef;
893: %parmaction=();
894: %parmvalue=();
895: $changedflag=0;
896: }
897:
898: sub remember_parms {
899: my ($idx,$parameter,$action,$value)=@_;
900: $parmidx=$idx;
901: $parmaction{$parameter}=$action;
902: $parmvalue{$parameter}=$value;
903: $changedflag=1;
904: }
905:
906: sub log_differences {
907: my ($plain)=@_;
908: my %storehash=('folder' => $plain,
909: 'currentfolder' => $env{'form.folder'});
910: if ($parmidx) {
911: $storehash{'parameter_res'}=$oldresources[$parmidx];
912: foreach my $parm (keys(%parmaction)) {
913: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
914: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
915: }
916: }
917: my $maxidx=$#oldresources;
918: if ($#LONCAPA::map::resources>$#oldresources) {
919: $maxidx=$#LONCAPA::map::resources;
920: }
921: for (my $idx=0; $idx<=$maxidx; $idx++) {
922: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
923: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
924: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
925: $changedflag=1;
926: }
927: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
928: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
929: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
930: $changedflag=1;
931: }
932: }
933: $storehash{'maxidx'}=$maxidx;
934: if ($changedflag) { &log_docs(\%storehash); }
935: }
936: }
937:
938: sub docs_change_log {
1.611 raeburn 939: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 940: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 941: my $navmap;
1.483 raeburn 942: my $js = '<script type="text/javascript">'."\n".
943: '// <![CDATA['."\n".
944: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 945: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 946: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 947: &history_tab_js()."\n".
1.484 raeburn 948: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 949: '// ]]>'."\n".
950: '</script>'."\n";
1.484 raeburn 951: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
952: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 953: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 954: my %orderhash;
955: my $container='sequence';
956: my $pathitem;
1.519 raeburn 957: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 958: $container='page';
959: }
1.519 raeburn 960: my $folderpath=$env{'form.folderpath'};
961: if ($folderpath eq '') {
1.617 raeburn 962: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 963: }
1.617 raeburn 964: undef($navmap);
1.519 raeburn 965: $pathitem = '<input type="hidden" name="folderpath" value="'.
966: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 967: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
968: my $jumpto = $readfile;
969: $jumpto =~ s{^/}{};
970: my $tid = 1;
1.489 raeburn 971: if ($supplementalflag) {
972: $tid = 2;
973: }
1.630 raeburn 974: my ($breadcrumbtrail) =
1.509 raeburn 975: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 976: $r->print($breadcrumbtrail.
977: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
978: $readfile));
1.329 droeschl 979: my %docslog=&Apache::lonnet::dump('nohist_docslog',
980: $env{'course.'.$env{'request.course.id'}.'.domain'},
981: $env{'course.'.$env{'request.course.id'}.'.num'});
982:
983: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
984:
985: my %saveable_parameters = ('show' => 'scalar',);
986: &Apache::loncommon::store_course_settings('docs_log',
987: \%saveable_parameters);
988: &Apache::loncommon::restore_course_settings('docs_log',
989: \%saveable_parameters);
990: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 991: # FIXME: internationalization seems wrong here
1.329 droeschl 992: my %lt=('hiddenresource' => 'Resources hidden',
993: 'encrypturl' => 'URL hidden',
994: 'randompick' => 'Randomly pick',
995: 'randomorder' => 'Randomly ordered',
996: 'set' => 'set to',
997: 'del' => 'deleted');
1.484 raeburn 998: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
999: $pathitem."\n".
1000: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1001: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1002: $r->print('<div class="LC_left_float">'.
1003: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1004: &makedocslogform($filter,1).
1005: '</fieldset></div><br clear="all" />');
1.329 droeschl 1006: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1007: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1008: &mt('After').'</th>'.
1009: &Apache::loncommon::end_data_table_header_row());
1010: my $shown=0;
1011: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1012: if ($env{'form.displayfilter'} eq 'currentfolder') {
1013: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1014: }
1015: my @changes=keys(%{$docslog{$id}{'logentry'}});
1016: if ($env{'form.displayfilter'} eq 'containing') {
1017: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1018: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1019: foreach my $key (@changes) {
1020: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1021: }
1.344 bisitz 1022: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1023: }
1024: my $count = 0;
1025: my $time =
1026: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1027: my $plainname =
1028: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1029: $docslog{$id}{'exe_udom'});
1030: my $about_me_link =
1031: &Apache::loncommon::aboutmewrapper($plainname,
1032: $docslog{$id}{'exe_uname'},
1033: $docslog{$id}{'exe_udom'});
1034: my $send_msg_link='';
1035: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1036: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1037: $send_msg_link ='<br />'.
1038: &Apache::loncommon::messagewrapper(&mt('Send message'),
1039: $docslog{$id}{'exe_uname'},
1040: $docslog{$id}{'exe_udom'});
1041: }
1042: $r->print(&Apache::loncommon::start_data_table_row());
1043: $r->print('<td>'.$time.'</td>
1044: <td>'.$about_me_link.
1045: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1046: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1047: $send_msg_link.'</td><td>'.
1048: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1049: my $is_supp = 0;
1050: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1051: $is_supp = 1;
1052: }
1.329 droeschl 1053: # Before
1054: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1055: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1056: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1057: if ($oldname ne $newname) {
1.488 raeburn 1058: my $shown = &LONCAPA::map::qtescape($oldname);
1059: if ($is_supp) {
1060: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1061: }
1062: $r->print($shown);
1.329 droeschl 1063: }
1064: }
1065: $r->print('<ul>');
1066: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1067: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1068: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1069: if ($is_supp) {
1070: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1071: }
1072: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1073: }
1074: }
1075: $r->print('</ul>');
1076: # After
1077: $r->print('</td><td>');
1078:
1079: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1080: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1081: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1082: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1083: my $shown = &LONCAPA::map::qtescape($newname);
1084: if ($is_supp) {
1085: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1086: }
1087: $r->print($shown);
1.329 droeschl 1088: }
1.364 bisitz 1089: }
1.329 droeschl 1090: $r->print('<ul>');
1091: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1092: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1093: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1094: if ($is_supp) {
1095: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1096: }
1097: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1098: }
1099: }
1100: $r->print('</ul>');
1101: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1102: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1103: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1104: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1105: # FIXME: internationalization seems wrong here
1.329 droeschl 1106: $r->print('<li>'.
1107: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1108: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1109: .'</li>');
1110: }
1111: }
1112: $r->print('</ul>');
1113: }
1114: # End
1115: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1116: $shown++;
1117: if (!($env{'form.show'} eq &mt('all')
1118: || $shown<=$env{'form.show'})) { last; }
1119: }
1.484 raeburn 1120: $r->print(&Apache::loncommon::end_data_table()."\n".
1121: &makesimpleeditform($pathitem)."\n".
1122: '</div></div>');
1123: $r->print(&endContentScreen());
1.329 droeschl 1124: }
1125:
1126: sub update_paste_buffer {
1.492 raeburn 1127: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1128: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1129: if ($env{'form.multiremove'}) {
1130: $env{'form.multiremove'} =~ s/,$//;
1131: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1132: }
1133: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1134: if ($env{'form.multicut'}) {
1135: $env{'form.multicut'} =~ s/,$//;
1136: foreach my $item (split(/,/,$env{'form.multicut'})) {
1137: unless ($removals{$item}) {
1138: $cuts{$item} = 1;
1139: push(@possibles,$item.':cut');
1140: }
1141: }
1142: }
1143: if ($env{'form.multicopy'}) {
1144: $env{'form.multicopy'} =~ s/,$//;
1145: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1146: unless ($removals{$item} || $cuts{$item}) {
1147: push(@possibles,$item.':copy');
1148: }
1149: }
1150: }
1151: } elsif ($env{'form.markcopy'}) {
1152: @possibles = split(/,/,$env{'form.markcopy'});
1153: }
1.329 droeschl 1154:
1.538 raeburn 1155: return if (@possibles == 0);
1.329 droeschl 1156: return if (!defined($env{'form.copyfolder'}));
1157:
1158: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1159: $env{'form.copyfolder'});
1.538 raeburn 1160: return if ($fatal);
1161:
1162: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1163:
1.538 raeburn 1164: # Retrieve current paste buffer suffixes.
1165: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1166: my (%pasteurls,@newpaste);
1167:
1168: # Construct identifiers for current contents of user's paste buffer
1169: if (@currpaste) {
1170: foreach my $suffix (@currpaste) {
1171: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1172: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.630 raeburn 1173: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1174: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1175: ($url ne '')) {
1.597 raeburn 1176: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1177: }
1178: }
1179: }
1180:
1181: # Mark items for copying (skip any items already in user's paste buffer)
1182: my %addtoenv;
1.597 raeburn 1183:
1184: my @pathitems = split(/\&/,$env{'form.folderpath'});
1185: my @folderconf = split(/\:/,$pathitems[-1]);
1186: my $ispage = $folderconf[4];
1187:
1.538 raeburn 1188: foreach my $item (@possibles) {
1189: my ($orderidx,$cmd) = split(/:/,$item);
1190: next if ($orderidx =~ /\D/);
1191: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1192: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1193: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1194: my %denied = &action_restrictions($coursenum,$coursedom,
1195: &LONCAPA::map::qtescape($url),
1196: $env{'form.folderpath'},\%curr_groups);
1197: next if ($denied{'copy'});
1198: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1199: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1200: my ($suffix,$errortxt,$locknotfreed) =
1201: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1202: if ($suffix ne '') {
1203: push(@newpaste,$suffix);
1204: } else {
1205: if ($locknotfreed) {
1206: return $locknotfreed;
1207: }
1.538 raeburn 1208: }
1209: if (&is_supplemental_title($title)) {
1210: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1211: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1212: }
1.329 droeschl 1213:
1.538 raeburn 1214: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1215: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1216: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1217: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1218: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1219: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1220: my $prefix = $1;
1221: my $subdir =$2;
1222: if ($subdir eq '') {
1223: $subdir = $prefix;
1.492 raeburn 1224: }
1.538 raeburn 1225: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1226: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1227: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1228: if (ref($hierarchy{$url}) eq 'HASH') {
1229: my ($nested,$nestednames);
1230: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1231: $nested =~ s/\&$//;
1232: $nestednames =~ s/\Q___&&&___\E$//;
1233: if ($nested ne '') {
1234: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1235: }
1236: if ($nestednames ne '') {
1237: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1238: }
1.492 raeburn 1239: }
1240: }
1.591 raeburn 1241: if ($locknotfreed) {
1242: $output = $locknotfreed;
1243: last;
1244: }
1.492 raeburn 1245: }
1.538 raeburn 1246: if (@newpaste) {
1247: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1248: }
1.492 raeburn 1249: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1250: delete($env{'form.markcopy'});
1.591 raeburn 1251: return $output;
1.329 droeschl 1252: }
1253:
1.492 raeburn 1254: sub recurse_uploaded_maps {
1255: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1256: if (ref($hierarchy->{$url}) eq 'HASH') {
1257: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1258: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1259: my (@uploaded,@names,%shorter);
1260: for (my $i=0; $i<@maps; $i++) {
1261: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1262: if ($inner ne '') {
1263: push(@uploaded,$inner);
1264: push(@names,&escape($titles[$i]));
1265: $shorter{$maps[$i]} = $inner;
1266: }
1267: }
1268: $$nestref .= "$dir:".join(',',@uploaded).'&';
1269: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1270: foreach my $map (@maps) {
1271: if ($shorter{$map} ne '') {
1272: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1273: }
1274: }
1275: }
1276: return;
1277: }
1278:
1.329 droeschl 1279: sub print_paste_buffer {
1.492 raeburn 1280: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1281: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1282:
1.538 raeburn 1283: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1284: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1285: }
1286:
1.538 raeburn 1287: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1288: my ($pasteitems,@pasteable);
1.575 raeburn 1289: my $clipboardcount = 0;
1.488 raeburn 1290:
1.538 raeburn 1291: # Construct identifiers for current contents of user's paste buffer
1292: foreach my $suffix (@currpaste) {
1293: next if ($suffix =~ /\D/);
1294: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1295: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1296: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1297: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1298: ($url ne '')) {
1.575 raeburn 1299: $clipboardcount ++;
1.538 raeburn 1300: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1301: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1302: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1303: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1304: $is_external = 1;
1.626 raeburn 1305: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1306: $is_exttool = 1;
1.538 raeburn 1307: }
1308: if ($folder =~ /^supplemental/) {
1309: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1310: unless ($canpaste) {
1311: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1312: }
1313: } else {
1314: $canpaste = 1;
1315: }
1316: if ($canpaste) {
1317: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1318: my $srcdom = $1;
1319: my $srcnum = $2;
1320: my $rem = $3;
1321: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1322: $othercourse = 1;
1323: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1324: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1325: } else {
1326: $canpaste = 0;
1327: $nopaste = &mt('Paste from another course unavailable.');
1328: }
1329: }
1330: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1331: my $prefix = $1;
1332: $parent = $2;
1333: if ($folder !~ /^\Q$prefix\E/) {
1334: $areachange = 1;
1335: }
1336: $is_uploaded_map = 1;
1.492 raeburn 1337: }
1.597 raeburn 1338: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1339: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1340: if ($cid ne $env{'request.course.id'}) {
1341: my ($srcdom,$srcnum) = split(/_/,$cid);
1342: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1343: if (($is_exttool) && ($srcdom ne $coursedom)) {
1344: $canpaste = 0;
1345: $nopaste = &mt('Paste from another domain unavailable.');
1346: } else {
1347: $othercrs = '<br />'.&mt('(from another course)');
1348: }
1.596 raeburn 1349: } else {
1350: $canpaste = 0;
1351: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1352: }
1.596 raeburn 1353: }
1.492 raeburn 1354: }
1.596 raeburn 1355: if ($canpaste) {
1356: push(@pasteable,$suffix);
1.629 raeburn 1357: }
1.538 raeburn 1358: }
1359: my $buffer;
1.627 raeburn 1360: if ($is_external) {
1.538 raeburn 1361: $buffer = &mt('External Resource').': '.
1362: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1363: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1364: } elsif ($is_exttool) {
1365: $buffer = &mt('External Tool').': '.
1366: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1367: } else {
1368: my $icon = &Apache::loncommon::icon($extension);
1369: if ($extension eq 'sequence' &&
1370: $url =~ m{/default_\d+\.sequence$}x) {
1371: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1372: $icon .= '/navmap.folder.closed.gif';
1373: }
1.589 raeburn 1374: my $title = $env{'docs.markedcopy_title_'.$suffix};
1375: if ($title eq '') {
1376: ($title) = ($url =~ m{/([^/]+)$});
1377: }
1.538 raeburn 1378: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1379: ': '.
1380: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1381: &LONCAPA::map::qtescape($title));
1.538 raeburn 1382: }
1383: $pasteitems .= '<div class="LC_left_float">';
1384: my ($options,$onclick);
1385: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1386: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1387: if (($is_uploaded_map) ||
1388: ($url =~ /(bulletinboard|smppg)$/) ||
1389: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1390: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1391: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1392: }
1393: }
1394: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1395: if ($nopaste) {
1396: $pasteitems .= $nopaste;
1397: } else {
1398: if ($othercrs) {
1399: $pasteitems .= $othercrs;
1400: }
1401: if ($options) {
1402: $pasteitems .= $options;
1.492 raeburn 1403: }
1404: }
1.538 raeburn 1405: $pasteitems .= '</div>';
1406: }
1407: }
1408: if ($pasteitems eq '') {
1409: &Apache::lonnet::delenv('docs.markedcopies');
1410: }
1411: my ($pasteform,$form_start,$buttons,$form_end);
1412: if ($pasteitems) {
1413: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1414: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1415: if (@pasteable) {
1.575 raeburn 1416: my $value = &mt('Paste to current folder');
1417: if ($container eq 'page') {
1418: $value = &mt('Paste to current page');
1419: }
1420: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1421: }
1422: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1423: if ($clipboardcount > 1) {
1424: $buttons .=
1425: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1426: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1427: (' 'x2).
1428: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1429: (' 'x2);
1.492 raeburn 1430: }
1.575 raeburn 1431: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1432: '</form>';
1.538 raeburn 1433: } else {
1434: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1435: }
1.538 raeburn 1436: $r->print($form_start
1437: .'<fieldset>'
1438: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1439: .$pasteitems
1440: .'</fieldset>'
1441: .$form_end);
1442: }
1443:
1444: sub paste_options {
1445: my ($suffix,$is_uploaded_map,$parent) = @_;
1446: my ($copytext,$movetext);
1447: if ($is_uploaded_map) {
1448: $copytext = &mt('Copy to new folder');
1449: $movetext = &mt('Move old');
1450: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1451: $copytext = &mt('Copy to new board');
1452: $movetext = &mt('Move (not posts)');
1453: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1454: $copytext = &mt('Copy to new page');
1455: $movetext = &mt('Move');
1.533 raeburn 1456: } else {
1.538 raeburn 1457: $copytext = &mt('Copy to new file');
1458: $movetext = &mt('Move');
1459: }
1460: my $output = '<br />'.
1461: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1462: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1463: '<label>'.
1464: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1465: $copytext.'</label></span>'.(' 'x2).' '.
1466: '<span class="LC_nobreak"><label>'.
1467: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1468: $movetext.'</label></span>';
1469: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1470: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1471: '</legend><table border="0">';
1472: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1473: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1474: my $lastdir = $parent;
1475: my %depths = (
1476: $lastdir => 0,
1477: );
1478: my (%display,%deps);
1479: for (my $i=0; $i<@pastemaps; $i++) {
1480: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1481: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1482: my @subfolders = split(/,/,$subfolderstr);
1483: $deps{$lastdir} = \@subfolders;
1484: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1485: my $depth = $depths{$lastdir} + 1;
1486: my $offset = int($depth * 4);
1487: my $indent = (' ' x $offset);
1488: for (my $j=0; $j<@subfolders; $j++) {
1489: $depths{$subfolders[$j]} = $depth;
1490: $display{$subfolders[$j]} =
1491: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1492: '<td><label>'.
1493: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1494: '<label>'.
1495: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1496: &mt('Move old').'</label>'.
1497: '</td></tr>';
1498: }
1.492 raeburn 1499: }
1.538 raeburn 1500: &recurse_print(\$output,$parent,\%deps,\%display);
1501: $output .= '</table></fieldset>';
1.329 droeschl 1502: }
1.538 raeburn 1503: $output .= '</div>';
1504: return $output;
1.488 raeburn 1505: }
1506:
1.492 raeburn 1507: sub recurse_print {
1.538 raeburn 1508: my ($outputref,$dir,$deps,$display) = @_;
1509: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1510: if (ref($deps->{$dir}) eq 'ARRAY') {
1511: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1512: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1513: }
1514: }
1515: }
1516:
1.488 raeburn 1517: sub supp_pasteable {
1518: my ($url) = @_;
1519: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1520: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1521: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1522: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1523: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1524: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1525: return 1;
1526: }
1527: return;
1.329 droeschl 1528: }
1529:
1.492 raeburn 1530: sub paste_popup_js {
1.594 damieng 1531: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1532: show => 'Show Options',
1533: hide => 'Hide Options',
1.594 damieng 1534: );
1535: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1536: none => 'No items selected from clipboard.',
1.492 raeburn 1537: );
1.594 damieng 1538: &html_escape(\%html_js_lt);
1539: &js_escape(\%html_js_lt);
1540: &js_escape(\%js_lt);
1.492 raeburn 1541: return <<"END";
1542:
1.538 raeburn 1543: function showPasteOptions(suffix) {
1544: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1545: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1546: return;
1547: }
1548:
1.538 raeburn 1549: function hidePasteOptions(suffix) {
1550: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1551: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1552: return;
1553: }
1554:
1555: function showOptions(caller,suffix) {
1556: if (document.getElementById('pasteoptionstext_'+suffix)) {
1557: if (caller.checked) {
1.594 damieng 1558: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1559: } else {
1560: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1561: }
1562: if (document.getElementById('pasteoptions_'+suffix)) {
1563: document.getElementById('pasteoptions_'+suffix).style.display='none';
1564: }
1565: }
1.492 raeburn 1566: return;
1567: }
1568:
1.541 raeburn 1569: function validateClipboard() {
1570: var numchk = 0;
1571: if (document.pasteform.pasting.length > 1) {
1572: for (var i=0; i<document.pasteform.pasting.length; i++) {
1573: if (document.pasteform.pasting[i].checked) {
1574: numchk ++;
1575: }
1576: }
1577: } else {
1578: if (document.pasteform.pasting.type == 'checkbox') {
1579: if (document.pasteform.pasting.checked) {
1580: numchk ++;
1581: }
1582: }
1583: }
1584: if (numchk > 0) {
1585: return true;
1586: } else {
1.594 damieng 1587: alert("$js_lt{'none'}");
1.541 raeburn 1588: return false;
1589: }
1590: }
1591:
1.575 raeburn 1592: function checkClipboard() {
1593: if (document.pasteform.pasting.length > 1) {
1594: for (var i=0; i<document.pasteform.pasting.length; i++) {
1595: document.pasteform.pasting[i].checked = true;
1596: }
1597: }
1598: return;
1599: }
1600:
1601: function uncheckClipboard() {
1602: if (document.pasteform.pasting.length >1) {
1603: for (var i=0; i<document.pasteform.pasting.length; i++) {
1604: document.pasteform.pasting[i].checked = false;
1605: }
1606: }
1607: return;
1608: }
1609:
1.492 raeburn 1610: END
1611:
1612: }
1613:
1.329 droeschl 1614: sub do_paste_from_buffer {
1.492 raeburn 1615: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1616:
1.538 raeburn 1617: # Array of items in paste buffer
1618: my (@currpaste,%pastebuffer,%allerrors);
1619: @currpaste = split(/,/,$env{'docs.markedcopies'});
1620:
1.492 raeburn 1621: # Early out if paste buffer is empty
1.538 raeburn 1622: if (@currpaste == 0) {
1.492 raeburn 1623: return ();
1.538 raeburn 1624: }
1625: map { $pastebuffer{$_} = 1; } @currpaste;
1626:
1627: # Array of items selected items to paste
1628: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1629:
1630: # Early out if nothing selected to paste
1631: if (@reqpaste == 0) {
1632: return();
1633: }
1634: my @topaste;
1635: foreach my $suffix (@reqpaste) {
1636: next if ($suffix =~ /\D/);
1637: next unless (exists($pastebuffer{$suffix}));
1638: push(@topaste,$suffix);
1639: }
1640:
1641: # Early out if nothing available to paste
1642: if (@topaste == 0) {
1643: return();
1.329 droeschl 1644: }
1645:
1.627 raeburn 1646: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1647: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1648:
1649: foreach my $suffix (@topaste) {
1650: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1651: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1652: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1653: # Supplemental content may only include certain types of content
1654: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1655: if ($folder =~ /^supplemental/) {
1656: unless (&supp_pasteable($url)) {
1657: $notinsupp{$suffix} = 1;
1658: next;
1659: }
1.492 raeburn 1660: }
1.538 raeburn 1661: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1662: my $srcd = $1;
1663: my $srcn = $2;
1.492 raeburn 1664: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1665: # check for mdc privilege in the course from which the resource was pasted
1666: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1667: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1668: $notincrs{$suffix} = 1;
1669: next;
1670: }
1.491 raeburn 1671: }
1.538 raeburn 1672: $srcdom{$suffix} = $srcd;
1673: $srcnum{$suffix} = $srcn;
1.597 raeburn 1674: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1675: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1676: my $srctype= $1;
1.596 raeburn 1677: my ($srcd,$srcn) = split(/_/,$cid);
1678: # When paste buffer was populated using an active role in a different course
1679: # check for mdc privilege in the course from which the resource was pasted
1680: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1681: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1682: $notincrs{$suffix} = 1;
1683: next;
1684: }
1685: }
1.627 raeburn 1686: if (($srctype eq 'ext.tool') && ($srcd ne $coursedom)) {
1687: $notindom{$suffix} = 1;
1688: next;
1689: }
1.596 raeburn 1690: $srcdom{$suffix} = $srcd;
1691: $srcnum{$suffix} = $srcn;
1.491 raeburn 1692: }
1.597 raeburn 1693: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1694: push(@dopaste,$suffix);
1695: if ($url=~/\.(page|sequence)$/) {
1696: $is_map{$suffix} = 1;
1697: }
1698: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1699: my $oldprefix = $1;
1.492 raeburn 1700: # When pasting content from Main Content to Supplemental Content and vice versa
1701: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1702: # a folder/page or a document).
1.538 raeburn 1703: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1704: $prefixchg{$suffix} = 'docstosupp';
1705: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1706: $prefixchg{$suffix} = 'supptodocs';
1707: }
1.491 raeburn 1708:
1.492 raeburn 1709: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1710: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1711: my @nested;
1712: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1713: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1714: my @deps = map { /\d+:([\d,]+$)/ } @items;
1715: foreach my $dep (@deps) {
1716: if ($dep =~ /,/) {
1717: push(@nested,split(/,/,$dep));
1718: } else {
1719: push(@nested,$dep);
1720: }
1.492 raeburn 1721: }
1.538 raeburn 1722: foreach my $item (@nested) {
1723: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1724: push(@{$marktomove{$suffix}},$type.'_'.$item);
1725: }
1.492 raeburn 1726: }
1727: }
1.488 raeburn 1728: }
1729: }
1730:
1.538 raeburn 1731: # Early out if nothing available to paste
1732: if (@dopaste == 0) {
1733: return ();
1734: }
1735:
1736: # Populate message hash and hashes used for main content <=> supplemental content
1737: # changes
1738:
1739: %msgs = &Apache::lonlocal::texthash (
1740: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1741: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.627 raeburn 1742: notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.538 raeburn 1743: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1744: );
1745:
1746: %before = (
1747: docstosupp => {
1748: map => 'default',
1749: doc => 'docs',
1750: },
1751: supptodocs => {
1752: map => 'supplemental',
1753: doc => 'supplemental',
1754: },
1755: );
1756:
1757: %after = (
1758: docstosupp => {
1759: map => 'supplemental',
1760: doc => 'supplemental'
1761: },
1762: supptodocs => {
1763: map => 'default',
1764: doc => 'docs',
1765: },
1766: );
1767:
1768: # Retrieve information about all course maps in main content area
1769:
1770: my $allmaps = {};
1771: if ($folder =~ /^default/) {
1772: $allmaps =
1773: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1774: $env{"course.$env{'request.course.id'}.home"},
1775: $env{'request.course.id'});
1776: }
1777:
1778: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1779:
1780: # Loop over the items to paste
1781: foreach my $suffix (@dopaste) {
1.329 droeschl 1782: # Maps need to be copied first
1.538 raeburn 1783: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1784: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1785: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1786: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1787: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1788: }
1789: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1790: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1791: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1792: my $oldurl = $url;
1793: if ($is_map{$suffix}) {
1.491 raeburn 1794: # If pasting a map, check if map contains other maps
1.538 raeburn 1795: my (%hierarchy,%titles);
1.627 raeburn 1796: &contained_map_check($url,$folder,$coursenum,$coursedom,
1797: \%removefrommap,\%removeparam,\%addedmaps,
1798: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1799: if ($url=~ m{^/uploaded/}) {
1800: my $newurl;
1801: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1802: ($newurl,my $error) =
1803: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1804: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1805: \$title,$allmaps,\%newurls);
1806: if ($error) {
1807: $allerrors{$suffix} = $error;
1808: next;
1809: }
1810: if ($newurl ne '') {
1811: if ($newurl ne $url) {
1812: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1813: $newsubdir{$url} = $1;
1814: }
1815: $mapchanges{$url} = 1;
1.492 raeburn 1816: }
1.538 raeburn 1817: }
1818: }
1819: if (($srcdom{$suffix} ne $coursedom) ||
1820: ($srcnum{$suffix} ne $coursenum) ||
1821: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1822: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1823: $coursedom,$coursenum,$srcdom{$suffix},
1824: $srcnum{$suffix},$allmaps,\%rewrites,
1825: \%retitles,\%copies,\%dbcopies,
1826: \%zombies,\%params,\%mapmoves,
1827: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1828: \%newurls,\%resdatacopy)) {
1.538 raeburn 1829: $mapmoves{$url} = 1;
1830: }
1831: $url = $newurl;
1832: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1833: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1834: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1835: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1836: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1837: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1838: }
1839: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1840: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1841: push(@toclear,$suffix);
1842: # if pasting published map (main content area only) check map not already in course
1843: if ($folder =~ /^default/) {
1844: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1845: $duplicate{$suffix} = 1;
1846: next;
1.492 raeburn 1847: }
1.491 raeburn 1848: }
1849: }
1.538 raeburn 1850: }
1.627 raeburn 1851: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1852: my $prefix = $1;
1.596 raeburn 1853: my $fromothercrs;
1.538 raeburn 1854: #need to copy the db contents to a new one, unless this is a move.
1855: my %info = (
1856: src => $url,
1857: cdom => $coursedom,
1858: cnum => $coursenum,
1.596 raeburn 1859: );
1860: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1861: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1862: $fromothercrs = 1;
1863: $info{'cdom'} = $srcdom{$suffix};
1864: $info{'cnum'} = $srcnum{$suffix};
1865: }
1866: }
1867: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 1868: my (%lockerr,$msg);
1.538 raeburn 1869: my ($newurl,$result,$errtext) =
1870: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1871: if ($result eq 'ok') {
1872: $url = $newurl;
1873: $title=&mt('Copy of').' '.$title;
1874: } else {
1875: if ($prefix eq 'smppg') {
1876: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1877: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1878: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 1879: } elsif ($prefix eq 'ext.tool') {
1880: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 1881: }
1882: $results{$suffix} = $result;
1883: $msgerrs{$suffix} = $msg;
1884: $lockerrs{$suffix} = $lockerr{$prefix};
1885: next;
1886: }
1887: if ($lockerr{$prefix}) {
1888: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1889: }
1.489 raeburn 1890: }
1891: }
1.538 raeburn 1892: $title = &LONCAPA::map::qtunescape($title);
1893: my $ext='false';
1894: if ($url=~m{^http(|s)://}) { $ext='true'; }
1895: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1896: if ($folder !~ /^supplemental/) {
1897: (undef,undef,$title) =
1898: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1899: }
1900: } else {
1901: if ($folder=~/^supplemental/) {
1902: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1903: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1904: }
1.533 raeburn 1905: }
1.491 raeburn 1906:
1907: # For uploaded files (excluding pages/sequences) path in copied file is changed
1908: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1909: # courses.
1910:
1.538 raeburn 1911: unless ($is_map{$suffix}) {
1912: my $newidx;
1.492 raeburn 1913: # Now insert the URL at the bottom
1.538 raeburn 1914: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1915: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1916: my $relpath = $1;
1917: if ($relpath ne '') {
1918: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1919: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1920: my $newprefix = $newloc;
1921: if ($newloc eq 'default') {
1922: $newprefix = 'docs';
1923: }
1924: if ($newdocsdir eq '') {
1925: $newdocsdir = 'default';
1926: }
1.630 raeburn 1927: if (($prefixchg{$suffix}) ||
1928: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 1929: ($srcnum{$suffix} ne $coursenum) ||
1930: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1931: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1932: $url =
1933: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1934: &Apache::lonnet::getfile($oldurl));
1935: if ($url eq '/adm/notfound.html') {
1936: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1937: next;
1938: } else {
1939: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1940: $newsubpath =~ s{/+$}{/};
1941: $docmoves{$oldurl} = $newsubpath;
1942: }
1.491 raeburn 1943: }
1944: }
1.597 raeburn 1945: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1946: my $template = $1;
1947: if ($newidx) {
1948: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1949: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1950: }
1.491 raeburn 1951: }
1.538 raeburn 1952: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1953: ':'.$ext.':normal:res';
1954: push(@LONCAPA::map::order,$newidx);
1955: # Store the result
1956: my ($errtext,$fatal) =
1957: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1958: if ($fatal) {
1959: $save_err .= $errtext;
1960: $allresult = 'fail';
1961: }
1.488 raeburn 1962: }
1.538 raeburn 1963:
1.597 raeburn 1964: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1965: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1966: unless ($allresult eq 'fail') {
1967: my %updated = (
1968: rewrites => \%rewrites,
1969: zombies => \%zombies,
1970: removefrommap => \%removefrommap,
1971: removeparam => \%removeparam,
1972: dbcopies => \%dbcopies,
1.597 raeburn 1973: resdatacopy => \%resdatacopy,
1.538 raeburn 1974: retitles => \%retitles,
1975: );
1976: my %info = (
1977: newsubdir => \%newsubdir,
1978: params => \%params,
1979: );
1980: if ($prefixchg{$suffix}) {
1981: $info{'before'} = $before{$prefixchg{$suffix}};
1982: $info{'after'} = $after{$prefixchg{$suffix}};
1983: }
1984: my %moves = (
1985: copies => \%copies,
1986: docmoves => \%docmoves,
1987: mapmoves => \%mapmoves,
1988: );
1989: (my $result,$msgs{$suffix},my $lockerror) =
1990: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1991: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1992: $url,'paste');
1993: $lockerrors .= $lockerror;
1994: if ($result eq 'ok') {
1995: if ($is_map{$suffix}) {
1996: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1997: $folder.'.'.$container);
1998: if ($fatal) {
1999: $allresult = 'failread';
2000: } else {
2001: if ($#LONCAPA::map::order<1) {
2002: my $idx=&LONCAPA::map::getresidx();
2003: if ($idx<=0) { $idx=1; }
2004: $LONCAPA::map::order[0]=$idx;
2005: $LONCAPA::map::resources[$idx]='';
2006: }
2007: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2008: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2009: ':'.$ext.':normal:res';
2010: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2011:
2012: # Store the result
1.538 raeburn 2013: my ($errtext,$fatal) =
2014: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2015: if ($fatal) {
2016: $save_err .= $errtext;
2017: $allresult = 'failstore';
2018: }
2019: }
2020: }
2021: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2022: push(@toclear,$suffix);
2023: }
2024: }
1.492 raeburn 2025: }
2026: }
1.538 raeburn 2027: &clear_from_buffer(\@toclear,\@currpaste);
2028: my $msgsarray;
2029: foreach my $suffix (keys(%msgs)) {
2030: if (ref($msgs{$suffix}) eq 'ARRAY') {
2031: $msgsarray .= join(',',@{$msgs{$suffix}});
2032: }
2033: }
2034: return ($allresult,$save_err,$msgsarray,$lockerrors);
2035: }
1.533 raeburn 2036:
1.538 raeburn 2037: sub do_buffer_empty {
2038: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2039: if (@currpaste == 0) {
2040: return &mt('Clipboard is already empty');
2041: }
2042: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2043: if (@toclear == 0) {
2044: return &mt('Nothing selected to clear from clipboard');
2045: }
2046: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2047: if ($numdel) {
2048: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2049: } else {
2050: return &mt('Clipboard unchanged');
1.492 raeburn 2051: }
1.538 raeburn 2052: return;
2053: }
2054:
2055: sub clear_from_buffer {
2056: my ($toclear,$currpaste) = @_;
2057: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2058: my %pastebuffer;
2059: map { $pastebuffer{$_} = 1; } @{$currpaste};
2060: my $numdel = 0;
2061: foreach my $suffix (@{$toclear}) {
2062: next if ($suffix =~ /\D/);
2063: next unless (exists($pastebuffer{$suffix}));
2064: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2065: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2066: delete($pastebuffer{$suffix});
2067: $numdel ++;
2068: }
2069: }
2070: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2071: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2072: return $numdel;
1.492 raeburn 2073: }
2074:
2075: sub get_newmap_url {
2076: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2077: $titleref,$allmaps,$newurls) = @_;
2078: my $newurl;
2079: if ($url=~ m{^/uploaded/}) {
2080: $$titleref=&mt('Copy of').' '.$$titleref;
2081: }
2082: my $now = time;
2083: my $suffix=$$.int(rand(100)).$now;
2084: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2085: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2086: my $path = $1;
2087: my $prefix = $2;
2088: my $ancestor = $3;
2089: if (length($ancestor) > 10) {
2090: $ancestor = substr($ancestor,-10,10);
2091: }
2092: my $newid;
2093: if ($prefixchg) {
2094: if ($folder =~ /^supplemental/) {
2095: $prefix =~ s/^default/supplemental/;
2096: } else {
2097: $prefix =~ s/^supplemental/default/;
2098: }
2099: }
2100: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2101: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2102: } else {
2103: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2104: }
2105: my $counter = 0;
2106: my $is_unique = &uniqueness_check($newurl);
2107: if ($folder =~ /^default/) {
2108: if ($allmaps->{$newurl}) {
2109: $is_unique = 0;
2110: }
2111: }
2112: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2113: $counter ++;
2114: $suffix ++;
2115: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2116: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2117: } else {
2118: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2119: }
2120: $is_unique = &uniqueness_check($newurl);
2121: }
2122: if ($is_unique) {
2123: $newurls->{$newurl} = 1;
2124: } else {
2125: if ($url=~/\.page$/) {
2126: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2127: } else {
2128: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2129: }
2130: }
1.329 droeschl 2131: }
1.492 raeburn 2132: return ($newurl);
1.329 droeschl 2133: }
2134:
1.488 raeburn 2135: sub dbcopy {
1.533 raeburn 2136: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2137: my ($url,$result,$errtext);
2138: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2139: $url = $dbref->{'src'};
1.627 raeburn 2140: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2141: my $prefix = $1;
1.627 raeburn 2142: if ($prefix eq 'ext.tool') {
2143: $prefix = 'exttool';
2144: }
1.533 raeburn 2145: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2146: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2147: my $db_name;
2148: my $marker = (split(m{/},$url))[4];
2149: $marker=~s/\D//g;
2150: if ($dbref->{'src'} =~ m{/smppg$}) {
2151: $db_name =
2152: &Apache::lonsimplepage::get_db_name($url,$marker,
2153: $dbref->{'cdom'},
2154: $dbref->{'cnum'});
1.627 raeburn 2155: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2156: $db_name = 'exttool_'.$marker;
1.533 raeburn 2157: } else {
2158: $db_name = 'bulletinpage_'.$marker;
2159: }
2160: my ($suffix,$freedlock,$error) =
2161: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2162: $coursedom,$coursenum,
2163: 'concat');
2164: if (!$suffix) {
2165: if ($prefix eq 'smppg') {
2166: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 ! raeburn 2167: } elsif ($prefix eq 'exttool') {
! 2168: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2169: } else {
1.565 bisitz 2170: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2171: }
2172: if ($error) {
2173: $errtext .= '<br />'.$error;
2174: }
2175: } else {
2176: #need to copy the db contents to a new one.
2177: my %contents=&Apache::lonnet::dump($db_name,
2178: $dbref->{'cdom'},
2179: $dbref->{'cnum'});
2180: if (exists($contents{'uploaded.photourl'})) {
2181: my $photo = $contents{'uploaded.photourl'};
2182: my ($subdir,$fname) =
2183: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2184: my $newphoto;
1.533 raeburn 2185: if ($fname ne '') {
2186: my $content = &Apache::lonnet::getfile($photo);
2187: unless ($content eq '-1') {
2188: $env{'form.'.$suffix.'.photourl'} = $content;
2189: $newphoto =
2190: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2191: delete($env{'form.'.$suffix.'.photourl'});
2192: }
2193: }
2194: if ($newphoto =~ m{^/uploaded/}) {
2195: $contents{'uploaded.photourl'} = $newphoto;
2196: }
2197: }
2198: $db_name =~ s{_\d*$ }{_$suffix}x;
2199: $result=&Apache::lonnet::put($db_name,\%contents,
2200: $coursedom,$coursenum);
2201: if ($result eq 'ok') {
1.627 raeburn 2202: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2203: }
2204: }
2205: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2206: $lockerrorsref->{$prefix} =
1.533 raeburn 2207: '<div class="LC_error">'.
2208: &mt('There was a problem removing a lockfile.');
2209: if ($prefix eq 'smppg') {
1.560 raeburn 2210: $lockerrorsref->{$prefix} .=
1.559 raeburn 2211: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2212: } elsif ($prefix eq 'exttool') {
2213: $lockerrorsref->{$prefix} .=
2214: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2215: } else {
1.565 bisitz 2216: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2217: }
1.560 raeburn 2218: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2219: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2220: '</div>';
1.533 raeburn 2221: }
2222: }
2223: } elsif ($url =~ m{/syllabus$}) {
2224: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2225: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2226: if (($dbref->{'cdom'} ne $coursedom) ||
2227: ($dbref->{'cnum'} ne $coursenum)) {
2228: my %contents=&Apache::lonnet::dump('syllabus',
2229: $dbref->{'cdom'},
2230: $dbref->{'cnum'});
2231: $result=&Apache::lonnet::put('syllabus',\%contents,
2232: $coursedom,$coursenum);
2233: }
2234: }
1.488 raeburn 2235: }
2236: }
1.533 raeburn 2237: return ($url,$result,$errtext);
1.488 raeburn 2238: }
2239:
1.597 raeburn 2240: sub copy_templated_files {
2241: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2242: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2243: my $srccontainer = 'sequence';
2244: if ($srcwaspage) {
2245: $srccontainer = 'page';
2246: }
2247: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2248: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2249: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2250: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2251: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2252: $template.'.problem';
2253: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2254: if ($template eq 'simpleproblem') {
2255: $srcprefix .= '.0.';
2256: my $weightprefix = $newprefix;
2257: $newprefix .= '.0.';
2258: my @simpleprobqtypes = qw(radio option string essay numerical);
2259: my $qtype=$srcparms{$srcprefix.'questiontype'};
2260: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2261: my %newdata;
2262: foreach my $type (@simpleprobqtypes) {
2263: if ($type eq $qtype) {
2264: $newdata{"$weightprefix.$type.weight"}=1;
2265: } else {
2266: $newdata{"$weightprefix.$type.weight"}=0;
2267: }
2268: }
2269: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2270: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2271: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2272: if ($qtype eq 'numerical') {
2273: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2274: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2275: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2276: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2277: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2278: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2279: unless (defined($maxfoils)) { $maxfoils=10; }
2280: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2281: if ($maxfoils<=0) { $maxfoils=10; }
2282: my $randomize=$srcparms{$srcprefix.'randomize'};
2283: unless (defined($randomize)) { $randomize='yes'; }
2284: unless ($randomize eq 'no') { $randomize='yes'; }
2285: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2286: $newdata{$newprefix.'randomize'} = $randomize;
2287: if ($qtype eq 'option') {
2288: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2289: }
2290: for (my $i=1; $i<=10; $i++) {
2291: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2292: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2293: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2294: }
2295:
2296: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2297: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2298: unless (defined($maxfoils)) { $maxfoils=10; }
2299: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2300: if ($maxfoils<=0) { $maxfoils=10; }
2301: my $randomize=$srcparms{$srcprefix.'randomize'};
2302: unless (defined($randomize)) { $randomize='yes'; }
2303: unless ($randomize eq 'no') { $randomize='yes'; }
2304: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2305: $newdata{$newprefix.'randomize'} = $randomize;
2306: if ($qtype eq 'option') {
2307: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2308: }
2309: for (my $i=1; $i<=10; $i++) {
2310: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2311: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2312: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2313: }
2314: } elsif ($qtype eq 'string') {
2315: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2316: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2317: }
2318: if (keys(%newdata)) {
2319: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2320: $coursenum);
2321: if ($putres eq 'ok') {
2322: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2323: }
2324: }
2325: }
2326: }
2327: }
2328:
1.329 droeschl 2329: sub uniqueness_check {
2330: my ($newurl) = @_;
2331: my $unique = 1;
2332: foreach my $res (@LONCAPA::map::order) {
2333: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2334: $url=&LONCAPA::map::qtescape($url);
2335: if ($newurl eq $url) {
2336: $unique = 0;
1.344 bisitz 2337: last;
1.329 droeschl 2338: }
2339: }
2340: return $unique;
2341: }
2342:
1.488 raeburn 2343: sub contained_map_check {
1.627 raeburn 2344: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2345: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2346: my $content = &Apache::lonnet::getfile($url);
2347: unless ($content eq '-1') {
2348: my $parser = HTML::TokeParser->new(\$content);
2349: $parser->attr_encoded(1);
2350: while (my $token = $parser->get_token) {
2351: next if ($token->[0] ne 'S');
2352: if ($token->[1] eq 'resource') {
2353: next if ($token->[2]->{'type'} eq 'zombie');
2354: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2355: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2356: my $srcdom = $1;
2357: unless ($srcdom eq $coursedom) {
2358: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2359: next;
2360: }
2361: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2362: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2363: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2364: next;
2365: }
2366: }
1.492 raeburn 2367: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2368: if ($1 eq 'uploaded') {
2369: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2370: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2371: } else {
1.492 raeburn 2372: if ($allmaps->{$ressrc}) {
1.529 raeburn 2373: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2374: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2375: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2376: } else {
2377: $addedmaps->{$ressrc} = [$url];
2378: }
1.488 raeburn 2379: }
1.627 raeburn 2380: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2381: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2382: }
1.492 raeburn 2383: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2384: if ($folder =~ /^supplemental/) {
1.492 raeburn 2385: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2386: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2387: } else {
2388: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2389: }
1.488 raeburn 2390: }
2391: }
2392: }
2393: }
2394: return;
2395: }
2396:
2397: sub url_paste_fixups {
1.533 raeburn 2398: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2399: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2400: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2401: my $checktitle;
2402: if (($prefixchg) &&
1.492 raeburn 2403: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2404: $checktitle = 1;
2405: }
1.492 raeburn 2406: my $skip;
2407: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2408: my $mapid = $1.$2;
2409: if ($tomove->{$mapid}) {
2410: $skip = 1;
2411: }
2412: }
1.491 raeburn 2413: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2414: return if ($file eq '-1');
2415: my $parser = HTML::TokeParser->new(\$file);
2416: $parser->attr_encoded(1);
1.491 raeburn 2417: my $changed = 0;
1.488 raeburn 2418: while (my $token = $parser->get_token) {
2419: next if ($token->[0] ne 'S');
2420: if ($token->[1] eq 'resource') {
2421: my $ressrc = $token->[2]->{'src'};
2422: next if ($ressrc eq '');
1.491 raeburn 2423: my $id = $token->[2]->{'id'};
1.492 raeburn 2424: my $title = $token->[2]->{'title'};
1.491 raeburn 2425: if ($checktitle) {
2426: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2427: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2428: }
2429: }
1.488 raeburn 2430: next if ($token->[2]->{'type'} eq 'external');
2431: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2432: next if ($skip);
1.532 raeburn 2433: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2434: $changed = 1;
2435: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2436: my $srcdom = $1;
2437: my $srcnum = $2;
1.488 raeburn 2438: my $rem = $3;
1.492 raeburn 2439: my $newurl;
2440: my $mapname;
2441: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2442: my $prefix = $1;
2443: $mapname = $prefix.$2;
2444: if ($tomove->{$mapname}) {
1.533 raeburn 2445: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2446: $srcdom,$srcnum,$allmaps,$rewrites,
2447: $retitles,$copies,$dbcopies,$zombies,
2448: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2449: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2450: next;
2451: } else {
2452: ($newurl,my $error) =
2453: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2454: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2455: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2456: $newsubdir->{$ressrc} = $1;
2457: }
2458: if ($error) {
2459: next;
2460: }
2461: }
2462: }
2463: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2464: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2465:
1.488 raeburn 2466: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2467: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2468: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2469: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2470: $cnum,$srcdom,$srcnum,$allmaps,
2471: $rewrites,$retitles,$copies,$dbcopies,
2472: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2473: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2474: $mapmoves->{$ressrc} = 1;
2475: }
2476: $changed = 1;
1.488 raeburn 2477: } else {
1.532 raeburn 2478: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2479: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2480: $changed = 1;
1.488 raeburn 2481: }
2482: }
1.533 raeburn 2483: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2484: next if ($skip);
1.492 raeburn 2485: my $srcdom = $1;
2486: my $srcnum = $2;
2487: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2488: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2489: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2490: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2491: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2492: $changed = 1;
2493: }
2494: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2495: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2496: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2497: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2498: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2499: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2500: $changed = 1;
1.488 raeburn 2501: }
1.597 raeburn 2502: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2503: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2504: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2505: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2506: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2507: }
1.488 raeburn 2508: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2509: next if ($skip);
2510: my $srcdom = $1;
2511: my $srcnum = $2;
2512: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2513: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2514: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2515: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2516: $changed = 1;
1.488 raeburn 2517: }
2518: }
2519: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2520: next if ($skip);
1.488 raeburn 2521: my $to = $token->[2]->{'to'};
2522: if ($to ne '') {
2523: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2524: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2525: } else {
2526: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2527: }
2528: }
2529: }
2530: }
1.491 raeburn 2531: return $changed;
1.488 raeburn 2532: }
2533:
2534: sub apply_fixups {
1.529 raeburn 2535: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2536: $oldurl,$url,$caller) = @_;
2537: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2538: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2539: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2540: if (ref($updated) eq 'HASH') {
2541: if (ref($updated->{'rewrites'}) eq 'HASH') {
2542: %rewrites = %{$updated->{'rewrites'}};
2543: }
2544: if (ref($updated->{'zombies'}) eq 'HASH') {
2545: %zombies = %{$updated->{'zombies'}};
2546: }
2547: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2548: %removefrommap = %{$updated->{'removefrommap'}};
2549: }
2550: if (ref($updated->{'removeparam'}) eq 'HASH') {
2551: %removeparam = %{$updated->{'removeparam'}};
2552: }
2553: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2554: %dbcopies = %{$updated->{'dbcopies'}};
2555: }
2556: if (ref($updated->{'retitles'}) eq 'HASH') {
2557: %retitles = %{$updated->{'retitles'}};
2558: }
1.597 raeburn 2559: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2560: %resdatacopy = %{$updated->{'resdatacopy'}};
2561: }
1.529 raeburn 2562: }
2563: if (ref($info) eq 'HASH') {
2564: if (ref($info->{'newsubdir'}) eq 'HASH') {
2565: %newsubdir = %{$info->{'newsubdir'}};
2566: }
2567: if (ref($info->{'params'}) eq 'HASH') {
2568: %params = %{$info->{'params'}};
2569: }
2570: if (ref($info->{'before'}) eq 'HASH') {
2571: %before = %{$info->{'before'}};
2572: }
2573: if (ref($info->{'after'}) eq 'HASH') {
2574: %after = %{$info->{'after'}};
2575: }
2576: }
2577: if (ref($moves) eq 'HASH') {
2578: if (ref($moves->{'copies'}) eq 'HASH') {
2579: %copies = %{$moves->{'copies'}};
2580: }
2581: if (ref($moves->{'docmoves'}) eq 'HASH') {
2582: %docmoves = %{$moves->{'docmoves'}};
2583: }
2584: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2585: %mapmoves = %{$moves->{'mapmoves'}};
2586: }
2587: }
2588: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2589: my @allcopies;
1.529 raeburn 2590: if (exists($copies{$key})) {
2591: if (ref($copies{$key}) eq 'HASH') {
2592: my %added;
2593: foreach my $innerkey (keys(%{$copies{$key}})) {
2594: if (($innerkey ne '') && (!$added{$innerkey})) {
2595: push(@allcopies,$innerkey);
2596: $added{$innerkey} = 1;
2597: }
1.491 raeburn 2598: }
1.529 raeburn 2599: undef(%added);
1.491 raeburn 2600: }
2601: }
2602: if ($key eq $oldurl) {
1.529 raeburn 2603: if ((exists($docmoves{$key}))) {
1.532 raeburn 2604: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2605: push(@allcopies,$oldurl);
2606: }
2607: }
2608: }
2609: if (@allcopies > 0) {
2610: foreach my $item (@allcopies) {
1.492 raeburn 2611: my ($relpath,$oldsubdir,$fname) =
2612: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2613: if ($fname ne '') {
2614: my $content = &Apache::lonnet::getfile($item);
2615: unless ($content eq '-1') {
2616: my $storefn;
1.529 raeburn 2617: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2618: $storefn = $docmoves{$key};
1.491 raeburn 2619: } else {
2620: $storefn = $relpath;
2621: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2622: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2623: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2624: }
1.529 raeburn 2625: if ($newsubdir{$key}) {
1.532 raeburn 2626: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2627: }
2628: }
2629: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2630: my $copyurl =
2631: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2632: $storefn.$fname,$content);
2633: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2634: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2635: return &mt('Paste failed: an error occurred copying the file.');
2636: } elsif (ref($errors) eq 'HASH') {
2637: $errors->{$item} = 1;
1.489 raeburn 2638: }
2639: }
1.488 raeburn 2640: }
2641: }
1.491 raeburn 2642: }
2643: }
2644: }
1.529 raeburn 2645: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2646: my $storefn=$key;
2647: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2648: if ($prefixchg && $before{'map'} && $after{'map'}) {
2649: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2650: }
1.529 raeburn 2651: if ($newsubdir{$key}) {
2652: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2653: }
1.491 raeburn 2654: my $mapcontent = &Apache::lonnet::getfile($key);
2655: if ($mapcontent eq '-1') {
2656: if (ref($errors) eq 'HASH') {
2657: $errors->{$key} = 1;
2658: }
2659: } else {
2660: my $newmap =
2661: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2662: $mapcontent);
2663: if ($newmap eq '/adm/notfound.html') {
2664: if (ref($errors) eq 'HASH') {
2665: $errors->{$key} = 1;
1.489 raeburn 2666: }
1.488 raeburn 2667: }
2668: }
2669: }
1.491 raeburn 2670: my %updates;
2671: if ($is_map) {
1.529 raeburn 2672: if (ref($updated) eq 'HASH') {
2673: foreach my $type (keys(%{$updated})) {
2674: if (ref($updated->{$type}) eq 'HASH') {
2675: foreach my $key (keys(%{$updated->{$type}})) {
2676: $updates{$key} = 1;
2677: }
2678: }
2679: }
1.491 raeburn 2680: }
2681: foreach my $key (keys(%updates)) {
1.492 raeburn 2682: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2683: if (ref($rewrites{$key}) eq 'HASH') {
2684: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2685: }
1.529 raeburn 2686: if (ref($retitles{$key}) eq 'HASH') {
2687: %toretitle = %{$retitles{$key}};
1.491 raeburn 2688: }
1.529 raeburn 2689: if (ref($removefrommap{$key}) eq 'HASH') {
2690: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2691: }
1.529 raeburn 2692: if (ref($removeparam{$key}) eq 'HASH') {
2693: %remparam = %{$removeparam{$key}};
1.492 raeburn 2694: }
1.529 raeburn 2695: if (ref($zombies{$key}) eq 'HASH') {
2696: %zombie = %{$zombies{$key}};
1.491 raeburn 2697: }
1.529 raeburn 2698: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2699: foreach my $idx (keys(%{$dbcopies{$key}})) {
2700: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2701: my ($newurl,$result,$errtext) =
2702: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2703: if ($result eq 'ok') {
2704: $newdb{$idx} = $newurl;
2705: } elsif (ref($errors) eq 'HASH') {
2706: $errors->{$key} = 1;
2707: }
2708: push(@msgs,$errtext);
2709: }
1.491 raeburn 2710: }
2711: }
1.597 raeburn 2712: if (ref($resdatacopy{$key}) eq 'HASH') {
2713: if ($newsubdir{$key}) {
2714:
2715: }
2716: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2717: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2718: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2719: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2720: my $template = $1;
2721: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2722: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2723: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2724: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2725: my ($newmapname) = ($key =~ m{/([^/]+)$});
2726: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2727: my $srcmapinfo = $srcfolder.':'.$idx;
2728: if ($srccontainer eq 'page') {
2729: $srcmapinfo .= ':1';
2730: }
2731: if ($newsubdir{$key}) {
2732: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2733: }
2734: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2735: $cnum,$template,$idx,$newmapname);
2736: }
2737: }
2738: }
2739: }
2740: }
1.529 raeburn 2741: if (ref($params{$key}) eq 'HASH') {
2742: %currparam = %{$params{$key}};
1.492 raeburn 2743: }
2744: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2745: if ($fatal) {
1.533 raeburn 2746: return ($errtext);
1.492 raeburn 2747: }
2748: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2749: if (defined($LONCAPA::map::zombies[$i])) {
2750: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2751: if ($zombie{$i} eq $src) {
1.492 raeburn 2752: undef($LONCAPA::map::zombies[$i]);
2753: }
2754: }
2755: }
1.529 raeburn 2756: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2757: my $idx = $LONCAPA::map::order[$i];
2758: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2759: my $changed;
1.529 raeburn 2760: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2761: if ((exists($toremove{$idx})) &&
2762: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2763: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2764: if (ref($currparam{$idx}) eq 'ARRAY') {
2765: foreach my $name (@{$currparam{$idx}}) {
2766: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2767: }
2768: }
2769: next;
2770: }
2771: my $origsrc = $src;
1.532 raeburn 2772: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2773: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2774: $changed = 1;
1.491 raeburn 2775: }
1.492 raeburn 2776: }
1.532 raeburn 2777: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2778: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2779: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2780: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2781: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2782: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2783: } else {
1.529 raeburn 2784: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2785: }
1.491 raeburn 2786: }
1.532 raeburn 2787: if ($origsrc =~ /\.(page|sequence)$/) {
2788: if ($newsubdir{$origsrc}) {
1.529 raeburn 2789: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2790: }
1.532 raeburn 2791: } elsif ($newsubdir{$key}) {
2792: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2793: }
2794: }
1.492 raeburn 2795: $changed = 1;
1.533 raeburn 2796: } elsif ($newdb{$idx} ne '') {
2797: $src = $newdb{$idx};
1.492 raeburn 2798: $changed = 1;
2799: }
2800: if ($changed) {
1.538 raeburn 2801: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2802: }
2803: }
2804: }
2805: foreach my $idx (keys(%remparam)) {
2806: if (ref($remparam{$idx}) eq 'ARRAY') {
2807: foreach my $name (@{$remparam{$idx}}) {
2808: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2809: }
2810: }
2811: }
1.533 raeburn 2812: if (values(%lockerrors) > 0) {
2813: $lockmsg = join('<br />',values(%lockerrors));
2814: }
1.491 raeburn 2815: my $storefn;
2816: if ($key eq $oldurl) {
2817: $storefn = $url;
2818: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2819: } else {
2820: $storefn = $key;
2821: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2822: if ($prefixchg && $before{'map'} && $after{'map'}) {
2823: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2824: }
1.529 raeburn 2825: if ($newsubdir{$key}) {
2826: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2827: }
1.491 raeburn 2828: }
1.492 raeburn 2829: my $report;
2830: if ($folder !~ /^supplemental/) {
2831: $report = 1;
2832: }
1.527 raeburn 2833: (my $outtext,$errtext) =
1.492 raeburn 2834: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2835: if ($errtext) {
1.529 raeburn 2836: if ($caller eq 'paste') {
1.533 raeburn 2837: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2838: }
1.491 raeburn 2839: }
2840: }
2841: }
1.533 raeburn 2842: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2843: }
2844:
2845: sub copy_dependencies {
2846: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2847: my $content;
2848: if (ref($contentref)) {
2849: $content = $$contentref;
2850: } else {
2851: $content = &Apache::lonnet::getfile($item);
2852: }
2853: unless ($content eq '-1') {
2854: my $mm = new File::MMagic;
2855: my $mimetype = $mm->checktype_contents($content);
2856: if ($mimetype eq 'text/html') {
2857: my (%allfiles,%codebase,$state);
2858: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2859: if ($res eq 'ok') {
2860: my ($numexisting,$numpathchanges,$existing);
2861: (undef,$numexisting,$numpathchanges,$existing) =
2862: &Apache::loncommon::ask_for_embedded_content(
2863: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2864: {'error_on_invalid_names' => 1,
2865: 'ignore_remote_references' => 1,
2866: 'docs_url' => $item,
2867: 'context' => 'paste'});
2868: if ($numexisting > 0) {
2869: if (ref($existing) eq 'HASH') {
2870: foreach my $dep (keys(%{$existing})) {
2871: my $depfile = $dep;
2872: unless ($depfile =~ m{^\Q$relpath\E}) {
2873: $depfile = $relpath.$dep;
2874: }
2875: my $depcontent = &Apache::lonnet::getfile($depfile);
2876: unless ($depcontent eq '-1') {
2877: my $storedep = $dep;
2878: $storedep =~ s{^\Q$relpath\E}{};
2879: my $dep_url =
2880: &Apache::lonclonecourse::writefile(
2881: $env{'request.course.id'},
2882: $storefn.$storedep,$depcontent);
2883: if ($dep_url eq '/adm/notfound.html') {
2884: if (ref($errors) eq 'HASH') {
2885: $errors->{$depfile} = 1;
2886: }
2887: } else {
2888: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2889: }
2890: }
2891: }
1.488 raeburn 2892: }
2893: }
2894: }
2895: }
2896: }
2897: return;
2898: }
2899:
1.329 droeschl 2900: my %parameter_type = ( 'randompick' => 'int_pos',
2901: 'hiddenresource' => 'string_yesno',
2902: 'encrypturl' => 'string_yesno',
2903: 'randomorder' => 'string_yesno',);
2904: my $valid_parameters_re = join('|',keys(%parameter_type));
2905: # set parameters
2906: sub update_parameter {
1.537 raeburn 2907: if ($env{'form.changeparms'} eq 'all') {
2908: my (@allidx,@allmapidx,%allchecked,%currchecked);
2909: %allchecked = (
2910: 'hiddenresource' => {},
2911: 'encrypturl' => {},
2912: 'randompick' => {},
2913: 'randomorder' => {},
2914: );
2915: foreach my $which (keys(%allchecked)) {
1.630 raeburn 2916: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 2917: if ($which eq 'randompick') {
2918: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2919: my ($res,$value) = split(/:/,$item);
2920: if ($value =~ /^\d+$/) {
2921: $allchecked{$which}{$res} = $value;
2922: }
2923: }
2924: } else {
1.539 raeburn 2925: if ($env{'form.all'.$which}) {
2926: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2927: }
1.537 raeburn 2928: }
2929: }
2930: my $haschanges = 0;
2931: foreach my $res (@LONCAPA::map::order) {
2932: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2933: $name=&LONCAPA::map::qtescape($name);
2934: $url=&LONCAPA::map::qtescape($url);
2935: next unless ($name && $url);
2936: my $is_map;
2937: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2938: $is_map = 1;
2939: }
2940: foreach my $which (keys(%allchecked)) {
2941: if (($which eq 'randompick' || $which eq 'randomorder')) {
2942: next if (!$is_map);
2943: }
2944: my $oldvalue = 0;
2945: my $newvalue = 0;
2946: if ($allchecked{$which}{$res}) {
2947: $newvalue = $allchecked{$which}{$res};
2948: }
2949: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2950: if ($which eq 'randompick') {
2951: if ($current =~ /^(\d+)$/) {
2952: $oldvalue = $1;
2953: }
2954: } else {
2955: if ($current =~ /^yes$/i) {
2956: $oldvalue = 1;
2957: }
2958: }
2959: if ($oldvalue ne $newvalue) {
2960: $haschanges = 1;
2961: if ($newvalue) {
2962: my $storeval = 'yes';
2963: if ($which eq 'randompick') {
2964: $storeval = $newvalue;
2965: }
2966: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2967: $storeval,
2968: $parameter_type{$which});
2969: &remember_parms($res,$which,'set',$storeval);
2970: } elsif ($oldvalue) {
2971: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2972: &remember_parms($res,$which,'del');
2973: }
2974: }
2975: }
2976: }
2977: return $haschanges;
2978: } else {
1.588 raeburn 2979: my $haschanges = 0;
2980: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2981:
1.537 raeburn 2982: my $which = $env{'form.changeparms'};
2983: my $idx = $env{'form.setparms'};
1.588 raeburn 2984: my $oldvalue = 0;
2985: my $newvalue = 0;
2986: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2987: if ($which eq 'randompick') {
2988: if ($current =~ /^(\d+)$/) {
2989: $oldvalue = $1;
2990: }
2991: } elsif ($current =~ /^yes$/i) {
2992: $oldvalue = 1;
2993: }
1.537 raeburn 2994: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2995: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2996: : 1;
2997: }
2998: if ($oldvalue ne $newvalue) {
2999: $haschanges = 1;
3000: if ($newvalue) {
3001: my $storeval = 'yes';
3002: if ($which eq 'randompick') {
3003: $storeval = $newvalue;
3004: }
3005: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3006: $parameter_type{$which});
3007: &remember_parms($idx,$which,'set',$storeval);
3008: } else {
3009: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3010: &remember_parms($idx,$which,'del');
3011: }
1.537 raeburn 3012: }
1.588 raeburn 3013: return $haschanges;
1.329 droeschl 3014: }
3015: }
3016:
3017: sub handle_edit_cmd {
3018: my ($coursenum,$coursedom) =@_;
1.543 raeburn 3019: if ($env{'form.cmd'} eq '') {
3020: return 0;
3021: }
1.329 droeschl 3022: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3023:
3024: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3025: my ($title, $url, @rrest) = split(':', $ratstr);
3026:
1.538 raeburn 3027: if ($cmd eq 'remove') {
1.329 droeschl 3028: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3029: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3030: &Apache::lonnet::removeuploadedurl($url);
3031: } else {
3032: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3033: }
3034: splice(@LONCAPA::map::order, $idx, 1);
3035:
3036: } elsif ($cmd eq 'cut') {
3037: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3038: splice(@LONCAPA::map::order, $idx, 1);
3039:
1.344 bisitz 3040: } elsif ($cmd eq 'up'
1.329 droeschl 3041: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3042: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3043:
3044: } elsif ($cmd eq 'down'
3045: && defined($LONCAPA::map::order[$idx+1])) {
3046: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3047:
3048: } elsif ($cmd eq 'rename') {
3049: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3050: if ($comment=~/\S/) {
3051: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3052: $comment.':'.join(':', $url, @rrest);
3053: }
3054: # Devalidate title cache
3055: my $renamed_url=&LONCAPA::map::qtescape($url);
3056: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 3057:
1.329 droeschl 3058: } else {
3059: return 0;
3060: }
3061: return 1;
3062: }
3063:
3064: sub editor {
1.458 raeburn 3065: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3066: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3067: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3068: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3069: if ($allowed) {
1.519 raeburn 3070: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3071: $is_random_order,$container) =
1.510 raeburn 3072: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3073: $r->print($breadcrumbtrail);
1.519 raeburn 3074: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3075: $container = 'page';
3076: } else {
3077: $container = 'sequence';
1.510 raeburn 3078: }
1.484 raeburn 3079:
1.525 raeburn 3080: my $jumpto;
3081:
3082: unless ($supplementalflag) {
1.546 raeburn 3083: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3084: }
1.484 raeburn 3085:
3086: unless ($allowed) {
3087: $randompick = -1;
3088: }
3089:
1.615 raeburn 3090: my ($errtext,$fatal);
3091: if (($folder eq '') && (!$supplementalflag)) {
3092: if (@LONCAPA::map::order) {
3093: undef(@LONCAPA::map::order);
3094: undef(@LONCAPA::map::resources);
3095: undef(@LONCAPA::map::resparms);
3096: undef(@LONCAPA::map::zombies);
3097: }
3098: $folder = 'default';
3099: $container = 'sequence';
3100: } else {
3101: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3102: $folder.'.'.$container);
3103: return $errtext if ($fatal);
3104: }
1.329 droeschl 3105:
3106: if ($#LONCAPA::map::order<1) {
3107: my $idx=&LONCAPA::map::getresidx();
3108: if ($idx<=0) { $idx=1; }
3109: $LONCAPA::map::order[0]=$idx;
3110: $LONCAPA::map::resources[$idx]='';
3111: }
1.364 bisitz 3112:
1.329 droeschl 3113: # ------------------------------------------------------------ Process commands
3114:
3115: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3116: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3117: # set parameters and change order
3118: &snapshotbefore();
3119:
3120: if (&update_parameter()) {
1.588 raeburn 3121: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3122: return $errtext if ($fatal);
3123: }
3124:
3125: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3126: # change order
3127: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3128: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3129:
3130: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3131: return $errtext if ($fatal);
3132: }
1.364 bisitz 3133:
1.329 droeschl 3134: if ($env{'form.pastemarked'}) {
1.491 raeburn 3135: my %paste_errors;
1.533 raeburn 3136: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3137: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3138: \%paste_errors);
1.541 raeburn 3139: if (ref($pastemsgarray) eq 'ARRAY') {
3140: if (@{$pastemsgarray} > 0) {
3141: $r->print('<p class="LC_info">'.
3142: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3143: '</p>');
3144: }
1.541 raeburn 3145: }
3146: if ($lockerror) {
3147: $r->print('<p class="LC_error">'.
3148: $lockerror.
3149: '</p>');
3150: }
3151: if ($save_error ne '') {
3152: return $save_error;
3153: }
3154: if ($paste_res) {
3155: my %errortext = &Apache::lonlocal::texthash (
3156: fail => 'Storage of folder contents failed',
3157: failread => 'Reading folder contents failed',
3158: failstore => 'Storage of folder contents failed',
3159: );
3160: if ($errortext{$paste_res}) {
3161: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3162: }
1.329 droeschl 3163: }
1.491 raeburn 3164: if (keys(%paste_errors) > 0) {
1.538 raeburn 3165: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3166: &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".
3167: '<ul>'."\n");
3168: foreach my $key (sort(keys(%paste_errors))) {
3169: $r->print('<li>'.$key.'</li>'."\n");
3170: }
3171: $r->print('</ul></p>'."\n");
3172: }
1.538 raeburn 3173: } elsif ($env{'form.clearmarked'}) {
3174: my $output = &do_buffer_empty();
3175: if ($output) {
3176: $r->print('<p class="LC_info">'.$output.'</p>');
3177: }
3178: }
1.329 droeschl 3179:
3180: $r->print($upload_output);
3181:
1.538 raeburn 3182: # Rename, cut, copy or remove a single resource
1.602 raeburn 3183: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3184: my $contentchg;
1.592 raeburn 3185: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 3186: $contentchg = 1;
3187: }
3188: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3189: return $errtext if ($fatal);
3190: }
1.538 raeburn 3191:
3192: # Cut, copy and/or remove multiple resources
3193: if ($env{'form.multichange'}) {
3194: my %allchecked = (
3195: cut => {},
3196: remove => {},
3197: );
3198: my $needsupdate;
3199: foreach my $which (keys(%allchecked)) {
3200: $env{'form.multi'.$which} =~ s/,$//;
3201: if ($env{'form.multi'.$which}) {
3202: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3203: if (ref($allchecked{$which}) eq 'HASH') {
3204: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3205: }
3206: }
3207: }
3208: if ($needsupdate) {
3209: my $haschanges = 0;
3210: my %curr_groups = &Apache::longroup::coursegroups();
3211: my $total = scalar(@LONCAPA::map::order) - 1;
3212: for (my $i=$total; $i>=0; $i--) {
3213: my $res = $LONCAPA::map::order[$i];
3214: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3215: $name=&LONCAPA::map::qtescape($name);
3216: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3217: next unless $url;
1.538 raeburn 3218: my %denied =
3219: &action_restrictions($coursenum,$coursedom,$url,
3220: $env{'form.folderpath'},\%curr_groups);
3221: foreach my $which (keys(%allchecked)) {
3222: next if ($denied{$which});
3223: next unless ($allchecked{$which}{$res});
3224: if ($which eq 'remove') {
3225: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3226: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3227: &Apache::lonnet::removeuploadedurl($url);
3228: } else {
3229: &LONCAPA::map::makezombie($res);
3230: }
3231: splice(@LONCAPA::map::order,$i,1);
3232: $haschanges ++;
3233: } elsif ($which eq 'cut') {
3234: &LONCAPA::map::makezombie($res);
3235: splice(@LONCAPA::map::order,$i,1);
3236: $haschanges ++;
3237: }
3238: }
3239: }
3240: if ($haschanges) {
3241: ($errtext,$fatal) =
3242: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3243: return $errtext if ($fatal);
3244: }
3245: }
3246: }
3247:
1.329 droeschl 3248: # Group import/search
3249: if ($env{'form.importdetail'}) {
3250: my @imports;
3251: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3252: if (defined($item)) {
3253: my ($name,$url,$residx)=
1.533 raeburn 3254: map { &unescape($_); } split(/\=/,$item);
3255: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3256: my ($suffix,$errortxt,$locknotfreed) =
3257: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3258: if ($locknotfreed) {
3259: $r->print($locknotfreed);
3260: }
3261: if ($suffix) {
3262: $url =~ s/_new\./_$suffix./;
3263: } else {
3264: return $errortxt;
3265: }
1.533 raeburn 3266: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3267: my $type = $1;
3268: my ($suffix,$errortxt,$locknotfreed) =
3269: &new_timebased_suffix($coursedom,$coursenum,$type);
3270: if ($locknotfreed) {
3271: $r->print($locknotfreed);
3272: }
3273: if ($suffix) {
3274: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3275: } else {
3276: return $errortxt;
3277: }
1.626 raeburn 3278: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3279: my ($suffix,$errortxt,$locknotfreed) =
3280: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3281: if ($locknotfreed) {
3282: $r->print($locknotfreed);
3283: }
3284: if ($suffix) {
3285: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3286: } else {
3287: return $errortxt;
3288: }
1.534 raeburn 3289: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3290: if ($supplementalflag) {
3291: next unless ($1 eq 'supplemental');
3292: if ($folder eq 'supplemental') {
3293: next unless ($2 eq 'default');
3294: } else {
3295: next unless ($folder eq 'supplemental_'.$2);
3296: }
3297: } else {
3298: next unless ($1 eq 'docs');
3299: if ($folder eq 'default') {
3300: next unless ($2 eq 'default');
3301: } else {
3302: next unless ($folder eq 'default_'.$2);
3303: }
3304: }
1.504 raeburn 3305: }
1.329 droeschl 3306: push(@imports, [$name, $url, $residx]);
3307: }
3308: }
1.530 raeburn 3309: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3310: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3311: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3312: return $errtext if ($fatal);
1.529 raeburn 3313: if ($fixuperrors) {
3314: $r->print($fixuperrors);
3315: }
1.329 droeschl 3316: }
3317: # Loading a complete map
3318: if ($env{'form.loadmap'}) {
3319: if ($env{'form.importmap'}=~/\w/) {
3320: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3321: my ($title,$url,$ext,$type)=split(/\:/,$res);
3322: my $idx=&LONCAPA::map::getresidx($url);
3323: $LONCAPA::map::resources[$idx]=$res;
3324: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3325: }
3326: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3327: $folder.'.'.$container,1);
1.329 droeschl 3328: return $errtext if ($fatal);
3329: } else {
3330: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3331:
1.329 droeschl 3332: }
3333: }
3334: &log_differences($plain);
3335: }
3336: # ---------------------------------------------------------------- End commands
3337: # ---------------------------------------------------------------- Print screen
3338: my $idx=0;
3339: my $shown=0;
3340: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3341: $r->print('<div class="LC_Box">'.
1.432 raeburn 3342: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3343: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3344: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3345: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3346: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3347: '</ol>');
1.381 bisitz 3348: if ($randompick>=0) {
3349: $r->print('<p class="LC_warning">'
3350: .&mt('Caution: this folder is set to randomly pick a subset'
3351: .' of resources. Adding or removing resources from this'
3352: .' folder will change the set of resources that the'
3353: .' students see, resulting in spurious or missing credit'
3354: .' for completed problems, not limited to ones you'
3355: .' modify. Do not modify the contents of this folder if'
3356: .' it is in active student use.')
3357: .'</p>'
3358: );
3359: }
3360: if ($is_random_order) {
3361: $r->print('<p class="LC_warning">'
3362: .&mt('Caution: this folder is set to randomly order its'
3363: .' contents. Adding or removing resources from this folder'
3364: .' will change the order of resources shown.')
3365: .'</p>'
3366: );
3367: }
3368: $r->print('</div>');
1.364 bisitz 3369: }
1.381 bisitz 3370:
1.538 raeburn 3371: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3372: %filters = (
1.543 raeburn 3373: canremove => [],
3374: cancut => [],
3375: cancopy => [],
3376: hiddenresource => [],
3377: encrypturl => [],
3378: randomorder => [],
3379: randompick => [],
1.538 raeburn 3380: );
3381: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3382: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3383: foreach my $res (@LONCAPA::map::order) {
3384: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3385: $name=&LONCAPA::map::qtescape($name);
3386: $url=&LONCAPA::map::qtescape($url);
3387: unless ($name) { $name=(split(/\//,$url))[-1]; }
3388: unless ($name) { $idx++; next; }
1.537 raeburn 3389: push(@allidx,$res);
3390: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3391: push(@allmapidx,$res);
3392: }
1.617 raeburn 3393:
1.381 bisitz 3394: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3395: $coursenum,$coursedom,$crstype,
1.538 raeburn 3396: $pathitem,$supplementalflag,$container,
1.620 raeburn 3397: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3398: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3399: $idx++;
3400: $shown++;
1.329 droeschl 3401: }
1.424 onken 3402: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3403:
1.538 raeburn 3404: my $need_save;
1.611 raeburn 3405: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3406: my $toolslink;
1.611 raeburn 3407: if ($allowed) {
1.544 raeburn 3408: $toolslink = '<table><tr><td>'
1.520 raeburn 3409: .&Apache::loncommon::help_open_menu('Navigation Screen',
3410: 'Navigation_Screen',undef,'RAT')
3411: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3412: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3413: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3414: .'id="LC_content_toolbar_edittoplevel" '
3415: .'class="LC_toolbarItem" '
3416: .'title="'.&mt('Supplemental Content Editor').'">'
3417: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3418: }
1.510 raeburn 3419: if ($shown) {
3420: if ($allowed) {
3421: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3422: .&Apache::loncommon::start_data_table(undef,'contentlist')
3423: .&Apache::loncommon::start_data_table_header_row()
3424: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3425: .'<th colspan="2">'.&mt('Actions').'</th>'
3426: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3427: if ($folder !~ /^supplemental/) {
3428: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3429: }
1.537 raeburn 3430: $to_show .= &Apache::loncommon::end_data_table_header_row();
3431: if ($folder !~ /^supplemental/) {
1.538 raeburn 3432: $lists{'canhide'} = join(',',@allidx);
3433: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3434: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3435: 'randomorder','randompick');
3436: foreach my $item (@possfilters) {
1.538 raeburn 3437: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3438: if (@{$filters{$item}} > 0) {
3439: $lists{$item} = join(',',@{$filters{$item}});
3440: }
1.538 raeburn 3441: }
3442: }
1.537 raeburn 3443: if (@allidx > 0) {
3444: my $path;
3445: if ($env{'form.folderpath'}) {
1.630 raeburn 3446: $path =
1.537 raeburn 3447: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3448: }
1.538 raeburn 3449: if (@allidx > 1) {
1.630 raeburn 3450: $to_show .=
1.538 raeburn 3451: &Apache::loncommon::continue_data_table_row().
3452: '<td colspan="2"> </td>'.
3453: '<td>'.
1.611 raeburn 3454: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3455: '</td>'.
3456: '<td> </td>'.
3457: '<td> </td>'.
3458: '<td colspan="4">'.
1.611 raeburn 3459: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3460: '</td>'.
3461: &Apache::loncommon::end_data_table_row();
3462: $need_save = 1;
3463: }
1.537 raeburn 3464: }
3465: }
3466: $to_show .= $output.' '
1.510 raeburn 3467: .&Apache::loncommon::end_data_table()
3468: .'<br style="line-height:2px;" />'
3469: .&Apache::loncommon::end_scrollbox();
3470: } else {
1.520 raeburn 3471: $to_show .= $toolslink
1.510 raeburn 3472: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3473: .$output.' '
3474: .&Apache::loncommon::end_data_table();
1.393 raeburn 3475: }
1.510 raeburn 3476: } else {
1.520 raeburn 3477: if (!$allowed) {
3478: $to_show .= $toolslink;
3479: }
1.615 raeburn 3480: my $noresmsg;
3481: if ($allowed && $hiddentop && !$supplementalflag) {
3482: $noresmsg = &mt('Main Content Hidden');
3483: } else {
3484: $noresmsg = &mt('Currently empty');
3485: }
1.510 raeburn 3486: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3487: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3488: .$noresmsg
1.510 raeburn 3489: .'</div>'
3490: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3491: }
3492: } else {
1.510 raeburn 3493: if ($shown) {
3494: $to_show = '<div>'
3495: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3496: .$output
3497: .&Apache::loncommon::end_data_table()
3498: .'</div>';
3499: } else {
3500: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3501: .&mt('Currently empty')
1.510 raeburn 3502: .'</div>'
3503: }
1.458 raeburn 3504: }
3505: my $tid = 1;
3506: if ($supplementalflag) {
3507: $tid = 2;
1.329 droeschl 3508: }
3509: if ($allowed) {
1.484 raeburn 3510: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3511: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3512: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3513: if ($canedit) {
3514: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3515: }
1.460 raeburn 3516: } else {
3517: $r->print($to_show);
1.329 droeschl 3518: }
3519: return;
3520: }
3521:
1.538 raeburn 3522: sub multiple_check_form {
1.611 raeburn 3523: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3524: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3525: my $disabled;
3526: unless ($canedit) {
3527: $disabled = 'disabled="disabled"';
3528: }
1.538 raeburn 3529: my $output =
3530: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3531: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3532: '<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>'.
3533: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3534: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3535: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3536: if ($caller eq 'settings') {
3537: $output .=
3538: '<table><tr>'.
3539: '<td class="LC_docs_entry_parameter">'.
3540: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3541: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3542: '</label></span></td>'.
3543: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3544: '<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 3545: '</span></td>'.
3546: '</tr>'."\n".
3547: '<tr>'.
3548: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3549: '<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 3550: '</label></span>'.
3551: '</td></tr></table>'."\n";
3552: } else {
3553: $output .=
3554: '<table><tr>'.
3555: '<td class="LC_docs_entry_parameter">'.
3556: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3557: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3558: '</label></span></td>'.
3559: '<td class="LC_docs_entry_parameter">'.
3560: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3561: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3562: '</label></span></td>'."\n".
3563: '<td class="LC_docs_entry_parameter">'.
3564: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3565: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3566: '</label></span></td>'.
3567: '</tr></table>'."\n";
3568: }
3569: $output .=
3570: '</fieldset>'.
3571: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3572: if ($caller eq 'settings') {
3573: $output .=
1.543 raeburn 3574: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3575: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3576: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3577: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3578: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3579: } elsif ($caller eq 'actions') {
3580: $output .=
3581: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3582: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3583: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3584: }
3585: $output .=
3586: '</form>'.
3587: '</div>';
3588: return $output;
3589: }
3590:
1.329 droeschl 3591: sub process_file_upload {
1.552 raeburn 3592: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3593: # upload a file, if present
1.552 raeburn 3594: my $filesize = length($env{'form.uploaddoc'});
3595: if (!$filesize) {
3596: $$upload_output = '<div class="LC_error">'.
3597: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3598: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3599: $filesize).'<br />'.
3600: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3601: '</div>';
3602: return;
3603: }
3604: my $quotatype = 'unofficial';
3605: if ($crstype eq 'Community') {
1.601 raeburn 3606: $quotatype = 'community';
3607: } elsif ($crstype eq 'Placement') {
3608: $quotatype = 'placement';
1.580 raeburn 3609: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3610: $quotatype = 'official';
1.573 raeburn 3611: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3612: $quotatype = 'textbook';
1.552 raeburn 3613: }
3614: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3615: $filesize = int($filesize/1000); #expressed in kb
3616: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3617: $env{'form.uploaddoc.filename'},$filesize,
3618: 'upload',$quotatype);
1.552 raeburn 3619: return if ($$upload_output);
3620: }
1.440 raeburn 3621: my ($parseaction,$showupload,$nextphase,$mimetype);
3622: if ($env{'form.parserflag'}) {
1.329 droeschl 3623: $parseaction = 'parse';
3624: }
3625: my $folder=$env{'form.folder'};
3626: if ($folder eq '') {
3627: $folder='default';
3628: }
3629: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3630: my $errtext='';
3631: my $fatal=0;
3632: my $container='sequence';
1.519 raeburn 3633: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3634: $container='page';
3635: }
3636: ($errtext,$fatal)=
1.534 raeburn 3637: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3638: if ($#LONCAPA::map::order<1) {
3639: $LONCAPA::map::order[0]=1;
3640: $LONCAPA::map::resources[1]='';
3641: }
3642: my $destination = 'docs/';
3643: if ($folder =~ /^supplemental/) {
3644: $destination = 'supplemental/';
3645: }
3646: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3647: $destination .= 'default/';
3648: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3649: $destination .= $2.'/';
3650: }
1.534 raeburn 3651: if ($fatal) {
3652: $$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>';
3653: return;
3654: }
1.440 raeburn 3655: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3656: my $newidx=&LONCAPA::map::getresidx();
3657: $destination .= $newidx;
1.439 raeburn 3658: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3659: $parseaction,$allfiles,
1.440 raeburn 3660: $codebase,undef,undef,undef,undef,
3661: undef,undef,\$mimetype);
3662: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3663: my $stored = $1;
3664: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3665: $stored.'</span>').'</p>';
3666: } else {
3667: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3668:
1.457 raeburn 3669: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3670: return;
3671: }
1.329 droeschl 3672: my $ext='false';
3673: if ($url=~m{^http://}) { $ext='true'; }
3674: $url = &LONCAPA::map::qtunescape($url);
3675: my $comment=$env{'form.comment'};
3676: $comment = &LONCAPA::map::qtunescape($comment);
3677: if ($folder=~/^supplemental/) {
3678: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3679: $env{'user.domain'}.'___&&&___'.$comment;
3680: }
3681:
3682: $LONCAPA::map::resources[$newidx]=
3683: $comment.':'.$url.':'.$ext.':normal:res';
3684: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3685: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3686: $folder.'.'.$container,1);
1.329 droeschl 3687: if ($fatal) {
1.457 raeburn 3688: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3689: return;
1.329 droeschl 3690: } else {
1.440 raeburn 3691: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3692: $$upload_output = $showupload;
1.384 raeburn 3693: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3694: if ($total_embedded > 0) {
1.440 raeburn 3695: my $uploadphase = 'upload_embedded';
3696: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3697: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3698: my ($embedded,$num) =
1.440 raeburn 3699: &Apache::loncommon::ask_for_embedded_content(
3700: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3701: if ($embedded) {
3702: if ($num) {
3703: $$upload_output .=
3704: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3705: $nextphase = $uploadphase;
3706: } else {
3707: $$upload_output .= $embedded;
3708: }
3709: } else {
3710: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3711: }
1.329 droeschl 3712: } else {
1.440 raeburn 3713: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3714: }
1.457 raeburn 3715: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3716: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3717: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3718: $nextphase = 'decompress_uploaded';
3719: my $position = scalar(@LONCAPA::map::order)-1;
3720: my $noextract = &return_to_editor();
3721: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3722: my %archiveitems = (
3723: folderpath => $env{'form.folderpath'},
3724: cmd => $nextphase,
3725: newidx => $newidx,
3726: position => $position,
3727: phase => $nextphase,
1.477 raeburn 3728: comment => $comment,
1.480 raeburn 3729: );
3730: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3731: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3732: $$upload_output = $showupload.
3733: &Apache::loncommon::decompress_form($mimetype,
3734: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3735: \%archiveitems,\@current);
1.329 droeschl 3736: }
3737: }
3738: }
1.440 raeburn 3739: return $nextphase;
1.329 droeschl 3740: }
3741:
1.480 raeburn 3742: sub get_dir_list {
3743: my ($url,$coursenum,$coursedom,$newidx) = @_;
3744: my ($destination,$dir_root) = &embedded_destination();
3745: my ($dirlistref,$listerror) =
3746: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3747: my @dir_lines;
3748: my $dirptr=16384;
3749: if (ref($dirlistref) eq 'ARRAY') {
3750: foreach my $dir_line (sort
3751: {
3752: my ($afile)=split('&',$a,2);
3753: my ($bfile)=split('&',$b,2);
3754: return (lc($afile) cmp lc($bfile));
3755: } (@{$dirlistref})) {
3756: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3757: $filename =~ s/\s+$//;
3758: next if ($filename =~ /^\.\.?$/);
3759: my $isdir = 0;
3760: if ($dirptr&$testdir) {
3761: $isdir = 1;
3762: }
3763: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3764: }
3765: }
3766: return @dir_lines;
3767: }
3768:
1.329 droeschl 3769: sub is_supplemental_title {
3770: my ($title) = @_;
3771: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3772: }
3773:
3774: # --------------------------------------------------------------- An entry line
3775:
3776: sub entryline {
1.501 raeburn 3777: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3778: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3779: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3780: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3781: if (&is_supplemental_title($title)) {
1.488 raeburn 3782: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3783: } else {
3784: $title=&HTML::Entities::encode($title,'"<>&\'');
3785: $renametitle=$title;
3786: $foldertitle=$title;
3787: }
3788:
1.611 raeburn 3789: my ($disabled,$readonly,$js_lt);
3790: unless ($canedit) {
3791: $disabled = 'disabled="disabled"';
3792: $readonly = 1;
3793: }
3794:
1.329 droeschl 3795: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3796:
1.329 droeschl 3797: $renametitle=~s/\\/\\\\/g;
3798: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3799: $renametitle=~s/"/%22/g;
1.581 raeburn 3800: $renametitle=~s/ /%20/g;
3801: $oldtitle = $renametitle;
1.576 raeburn 3802: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3803: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3804: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3805: # Edit commands
1.535 raeburn 3806: my ($esc_path, $path, $symb);
1.329 droeschl 3807: if ($env{'form.folderpath'}) {
3808: $esc_path=&escape($env{'form.folderpath'});
3809: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3810: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3811: }
1.505 raeburn 3812: my $isexternal;
1.510 raeburn 3813: if ($residx) {
1.501 raeburn 3814: my $currurl = $url;
3815: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3816: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3817: $isexternal = 1;
3818: }
1.510 raeburn 3819: if (!$supplementalflag) {
3820: my $path = 'uploaded/'.
3821: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3822: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3823: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3824: $residx,
3825: &Apache::lonnet::declutter($currurl));
3826: }
1.501 raeburn 3827: }
1.538 raeburn 3828: my ($renamelink,%lt,$ishash);
3829: if (ref($filtersref) eq 'HASH') {
3830: $ishash = 1;
3831: }
3832:
1.329 droeschl 3833: if ($allowed) {
1.538 raeburn 3834: $form_start = '
3835: <form action="/adm/coursedocs" method="post">
3836: ';
3837: $form_common=(<<END);
3838: <input type="hidden" name="folderpath" value="$path" />
3839: <input type="hidden" name="symb" value="$symb" />
3840: END
3841: $form_param=(<<END);
3842: <input type="hidden" name="setparms" value="$orderidx" />
3843: <input type="hidden" name="changeparms" value="0" />
3844: END
3845: $form_end = '</form>';
3846:
1.329 droeschl 3847: my $incindex=$index+1;
3848: my $selectbox='';
1.471 raeburn 3849: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3850: ((split(/\:/,
1.344 bisitz 3851: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3852: ne '') &&
1.329 droeschl 3853: ((split(/\:/,
1.344 bisitz 3854: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3855: ne '')) {
3856: $selectbox=
3857: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3858: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3859: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3860: if ($i==$incindex) {
1.358 bisitz 3861: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3862: } else {
3863: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3864: }
3865: }
3866: $selectbox.='</select>';
3867: }
1.501 raeburn 3868: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3869: 'up' => 'Move Up',
3870: 'dw' => 'Move Down',
3871: 'rm' => 'Remove',
3872: 'ct' => 'Cut',
3873: 'rn' => 'Rename',
1.501 raeburn 3874: 'cp' => 'Copy',
3875: 'ex' => 'External Resource',
1.598 raeburn 3876: 'et' => 'External Tool',
1.501 raeburn 3877: 'ed' => 'Edit',
3878: 'pr' => 'Preview',
3879: 'sv' => 'Save',
3880: 'ul' => 'URL',
1.611 raeburn 3881: 'ti' => 'Title',
1.618 raeburn 3882: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3883: );
1.538 raeburn 3884: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3885: $env{'form.folderpath'},
3886: $currgroups);
1.517 raeburn 3887: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3888: my $skip_confirm = 0;
1.603 raeburn 3889: my $confirm_removal = 0;
1.329 droeschl 3890: if ( $folder =~ /^supplemental/
3891: || ($url =~ m{( /smppg$
3892: |/syllabus$
3893: |/aboutme$
3894: |/navmaps$
3895: |/bulletinboard$
1.626 raeburn 3896: |/ext\.tool$
1.505 raeburn 3897: |\.html$)}x)
3898: || $isexternal) {
1.329 droeschl 3899: $skip_confirm = 1;
3900: }
1.603 raeburn 3901: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3902: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3903: $confirm_removal = 1;
3904: }
1.329 droeschl 3905:
1.538 raeburn 3906: if ($denied{'copy'}) {
1.543 raeburn 3907: $copylink=(<<ENDCOPY)
1.507 raeburn 3908: <span style="visibility: hidden;">$lt{'cp'}</span>
3909: ENDCOPY
3910: } else {
1.538 raeburn 3911: my $formname = 'edit_copy_'.$orderidx;
3912: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3913: $copylink=(<<ENDCOPY);
1.538 raeburn 3914: <form name="$formname" method="post" action="/adm/coursedocs">
3915: $form_common
1.611 raeburn 3916: <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 3917: $form_end
1.329 droeschl 3918: ENDCOPY
1.538 raeburn 3919: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3920: push(@{$filtersref->{'cancopy'}},$orderidx);
3921: }
1.329 droeschl 3922: }
1.538 raeburn 3923: if ($denied{'cut'}) {
1.507 raeburn 3924: $cutlink=(<<ENDCUT);
3925: <span style="visibility: hidden;">$lt{'ct'}</span>
3926: ENDCUT
3927: } else {
1.538 raeburn 3928: my $formname = 'edit_cut_'.$orderidx;
3929: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3930: $cutlink=(<<ENDCUT);
1.538 raeburn 3931: <form name="$formname" method="post" action="/adm/coursedocs">
3932: $form_common
1.542 raeburn 3933: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3934: <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 3935: $form_end
1.329 droeschl 3936: ENDCUT
1.538 raeburn 3937: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3938: push(@{$filtersref->{'cancut'}},$orderidx);
3939: }
1.329 droeschl 3940: }
1.538 raeburn 3941: if ($denied{'remove'}) {
1.507 raeburn 3942: $removelink=(<<ENDREM);
3943: <span style="visibility: hidden;">$lt{'rm'}</a>
3944: ENDREM
3945: } else {
1.538 raeburn 3946: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3947: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3948: $removelink=(<<ENDREM);
1.538 raeburn 3949: <form name="$formname" method="post" action="/adm/coursedocs">
3950: $form_common
1.542 raeburn 3951: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3952: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 3953: <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 3954: $form_end
1.497 raeburn 3955: ENDREM
1.538 raeburn 3956: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3957: push(@{$filtersref->{'canremove'}},$orderidx);
3958: }
1.497 raeburn 3959: }
1.551 raeburn 3960: $renamelink=(<<ENDREN);
1.581 raeburn 3961: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3962: ENDREN
1.611 raeburn 3963: my ($uplink,$downlink);
3964: if ($canedit) {
3965: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3966: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3967: } else {
3968: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3969: $downlink = $uplink;
3970: }
1.329 droeschl 3971: $line.=(<<END);
3972: <td>
1.379 bisitz 3973: <div class="LC_docs_entry_move">
1.611 raeburn 3974: <a href="$uplink">
1.501 raeburn 3975: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3976: </a>
3977: </div>
3978: <div class="LC_docs_entry_move">
1.611 raeburn 3979: <a href="$downlink">
1.501 raeburn 3980: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3981: </a>
3982: </div>
1.329 droeschl 3983: </td>
3984: <td>
3985: $form_start
1.538 raeburn 3986: $form_param
1.478 raeburn 3987: $form_common
1.329 droeschl 3988: $selectbox
3989: $form_end
3990: </td>
1.540 raeburn 3991: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3992: $removelink
1.329 droeschl 3993: $cutlink
3994: $copylink
3995: </td>
3996: END
3997: }
3998: # Figure out what kind of a resource this is
3999: my ($extension)=($url=~/\.(\w+)$/);
4000: my $uploaded=($url=~/^\/*uploaded\//);
4001: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4002: my $isfolder;
4003: my $ispage;
4004: my $containerarg;
1.615 raeburn 4005: my $folderurl;
1.329 droeschl 4006: if ($uploaded) {
1.472 raeburn 4007: if (($extension eq 'sequence') || ($extension eq 'page')) {
4008: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4009: $containerarg = $1;
1.472 raeburn 4010: if ($extension eq 'sequence') {
4011: $icon=$iconpath.'navmap.folder.closed.gif';
4012: $isfolder=1;
4013: } else {
4014: $icon=$iconpath.'page.gif';
4015: $ispage=1;
4016: }
1.615 raeburn 4017: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4018: if ($allowed) {
4019: $url='/adm/coursedocs?';
4020: } else {
4021: $url='/adm/supplemental?';
4022: }
1.329 droeschl 4023: } else {
4024: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4025: }
4026: }
1.364 bisitz 4027:
1.621 raeburn 4028: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4029: my $orig_url = $url;
1.340 raeburn 4030: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 4031: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 4032: if (!$supplementalflag && $residx && $symb) {
4033: if ((!$isfolder) && (!$ispage)) {
4034: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4035: $url=&Apache::lonnet::clutter($url);
4036: if ($url=~/^\/*uploaded\//) {
4037: $url=~/\.(\w+)$/;
4038: my $embstyle=&Apache::loncommon::fileembstyle($1);
4039: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4040: $url='/adm/wrapper'.$url;
4041: } elsif ($embstyle eq 'ssi') {
4042: #do nothing with these
4043: } elsif ($url!~/\.(sequence|page)$/) {
4044: $url='/adm/coursedocs/showdoc'.$url;
4045: }
1.623 raeburn 4046: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4047: my $wrapped = $1;
4048: my $exturl = $2;
4049: if ($wrapped eq '') {
4050: $url='/adm/wrapper'.$url;
4051: }
4052: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4053: $nomodal = 1;
4054: }
1.626 raeburn 4055: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4056: $url='/adm/wrapper'.$url;
1.621 raeburn 4057: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4058: if (($ENV{'SERVER_PORT'} == 443) &&
4059: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4060: $url .= '?usehttp=1';
4061: $nomodal = 1;
4062: }
1.598 raeburn 4063: }
1.501 raeburn 4064: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4065: my $shownsymb = $symb;
4066: if ($isexternal) {
4067: if ($url =~ /^([^#]+)#([^#]+)$/) {
4068: $url = $1;
4069: $anchor = $2;
4070: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4071: $shownsymb = $1.&escape('#').$anchor;
4072: }
4073: }
4074: }
1.617 raeburn 4075: unless ($env{'request.role.adv'}) {
4076: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4077: $url = '';
4078: }
4079: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4080: $url = '';
4081: $hiddenres = 1;
4082: }
4083: }
4084: if ($url ne '') {
4085: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4086: }
1.615 raeburn 4087: } elsif (!$env{'request.role.adv'}) {
4088: my $checkencrypt;
4089: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4090: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4091: $checkencrypt = 1;
1.620 raeburn 4092: } elsif (ref($navmapref)) {
1.615 raeburn 4093: unless (ref($$navmapref)) {
4094: $$navmapref = Apache::lonnavmaps::navmap->new();
4095: }
4096: if (ref($$navmapref)) {
4097: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4098: $checkencrypt = 1;
4099: }
4100: }
4101: }
4102: if ($checkencrypt) {
4103: my $shownsymb = &Apache::lonenc::encrypted($symb);
4104: my $shownurl = &Apache::lonenc::encrypted($url);
4105: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4106: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4107: if ($env{'request.enc'} ne '') {
4108: delete($env{'request.enc'});
4109: }
4110: } else {
4111: $url='';
1.613 raeburn 4112: }
1.612 raeburn 4113: } else {
4114: $url='';
4115: }
1.501 raeburn 4116: } else {
4117: $url='';
4118: }
1.329 droeschl 4119: }
1.621 raeburn 4120: } elsif ($supplementalflag) {
1.610 raeburn 4121: if ($isexternal) {
4122: if ($url =~ /^([^#]+)#([^#]+)$/) {
4123: $url = $1;
4124: $anchor = $2;
1.623 raeburn 4125: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4126: if ($hostname ne '') {
4127: $url = 'http://'.$hostname.$url;
4128: }
4129: $nomodal = 1;
4130: }
1.610 raeburn 4131: }
1.621 raeburn 4132: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4133: if (($ENV{'SERVER_PORT'} == 443) &&
4134: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.622 raeburn 4135: if ($hostname ne '') {
4136: $url = 'http://'.$hostname.$url;
4137: }
1.621 raeburn 4138: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4139: $nomodal = 1;
4140: }
1.610 raeburn 4141: }
1.329 droeschl 4142: }
1.615 raeburn 4143: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4144: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4145: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4146: my $foldername=&escape($foldertitle);
4147: my $folderpath=$env{'form.folderpath'};
4148: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4149: if (!$allowed && $supplementalflag) {
1.519 raeburn 4150: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4151: $url.='folderpath='.&escape($folderpath);
4152: } else {
1.617 raeburn 4153: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4154: 'parameter_randompick'))[0];
4155: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4156: 'parameter_randomorder'))[0]=~/^yes$/i);
4157: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4158: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4159: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4160: 'parameter_encrypturl'))[0]=~/^yes$/i);
4161: unless ($hiddenmap) {
1.620 raeburn 4162: if (ref($navmapref)) {
4163: unless (ref($$navmapref)) {
4164: $$navmapref = Apache::lonnavmaps::navmap->new();
4165: }
4166: if (ref($$navmapref)) {
4167: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4168: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4169: unless (@resources) {
4170: $hiddenmap = 1;
4171: unless ($env{'request.role.adv'}) {
4172: $url = '';
4173: $hiddenfolder = 1;
4174: }
1.617 raeburn 4175: }
1.615 raeburn 4176: }
4177: }
4178: }
4179: }
1.617 raeburn 4180: unless ($encryptmap) {
1.620 raeburn 4181: if ((ref($navmapref)) && (ref($$navmapref))) {
4182: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4183: $encryptmap = 1;
4184: }
1.617 raeburn 4185: }
4186: }
1.630 raeburn 4187:
1.617 raeburn 4188: # Append randompick number, hidden, and encrypted with ":" to foldername,
4189: # so it gets transferred between levels
4190: $folderpath.=$containerarg.'&'.$foldername.
4191: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4192: unless ($url eq '') {
1.612 raeburn 4193: $url.='folderpath='.&escape($folderpath);
4194: }
1.510 raeburn 4195: my $rpckchk;
4196: if ($rpicknum) {
4197: $rpckchk = ' checked="checked"';
1.543 raeburn 4198: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4199: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4200: }
1.510 raeburn 4201: }
1.537 raeburn 4202: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4203: $rand_pick_text =
1.478 raeburn 4204: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4205: $form_param."\n".
1.478 raeburn 4206: $form_common."\n".
1.611 raeburn 4207: '<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 4208: if ($rpicknum ne '') {
4209: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4210: }
1.537 raeburn 4211: $rand_pick_text .= '</span></span>'.
4212: $form_end;
1.543 raeburn 4213: my $ro_set;
1.617 raeburn 4214: if ($randorder) {
1.543 raeburn 4215: $ro_set = 'checked="checked"';
4216: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4217: push(@{$filtersref->{'randomorder'}},$orderidx);
4218: }
4219: }
1.564 raeburn 4220: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4221: $rand_order_text =
1.537 raeburn 4222: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4223: $form_param."\n".
1.537 raeburn 4224: $form_common."\n".
1.611 raeburn 4225: '<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 4226: $form_end;
1.510 raeburn 4227: }
1.509 raeburn 4228: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4229: my $isexttool;
1.626 raeburn 4230: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4231: $url='/adm/wrapper'.$url;
4232: $isexttool = 1;
4233: }
1.510 raeburn 4234: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4235: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4236: if ($title) {
4237: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4238: }
1.598 raeburn 4239: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4240: $url .= '&idx='.$orderidx;
4241: }
1.610 raeburn 4242: if ($anchor ne '') {
4243: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4244: }
1.329 droeschl 4245: }
1.519 raeburn 4246: my ($tdalign,$tdwidth);
1.501 raeburn 4247: if ($allowed) {
1.630 raeburn 4248: my $fileloc =
1.501 raeburn 4249: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4250: if ($isexternal) {
1.630 raeburn 4251: ($editlink,$extresform) =
1.611 raeburn 4252: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4253: undef,undef,undef,undef,undef,undef,
4254: undef,$disabled);
1.626 raeburn 4255: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4256: ($editlink,$extresform) =
4257: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4258: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4259: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4260: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4261: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4262: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4263: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4264: my $suppanchor;
4265: if ($supplementalflag) {
4266: $suppanchor = $anchor;
4267: }
1.630 raeburn 4268: my $jscall =
1.501 raeburn 4269: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4270: $switchserver,
1.503 raeburn 4271: $forceedit,
1.511 raeburn 4272: undef,$symb,
4273: &escape($env{'form.folderpath'}),
1.622 raeburn 4274: $renametitle,$hostname,
4275: '','',1,$suppanchor);
1.501 raeburn 4276: if ($jscall) {
1.518 raeburn 4277: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4278: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4279: }
4280: }
4281: }
1.519 raeburn 4282: $tdalign = ' align="right" valign="top"';
4283: $tdwidth = ' width="80%"';
1.329 droeschl 4284: }
1.408 raeburn 4285: my $reinit;
4286: if ($crstype eq 'Community') {
4287: $reinit = &mt('(re-initialize community to access)');
4288: } else {
4289: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4290: }
4291: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.621 raeburn 4292: my $link;
1.472 raeburn 4293: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4294: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4295: } elsif ($url) {
1.610 raeburn 4296: if ($anchor ne '') {
4297: if ($supplementalflag) {
4298: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4299: } else {
4300: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4301: }
4302: }
1.622 raeburn 4303: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4304: $link = 'http://'.$hostname.$url;
4305: } else {
4306: $link = $url;
4307: }
4308: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.621 raeburn 4309: (($anchor ne '')?$anchor:''));
4310: if ($nomodal) {
4311: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4312: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4313: } else {
4314: $line.=&Apache::loncommon::modal_link($link,
4315: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4316: }
1.469 www 4317: } else {
4318: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4319: }
1.519 raeburn 4320: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4321: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4322: $line.='<a href="'.$url.'">'.$title.'</a>';
4323: } elsif ($url) {
1.621 raeburn 4324: if ($nomodal) {
4325: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4326: $title.'</a>';
4327: } else {
4328: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4329: }
1.617 raeburn 4330: } elsif (($hiddenfolder) || ($hiddenres)) {
1.615 raeburn 4331: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
1.469 www 4332: } else {
4333: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4334: }
1.518 raeburn 4335: $line.="$extresform</td>";
1.478 raeburn 4336: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4337: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4338: if (($allowed) && ($folder!~/^supplemental/)) {
4339: my %lt=&Apache::lonlocal::texthash(
4340: 'hd' => 'Hidden',
4341: 'ec' => 'URL hidden');
1.543 raeburn 4342: my ($enctext,$hidtext);
4343: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4344: $enctext = ' checked="checked"';
4345: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4346: push(@{$filtersref->{'encrypturl'}},$orderidx);
4347: }
4348: }
4349: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4350: $hidtext = ' checked="checked"';
4351: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4352: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4353: }
4354: }
1.537 raeburn 4355: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4356: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4357: $line.=(<<ENDPARMS);
4358: <td class="LC_docs_entry_parameter">
1.537 raeburn 4359: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4360: $form_param
1.478 raeburn 4361: $form_common
1.611 raeburn 4362: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4363: $form_end
1.458 raeburn 4364: <br />
1.537 raeburn 4365: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4366: $form_param
1.478 raeburn 4367: $form_common
1.611 raeburn 4368: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4369: $form_end
4370: </td>
1.478 raeburn 4371: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4372: $rand_order_text</td>
1.329 droeschl 4373: ENDPARMS
4374: }
1.379 bisitz 4375: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4376: return $line;
4377: }
4378:
1.538 raeburn 4379: sub action_restrictions {
4380: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4381: my %denied = (
4382: cut => 0,
4383: copy => 0,
4384: remove => 0,
4385: );
4386: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4387: # no copy for published maps
4388: $denied{'copy'} = 1;
1.597 raeburn 4389: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4390: unless ($1 eq 'simpleproblem') {
4391: $denied{'copy'} = 1;
4392: }
4393: $denied{'cut'} = 1;
1.538 raeburn 4394: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4395: if ($folderpath =~ /^default&[^\&]+$/) {
4396: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4397: $denied{'remove'} = 1;
4398: }
4399: $denied{'cut'} = 1;
4400: $denied{'copy'} = 1;
4401: }
4402: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4403: my $group = $1;
4404: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4405: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4406: $denied{'remove'} = 1;
4407: }
4408: }
4409: $denied{'cut'} = 1;
4410: $denied{'copy'} = 1;
4411: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4412: my $group = $1;
4413: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$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: $denied{'remove'} = 1;
4418: }
4419: $denied{'cut'} = 1;
4420: $denied{'copy'} = 1;
4421: }
4422: }
4423: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4424: my $group = $1;
4425: if ($url =~ /group_boards_\Q$group\E/) {
4426: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4427: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4428: if (keys(%groupsettings) > 0) {
4429: if (ref($groupsettings{'functions'}) eq 'HASH') {
4430: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4431: $denied{'remove'} = 1;
4432: }
4433: }
4434: }
4435: $denied{'cut'} = 1;
4436: $denied{'copy'} = 1;
4437: }
4438: }
4439: }
4440: return %denied;
4441: }
4442:
1.533 raeburn 4443: sub new_timebased_suffix {
1.538 raeburn 4444: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4445: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4446: if ($type eq 'paste') {
4447: $prefix = $type;
4448: $namespace = 'courseeditor';
1.587 raeburn 4449: $idtype = 'addcode';
1.538 raeburn 4450: } elsif ($type eq 'map') {
1.533 raeburn 4451: $prefix = 'docs';
4452: if ($area eq 'supplemental') {
4453: $prefix = 'supp';
4454: }
4455: $prefix .= $container;
4456: $namespace = 'uploadedmaps';
4457: } else {
4458: $prefix = $type;
4459: $namespace = 'templated';
1.504 raeburn 4460: }
4461: my ($suffix,$freedlock,$error) =
1.587 raeburn 4462: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4463: if (!$suffix) {
1.538 raeburn 4464: if ($type eq 'paste') {
4465: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4466: } elsif ($type eq 'map') {
1.533 raeburn 4467: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4468: } elsif ($type eq 'smppg') {
4469: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4470: } elsif ($type eq 'exttool') {
4471: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4472: } else {
1.565 bisitz 4473: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4474: }
1.504 raeburn 4475: if ($error) {
4476: $errtext .= '<br />'.$error;
4477: }
4478: }
4479: if ($freedlock ne 'ok') {
1.630 raeburn 4480: $locknotfreed =
1.533 raeburn 4481: '<div class="LC_error">'.
4482: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4483: if ($type eq 'paste') {
1.591 raeburn 4484: if ($freedlock eq 'nolock') {
4485: $locknotfreed =
4486: '<div class="LC_error">'.
4487: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4488:
1.593 droeschl 4489: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4490: } else {
4491: $locknotfreed .=
4492: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4493: }
1.538 raeburn 4494: } elsif ($type eq 'map') {
1.591 raeburn 4495: $locknotfreed .=
4496: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4497: } elsif ($type eq 'smppg') {
4498: $locknotfreed .=
4499: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4500: } elsif ($type eq 'exttool') {
4501: $locknotfreed .=
4502: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4503: } else {
4504: $locknotfreed .=
1.565 bisitz 4505: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4506: }
1.538 raeburn 4507: unless ($type eq 'paste') {
4508: $locknotfreed .=
1.560 raeburn 4509: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4510: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4511: }
4512: $locknotfreed .= '</div>';
1.504 raeburn 4513: }
4514: return ($suffix,$errtext,$locknotfreed);
4515: }
4516:
1.329 droeschl 4517: =pod
4518:
4519: =item tiehash()
4520:
4521: tie the hash
4522:
4523: =cut
4524:
4525: sub tiehash {
4526: my ($mode)=@_;
4527: $hashtied=0;
4528: if ($env{'request.course.fn'}) {
4529: if ($mode eq 'write') {
4530: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4531: &GDBM_WRCREAT(),0640)) {
4532: $hashtied=2;
4533: }
4534: } else {
4535: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4536: &GDBM_READER(),0640)) {
4537: $hashtied=1;
4538: }
4539: }
1.364 bisitz 4540: }
1.329 droeschl 4541: }
4542:
4543: sub untiehash {
4544: if ($hashtied) { untie %hash; }
4545: $hashtied=0;
4546: return OK;
4547: }
4548:
4549:
4550:
4551:
4552: sub checkonthis {
4553: my ($r,$url,$level,$title)=@_;
4554: $url=&unescape($url);
4555: $alreadyseen{$url}=1;
4556: $r->rflush();
4557: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4558: $r->print("\n<br />");
4559: if ($level==0) {
4560: $r->print("<br />");
4561: }
4562: for (my $i=0;$i<=$level*5;$i++) {
4563: $r->print(' ');
4564: }
4565: $r->print('<a href="'.$url.'" target="cat">'.
4566: ($title?$title:$url).'</a> ');
4567: if ($url=~/^\/res\//) {
4568: my $result=&Apache::lonnet::repcopy(
4569: &Apache::lonnet::filelocation('',$url));
4570: if ($result eq 'ok') {
4571: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4572: $r->rflush();
4573: &Apache::lonnet::countacc($url);
4574: $url=~/\.(\w+)$/;
4575: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4576: $r->print('<br />');
4577: $r->rflush();
4578: for (my $i=0;$i<=$level*5;$i++) {
4579: $r->print(' ');
4580: }
4581: $r->print('- '.&mt('Rendering:').' ');
4582: my ($errorcount,$warningcount)=split(/:/,
4583: &Apache::lonnet::ssi_body($url,
4584: ('grade_target'=>'web',
4585: 'return_only_error_and_warning_counts' => 1)));
4586: if (($errorcount) ||
4587: ($warningcount)) {
4588: if ($errorcount) {
1.369 bisitz 4589: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4590: &mt('[quant,_1,error]',$errorcount).'</span>');
4591: }
4592: if ($warningcount) {
4593: $r->print('<span class="LC_warning">'.
4594: &mt('[quant,_1,warning]',$warningcount).'</span>');
4595: }
4596: } else {
4597: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4598: }
4599: $r->rflush();
4600: }
4601: my $dependencies=
4602: &Apache::lonnet::metadata($url,'dependencies');
4603: foreach my $dep (split(/\,/,$dependencies)) {
4604: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4605: &checkonthis($r,$dep,$level+1);
4606: }
4607: }
4608: } elsif ($result eq 'unavailable') {
4609: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4610: } elsif ($result eq 'not_found') {
4611: unless ($url=~/\$/) {
1.521 bisitz 4612: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4613: } else {
1.366 bisitz 4614: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4615: }
4616: } else {
4617: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4618: }
4619: }
4620: }
4621: }
4622:
4623:
4624:
4625: =pod
4626:
4627: =item list_symbs()
4628:
1.485 raeburn 4629: List Content Identifiers
1.329 droeschl 4630:
4631: =cut
4632:
4633: sub list_symbs {
4634: my ($r) = @_;
4635:
1.408 raeburn 4636: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4637: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4638: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4639: $r->print(&startContentScreen('tools'));
1.329 droeschl 4640: my $navmap = Apache::lonnavmaps::navmap->new();
4641: if (!defined($navmap)) {
4642: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4643: '<div class="LC_error">'.
4644: &mt('Unable to retrieve information about course contents').
4645: '</div>');
1.408 raeburn 4646: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4647: } else {
1.484 raeburn 4648: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4649: &Apache::loncommon::start_data_table().
4650: &Apache::loncommon::start_data_table_header_row().
4651: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4652: &Apache::loncommon::end_data_table_header_row()."\n");
4653: my $count;
1.329 droeschl 4654: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4655: $r->print(&Apache::loncommon::start_data_table_row().
4656: '<td>'.$res->compTitle().'</td>'.
4657: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4658: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4659: $count ++;
4660: }
4661: if (!$count) {
4662: $r->print(&Apache::loncommon::start_data_table_row().
4663: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4664: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4665: }
1.484 raeburn 4666: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4667: }
1.521 bisitz 4668: $r->print(&endContentScreen());
1.329 droeschl 4669: }
4670:
4671:
4672: sub verifycontent {
4673: my ($r) = @_;
1.408 raeburn 4674: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4675: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4676: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4677: $r->print(&startContentScreen('tools'));
4678: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4679: $hashtied=0;
4680: undef %alreadyseen;
4681: %alreadyseen=();
4682: &tiehash();
1.484 raeburn 4683:
1.329 droeschl 4684: foreach my $key (keys(%hash)) {
4685: if ($hash{$key}=~/\.(page|sequence)$/) {
4686: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4687: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4688: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4689: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4690: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4691: }
4692: }
4693: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4694: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4695: }
4696: }
4697: &untiehash();
1.442 www 4698: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4699: $r->print(&endContentScreen());
1.329 droeschl 4700: }
4701:
4702:
4703: sub devalidateversioncache {
4704: my $src=shift;
4705: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4706: &Apache::lonnet::clutter($src));
4707: }
4708:
4709: sub checkversions {
1.611 raeburn 4710: my ($r,$canedit) = @_;
1.408 raeburn 4711: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4712: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4713: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4714: $r->print(&startContentScreen('tools'));
1.442 www 4715:
1.329 droeschl 4716: my $header='';
4717: my $startsel='';
4718: my $monthsel='';
4719: my $weeksel='';
4720: my $daysel='';
4721: my $allsel='';
4722: my %changes=();
4723: my $starttime=0;
4724: my $haschanged=0;
4725: my %setversions=&Apache::lonnet::dump('resourceversions',
4726: $env{'course.'.$env{'request.course.id'}.'.domain'},
4727: $env{'course.'.$env{'request.course.id'}.'.num'});
4728:
4729: $hashtied=0;
4730: &tiehash();
1.611 raeburn 4731: if ($canedit) {
4732: my %newsetversions=();
4733: if ($env{'form.setmostrecent'}) {
4734: $haschanged=1;
4735: foreach my $key (keys(%hash)) {
4736: if ($key=~/^ids\_(\/res\/.+)$/) {
4737: $newsetversions{$1}='mostrecent';
4738: &devalidateversioncache($1);
4739: }
4740: }
4741: } elsif ($env{'form.setcurrent'}) {
4742: $haschanged=1;
4743: foreach my $key (keys(%hash)) {
4744: if ($key=~/^ids\_(\/res\/.+)$/) {
4745: my $getvers=&Apache::lonnet::getversion($1);
4746: if ($getvers>0) {
4747: $newsetversions{$1}=$getvers;
4748: &devalidateversioncache($1);
4749: }
4750: }
1.329 droeschl 4751: }
1.611 raeburn 4752: } elsif ($env{'form.setversions'}) {
4753: $haschanged=1;
4754: foreach my $key (keys(%env)) {
4755: if ($key=~/^form\.set_version_(.+)$/) {
4756: my $src=$1;
4757: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4758: $newsetversions{$src}=$env{$key};
4759: &devalidateversioncache($src);
4760: }
4761: }
1.329 droeschl 4762: }
1.611 raeburn 4763: }
4764: if ($haschanged) {
4765: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4766: $env{'course.'.$env{'request.course.id'}.'.domain'},
4767: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4768: $r->print(&Apache::loncommon::confirmwrapper(
4769: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4770: } else {
4771: $r->print(&Apache::loncommon::confirmwrapper(
4772: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4773: }
1.611 raeburn 4774: &mark_hash_old();
4775: }
4776: &changewarning($r,'');
1.329 droeschl 4777: }
4778: if ($env{'form.timerange'} eq 'all') {
4779: # show all documents
1.549 raeburn 4780: $header=&mt('All content in '.$crstype);
1.521 bisitz 4781: $allsel=' selected="selected"';
1.329 droeschl 4782: foreach my $key (keys(%hash)) {
4783: if ($key=~/^ids\_(\/res\/.+)$/) {
4784: my $src=$1;
4785: $changes{$src}=1;
4786: }
4787: }
4788: } else {
4789: # show documents which changed
4790: %changes=&Apache::lonnet::dump
4791: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4792: $env{'course.'.$env{'request.course.id'}.'.num'});
4793: my $firstkey=(keys(%changes))[0];
4794: unless ($firstkey=~/^error\:/) {
4795: unless ($env{'form.timerange'}) {
4796: $env{'form.timerange'}=604800;
4797: }
4798: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4799: .&mt('seconds');
4800: if ($env{'form.timerange'}==-1) {
4801: $seltext='since start of course';
1.521 bisitz 4802: $startsel=' selected="selected"';
1.329 droeschl 4803: $env{'form.timerange'}=time;
4804: }
4805: $starttime=time-$env{'form.timerange'};
4806: if ($env{'form.timerange'}==2592000) {
4807: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4808: $monthsel=' selected="selected"';
1.329 droeschl 4809: } elsif ($env{'form.timerange'}==604800) {
4810: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4811: $weeksel=' selected="selected"';
1.329 droeschl 4812: } elsif ($env{'form.timerange'}==86400) {
4813: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4814: $daysel=' selected="selected"';
1.329 droeschl 4815: }
4816: $header=&mt('Content changed').' '.$seltext;
4817: } else {
4818: $header=&mt('No content modifications yet.');
4819: }
4820: }
4821: %setversions=&Apache::lonnet::dump('resourceversions',
4822: $env{'course.'.$env{'request.course.id'}.'.domain'},
4823: $env{'course.'.$env{'request.course.id'}.'.num'});
4824: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4825: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4826: 'lm' => 'Version changes since last Month',
4827: 'lw' => 'Version changes since last Week',
4828: 'sy' => 'Version changes since Yesterday',
4829: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4830: 'cd' => 'Change display',
1.329 droeschl 4831: 'sd' => 'Display',
4832: 'fi' => 'File',
4833: 'md' => 'Modification Date',
4834: 'mr' => 'Most recently published Version',
1.408 raeburn 4835: 've' => 'Version used in '.$crstype,
4836: 'vu' => 'Set Version to be used in '.$crstype,
4837: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4838: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4839: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4840: 'di' => 'Differences',
1.484 raeburn 4841: 'save' => 'Save changes',
4842: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4843: 'act' => 'Actions');
1.611 raeburn 4844: my ($disabled,$readonly);
4845: unless ($canedit) {
4846: $disabled = 'disabled="disabled"';
4847: $readonly = 1;
4848: }
1.329 droeschl 4849: $r->print(<<ENDHEADERS);
1.484 raeburn 4850: <h4 class="LC_info">$header</h4>
1.329 droeschl 4851: <form action="/adm/coursedocs" method="post">
4852: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4853: <div class="LC_left_float">
1.479 golterma 4854: <fieldset>
1.484 raeburn 4855: <legend>$lt{'cd'}</legend>
1.329 droeschl 4856: <select name="timerange">
1.521 bisitz 4857: <option value='all'$allsel>$lt{'al'}</option>
4858: <option value="-1"$startsel>$lt{'st'}</option>
4859: <option value="2592000"$monthsel>$lt{'lm'}</option>
4860: <option value="604800"$weeksel>$lt{'lw'}</option>
4861: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4862: </select>
4863: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4864: </fieldset>
4865: </div>
4866: <div class="LC_left_float">
4867: <fieldset>
4868: <legend>$lt{'act'}</legend>
1.611 raeburn 4869: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4870: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4871: </fieldset>
4872: </div>
4873: <br clear="all" />
4874: <hr />
4875: <h4>$lt{'vers'}</h4>
1.329 droeschl 4876: ENDHEADERS
1.479 golterma 4877: #number of columns for version history
1.571 raeburn 4878: my %changedbytime;
4879: foreach my $key (keys(%changes)) {
4880: #excludes not versionable problems from resource version history:
4881: next if ($key =~ /^\/res\/lib\/templates/);
4882: my $chg;
4883: if ($env{'form.timerange'} eq 'all') {
4884: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4885: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4886: } else {
4887: $chg = $changes{$key};
4888: next if ($chg < $starttime);
4889: }
4890: push(@{$changedbytime{$chg}},$key);
4891: }
4892: if (keys(%changedbytime) == 0) {
4893: &untiehash();
4894: $r->print(&mt('No content changes in imported content in specified time frame').
4895: &endContentScreen());
4896: return;
4897: }
1.479 golterma 4898: $r->print(
1.611 raeburn 4899: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4900: &Apache::loncommon::start_data_table().
4901: &Apache::loncommon::start_data_table_header_row().
4902: '<th>'.&mt('Resources').'</th>'.
4903: "<th>$lt{'mr'}</th>".
4904: "<th>$lt{'ve'}</th>".
4905: "<th>$lt{'vu'}</th>".
4906: '<th>'.&mt('History').'</th>'.
4907: &Apache::loncommon::end_data_table_header_row()
4908: );
1.571 raeburn 4909: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4910: foreach my $key (sort(@{$changedbytime{$chg}})) {
4911: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4912: my $currentversion=&Apache::lonnet::getversion($key);
4913: if ($currentversion<0) {
4914: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4915: }
4916: my $linkurl=&Apache::lonnet::clutter($key);
4917: $r->print(
4918: &Apache::loncommon::start_data_table_row().
4919: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4920: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4921: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4922: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4923: '<td align="right">'
4924: );
4925: # Used in course
4926: my $usedversion=$hash{'version_'.$linkurl};
4927: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4928: if ($usedversion != $currentversion) {
1.479 golterma 4929: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4930: } else {
1.479 golterma 4931: $r->print($usedversion);
4932: }
1.329 droeschl 4933: } else {
1.521 bisitz 4934: $r->print($currentversion);
1.329 droeschl 4935: }
1.571 raeburn 4936: $r->print('</td><td title="'.$lt{'vu'}.'">');
4937: # Set version
4938: $r->print(&Apache::loncommon::select_form(
4939: $setversions{$linkurl},
4940: 'set_version_'.$linkurl,
4941: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4942: '' => '',
4943: 'mostrecent' => &mt('most recent'),
1.611 raeburn 4944: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 4945: my $lastold=1;
4946: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4947: my $url=$root.'.'.$prevvers.'.'.$extension;
4948: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4949: $lastold=$prevvers;
4950: }
4951: }
4952: $r->print('</td>');
4953: # List all available versions
4954: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4955: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4956: my $url=$root.'.'.$prevvers.'.'.$extension;
4957: $r->print(
4958: '<span class="LC_nobreak">'
4959: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4960: .&mt('Version [_1]',$prevvers).'</a>'
4961: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4962: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4963: .')');
4964: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4965: $r->print(
4966: ' <a href="/adm/diff?filename='.
4967: &Apache::lonnet::clutter($root.'.'.$extension).
4968: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4969: '" target="diffs">'.&mt('Diffs').'</a>');
4970: }
4971: $r->print('</span><br />');
1.329 droeschl 4972: }
1.571 raeburn 4973: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4974: }
1.329 droeschl 4975: }
1.521 bisitz 4976: $r->print(
4977: &Apache::loncommon::end_data_table().
1.611 raeburn 4978: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4979: '</form>'
4980: );
1.329 droeschl 4981:
4982: &untiehash();
1.521 bisitz 4983: $r->print(&endContentScreen());
1.571 raeburn 4984: return;
1.329 droeschl 4985: }
4986:
4987: sub mark_hash_old {
4988: my $retie_hash=0;
4989: if ($hashtied) {
4990: $retie_hash=1;
4991: &untiehash();
4992: }
4993: &tiehash('write');
4994: $hash{'old'}=1;
4995: &untiehash();
4996: if ($retie_hash) { &tiehash(); }
4997: }
4998:
4999: sub is_hash_old {
5000: my $untie_hash=0;
5001: if (!$hashtied) {
5002: $untie_hash=1;
5003: &tiehash();
5004: }
5005: my $return=$hash{'old'};
5006: if ($untie_hash) { &untiehash(); }
5007: return $return;
5008: }
5009:
5010: sub changewarning {
5011: my ($r,$postexec,$message,$url)=@_;
5012: if (!&is_hash_old()) { return; }
5013: my $pathvar='folderpath';
5014: my $path=&escape($env{'form.folderpath'});
5015: if (!defined($url)) {
5016: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5017: }
5018: my $course_type = &Apache::loncommon::course_type();
5019: if (!defined($message)) {
5020: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5021: }
5022: $r->print("\n\n".
1.372 bisitz 5023: '<script type="text/javascript">'."\n".
5024: '// <![CDATA['."\n".
5025: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5026: '// ]]>'."\n".
1.369 bisitz 5027: '</script>'."\n".
1.375 tempelho 5028: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5029: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5030: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5031: &mt($message,' <input type="hidden" name="'.
5032: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5033: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5034: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5035: }
5036:
5037:
5038: sub init_breadcrumbs {
1.571 raeburn 5039: my ($form,$text,$help)=@_;
1.329 droeschl 5040: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5041: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5042: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5043: faq=>273,
5044: bug=>'Instructor Interface',
1.571 raeburn 5045: help => $help});
1.329 droeschl 5046: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5047: text=>$text,
5048: faq=>273,
5049: bug=>'Instructor Interface'});
5050: }
5051:
1.441 www 5052: # subroutine to list form elements
5053: sub create_list_elements {
5054: my @formarr = @_;
5055: my $list = '';
1.501 raeburn 5056: foreach my $button (@formarr){
5057: foreach my $picture (keys(%{$button})) {
5058: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5059: }
5060: }
5061: return $list;
5062: }
1.329 droeschl 5063:
1.441 www 5064: # subroutine to create ul from list elements
5065: sub create_form_ul {
5066: my $list = shift;
5067: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5068: return $ul;
5069: }
1.329 droeschl 5070:
1.442 www 5071: #
5072: # Start tabs
5073: #
5074:
5075: sub startContentScreen {
1.484 raeburn 5076: my ($mode) = @_;
5077: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5078: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5079: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5080: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5081: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5082: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5083: } else {
1.549 raeburn 5084: $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 5085: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5086: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5087: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5088: }
5089: $output .= "\n".'</ul>'."\n";
5090: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5091: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5092: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5093: return $output;
1.442 www 5094: }
5095:
5096: #
5097: # End tabs
5098: #
5099:
5100: sub endContentScreen {
1.484 raeburn 5101: return '</div></div></div>';
1.442 www 5102: }
1.329 droeschl 5103:
1.446 www 5104: sub supplemental_base {
1.548 raeburn 5105: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5106: }
5107:
1.329 droeschl 5108: sub handler {
5109: my $r = shift;
5110: &Apache::loncommon::content_type($r,'text/html');
5111: $r->send_http_header;
5112: return OK if $r->header_only;
1.484 raeburn 5113:
5114: # get course data
1.408 raeburn 5115: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5116: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5117: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5118:
1.606 raeburn 5119: # get docroot
5120: my $londocroot = $r->dir_config('lonDocRoot');
5121:
1.484 raeburn 5122: # graphics settings
5123: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5124:
1.443 www 5125: #
1.329 droeschl 5126: # --------------------------------------------- Initialize help topics for this
5127: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5128: 'Adding_External_Resource','Adding_External_Tool',
5129: 'Navigate_Content','Adding_Folders','Docs_Overview',
5130: 'Load_Map','Supplemental','Score_Upload_Form',
5131: 'Adding_Pages','Importing_LON-CAPA_Resource',
5132: 'Importing_IMS_Course','Uploading_From_Harddrive',
5133: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5134: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5135: }
5136: # Composite help files
5137: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5138: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5139: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5140: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5141: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5142: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5143: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5144: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5145: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5146: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5147:
1.611 raeburn 5148: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5149: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5150: unless ($r->uri eq '/adm/supplemental') {
5151: # does this user have privileges to modify content.
1.611 raeburn 5152: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5153: $allowed = 1;
5154: $canedit = 1;
5155: $canview = 1;
5156: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5157: $allowed = 1;
5158: $canview = 1;
5159: }
5160: }
5161: unless ($canedit) {
5162: $disabled = ' disabled="disabled"';
1.472 raeburn 5163: }
1.582 raeburn 5164: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5165: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5166: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 5167: &verifycontent($r);
5168: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5169: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5170: &list_symbs($r);
5171: } elsif ($allowed && $env{'form.docslog'}) {
5172: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5173: my $folder = $env{'form.folder'};
5174: if ($folder eq '') {
5175: $folder='default';
5176: }
1.611 raeburn 5177: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5178: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5179: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5180: &checkversions($r,$canedit);
5181: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5182: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5183: &dumpcourse($r);
1.611 raeburn 5184: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5185: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5186: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5187: } else {
1.611 raeburn 5188: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5189: $noendpage = 1;
5190: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5191: if ($redirect) {
5192: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5193: my $container = 'sequence';
5194: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5195: $is_random_order,$container) =
5196: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5197: my (@folders)=split('&',$env{'form.folderpath'});
5198: $env{'form.foldername'}=&unescape(pop(@folders));
5199: my $folder=pop(@folders);
5200: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5201: $folder.'.'.$container);
5202: my $warning;
5203: if ($fatal) {
5204: if ($container eq 'page') {
5205: $warning = &mt('An error occurred retrieving the contents of the current page.');
5206: } else {
5207: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5208: }
5209: } else {
5210: my $url = $redirect;
5211: my $srcfile = $londocroot.$url;
5212: $url =~ s{^/priv/}{/res/};
5213: my $targetfile = $londocroot.$url;
5214: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5215: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5216: $env{'form.folder'} = $folder;
5217: &snapshotbefore();
5218: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5219: my $ext = 'false';
5220: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5221: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5222: ':'.$ext.':normal:res';
5223: push(@LONCAPA::map::order,$newidx);
5224: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5225: 'string_yesno');
5226: &remember_parms($newidx,'hiddenresource','set','yes');
5227: ($errtext,$fatal) =
5228: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5229: &log_differences($plain);
5230: &mark_hash_old();
5231: $r->internal_redirect($redirect);
5232: return OK;
5233: }
5234: }
5235: }
5236: }
1.445 www 5237: #
5238: # Done catching special calls
1.484 raeburn 5239: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5240: # Get the parameters that may be needed
5241: #
5242: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5243: ['folderpath',
5244: 'forcesupplement','forcestandard',
1.510 raeburn 5245: 'tools','symb','command','supppath']);
1.445 www 5246:
5247: # standard=1: this is a "new-style" course with an uploaded map as top level
5248: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5249:
5250: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5251:
1.484 raeburn 5252: # Decide whether this should display supplemental or main content or utilities
1.445 www 5253: # supplementalflag=1: show supplemental documents
5254: # supplementalflag=0: show standard documents
1.484 raeburn 5255: # toolsflag=1: show utilities
1.445 www 5256:
1.561 raeburn 5257: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5258: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5259: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5260: $supplementalflag=0;
5261: }
5262: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5263: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5264: unless ($allowed) { $supplementalflag=1; }
5265: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5266: my $toolsflag=0;
5267: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5268:
1.329 droeschl 5269: my $script='';
5270: my $showdoc=0;
1.457 raeburn 5271: my $addentries = {};
1.475 raeburn 5272: my $container;
1.329 droeschl 5273: my $containertag;
1.508 raeburn 5274: my $pathitem;
1.598 raeburn 5275: my %ltitools;
1.617 raeburn 5276: my $hiddentop;
1.615 raeburn 5277: my $navmap;
1.617 raeburn 5278: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5279:
1.464 www 5280: # Do we directly jump somewhere?
1.525 raeburn 5281: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5282: if ($env{'form.symb'} ne '') {
1.522 raeburn 5283: $env{'form.folderpath'}=
1.617 raeburn 5284: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5285: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5286: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5287: } elsif ($env{'form.supppath'} ne '') {
5288: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5289: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5290: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5291: }
1.472 raeburn 5292: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5293: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5294: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5295: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5296: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5297: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5298: } elsif ($env{'form.command'} eq 'contents') {
5299: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5300: } elsif ($env{'form.command'} eq 'home') {
5301: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5302: }
5303:
1.525 raeburn 5304:
1.445 www 5305: # Where do we store these for when we come back?
5306: my $stored_folderpath='docs_folderpath';
5307: if ($supplementalflag) {
5308: $stored_folderpath='docs_sup_folderpath';
5309: }
1.464 www 5310:
1.519 raeburn 5311: # No folderpath, and in edit mode, see if we have something stored
5312: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5313: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5314: {'folderpath' => 'scalar'});
1.615 raeburn 5315:
5316: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5317: if ($supplementalflag) {
5318: undef($env{'form.folderpath'}) if ($1 eq 'default');
5319: } else {
5320: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5321: }
5322: } else {
1.523 raeburn 5323: undef($env{'form.folderpath'});
5324: }
1.329 droeschl 5325: }
1.446 www 5326:
5327: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5328: if (!$allowed) {
1.446 www 5329: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5330: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5331: }
5332: }
1.446 www 5333: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5334: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5335: $env{'form.folderpath'} = &supplemental_base()
5336: .'&'.
1.329 droeschl 5337: $env{'form.folderpath'};
5338: }
1.615 raeburn 5339: # If allowed and user's role is not advanced check folderpath is not hidden
5340: if (($allowed) && (!$env{'request.role.adv'}) &&
5341: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5342: my $folderurl;
5343: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5344: my $folder = $pathitems[-2];
5345: if ($folder eq '') {
5346: undef($env{'form.folderpath'});
5347: } else {
5348: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5349: if ((split(/\:/,$pathitems[-1]))[4]) {
5350: $folderurl .= '.page';
5351: } else {
5352: $folderurl .= '.sequence';
5353: }
1.617 raeburn 5354: unless (ref($navmap)) {
5355: $navmap = Apache::lonnavmaps::navmap->new();
5356: }
1.615 raeburn 5357: if (ref($navmap)) {
5358: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5359: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5360: unless (@resources) {
5361: undef($env{'form.folderpath'});
5362: }
1.615 raeburn 5363: }
5364: }
5365: }
5366: }
5367:
5368:
1.446 www 5369: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5370: unless ($env{'form.folderpath'}) {
1.446 www 5371: if ($supplementalflag) {
5372: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5373: } elsif ($allowed) {
5374: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5375: }
1.472 raeburn 5376: }
1.446 www 5377:
1.445 www 5378: # Store this
1.484 raeburn 5379: unless ($toolsflag) {
1.615 raeburn 5380: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5381: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5382: {'folderpath' => 'scalar'});
1.510 raeburn 5383: }
1.519 raeburn 5384: my $folderpath;
1.484 raeburn 5385: if ($env{'form.folderpath'}) {
1.519 raeburn 5386: $folderpath = $env{'form.folderpath'};
5387: my (@folders)=split('&',$env{'form.folderpath'});
5388: $env{'form.foldername'}=&unescape(pop(@folders));
5389: if ($env{'form.foldername'} =~ /\:1$/) {
5390: $container = 'page';
5391: } else {
5392: $container = 'sequence';
5393: }
5394: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5395: } else {
1.519 raeburn 5396: if ($env{'form.folder'} eq '' ||
5397: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5398: if ($env{'form.folder'} eq 'supplemental') {
5399: $folderpath=&supplemental_base();
5400: } elsif (!$hiddentop) {
5401: $folderpath='default&'.
5402: &escape(&mt('Main Content').':::::');
5403: }
1.484 raeburn 5404: }
5405: }
1.519 raeburn 5406: $containertag = '<input type="hidden" name="folderpath" value="" />';
5407: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5408: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5409: $showdoc='/'.$1;
5410: }
5411: if ($showdoc) { # got called in sequence from course
5412: $allowed=0;
5413: } else {
1.611 raeburn 5414: if ($canedit) {
1.484 raeburn 5415: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5416: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5417: }
5418: }
1.329 droeschl 5419: }
5420:
1.344 bisitz 5421: # get personal data
1.329 droeschl 5422: my $uname=$env{'user.name'};
5423: my $udom=$env{'user.domain'};
5424: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5425:
5426: if ($allowed) {
1.484 raeburn 5427: if ($toolsflag) {
5428: $script .= &inject_data_js();
5429: my ($home,$other,%outhash)=&authorhosts();
5430: if (!$home && $other) {
5431: my @hosts;
5432: foreach my $aurole (keys(%outhash)) {
5433: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5434: push(@hosts,$outhash{$aurole});
5435: }
5436: }
5437: $script .= &dump_switchserver_js(@hosts);
5438: }
1.458 raeburn 5439: } else {
1.570 raeburn 5440: my $tid = 1;
1.484 raeburn 5441: my @tabids;
5442: if ($supplementalflag) {
5443: @tabids = ('002','ee2','ff2');
1.570 raeburn 5444: $tid = 2;
1.484 raeburn 5445: } else {
5446: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5447: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5448: unshift(@tabids,'001');
5449: push(@tabids,('dd1','ee1'));
5450: }
1.458 raeburn 5451: }
1.484 raeburn 5452: my $tabidstr = join("','",@tabids);
1.598 raeburn 5453: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5454: my $posslti = keys(%ltitools);
1.622 raeburn 5455: my $hostname = $r->hostname();
1.606 raeburn 5456: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5457: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5458: &history_tab_js().
5459: &inject_data_js().
1.570 raeburn 5460: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5461: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5462: $addentries = {
1.485 raeburn 5463: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5464: };
1.458 raeburn 5465: }
1.538 raeburn 5466: $script .= &paste_popup_js();
1.501 raeburn 5467: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5468: &mt('Switch server?');
5469:
5470:
1.329 droeschl 5471: }
5472: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5473: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5474: .'// <![CDATA['."\n"
5475: .$script."\n"
5476: .'// ]]>'."\n"
1.595 musolffc 5477: .'</script>'."\n"
5478: .'<script type="text/javascript"
5479: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5480:
5481: # Breadcrumbs
5482: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5483:
5484: if ($showdoc) {
5485: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5486: {'force_register' => $showdoc,}));
1.571 raeburn 5487: } elsif ($toolsflag) {
1.611 raeburn 5488: my ($breadtext,$breadtitle);
1.617 raeburn 5489: $breadtext = "$crstype Editor";
1.611 raeburn 5490: if ($canedit) {
5491: $breadtitle = 'Editing '.$crstype.' Contents';
5492: } else {
5493: $breadtext .= ' (View-only mode)';
5494: $breadtitle = 'Viewing '.$crstype.' Contents';
5495: }
1.571 raeburn 5496: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5497: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5498: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5499: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5500: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5501: $breadtitle)
1.571 raeburn 5502: );
1.510 raeburn 5503: } elsif ($r->uri eq '/adm/supplemental') {
5504: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5505: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5506: {'bread_crumbs' => $brcrum,}));
5507: } else {
1.611 raeburn 5508: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5509: $breadtext = "$crstype Editor";
1.611 raeburn 5510: if ($canedit) {
5511: $breadtitle = 'Editing '.$crstype.' Contents';
5512: $helpitem = 'Docs_Adding_Course_Doc';
5513: } else {
5514: $breadtext .= ' (View-only mode)';
5515: $breadtitle = 'Viewing '.$crstype.' Contents';
5516: $helpitem = 'Docs_Viewing_Course_Doc';
5517: }
1.392 raeburn 5518: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5519: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5520: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5521: {'add_entries' => $addentries}
5522: )
1.392 raeburn 5523: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5524: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5525: $breadtitle,
5526: $helpitem)
1.392 raeburn 5527: );
5528: }
1.364 bisitz 5529:
1.329 droeschl 5530: my %allfiles = ();
5531: my %codebase = ();
1.440 raeburn 5532: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5533: if ($canedit) {
1.329 droeschl 5534: if (($env{'form.uploaddoc.filename'}) &&
5535: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5536: my $context = $1;
5537: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5538: undef($hadchanges);
1.440 raeburn 5539: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5540: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5541: if ($hadchanges) {
5542: &mark_hash_old();
5543: }
1.440 raeburn 5544: $r->print($upload_output);
5545: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5546: # Process file upload - phase two - upload embedded objects
5547: $uploadphase = 'check_embedded';
5548: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5549: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5550: $env{'form.newidx'});
5551: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5552: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5553: my ($destination,$dir_root) = &embedded_destination();
5554: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5555: my $actionurl = '/adm/coursedocs';
1.630 raeburn 5556: my ($result,$flag) =
1.440 raeburn 5557: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5558: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5559: $actionurl);
5560: $r->print($result.&return_to_editor());
5561: } elsif ($env{'form.phase'} eq 'check_embedded') {
5562: # Process file upload - phase three - modify references in HTML file
5563: $uploadphase = 'modified_orightml';
5564: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5565: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5566: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 5567: my $result =
1.482 raeburn 5568: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5569: $docuname,$docudom,undef,
5570: $dir_root);
1.630 raeburn 5571: $r->print($result.&return_to_editor());
1.476 raeburn 5572: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5573: $uploadphase = 'decompress_phase_one';
5574: $r->print(&decompression_phase_one().
5575: &return_to_editor());
5576: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5577: $uploadphase = 'decompress_phase_two';
5578: $r->print(&decompression_phase_two().
5579: &return_to_editor());
1.329 droeschl 5580: }
5581: }
5582:
1.484 raeburn 5583: if ($allowed && $toolsflag) {
5584: $r->print(&startContentScreen('tools'));
1.611 raeburn 5585: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5586: $r->print(&endContentScreen());
5587: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5588: # -----------------------------------------------------------------------------
5589: my %lt=&Apache::lonlocal::texthash(
5590: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5591: 'upfi' => 'Upload File',
1.553 raeburn 5592: 'upld' => 'Upload Content',
1.329 droeschl 5593: 'srch' => 'Search',
5594: 'impo' => 'Import',
1.487 raeburn 5595: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5596: 'impm' => 'Import from Assembled Map',
1.630 raeburn 5597: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5598: 'extr' => 'External Resource',
5599: 'extt' => 'External Tool',
1.329 droeschl 5600: 'selm' => 'Select Map',
5601: 'load' => 'Load Map',
5602: 'newf' => 'New Folder',
5603: 'newp' => 'New Composite Page',
5604: 'syll' => 'Syllabus',
1.425 raeburn 5605: 'navc' => 'Table of Contents',
1.343 biermanm 5606: 'sipa' => 'Simple Course Page',
1.329 droeschl 5607: 'sipr' => 'Simple Problem',
1.630 raeburn 5608: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5609: 'stpr' => 'Standard Problem',
5610: 'news' => 'New sub-directory',
5611: 'crpr' => 'Create Problem',
1.329 droeschl 5612: 'drbx' => 'Drop Box',
1.451 www 5613: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5614: 'bull' => 'Discussion Board',
1.347 weissno 5615: 'mypi' => 'My Personal Information Page',
1.353 weissno 5616: 'grpo' => 'Group Portfolio',
1.329 droeschl 5617: 'rost' => 'Course Roster',
1.528 raeburn 5618: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5619: 'imsf' => 'IMS Upload',
5620: 'imsl' => 'Upload IMS package',
1.501 raeburn 5621: 'cms' => 'Origin of IMS package',
5622: 'se' => 'Select',
1.329 droeschl 5623: 'file' => 'File',
5624: 'title' => 'Title',
1.606 raeburn 5625: 'addp' => 'Add Placeholder to course?',
5626: 'uste' => 'Use Template?',
5627: 'fnam' => 'File Name:',
5628: 'loca' => 'Location:',
5629: 'dire' => 'Directory:',
5630: 'cate' => 'Category:',
5631: 'tmpl' => 'Template:',
1.329 droeschl 5632: 'comment' => 'Comment',
1.403 raeburn 5633: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5634: 'bb5' => 'Blackboard 5',
5635: 'bb6' => 'Blackboard 6',
5636: 'angel5' => 'ANGEL 5.5',
5637: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5638: 'yes' => 'Yes',
5639: 'no' => 'No',
1.618 raeburn 5640: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5641: );
1.329 droeschl 5642: # -----------------------------------------------------------------------------
1.595 musolffc 5643:
5644: # Calculate free quota space for a user or course. A javascript function checks
5645: # file size to determine if upload should be allowed.
5646: my $quotatype = 'unofficial';
5647: if ($crstype eq 'Community') {
1.601 raeburn 5648: $quotatype = 'community';
5649: } elsif ($crstype eq 'Placement') {
5650: $quotatype = 'placement';
1.595 musolffc 5651: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5652: $quotatype = 'official';
5653: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5654: $quotatype = 'textbook';
5655: }
5656: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5657: 'course',$quotatype); # expressed in MB
5658: my $current_disk_usage = 0;
5659: foreach my $subdir ('docs','supplemental') {
5660: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5661: "userfiles/$subdir",1); # expressed in kB
5662: }
5663: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5664: my $usage = $current_disk_usage/1024; # in MB
5665: my $quota = $disk_quota;
5666: my $percent;
5667: if ($disk_quota == 0) {
5668: $percent = 100.0;
5669: } else {
1.619 raeburn 5670: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5671: }
5672: $usage = sprintf("%.2f",$usage);
5673: $quota = sprintf("%.2f",$quota);
5674: $percent = sprintf("%.0f",$percent);
5675: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5676: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5677:
1.329 droeschl 5678: my $fileupload=(<<FIUP);
1.605 raeburn 5679: $quotainfo
1.329 droeschl 5680: $lt{'file'}:<br />
1.611 raeburn 5681: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5682: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5683: FIUP
5684:
5685: my $checkbox=(<<CHBO);
5686: <!-- <label>$lt{'parse'}?
5687: <input type="checkbox" name="parserflag" />
5688: </label> -->
5689: <label>
1.611 raeburn 5690: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5691: </label>
5692: CHBO
1.501 raeburn 5693: my $imsfolder = $env{'form.folder'};
5694: if ($imsfolder eq '') {
5695: $imsfolder = 'default';
5696: }
5697: my $imspform=(<<IMSFORM);
5698: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5699: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5700: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5701: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5702: <legend>$lt{'imsf'}</legend>
5703: $fileupload
5704: <br />
5705: <p>
5706: $lt{'cms'}:
1.611 raeburn 5707: <select name="source" $disabled>
1.501 raeburn 5708: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5709: <option value="bb5">$lt{'bb5'}</option>
5710: <option value="bb6">$lt{'bb6'}</option>
5711: <option value="angel5">$lt{'angel5'}</option>
5712: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5713: </select>
5714: <input type="hidden" name="folder" value="$imsfolder" />
5715: </p>
5716: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5717: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5718: </fieldset>
5719: </form>
5720: IMSFORM
1.329 droeschl 5721:
5722: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5723: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5724: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5725: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5726: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5727: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5728: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5729: $fileupload
1.329 droeschl 5730: <br />
5731: $lt{'title'}:<br />
1.611 raeburn 5732: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5733: $pathitem
1.329 droeschl 5734: <input type="hidden" name="cmd" value="upload_default" />
5735: <br />
1.458 raeburn 5736: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5737: $checkbox
5738: </span>
1.501 raeburn 5739: <br clear="all" />
1.611 raeburn 5740: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5741: </fieldset>
5742: </form>
1.383 tempelho 5743: FUFORM
1.329 droeschl 5744:
1.611 raeburn 5745: my $mapimportjs;
5746: if ($canedit) {
5747: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5748: } else {
5749: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5750: }
1.502 raeburn 5751: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5752: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5753: $lt{'impm'}</a>$help{'Load_Map'}
5754: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5755: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5756: <legend>$lt{'impm'}</legend>
1.371 tempelho 5757: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5758: $lt{'copm'}<br />
5759: <span class="LC_nobreak">
5760: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5761: onfocus="this.blur();$mapimportjs" $disabled />
5762: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5763: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5764: </fieldset>
5765: </form>
5766:
1.383 tempelho 5767: SEDFFORM
1.606 raeburn 5768: my $importcrsresform;
1.608 raeburn 5769: my ($numdirs,$pickfile) =
5770: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5771: "resize_scrollbox('contentscroll','1','0');",
5772: undef,'res');
1.606 raeburn 5773: if ($pickfile) {
5774: $importcrsresform=(<<CRSFORM);
5775: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5776: $lt{'imcr'}</a>$help{'Course_Resources'}
5777: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5778: <fieldset id="importcrsresform" style="display: none;">
5779: <legend>$lt{'imcr'}</legend>
5780: <input type="hidden" name="active" value="bb" />
5781: $pickfile
5782: <p>
1.611 raeburn 5783: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5784: </p>
5785: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5786: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5787: </fieldset>
5788: </form>
5789: CRSFORM
5790: }
5791:
1.611 raeburn 5792: my $fromstoredjs;
5793: if ($canedit) {
5794: $fromstoredjs = 'open_StoredLinks_Import()';
5795: } else {
5796: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5797: }
5798:
1.502 raeburn 5799: my @importpubforma = (
1.508 raeburn 5800: { '<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 5801: { '<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 5802: { '<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 5803: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5804: );
5805: if ($pickfile) {
5806: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5807: }
1.502 raeburn 5808: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5809: my $extresourcesform =
5810: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5811: $help{'Adding_External_Resource'},
5812: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5813: my $exttoolform =
5814: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5815: $help{'Adding_External_Tool'},undef,
5816: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5817: \%ltitools,$disabled);
1.329 droeschl 5818: if ($allowed) {
1.492 raeburn 5819: my $folder = $env{'form.folder'};
5820: if ($folder eq '') {
5821: $folder='default';
5822: }
1.615 raeburn 5823: if ($canedit) {
5824: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5825: if ($output) {
5826: $r->print($output);
5827: }
1.538 raeburn 5828: }
1.337 ehlerst 5829: $r->print(<<HIDDENFORM);
5830: <form name="renameform" method="post" action="/adm/coursedocs">
5831: <input type="hidden" name="title" />
5832: <input type="hidden" name="cmd" />
5833: <input type="hidden" name="markcopy" />
5834: <input type="hidden" name="copyfolder" />
5835: $containertag
5836: </form>
1.484 raeburn 5837:
1.337 ehlerst 5838: HIDDENFORM
1.508 raeburn 5839: $r->print(&makesimpleeditform($pathitem)."\n".
5840: &makedocslogform($pathitem."\n".
1.484 raeburn 5841: '<input type="hidden" name="folder" value="'.
5842: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5843: }
1.442 www 5844:
5845: # Generate the tabs
1.510 raeburn 5846: my ($mode,$needs_end);
1.472 raeburn 5847: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5848: my @folders = split('&',$env{'form.folderpath'});
5849: unless (@folders > 2) {
5850: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5851: $needs_end = 1;
5852: }
1.472 raeburn 5853: } else {
1.484 raeburn 5854: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5855: $needs_end = 1;
1.472 raeburn 5856: }
1.443 www 5857:
1.442 www 5858: #
1.622 raeburn 5859: my $hostname = $r->hostname();
1.442 www 5860: my $savefolderpath;
5861:
1.395 raeburn 5862: if ($allowed) {
1.329 droeschl 5863: my $folder=$env{'form.folder'};
1.615 raeburn 5864: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5865: $folder='default';
1.356 tempelho 5866: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5867: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5868: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5869: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5870: }
5871: my $postexec='';
5872: if ($folder eq 'default') {
1.372 bisitz 5873: $r->print('<script type="text/javascript">'."\n"
5874: .'// <![CDATA['."\n"
5875: .'this.window.name="loncapaclient";'."\n"
5876: .'// ]]>'."\n"
5877: .'</script>'."\n"
1.369 bisitz 5878: );
1.329 droeschl 5879: } else {
5880: #$postexec='self.close();';
5881: }
1.504 raeburn 5882: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5883: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5884: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5885:
5886: my $newnavform=(<<NNFORM);
5887: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5888: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5889: $pathitem
1.329 droeschl 5890: <input type="hidden" name="importdetail"
5891: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 5892: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5893: $help{'Navigate_Content'}
5894: </form>
5895: NNFORM
5896: my $newsmppageform=(<<NSPFORM);
5897: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5898: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5899: $pathitem
1.329 droeschl 5900: <input type="hidden" name="importdetail" value="" />
1.423 onken 5901: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5902: $help{'Simple Page'}
1.329 droeschl 5903: </form>
5904: NSPFORM
5905:
5906: my $newsmpproblemform=(<<NSPROBFORM);
5907: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5908: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5909: $pathitem
1.329 droeschl 5910: <input type="hidden" name="importdetail" value="" />
1.423 onken 5911: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5912: $help{'Simple_Problem'}
1.329 droeschl 5913: </form>
5914:
5915: NSPROBFORM
5916:
5917: my $newdropboxform=(<<NDBFORM);
5918: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5919: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5920: $pathitem
1.329 droeschl 5921: <input type="hidden" name="importdetail" value="" />
1.423 onken 5922: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5923: $help{'Dropbox'}
1.344 bisitz 5924: </form>
1.329 droeschl 5925: NDBFORM
5926:
5927: my $newexuploadform=(<<NEXUFORM);
5928: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5929: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5930: $pathitem
1.329 droeschl 5931: <input type="hidden" name="importdetail" value="" />
1.423 onken 5932: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5933: $help{'Score_Upload_Form'}
5934: </form>
5935: NEXUFORM
5936:
5937: my $newbulform=(<<NBFORM);
5938: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5939: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5940: $pathitem
1.329 droeschl 5941: <input type="hidden" name="importdetail" value="" />
1.423 onken 5942: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5943: $help{'Bulletin Board'}
5944: </form>
5945: NBFORM
5946:
5947: my $newaboutmeform=(<<NAMFORM);
5948: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5949: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5950: $pathitem
1.329 droeschl 5951: <input type="hidden" name="importdetail"
5952: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 5953: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5954: $help{'My Personal Information Page'}
1.329 droeschl 5955: </form>
5956: NAMFORM
5957:
5958: my $newaboutsomeoneform=(<<NASOFORM);
5959: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5960: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5961: $pathitem
1.329 droeschl 5962: <input type="hidden" name="importdetail" value="" />
1.423 onken 5963: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5964: </form>
5965: NASOFORM
5966:
5967: my $newrosterform=(<<NROSTFORM);
5968: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5969: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5970: $pathitem
1.329 droeschl 5971: <input type="hidden" name="importdetail"
5972: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 5973: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 5974: $help{'Course_Roster'}
1.329 droeschl 5975: </form>
5976: NROSTFORM
5977:
1.534 raeburn 5978: my $newwebpage;
5979: if ($folder =~ /^default_?(\d*)$/) {
5980: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5981: if ($1) {
5982: $newwebpage .= $1;
5983: } else {
5984: $newwebpage .= 'default';
5985: }
5986: $newwebpage .= '/new.html';
5987: }
5988: my $newwebpageform =(<<NWEBFORM);
5989: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5990: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5991: $pathitem
5992: <input type="hidden" name="importdetail" value="$newwebpage" />
5993: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5994: $help{'Web_Page'}
1.534 raeburn 5995: </form>
5996: NWEBFORM
1.604 raeburn 5997:
1.606 raeburn 5998: my @ids=&Apache::lonnet::current_machine_ids();
5999: my %select_menus;
6000: my $numauthor = 0;
6001: my $numcrsdirs = 0;
6002: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6003: if ($env{'user.author'}) {
6004: $numauthor ++;
6005: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6006: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6007: my $is_home = 1;
6008: my %subdirs;
1.608 raeburn 6009: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6010: $select_menus{'author'}->{'default'} = '/';
6011: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6012: my @ordered = ('/');
6013: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6014: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6015: push(@ordered,$relpath);
6016: }
6017: $select_menus{'author'}->{'order'} = \@ordered;
6018: } else {
6019: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6020: $select_menus{'author'}->{'default'} = 'switch';
6021: $select_menus{'author'}->{'order'} = ['switch'];
6022: }
6023: }
6024: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6025: ['active'],['ca','aa']);
6026: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6027: my %by_roletype;
6028: if (keys(%roleshash)) {
6029: foreach my $entry (keys(%roleshash)) {
6030: my ($auname,$audom,$roletype) = split(/:/,$entry);
6031: my $key = $entry;
6032: $key =~ s/:/___/g;
6033: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6034: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6035: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6036: if (grep(/^\Q$rolehome\E$/,@ids)) {
6037: my $is_home = 1;
6038: my (%subdirs,@ordered);
6039: my $toppath="/priv/$audom/$auname";
1.608 raeburn 6040: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6041: $select_menus{$key}->{'default'} = '/';
6042: $select_menus{$key}->{'select2'}->{'/'} = '/';
6043: my @ordered = ('/');
6044: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6045: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6046: push(@ordered,$relpath);
6047: }
6048: $select_menus{$key}->{'order'} = \@ordered;
6049: } else {
6050: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6051: $select_menus{$key}->{'default'} = 'switch';
6052: $select_menus{$key}->{'order'} = ['switch'];
6053: }
6054: $numauthor ++;
6055: }
6056: }
1.631 ! raeburn 6057: my ($pickdir,$showtitle);
1.606 raeburn 6058: if ($numauthor) {
6059: my @order;
6060: my $defrole;
6061: if ($env{'user.author'}) {
6062: push(@order,'author');
6063: $defrole = 'author';
6064: }
6065: if (keys(%by_roletype)) {
6066: foreach my $possrole ('ca','aa') {
6067: if (ref($by_roletype{$possrole}) eq 'HASH') {
6068: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6069: unless ($defrole) {
6070: $defrole = $author;
6071: }
6072: push(@order,$author.'___'.$possrole);
6073: }
6074: }
6075: }
6076: }
6077: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6078: if (grep(/^\Q$crshome\E$/,@ids)) {
6079: my $is_home = 1;
6080: my %subdirs;
6081: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6082: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6083: $numcrsdirs = keys(%subdirs);
6084: $select_menus{'course'}->{'default'} = '/';
6085: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6086: my @ordered = ('/');
6087: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6088: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6089: push(@ordered,$relpath);
6090: }
6091: $select_menus{'course'}->{'order'} = \@ordered;
6092: } else {
6093: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6094: $select_menus{'course'}->{'default'} = 'switch';
6095: $select_menus{'course'}->{'order'} = ['switch'];
6096: }
6097: push(@order,'course');
6098: $pickdir = $lt{'loca'}.
6099: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6100: $defrole,'authorrole','authorpath',
6101: \%select_menus,\@order,'toggleCrsResTitle();',
6102: '','priv').'<br />';
6103: $showtitle = 'none';
6104: } else {
6105: my $is_home;
6106: $showtitle = 'inline';
6107: if (grep(/^\Q$crshome\E$/,@ids)) {
6108: $is_home = 1;
6109: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6110: my $toppath="/priv/$coursedom/$coursenum'}";
6111: my %subdirs;
1.608 raeburn 6112: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6113: $numcrsdirs = keys(%subdirs);
6114: if ($numcrsdirs) {
6115: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6116: '<option value="/">/</option>'."\n";
6117: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6118: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6119: }
6120: $pickdir .= '</select>';
6121: } else {
6122: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6123: }
6124: }
6125: }
6126:
6127: my %seltemplate_menus;
6128: my @files = &Apache::lonhomework::get_template_list('problem');
6129: my @noexamplelink = ('blank.problem','blank.library','script.library');
6130: my $currentcategory = '';
6131: my @ordered = ('');
6132: my %templatehelp;
6133: my $defcategory = '';
6134: my @catorder = ($defcategory);
6135: $seltemplate_menus{$defcategory}->{'order'} = [''];
6136: $seltemplate_menus{$defcategory}->{'text'} = '';
6137: foreach my $file (@files) {
6138: if (ref($file) eq 'ARRAY') {
6139: my ($path,$title,$category,$help) = @{$file};
6140: next if ($title !~ /\S/);
6141: if (&js_escape($category) ne $currentcategory) {
6142: $currentcategory = &js_escape($category);
6143: push(@catorder,&js_escape($currentcategory));
6144: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6145: $seltemplate_menus{$currentcategory}->{'default'} = '';
6146: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6147: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6148: }
6149: if ($path) {
6150: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6151: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6152: if ($help) {
6153: $templatehelp{$path} = $help;
6154: }
6155: }
6156: }
6157: }
6158:
6159: my $templates = $lt{'cate'}.' '.
6160: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6161: $defcategory,'tempcategory','template',
6162: \%seltemplate_menus,\@catorder,
6163: "resize_scrollbox('contentscroll','1','0');",
6164: "toggleExampleText();",'template').'<br />';
6165: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6166: '<span id="newresexample">'.&mt('Example').'<span></a>';
6167: my $crsresform=(<<RESFORM);
6168: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6169: $lt{'stpr'}</a>$help{'Course_Resource'}
6170: <form action="/adm/coursedocs" method="post" name="courseresform">
6171: <fieldset id="crsresform" style="display:none;">
6172: <legend>$lt{'stpr'}</legend>
6173: <input type="hidden" name="active" value="ee" />
6174: <p>
6175: $pickdir
6176: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6177: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6178:
1.611 raeburn 6179: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6180: </span><span id="newsubdir"></span>
6181: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6182: </p>
6183: $lt{'fnam'}
1.611 raeburn 6184: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6185: <p>
6186: <div id="newresource" style="display:$showtitle">
6187: $lt{'addp'}
1.611 raeburn 6188: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6189: $lt{'no'}</label>
1.611 raeburn 6190: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6191: $lt{'yes'}</label>
6192: <span id="newrestitle"></span>
1.611 raeburn 6193: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6194: </div>
6195: </p>
6196: <p>
6197: $lt{'uste'}
1.611 raeburn 6198: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6199: $lt{'no'}</label>
1.611 raeburn 6200: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6201: $lt{'yes'}</label>
6202: <div id="newrestemplate" style="display:none">
6203: $templates
6204: $templatepreview
6205: </div>
6206: </p>
6207: <span class="LC_nobreak">
6208: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6209: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6210: </span>
6211: </fieldset>
6212: </form>
6213:
6214: RESFORM
1.534 raeburn 6215:
1.342 ehlerst 6216: my $specialdocumentsform;
1.383 tempelho 6217: my @specialdocumentsforma;
1.451 www 6218: my $gradingform;
6219: my @gradingforma;
6220: my $communityform;
6221: my @communityforma;
1.351 ehlerst 6222: my $newfolderform;
1.390 tempelho 6223: my $newfolderb;
1.342 ehlerst 6224:
1.451 www 6225: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6226:
1.329 droeschl 6227: my $newpageform=(<<NPFORM);
6228: <form action="/adm/coursedocs" method="post" name="newpage">
6229: <input type="hidden" name="folderpath" value="$path" />
6230: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6231: <input type="hidden" name="active" value="ee" />
1.423 onken 6232: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6233: $help{'Adding_Pages'}
1.329 droeschl 6234: </form>
6235: NPFORM
1.390 tempelho 6236:
6237:
1.351 ehlerst 6238: $newfolderform=(<<NFFORM);
1.329 droeschl 6239: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6240: $pathitem
1.329 droeschl 6241: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6242: <input type="hidden" name="active" value="" />
1.422 onken 6243: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6244: </form>
6245: NFFORM
6246:
6247: my $newsylform=(<<NSYLFORM);
6248: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6249: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6250: $pathitem
1.329 droeschl 6251: <input type="hidden" name="importdetail"
6252: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6253: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6254: $help{'Syllabus'}
1.383 tempelho 6255:
1.329 droeschl 6256: </form>
6257: NSYLFORM
1.364 bisitz 6258:
1.329 droeschl 6259: my $newgroupfileform=(<<NGFFORM);
6260: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6261: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6262: $pathitem
1.329 droeschl 6263: <input type="hidden" name="importdetail"
6264: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6265: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6266: $help{'Group Portfolio'}
1.329 droeschl 6267: </form>
6268: NGFFORM
1.383 tempelho 6269: @specialdocumentsforma=(
1.421 onken 6270: {'<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 6271: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6272: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6273: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6274: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6275: );
6276: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6277:
1.434 raeburn 6278:
6279: my @importdoc = (
1.519 raeburn 6280: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6281: );
1.598 raeburn 6282: if (keys(%ltitools)) {
6283: push(@importdoc,
1.627 raeburn 6284: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
1.598 raeburn 6285: );
6286: }
1.519 raeburn 6287: unless ($container eq 'page') {
6288: push(@importdoc,
6289: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6290: );
6291: }
6292: push(@importdoc,
1.558 raeburn 6293: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6294: );
1.501 raeburn 6295: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6296:
1.451 www 6297: @gradingforma=(
6298: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6299: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6300: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6301: {'<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 6302: );
6303: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6304:
6305: @communityforma=(
6306: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6307: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6308: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6309: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6310: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6311: );
6312: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6313:
1.330 tempelho 6314: my %orderhash = (
1.553 raeburn 6315: 'aa' => ['Upload',$fileuploadform],
6316: 'bb' => ['Import',$importpubform],
6317: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6318: );
1.519 raeburn 6319: unless ($container eq 'page') {
1.434 raeburn 6320: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6321: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6322: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6323: }
6324:
1.341 ehlerst 6325: $hadchanges=0;
1.484 raeburn 6326: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6327: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6328: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6329: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6330: undef($navmap);
1.443 www 6331: if ($error) {
6332: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6333: }
6334: if ($hadchanges) {
6335: &mark_hash_old();
6336: }
1.341 ehlerst 6337:
1.443 www 6338: &changewarning($r,'');
6339: }
1.458 raeburn 6340: }
1.442 www 6341:
1.443 www 6342: # Supplemental documents start here
6343:
1.329 droeschl 6344: my $folder=$env{'form.folder'};
1.443 www 6345: unless ($supplementalflag) {
1.329 droeschl 6346: $folder='supplemental';
6347: }
6348: if ($folder =~ /^supplemental$/ &&
6349: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6350: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6351: } elsif ($allowed) {
1.356 tempelho 6352: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6353: }
1.508 raeburn 6354: $pathitem = '<input type="hidden" name="folderpath" value="'.
6355: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6356: if ($allowed) {
6357: my $folderseq=
1.504 raeburn 6358: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6359:
6360: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6361: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6362: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6363: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6364: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6365: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6366: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6367: $fileupload
6368: <br />
6369: <br />
6370: <span class="LC_nobreak">
6371: $checkbox
6372: </span>
6373: <br /><br />
6374: $lt{'comment'}:<br />
1.383 tempelho 6375: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6376: <br />
1.508 raeburn 6377: $pathitem
1.329 droeschl 6378: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6379: <input type='submit' value="$lt{'upld'}" />
6380: </form>
1.329 droeschl 6381: SUPDOCFORM
6382:
6383: my $supnewfolderform=(<<SNFFORM);
6384: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6385: <input type="hidden" name="active" value="" />
1.508 raeburn 6386: $pathitem
1.329 droeschl 6387: <input type="hidden" name="importdetail" value="" />
1.423 onken 6388: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6389: $help{'Adding_Folders'}
1.329 droeschl 6390: </form>
6391: SNFFORM
1.383 tempelho 6392:
1.510 raeburn 6393: my $supextform =
6394: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6395: $help{'Adding_External_Resource'},
6396: undef,undef,undef,undef,undef,undef,
6397: $disabled);
1.329 droeschl 6398:
1.598 raeburn 6399: my $supexttoolform =
6400: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6401: $help{'Adding_External_Tool'},
6402: undef,undef,'tool',$coursedom,
1.611 raeburn 6403: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6404:
1.329 droeschl 6405: my $supnewsylform=(<<SNSFORM);
6406: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6407: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6408: $pathitem
1.329 droeschl 6409: <input type="hidden" name="importdetail"
6410: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6411: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6412: $help{'Syllabus'}
6413: </form>
6414: SNSFORM
6415:
6416: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6417: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6418: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6419: $pathitem
1.329 droeschl 6420: <input type="hidden" name="importdetail"
6421: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6422: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6423: $help{'My Personal Information Page'}
1.329 droeschl 6424: </form>
6425: SNAMFORM
6426:
1.534 raeburn 6427: my $supwebpage;
6428: if ($folder =~ /^supplemental_?(\d*)$/) {
6429: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6430: if ($1) {
6431: $supwebpage .= $1;
6432: } else {
6433: $supwebpage .= 'default';
6434: }
6435: $supwebpage .= '/new.html';
6436: }
6437: my $supwebpageform =(<<SWEBFORM);
6438: <form action="/adm/coursedocs" method="post" name="supwebpage">
6439: <input type="hidden" name="active" value="cc" />
6440: $pathitem
6441: <input type="hidden" name="importdetail" value="$supwebpage" />
6442: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6443: $help{'Web_Page'}
1.534 raeburn 6444: </form>
6445: SWEBFORM
6446:
1.333 muellerd 6447:
1.383 tempelho 6448: my @specialdocs = (
1.618 raeburn 6449: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6450: =>$supnewsylform},
1.611 raeburn 6451: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6452: =>$supnewaboutmeform},
1.534 raeburn 6453: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6454:
1.383 tempelho 6455: );
1.417 droeschl 6456: my @supimportdoc = (
1.515 raeburn 6457: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6458: =>$supextform});
6459: if (keys(%ltitools)) {
6460: push(@supimportdoc,
1.627 raeburn 6461: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
1.598 raeburn 6462: =>$supexttoolform});
6463: }
6464: push(@supimportdoc,
6465: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6466: =>$supupdocform},
1.598 raeburn 6467: );
1.501 raeburn 6468:
6469: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6470: my %suporderhash = (
1.390 tempelho 6471: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6472: 'ee' => ['Upload',$supupdocform],
6473: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6474: );
1.443 www 6475: if ($supplementalflag) {
1.458 raeburn 6476: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6477: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6478: \%ltitools,$canedit,$hostname);
1.443 www 6479: if ($error) {
6480: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6481: } else {
6482: if ($suppchanges) {
6483: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6484: my @ids=&Apache::lonnet::current_machine_ids();
6485: foreach my $server (keys(%servers)) {
6486: next if (grep(/^\Q$server\E$/,@ids));
6487: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6488: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6489: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6490: }
6491: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6492: undef($suppchanges);
1.630 raeburn 6493: }
6494: }
1.393 raeburn 6495: }
1.443 www 6496: } elsif ($supplementalflag) {
1.458 raeburn 6497: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6498: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6499: if ($error) {
6500: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6501: }
1.393 raeburn 6502: }
1.389 tempelho 6503:
1.510 raeburn 6504: if ($needs_end) {
6505: $r->print(&endContentScreen());
6506: }
1.383 tempelho 6507:
1.329 droeschl 6508: if ($allowed) {
6509: $r->print('
6510: <form method="post" name="extimport" action="/adm/coursedocs">
6511: <input type="hidden" name="title" />
6512: <input type="hidden" name="url" />
6513: <input type="hidden" name="useform" />
6514: <input type="hidden" name="residx" />
6515: </form>');
6516: }
1.484 raeburn 6517: } elsif ($showdoc) {
1.329 droeschl 6518: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6519: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6520: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6521: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6522: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6523: }
6524: }
1.630 raeburn 6525: unless ($noendpage) {
1.606 raeburn 6526: $r->print(&Apache::loncommon::end_page());
6527: }
1.329 droeschl 6528: return OK;
1.364 bisitz 6529: }
1.329 droeschl 6530:
1.440 raeburn 6531: sub embedded_form_elems {
6532: my ($phase,$primaryurl,$newidx) = @_;
6533: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6534: return <<STATE;
6535: <input type="hidden" name="folderpath" value="$folderpath" />
6536: <input type="hidden" name="cmd" value="upload_embedded" />
6537: <input type="hidden" name="newidx" value="$newidx" />
6538: <input type="hidden" name="phase" value="$phase" />
6539: <input type="hidden" name="primaryurl" value="$primaryurl" />
6540: STATE
6541: }
6542:
6543: sub embedded_destination {
6544: my $folder=$env{'form.folder'};
6545: my $destination = 'docs/';
6546: if ($folder =~ /^supplemental/) {
6547: $destination = 'supplemental/';
6548: }
6549: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6550: $destination .= 'default/';
6551: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6552: $destination .= $2.'/';
6553: }
6554: $destination .= $env{'form.newidx'};
6555: my $dir_root = '/userfiles';
6556: return ($destination,$dir_root);
6557: }
6558:
6559: sub return_to_editor {
6560: my $actionurl = '/adm/coursedocs';
6561: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6562: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6563: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6564: '</a></p>';
6565: }
6566:
1.476 raeburn 6567: sub decompression_info {
6568: my ($destination,$dir_root) = &embedded_destination();
6569: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6570: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6571: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6572: my $container='sequence';
1.480 raeburn 6573: my ($pathitem,$hiddenelem);
1.583 raeburn 6574: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6575: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6576: $container='page';
6577: }
1.480 raeburn 6578: unshift(@hiddens,$pathitem);
6579: foreach my $item (@hiddens) {
6580: if ($env{'form.'.$item}) {
6581: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6582: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6583: }
1.477 raeburn 6584: }
1.476 raeburn 6585: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6586: $hiddenelem);
6587: }
6588:
6589: sub decompression_phase_one {
6590: my ($dir,$file,$warning,$error,$output);
6591: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6592: &decompression_info();
1.490 raeburn 6593: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6594: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6595: } else {
6596: my $file = $1;
1.630 raeburn 6597: $output =
1.481 raeburn 6598: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6599: $destination,$dir_root,
6600: $hiddenelem);
6601: if ($env{'form.autoextract_camtasia'}) {
6602: $output .= &remove_archive($docudom,$docuname,$container);
6603: }
1.476 raeburn 6604: }
6605: if ($error) {
6606: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6607: $error.'</p>'."\n";
6608: }
6609: if ($warning) {
6610: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6611: }
6612: return $output;
6613: }
6614:
6615: sub decompression_phase_two {
6616: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6617: &decompression_info();
1.481 raeburn 6618: my $output;
1.480 raeburn 6619: if ($env{'form.archivedelete'}) {
1.481 raeburn 6620: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6621: }
6622: $output .=
1.481 raeburn 6623: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6624: $destination,$dir_root,$hiddenelem);
6625: return $output;
6626: }
6627:
1.480 raeburn 6628: sub remove_archive {
6629: my ($docudom,$docuname,$container) = @_;
6630: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6631: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6632: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6633: if ($fatal) {
6634: if ($container eq 'page') {
6635: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6636: } else {
6637: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6638: }
1.583 raeburn 6639: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6640: } else {
6641: my $currcmd = $env{'form.cmd'};
6642: my $position = $env{'form.position'};
1.583 raeburn 6643: my $archiveidx = $position;
1.563 raeburn 6644: if ($position > 0) {
1.583 raeburn 6645: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6646: $archiveidx = $position-1;
6647: }
6648: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6649: my ($title,$url,@rrest) =
1.583 raeburn 6650: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6651: if ($url eq $env{'form.archiveurl'}) {
6652: if (&handle_edit_cmd($docuname,$docudom)) {
6653: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6654: if ($fatal) {
6655: if ($container eq 'page') {
6656: $delwarning = &mt('An error occurred updating the contents of the current page.');
6657: } else {
6658: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6659: }
1.480 raeburn 6660: } else {
1.583 raeburn 6661: $delresult = &mt('Archive file removed.');
1.480 raeburn 6662: }
6663: }
1.583 raeburn 6664: } else {
6665: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6666: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6667: }
6668: }
6669: $env{'form.cmd'} = $currcmd;
6670: }
6671: if ($delwarning) {
6672: $output = '<p class="LC_warning">'.
6673: $delwarning.
6674: '</p>';
6675: }
6676: if ($delresult) {
6677: $output .= '<p class="LC_info">'.
6678: $delresult.
6679: '</p>';
6680: }
1.481 raeburn 6681: return $output;
1.480 raeburn 6682: }
6683:
1.484 raeburn 6684: sub generate_admin_menu {
1.611 raeburn 6685: my ($crstype,$canedit) = @_;
1.484 raeburn 6686: my $lc_crstype = lc($crstype);
6687: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6688: my %lt= ( # do not translate here
1.484 raeburn 6689: 'vc' => 'Verify Content',
6690: 'cv' => 'Check/Set Resource Versions',
6691: 'ls' => 'List Resource Identifiers',
6692: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6693: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6694: );
1.484 raeburn 6695: my ($candump,$dumpurl);
6696: if ($home + $other > 0) {
6697: $candump = 'F';
6698: if ($home) {
6699: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6700: } else {
6701: my @hosts;
6702: foreach my $aurole (keys(%outhash)) {
6703: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6704: push(@hosts,$outhash{$aurole});
1.538 raeburn 6705: }
1.484 raeburn 6706: }
6707: if (@hosts == 1) {
6708: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6709: '&role='.
6710: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6711: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6712: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6713: } else {
6714: $dumpurl = "javascript:choose_switchserver_window()";
6715: }
6716: }
6717: }
6718: my @menu=
6719: ({ categorytitle=>'Administration',
6720: items =>[
6721: { linktext => $lt{'vc'},
6722: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6723: permission => 'F',
1.571 raeburn 6724: help => 'Docs_Verify_Content',
1.484 raeburn 6725: icon => 'verify.png',
6726: linktitle => 'Verify contents can be retrieved/rendered',
6727: },
6728: { linktext => $lt{'cv'},
6729: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6730: permission => 'F',
1.571 raeburn 6731: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6732: icon => 'resversion.png',
6733: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6734: },
6735: { linktext => $lt{'ls'},
6736: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6737: permission => 'F',
6738: #help => '',
6739: icon => 'symbs.png',
6740: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6741: },
6742: ]
1.611 raeburn 6743: });
6744: if ($canedit) {
6745: push(@menu,
1.484 raeburn 6746: { categorytitle=>'Export',
6747: items =>[
6748: { linktext => $lt{'imse'},
6749: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6750: permission => 'F',
6751: help => 'Docs_Export_Course_Docs',
6752: icon => 'imsexport.png',
6753: linktitle => $lt{'imse'},
6754: },
6755: { linktext => $lt{'dcd'},
6756: url => $dumpurl,
6757: permission => $candump,
1.571 raeburn 6758: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6759: icon => 'dump.png',
6760: linktitle => $lt{'dcd'},
6761: },
6762: ]
6763: });
1.611 raeburn 6764: }
1.484 raeburn 6765: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6766: '<input type="hidden" id="dummy" />'."\n".
6767: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6768: '</form>';
1.329 droeschl 6769: }
6770:
6771: sub generate_edit_table {
1.538 raeburn 6772: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6773: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6774: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6775: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6776: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6777: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6778: $activetab = $env{'form.active'};
6779: }
1.611 raeburn 6780: unless ($canedit) {
6781: $disabled = ' disabled="disabled"';
6782: }
1.472 raeburn 6783: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6784: my $backtext = &mt('Exit Editor');
1.458 raeburn 6785: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6786: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6787: '<li class="goback">'.
1.546 raeburn 6788: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6789: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6790: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6791: '<li>'.
6792: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6793: &mt('Undo Delete').'</a></li>'."\n";
6794: if ($env{'form.docslog'}) {
6795: $form .= '<li class="active">';
6796: } else {
6797: $form .= '<li>';
6798: }
6799: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6800: &mt('History').'</a></li>'."\n";
6801: if ($env{'form.docslog'}) {
6802: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6803: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6804: }
1.458 raeburn 6805: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6806: if($name ne '00'){
1.371 tempelho 6807: if($activetab eq '' || $activetab ne $name){
6808: $active = '';
6809: }elsif($activetab eq $name){
6810: $active = 'class="active"';
6811: }
1.458 raeburn 6812: $form .= '<li style="float:right" '.$active
1.484 raeburn 6813: .' 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 6814: } else {
1.570 raeburn 6815: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6816:
6817: }
1.329 droeschl 6818: }
1.484 raeburn 6819: $form .= '</ul>'."\n";
6820: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6821:
6822: if ($to_show ne '') {
1.538 raeburn 6823: my $saveform;
6824: if ($need_save) {
6825: my $button = &mt('Make changes');
6826: my $path;
6827: if ($env{'form.folderpath'}) {
6828: $path =
6829: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6830: }
6831: $saveform = <<"END";
6832: <div id="multisave" style="display:none; clear:both;" >
6833: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6834: <input type="hidden" name="folderpath" value="$path" />
6835: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6836: <input type="hidden" name="allhiddenresource" value="" />
6837: <input type="hidden" name="allencrypturl" value="" />
6838: <input type="hidden" name="allrandompick" value="" />
6839: <input type="hidden" name="allrandomorder" value="" />
6840: <input type="hidden" name="changeparms" value="" />
6841: <input type="hidden" name="multiremove" value="" />
6842: <input type="hidden" name="multicut" value="" />
6843: <input type="hidden" name="multicopy" value="" />
6844: <input type="hidden" name="multichange" value="" />
6845: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 6846: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 6847: </form>
6848: </div>
6849: END
6850: }
6851: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6852: }
1.363 ehlerst 6853: foreach my $field (keys(%orderhash)){
1.390 tempelho 6854: if($field ne '00'){
1.422 onken 6855: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6856: $active = 'style="display: none;float:left"';
1.422 onken 6857: }elsif($activetab eq $field){
1.458 raeburn 6858: $active = 'style="display:block;float:left"';
1.422 onken 6859: }
6860: $form .= '<div id="'.$field.$tid.'"'
6861: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6862: .'</div>'."\n";
1.363 ehlerst 6863: }
6864: }
1.484 raeburn 6865: unless ($env{'form.docslog'}) {
6866: $form .= '</div></div>'."\n";
6867: }
1.329 droeschl 6868: return $form;
6869: }
6870:
6871: sub editing_js {
1.622 raeburn 6872: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
6873: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 6874: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6875: p_mnf => 'Name of New Folder',
6876: t_mnf => 'New Folder',
6877: p_mnp => 'Name of New Page',
6878: t_mnp => 'New Page',
1.451 www 6879: p_mxu => 'Title for the External Score',
1.349 biermanm 6880: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6881: p_msb => 'Title for the Problem',
6882: p_mdb => 'Title for the Drop Box',
1.336 schafran 6883: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 6884: p_mwp => 'Title for Web Page',
1.606 raeburn 6885: p_mnr => 'Title for the Resource',
1.348 weissno 6886: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6887: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6888: p_mab_alrt1 => 'Not a valid user:domain',
6889: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6890: p_chn => 'New Title',
6891: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 6892: p_rmr2a => 'Remove',
6893: p_rmr2b => '?',
6894: p_rmr3a => 'Remove those',
6895: p_rmr3b => 'items?',
6896: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6897: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6898: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6899: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 6900: p_ctr2a => 'Cut',
6901: p_ctr2b => '?',
6902: p_ctr3a => 'Cut those',
6903: p_ctr3b => 'items?',
1.478 raeburn 6904: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6905: imsfile => 'You must choose an IMS package for import',
6906: imscms => 'You must select which Course Management System was the source of the IMS package',
6907: invurl => 'Invalid URL',
6908: titbl => 'Title is blank',
1.538 raeburn 6909: more => '(More ...)',
6910: less => '(Less ...)',
1.543 raeburn 6911: noor => 'No actions selected or changes to settings specified.',
6912: noch => 'No changes to settings specified.',
6913: noac => 'No actions selected.',
1.606 raeburn 6914: nofi => 'No file selected',
6915: tinc => 'Title in course',
6916: sunm => 'Sub-directory name',
1.618 raeburn 6917: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6918: );
1.594 damieng 6919: &js_escape(\%js_lt);
1.433 raeburn 6920: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6921: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6922: my $main_container_page;
1.519 raeburn 6923: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6924: $main_container_page = 1;
1.434 raeburn 6925: }
1.617 raeburn 6926: my $backtourl;
6927: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6928: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6929:
1.530 raeburn 6930: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6931: my $caller = $1;
1.525 raeburn 6932: if ($caller =~ /^supplemental/) {
6933: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6934: } else {
6935: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6936: $res = &Apache::lonnet::clutter($res);
6937: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 6938: my ($url,$anchor);
6939: if ($res =~ /^([^#]+)#([^#]+)$/) {
6940: $url = $1;
6941: $anchor = $2;
6942: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6943: $caller = $1.&escape('#').$anchor;
6944: }
1.614 raeburn 6945: } else {
6946: $url = $res;
1.609 raeburn 6947: }
6948: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 6949: &HTML::Entities::encode($caller,'<>&"');
1.622 raeburn 6950: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6951: if (($ENV{'SERVER_PORT'} == 443) &&
6952: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6953: if ($hostname ne '') {
6954: $backtourl = 'http://'.$hostname.$backtourl;
6955: }
1.627 raeburn 6956: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 6957: }
1.623 raeburn 6958: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6959: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6960: $backtourl = 'http://'.$hostname.$backtourl;
6961: }
1.622 raeburn 6962: }
1.609 raeburn 6963: if ($anchor ne '') {
6964: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6965: }
1.590 raeburn 6966: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6967: } else {
6968: $backtourl = '/adm/navmaps';
1.525 raeburn 6969: }
6970: }
6971: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6972: $backtourl = '/adm/menu';
6973: } elsif ($supplementalflag) {
1.472 raeburn 6974: $backtourl = '/adm/supplemental';
1.525 raeburn 6975: } else {
6976: $backtourl = '/adm/navmaps';
1.472 raeburn 6977: }
6978:
1.600 raeburn 6979: my $fieldsets = "'ext','doc'";
6980: if ($posslti) {
6981: $fieldsets .= ",'tool'";
6982: }
1.519 raeburn 6983: unless ($main_container_page) {
6984: $fieldsets .=",'ims'";
6985: }
1.501 raeburn 6986: if ($supplementalflag) {
1.600 raeburn 6987: $fieldsets = "'suppext','suppdoc'";
6988: if ($posslti) {
6989: $fieldsets .= ",'supptool'";
6990: }
1.501 raeburn 6991: }
1.611 raeburn 6992:
6993: my $jsmakefunctions;
6994: if ($canedit) {
6995: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6996: function makenewfolder(targetform,folderseq) {
1.594 damieng 6997: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6998: if (foldername) {
6999: targetform.importdetail.value=escape(foldername)+"="+folderseq;
7000: targetform.submit();
7001: }
7002: }
7003:
7004: function makenewpage(targetform,folderseq) {
1.594 damieng 7005: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7006: if (pagename) {
7007: targetform.importdetail.value=escape(pagename)+"="+folderseq;
7008: targetform.submit();
7009: }
7010: }
7011:
7012: function makeexamupload() {
1.594 damieng 7013: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7014: if (title) {
1.329 droeschl 7015: this.document.forms.newexamupload.importdetail.value=
7016: escape(title)+'=/res/lib/templates/examupload.problem';
7017: this.document.forms.newexamupload.submit();
7018: }
7019: }
7020:
7021: function makesmppage() {
1.594 damieng 7022: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7023: if (title) {
1.329 droeschl 7024: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 7025: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7026: this.document.forms.newsmppg.submit();
7027: }
7028: }
7029:
1.534 raeburn 7030: function makewebpage(type) {
1.594 damieng 7031: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7032: var formname;
7033: if (type == 'supp') {
7034: formname = this.document.forms.supwebpage;
7035: } else {
7036: formname = this.document.forms.newwebpage;
7037: }
7038: if (title) {
7039: var webpage = formname.importdetail.value;
7040: formname.importdetail.value = escape(title)+'='+webpage;
7041: formname.submit();
7042: }
7043: }
7044:
1.329 droeschl 7045: function makesmpproblem() {
1.594 damieng 7046: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7047: if (title) {
1.329 droeschl 7048: this.document.forms.newsmpproblem.importdetail.value=
7049: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7050: this.document.forms.newsmpproblem.submit();
7051: }
7052: }
7053:
7054: function makedropbox() {
1.594 damieng 7055: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7056: if (title) {
1.329 droeschl 7057: this.document.forms.newdropbox.importdetail.value=
7058: escape(title)+'=/res/lib/templates/DropBox.problem';
7059: this.document.forms.newdropbox.submit();
7060: }
7061: }
7062:
7063: function makebulboard() {
1.594 damieng 7064: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7065: if (title) {
7066: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7067: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7068: this.document.forms.newbul.submit();
7069: }
7070: }
7071:
7072: function makeabout() {
1.594 damieng 7073: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7074: if (user) {
7075: var comp=new Array();
7076: comp=user.split(':');
7077: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7078: if ((comp[0]) && (comp[1])) {
7079: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7080: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7081: this.document.forms.newaboutsomeone.submit();
7082: } else {
7083: alert("$js_lt{'p_mab_alrt1'}");
7084: }
7085: } else {
7086: alert("$js_lt{'p_mab_alrt2'}");
7087: }
7088: }
7089: }
7090:
7091: function makenew(targetform) {
7092: targetform.submit();
7093: }
7094:
7095: function changename(folderpath,index,oldtitle) {
7096: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7097: if (title) {
7098: this.document.forms.renameform.markcopy.value='';
7099: this.document.forms.renameform.title.value=title;
7100: this.document.forms.renameform.cmd.value='rename_'+index;
7101: this.document.forms.renameform.folderpath.value=folderpath;
7102: this.document.forms.renameform.submit();
7103: }
7104: }
7105:
7106: ENDNEWSCRIPT
7107: } else {
7108: $jsmakefunctions = <<ENDNEWSCRIPT;
7109:
7110: function makenewfolder() {
7111: alert("$js_lt{'edri'}");
7112: }
7113:
7114: function makenewpage() {
7115: alert("$js_lt{'edri'}");
7116: }
7117:
7118: function makeexamupload() {
7119: alert("$js_lt{'edri'}");
7120: }
7121:
7122: function makesmppage() {
7123: alert("$js_lt{'edri'}");
7124: }
7125:
7126: function makewebpage(type) {
7127: alert("$js_lt{'edri'}");
7128: }
7129:
7130: function makesmpproblem() {
7131: alert("$js_lt{'edri'}");
7132: }
7133:
7134: function makedropbox() {
7135: alert("$js_lt{'edri'}");
7136: }
7137:
7138: function makebulboard() {
7139: alert("$js_lt{'edri'}");
7140: }
7141:
7142: function makeabout() {
7143: alert("$js_lt{'edri'}");
7144: }
7145:
7146: function changename() {
7147: alert("$js_lt{'edri'}");
7148: }
7149:
7150: function makenew() {
7151: alert("$js_lt{'edri'}");
7152: }
7153:
7154: function groupimport() {
7155: alert("$js_lt{'edri'}");
1.335 ehlerst 7156: }
1.611 raeburn 7157:
7158: function groupsearch() {
7159: alert("$js_lt{'edri'}");
1.335 ehlerst 7160: }
1.611 raeburn 7161:
7162: function groupopen(url,recover) {
7163: var options="scrollbars=1,resizable=1,menubar=0";
7164: idxflag=1;
7165: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7166: idx.focus();
1.329 droeschl 7167: }
7168:
1.611 raeburn 7169: ENDNEWSCRIPT
7170:
7171: }
7172: return <<ENDSCRIPT;
7173:
7174: $jsmakefunctions
7175:
1.501 raeburn 7176: function toggleUpload(caller) {
7177: var blocks = Array($fieldsets);
7178: for (var i=0; i<blocks.length; i++) {
7179: var disp = 'none';
7180: if (caller == blocks[i]) {
7181: var curr = document.getElementById('upload'+caller+'form').style.display;
7182: if (curr == 'none') {
7183: disp='block';
7184: }
7185: }
7186: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7187: if ((caller == 'tool') || (caller == 'supptool')) {
7188: if (disp == 'block') {
7189: if (document.getElementById('LC_exttoolid')) {
7190: var toolselector = document.getElementById('LC_exttoolid');
7191: var suppflag = 0;
7192: if (caller == 'supptool') {
7193: suppflag = 1;
7194: }
7195: currForm = document.getElementById('new'+caller);
7196: updateExttool(toolselector,currForm,suppflag);
7197: }
7198: }
7199: }
1.501 raeburn 7200: }
1.502 raeburn 7201: resize_scrollbox('contentscroll','1','1');
7202: return;
7203: }
7204:
1.514 raeburn 7205: function toggleMap(caller) {
1.502 raeburn 7206: var disp = 'none';
1.510 raeburn 7207: if (document.getElementById('importmapform')) {
1.514 raeburn 7208: if (caller == 'map') {
7209: var curr = document.getElementById('importmapform').style.display;
7210: if (curr == 'none') {
7211: disp='block';
7212: }
1.510 raeburn 7213: }
7214: document.getElementById('importmapform').style.display=disp;
7215: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7216: }
1.501 raeburn 7217: return;
1.329 droeschl 7218: }
7219:
1.606 raeburn 7220: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7221: var disp = 'none';
7222: if (document.getElementById('crsresform')) {
7223: if (caller == 'res') {
7224: var curr = document.getElementById('crsresform').style.display;
7225: if (curr == 'none') {
7226: disp='block';
7227: numauthor = parseInt(numauthorrole);
7228: if (numauthor > 0) {
7229: document.courseresform.authorrole.selectedIndex = 0;
7230: select1priv_changed();
7231: document.courseresform.authorpath.selectedIndex = 0;
7232: document.courseresform.newresourceadd.selectedIndex = 0;
7233: toggleNewInCourse(document.courseresform);
7234: if (document.getElementById('newresource')) {
7235: document.getElementById('newresource').style.display = 'none';
7236: }
7237: } else {
7238: if (numcrsdirs) {
7239: document.courseresform.authorpath.selectedIndex = 0;
7240: }
7241: }
7242: if (document.courseresform.newresusetemp.length) {
7243: document.courseresform.newresusetemp[0].checked = true;
7244: toggleWithTemplate(document.courseresform);
7245: }
7246: document.courseresform.newresourcename.value = '';
7247: }
7248: }
7249: if (document.courseresform.newsubdir.length) {
7250: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7251: if (document.courseresform.newsubdir[j].value == 0) {
7252: document.courseresform.newsubdir[j].checked = true;
7253: }
7254: break;
7255: }
7256: if (document.getElementById('newsubdirname')) {
7257: document.getElementById('newsubdirname').type = "hidden";
7258: document.getElementById('newsubdirname').value = "";
7259: }
7260: if (document.getElementById('newsubdir')) {
7261: document.getElementById('newsubdir').innerHTML = "";
7262: }
7263: }
7264: document.getElementById('crsresform').style.display=disp;
7265: resize_scrollbox('contentscroll','1','0');
7266: }
7267: return;
7268: }
7269:
7270: function toggleNewsubdir(form) {
7271: if (form.newsubdir.length) {
7272: for (var j=0; j<form.newsubdir.length; j++) {
7273: if (form.newsubdir[j].checked) {
7274: if (document.getElementById('newsubdirname')) {
7275: if (form.newsubdir[j].value == '1') {
7276: document.getElementById('newsubdirname').type = "text";
7277: if (document.getElementById('newsubdir')) {
7278: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7279: }
7280: } else {
7281: document.getElementById('newsubdirname').type = "hidden";
7282: document.getElementById('newsubdirname').value = "";
7283: document.getElementById('newsubdir').innerHTML = "";
7284: }
7285: }
7286: break;
7287: }
7288: }
7289: }
7290: }
7291:
7292: function toggleCrsResTitle() {
7293: if (document.getElementById('newresource')) {
7294: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7295: document.getElementById('newresource').style.display = 'inline';
7296: document.courseresform.newresourceadd[0].checked = true;
7297: toggleNewInCourse(document.courseresform);
7298: } else {
7299: document.getElementById('newresource').style.display = 'none';
7300: }
7301: }
7302: }
7303:
7304: function toggleNewInCourse(form) {
7305: if (form.newresourceadd.length) {
7306: for (var i=0; i<form.newresourceadd.length; i++) {
7307: if (form.newresourceadd[i].checked) {
7308: if (document.getElementById('newresourcetitle')) {
7309: if (form.newresourceadd[i].value == '1') {
7310: document.getElementById('newresourcetitle').type = 'text';
7311: if (document.getElementById('newrestitle')) {
7312: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7313: }
7314: } else {
7315: document.getElementById('newresourcetitle').type = 'hidden';
7316: document.getElementById('newresourcetitle').value = '';
7317: if (document.getElementById('newrestitle')) {
7318: document.getElementById('newrestitle').innerHTML = '';
7319: }
7320: }
7321: }
7322: break;
7323: }
7324: }
7325: }
7326: }
7327:
7328: function toggleWithTemplate(form) {
7329: if (form.newresusetemp.length) {
7330: for (var i=0; i<form.newresusetemp.length; i++) {
7331: if (form.newresusetemp[i].checked) {
7332: if (document.getElementById('newrestemplate')) {
7333: if (form.newresusetemp[i].value == '1') {
7334: document.getElementById('newrestemplate').style.display = 'inline';
7335: toggleExampleText();
7336: } else {
7337: form.tempcategory.selectedIndex = 0;
7338: select1template_changed();
7339: document.getElementById('newrestemplate').style.display = 'none';
7340: }
7341: }
7342: }
7343: }
7344: }
7345: }
7346:
7347: function toggleExampleText() {
7348: if (document.getElementById('newresexample')) {
7349: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7350: if (url == '') {
7351: document.getElementById('newresexample').style.fontWeight = 'normal';
7352: } else {
7353: document.getElementById('newresexample').style.fontWeight = 'bold';
7354: }
7355: }
7356: }
7357:
7358: function getExample(width,height,scrolling,transparency) {
7359: var url;
7360: if (document.courseresform.newresusetemp.length) {
7361: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7362: if (document.courseresform.newresusetemp[i].checked) {
7363: if (document.courseresform.newresusetemp[i].value == '1') {
7364: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7365: if (url == '') {
7366: alert('Pick a category and template');
7367: } else {
7368: url = url.replace("$londocroot","");
7369: url += '?inhibitmenu=yes';
7370: }
7371: }
7372: break;
7373: }
7374: }
7375: }
7376: if (url != '') {
7377: openMyModal(url,width,height,scrolling,transparency,'');
7378: }
7379: }
7380:
7381: function toggleImportCrsres(caller,dircount) {
7382: var disp = 'none';
7383: if (document.getElementById('importcrsresform')) {
7384: if (caller == 'res') {
7385: var numdirs = parseInt(dircount);
7386: var curr = document.getElementById('importcrsresform').style.display;
7387: if (curr == 'none') {
7388: disp='block';
7389: if (numdirs > 1) {
7390: select1res_changed();
7391: }
7392: }
7393: }
7394: document.getElementById('importcrsresform').style.display=disp;
7395: resize_scrollbox('contentscroll','1','0');
7396: }
7397: return;
7398: }
7399:
1.501 raeburn 7400: function makeims(imsform) {
7401: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7402: alert("$js_lt{'imsfile'}");
1.501 raeburn 7403: return;
7404: }
7405: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7406: alert("$js_lt{'imscms'}");
1.501 raeburn 7407: return;
7408: }
7409: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7410: imsform.submit();
7411: }
7412:
1.478 raeburn 7413: function updatePick(targetform,index,caller) {
1.537 raeburn 7414: var pickitem;
7415: var picknumitem;
7416: var picknumtext;
7417: if (index == 'all') {
7418: pickitem = document.getElementById('randompickall');
7419: picknumitem = document.getElementById('rpicknumall');
7420: picknumtext = document.getElementById('rpicktextall');
7421: } else {
7422: pickitem = document.getElementById('randompick_'+index);
7423: picknumitem = document.getElementById('rpicknum_'+index);
7424: picknumtext = document.getElementById('randompicknum_'+index);
7425: }
1.478 raeburn 7426: if (pickitem.checked) {
1.594 damieng 7427: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7428: if (picknum == '' || picknum == null) {
7429: if (caller == 'check') {
7430: pickitem.checked=false;
1.537 raeburn 7431: if (index == 'all') {
7432: picknumtext.innerHTML = '';
7433: if (caller == 'link') {
7434: propagateState(targetform,'rpicknum');
7435: }
7436: } else {
1.538 raeburn 7437: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7438: }
1.478 raeburn 7439: }
7440: } else {
7441: picknum.toString();
7442: var regexdigit=/^\\d+\$/;
7443: if (regexdigit.test(picknum)) {
7444: picknumitem.value = picknum;
1.537 raeburn 7445: if (index == 'all') {
1.538 raeburn 7446: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7447: if (caller == 'link') {
7448: propagateState(targetform,'rpicknum');
7449: }
7450: } else {
7451: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7452: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7453: }
1.478 raeburn 7454: } else {
7455: if (caller == 'check') {
1.537 raeburn 7456: if (index == 'all') {
7457: picknumtext.innerHTML = '';
7458: if (caller == 'link') {
7459: propagateState(targetform,'rpicknum');
7460: }
7461: } else {
7462: pickitem.checked=false;
1.538 raeburn 7463: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7464: }
1.478 raeburn 7465: }
7466: return;
7467: }
7468: }
7469: } else {
1.537 raeburn 7470: picknumitem.value = '';
7471: picknumtext.innerHTML = '';
7472: if (index == 'all') {
7473: if (caller == 'link') {
7474: propagateState(targetform,'rpicknum');
7475: }
7476: } else {
1.538 raeburn 7477: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7478: }
7479: }
7480: }
7481:
7482: function propagateState(form,param) {
7483: if (document.getElementById(param+'all')) {
7484: var setcheck = 0;
7485: var rpick = 0;
7486: if (param == 'rpicknum') {
7487: if (document.getElementById('randompickall')) {
7488: if (document.getElementById('randompickall').checked) {
7489: if (document.getElementById('rpicknumall')) {
7490: rpick = document.getElementById('rpicknumall').value;
7491: }
7492: }
7493: }
7494: } else {
7495: if (document.getElementById(param+'all').checked) {
7496: setcheck = 1;
7497: }
7498: }
1.538 raeburn 7499: var allidxlist;
7500: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7501: if (document.getElementById('all'+param+'idx')) {
7502: allidxlist = document.getElementById('all'+param+'idx').value;
7503: }
7504: var actions = new Array ('remove','cut','copy');
7505: for (var i=0; i<actions.length; i++) {
7506: if (actions[i] != param) {
7507: if (document.getElementById(actions[i]+'all')) {
7508: document.getElementById(actions[i]+'all').checked = false;
7509: }
7510: }
7511: }
7512: }
1.537 raeburn 7513: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7514: allidxlist = form.allidx.value;
7515: }
7516: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7517: allidxlist = form.allmapidx.value;
7518: }
7519: if ((allidxlist != '') && (allidxlist != null)) {
7520: var allidxs = allidxlist.split(',');
7521: if (allidxs.length > 1) {
7522: for (var i=0; i<allidxs.length; i++) {
7523: if (document.getElementById(param+'_'+allidxs[i])) {
7524: if (param == 'rpicknum') {
7525: if (document.getElementById('randompick_'+allidxs[i])) {
7526: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7527: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7528: if (rpick > 0) {
7529: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7530: } else {
7531: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7532: }
7533: }
7534: }
7535: } else {
1.537 raeburn 7536: if (setcheck == 1) {
7537: document.getElementById(param+'_'+allidxs[i]).checked = true;
7538: } else {
7539: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7540: if (param == 'randompick') {
7541: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7542: }
1.537 raeburn 7543: }
7544: }
7545: }
7546: }
1.538 raeburn 7547: if (setcheck == 1) {
7548: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7549: var actions = new Array('copy','cut','remove');
7550: for (var i=0; i<actions.length; i++) {
7551: var otheractions;
7552: var otheridxs;
7553: if (actions[i] === param) {
7554: continue;
7555: } else {
7556: if (document.getElementById('all'+actions[i]+'idx')) {
7557: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7558: otheridxs = otheractions.split(',');
7559: if (otheridxs.length > 1) {
7560: for (var j=0; j<otheridxs.length; j++) {
7561: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7562: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7563: }
1.537 raeburn 7564: }
7565: }
7566: }
1.538 raeburn 7567: }
7568: }
7569: }
7570: }
7571: }
7572: }
7573: }
7574: return;
7575: }
7576:
1.603 raeburn 7577: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7578: var canedit = '$canedit';
7579: if (canedit == '') {
7580: alert("$js_lt{'edri'}");
7581: return;
7582: }
1.539 raeburn 7583: var dosettings;
7584: var doaction;
1.538 raeburn 7585: var control = document.togglemultsettings;
7586: if (context == 'actions') {
7587: control = document.togglemultactions;
1.539 raeburn 7588: doaction = 1;
7589: } else {
7590: dosettings = 1;
1.538 raeburn 7591: }
1.539 raeburn 7592: if (control) {
7593: if (control.showmultpick.length) {
7594: for (var i=0; i<control.showmultpick.length; i++) {
7595: if (control.showmultpick[i].checked) {
7596: if (control.showmultpick[i].value == 1) {
7597: if (context == 'settings') {
7598: dosettings = 0;
7599: } else {
7600: doaction = 0;
1.538 raeburn 7601: }
7602: }
7603: }
1.537 raeburn 7604: }
7605: }
1.539 raeburn 7606: }
7607: if (context == 'settings') {
7608: if (dosettings == 1) {
1.538 raeburn 7609: targetform.changeparms.value=param;
7610: targetform.submit();
7611: }
1.537 raeburn 7612: }
1.539 raeburn 7613: if (context == 'actions') {
7614: if (doaction == 1) {
7615: targetform.cmd.value=param+'_'+index;
7616: targetform.folderpath.value=folderpath;
7617: targetform.markcopy.value=idx+':'+param;
7618: targetform.copyfolder.value=folder+'.'+container;
7619: if (param == 'remove') {
1.603 raeburn 7620: var doremove = 0;
7621: if (skip_confirm) {
7622: if (confirm_removal) {
7623: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7624: doremove = 1;
7625: }
7626: } else {
7627: doremove = 1;
7628: }
7629: } else {
7630: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7631: doremove = 1;
7632: }
7633: }
7634: if (doremove) {
1.539 raeburn 7635: targetform.markcopy.value='';
7636: targetform.copyfolder.value='';
7637: targetform.submit();
7638: }
7639: }
7640: if (param == 'cut') {
1.594 damieng 7641: 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 7642: targetform.submit();
7643: return;
7644: }
7645: }
7646: if (param == 'copy') {
7647: targetform.submit();
7648: return;
7649: }
7650: targetform.markcopy.value='';
7651: targetform.copyfolder.value='';
7652: targetform.cmd.value='';
7653: targetform.folderpath.value='';
7654: return;
7655: } else {
7656: if (document.getElementById(param+'_'+idx)) {
7657: item = document.getElementById(param+'_'+idx);
7658: if (item.type == 'checkbox') {
7659: if (item.checked) {
7660: item.checked = false;
7661: } else {
7662: item.checked = true;
7663: singleCheck(item,idx,param);
7664: }
7665: }
7666: }
7667: }
7668: }
1.537 raeburn 7669: return;
7670: }
7671:
1.538 raeburn 7672: function singleCheck(caller,idx,action) {
7673: actions = new Array('cut','copy','remove');
7674: if (caller.checked) {
7675: for (var i=0; i<actions.length; i++) {
7676: if (actions[i] != action) {
7677: if (document.getElementById(actions[i]+'_'+idx)) {
7678: if (document.getElementById(actions[i]+'_'+idx).checked) {
7679: document.getElementById(actions[i]+'_'+idx).checked = false;
7680: }
1.537 raeburn 7681: }
7682: }
7683: }
1.478 raeburn 7684: }
1.537 raeburn 7685: return;
1.478 raeburn 7686: }
7687:
1.334 muellerd 7688: function unselectInactive(nav) {
1.335 ehlerst 7689: currentNav = document.getElementById(nav);
7690: currentLis = currentNav.getElementsByTagName('LI');
7691: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7692: if (currentLis[i].className == 'goback') {
7693: currentLis[i].className = 'goback';
7694: } else {
7695: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7696: currentLis[i].className = 'right';
1.472 raeburn 7697: } else {
1.374 tempelho 7698: currentLis[i].className = 'i';
1.472 raeburn 7699: }
7700: }
1.335 ehlerst 7701: }
1.332 tempelho 7702: }
7703:
1.334 muellerd 7704: function hideAll(current, nav, data) {
1.335 ehlerst 7705: unselectInactive(nav);
1.570 raeburn 7706: if (current) {
7707: if (current.className == 'right'){
7708: current.className = 'right active'
7709: } else {
7710: current.className = 'active';
7711: }
1.374 tempelho 7712: }
1.335 ehlerst 7713: currentData = document.getElementById(data);
7714: currentDivs = currentData.getElementsByTagName('DIV');
7715: for (i = 0; i < currentDivs.length; i++) {
7716: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7717: currentDivs[i].style.display = 'none';
1.330 tempelho 7718: }
7719: }
1.335 ehlerst 7720: }
1.330 tempelho 7721:
1.374 tempelho 7722: function openTabs(pageId) {
7723: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7724: if(tabnav.length > 2 ){
1.389 tempelho 7725: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7726: currentLis = currentNav.getElementsByTagName('LI');
7727: for(i = 0; i< currentLis.length; i++){
7728: if(currentLis[i].className == 'active') {
1.375 tempelho 7729: funcString = currentLis[i].onclick.toString();
7730: tab = funcString.split('"');
1.420 onken 7731: if(tab.length < 2) {
7732: tab = funcString.split("'");
7733: }
1.375 tempelho 7734: currentData = document.getElementById(tab[1]);
7735: currentData.style.display = 'block';
1.374 tempelho 7736: }
7737: }
7738: }
7739: }
7740:
1.334 muellerd 7741: function showPage(current, pageId, nav, data) {
1.570 raeburn 7742: currstate = current.className;
1.334 muellerd 7743: hideAll(current, nav, data);
1.375 tempelho 7744: openTabs(pageId);
1.334 muellerd 7745: unselectInactive(nav);
1.570 raeburn 7746: if ((currstate == 'active') || (currstate == 'right active')) {
7747: if (currstate == 'active') {
7748: current.className = '';
7749: } else {
7750: current.className = 'right';
7751: }
7752: activeTab = '';
7753: toggleUpload();
7754: toggleMap();
1.606 raeburn 7755: toggleCrsRes();
7756: toggleImportCrsres();
1.570 raeburn 7757: resize_scrollbox('contentscroll','1','0');
7758: return;
7759: } else {
7760: current.className = 'active';
7761: }
1.330 tempelho 7762: currentData = document.getElementById(pageId);
7763: currentData.style.display = 'block';
1.458 raeburn 7764: activeTab = pageId;
1.501 raeburn 7765: toggleUpload();
1.503 raeburn 7766: toggleMap();
1.606 raeburn 7767: toggleCrsRes();
7768: toggleImportCrsres();
1.433 raeburn 7769: if (nav == 'mainnav') {
7770: var storedpath = "$docs_folderpath";
1.434 raeburn 7771: var storedpage = "$main_container_page";
1.433 raeburn 7772: var reg = new RegExp("^supplemental");
7773: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7774: if (storedpage == 1) {
7775: document.simpleedit.folderpath.value = '';
7776: document.uploaddocument.folderpath.value = '';
7777: } else {
7778: if (reg.test(storedpath)) {
7779: document.simpleedit.folderpath.value = '$toplevelmain';
7780: document.uploaddocument.folderpath.value = '$toplevelmain';
7781: document.newext.folderpath.value = '$toplevelmain';
7782: } else {
7783: document.simpleedit.folderpath.value = storedpath;
7784: document.uploaddocument.folderpath.value = storedpath;
7785: document.newext.folderpath.value = storedpath;
7786: }
1.433 raeburn 7787: }
7788: } else {
1.434 raeburn 7789: if (reg.test(storedpath)) {
7790: document.simpleedit.folderpath.value = storedpath;
7791: document.supuploaddocument.folderpath.value = storedpath;
7792: document.supnewext.folderpath.value = storedpath;
7793: } else {
1.433 raeburn 7794: document.simpleedit.folderpath.value = '$toplevelsupp';
7795: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7796: document.supnewext.folderpath.value = '$toplevelsupp';
7797: }
7798: }
7799: }
1.485 raeburn 7800: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7801: return false;
7802: }
1.329 droeschl 7803:
1.472 raeburn 7804: function toContents(jumpto) {
7805: var newurl = '$backtourl';
1.525 raeburn 7806: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7807: newurl = newurl+'?postdata='+jumpto;
7808: }
7809: location.href=newurl;
7810: }
7811:
1.538 raeburn 7812: function togglePick(caller,value) {
7813: var disp = 'none';
7814: if (document.getElementById('multi'+caller)) {
7815: var curr = document.getElementById('multi'+caller).style.display;
7816: if (value == 1) {
7817: disp='block';
7818: }
7819: if (curr == disp) {
7820: return;
7821: }
7822: document.getElementById('multi'+caller).style.display=disp;
7823: if (value == 1) {
1.594 damieng 7824: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7825: } else {
7826: document.getElementById('more'+caller).innerHTML = '';
7827: }
7828: if (caller == 'actions') {
7829: setClass(value);
7830: setBoxes(value);
7831: }
7832: }
7833: var showButton = multiSettings();
7834: if (showButton != 1) {
7835: showButton = multiActions();
7836: }
7837: if (document.getElementById('multisave')) {
7838: if (showButton == 1) {
7839: document.getElementById('multisave').style.display='block';
7840: } else {
7841: document.getElementById('multisave').style.display='none';
7842: }
7843: }
7844: resize_scrollbox('contentscroll','1','1');
7845: return;
7846: }
7847:
7848: function toggleCheckUncheck(caller,more) {
7849: if (more == 1) {
1.594 damieng 7850: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 7851: document.getElementById('allfields'+caller).style.display='block';
7852: } else {
1.594 damieng 7853: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7854: document.getElementById('allfields'+caller).style.display='none';
7855: }
7856: resize_scrollbox('contentscroll','1','1');
7857: }
7858:
7859: function multiSettings() {
7860: var inuse = 0;
7861: var settingsform = document.togglemultsettings;
7862: if (settingsform.showmultpick.length > 1) {
7863: for (var i=0; i<settingsform.showmultpick.length; i++) {
7864: if (settingsform.showmultpick[i].checked) {
7865: if (settingsform.showmultpick[i].value == 1) {
7866: inuse = 1;
7867: }
7868: }
7869: }
7870: }
7871: return inuse;
7872: }
7873:
7874: function multiActions() {
7875: var inuse = 0;
7876: var actionsform = document.togglemultactions;
7877: if (actionsform.showmultpick.length > 1) {
7878: for (var i=0; i<actionsform.showmultpick.length; i++) {
7879: if (actionsform.showmultpick[i].checked) {
7880: if (actionsform.showmultpick[i].value == 1) {
7881: inuse = 1;
7882: }
7883: }
7884: }
7885: }
7886: return inuse;
7887: }
7888:
7889: function checkSubmits() {
7890: var numchanges = 0;
7891: var form = document.saveactions;
7892: var doactions = multiActions();
1.542 raeburn 7893: var cutwarnings = 0;
7894: var remwarnings = 0;
1.603 raeburn 7895: var removalinfo = 0;
1.538 raeburn 7896: if (doactions == 1) {
7897: var remidxlist = document.cumulativeactions.allremoveidx.value;
7898: if ((remidxlist != '') && (remidxlist != null)) {
7899: var remidxs = remidxlist.split(',');
7900: for (var i=0; i<remidxs.length; i++) {
7901: if (document.getElementById('remove_'+remidxs[i])) {
7902: if (document.getElementById('remove_'+remidxs[i]).checked) {
7903: form.multiremove.value += remidxs[i]+',';
7904: numchanges ++;
1.542 raeburn 7905: if (document.getElementById('skip_remove_'+remidxs[i])) {
7906: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7907: remwarnings ++;
7908: }
7909: }
1.603 raeburn 7910: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7911: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7912: removalinfo ++;
7913: }
7914: }
1.537 raeburn 7915: }
7916: }
1.538 raeburn 7917: }
7918: }
7919: var cutidxlist = document.cumulativeactions.allcutidx.value;
7920: if ((cutidxlist != '') && (cutidxlist != null)) {
7921: var cutidxs = cutidxlist.split(',');
7922: for (var i=0; i<cutidxs.length; i++) {
7923: if (document.getElementById('cut_'+cutidxs[i])) {
7924: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7925: form.multicut.value += cutidxs[i]+',';
7926: numchanges ++;
1.542 raeburn 7927: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7928: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7929: cutwarnings ++;
7930: }
7931: }
1.537 raeburn 7932: }
7933: }
7934: }
7935: }
1.538 raeburn 7936: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7937: if ((copyidxlist != '') && (copyidxlist != null)) {
7938: var copyidxs = copyidxlist.split(',');
7939: for (var i=0; i<copyidxs.length; i++) {
7940: if (document.getElementById('copy_'+copyidxs[i])) {
7941: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7942: form.multicopy.value += copyidxs[i]+',';
7943: numchanges ++;
7944: }
7945: }
7946: }
7947: }
7948: if (numchanges > 0) {
7949: form.multichange.value = numchanges;
7950: }
1.537 raeburn 7951: }
1.538 raeburn 7952: var dosettings = multiSettings();
1.543 raeburn 7953: var haschanges = 0;
1.538 raeburn 7954: if (dosettings == 1) {
7955: form.allencrypturl.value = '';
7956: form.allhiddenresource.value = '';
1.543 raeburn 7957: form.changeparms.value = 'all';
7958: var patt=new RegExp(",\$");
1.538 raeburn 7959: var allidxlist = document.cumulativesettings.allidx.value;
7960: if ((allidxlist != '') && (allidxlist != null)) {
7961: var allidxs = allidxlist.split(',');
7962: if (allidxs.length > 1) {
7963: for (var i=0; i<allidxs.length; i++) {
7964: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7965: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7966: form.allhiddenresource.value += allidxs[i]+',';
7967: }
7968: }
7969: if (document.getElementById('encrypturl_'+allidxs[i])) {
7970: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7971: form.allencrypturl.value += allidxs[i]+',';
7972: }
7973: }
7974: }
1.543 raeburn 7975: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7976: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 7977: }
1.538 raeburn 7978: }
7979: form.allrandompick.value = '';
7980: form.allrandomorder.value = '';
7981: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7982: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7983: var allmapidxs = allmapidxlist.split(',');
7984: for (var i=0; i<allmapidxs.length; i++) {
7985: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7986: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7987: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7988: if ((randompick.checked) && (rpicknum.value != '')) {
7989: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7990: }
7991: if (randorder.checked) {
7992: form.allrandomorder.value += allmapidxs[i]+',';
7993: }
1.537 raeburn 7994: }
1.543 raeburn 7995: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7996: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7997: }
7998: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7999: haschanges = 1;
8000: }
8001: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8002: haschanges = 1;
8003: }
8004: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8005: haschanges = 1;
8006: }
8007: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8008: haschanges = 1;
1.537 raeburn 8009: }
8010: }
1.543 raeburn 8011: if (doactions == 1) {
1.542 raeburn 8012: if (numchanges > 0) {
1.603 raeburn 8013: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8014: if (remwarnings > 0) {
1.594 damieng 8015: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8016: return false;
8017: }
8018: }
1.603 raeburn 8019: if (removalinfo > 0) {
8020: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8021: return false;
8022: }
8023: }
1.542 raeburn 8024: if (cutwarnings > 0) {
1.594 damieng 8025: 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 8026: return false;
8027: }
8028: }
8029: }
8030: form.submit();
8031: return true;
1.543 raeburn 8032: }
8033: }
8034: if (dosettings == 1) {
8035: if (haschanges == 1) {
1.542 raeburn 8036: form.submit();
8037: return true;
8038: }
1.543 raeburn 8039: }
8040: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8041: alert("$js_lt{'noor'}");
1.543 raeburn 8042: } else {
8043: if (dosettings == 1) {
1.594 damieng 8044: alert("$js_lt{'noch'}");
1.543 raeburn 8045: } else {
1.594 damieng 8046: alert("$js_lt{'noac'}");
1.543 raeburn 8047: }
8048: }
1.538 raeburn 8049: return false;
8050: }
8051:
8052: function setClass(value) {
8053: var cutclass = 'LC_docs_cut';
8054: var copyclass = 'LC_docs_copy';
8055: var removeclass = 'LC_docs_remove';
8056: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8057: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8058: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8059: var links = document.getElementsByTagName('a');
8060: for (var i=0; i<links.length; i++) {
8061: var classes = links[i].className;
8062: if (cutreg.test(classes)) {
8063: links[i].className = cutclass;
8064: if (value == 1) {
8065: links[i].className += " LC_menubuttons_link";
8066: }
8067: } else {
8068: if (copyreg.test(classes)) {
8069: links[i].className = copyclass;
8070: if (value == 1) {
8071: links[i].className += " LC_menubuttons_link";
8072: }
8073: } else {
8074: if (removereg.test(classes)) {
8075: links[i].className = removeclass;
8076: if (value == 1) {
8077: links[i].className += " LC_menubuttons_link";
8078: }
8079: }
8080: }
8081: }
8082: }
8083: return;
1.537 raeburn 8084: }
8085:
1.538 raeburn 8086: function setBoxes(value) {
8087: var remidxlist = document.cumulativeactions.allremoveidx.value;
8088: if ((remidxlist != '') && (remidxlist != null)) {
8089: var remidxs = remidxlist.split(',');
8090: for (var i=0; i<remidxs.length; i++) {
8091: if (document.getElementById('remove_'+remidxs[i])) {
8092: var item = document.getElementById('remove_'+remidxs[i]);
8093: if (value == 1) {
8094: item.className = 'LC_docs_remove';
8095: } else {
8096: item.className = 'LC_hidden';
8097: }
8098: }
8099: }
8100: }
8101: var cutidxlist = document.cumulativeactions.allcutidx.value;
8102: if ((cutidxlist != '') && (cutidxlist != null)) {
8103: var cutidxs = cutidxlist.split(',');
8104: for (var i=0; i<cutidxs.length; i++) {
8105: if (document.getElementById('cut_'+cutidxs[i])) {
8106: var item = document.getElementById('cut_'+cutidxs[i]);
8107: if (value == 1) {
8108: item.className = 'LC_docs_cut';
8109: } else {
8110: item.className = 'LC_hidden';
8111: }
8112: }
1.537 raeburn 8113: }
8114: }
1.538 raeburn 8115: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8116: if ((copyidxlist != '') && (copyidxlist != null)) {
8117: var copyidxs = copyidxlist.split(',');
8118: for (var i=0; i<copyidxs.length; i++) {
8119: if (document.getElementById('copy_'+copyidxs[i])) {
8120: var item = document.getElementById('copy_'+copyidxs[i]);
8121: if (value == 1) {
8122: item.className = 'LC_docs_copy';
8123: } else {
8124: item.className = 'LC_hidden';
8125: }
8126: }
1.537 raeburn 8127: }
8128: }
8129: return;
8130: }
8131:
1.606 raeburn 8132: function validImportCrsRes() {
8133: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8134: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8135: if ((fname == '') || (fname == null)) {
8136: alert("$js_lt{'nofi'}");
8137: return false;
8138: }
8139: var url = '/res/$coursedom/$coursenum/';
8140: if (path && path != '/') {
8141: url += path+'/';
8142: }
8143: if (fname != '') {
8144: url += fname;
8145: }
8146: var title = document.crsresimportform.crsrestitle.value;
8147: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8148: return true;
8149: }
8150:
8151: function validateNewRes(caller) {
8152: if (caller == 'single') {
8153: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8154: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8155: var resname = document.courseresform.newresourcename.value;
8156: }
8157: }
8158:
1.611 raeburn 8159: ENDSCRIPT
1.329 droeschl 8160: }
1.457 raeburn 8161:
1.483 raeburn 8162: sub history_tab_js {
8163: return <<"ENDHIST";
8164: function toggleHistoryDisp(choice) {
8165: document.docslogform.docslog.value = choice;
8166: document.docslogform.submit();
8167: return;
8168: }
8169:
8170: ENDHIST
8171: }
8172:
1.484 raeburn 8173: sub inject_data_js {
8174: return <<ENDINJECT;
8175:
8176: function injectData(current, hiddenField, name, value) {
8177: currentElement = document.getElementById(hiddenField);
8178: currentElement.name = name;
8179: currentElement.value = value;
8180: current.submit();
8181: }
8182:
8183: ENDINJECT
8184: }
8185:
8186: sub dump_switchserver_js {
8187: my @hosts = @_;
1.594 damieng 8188: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8189: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8190: swit => 'Switch server?',
1.594 damieng 8191: );
8192: my %html_js_lt = &Apache::lonlocal::texthash(
8193: swit => 'Switch server?',
1.568 raeburn 8194: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8195: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8196: chos => 'Choose server',
8197: );
1.594 damieng 8198: &js_escape(\%js_lt);
8199: &html_escape(\%html_js_lt);
8200: &js_escape(\%html_js_lt);
1.484 raeburn 8201: my $role = $env{'request.role'};
8202: my $js = <<"ENDSWJS";
8203: <script type="text/javascript">
8204: function write_switchserver() {
8205: var server;
8206: if (document.setserver.posshosts.length > 0) {
8207: for (var i=0; i<document.setserver.posshosts.length; i++) {
8208: if (document.setserver.posshosts[i].checked) {
8209: server = document.setserver.posshosts[i].value;
8210: }
8211: }
8212: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8213: }
8214: window.close();
8215: }
8216: </script>
8217:
8218: ENDSWJS
8219:
8220: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8221: {'only_body' => 1,
8222: 'js_ready' => 1,});
8223: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8224:
8225: my $hostpicker;
8226: my $count = 0;
8227: foreach my $host (sort(@hosts)) {
8228: my $checked;
8229: if ($count == 0) {
8230: $checked = ' checked="checked"';
8231: }
8232: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8233: $host.'"'.$checked.' />'.$host.'</label> ';
8234: $count++;
8235: }
8236:
8237: return <<"ENDSWITCHJS";
8238:
8239: function dump_needs_switchserver(url) {
8240: if (url!='' && url!= null) {
1.594 damieng 8241: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8242: go(url);
8243: }
8244: }
8245: return;
8246: }
8247:
8248: function choose_switchserver_window() {
8249: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8250: newWindow.document.open();
8251: newWindow.document.writeln('$startpage');
1.594 damieng 8252: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8253: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8254: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8255: '<form name="setserver" method="post" action="" \\/>\\n'+
8256: '$hostpicker\\n'+
8257: '<br \\/><br \\/>\\n'+
1.594 damieng 8258: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8259: 'onclick="write_switchserver();" \\/>\\n'+
8260: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8261: newWindow.document.writeln('$endpage');
8262: newWindow.document.close();
8263: newWindow.focus();
8264: }
8265:
8266: ENDSWITCHJS
8267: }
8268:
8269: sub makedocslogform {
8270: my ($formelems,$docslog) = @_;
8271: return <<"LOGSFORM";
8272: <form action="/adm/coursedocs" method="post" name="docslogform">
8273: <input type="hidden" name="docslog" value="$docslog" />
8274: $formelems
8275: </form>
8276: LOGSFORM
8277: }
8278:
8279: sub makesimpleeditform {
8280: my ($formelems) = @_;
8281: return <<"SIMPFORM";
8282: <form name="simpleedit" method="post" action="/adm/coursedocs">
8283: <input type="hidden" name="importdetail" value="" />
8284: $formelems
8285: </form>
8286: SIMPFORM
8287: }
8288:
1.606 raeburn 8289: sub makenewproblem {
8290: my ($r,$coursedom,$coursenum) = @_;
8291: # Creating a new problem
8292: my ($redirect,$error);
8293: if ($env{'form.authorrole'}) {
8294: my ($newsubdir,$filename);
8295: if ($env{'form.newsubdir'}) {
8296: if ($env{'form.newsubdirname'} ne '') {
8297: $newsubdir = $env{'form.newsubdirname'};
8298: }
8299: }
8300: if ($env{'form.newresourcename'}) {
8301: $filename = $env{'form.newresourcename'};
8302: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8303: $filename =~ s/`//g;
8304: $filename =~ s{/\.\./}{_}g;
8305: $filename =~ s/\.+/./g;
8306: $filename =~ s{/+}{_}g;
8307: if ($filename ne '') {
8308: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8309: if (($ext) && ($ext ne '.problem')) {
8310: $filename = $name.'.problem';
8311: } elsif ($ext eq '') {
8312: $filename .= '.problem';
8313: }
8314: my $docroot = $r->dir_config('lonDocRoot');
8315: my @ids=&Apache::lonnet::current_machine_ids();
8316: if ($env{'form.authorrole'} eq 'author') {
8317: if ($env{'user.author'}) {
8318: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8319: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8320: my $path = $docroot.$url;
8321: my $subdir = $env{'form.authorpath'};
8322: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8323: }
8324: }
8325: } elsif ($env{'form.authorrole'} eq 'course') {
8326: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8327: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8328: my $url = "/priv/$coursedom/$coursenum";
8329: my $path=$docroot.$url;
8330: my $subdir = $env{'form.authorpath'};
8331: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8332: if ($redirect) {
8333: my $rightsfile = 'default.rights';
8334: my $sourcerights = "$path/$rightsfile";
8335: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8336: my $now = time;
8337: if (!-e $sourcerights) {
8338: my $cid = $coursedom.'_'.$coursenum;
8339: if (open(my $fh,">$sourcerights")) {
8340: print $fh <<END;
8341: <accessrule effect="deny" realm="" type="course" role="" />
8342: <accessrule effect="allow" realm="$cid" type="course" role="" />
8343: END
8344: close($fh);
8345: }
8346: }
8347: if (!-e "$sourcerights.meta") {
8348: if (open(my $fh,">$sourcerights.meta")) {
8349: my $author=$env{'environment.firstname'}.' '.
8350: $env{'environment.middlename'}.' '.
8351: $env{'environment.lastname'}.' '.
8352: $env{'environment.generation'};
8353: $author =~ s/\s+$//;
8354: print $fh <<"END";
8355:
8356: <abstract></abstract>
8357: <author>$author</author>
8358: <authorspace>$coursenum:$coursedom</authorspace>
8359: <copyright>private</copyright>
8360: <creationdate>$now</creationdate>
8361: <customdistributionfile></customdistributionfile>
8362: <dependencies></dependencies>
8363: <domain>$coursedom</domain>
8364: <highestgradelevel>0</highestgradelevel>
8365: <keywords></keywords>
8366: <language>notset </language>
8367: <lastrevisiondate>$now</lastrevisiondate>
8368: <lowestgradelevel>0</lowestgradelevel>
8369: <mime>rights</mime>
8370: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8371: <notes></notes>
8372: <obsolete></obsolete>
8373: <obsoletereplacement></obsoletereplacement>
8374: <owner>$coursenum:$coursedom</owner>
8375: <rule>deny:::course,allow:$cid::course</rule>
8376: <sourceavail></sourceavail>
8377: <standards></standards>
8378: <subject></subject>
8379: <title></title>
8380: END
8381: close($fh);
8382: }
8383: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8384: if (!-e "$docroot/res/$coursedom") {
8385: mkdir("$docroot/res/$coursedom",0755);
8386: }
8387: if (!-e "$docroot/res/$coursedom/$coursenum") {
8388: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8389: }
8390: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8391: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8392: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8393: }
8394: }
8395: }
8396: if ($env{'form.newresourceadd'}) {
8397: my $template = $env{'form.template'};
8398: my $source = $docroot.$redirect;
8399: my $target = $redirect;
8400: $target =~ s{^/priv/}{/res/};
8401: $target = $docroot.$target;
8402: if (!-e $source) {
8403: my $copyfrom;
8404: if ($template) {
8405: my %templates;
8406: my @files = &Apache::lonhomework::get_template_list('problem');
8407: foreach my $poss (@files) {
8408: if (ref($poss) eq 'ARRAY') {
8409: if ($template eq $poss->[0]) {
8410: $templates{$template} = 1;
8411: last;
8412: }
8413: }
8414: }
8415: if ($templates{$template}) {
8416: $copyfrom = $template;
8417: }
8418: }
8419: unless ($copyfrom) {
8420: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8421: }
8422: &File::Copy::copy($copyfrom,$source);
8423: }
8424: if (!-e "$source.meta") {
8425: my $cid = $coursedom.'_'.$coursenum;
8426: my $now = time;
8427: if (open(my $fh,">$source.meta")) {
8428: my $author=$env{'environment.firstname'}.' '.
8429: $env{'environment.middlename'}.' '.
8430: $env{'environment.lastname'}.' '.
8431: $env{'environment.generation'};
8432: $author =~ s/\s+$//;
8433: my $title = $env{'form.newresourcetitle'};
8434: $title =~ s/^\s+|\s+$//g;
8435: print $fh <<END;
8436:
8437: <abstract></abstract>
8438: <author>$author</author>
8439: <authorspace>$coursenum:$coursedom</authorspace>
8440: <copyright>custom</copyright>
8441: <creationdate>$now</creationdate>
8442: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8443: <dependencies></dependencies>
8444: <domain>$coursedom</domain>
8445: <highestgradelevel>0</highestgradelevel>
8446: <keywords></keywords>
8447: <language>notset </language>
8448: <lastrevisiondate>$now</lastrevisiondate>
8449: <lowestgradelevel>0</lowestgradelevel>
8450: <mime>problem</mime>
8451: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8452: <notes></notes>
8453: <obsolete></obsolete>
8454: <obsoletereplacement></obsoletereplacement>
8455: <owner>$coursenum:$coursedom</owner>
8456: <sourceavail></sourceavail>
8457: <standards></standards>
8458: <subject></subject>
8459: <title>$title</title>
8460: END
8461: close($fh);
8462: }
8463: }
8464: }
8465: }
8466: }
8467: } else {
8468: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8469: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8470: if (grep(/^\Q$rolehome\E$/,@ids)) {
8471: my $now = time;
8472: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8473: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8474: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8475: my $url = "/priv/$audom/$auname";
8476: my $path = $r->dir_config('lonDocRoot').$url;
8477: my $subdir = $env{'form.authorpath'};
8478: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8479: }
8480: }
8481: }
8482: }
8483: }
8484: }
8485: }
8486: return ($redirect,$error);
8487: }
8488:
8489: sub finishnewprob {
8490: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8491: unless (-d $path) {
8492: unless (mkdir($path,02770)) {
8493: return;
8494: }
8495: }
1.606 raeburn 8496: my $redirect;
8497: if ($subdir ne '/') {
8498: $subdir = &cleandir($subdir);
8499: if (($subdir ne '') && (-d "$path/$subdir")) {
8500: $path .= "/$subdir";
8501: $url .= "/$subdir";
8502: }
8503: }
8504: my $dest;
8505: if ($newsubdir ne '') {
8506: $newsubdir = &cleandir($newsubdir);
8507: }
8508: if ($newsubdir ne '') {
8509: if (-d "$path/$newsubdir") {
8510: $dest = "$path/$newsubdir/$filename";
8511: } else {
8512: my $dirok;
8513: unless (-e "$path/$newsubdir") {
8514: if (mkdir("$path/$newsubdir",02770)) {
8515: if (chmod(02770,"$path/$newsubdir")) {
8516: $dirok = 1;
8517: }
8518: }
8519: }
8520: if ($dirok) {
8521: $dest = "$path/$newsubdir/$filename";
8522: }
8523: }
8524: if (($dest ne '') && (!-e $dest)) {
8525: $redirect = "$url/$newsubdir/$filename";
8526: }
8527: } else {
8528: $dest = "$path/$filename";
8529: if (($dest ne '') && (!-e $dest)) {
8530: $redirect = "$url/$filename";
8531: }
8532: }
8533: return $redirect;
8534: }
8535:
8536: sub cleandir {
8537: my ($dir) = @_;
8538: $dir =~ s/^\s+//;
8539: $dir =~ s/\s+$//;
8540: $dir =~ s/\.+//g;
8541: $dir =~ s/[\#\?&%\":]//g;
8542: return $dir;
8543: }
8544:
1.329 droeschl 8545: 1;
8546: __END__
8547:
8548:
8549: =head1 NAME
8550:
8551: Apache::londocs.pm
8552:
8553: =head1 SYNOPSIS
8554:
8555: This is part of the LearningOnline Network with CAPA project
8556: described at http://www.lon-capa.org.
8557:
8558: =head1 SUBROUTINES
8559:
8560: =over
8561:
8562: =item %help=()
8563:
8564: Available help topics
8565:
8566: =item mapread()
8567:
1.344 bisitz 8568: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8569: @order and @resources, determines status
8570: sets @order - pointer to resources in right order
8571: sets @resources - array with the resources with correct idx
8572:
8573: =item authorhosts()
8574:
8575: Return hash with valid author names
8576:
8577: =item clean()
8578:
8579: =item dumpcourse()
8580:
8581: Actually dump course
8582:
8583: =item group_import()
8584:
8585: Imports the given (name, url) resources into the course
8586: coursenum, coursedom, and folder must precede the list
8587:
8588: =item breadcrumbs()
8589:
8590: =item log_docs()
8591:
8592: =item docs_change_log()
8593:
8594: =item update_paste_buffer()
8595:
8596: =item print_paste_buffer()
8597:
8598: =item do_paste_from_buffer()
8599:
1.538 raeburn 8600: =item do_buffer_empty()
8601:
8602: =item clear_from_buffer()
8603:
1.492 raeburn 8604: =item get_newmap_url()
8605:
8606: =item dbcopy()
8607:
8608: =item uniqueness_check()
8609:
8610: =item contained_map_check()
8611:
8612: =item url_paste_fixups()
8613:
8614: =item apply_fixups()
8615:
8616: =item copy_dependencies()
8617:
1.329 droeschl 8618: =item update_parameter()
8619:
8620: =item handle_edit_cmd()
8621:
8622: =item editor()
8623:
8624: =item process_file_upload()
8625:
8626: =item process_secondary_uploads()
8627:
8628: =item is_supplemental_title()
8629:
8630: =item entryline()
8631:
8632: =item tiehash()
8633:
8634: =item untiehash()
8635:
8636: =item checkonthis()
8637:
8638: check on this
8639:
8640: =item verifycontent()
8641:
8642: Verify Content
8643:
8644: =item devalidateversioncache() & checkversions()
8645:
8646: Check Versions
8647:
8648: =item mark_hash_old()
8649:
8650: =item is_hash_old()
8651:
8652: =item changewarning()
8653:
8654: =item init_breadcrumbs()
8655:
8656: Breadcrumbs for special functions
8657:
1.484 raeburn 8658: =item create_list_elements()
8659:
8660: =item create_form_ul()
8661:
8662: =item startContentScreen()
8663:
8664: =item endContentScreen()
8665:
8666: =item supplemental_base()
8667:
8668: =item embedded_form_elems()
8669:
8670: =item embedded_destination()
8671:
8672: =item return_to_editor()
8673:
8674: =item decompression_info()
8675:
8676: =item decompression_phase_one()
8677:
8678: =item decompression_phase_two()
8679:
8680: =item remove_archive()
8681:
8682: =item generate_admin_menu()
8683:
8684: =item generate_edit_table()
8685:
8686: =item editing_js()
8687:
8688: =item history_tab_js()
8689:
8690: =item inject_data_js()
8691:
8692: =item dump_switchserver_js()
8693:
1.485 raeburn 8694: =item resize_scrollbox_js()
1.484 raeburn 8695:
8696: =item makedocslogform()
8697:
1.485 raeburn 8698: =item makesimpleeditform()
8699:
1.329 droeschl 8700: =back
8701:
8702: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>