Annotation of loncom/interface/londocs.pm, revision 1.484.2.85.2.8
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.85.2. (raeburn 4:): # $Id: londocs.pm,v 1.484.2.85.2.7 2020/10/25 20:36:06 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.484.2.19 raeburn 43: use Apache::lonextresedit();
1.484.2.43 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.484.2.85.2. (raeburn 46:): use Apache::loncourserespicker();
1.329 droeschl 47: use HTML::Entities;
1.484.2.7 raeburn 48: use HTML::TokeParser;
1.329 droeschl 49: use GDBM_File;
1.484.2.51 raeburn 50: use File::MMagic;
1.329 droeschl 51: use Apache::lonlocal;
52: use Cwd;
53: use LONCAPA qw(:DEFAULT :match);
54:
55: my $iconpath;
56:
57: my %hash;
58:
59: my $hashtied;
60: my %alreadyseen=();
61:
62: my $hadchanges;
1.484.2.37 raeburn 63: my $suppchanges;
1.329 droeschl 64:
65:
66: my %help=();
67:
68:
69: sub mapread {
70: my ($coursenum,$coursedom,$map)=@_;
71: return
72: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
73: $map);
74: }
75:
76: sub storemap {
1.484.2.7 raeburn 77: my ($coursenum,$coursedom,$map,$contentchg)=@_;
78: my $report;
79: if (($contentchg) && ($map =~ /^default/)) {
80: $report = 1;
81: }
1.329 droeschl 82: my ($outtext,$errtext)=
83: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 84: $map,1,$report);
1.329 droeschl 85: if ($errtext) { return ($errtext,2); }
1.364 bisitz 86:
1.484.2.37 raeburn 87: if ($map =~ /^default/) {
88: $hadchanges=1;
89: } else {
90: $suppchanges=1;
91: }
1.329 droeschl 92: return ($errtext,0);
93: }
94:
95:
96:
97: sub authorhosts {
98: my %outhash=();
99: my $home=0;
100: my $other=0;
101: foreach my $key (keys(%env)) {
102: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
103: my $role=$1;
104: my $realm=$2;
105: my ($start,$end)=split(/\./,$env{$key});
106: if (($start) && ($start>time)) { next; }
107: if (($end) && (time>$end)) { next; }
108: my ($ca,$cd);
109: if ($1 eq 'au') {
110: $ca=$env{'user.name'};
111: $cd=$env{'user.domain'};
112: } else {
113: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
114: }
115: my $allowed=0;
116: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
117: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 118: foreach my $id (@ids) {
119: if ($id eq $myhome) {
120: $allowed=1;
121: last;
122: }
123: }
1.329 droeschl 124: if ($allowed) {
125: $home++;
1.484 raeburn 126: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 127: } else {
1.484 raeburn 128: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 129: $other++;
130: }
131: }
132: }
133: return ($home,$other,%outhash);
134: }
135:
136:
137: sub clean {
138: my ($title)=@_;
139: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 140: return $title;
1.329 droeschl 141: }
142:
1.484.2.67 raeburn 143: sub default_folderpath {
144: my ($coursenum,$coursedom,$navmapref) = @_;
145: return unless ($coursenum && $coursedom && ref($navmapref));
146: # Check if entire course is hidden and/or encrypted
147: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
148: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
149: unless (ref($$navmapref)) {
150: $$navmapref = Apache::lonnavmaps::navmap->new();
151: }
152: if (ref($$navmapref)) {
153: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
154: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
155: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
156: unless (@resources) {
157: $hiddenmap = 1;
158: unless ($env{'request.role.adv'}) {
159: $hiddentop = 1;
160: if ($env{'form.folder'}) {
161: undef($env{'form.folder'});
162: }
163: }
164: }
165: }
166: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
167: $encryptmap = 1;
168: }
169: }
170: unless ($hiddentop) {
171: $folderpath='default&'.&escape(&mt('Main Content')).
172: '::'.$hiddenmap.':'.$encryptmap.'::';
173: }
174: if (wantarray) {
175: return ($folderpath,$hiddentop);
176: } else {
177: return $folderpath;
178: }
179: }
1.329 droeschl 180:
181: sub dumpcourse {
182: my ($r) = @_;
1.408 raeburn 183: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 184: my ($starthash,$js);
185: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
186: $js = <<"ENDJS";
187: <script type="text/javascript">
188: // <![CDATA[
189:
190: function hide_searching() {
191: if (document.getElementById('searching')) {
192: document.getElementById('searching').style.display = 'none';
193: }
194: return;
195: }
196:
197: // ]]>
198: </script>
199: ENDJS
200: $starthash = {
201: add_entries => {'onload' => "hide_searching();"},
202: };
203: }
204: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
205: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 206: $r->print(&startContentScreen('tools'));
1.329 droeschl 207: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 208: unless ($home) {
209: $r->print(&endContentScreen());
210: return '';
211: }
1.329 droeschl 212: my $origcrsid=$env{'request.course.id'};
213: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
214: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
215: # Do the dumping
1.484 raeburn 216: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
217: $r->print(&endContentScreen());
218: return '';
219: }
1.484.2.24 raeburn 220: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 221: $r->print('<h3>'.&mt('Copying Files').'</h3>');
222: my $title=$env{'form.authorfolder'};
223: $title=&clean($title);
1.484.2.43 raeburn 224: my ($navmap,$errormsg) =
225: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
226: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
227: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
228: my (%maps,%resources,%titles);
229: if (!ref($navmap)) {
230: $r->print($errormsg.
231: &endContentScreen());
232: return '';
233: } else {
234: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
235: 'dumpdocs',$cdom,$cnum);
236: }
237: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
238: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
239: %newcontent,%has_simpleprobs);
240: foreach my $item (sort {$a <=> $b} (@todump)) {
241: my $name = $env{'form.namefor_'.$item};
242: if ($resources{$item}) {
243: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
244: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
245: $tocopy{$1} = $name;
246: $display{$item} = $1;
247: $lookup{$1} = $item;
248: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
249: $simpleproblems{$item} = {
250: symb => $resources{$item},
251: name => $name,
252: };
253: $display{$item} = 'simpleproblem_'.$name;
254: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
255: $has_simpleprobs{$1}{$id} = $item;
256: }
257: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
258: my $marker = $1;
259: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
260: $simplepages{$item} = {
261: res => $res,
262: title => $titles{$item},
263: db => $db_name,
264: marker => $marker,
265: symb => $resources{$item},
266: name => $name,
267: };
268: $display{$item} = '/'.$res;
269: }
270: } elsif ($maps{$item}) {
271: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
272: $tocopy{$1} = $name;
273: $display{$item} = $1;
274: $lookup{$1} = $item;
275: }
276: } else {
277: next;
278: }
279: }
1.329 droeschl 280: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
281: $crs=~s/\_/\//g;
1.484.2.43 raeburn 282: my $mm = new File::MMagic;
283: my $prefix = "/uploaded/$cdom/$cnum/";
284: %replacehash = %tocopy;
285: foreach my $item (sort(keys(%simpleproblems))) {
286: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
287: $newcontent{$display{$item}} = $content;
288: }
289: my $gateway = Apache::lonhtmlgateway->new('web');
290: foreach my $item (sort(keys(%simplepages))) {
291: if (ref($simplepages{$item}) eq 'HASH') {
292: my $pagetitle = $simplepages{$item}{'title'};
293: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
294: my %contents;
295: foreach my $field (keys(%fields)) {
296: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
297: my $name = $1;
298: my $msg = $fields{$field};
299: if ($name eq 'webreferences') {
300: if ($msg =~ m{^https?://}) {
301: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
302: }
303: } else {
304: $msg = &Encode::decode('utf8',$msg);
305: $msg = $gateway->process_outgoing_html($msg,1);
306: $contents{$name} = $msg;
307: }
308: } elsif ($field eq 'uploaded.photourl') {
309: my $marker = $simplepages{$item}{marker};
310: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
311: my $filepath = $1;
312: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
313: if ($fname ne '') {
314: $fname=~s/\.(\w+)$//;
315: my $ext=$1;
316: $fname = &clean($fname);
317: $fname.='.'.$ext;
318: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
319: $replacehash{$filepath} = $relpath.$fname;
320: $deps{$item}{$filepath} = 1;
321: }
322: }
323: }
324: }
325: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
326: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
327: my $content = '
328: <html>
329: <head>
330: <title>'.$pagetitle.'</title>
331: </head>
332: <body bgcolor="#ffffff">';
333: if ($contents{title}) {
334: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
335: }
336: if ($contents{image}) {
337: $content .= "\n".$contents{image};
338: }
339: if ($contents{content}) {
340: $content .= '
341: <div class="LC_Box">
1.484.2.50 raeburn 342: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 343: $contents{content}.'
344: </div>';
345: }
346: if ($contents{webreferences}) {
347: $content .= '
348: <div class="LC_Box">
1.484.2.50 raeburn 349: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 350: $contents{webreferences}.'
351: </div>';
352: }
353: $content .= '
354: </body>
355: </html>
356: ';
357: $newcontent{'/'.$simplepages{$item}{res}} = $content;
358: }
359: }
360: foreach my $item (keys(%tocopy)) {
361: unless ($item=~/\.(sequence|page)$/) {
362: my $currurlpath = $prefix.$item;
363: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
364: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
365: }
366: }
367: foreach my $num (sort {$a <=> $b} (@todump)) {
368: my $src = $display{$num};
369: next if ($src eq '');
370: my @needcopy = ();
371: if ($replacehash{$src}) {
372: push(@needcopy,$src);
373: if (ref($deps{$num}) eq 'HASH') {
374: foreach my $dep (sort(keys(%{$deps{$num}}))) {
375: if ($replacehash{$dep}) {
376: push(@needcopy,$dep);
377: }
378: }
379: }
380: } elsif ($src =~ /^simpleproblem_/) {
381: push(@needcopy,$src);
382: }
383: next if (@needcopy == 0);
384: my ($result,$depresult);
385: for (my $i=0; $i<@needcopy; $i++) {
386: my $item = $needcopy[$i];
387: my $newfilename;
388: if ($simpleproblems{$num}) {
389: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
390: } else {
391: $newfilename=$title.'/'.$replacehash{$item};
392: }
393: $newfilename=~s/\.(\w+)$//;
394: my $ext=$1;
395: $newfilename=&clean($newfilename);
396: $newfilename.='.'.$ext;
397: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
398: if ($newrelpath ne $replacehash{$item}) {
399: $replacehash{$item} = $newrelpath;
400: }
401: my @dirs=split(/\//,$newfilename);
402: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
403: my $makepath=$path;
404: my $fail;
405: my $origin;
406: for (my $i=0;$i<$#dirs;$i++) {
407: $makepath.='/'.$dirs[$i];
408: unless (-e $makepath) {
409: unless(mkdir($makepath,0755)) {
410: $fail = &mt('Directory creation failed.');
411: }
412: }
413: }
414: if ($i == 0) {
415: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
416: } else {
417: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
418: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
419: &mt('(dependency)').'</span>: ';
420: }
421: if (-e $path.'/'.$newfilename) {
422: $fail = &mt('Destination already exists -- not overwriting.');
423: } else {
424: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
425: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
426: ($item =~ /^simpleproblem_/)) {
427: print $fh $newcontent{$item};
428: } else {
429: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
430: if (-e $fileloc) {
431: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
432: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
433: (ref($has_simpleprobs{$item}) eq 'HASH')) {
434: my %changes = %{$has_simpleprobs{$item}};
435: my $content = &Apache::lonclonecourse::rewritefile(
436: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
437: (%replacehash,$crs => '')
438: );
439: my $updatedcontent = '';
440: my $parser = HTML::TokeParser->new(\$content);
441: $parser->attr_encoded(1);
442: while (my $token = $parser->get_token) {
443: if ($token->[0] eq 'S') {
444: if (($token->[1] eq 'resource') &&
445: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
446: ($changes{$token->[2]->{'id'}})) {
447: my $id = $token->[2]->{'id'};
448: $updatedcontent .= '<'.$token->[1];
449: foreach my $attrib (@{$token->[3]}) {
450: next unless ($attrib =~ /^(src|type|title|id)$/);
451: if ($attrib eq 'src') {
452: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
453: if ($file) {
454: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
455: } else {
456: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
457: }
458: } else {
459: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
460: }
461: }
462: $updatedcontent .= ' />'."\n";
463: } else {
464: $updatedcontent .= $token->[4]."\n";
465: }
466: } else {
467: $updatedcontent .= $token->[2];
468: }
469: }
470: print $fh $updatedcontent;
471: } else {
472: print $fh &Apache::lonclonecourse::rewritefile(
473: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
474: (%replacehash,$crs => '')
475: );
476: }
477: } else {
478: print $fh
479: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
480: }
481: } else {
482: $fail = &mt('Source does not exist.');
483: }
484: }
485: $fh->close();
486: } else {
487: $fail = &mt('Could not write to destination.');
488: }
489: }
490: my $text;
491: if ($fail) {
492: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
493: } else {
494: $text = '<span class="LC_success">'.&mt('ok').'</span>';
495: }
496: if ($i == 0) {
497: $result .= $text;
498: } else {
499: $depresult .= $text.'</li>';
500: }
501: }
502: $r->print($result);
503: if ($depresult) {
504: $r->print('<ul>'.$depresult.'</ul>');
505: }
506: }
1.329 droeschl 507: } else {
1.484.2.43 raeburn 508: my ($navmap,$errormsg) =
509: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
510: if (!ref($navmap)) {
511: $r->print($errormsg);
512: } else {
513: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
514: $r->rflush();
515: my ($preamble,$formname);
516: $formname = 'dumpdoc';
517: unless ($home==1) {
518: $preamble = '<div class="LC_left_float">'.
519: '<fieldset><legend>'.
520: &mt('Select the Authoring Space').
521: '</legend><select name="authorspace">';
522: }
523: my @orderspaces = ();
524: foreach my $key (sort(keys(%outhash))) {
525: if ($key=~/^home_(.+)$/) {
526: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
527: unshift(@orderspaces,$1);
528: } else {
529: push(@orderspaces,$1);
530: }
531: }
532: }
533: if ($home>1) {
534: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
535: }
536: foreach my $user (@orderspaces) {
537: if ($home==1) {
538: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
539: } else {
540: $preamble .= '<option value="'.$user.'">'.$user.' - '.
541: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
542: }
543: }
544: unless ($home==1) {
545: $preamble .= '</select></fieldset></div>'."\n";
546: }
547: my $title=$origcrsdata{'description'};
548: $title=~s/[\/\s]+/\_/gs;
549: $title=&clean($title);
550: $preamble .= '<div class="LC_left_float">'.
551: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
552: '<input type="text" size="50" name="authorfolder" value="'.
553: $title.'" />'.
554: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
555: my %uploadedfiles;
556: &tiehash();
557: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
558: my ($ext)=($file=~/\.(\w+)$/);
559: # FIXME Check supplemental here
560: my $title=$hash{'title_'.$hash{
561: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
562: if (!$title) {
563: $title=$file;
564: } else {
565: $title=~s|/|_|g;
566: }
567: $title=~s/\.(\w+)$//;
568: $title=&clean($title);
569: $title.='.'.$ext;
570: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
571: $uploadedfiles{$file} = $title;
572: }
573: &untiehash();
574: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
575: undef,undef,$preamble,$home,\%uploadedfiles));
576: }
1.329 droeschl 577: }
1.484 raeburn 578: $r->print(&endContentScreen());
1.329 droeschl 579: }
580:
1.484.2.43 raeburn 581: sub recurse_html {
582: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
583: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
584: my (%allfiles,%codebase);
585: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
586: if (keys(%allfiles)) {
587: foreach my $dependency (keys(%allfiles)) {
588: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
589: my ($depurl,$relfile,$newcontainer);
590: if ($dependency =~ m{^/}) {
591: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
592: $relfile = $1;
593: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
594: $newcontainer = $1;
595: next if ($replacehash->{$newcontainer});
596: }
597: $depurl = $dependency;
598: } else {
599: next;
600: }
601: } else {
602: $relfile = $dependency;
603: $depurl = $currurlpath;
604: $depurl =~ s{[^/]+$}{};
605: $depurl .= $dependency;
606: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
607: }
608: next if ($relfile eq '');
609: my $newname = $replacehash->{$container};
610: $newname =~ s{[^/]+$}{};
611: $replacehash->{$newcontainer} = $newname.$relfile;
612: $deps->{$item}{$newcontainer} = 1;
613: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
614: my $depfile = &Apache::lonnet::filelocation('',$depurl);
615: my $type = $mm->checktype_filename($depfile);
616: if ($type eq 'text/html') {
617: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
618: }
619: }
620: }
621: }
622: return;
623: }
624:
1.329 droeschl 625: sub group_import {
1.484.2.85.2. (raeburn 626:): my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.484.2.23 raeburn 627: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
628: %removeparam,$importuploaded,$fixuperrors);
629: $allmaps = {};
1.329 droeschl 630: while (@files) {
631: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 632: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 633: && ($caller eq 'londocs')
634: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 635:
1.329 droeschl 636: my $errtext = '';
637: my $fatal = 0;
638: my $newmapstr = '<map>'."\n".
639: '<resource id="1" src="" type="start"></resource>'."\n".
640: '<link from="1" to="2" index="1"></link>'."\n".
641: '<resource id="2" src="" type="finish"></resource>'."\n".
642: '</map>';
643: $env{'form.output'}=$newmapstr;
644: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
645: 'output',$1.$2);
1.484.2.27 raeburn 646: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 647: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
648: $fatal = 2;
649: }
650: if ($fatal) {
651: return ($errtext,$fatal);
652: }
653: }
654: if ($url) {
1.484.2.85.2. (raeburn 655:): if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
656:): $url = $1;
657:): my $marker = $2;
658:): my $info = $3;
659:): my ($toolid,%toolhash,%toolsettings);
660:): my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
661:): my @toolinfo = split(/:/,$info);
662:): if ($residx) {
663:): %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
664:): $toolid = $toolsettings{'id'};
665:): } else {
666:): $toolid = shift(@toolinfo);
667:): }
668:): $toolid =~ s/\D//g;
669:): ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
670:): $toolhash{'linktext'},$toolhash{'explanation'},
671:): $toolhash{'crslabel'},$toolhash{'crstitle'},$toolhash{'crsappend'}) = @toolinfo;
672:): foreach my $item (@extras) {
673:): $toolhash{$item} = &unescape($toolhash{$item});
674:): }
675:): if (ref($ltitoolsref) eq 'HASH') {
676:): my @deleted;
677:): if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
678:): $toolhash{'id'} = $toolid;
679:): if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
680:): ($toolhash{'target'} eq 'window')) {
681:): if ($toolhash{'target'} eq 'window') {
682:): foreach my $item ('width','height') {
683:): $toolhash{$item} =~ s/^\s+//;
684:): $toolhash{$item} =~ s/\s+$//;
685:): if ($toolhash{$item} =~ /\D/) {
686:): delete($toolhash{$item});
687:): if ($residx) {
688:): if ($toolsettings{$item}) {
689:): push(@deleted,$item);
690:): }
691:): }
692:): }
693:): }
694:): }
695:): } elsif ($residx) {
696:): $toolhash{'target'} = $toolsettings{'target'};
697:): if ($toolhash{'target'} eq 'window') {
698:): foreach my $item ('width','height') {
699:): $toolhash{$item} = $toolsettings{$item};
700:): }
701:): }
702:): } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
703:): $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
704:): if ($toolhash{'target'} eq 'window') {
705:): $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
706:): $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
707:): }
708:): }
709:): if ($toolhash{'target'} eq 'iframe') {
710:): foreach my $item ('width','height','linktext','explanation') {
711:): delete($toolhash{$item});
712:): if ($residx) {
713:): if ($toolsettings{$item}) {
714:): push(@deleted,$item);
715:): }
716:): }
717:): }
718:): } elsif ($toolhash{'target'} eq 'tab') {
719:): foreach my $item ('width','height') {
720:): delete($toolhash{$item});
721:): if ($residx) {
722:): if ($toolsettings{$item}) {
723:): push(@deleted,$item);
724:): }
725:): }
726:): }
727:): }
728:): if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
729:): foreach my $item ('label','title','linktext','explanation') {
730:): my $crsitem;
731:): if (($item eq 'label') || ($item eq 'title')) {
732:): $crsitem = 'crs'.$item;
733:): } else {
734:): $crsitem = $item;
735:): }
736:): if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
737:): $toolhash{$crsitem} =~ s/^\s+//;
738:): $toolhash{$crsitem} =~ s/\s+$//;
739:): if ($toolhash{$crsitem} eq '') {
740:): delete($toolhash{$crsitem});
741:): }
742:): } else {
743:): delete($toolhash{$crsitem});
744:): }
745:): if (($residx) && (exists($toolsettings{$crsitem}))) {
746:): unless (exists($toolhash{$crsitem})) {
747:): push(@deleted,$crsitem);
748:): }
749:): }
750:): }
751:): }
752:): my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
753:): if ($putres eq 'ok') {
754:): if (@deleted) {
755:): &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
756:): }
757:): }
758:): }
759:): }
760:): }
1.484.2.23 raeburn 761: if (($caller eq 'londocs') &&
762: ($folder =~ /^default/)) {
1.484.2.27 raeburn 763: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 764: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
765: my $cid = $coursedom.'_'.$coursenum;
766: $allmaps =
767: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
768: $chome,$cid);
769: $donechk = 1;
770: }
771: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.484.2.85.2. (raeburn 772:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
773:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.484.2.23 raeburn 774: $importuploaded = 1;
775: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
776: next if ($allmaps->{$url});
777: }
778: }
1.344 bisitz 779: if (!$residx
1.329 droeschl 780: || defined($LONCAPA::map::zombies[$residx])) {
781: $residx = &LONCAPA::map::getresidx($url,$residx);
782: push(@LONCAPA::map::order, $residx);
783: }
784: my $ext = 'false';
785: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.484.2.27 raeburn 786: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
787: my $filepath = $1;
1.484.2.85.2. (raeburn 788:): my $fname;
789:): if ($name eq '') {
790:): $name = &mt('Web Page');
1.484.2.27 raeburn 791: $fname = 'web';
792: } else {
1.484.2.85.2. (raeburn 793:): $fname = $name;
794:): $fname=&Apache::lonnet::clean_filename($fname);
795:): if ($fname eq '') {
796:): $fname = 'web';
797:): } elsif (length($fname) > 15) {
798:): $fname = substr($fname,0,14);
799:): }
1.484.2.27 raeburn 800: }
1.484.2.85.2. (raeburn 801:): my $title = &Apache::loncommon::cleanup_html($name);
1.484.2.27 raeburn 802: my $initialtext = &mt('Replace with your own content.');
803: my $newhtml = <<END;
1.484.2.31 raeburn 804: <html>
1.484.2.27 raeburn 805: <head>
1.484.2.85.2. (raeburn 806:): <title>$title</title>
1.484.2.27 raeburn 807: </head>
808: <body bgcolor="#ffffff">
809: $initialtext
810: </body>
811: </html>
812: END
813: $env{'form.output'}=$newhtml;
814: my $result =
815: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
816: 'output',
817: "$filepath/$residx/$fname.html");
818: if ($result =~ m{^/uploaded/}) {
819: $url = $result;
820: if ($filepath =~ /^supplemental/) {
821: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
822: $env{'user.domain'}.'___&&&___'.$name;
823: }
824: } else {
825: return (&mt('Failed to save new web page.'),1);
826: }
827: }
1.484.2.85.2. (raeburn 828:): $name = &LONCAPA::map::qtunescape($name);
1.484.2.30 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.484.2.23 raeburn 834: if ($importuploaded) {
835: my %import_errors;
836: my %updated = (
837: removefrommap => \%removefrommap,
838: removeparam => \%removeparam,
839: );
1.484.2.26 raeburn 840: my ($result,$msgsarray,$lockerror) =
841: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 842: if (keys(%import_errors) > 0) {
843: $fixuperrors =
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.484.2.26 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.484.2.23 raeburn 864: }
865: my ($errtext,$fatal) =
866: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 867: unless ($fatal) {
868: if ($folder =~ /^supplemental/) {
869: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 870: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
871: $folder.'.'.$container);
1.484.2.37 raeburn 872: }
873: }
1.484.2.23 raeburn 874: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 875: }
876:
877: sub log_docs {
1.484.2.8 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.484.2.67 raeburn 939: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 940: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 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.484.2.67 raeburn 945: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.85.2. (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.484.2.7 raeburn 953: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 954: my %orderhash;
955: my $container='sequence';
956: my $pathitem;
1.484.2.19 raeburn 957: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 958: $container='page';
959: }
1.484.2.19 raeburn 960: my $folderpath=$env{'form.folderpath'};
961: if ($folderpath eq '') {
1.484.2.67 raeburn 962: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 963: }
1.484.2.67 raeburn 964: undef($navmap);
1.484.2.19 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.484.2.7 raeburn 971: if ($supplementalflag) {
972: $tid = 2;
973: }
1.484.2.19 raeburn 974: my ($breadcrumbtrail) =
1.484.2.18 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.484.2.19 raeburn 1049: my $is_supp = 0;
1.484.2.7 raeburn 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.484.2.7 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.484.2.7 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: }
1.484.2.19 raeburn 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.484.2.7 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.484.2.7 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.484.2.7 raeburn 1127: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1128: my (@possibles,%removals,%cuts,$output);
1.484.2.30 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.484.2.30 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'});
1160: return if ($fatal);
1161:
1.484.2.30 raeburn 1162: my %curr_groups = &Apache::longroup::coursegroups();
1163:
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) {
1.484.2.85.2. (raeburn 1171:): my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1172:): my $url = $env{'docs.markedcopy_url_'.$suffix};
1173:): my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1174:): if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1175:): ($url ne '')) {
1176:): if ($url eq '/res/lib/templates/simpleproblem.problem') {
1177:): $pasteurls{$cid.'_'.$mapidx} = 1;
1178:): } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1179:): $pasteurls{$url} = 1;
1180:): } else {
1181:): $pasteurls{$cid.'_'.$url} = 1;
1182:): }
1183:): }
1.484.2.30 raeburn 1184: }
1185: }
1186:
1187: # Mark items for copying (skip any items already in user's paste buffer)
1188: my %addtoenv;
1.484.2.82 raeburn 1189:
1190: my @pathitems = split(/\&/,$env{'form.folderpath'});
1191: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.85.2. (raeburn 1192:): my $ispage = $folderconf[5];
1.484.2.82 raeburn 1193:
1.484.2.30 raeburn 1194: foreach my $item (@possibles) {
1195: my ($orderidx,$cmd) = split(/:/,$item);
1196: next if ($orderidx =~ /\D/);
1197: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1198: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1199: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1200: my %denied = &action_restrictions($coursenum,$coursedom,
1201: &LONCAPA::map::qtescape($url),
1202: $env{'form.folderpath'},\%curr_groups);
1203: next if ($denied{'copy'});
1204: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.85.2. (raeburn 1205:): if ($url eq '/res/lib/templates/simpleproblem.problem') {
1206:): next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1207:): } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1208:): next if (exists($pasteurls{$url}));
1209:): } else {
1210:): next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1211:): }
1.484.2.30 raeburn 1212: my ($suffix,$errortxt,$locknotfreed) =
1213: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1214: if ($suffix ne '') {
1215: push(@newpaste,$suffix);
1216: } else {
1217: if ($locknotfreed) {
1218: return $locknotfreed;
1219: }
1.484.2.30 raeburn 1220: }
1221: if (&is_supplemental_title($title)) {
1222: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1223: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1224: }
1225:
1226: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1227: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1228: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1229: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1230: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1231: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1232: my $prefix = $1;
1233: my $subdir =$2;
1234: if ($subdir eq '') {
1235: $subdir = $prefix;
1.484.2.7 raeburn 1236: }
1.484.2.30 raeburn 1237: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.484.2.85.2. (raeburn 1238:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1239:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.484.2.30 raeburn 1240: if (ref($hierarchy{$url}) eq 'HASH') {
1241: my ($nested,$nestednames);
1242: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1243: $nested =~ s/\&$//;
1244: $nestednames =~ s/\Q___&&&___\E$//;
1245: if ($nested ne '') {
1246: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1247: }
1248: if ($nestednames ne '') {
1249: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1250: }
1.484.2.7 raeburn 1251: }
1252: }
1.484.2.57 raeburn 1253: if ($locknotfreed) {
1254: $output = $locknotfreed;
1255: last;
1256: }
1.484.2.7 raeburn 1257: }
1.484.2.30 raeburn 1258: if (@newpaste) {
1259: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1260: }
1.484.2.7 raeburn 1261: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1262: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1263: return $output;
1.329 droeschl 1264: }
1265:
1.484.2.7 raeburn 1266: sub recurse_uploaded_maps {
1267: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1268: if (ref($hierarchy->{$url}) eq 'HASH') {
1269: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1270: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1271: my (@uploaded,@names,%shorter);
1272: for (my $i=0; $i<@maps; $i++) {
1273: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1274: if ($inner ne '') {
1275: push(@uploaded,$inner);
1276: push(@names,&escape($titles[$i]));
1277: $shorter{$maps[$i]} = $inner;
1278: }
1279: }
1280: $$nestref .= "$dir:".join(',',@uploaded).'&';
1281: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1282: foreach my $map (@maps) {
1283: if ($shorter{$map} ne '') {
1284: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1285: }
1286: }
1287: }
1288: return;
1289: }
1290:
1.329 droeschl 1291: sub print_paste_buffer {
1.484.2.7 raeburn 1292: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1293: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1294:
1.484.2.30 raeburn 1295: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1296: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1297: }
1298:
1.484.2.30 raeburn 1299: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1300: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1301: my $clipboardcount = 0;
1.484.2.7 raeburn 1302:
1.484.2.30 raeburn 1303: # Construct identifiers for current contents of user's paste buffer
1304: foreach my $suffix (@currpaste) {
1305: next if ($suffix =~ /\D/);
1306: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1307: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1308: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1309: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1310: ($url ne '')) {
1.484.2.47 raeburn 1311: $clipboardcount ++;
1.484.2.30 raeburn 1312: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.484.2.85.2. (raeburn 1313:): $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.484.2.30 raeburn 1314: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1315: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1316: $is_external = 1;
1.484.2.85.2. (raeburn 1317:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1318:): $is_exttool = 1;
1.484.2.7 raeburn 1319: }
1.484.2.30 raeburn 1320: if ($folder =~ /^supplemental/) {
1321: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1322: unless ($canpaste) {
1323: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1324: }
1.484.2.30 raeburn 1325: } else {
1326: $canpaste = 1;
1.484.2.7 raeburn 1327: }
1.484.2.30 raeburn 1328: if ($canpaste) {
1329: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1330: my $srcdom = $1;
1331: my $srcnum = $2;
1332: my $rem = $3;
1333: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1334: $othercourse = 1;
1335: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1336: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1337: } else {
1338: $canpaste = 0;
1339: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1340: }
1341: }
1.484.2.30 raeburn 1342: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1343: my $prefix = $1;
1344: $parent = $2;
1345: if ($folder !~ /^\Q$prefix\E/) {
1346: $areachange = 1;
1347: }
1348: $is_uploaded_map = 1;
1349: }
1.484.2.82 raeburn 1350: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.484.2.85.2. (raeburn 1351:): ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.484.2.76 raeburn 1352: if ($cid ne $env{'request.course.id'}) {
1353: my ($srcdom,$srcnum) = split(/_/,$cid);
1354: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.85.2. (raeburn 1355:): if (($is_exttool) && ($srcdom ne $coursedom)) {
1356:): $canpaste = 0;
1357:): $nopaste = &mt('Paste from another domain unavailable.');
1358:): } else {
1359:): $othercrs = '<br />'.&mt('(from another course)');
1360:): }
1.484.2.76 raeburn 1361: } else {
1362: $canpaste = 0;
1363: $nopaste = &mt('Paste from another course unavailable.');
1364: }
1365: }
1366: }
1367: if ($canpaste) {
1368: push(@pasteable,$suffix);
1.484.2.30 raeburn 1369: }
1370: }
1371: my $buffer;
1372: if ($is_external) {
1373: $buffer = &mt('External Resource').': '.
1374: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1375: &LONCAPA::map::qtescape($url).')';
1.484.2.85.2. (raeburn 1376:): } elsif ($is_exttool) {
1377:): $buffer = &mt('External Tool').': '.
1378:): &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.30 raeburn 1379: } else {
1380: my $icon = &Apache::loncommon::icon($extension);
1381: if ($extension eq 'sequence' &&
1382: $url =~ m{/default_\d+\.sequence$}x) {
1383: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1384: $icon .= '/navmap.folder.closed.gif';
1385: }
1.484.2.57 raeburn 1386: my $title = $env{'docs.markedcopy_title_'.$suffix};
1387: if ($title eq '') {
1388: ($title) = ($url =~ m{/([^/]+)$});
1389: }
1.484.2.30 raeburn 1390: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1391: ': '.
1392: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1393: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1394: }
1395: $pasteitems .= '<div class="LC_left_float">';
1396: my ($options,$onclick);
1397: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1398: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1399: if (($is_uploaded_map) ||
1400: ($url =~ /(bulletinboard|smppg)$/) ||
1401: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1402: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1403: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1404: }
1405: }
1406: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1407: if ($nopaste) {
1408: $pasteitems .= $nopaste;
1409: } else {
1410: if ($othercrs) {
1411: $pasteitems .= $othercrs;
1412: }
1413: if ($options) {
1414: $pasteitems .= $options;
1.484.2.7 raeburn 1415: }
1416: }
1.484.2.30 raeburn 1417: $pasteitems .= '</div>';
1418: }
1419: }
1420: if ($pasteitems eq '') {
1421: &Apache::lonnet::delenv('docs.markedcopies');
1422: }
1423: my ($pasteform,$form_start,$buttons,$form_end);
1424: if ($pasteitems) {
1425: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1426: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1427: if (@pasteable) {
1.484.2.47 raeburn 1428: my $value = &mt('Paste to current folder');
1429: if ($container eq 'page') {
1430: $value = &mt('Paste to current page');
1431: }
1432: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1433: }
1.484.2.85.2. (raeburn 1434:): $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1.484.2.47 raeburn 1435: if ($clipboardcount > 1) {
1436: $buttons .=
1437: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1438: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1439: (' 'x2).
1440: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1441: (' 'x2);
1.484.2.7 raeburn 1442: }
1.484.2.48 raeburn 1443: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1444: '</form>';
1.484.2.30 raeburn 1445: } else {
1446: $pasteitems = &mt('Clipboard is empty');
1447: }
1448: $r->print($form_start
1449: .'<fieldset>'
1450: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1451: .$pasteitems
1452: .'</fieldset>'
1453: .$form_end);
1454: }
1455:
1456: sub paste_options {
1457: my ($suffix,$is_uploaded_map,$parent) = @_;
1458: my ($copytext,$movetext);
1459: if ($is_uploaded_map) {
1460: $copytext = &mt('Copy to new folder');
1461: $movetext = &mt('Move old');
1462: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1463: $copytext = &mt('Copy to new board');
1464: $movetext = &mt('Move (not posts)');
1465: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1466: $copytext = &mt('Copy to new page');
1467: $movetext = &mt('Move');
1.484.2.7 raeburn 1468: } else {
1.484.2.30 raeburn 1469: $copytext = &mt('Copy to new file');
1470: $movetext = &mt('Move');
1471: }
1472: my $output = '<br />'.
1473: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1474: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1475: '<label>'.
1476: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1477: $copytext.'</label></span>'.(' 'x2).' '.
1478: '<span class="LC_nobreak"><label>'.
1479: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1480: $movetext.'</label></span>';
1481: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1482: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1483: '</legend><table border="0">';
1484: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1485: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1486: my $lastdir = $parent;
1487: my %depths = (
1488: $lastdir => 0,
1489: );
1490: my (%display,%deps);
1491: for (my $i=0; $i<@pastemaps; $i++) {
1492: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1493: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1494: my @subfolders = split(/,/,$subfolderstr);
1495: $deps{$lastdir} = \@subfolders;
1496: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1497: my $depth = $depths{$lastdir} + 1;
1498: my $offset = int($depth * 4);
1499: my $indent = (' ' x $offset);
1500: for (my $j=0; $j<@subfolders; $j++) {
1501: $depths{$subfolders[$j]} = $depth;
1502: $display{$subfolders[$j]} =
1503: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1504: '<td><label>'.
1505: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1506: '<label>'.
1507: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1508: &mt('Move old').'</label>'.
1509: '</td></tr>';
1510: }
1511: }
1512: &recurse_print(\$output,$parent,\%deps,\%display);
1513: $output .= '</table></fieldset>';
1.329 droeschl 1514: }
1.484.2.30 raeburn 1515: $output .= '</div>';
1516: return $output;
1.329 droeschl 1517: }
1518:
1.484.2.7 raeburn 1519: sub recurse_print {
1.484.2.30 raeburn 1520: my ($outputref,$dir,$deps,$display) = @_;
1521: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1522: if (ref($deps->{$dir}) eq 'ARRAY') {
1523: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1524: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1525: }
1526: }
1527: }
1528:
1529: sub supp_pasteable {
1530: my ($url) = @_;
1531: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1532: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1533: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1534: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.484.2.85.2. (raeburn 1535:): ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1536:): ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.484.2.7 raeburn 1537: return 1;
1538: }
1539: return;
1540: }
1541:
1542: sub paste_popup_js {
1.484.2.61 raeburn 1543: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1544: show => 'Show Options',
1545: hide => 'Hide Options',
1.484.2.61 raeburn 1546: );
1547: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1548: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1549: );
1.484.2.61 raeburn 1550: &html_escape(\%html_js_lt);
1551: &js_escape(\%html_js_lt);
1552: &js_escape(\%js_lt);
1.484.2.7 raeburn 1553: return <<"END";
1554:
1.484.2.30 raeburn 1555: function showPasteOptions(suffix) {
1556: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1557: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1558: return;
1559: }
1560:
1.484.2.30 raeburn 1561: function hidePasteOptions(suffix) {
1562: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1563: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1564: return;
1565: }
1566:
1.484.2.30 raeburn 1567: function showOptions(caller,suffix) {
1568: if (document.getElementById('pasteoptionstext_'+suffix)) {
1569: if (caller.checked) {
1.484.2.61 raeburn 1570: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1571: } else {
1572: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1573: }
1574: if (document.getElementById('pasteoptions_'+suffix)) {
1575: document.getElementById('pasteoptions_'+suffix).style.display='none';
1576: }
1577: }
1578: return;
1579: }
1.484.2.7 raeburn 1580:
1.484.2.30 raeburn 1581: function validateClipboard() {
1582: var numchk = 0;
1583: if (document.pasteform.pasting.length > 1) {
1584: for (var i=0; i<document.pasteform.pasting.length; i++) {
1585: if (document.pasteform.pasting[i].checked) {
1586: numchk ++;
1587: }
1588: }
1589: } else {
1590: if (document.pasteform.pasting.type == 'checkbox') {
1591: if (document.pasteform.pasting.checked) {
1592: numchk ++;
1593: }
1594: }
1595: }
1596: if (numchk > 0) {
1597: return true;
1598: } else {
1.484.2.61 raeburn 1599: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1600: return false;
1601: }
1.484.2.7 raeburn 1602: }
1603:
1.484.2.47 raeburn 1604: function checkClipboard() {
1605: if (document.pasteform.pasting.length > 1) {
1606: for (var i=0; i<document.pasteform.pasting.length; i++) {
1607: document.pasteform.pasting[i].checked = true;
1608: }
1609: }
1610: return;
1611: }
1612:
1613: function uncheckClipboard() {
1614: if (document.pasteform.pasting.length >1) {
1615: for (var i=0; i<document.pasteform.pasting.length; i++) {
1616: document.pasteform.pasting[i].checked = false;
1617: }
1618: }
1619: return;
1620: }
1621:
1.484.2.30 raeburn 1622: END
1623:
1624: }
1.484.2.7 raeburn 1625:
1.329 droeschl 1626: sub do_paste_from_buffer {
1.484.2.7 raeburn 1627: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1628:
1.484.2.30 raeburn 1629: # Array of items in paste buffer
1630: my (@currpaste,%pastebuffer,%allerrors);
1631: @currpaste = split(/,/,$env{'docs.markedcopies'});
1632:
1.484.2.7 raeburn 1633: # Early out if paste buffer is empty
1.484.2.30 raeburn 1634: if (@currpaste == 0) {
1.484.2.7 raeburn 1635: return ();
1.484.2.30 raeburn 1636: }
1637: map { $pastebuffer{$_} = 1; } @currpaste;
1638:
1639: # Array of items selected items to paste
1640: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1641:
1642: # Early out if nothing selected to paste
1643: if (@reqpaste == 0) {
1644: return();
1645: }
1646: my @topaste;
1647: foreach my $suffix (@reqpaste) {
1648: next if ($suffix =~ /\D/);
1649: next unless (exists($pastebuffer{$suffix}));
1650: push(@topaste,$suffix);
1.484.2.7 raeburn 1651: }
1652:
1.484.2.30 raeburn 1653: # Early out if nothing available to paste
1654: if (@topaste == 0) {
1655: return();
1.329 droeschl 1656: }
1657:
1.484.2.85.2. (raeburn 1658:): my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.484.2.82 raeburn 1659: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1660:
1.484.2.30 raeburn 1661: foreach my $suffix (@topaste) {
1662: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1663: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1664: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1665: # Supplemental content may only include certain types of content
1666: # Early out if pasted content is not supported in Supplemental area
1667: if ($folder =~ /^supplemental/) {
1668: unless (&supp_pasteable($url)) {
1669: $notinsupp{$suffix} = 1;
1670: next;
1671: }
1672: }
1673: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1674: my $srcd = $1;
1675: my $srcn = $2;
1.484.2.7 raeburn 1676: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1677: # check for mdc privilege in the course from which the resource was pasted
1678: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1679: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1680: $notincrs{$suffix} = 1;
1681: next;
1682: }
1.329 droeschl 1683: }
1.484.2.30 raeburn 1684: $srcdom{$suffix} = $srcd;
1685: $srcnum{$suffix} = $srcn;
1.484.2.85.2. (raeburn 1686:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1687:): my ($srcd,$srcn) = split(/_/,$cid);
1688:): # When paste buffer was populated using an active role in a different course
1689:): # check for mdc privilege in the course from which the resource was pasted
1690:): if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1691:): unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1692:): $notincrs{$suffix} = 1;
1693:): next;
1694:): }
1695:): }
1696:): # When buffer was populated using an active role in a different course
1697:): # disallow pasting of External Tool if course is in a different domain.
1698:): if ($srcd ne $coursedom) {
1699:): $notindom{$suffix} = 1;
1700:): next;
1701:): }
1702:): $srcdom{$suffix} = $srcd;
1703:): $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1704: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1705: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1706: my ($srcd,$srcn) = split(/_/,$cid);
1707: # When paste buffer was populated using an active role in a different course
1708: # check for mdc privilege in the course from which the resource was pasted
1709: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1710: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1711: $notincrs{$suffix} = 1;
1712: next;
1713: }
1714: }
1715: $srcdom{$suffix} = $srcd;
1716: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1717: }
1.484.2.82 raeburn 1718: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1719: push(@dopaste,$suffix);
1720: if ($url=~/\.(page|sequence)$/) {
1721: $is_map{$suffix} = 1;
1.329 droeschl 1722: }
1.484.2.30 raeburn 1723:
1724: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1725: my $oldprefix = $1;
1.484.2.19 raeburn 1726: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1727: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1728: # a folder/page or a document).
1.484.2.30 raeburn 1729: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1730: $prefixchg{$suffix} = 'docstosupp';
1731: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1732: $prefixchg{$suffix} = 'supptodocs';
1733: }
1.484.2.7 raeburn 1734:
1735: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1736: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1737: my @nested;
1738: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1739: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1740: my @deps = map { /\d+:([\d,]+$)/ } @items;
1741: foreach my $dep (@deps) {
1742: if ($dep =~ /,/) {
1743: push(@nested,split(/,/,$dep));
1744: } else {
1745: push(@nested,$dep);
1746: }
1.484.2.7 raeburn 1747: }
1.484.2.30 raeburn 1748: foreach my $item (@nested) {
1749: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1750: push(@{$marktomove{$suffix}},$type.'_'.$item);
1751: }
1.484.2.7 raeburn 1752: }
1753: }
1.329 droeschl 1754: }
1.484.2.7 raeburn 1755: }
1756:
1.484.2.30 raeburn 1757: # Early out if nothing available to paste
1758: if (@dopaste == 0) {
1759: return ();
1760: }
1761:
1762: # Populate message hash and hashes used for main content <=> supplemental content
1763: # changes
1764:
1765: %msgs = &Apache::lonlocal::texthash (
1766: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1767: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.484.2.85.2. (raeburn 1768:): notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.484.2.30 raeburn 1769: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1770: );
1771:
1772: %before = (
1773: docstosupp => {
1774: map => 'default',
1775: doc => 'docs',
1776: },
1777: supptodocs => {
1778: map => 'supplemental',
1779: doc => 'supplemental',
1780: },
1781: );
1782:
1783: %after = (
1784: docstosupp => {
1785: map => 'supplemental',
1786: doc => 'supplemental'
1787: },
1788: supptodocs => {
1789: map => 'default',
1790: doc => 'docs',
1791: },
1792: );
1793:
1794: # Retrieve information about all course maps in main content area
1795:
1796: my $allmaps = {};
1.484.2.79 raeburn 1797: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1798:
1799: # Loop over the items to paste
1800: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1801: # Maps need to be copied first
1.484.2.30 raeburn 1802: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1803: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1804: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1805: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1806: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1807: }
1808: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1809: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1810: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1811: my $oldurl = $url;
1812: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1813: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1814: my (%hierarchy,%titles);
1.484.2.79 raeburn 1815: if (($folder =~ /^default/) && (!$donechk)) {
1816: $allmaps =
1817: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1818: $env{"course.$env{'request.course.id'}.home"},
1819: $env{'request.course.id'});
1820: $donechk = 1;
1821: }
1.484.2.85.2. (raeburn 1822:): &contained_map_check($url,$folder,$coursenum,$coursedom,
1823:): \%removefrommap,\%removeparam,\%addedmaps,
1824:): \%hierarchy,\%titles,$allmaps);
1.484.2.30 raeburn 1825: if ($url=~ m{^/uploaded/}) {
1826: my $newurl;
1827: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1828: ($newurl,my $error) =
1829: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1830: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1831: \$title,$allmaps,\%newurls);
1832: if ($error) {
1833: $allerrors{$suffix} = $error;
1834: next;
1835: }
1836: if ($newurl ne '') {
1837: if ($newurl ne $url) {
1838: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1839: $newsubdir{$url} = $1;
1840: }
1841: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1842: }
1843: }
1844: }
1.484.2.30 raeburn 1845: if (($srcdom{$suffix} ne $coursedom) ||
1846: ($srcnum{$suffix} ne $coursenum) ||
1847: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1848: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1849: $coursedom,$coursenum,$srcdom{$suffix},
1850: $srcnum{$suffix},$allmaps,\%rewrites,
1851: \%retitles,\%copies,\%dbcopies,
1852: \%zombies,\%params,\%mapmoves,
1853: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1854: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1855: $mapmoves{$url} = 1;
1856: }
1857: $url = $newurl;
1858: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1859: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1860: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1861: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1862: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1863: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1864: }
1865: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1866: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1867: push(@toclear,$suffix);
1868: # if pasting published map (main content area only) check map not already in course
1869: if ($folder =~ /^default/) {
1870: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1871: $duplicate{$suffix} = 1;
1872: next;
1873: }
1.484.2.7 raeburn 1874: }
1875: }
1876: }
1.484.2.85.2. (raeburn 1877:): if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.484.2.30 raeburn 1878: my $prefix = $1;
1.484.2.76 raeburn 1879: my $fromothercrs;
1.484.2.30 raeburn 1880: #need to copy the db contents to a new one, unless this is a move.
1881: my %info = (
1882: src => $url,
1883: cdom => $coursedom,
1884: cnum => $coursenum,
1.484.2.76 raeburn 1885: );
1886: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1887: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1888: $fromothercrs = 1;
1889: $info{'cdom'} = $srcdom{$suffix};
1890: $info{'cnum'} = $srcnum{$suffix};
1891: }
1892: }
1893: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1894: my (%lockerr,$msg);
1895: my ($newurl,$result,$errtext) =
1896: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1897: if ($result eq 'ok') {
1898: $url = $newurl;
1899: $title=&mt('Copy of').' '.$title;
1900: } else {
1901: if ($prefix eq 'smppg') {
1902: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1903: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1904: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.85.2. (raeburn 1905:): } elsif ($prefix eq 'ext.tool') {
1906:): $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.484.2.30 raeburn 1907: }
1908: $results{$suffix} = $result;
1909: $msgerrs{$suffix} = $msg;
1910: $lockerrs{$suffix} = $lockerr{$prefix};
1911: next;
1912: }
1913: if ($lockerr{$prefix}) {
1914: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1915: }
1.484.2.7 raeburn 1916: }
1.484.2.30 raeburn 1917: }
1918: $title = &LONCAPA::map::qtunescape($title);
1919: my $ext='false';
1920: if ($url=~m{^http(|s)://}) { $ext='true'; }
1921: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1922: if ($folder !~ /^supplemental/) {
1923: (undef,undef,$title) =
1924: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1925: }
1926: } else {
1927: if ($folder=~/^supplemental/) {
1928: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1929: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1930: }
1931: }
1.484.2.7 raeburn 1932:
1933: # For uploaded files (excluding pages/sequences) path in copied file is changed
1934: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1935: # courses.
1936:
1.484.2.30 raeburn 1937: unless ($is_map{$suffix}) {
1938: my $newidx;
1.329 droeschl 1939: # Now insert the URL at the bottom
1.484.2.30 raeburn 1940: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1941: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1942: my $relpath = $1;
1943: if ($relpath ne '') {
1944: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1945: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1946: my $newprefix = $newloc;
1947: if ($newloc eq 'default') {
1948: $newprefix = 'docs';
1949: }
1950: if ($newdocsdir eq '') {
1951: $newdocsdir = 'default';
1952: }
1953: if (($prefixchg{$suffix}) ||
1954: ($srcdom{$suffix} ne $coursedom) ||
1955: ($srcnum{$suffix} ne $coursenum) ||
1956: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1957: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1958: $url =
1959: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1960: &Apache::lonnet::getfile($oldurl));
1961: if ($url eq '/adm/notfound.html') {
1962: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1963: next;
1964: } else {
1965: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1966: $newsubpath =~ s{/+$}{/};
1967: $docmoves{$oldurl} = $newsubpath;
1968: }
1.484.2.7 raeburn 1969: }
1970: }
1.484.2.82 raeburn 1971: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1972: my $template = $1;
1973: if ($newidx) {
1974: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1975: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1976: }
1.484.2.7 raeburn 1977: }
1.484.2.30 raeburn 1978: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1979: ':'.$ext.':normal:res';
1980: push(@LONCAPA::map::order,$newidx);
1981: # Store the result
1982: my ($errtext,$fatal) =
1983: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1984: if ($fatal) {
1985: $save_err .= $errtext;
1986: $allresult = 'fail';
1.484.2.7 raeburn 1987: }
1.329 droeschl 1988: }
1.484.2.30 raeburn 1989:
1.484.2.82 raeburn 1990: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1991: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 1992: unless ($allresult eq 'fail') {
1993: my %updated = (
1994: rewrites => \%rewrites,
1995: zombies => \%zombies,
1996: removefrommap => \%removefrommap,
1997: removeparam => \%removeparam,
1998: dbcopies => \%dbcopies,
1.484.2.82 raeburn 1999: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 2000: retitles => \%retitles,
2001: );
2002: my %info = (
2003: newsubdir => \%newsubdir,
2004: params => \%params,
2005: );
2006: if ($prefixchg{$suffix}) {
2007: $info{'before'} = $before{$prefixchg{$suffix}};
2008: $info{'after'} = $after{$prefixchg{$suffix}};
2009: }
2010: my %moves = (
2011: copies => \%copies,
2012: docmoves => \%docmoves,
2013: mapmoves => \%mapmoves,
2014: );
2015: (my $result,$msgs{$suffix},my $lockerror) =
2016: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2017: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2018: $url,'paste');
2019: $lockerrors .= $lockerror;
2020: if ($result eq 'ok') {
2021: if ($is_map{$suffix}) {
2022: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2023: $folder.'.'.$container);
2024: if ($fatal) {
2025: $allresult = 'failread';
2026: } else {
2027: if ($#LONCAPA::map::order<1) {
2028: my $idx=&LONCAPA::map::getresidx();
2029: if ($idx<=0) { $idx=1; }
2030: $LONCAPA::map::order[0]=$idx;
2031: $LONCAPA::map::resources[$idx]='';
2032: }
2033: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2034: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2035: ':'.$ext.':normal:res';
2036: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 2037:
2038: # Store the result
1.484.2.30 raeburn 2039: my ($errtext,$fatal) =
2040: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2041: if ($fatal) {
2042: $save_err .= $errtext;
2043: $allresult = 'failstore';
2044: }
2045: }
2046: }
2047: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2048: push(@toclear,$suffix);
2049: }
2050: }
1.329 droeschl 2051: }
2052: }
1.484.2.30 raeburn 2053: &clear_from_buffer(\@toclear,\@currpaste);
2054: my $msgsarray;
2055: foreach my $suffix (keys(%msgs)) {
2056: if (ref($msgs{$suffix}) eq 'ARRAY') {
2057: $msgsarray .= join(',',@{$msgs{$suffix}});
2058: }
2059: }
2060: return ($allresult,$save_err,$msgsarray,$lockerrors);
2061: }
2062:
2063: sub do_buffer_empty {
2064: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2065: if (@currpaste == 0) {
2066: return &mt('Clipboard is already empty');
2067: }
2068: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2069: if (@toclear == 0) {
2070: return &mt('Nothing selected to clear from clipboard');
2071: }
2072: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2073: if ($numdel) {
2074: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2075: } else {
2076: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 2077: }
1.484.2.30 raeburn 2078: return;
2079: }
2080:
2081: sub clear_from_buffer {
2082: my ($toclear,$currpaste) = @_;
2083: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2084: my %pastebuffer;
2085: map { $pastebuffer{$_} = 1; } @{$currpaste};
2086: my $numdel = 0;
2087: foreach my $suffix (@{$toclear}) {
2088: next if ($suffix =~ /\D/);
2089: next unless (exists($pastebuffer{$suffix}));
2090: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2091: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2092: delete($pastebuffer{$suffix});
2093: $numdel ++;
2094: }
2095: }
2096: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2097: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2098: return $numdel;
1.484.2.7 raeburn 2099: }
2100:
2101: sub get_newmap_url {
2102: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2103: $titleref,$allmaps,$newurls) = @_;
2104: my $newurl;
2105: if ($url=~ m{^/uploaded/}) {
2106: $$titleref=&mt('Copy of').' '.$$titleref;
2107: }
2108: my $now = time;
2109: my $suffix=$$.int(rand(100)).$now;
2110: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2111: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2112: my $path = $1;
2113: my $prefix = $2;
2114: my $ancestor = $3;
2115: if (length($ancestor) > 10) {
2116: $ancestor = substr($ancestor,-10,10);
2117: }
2118: my $newid;
2119: if ($prefixchg) {
2120: if ($folder =~ /^supplemental/) {
2121: $prefix =~ s/^default/supplemental/;
2122: } else {
2123: $prefix =~ s/^supplemental/default/;
2124: }
2125: }
2126: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2127: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2128: } else {
2129: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2130: }
2131: my $counter = 0;
2132: my $is_unique = &uniqueness_check($newurl);
2133: if ($folder =~ /^default/) {
2134: if ($allmaps->{$newurl}) {
2135: $is_unique = 0;
2136: }
2137: }
2138: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2139: $counter ++;
2140: $suffix ++;
2141: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2142: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2143: } else {
2144: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2145: }
2146: $is_unique = &uniqueness_check($newurl);
2147: }
2148: if ($is_unique) {
2149: $newurls->{$newurl} = 1;
2150: } else {
2151: if ($url=~/\.page$/) {
2152: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2153: } else {
2154: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2155: }
2156: }
2157: }
2158: return ($newurl);
2159: }
2160:
2161: sub dbcopy {
1.484.2.26 raeburn 2162: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2163: my ($url,$result,$errtext);
2164: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2165: $url = $dbref->{'src'};
1.484.2.85.2. (raeburn 2166:): if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.484.2.26 raeburn 2167: my $prefix = $1;
1.484.2.85.2. (raeburn 2168:): if ($prefix eq 'ext.tool') {
2169:): $prefix = 'exttool';
2170:): }
1.484.2.26 raeburn 2171: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2172: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2173: my $db_name;
2174: my $marker = (split(m{/},$url))[4];
2175: $marker=~s/\D//g;
2176: if ($dbref->{'src'} =~ m{/smppg$}) {
2177: $db_name =
2178: &Apache::lonsimplepage::get_db_name($url,$marker,
2179: $dbref->{'cdom'},
2180: $dbref->{'cnum'});
1.484.2.85.2. (raeburn 2181:): } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2182:): $db_name = 'exttool_'.$marker;
1.484.2.26 raeburn 2183: } else {
2184: $db_name = 'bulletinpage_'.$marker;
2185: }
2186: my ($suffix,$freedlock,$error) =
2187: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2188: $coursedom,$coursenum,
2189: 'concat');
2190: if (!$suffix) {
2191: if ($prefix eq 'smppg') {
2192: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.484.2.85.2. (raeburn 2193:): } elsif ($prefix eq 'exttool') {
2194:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.484.2.26 raeburn 2195: } else {
1.484.2.42 raeburn 2196: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2197: }
2198: if ($error) {
2199: $errtext .= '<br />'.$error;
2200: }
2201: } else {
2202: #need to copy the db contents to a new one.
2203: my %contents=&Apache::lonnet::dump($db_name,
2204: $dbref->{'cdom'},
2205: $dbref->{'cnum'});
2206: if (exists($contents{'uploaded.photourl'})) {
2207: my $photo = $contents{'uploaded.photourl'};
2208: my ($subdir,$fname) =
2209: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2210: my $newphoto;
2211: if ($fname ne '') {
2212: my $content = &Apache::lonnet::getfile($photo);
2213: unless ($content eq '-1') {
2214: $env{'form.'.$suffix.'.photourl'} = $content;
2215: $newphoto =
2216: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2217: delete($env{'form.'.$suffix.'.photourl'});
2218: }
2219: }
2220: if ($newphoto =~ m{^/uploaded/}) {
2221: $contents{'uploaded.photourl'} = $newphoto;
2222: }
2223: }
2224: $db_name =~ s{_\d*$ }{_$suffix}x;
2225: $result=&Apache::lonnet::put($db_name,\%contents,
2226: $coursedom,$coursenum);
2227: if ($result eq 'ok') {
1.484.2.85.2. (raeburn 2228:): $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.484.2.26 raeburn 2229: }
2230: }
2231: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2232: $lockerrorsref->{$prefix} =
2233: '<div class="LC_error">'.
2234: &mt('There was a problem removing a lockfile.');
2235: if ($prefix eq 'smppg') {
2236: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2237: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.85.2. (raeburn 2238:): } elsif ($prefix eq 'exttool') {
2239:): $lockerrorsref->{$prefix} .=
2240:): ' '.&mt('This will prevent addition of more external tools to this course.');
1.484.2.26 raeburn 2241: } else {
1.484.2.42 raeburn 2242: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2243: }
1.484.2.38 raeburn 2244: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2245: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2246: '</div>';
1.484.2.26 raeburn 2247: }
2248: }
2249: } elsif ($url =~ m{/syllabus$}) {
2250: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2251: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2252: if (($dbref->{'cdom'} ne $coursedom) ||
2253: ($dbref->{'cnum'} ne $coursenum)) {
2254: my %contents=&Apache::lonnet::dump('syllabus',
2255: $dbref->{'cdom'},
2256: $dbref->{'cnum'});
2257: $result=&Apache::lonnet::put('syllabus',\%contents,
2258: $coursedom,$coursenum);
2259: }
2260: }
1.484.2.7 raeburn 2261: }
2262: }
1.484.2.26 raeburn 2263: return ($url,$result,$errtext);
1.329 droeschl 2264: }
2265:
1.484.2.82 raeburn 2266: sub copy_templated_files {
2267: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2268: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2269: my $srccontainer = 'sequence';
2270: if ($srcwaspage) {
2271: $srccontainer = 'page';
2272: }
2273: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2274: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2275: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2276: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2277: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2278: $template.'.problem';
2279: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2280: if ($template eq 'simpleproblem') {
2281: $srcprefix .= '.0.';
2282: my $weightprefix = $newprefix;
2283: $newprefix .= '.0.';
2284: my @simpleprobqtypes = qw(radio option string essay numerical);
2285: my $qtype=$srcparms{$srcprefix.'questiontype'};
2286: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2287: my %newdata = (
2288: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2289: );
1.484.2.82 raeburn 2290: foreach my $type (@simpleprobqtypes) {
2291: if ($type eq $qtype) {
2292: $newdata{"$weightprefix.$type.weight"}=1;
2293: } else {
2294: $newdata{"$weightprefix.$type.weight"}=0;
2295: }
2296: }
2297: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2298: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2299: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2300: if ($qtype eq 'numerical') {
2301: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2302: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2303: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2304: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2305: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2306: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2307: unless (defined($maxfoils)) { $maxfoils=10; }
2308: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2309: if ($maxfoils<=0) { $maxfoils=10; }
2310: my $randomize=$srcparms{$srcprefix.'randomize'};
2311: unless (defined($randomize)) { $randomize='yes'; }
2312: unless ($randomize eq 'no') { $randomize='yes'; }
2313: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2314: $newdata{$newprefix.'randomize'} = $randomize;
2315: if ($qtype eq 'option') {
2316: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2317: }
2318: for (my $i=1; $i<=10; $i++) {
2319: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2320: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2321: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2322: }
2323:
2324: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2325: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2326: unless (defined($maxfoils)) { $maxfoils=10; }
2327: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2328: if ($maxfoils<=0) { $maxfoils=10; }
2329: my $randomize=$srcparms{$srcprefix.'randomize'};
2330: unless (defined($randomize)) { $randomize='yes'; }
2331: unless ($randomize eq 'no') { $randomize='yes'; }
2332: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2333: $newdata{$newprefix.'randomize'} = $randomize;
2334: if ($qtype eq 'option') {
2335: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2336: }
2337: for (my $i=1; $i<=10; $i++) {
2338: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2339: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2340: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2341: }
2342: } elsif ($qtype eq 'string') {
2343: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2344: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2345: }
2346: if (keys(%newdata)) {
2347: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2348: $coursenum);
2349: if ($putres eq 'ok') {
2350: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2351: }
2352: }
2353: }
2354: }
2355: }
2356:
1.329 droeschl 2357: sub uniqueness_check {
2358: my ($newurl) = @_;
2359: my $unique = 1;
2360: foreach my $res (@LONCAPA::map::order) {
2361: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2362: $url=&LONCAPA::map::qtescape($url);
2363: if ($newurl eq $url) {
2364: $unique = 0;
1.344 bisitz 2365: last;
1.329 droeschl 2366: }
2367: }
2368: return $unique;
2369: }
2370:
1.484.2.7 raeburn 2371: sub contained_map_check {
1.484.2.85.2. (raeburn 2372:): my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2373:): $hierarchy,$titles,$allmaps) = @_;
1.484.2.7 raeburn 2374: my $content = &Apache::lonnet::getfile($url);
2375: unless ($content eq '-1') {
2376: my $parser = HTML::TokeParser->new(\$content);
2377: $parser->attr_encoded(1);
2378: while (my $token = $parser->get_token) {
2379: next if ($token->[0] ne 'S');
2380: if ($token->[1] eq 'resource') {
2381: next if ($token->[2]->{'type'} eq 'zombie');
2382: my $ressrc = $token->[2]->{'src'};
2383: if ($folder =~ /^supplemental/) {
2384: unless (&supp_pasteable($ressrc)) {
2385: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2386: next;
2387: }
2388: }
2389: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2390: if ($1 eq 'uploaded') {
2391: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2392: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2393: } else {
2394: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2395: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2396: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2397: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2398: } else {
2399: $addedmaps->{$ressrc} = [$url];
2400: }
2401: }
1.484.2.85.2. (raeburn 2402:): &contained_map_check($ressrc,$folder,$coursenum,$coursedom,
2403:): $removefrommap,$removeparam,
1.484.2.7 raeburn 2404: $addedmaps,$hierarchy,$titles,$allmaps);
2405: }
2406: } elsif ($token->[1] eq 'param') {
2407: if ($folder =~ /^supplemental/) {
2408: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2409: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2410: } else {
1.484.2.19 raeburn 2411: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2412: }
2413: }
2414: }
2415: }
2416: }
2417: return;
2418: }
2419:
2420: sub url_paste_fixups {
1.484.2.26 raeburn 2421: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2422: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2423: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2424: my $checktitle;
2425: if (($prefixchg) &&
2426: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2427: $checktitle = 1;
2428: }
2429: my $skip;
2430: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2431: my $mapid = $1.$2;
2432: if ($tomove->{$mapid}) {
2433: $skip = 1;
2434: }
2435: }
2436: my $file = &Apache::lonnet::getfile($oldurl);
2437: return if ($file eq '-1');
2438: my $parser = HTML::TokeParser->new(\$file);
2439: $parser->attr_encoded(1);
2440: my $changed = 0;
2441: while (my $token = $parser->get_token) {
2442: next if ($token->[0] ne 'S');
2443: if ($token->[1] eq 'resource') {
2444: my $ressrc = $token->[2]->{'src'};
2445: next if ($ressrc eq '');
2446: my $id = $token->[2]->{'id'};
2447: my $title = $token->[2]->{'title'};
2448: if ($checktitle) {
2449: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2450: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2451: }
2452: }
2453: next if ($token->[2]->{'type'} eq 'external');
2454: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2455: next if ($skip);
1.484.2.25 raeburn 2456: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2457: $changed = 1;
2458: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2459: my $srcdom = $1;
2460: my $srcnum = $2;
2461: my $rem = $3;
2462: my $newurl;
2463: my $mapname;
2464: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2465: my $prefix = $1;
2466: $mapname = $prefix.$2;
2467: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2468: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2469: $srcdom,$srcnum,$allmaps,$rewrites,
2470: $retitles,$copies,$dbcopies,$zombies,
2471: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2472: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2473: next;
2474: } else {
2475: ($newurl,my $error) =
2476: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2477: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2478: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2479: $newsubdir->{$ressrc} = $1;
2480: }
2481: if ($error) {
2482: next;
2483: }
2484: }
2485: }
2486: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2487: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2488:
1.484.2.7 raeburn 2489: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2490: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2491: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2492: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2493: $cnum,$srcdom,$srcnum,$allmaps,
2494: $rewrites,$retitles,$copies,$dbcopies,
2495: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2496: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2497: $mapmoves->{$ressrc} = 1;
2498: }
2499: $changed = 1;
2500: } else {
1.484.2.25 raeburn 2501: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2502: $copies->{$oldurl}{$ressrc} = $id;
2503: $changed = 1;
2504: }
2505: }
1.484.2.26 raeburn 2506: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2507: next if ($skip);
1.484.2.7 raeburn 2508: my $srcdom = $1;
2509: my $srcnum = $2;
2510: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2511: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2512: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2513: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2514: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2515: $changed = 1;
2516: }
2517: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2518: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2519: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2520: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2521: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2522: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2523: $changed = 1;
2524: }
1.484.2.82 raeburn 2525: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2526: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2527: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2528: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2529: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2530: }
1.484.2.7 raeburn 2531: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2532: next if ($skip);
2533: my $srcdom = $1;
2534: my $srcnum = $2;
2535: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2536: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2537: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2538: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2539: $changed = 1;
2540: }
2541: }
2542: } elsif ($token->[1] eq 'param') {
2543: next if ($skip);
1.484.2.19 raeburn 2544: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2545: if ($to ne '') {
2546: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2547: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2548: } else {
2549: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2550: }
2551: }
2552: }
2553: }
2554: return $changed;
2555: }
2556:
2557: sub apply_fixups {
1.484.2.23 raeburn 2558: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2559: $oldurl,$url,$caller) = @_;
2560: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2561: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2562: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2563: if (ref($updated) eq 'HASH') {
2564: if (ref($updated->{'rewrites'}) eq 'HASH') {
2565: %rewrites = %{$updated->{'rewrites'}};
2566: }
2567: if (ref($updated->{'zombies'}) eq 'HASH') {
2568: %zombies = %{$updated->{'zombies'}};
2569: }
2570: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2571: %removefrommap = %{$updated->{'removefrommap'}};
2572: }
2573: if (ref($updated->{'removeparam'}) eq 'HASH') {
2574: %removeparam = %{$updated->{'removeparam'}};
2575: }
2576: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2577: %dbcopies = %{$updated->{'dbcopies'}};
2578: }
2579: if (ref($updated->{'retitles'}) eq 'HASH') {
2580: %retitles = %{$updated->{'retitles'}};
2581: }
1.484.2.82 raeburn 2582: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2583: %resdatacopy = %{$updated->{'resdatacopy'}};
2584: }
1.484.2.23 raeburn 2585: }
2586: if (ref($info) eq 'HASH') {
2587: if (ref($info->{'newsubdir'}) eq 'HASH') {
2588: %newsubdir = %{$info->{'newsubdir'}};
2589: }
2590: if (ref($info->{'params'}) eq 'HASH') {
2591: %params = %{$info->{'params'}};
2592: }
2593: if (ref($info->{'before'}) eq 'HASH') {
2594: %before = %{$info->{'before'}};
2595: }
2596: if (ref($info->{'after'}) eq 'HASH') {
2597: %after = %{$info->{'after'}};
2598: }
2599: }
2600: if (ref($moves) eq 'HASH') {
2601: if (ref($moves->{'copies'}) eq 'HASH') {
2602: %copies = %{$moves->{'copies'}};
2603: }
2604: if (ref($moves->{'docmoves'}) eq 'HASH') {
2605: %docmoves = %{$moves->{'docmoves'}};
2606: }
2607: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2608: %mapmoves = %{$moves->{'mapmoves'}};
2609: }
2610: }
2611: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2612: my @allcopies;
1.484.2.23 raeburn 2613: if (exists($copies{$key})) {
2614: if (ref($copies{$key}) eq 'HASH') {
2615: my %added;
2616: foreach my $innerkey (keys(%{$copies{$key}})) {
2617: if (($innerkey ne '') && (!$added{$innerkey})) {
2618: push(@allcopies,$innerkey);
2619: $added{$innerkey} = 1;
2620: }
1.484.2.7 raeburn 2621: }
1.484.2.23 raeburn 2622: undef(%added);
1.484.2.7 raeburn 2623: }
2624: }
2625: if ($key eq $oldurl) {
1.484.2.23 raeburn 2626: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2627: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2628: push(@allcopies,$oldurl);
2629: }
2630: }
2631: }
2632: if (@allcopies > 0) {
2633: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2634: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2635: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2636: if ($fname ne '') {
2637: my $content = &Apache::lonnet::getfile($item);
2638: unless ($content eq '-1') {
2639: my $storefn;
1.484.2.23 raeburn 2640: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2641: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2642: } else {
2643: $storefn = $relpath;
2644: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2645: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2646: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2647: }
1.484.2.23 raeburn 2648: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2649: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2650: }
2651: }
2652: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2653: my $copyurl =
1.484.2.7 raeburn 2654: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2655: $storefn.$fname,$content);
2656: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2657: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2658: return &mt('Paste failed: an error occurred copying the file.');
2659: } elsif (ref($errors) eq 'HASH') {
2660: $errors->{$item} = 1;
2661: }
2662: }
2663: }
2664: }
2665: }
2666: }
2667: }
1.484.2.23 raeburn 2668: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2669: my $storefn=$key;
2670: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2671: if ($prefixchg && $before{'map'} && $after{'map'}) {
2672: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2673: }
1.484.2.23 raeburn 2674: if ($newsubdir{$key}) {
2675: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2676: }
2677: my $mapcontent = &Apache::lonnet::getfile($key);
2678: if ($mapcontent eq '-1') {
2679: if (ref($errors) eq 'HASH') {
2680: $errors->{$key} = 1;
2681: }
2682: } else {
2683: my $newmap =
2684: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2685: $mapcontent);
2686: if ($newmap eq '/adm/notfound.html') {
2687: if (ref($errors) eq 'HASH') {
2688: $errors->{$key} = 1;
2689: }
2690: }
2691: }
2692: }
2693: my %updates;
2694: if ($is_map) {
1.484.2.23 raeburn 2695: if (ref($updated) eq 'HASH') {
2696: foreach my $type (keys(%{$updated})) {
2697: if (ref($updated->{$type}) eq 'HASH') {
2698: foreach my $key (keys(%{$updated->{$type}})) {
2699: $updates{$key} = 1;
2700: }
2701: }
2702: }
1.484.2.7 raeburn 2703: }
2704: foreach my $key (keys(%updates)) {
2705: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2706: if (ref($rewrites{$key}) eq 'HASH') {
2707: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2708: }
1.484.2.23 raeburn 2709: if (ref($retitles{$key}) eq 'HASH') {
2710: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2711: }
1.484.2.23 raeburn 2712: if (ref($removefrommap{$key}) eq 'HASH') {
2713: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2714: }
1.484.2.23 raeburn 2715: if (ref($removeparam{$key}) eq 'HASH') {
2716: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2717: }
1.484.2.23 raeburn 2718: if (ref($zombies{$key}) eq 'HASH') {
2719: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2720: }
1.484.2.23 raeburn 2721: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2722: foreach my $idx (keys(%{$dbcopies{$key}})) {
2723: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2724: my ($newurl,$result,$errtext) =
2725: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2726: if ($result eq 'ok') {
2727: $newdb{$idx} = $newurl;
2728: } elsif (ref($errors) eq 'HASH') {
2729: $errors->{$key} = 1;
2730: }
2731: push(@msgs,$errtext);
2732: }
1.484.2.7 raeburn 2733: }
2734: }
1.484.2.82 raeburn 2735: if (ref($resdatacopy{$key}) eq 'HASH') {
2736: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2737: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2738: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2739: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2740: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2741: my $template = $1;
2742: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2743: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2744: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2745: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2746: unless ($gotnewmapname) {
2747: ($newmapname) = ($key =~ m{/([^/]+)$});
2748: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2749: if ($newsubdir{$key}) {
2750: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2751: }
2752: $gotnewmapname = 1;
2753: }
2754: my $srcmapinfo = $srcfolder.':'.$idx;
2755: if ($srccontainer eq 'page') {
2756: $srcmapinfo .= ':1';
2757: }
2758: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2759: $cnum,$template,$idx,$newmapname);
2760: }
2761: }
2762: }
2763: }
2764: }
1.484.2.23 raeburn 2765: if (ref($params{$key}) eq 'HASH') {
2766: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2767: }
2768: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2769: if ($fatal) {
1.484.2.26 raeburn 2770: return ($errtext);
1.484.2.7 raeburn 2771: }
2772: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2773: if (defined($LONCAPA::map::zombies[$i])) {
2774: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2775: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2776: undef($LONCAPA::map::zombies[$i]);
2777: }
2778: }
2779: }
1.484.2.77 raeburn 2780: my $total = scalar(@LONCAPA::map::order) - 1;
2781: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2782: my $idx = $LONCAPA::map::order[$i];
2783: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2784: my $changed;
1.484.2.23 raeburn 2785: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2786: if ((exists($toremove{$idx})) &&
2787: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2788: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2789: if (ref($currparam{$idx}) eq 'ARRAY') {
2790: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2791: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2792: }
2793: }
2794: next;
2795: }
2796: my $origsrc = $src;
1.484.2.25 raeburn 2797: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2798: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2799: $changed = 1;
2800: }
2801: }
1.484.2.25 raeburn 2802: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2803: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2804: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2805: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2806: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2807: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2808: } else {
1.484.2.23 raeburn 2809: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2810: }
2811: }
1.484.2.25 raeburn 2812: if ($origsrc =~ /\.(page|sequence)$/) {
2813: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2814: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2815: }
1.484.2.25 raeburn 2816: } elsif ($newsubdir{$key}) {
2817: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2818: }
2819: }
2820: $changed = 1;
1.484.2.26 raeburn 2821: } elsif ($newdb{$idx} ne '') {
2822: $src = $newdb{$idx};
1.484.2.7 raeburn 2823: $changed = 1;
2824: }
2825: if ($changed) {
1.484.2.30 raeburn 2826: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2827: }
2828: }
2829: }
2830: foreach my $idx (keys(%remparam)) {
2831: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2832: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2833: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2834: }
2835: }
2836: }
1.484.2.26 raeburn 2837: if (values(%lockerrors) > 0) {
2838: $lockmsg = join('<br />',values(%lockerrors));
2839: }
1.484.2.7 raeburn 2840: my $storefn;
2841: if ($key eq $oldurl) {
2842: $storefn = $url;
2843: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2844: } else {
2845: $storefn = $key;
2846: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2847: if ($prefixchg && $before{'map'} && $after{'map'}) {
2848: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2849: }
1.484.2.23 raeburn 2850: if ($newsubdir{$key}) {
2851: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2852: }
2853: }
2854: my $report;
2855: if ($folder !~ /^supplemental/) {
2856: $report = 1;
2857: }
1.484.2.20 raeburn 2858: (my $outtext,$errtext) =
1.484.2.7 raeburn 2859: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2860: if ($errtext) {
1.484.2.23 raeburn 2861: if ($caller eq 'paste') {
1.484.2.26 raeburn 2862: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2863: }
1.484.2.7 raeburn 2864: }
2865: }
2866: }
1.484.2.26 raeburn 2867: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2868: }
2869:
2870: sub copy_dependencies {
2871: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2872: my $content;
2873: if (ref($contentref)) {
2874: $content = $$contentref;
2875: } else {
2876: $content = &Apache::lonnet::getfile($item);
2877: }
2878: unless ($content eq '-1') {
2879: my $mm = new File::MMagic;
2880: my $mimetype = $mm->checktype_contents($content);
2881: if ($mimetype eq 'text/html') {
2882: my (%allfiles,%codebase,$state);
2883: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2884: if ($res eq 'ok') {
2885: my ($numexisting,$numpathchanges,$existing);
2886: (undef,$numexisting,$numpathchanges,$existing) =
2887: &Apache::loncommon::ask_for_embedded_content(
2888: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2889: {'error_on_invalid_names' => 1,
2890: 'ignore_remote_references' => 1,
2891: 'docs_url' => $item,
2892: 'context' => 'paste'});
2893: if ($numexisting > 0) {
2894: if (ref($existing) eq 'HASH') {
2895: foreach my $dep (keys(%{$existing})) {
2896: my $depfile = $dep;
2897: unless ($depfile =~ m{^\Q$relpath\E}) {
2898: $depfile = $relpath.$dep;
2899: }
2900: my $depcontent = &Apache::lonnet::getfile($depfile);
2901: unless ($depcontent eq '-1') {
2902: my $storedep = $dep;
2903: $storedep =~ s{^\Q$relpath\E}{};
2904: my $dep_url =
2905: &Apache::lonclonecourse::writefile(
2906: $env{'request.course.id'},
2907: $storefn.$storedep,$depcontent);
2908: if ($dep_url eq '/adm/notfound.html') {
2909: if (ref($errors) eq 'HASH') {
2910: $errors->{$depfile} = 1;
2911: }
2912: } else {
2913: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2914: }
2915: }
2916: }
2917: }
2918: }
2919: }
2920: }
2921: }
2922: return;
2923: }
2924:
1.329 droeschl 2925: my %parameter_type = ( 'randompick' => 'int_pos',
2926: 'hiddenresource' => 'string_yesno',
2927: 'encrypturl' => 'string_yesno',
2928: 'randomorder' => 'string_yesno',);
2929: my $valid_parameters_re = join('|',keys(%parameter_type));
2930: # set parameters
2931: sub update_parameter {
1.484.2.29 raeburn 2932: if ($env{'form.changeparms'} eq 'all') {
2933: my (@allidx,@allmapidx,%allchecked,%currchecked);
2934: %allchecked = (
2935: 'hiddenresource' => {},
2936: 'encrypturl' => {},
2937: 'randompick' => {},
2938: 'randomorder' => {},
2939: );
2940: foreach my $which (keys(%allchecked)) {
2941: $env{'form.all'.$which} =~ s/,$//;
2942: if ($which eq 'randompick') {
2943: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2944: my ($res,$value) = split(/:/,$item);
2945: if ($value =~ /^\d+$/) {
2946: $allchecked{$which}{$res} = $value;
2947: }
2948: }
2949: } else {
1.484.2.30 raeburn 2950: if ($env{'form.all'.$which}) {
2951: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2952: }
1.484.2.29 raeburn 2953: }
2954: }
2955: my $haschanges = 0;
2956: foreach my $res (@LONCAPA::map::order) {
2957: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2958: $name=&LONCAPA::map::qtescape($name);
2959: $url=&LONCAPA::map::qtescape($url);
2960: next unless ($name && $url);
2961: my $is_map;
2962: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2963: $is_map = 1;
2964: }
2965: foreach my $which (keys(%allchecked)) {
2966: if (($which eq 'randompick' || $which eq 'randomorder')) {
2967: next if (!$is_map);
2968: }
2969: my $oldvalue = 0;
2970: my $newvalue = 0;
2971: if ($allchecked{$which}{$res}) {
2972: $newvalue = $allchecked{$which}{$res};
2973: }
2974: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2975: if ($which eq 'randompick') {
2976: if ($current =~ /^(\d+)$/) {
2977: $oldvalue = $1;
2978: }
2979: } else {
2980: if ($current =~ /^yes$/i) {
2981: $oldvalue = 1;
2982: }
2983: }
2984: if ($oldvalue ne $newvalue) {
2985: $haschanges = 1;
2986: if ($newvalue) {
2987: my $storeval = 'yes';
2988: if ($which eq 'randompick') {
2989: $storeval = $newvalue;
2990: }
2991: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2992: $storeval,
2993: $parameter_type{$which});
2994: &remember_parms($res,$which,'set',$storeval);
2995: } elsif ($oldvalue) {
2996: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2997: &remember_parms($res,$which,'del');
2998: }
2999: }
3000: }
3001: }
3002: return $haschanges;
1.329 droeschl 3003: } else {
1.484.2.59 raeburn 3004: my $haschanges = 0;
3005: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 3006:
1.484.2.29 raeburn 3007: my $which = $env{'form.changeparms'};
3008: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 3009: my $oldvalue = 0;
3010: my $newvalue = 0;
3011: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3012: if ($which eq 'randompick') {
3013: if ($current =~ /^(\d+)$/) {
3014: $oldvalue = $1;
3015: }
3016: } elsif ($current =~ /^yes$/i) {
3017: $oldvalue = 1;
3018: }
1.484.2.29 raeburn 3019: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 3020: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3021: : 1;
1.484.2.29 raeburn 3022: }
1.484.2.59 raeburn 3023: if ($oldvalue ne $newvalue) {
3024: $haschanges = 1;
3025: if ($newvalue) {
3026: my $storeval = 'yes';
3027: if ($which eq 'randompick') {
3028: $storeval = $newvalue;
3029: }
3030: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3031: $parameter_type{$which});
3032: &remember_parms($idx,$which,'set',$storeval);
3033: } else {
3034: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3035: &remember_parms($idx,$which,'del');
3036: }
3037: }
3038: return $haschanges;
1.329 droeschl 3039: }
1.484.2.59 raeburn 3040: return;
1.329 droeschl 3041: }
3042:
3043: sub handle_edit_cmd {
3044: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 3045: if ($env{'form.cmd'} eq '') {
3046: return 0;
3047: }
1.329 droeschl 3048: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3049:
3050: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3051: my ($title, $url, @rrest) = split(':', $ratstr);
3052:
1.484.2.30 raeburn 3053: if ($cmd eq 'remove') {
1.329 droeschl 3054: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3055: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3056: &Apache::lonnet::removeuploadedurl($url);
3057: } else {
3058: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3059: }
3060: splice(@LONCAPA::map::order, $idx, 1);
3061:
3062: } elsif ($cmd eq 'cut') {
3063: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3064: splice(@LONCAPA::map::order, $idx, 1);
3065:
1.344 bisitz 3066: } elsif ($cmd eq 'up'
1.329 droeschl 3067: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3068: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3069:
3070: } elsif ($cmd eq 'down'
3071: && defined($LONCAPA::map::order[$idx+1])) {
3072: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3073:
3074: } elsif ($cmd eq 'rename') {
3075: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3076: if ($comment=~/\S/) {
3077: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3078: $comment.':'.join(':', $url, @rrest);
3079: }
3080: # Devalidate title cache
3081: my $renamed_url=&LONCAPA::map::qtescape($url);
3082: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 3083:
1.329 droeschl 3084: } else {
3085: return 0;
3086: }
3087: return 1;
3088: }
3089:
3090: sub editor {
1.458 raeburn 3091: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.85.2. (raeburn 3092:): $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3093:): $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 3094: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3095: if ($allowed) {
3096: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3097: $is_random_order,$container) =
3098: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3099: $r->print($breadcrumbtrail);
3100: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3101: $container = 'page';
3102: } else {
3103: $container = 'sequence';
3104: }
1.484 raeburn 3105:
1.484.2.21 raeburn 3106: my $jumpto;
3107:
3108: unless ($supplementalflag) {
1.484.2.32 raeburn 3109: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 3110: }
1.484 raeburn 3111:
3112: unless ($allowed) {
3113: $randompick = -1;
3114: }
3115:
1.484.2.67 raeburn 3116: my ($errtext,$fatal);
3117: if (($folder eq '') && (!$supplementalflag)) {
3118: if (@LONCAPA::map::order) {
3119: undef(@LONCAPA::map::order);
3120: undef(@LONCAPA::map::resources);
3121: undef(@LONCAPA::map::resparms);
3122: undef(@LONCAPA::map::zombies);
3123: }
3124: $folder = 'default';
3125: $container = 'sequence';
3126: } else {
3127: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3128: $folder.'.'.$container);
3129: return $errtext if ($fatal);
3130: }
1.329 droeschl 3131:
3132: if ($#LONCAPA::map::order<1) {
3133: my $idx=&LONCAPA::map::getresidx();
3134: if ($idx<=0) { $idx=1; }
3135: $LONCAPA::map::order[0]=$idx;
3136: $LONCAPA::map::resources[$idx]='';
3137: }
1.364 bisitz 3138:
1.329 droeschl 3139: # ------------------------------------------------------------ Process commands
3140:
3141: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 3142: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3143: # set parameters and change order
3144: &snapshotbefore();
3145:
3146: if (&update_parameter()) {
1.484.2.59 raeburn 3147: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3148: return $errtext if ($fatal);
3149: }
3150:
3151: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3152: # change order
3153: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3154: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3155:
3156: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3157: return $errtext if ($fatal);
3158: }
1.364 bisitz 3159:
1.329 droeschl 3160: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3161: my %paste_errors;
1.484.2.26 raeburn 3162: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3163: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3164: \%paste_errors);
1.484.2.30 raeburn 3165: if (ref($pastemsgarray) eq 'ARRAY') {
3166: if (@{$pastemsgarray} > 0) {
3167: $r->print('<p class="LC_info">'.
3168: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3169: '</p>');
3170: }
1.484.2.30 raeburn 3171: }
3172: if ($lockerror) {
3173: $r->print('<p class="LC_error">'.
3174: $lockerror.
3175: '</p>');
3176: }
3177: if ($save_error ne '') {
3178: return $save_error;
3179: }
3180: if ($paste_res) {
3181: my %errortext = &Apache::lonlocal::texthash (
3182: fail => 'Storage of folder contents failed',
3183: failread => 'Reading folder contents failed',
3184: failstore => 'Storage of folder contents failed',
3185: );
3186: if ($errortext{$paste_res}) {
3187: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3188: }
1.329 droeschl 3189: }
1.484.2.7 raeburn 3190: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3191: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3192: &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".
3193: '<ul>'."\n");
3194: foreach my $key (sort(keys(%paste_errors))) {
3195: $r->print('<li>'.$key.'</li>'."\n");
3196: }
3197: $r->print('</ul></p>'."\n");
3198: }
1.484.2.30 raeburn 3199: } elsif ($env{'form.clearmarked'}) {
3200: my $output = &do_buffer_empty();
3201: if ($output) {
3202: $r->print('<p class="LC_info">'.$output.'</p>');
3203: }
3204: }
1.329 droeschl 3205:
3206: $r->print($upload_output);
3207:
1.484.2.30 raeburn 3208: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3209: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3210: my $contentchg;
1.484.2.58 raeburn 3211: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3212: $contentchg = 1;
3213: }
3214: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3215: return $errtext if ($fatal);
3216: }
1.484.2.30 raeburn 3217:
3218: # Cut, copy and/or remove multiple resources
3219: if ($env{'form.multichange'}) {
3220: my %allchecked = (
3221: cut => {},
3222: remove => {},
3223: );
3224: my $needsupdate;
3225: foreach my $which (keys(%allchecked)) {
3226: $env{'form.multi'.$which} =~ s/,$//;
3227: if ($env{'form.multi'.$which}) {
3228: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3229: if (ref($allchecked{$which}) eq 'HASH') {
3230: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3231: }
3232: }
3233: }
3234: if ($needsupdate) {
3235: my $haschanges = 0;
3236: my %curr_groups = &Apache::longroup::coursegroups();
3237: my $total = scalar(@LONCAPA::map::order) - 1;
3238: for (my $i=$total; $i>=0; $i--) {
3239: my $res = $LONCAPA::map::order[$i];
3240: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3241: $name=&LONCAPA::map::qtescape($name);
3242: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3243: next unless $url;
1.484.2.30 raeburn 3244: my %denied =
3245: &action_restrictions($coursenum,$coursedom,$url,
3246: $env{'form.folderpath'},\%curr_groups);
3247: foreach my $which (keys(%allchecked)) {
3248: next if ($denied{$which});
3249: next unless ($allchecked{$which}{$res});
3250: if ($which eq 'remove') {
3251: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3252: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3253: &Apache::lonnet::removeuploadedurl($url);
3254: } else {
3255: &LONCAPA::map::makezombie($res);
3256: }
3257: splice(@LONCAPA::map::order,$i,1);
3258: $haschanges ++;
3259: } elsif ($which eq 'cut') {
3260: &LONCAPA::map::makezombie($res);
3261: splice(@LONCAPA::map::order,$i,1);
3262: $haschanges ++;
3263: }
3264: }
3265: }
3266: if ($haschanges) {
3267: ($errtext,$fatal) =
3268: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3269: return $errtext if ($fatal);
3270: }
3271: }
3272: }
3273:
1.329 droeschl 3274: # Group import/search
3275: if ($env{'form.importdetail'}) {
3276: my @imports;
3277: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3278: if (defined($item)) {
3279: my ($name,$url,$residx)=
1.484.2.26 raeburn 3280: map { &unescape($_); } split(/\=/,$item);
3281: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3282: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3283: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3284: if ($locknotfreed) {
3285: $r->print($locknotfreed);
3286: }
3287: if ($suffix) {
1.484.2.19 raeburn 3288: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3289: } else {
3290: return $errortxt;
3291: }
1.484.2.26 raeburn 3292: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3293: my $type = $1;
3294: my ($suffix,$errortxt,$locknotfreed) =
3295: &new_timebased_suffix($coursedom,$coursenum,$type);
3296: if ($locknotfreed) {
3297: $r->print($locknotfreed);
3298: }
3299: if ($suffix) {
3300: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3301: } else {
3302: return $errortxt;
3303: }
1.484.2.85.2. (raeburn 3304:): } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3305:): my ($suffix,$errortxt,$locknotfreed) =
3306:): &new_timebased_suffix($coursedom,$coursenum,'exttool');
3307:): if ($locknotfreed) {
3308:): $r->print($locknotfreed);
3309:): }
3310:): if ($suffix) {
3311:): $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3312:): } else {
3313:): return $errortxt;
3314:): }
1.484.2.27 raeburn 3315: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3316: if ($supplementalflag) {
3317: next unless ($1 eq 'supplemental');
3318: if ($folder eq 'supplemental') {
3319: next unless ($2 eq 'default');
3320: } else {
3321: next unless ($folder eq 'supplemental_'.$2);
3322: }
3323: } else {
3324: next unless ($1 eq 'docs');
3325: if ($folder eq 'default') {
3326: next unless ($2 eq 'default');
3327: } else {
3328: next unless ($folder eq 'default_'.$2);
3329: }
3330: }
1.484.2.15 raeburn 3331: }
1.329 droeschl 3332: push(@imports, [$name, $url, $residx]);
3333: }
3334: }
1.484.2.23 raeburn 3335: ($errtext,$fatal,my $fixuperrors) =
3336: &group_import($coursenum, $coursedom, $folder,$container,
1.484.2.85.2. (raeburn 3337:): 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3338: return $errtext if ($fatal);
1.484.2.23 raeburn 3339: if ($fixuperrors) {
3340: $r->print($fixuperrors);
3341: }
1.329 droeschl 3342: }
3343: # Loading a complete map
3344: if ($env{'form.loadmap'}) {
3345: if ($env{'form.importmap'}=~/\w/) {
3346: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3347: my ($title,$url,$ext,$type)=split(/\:/,$res);
3348: my $idx=&LONCAPA::map::getresidx($url);
3349: $LONCAPA::map::resources[$idx]=$res;
3350: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3351: }
3352: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3353: $folder.'.'.$container,1);
1.329 droeschl 3354: return $errtext if ($fatal);
3355: } else {
3356: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3357:
1.329 droeschl 3358: }
3359: }
3360: &log_differences($plain);
3361: }
3362: # ---------------------------------------------------------------- End commands
3363: # ---------------------------------------------------------------- Print screen
3364: my $idx=0;
3365: my $shown=0;
3366: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3367: $r->print('<div class="LC_Box">'.
1.432 raeburn 3368: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3369: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3370: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3371: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3372: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3373: '</ol>');
1.381 bisitz 3374: if ($randompick>=0) {
3375: $r->print('<p class="LC_warning">'
3376: .&mt('Caution: this folder is set to randomly pick a subset'
3377: .' of resources. Adding or removing resources from this'
3378: .' folder will change the set of resources that the'
3379: .' students see, resulting in spurious or missing credit'
3380: .' for completed problems, not limited to ones you'
3381: .' modify. Do not modify the contents of this folder if'
3382: .' it is in active student use.')
3383: .'</p>'
3384: );
3385: }
3386: if ($is_random_order) {
3387: $r->print('<p class="LC_warning">'
3388: .&mt('Caution: this folder is set to randomly order its'
3389: .' contents. Adding or removing resources from this folder'
3390: .' will change the order of resources shown.')
3391: .'</p>'
3392: );
3393: }
3394: $r->print('</div>');
1.364 bisitz 3395: }
1.381 bisitz 3396:
1.484.2.30 raeburn 3397: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3398: %filters = (
3399: canremove => [],
3400: cancut => [],
3401: cancopy => [],
3402: hiddenresource => [],
3403: encrypturl => [],
3404: randomorder => [],
3405: randompick => [],
3406: );
3407: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3408: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3409: foreach my $res (@LONCAPA::map::order) {
3410: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3411: $name=&LONCAPA::map::qtescape($name);
3412: $url=&LONCAPA::map::qtescape($url);
3413: unless ($name) { $name=(split(/\//,$url))[-1]; }
3414: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3415: push(@allidx,$res);
3416: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3417: push(@allmapidx,$res);
3418: }
1.484.2.67 raeburn 3419:
1.381 bisitz 3420: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3421: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3422: $pathitem,$supplementalflag,$container,
1.484.2.85.2. (raeburn 3423:): \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.484.2.80 raeburn 3424: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3425: $idx++;
3426: $shown++;
1.329 droeschl 3427: }
1.424 onken 3428: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3429:
1.484.2.30 raeburn 3430: my $need_save;
1.484.2.67 raeburn 3431: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3432: my $toolslink;
1.484.2.67 raeburn 3433: if ($allowed) {
1.484.2.31 raeburn 3434: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3435: .&Apache::loncommon::help_open_menu('Navigation Screen',
3436: 'Navigation_Screen',undef,'RAT')
3437: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3438: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3439: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3440: .'id="LC_content_toolbar_edittoplevel" '
3441: .'class="LC_toolbarItem" '
3442: .'title="'.&mt('Supplemental Content Editor').'">'
3443: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3444: }
1.484.2.19 raeburn 3445: if ($shown) {
3446: if ($allowed) {
3447: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3448: .&Apache::loncommon::start_data_table(undef,'contentlist')
3449: .&Apache::loncommon::start_data_table_header_row()
3450: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3451: .'<th colspan="2">'.&mt('Actions').'</th>'
3452: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3453: if ($folder !~ /^supplemental/) {
3454: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3455: }
1.484.2.29 raeburn 3456: $to_show .= &Apache::loncommon::end_data_table_header_row();
3457: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3458: $lists{'canhide'} = join(',',@allidx);
3459: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3460: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3461: 'randomorder','randompick');
3462: foreach my $item (@possfilters) {
3463: if (ref($filters{$item}) eq 'ARRAY') {
3464: if (@{$filters{$item}} > 0) {
3465: $lists{$item} = join(',',@{$filters{$item}});
3466: }
3467: }
3468: }
1.484.2.29 raeburn 3469: if (@allidx > 0) {
3470: my $path;
3471: if ($env{'form.folderpath'}) {
3472: $path =
3473: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3474: }
1.484.2.30 raeburn 3475: if (@allidx > 1) {
3476: $to_show .=
3477: &Apache::loncommon::continue_data_table_row().
3478: '<td colspan="2"> </td>'.
3479: '<td>'.
1.484.2.67 raeburn 3480: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3481: '</td>'.
3482: '<td> </td>'.
3483: '<td> </td>'.
3484: '<td colspan="4">'.
1.484.2.67 raeburn 3485: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3486: '</td>'.
3487: &Apache::loncommon::end_data_table_row();
3488: $need_save = 1;
3489: }
1.484.2.29 raeburn 3490: }
3491: }
3492: $to_show .= $output.' '
1.484.2.19 raeburn 3493: .&Apache::loncommon::end_data_table()
3494: .'<br style="line-height:2px;" />'
3495: .&Apache::loncommon::end_scrollbox();
3496: } else {
3497: $to_show .= $toolslink
3498: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3499: .$output.' '
3500: .&Apache::loncommon::end_data_table();
3501: }
3502: } else {
3503: if (!$allowed) {
3504: $to_show .= $toolslink;
1.393 raeburn 3505: }
1.484.2.67 raeburn 3506: my $noresmsg;
3507: if ($allowed && $hiddentop && !$supplementalflag) {
3508: $noresmsg = &mt('Main Content Hidden');
3509: } else {
3510: $noresmsg = &mt('Currently empty');
3511: }
1.484.2.19 raeburn 3512: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3513: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3514: .$noresmsg
1.484.2.19 raeburn 3515: .'</div>'
3516: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3517: }
3518: } else {
1.484.2.19 raeburn 3519: if ($shown) {
3520: $to_show = '<div>'
3521: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3522: .$output
3523: .&Apache::loncommon::end_data_table()
3524: .'</div>';
3525: } else {
3526: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3527: .&mt('Currently empty')
1.484.2.19 raeburn 3528: .'</div>'
3529: }
1.458 raeburn 3530: }
3531: my $tid = 1;
3532: if ($supplementalflag) {
3533: $tid = 2;
1.329 droeschl 3534: }
3535: if ($allowed) {
1.484 raeburn 3536: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3537: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3538: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3539: if ($canedit) {
1.484.2.67 raeburn 3540: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3541: }
1.460 raeburn 3542: } else {
3543: $r->print($to_show);
1.329 droeschl 3544: }
3545: return;
3546: }
3547:
1.484.2.30 raeburn 3548: sub multiple_check_form {
1.484.2.67 raeburn 3549: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3550: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3551: my $disabled;
3552: unless ($canedit) {
3553: $disabled = 'disabled="disabled"';
3554: }
1.484.2.30 raeburn 3555: my $output =
3556: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3557: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3558: '<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>'.
3559: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3560: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3561: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3562: if ($caller eq 'settings') {
3563: $output .=
3564: '<table><tr>'.
3565: '<td class="LC_docs_entry_parameter">'.
3566: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3567: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3568: '</label></span></td>'.
3569: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3570: '<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.484.2.30 raeburn 3571: '</span></td>'.
3572: '</tr>'."\n".
3573: '<tr>'.
3574: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3575: '<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.484.2.30 raeburn 3576: '</label></span>'.
3577: '</td></tr></table>'."\n";
3578: } else {
3579: $output .=
3580: '<table><tr>'.
3581: '<td class="LC_docs_entry_parameter">'.
3582: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3583: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3584: '</label></span></td>'.
3585: '<td class="LC_docs_entry_parameter">'.
3586: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3587: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3588: '</label></span></td>'."\n".
3589: '<td class="LC_docs_entry_parameter">'.
3590: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3591: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3592: '</label></span></td>'.
3593: '</tr></table>'."\n";
3594: }
3595: $output .=
3596: '</fieldset>'.
3597: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3598: if ($caller eq 'settings') {
3599: $output .=
3600: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3601: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3602: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3603: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3604: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3605: } elsif ($caller eq 'actions') {
3606: $output .=
3607: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3608: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3609: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3610: }
3611: $output .=
3612: '</form>'.
3613: '</div>';
3614: return $output;
3615: }
3616:
1.329 droeschl 3617: sub process_file_upload {
1.484.2.36 raeburn 3618: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3619: # upload a file, if present
1.484.2.36 raeburn 3620: my $filesize = length($env{'form.uploaddoc'});
3621: if (!$filesize) {
3622: $$upload_output = '<div class="LC_error">'.
3623: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3624: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3625: $filesize).'<br />'.
3626: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3627: '</div>';
3628: return;
3629: }
3630: my $quotatype = 'unofficial';
3631: if ($crstype eq 'Community') {
3632: $quotatype = 'community';
1.484.2.51 raeburn 3633: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3634: $quotatype = 'official';
1.484.2.45 raeburn 3635: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3636: $quotatype = 'textbook';
1.484.2.36 raeburn 3637: }
3638: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3639: $filesize = int($filesize/1000); #expressed in kb
3640: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3641: $env{'form.uploaddoc.filename'},$filesize,
3642: 'upload',$quotatype);
1.484.2.36 raeburn 3643: return if ($$upload_output);
3644: }
1.440 raeburn 3645: my ($parseaction,$showupload,$nextphase,$mimetype);
3646: if ($env{'form.parserflag'}) {
1.329 droeschl 3647: $parseaction = 'parse';
3648: }
3649: my $folder=$env{'form.folder'};
3650: if ($folder eq '') {
3651: $folder='default';
3652: }
3653: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3654: my $errtext='';
3655: my $fatal=0;
3656: my $container='sequence';
1.484.2.19 raeburn 3657: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3658: $container='page';
3659: }
3660: ($errtext,$fatal)=
1.484.2.27 raeburn 3661: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3662: if ($#LONCAPA::map::order<1) {
3663: $LONCAPA::map::order[0]=1;
3664: $LONCAPA::map::resources[1]='';
3665: }
3666: my $destination = 'docs/';
3667: if ($folder =~ /^supplemental/) {
3668: $destination = 'supplemental/';
3669: }
3670: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3671: $destination .= 'default/';
3672: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3673: $destination .= $2.'/';
3674: }
1.484.2.27 raeburn 3675: if ($fatal) {
3676: $$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>';
3677: return;
3678: }
1.440 raeburn 3679: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3680: my $newidx=&LONCAPA::map::getresidx();
3681: $destination .= $newidx;
1.439 raeburn 3682: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3683: $parseaction,$allfiles,
1.440 raeburn 3684: $codebase,undef,undef,undef,undef,
3685: undef,undef,\$mimetype);
3686: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3687: my $stored = $1;
3688: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3689: $stored.'</span>').'</p>';
3690: } else {
3691: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3692:
1.457 raeburn 3693: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3694: return;
3695: }
1.329 droeschl 3696: my $ext='false';
3697: if ($url=~m{^http://}) { $ext='true'; }
3698: $url = &LONCAPA::map::qtunescape($url);
3699: my $comment=$env{'form.comment'};
3700: $comment = &LONCAPA::map::qtunescape($comment);
3701: if ($folder=~/^supplemental/) {
3702: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3703: $env{'user.domain'}.'___&&&___'.$comment;
3704: }
3705:
3706: $LONCAPA::map::resources[$newidx]=
3707: $comment.':'.$url.':'.$ext.':normal:res';
3708: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3709: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3710: $folder.'.'.$container,1);
1.329 droeschl 3711: if ($fatal) {
1.457 raeburn 3712: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3713: return;
1.329 droeschl 3714: } else {
1.440 raeburn 3715: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3716: $$upload_output = $showupload;
1.384 raeburn 3717: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3718: if ($total_embedded > 0) {
1.440 raeburn 3719: my $uploadphase = 'upload_embedded';
3720: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3721: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3722: my ($embedded,$num) =
3723: &Apache::loncommon::ask_for_embedded_content(
3724: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3725: if ($embedded) {
3726: if ($num) {
3727: $$upload_output .=
3728: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3729: $nextphase = $uploadphase;
3730: } else {
3731: $$upload_output .= $embedded;
3732: }
3733: } else {
3734: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3735: }
1.329 droeschl 3736: } else {
1.440 raeburn 3737: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3738: }
1.457 raeburn 3739: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3740: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3741: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3742: $nextphase = 'decompress_uploaded';
3743: my $position = scalar(@LONCAPA::map::order)-1;
3744: my $noextract = &return_to_editor();
3745: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3746: my %archiveitems = (
3747: folderpath => $env{'form.folderpath'},
3748: cmd => $nextphase,
3749: newidx => $newidx,
3750: position => $position,
3751: phase => $nextphase,
1.477 raeburn 3752: comment => $comment,
1.480 raeburn 3753: );
3754: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3755: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3756: $$upload_output = $showupload.
3757: &Apache::loncommon::decompress_form($mimetype,
3758: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3759: \%archiveitems,\@current);
1.329 droeschl 3760: }
3761: }
3762: }
1.440 raeburn 3763: return $nextphase;
1.329 droeschl 3764: }
3765:
1.480 raeburn 3766: sub get_dir_list {
3767: my ($url,$coursenum,$coursedom,$newidx) = @_;
3768: my ($destination,$dir_root) = &embedded_destination();
3769: my ($dirlistref,$listerror) =
3770: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3771: my @dir_lines;
3772: my $dirptr=16384;
3773: if (ref($dirlistref) eq 'ARRAY') {
3774: foreach my $dir_line (sort
3775: {
3776: my ($afile)=split('&',$a,2);
3777: my ($bfile)=split('&',$b,2);
3778: return (lc($afile) cmp lc($bfile));
3779: } (@{$dirlistref})) {
3780: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3781: $filename =~ s/\s+$//;
3782: next if ($filename =~ /^\.\.?$/);
3783: my $isdir = 0;
3784: if ($dirptr&$testdir) {
3785: $isdir = 1;
3786: }
3787: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3788: }
3789: }
3790: return @dir_lines;
3791: }
3792:
1.329 droeschl 3793: sub is_supplemental_title {
3794: my ($title) = @_;
3795: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3796: }
3797:
3798: # --------------------------------------------------------------- An entry line
3799:
3800: sub entryline {
1.484.2.12 raeburn 3801: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3802: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.85.2. (raeburn 3803:): $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3804: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3805: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3806: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3807: } else {
3808: $title=&HTML::Entities::encode($title,'"<>&\'');
3809: $renametitle=$title;
3810: $foldertitle=$title;
3811: }
3812:
1.484.2.67 raeburn 3813: my ($disabled,$readonly,$js_lt);
3814: unless ($canedit) {
3815: $disabled = 'disabled="disabled"';
3816: $readonly = 1;
3817: }
3818:
1.329 droeschl 3819: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3820:
1.329 droeschl 3821: $renametitle=~s/\\/\\\\/g;
3822: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3823: $renametitle=~s/"/%22/g;
1.329 droeschl 3824: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3825: $oldtitle = $renametitle;
3826: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3827: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3828: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3829: # Edit commands
1.484.2.28 raeburn 3830: my ($esc_path, $path, $symb);
1.329 droeschl 3831: if ($env{'form.folderpath'}) {
3832: $esc_path=&escape($env{'form.folderpath'});
3833: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3834: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3835: }
1.484.2.16 raeburn 3836: my $isexternal;
1.484.2.19 raeburn 3837: if ($residx) {
1.484.2.12 raeburn 3838: my $currurl = $url;
3839: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3840: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3841: $isexternal = 1;
3842: }
1.484.2.19 raeburn 3843: if (!$supplementalflag) {
3844: my $path = 'uploaded/'.
3845: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3846: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3847: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3848: $residx,
3849: &Apache::lonnet::declutter($currurl));
3850: }
1.484.2.12 raeburn 3851: }
1.484.2.30 raeburn 3852: my ($renamelink,%lt,$ishash);
3853: if (ref($filtersref) eq 'HASH') {
3854: $ishash = 1;
3855: }
3856:
1.329 droeschl 3857: if ($allowed) {
1.484.2.30 raeburn 3858: $form_start = '
3859: <form action="/adm/coursedocs" method="post">
3860: ';
3861: $form_common=(<<END);
3862: <input type="hidden" name="folderpath" value="$path" />
3863: <input type="hidden" name="symb" value="$symb" />
3864: END
3865: $form_param=(<<END);
3866: <input type="hidden" name="setparms" value="$orderidx" />
3867: <input type="hidden" name="changeparms" value="0" />
3868: END
3869: $form_end = '</form>';
3870:
1.329 droeschl 3871: my $incindex=$index+1;
3872: my $selectbox='';
1.471 raeburn 3873: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3874: ((split(/\:/,
1.344 bisitz 3875: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3876: ne '') &&
1.329 droeschl 3877: ((split(/\:/,
1.344 bisitz 3878: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3879: ne '')) {
3880: $selectbox=
3881: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3882: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3883: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3884: if ($i==$incindex) {
1.358 bisitz 3885: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3886: } else {
3887: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3888: }
3889: }
3890: $selectbox.='</select>';
3891: }
1.484.2.12 raeburn 3892: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3893: 'up' => 'Move Up',
3894: 'dw' => 'Move Down',
3895: 'rm' => 'Remove',
3896: 'ct' => 'Cut',
3897: 'rn' => 'Rename',
1.484.2.12 raeburn 3898: 'cp' => 'Copy',
3899: 'ex' => 'External Resource',
1.484.2.85.2. (raeburn 3900:): 'et' => 'External Tool',
1.484.2.12 raeburn 3901: 'ed' => 'Edit',
3902: 'pr' => 'Preview',
3903: 'sv' => 'Save',
3904: 'ul' => 'URL',
1.484.2.67 raeburn 3905: 'ti' => 'Title',
3906: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3907: );
1.484.2.30 raeburn 3908: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3909: $env{'form.folderpath'},
3910: $currgroups);
1.484.2.19 raeburn 3911: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3912: my $skip_confirm = 0;
1.484.2.63 raeburn 3913: my $confirm_removal = 0;
1.329 droeschl 3914: if ( $folder =~ /^supplemental/
3915: || ($url =~ m{( /smppg$
3916: |/syllabus$
3917: |/aboutme$
3918: |/navmaps$
3919: |/bulletinboard$
1.484.2.85.2. (raeburn 3920:): |/ext\.tool$
1.484.2.16 raeburn 3921: |\.html$)}x)
1.484.2.19 raeburn 3922: || $isexternal) {
1.329 droeschl 3923: $skip_confirm = 1;
3924: }
1.484.2.63 raeburn 3925: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3926: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3927: $confirm_removal = 1;
3928: }
1.484.2.19 raeburn 3929:
1.484.2.30 raeburn 3930: if ($denied{'copy'}) {
3931: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3932: <span style="visibility: hidden;">$lt{'cp'}</span>
3933: ENDCOPY
3934: } else {
1.484.2.30 raeburn 3935: my $formname = 'edit_copy_'.$orderidx;
3936: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3937: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3938: <form name="$formname" method="post" action="/adm/coursedocs">
3939: $form_common
1.484.2.67 raeburn 3940: <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.484.2.30 raeburn 3941: $form_end
1.329 droeschl 3942: ENDCOPY
1.484.2.30 raeburn 3943: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3944: push(@{$filtersref->{'cancopy'}},$orderidx);
3945: }
1.329 droeschl 3946: }
1.484.2.30 raeburn 3947: if ($denied{'cut'}) {
1.484.2.16 raeburn 3948: $cutlink=(<<ENDCUT);
3949: <span style="visibility: hidden;">$lt{'ct'}</span>
3950: ENDCUT
3951: } else {
1.484.2.30 raeburn 3952: my $formname = 'edit_cut_'.$orderidx;
3953: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3954: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3955: <form name="$formname" method="post" action="/adm/coursedocs">
3956: $form_common
3957: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3958: <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.484.2.30 raeburn 3959: $form_end
1.329 droeschl 3960: ENDCUT
1.484.2.30 raeburn 3961: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3962: push(@{$filtersref->{'cancut'}},$orderidx);
3963: }
1.329 droeschl 3964: }
1.484.2.30 raeburn 3965: if ($denied{'remove'}) {
1.484.2.16 raeburn 3966: $removelink=(<<ENDREM);
3967: <span style="visibility: hidden;">$lt{'rm'}</a>
3968: ENDREM
3969: } else {
1.484.2.30 raeburn 3970: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3971: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.484.2.9 raeburn 3972: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3973: <form name="$formname" method="post" action="/adm/coursedocs">
3974: $form_common
3975: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3976: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3977: <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.484.2.30 raeburn 3978: $form_end
1.484.2.9 raeburn 3979: ENDREM
1.484.2.30 raeburn 3980: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3981: push(@{$filtersref->{'canremove'}},$orderidx);
3982: }
1.484.2.9 raeburn 3983: }
1.484.2.35 raeburn 3984: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3985: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3986: ENDREN
1.484.2.67 raeburn 3987: my ($uplink,$downlink);
3988: if ($canedit) {
3989: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3990: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3991: } else {
3992: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3993: $downlink = $uplink;
3994: }
1.329 droeschl 3995: $line.=(<<END);
3996: <td>
1.379 bisitz 3997: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3998: <a href="$uplink">
1.484.2.12 raeburn 3999: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4000: </a>
4001: </div>
4002: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4003: <a href="$downlink">
1.484.2.12 raeburn 4004: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4005: </a>
4006: </div>
1.329 droeschl 4007: </td>
4008: <td>
4009: $form_start
1.484.2.30 raeburn 4010: $form_param
1.478 raeburn 4011: $form_common
1.329 droeschl 4012: $selectbox
4013: $form_end
4014: </td>
1.484.2.30 raeburn 4015: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 4016: $removelink
1.329 droeschl 4017: $cutlink
4018: $copylink
4019: </td>
4020: END
4021: }
4022: # Figure out what kind of a resource this is
4023: my ($extension)=($url=~/\.(\w+)$/);
4024: my $uploaded=($url=~/^\/*uploaded\//);
4025: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 4026: my $isfolder;
4027: my $ispage;
4028: my $containerarg;
1.484.2.67 raeburn 4029: my $folderurl;
1.329 droeschl 4030: if ($uploaded) {
1.472 raeburn 4031: if (($extension eq 'sequence') || ($extension eq 'page')) {
4032: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 4033: $containerarg = $1;
1.472 raeburn 4034: if ($extension eq 'sequence') {
4035: $icon=$iconpath.'navmap.folder.closed.gif';
4036: $isfolder=1;
4037: } else {
4038: $icon=$iconpath.'page.gif';
4039: $ispage=1;
4040: }
1.484.2.67 raeburn 4041: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4042: if ($allowed) {
4043: $url='/adm/coursedocs?';
4044: } else {
4045: $url='/adm/supplemental?';
4046: }
1.329 droeschl 4047: } else {
4048: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4049: }
4050: }
1.364 bisitz 4051:
1.484.2.70 raeburn 4052: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4053: my $orig_url = $url;
1.340 raeburn 4054: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.85.2. (raeburn 4055:): if ($container eq 'page') {
4056:): $url=~s{^http(|s)(:|:)//}{/ext/};
4057:): } else {
4058:): $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4059:): }
1.484.2.12 raeburn 4060: if (!$supplementalflag && $residx && $symb) {
4061: if ((!$isfolder) && (!$ispage)) {
4062: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.85.2. (raeburn 4063:): if (($url =~ m{^ext/}) && ($container eq 'page')) {
4064:): $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4065:): } else {
4066:): $url=&Apache::lonnet::clutter($url);
4067:): }
1.484.2.12 raeburn 4068: if ($url=~/^\/*uploaded\//) {
4069: $url=~/\.(\w+)$/;
4070: my $embstyle=&Apache::loncommon::fileembstyle($1);
4071: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4072: $url='/adm/wrapper'.$url;
4073: } elsif ($embstyle eq 'ssi') {
4074: #do nothing with these
4075: } elsif ($url!~/\.(sequence|page)$/) {
4076: $url='/adm/coursedocs/showdoc'.$url;
4077: }
1.484.2.70 raeburn 4078: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4079: my $wrapped = $1;
4080: my $exturl = $2;
1.484.2.85.2. (raeburn 4081:): if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 4082: $url='/adm/wrapper'.$url;
4083: }
4084: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4085: $nomodal = 1;
4086: }
1.484.2.85.2. (raeburn 4087:): } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4088:): $url='/adm/wrapper'.$url;
1.484.2.70 raeburn 4089: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4090: if (($ENV{'SERVER_PORT'} == 443) &&
4091: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 4092: unless (&Apache::lonnet::uses_sts()) {
4093: $url .= '?usehttp=1';
4094: }
1.484.2.70 raeburn 4095: $nomodal = 1;
4096: }
1.484.2.19 raeburn 4097: }
1.484.2.12 raeburn 4098: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 4099: my $shownsymb = $symb;
4100: if ($isexternal) {
1.484.2.85.2. (raeburn 4101:): $url =~ s/\#[^#]+$//;
4102:): if ($container eq 'page') {
4103:): $url = &Apache::lonnet::clutter($url);
1.484.2.66 raeburn 4104: }
4105: }
1.484.2.67 raeburn 4106: unless ($env{'request.role.adv'}) {
4107: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4108: $url = '';
4109: }
4110: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4111: $url = '';
4112: $hiddenres = 1;
4113: }
4114: }
4115: if ($url ne '') {
1.484.2.75 raeburn 4116: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4117: }
4118: } elsif (!$env{'request.role.adv'}) {
4119: my $checkencrypt;
4120: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4121: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4122: $checkencrypt = 1;
1.484.2.70 raeburn 4123: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 4124: unless (ref($$navmapref)) {
4125: $$navmapref = Apache::lonnavmaps::navmap->new();
4126: }
4127: if (ref($$navmapref)) {
4128: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4129: $checkencrypt = 1;
4130: }
4131: }
4132: }
4133: if ($checkencrypt) {
4134: my $shownsymb = &Apache::lonenc::encrypted($symb);
4135: my $shownurl = &Apache::lonenc::encrypted($url);
4136: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 4137: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4138: if ($env{'request.enc'} ne '') {
4139: delete($env{'request.enc'});
4140: }
4141: } else {
4142: $url='';
4143: }
4144: } else {
4145: $url='';
4146: }
1.484.2.12 raeburn 4147: } else {
4148: $url='';
4149: }
1.484.2.19 raeburn 4150: }
1.484.2.66 raeburn 4151: } elsif ($supplementalflag) {
4152: if ($isexternal) {
4153: if ($url =~ /^([^#]+)#([^#]+)$/) {
4154: $url = $1;
4155: $anchor = $2;
1.484.2.70 raeburn 4156: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.80 raeburn 4157: unless (&Apache::lonnet::uses_sts()) {
4158: if ($hostname ne '') {
4159: $url = 'http://'.$hostname.$url;
4160: }
4161: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4162: }
1.484.2.70 raeburn 4163: $nomodal = 1;
4164: }
4165: }
4166: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4167: if (($ENV{'SERVER_PORT'} == 443) &&
4168: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 4169: unless (&Apache::lonnet::uses_sts()) {
4170: if ($hostname ne '') {
4171: $url = 'http://'.$hostname.$url;
4172: }
4173: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4174: }
1.484.2.70 raeburn 4175: $nomodal = 1;
1.484.2.66 raeburn 4176: }
4177: }
1.329 droeschl 4178: }
1.484.2.67 raeburn 4179: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4180: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4181: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4182: my $foldername=&escape($foldertitle);
4183: my $folderpath=$env{'form.folderpath'};
4184: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4185: if (!$allowed && $supplementalflag) {
4186: $folderpath.=$containerarg.'&'.$foldername;
4187: $url.='folderpath='.&escape($folderpath);
4188: } else {
4189: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4190: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4191: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4192: 'parameter_randomorder'))[0]=~/^yes$/i);
4193: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4194: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4195: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4196: 'parameter_encrypturl'))[0]=~/^yes$/i);
4197: unless ($hiddenmap) {
1.484.2.70 raeburn 4198: if (ref($navmapref)) {
4199: unless (ref($$navmapref)) {
4200: $$navmapref = Apache::lonnavmaps::navmap->new();
4201: }
4202: if (ref($$navmapref)) {
4203: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4204: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4205: unless (@resources) {
4206: $hiddenmap = 1;
4207: unless ($env{'request.role.adv'}) {
4208: $url = '';
4209: $hiddenfolder = 1;
4210: }
1.484.2.67 raeburn 4211: }
4212: }
4213: }
4214: }
4215: }
4216: unless ($encryptmap) {
1.484.2.70 raeburn 4217: if ((ref($navmapref)) && (ref($$navmapref))) {
4218: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4219: $encryptmap = 1;
4220: }
1.484.2.67 raeburn 4221: }
4222: }
4223:
4224: # Append randompick number, hidden, and encrypted with ":" to foldername,
4225: # so it gets transferred between levels
4226: $folderpath.=$containerarg.'&'.$foldername.
4227: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4228: unless ($url eq '') {
4229: $url.='folderpath='.&escape($folderpath);
4230: }
1.484.2.19 raeburn 4231: my $rpckchk;
4232: if ($rpicknum) {
4233: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4234: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4235: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4236: }
1.484.2.19 raeburn 4237: }
1.484.2.29 raeburn 4238: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4239: $rand_pick_text =
1.478 raeburn 4240: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4241: $form_param."\n".
1.478 raeburn 4242: $form_common."\n".
1.484.2.67 raeburn 4243: '<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.484.2.19 raeburn 4244: if ($rpicknum ne '') {
4245: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4246: }
1.484.2.29 raeburn 4247: $rand_pick_text .= '</span></span>'.
4248: $form_end;
1.484.2.30 raeburn 4249: my $ro_set;
1.484.2.67 raeburn 4250: if ($randorder) {
1.484.2.30 raeburn 4251: $ro_set = 'checked="checked"';
4252: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4253: push(@{$filtersref->{'randomorder'}},$orderidx);
4254: }
4255: }
1.484.2.41 raeburn 4256: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4257: $rand_order_text =
1.484.2.29 raeburn 4258: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4259: $form_param."\n".
1.484.2.29 raeburn 4260: $form_common."\n".
1.484.2.67 raeburn 4261: '<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.484.2.29 raeburn 4262: $form_end;
1.484.2.19 raeburn 4263: }
1.484.2.18 raeburn 4264: } elsif ($supplementalflag && !$allowed) {
1.484.2.85.2. (raeburn 4265:): my $isexttool;
4266:): if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4267:): $url='/adm/wrapper'.$url;
4268:): $isexttool = 1;
4269:): }
1.484.2.19 raeburn 4270: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4271: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4272: if ($title) {
4273: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4274: }
1.484.2.85.2. (raeburn 4275:): if ((($isexternal) || ($isexttool)) && $orderidx) {
1.484.2.19 raeburn 4276: $url .= '&idx='.$orderidx;
4277: }
1.484.2.66 raeburn 4278: if ($anchor ne '') {
4279: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4280: }
1.329 droeschl 4281: }
1.484.2.19 raeburn 4282: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4283: if ($allowed) {
1.484.2.19 raeburn 4284: my $fileloc =
1.484.2.12 raeburn 4285: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4286: if ($isexternal) {
4287: ($editlink,$extresform) =
1.484.2.67 raeburn 4288: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
1.484.2.85.2. (raeburn 4289:): undef,undef,undef,undef,undef,undef,
4290:): undef,$disabled);
4291:): } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4292:): ($editlink,$extresform) =
4293:): &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4294:): undef,undef,undef,'tool',$coursedom,
4295:): $coursenum,$ltitoolsref,$disabled);
1.484.2.19 raeburn 4296: } elsif (!$isfolder && !$ispage) {
4297: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4298: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4299: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4300: my $suppanchor;
4301: if ($supplementalflag) {
4302: $suppanchor = $anchor;
4303: }
1.484.2.19 raeburn 4304: my $jscall =
1.484.2.12 raeburn 4305: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4306: $switchserver,
1.484.2.14 raeburn 4307: $forceedit,
1.484.2.19 raeburn 4308: undef,$symb,
4309: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4310: $renametitle,$hostname,
4311: '','',1,$suppanchor);
1.484.2.12 raeburn 4312: if ($jscall) {
1.484.2.19 raeburn 4313: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4314: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4315: }
4316: }
4317: }
1.484.2.19 raeburn 4318: $tdalign = ' align="right" valign="top"';
4319: $tdwidth = ' width="80%"';
1.329 droeschl 4320: }
1.408 raeburn 4321: my $reinit;
4322: if ($crstype eq 'Community') {
4323: $reinit = &mt('(re-initialize community to access)');
4324: } else {
4325: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4326: }
4327: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4328: my $link;
1.472 raeburn 4329: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4330: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4331: } elsif ($url) {
1.484.2.66 raeburn 4332: if ($anchor ne '') {
4333: if ($supplementalflag) {
4334: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4335: } else {
4336: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4337: }
4338: }
1.484.2.80 raeburn 4339:
4340: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4341: $link = 'http://'.$hostname.$url;
4342: } else {
4343: $link = $url;
4344: }
4345: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4346: if ($nomodal) {
4347: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4348: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4349: } else {
4350: $line.=&Apache::loncommon::modal_link($link,
4351: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4352: }
1.469 www 4353: } else {
4354: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4355: }
1.484.2.19 raeburn 4356: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4357: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4358: $line.='<a href="'.$url.'">'.$title.'</a>';
4359: } elsif ($url) {
1.484.2.70 raeburn 4360: if ($nomodal) {
4361: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4362: $title.'</a>';
4363: } else {
4364: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4365: }
1.484.2.67 raeburn 4366: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4367: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4368: } else {
4369: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4370: }
1.484.2.19 raeburn 4371: $line.="$extresform</td>";
1.478 raeburn 4372: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4373: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4374: if (($allowed) && ($folder!~/^supplemental/)) {
4375: my %lt=&Apache::lonlocal::texthash(
4376: 'hd' => 'Hidden',
4377: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4378: my ($enctext,$hidtext);
4379: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4380: $enctext = ' checked="checked"';
4381: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4382: push(@{$filtersref->{'encrypturl'}},$orderidx);
4383: }
4384: }
4385: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4386: $hidtext = ' checked="checked"';
4387: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4388: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4389: }
4390: }
1.484.2.29 raeburn 4391: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4392: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4393: $line.=(<<ENDPARMS);
4394: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4395: <form action="/adm/coursedocs" method="post" name="$formhidden">
4396: $form_param
1.478 raeburn 4397: $form_common
1.484.2.67 raeburn 4398: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4399: $form_end
1.458 raeburn 4400: <br />
1.484.2.29 raeburn 4401: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4402: $form_param
1.478 raeburn 4403: $form_common
1.484.2.67 raeburn 4404: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4405: $form_end
4406: </td>
1.478 raeburn 4407: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4408: $rand_order_text</td>
1.329 droeschl 4409: ENDPARMS
4410: }
1.379 bisitz 4411: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4412: return $line;
4413: }
4414:
1.484.2.30 raeburn 4415: sub action_restrictions {
4416: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4417: my %denied = (
4418: cut => 0,
4419: copy => 0,
4420: remove => 0,
4421: );
4422: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4423: # no copy for published maps
4424: $denied{'copy'} = 1;
1.484.2.82 raeburn 4425: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4426: unless ($1 eq 'simpleproblem') {
4427: $denied{'copy'} = 1;
4428: }
4429: $denied{'cut'} = 1;
1.484.2.30 raeburn 4430: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4431: if ($folderpath =~ /^default&[^\&]+$/) {
4432: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4433: $denied{'remove'} = 1;
4434: }
4435: $denied{'cut'} = 1;
4436: $denied{'copy'} = 1;
4437: }
4438: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4439: my $group = $1;
4440: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4441: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4442: $denied{'remove'} = 1;
4443: }
4444: }
4445: $denied{'cut'} = 1;
4446: $denied{'copy'} = 1;
4447: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4448: my $group = $1;
4449: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4450: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4451: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4452: if (keys(%groupsettings) > 0) {
4453: $denied{'remove'} = 1;
4454: }
4455: $denied{'cut'} = 1;
4456: $denied{'copy'} = 1;
4457: }
4458: }
4459: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4460: my $group = $1;
4461: if ($url =~ /group_boards_\Q$group\E/) {
4462: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4463: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4464: if (keys(%groupsettings) > 0) {
4465: if (ref($groupsettings{'functions'}) eq 'HASH') {
4466: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4467: $denied{'remove'} = 1;
4468: }
4469: }
4470: }
4471: $denied{'cut'} = 1;
4472: $denied{'copy'} = 1;
4473: }
4474: }
4475: }
4476: return %denied;
4477: }
4478:
1.484.2.26 raeburn 4479: sub new_timebased_suffix {
1.484.2.30 raeburn 4480: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4481: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4482: if ($type eq 'paste') {
4483: $prefix = $type;
4484: $namespace = 'courseeditor';
1.484.2.56 raeburn 4485: $idtype = 'addcode';
1.484.2.30 raeburn 4486: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4487: $prefix = 'docs';
4488: if ($area eq 'supplemental') {
4489: $prefix = 'supp';
4490: }
4491: $prefix .= $container;
4492: $namespace = 'uploadedmaps';
4493: } else {
4494: $prefix = $type;
4495: $namespace = 'templated';
1.484.2.15 raeburn 4496: }
4497: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4498: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4499: if (!$suffix) {
1.484.2.30 raeburn 4500: if ($type eq 'paste') {
4501: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4502: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4503: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4504: } elsif ($type eq 'smppg') {
4505: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.484.2.85.2. (raeburn 4506:): } elsif ($type eq 'exttool') {
4507:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.484.2.26 raeburn 4508: } else {
1.484.2.42 raeburn 4509: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4510: }
1.484.2.15 raeburn 4511: if ($error) {
4512: $errtext .= '<br />'.$error;
4513: }
4514: }
4515: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4516: $locknotfreed =
4517: '<div class="LC_error">'.
4518: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4519: if ($type eq 'paste') {
1.484.2.57 raeburn 4520: if ($freedlock eq 'nolock') {
4521: $locknotfreed =
4522: '<div class="LC_error">'.
4523: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4524:
1.484.2.60 raeburn 4525: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4526: } else {
4527: $locknotfreed .=
4528: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4529: }
1.484.2.30 raeburn 4530: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4531: $locknotfreed .=
4532: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4533: } elsif ($type eq 'smppg') {
4534: $locknotfreed .=
4535: &mt('This will prevent creation of additional simple pages in this course.');
1.484.2.85.2. (raeburn 4536:): } elsif ($type eq 'exttool') {
4537:): $locknotfreed .=
4538:): &mt('This will prevent creation of additional external tools in this course.');
1.484.2.26 raeburn 4539: } else {
4540: $locknotfreed .=
1.484.2.42 raeburn 4541: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4542: }
1.484.2.30 raeburn 4543: unless ($type eq 'paste') {
4544: $locknotfreed .=
1.484.2.38 raeburn 4545: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4546: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4547: }
4548: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4549: }
4550: return ($suffix,$errtext,$locknotfreed);
4551: }
4552:
1.329 droeschl 4553: =pod
4554:
4555: =item tiehash()
4556:
4557: tie the hash
4558:
4559: =cut
4560:
4561: sub tiehash {
4562: my ($mode)=@_;
4563: $hashtied=0;
4564: if ($env{'request.course.fn'}) {
4565: if ($mode eq 'write') {
4566: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4567: &GDBM_WRCREAT(),0640)) {
4568: $hashtied=2;
4569: }
4570: } else {
4571: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4572: &GDBM_READER(),0640)) {
4573: $hashtied=1;
4574: }
4575: }
1.364 bisitz 4576: }
1.329 droeschl 4577: }
4578:
4579: sub untiehash {
4580: if ($hashtied) { untie %hash; }
4581: $hashtied=0;
4582: return OK;
4583: }
4584:
4585:
4586:
4587:
4588: sub checkonthis {
1.484.2.78 raeburn 4589: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4590: $url=&unescape($url);
4591: $alreadyseen{$url}=1;
4592: $r->rflush();
4593: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4594: $r->print("\n<br />");
4595: if ($level==0) {
4596: $r->print("<br />");
4597: }
4598: for (my $i=0;$i<=$level*5;$i++) {
4599: $r->print(' ');
4600: }
4601: $r->print('<a href="'.$url.'" target="cat">'.
4602: ($title?$title:$url).'</a> ');
4603: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4604: my $updated;
4605: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4606: ($url !~ /\.\d+\.\w+$/)) {
4607: $updated = &Apache::lonnet::remove_stale_resfile($url);
4608: }
1.329 droeschl 4609: my $result=&Apache::lonnet::repcopy(
4610: &Apache::lonnet::filelocation('',$url));
4611: if ($result eq 'ok') {
4612: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4613: if ($updated) {
4614: $r->print('<br />');
4615: for (my $i=0;$i<=$level*5;$i++) {
4616: $r->print(' ');
4617: }
4618: $r->print('- '.&mt('Outdated copy removed'));
4619: }
1.329 droeschl 4620: $r->rflush();
4621: &Apache::lonnet::countacc($url);
4622: $url=~/\.(\w+)$/;
4623: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4624: $r->print('<br />');
4625: $r->rflush();
4626: for (my $i=0;$i<=$level*5;$i++) {
4627: $r->print(' ');
4628: }
4629: $r->print('- '.&mt('Rendering:').' ');
4630: my ($errorcount,$warningcount)=split(/:/,
4631: &Apache::lonnet::ssi_body($url,
4632: ('grade_target'=>'web',
4633: 'return_only_error_and_warning_counts' => 1)));
4634: if (($errorcount) ||
4635: ($warningcount)) {
4636: if ($errorcount) {
1.369 bisitz 4637: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4638: &mt('[quant,_1,error]',$errorcount).'</span>');
4639: }
4640: if ($warningcount) {
4641: $r->print('<span class="LC_warning">'.
4642: &mt('[quant,_1,warning]',$warningcount).'</span>');
4643: }
4644: } else {
4645: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4646: }
4647: $r->rflush();
4648: }
4649: my $dependencies=
4650: &Apache::lonnet::metadata($url,'dependencies');
4651: foreach my $dep (split(/\,/,$dependencies)) {
4652: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4653: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4654: }
4655: }
4656: } elsif ($result eq 'unavailable') {
4657: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4658: } elsif ($result eq 'not_found') {
4659: unless ($url=~/\$/) {
1.484.2.19 raeburn 4660: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4661: } else {
1.366 bisitz 4662: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4663: }
4664: } else {
4665: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4666: }
1.484.2.78 raeburn 4667: if (($updated) && ($result ne 'ok')) {
4668: $r->print('<br />'.&mt('Outdated copy removed'));
4669: }
1.329 droeschl 4670: }
4671: }
4672: }
4673:
4674:
4675:
4676: =pod
4677:
4678: =item list_symbs()
4679:
1.484.2.3 raeburn 4680: List Content Identifiers
1.329 droeschl 4681:
4682: =cut
4683:
4684: sub list_symbs {
4685: my ($r) = @_;
4686:
1.408 raeburn 4687: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4688: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4689: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4690: $r->print(&startContentScreen('tools'));
1.329 droeschl 4691: my $navmap = Apache::lonnavmaps::navmap->new();
4692: if (!defined($navmap)) {
4693: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4694: '<div class="LC_error">'.
4695: &mt('Unable to retrieve information about course contents').
4696: '</div>');
1.408 raeburn 4697: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4698: } else {
1.484 raeburn 4699: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4700: &Apache::loncommon::start_data_table().
4701: &Apache::loncommon::start_data_table_header_row().
4702: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4703: &Apache::loncommon::end_data_table_header_row()."\n");
4704: my $count;
1.329 droeschl 4705: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4706: $r->print(&Apache::loncommon::start_data_table_row().
4707: '<td>'.$res->compTitle().'</td>'.
4708: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4709: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4710: $count ++;
4711: }
4712: if (!$count) {
4713: $r->print(&Apache::loncommon::start_data_table_row().
4714: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4715: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4716: }
1.484 raeburn 4717: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4718: }
1.484.2.19 raeburn 4719: $r->print(&endContentScreen());
1.329 droeschl 4720: }
4721:
1.484.2.85.2. (raeburn 4722:): sub short_urls {
4723:): my ($r,$canedit) = @_;
4724:): my $crstype = &Apache::loncommon::course_type();
4725:): my $formname = 'shortenurl';
4726:): $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4727:): $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4728:): $r->print(&startContentScreen('tools'));
4729:): my ($navmap,$errormsg) =
4730:): &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4731:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4732:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4733:): my (%maps,%resources,%titles);
4734:): if (!ref($navmap)) {
4735:): $r->print($errormsg.
4736:): &endContentScreen());
4737:): return '';
4738:): } else {
4739:): $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4740:): $r->rflush();
4741:): my $readonly;
4742:): if ($canedit) {
4743:): my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
4744:): if ($numnew) {
4745:): $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4746:): }
4747:): if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4748:): $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4749:): foreach my $error (@{$errors}) {
4750:): $r->print('<li>'.$error.'</li>');
4751:): }
4752:): $r->print('</ul><br />');
4753:): }
4754:): } else {
4755:): $readonly = 1;
4756:): }
4757:): my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4758:): $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4759:): undef,undef,undef,undef,undef,\%currtiny,$readonly));
4760:): }
4761:): $r->print(&endContentScreen());
4762:): }
4763:):
1.484.2.78 raeburn 4764: sub contentverifyform {
4765: my ($r) = @_;
4766: my $crstype = &Apache::loncommon::course_type();
4767: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4768: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4769: $r->print(&startContentScreen('tools'));
4770: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4771: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4772: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4773: ' <span class="LC_nobreak">'.
4774: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4775: &mt('No').'</label>'.(' 'x2).
4776: '<label><input type="radio" name="checkstale" value="1" />'.
4777: &mt('Yes').'</label></span></p><p>'.
1.484.2.85.2. (raeburn 4778:): '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4779: '<input type="hidden" value="1" name="tools" />'.
4780: '<input type="hidden" value="1" name="verify" /></p></form>');
4781: $r->print(&endContentScreen());
4782: return;
4783: }
1.329 droeschl 4784:
4785: sub verifycontent {
1.484.2.78 raeburn 4786: my ($r,$checkstale) = @_;
1.408 raeburn 4787: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4788: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4789: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4790: $r->print(&startContentScreen('tools'));
4791: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4792: $hashtied=0;
4793: undef %alreadyseen;
4794: %alreadyseen=();
4795: &tiehash();
1.484 raeburn 4796:
1.329 droeschl 4797: foreach my $key (keys(%hash)) {
4798: if ($hash{$key}=~/\.(page|sequence)$/) {
4799: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4800: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4801: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4802: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4803: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4804: }
4805: }
4806: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4807: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4808: }
4809: }
4810: &untiehash();
1.442 www 4811: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4812: $r->print(&endContentScreen());
1.329 droeschl 4813: }
4814:
4815:
4816: sub devalidateversioncache {
4817: my $src=shift;
4818: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4819: &Apache::lonnet::clutter($src));
4820: }
4821:
4822: sub checkversions {
1.484.2.67 raeburn 4823: my ($r,$canedit) = @_;
1.408 raeburn 4824: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4825: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4826: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4827: $r->print(&startContentScreen('tools'));
1.442 www 4828:
1.329 droeschl 4829: my $header='';
4830: my $startsel='';
4831: my $monthsel='';
4832: my $weeksel='';
4833: my $daysel='';
4834: my $allsel='';
4835: my %changes=();
4836: my $starttime=0;
4837: my $haschanged=0;
4838: my %setversions=&Apache::lonnet::dump('resourceversions',
4839: $env{'course.'.$env{'request.course.id'}.'.domain'},
4840: $env{'course.'.$env{'request.course.id'}.'.num'});
4841:
4842: $hashtied=0;
4843: &tiehash();
1.484.2.67 raeburn 4844: if ($canedit) {
4845: my %newsetversions=();
4846: if ($env{'form.setmostrecent'}) {
4847: $haschanged=1;
4848: foreach my $key (keys(%hash)) {
4849: if ($key=~/^ids\_(\/res\/.+)$/) {
4850: $newsetversions{$1}='mostrecent';
4851: &devalidateversioncache($1);
4852: }
1.329 droeschl 4853: }
1.484.2.67 raeburn 4854: } elsif ($env{'form.setcurrent'}) {
4855: $haschanged=1;
4856: foreach my $key (keys(%hash)) {
4857: if ($key=~/^ids\_(\/res\/.+)$/) {
4858: my $getvers=&Apache::lonnet::getversion($1);
4859: if ($getvers>0) {
4860: $newsetversions{$1}=$getvers;
4861: &devalidateversioncache($1);
4862: }
4863: }
1.329 droeschl 4864: }
1.484.2.67 raeburn 4865: } elsif ($env{'form.setversions'}) {
4866: $haschanged=1;
4867: foreach my $key (keys(%env)) {
4868: if ($key=~/^form\.set_version_(.+)$/) {
4869: my $src=$1;
4870: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4871: $newsetversions{$src}=$env{$key};
4872: &devalidateversioncache($src);
4873: }
4874: }
1.329 droeschl 4875: }
1.484.2.67 raeburn 4876: }
4877: if ($haschanged) {
4878: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4879: $env{'course.'.$env{'request.course.id'}.'.domain'},
4880: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4881: $r->print(&Apache::loncommon::confirmwrapper(
4882: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4883: } else {
4884: $r->print(&Apache::loncommon::confirmwrapper(
4885: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4886: }
4887: &mark_hash_old();
4888: }
4889: &changewarning($r,'');
1.329 droeschl 4890: }
4891: if ($env{'form.timerange'} eq 'all') {
4892: # show all documents
1.484.2.34 raeburn 4893: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4894: $allsel=' selected="selected"';
1.329 droeschl 4895: foreach my $key (keys(%hash)) {
4896: if ($key=~/^ids\_(\/res\/.+)$/) {
4897: my $src=$1;
4898: $changes{$src}=1;
4899: }
4900: }
4901: } else {
4902: # show documents which changed
4903: %changes=&Apache::lonnet::dump
4904: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4905: $env{'course.'.$env{'request.course.id'}.'.num'});
4906: my $firstkey=(keys(%changes))[0];
4907: unless ($firstkey=~/^error\:/) {
4908: unless ($env{'form.timerange'}) {
4909: $env{'form.timerange'}=604800;
4910: }
4911: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4912: .&mt('seconds');
4913: if ($env{'form.timerange'}==-1) {
4914: $seltext='since start of course';
1.484.2.19 raeburn 4915: $startsel=' selected="selected"';
1.329 droeschl 4916: $env{'form.timerange'}=time;
4917: }
4918: $starttime=time-$env{'form.timerange'};
4919: if ($env{'form.timerange'}==2592000) {
4920: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4921: $monthsel=' selected="selected"';
1.329 droeschl 4922: } elsif ($env{'form.timerange'}==604800) {
4923: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4924: $weeksel=' selected="selected"';
1.329 droeschl 4925: } elsif ($env{'form.timerange'}==86400) {
4926: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4927: $daysel=' selected="selected"';
1.329 droeschl 4928: }
4929: $header=&mt('Content changed').' '.$seltext;
4930: } else {
4931: $header=&mt('No content modifications yet.');
4932: }
4933: }
4934: %setversions=&Apache::lonnet::dump('resourceversions',
4935: $env{'course.'.$env{'request.course.id'}.'.domain'},
4936: $env{'course.'.$env{'request.course.id'}.'.num'});
4937: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4938: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4939: 'lm' => 'Version changes since last Month',
4940: 'lw' => 'Version changes since last Week',
4941: 'sy' => 'Version changes since Yesterday',
4942: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4943: 'cd' => 'Change display',
1.329 droeschl 4944: 'sd' => 'Display',
4945: 'fi' => 'File',
4946: 'md' => 'Modification Date',
4947: 'mr' => 'Most recently published Version',
1.408 raeburn 4948: 've' => 'Version used in '.$crstype,
4949: 'vu' => 'Set Version to be used in '.$crstype,
4950: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4951: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4952: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4953: 'di' => 'Differences',
1.484 raeburn 4954: 'save' => 'Save changes',
4955: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4956: 'act' => 'Actions');
1.484.2.67 raeburn 4957: my ($disabled,$readonly);
4958: unless ($canedit) {
4959: $disabled = 'disabled="disabled"';
4960: $readonly = 1;
4961: }
1.329 droeschl 4962: $r->print(<<ENDHEADERS);
1.484 raeburn 4963: <h4 class="LC_info">$header</h4>
1.329 droeschl 4964: <form action="/adm/coursedocs" method="post">
4965: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4966: <div class="LC_left_float">
1.479 golterma 4967: <fieldset>
1.484 raeburn 4968: <legend>$lt{'cd'}</legend>
1.329 droeschl 4969: <select name="timerange">
1.484.2.19 raeburn 4970: <option value='all'$allsel>$lt{'al'}</option>
4971: <option value="-1"$startsel>$lt{'st'}</option>
4972: <option value="2592000"$monthsel>$lt{'lm'}</option>
4973: <option value="604800"$weeksel>$lt{'lw'}</option>
4974: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4975: </select>
4976: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4977: </fieldset>
4978: </div>
4979: <div class="LC_left_float">
4980: <fieldset>
4981: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4982: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4983: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4984: </fieldset>
4985: </div>
4986: <br clear="all" />
4987: <hr />
4988: <h4>$lt{'vers'}</h4>
1.329 droeschl 4989: ENDHEADERS
1.479 golterma 4990: #number of columns for version history
1.484.2.44 raeburn 4991: my %changedbytime;
4992: foreach my $key (keys(%changes)) {
4993: #excludes not versionable problems from resource version history:
4994: next if ($key =~ /^\/res\/lib\/templates/);
4995: my $chg;
4996: if ($env{'form.timerange'} eq 'all') {
4997: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4998: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4999: } else {
5000: $chg = $changes{$key};
5001: next if ($chg < $starttime);
5002: }
5003: push(@{$changedbytime{$chg}},$key);
5004: }
5005: if (keys(%changedbytime) == 0) {
5006: &untiehash();
5007: $r->print(&mt('No content changes in imported content in specified time frame').
5008: &endContentScreen());
5009: return;
5010: }
1.479 golterma 5011: $r->print(
1.484.2.67 raeburn 5012: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5013: &Apache::loncommon::start_data_table().
5014: &Apache::loncommon::start_data_table_header_row().
5015: '<th>'.&mt('Resources').'</th>'.
5016: "<th>$lt{'mr'}</th>".
5017: "<th>$lt{'ve'}</th>".
5018: "<th>$lt{'vu'}</th>".
5019: '<th>'.&mt('History').'</th>'.
5020: &Apache::loncommon::end_data_table_header_row()
5021: );
1.484.2.44 raeburn 5022: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5023: foreach my $key (sort(@{$changedbytime{$chg}})) {
5024: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5025: my $currentversion=&Apache::lonnet::getversion($key);
5026: if ($currentversion<0) {
5027: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5028: }
5029: my $linkurl=&Apache::lonnet::clutter($key);
5030: $r->print(
5031: &Apache::loncommon::start_data_table_row().
5032: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5033: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5034: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5035: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5036: '<td align="right">'
5037: );
5038: # Used in course
5039: my $usedversion=$hash{'version_'.$linkurl};
5040: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 5041: if ($usedversion != $currentversion) {
1.479 golterma 5042: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 5043: } else {
1.479 golterma 5044: $r->print($usedversion);
5045: }
1.329 droeschl 5046: } else {
1.484.2.19 raeburn 5047: $r->print($currentversion);
1.329 droeschl 5048: }
1.484.2.44 raeburn 5049: $r->print('</td><td title="'.$lt{'vu'}.'">');
5050: # Set version
5051: $r->print(&Apache::loncommon::select_form(
5052: $setversions{$linkurl},
5053: 'set_version_'.$linkurl,
5054: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5055: '' => '',
5056: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 5057: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 5058: my $lastold=1;
5059: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5060: my $url=$root.'.'.$prevvers.'.'.$extension;
5061: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5062: $lastold=$prevvers;
5063: }
5064: }
5065: $r->print('</td>');
5066: # List all available versions
5067: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5068: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5069: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 5070: $r->print(
1.484.2.44 raeburn 5071: '<span class="LC_nobreak">'
5072: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5073: .&mt('Version [_1]',$prevvers).'</a>'
5074: .' ('.&Apache::lonlocal::locallocaltime(
5075: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5076: .')');
5077: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5078: $r->print(
5079: ' <a href="/adm/diff?filename='.
5080: &Apache::lonnet::clutter($root.'.'.$extension).
5081: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5082: '" target="diffs">'.&mt('Diffs').'</a>');
5083: }
5084: $r->print('</span><br />');
1.329 droeschl 5085: }
1.484.2.44 raeburn 5086: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 5087: }
1.329 droeschl 5088: }
1.484.2.19 raeburn 5089: $r->print(
5090: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 5091: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5092: '</form>'
5093: );
1.329 droeschl 5094:
5095: &untiehash();
1.484.2.19 raeburn 5096: $r->print(&endContentScreen());
1.484.2.44 raeburn 5097: return;
1.329 droeschl 5098: }
5099:
5100: sub mark_hash_old {
5101: my $retie_hash=0;
5102: if ($hashtied) {
5103: $retie_hash=1;
5104: &untiehash();
5105: }
5106: &tiehash('write');
5107: $hash{'old'}=1;
5108: &untiehash();
5109: if ($retie_hash) { &tiehash(); }
5110: }
5111:
5112: sub is_hash_old {
5113: my $untie_hash=0;
5114: if (!$hashtied) {
5115: $untie_hash=1;
5116: &tiehash();
5117: }
5118: my $return=$hash{'old'};
5119: if ($untie_hash) { &untiehash(); }
5120: return $return;
5121: }
5122:
5123: sub changewarning {
5124: my ($r,$postexec,$message,$url)=@_;
5125: if (!&is_hash_old()) { return; }
5126: my $pathvar='folderpath';
5127: my $path=&escape($env{'form.folderpath'});
5128: if (!defined($url)) {
5129: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5130: }
5131: my $course_type = &Apache::loncommon::course_type();
5132: if (!defined($message)) {
5133: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5134: }
5135: $r->print("\n\n".
1.372 bisitz 5136: '<script type="text/javascript">'."\n".
5137: '// <![CDATA['."\n".
5138: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5139: '// ]]>'."\n".
1.369 bisitz 5140: '</script>'."\n".
1.375 tempelho 5141: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5142: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5143: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5144: &mt($message,' <input type="hidden" name="'.
5145: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5146: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5147: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5148: }
5149:
5150:
5151: sub init_breadcrumbs {
1.484.2.44 raeburn 5152: my ($form,$text,$help)=@_;
1.329 droeschl 5153: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5154: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5155: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5156: faq=>273,
5157: bug=>'Instructor Interface',
1.484.2.44 raeburn 5158: help => $help});
1.329 droeschl 5159: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5160: text=>$text,
5161: faq=>273,
5162: bug=>'Instructor Interface'});
5163: }
5164:
1.441 www 5165: # subroutine to list form elements
5166: sub create_list_elements {
5167: my @formarr = @_;
5168: my $list = '';
1.484.2.12 raeburn 5169: foreach my $button (@formarr){
5170: foreach my $picture (keys(%{$button})) {
5171: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5172: }
5173: }
5174: return $list;
5175: }
1.329 droeschl 5176:
1.441 www 5177: # subroutine to create ul from list elements
5178: sub create_form_ul {
5179: my $list = shift;
5180: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5181: return $ul;
5182: }
1.329 droeschl 5183:
1.442 www 5184: #
5185: # Start tabs
5186: #
5187:
5188: sub startContentScreen {
1.484 raeburn 5189: my ($mode) = @_;
5190: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5191: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5192: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5193: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5194: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5195: } else {
1.484.2.34 raeburn 5196: $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 5197: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5198: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5199: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5200: }
5201: $output .= "\n".'</ul>'."\n";
5202: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5203: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5204: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5205: return $output;
1.442 www 5206: }
5207:
5208: #
5209: # End tabs
5210: #
5211:
5212: sub endContentScreen {
1.484 raeburn 5213: return '</div></div></div>';
1.442 www 5214: }
1.329 droeschl 5215:
1.446 www 5216: sub supplemental_base {
1.484.2.33 raeburn 5217: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5218: }
5219:
1.329 droeschl 5220: sub handler {
5221: my $r = shift;
5222: &Apache::loncommon::content_type($r,'text/html');
5223: $r->send_http_header;
5224: return OK if $r->header_only;
1.484 raeburn 5225:
5226: # get course data
1.408 raeburn 5227: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5228: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5229: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5230:
5231: # graphics settings
5232: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5233:
1.443 www 5234: #
1.329 droeschl 5235: # --------------------------------------------- Initialize help topics for this
5236: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.484.2.85.2. (raeburn 5237:): 'Adding_External_Resource','Adding_External_Tool',
5238:): 'Navigate_Content','Adding_Folders','Docs_Overview',
5239:): 'Load_Map','Supplemental','Score_Upload_Form',
5240:): 'Adding_Pages','Importing_LON-CAPA_Resource',
5241:): 'Importing_IMS_Course','Uploading_From_Harddrive',
5242:): 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5243: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5244: }
5245: # Composite help files
5246: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5247: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5248: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5249: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5250: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5251: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5252: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5253: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5254: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5255: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5256:
1.484.2.67 raeburn 5257: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5258: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5259: unless ($r->uri eq '/adm/supplemental') {
5260: # does this user have privileges to modify content.
1.484.2.67 raeburn 5261: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5262: $allowed = 1;
5263: $canedit = 1;
5264: $canview = 1;
5265: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5266: $allowed = 1;
5267: $canview = 1;
5268: }
5269: }
5270: unless ($canedit) {
5271: $disabled = ' disabled="disabled"';
1.472 raeburn 5272: }
1.484.2.53 raeburn 5273: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5274: if ($env{'form.inhibitmenu'}) {
5275: unless ($env{'form.inhibitmenu'} eq 'yes') {
5276: delete($env{'form.inhibitmenu'});
5277: }
5278: }
5279:
1.484.2.53 raeburn 5280: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5281: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5282: if (!$canedit) {
5283: &verifycontent($r);
5284: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5285: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5286: text=>'Results',
5287: faq=>273,
5288: bug=>'Instructor Interface'});
5289: &verifycontent($r,$env{'form.checkstale'});
5290: } else {
5291: &contentverifyform($r);
5292: }
1.329 droeschl 5293: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5294: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5295: &list_symbs($r);
1.484.2.85.2. (raeburn 5296:): } elsif ($allowed && $env{'form.shorturls'}) {
5297:): &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5298:): &short_urls($r,$canedit);
1.329 droeschl 5299: } elsif ($allowed && $env{'form.docslog'}) {
5300: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5301: my $folder = $env{'form.folder'};
5302: if ($folder eq '') {
5303: $folder='default';
5304: }
1.484.2.67 raeburn 5305: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5306: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5307: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5308: &checkversions($r,$canedit);
5309: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5310: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5311: &dumpcourse($r);
5312: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5313: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5314: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5315: } else {
1.445 www 5316: #
5317: # Done catching special calls
1.484 raeburn 5318: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5319: # Get the parameters that may be needed
5320: #
5321: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5322: ['folderpath',
5323: 'forcesupplement','forcestandard',
5324: 'tools','symb','command','supppath']);
1.445 www 5325:
1.484.2.78 raeburn 5326: foreach my $item ('forcesupplement','forcestandard','tools') {
5327: next if ($env{'form.'.$item} eq '');
5328: unless ($env{'form.'.$item} eq '1') {
5329: delete($env{'form.'.$item});
5330: }
5331: }
5332:
5333: if ($env{'form.command'}) {
5334: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5335: delete($env{'form.command'});
5336: }
5337: }
5338:
5339: if ($env{'form.symb'}) {
5340: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5341: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5342: delete($env{'form.symb'});
5343: }
5344: }
5345:
1.445 www 5346: # standard=1: this is a "new-style" course with an uploaded map as top level
5347: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5348:
5349: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5350:
1.484 raeburn 5351: # Decide whether this should display supplemental or main content or utilities
1.445 www 5352: # supplementalflag=1: show supplemental documents
5353: # supplementalflag=0: show standard documents
1.484 raeburn 5354: # toolsflag=1: show utilities
1.445 www 5355:
1.484.2.39 raeburn 5356: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5357: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5358: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5359: $supplementalflag=0;
5360: }
5361: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5362: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5363: unless ($allowed) { $supplementalflag=1; }
5364: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5365: my $toolsflag=0;
5366: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5367:
1.484.2.78 raeburn 5368: if ($env{'form.folderpath'} ne '') {
5369: my @items = split(/\&/,$env{'form.folderpath'});
5370: my $badpath;
5371: for (my $i=0; $i<@items; $i++) {
5372: my $odd = $i%2;
5373: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5374: $badpath = 1;
5375: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5376: $badpath = 1;
5377: }
5378: last if ($badpath);
5379: }
5380: if ($badpath) {
5381: delete($env{'form.folderpath'});
5382: }
5383: }
5384:
5385: if ($env{'form.supppath'} ne '') {
5386: my @items = split(/\&/,$env{'form.supppath'});
5387: my $badpath;
5388: for (my $i=0; $i<@items; $i++) {
5389: my $odd = $i%2;
5390: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5391: $badpath = 1;
5392: }
5393: last if ($badpath);
5394: }
5395: if ($badpath) {
5396: delete($env{'form.supppath'});
5397: }
5398: }
5399:
1.329 droeschl 5400: my $script='';
5401: my $showdoc=0;
1.457 raeburn 5402: my $addentries = {};
1.475 raeburn 5403: my $container;
1.329 droeschl 5404: my $containertag;
1.484.2.17 raeburn 5405: my $pathitem;
1.484.2.85.2. (raeburn 5406:): my %ltitools;
1.484.2.67 raeburn 5407: my $hiddentop;
5408: my $navmap;
5409: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5410:
1.464 www 5411: # Do we directly jump somewhere?
1.484.2.21 raeburn 5412: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5413: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5414: $env{'form.folderpath'}=
1.484.2.67 raeburn 5415: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5416: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5417: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5418: } elsif ($env{'form.supppath'} ne '') {
5419: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5420: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5421: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5422: }
1.472 raeburn 5423: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5424: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5425: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5426: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5427: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5428: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5429: } elsif ($env{'form.command'} eq 'contents') {
5430: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5431: } elsif ($env{'form.command'} eq 'home') {
5432: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5433: }
5434:
1.484.2.23 raeburn 5435:
1.445 www 5436: # Where do we store these for when we come back?
5437: my $stored_folderpath='docs_folderpath';
5438: if ($supplementalflag) {
5439: $stored_folderpath='docs_sup_folderpath';
5440: }
1.464 www 5441:
1.484.2.19 raeburn 5442: # No folderpath, and in edit mode, see if we have something stored
5443: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5444: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5445: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5446:
5447: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5448: if ($supplementalflag) {
5449: undef($env{'form.folderpath'}) if ($1 eq 'default');
5450: } else {
5451: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5452: }
5453: } else {
1.484.2.19 raeburn 5454: undef($env{'form.folderpath'});
5455: }
1.329 droeschl 5456: }
1.446 www 5457:
5458: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5459: if (!$allowed) {
1.446 www 5460: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5461: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5462: }
5463: }
1.446 www 5464: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5465: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5466: $env{'form.folderpath'} = &supplemental_base()
5467: .'&'.
1.329 droeschl 5468: $env{'form.folderpath'};
5469: }
1.484.2.67 raeburn 5470: # If allowed and user's role is not advanced check folderpath is not hidden
5471: if (($allowed) && (!$env{'request.role.adv'}) &&
5472: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5473: my $folderurl;
5474: my @pathitems = split(/\&/,$env{'form.folderpath'});
5475: my $folder = $pathitems[-2];
5476: if ($folder eq '') {
5477: undef($env{'form.folderpath'});
5478: } else {
5479: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.85.2. (raeburn 5480:): if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5481: $folderurl .= '.page';
5482: } else {
5483: $folderurl .= '.sequence';
5484: }
5485: unless (ref($navmap)) {
5486: $navmap = Apache::lonnavmaps::navmap->new();
5487: }
5488: if (ref($navmap)) {
5489: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5490: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5491: unless (@resources) {
5492: undef($env{'form.folderpath'});
5493: }
5494: }
5495: }
5496: }
5497: }
5498:
5499:
1.446 www 5500: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5501: unless ($env{'form.folderpath'}) {
1.446 www 5502: if ($supplementalflag) {
5503: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5504: } elsif ($allowed) {
5505: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5506: }
1.472 raeburn 5507: }
1.446 www 5508:
1.445 www 5509: # Store this
1.484 raeburn 5510: unless ($toolsflag) {
1.484.2.67 raeburn 5511: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5512: &Apache::loncommon::store_course_settings($stored_folderpath,
5513: {'folderpath' => 'scalar'});
5514: }
5515: my $folderpath;
1.484 raeburn 5516: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5517: $folderpath = $env{'form.folderpath'};
5518: my (@folders)=split('&',$env{'form.folderpath'});
5519: $env{'form.foldername'}=&unescape(pop(@folders));
5520: if ($env{'form.foldername'} =~ /\:1$/) {
5521: $container = 'page';
5522: } else {
5523: $container = 'sequence';
5524: }
5525: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5526: } else {
1.484.2.19 raeburn 5527: if ($env{'form.folder'} eq '' ||
5528: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5529: if ($env{'form.folder'} eq 'supplemental') {
5530: $folderpath=&supplemental_base();
5531: } elsif (!$hiddentop) {
5532: $folderpath='default&'.
5533: &escape(&mt('Main Content').':::::');
5534: }
1.484 raeburn 5535: }
5536: }
1.484.2.19 raeburn 5537: $containertag = '<input type="hidden" name="folderpath" value="" />';
5538: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5539: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5540: $showdoc='/'.$1;
5541: }
5542: if ($showdoc) { # got called in sequence from course
5543: $allowed=0;
5544: } else {
1.484.2.67 raeburn 5545: if ($canedit) {
1.484 raeburn 5546: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5547: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5548: }
5549: }
1.329 droeschl 5550: }
5551:
1.344 bisitz 5552: # get personal data
1.329 droeschl 5553: my $uname=$env{'user.name'};
5554: my $udom=$env{'user.domain'};
5555: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5556:
5557: if ($allowed) {
1.484 raeburn 5558: if ($toolsflag) {
5559: $script .= &inject_data_js();
5560: my ($home,$other,%outhash)=&authorhosts();
5561: if (!$home && $other) {
5562: my @hosts;
5563: foreach my $aurole (keys(%outhash)) {
5564: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5565: push(@hosts,$outhash{$aurole});
5566: }
5567: }
5568: $script .= &dump_switchserver_js(@hosts);
5569: }
1.458 raeburn 5570: } else {
1.484.2.43 raeburn 5571: my $tid = 1;
1.484 raeburn 5572: my @tabids;
5573: if ($supplementalflag) {
5574: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5575: $tid = 2;
1.484 raeburn 5576: } else {
5577: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5578: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5579: unshift(@tabids,'001');
5580: push(@tabids,('dd1','ee1'));
5581: }
1.458 raeburn 5582: }
1.484 raeburn 5583: my $tabidstr = join("','",@tabids);
1.484.2.85.2. (raeburn 5584:): %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5585:): my $posslti = keys(%ltitools);
1.484.2.80 raeburn 5586: my $hostname = $r->hostname();
1.484.2.85.2. (raeburn 5587:): $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 5588: $canedit,$hostname,\$navmap).
1.484 raeburn 5589: &history_tab_js().
5590: &inject_data_js().
1.484.2.43 raeburn 5591: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.85.2. (raeburn 5592:): &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5593: $addentries = {
1.484.2.3 raeburn 5594: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5595: };
1.458 raeburn 5596: }
1.484.2.30 raeburn 5597: $script .= &paste_popup_js();
1.484.2.12 raeburn 5598: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5599: &mt('Switch server?');
1.484.2.19 raeburn 5600:
5601:
1.329 droeschl 5602: }
5603: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5604: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5605: .'// <![CDATA['."\n"
5606: .$script."\n"
5607: .'// ]]>'."\n"
1.484.2.81 raeburn 5608: .'</script>'."\n"
5609: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5610:
5611: # Breadcrumbs
5612: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5613:
5614: if ($showdoc) {
5615: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5616: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5617: } elsif ($toolsflag) {
1.484.2.67 raeburn 5618: my ($breadtext,$breadtitle);
5619: $breadtext = "$crstype Editor";
5620: if ($canedit) {
5621: $breadtitle = 'Editing '.$crstype.' Contents';
5622: } else {
5623: $breadtext .= ' (View-only mode)';
5624: $breadtitle = 'Viewing '.$crstype.' Contents';
5625: }
1.484.2.44 raeburn 5626: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5627: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5628: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5629: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5630: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5631: $breadtitle)
1.484.2.44 raeburn 5632: );
1.484.2.19 raeburn 5633: } elsif ($r->uri eq '/adm/supplemental') {
5634: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5635: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5636: {'bread_crumbs' => $brcrum,}));
5637: } else {
1.484.2.67 raeburn 5638: my ($breadtext,$breadtitle,$helpitem);
5639: $breadtext = "$crstype Editor";
5640: if ($canedit) {
5641: $breadtitle = 'Editing '.$crstype.' Contents';
5642: $helpitem = 'Docs_Adding_Course_Doc';
5643: } else {
5644: $breadtext .= ' (View-only mode)';
5645: $breadtitle = 'Viewing '.$crstype.' Contents';
5646: $helpitem = 'Docs_Viewing_Course_Doc';
5647: }
1.392 raeburn 5648: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5649: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5650: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5651: {'add_entries' => $addentries}
5652: )
1.392 raeburn 5653: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5654: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5655: $breadtitle,
5656: $helpitem)
1.392 raeburn 5657: );
5658: }
1.364 bisitz 5659:
1.329 droeschl 5660: my %allfiles = ();
5661: my %codebase = ();
1.440 raeburn 5662: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5663: if ($canedit) {
1.329 droeschl 5664: if (($env{'form.uploaddoc.filename'}) &&
5665: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5666: my $context = $1;
5667: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5668: undef($hadchanges);
1.440 raeburn 5669: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5670: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5671: undef($navmap);
1.329 droeschl 5672: if ($hadchanges) {
5673: &mark_hash_old();
5674: }
1.440 raeburn 5675: $r->print($upload_output);
5676: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5677: # Process file upload - phase two - upload embedded objects
5678: $uploadphase = 'check_embedded';
5679: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5680: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5681: $env{'form.newidx'});
5682: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5683: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5684: my ($destination,$dir_root) = &embedded_destination();
5685: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5686: my $actionurl = '/adm/coursedocs';
5687: my ($result,$flag) =
5688: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5689: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5690: $actionurl);
5691: $r->print($result.&return_to_editor());
5692: } elsif ($env{'form.phase'} eq 'check_embedded') {
5693: # Process file upload - phase three - modify references in HTML file
5694: $uploadphase = 'modified_orightml';
5695: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5696: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5697: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5698: my $result =
5699: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5700: $docuname,$docudom,undef,
5701: $dir_root);
5702: $r->print($result.&return_to_editor());
1.476 raeburn 5703: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5704: $uploadphase = 'decompress_phase_one';
5705: $r->print(&decompression_phase_one().
5706: &return_to_editor());
5707: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5708: $uploadphase = 'decompress_phase_two';
5709: $r->print(&decompression_phase_two().
5710: &return_to_editor());
1.329 droeschl 5711: }
5712: }
5713:
1.484 raeburn 5714: if ($allowed && $toolsflag) {
5715: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5716: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5717: $r->print(&endContentScreen());
5718: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5719: # -----------------------------------------------------------------------------
5720: my %lt=&Apache::lonlocal::texthash(
5721: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5722: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5723: 'upld' => 'Upload Content',
1.329 droeschl 5724: 'srch' => 'Search',
5725: 'impo' => 'Import',
1.484.2.19 raeburn 5726: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5727: 'impm' => 'Import from Assembled Map',
1.484.2.85.2. (raeburn 5728:): 'extr' => 'External Resource',
5729:): 'extt' => 'External Tool',
1.329 droeschl 5730: 'selm' => 'Select Map',
5731: 'load' => 'Load Map',
5732: 'newf' => 'New Folder',
5733: 'newp' => 'New Composite Page',
5734: 'syll' => 'Syllabus',
1.425 raeburn 5735: 'navc' => 'Table of Contents',
1.343 biermanm 5736: 'sipa' => 'Simple Course Page',
1.329 droeschl 5737: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5738: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5739: 'drbx' => 'Drop Box',
1.451 www 5740: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5741: 'bull' => 'Discussion Board',
1.347 weissno 5742: 'mypi' => 'My Personal Information Page',
1.353 weissno 5743: 'grpo' => 'Group Portfolio',
1.329 droeschl 5744: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5745: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5746: 'imsf' => 'IMS Upload',
5747: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5748: 'cms' => 'Origin of IMS package',
5749: 'se' => 'Select',
1.484.2.19 raeburn 5750: 'file' => 'File',
1.329 droeschl 5751: 'title' => 'Title',
5752: 'comment' => 'Comment',
1.403 raeburn 5753: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5754: 'bb5' => 'Blackboard 5',
5755: 'bb6' => 'Blackboard 6',
5756: 'angel5' => 'ANGEL 5.5',
5757: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5758: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5759: );
1.329 droeschl 5760: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5761: # Calculate free quota space for a user or course. A javascript function checks
5762: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5763: my $quotatype = 'unofficial';
5764: if ($crstype eq 'Community') {
5765: $quotatype = 'community';
5766: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5767: $quotatype = 'official';
5768: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5769: $quotatype = 'textbook';
5770: }
5771: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5772: 'course',$quotatype); # expressed in MB
5773: my $current_disk_usage = 0;
5774: foreach my $subdir ('docs','supplemental') {
5775: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5776: "userfiles/$subdir",1); # expressed in kB
5777: }
5778: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5779: my $usage = $current_disk_usage/1024; # in MB
5780: my $quota = $disk_quota;
5781: my $percent;
5782: if ($disk_quota == 0) {
5783: $percent = 100.0;
5784: } else {
1.484.2.69 raeburn 5785: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5786: }
5787: $usage = sprintf("%.2f",$usage);
5788: $quota = sprintf("%.2f",$quota);
5789: $percent = sprintf("%.0f",$percent);
5790: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5791: $percent.'%',$quota.' MB').'</p>';
5792:
1.329 droeschl 5793: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5794: $quotainfo
1.329 droeschl 5795: $lt{'file'}:<br />
1.484.2.81 raeburn 5796: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5797: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5798: FIUP
5799:
5800: my $checkbox=(<<CHBO);
5801: <!-- <label>$lt{'parse'}?
5802: <input type="checkbox" name="parserflag" />
5803: </label> -->
5804: <label>
1.484.2.67 raeburn 5805: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5806: </label>
5807: CHBO
1.484.2.12 raeburn 5808: my $imsfolder = $env{'form.folder'};
5809: if ($imsfolder eq '') {
1.484.2.19 raeburn 5810: $imsfolder = 'default';
1.484.2.12 raeburn 5811: }
5812: my $imspform=(<<IMSFORM);
5813: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5814: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5815: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5816: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5817: <legend>$lt{'imsf'}</legend>
5818: $fileupload
5819: <br />
5820: <p>
1.484.2.19 raeburn 5821: $lt{'cms'}:
1.484.2.67 raeburn 5822: <select name="source" $disabled>
1.484.2.12 raeburn 5823: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5824: <option value="bb5">$lt{'bb5'}</option>
5825: <option value="bb6">$lt{'bb6'}</option>
5826: <option value="angel5">$lt{'angel5'}</option>
5827: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5828: </select>
5829: <input type="hidden" name="folder" value="$imsfolder" />
5830: </p>
5831: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5832: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5833: </fieldset>
5834: </form>
5835: IMSFORM
5836:
1.484.2.19 raeburn 5837: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5838: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5839: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5840: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5841: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5842: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5843: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5844: $fileupload
5845: <br />
5846: $lt{'title'}:<br />
1.484.2.67 raeburn 5847: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5848: $pathitem
1.329 droeschl 5849: <input type="hidden" name="cmd" value="upload_default" />
5850: <br />
1.458 raeburn 5851: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5852: $checkbox
5853: </span>
1.484.2.12 raeburn 5854: <br clear="all" />
1.484.2.67 raeburn 5855: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5856: </fieldset>
5857: </form>
1.383 tempelho 5858: FUFORM
1.329 droeschl 5859:
1.484.2.67 raeburn 5860: my $mapimportjs;
5861: if ($canedit) {
5862: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5863: } else {
5864: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5865: }
1.484.2.19 raeburn 5866: my $importpubform=(<<SEDFFORM);
5867: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5868: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5869: <form action="/adm/coursedocs" method="post" name="mapimportform">
5870: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5871: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5872: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5873: $lt{'copm'}<br />
5874: <span class="LC_nobreak">
1.484.2.19 raeburn 5875: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5876: onfocus="this.blur();$mapimportjs" $disabled />
5877: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5878: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5879: </fieldset>
5880: </form>
5881:
1.383 tempelho 5882: SEDFFORM
1.484.2.67 raeburn 5883:
5884: my $fromstoredjs;
5885: if ($canedit) {
5886: $fromstoredjs = 'open_StoredLinks_Import()';
5887: } else {
5888: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5889: }
5890:
1.484.2.19 raeburn 5891: my @importpubforma = (
5892: { '<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 5893: { '<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.484.2.67 raeburn 5894: { '<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.484.2.19 raeburn 5895: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5896: );
5897: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5898: my $extresourcesform =
5899: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5900: $help{'Adding_External_Resource'},
1.484.2.85.2. (raeburn 5901:): undef,undef,undef,undef,undef,undef,$disabled);
5902:): my $exttoolform =
5903:): &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5904:): $help{'Adding_External_Tool'},undef,
5905:): undef,'tool',$coursedom,$coursenum,
5906:): \%ltitools,$disabled);
1.329 droeschl 5907: if ($allowed) {
1.484.2.7 raeburn 5908: my $folder = $env{'form.folder'};
5909: if ($folder eq '') {
5910: $folder='default';
5911: }
1.484.2.67 raeburn 5912: if ($canedit) {
5913: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5914: if ($output) {
5915: $r->print($output);
5916: }
1.484.2.30 raeburn 5917: }
1.337 ehlerst 5918: $r->print(<<HIDDENFORM);
5919: <form name="renameform" method="post" action="/adm/coursedocs">
5920: <input type="hidden" name="title" />
5921: <input type="hidden" name="cmd" />
5922: <input type="hidden" name="markcopy" />
5923: <input type="hidden" name="copyfolder" />
5924: $containertag
5925: </form>
1.484 raeburn 5926:
1.337 ehlerst 5927: HIDDENFORM
1.484.2.17 raeburn 5928: $r->print(&makesimpleeditform($pathitem)."\n".
5929: &makedocslogform($pathitem."\n".
1.484 raeburn 5930: '<input type="hidden" name="folder" value="'.
5931: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5932: }
1.442 www 5933:
5934: # Generate the tabs
1.484.2.19 raeburn 5935: my ($mode,$needs_end);
1.472 raeburn 5936: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5937: my @folders = split('&',$env{'form.folderpath'});
5938: unless (@folders > 2) {
5939: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5940: $needs_end = 1;
5941: }
1.472 raeburn 5942: } else {
1.484 raeburn 5943: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5944: $needs_end = 1;
1.472 raeburn 5945: }
1.443 www 5946:
1.442 www 5947: #
5948:
5949: my $savefolderpath;
1.484.2.85.2. (raeburn 5950:): my $hostname = $r->hostname();
1.442 www 5951:
1.395 raeburn 5952: if ($allowed) {
1.329 droeschl 5953: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5954: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5955: $folder='default';
1.356 tempelho 5956: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5957: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5958: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5959: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5960: }
5961: my $postexec='';
5962: if ($folder eq 'default') {
1.372 bisitz 5963: $r->print('<script type="text/javascript">'."\n"
5964: .'// <![CDATA['."\n"
5965: .'this.window.name="loncapaclient";'."\n"
5966: .'// ]]>'."\n"
5967: .'</script>'."\n"
1.369 bisitz 5968: );
1.329 droeschl 5969: } else {
5970: #$postexec='self.close();';
5971: }
1.484.2.15 raeburn 5972: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5973: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5974: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5975:
5976: my $newnavform=(<<NNFORM);
5977: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5978: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5979: $pathitem
1.329 droeschl 5980: <input type="hidden" name="importdetail"
5981: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5982: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5983: $help{'Navigate_Content'}
5984: </form>
5985: NNFORM
5986: my $newsmppageform=(<<NSPFORM);
5987: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5988: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5989: $pathitem
1.329 droeschl 5990: <input type="hidden" name="importdetail" value="" />
1.423 onken 5991: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5992: $help{'Simple Page'}
1.329 droeschl 5993: </form>
5994: NSPFORM
5995:
5996: my $newsmpproblemform=(<<NSPROBFORM);
5997: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5998: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5999: $pathitem
1.329 droeschl 6000: <input type="hidden" name="importdetail" value="" />
1.423 onken 6001: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 6002: $help{'Simple_Problem'}
1.329 droeschl 6003: </form>
6004:
6005: NSPROBFORM
6006:
6007: my $newdropboxform=(<<NDBFORM);
6008: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6009: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6010: $pathitem
1.329 droeschl 6011: <input type="hidden" name="importdetail" value="" />
1.423 onken 6012: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 6013: $help{'Dropbox'}
1.344 bisitz 6014: </form>
1.329 droeschl 6015: NDBFORM
6016:
6017: my $newexuploadform=(<<NEXUFORM);
6018: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6019: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6020: $pathitem
1.329 droeschl 6021: <input type="hidden" name="importdetail" value="" />
1.423 onken 6022: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6023: $help{'Score_Upload_Form'}
6024: </form>
6025: NEXUFORM
6026:
6027: my $newbulform=(<<NBFORM);
6028: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 6029: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6030: $pathitem
1.329 droeschl 6031: <input type="hidden" name="importdetail" value="" />
1.423 onken 6032: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6033: $help{'Bulletin Board'}
6034: </form>
6035: NBFORM
6036:
6037: my $newaboutmeform=(<<NAMFORM);
6038: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 6039: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6040: $pathitem
1.329 droeschl 6041: <input type="hidden" name="importdetail"
6042: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6043: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6044: $help{'My Personal Information Page'}
1.329 droeschl 6045: </form>
6046: NAMFORM
6047:
6048: my $newaboutsomeoneform=(<<NASOFORM);
6049: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 6050: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6051: $pathitem
1.329 droeschl 6052: <input type="hidden" name="importdetail" value="" />
1.423 onken 6053: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6054: </form>
6055: NASOFORM
6056:
6057: my $newrosterform=(<<NROSTFORM);
6058: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 6059: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6060: $pathitem
1.329 droeschl 6061: <input type="hidden" name="importdetail"
6062: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 6063: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 6064: $help{'Course_Roster'}
1.329 droeschl 6065: </form>
6066: NROSTFORM
6067:
1.484.2.27 raeburn 6068: my $newwebpage;
6069: if ($folder =~ /^default_?(\d*)$/) {
6070: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6071: if ($1) {
6072: $newwebpage .= $1;
6073: } else {
6074: $newwebpage .= 'default';
6075: }
6076: $newwebpage .= '/new.html';
6077: }
6078: my $newwebpageform =(<<NWEBFORM);
6079: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 6080: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 6081: $pathitem
6082: <input type="hidden" name="importdetail" value="$newwebpage" />
6083: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 6084: $help{'Web_Page'}
1.484.2.27 raeburn 6085: </form>
6086: NWEBFORM
1.484.2.30 raeburn 6087:
1.484.2.27 raeburn 6088:
1.342 ehlerst 6089: my $specialdocumentsform;
1.383 tempelho 6090: my @specialdocumentsforma;
1.451 www 6091: my $gradingform;
6092: my @gradingforma;
6093: my $communityform;
6094: my @communityforma;
1.351 ehlerst 6095: my $newfolderform;
1.390 tempelho 6096: my $newfolderb;
1.342 ehlerst 6097:
1.451 www 6098: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6099:
1.329 droeschl 6100: my $newpageform=(<<NPFORM);
6101: <form action="/adm/coursedocs" method="post" name="newpage">
6102: <input type="hidden" name="folderpath" value="$path" />
6103: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6104: <input type="hidden" name="active" value="ee" />
1.423 onken 6105: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6106: $help{'Adding_Pages'}
1.329 droeschl 6107: </form>
6108: NPFORM
1.390 tempelho 6109:
6110:
1.351 ehlerst 6111: $newfolderform=(<<NFFORM);
1.329 droeschl 6112: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 6113: $pathitem
1.329 droeschl 6114: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6115: <input type="hidden" name="active" value="" />
1.422 onken 6116: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6117: </form>
6118: NFFORM
6119:
6120: my $newsylform=(<<NSYLFORM);
6121: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 6122: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6123: $pathitem
1.329 droeschl 6124: <input type="hidden" name="importdetail"
6125: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6126: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6127: $help{'Syllabus'}
1.383 tempelho 6128:
1.329 droeschl 6129: </form>
6130: NSYLFORM
1.364 bisitz 6131:
1.329 droeschl 6132: my $newgroupfileform=(<<NGFFORM);
6133: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 6134: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6135: $pathitem
1.329 droeschl 6136: <input type="hidden" name="importdetail"
6137: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 6138: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6139: $help{'Group Portfolio'}
1.329 droeschl 6140: </form>
6141: NGFFORM
1.484.2.85.2. (raeburn 6142:): if ($container eq 'page') {
6143:): @specialdocumentsforma=(
6144:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6145:): );
6146:): } else {
6147:): @specialdocumentsforma=(
1.421 onken 6148: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.484.2.67 raeburn 6149: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6150: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6151: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 6152: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.85.2. (raeburn 6153:): );
6154:): }
1.451 www 6155: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6156:
1.434 raeburn 6157:
6158: my @importdoc = (
1.484.2.19 raeburn 6159: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6160: );
1.484.2.85.2. (raeburn 6161:): if (keys(%ltitools)) {
6162:): push(@importdoc,
6163:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6164:): );
6165:): }
1.484.2.19 raeburn 6166: unless ($container eq 'page') {
6167: push(@importdoc,
6168: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6169: );
6170: }
6171: push(@importdoc,
1.484.2.38 raeburn 6172: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.484.2.19 raeburn 6173: );
1.484.2.12 raeburn 6174: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6175:
1.451 www 6176: @gradingforma=(
6177: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6178: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6179: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6180:
6181: );
6182: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6183:
6184: @communityforma=(
6185: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6186: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6187: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 6188: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6189: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6190: );
6191: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6192:
1.330 tempelho 6193: my %orderhash = (
1.484.2.36 raeburn 6194: 'aa' => ['Upload',$fileuploadform],
6195: 'bb' => ['Import',$importpubform],
6196: 'cc' => ['Grading',$gradingform],
1.484.2.85.2. (raeburn 6197:): 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 6198: );
1.484.2.19 raeburn 6199: unless ($container eq 'page') {
1.434 raeburn 6200: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6201: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 6202: }
6203:
1.341 ehlerst 6204: $hadchanges=0;
1.484 raeburn 6205: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6206: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6207: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.85.2. (raeburn 6208:): \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 6209: undef($navmap);
1.443 www 6210: if ($error) {
6211: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6212: }
6213: if ($hadchanges) {
1.484.2.73 raeburn 6214: unless (&is_hash_old()) {
6215: &mark_hash_old();
6216: }
1.443 www 6217: }
1.341 ehlerst 6218:
1.443 www 6219: &changewarning($r,'');
6220: }
1.458 raeburn 6221: }
1.442 www 6222:
1.443 www 6223: # Supplemental documents start here
6224:
1.329 droeschl 6225: my $folder=$env{'form.folder'};
1.443 www 6226: unless ($supplementalflag) {
1.329 droeschl 6227: $folder='supplemental';
6228: }
6229: if ($folder =~ /^supplemental$/ &&
6230: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6231: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6232: } elsif ($allowed) {
1.356 tempelho 6233: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6234: }
1.484.2.17 raeburn 6235: $pathitem = '<input type="hidden" name="folderpath" value="'.
6236: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6237: if ($allowed) {
6238: my $folderseq=
1.484.2.15 raeburn 6239: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6240:
6241: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6242: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6243: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6244: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6245: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6246: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6247: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6248: $fileupload
6249: <br />
6250: <br />
6251: <span class="LC_nobreak">
6252: $checkbox
6253: </span>
6254: <br /><br />
6255: $lt{'comment'}:<br />
1.383 tempelho 6256: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6257: <br />
1.484.2.19 raeburn 6258: $pathitem
1.329 droeschl 6259: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6260: <input type='submit' value="$lt{'upld'}" />
6261: </form>
1.484.2.19 raeburn 6262: SUPDOCFORM
1.329 droeschl 6263:
6264: my $supnewfolderform=(<<SNFFORM);
6265: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6266: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6267: $pathitem
1.329 droeschl 6268: <input type="hidden" name="importdetail" value="" />
1.423 onken 6269: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6270: $help{'Adding_Folders'}
1.329 droeschl 6271: </form>
6272: SNFFORM
1.383 tempelho 6273:
1.484.2.19 raeburn 6274: my $supextform =
6275: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6276: $help{'Adding_External_Resource'},
6277: undef,undef,$disabled);
1.484.2.85.2. (raeburn 6278:): my $supexttoolform =
6279:): &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6280:): $help{'Adding_External_Tool'},
6281:): undef,undef,'tool',$coursedom,
6282:): $coursenum,\%ltitools,$disabled);
1.329 droeschl 6283:
6284: my $supnewsylform=(<<SNSFORM);
6285: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6286: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6287: $pathitem
1.329 droeschl 6288: <input type="hidden" name="importdetail"
6289: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6290: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6291: $help{'Syllabus'}
6292: </form>
6293: SNSFORM
6294:
6295: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6296: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6297: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6298: $pathitem
1.329 droeschl 6299: <input type="hidden" name="importdetail"
6300: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6301: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6302: $help{'My Personal Information Page'}
1.329 droeschl 6303: </form>
6304: SNAMFORM
6305:
1.484.2.27 raeburn 6306: my $supwebpage;
6307: if ($folder =~ /^supplemental_?(\d*)$/) {
6308: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6309: if ($1) {
6310: $supwebpage .= $1;
6311: } else {
6312: $supwebpage .= 'default';
6313: }
6314: $supwebpage .= '/new.html';
6315: }
6316: my $supwebpageform =(<<SWEBFORM);
6317: <form action="/adm/coursedocs" method="post" name="supwebpage">
6318: <input type="hidden" name="active" value="cc" />
6319: $pathitem
6320: <input type="hidden" name="importdetail" value="$supwebpage" />
6321: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6322: $help{'Web_Page'}
1.484.2.27 raeburn 6323: </form>
6324: SWEBFORM
6325:
1.333 muellerd 6326:
1.383 tempelho 6327: my @specialdocs = (
1.484.2.67 raeburn 6328: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6329: =>$supnewsylform},
1.484.2.67 raeburn 6330: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6331: =>$supnewaboutmeform},
1.484.2.27 raeburn 6332: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6333:
1.383 tempelho 6334: );
1.417 droeschl 6335: my @supimportdoc = (
1.484.2.19 raeburn 6336: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.85.2. (raeburn 6337:): =>$supextform});
6338:): if (keys(%ltitools)) {
6339:): push(@supimportdoc,
6340:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6341:): =>$supexttoolform});
6342:): }
6343:): push(@supimportdoc,
1.484.2.12 raeburn 6344: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6345: =>$supupdocform},
1.484.2.85.2. (raeburn 6346:): );
1.484.2.19 raeburn 6347:
1.484.2.12 raeburn 6348: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6349: my %suporderhash = (
1.390 tempelho 6350: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6351: 'ee' => ['Upload',$supupdocform],
6352: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6353: );
1.443 www 6354: if ($supplementalflag) {
1.458 raeburn 6355: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6356: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.85.2. (raeburn 6357:): \%ltitools,$canedit,$hostname);
1.443 www 6358: if ($error) {
6359: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6360: } else {
6361: if ($suppchanges) {
6362: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6363: my @ids=&Apache::lonnet::current_machine_ids();
6364: foreach my $server (keys(%servers)) {
6365: next if (grep(/^\Q$server\E$/,@ids));
6366: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6367: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6368: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6369: }
6370: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6371: undef($suppchanges);
6372: }
1.443 www 6373: }
1.393 raeburn 6374: }
1.443 www 6375: } elsif ($supplementalflag) {
1.458 raeburn 6376: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6377: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6378: if ($error) {
6379: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6380: }
1.393 raeburn 6381: }
1.389 tempelho 6382:
1.484.2.19 raeburn 6383: if ($needs_end) {
6384: $r->print(&endContentScreen());
6385: }
1.383 tempelho 6386:
1.329 droeschl 6387: if ($allowed) {
6388: $r->print('
6389: <form method="post" name="extimport" action="/adm/coursedocs">
6390: <input type="hidden" name="title" />
6391: <input type="hidden" name="url" />
6392: <input type="hidden" name="useform" />
6393: <input type="hidden" name="residx" />
6394: </form>');
6395: }
1.484 raeburn 6396: } elsif ($showdoc) {
1.329 droeschl 6397: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6398: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6399: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6400: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6401: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6402: }
6403: }
6404: $r->print(&Apache::loncommon::end_page());
6405: return OK;
1.364 bisitz 6406: }
1.329 droeschl 6407:
1.440 raeburn 6408: sub embedded_form_elems {
6409: my ($phase,$primaryurl,$newidx) = @_;
6410: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6411: $newidx =~s /\D+//g;
1.440 raeburn 6412: return <<STATE;
6413: <input type="hidden" name="folderpath" value="$folderpath" />
6414: <input type="hidden" name="cmd" value="upload_embedded" />
6415: <input type="hidden" name="newidx" value="$newidx" />
6416: <input type="hidden" name="phase" value="$phase" />
6417: <input type="hidden" name="primaryurl" value="$primaryurl" />
6418: STATE
6419: }
6420:
6421: sub embedded_destination {
6422: my $folder=$env{'form.folder'};
6423: my $destination = 'docs/';
6424: if ($folder =~ /^supplemental/) {
6425: $destination = 'supplemental/';
6426: }
6427: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6428: $destination .= 'default/';
6429: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6430: $destination .= $2.'/';
6431: }
1.484.2.78 raeburn 6432: my $newidx = $env{'form.newidx'};
6433: $newidx =~s /\D+//g;
6434: if ($newidx) {
6435: $destination .= $newidx;
6436: }
1.440 raeburn 6437: my $dir_root = '/userfiles';
6438: return ($destination,$dir_root);
6439: }
6440:
6441: sub return_to_editor {
6442: my $actionurl = '/adm/coursedocs';
6443: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6444: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6445: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6446: '</a></p>';
6447: }
6448:
1.476 raeburn 6449: sub decompression_info {
6450: my ($destination,$dir_root) = &embedded_destination();
6451: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6452: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6453: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6454: my $container='sequence';
1.480 raeburn 6455: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6456: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6457: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6458: $container='page';
6459: }
1.480 raeburn 6460: unshift(@hiddens,$pathitem);
6461: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6462: if ($item eq 'newidx') {
6463: next if ($env{'form.'.$item} =~ /\D/);
6464: }
1.480 raeburn 6465: if ($env{'form.'.$item}) {
6466: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6467: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6468: }
1.477 raeburn 6469: }
1.476 raeburn 6470: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6471: $hiddenelem);
6472: }
6473:
6474: sub decompression_phase_one {
6475: my ($dir,$file,$warning,$error,$output);
6476: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6477: &decompression_info();
1.484.2.7 raeburn 6478: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6479: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6480: } else {
6481: my $file = $1;
1.481 raeburn 6482: $output =
6483: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6484: $destination,$dir_root,
6485: $hiddenelem);
6486: if ($env{'form.autoextract_camtasia'}) {
6487: $output .= &remove_archive($docudom,$docuname,$container);
6488: }
1.476 raeburn 6489: }
6490: if ($error) {
6491: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6492: $error.'</p>'."\n";
6493: }
6494: if ($warning) {
6495: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6496: }
6497: return $output;
6498: }
6499:
6500: sub decompression_phase_two {
6501: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6502: &decompression_info();
1.481 raeburn 6503: my $output;
1.480 raeburn 6504: if ($env{'form.archivedelete'}) {
1.481 raeburn 6505: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6506: }
6507: $output .=
1.481 raeburn 6508: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6509: $destination,$dir_root,$hiddenelem);
6510: return $output;
6511: }
6512:
1.480 raeburn 6513: sub remove_archive {
6514: my ($docudom,$docuname,$container) = @_;
6515: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6516: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6517: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6518: if ($fatal) {
6519: if ($container eq 'page') {
6520: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6521: } else {
6522: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6523: }
1.484.2.54 raeburn 6524: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6525: } else {
6526: my $currcmd = $env{'form.cmd'};
6527: my $position = $env{'form.position'};
1.484.2.54 raeburn 6528: my $archiveidx = $position;
6529: if ($position > 0) {
6530: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6531: $archiveidx = $position-1;
6532: }
6533: $env{'form.cmd'} = 'remove_'.$archiveidx;
6534: my ($title,$url,@rrest) =
6535: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6536: if ($url eq $env{'form.archiveurl'}) {
6537: if (&handle_edit_cmd($docuname,$docudom)) {
6538: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6539: if ($fatal) {
6540: if ($container eq 'page') {
6541: $delwarning = &mt('An error occurred updating the contents of the current page.');
6542: } else {
6543: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6544: }
1.480 raeburn 6545: } else {
1.484.2.54 raeburn 6546: $delresult = &mt('Archive file removed.');
1.480 raeburn 6547: }
6548: }
1.484.2.54 raeburn 6549: } else {
6550: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6551: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6552: }
6553: }
6554: $env{'form.cmd'} = $currcmd;
6555: }
6556: if ($delwarning) {
6557: $output = '<p class="LC_warning">'.
6558: $delwarning.
6559: '</p>';
6560: }
6561: if ($delresult) {
6562: $output .= '<p class="LC_info">'.
6563: $delresult.
6564: '</p>';
6565: }
1.481 raeburn 6566: return $output;
1.480 raeburn 6567: }
6568:
1.484 raeburn 6569: sub generate_admin_menu {
1.484.2.67 raeburn 6570: my ($crstype,$canedit) = @_;
1.484 raeburn 6571: my $lc_crstype = lc($crstype);
6572: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6573: my %lt= ( # do not translate here
1.484 raeburn 6574: 'vc' => 'Verify Content',
6575: 'cv' => 'Check/Set Resource Versions',
6576: 'ls' => 'List Resource Identifiers',
1.484.2.85.2. (raeburn 6577:): 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 6578: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6579: 'dcd' => "Copy $crstype Content to Authoring Space",
6580: );
1.484 raeburn 6581: my ($candump,$dumpurl);
6582: if ($home + $other > 0) {
6583: $candump = 'F';
6584: if ($home) {
6585: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6586: } else {
6587: my @hosts;
6588: foreach my $aurole (keys(%outhash)) {
6589: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6590: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6591: }
1.484 raeburn 6592: }
6593: if (@hosts == 1) {
6594: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6595: '&role='.
6596: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6597: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6598: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6599: } else {
6600: $dumpurl = "javascript:choose_switchserver_window()";
6601: }
6602: }
6603: }
6604: my @menu=
6605: ({ categorytitle=>'Administration',
6606: items =>[
6607: { linktext => $lt{'vc'},
6608: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6609: permission => 'F',
1.484.2.44 raeburn 6610: help => 'Docs_Verify_Content',
1.484 raeburn 6611: icon => 'verify.png',
6612: linktitle => 'Verify contents can be retrieved/rendered',
6613: },
6614: { linktext => $lt{'cv'},
6615: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6616: permission => 'F',
1.484.2.44 raeburn 6617: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6618: icon => 'resversion.png',
6619: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6620: },
6621: { linktext => $lt{'ls'},
6622: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6623: permission => 'F',
6624: #help => '',
6625: icon => 'symbs.png',
6626: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6627: },
1.484.2.85.2. (raeburn 6628:): { linktext => $lt{'ct'},
6629:): url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
6630:): permission => 'F',
6631:): help => 'Docs_Short_URLs',
6632:): icon => 'shorturls.png',
6633:): linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
6634:): },
1.484 raeburn 6635: ]
1.484.2.67 raeburn 6636: });
6637: if ($canedit) {
6638: push(@menu,
1.484 raeburn 6639: { categorytitle=>'Export',
6640: items =>[
6641: { linktext => $lt{'imse'},
6642: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6643: permission => 'F',
6644: help => 'Docs_Export_Course_Docs',
6645: icon => 'imsexport.png',
6646: linktitle => $lt{'imse'},
6647: },
6648: { linktext => $lt{'dcd'},
6649: url => $dumpurl,
6650: permission => $candump,
1.484.2.44 raeburn 6651: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6652: icon => 'dump.png',
6653: linktitle => $lt{'dcd'},
6654: },
6655: ]
6656: });
1.484.2.67 raeburn 6657: }
1.484 raeburn 6658: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6659: '<input type="hidden" id="dummy" />'."\n".
6660: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6661: '</form>';
1.329 droeschl 6662: }
6663:
6664: sub generate_edit_table {
1.484.2.30 raeburn 6665: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6666: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6667: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6668: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6669: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6670: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6671: $activetab = $env{'form.active'};
6672: }
1.484.2.67 raeburn 6673: unless ($canedit) {
6674: $disabled = ' disabled="disabled"';
6675: }
1.472 raeburn 6676: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6677: my $backtext = &mt('Exit Editor');
1.458 raeburn 6678: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6679: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6680: '<li class="goback">'.
1.484.2.32 raeburn 6681: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6682: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6683: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6684: '<li>'.
6685: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6686: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6687: if ($env{'form.docslog'}) {
6688: $form .= '<li class="active">';
6689: } else {
6690: $form .= '<li>';
6691: }
6692: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6693: &mt('History').'</a></li>'."\n";
6694: if ($env{'form.docslog'}) {
6695: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6696: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6697: }
1.458 raeburn 6698: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6699: if($name ne '00'){
1.371 tempelho 6700: if($activetab eq '' || $activetab ne $name){
6701: $active = '';
6702: }elsif($activetab eq $name){
6703: $active = 'class="active"';
6704: }
1.458 raeburn 6705: $form .= '<li style="float:right" '.$active
1.484 raeburn 6706: .' 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 6707: } else {
1.484.2.43 raeburn 6708: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6709:
6710: }
1.329 droeschl 6711: }
1.484 raeburn 6712: $form .= '</ul>'."\n";
6713: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6714:
6715: if ($to_show ne '') {
1.484.2.30 raeburn 6716: my $saveform;
6717: if ($need_save) {
6718: my $button = &mt('Make changes');
6719: my $path;
6720: if ($env{'form.folderpath'}) {
6721: $path =
6722: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6723: }
6724: $saveform = <<"END";
6725: <div id="multisave" style="display:none; clear:both;" >
6726: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6727: <input type="hidden" name="folderpath" value="$path" />
6728: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6729: <input type="hidden" name="allhiddenresource" value="" />
6730: <input type="hidden" name="allencrypturl" value="" />
6731: <input type="hidden" name="allrandompick" value="" />
6732: <input type="hidden" name="allrandomorder" value="" />
6733: <input type="hidden" name="changeparms" value="" />
6734: <input type="hidden" name="multiremove" value="" />
6735: <input type="hidden" name="multicut" value="" />
6736: <input type="hidden" name="multicopy" value="" />
6737: <input type="hidden" name="multichange" value="" />
6738: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6739: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6740: </form>
6741: </div>
6742: END
6743: }
6744: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6745: }
1.363 ehlerst 6746: foreach my $field (keys(%orderhash)){
1.390 tempelho 6747: if($field ne '00'){
1.422 onken 6748: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6749: $active = 'style="display: none;float:left"';
1.422 onken 6750: }elsif($activetab eq $field){
1.458 raeburn 6751: $active = 'style="display:block;float:left"';
1.422 onken 6752: }
6753: $form .= '<div id="'.$field.$tid.'"'
6754: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6755: .'</div>'."\n";
1.363 ehlerst 6756: }
6757: }
1.484 raeburn 6758: unless ($env{'form.docslog'}) {
6759: $form .= '</div></div>'."\n";
6760: }
1.329 droeschl 6761: return $form;
6762: }
6763:
6764: sub editing_js {
1.484.2.85.2. (raeburn 6765:): my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 6766: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6767: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6768: p_mnf => 'Name of New Folder',
6769: t_mnf => 'New Folder',
6770: p_mnp => 'Name of New Page',
6771: t_mnp => 'New Page',
1.451 www 6772: p_mxu => 'Title for the External Score',
1.349 biermanm 6773: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6774: p_msb => 'Title for the Problem',
6775: p_mdb => 'Title for the Drop Box',
1.336 schafran 6776: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6777: p_mwp => 'Title for Web Page',
1.348 weissno 6778: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6779: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6780: p_mab_alrt1 => 'Not a valid user:domain',
6781: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6782: p_chn => 'New Title',
6783: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6784: p_rmr2a => 'Remove',
6785: p_rmr2b => '?',
6786: p_rmr3a => 'Remove those',
6787: p_rmr3b => 'items?',
6788: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6789: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6790: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6791: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6792: p_ctr2a => 'Cut',
6793: p_ctr2b => '?',
6794: p_ctr3a => 'Cut those',
6795: p_ctr3b => 'items?',
1.478 raeburn 6796: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6797: imsfile => 'You must choose an IMS package for import',
6798: imscms => 'You must select which Course Management System was the source of the IMS package',
6799: invurl => 'Invalid URL',
6800: titbl => 'Title is blank',
1.484.2.30 raeburn 6801: more => '(More ...)',
6802: less => '(Less ...)',
6803: noor => 'No actions selected or changes to settings specified.',
6804: noch => 'No changes to settings specified.',
6805: noac => 'No actions selected.',
1.484.2.67 raeburn 6806: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6807: );
6808:
1.484.2.61 raeburn 6809: &js_escape(\%js_lt);
1.433 raeburn 6810: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6811: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6812: my $main_container_page;
1.484.2.19 raeburn 6813: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6814: $main_container_page = 1;
1.434 raeburn 6815: }
1.484.2.67 raeburn 6816: my $backtourl;
6817: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6818: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6819:
1.484.2.21 raeburn 6820: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6821: my $caller = $1;
6822: if ($caller =~ /^supplemental/) {
6823: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6824: } else {
6825: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6826: $res = &Apache::lonnet::clutter($res);
6827: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6828: my ($url,$anchor);
6829: if ($res =~ /^([^#]+)#([^#]+)$/) {
6830: $url = $1;
6831: $anchor = $2;
6832: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6833: $caller = $1.&escape('#').$anchor;
6834: }
1.484.2.67 raeburn 6835: } else {
6836: $url = $res;
1.484.2.66 raeburn 6837: }
1.484.2.83 raeburn 6838: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6839: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6840: $backtourl .= '?navmap=1';
6841: } else {
6842: $backtourl .= '?symb='.
6843: &HTML::Entities::encode($caller,'<>&"');
6844: }
1.484.2.80 raeburn 6845: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6846: if (($ENV{'SERVER_PORT'} == 443) &&
6847: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6848: unless (&Apache::lonnet::uses_sts()) {
6849: if ($hostname ne '') {
6850: $backtourl = 'http://'.$hostname.$backtourl;
6851: }
6852: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6853: }
6854: }
6855: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6856: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6857: unless (&Apache::lonnet::uses_sts()) {
6858: if ($hostname ne '') {
6859: $backtourl = 'http://'.$hostname.$backtourl;
6860: }
6861: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6862: }
6863: }
6864: }
1.484.2.66 raeburn 6865: if ($anchor ne '') {
6866: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6867: }
1.484.2.57 raeburn 6868: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6869: } else {
6870: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6871: }
6872: }
6873: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6874: $backtourl = '/adm/menu';
6875: } elsif ($supplementalflag) {
1.472 raeburn 6876: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6877: } else {
6878: $backtourl = '/adm/navmaps';
1.472 raeburn 6879: }
6880:
1.484.2.19 raeburn 6881: my $fieldsets = "'ext','doc'";
1.484.2.85.2. (raeburn 6882:): if ($posslti) {
6883:): $fieldsets .= ",'tool'";
6884:): }
1.484.2.19 raeburn 6885: unless ($main_container_page) {
6886: $fieldsets .=",'ims'";
6887: }
1.484.2.12 raeburn 6888: if ($supplementalflag) {
6889: $fieldsets = "'suppext','suppdoc'";
1.484.2.85.2. (raeburn 6890:): if ($posslti) {
6891:): $fieldsets .= ",'supptool'";
6892:): }
1.484.2.12 raeburn 6893: }
6894:
1.484.2.67 raeburn 6895: my $jsmakefunctions;
6896: if ($canedit) {
6897: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6898: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6899: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6900: if (foldername) {
1.484.2.85.2. (raeburn 6901:): targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 6902: targetform.submit();
6903: }
6904: }
6905:
6906: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6907: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6908: if (pagename) {
1.484.2.85.2. (raeburn 6909:): targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 6910: targetform.submit();
6911: }
6912: }
6913:
6914: function makeexamupload() {
1.484.2.61 raeburn 6915: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6916: if (title) {
1.329 droeschl 6917: this.document.forms.newexamupload.importdetail.value=
1.484.2.85.2. (raeburn 6918:): encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 6919: this.document.forms.newexamupload.submit();
6920: }
6921: }
6922:
6923: function makesmppage() {
1.484.2.61 raeburn 6924: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6925: if (title) {
1.329 droeschl 6926: this.document.forms.newsmppg.importdetail.value=
1.484.2.85.2. (raeburn 6927:): encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6928: this.document.forms.newsmppg.submit();
6929: }
6930: }
6931:
1.484.2.27 raeburn 6932: function makewebpage(type) {
1.484.2.61 raeburn 6933: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6934: var formname;
6935: if (type == 'supp') {
6936: formname = this.document.forms.supwebpage;
6937: } else {
6938: formname = this.document.forms.newwebpage;
6939: }
6940: if (title) {
6941: var webpage = formname.importdetail.value;
1.484.2.85.2. (raeburn 6942:): formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 6943: formname.submit();
6944: }
6945: }
6946:
1.329 droeschl 6947: function makesmpproblem() {
1.484.2.61 raeburn 6948: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6949: if (title) {
1.329 droeschl 6950: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.85.2. (raeburn 6951:): encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 6952: this.document.forms.newsmpproblem.submit();
6953: }
6954: }
6955:
6956: function makedropbox() {
1.484.2.61 raeburn 6957: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6958: if (title) {
1.329 droeschl 6959: this.document.forms.newdropbox.importdetail.value=
1.484.2.85.2. (raeburn 6960:): encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 6961: this.document.forms.newdropbox.submit();
6962: }
6963: }
6964:
6965: function makebulboard() {
1.484.2.61 raeburn 6966: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6967: if (title) {
6968: this.document.forms.newbul.importdetail.value=
1.484.2.85.2. (raeburn 6969:): encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6970: this.document.forms.newbul.submit();
6971: }
6972: }
6973:
6974: function makeabout() {
1.484.2.61 raeburn 6975: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6976: if (user) {
6977: var comp=new Array();
6978: comp=user.split(':');
6979: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6980: if ((comp[0]) && (comp[1])) {
6981: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6982: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6983: this.document.forms.newaboutsomeone.submit();
6984: } else {
6985: alert("$js_lt{'p_mab_alrt1'}");
6986: }
6987: } else {
6988: alert("$js_lt{'p_mab_alrt2'}");
6989: }
6990: }
1.335 ehlerst 6991: }
1.484.2.67 raeburn 6992:
6993: function makenew(targetform) {
6994: targetform.submit();
1.335 ehlerst 6995: }
1.484.2.67 raeburn 6996:
6997: function changename(folderpath,index,oldtitle) {
6998: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6999: if (title) {
7000: this.document.forms.renameform.markcopy.value='';
7001: this.document.forms.renameform.title.value=title;
7002: this.document.forms.renameform.cmd.value='rename_'+index;
7003: this.document.forms.renameform.folderpath.value=folderpath;
7004: this.document.forms.renameform.submit();
7005: }
1.329 droeschl 7006: }
7007:
1.484.2.67 raeburn 7008: ENDNEWSCRIPT
7009: } else {
7010: $jsmakefunctions = <<ENDNEWSCRIPT;
7011:
7012: function makenewfolder() {
7013: alert("$js_lt{'edri'}");
7014: }
7015:
7016: function makenewpage() {
7017: alert("$js_lt{'edri'}");
7018: }
7019:
7020: function makeexamupload() {
7021: alert("$js_lt{'edri'}");
7022: }
7023:
7024: function makesmppage() {
7025: alert("$js_lt{'edri'}");
7026: }
7027:
7028: function makewebpage(type) {
7029: alert("$js_lt{'edri'}");
7030: }
7031:
7032: function makesmpproblem() {
7033: alert("$js_lt{'edri'}");
7034: }
7035:
7036: function makedropbox() {
7037: alert("$js_lt{'edri'}");
7038: }
7039:
7040: function makebulboard() {
7041: alert("$js_lt{'edri'}");
7042: }
7043:
7044: function makeabout() {
7045: alert("$js_lt{'edri'}");
7046: }
7047:
7048: function changename() {
7049: alert("$js_lt{'edri'}");
7050: }
7051:
7052: function makenew() {
7053: alert("$js_lt{'edri'}");
7054: }
7055:
7056: function groupimport() {
7057: alert("$js_lt{'edri'}");
7058: }
7059:
7060: function groupsearch() {
7061: alert("$js_lt{'edri'}");
7062: }
7063:
7064: function groupopen(url,recover) {
7065: var options="scrollbars=1,resizable=1,menubar=0";
7066: idxflag=1;
7067: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7068: idx.focus();
7069: }
7070:
7071: ENDNEWSCRIPT
7072:
7073: }
7074: return <<ENDSCRIPT;
7075:
7076: $jsmakefunctions
7077:
1.484.2.13 raeburn 7078: function toggleUpload(caller) {
7079: var blocks = Array($fieldsets);
7080: for (var i=0; i<blocks.length; i++) {
7081: var disp = 'none';
7082: if (caller == blocks[i]) {
7083: var curr = document.getElementById('upload'+caller+'form').style.display;
7084: if (curr == 'none') {
7085: disp='block';
7086: }
7087: }
7088: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.484.2.85.2. (raeburn 7089:): if ((caller == 'tool') || (caller == 'supptool')) {
7090:): if (disp == 'block') {
7091:): if (document.getElementById('LC_exttoolid')) {
7092:): var toolselector = document.getElementById('LC_exttoolid');
7093:): var suppflag = 0;
7094:): if (caller == 'supptool') {
7095:): suppflag = 1;
7096:): }
7097:): currForm = document.getElementById('new'+caller);
7098:): updateExttool(toolselector,currForm,suppflag);
7099:): }
7100:): }
7101:): }
1.484.2.13 raeburn 7102: }
7103: resize_scrollbox('contentscroll','1','1');
7104: return;
7105: }
7106:
1.484.2.19 raeburn 7107: function toggleMap(caller) {
1.484.2.13 raeburn 7108: var disp = 'none';
1.484.2.19 raeburn 7109: if (document.getElementById('importmapform')) {
7110: if (caller == 'map') {
7111: var curr = document.getElementById('importmapform').style.display;
7112: if (curr == 'none') {
7113: disp='block';
7114: }
1.484.2.12 raeburn 7115: }
1.484.2.19 raeburn 7116: document.getElementById('importmapform').style.display=disp;
7117: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 7118: }
1.484.2.19 raeburn 7119: return;
1.329 droeschl 7120: }
7121:
1.484.2.12 raeburn 7122: function makeims(imsform) {
7123: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 7124: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 7125: return;
7126: }
7127: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 7128: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 7129: return;
7130: }
7131: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7132: imsform.submit();
7133: }
7134:
1.478 raeburn 7135: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 7136: var pickitem;
7137: var picknumitem;
7138: var picknumtext;
7139: if (index == 'all') {
7140: pickitem = document.getElementById('randompickall');
7141: picknumitem = document.getElementById('rpicknumall');
7142: picknumtext = document.getElementById('rpicktextall');
7143: } else {
7144: pickitem = document.getElementById('randompick_'+index);
7145: picknumitem = document.getElementById('rpicknum_'+index);
7146: picknumtext = document.getElementById('randompicknum_'+index);
7147: }
1.478 raeburn 7148: if (pickitem.checked) {
1.484.2.61 raeburn 7149: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7150: if (picknum == '' || picknum == null) {
7151: if (caller == 'check') {
7152: pickitem.checked=false;
1.484.2.29 raeburn 7153: if (index == 'all') {
7154: picknumtext.innerHTML = '';
7155: if (caller == 'link') {
7156: propagateState(targetform,'rpicknum');
7157: }
7158: } else {
1.484.2.30 raeburn 7159: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7160: }
1.478 raeburn 7161: }
7162: } else {
7163: picknum.toString();
7164: var regexdigit=/^\\d+\$/;
7165: if (regexdigit.test(picknum)) {
7166: picknumitem.value = picknum;
1.484.2.29 raeburn 7167: if (index == 'all') {
1.484.2.30 raeburn 7168: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 7169: if (caller == 'link') {
7170: propagateState(targetform,'rpicknum');
7171: }
7172: } else {
7173: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 7174: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7175: }
1.478 raeburn 7176: } else {
7177: if (caller == 'check') {
1.484.2.29 raeburn 7178: if (index == 'all') {
7179: picknumtext.innerHTML = '';
7180: if (caller == 'link') {
7181: propagateState(targetform,'rpicknum');
7182: }
7183: } else {
7184: pickitem.checked=false;
1.484.2.30 raeburn 7185: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7186: }
1.478 raeburn 7187: }
7188: return;
7189: }
7190: }
7191: } else {
1.484.2.29 raeburn 7192: picknumitem.value = '';
7193: picknumtext.innerHTML = '';
7194: if (index == 'all') {
7195: if (caller == 'link') {
7196: propagateState(targetform,'rpicknum');
7197: }
7198: } else {
1.484.2.30 raeburn 7199: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7200: }
7201: }
7202: }
7203:
7204: function propagateState(form,param) {
7205: if (document.getElementById(param+'all')) {
7206: var setcheck = 0;
7207: var rpick = 0;
7208: if (param == 'rpicknum') {
7209: if (document.getElementById('randompickall')) {
7210: if (document.getElementById('randompickall').checked) {
7211: if (document.getElementById('rpicknumall')) {
7212: rpick = document.getElementById('rpicknumall').value;
7213: }
7214: }
7215: }
7216: } else {
7217: if (document.getElementById(param+'all').checked) {
7218: setcheck = 1;
7219: }
7220: }
1.484.2.30 raeburn 7221: var allidxlist;
7222: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7223: if (document.getElementById('all'+param+'idx')) {
7224: allidxlist = document.getElementById('all'+param+'idx').value;
7225: }
7226: var actions = new Array ('remove','cut','copy');
7227: for (var i=0; i<actions.length; i++) {
7228: if (actions[i] != param) {
7229: if (document.getElementById(actions[i]+'all')) {
7230: document.getElementById(actions[i]+'all').checked = false;
7231: }
7232: }
7233: }
7234: }
1.484.2.29 raeburn 7235: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 7236: allidxlist = form.allidx.value;
7237: }
7238: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7239: allidxlist = form.allmapidx.value;
7240: }
7241: if ((allidxlist != '') && (allidxlist != null)) {
7242: var allidxs = allidxlist.split(',');
7243: if (allidxs.length > 1) {
7244: for (var i=0; i<allidxs.length; i++) {
7245: if (document.getElementById(param+'_'+allidxs[i])) {
7246: if (param == 'rpicknum') {
7247: if (document.getElementById('randompick_'+allidxs[i])) {
7248: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7249: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7250: if (rpick > 0) {
7251: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7252: } else {
7253: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7254: }
7255: }
7256: }
7257: } else {
1.484.2.29 raeburn 7258: if (setcheck == 1) {
7259: document.getElementById(param+'_'+allidxs[i]).checked = true;
7260: } else {
7261: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7262: if (param == 'randompick') {
7263: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7264: }
1.484.2.29 raeburn 7265: }
7266: }
7267: }
7268: }
1.484.2.30 raeburn 7269: if (setcheck == 1) {
7270: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7271: var actions = new Array('copy','cut','remove');
7272: for (var i=0; i<actions.length; i++) {
7273: var otheractions;
7274: var otheridxs;
7275: if (actions[i] === param) {
7276: continue;
7277: } else {
7278: if (document.getElementById('all'+actions[i]+'idx')) {
7279: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7280: otheridxs = otheractions.split(',');
7281: if (otheridxs.length > 1) {
7282: for (var j=0; j<otheridxs.length; j++) {
7283: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7284: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7285: }
1.484.2.29 raeburn 7286: }
7287: }
7288: }
7289: }
1.484.2.30 raeburn 7290: }
1.484.2.29 raeburn 7291: }
7292: }
7293: }
7294: }
1.478 raeburn 7295: }
1.484.2.29 raeburn 7296: return;
7297: }
7298:
1.484.2.63 raeburn 7299: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7300: var canedit = '$canedit';
7301: if (canedit == '') {
7302: alert("$js_lt{'edri'}");
7303: return;
7304: }
1.484.2.30 raeburn 7305: var dosettings;
7306: var doaction;
7307: var control = document.togglemultsettings;
7308: if (context == 'actions') {
7309: control = document.togglemultactions;
7310: doaction = 1;
7311: } else {
7312: dosettings = 1;
7313: }
7314: if (control) {
7315: if (control.showmultpick.length) {
7316: for (var i=0; i<control.showmultpick.length; i++) {
7317: if (control.showmultpick[i].checked) {
7318: if (control.showmultpick[i].value == 1) {
7319: if (context == 'settings') {
7320: dosettings = 0;
7321: } else {
7322: doaction = 0;
7323: }
7324: }
7325: }
7326: }
7327: }
7328: }
7329: if (context == 'settings') {
7330: if (dosettings == 1) {
7331: targetform.changeparms.value=param;
7332: targetform.submit();
7333: }
7334: }
7335: if (context == 'actions') {
7336: if (doaction == 1) {
7337: targetform.cmd.value=param+'_'+index;
7338: targetform.folderpath.value=folderpath;
7339: targetform.markcopy.value=idx+':'+param;
7340: targetform.copyfolder.value=folder+'.'+container;
7341: if (param == 'remove') {
1.484.2.63 raeburn 7342: var doremove = 0;
7343: if (skip_confirm) {
7344: if (confirm_removal) {
7345: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7346: doremove = 1;
7347: }
7348: } else {
7349: doremove = 1;
7350: }
7351: } else {
7352: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7353: doremove = 1;
7354: }
7355: }
7356: if (doremove) {
1.484.2.30 raeburn 7357: targetform.markcopy.value='';
7358: targetform.copyfolder.value='';
1.484.2.29 raeburn 7359: targetform.submit();
7360: }
7361: }
1.484.2.30 raeburn 7362: if (param == 'cut') {
1.484.2.61 raeburn 7363: 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.484.2.30 raeburn 7364: targetform.submit();
7365: return;
7366: }
7367: }
7368: if (param == 'copy') {
7369: targetform.submit();
7370: return;
7371: }
7372: targetform.markcopy.value='';
7373: targetform.copyfolder.value='';
7374: targetform.cmd.value='';
7375: targetform.folderpath.value='';
7376: return;
7377: } else {
7378: if (document.getElementById(param+'_'+idx)) {
7379: item = document.getElementById(param+'_'+idx);
7380: if (item.type == 'checkbox') {
7381: if (item.checked) {
7382: item.checked = false;
7383: } else {
7384: item.checked = true;
7385: singleCheck(item,idx,param);
7386: }
7387: }
7388: }
7389: }
7390: }
7391: return;
7392: }
7393:
7394: function singleCheck(caller,idx,action) {
7395: actions = new Array('cut','copy','remove');
7396: if (caller.checked) {
7397: for (var i=0; i<actions.length; i++) {
7398: if (actions[i] != action) {
7399: if (document.getElementById(actions[i]+'_'+idx)) {
7400: if (document.getElementById(actions[i]+'_'+idx).checked) {
7401: document.getElementById(actions[i]+'_'+idx).checked = false;
7402: }
7403: }
7404: }
1.484.2.29 raeburn 7405: }
7406: }
7407: return;
1.478 raeburn 7408: }
7409:
1.334 muellerd 7410: function unselectInactive(nav) {
1.335 ehlerst 7411: currentNav = document.getElementById(nav);
7412: currentLis = currentNav.getElementsByTagName('LI');
7413: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7414: if (currentLis[i].className == 'goback') {
7415: currentLis[i].className = 'goback';
7416: } else {
7417: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7418: currentLis[i].className = 'right';
1.472 raeburn 7419: } else {
1.374 tempelho 7420: currentLis[i].className = 'i';
1.472 raeburn 7421: }
7422: }
1.335 ehlerst 7423: }
1.332 tempelho 7424: }
7425:
1.334 muellerd 7426: function hideAll(current, nav, data) {
1.335 ehlerst 7427: unselectInactive(nav);
1.484.2.43 raeburn 7428: if (current) {
7429: if (current.className == 'right'){
1.374 tempelho 7430: current.className = 'right active'
1.484.2.43 raeburn 7431: } else {
1.374 tempelho 7432: current.className = 'active';
1.484.2.43 raeburn 7433: }
1.374 tempelho 7434: }
1.335 ehlerst 7435: currentData = document.getElementById(data);
7436: currentDivs = currentData.getElementsByTagName('DIV');
7437: for (i = 0; i < currentDivs.length; i++) {
7438: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7439: currentDivs[i].style.display = 'none';
1.330 tempelho 7440: }
7441: }
1.335 ehlerst 7442: }
1.330 tempelho 7443:
1.374 tempelho 7444: function openTabs(pageId) {
7445: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7446: if(tabnav.length > 2 ){
1.389 tempelho 7447: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7448: currentLis = currentNav.getElementsByTagName('LI');
7449: for(i = 0; i< currentLis.length; i++){
7450: if(currentLis[i].className == 'active') {
1.375 tempelho 7451: funcString = currentLis[i].onclick.toString();
7452: tab = funcString.split('"');
1.420 onken 7453: if(tab.length < 2) {
7454: tab = funcString.split("'");
7455: }
1.375 tempelho 7456: currentData = document.getElementById(tab[1]);
7457: currentData.style.display = 'block';
1.374 tempelho 7458: }
7459: }
7460: }
7461: }
7462:
1.334 muellerd 7463: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7464: currstate = current.className;
1.334 muellerd 7465: hideAll(current, nav, data);
1.375 tempelho 7466: openTabs(pageId);
1.334 muellerd 7467: unselectInactive(nav);
1.484.2.43 raeburn 7468: if ((currstate == 'active') || (currstate == 'right active')) {
7469: if (currstate == 'active') {
7470: current.className = '';
7471: } else {
7472: current.className = 'right';
7473: }
7474: activeTab = '';
7475: toggleUpload();
7476: toggleMap();
7477: resize_scrollbox('contentscroll','1','0');
7478: return;
7479: } else {
7480: current.className = 'active';
7481: }
1.330 tempelho 7482: currentData = document.getElementById(pageId);
7483: currentData.style.display = 'block';
1.458 raeburn 7484: activeTab = pageId;
1.484.2.12 raeburn 7485: toggleUpload();
1.484.2.14 raeburn 7486: toggleMap();
1.433 raeburn 7487: if (nav == 'mainnav') {
7488: var storedpath = "$docs_folderpath";
1.434 raeburn 7489: var storedpage = "$main_container_page";
1.433 raeburn 7490: var reg = new RegExp("^supplemental");
7491: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7492: if (storedpage == 1) {
7493: document.simpleedit.folderpath.value = '';
7494: document.uploaddocument.folderpath.value = '';
7495: } else {
7496: if (reg.test(storedpath)) {
7497: document.simpleedit.folderpath.value = '$toplevelmain';
7498: document.uploaddocument.folderpath.value = '$toplevelmain';
7499: document.newext.folderpath.value = '$toplevelmain';
7500: } else {
7501: document.simpleedit.folderpath.value = storedpath;
7502: document.uploaddocument.folderpath.value = storedpath;
7503: document.newext.folderpath.value = storedpath;
7504: }
1.433 raeburn 7505: }
7506: } else {
1.434 raeburn 7507: if (reg.test(storedpath)) {
7508: document.simpleedit.folderpath.value = storedpath;
7509: document.supuploaddocument.folderpath.value = storedpath;
7510: document.supnewext.folderpath.value = storedpath;
7511: } else {
1.433 raeburn 7512: document.simpleedit.folderpath.value = '$toplevelsupp';
7513: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7514: document.supnewext.folderpath.value = '$toplevelsupp';
7515: }
7516: }
7517: }
1.484.2.3 raeburn 7518: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7519: return false;
7520: }
1.329 droeschl 7521:
1.472 raeburn 7522: function toContents(jumpto) {
7523: var newurl = '$backtourl';
1.484.2.21 raeburn 7524: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7525: newurl = newurl+'?postdata='+jumpto;
7526: }
7527: location.href=newurl;
7528: }
7529:
1.484.2.30 raeburn 7530: function togglePick(caller,value) {
7531: var disp = 'none';
7532: if (document.getElementById('multi'+caller)) {
7533: var curr = document.getElementById('multi'+caller).style.display;
7534: if (value == 1) {
7535: disp='block';
7536: }
7537: if (curr == disp) {
7538: return;
7539: }
7540: document.getElementById('multi'+caller).style.display=disp;
7541: if (value == 1) {
1.484.2.61 raeburn 7542: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7543: } else {
7544: document.getElementById('more'+caller).innerHTML = '';
7545: }
7546: if (caller == 'actions') {
7547: setClass(value);
7548: setBoxes(value);
7549: }
7550: }
7551: var showButton = multiSettings();
7552: if (showButton != 1) {
7553: showButton = multiActions();
7554: }
7555: if (document.getElementById('multisave')) {
7556: if (showButton == 1) {
7557: document.getElementById('multisave').style.display='block';
7558: } else {
7559: document.getElementById('multisave').style.display='none';
7560: }
7561: }
7562: resize_scrollbox('contentscroll','1','1');
7563: return;
7564: }
7565:
7566: function toggleCheckUncheck(caller,more) {
7567: if (more == 1) {
1.484.2.61 raeburn 7568: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7569: document.getElementById('allfields'+caller).style.display='block';
7570: } else {
1.484.2.61 raeburn 7571: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7572: document.getElementById('allfields'+caller).style.display='none';
7573: }
7574: resize_scrollbox('contentscroll','1','1');
7575: }
7576:
7577: function multiSettings() {
7578: var inuse = 0;
7579: var settingsform = document.togglemultsettings;
7580: if (settingsform.showmultpick.length > 1) {
7581: for (var i=0; i<settingsform.showmultpick.length; i++) {
7582: if (settingsform.showmultpick[i].checked) {
7583: if (settingsform.showmultpick[i].value == 1) {
7584: inuse = 1;
7585: }
7586: }
7587: }
7588: }
7589: return inuse;
7590: }
7591:
7592: function multiActions() {
7593: var inuse = 0;
7594: var actionsform = document.togglemultactions;
7595: if (actionsform.showmultpick.length > 1) {
7596: for (var i=0; i<actionsform.showmultpick.length; i++) {
7597: if (actionsform.showmultpick[i].checked) {
7598: if (actionsform.showmultpick[i].value == 1) {
7599: inuse = 1;
7600: }
7601: }
7602: }
7603: }
7604: return inuse;
7605: }
7606:
7607: function checkSubmits() {
7608: var numchanges = 0;
7609: var form = document.saveactions;
7610: var doactions = multiActions();
7611: var cutwarnings = 0;
7612: var remwarnings = 0;
1.484.2.63 raeburn 7613: var removalinfo = 0;
1.484.2.30 raeburn 7614: if (doactions == 1) {
7615: var remidxlist = document.cumulativeactions.allremoveidx.value;
7616: if ((remidxlist != '') && (remidxlist != null)) {
7617: var remidxs = remidxlist.split(',');
7618: for (var i=0; i<remidxs.length; i++) {
7619: if (document.getElementById('remove_'+remidxs[i])) {
7620: if (document.getElementById('remove_'+remidxs[i]).checked) {
7621: form.multiremove.value += remidxs[i]+',';
7622: numchanges ++;
7623: if (document.getElementById('skip_remove_'+remidxs[i])) {
7624: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7625: remwarnings ++;
7626: }
7627: }
1.484.2.63 raeburn 7628: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7629: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7630: removalinfo ++;
7631: }
7632: }
1.484.2.30 raeburn 7633: }
7634: }
7635: }
7636: }
7637: var cutidxlist = document.cumulativeactions.allcutidx.value;
7638: if ((cutidxlist != '') && (cutidxlist != null)) {
7639: var cutidxs = cutidxlist.split(',');
7640: for (var i=0; i<cutidxs.length; i++) {
7641: if (document.getElementById('cut_'+cutidxs[i])) {
7642: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7643: form.multicut.value += cutidxs[i]+',';
7644: numchanges ++;
7645: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7646: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7647: cutwarnings ++;
7648: }
7649: }
7650: }
7651: }
7652: }
7653: }
7654: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7655: if ((copyidxlist != '') && (copyidxlist != null)) {
7656: var copyidxs = copyidxlist.split(',');
7657: for (var i=0; i<copyidxs.length; i++) {
7658: if (document.getElementById('copy_'+copyidxs[i])) {
7659: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7660: form.multicopy.value += copyidxs[i]+',';
7661: numchanges ++;
7662: }
7663: }
7664: }
7665: }
7666: if (numchanges > 0) {
7667: form.multichange.value = numchanges;
7668: }
7669: }
7670: var dosettings = multiSettings();
7671: var haschanges = 0;
7672: if (dosettings == 1) {
7673: form.allencrypturl.value = '';
7674: form.allhiddenresource.value = '';
7675: form.changeparms.value = 'all';
7676: var patt=new RegExp(",\$");
7677: var allidxlist = document.cumulativesettings.allidx.value;
7678: if ((allidxlist != '') && (allidxlist != null)) {
7679: var allidxs = allidxlist.split(',');
7680: if (allidxs.length > 1) {
7681: for (var i=0; i<allidxs.length; i++) {
7682: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7683: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7684: form.allhiddenresource.value += allidxs[i]+',';
7685: }
7686: }
7687: if (document.getElementById('encrypturl_'+allidxs[i])) {
7688: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7689: form.allencrypturl.value += allidxs[i]+',';
7690: }
1.484.2.29 raeburn 7691: }
7692: }
1.484.2.30 raeburn 7693: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7694: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7695: }
7696: }
7697: form.allrandompick.value = '';
7698: form.allrandomorder.value = '';
7699: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7700: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7701: var allmapidxs = allmapidxlist.split(',');
7702: for (var i=0; i<allmapidxs.length; i++) {
7703: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7704: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7705: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7706: if ((randompick.checked) && (rpicknum.value != '')) {
7707: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7708: }
7709: if (randorder.checked) {
7710: form.allrandomorder.value += allmapidxs[i]+',';
7711: }
7712: }
7713: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7714: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7715: }
7716: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7717: haschanges = 1;
7718: }
7719: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7720: haschanges = 1;
7721: }
7722: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7723: haschanges = 1;
7724: }
7725: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7726: haschanges = 1;
7727: }
7728: }
7729: if (doactions == 1) {
7730: if (numchanges > 0) {
1.484.2.63 raeburn 7731: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7732: if (remwarnings > 0) {
1.484.2.61 raeburn 7733: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7734: return false;
7735: }
7736: }
1.484.2.63 raeburn 7737: if (removalinfo > 0) {
7738: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7739: return false;
7740: }
7741: }
1.484.2.30 raeburn 7742: if (cutwarnings > 0) {
1.484.2.61 raeburn 7743: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
1.484.2.30 raeburn 7744: return false;
1.484.2.29 raeburn 7745: }
7746: }
7747: }
1.484.2.30 raeburn 7748: form.submit();
7749: return true;
7750: }
7751: }
7752: if (dosettings == 1) {
7753: if (haschanges == 1) {
7754: form.submit();
7755: return true;
1.484.2.29 raeburn 7756: }
7757: }
1.484.2.30 raeburn 7758: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7759: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7760: } else {
7761: if (dosettings == 1) {
1.484.2.61 raeburn 7762: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7763: } else {
1.484.2.61 raeburn 7764: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7765: }
7766: }
7767: return false;
7768: }
7769:
7770: function setClass(value) {
7771: var cutclass = 'LC_docs_cut';
7772: var copyclass = 'LC_docs_copy';
7773: var removeclass = 'LC_docs_remove';
7774: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7775: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7776: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7777: var links = document.getElementsByTagName('a');
7778: for (var i=0; i<links.length; i++) {
7779: var classes = links[i].className;
7780: if (cutreg.test(classes)) {
7781: links[i].className = cutclass;
7782: if (value == 1) {
7783: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7784: }
1.484.2.30 raeburn 7785: } else {
7786: if (copyreg.test(classes)) {
7787: links[i].className = copyclass;
7788: if (value == 1) {
7789: links[i].className += " LC_menubuttons_link";
7790: }
7791: } else {
7792: if (removereg.test(classes)) {
7793: links[i].className = removeclass;
7794: if (value == 1) {
7795: links[i].className += " LC_menubuttons_link";
7796: }
7797: }
1.484.2.29 raeburn 7798: }
7799: }
7800: }
1.484.2.30 raeburn 7801: return;
1.484.2.29 raeburn 7802: }
7803:
1.484.2.30 raeburn 7804: function setBoxes(value) {
7805: var remidxlist = document.cumulativeactions.allremoveidx.value;
7806: if ((remidxlist != '') && (remidxlist != null)) {
7807: var remidxs = remidxlist.split(',');
7808: for (var i=0; i<remidxs.length; i++) {
7809: if (document.getElementById('remove_'+remidxs[i])) {
7810: var item = document.getElementById('remove_'+remidxs[i]);
7811: if (value == 1) {
7812: item.className = 'LC_docs_remove';
7813: } else {
7814: item.className = 'LC_hidden';
7815: }
7816: }
1.484.2.29 raeburn 7817: }
7818: }
1.484.2.30 raeburn 7819: var cutidxlist = document.cumulativeactions.allcutidx.value;
7820: if ((cutidxlist != '') && (cutidxlist != null)) {
7821: var cutidxs = cutidxlist.split(',');
7822: for (var i=0; i<cutidxs.length; i++) {
7823: if (document.getElementById('cut_'+cutidxs[i])) {
7824: var item = document.getElementById('cut_'+cutidxs[i]);
7825: if (value == 1) {
7826: item.className = 'LC_docs_cut';
7827: } else {
7828: item.className = 'LC_hidden';
7829: }
7830: }
7831: }
7832: }
7833: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7834: if ((copyidxlist != '') && (copyidxlist != null)) {
7835: var copyidxs = copyidxlist.split(',');
7836: for (var i=0; i<copyidxs.length; i++) {
7837: if (document.getElementById('copy_'+copyidxs[i])) {
7838: var item = document.getElementById('copy_'+copyidxs[i]);
7839: if (value == 1) {
7840: item.className = 'LC_docs_copy';
7841: } else {
7842: item.className = 'LC_hidden';
7843: }
7844: }
1.484.2.29 raeburn 7845: }
7846: }
7847: return;
7848: }
7849:
1.484.2.67 raeburn 7850: ENDSCRIPT
1.329 droeschl 7851: }
1.457 raeburn 7852:
1.483 raeburn 7853: sub history_tab_js {
7854: return <<"ENDHIST";
7855: function toggleHistoryDisp(choice) {
7856: document.docslogform.docslog.value = choice;
7857: document.docslogform.submit();
7858: return;
7859: }
7860:
7861: ENDHIST
7862: }
7863:
1.484 raeburn 7864: sub inject_data_js {
7865: return <<ENDINJECT;
7866:
7867: function injectData(current, hiddenField, name, value) {
7868: currentElement = document.getElementById(hiddenField);
7869: currentElement.name = name;
7870: currentElement.value = value;
7871: current.submit();
7872: }
7873:
7874: ENDINJECT
7875: }
7876:
7877: sub dump_switchserver_js {
7878: my @hosts = @_;
1.484.2.61 raeburn 7879: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7880: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7881: swit => 'Switch server?',
1.484.2.61 raeburn 7882: );
7883: my %html_js_lt = &Apache::lonlocal::texthash(
7884: swit => 'Switch server?',
1.484.2.43 raeburn 7885: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7886: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7887: chos => 'Choose server',
7888: );
1.484.2.61 raeburn 7889: &js_escape(\%js_lt);
7890: &html_escape(\%html_js_lt);
7891: &js_escape(\%html_js_lt);
1.484 raeburn 7892: my $role = $env{'request.role'};
7893: my $js = <<"ENDSWJS";
7894: <script type="text/javascript">
7895: function write_switchserver() {
7896: var server;
7897: if (document.setserver.posshosts.length > 0) {
7898: for (var i=0; i<document.setserver.posshosts.length; i++) {
7899: if (document.setserver.posshosts[i].checked) {
7900: server = document.setserver.posshosts[i].value;
7901: }
7902: }
7903: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7904: }
7905: window.close();
7906: }
7907: </script>
7908:
7909: ENDSWJS
7910:
7911: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7912: {'only_body' => 1,
7913: 'js_ready' => 1,});
7914: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7915:
7916: my $hostpicker;
7917: my $count = 0;
7918: foreach my $host (sort(@hosts)) {
7919: my $checked;
7920: if ($count == 0) {
7921: $checked = ' checked="checked"';
7922: }
7923: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7924: $host.'"'.$checked.' />'.$host.'</label> ';
7925: $count++;
7926: }
7927:
7928: return <<"ENDSWITCHJS";
7929:
7930: function dump_needs_switchserver(url) {
7931: if (url!='' && url!= null) {
1.484.2.61 raeburn 7932: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7933: go(url);
7934: }
7935: }
7936: return;
7937: }
7938:
7939: function choose_switchserver_window() {
7940: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7941: newWindow.document.open();
7942: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7943: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7944: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7945: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7946: '<form name="setserver" method="post" action="" \\/>\\n'+
7947: '$hostpicker\\n'+
7948: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7949: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7950: 'onclick="write_switchserver();" \\/>\\n'+
7951: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7952: newWindow.document.writeln('$endpage');
7953: newWindow.document.close();
7954: newWindow.focus();
7955: }
7956:
7957: ENDSWITCHJS
7958: }
7959:
7960: sub makedocslogform {
7961: my ($formelems,$docslog) = @_;
7962: return <<"LOGSFORM";
7963: <form action="/adm/coursedocs" method="post" name="docslogform">
7964: <input type="hidden" name="docslog" value="$docslog" />
7965: $formelems
7966: </form>
7967: LOGSFORM
7968: }
7969:
7970: sub makesimpleeditform {
7971: my ($formelems) = @_;
7972: return <<"SIMPFORM";
7973: <form name="simpleedit" method="post" action="/adm/coursedocs">
7974: <input type="hidden" name="importdetail" value="" />
7975: $formelems
7976: </form>
7977: SIMPFORM
7978: }
7979:
1.329 droeschl 7980: 1;
7981: __END__
7982:
7983:
7984: =head1 NAME
7985:
7986: Apache::londocs.pm
7987:
7988: =head1 SYNOPSIS
7989:
7990: This is part of the LearningOnline Network with CAPA project
7991: described at http://www.lon-capa.org.
7992:
7993: =head1 SUBROUTINES
7994:
7995: =over
7996:
7997: =item %help=()
7998:
7999: Available help topics
8000:
8001: =item mapread()
8002:
1.344 bisitz 8003: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8004: @order and @resources, determines status
8005: sets @order - pointer to resources in right order
8006: sets @resources - array with the resources with correct idx
8007:
8008: =item authorhosts()
8009:
8010: Return hash with valid author names
8011:
8012: =item clean()
8013:
8014: =item dumpcourse()
8015:
8016: Actually dump course
8017:
8018: =item group_import()
8019:
8020: Imports the given (name, url) resources into the course
8021: coursenum, coursedom, and folder must precede the list
8022:
8023: =item breadcrumbs()
8024:
8025: =item log_docs()
8026:
8027: =item docs_change_log()
8028:
8029: =item update_paste_buffer()
8030:
8031: =item print_paste_buffer()
8032:
8033: =item do_paste_from_buffer()
8034:
1.484.2.30 raeburn 8035: =item do_buffer_empty()
8036:
8037: =item clear_from_buffer()
8038:
1.484.2.7 raeburn 8039: =item get_newmap_url()
8040:
8041: =item dbcopy()
8042:
8043: =item uniqueness_check()
8044:
8045: =item contained_map_check()
8046:
8047: =item url_paste_fixups()
8048:
8049: =item apply_fixups()
8050:
8051: =item copy_dependencies()
8052:
1.329 droeschl 8053: =item update_parameter()
8054:
8055: =item handle_edit_cmd()
8056:
8057: =item editor()
8058:
8059: =item process_file_upload()
8060:
8061: =item process_secondary_uploads()
8062:
8063: =item is_supplemental_title()
8064:
8065: =item entryline()
8066:
8067: =item tiehash()
8068:
8069: =item untiehash()
8070:
8071: =item checkonthis()
8072:
8073: check on this
8074:
8075: =item verifycontent()
8076:
8077: Verify Content
8078:
1.484.2.78 raeburn 8079: =item devalidateversioncache()
8080:
8081: =item checkversions()
1.329 droeschl 8082:
8083: Check Versions
8084:
8085: =item mark_hash_old()
8086:
8087: =item is_hash_old()
8088:
8089: =item changewarning()
8090:
8091: =item init_breadcrumbs()
8092:
8093: Breadcrumbs for special functions
8094:
1.484 raeburn 8095: =item create_list_elements()
8096:
8097: =item create_form_ul()
8098:
8099: =item startContentScreen()
8100:
8101: =item endContentScreen()
8102:
8103: =item supplemental_base()
8104:
8105: =item embedded_form_elems()
8106:
8107: =item embedded_destination()
8108:
8109: =item return_to_editor()
8110:
8111: =item decompression_info()
8112:
8113: =item decompression_phase_one()
8114:
8115: =item decompression_phase_two()
8116:
8117: =item remove_archive()
8118:
8119: =item generate_admin_menu()
8120:
8121: =item generate_edit_table()
8122:
8123: =item editing_js()
8124:
8125: =item history_tab_js()
8126:
8127: =item inject_data_js()
8128:
8129: =item dump_switchserver_js()
8130:
1.484.2.3 raeburn 8131: =item resize_scrollbox_js()
1.484 raeburn 8132:
8133: =item makedocslogform()
8134:
1.484.2.3 raeburn 8135: =item makesimpleeditform()
8136:
1.329 droeschl 8137: =back
8138:
8139: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>