Annotation of loncom/interface/londocs.pm, revision 1.484.2.85.2.6
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.5 2020/09/02 02:33:04 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');
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'}) = @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'; }
786: $name = &LONCAPA::map::qtunescape($name);
1.484.2.27 raeburn 787: if ($name eq '') {
1.484.2.30 raeburn 788: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.484.2.27 raeburn 789: }
790: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
791: my $filepath = $1;
792: my $fname = $name;
793: if ($fname =~ /^\W+$/) {
794: $fname = 'web';
795: } else {
796: $fname =~ s/\W/_/g;
797: }
1.484.2.62 raeburn 798: if (length($fname) > 15) {
1.484.2.27 raeburn 799: $fname = substr($fname,0,14);
800: }
801: my $initialtext = &mt('Replace with your own content.');
802: my $newhtml = <<END;
1.484.2.31 raeburn 803: <html>
1.484.2.27 raeburn 804: <head>
805: <title>$name</title>
806: </head>
807: <body bgcolor="#ffffff">
808: $initialtext
809: </body>
810: </html>
811: END
812: $env{'form.output'}=$newhtml;
813: my $result =
814: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
815: 'output',
816: "$filepath/$residx/$fname.html");
817: if ($result =~ m{^/uploaded/}) {
818: $url = $result;
819: if ($filepath =~ /^supplemental/) {
820: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
821: $env{'user.domain'}.'___&&&___'.$name;
822: }
823: } else {
824: return (&mt('Failed to save new web page.'),1);
825: }
826: }
1.484.2.30 raeburn 827: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 828: $LONCAPA::map::resources[$residx] =
1.329 droeschl 829: join(':', ($name, $url, $ext, 'normal', 'res'));
830: }
831: }
1.484.2.23 raeburn 832: if ($importuploaded) {
833: my %import_errors;
834: my %updated = (
835: removefrommap => \%removefrommap,
836: removeparam => \%removeparam,
837: );
1.484.2.26 raeburn 838: my ($result,$msgsarray,$lockerror) =
839: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 840: if (keys(%import_errors) > 0) {
841: $fixuperrors =
842: '<p span class="LC_warning">'."\n".
843: &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".
844: '<ul>'."\n";
845: foreach my $key (sort(keys(%import_errors))) {
846: $fixuperrors .= '<li>'.$key.'</li>'."\n";
847: }
848: $fixuperrors .= '</ul></p>'."\n";
849: }
1.484.2.26 raeburn 850: if (ref($msgsarray) eq 'ARRAY') {
851: if (@{$msgsarray} > 0) {
852: $fixuperrors .= '<p class="LC_info">'.
853: join('<br />',@{$msgsarray}).
854: '</p>';
855: }
856: }
857: if ($lockerror) {
858: $fixuperrors .= '<p class="LC_error">'.
859: $lockerror.
860: '</p>';
861: }
1.484.2.23 raeburn 862: }
863: my ($errtext,$fatal) =
864: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 865: unless ($fatal) {
866: if ($folder =~ /^supplemental/) {
867: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 868: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
869: $folder.'.'.$container);
1.484.2.37 raeburn 870: }
871: }
1.484.2.23 raeburn 872: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 873: }
874:
875: sub log_docs {
1.484.2.8 raeburn 876: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 877: }
878:
879: {
880: my @oldresources=();
881: my @oldorder=();
882: my $parmidx;
883: my %parmaction=();
884: my %parmvalue=();
885: my $changedflag;
886:
887: sub snapshotbefore {
888: @oldresources=@LONCAPA::map::resources;
889: @oldorder=@LONCAPA::map::order;
890: $parmidx=undef;
891: %parmaction=();
892: %parmvalue=();
893: $changedflag=0;
894: }
895:
896: sub remember_parms {
897: my ($idx,$parameter,$action,$value)=@_;
898: $parmidx=$idx;
899: $parmaction{$parameter}=$action;
900: $parmvalue{$parameter}=$value;
901: $changedflag=1;
902: }
903:
904: sub log_differences {
905: my ($plain)=@_;
906: my %storehash=('folder' => $plain,
907: 'currentfolder' => $env{'form.folder'});
908: if ($parmidx) {
909: $storehash{'parameter_res'}=$oldresources[$parmidx];
910: foreach my $parm (keys(%parmaction)) {
911: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
912: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
913: }
914: }
915: my $maxidx=$#oldresources;
916: if ($#LONCAPA::map::resources>$#oldresources) {
917: $maxidx=$#LONCAPA::map::resources;
918: }
919: for (my $idx=0; $idx<=$maxidx; $idx++) {
920: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
921: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
922: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
923: $changedflag=1;
924: }
925: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
926: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
927: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
928: $changedflag=1;
929: }
930: }
931: $storehash{'maxidx'}=$maxidx;
932: if ($changedflag) { &log_docs(\%storehash); }
933: }
934: }
935:
936: sub docs_change_log {
1.484.2.67 raeburn 937: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 938: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 939: my $navmap;
1.483 raeburn 940: my $js = '<script type="text/javascript">'."\n".
941: '// <![CDATA['."\n".
942: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 943: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.85.2. (raeburn 944:): $coursedom,$coursenum,'',$canedit,'',\$navmap)."\n".
1.483 raeburn 945: &history_tab_js()."\n".
1.484 raeburn 946: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 947: '// ]]>'."\n".
948: '</script>'."\n";
1.484 raeburn 949: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
950: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 951: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 952: my %orderhash;
953: my $container='sequence';
954: my $pathitem;
1.484.2.19 raeburn 955: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 956: $container='page';
957: }
1.484.2.19 raeburn 958: my $folderpath=$env{'form.folderpath'};
959: if ($folderpath eq '') {
1.484.2.67 raeburn 960: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 961: }
1.484.2.67 raeburn 962: undef($navmap);
1.484.2.19 raeburn 963: $pathitem = '<input type="hidden" name="folderpath" value="'.
964: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 965: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
966: my $jumpto = $readfile;
967: $jumpto =~ s{^/}{};
968: my $tid = 1;
1.484.2.7 raeburn 969: if ($supplementalflag) {
970: $tid = 2;
971: }
1.484.2.19 raeburn 972: my ($breadcrumbtrail) =
1.484.2.18 raeburn 973: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 974: $r->print($breadcrumbtrail.
975: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
976: $readfile));
1.329 droeschl 977: my %docslog=&Apache::lonnet::dump('nohist_docslog',
978: $env{'course.'.$env{'request.course.id'}.'.domain'},
979: $env{'course.'.$env{'request.course.id'}.'.num'});
980:
981: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
982:
983: my %saveable_parameters = ('show' => 'scalar',);
984: &Apache::loncommon::store_course_settings('docs_log',
985: \%saveable_parameters);
986: &Apache::loncommon::restore_course_settings('docs_log',
987: \%saveable_parameters);
988: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 989: # FIXME: internationalization seems wrong here
1.329 droeschl 990: my %lt=('hiddenresource' => 'Resources hidden',
991: 'encrypturl' => 'URL hidden',
992: 'randompick' => 'Randomly pick',
993: 'randomorder' => 'Randomly ordered',
994: 'set' => 'set to',
995: 'del' => 'deleted');
1.484 raeburn 996: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
997: $pathitem."\n".
998: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
999: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1000: $r->print('<div class="LC_left_float">'.
1001: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1002: &makedocslogform($filter,1).
1003: '</fieldset></div><br clear="all" />');
1.329 droeschl 1004: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1005: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1006: &mt('After').'</th>'.
1007: &Apache::loncommon::end_data_table_header_row());
1008: my $shown=0;
1009: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1010: if ($env{'form.displayfilter'} eq 'currentfolder') {
1011: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1012: }
1013: my @changes=keys(%{$docslog{$id}{'logentry'}});
1014: if ($env{'form.displayfilter'} eq 'containing') {
1015: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1016: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1017: foreach my $key (@changes) {
1018: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1019: }
1.344 bisitz 1020: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1021: }
1022: my $count = 0;
1023: my $time =
1024: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1025: my $plainname =
1026: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1027: $docslog{$id}{'exe_udom'});
1028: my $about_me_link =
1029: &Apache::loncommon::aboutmewrapper($plainname,
1030: $docslog{$id}{'exe_uname'},
1031: $docslog{$id}{'exe_udom'});
1032: my $send_msg_link='';
1033: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1034: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1035: $send_msg_link ='<br />'.
1036: &Apache::loncommon::messagewrapper(&mt('Send message'),
1037: $docslog{$id}{'exe_uname'},
1038: $docslog{$id}{'exe_udom'});
1039: }
1040: $r->print(&Apache::loncommon::start_data_table_row());
1041: $r->print('<td>'.$time.'</td>
1042: <td>'.$about_me_link.
1043: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1044: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1045: $send_msg_link.'</td><td>'.
1046: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 1047: my $is_supp = 0;
1.484.2.7 raeburn 1048: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1049: $is_supp = 1;
1050: }
1.329 droeschl 1051: # Before
1052: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1053: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1054: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1055: if ($oldname ne $newname) {
1.484.2.7 raeburn 1056: my $shown = &LONCAPA::map::qtescape($oldname);
1057: if ($is_supp) {
1058: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1059: }
1060: $r->print($shown);
1.329 droeschl 1061: }
1062: }
1063: $r->print('<ul>');
1064: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1065: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 1066: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1067: if ($is_supp) {
1068: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1069: }
1.484.2.19 raeburn 1070: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1071: }
1072: }
1073: $r->print('</ul>');
1074: # After
1075: $r->print('</td><td>');
1076:
1077: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1078: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1079: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1080: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 1081: my $shown = &LONCAPA::map::qtescape($newname);
1082: if ($is_supp) {
1083: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1084: }
1085: $r->print($shown);
1.329 droeschl 1086: }
1.364 bisitz 1087: }
1.329 droeschl 1088: $r->print('<ul>');
1089: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1090: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 1091: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1092: if ($is_supp) {
1093: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1094: }
1095: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1096: }
1097: }
1098: $r->print('</ul>');
1099: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1100: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1101: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1102: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1103: # FIXME: internationalization seems wrong here
1.329 droeschl 1104: $r->print('<li>'.
1105: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1106: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1107: .'</li>');
1108: }
1109: }
1110: $r->print('</ul>');
1111: }
1112: # End
1113: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1114: $shown++;
1115: if (!($env{'form.show'} eq &mt('all')
1116: || $shown<=$env{'form.show'})) { last; }
1117: }
1.484 raeburn 1118: $r->print(&Apache::loncommon::end_data_table()."\n".
1119: &makesimpleeditform($pathitem)."\n".
1120: '</div></div>');
1121: $r->print(&endContentScreen());
1.329 droeschl 1122: }
1123:
1124: sub update_paste_buffer {
1.484.2.7 raeburn 1125: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1126: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1127: if ($env{'form.multiremove'}) {
1128: $env{'form.multiremove'} =~ s/,$//;
1129: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1130: }
1131: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1132: if ($env{'form.multicut'}) {
1133: $env{'form.multicut'} =~ s/,$//;
1134: foreach my $item (split(/,/,$env{'form.multicut'})) {
1135: unless ($removals{$item}) {
1136: $cuts{$item} = 1;
1137: push(@possibles,$item.':cut');
1138: }
1139: }
1140: }
1141: if ($env{'form.multicopy'}) {
1142: $env{'form.multicopy'} =~ s/,$//;
1143: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1144: unless ($removals{$item} || $cuts{$item}) {
1145: push(@possibles,$item.':copy');
1146: }
1147: }
1148: }
1149: } elsif ($env{'form.markcopy'}) {
1150: @possibles = split(/,/,$env{'form.markcopy'});
1151: }
1.329 droeschl 1152:
1.484.2.30 raeburn 1153: return if (@possibles == 0);
1.329 droeschl 1154: return if (!defined($env{'form.copyfolder'}));
1155:
1156: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1157: $env{'form.copyfolder'});
1158: return if ($fatal);
1159:
1.484.2.30 raeburn 1160: my %curr_groups = &Apache::longroup::coursegroups();
1161:
1162: # Retrieve current paste buffer suffixes.
1163: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1164: my (%pasteurls,@newpaste);
1165:
1166: # Construct identifiers for current contents of user's paste buffer
1167: if (@currpaste) {
1168: foreach my $suffix (@currpaste) {
1.484.2.85.2. (raeburn 1169:): my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1170:): my $url = $env{'docs.markedcopy_url_'.$suffix};
1171:): my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1172:): if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1173:): ($url ne '')) {
1174:): if ($url eq '/res/lib/templates/simpleproblem.problem') {
1175:): $pasteurls{$cid.'_'.$mapidx} = 1;
1176:): } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1177:): $pasteurls{$url} = 1;
1178:): } else {
1179:): $pasteurls{$cid.'_'.$url} = 1;
1180:): }
1181:): }
1.484.2.30 raeburn 1182: }
1183: }
1184:
1185: # Mark items for copying (skip any items already in user's paste buffer)
1186: my %addtoenv;
1.484.2.82 raeburn 1187:
1188: my @pathitems = split(/\&/,$env{'form.folderpath'});
1189: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.85.2. (raeburn 1190:): my $ispage = $folderconf[5];
1.484.2.82 raeburn 1191:
1.484.2.30 raeburn 1192: foreach my $item (@possibles) {
1193: my ($orderidx,$cmd) = split(/:/,$item);
1194: next if ($orderidx =~ /\D/);
1195: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1196: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1197: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1198: my %denied = &action_restrictions($coursenum,$coursedom,
1199: &LONCAPA::map::qtescape($url),
1200: $env{'form.folderpath'},\%curr_groups);
1201: next if ($denied{'copy'});
1202: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.85.2. (raeburn 1203:): if ($url eq '/res/lib/templates/simpleproblem.problem') {
1204:): next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1205:): } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1206:): next if (exists($pasteurls{$url}));
1207:): } else {
1208:): next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1209:): }
1.484.2.30 raeburn 1210: my ($suffix,$errortxt,$locknotfreed) =
1211: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1212: if ($suffix ne '') {
1213: push(@newpaste,$suffix);
1214: } else {
1215: if ($locknotfreed) {
1216: return $locknotfreed;
1217: }
1.484.2.30 raeburn 1218: }
1219: if (&is_supplemental_title($title)) {
1220: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1221: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1222: }
1223:
1224: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1225: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1226: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1227: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1228: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1229: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1230: my $prefix = $1;
1231: my $subdir =$2;
1232: if ($subdir eq '') {
1233: $subdir = $prefix;
1.484.2.7 raeburn 1234: }
1.484.2.30 raeburn 1235: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.484.2.85.2. (raeburn 1236:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1237:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.484.2.30 raeburn 1238: if (ref($hierarchy{$url}) eq 'HASH') {
1239: my ($nested,$nestednames);
1240: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1241: $nested =~ s/\&$//;
1242: $nestednames =~ s/\Q___&&&___\E$//;
1243: if ($nested ne '') {
1244: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1245: }
1246: if ($nestednames ne '') {
1247: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1248: }
1.484.2.7 raeburn 1249: }
1250: }
1.484.2.57 raeburn 1251: if ($locknotfreed) {
1252: $output = $locknotfreed;
1253: last;
1254: }
1.484.2.7 raeburn 1255: }
1.484.2.30 raeburn 1256: if (@newpaste) {
1257: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1258: }
1.484.2.7 raeburn 1259: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1260: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1261: return $output;
1.329 droeschl 1262: }
1263:
1.484.2.7 raeburn 1264: sub recurse_uploaded_maps {
1265: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1266: if (ref($hierarchy->{$url}) eq 'HASH') {
1267: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1268: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1269: my (@uploaded,@names,%shorter);
1270: for (my $i=0; $i<@maps; $i++) {
1271: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1272: if ($inner ne '') {
1273: push(@uploaded,$inner);
1274: push(@names,&escape($titles[$i]));
1275: $shorter{$maps[$i]} = $inner;
1276: }
1277: }
1278: $$nestref .= "$dir:".join(',',@uploaded).'&';
1279: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1280: foreach my $map (@maps) {
1281: if ($shorter{$map} ne '') {
1282: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1283: }
1284: }
1285: }
1286: return;
1287: }
1288:
1.329 droeschl 1289: sub print_paste_buffer {
1.484.2.7 raeburn 1290: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1291: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1292:
1.484.2.30 raeburn 1293: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1294: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1295: }
1296:
1.484.2.30 raeburn 1297: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1298: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1299: my $clipboardcount = 0;
1.484.2.7 raeburn 1300:
1.484.2.30 raeburn 1301: # Construct identifiers for current contents of user's paste buffer
1302: foreach my $suffix (@currpaste) {
1303: next if ($suffix =~ /\D/);
1304: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1305: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1306: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1307: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1308: ($url ne '')) {
1.484.2.47 raeburn 1309: $clipboardcount ++;
1.484.2.30 raeburn 1310: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.484.2.85.2. (raeburn 1311:): $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.484.2.30 raeburn 1312: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1313: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1314: $is_external = 1;
1.484.2.85.2. (raeburn 1315:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1316:): $is_exttool = 1;
1.484.2.7 raeburn 1317: }
1.484.2.30 raeburn 1318: if ($folder =~ /^supplemental/) {
1319: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1320: unless ($canpaste) {
1321: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1322: }
1.484.2.30 raeburn 1323: } else {
1324: $canpaste = 1;
1.484.2.7 raeburn 1325: }
1.484.2.30 raeburn 1326: if ($canpaste) {
1327: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1328: my $srcdom = $1;
1329: my $srcnum = $2;
1330: my $rem = $3;
1331: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1332: $othercourse = 1;
1333: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1334: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1335: } else {
1336: $canpaste = 0;
1337: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1338: }
1339: }
1.484.2.30 raeburn 1340: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1341: my $prefix = $1;
1342: $parent = $2;
1343: if ($folder !~ /^\Q$prefix\E/) {
1344: $areachange = 1;
1345: }
1346: $is_uploaded_map = 1;
1347: }
1.484.2.82 raeburn 1348: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.484.2.85.2. (raeburn 1349:): ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.484.2.76 raeburn 1350: if ($cid ne $env{'request.course.id'}) {
1351: my ($srcdom,$srcnum) = split(/_/,$cid);
1352: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.85.2. (raeburn 1353:): if (($is_exttool) && ($srcdom ne $coursedom)) {
1354:): $canpaste = 0;
1355:): $nopaste = &mt('Paste from another domain unavailable.');
1356:): } else {
1357:): $othercrs = '<br />'.&mt('(from another course)');
1358:): }
1.484.2.76 raeburn 1359: } else {
1360: $canpaste = 0;
1361: $nopaste = &mt('Paste from another course unavailable.');
1362: }
1363: }
1364: }
1365: if ($canpaste) {
1366: push(@pasteable,$suffix);
1.484.2.30 raeburn 1367: }
1368: }
1369: my $buffer;
1370: if ($is_external) {
1371: $buffer = &mt('External Resource').': '.
1372: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1373: &LONCAPA::map::qtescape($url).')';
1.484.2.85.2. (raeburn 1374:): } elsif ($is_exttool) {
1375:): $buffer = &mt('External Tool').': '.
1376:): &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.30 raeburn 1377: } else {
1378: my $icon = &Apache::loncommon::icon($extension);
1379: if ($extension eq 'sequence' &&
1380: $url =~ m{/default_\d+\.sequence$}x) {
1381: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1382: $icon .= '/navmap.folder.closed.gif';
1383: }
1.484.2.57 raeburn 1384: my $title = $env{'docs.markedcopy_title_'.$suffix};
1385: if ($title eq '') {
1386: ($title) = ($url =~ m{/([^/]+)$});
1387: }
1.484.2.30 raeburn 1388: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1389: ': '.
1390: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1391: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1392: }
1393: $pasteitems .= '<div class="LC_left_float">';
1394: my ($options,$onclick);
1395: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1396: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1397: if (($is_uploaded_map) ||
1398: ($url =~ /(bulletinboard|smppg)$/) ||
1399: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1400: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1401: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1402: }
1403: }
1404: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1405: if ($nopaste) {
1406: $pasteitems .= $nopaste;
1407: } else {
1408: if ($othercrs) {
1409: $pasteitems .= $othercrs;
1410: }
1411: if ($options) {
1412: $pasteitems .= $options;
1.484.2.7 raeburn 1413: }
1414: }
1.484.2.30 raeburn 1415: $pasteitems .= '</div>';
1416: }
1417: }
1418: if ($pasteitems eq '') {
1419: &Apache::lonnet::delenv('docs.markedcopies');
1420: }
1421: my ($pasteform,$form_start,$buttons,$form_end);
1422: if ($pasteitems) {
1423: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1424: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1425: if (@pasteable) {
1.484.2.47 raeburn 1426: my $value = &mt('Paste to current folder');
1427: if ($container eq 'page') {
1428: $value = &mt('Paste to current page');
1429: }
1430: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1431: }
1.484.2.85.2. (raeburn 1432:): $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1.484.2.47 raeburn 1433: if ($clipboardcount > 1) {
1434: $buttons .=
1435: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1436: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1437: (' 'x2).
1438: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1439: (' 'x2);
1.484.2.7 raeburn 1440: }
1.484.2.48 raeburn 1441: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1442: '</form>';
1.484.2.30 raeburn 1443: } else {
1444: $pasteitems = &mt('Clipboard is empty');
1445: }
1446: $r->print($form_start
1447: .'<fieldset>'
1448: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1449: .$pasteitems
1450: .'</fieldset>'
1451: .$form_end);
1452: }
1453:
1454: sub paste_options {
1455: my ($suffix,$is_uploaded_map,$parent) = @_;
1456: my ($copytext,$movetext);
1457: if ($is_uploaded_map) {
1458: $copytext = &mt('Copy to new folder');
1459: $movetext = &mt('Move old');
1460: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1461: $copytext = &mt('Copy to new board');
1462: $movetext = &mt('Move (not posts)');
1463: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1464: $copytext = &mt('Copy to new page');
1465: $movetext = &mt('Move');
1.484.2.7 raeburn 1466: } else {
1.484.2.30 raeburn 1467: $copytext = &mt('Copy to new file');
1468: $movetext = &mt('Move');
1469: }
1470: my $output = '<br />'.
1471: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1472: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1473: '<label>'.
1474: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1475: $copytext.'</label></span>'.(' 'x2).' '.
1476: '<span class="LC_nobreak"><label>'.
1477: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1478: $movetext.'</label></span>';
1479: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1480: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1481: '</legend><table border="0">';
1482: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1483: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1484: my $lastdir = $parent;
1485: my %depths = (
1486: $lastdir => 0,
1487: );
1488: my (%display,%deps);
1489: for (my $i=0; $i<@pastemaps; $i++) {
1490: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1491: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1492: my @subfolders = split(/,/,$subfolderstr);
1493: $deps{$lastdir} = \@subfolders;
1494: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1495: my $depth = $depths{$lastdir} + 1;
1496: my $offset = int($depth * 4);
1497: my $indent = (' ' x $offset);
1498: for (my $j=0; $j<@subfolders; $j++) {
1499: $depths{$subfolders[$j]} = $depth;
1500: $display{$subfolders[$j]} =
1501: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1502: '<td><label>'.
1503: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1504: '<label>'.
1505: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1506: &mt('Move old').'</label>'.
1507: '</td></tr>';
1508: }
1509: }
1510: &recurse_print(\$output,$parent,\%deps,\%display);
1511: $output .= '</table></fieldset>';
1.329 droeschl 1512: }
1.484.2.30 raeburn 1513: $output .= '</div>';
1514: return $output;
1.329 droeschl 1515: }
1516:
1.484.2.7 raeburn 1517: sub recurse_print {
1.484.2.30 raeburn 1518: my ($outputref,$dir,$deps,$display) = @_;
1519: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1520: if (ref($deps->{$dir}) eq 'ARRAY') {
1521: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1522: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1523: }
1524: }
1525: }
1526:
1527: sub supp_pasteable {
1528: my ($url) = @_;
1529: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1530: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1531: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1532: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.484.2.85.2. (raeburn 1533:): ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1534:): ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.484.2.7 raeburn 1535: return 1;
1536: }
1537: return;
1538: }
1539:
1540: sub paste_popup_js {
1.484.2.61 raeburn 1541: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1542: show => 'Show Options',
1543: hide => 'Hide Options',
1.484.2.61 raeburn 1544: );
1545: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1546: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1547: );
1.484.2.61 raeburn 1548: &html_escape(\%html_js_lt);
1549: &js_escape(\%html_js_lt);
1550: &js_escape(\%js_lt);
1.484.2.7 raeburn 1551: return <<"END";
1552:
1.484.2.30 raeburn 1553: function showPasteOptions(suffix) {
1554: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1555: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1556: return;
1557: }
1558:
1.484.2.30 raeburn 1559: function hidePasteOptions(suffix) {
1560: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1561: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1562: return;
1563: }
1564:
1.484.2.30 raeburn 1565: function showOptions(caller,suffix) {
1566: if (document.getElementById('pasteoptionstext_'+suffix)) {
1567: if (caller.checked) {
1.484.2.61 raeburn 1568: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1569: } else {
1570: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1571: }
1572: if (document.getElementById('pasteoptions_'+suffix)) {
1573: document.getElementById('pasteoptions_'+suffix).style.display='none';
1574: }
1575: }
1576: return;
1577: }
1.484.2.7 raeburn 1578:
1.484.2.30 raeburn 1579: function validateClipboard() {
1580: var numchk = 0;
1581: if (document.pasteform.pasting.length > 1) {
1582: for (var i=0; i<document.pasteform.pasting.length; i++) {
1583: if (document.pasteform.pasting[i].checked) {
1584: numchk ++;
1585: }
1586: }
1587: } else {
1588: if (document.pasteform.pasting.type == 'checkbox') {
1589: if (document.pasteform.pasting.checked) {
1590: numchk ++;
1591: }
1592: }
1593: }
1594: if (numchk > 0) {
1595: return true;
1596: } else {
1.484.2.61 raeburn 1597: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1598: return false;
1599: }
1.484.2.7 raeburn 1600: }
1601:
1.484.2.47 raeburn 1602: function checkClipboard() {
1603: if (document.pasteform.pasting.length > 1) {
1604: for (var i=0; i<document.pasteform.pasting.length; i++) {
1605: document.pasteform.pasting[i].checked = true;
1606: }
1607: }
1608: return;
1609: }
1610:
1611: function uncheckClipboard() {
1612: if (document.pasteform.pasting.length >1) {
1613: for (var i=0; i<document.pasteform.pasting.length; i++) {
1614: document.pasteform.pasting[i].checked = false;
1615: }
1616: }
1617: return;
1618: }
1619:
1.484.2.30 raeburn 1620: END
1621:
1622: }
1.484.2.7 raeburn 1623:
1.329 droeschl 1624: sub do_paste_from_buffer {
1.484.2.7 raeburn 1625: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1626:
1.484.2.30 raeburn 1627: # Array of items in paste buffer
1628: my (@currpaste,%pastebuffer,%allerrors);
1629: @currpaste = split(/,/,$env{'docs.markedcopies'});
1630:
1.484.2.7 raeburn 1631: # Early out if paste buffer is empty
1.484.2.30 raeburn 1632: if (@currpaste == 0) {
1.484.2.7 raeburn 1633: return ();
1.484.2.30 raeburn 1634: }
1635: map { $pastebuffer{$_} = 1; } @currpaste;
1636:
1637: # Array of items selected items to paste
1638: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1639:
1640: # Early out if nothing selected to paste
1641: if (@reqpaste == 0) {
1642: return();
1643: }
1644: my @topaste;
1645: foreach my $suffix (@reqpaste) {
1646: next if ($suffix =~ /\D/);
1647: next unless (exists($pastebuffer{$suffix}));
1648: push(@topaste,$suffix);
1.484.2.7 raeburn 1649: }
1650:
1.484.2.30 raeburn 1651: # Early out if nothing available to paste
1652: if (@topaste == 0) {
1653: return();
1.329 droeschl 1654: }
1655:
1.484.2.85.2. (raeburn 1656:): my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.484.2.82 raeburn 1657: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1658:
1.484.2.30 raeburn 1659: foreach my $suffix (@topaste) {
1660: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1661: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1662: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1663: # Supplemental content may only include certain types of content
1664: # Early out if pasted content is not supported in Supplemental area
1665: if ($folder =~ /^supplemental/) {
1666: unless (&supp_pasteable($url)) {
1667: $notinsupp{$suffix} = 1;
1668: next;
1669: }
1670: }
1671: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1672: my $srcd = $1;
1673: my $srcn = $2;
1.484.2.7 raeburn 1674: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1675: # check for mdc privilege in the course from which the resource was pasted
1676: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1677: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1678: $notincrs{$suffix} = 1;
1679: next;
1680: }
1.329 droeschl 1681: }
1.484.2.30 raeburn 1682: $srcdom{$suffix} = $srcd;
1683: $srcnum{$suffix} = $srcn;
1.484.2.85.2. (raeburn 1684:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1685:): my ($srcd,$srcn) = split(/_/,$cid);
1686:): # When paste buffer was populated using an active role in a different course
1687:): # check for mdc privilege in the course from which the resource was pasted
1688:): if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1689:): unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1690:): $notincrs{$suffix} = 1;
1691:): next;
1692:): }
1693:): }
1694:): # When buffer was populated using an active role in a different course
1695:): # disallow pasting of External Tool if course is in a different domain.
1696:): if ($srcd ne $coursedom) {
1697:): $notindom{$suffix} = 1;
1698:): next;
1699:): }
1700:): $srcdom{$suffix} = $srcd;
1701:): $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1702: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1703: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1704: my ($srcd,$srcn) = split(/_/,$cid);
1705: # When paste buffer was populated using an active role in a different course
1706: # check for mdc privilege in the course from which the resource was pasted
1707: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1708: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1709: $notincrs{$suffix} = 1;
1710: next;
1711: }
1712: }
1713: $srcdom{$suffix} = $srcd;
1714: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1715: }
1.484.2.82 raeburn 1716: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1717: push(@dopaste,$suffix);
1718: if ($url=~/\.(page|sequence)$/) {
1719: $is_map{$suffix} = 1;
1.329 droeschl 1720: }
1.484.2.30 raeburn 1721:
1722: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1723: my $oldprefix = $1;
1.484.2.19 raeburn 1724: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1725: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1726: # a folder/page or a document).
1.484.2.30 raeburn 1727: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1728: $prefixchg{$suffix} = 'docstosupp';
1729: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1730: $prefixchg{$suffix} = 'supptodocs';
1731: }
1.484.2.7 raeburn 1732:
1733: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1734: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1735: my @nested;
1736: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1737: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1738: my @deps = map { /\d+:([\d,]+$)/ } @items;
1739: foreach my $dep (@deps) {
1740: if ($dep =~ /,/) {
1741: push(@nested,split(/,/,$dep));
1742: } else {
1743: push(@nested,$dep);
1744: }
1.484.2.7 raeburn 1745: }
1.484.2.30 raeburn 1746: foreach my $item (@nested) {
1747: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1748: push(@{$marktomove{$suffix}},$type.'_'.$item);
1749: }
1.484.2.7 raeburn 1750: }
1751: }
1.329 droeschl 1752: }
1.484.2.7 raeburn 1753: }
1754:
1.484.2.30 raeburn 1755: # Early out if nothing available to paste
1756: if (@dopaste == 0) {
1757: return ();
1758: }
1759:
1760: # Populate message hash and hashes used for main content <=> supplemental content
1761: # changes
1762:
1763: %msgs = &Apache::lonlocal::texthash (
1764: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1765: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.484.2.85.2. (raeburn 1766:): notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.484.2.30 raeburn 1767: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1768: );
1769:
1770: %before = (
1771: docstosupp => {
1772: map => 'default',
1773: doc => 'docs',
1774: },
1775: supptodocs => {
1776: map => 'supplemental',
1777: doc => 'supplemental',
1778: },
1779: );
1780:
1781: %after = (
1782: docstosupp => {
1783: map => 'supplemental',
1784: doc => 'supplemental'
1785: },
1786: supptodocs => {
1787: map => 'default',
1788: doc => 'docs',
1789: },
1790: );
1791:
1792: # Retrieve information about all course maps in main content area
1793:
1794: my $allmaps = {};
1.484.2.79 raeburn 1795: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1796:
1797: # Loop over the items to paste
1798: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1799: # Maps need to be copied first
1.484.2.30 raeburn 1800: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1801: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1802: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1803: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1804: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1805: }
1806: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1807: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1808: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1809: my $oldurl = $url;
1810: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1811: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1812: my (%hierarchy,%titles);
1.484.2.79 raeburn 1813: if (($folder =~ /^default/) && (!$donechk)) {
1814: $allmaps =
1815: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1816: $env{"course.$env{'request.course.id'}.home"},
1817: $env{'request.course.id'});
1818: $donechk = 1;
1819: }
1.484.2.85.2. (raeburn 1820:): &contained_map_check($url,$folder,$coursenum,$coursedom,
1821:): \%removefrommap,\%removeparam,\%addedmaps,
1822:): \%hierarchy,\%titles,$allmaps);
1.484.2.30 raeburn 1823: if ($url=~ m{^/uploaded/}) {
1824: my $newurl;
1825: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1826: ($newurl,my $error) =
1827: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1828: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1829: \$title,$allmaps,\%newurls);
1830: if ($error) {
1831: $allerrors{$suffix} = $error;
1832: next;
1833: }
1834: if ($newurl ne '') {
1835: if ($newurl ne $url) {
1836: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1837: $newsubdir{$url} = $1;
1838: }
1839: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1840: }
1841: }
1842: }
1.484.2.30 raeburn 1843: if (($srcdom{$suffix} ne $coursedom) ||
1844: ($srcnum{$suffix} ne $coursenum) ||
1845: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1846: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1847: $coursedom,$coursenum,$srcdom{$suffix},
1848: $srcnum{$suffix},$allmaps,\%rewrites,
1849: \%retitles,\%copies,\%dbcopies,
1850: \%zombies,\%params,\%mapmoves,
1851: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1852: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1853: $mapmoves{$url} = 1;
1854: }
1855: $url = $newurl;
1856: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1857: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1858: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1859: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1860: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1861: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1862: }
1863: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1864: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1865: push(@toclear,$suffix);
1866: # if pasting published map (main content area only) check map not already in course
1867: if ($folder =~ /^default/) {
1868: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1869: $duplicate{$suffix} = 1;
1870: next;
1871: }
1.484.2.7 raeburn 1872: }
1873: }
1874: }
1.484.2.85.2. (raeburn 1875:): if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.484.2.30 raeburn 1876: my $prefix = $1;
1.484.2.76 raeburn 1877: my $fromothercrs;
1.484.2.30 raeburn 1878: #need to copy the db contents to a new one, unless this is a move.
1879: my %info = (
1880: src => $url,
1881: cdom => $coursedom,
1882: cnum => $coursenum,
1.484.2.76 raeburn 1883: );
1884: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1885: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1886: $fromothercrs = 1;
1887: $info{'cdom'} = $srcdom{$suffix};
1888: $info{'cnum'} = $srcnum{$suffix};
1889: }
1890: }
1891: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1892: my (%lockerr,$msg);
1893: my ($newurl,$result,$errtext) =
1894: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1895: if ($result eq 'ok') {
1896: $url = $newurl;
1897: $title=&mt('Copy of').' '.$title;
1898: } else {
1899: if ($prefix eq 'smppg') {
1900: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1901: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1902: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.85.2. (raeburn 1903:): } elsif ($prefix eq 'ext.tool') {
1904:): $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.484.2.30 raeburn 1905: }
1906: $results{$suffix} = $result;
1907: $msgerrs{$suffix} = $msg;
1908: $lockerrs{$suffix} = $lockerr{$prefix};
1909: next;
1910: }
1911: if ($lockerr{$prefix}) {
1912: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1913: }
1.484.2.7 raeburn 1914: }
1.484.2.30 raeburn 1915: }
1916: $title = &LONCAPA::map::qtunescape($title);
1917: my $ext='false';
1918: if ($url=~m{^http(|s)://}) { $ext='true'; }
1919: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1920: if ($folder !~ /^supplemental/) {
1921: (undef,undef,$title) =
1922: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1923: }
1924: } else {
1925: if ($folder=~/^supplemental/) {
1926: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1927: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1928: }
1929: }
1.484.2.7 raeburn 1930:
1931: # For uploaded files (excluding pages/sequences) path in copied file is changed
1932: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1933: # courses.
1934:
1.484.2.30 raeburn 1935: unless ($is_map{$suffix}) {
1936: my $newidx;
1.329 droeschl 1937: # Now insert the URL at the bottom
1.484.2.30 raeburn 1938: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1939: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1940: my $relpath = $1;
1941: if ($relpath ne '') {
1942: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1943: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1944: my $newprefix = $newloc;
1945: if ($newloc eq 'default') {
1946: $newprefix = 'docs';
1947: }
1948: if ($newdocsdir eq '') {
1949: $newdocsdir = 'default';
1950: }
1951: if (($prefixchg{$suffix}) ||
1952: ($srcdom{$suffix} ne $coursedom) ||
1953: ($srcnum{$suffix} ne $coursenum) ||
1954: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1955: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1956: $url =
1957: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1958: &Apache::lonnet::getfile($oldurl));
1959: if ($url eq '/adm/notfound.html') {
1960: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1961: next;
1962: } else {
1963: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1964: $newsubpath =~ s{/+$}{/};
1965: $docmoves{$oldurl} = $newsubpath;
1966: }
1.484.2.7 raeburn 1967: }
1968: }
1.484.2.82 raeburn 1969: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1970: my $template = $1;
1971: if ($newidx) {
1972: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1973: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1974: }
1.484.2.7 raeburn 1975: }
1.484.2.30 raeburn 1976: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1977: ':'.$ext.':normal:res';
1978: push(@LONCAPA::map::order,$newidx);
1979: # Store the result
1980: my ($errtext,$fatal) =
1981: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1982: if ($fatal) {
1983: $save_err .= $errtext;
1984: $allresult = 'fail';
1.484.2.7 raeburn 1985: }
1.329 droeschl 1986: }
1.484.2.30 raeburn 1987:
1.484.2.82 raeburn 1988: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1989: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 1990: unless ($allresult eq 'fail') {
1991: my %updated = (
1992: rewrites => \%rewrites,
1993: zombies => \%zombies,
1994: removefrommap => \%removefrommap,
1995: removeparam => \%removeparam,
1996: dbcopies => \%dbcopies,
1.484.2.82 raeburn 1997: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 1998: retitles => \%retitles,
1999: );
2000: my %info = (
2001: newsubdir => \%newsubdir,
2002: params => \%params,
2003: );
2004: if ($prefixchg{$suffix}) {
2005: $info{'before'} = $before{$prefixchg{$suffix}};
2006: $info{'after'} = $after{$prefixchg{$suffix}};
2007: }
2008: my %moves = (
2009: copies => \%copies,
2010: docmoves => \%docmoves,
2011: mapmoves => \%mapmoves,
2012: );
2013: (my $result,$msgs{$suffix},my $lockerror) =
2014: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2015: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2016: $url,'paste');
2017: $lockerrors .= $lockerror;
2018: if ($result eq 'ok') {
2019: if ($is_map{$suffix}) {
2020: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2021: $folder.'.'.$container);
2022: if ($fatal) {
2023: $allresult = 'failread';
2024: } else {
2025: if ($#LONCAPA::map::order<1) {
2026: my $idx=&LONCAPA::map::getresidx();
2027: if ($idx<=0) { $idx=1; }
2028: $LONCAPA::map::order[0]=$idx;
2029: $LONCAPA::map::resources[$idx]='';
2030: }
2031: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2032: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2033: ':'.$ext.':normal:res';
2034: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 2035:
2036: # Store the result
1.484.2.30 raeburn 2037: my ($errtext,$fatal) =
2038: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2039: if ($fatal) {
2040: $save_err .= $errtext;
2041: $allresult = 'failstore';
2042: }
2043: }
2044: }
2045: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2046: push(@toclear,$suffix);
2047: }
2048: }
1.329 droeschl 2049: }
2050: }
1.484.2.30 raeburn 2051: &clear_from_buffer(\@toclear,\@currpaste);
2052: my $msgsarray;
2053: foreach my $suffix (keys(%msgs)) {
2054: if (ref($msgs{$suffix}) eq 'ARRAY') {
2055: $msgsarray .= join(',',@{$msgs{$suffix}});
2056: }
2057: }
2058: return ($allresult,$save_err,$msgsarray,$lockerrors);
2059: }
2060:
2061: sub do_buffer_empty {
2062: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2063: if (@currpaste == 0) {
2064: return &mt('Clipboard is already empty');
2065: }
2066: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2067: if (@toclear == 0) {
2068: return &mt('Nothing selected to clear from clipboard');
2069: }
2070: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2071: if ($numdel) {
2072: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2073: } else {
2074: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 2075: }
1.484.2.30 raeburn 2076: return;
2077: }
2078:
2079: sub clear_from_buffer {
2080: my ($toclear,$currpaste) = @_;
2081: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2082: my %pastebuffer;
2083: map { $pastebuffer{$_} = 1; } @{$currpaste};
2084: my $numdel = 0;
2085: foreach my $suffix (@{$toclear}) {
2086: next if ($suffix =~ /\D/);
2087: next unless (exists($pastebuffer{$suffix}));
2088: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2089: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2090: delete($pastebuffer{$suffix});
2091: $numdel ++;
2092: }
2093: }
2094: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2095: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2096: return $numdel;
1.484.2.7 raeburn 2097: }
2098:
2099: sub get_newmap_url {
2100: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2101: $titleref,$allmaps,$newurls) = @_;
2102: my $newurl;
2103: if ($url=~ m{^/uploaded/}) {
2104: $$titleref=&mt('Copy of').' '.$$titleref;
2105: }
2106: my $now = time;
2107: my $suffix=$$.int(rand(100)).$now;
2108: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2109: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2110: my $path = $1;
2111: my $prefix = $2;
2112: my $ancestor = $3;
2113: if (length($ancestor) > 10) {
2114: $ancestor = substr($ancestor,-10,10);
2115: }
2116: my $newid;
2117: if ($prefixchg) {
2118: if ($folder =~ /^supplemental/) {
2119: $prefix =~ s/^default/supplemental/;
2120: } else {
2121: $prefix =~ s/^supplemental/default/;
2122: }
2123: }
2124: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2125: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2126: } else {
2127: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2128: }
2129: my $counter = 0;
2130: my $is_unique = &uniqueness_check($newurl);
2131: if ($folder =~ /^default/) {
2132: if ($allmaps->{$newurl}) {
2133: $is_unique = 0;
2134: }
2135: }
2136: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2137: $counter ++;
2138: $suffix ++;
2139: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2140: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2141: } else {
2142: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2143: }
2144: $is_unique = &uniqueness_check($newurl);
2145: }
2146: if ($is_unique) {
2147: $newurls->{$newurl} = 1;
2148: } else {
2149: if ($url=~/\.page$/) {
2150: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2151: } else {
2152: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2153: }
2154: }
2155: }
2156: return ($newurl);
2157: }
2158:
2159: sub dbcopy {
1.484.2.26 raeburn 2160: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2161: my ($url,$result,$errtext);
2162: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2163: $url = $dbref->{'src'};
1.484.2.85.2. (raeburn 2164:): if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.484.2.26 raeburn 2165: my $prefix = $1;
1.484.2.85.2. (raeburn 2166:): if ($prefix eq 'ext.tool') {
2167:): $prefix = 'exttool';
2168:): }
1.484.2.26 raeburn 2169: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2170: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2171: my $db_name;
2172: my $marker = (split(m{/},$url))[4];
2173: $marker=~s/\D//g;
2174: if ($dbref->{'src'} =~ m{/smppg$}) {
2175: $db_name =
2176: &Apache::lonsimplepage::get_db_name($url,$marker,
2177: $dbref->{'cdom'},
2178: $dbref->{'cnum'});
1.484.2.85.2. (raeburn 2179:): } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2180:): $db_name = 'exttool_'.$marker;
1.484.2.26 raeburn 2181: } else {
2182: $db_name = 'bulletinpage_'.$marker;
2183: }
2184: my ($suffix,$freedlock,$error) =
2185: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2186: $coursedom,$coursenum,
2187: 'concat');
2188: if (!$suffix) {
2189: if ($prefix eq 'smppg') {
2190: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.484.2.85.2. (raeburn 2191:): } elsif ($prefix eq 'exttool') {
2192:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.484.2.26 raeburn 2193: } else {
1.484.2.42 raeburn 2194: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2195: }
2196: if ($error) {
2197: $errtext .= '<br />'.$error;
2198: }
2199: } else {
2200: #need to copy the db contents to a new one.
2201: my %contents=&Apache::lonnet::dump($db_name,
2202: $dbref->{'cdom'},
2203: $dbref->{'cnum'});
2204: if (exists($contents{'uploaded.photourl'})) {
2205: my $photo = $contents{'uploaded.photourl'};
2206: my ($subdir,$fname) =
2207: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2208: my $newphoto;
2209: if ($fname ne '') {
2210: my $content = &Apache::lonnet::getfile($photo);
2211: unless ($content eq '-1') {
2212: $env{'form.'.$suffix.'.photourl'} = $content;
2213: $newphoto =
2214: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2215: delete($env{'form.'.$suffix.'.photourl'});
2216: }
2217: }
2218: if ($newphoto =~ m{^/uploaded/}) {
2219: $contents{'uploaded.photourl'} = $newphoto;
2220: }
2221: }
2222: $db_name =~ s{_\d*$ }{_$suffix}x;
2223: $result=&Apache::lonnet::put($db_name,\%contents,
2224: $coursedom,$coursenum);
2225: if ($result eq 'ok') {
1.484.2.85.2. (raeburn 2226:): $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.484.2.26 raeburn 2227: }
2228: }
2229: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2230: $lockerrorsref->{$prefix} =
2231: '<div class="LC_error">'.
2232: &mt('There was a problem removing a lockfile.');
2233: if ($prefix eq 'smppg') {
2234: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2235: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.85.2. (raeburn 2236:): } elsif ($prefix eq 'exttool') {
2237:): $lockerrorsref->{$prefix} .=
2238:): ' '.&mt('This will prevent addition of more external tools to this course.');
1.484.2.26 raeburn 2239: } else {
1.484.2.42 raeburn 2240: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2241: }
1.484.2.38 raeburn 2242: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2243: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2244: '</div>';
1.484.2.26 raeburn 2245: }
2246: }
2247: } elsif ($url =~ m{/syllabus$}) {
2248: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2249: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2250: if (($dbref->{'cdom'} ne $coursedom) ||
2251: ($dbref->{'cnum'} ne $coursenum)) {
2252: my %contents=&Apache::lonnet::dump('syllabus',
2253: $dbref->{'cdom'},
2254: $dbref->{'cnum'});
2255: $result=&Apache::lonnet::put('syllabus',\%contents,
2256: $coursedom,$coursenum);
2257: }
2258: }
1.484.2.7 raeburn 2259: }
2260: }
1.484.2.26 raeburn 2261: return ($url,$result,$errtext);
1.329 droeschl 2262: }
2263:
1.484.2.82 raeburn 2264: sub copy_templated_files {
2265: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2266: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2267: my $srccontainer = 'sequence';
2268: if ($srcwaspage) {
2269: $srccontainer = 'page';
2270: }
2271: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2272: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2273: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2274: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2275: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2276: $template.'.problem';
2277: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2278: if ($template eq 'simpleproblem') {
2279: $srcprefix .= '.0.';
2280: my $weightprefix = $newprefix;
2281: $newprefix .= '.0.';
2282: my @simpleprobqtypes = qw(radio option string essay numerical);
2283: my $qtype=$srcparms{$srcprefix.'questiontype'};
2284: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2285: my %newdata = (
2286: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2287: );
1.484.2.82 raeburn 2288: foreach my $type (@simpleprobqtypes) {
2289: if ($type eq $qtype) {
2290: $newdata{"$weightprefix.$type.weight"}=1;
2291: } else {
2292: $newdata{"$weightprefix.$type.weight"}=0;
2293: }
2294: }
2295: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2296: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2297: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2298: if ($qtype eq 'numerical') {
2299: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2300: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2301: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2302: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2303: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2304: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2305: unless (defined($maxfoils)) { $maxfoils=10; }
2306: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2307: if ($maxfoils<=0) { $maxfoils=10; }
2308: my $randomize=$srcparms{$srcprefix.'randomize'};
2309: unless (defined($randomize)) { $randomize='yes'; }
2310: unless ($randomize eq 'no') { $randomize='yes'; }
2311: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2312: $newdata{$newprefix.'randomize'} = $randomize;
2313: if ($qtype eq 'option') {
2314: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2315: }
2316: for (my $i=1; $i<=10; $i++) {
2317: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2318: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2319: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2320: }
2321:
2322: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2323: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2324: unless (defined($maxfoils)) { $maxfoils=10; }
2325: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2326: if ($maxfoils<=0) { $maxfoils=10; }
2327: my $randomize=$srcparms{$srcprefix.'randomize'};
2328: unless (defined($randomize)) { $randomize='yes'; }
2329: unless ($randomize eq 'no') { $randomize='yes'; }
2330: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2331: $newdata{$newprefix.'randomize'} = $randomize;
2332: if ($qtype eq 'option') {
2333: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2334: }
2335: for (my $i=1; $i<=10; $i++) {
2336: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2337: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2338: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2339: }
2340: } elsif ($qtype eq 'string') {
2341: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2342: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2343: }
2344: if (keys(%newdata)) {
2345: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2346: $coursenum);
2347: if ($putres eq 'ok') {
2348: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2349: }
2350: }
2351: }
2352: }
2353: }
2354:
1.329 droeschl 2355: sub uniqueness_check {
2356: my ($newurl) = @_;
2357: my $unique = 1;
2358: foreach my $res (@LONCAPA::map::order) {
2359: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2360: $url=&LONCAPA::map::qtescape($url);
2361: if ($newurl eq $url) {
2362: $unique = 0;
1.344 bisitz 2363: last;
1.329 droeschl 2364: }
2365: }
2366: return $unique;
2367: }
2368:
1.484.2.7 raeburn 2369: sub contained_map_check {
1.484.2.85.2. (raeburn 2370:): my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2371:): $hierarchy,$titles,$allmaps) = @_;
1.484.2.7 raeburn 2372: my $content = &Apache::lonnet::getfile($url);
2373: unless ($content eq '-1') {
2374: my $parser = HTML::TokeParser->new(\$content);
2375: $parser->attr_encoded(1);
2376: while (my $token = $parser->get_token) {
2377: next if ($token->[0] ne 'S');
2378: if ($token->[1] eq 'resource') {
2379: next if ($token->[2]->{'type'} eq 'zombie');
2380: my $ressrc = $token->[2]->{'src'};
2381: if ($folder =~ /^supplemental/) {
2382: unless (&supp_pasteable($ressrc)) {
2383: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2384: next;
2385: }
2386: }
2387: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2388: if ($1 eq 'uploaded') {
2389: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2390: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2391: } else {
2392: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2393: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2394: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2395: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2396: } else {
2397: $addedmaps->{$ressrc} = [$url];
2398: }
2399: }
1.484.2.85.2. (raeburn 2400:): &contained_map_check($ressrc,$folder,$coursenum,$coursedom,
2401:): $removefrommap,$removeparam,
1.484.2.7 raeburn 2402: $addedmaps,$hierarchy,$titles,$allmaps);
2403: }
2404: } elsif ($token->[1] eq 'param') {
2405: if ($folder =~ /^supplemental/) {
2406: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2407: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2408: } else {
1.484.2.19 raeburn 2409: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2410: }
2411: }
2412: }
2413: }
2414: }
2415: return;
2416: }
2417:
2418: sub url_paste_fixups {
1.484.2.26 raeburn 2419: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2420: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2421: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2422: my $checktitle;
2423: if (($prefixchg) &&
2424: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2425: $checktitle = 1;
2426: }
2427: my $skip;
2428: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2429: my $mapid = $1.$2;
2430: if ($tomove->{$mapid}) {
2431: $skip = 1;
2432: }
2433: }
2434: my $file = &Apache::lonnet::getfile($oldurl);
2435: return if ($file eq '-1');
2436: my $parser = HTML::TokeParser->new(\$file);
2437: $parser->attr_encoded(1);
2438: my $changed = 0;
2439: while (my $token = $parser->get_token) {
2440: next if ($token->[0] ne 'S');
2441: if ($token->[1] eq 'resource') {
2442: my $ressrc = $token->[2]->{'src'};
2443: next if ($ressrc eq '');
2444: my $id = $token->[2]->{'id'};
2445: my $title = $token->[2]->{'title'};
2446: if ($checktitle) {
2447: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2448: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2449: }
2450: }
2451: next if ($token->[2]->{'type'} eq 'external');
2452: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2453: next if ($skip);
1.484.2.25 raeburn 2454: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2455: $changed = 1;
2456: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2457: my $srcdom = $1;
2458: my $srcnum = $2;
2459: my $rem = $3;
2460: my $newurl;
2461: my $mapname;
2462: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2463: my $prefix = $1;
2464: $mapname = $prefix.$2;
2465: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2466: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2467: $srcdom,$srcnum,$allmaps,$rewrites,
2468: $retitles,$copies,$dbcopies,$zombies,
2469: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2470: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2471: next;
2472: } else {
2473: ($newurl,my $error) =
2474: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2475: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2476: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2477: $newsubdir->{$ressrc} = $1;
2478: }
2479: if ($error) {
2480: next;
2481: }
2482: }
2483: }
2484: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2485: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2486:
1.484.2.7 raeburn 2487: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2488: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2489: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2490: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2491: $cnum,$srcdom,$srcnum,$allmaps,
2492: $rewrites,$retitles,$copies,$dbcopies,
2493: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2494: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2495: $mapmoves->{$ressrc} = 1;
2496: }
2497: $changed = 1;
2498: } else {
1.484.2.25 raeburn 2499: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2500: $copies->{$oldurl}{$ressrc} = $id;
2501: $changed = 1;
2502: }
2503: }
1.484.2.26 raeburn 2504: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2505: next if ($skip);
1.484.2.7 raeburn 2506: my $srcdom = $1;
2507: my $srcnum = $2;
2508: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2509: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2510: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2511: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2512: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2513: $changed = 1;
2514: }
2515: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2516: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2517: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2518: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2519: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2520: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2521: $changed = 1;
2522: }
1.484.2.82 raeburn 2523: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2524: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2525: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2526: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2527: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2528: }
1.484.2.7 raeburn 2529: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2530: next if ($skip);
2531: my $srcdom = $1;
2532: my $srcnum = $2;
2533: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2534: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2535: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2536: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2537: $changed = 1;
2538: }
2539: }
2540: } elsif ($token->[1] eq 'param') {
2541: next if ($skip);
1.484.2.19 raeburn 2542: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2543: if ($to ne '') {
2544: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2545: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2546: } else {
2547: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2548: }
2549: }
2550: }
2551: }
2552: return $changed;
2553: }
2554:
2555: sub apply_fixups {
1.484.2.23 raeburn 2556: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2557: $oldurl,$url,$caller) = @_;
2558: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2559: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2560: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2561: if (ref($updated) eq 'HASH') {
2562: if (ref($updated->{'rewrites'}) eq 'HASH') {
2563: %rewrites = %{$updated->{'rewrites'}};
2564: }
2565: if (ref($updated->{'zombies'}) eq 'HASH') {
2566: %zombies = %{$updated->{'zombies'}};
2567: }
2568: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2569: %removefrommap = %{$updated->{'removefrommap'}};
2570: }
2571: if (ref($updated->{'removeparam'}) eq 'HASH') {
2572: %removeparam = %{$updated->{'removeparam'}};
2573: }
2574: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2575: %dbcopies = %{$updated->{'dbcopies'}};
2576: }
2577: if (ref($updated->{'retitles'}) eq 'HASH') {
2578: %retitles = %{$updated->{'retitles'}};
2579: }
1.484.2.82 raeburn 2580: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2581: %resdatacopy = %{$updated->{'resdatacopy'}};
2582: }
1.484.2.23 raeburn 2583: }
2584: if (ref($info) eq 'HASH') {
2585: if (ref($info->{'newsubdir'}) eq 'HASH') {
2586: %newsubdir = %{$info->{'newsubdir'}};
2587: }
2588: if (ref($info->{'params'}) eq 'HASH') {
2589: %params = %{$info->{'params'}};
2590: }
2591: if (ref($info->{'before'}) eq 'HASH') {
2592: %before = %{$info->{'before'}};
2593: }
2594: if (ref($info->{'after'}) eq 'HASH') {
2595: %after = %{$info->{'after'}};
2596: }
2597: }
2598: if (ref($moves) eq 'HASH') {
2599: if (ref($moves->{'copies'}) eq 'HASH') {
2600: %copies = %{$moves->{'copies'}};
2601: }
2602: if (ref($moves->{'docmoves'}) eq 'HASH') {
2603: %docmoves = %{$moves->{'docmoves'}};
2604: }
2605: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2606: %mapmoves = %{$moves->{'mapmoves'}};
2607: }
2608: }
2609: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2610: my @allcopies;
1.484.2.23 raeburn 2611: if (exists($copies{$key})) {
2612: if (ref($copies{$key}) eq 'HASH') {
2613: my %added;
2614: foreach my $innerkey (keys(%{$copies{$key}})) {
2615: if (($innerkey ne '') && (!$added{$innerkey})) {
2616: push(@allcopies,$innerkey);
2617: $added{$innerkey} = 1;
2618: }
1.484.2.7 raeburn 2619: }
1.484.2.23 raeburn 2620: undef(%added);
1.484.2.7 raeburn 2621: }
2622: }
2623: if ($key eq $oldurl) {
1.484.2.23 raeburn 2624: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2625: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2626: push(@allcopies,$oldurl);
2627: }
2628: }
2629: }
2630: if (@allcopies > 0) {
2631: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2632: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2633: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2634: if ($fname ne '') {
2635: my $content = &Apache::lonnet::getfile($item);
2636: unless ($content eq '-1') {
2637: my $storefn;
1.484.2.23 raeburn 2638: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2639: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2640: } else {
2641: $storefn = $relpath;
2642: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2643: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2644: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2645: }
1.484.2.23 raeburn 2646: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2647: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2648: }
2649: }
2650: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2651: my $copyurl =
1.484.2.7 raeburn 2652: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2653: $storefn.$fname,$content);
2654: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2655: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2656: return &mt('Paste failed: an error occurred copying the file.');
2657: } elsif (ref($errors) eq 'HASH') {
2658: $errors->{$item} = 1;
2659: }
2660: }
2661: }
2662: }
2663: }
2664: }
2665: }
1.484.2.23 raeburn 2666: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2667: my $storefn=$key;
2668: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2669: if ($prefixchg && $before{'map'} && $after{'map'}) {
2670: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2671: }
1.484.2.23 raeburn 2672: if ($newsubdir{$key}) {
2673: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2674: }
2675: my $mapcontent = &Apache::lonnet::getfile($key);
2676: if ($mapcontent eq '-1') {
2677: if (ref($errors) eq 'HASH') {
2678: $errors->{$key} = 1;
2679: }
2680: } else {
2681: my $newmap =
2682: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2683: $mapcontent);
2684: if ($newmap eq '/adm/notfound.html') {
2685: if (ref($errors) eq 'HASH') {
2686: $errors->{$key} = 1;
2687: }
2688: }
2689: }
2690: }
2691: my %updates;
2692: if ($is_map) {
1.484.2.23 raeburn 2693: if (ref($updated) eq 'HASH') {
2694: foreach my $type (keys(%{$updated})) {
2695: if (ref($updated->{$type}) eq 'HASH') {
2696: foreach my $key (keys(%{$updated->{$type}})) {
2697: $updates{$key} = 1;
2698: }
2699: }
2700: }
1.484.2.7 raeburn 2701: }
2702: foreach my $key (keys(%updates)) {
2703: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2704: if (ref($rewrites{$key}) eq 'HASH') {
2705: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2706: }
1.484.2.23 raeburn 2707: if (ref($retitles{$key}) eq 'HASH') {
2708: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2709: }
1.484.2.23 raeburn 2710: if (ref($removefrommap{$key}) eq 'HASH') {
2711: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2712: }
1.484.2.23 raeburn 2713: if (ref($removeparam{$key}) eq 'HASH') {
2714: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2715: }
1.484.2.23 raeburn 2716: if (ref($zombies{$key}) eq 'HASH') {
2717: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2718: }
1.484.2.23 raeburn 2719: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2720: foreach my $idx (keys(%{$dbcopies{$key}})) {
2721: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2722: my ($newurl,$result,$errtext) =
2723: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2724: if ($result eq 'ok') {
2725: $newdb{$idx} = $newurl;
2726: } elsif (ref($errors) eq 'HASH') {
2727: $errors->{$key} = 1;
2728: }
2729: push(@msgs,$errtext);
2730: }
1.484.2.7 raeburn 2731: }
2732: }
1.484.2.82 raeburn 2733: if (ref($resdatacopy{$key}) eq 'HASH') {
2734: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2735: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2736: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2737: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2738: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2739: my $template = $1;
2740: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2741: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2742: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2743: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2744: unless ($gotnewmapname) {
2745: ($newmapname) = ($key =~ m{/([^/]+)$});
2746: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2747: if ($newsubdir{$key}) {
2748: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2749: }
2750: $gotnewmapname = 1;
2751: }
2752: my $srcmapinfo = $srcfolder.':'.$idx;
2753: if ($srccontainer eq 'page') {
2754: $srcmapinfo .= ':1';
2755: }
2756: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2757: $cnum,$template,$idx,$newmapname);
2758: }
2759: }
2760: }
2761: }
2762: }
1.484.2.23 raeburn 2763: if (ref($params{$key}) eq 'HASH') {
2764: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2765: }
2766: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2767: if ($fatal) {
1.484.2.26 raeburn 2768: return ($errtext);
1.484.2.7 raeburn 2769: }
2770: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2771: if (defined($LONCAPA::map::zombies[$i])) {
2772: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2773: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2774: undef($LONCAPA::map::zombies[$i]);
2775: }
2776: }
2777: }
1.484.2.77 raeburn 2778: my $total = scalar(@LONCAPA::map::order) - 1;
2779: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2780: my $idx = $LONCAPA::map::order[$i];
2781: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2782: my $changed;
1.484.2.23 raeburn 2783: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2784: if ((exists($toremove{$idx})) &&
2785: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2786: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2787: if (ref($currparam{$idx}) eq 'ARRAY') {
2788: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2789: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2790: }
2791: }
2792: next;
2793: }
2794: my $origsrc = $src;
1.484.2.25 raeburn 2795: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2796: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2797: $changed = 1;
2798: }
2799: }
1.484.2.25 raeburn 2800: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2801: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2802: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2803: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2804: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2805: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2806: } else {
1.484.2.23 raeburn 2807: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2808: }
2809: }
1.484.2.25 raeburn 2810: if ($origsrc =~ /\.(page|sequence)$/) {
2811: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2812: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2813: }
1.484.2.25 raeburn 2814: } elsif ($newsubdir{$key}) {
2815: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2816: }
2817: }
2818: $changed = 1;
1.484.2.26 raeburn 2819: } elsif ($newdb{$idx} ne '') {
2820: $src = $newdb{$idx};
1.484.2.7 raeburn 2821: $changed = 1;
2822: }
2823: if ($changed) {
1.484.2.30 raeburn 2824: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2825: }
2826: }
2827: }
2828: foreach my $idx (keys(%remparam)) {
2829: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2830: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2831: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2832: }
2833: }
2834: }
1.484.2.26 raeburn 2835: if (values(%lockerrors) > 0) {
2836: $lockmsg = join('<br />',values(%lockerrors));
2837: }
1.484.2.7 raeburn 2838: my $storefn;
2839: if ($key eq $oldurl) {
2840: $storefn = $url;
2841: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2842: } else {
2843: $storefn = $key;
2844: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2845: if ($prefixchg && $before{'map'} && $after{'map'}) {
2846: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2847: }
1.484.2.23 raeburn 2848: if ($newsubdir{$key}) {
2849: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2850: }
2851: }
2852: my $report;
2853: if ($folder !~ /^supplemental/) {
2854: $report = 1;
2855: }
1.484.2.20 raeburn 2856: (my $outtext,$errtext) =
1.484.2.7 raeburn 2857: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2858: if ($errtext) {
1.484.2.23 raeburn 2859: if ($caller eq 'paste') {
1.484.2.26 raeburn 2860: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2861: }
1.484.2.7 raeburn 2862: }
2863: }
2864: }
1.484.2.26 raeburn 2865: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2866: }
2867:
2868: sub copy_dependencies {
2869: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2870: my $content;
2871: if (ref($contentref)) {
2872: $content = $$contentref;
2873: } else {
2874: $content = &Apache::lonnet::getfile($item);
2875: }
2876: unless ($content eq '-1') {
2877: my $mm = new File::MMagic;
2878: my $mimetype = $mm->checktype_contents($content);
2879: if ($mimetype eq 'text/html') {
2880: my (%allfiles,%codebase,$state);
2881: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2882: if ($res eq 'ok') {
2883: my ($numexisting,$numpathchanges,$existing);
2884: (undef,$numexisting,$numpathchanges,$existing) =
2885: &Apache::loncommon::ask_for_embedded_content(
2886: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2887: {'error_on_invalid_names' => 1,
2888: 'ignore_remote_references' => 1,
2889: 'docs_url' => $item,
2890: 'context' => 'paste'});
2891: if ($numexisting > 0) {
2892: if (ref($existing) eq 'HASH') {
2893: foreach my $dep (keys(%{$existing})) {
2894: my $depfile = $dep;
2895: unless ($depfile =~ m{^\Q$relpath\E}) {
2896: $depfile = $relpath.$dep;
2897: }
2898: my $depcontent = &Apache::lonnet::getfile($depfile);
2899: unless ($depcontent eq '-1') {
2900: my $storedep = $dep;
2901: $storedep =~ s{^\Q$relpath\E}{};
2902: my $dep_url =
2903: &Apache::lonclonecourse::writefile(
2904: $env{'request.course.id'},
2905: $storefn.$storedep,$depcontent);
2906: if ($dep_url eq '/adm/notfound.html') {
2907: if (ref($errors) eq 'HASH') {
2908: $errors->{$depfile} = 1;
2909: }
2910: } else {
2911: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2912: }
2913: }
2914: }
2915: }
2916: }
2917: }
2918: }
2919: }
2920: return;
2921: }
2922:
1.329 droeschl 2923: my %parameter_type = ( 'randompick' => 'int_pos',
2924: 'hiddenresource' => 'string_yesno',
2925: 'encrypturl' => 'string_yesno',
2926: 'randomorder' => 'string_yesno',);
2927: my $valid_parameters_re = join('|',keys(%parameter_type));
2928: # set parameters
2929: sub update_parameter {
1.484.2.29 raeburn 2930: if ($env{'form.changeparms'} eq 'all') {
2931: my (@allidx,@allmapidx,%allchecked,%currchecked);
2932: %allchecked = (
2933: 'hiddenresource' => {},
2934: 'encrypturl' => {},
2935: 'randompick' => {},
2936: 'randomorder' => {},
2937: );
2938: foreach my $which (keys(%allchecked)) {
2939: $env{'form.all'.$which} =~ s/,$//;
2940: if ($which eq 'randompick') {
2941: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2942: my ($res,$value) = split(/:/,$item);
2943: if ($value =~ /^\d+$/) {
2944: $allchecked{$which}{$res} = $value;
2945: }
2946: }
2947: } else {
1.484.2.30 raeburn 2948: if ($env{'form.all'.$which}) {
2949: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2950: }
1.484.2.29 raeburn 2951: }
2952: }
2953: my $haschanges = 0;
2954: foreach my $res (@LONCAPA::map::order) {
2955: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2956: $name=&LONCAPA::map::qtescape($name);
2957: $url=&LONCAPA::map::qtescape($url);
2958: next unless ($name && $url);
2959: my $is_map;
2960: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2961: $is_map = 1;
2962: }
2963: foreach my $which (keys(%allchecked)) {
2964: if (($which eq 'randompick' || $which eq 'randomorder')) {
2965: next if (!$is_map);
2966: }
2967: my $oldvalue = 0;
2968: my $newvalue = 0;
2969: if ($allchecked{$which}{$res}) {
2970: $newvalue = $allchecked{$which}{$res};
2971: }
2972: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2973: if ($which eq 'randompick') {
2974: if ($current =~ /^(\d+)$/) {
2975: $oldvalue = $1;
2976: }
2977: } else {
2978: if ($current =~ /^yes$/i) {
2979: $oldvalue = 1;
2980: }
2981: }
2982: if ($oldvalue ne $newvalue) {
2983: $haschanges = 1;
2984: if ($newvalue) {
2985: my $storeval = 'yes';
2986: if ($which eq 'randompick') {
2987: $storeval = $newvalue;
2988: }
2989: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2990: $storeval,
2991: $parameter_type{$which});
2992: &remember_parms($res,$which,'set',$storeval);
2993: } elsif ($oldvalue) {
2994: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2995: &remember_parms($res,$which,'del');
2996: }
2997: }
2998: }
2999: }
3000: return $haschanges;
1.329 droeschl 3001: } else {
1.484.2.59 raeburn 3002: my $haschanges = 0;
3003: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 3004:
1.484.2.29 raeburn 3005: my $which = $env{'form.changeparms'};
3006: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 3007: my $oldvalue = 0;
3008: my $newvalue = 0;
3009: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3010: if ($which eq 'randompick') {
3011: if ($current =~ /^(\d+)$/) {
3012: $oldvalue = $1;
3013: }
3014: } elsif ($current =~ /^yes$/i) {
3015: $oldvalue = 1;
3016: }
1.484.2.29 raeburn 3017: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 3018: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3019: : 1;
1.484.2.29 raeburn 3020: }
1.484.2.59 raeburn 3021: if ($oldvalue ne $newvalue) {
3022: $haschanges = 1;
3023: if ($newvalue) {
3024: my $storeval = 'yes';
3025: if ($which eq 'randompick') {
3026: $storeval = $newvalue;
3027: }
3028: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3029: $parameter_type{$which});
3030: &remember_parms($idx,$which,'set',$storeval);
3031: } else {
3032: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3033: &remember_parms($idx,$which,'del');
3034: }
3035: }
3036: return $haschanges;
1.329 droeschl 3037: }
1.484.2.59 raeburn 3038: return;
1.329 droeschl 3039: }
3040:
3041: sub handle_edit_cmd {
3042: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 3043: if ($env{'form.cmd'} eq '') {
3044: return 0;
3045: }
1.329 droeschl 3046: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3047:
3048: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3049: my ($title, $url, @rrest) = split(':', $ratstr);
3050:
1.484.2.30 raeburn 3051: if ($cmd eq 'remove') {
1.329 droeschl 3052: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3053: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3054: &Apache::lonnet::removeuploadedurl($url);
3055: } else {
3056: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3057: }
3058: splice(@LONCAPA::map::order, $idx, 1);
3059:
3060: } elsif ($cmd eq 'cut') {
3061: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3062: splice(@LONCAPA::map::order, $idx, 1);
3063:
1.344 bisitz 3064: } elsif ($cmd eq 'up'
1.329 droeschl 3065: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3066: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3067:
3068: } elsif ($cmd eq 'down'
3069: && defined($LONCAPA::map::order[$idx+1])) {
3070: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3071:
3072: } elsif ($cmd eq 'rename') {
3073: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3074: if ($comment=~/\S/) {
3075: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3076: $comment.':'.join(':', $url, @rrest);
3077: }
3078: # Devalidate title cache
3079: my $renamed_url=&LONCAPA::map::qtescape($url);
3080: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 3081:
1.329 droeschl 3082: } else {
3083: return 0;
3084: }
3085: return 1;
3086: }
3087:
3088: sub editor {
1.458 raeburn 3089: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.85.2. (raeburn 3090:): $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3091:): $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 3092: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3093: if ($allowed) {
3094: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3095: $is_random_order,$container) =
3096: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3097: $r->print($breadcrumbtrail);
3098: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3099: $container = 'page';
3100: } else {
3101: $container = 'sequence';
3102: }
1.484 raeburn 3103:
1.484.2.21 raeburn 3104: my $jumpto;
3105:
3106: unless ($supplementalflag) {
1.484.2.32 raeburn 3107: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 3108: }
1.484 raeburn 3109:
3110: unless ($allowed) {
3111: $randompick = -1;
3112: }
3113:
1.484.2.67 raeburn 3114: my ($errtext,$fatal);
3115: if (($folder eq '') && (!$supplementalflag)) {
3116: if (@LONCAPA::map::order) {
3117: undef(@LONCAPA::map::order);
3118: undef(@LONCAPA::map::resources);
3119: undef(@LONCAPA::map::resparms);
3120: undef(@LONCAPA::map::zombies);
3121: }
3122: $folder = 'default';
3123: $container = 'sequence';
3124: } else {
3125: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3126: $folder.'.'.$container);
3127: return $errtext if ($fatal);
3128: }
1.329 droeschl 3129:
3130: if ($#LONCAPA::map::order<1) {
3131: my $idx=&LONCAPA::map::getresidx();
3132: if ($idx<=0) { $idx=1; }
3133: $LONCAPA::map::order[0]=$idx;
3134: $LONCAPA::map::resources[$idx]='';
3135: }
1.364 bisitz 3136:
1.329 droeschl 3137: # ------------------------------------------------------------ Process commands
3138:
3139: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 3140: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3141: # set parameters and change order
3142: &snapshotbefore();
3143:
3144: if (&update_parameter()) {
1.484.2.59 raeburn 3145: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3146: return $errtext if ($fatal);
3147: }
3148:
3149: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3150: # change order
3151: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3152: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3153:
3154: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3155: return $errtext if ($fatal);
3156: }
1.364 bisitz 3157:
1.329 droeschl 3158: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3159: my %paste_errors;
1.484.2.26 raeburn 3160: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3161: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3162: \%paste_errors);
1.484.2.30 raeburn 3163: if (ref($pastemsgarray) eq 'ARRAY') {
3164: if (@{$pastemsgarray} > 0) {
3165: $r->print('<p class="LC_info">'.
3166: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3167: '</p>');
3168: }
1.484.2.30 raeburn 3169: }
3170: if ($lockerror) {
3171: $r->print('<p class="LC_error">'.
3172: $lockerror.
3173: '</p>');
3174: }
3175: if ($save_error ne '') {
3176: return $save_error;
3177: }
3178: if ($paste_res) {
3179: my %errortext = &Apache::lonlocal::texthash (
3180: fail => 'Storage of folder contents failed',
3181: failread => 'Reading folder contents failed',
3182: failstore => 'Storage of folder contents failed',
3183: );
3184: if ($errortext{$paste_res}) {
3185: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3186: }
1.329 droeschl 3187: }
1.484.2.7 raeburn 3188: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3189: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3190: &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".
3191: '<ul>'."\n");
3192: foreach my $key (sort(keys(%paste_errors))) {
3193: $r->print('<li>'.$key.'</li>'."\n");
3194: }
3195: $r->print('</ul></p>'."\n");
3196: }
1.484.2.30 raeburn 3197: } elsif ($env{'form.clearmarked'}) {
3198: my $output = &do_buffer_empty();
3199: if ($output) {
3200: $r->print('<p class="LC_info">'.$output.'</p>');
3201: }
3202: }
1.329 droeschl 3203:
3204: $r->print($upload_output);
3205:
1.484.2.30 raeburn 3206: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3207: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3208: my $contentchg;
1.484.2.58 raeburn 3209: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3210: $contentchg = 1;
3211: }
3212: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3213: return $errtext if ($fatal);
3214: }
1.484.2.30 raeburn 3215:
3216: # Cut, copy and/or remove multiple resources
3217: if ($env{'form.multichange'}) {
3218: my %allchecked = (
3219: cut => {},
3220: remove => {},
3221: );
3222: my $needsupdate;
3223: foreach my $which (keys(%allchecked)) {
3224: $env{'form.multi'.$which} =~ s/,$//;
3225: if ($env{'form.multi'.$which}) {
3226: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3227: if (ref($allchecked{$which}) eq 'HASH') {
3228: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3229: }
3230: }
3231: }
3232: if ($needsupdate) {
3233: my $haschanges = 0;
3234: my %curr_groups = &Apache::longroup::coursegroups();
3235: my $total = scalar(@LONCAPA::map::order) - 1;
3236: for (my $i=$total; $i>=0; $i--) {
3237: my $res = $LONCAPA::map::order[$i];
3238: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3239: $name=&LONCAPA::map::qtescape($name);
3240: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3241: next unless $url;
1.484.2.30 raeburn 3242: my %denied =
3243: &action_restrictions($coursenum,$coursedom,$url,
3244: $env{'form.folderpath'},\%curr_groups);
3245: foreach my $which (keys(%allchecked)) {
3246: next if ($denied{$which});
3247: next unless ($allchecked{$which}{$res});
3248: if ($which eq 'remove') {
3249: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3250: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3251: &Apache::lonnet::removeuploadedurl($url);
3252: } else {
3253: &LONCAPA::map::makezombie($res);
3254: }
3255: splice(@LONCAPA::map::order,$i,1);
3256: $haschanges ++;
3257: } elsif ($which eq 'cut') {
3258: &LONCAPA::map::makezombie($res);
3259: splice(@LONCAPA::map::order,$i,1);
3260: $haschanges ++;
3261: }
3262: }
3263: }
3264: if ($haschanges) {
3265: ($errtext,$fatal) =
3266: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3267: return $errtext if ($fatal);
3268: }
3269: }
3270: }
3271:
1.329 droeschl 3272: # Group import/search
3273: if ($env{'form.importdetail'}) {
3274: my @imports;
3275: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3276: if (defined($item)) {
3277: my ($name,$url,$residx)=
1.484.2.26 raeburn 3278: map { &unescape($_); } split(/\=/,$item);
3279: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3280: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3281: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3282: if ($locknotfreed) {
3283: $r->print($locknotfreed);
3284: }
3285: if ($suffix) {
1.484.2.19 raeburn 3286: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3287: } else {
3288: return $errortxt;
3289: }
1.484.2.26 raeburn 3290: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3291: my $type = $1;
3292: my ($suffix,$errortxt,$locknotfreed) =
3293: &new_timebased_suffix($coursedom,$coursenum,$type);
3294: if ($locknotfreed) {
3295: $r->print($locknotfreed);
3296: }
3297: if ($suffix) {
3298: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3299: } else {
3300: return $errortxt;
3301: }
1.484.2.85.2. (raeburn 3302:): } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3303:): my ($suffix,$errortxt,$locknotfreed) =
3304:): &new_timebased_suffix($coursedom,$coursenum,'exttool');
3305:): if ($locknotfreed) {
3306:): $r->print($locknotfreed);
3307:): }
3308:): if ($suffix) {
3309:): $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3310:): } else {
3311:): return $errortxt;
3312:): }
1.484.2.27 raeburn 3313: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3314: if ($supplementalflag) {
3315: next unless ($1 eq 'supplemental');
3316: if ($folder eq 'supplemental') {
3317: next unless ($2 eq 'default');
3318: } else {
3319: next unless ($folder eq 'supplemental_'.$2);
3320: }
3321: } else {
3322: next unless ($1 eq 'docs');
3323: if ($folder eq 'default') {
3324: next unless ($2 eq 'default');
3325: } else {
3326: next unless ($folder eq 'default_'.$2);
3327: }
3328: }
1.484.2.15 raeburn 3329: }
1.329 droeschl 3330: push(@imports, [$name, $url, $residx]);
3331: }
3332: }
1.484.2.23 raeburn 3333: ($errtext,$fatal,my $fixuperrors) =
3334: &group_import($coursenum, $coursedom, $folder,$container,
1.484.2.85.2. (raeburn 3335:): 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3336: return $errtext if ($fatal);
1.484.2.23 raeburn 3337: if ($fixuperrors) {
3338: $r->print($fixuperrors);
3339: }
1.329 droeschl 3340: }
3341: # Loading a complete map
3342: if ($env{'form.loadmap'}) {
3343: if ($env{'form.importmap'}=~/\w/) {
3344: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3345: my ($title,$url,$ext,$type)=split(/\:/,$res);
3346: my $idx=&LONCAPA::map::getresidx($url);
3347: $LONCAPA::map::resources[$idx]=$res;
3348: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3349: }
3350: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3351: $folder.'.'.$container,1);
1.329 droeschl 3352: return $errtext if ($fatal);
3353: } else {
3354: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3355:
1.329 droeschl 3356: }
3357: }
3358: &log_differences($plain);
3359: }
3360: # ---------------------------------------------------------------- End commands
3361: # ---------------------------------------------------------------- Print screen
3362: my $idx=0;
3363: my $shown=0;
3364: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3365: $r->print('<div class="LC_Box">'.
1.432 raeburn 3366: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3367: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3368: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3369: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3370: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3371: '</ol>');
1.381 bisitz 3372: if ($randompick>=0) {
3373: $r->print('<p class="LC_warning">'
3374: .&mt('Caution: this folder is set to randomly pick a subset'
3375: .' of resources. Adding or removing resources from this'
3376: .' folder will change the set of resources that the'
3377: .' students see, resulting in spurious or missing credit'
3378: .' for completed problems, not limited to ones you'
3379: .' modify. Do not modify the contents of this folder if'
3380: .' it is in active student use.')
3381: .'</p>'
3382: );
3383: }
3384: if ($is_random_order) {
3385: $r->print('<p class="LC_warning">'
3386: .&mt('Caution: this folder is set to randomly order its'
3387: .' contents. Adding or removing resources from this folder'
3388: .' will change the order of resources shown.')
3389: .'</p>'
3390: );
3391: }
3392: $r->print('</div>');
1.364 bisitz 3393: }
1.381 bisitz 3394:
1.484.2.30 raeburn 3395: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3396: %filters = (
3397: canremove => [],
3398: cancut => [],
3399: cancopy => [],
3400: hiddenresource => [],
3401: encrypturl => [],
3402: randomorder => [],
3403: randompick => [],
3404: );
3405: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3406: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3407: foreach my $res (@LONCAPA::map::order) {
3408: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3409: $name=&LONCAPA::map::qtescape($name);
3410: $url=&LONCAPA::map::qtescape($url);
3411: unless ($name) { $name=(split(/\//,$url))[-1]; }
3412: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3413: push(@allidx,$res);
3414: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3415: push(@allmapidx,$res);
3416: }
1.484.2.67 raeburn 3417:
1.381 bisitz 3418: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3419: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3420: $pathitem,$supplementalflag,$container,
1.484.2.85.2. (raeburn 3421:): \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.484.2.80 raeburn 3422: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3423: $idx++;
3424: $shown++;
1.329 droeschl 3425: }
1.424 onken 3426: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3427:
1.484.2.30 raeburn 3428: my $need_save;
1.484.2.67 raeburn 3429: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3430: my $toolslink;
1.484.2.67 raeburn 3431: if ($allowed) {
1.484.2.31 raeburn 3432: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3433: .&Apache::loncommon::help_open_menu('Navigation Screen',
3434: 'Navigation_Screen',undef,'RAT')
3435: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3436: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3437: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3438: .'id="LC_content_toolbar_edittoplevel" '
3439: .'class="LC_toolbarItem" '
3440: .'title="'.&mt('Supplemental Content Editor').'">'
3441: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3442: }
1.484.2.19 raeburn 3443: if ($shown) {
3444: if ($allowed) {
3445: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3446: .&Apache::loncommon::start_data_table(undef,'contentlist')
3447: .&Apache::loncommon::start_data_table_header_row()
3448: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3449: .'<th colspan="2">'.&mt('Actions').'</th>'
3450: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3451: if ($folder !~ /^supplemental/) {
3452: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3453: }
1.484.2.29 raeburn 3454: $to_show .= &Apache::loncommon::end_data_table_header_row();
3455: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3456: $lists{'canhide'} = join(',',@allidx);
3457: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3458: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3459: 'randomorder','randompick');
3460: foreach my $item (@possfilters) {
3461: if (ref($filters{$item}) eq 'ARRAY') {
3462: if (@{$filters{$item}} > 0) {
3463: $lists{$item} = join(',',@{$filters{$item}});
3464: }
3465: }
3466: }
1.484.2.29 raeburn 3467: if (@allidx > 0) {
3468: my $path;
3469: if ($env{'form.folderpath'}) {
3470: $path =
3471: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3472: }
1.484.2.30 raeburn 3473: if (@allidx > 1) {
3474: $to_show .=
3475: &Apache::loncommon::continue_data_table_row().
3476: '<td colspan="2"> </td>'.
3477: '<td>'.
1.484.2.67 raeburn 3478: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3479: '</td>'.
3480: '<td> </td>'.
3481: '<td> </td>'.
3482: '<td colspan="4">'.
1.484.2.67 raeburn 3483: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3484: '</td>'.
3485: &Apache::loncommon::end_data_table_row();
3486: $need_save = 1;
3487: }
1.484.2.29 raeburn 3488: }
3489: }
3490: $to_show .= $output.' '
1.484.2.19 raeburn 3491: .&Apache::loncommon::end_data_table()
3492: .'<br style="line-height:2px;" />'
3493: .&Apache::loncommon::end_scrollbox();
3494: } else {
3495: $to_show .= $toolslink
3496: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3497: .$output.' '
3498: .&Apache::loncommon::end_data_table();
3499: }
3500: } else {
3501: if (!$allowed) {
3502: $to_show .= $toolslink;
1.393 raeburn 3503: }
1.484.2.67 raeburn 3504: my $noresmsg;
3505: if ($allowed && $hiddentop && !$supplementalflag) {
3506: $noresmsg = &mt('Main Content Hidden');
3507: } else {
3508: $noresmsg = &mt('Currently empty');
3509: }
1.484.2.19 raeburn 3510: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3511: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3512: .$noresmsg
1.484.2.19 raeburn 3513: .'</div>'
3514: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3515: }
3516: } else {
1.484.2.19 raeburn 3517: if ($shown) {
3518: $to_show = '<div>'
3519: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3520: .$output
3521: .&Apache::loncommon::end_data_table()
3522: .'</div>';
3523: } else {
3524: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3525: .&mt('Currently empty')
1.484.2.19 raeburn 3526: .'</div>'
3527: }
1.458 raeburn 3528: }
3529: my $tid = 1;
3530: if ($supplementalflag) {
3531: $tid = 2;
1.329 droeschl 3532: }
3533: if ($allowed) {
1.484 raeburn 3534: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3535: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3536: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3537: if ($canedit) {
1.484.2.67 raeburn 3538: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3539: }
1.460 raeburn 3540: } else {
3541: $r->print($to_show);
1.329 droeschl 3542: }
3543: return;
3544: }
3545:
1.484.2.30 raeburn 3546: sub multiple_check_form {
1.484.2.67 raeburn 3547: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3548: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3549: my $disabled;
3550: unless ($canedit) {
3551: $disabled = 'disabled="disabled"';
3552: }
1.484.2.30 raeburn 3553: my $output =
3554: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3555: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3556: '<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>'.
3557: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3558: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3559: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3560: if ($caller eq 'settings') {
3561: $output .=
3562: '<table><tr>'.
3563: '<td class="LC_docs_entry_parameter">'.
3564: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3565: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3566: '</label></span></td>'.
3567: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3568: '<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 3569: '</span></td>'.
3570: '</tr>'."\n".
3571: '<tr>'.
3572: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3573: '<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 3574: '</label></span>'.
3575: '</td></tr></table>'."\n";
3576: } else {
3577: $output .=
3578: '<table><tr>'.
3579: '<td class="LC_docs_entry_parameter">'.
3580: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3581: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3582: '</label></span></td>'.
3583: '<td class="LC_docs_entry_parameter">'.
3584: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3585: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3586: '</label></span></td>'."\n".
3587: '<td class="LC_docs_entry_parameter">'.
3588: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3589: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3590: '</label></span></td>'.
3591: '</tr></table>'."\n";
3592: }
3593: $output .=
3594: '</fieldset>'.
3595: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3596: if ($caller eq 'settings') {
3597: $output .=
3598: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3599: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3600: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3601: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3602: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3603: } elsif ($caller eq 'actions') {
3604: $output .=
3605: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3606: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3607: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3608: }
3609: $output .=
3610: '</form>'.
3611: '</div>';
3612: return $output;
3613: }
3614:
1.329 droeschl 3615: sub process_file_upload {
1.484.2.36 raeburn 3616: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3617: # upload a file, if present
1.484.2.36 raeburn 3618: my $filesize = length($env{'form.uploaddoc'});
3619: if (!$filesize) {
3620: $$upload_output = '<div class="LC_error">'.
3621: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3622: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3623: $filesize).'<br />'.
3624: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3625: '</div>';
3626: return;
3627: }
3628: my $quotatype = 'unofficial';
3629: if ($crstype eq 'Community') {
3630: $quotatype = 'community';
1.484.2.51 raeburn 3631: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3632: $quotatype = 'official';
1.484.2.45 raeburn 3633: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3634: $quotatype = 'textbook';
1.484.2.36 raeburn 3635: }
3636: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3637: $filesize = int($filesize/1000); #expressed in kb
3638: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3639: $env{'form.uploaddoc.filename'},$filesize,
3640: 'upload',$quotatype);
1.484.2.36 raeburn 3641: return if ($$upload_output);
3642: }
1.440 raeburn 3643: my ($parseaction,$showupload,$nextphase,$mimetype);
3644: if ($env{'form.parserflag'}) {
1.329 droeschl 3645: $parseaction = 'parse';
3646: }
3647: my $folder=$env{'form.folder'};
3648: if ($folder eq '') {
3649: $folder='default';
3650: }
3651: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3652: my $errtext='';
3653: my $fatal=0;
3654: my $container='sequence';
1.484.2.19 raeburn 3655: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3656: $container='page';
3657: }
3658: ($errtext,$fatal)=
1.484.2.27 raeburn 3659: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3660: if ($#LONCAPA::map::order<1) {
3661: $LONCAPA::map::order[0]=1;
3662: $LONCAPA::map::resources[1]='';
3663: }
3664: my $destination = 'docs/';
3665: if ($folder =~ /^supplemental/) {
3666: $destination = 'supplemental/';
3667: }
3668: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3669: $destination .= 'default/';
3670: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3671: $destination .= $2.'/';
3672: }
1.484.2.27 raeburn 3673: if ($fatal) {
3674: $$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>';
3675: return;
3676: }
1.440 raeburn 3677: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3678: my $newidx=&LONCAPA::map::getresidx();
3679: $destination .= $newidx;
1.439 raeburn 3680: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3681: $parseaction,$allfiles,
1.440 raeburn 3682: $codebase,undef,undef,undef,undef,
3683: undef,undef,\$mimetype);
3684: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3685: my $stored = $1;
3686: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3687: $stored.'</span>').'</p>';
3688: } else {
3689: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3690:
1.457 raeburn 3691: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3692: return;
3693: }
1.329 droeschl 3694: my $ext='false';
3695: if ($url=~m{^http://}) { $ext='true'; }
3696: $url = &LONCAPA::map::qtunescape($url);
3697: my $comment=$env{'form.comment'};
3698: $comment = &LONCAPA::map::qtunescape($comment);
3699: if ($folder=~/^supplemental/) {
3700: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3701: $env{'user.domain'}.'___&&&___'.$comment;
3702: }
3703:
3704: $LONCAPA::map::resources[$newidx]=
3705: $comment.':'.$url.':'.$ext.':normal:res';
3706: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3707: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3708: $folder.'.'.$container,1);
1.329 droeschl 3709: if ($fatal) {
1.457 raeburn 3710: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3711: return;
1.329 droeschl 3712: } else {
1.440 raeburn 3713: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3714: $$upload_output = $showupload;
1.384 raeburn 3715: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3716: if ($total_embedded > 0) {
1.440 raeburn 3717: my $uploadphase = 'upload_embedded';
3718: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3719: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3720: my ($embedded,$num) =
3721: &Apache::loncommon::ask_for_embedded_content(
3722: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3723: if ($embedded) {
3724: if ($num) {
3725: $$upload_output .=
3726: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3727: $nextphase = $uploadphase;
3728: } else {
3729: $$upload_output .= $embedded;
3730: }
3731: } else {
3732: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3733: }
1.329 droeschl 3734: } else {
1.440 raeburn 3735: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3736: }
1.457 raeburn 3737: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3738: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3739: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3740: $nextphase = 'decompress_uploaded';
3741: my $position = scalar(@LONCAPA::map::order)-1;
3742: my $noextract = &return_to_editor();
3743: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3744: my %archiveitems = (
3745: folderpath => $env{'form.folderpath'},
3746: cmd => $nextphase,
3747: newidx => $newidx,
3748: position => $position,
3749: phase => $nextphase,
1.477 raeburn 3750: comment => $comment,
1.480 raeburn 3751: );
3752: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3753: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3754: $$upload_output = $showupload.
3755: &Apache::loncommon::decompress_form($mimetype,
3756: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3757: \%archiveitems,\@current);
1.329 droeschl 3758: }
3759: }
3760: }
1.440 raeburn 3761: return $nextphase;
1.329 droeschl 3762: }
3763:
1.480 raeburn 3764: sub get_dir_list {
3765: my ($url,$coursenum,$coursedom,$newidx) = @_;
3766: my ($destination,$dir_root) = &embedded_destination();
3767: my ($dirlistref,$listerror) =
3768: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3769: my @dir_lines;
3770: my $dirptr=16384;
3771: if (ref($dirlistref) eq 'ARRAY') {
3772: foreach my $dir_line (sort
3773: {
3774: my ($afile)=split('&',$a,2);
3775: my ($bfile)=split('&',$b,2);
3776: return (lc($afile) cmp lc($bfile));
3777: } (@{$dirlistref})) {
3778: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3779: $filename =~ s/\s+$//;
3780: next if ($filename =~ /^\.\.?$/);
3781: my $isdir = 0;
3782: if ($dirptr&$testdir) {
3783: $isdir = 1;
3784: }
3785: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3786: }
3787: }
3788: return @dir_lines;
3789: }
3790:
1.329 droeschl 3791: sub is_supplemental_title {
3792: my ($title) = @_;
3793: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3794: }
3795:
3796: # --------------------------------------------------------------- An entry line
3797:
3798: sub entryline {
1.484.2.12 raeburn 3799: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3800: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.85.2. (raeburn 3801:): $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3802: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3803: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3804: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3805: } else {
3806: $title=&HTML::Entities::encode($title,'"<>&\'');
3807: $renametitle=$title;
3808: $foldertitle=$title;
3809: }
3810:
1.484.2.67 raeburn 3811: my ($disabled,$readonly,$js_lt);
3812: unless ($canedit) {
3813: $disabled = 'disabled="disabled"';
3814: $readonly = 1;
3815: }
3816:
1.329 droeschl 3817: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3818:
1.329 droeschl 3819: $renametitle=~s/\\/\\\\/g;
3820: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3821: $renametitle=~s/"/%22/g;
1.329 droeschl 3822: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3823: $oldtitle = $renametitle;
3824: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3825: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3826: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3827: # Edit commands
1.484.2.28 raeburn 3828: my ($esc_path, $path, $symb);
1.329 droeschl 3829: if ($env{'form.folderpath'}) {
3830: $esc_path=&escape($env{'form.folderpath'});
3831: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3832: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3833: }
1.484.2.16 raeburn 3834: my $isexternal;
1.484.2.19 raeburn 3835: if ($residx) {
1.484.2.12 raeburn 3836: my $currurl = $url;
3837: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3838: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3839: $isexternal = 1;
3840: }
1.484.2.19 raeburn 3841: if (!$supplementalflag) {
3842: my $path = 'uploaded/'.
3843: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3844: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3845: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3846: $residx,
3847: &Apache::lonnet::declutter($currurl));
3848: }
1.484.2.12 raeburn 3849: }
1.484.2.30 raeburn 3850: my ($renamelink,%lt,$ishash);
3851: if (ref($filtersref) eq 'HASH') {
3852: $ishash = 1;
3853: }
3854:
1.329 droeschl 3855: if ($allowed) {
1.484.2.30 raeburn 3856: $form_start = '
3857: <form action="/adm/coursedocs" method="post">
3858: ';
3859: $form_common=(<<END);
3860: <input type="hidden" name="folderpath" value="$path" />
3861: <input type="hidden" name="symb" value="$symb" />
3862: END
3863: $form_param=(<<END);
3864: <input type="hidden" name="setparms" value="$orderidx" />
3865: <input type="hidden" name="changeparms" value="0" />
3866: END
3867: $form_end = '</form>';
3868:
1.329 droeschl 3869: my $incindex=$index+1;
3870: my $selectbox='';
1.471 raeburn 3871: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3872: ((split(/\:/,
1.344 bisitz 3873: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3874: ne '') &&
1.329 droeschl 3875: ((split(/\:/,
1.344 bisitz 3876: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3877: ne '')) {
3878: $selectbox=
3879: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3880: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3881: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3882: if ($i==$incindex) {
1.358 bisitz 3883: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3884: } else {
3885: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3886: }
3887: }
3888: $selectbox.='</select>';
3889: }
1.484.2.12 raeburn 3890: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3891: 'up' => 'Move Up',
3892: 'dw' => 'Move Down',
3893: 'rm' => 'Remove',
3894: 'ct' => 'Cut',
3895: 'rn' => 'Rename',
1.484.2.12 raeburn 3896: 'cp' => 'Copy',
3897: 'ex' => 'External Resource',
1.484.2.85.2. (raeburn 3898:): 'et' => 'External Tool',
1.484.2.12 raeburn 3899: 'ed' => 'Edit',
3900: 'pr' => 'Preview',
3901: 'sv' => 'Save',
3902: 'ul' => 'URL',
1.484.2.67 raeburn 3903: 'ti' => 'Title',
3904: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3905: );
1.484.2.30 raeburn 3906: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3907: $env{'form.folderpath'},
3908: $currgroups);
1.484.2.19 raeburn 3909: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3910: my $skip_confirm = 0;
1.484.2.63 raeburn 3911: my $confirm_removal = 0;
1.329 droeschl 3912: if ( $folder =~ /^supplemental/
3913: || ($url =~ m{( /smppg$
3914: |/syllabus$
3915: |/aboutme$
3916: |/navmaps$
3917: |/bulletinboard$
1.484.2.85.2. (raeburn 3918:): |/ext\.tool$
1.484.2.16 raeburn 3919: |\.html$)}x)
1.484.2.19 raeburn 3920: || $isexternal) {
1.329 droeschl 3921: $skip_confirm = 1;
3922: }
1.484.2.63 raeburn 3923: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3924: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3925: $confirm_removal = 1;
3926: }
1.484.2.19 raeburn 3927:
1.484.2.30 raeburn 3928: if ($denied{'copy'}) {
3929: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3930: <span style="visibility: hidden;">$lt{'cp'}</span>
3931: ENDCOPY
3932: } else {
1.484.2.30 raeburn 3933: my $formname = 'edit_copy_'.$orderidx;
3934: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3935: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3936: <form name="$formname" method="post" action="/adm/coursedocs">
3937: $form_common
1.484.2.67 raeburn 3938: <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 3939: $form_end
1.329 droeschl 3940: ENDCOPY
1.484.2.30 raeburn 3941: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3942: push(@{$filtersref->{'cancopy'}},$orderidx);
3943: }
1.329 droeschl 3944: }
1.484.2.30 raeburn 3945: if ($denied{'cut'}) {
1.484.2.16 raeburn 3946: $cutlink=(<<ENDCUT);
3947: <span style="visibility: hidden;">$lt{'ct'}</span>
3948: ENDCUT
3949: } else {
1.484.2.30 raeburn 3950: my $formname = 'edit_cut_'.$orderidx;
3951: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3952: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3953: <form name="$formname" method="post" action="/adm/coursedocs">
3954: $form_common
3955: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3956: <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 3957: $form_end
1.329 droeschl 3958: ENDCUT
1.484.2.30 raeburn 3959: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3960: push(@{$filtersref->{'cancut'}},$orderidx);
3961: }
1.329 droeschl 3962: }
1.484.2.30 raeburn 3963: if ($denied{'remove'}) {
1.484.2.16 raeburn 3964: $removelink=(<<ENDREM);
3965: <span style="visibility: hidden;">$lt{'rm'}</a>
3966: ENDREM
3967: } else {
1.484.2.30 raeburn 3968: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3969: 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 3970: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3971: <form name="$formname" method="post" action="/adm/coursedocs">
3972: $form_common
3973: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3974: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3975: <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 3976: $form_end
1.484.2.9 raeburn 3977: ENDREM
1.484.2.30 raeburn 3978: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3979: push(@{$filtersref->{'canremove'}},$orderidx);
3980: }
1.484.2.9 raeburn 3981: }
1.484.2.35 raeburn 3982: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3983: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3984: ENDREN
1.484.2.67 raeburn 3985: my ($uplink,$downlink);
3986: if ($canedit) {
3987: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3988: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3989: } else {
3990: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3991: $downlink = $uplink;
3992: }
1.329 droeschl 3993: $line.=(<<END);
3994: <td>
1.379 bisitz 3995: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3996: <a href="$uplink">
1.484.2.12 raeburn 3997: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3998: </a>
3999: </div>
4000: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 4001: <a href="$downlink">
1.484.2.12 raeburn 4002: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4003: </a>
4004: </div>
1.329 droeschl 4005: </td>
4006: <td>
4007: $form_start
1.484.2.30 raeburn 4008: $form_param
1.478 raeburn 4009: $form_common
1.329 droeschl 4010: $selectbox
4011: $form_end
4012: </td>
1.484.2.30 raeburn 4013: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 4014: $removelink
1.329 droeschl 4015: $cutlink
4016: $copylink
4017: </td>
4018: END
4019: }
4020: # Figure out what kind of a resource this is
4021: my ($extension)=($url=~/\.(\w+)$/);
4022: my $uploaded=($url=~/^\/*uploaded\//);
4023: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 4024: my $isfolder;
4025: my $ispage;
4026: my $containerarg;
1.484.2.67 raeburn 4027: my $folderurl;
1.329 droeschl 4028: if ($uploaded) {
1.472 raeburn 4029: if (($extension eq 'sequence') || ($extension eq 'page')) {
4030: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 4031: $containerarg = $1;
1.472 raeburn 4032: if ($extension eq 'sequence') {
4033: $icon=$iconpath.'navmap.folder.closed.gif';
4034: $isfolder=1;
4035: } else {
4036: $icon=$iconpath.'page.gif';
4037: $ispage=1;
4038: }
1.484.2.67 raeburn 4039: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4040: if ($allowed) {
4041: $url='/adm/coursedocs?';
4042: } else {
4043: $url='/adm/supplemental?';
4044: }
1.329 droeschl 4045: } else {
4046: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4047: }
4048: }
1.364 bisitz 4049:
1.484.2.70 raeburn 4050: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4051: my $orig_url = $url;
1.340 raeburn 4052: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.85.2. (raeburn 4053:): if ($container eq 'page') {
4054:): $url=~s{^http(|s)(:|:)//}{/ext/};
4055:): } else {
4056:): $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4057:): }
1.484.2.12 raeburn 4058: if (!$supplementalflag && $residx && $symb) {
4059: if ((!$isfolder) && (!$ispage)) {
4060: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.85.2. (raeburn 4061:): if (($url =~ m{^ext/}) && ($container eq 'page')) {
4062:): $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4063:): } else {
4064:): $url=&Apache::lonnet::clutter($url);
4065:): }
1.484.2.12 raeburn 4066: if ($url=~/^\/*uploaded\//) {
4067: $url=~/\.(\w+)$/;
4068: my $embstyle=&Apache::loncommon::fileembstyle($1);
4069: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4070: $url='/adm/wrapper'.$url;
4071: } elsif ($embstyle eq 'ssi') {
4072: #do nothing with these
4073: } elsif ($url!~/\.(sequence|page)$/) {
4074: $url='/adm/coursedocs/showdoc'.$url;
4075: }
1.484.2.70 raeburn 4076: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4077: my $wrapped = $1;
4078: my $exturl = $2;
1.484.2.85.2. (raeburn 4079:): if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 4080: $url='/adm/wrapper'.$url;
4081: }
4082: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4083: $nomodal = 1;
4084: }
1.484.2.85.2. (raeburn 4085:): } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4086:): $url='/adm/wrapper'.$url;
1.484.2.70 raeburn 4087: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4088: if (($ENV{'SERVER_PORT'} == 443) &&
4089: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 4090: unless (&Apache::lonnet::uses_sts()) {
4091: $url .= '?usehttp=1';
4092: }
1.484.2.70 raeburn 4093: $nomodal = 1;
4094: }
1.484.2.19 raeburn 4095: }
1.484.2.12 raeburn 4096: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 4097: my $shownsymb = $symb;
4098: if ($isexternal) {
1.484.2.85.2. (raeburn 4099:): $url =~ s/\#[^#]+$//;
4100:): if ($container eq 'page') {
4101:): $url = &Apache::lonnet::clutter($url);
1.484.2.66 raeburn 4102: }
4103: }
1.484.2.67 raeburn 4104: unless ($env{'request.role.adv'}) {
4105: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4106: $url = '';
4107: }
4108: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4109: $url = '';
4110: $hiddenres = 1;
4111: }
4112: }
4113: if ($url ne '') {
1.484.2.75 raeburn 4114: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4115: }
4116: } elsif (!$env{'request.role.adv'}) {
4117: my $checkencrypt;
4118: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4119: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4120: $checkencrypt = 1;
1.484.2.70 raeburn 4121: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 4122: unless (ref($$navmapref)) {
4123: $$navmapref = Apache::lonnavmaps::navmap->new();
4124: }
4125: if (ref($$navmapref)) {
4126: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4127: $checkencrypt = 1;
4128: }
4129: }
4130: }
4131: if ($checkencrypt) {
4132: my $shownsymb = &Apache::lonenc::encrypted($symb);
4133: my $shownurl = &Apache::lonenc::encrypted($url);
4134: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 4135: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4136: if ($env{'request.enc'} ne '') {
4137: delete($env{'request.enc'});
4138: }
4139: } else {
4140: $url='';
4141: }
4142: } else {
4143: $url='';
4144: }
1.484.2.12 raeburn 4145: } else {
4146: $url='';
4147: }
1.484.2.19 raeburn 4148: }
1.484.2.66 raeburn 4149: } elsif ($supplementalflag) {
4150: if ($isexternal) {
4151: if ($url =~ /^([^#]+)#([^#]+)$/) {
4152: $url = $1;
4153: $anchor = $2;
1.484.2.70 raeburn 4154: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.80 raeburn 4155: unless (&Apache::lonnet::uses_sts()) {
4156: if ($hostname ne '') {
4157: $url = 'http://'.$hostname.$url;
4158: }
4159: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4160: }
1.484.2.70 raeburn 4161: $nomodal = 1;
4162: }
4163: }
4164: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4165: if (($ENV{'SERVER_PORT'} == 443) &&
4166: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 4167: unless (&Apache::lonnet::uses_sts()) {
4168: if ($hostname ne '') {
4169: $url = 'http://'.$hostname.$url;
4170: }
4171: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4172: }
1.484.2.70 raeburn 4173: $nomodal = 1;
1.484.2.66 raeburn 4174: }
4175: }
1.329 droeschl 4176: }
1.484.2.67 raeburn 4177: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4178: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4179: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4180: my $foldername=&escape($foldertitle);
4181: my $folderpath=$env{'form.folderpath'};
4182: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4183: if (!$allowed && $supplementalflag) {
4184: $folderpath.=$containerarg.'&'.$foldername;
4185: $url.='folderpath='.&escape($folderpath);
4186: } else {
4187: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4188: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4189: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4190: 'parameter_randomorder'))[0]=~/^yes$/i);
4191: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4192: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4193: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4194: 'parameter_encrypturl'))[0]=~/^yes$/i);
4195: unless ($hiddenmap) {
1.484.2.70 raeburn 4196: if (ref($navmapref)) {
4197: unless (ref($$navmapref)) {
4198: $$navmapref = Apache::lonnavmaps::navmap->new();
4199: }
4200: if (ref($$navmapref)) {
4201: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4202: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4203: unless (@resources) {
4204: $hiddenmap = 1;
4205: unless ($env{'request.role.adv'}) {
4206: $url = '';
4207: $hiddenfolder = 1;
4208: }
1.484.2.67 raeburn 4209: }
4210: }
4211: }
4212: }
4213: }
4214: unless ($encryptmap) {
1.484.2.70 raeburn 4215: if ((ref($navmapref)) && (ref($$navmapref))) {
4216: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4217: $encryptmap = 1;
4218: }
1.484.2.67 raeburn 4219: }
4220: }
4221:
4222: # Append randompick number, hidden, and encrypted with ":" to foldername,
4223: # so it gets transferred between levels
4224: $folderpath.=$containerarg.'&'.$foldername.
4225: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4226: unless ($url eq '') {
4227: $url.='folderpath='.&escape($folderpath);
4228: }
1.484.2.19 raeburn 4229: my $rpckchk;
4230: if ($rpicknum) {
4231: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4232: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4233: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4234: }
1.484.2.19 raeburn 4235: }
1.484.2.29 raeburn 4236: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4237: $rand_pick_text =
1.478 raeburn 4238: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4239: $form_param."\n".
1.478 raeburn 4240: $form_common."\n".
1.484.2.67 raeburn 4241: '<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 4242: if ($rpicknum ne '') {
4243: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4244: }
1.484.2.29 raeburn 4245: $rand_pick_text .= '</span></span>'.
4246: $form_end;
1.484.2.30 raeburn 4247: my $ro_set;
1.484.2.67 raeburn 4248: if ($randorder) {
1.484.2.30 raeburn 4249: $ro_set = 'checked="checked"';
4250: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4251: push(@{$filtersref->{'randomorder'}},$orderidx);
4252: }
4253: }
1.484.2.41 raeburn 4254: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4255: $rand_order_text =
1.484.2.29 raeburn 4256: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4257: $form_param."\n".
1.484.2.29 raeburn 4258: $form_common."\n".
1.484.2.67 raeburn 4259: '<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 4260: $form_end;
1.484.2.19 raeburn 4261: }
1.484.2.18 raeburn 4262: } elsif ($supplementalflag && !$allowed) {
1.484.2.85.2. (raeburn 4263:): my $isexttool;
4264:): if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4265:): $url='/adm/wrapper'.$url;
4266:): $isexttool = 1;
4267:): }
1.484.2.19 raeburn 4268: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4269: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4270: if ($title) {
4271: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4272: }
1.484.2.85.2. (raeburn 4273:): if ((($isexternal) || ($isexttool)) && $orderidx) {
1.484.2.19 raeburn 4274: $url .= '&idx='.$orderidx;
4275: }
1.484.2.66 raeburn 4276: if ($anchor ne '') {
4277: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4278: }
1.329 droeschl 4279: }
1.484.2.19 raeburn 4280: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4281: if ($allowed) {
1.484.2.19 raeburn 4282: my $fileloc =
1.484.2.12 raeburn 4283: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4284: if ($isexternal) {
4285: ($editlink,$extresform) =
1.484.2.67 raeburn 4286: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
1.484.2.85.2. (raeburn 4287:): undef,undef,undef,undef,undef,undef,
4288:): undef,$disabled);
4289:): } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4290:): ($editlink,$extresform) =
4291:): &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4292:): undef,undef,undef,'tool',$coursedom,
4293:): $coursenum,$ltitoolsref,$disabled);
1.484.2.19 raeburn 4294: } elsif (!$isfolder && !$ispage) {
4295: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4296: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4297: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4298: my $suppanchor;
4299: if ($supplementalflag) {
4300: $suppanchor = $anchor;
4301: }
1.484.2.19 raeburn 4302: my $jscall =
1.484.2.12 raeburn 4303: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4304: $switchserver,
1.484.2.14 raeburn 4305: $forceedit,
1.484.2.19 raeburn 4306: undef,$symb,
4307: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4308: $renametitle,$hostname,
4309: '','',1,$suppanchor);
1.484.2.12 raeburn 4310: if ($jscall) {
1.484.2.19 raeburn 4311: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4312: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4313: }
4314: }
4315: }
1.484.2.19 raeburn 4316: $tdalign = ' align="right" valign="top"';
4317: $tdwidth = ' width="80%"';
1.329 droeschl 4318: }
1.408 raeburn 4319: my $reinit;
4320: if ($crstype eq 'Community') {
4321: $reinit = &mt('(re-initialize community to access)');
4322: } else {
4323: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4324: }
4325: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4326: my $link;
1.472 raeburn 4327: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4328: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4329: } elsif ($url) {
1.484.2.66 raeburn 4330: if ($anchor ne '') {
4331: if ($supplementalflag) {
4332: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4333: } else {
4334: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4335: }
4336: }
1.484.2.80 raeburn 4337:
4338: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4339: $link = 'http://'.$hostname.$url;
4340: } else {
4341: $link = $url;
4342: }
4343: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4344: if ($nomodal) {
4345: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4346: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4347: } else {
4348: $line.=&Apache::loncommon::modal_link($link,
4349: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4350: }
1.469 www 4351: } else {
4352: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4353: }
1.484.2.19 raeburn 4354: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4355: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4356: $line.='<a href="'.$url.'">'.$title.'</a>';
4357: } elsif ($url) {
1.484.2.70 raeburn 4358: if ($nomodal) {
4359: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4360: $title.'</a>';
4361: } else {
4362: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4363: }
1.484.2.67 raeburn 4364: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4365: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4366: } else {
4367: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4368: }
1.484.2.19 raeburn 4369: $line.="$extresform</td>";
1.478 raeburn 4370: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4371: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4372: if (($allowed) && ($folder!~/^supplemental/)) {
4373: my %lt=&Apache::lonlocal::texthash(
4374: 'hd' => 'Hidden',
4375: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4376: my ($enctext,$hidtext);
4377: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4378: $enctext = ' checked="checked"';
4379: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4380: push(@{$filtersref->{'encrypturl'}},$orderidx);
4381: }
4382: }
4383: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4384: $hidtext = ' checked="checked"';
4385: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4386: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4387: }
4388: }
1.484.2.29 raeburn 4389: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4390: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4391: $line.=(<<ENDPARMS);
4392: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4393: <form action="/adm/coursedocs" method="post" name="$formhidden">
4394: $form_param
1.478 raeburn 4395: $form_common
1.484.2.67 raeburn 4396: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4397: $form_end
1.458 raeburn 4398: <br />
1.484.2.29 raeburn 4399: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4400: $form_param
1.478 raeburn 4401: $form_common
1.484.2.67 raeburn 4402: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4403: $form_end
4404: </td>
1.478 raeburn 4405: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4406: $rand_order_text</td>
1.329 droeschl 4407: ENDPARMS
4408: }
1.379 bisitz 4409: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4410: return $line;
4411: }
4412:
1.484.2.30 raeburn 4413: sub action_restrictions {
4414: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4415: my %denied = (
4416: cut => 0,
4417: copy => 0,
4418: remove => 0,
4419: );
4420: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4421: # no copy for published maps
4422: $denied{'copy'} = 1;
1.484.2.82 raeburn 4423: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4424: unless ($1 eq 'simpleproblem') {
4425: $denied{'copy'} = 1;
4426: }
4427: $denied{'cut'} = 1;
1.484.2.30 raeburn 4428: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4429: if ($folderpath =~ /^default&[^\&]+$/) {
4430: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4431: $denied{'remove'} = 1;
4432: }
4433: $denied{'cut'} = 1;
4434: $denied{'copy'} = 1;
4435: }
4436: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4437: my $group = $1;
4438: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4439: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4440: $denied{'remove'} = 1;
4441: }
4442: }
4443: $denied{'cut'} = 1;
4444: $denied{'copy'} = 1;
4445: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4446: my $group = $1;
4447: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4448: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4449: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4450: if (keys(%groupsettings) > 0) {
4451: $denied{'remove'} = 1;
4452: }
4453: $denied{'cut'} = 1;
4454: $denied{'copy'} = 1;
4455: }
4456: }
4457: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4458: my $group = $1;
4459: if ($url =~ /group_boards_\Q$group\E/) {
4460: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4461: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4462: if (keys(%groupsettings) > 0) {
4463: if (ref($groupsettings{'functions'}) eq 'HASH') {
4464: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4465: $denied{'remove'} = 1;
4466: }
4467: }
4468: }
4469: $denied{'cut'} = 1;
4470: $denied{'copy'} = 1;
4471: }
4472: }
4473: }
4474: return %denied;
4475: }
4476:
1.484.2.26 raeburn 4477: sub new_timebased_suffix {
1.484.2.30 raeburn 4478: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4479: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4480: if ($type eq 'paste') {
4481: $prefix = $type;
4482: $namespace = 'courseeditor';
1.484.2.56 raeburn 4483: $idtype = 'addcode';
1.484.2.30 raeburn 4484: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4485: $prefix = 'docs';
4486: if ($area eq 'supplemental') {
4487: $prefix = 'supp';
4488: }
4489: $prefix .= $container;
4490: $namespace = 'uploadedmaps';
4491: } else {
4492: $prefix = $type;
4493: $namespace = 'templated';
1.484.2.15 raeburn 4494: }
4495: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4496: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4497: if (!$suffix) {
1.484.2.30 raeburn 4498: if ($type eq 'paste') {
4499: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4500: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4501: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4502: } elsif ($type eq 'smppg') {
4503: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.484.2.85.2. (raeburn 4504:): } elsif ($type eq 'exttool') {
4505:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.484.2.26 raeburn 4506: } else {
1.484.2.42 raeburn 4507: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4508: }
1.484.2.15 raeburn 4509: if ($error) {
4510: $errtext .= '<br />'.$error;
4511: }
4512: }
4513: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4514: $locknotfreed =
4515: '<div class="LC_error">'.
4516: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4517: if ($type eq 'paste') {
1.484.2.57 raeburn 4518: if ($freedlock eq 'nolock') {
4519: $locknotfreed =
4520: '<div class="LC_error">'.
4521: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4522:
1.484.2.60 raeburn 4523: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4524: } else {
4525: $locknotfreed .=
4526: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4527: }
1.484.2.30 raeburn 4528: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4529: $locknotfreed .=
4530: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4531: } elsif ($type eq 'smppg') {
4532: $locknotfreed .=
4533: &mt('This will prevent creation of additional simple pages in this course.');
1.484.2.85.2. (raeburn 4534:): } elsif ($type eq 'exttool') {
4535:): $locknotfreed .=
4536:): &mt('This will prevent creation of additional external tools in this course.');
1.484.2.26 raeburn 4537: } else {
4538: $locknotfreed .=
1.484.2.42 raeburn 4539: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4540: }
1.484.2.30 raeburn 4541: unless ($type eq 'paste') {
4542: $locknotfreed .=
1.484.2.38 raeburn 4543: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4544: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4545: }
4546: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4547: }
4548: return ($suffix,$errtext,$locknotfreed);
4549: }
4550:
1.329 droeschl 4551: =pod
4552:
4553: =item tiehash()
4554:
4555: tie the hash
4556:
4557: =cut
4558:
4559: sub tiehash {
4560: my ($mode)=@_;
4561: $hashtied=0;
4562: if ($env{'request.course.fn'}) {
4563: if ($mode eq 'write') {
4564: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4565: &GDBM_WRCREAT(),0640)) {
4566: $hashtied=2;
4567: }
4568: } else {
4569: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4570: &GDBM_READER(),0640)) {
4571: $hashtied=1;
4572: }
4573: }
1.364 bisitz 4574: }
1.329 droeschl 4575: }
4576:
4577: sub untiehash {
4578: if ($hashtied) { untie %hash; }
4579: $hashtied=0;
4580: return OK;
4581: }
4582:
4583:
4584:
4585:
4586: sub checkonthis {
1.484.2.78 raeburn 4587: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4588: $url=&unescape($url);
4589: $alreadyseen{$url}=1;
4590: $r->rflush();
4591: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4592: $r->print("\n<br />");
4593: if ($level==0) {
4594: $r->print("<br />");
4595: }
4596: for (my $i=0;$i<=$level*5;$i++) {
4597: $r->print(' ');
4598: }
4599: $r->print('<a href="'.$url.'" target="cat">'.
4600: ($title?$title:$url).'</a> ');
4601: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4602: my $updated;
4603: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4604: ($url !~ /\.\d+\.\w+$/)) {
4605: $updated = &Apache::lonnet::remove_stale_resfile($url);
4606: }
1.329 droeschl 4607: my $result=&Apache::lonnet::repcopy(
4608: &Apache::lonnet::filelocation('',$url));
4609: if ($result eq 'ok') {
4610: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4611: if ($updated) {
4612: $r->print('<br />');
4613: for (my $i=0;$i<=$level*5;$i++) {
4614: $r->print(' ');
4615: }
4616: $r->print('- '.&mt('Outdated copy removed'));
4617: }
1.329 droeschl 4618: $r->rflush();
4619: &Apache::lonnet::countacc($url);
4620: $url=~/\.(\w+)$/;
4621: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4622: $r->print('<br />');
4623: $r->rflush();
4624: for (my $i=0;$i<=$level*5;$i++) {
4625: $r->print(' ');
4626: }
4627: $r->print('- '.&mt('Rendering:').' ');
4628: my ($errorcount,$warningcount)=split(/:/,
4629: &Apache::lonnet::ssi_body($url,
4630: ('grade_target'=>'web',
4631: 'return_only_error_and_warning_counts' => 1)));
4632: if (($errorcount) ||
4633: ($warningcount)) {
4634: if ($errorcount) {
1.369 bisitz 4635: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4636: &mt('[quant,_1,error]',$errorcount).'</span>');
4637: }
4638: if ($warningcount) {
4639: $r->print('<span class="LC_warning">'.
4640: &mt('[quant,_1,warning]',$warningcount).'</span>');
4641: }
4642: } else {
4643: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4644: }
4645: $r->rflush();
4646: }
4647: my $dependencies=
4648: &Apache::lonnet::metadata($url,'dependencies');
4649: foreach my $dep (split(/\,/,$dependencies)) {
4650: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4651: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4652: }
4653: }
4654: } elsif ($result eq 'unavailable') {
4655: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4656: } elsif ($result eq 'not_found') {
4657: unless ($url=~/\$/) {
1.484.2.19 raeburn 4658: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4659: } else {
1.366 bisitz 4660: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4661: }
4662: } else {
4663: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4664: }
1.484.2.78 raeburn 4665: if (($updated) && ($result ne 'ok')) {
4666: $r->print('<br />'.&mt('Outdated copy removed'));
4667: }
1.329 droeschl 4668: }
4669: }
4670: }
4671:
4672:
4673:
4674: =pod
4675:
4676: =item list_symbs()
4677:
1.484.2.3 raeburn 4678: List Content Identifiers
1.329 droeschl 4679:
4680: =cut
4681:
4682: sub list_symbs {
4683: my ($r) = @_;
4684:
1.408 raeburn 4685: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4686: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4687: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4688: $r->print(&startContentScreen('tools'));
1.329 droeschl 4689: my $navmap = Apache::lonnavmaps::navmap->new();
4690: if (!defined($navmap)) {
4691: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4692: '<div class="LC_error">'.
4693: &mt('Unable to retrieve information about course contents').
4694: '</div>');
1.408 raeburn 4695: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4696: } else {
1.484 raeburn 4697: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4698: &Apache::loncommon::start_data_table().
4699: &Apache::loncommon::start_data_table_header_row().
4700: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4701: &Apache::loncommon::end_data_table_header_row()."\n");
4702: my $count;
1.329 droeschl 4703: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4704: $r->print(&Apache::loncommon::start_data_table_row().
4705: '<td>'.$res->compTitle().'</td>'.
4706: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4707: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4708: $count ++;
4709: }
4710: if (!$count) {
4711: $r->print(&Apache::loncommon::start_data_table_row().
4712: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4713: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4714: }
1.484 raeburn 4715: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4716: }
1.484.2.19 raeburn 4717: $r->print(&endContentScreen());
1.329 droeschl 4718: }
4719:
1.484.2.85.2. (raeburn 4720:): sub short_urls {
4721:): my ($r,$canedit) = @_;
4722:): my $crstype = &Apache::loncommon::course_type();
4723:): my $formname = 'shortenurl';
4724:): $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4725:): $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4726:): $r->print(&startContentScreen('tools'));
4727:): my ($navmap,$errormsg) =
4728:): &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4729:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4730:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4731:): my (%maps,%resources,%titles);
4732:): if (!ref($navmap)) {
4733:): $r->print($errormsg.
4734:): &endContentScreen());
4735:): return '';
4736:): } else {
4737:): $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4738:): $r->rflush();
4739:): my $readonly;
4740:): if ($canedit) {
4741:): my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
4742:): if ($numnew) {
4743:): $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4744:): }
4745:): if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4746:): $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4747:): foreach my $error (@{$errors}) {
4748:): $r->print('<li>'.$error.'</li>');
4749:): }
4750:): $r->print('</ul><br />');
4751:): }
4752:): } else {
4753:): $readonly = 1;
4754:): }
4755:): my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4756:): $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4757:): undef,undef,undef,undef,undef,\%currtiny,$readonly));
4758:): }
4759:): $r->print(&endContentScreen());
4760:): }
4761:):
1.484.2.78 raeburn 4762: sub contentverifyform {
4763: my ($r) = @_;
4764: my $crstype = &Apache::loncommon::course_type();
4765: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4766: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4767: $r->print(&startContentScreen('tools'));
4768: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4769: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4770: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4771: ' <span class="LC_nobreak">'.
4772: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4773: &mt('No').'</label>'.(' 'x2).
4774: '<label><input type="radio" name="checkstale" value="1" />'.
4775: &mt('Yes').'</label></span></p><p>'.
1.484.2.85.2. (raeburn 4776:): '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4777: '<input type="hidden" value="1" name="tools" />'.
4778: '<input type="hidden" value="1" name="verify" /></p></form>');
4779: $r->print(&endContentScreen());
4780: return;
4781: }
1.329 droeschl 4782:
4783: sub verifycontent {
1.484.2.78 raeburn 4784: my ($r,$checkstale) = @_;
1.408 raeburn 4785: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4786: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4787: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4788: $r->print(&startContentScreen('tools'));
4789: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4790: $hashtied=0;
4791: undef %alreadyseen;
4792: %alreadyseen=();
4793: &tiehash();
1.484 raeburn 4794:
1.329 droeschl 4795: foreach my $key (keys(%hash)) {
4796: if ($hash{$key}=~/\.(page|sequence)$/) {
4797: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4798: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4799: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4800: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4801: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4802: }
4803: }
4804: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4805: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4806: }
4807: }
4808: &untiehash();
1.442 www 4809: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4810: $r->print(&endContentScreen());
1.329 droeschl 4811: }
4812:
4813:
4814: sub devalidateversioncache {
4815: my $src=shift;
4816: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4817: &Apache::lonnet::clutter($src));
4818: }
4819:
4820: sub checkversions {
1.484.2.67 raeburn 4821: my ($r,$canedit) = @_;
1.408 raeburn 4822: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4823: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4824: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4825: $r->print(&startContentScreen('tools'));
1.442 www 4826:
1.329 droeschl 4827: my $header='';
4828: my $startsel='';
4829: my $monthsel='';
4830: my $weeksel='';
4831: my $daysel='';
4832: my $allsel='';
4833: my %changes=();
4834: my $starttime=0;
4835: my $haschanged=0;
4836: my %setversions=&Apache::lonnet::dump('resourceversions',
4837: $env{'course.'.$env{'request.course.id'}.'.domain'},
4838: $env{'course.'.$env{'request.course.id'}.'.num'});
4839:
4840: $hashtied=0;
4841: &tiehash();
1.484.2.67 raeburn 4842: if ($canedit) {
4843: my %newsetversions=();
4844: if ($env{'form.setmostrecent'}) {
4845: $haschanged=1;
4846: foreach my $key (keys(%hash)) {
4847: if ($key=~/^ids\_(\/res\/.+)$/) {
4848: $newsetversions{$1}='mostrecent';
4849: &devalidateversioncache($1);
4850: }
1.329 droeschl 4851: }
1.484.2.67 raeburn 4852: } elsif ($env{'form.setcurrent'}) {
4853: $haschanged=1;
4854: foreach my $key (keys(%hash)) {
4855: if ($key=~/^ids\_(\/res\/.+)$/) {
4856: my $getvers=&Apache::lonnet::getversion($1);
4857: if ($getvers>0) {
4858: $newsetversions{$1}=$getvers;
4859: &devalidateversioncache($1);
4860: }
4861: }
1.329 droeschl 4862: }
1.484.2.67 raeburn 4863: } elsif ($env{'form.setversions'}) {
4864: $haschanged=1;
4865: foreach my $key (keys(%env)) {
4866: if ($key=~/^form\.set_version_(.+)$/) {
4867: my $src=$1;
4868: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4869: $newsetversions{$src}=$env{$key};
4870: &devalidateversioncache($src);
4871: }
4872: }
1.329 droeschl 4873: }
1.484.2.67 raeburn 4874: }
4875: if ($haschanged) {
4876: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4877: $env{'course.'.$env{'request.course.id'}.'.domain'},
4878: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4879: $r->print(&Apache::loncommon::confirmwrapper(
4880: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4881: } else {
4882: $r->print(&Apache::loncommon::confirmwrapper(
4883: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4884: }
4885: &mark_hash_old();
4886: }
4887: &changewarning($r,'');
1.329 droeschl 4888: }
4889: if ($env{'form.timerange'} eq 'all') {
4890: # show all documents
1.484.2.34 raeburn 4891: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4892: $allsel=' selected="selected"';
1.329 droeschl 4893: foreach my $key (keys(%hash)) {
4894: if ($key=~/^ids\_(\/res\/.+)$/) {
4895: my $src=$1;
4896: $changes{$src}=1;
4897: }
4898: }
4899: } else {
4900: # show documents which changed
4901: %changes=&Apache::lonnet::dump
4902: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4903: $env{'course.'.$env{'request.course.id'}.'.num'});
4904: my $firstkey=(keys(%changes))[0];
4905: unless ($firstkey=~/^error\:/) {
4906: unless ($env{'form.timerange'}) {
4907: $env{'form.timerange'}=604800;
4908: }
4909: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4910: .&mt('seconds');
4911: if ($env{'form.timerange'}==-1) {
4912: $seltext='since start of course';
1.484.2.19 raeburn 4913: $startsel=' selected="selected"';
1.329 droeschl 4914: $env{'form.timerange'}=time;
4915: }
4916: $starttime=time-$env{'form.timerange'};
4917: if ($env{'form.timerange'}==2592000) {
4918: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4919: $monthsel=' selected="selected"';
1.329 droeschl 4920: } elsif ($env{'form.timerange'}==604800) {
4921: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4922: $weeksel=' selected="selected"';
1.329 droeschl 4923: } elsif ($env{'form.timerange'}==86400) {
4924: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4925: $daysel=' selected="selected"';
1.329 droeschl 4926: }
4927: $header=&mt('Content changed').' '.$seltext;
4928: } else {
4929: $header=&mt('No content modifications yet.');
4930: }
4931: }
4932: %setversions=&Apache::lonnet::dump('resourceversions',
4933: $env{'course.'.$env{'request.course.id'}.'.domain'},
4934: $env{'course.'.$env{'request.course.id'}.'.num'});
4935: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4936: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4937: 'lm' => 'Version changes since last Month',
4938: 'lw' => 'Version changes since last Week',
4939: 'sy' => 'Version changes since Yesterday',
4940: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4941: 'cd' => 'Change display',
1.329 droeschl 4942: 'sd' => 'Display',
4943: 'fi' => 'File',
4944: 'md' => 'Modification Date',
4945: 'mr' => 'Most recently published Version',
1.408 raeburn 4946: 've' => 'Version used in '.$crstype,
4947: 'vu' => 'Set Version to be used in '.$crstype,
4948: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4949: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4950: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4951: 'di' => 'Differences',
1.484 raeburn 4952: 'save' => 'Save changes',
4953: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4954: 'act' => 'Actions');
1.484.2.67 raeburn 4955: my ($disabled,$readonly);
4956: unless ($canedit) {
4957: $disabled = 'disabled="disabled"';
4958: $readonly = 1;
4959: }
1.329 droeschl 4960: $r->print(<<ENDHEADERS);
1.484 raeburn 4961: <h4 class="LC_info">$header</h4>
1.329 droeschl 4962: <form action="/adm/coursedocs" method="post">
4963: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4964: <div class="LC_left_float">
1.479 golterma 4965: <fieldset>
1.484 raeburn 4966: <legend>$lt{'cd'}</legend>
1.329 droeschl 4967: <select name="timerange">
1.484.2.19 raeburn 4968: <option value='all'$allsel>$lt{'al'}</option>
4969: <option value="-1"$startsel>$lt{'st'}</option>
4970: <option value="2592000"$monthsel>$lt{'lm'}</option>
4971: <option value="604800"$weeksel>$lt{'lw'}</option>
4972: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4973: </select>
4974: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4975: </fieldset>
4976: </div>
4977: <div class="LC_left_float">
4978: <fieldset>
4979: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4980: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4981: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4982: </fieldset>
4983: </div>
4984: <br clear="all" />
4985: <hr />
4986: <h4>$lt{'vers'}</h4>
1.329 droeschl 4987: ENDHEADERS
1.479 golterma 4988: #number of columns for version history
1.484.2.44 raeburn 4989: my %changedbytime;
4990: foreach my $key (keys(%changes)) {
4991: #excludes not versionable problems from resource version history:
4992: next if ($key =~ /^\/res\/lib\/templates/);
4993: my $chg;
4994: if ($env{'form.timerange'} eq 'all') {
4995: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4996: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4997: } else {
4998: $chg = $changes{$key};
4999: next if ($chg < $starttime);
5000: }
5001: push(@{$changedbytime{$chg}},$key);
5002: }
5003: if (keys(%changedbytime) == 0) {
5004: &untiehash();
5005: $r->print(&mt('No content changes in imported content in specified time frame').
5006: &endContentScreen());
5007: return;
5008: }
1.479 golterma 5009: $r->print(
1.484.2.67 raeburn 5010: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5011: &Apache::loncommon::start_data_table().
5012: &Apache::loncommon::start_data_table_header_row().
5013: '<th>'.&mt('Resources').'</th>'.
5014: "<th>$lt{'mr'}</th>".
5015: "<th>$lt{'ve'}</th>".
5016: "<th>$lt{'vu'}</th>".
5017: '<th>'.&mt('History').'</th>'.
5018: &Apache::loncommon::end_data_table_header_row()
5019: );
1.484.2.44 raeburn 5020: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5021: foreach my $key (sort(@{$changedbytime{$chg}})) {
5022: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5023: my $currentversion=&Apache::lonnet::getversion($key);
5024: if ($currentversion<0) {
5025: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5026: }
5027: my $linkurl=&Apache::lonnet::clutter($key);
5028: $r->print(
5029: &Apache::loncommon::start_data_table_row().
5030: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5031: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5032: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5033: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5034: '<td align="right">'
5035: );
5036: # Used in course
5037: my $usedversion=$hash{'version_'.$linkurl};
5038: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 5039: if ($usedversion != $currentversion) {
1.479 golterma 5040: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 5041: } else {
1.479 golterma 5042: $r->print($usedversion);
5043: }
1.329 droeschl 5044: } else {
1.484.2.19 raeburn 5045: $r->print($currentversion);
1.329 droeschl 5046: }
1.484.2.44 raeburn 5047: $r->print('</td><td title="'.$lt{'vu'}.'">');
5048: # Set version
5049: $r->print(&Apache::loncommon::select_form(
5050: $setversions{$linkurl},
5051: 'set_version_'.$linkurl,
5052: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5053: '' => '',
5054: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 5055: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 5056: my $lastold=1;
5057: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5058: my $url=$root.'.'.$prevvers.'.'.$extension;
5059: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5060: $lastold=$prevvers;
5061: }
5062: }
5063: $r->print('</td>');
5064: # List all available versions
5065: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5066: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5067: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 5068: $r->print(
1.484.2.44 raeburn 5069: '<span class="LC_nobreak">'
5070: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5071: .&mt('Version [_1]',$prevvers).'</a>'
5072: .' ('.&Apache::lonlocal::locallocaltime(
5073: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5074: .')');
5075: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5076: $r->print(
5077: ' <a href="/adm/diff?filename='.
5078: &Apache::lonnet::clutter($root.'.'.$extension).
5079: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5080: '" target="diffs">'.&mt('Diffs').'</a>');
5081: }
5082: $r->print('</span><br />');
1.329 droeschl 5083: }
1.484.2.44 raeburn 5084: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 5085: }
1.329 droeschl 5086: }
1.484.2.19 raeburn 5087: $r->print(
5088: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 5089: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 5090: '</form>'
5091: );
1.329 droeschl 5092:
5093: &untiehash();
1.484.2.19 raeburn 5094: $r->print(&endContentScreen());
1.484.2.44 raeburn 5095: return;
1.329 droeschl 5096: }
5097:
5098: sub mark_hash_old {
5099: my $retie_hash=0;
5100: if ($hashtied) {
5101: $retie_hash=1;
5102: &untiehash();
5103: }
5104: &tiehash('write');
5105: $hash{'old'}=1;
5106: &untiehash();
5107: if ($retie_hash) { &tiehash(); }
5108: }
5109:
5110: sub is_hash_old {
5111: my $untie_hash=0;
5112: if (!$hashtied) {
5113: $untie_hash=1;
5114: &tiehash();
5115: }
5116: my $return=$hash{'old'};
5117: if ($untie_hash) { &untiehash(); }
5118: return $return;
5119: }
5120:
5121: sub changewarning {
5122: my ($r,$postexec,$message,$url)=@_;
5123: if (!&is_hash_old()) { return; }
5124: my $pathvar='folderpath';
5125: my $path=&escape($env{'form.folderpath'});
5126: if (!defined($url)) {
5127: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5128: }
5129: my $course_type = &Apache::loncommon::course_type();
5130: if (!defined($message)) {
5131: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5132: }
5133: $r->print("\n\n".
1.372 bisitz 5134: '<script type="text/javascript">'."\n".
5135: '// <![CDATA['."\n".
5136: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5137: '// ]]>'."\n".
1.369 bisitz 5138: '</script>'."\n".
1.375 tempelho 5139: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5140: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5141: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5142: &mt($message,' <input type="hidden" name="'.
5143: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5144: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5145: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5146: }
5147:
5148:
5149: sub init_breadcrumbs {
1.484.2.44 raeburn 5150: my ($form,$text,$help)=@_;
1.329 droeschl 5151: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5152: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5153: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5154: faq=>273,
5155: bug=>'Instructor Interface',
1.484.2.44 raeburn 5156: help => $help});
1.329 droeschl 5157: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5158: text=>$text,
5159: faq=>273,
5160: bug=>'Instructor Interface'});
5161: }
5162:
1.441 www 5163: # subroutine to list form elements
5164: sub create_list_elements {
5165: my @formarr = @_;
5166: my $list = '';
1.484.2.12 raeburn 5167: foreach my $button (@formarr){
5168: foreach my $picture (keys(%{$button})) {
5169: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5170: }
5171: }
5172: return $list;
5173: }
1.329 droeschl 5174:
1.441 www 5175: # subroutine to create ul from list elements
5176: sub create_form_ul {
5177: my $list = shift;
5178: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5179: return $ul;
5180: }
1.329 droeschl 5181:
1.442 www 5182: #
5183: # Start tabs
5184: #
5185:
5186: sub startContentScreen {
1.484 raeburn 5187: my ($mode) = @_;
5188: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5189: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5190: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5191: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5192: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5193: } else {
1.484.2.34 raeburn 5194: $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 5195: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5196: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5197: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5198: }
5199: $output .= "\n".'</ul>'."\n";
5200: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5201: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5202: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5203: return $output;
1.442 www 5204: }
5205:
5206: #
5207: # End tabs
5208: #
5209:
5210: sub endContentScreen {
1.484 raeburn 5211: return '</div></div></div>';
1.442 www 5212: }
1.329 droeschl 5213:
1.446 www 5214: sub supplemental_base {
1.484.2.33 raeburn 5215: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5216: }
5217:
1.329 droeschl 5218: sub handler {
5219: my $r = shift;
5220: &Apache::loncommon::content_type($r,'text/html');
5221: $r->send_http_header;
5222: return OK if $r->header_only;
1.484 raeburn 5223:
5224: # get course data
1.408 raeburn 5225: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5226: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5227: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5228:
5229: # graphics settings
5230: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5231:
1.443 www 5232: #
1.329 droeschl 5233: # --------------------------------------------- Initialize help topics for this
5234: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.484.2.85.2. (raeburn 5235:): 'Adding_External_Resource','Adding_External_Tool',
5236:): 'Navigate_Content','Adding_Folders','Docs_Overview',
5237:): 'Load_Map','Supplemental','Score_Upload_Form',
5238:): 'Adding_Pages','Importing_LON-CAPA_Resource',
5239:): 'Importing_IMS_Course','Uploading_From_Harddrive',
5240:): 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5241: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5242: }
5243: # Composite help files
5244: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5245: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5246: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5247: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5248: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5249: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5250: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5251: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5252: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5253: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5254:
1.484.2.67 raeburn 5255: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5256: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5257: unless ($r->uri eq '/adm/supplemental') {
5258: # does this user have privileges to modify content.
1.484.2.67 raeburn 5259: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5260: $allowed = 1;
5261: $canedit = 1;
5262: $canview = 1;
5263: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5264: $allowed = 1;
5265: $canview = 1;
5266: }
5267: }
5268: unless ($canedit) {
5269: $disabled = ' disabled="disabled"';
1.472 raeburn 5270: }
1.484.2.53 raeburn 5271: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5272: if ($env{'form.inhibitmenu'}) {
5273: unless ($env{'form.inhibitmenu'} eq 'yes') {
5274: delete($env{'form.inhibitmenu'});
5275: }
5276: }
5277:
1.484.2.53 raeburn 5278: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5279: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5280: if (!$canedit) {
5281: &verifycontent($r);
5282: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5283: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5284: text=>'Results',
5285: faq=>273,
5286: bug=>'Instructor Interface'});
5287: &verifycontent($r,$env{'form.checkstale'});
5288: } else {
5289: &contentverifyform($r);
5290: }
1.329 droeschl 5291: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5292: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5293: &list_symbs($r);
1.484.2.85.2. (raeburn 5294:): } elsif ($allowed && $env{'form.shorturls'}) {
5295:): &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5296:): &short_urls($r,$canedit);
1.329 droeschl 5297: } elsif ($allowed && $env{'form.docslog'}) {
5298: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5299: my $folder = $env{'form.folder'};
5300: if ($folder eq '') {
5301: $folder='default';
5302: }
1.484.2.67 raeburn 5303: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5304: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5305: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5306: &checkversions($r,$canedit);
5307: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5308: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5309: &dumpcourse($r);
5310: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5311: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5312: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5313: } else {
1.445 www 5314: #
5315: # Done catching special calls
1.484 raeburn 5316: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5317: # Get the parameters that may be needed
5318: #
5319: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5320: ['folderpath',
5321: 'forcesupplement','forcestandard',
5322: 'tools','symb','command','supppath']);
1.445 www 5323:
1.484.2.78 raeburn 5324: foreach my $item ('forcesupplement','forcestandard','tools') {
5325: next if ($env{'form.'.$item} eq '');
5326: unless ($env{'form.'.$item} eq '1') {
5327: delete($env{'form.'.$item});
5328: }
5329: }
5330:
5331: if ($env{'form.command'}) {
5332: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5333: delete($env{'form.command'});
5334: }
5335: }
5336:
5337: if ($env{'form.symb'}) {
5338: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5339: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5340: delete($env{'form.symb'});
5341: }
5342: }
5343:
1.445 www 5344: # standard=1: this is a "new-style" course with an uploaded map as top level
5345: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5346:
5347: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5348:
1.484 raeburn 5349: # Decide whether this should display supplemental or main content or utilities
1.445 www 5350: # supplementalflag=1: show supplemental documents
5351: # supplementalflag=0: show standard documents
1.484 raeburn 5352: # toolsflag=1: show utilities
1.445 www 5353:
1.484.2.39 raeburn 5354: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5355: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5356: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5357: $supplementalflag=0;
5358: }
5359: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5360: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5361: unless ($allowed) { $supplementalflag=1; }
5362: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5363: my $toolsflag=0;
5364: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5365:
1.484.2.78 raeburn 5366: if ($env{'form.folderpath'} ne '') {
5367: my @items = split(/\&/,$env{'form.folderpath'});
5368: my $badpath;
5369: for (my $i=0; $i<@items; $i++) {
5370: my $odd = $i%2;
5371: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5372: $badpath = 1;
5373: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5374: $badpath = 1;
5375: }
5376: last if ($badpath);
5377: }
5378: if ($badpath) {
5379: delete($env{'form.folderpath'});
5380: }
5381: }
5382:
5383: if ($env{'form.supppath'} ne '') {
5384: my @items = split(/\&/,$env{'form.supppath'});
5385: my $badpath;
5386: for (my $i=0; $i<@items; $i++) {
5387: my $odd = $i%2;
5388: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5389: $badpath = 1;
5390: }
5391: last if ($badpath);
5392: }
5393: if ($badpath) {
5394: delete($env{'form.supppath'});
5395: }
5396: }
5397:
1.329 droeschl 5398: my $script='';
5399: my $showdoc=0;
1.457 raeburn 5400: my $addentries = {};
1.475 raeburn 5401: my $container;
1.329 droeschl 5402: my $containertag;
1.484.2.17 raeburn 5403: my $pathitem;
1.484.2.85.2. (raeburn 5404:): my %ltitools;
1.484.2.67 raeburn 5405: my $hiddentop;
5406: my $navmap;
5407: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5408:
1.464 www 5409: # Do we directly jump somewhere?
1.484.2.21 raeburn 5410: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5411: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5412: $env{'form.folderpath'}=
1.484.2.67 raeburn 5413: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5414: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5415: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5416: } elsif ($env{'form.supppath'} ne '') {
5417: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5418: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5419: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5420: }
1.472 raeburn 5421: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5422: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5423: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5424: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5425: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5426: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5427: } elsif ($env{'form.command'} eq 'contents') {
5428: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5429: } elsif ($env{'form.command'} eq 'home') {
5430: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5431: }
5432:
1.484.2.23 raeburn 5433:
1.445 www 5434: # Where do we store these for when we come back?
5435: my $stored_folderpath='docs_folderpath';
5436: if ($supplementalflag) {
5437: $stored_folderpath='docs_sup_folderpath';
5438: }
1.464 www 5439:
1.484.2.19 raeburn 5440: # No folderpath, and in edit mode, see if we have something stored
5441: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5442: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5443: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5444:
5445: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5446: if ($supplementalflag) {
5447: undef($env{'form.folderpath'}) if ($1 eq 'default');
5448: } else {
5449: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5450: }
5451: } else {
1.484.2.19 raeburn 5452: undef($env{'form.folderpath'});
5453: }
1.329 droeschl 5454: }
1.446 www 5455:
5456: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5457: if (!$allowed) {
1.446 www 5458: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5459: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5460: }
5461: }
1.446 www 5462: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5463: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5464: $env{'form.folderpath'} = &supplemental_base()
5465: .'&'.
1.329 droeschl 5466: $env{'form.folderpath'};
5467: }
1.484.2.67 raeburn 5468: # If allowed and user's role is not advanced check folderpath is not hidden
5469: if (($allowed) && (!$env{'request.role.adv'}) &&
5470: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5471: my $folderurl;
5472: my @pathitems = split(/\&/,$env{'form.folderpath'});
5473: my $folder = $pathitems[-2];
5474: if ($folder eq '') {
5475: undef($env{'form.folderpath'});
5476: } else {
5477: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.85.2. (raeburn 5478:): if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5479: $folderurl .= '.page';
5480: } else {
5481: $folderurl .= '.sequence';
5482: }
5483: unless (ref($navmap)) {
5484: $navmap = Apache::lonnavmaps::navmap->new();
5485: }
5486: if (ref($navmap)) {
5487: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5488: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5489: unless (@resources) {
5490: undef($env{'form.folderpath'});
5491: }
5492: }
5493: }
5494: }
5495: }
5496:
5497:
1.446 www 5498: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5499: unless ($env{'form.folderpath'}) {
1.446 www 5500: if ($supplementalflag) {
5501: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5502: } elsif ($allowed) {
5503: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5504: }
1.472 raeburn 5505: }
1.446 www 5506:
1.445 www 5507: # Store this
1.484 raeburn 5508: unless ($toolsflag) {
1.484.2.67 raeburn 5509: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5510: &Apache::loncommon::store_course_settings($stored_folderpath,
5511: {'folderpath' => 'scalar'});
5512: }
5513: my $folderpath;
1.484 raeburn 5514: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5515: $folderpath = $env{'form.folderpath'};
5516: my (@folders)=split('&',$env{'form.folderpath'});
5517: $env{'form.foldername'}=&unescape(pop(@folders));
5518: if ($env{'form.foldername'} =~ /\:1$/) {
5519: $container = 'page';
5520: } else {
5521: $container = 'sequence';
5522: }
5523: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5524: } else {
1.484.2.19 raeburn 5525: if ($env{'form.folder'} eq '' ||
5526: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5527: if ($env{'form.folder'} eq 'supplemental') {
5528: $folderpath=&supplemental_base();
5529: } elsif (!$hiddentop) {
5530: $folderpath='default&'.
5531: &escape(&mt('Main Content').':::::');
5532: }
1.484 raeburn 5533: }
5534: }
1.484.2.19 raeburn 5535: $containertag = '<input type="hidden" name="folderpath" value="" />';
5536: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5537: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5538: $showdoc='/'.$1;
5539: }
5540: if ($showdoc) { # got called in sequence from course
5541: $allowed=0;
5542: } else {
1.484.2.67 raeburn 5543: if ($canedit) {
1.484 raeburn 5544: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5545: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5546: }
5547: }
1.329 droeschl 5548: }
5549:
1.344 bisitz 5550: # get personal data
1.329 droeschl 5551: my $uname=$env{'user.name'};
5552: my $udom=$env{'user.domain'};
5553: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5554:
5555: if ($allowed) {
1.484 raeburn 5556: if ($toolsflag) {
5557: $script .= &inject_data_js();
5558: my ($home,$other,%outhash)=&authorhosts();
5559: if (!$home && $other) {
5560: my @hosts;
5561: foreach my $aurole (keys(%outhash)) {
5562: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5563: push(@hosts,$outhash{$aurole});
5564: }
5565: }
5566: $script .= &dump_switchserver_js(@hosts);
5567: }
1.458 raeburn 5568: } else {
1.484.2.43 raeburn 5569: my $tid = 1;
1.484 raeburn 5570: my @tabids;
5571: if ($supplementalflag) {
5572: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5573: $tid = 2;
1.484 raeburn 5574: } else {
5575: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5576: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5577: unshift(@tabids,'001');
5578: push(@tabids,('dd1','ee1'));
5579: }
1.458 raeburn 5580: }
1.484 raeburn 5581: my $tabidstr = join("','",@tabids);
1.484.2.85.2. (raeburn 5582:): %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
5583:): my $posslti = keys(%ltitools);
1.484.2.80 raeburn 5584: my $hostname = $r->hostname();
1.484.2.85.2. (raeburn 5585:): $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 5586: $canedit,$hostname,\$navmap).
1.484 raeburn 5587: &history_tab_js().
5588: &inject_data_js().
1.484.2.43 raeburn 5589: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.85.2. (raeburn 5590:): &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5591: $addentries = {
1.484.2.3 raeburn 5592: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5593: };
1.458 raeburn 5594: }
1.484.2.30 raeburn 5595: $script .= &paste_popup_js();
1.484.2.12 raeburn 5596: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5597: &mt('Switch server?');
1.484.2.19 raeburn 5598:
5599:
1.329 droeschl 5600: }
5601: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5602: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5603: .'// <![CDATA['."\n"
5604: .$script."\n"
5605: .'// ]]>'."\n"
1.484.2.81 raeburn 5606: .'</script>'."\n"
5607: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5608:
5609: # Breadcrumbs
5610: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5611:
5612: if ($showdoc) {
5613: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5614: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5615: } elsif ($toolsflag) {
1.484.2.67 raeburn 5616: my ($breadtext,$breadtitle);
5617: $breadtext = "$crstype Editor";
5618: if ($canedit) {
5619: $breadtitle = 'Editing '.$crstype.' Contents';
5620: } else {
5621: $breadtext .= ' (View-only mode)';
5622: $breadtitle = 'Viewing '.$crstype.' Contents';
5623: }
1.484.2.44 raeburn 5624: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5625: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5626: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5627: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5628: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5629: $breadtitle)
1.484.2.44 raeburn 5630: );
1.484.2.19 raeburn 5631: } elsif ($r->uri eq '/adm/supplemental') {
5632: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5633: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5634: {'bread_crumbs' => $brcrum,}));
5635: } else {
1.484.2.67 raeburn 5636: my ($breadtext,$breadtitle,$helpitem);
5637: $breadtext = "$crstype Editor";
5638: if ($canedit) {
5639: $breadtitle = 'Editing '.$crstype.' Contents';
5640: $helpitem = 'Docs_Adding_Course_Doc';
5641: } else {
5642: $breadtext .= ' (View-only mode)';
5643: $breadtitle = 'Viewing '.$crstype.' Contents';
5644: $helpitem = 'Docs_Viewing_Course_Doc';
5645: }
1.392 raeburn 5646: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5647: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5648: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5649: {'add_entries' => $addentries}
5650: )
1.392 raeburn 5651: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5652: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5653: $breadtitle,
5654: $helpitem)
1.392 raeburn 5655: );
5656: }
1.364 bisitz 5657:
1.329 droeschl 5658: my %allfiles = ();
5659: my %codebase = ();
1.440 raeburn 5660: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5661: if ($canedit) {
1.329 droeschl 5662: if (($env{'form.uploaddoc.filename'}) &&
5663: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5664: my $context = $1;
5665: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5666: undef($hadchanges);
1.440 raeburn 5667: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5668: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5669: undef($navmap);
1.329 droeschl 5670: if ($hadchanges) {
5671: &mark_hash_old();
5672: }
1.440 raeburn 5673: $r->print($upload_output);
5674: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5675: # Process file upload - phase two - upload embedded objects
5676: $uploadphase = 'check_embedded';
5677: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5678: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5679: $env{'form.newidx'});
5680: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5681: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5682: my ($destination,$dir_root) = &embedded_destination();
5683: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5684: my $actionurl = '/adm/coursedocs';
5685: my ($result,$flag) =
5686: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5687: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5688: $actionurl);
5689: $r->print($result.&return_to_editor());
5690: } elsif ($env{'form.phase'} eq 'check_embedded') {
5691: # Process file upload - phase three - modify references in HTML file
5692: $uploadphase = 'modified_orightml';
5693: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5694: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5695: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5696: my $result =
5697: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5698: $docuname,$docudom,undef,
5699: $dir_root);
5700: $r->print($result.&return_to_editor());
1.476 raeburn 5701: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5702: $uploadphase = 'decompress_phase_one';
5703: $r->print(&decompression_phase_one().
5704: &return_to_editor());
5705: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5706: $uploadphase = 'decompress_phase_two';
5707: $r->print(&decompression_phase_two().
5708: &return_to_editor());
1.329 droeschl 5709: }
5710: }
5711:
1.484 raeburn 5712: if ($allowed && $toolsflag) {
5713: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5714: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5715: $r->print(&endContentScreen());
5716: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5717: # -----------------------------------------------------------------------------
5718: my %lt=&Apache::lonlocal::texthash(
5719: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5720: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5721: 'upld' => 'Upload Content',
1.329 droeschl 5722: 'srch' => 'Search',
5723: 'impo' => 'Import',
1.484.2.19 raeburn 5724: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5725: 'impm' => 'Import from Assembled Map',
1.484.2.85.2. (raeburn 5726:): 'extr' => 'External Resource',
5727:): 'extt' => 'External Tool',
1.329 droeschl 5728: 'selm' => 'Select Map',
5729: 'load' => 'Load Map',
5730: 'newf' => 'New Folder',
5731: 'newp' => 'New Composite Page',
5732: 'syll' => 'Syllabus',
1.425 raeburn 5733: 'navc' => 'Table of Contents',
1.343 biermanm 5734: 'sipa' => 'Simple Course Page',
1.329 droeschl 5735: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5736: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5737: 'drbx' => 'Drop Box',
1.451 www 5738: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5739: 'bull' => 'Discussion Board',
1.347 weissno 5740: 'mypi' => 'My Personal Information Page',
1.353 weissno 5741: 'grpo' => 'Group Portfolio',
1.329 droeschl 5742: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5743: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5744: 'imsf' => 'IMS Upload',
5745: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5746: 'cms' => 'Origin of IMS package',
5747: 'se' => 'Select',
1.484.2.19 raeburn 5748: 'file' => 'File',
1.329 droeschl 5749: 'title' => 'Title',
5750: 'comment' => 'Comment',
1.403 raeburn 5751: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5752: 'bb5' => 'Blackboard 5',
5753: 'bb6' => 'Blackboard 6',
5754: 'angel5' => 'ANGEL 5.5',
5755: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5756: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5757: );
1.329 droeschl 5758: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5759: # Calculate free quota space for a user or course. A javascript function checks
5760: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5761: my $quotatype = 'unofficial';
5762: if ($crstype eq 'Community') {
5763: $quotatype = 'community';
5764: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5765: $quotatype = 'official';
5766: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5767: $quotatype = 'textbook';
5768: }
5769: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5770: 'course',$quotatype); # expressed in MB
5771: my $current_disk_usage = 0;
5772: foreach my $subdir ('docs','supplemental') {
5773: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5774: "userfiles/$subdir",1); # expressed in kB
5775: }
5776: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5777: my $usage = $current_disk_usage/1024; # in MB
5778: my $quota = $disk_quota;
5779: my $percent;
5780: if ($disk_quota == 0) {
5781: $percent = 100.0;
5782: } else {
1.484.2.69 raeburn 5783: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5784: }
5785: $usage = sprintf("%.2f",$usage);
5786: $quota = sprintf("%.2f",$quota);
5787: $percent = sprintf("%.0f",$percent);
5788: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5789: $percent.'%',$quota.' MB').'</p>';
5790:
1.329 droeschl 5791: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5792: $quotainfo
1.329 droeschl 5793: $lt{'file'}:<br />
1.484.2.81 raeburn 5794: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5795: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5796: FIUP
5797:
5798: my $checkbox=(<<CHBO);
5799: <!-- <label>$lt{'parse'}?
5800: <input type="checkbox" name="parserflag" />
5801: </label> -->
5802: <label>
1.484.2.67 raeburn 5803: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5804: </label>
5805: CHBO
1.484.2.12 raeburn 5806: my $imsfolder = $env{'form.folder'};
5807: if ($imsfolder eq '') {
1.484.2.19 raeburn 5808: $imsfolder = 'default';
1.484.2.12 raeburn 5809: }
5810: my $imspform=(<<IMSFORM);
5811: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5812: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5813: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5814: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5815: <legend>$lt{'imsf'}</legend>
5816: $fileupload
5817: <br />
5818: <p>
1.484.2.19 raeburn 5819: $lt{'cms'}:
1.484.2.67 raeburn 5820: <select name="source" $disabled>
1.484.2.12 raeburn 5821: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5822: <option value="bb5">$lt{'bb5'}</option>
5823: <option value="bb6">$lt{'bb6'}</option>
5824: <option value="angel5">$lt{'angel5'}</option>
5825: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5826: </select>
5827: <input type="hidden" name="folder" value="$imsfolder" />
5828: </p>
5829: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5830: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5831: </fieldset>
5832: </form>
5833: IMSFORM
5834:
1.484.2.19 raeburn 5835: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5836: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5837: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5838: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5839: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5840: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5841: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5842: $fileupload
5843: <br />
5844: $lt{'title'}:<br />
1.484.2.67 raeburn 5845: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5846: $pathitem
1.329 droeschl 5847: <input type="hidden" name="cmd" value="upload_default" />
5848: <br />
1.458 raeburn 5849: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5850: $checkbox
5851: </span>
1.484.2.12 raeburn 5852: <br clear="all" />
1.484.2.67 raeburn 5853: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5854: </fieldset>
5855: </form>
1.383 tempelho 5856: FUFORM
1.329 droeschl 5857:
1.484.2.67 raeburn 5858: my $mapimportjs;
5859: if ($canedit) {
5860: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5861: } else {
5862: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5863: }
1.484.2.19 raeburn 5864: my $importpubform=(<<SEDFFORM);
5865: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5866: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5867: <form action="/adm/coursedocs" method="post" name="mapimportform">
5868: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5869: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5870: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5871: $lt{'copm'}<br />
5872: <span class="LC_nobreak">
1.484.2.19 raeburn 5873: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5874: onfocus="this.blur();$mapimportjs" $disabled />
5875: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5876: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5877: </fieldset>
5878: </form>
5879:
1.383 tempelho 5880: SEDFFORM
1.484.2.67 raeburn 5881:
5882: my $fromstoredjs;
5883: if ($canedit) {
5884: $fromstoredjs = 'open_StoredLinks_Import()';
5885: } else {
5886: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5887: }
5888:
1.484.2.19 raeburn 5889: my @importpubforma = (
5890: { '<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 5891: { '<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 5892: { '<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 5893: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5894: );
5895: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5896: my $extresourcesform =
5897: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5898: $help{'Adding_External_Resource'},
1.484.2.85.2. (raeburn 5899:): undef,undef,undef,undef,undef,undef,$disabled);
5900:): my $exttoolform =
5901:): &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5902:): $help{'Adding_External_Tool'},undef,
5903:): undef,'tool',$coursedom,$coursenum,
5904:): \%ltitools,$disabled);
1.329 droeschl 5905: if ($allowed) {
1.484.2.7 raeburn 5906: my $folder = $env{'form.folder'};
5907: if ($folder eq '') {
5908: $folder='default';
5909: }
1.484.2.67 raeburn 5910: if ($canedit) {
5911: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5912: if ($output) {
5913: $r->print($output);
5914: }
1.484.2.30 raeburn 5915: }
1.337 ehlerst 5916: $r->print(<<HIDDENFORM);
5917: <form name="renameform" method="post" action="/adm/coursedocs">
5918: <input type="hidden" name="title" />
5919: <input type="hidden" name="cmd" />
5920: <input type="hidden" name="markcopy" />
5921: <input type="hidden" name="copyfolder" />
5922: $containertag
5923: </form>
1.484 raeburn 5924:
1.337 ehlerst 5925: HIDDENFORM
1.484.2.17 raeburn 5926: $r->print(&makesimpleeditform($pathitem)."\n".
5927: &makedocslogform($pathitem."\n".
1.484 raeburn 5928: '<input type="hidden" name="folder" value="'.
5929: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5930: }
1.442 www 5931:
5932: # Generate the tabs
1.484.2.19 raeburn 5933: my ($mode,$needs_end);
1.472 raeburn 5934: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5935: my @folders = split('&',$env{'form.folderpath'});
5936: unless (@folders > 2) {
5937: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5938: $needs_end = 1;
5939: }
1.472 raeburn 5940: } else {
1.484 raeburn 5941: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5942: $needs_end = 1;
1.472 raeburn 5943: }
1.443 www 5944:
1.442 www 5945: #
5946:
5947: my $savefolderpath;
1.484.2.85.2. (raeburn 5948:): my $hostname = $r->hostname();
1.442 www 5949:
1.395 raeburn 5950: if ($allowed) {
1.329 droeschl 5951: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5952: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5953: $folder='default';
1.356 tempelho 5954: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5955: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5956: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5957: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5958: }
5959: my $postexec='';
5960: if ($folder eq 'default') {
1.372 bisitz 5961: $r->print('<script type="text/javascript">'."\n"
5962: .'// <![CDATA['."\n"
5963: .'this.window.name="loncapaclient";'."\n"
5964: .'// ]]>'."\n"
5965: .'</script>'."\n"
1.369 bisitz 5966: );
1.329 droeschl 5967: } else {
5968: #$postexec='self.close();';
5969: }
1.484.2.15 raeburn 5970: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5971: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5972: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5973:
5974: my $newnavform=(<<NNFORM);
5975: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5976: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5977: $pathitem
1.329 droeschl 5978: <input type="hidden" name="importdetail"
5979: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5980: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5981: $help{'Navigate_Content'}
5982: </form>
5983: NNFORM
5984: my $newsmppageform=(<<NSPFORM);
5985: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5986: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5987: $pathitem
1.329 droeschl 5988: <input type="hidden" name="importdetail" value="" />
1.423 onken 5989: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5990: $help{'Simple Page'}
1.329 droeschl 5991: </form>
5992: NSPFORM
5993:
5994: my $newsmpproblemform=(<<NSPROBFORM);
5995: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5996: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5997: $pathitem
1.329 droeschl 5998: <input type="hidden" name="importdetail" value="" />
1.423 onken 5999: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 6000: $help{'Simple_Problem'}
1.329 droeschl 6001: </form>
6002:
6003: NSPROBFORM
6004:
6005: my $newdropboxform=(<<NDBFORM);
6006: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6007: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6008: $pathitem
1.329 droeschl 6009: <input type="hidden" name="importdetail" value="" />
1.423 onken 6010: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 6011: $help{'Dropbox'}
1.344 bisitz 6012: </form>
1.329 droeschl 6013: NDBFORM
6014:
6015: my $newexuploadform=(<<NEXUFORM);
6016: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6017: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 6018: $pathitem
1.329 droeschl 6019: <input type="hidden" name="importdetail" value="" />
1.423 onken 6020: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6021: $help{'Score_Upload_Form'}
6022: </form>
6023: NEXUFORM
6024:
6025: my $newbulform=(<<NBFORM);
6026: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 6027: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6028: $pathitem
1.329 droeschl 6029: <input type="hidden" name="importdetail" value="" />
1.423 onken 6030: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6031: $help{'Bulletin Board'}
6032: </form>
6033: NBFORM
6034:
6035: my $newaboutmeform=(<<NAMFORM);
6036: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 6037: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6038: $pathitem
1.329 droeschl 6039: <input type="hidden" name="importdetail"
6040: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6041: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6042: $help{'My Personal Information Page'}
1.329 droeschl 6043: </form>
6044: NAMFORM
6045:
6046: my $newaboutsomeoneform=(<<NASOFORM);
6047: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 6048: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6049: $pathitem
1.329 droeschl 6050: <input type="hidden" name="importdetail" value="" />
1.423 onken 6051: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6052: </form>
6053: NASOFORM
6054:
6055: my $newrosterform=(<<NROSTFORM);
6056: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 6057: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6058: $pathitem
1.329 droeschl 6059: <input type="hidden" name="importdetail"
6060: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 6061: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 6062: $help{'Course_Roster'}
1.329 droeschl 6063: </form>
6064: NROSTFORM
6065:
1.484.2.27 raeburn 6066: my $newwebpage;
6067: if ($folder =~ /^default_?(\d*)$/) {
6068: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6069: if ($1) {
6070: $newwebpage .= $1;
6071: } else {
6072: $newwebpage .= 'default';
6073: }
6074: $newwebpage .= '/new.html';
6075: }
6076: my $newwebpageform =(<<NWEBFORM);
6077: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 6078: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 6079: $pathitem
6080: <input type="hidden" name="importdetail" value="$newwebpage" />
6081: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 6082: $help{'Web_Page'}
1.484.2.27 raeburn 6083: </form>
6084: NWEBFORM
1.484.2.30 raeburn 6085:
1.484.2.27 raeburn 6086:
1.342 ehlerst 6087: my $specialdocumentsform;
1.383 tempelho 6088: my @specialdocumentsforma;
1.451 www 6089: my $gradingform;
6090: my @gradingforma;
6091: my $communityform;
6092: my @communityforma;
1.351 ehlerst 6093: my $newfolderform;
1.390 tempelho 6094: my $newfolderb;
1.342 ehlerst 6095:
1.451 www 6096: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6097:
1.329 droeschl 6098: my $newpageform=(<<NPFORM);
6099: <form action="/adm/coursedocs" method="post" name="newpage">
6100: <input type="hidden" name="folderpath" value="$path" />
6101: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6102: <input type="hidden" name="active" value="ee" />
1.423 onken 6103: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6104: $help{'Adding_Pages'}
1.329 droeschl 6105: </form>
6106: NPFORM
1.390 tempelho 6107:
6108:
1.351 ehlerst 6109: $newfolderform=(<<NFFORM);
1.329 droeschl 6110: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 6111: $pathitem
1.329 droeschl 6112: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 6113: <input type="hidden" name="active" value="" />
1.422 onken 6114: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6115: </form>
6116: NFFORM
6117:
6118: my $newsylform=(<<NSYLFORM);
6119: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 6120: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 6121: $pathitem
1.329 droeschl 6122: <input type="hidden" name="importdetail"
6123: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6124: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6125: $help{'Syllabus'}
1.383 tempelho 6126:
1.329 droeschl 6127: </form>
6128: NSYLFORM
1.364 bisitz 6129:
1.329 droeschl 6130: my $newgroupfileform=(<<NGFFORM);
6131: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 6132: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 6133: $pathitem
1.329 droeschl 6134: <input type="hidden" name="importdetail"
6135: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 6136: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6137: $help{'Group Portfolio'}
1.329 droeschl 6138: </form>
6139: NGFFORM
1.484.2.85.2. (raeburn 6140:): if ($container eq 'page') {
6141:): @specialdocumentsforma=(
6142:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6143:): );
6144:): } else {
6145:): @specialdocumentsforma=(
1.421 onken 6146: {'<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 6147: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6148: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6149: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 6150: {'<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 6151:): );
6152:): }
1.451 www 6153: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6154:
1.434 raeburn 6155:
6156: my @importdoc = (
1.484.2.19 raeburn 6157: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6158: );
1.484.2.85.2. (raeburn 6159:): if (keys(%ltitools)) {
6160:): push(@importdoc,
6161:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6162:): );
6163:): }
1.484.2.19 raeburn 6164: unless ($container eq 'page') {
6165: push(@importdoc,
6166: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6167: );
6168: }
6169: push(@importdoc,
1.484.2.38 raeburn 6170: {'<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 6171: );
1.484.2.12 raeburn 6172: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6173:
1.451 www 6174: @gradingforma=(
6175: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6176: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6177: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6178:
6179: );
6180: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6181:
6182: @communityforma=(
6183: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6184: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6185: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 6186: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6187: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6188: );
6189: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6190:
1.330 tempelho 6191: my %orderhash = (
1.484.2.36 raeburn 6192: 'aa' => ['Upload',$fileuploadform],
6193: 'bb' => ['Import',$importpubform],
6194: 'cc' => ['Grading',$gradingform],
1.484.2.85.2. (raeburn 6195:): 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 6196: );
1.484.2.19 raeburn 6197: unless ($container eq 'page') {
1.434 raeburn 6198: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6199: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 6200: }
6201:
1.341 ehlerst 6202: $hadchanges=0;
1.484 raeburn 6203: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6204: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6205: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.85.2. (raeburn 6206:): \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 6207: undef($navmap);
1.443 www 6208: if ($error) {
6209: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6210: }
6211: if ($hadchanges) {
1.484.2.73 raeburn 6212: unless (&is_hash_old()) {
6213: &mark_hash_old();
6214: }
1.443 www 6215: }
1.341 ehlerst 6216:
1.443 www 6217: &changewarning($r,'');
6218: }
1.458 raeburn 6219: }
1.442 www 6220:
1.443 www 6221: # Supplemental documents start here
6222:
1.329 droeschl 6223: my $folder=$env{'form.folder'};
1.443 www 6224: unless ($supplementalflag) {
1.329 droeschl 6225: $folder='supplemental';
6226: }
6227: if ($folder =~ /^supplemental$/ &&
6228: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6229: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6230: } elsif ($allowed) {
1.356 tempelho 6231: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6232: }
1.484.2.17 raeburn 6233: $pathitem = '<input type="hidden" name="folderpath" value="'.
6234: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6235: if ($allowed) {
6236: my $folderseq=
1.484.2.15 raeburn 6237: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6238:
6239: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6240: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6241: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6242: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6243: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6244: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6245: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6246: $fileupload
6247: <br />
6248: <br />
6249: <span class="LC_nobreak">
6250: $checkbox
6251: </span>
6252: <br /><br />
6253: $lt{'comment'}:<br />
1.383 tempelho 6254: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6255: <br />
1.484.2.19 raeburn 6256: $pathitem
1.329 droeschl 6257: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6258: <input type='submit' value="$lt{'upld'}" />
6259: </form>
1.484.2.19 raeburn 6260: SUPDOCFORM
1.329 droeschl 6261:
6262: my $supnewfolderform=(<<SNFFORM);
6263: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6264: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6265: $pathitem
1.329 droeschl 6266: <input type="hidden" name="importdetail" value="" />
1.423 onken 6267: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6268: $help{'Adding_Folders'}
1.329 droeschl 6269: </form>
6270: SNFFORM
1.383 tempelho 6271:
1.484.2.19 raeburn 6272: my $supextform =
6273: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6274: $help{'Adding_External_Resource'},
6275: undef,undef,$disabled);
1.484.2.85.2. (raeburn 6276:): my $supexttoolform =
6277:): &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6278:): $help{'Adding_External_Tool'},
6279:): undef,undef,'tool',$coursedom,
6280:): $coursenum,\%ltitools,$disabled);
1.329 droeschl 6281:
6282: my $supnewsylform=(<<SNSFORM);
6283: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6284: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6285: $pathitem
1.329 droeschl 6286: <input type="hidden" name="importdetail"
6287: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6288: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6289: $help{'Syllabus'}
6290: </form>
6291: SNSFORM
6292:
6293: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6294: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6295: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6296: $pathitem
1.329 droeschl 6297: <input type="hidden" name="importdetail"
6298: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6299: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6300: $help{'My Personal Information Page'}
1.329 droeschl 6301: </form>
6302: SNAMFORM
6303:
1.484.2.27 raeburn 6304: my $supwebpage;
6305: if ($folder =~ /^supplemental_?(\d*)$/) {
6306: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6307: if ($1) {
6308: $supwebpage .= $1;
6309: } else {
6310: $supwebpage .= 'default';
6311: }
6312: $supwebpage .= '/new.html';
6313: }
6314: my $supwebpageform =(<<SWEBFORM);
6315: <form action="/adm/coursedocs" method="post" name="supwebpage">
6316: <input type="hidden" name="active" value="cc" />
6317: $pathitem
6318: <input type="hidden" name="importdetail" value="$supwebpage" />
6319: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6320: $help{'Web_Page'}
1.484.2.27 raeburn 6321: </form>
6322: SWEBFORM
6323:
1.333 muellerd 6324:
1.383 tempelho 6325: my @specialdocs = (
1.484.2.67 raeburn 6326: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6327: =>$supnewsylform},
1.484.2.67 raeburn 6328: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6329: =>$supnewaboutmeform},
1.484.2.27 raeburn 6330: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6331:
1.383 tempelho 6332: );
1.417 droeschl 6333: my @supimportdoc = (
1.484.2.19 raeburn 6334: {'<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 6335:): =>$supextform});
6336:): if (keys(%ltitools)) {
6337:): push(@supimportdoc,
6338:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6339:): =>$supexttoolform});
6340:): }
6341:): push(@supimportdoc,
1.484.2.12 raeburn 6342: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6343: =>$supupdocform},
1.484.2.85.2. (raeburn 6344:): );
1.484.2.19 raeburn 6345:
1.484.2.12 raeburn 6346: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6347: my %suporderhash = (
1.390 tempelho 6348: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6349: 'ee' => ['Upload',$supupdocform],
6350: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6351: );
1.443 www 6352: if ($supplementalflag) {
1.458 raeburn 6353: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6354: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.85.2. (raeburn 6355:): \%ltitools,$canedit,$hostname);
1.443 www 6356: if ($error) {
6357: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6358: } else {
6359: if ($suppchanges) {
6360: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6361: my @ids=&Apache::lonnet::current_machine_ids();
6362: foreach my $server (keys(%servers)) {
6363: next if (grep(/^\Q$server\E$/,@ids));
6364: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6365: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6366: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6367: }
6368: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6369: undef($suppchanges);
6370: }
1.443 www 6371: }
1.393 raeburn 6372: }
1.443 www 6373: } elsif ($supplementalflag) {
1.458 raeburn 6374: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6375: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6376: if ($error) {
6377: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6378: }
1.393 raeburn 6379: }
1.389 tempelho 6380:
1.484.2.19 raeburn 6381: if ($needs_end) {
6382: $r->print(&endContentScreen());
6383: }
1.383 tempelho 6384:
1.329 droeschl 6385: if ($allowed) {
6386: $r->print('
6387: <form method="post" name="extimport" action="/adm/coursedocs">
6388: <input type="hidden" name="title" />
6389: <input type="hidden" name="url" />
6390: <input type="hidden" name="useform" />
6391: <input type="hidden" name="residx" />
6392: </form>');
6393: }
1.484 raeburn 6394: } elsif ($showdoc) {
1.329 droeschl 6395: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6396: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6397: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6398: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6399: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6400: }
6401: }
6402: $r->print(&Apache::loncommon::end_page());
6403: return OK;
1.364 bisitz 6404: }
1.329 droeschl 6405:
1.440 raeburn 6406: sub embedded_form_elems {
6407: my ($phase,$primaryurl,$newidx) = @_;
6408: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6409: $newidx =~s /\D+//g;
1.440 raeburn 6410: return <<STATE;
6411: <input type="hidden" name="folderpath" value="$folderpath" />
6412: <input type="hidden" name="cmd" value="upload_embedded" />
6413: <input type="hidden" name="newidx" value="$newidx" />
6414: <input type="hidden" name="phase" value="$phase" />
6415: <input type="hidden" name="primaryurl" value="$primaryurl" />
6416: STATE
6417: }
6418:
6419: sub embedded_destination {
6420: my $folder=$env{'form.folder'};
6421: my $destination = 'docs/';
6422: if ($folder =~ /^supplemental/) {
6423: $destination = 'supplemental/';
6424: }
6425: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6426: $destination .= 'default/';
6427: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6428: $destination .= $2.'/';
6429: }
1.484.2.78 raeburn 6430: my $newidx = $env{'form.newidx'};
6431: $newidx =~s /\D+//g;
6432: if ($newidx) {
6433: $destination .= $newidx;
6434: }
1.440 raeburn 6435: my $dir_root = '/userfiles';
6436: return ($destination,$dir_root);
6437: }
6438:
6439: sub return_to_editor {
6440: my $actionurl = '/adm/coursedocs';
6441: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6442: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6443: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6444: '</a></p>';
6445: }
6446:
1.476 raeburn 6447: sub decompression_info {
6448: my ($destination,$dir_root) = &embedded_destination();
6449: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6450: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6451: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6452: my $container='sequence';
1.480 raeburn 6453: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6454: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6455: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6456: $container='page';
6457: }
1.480 raeburn 6458: unshift(@hiddens,$pathitem);
6459: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6460: if ($item eq 'newidx') {
6461: next if ($env{'form.'.$item} =~ /\D/);
6462: }
1.480 raeburn 6463: if ($env{'form.'.$item}) {
6464: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6465: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6466: }
1.477 raeburn 6467: }
1.476 raeburn 6468: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6469: $hiddenelem);
6470: }
6471:
6472: sub decompression_phase_one {
6473: my ($dir,$file,$warning,$error,$output);
6474: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6475: &decompression_info();
1.484.2.7 raeburn 6476: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6477: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6478: } else {
6479: my $file = $1;
1.481 raeburn 6480: $output =
6481: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6482: $destination,$dir_root,
6483: $hiddenelem);
6484: if ($env{'form.autoextract_camtasia'}) {
6485: $output .= &remove_archive($docudom,$docuname,$container);
6486: }
1.476 raeburn 6487: }
6488: if ($error) {
6489: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6490: $error.'</p>'."\n";
6491: }
6492: if ($warning) {
6493: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6494: }
6495: return $output;
6496: }
6497:
6498: sub decompression_phase_two {
6499: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6500: &decompression_info();
1.481 raeburn 6501: my $output;
1.480 raeburn 6502: if ($env{'form.archivedelete'}) {
1.481 raeburn 6503: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6504: }
6505: $output .=
1.481 raeburn 6506: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6507: $destination,$dir_root,$hiddenelem);
6508: return $output;
6509: }
6510:
1.480 raeburn 6511: sub remove_archive {
6512: my ($docudom,$docuname,$container) = @_;
6513: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6514: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6515: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6516: if ($fatal) {
6517: if ($container eq 'page') {
6518: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6519: } else {
6520: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6521: }
1.484.2.54 raeburn 6522: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6523: } else {
6524: my $currcmd = $env{'form.cmd'};
6525: my $position = $env{'form.position'};
1.484.2.54 raeburn 6526: my $archiveidx = $position;
6527: if ($position > 0) {
6528: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6529: $archiveidx = $position-1;
6530: }
6531: $env{'form.cmd'} = 'remove_'.$archiveidx;
6532: my ($title,$url,@rrest) =
6533: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6534: if ($url eq $env{'form.archiveurl'}) {
6535: if (&handle_edit_cmd($docuname,$docudom)) {
6536: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6537: if ($fatal) {
6538: if ($container eq 'page') {
6539: $delwarning = &mt('An error occurred updating the contents of the current page.');
6540: } else {
6541: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6542: }
1.480 raeburn 6543: } else {
1.484.2.54 raeburn 6544: $delresult = &mt('Archive file removed.');
1.480 raeburn 6545: }
6546: }
1.484.2.54 raeburn 6547: } else {
6548: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6549: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6550: }
6551: }
6552: $env{'form.cmd'} = $currcmd;
6553: }
6554: if ($delwarning) {
6555: $output = '<p class="LC_warning">'.
6556: $delwarning.
6557: '</p>';
6558: }
6559: if ($delresult) {
6560: $output .= '<p class="LC_info">'.
6561: $delresult.
6562: '</p>';
6563: }
1.481 raeburn 6564: return $output;
1.480 raeburn 6565: }
6566:
1.484 raeburn 6567: sub generate_admin_menu {
1.484.2.67 raeburn 6568: my ($crstype,$canedit) = @_;
1.484 raeburn 6569: my $lc_crstype = lc($crstype);
6570: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6571: my %lt= ( # do not translate here
1.484 raeburn 6572: 'vc' => 'Verify Content',
6573: 'cv' => 'Check/Set Resource Versions',
6574: 'ls' => 'List Resource Identifiers',
1.484.2.85.2. (raeburn 6575:): 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 6576: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6577: 'dcd' => "Copy $crstype Content to Authoring Space",
6578: );
1.484 raeburn 6579: my ($candump,$dumpurl);
6580: if ($home + $other > 0) {
6581: $candump = 'F';
6582: if ($home) {
6583: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6584: } else {
6585: my @hosts;
6586: foreach my $aurole (keys(%outhash)) {
6587: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6588: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6589: }
1.484 raeburn 6590: }
6591: if (@hosts == 1) {
6592: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6593: '&role='.
6594: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6595: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6596: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6597: } else {
6598: $dumpurl = "javascript:choose_switchserver_window()";
6599: }
6600: }
6601: }
6602: my @menu=
6603: ({ categorytitle=>'Administration',
6604: items =>[
6605: { linktext => $lt{'vc'},
6606: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6607: permission => 'F',
1.484.2.44 raeburn 6608: help => 'Docs_Verify_Content',
1.484 raeburn 6609: icon => 'verify.png',
6610: linktitle => 'Verify contents can be retrieved/rendered',
6611: },
6612: { linktext => $lt{'cv'},
6613: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6614: permission => 'F',
1.484.2.44 raeburn 6615: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6616: icon => 'resversion.png',
6617: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6618: },
6619: { linktext => $lt{'ls'},
6620: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6621: permission => 'F',
6622: #help => '',
6623: icon => 'symbs.png',
6624: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6625: },
1.484.2.85.2. (raeburn 6626:): { linktext => $lt{'ct'},
6627:): url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
6628:): permission => 'F',
6629:): help => 'Docs_Short_URLs',
6630:): icon => 'shorturls.png',
6631:): linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
6632:): },
1.484 raeburn 6633: ]
1.484.2.67 raeburn 6634: });
6635: if ($canedit) {
6636: push(@menu,
1.484 raeburn 6637: { categorytitle=>'Export',
6638: items =>[
6639: { linktext => $lt{'imse'},
6640: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6641: permission => 'F',
6642: help => 'Docs_Export_Course_Docs',
6643: icon => 'imsexport.png',
6644: linktitle => $lt{'imse'},
6645: },
6646: { linktext => $lt{'dcd'},
6647: url => $dumpurl,
6648: permission => $candump,
1.484.2.44 raeburn 6649: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6650: icon => 'dump.png',
6651: linktitle => $lt{'dcd'},
6652: },
6653: ]
6654: });
1.484.2.67 raeburn 6655: }
1.484 raeburn 6656: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6657: '<input type="hidden" id="dummy" />'."\n".
6658: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6659: '</form>';
1.329 droeschl 6660: }
6661:
6662: sub generate_edit_table {
1.484.2.30 raeburn 6663: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6664: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6665: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6666: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6667: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6668: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6669: $activetab = $env{'form.active'};
6670: }
1.484.2.67 raeburn 6671: unless ($canedit) {
6672: $disabled = ' disabled="disabled"';
6673: }
1.472 raeburn 6674: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6675: my $backtext = &mt('Exit Editor');
1.458 raeburn 6676: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6677: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6678: '<li class="goback">'.
1.484.2.32 raeburn 6679: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6680: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6681: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6682: '<li>'.
6683: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6684: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6685: if ($env{'form.docslog'}) {
6686: $form .= '<li class="active">';
6687: } else {
6688: $form .= '<li>';
6689: }
6690: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6691: &mt('History').'</a></li>'."\n";
6692: if ($env{'form.docslog'}) {
6693: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6694: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6695: }
1.458 raeburn 6696: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6697: if($name ne '00'){
1.371 tempelho 6698: if($activetab eq '' || $activetab ne $name){
6699: $active = '';
6700: }elsif($activetab eq $name){
6701: $active = 'class="active"';
6702: }
1.458 raeburn 6703: $form .= '<li style="float:right" '.$active
1.484 raeburn 6704: .' 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 6705: } else {
1.484.2.43 raeburn 6706: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6707:
6708: }
1.329 droeschl 6709: }
1.484 raeburn 6710: $form .= '</ul>'."\n";
6711: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6712:
6713: if ($to_show ne '') {
1.484.2.30 raeburn 6714: my $saveform;
6715: if ($need_save) {
6716: my $button = &mt('Make changes');
6717: my $path;
6718: if ($env{'form.folderpath'}) {
6719: $path =
6720: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6721: }
6722: $saveform = <<"END";
6723: <div id="multisave" style="display:none; clear:both;" >
6724: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6725: <input type="hidden" name="folderpath" value="$path" />
6726: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6727: <input type="hidden" name="allhiddenresource" value="" />
6728: <input type="hidden" name="allencrypturl" value="" />
6729: <input type="hidden" name="allrandompick" value="" />
6730: <input type="hidden" name="allrandomorder" value="" />
6731: <input type="hidden" name="changeparms" value="" />
6732: <input type="hidden" name="multiremove" value="" />
6733: <input type="hidden" name="multicut" value="" />
6734: <input type="hidden" name="multicopy" value="" />
6735: <input type="hidden" name="multichange" value="" />
6736: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6737: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6738: </form>
6739: </div>
6740: END
6741: }
6742: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6743: }
1.363 ehlerst 6744: foreach my $field (keys(%orderhash)){
1.390 tempelho 6745: if($field ne '00'){
1.422 onken 6746: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6747: $active = 'style="display: none;float:left"';
1.422 onken 6748: }elsif($activetab eq $field){
1.458 raeburn 6749: $active = 'style="display:block;float:left"';
1.422 onken 6750: }
6751: $form .= '<div id="'.$field.$tid.'"'
6752: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6753: .'</div>'."\n";
1.363 ehlerst 6754: }
6755: }
1.484 raeburn 6756: unless ($env{'form.docslog'}) {
6757: $form .= '</div></div>'."\n";
6758: }
1.329 droeschl 6759: return $form;
6760: }
6761:
6762: sub editing_js {
1.484.2.85.2. (raeburn 6763:): my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.80 raeburn 6764: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6765: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6766: p_mnf => 'Name of New Folder',
6767: t_mnf => 'New Folder',
6768: p_mnp => 'Name of New Page',
6769: t_mnp => 'New Page',
1.451 www 6770: p_mxu => 'Title for the External Score',
1.349 biermanm 6771: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6772: p_msb => 'Title for the Problem',
6773: p_mdb => 'Title for the Drop Box',
1.336 schafran 6774: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6775: p_mwp => 'Title for Web Page',
1.348 weissno 6776: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6777: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6778: p_mab_alrt1 => 'Not a valid user:domain',
6779: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6780: p_chn => 'New Title',
6781: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6782: p_rmr2a => 'Remove',
6783: p_rmr2b => '?',
6784: p_rmr3a => 'Remove those',
6785: p_rmr3b => 'items?',
6786: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6787: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6788: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6789: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6790: p_ctr2a => 'Cut',
6791: p_ctr2b => '?',
6792: p_ctr3a => 'Cut those',
6793: p_ctr3b => 'items?',
1.478 raeburn 6794: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6795: imsfile => 'You must choose an IMS package for import',
6796: imscms => 'You must select which Course Management System was the source of the IMS package',
6797: invurl => 'Invalid URL',
6798: titbl => 'Title is blank',
1.484.2.30 raeburn 6799: more => '(More ...)',
6800: less => '(Less ...)',
6801: noor => 'No actions selected or changes to settings specified.',
6802: noch => 'No changes to settings specified.',
6803: noac => 'No actions selected.',
1.484.2.67 raeburn 6804: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6805: );
6806:
1.484.2.61 raeburn 6807: &js_escape(\%js_lt);
1.433 raeburn 6808: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6809: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6810: my $main_container_page;
1.484.2.19 raeburn 6811: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6812: $main_container_page = 1;
1.434 raeburn 6813: }
1.484.2.67 raeburn 6814: my $backtourl;
6815: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6816: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6817:
1.484.2.21 raeburn 6818: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6819: my $caller = $1;
6820: if ($caller =~ /^supplemental/) {
6821: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6822: } else {
6823: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6824: $res = &Apache::lonnet::clutter($res);
6825: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6826: my ($url,$anchor);
6827: if ($res =~ /^([^#]+)#([^#]+)$/) {
6828: $url = $1;
6829: $anchor = $2;
6830: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6831: $caller = $1.&escape('#').$anchor;
6832: }
1.484.2.67 raeburn 6833: } else {
6834: $url = $res;
1.484.2.66 raeburn 6835: }
1.484.2.83 raeburn 6836: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6837: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6838: $backtourl .= '?navmap=1';
6839: } else {
6840: $backtourl .= '?symb='.
6841: &HTML::Entities::encode($caller,'<>&"');
6842: }
1.484.2.80 raeburn 6843: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6844: if (($ENV{'SERVER_PORT'} == 443) &&
6845: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6846: unless (&Apache::lonnet::uses_sts()) {
6847: if ($hostname ne '') {
6848: $backtourl = 'http://'.$hostname.$backtourl;
6849: }
6850: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6851: }
6852: }
6853: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6854: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6855: unless (&Apache::lonnet::uses_sts()) {
6856: if ($hostname ne '') {
6857: $backtourl = 'http://'.$hostname.$backtourl;
6858: }
6859: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6860: }
6861: }
6862: }
1.484.2.66 raeburn 6863: if ($anchor ne '') {
6864: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6865: }
1.484.2.57 raeburn 6866: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6867: } else {
6868: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6869: }
6870: }
6871: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6872: $backtourl = '/adm/menu';
6873: } elsif ($supplementalflag) {
1.472 raeburn 6874: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6875: } else {
6876: $backtourl = '/adm/navmaps';
1.472 raeburn 6877: }
6878:
1.484.2.19 raeburn 6879: my $fieldsets = "'ext','doc'";
1.484.2.85.2. (raeburn 6880:): if ($posslti) {
6881:): $fieldsets .= ",'tool'";
6882:): }
1.484.2.19 raeburn 6883: unless ($main_container_page) {
6884: $fieldsets .=",'ims'";
6885: }
1.484.2.12 raeburn 6886: if ($supplementalflag) {
6887: $fieldsets = "'suppext','suppdoc'";
1.484.2.85.2. (raeburn 6888:): if ($posslti) {
6889:): $fieldsets .= ",'supptool'";
6890:): }
1.484.2.12 raeburn 6891: }
6892:
1.484.2.67 raeburn 6893: my $jsmakefunctions;
6894: if ($canedit) {
6895: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6896: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6897: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6898: if (foldername) {
6899: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6900: targetform.submit();
6901: }
6902: }
6903:
6904: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6905: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6906: if (pagename) {
6907: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6908: targetform.submit();
6909: }
6910: }
6911:
6912: function makeexamupload() {
1.484.2.61 raeburn 6913: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6914: if (title) {
1.329 droeschl 6915: this.document.forms.newexamupload.importdetail.value=
6916: escape(title)+'=/res/lib/templates/examupload.problem';
6917: this.document.forms.newexamupload.submit();
6918: }
6919: }
6920:
6921: function makesmppage() {
1.484.2.61 raeburn 6922: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6923: if (title) {
1.329 droeschl 6924: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6925: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6926: this.document.forms.newsmppg.submit();
6927: }
6928: }
6929:
1.484.2.27 raeburn 6930: function makewebpage(type) {
1.484.2.61 raeburn 6931: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6932: var formname;
6933: if (type == 'supp') {
6934: formname = this.document.forms.supwebpage;
6935: } else {
6936: formname = this.document.forms.newwebpage;
6937: }
6938: if (title) {
6939: var webpage = formname.importdetail.value;
6940: formname.importdetail.value = escape(title)+'='+webpage;
6941: formname.submit();
6942: }
6943: }
6944:
1.329 droeschl 6945: function makesmpproblem() {
1.484.2.61 raeburn 6946: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6947: if (title) {
1.329 droeschl 6948: this.document.forms.newsmpproblem.importdetail.value=
6949: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6950: this.document.forms.newsmpproblem.submit();
6951: }
6952: }
6953:
6954: function makedropbox() {
1.484.2.61 raeburn 6955: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6956: if (title) {
1.329 droeschl 6957: this.document.forms.newdropbox.importdetail.value=
6958: escape(title)+'=/res/lib/templates/DropBox.problem';
6959: this.document.forms.newdropbox.submit();
6960: }
6961: }
6962:
6963: function makebulboard() {
1.484.2.61 raeburn 6964: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6965: if (title) {
6966: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6967: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6968: this.document.forms.newbul.submit();
6969: }
6970: }
6971:
6972: function makeabout() {
1.484.2.61 raeburn 6973: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6974: if (user) {
6975: var comp=new Array();
6976: comp=user.split(':');
6977: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6978: if ((comp[0]) && (comp[1])) {
6979: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6980: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6981: this.document.forms.newaboutsomeone.submit();
6982: } else {
6983: alert("$js_lt{'p_mab_alrt1'}");
6984: }
6985: } else {
6986: alert("$js_lt{'p_mab_alrt2'}");
6987: }
6988: }
1.335 ehlerst 6989: }
1.484.2.67 raeburn 6990:
6991: function makenew(targetform) {
6992: targetform.submit();
1.335 ehlerst 6993: }
1.484.2.67 raeburn 6994:
6995: function changename(folderpath,index,oldtitle) {
6996: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6997: if (title) {
6998: this.document.forms.renameform.markcopy.value='';
6999: this.document.forms.renameform.title.value=title;
7000: this.document.forms.renameform.cmd.value='rename_'+index;
7001: this.document.forms.renameform.folderpath.value=folderpath;
7002: this.document.forms.renameform.submit();
7003: }
1.329 droeschl 7004: }
7005:
1.484.2.67 raeburn 7006: ENDNEWSCRIPT
7007: } else {
7008: $jsmakefunctions = <<ENDNEWSCRIPT;
7009:
7010: function makenewfolder() {
7011: alert("$js_lt{'edri'}");
7012: }
7013:
7014: function makenewpage() {
7015: alert("$js_lt{'edri'}");
7016: }
7017:
7018: function makeexamupload() {
7019: alert("$js_lt{'edri'}");
7020: }
7021:
7022: function makesmppage() {
7023: alert("$js_lt{'edri'}");
7024: }
7025:
7026: function makewebpage(type) {
7027: alert("$js_lt{'edri'}");
7028: }
7029:
7030: function makesmpproblem() {
7031: alert("$js_lt{'edri'}");
7032: }
7033:
7034: function makedropbox() {
7035: alert("$js_lt{'edri'}");
7036: }
7037:
7038: function makebulboard() {
7039: alert("$js_lt{'edri'}");
7040: }
7041:
7042: function makeabout() {
7043: alert("$js_lt{'edri'}");
7044: }
7045:
7046: function changename() {
7047: alert("$js_lt{'edri'}");
7048: }
7049:
7050: function makenew() {
7051: alert("$js_lt{'edri'}");
7052: }
7053:
7054: function groupimport() {
7055: alert("$js_lt{'edri'}");
7056: }
7057:
7058: function groupsearch() {
7059: alert("$js_lt{'edri'}");
7060: }
7061:
7062: function groupopen(url,recover) {
7063: var options="scrollbars=1,resizable=1,menubar=0";
7064: idxflag=1;
7065: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7066: idx.focus();
7067: }
7068:
7069: ENDNEWSCRIPT
7070:
7071: }
7072: return <<ENDSCRIPT;
7073:
7074: $jsmakefunctions
7075:
1.484.2.13 raeburn 7076: function toggleUpload(caller) {
7077: var blocks = Array($fieldsets);
7078: for (var i=0; i<blocks.length; i++) {
7079: var disp = 'none';
7080: if (caller == blocks[i]) {
7081: var curr = document.getElementById('upload'+caller+'form').style.display;
7082: if (curr == 'none') {
7083: disp='block';
7084: }
7085: }
7086: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.484.2.85.2. (raeburn 7087:): if ((caller == 'tool') || (caller == 'supptool')) {
7088:): if (disp == 'block') {
7089:): if (document.getElementById('LC_exttoolid')) {
7090:): var toolselector = document.getElementById('LC_exttoolid');
7091:): var suppflag = 0;
7092:): if (caller == 'supptool') {
7093:): suppflag = 1;
7094:): }
7095:): currForm = document.getElementById('new'+caller);
7096:): updateExttool(toolselector,currForm,suppflag);
7097:): }
7098:): }
7099:): }
1.484.2.13 raeburn 7100: }
7101: resize_scrollbox('contentscroll','1','1');
7102: return;
7103: }
7104:
1.484.2.19 raeburn 7105: function toggleMap(caller) {
1.484.2.13 raeburn 7106: var disp = 'none';
1.484.2.19 raeburn 7107: if (document.getElementById('importmapform')) {
7108: if (caller == 'map') {
7109: var curr = document.getElementById('importmapform').style.display;
7110: if (curr == 'none') {
7111: disp='block';
7112: }
1.484.2.12 raeburn 7113: }
1.484.2.19 raeburn 7114: document.getElementById('importmapform').style.display=disp;
7115: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 7116: }
1.484.2.19 raeburn 7117: return;
1.329 droeschl 7118: }
7119:
1.484.2.12 raeburn 7120: function makeims(imsform) {
7121: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 7122: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 7123: return;
7124: }
7125: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 7126: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 7127: return;
7128: }
7129: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7130: imsform.submit();
7131: }
7132:
1.478 raeburn 7133: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 7134: var pickitem;
7135: var picknumitem;
7136: var picknumtext;
7137: if (index == 'all') {
7138: pickitem = document.getElementById('randompickall');
7139: picknumitem = document.getElementById('rpicknumall');
7140: picknumtext = document.getElementById('rpicktextall');
7141: } else {
7142: pickitem = document.getElementById('randompick_'+index);
7143: picknumitem = document.getElementById('rpicknum_'+index);
7144: picknumtext = document.getElementById('randompicknum_'+index);
7145: }
1.478 raeburn 7146: if (pickitem.checked) {
1.484.2.61 raeburn 7147: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7148: if (picknum == '' || picknum == null) {
7149: if (caller == 'check') {
7150: pickitem.checked=false;
1.484.2.29 raeburn 7151: if (index == 'all') {
7152: picknumtext.innerHTML = '';
7153: if (caller == 'link') {
7154: propagateState(targetform,'rpicknum');
7155: }
7156: } else {
1.484.2.30 raeburn 7157: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7158: }
1.478 raeburn 7159: }
7160: } else {
7161: picknum.toString();
7162: var regexdigit=/^\\d+\$/;
7163: if (regexdigit.test(picknum)) {
7164: picknumitem.value = picknum;
1.484.2.29 raeburn 7165: if (index == 'all') {
1.484.2.30 raeburn 7166: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 7167: if (caller == 'link') {
7168: propagateState(targetform,'rpicknum');
7169: }
7170: } else {
7171: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 7172: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7173: }
1.478 raeburn 7174: } else {
7175: if (caller == 'check') {
1.484.2.29 raeburn 7176: if (index == 'all') {
7177: picknumtext.innerHTML = '';
7178: if (caller == 'link') {
7179: propagateState(targetform,'rpicknum');
7180: }
7181: } else {
7182: pickitem.checked=false;
1.484.2.30 raeburn 7183: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7184: }
1.478 raeburn 7185: }
7186: return;
7187: }
7188: }
7189: } else {
1.484.2.29 raeburn 7190: picknumitem.value = '';
7191: picknumtext.innerHTML = '';
7192: if (index == 'all') {
7193: if (caller == 'link') {
7194: propagateState(targetform,'rpicknum');
7195: }
7196: } else {
1.484.2.30 raeburn 7197: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 7198: }
7199: }
7200: }
7201:
7202: function propagateState(form,param) {
7203: if (document.getElementById(param+'all')) {
7204: var setcheck = 0;
7205: var rpick = 0;
7206: if (param == 'rpicknum') {
7207: if (document.getElementById('randompickall')) {
7208: if (document.getElementById('randompickall').checked) {
7209: if (document.getElementById('rpicknumall')) {
7210: rpick = document.getElementById('rpicknumall').value;
7211: }
7212: }
7213: }
7214: } else {
7215: if (document.getElementById(param+'all').checked) {
7216: setcheck = 1;
7217: }
7218: }
1.484.2.30 raeburn 7219: var allidxlist;
7220: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7221: if (document.getElementById('all'+param+'idx')) {
7222: allidxlist = document.getElementById('all'+param+'idx').value;
7223: }
7224: var actions = new Array ('remove','cut','copy');
7225: for (var i=0; i<actions.length; i++) {
7226: if (actions[i] != param) {
7227: if (document.getElementById(actions[i]+'all')) {
7228: document.getElementById(actions[i]+'all').checked = false;
7229: }
7230: }
7231: }
7232: }
1.484.2.29 raeburn 7233: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 7234: allidxlist = form.allidx.value;
7235: }
7236: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7237: allidxlist = form.allmapidx.value;
7238: }
7239: if ((allidxlist != '') && (allidxlist != null)) {
7240: var allidxs = allidxlist.split(',');
7241: if (allidxs.length > 1) {
7242: for (var i=0; i<allidxs.length; i++) {
7243: if (document.getElementById(param+'_'+allidxs[i])) {
7244: if (param == 'rpicknum') {
7245: if (document.getElementById('randompick_'+allidxs[i])) {
7246: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7247: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7248: if (rpick > 0) {
7249: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7250: } else {
7251: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7252: }
7253: }
7254: }
7255: } else {
1.484.2.29 raeburn 7256: if (setcheck == 1) {
7257: document.getElementById(param+'_'+allidxs[i]).checked = true;
7258: } else {
7259: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7260: if (param == 'randompick') {
7261: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7262: }
1.484.2.29 raeburn 7263: }
7264: }
7265: }
7266: }
1.484.2.30 raeburn 7267: if (setcheck == 1) {
7268: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7269: var actions = new Array('copy','cut','remove');
7270: for (var i=0; i<actions.length; i++) {
7271: var otheractions;
7272: var otheridxs;
7273: if (actions[i] === param) {
7274: continue;
7275: } else {
7276: if (document.getElementById('all'+actions[i]+'idx')) {
7277: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7278: otheridxs = otheractions.split(',');
7279: if (otheridxs.length > 1) {
7280: for (var j=0; j<otheridxs.length; j++) {
7281: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7282: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7283: }
1.484.2.29 raeburn 7284: }
7285: }
7286: }
7287: }
1.484.2.30 raeburn 7288: }
1.484.2.29 raeburn 7289: }
7290: }
7291: }
7292: }
1.478 raeburn 7293: }
1.484.2.29 raeburn 7294: return;
7295: }
7296:
1.484.2.63 raeburn 7297: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7298: var canedit = '$canedit';
7299: if (canedit == '') {
7300: alert("$js_lt{'edri'}");
7301: return;
7302: }
1.484.2.30 raeburn 7303: var dosettings;
7304: var doaction;
7305: var control = document.togglemultsettings;
7306: if (context == 'actions') {
7307: control = document.togglemultactions;
7308: doaction = 1;
7309: } else {
7310: dosettings = 1;
7311: }
7312: if (control) {
7313: if (control.showmultpick.length) {
7314: for (var i=0; i<control.showmultpick.length; i++) {
7315: if (control.showmultpick[i].checked) {
7316: if (control.showmultpick[i].value == 1) {
7317: if (context == 'settings') {
7318: dosettings = 0;
7319: } else {
7320: doaction = 0;
7321: }
7322: }
7323: }
7324: }
7325: }
7326: }
7327: if (context == 'settings') {
7328: if (dosettings == 1) {
7329: targetform.changeparms.value=param;
7330: targetform.submit();
7331: }
7332: }
7333: if (context == 'actions') {
7334: if (doaction == 1) {
7335: targetform.cmd.value=param+'_'+index;
7336: targetform.folderpath.value=folderpath;
7337: targetform.markcopy.value=idx+':'+param;
7338: targetform.copyfolder.value=folder+'.'+container;
7339: if (param == 'remove') {
1.484.2.63 raeburn 7340: var doremove = 0;
7341: if (skip_confirm) {
7342: if (confirm_removal) {
7343: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7344: doremove = 1;
7345: }
7346: } else {
7347: doremove = 1;
7348: }
7349: } else {
7350: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7351: doremove = 1;
7352: }
7353: }
7354: if (doremove) {
1.484.2.30 raeburn 7355: targetform.markcopy.value='';
7356: targetform.copyfolder.value='';
1.484.2.29 raeburn 7357: targetform.submit();
7358: }
7359: }
1.484.2.30 raeburn 7360: if (param == 'cut') {
1.484.2.61 raeburn 7361: 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 7362: targetform.submit();
7363: return;
7364: }
7365: }
7366: if (param == 'copy') {
7367: targetform.submit();
7368: return;
7369: }
7370: targetform.markcopy.value='';
7371: targetform.copyfolder.value='';
7372: targetform.cmd.value='';
7373: targetform.folderpath.value='';
7374: return;
7375: } else {
7376: if (document.getElementById(param+'_'+idx)) {
7377: item = document.getElementById(param+'_'+idx);
7378: if (item.type == 'checkbox') {
7379: if (item.checked) {
7380: item.checked = false;
7381: } else {
7382: item.checked = true;
7383: singleCheck(item,idx,param);
7384: }
7385: }
7386: }
7387: }
7388: }
7389: return;
7390: }
7391:
7392: function singleCheck(caller,idx,action) {
7393: actions = new Array('cut','copy','remove');
7394: if (caller.checked) {
7395: for (var i=0; i<actions.length; i++) {
7396: if (actions[i] != action) {
7397: if (document.getElementById(actions[i]+'_'+idx)) {
7398: if (document.getElementById(actions[i]+'_'+idx).checked) {
7399: document.getElementById(actions[i]+'_'+idx).checked = false;
7400: }
7401: }
7402: }
1.484.2.29 raeburn 7403: }
7404: }
7405: return;
1.478 raeburn 7406: }
7407:
1.334 muellerd 7408: function unselectInactive(nav) {
1.335 ehlerst 7409: currentNav = document.getElementById(nav);
7410: currentLis = currentNav.getElementsByTagName('LI');
7411: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7412: if (currentLis[i].className == 'goback') {
7413: currentLis[i].className = 'goback';
7414: } else {
7415: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7416: currentLis[i].className = 'right';
1.472 raeburn 7417: } else {
1.374 tempelho 7418: currentLis[i].className = 'i';
1.472 raeburn 7419: }
7420: }
1.335 ehlerst 7421: }
1.332 tempelho 7422: }
7423:
1.334 muellerd 7424: function hideAll(current, nav, data) {
1.335 ehlerst 7425: unselectInactive(nav);
1.484.2.43 raeburn 7426: if (current) {
7427: if (current.className == 'right'){
1.374 tempelho 7428: current.className = 'right active'
1.484.2.43 raeburn 7429: } else {
1.374 tempelho 7430: current.className = 'active';
1.484.2.43 raeburn 7431: }
1.374 tempelho 7432: }
1.335 ehlerst 7433: currentData = document.getElementById(data);
7434: currentDivs = currentData.getElementsByTagName('DIV');
7435: for (i = 0; i < currentDivs.length; i++) {
7436: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7437: currentDivs[i].style.display = 'none';
1.330 tempelho 7438: }
7439: }
1.335 ehlerst 7440: }
1.330 tempelho 7441:
1.374 tempelho 7442: function openTabs(pageId) {
7443: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7444: if(tabnav.length > 2 ){
1.389 tempelho 7445: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7446: currentLis = currentNav.getElementsByTagName('LI');
7447: for(i = 0; i< currentLis.length; i++){
7448: if(currentLis[i].className == 'active') {
1.375 tempelho 7449: funcString = currentLis[i].onclick.toString();
7450: tab = funcString.split('"');
1.420 onken 7451: if(tab.length < 2) {
7452: tab = funcString.split("'");
7453: }
1.375 tempelho 7454: currentData = document.getElementById(tab[1]);
7455: currentData.style.display = 'block';
1.374 tempelho 7456: }
7457: }
7458: }
7459: }
7460:
1.334 muellerd 7461: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7462: currstate = current.className;
1.334 muellerd 7463: hideAll(current, nav, data);
1.375 tempelho 7464: openTabs(pageId);
1.334 muellerd 7465: unselectInactive(nav);
1.484.2.43 raeburn 7466: if ((currstate == 'active') || (currstate == 'right active')) {
7467: if (currstate == 'active') {
7468: current.className = '';
7469: } else {
7470: current.className = 'right';
7471: }
7472: activeTab = '';
7473: toggleUpload();
7474: toggleMap();
7475: resize_scrollbox('contentscroll','1','0');
7476: return;
7477: } else {
7478: current.className = 'active';
7479: }
1.330 tempelho 7480: currentData = document.getElementById(pageId);
7481: currentData.style.display = 'block';
1.458 raeburn 7482: activeTab = pageId;
1.484.2.12 raeburn 7483: toggleUpload();
1.484.2.14 raeburn 7484: toggleMap();
1.433 raeburn 7485: if (nav == 'mainnav') {
7486: var storedpath = "$docs_folderpath";
1.434 raeburn 7487: var storedpage = "$main_container_page";
1.433 raeburn 7488: var reg = new RegExp("^supplemental");
7489: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7490: if (storedpage == 1) {
7491: document.simpleedit.folderpath.value = '';
7492: document.uploaddocument.folderpath.value = '';
7493: } else {
7494: if (reg.test(storedpath)) {
7495: document.simpleedit.folderpath.value = '$toplevelmain';
7496: document.uploaddocument.folderpath.value = '$toplevelmain';
7497: document.newext.folderpath.value = '$toplevelmain';
7498: } else {
7499: document.simpleedit.folderpath.value = storedpath;
7500: document.uploaddocument.folderpath.value = storedpath;
7501: document.newext.folderpath.value = storedpath;
7502: }
1.433 raeburn 7503: }
7504: } else {
1.434 raeburn 7505: if (reg.test(storedpath)) {
7506: document.simpleedit.folderpath.value = storedpath;
7507: document.supuploaddocument.folderpath.value = storedpath;
7508: document.supnewext.folderpath.value = storedpath;
7509: } else {
1.433 raeburn 7510: document.simpleedit.folderpath.value = '$toplevelsupp';
7511: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7512: document.supnewext.folderpath.value = '$toplevelsupp';
7513: }
7514: }
7515: }
1.484.2.3 raeburn 7516: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7517: return false;
7518: }
1.329 droeschl 7519:
1.472 raeburn 7520: function toContents(jumpto) {
7521: var newurl = '$backtourl';
1.484.2.21 raeburn 7522: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7523: newurl = newurl+'?postdata='+jumpto;
7524: }
7525: location.href=newurl;
7526: }
7527:
1.484.2.30 raeburn 7528: function togglePick(caller,value) {
7529: var disp = 'none';
7530: if (document.getElementById('multi'+caller)) {
7531: var curr = document.getElementById('multi'+caller).style.display;
7532: if (value == 1) {
7533: disp='block';
7534: }
7535: if (curr == disp) {
7536: return;
7537: }
7538: document.getElementById('multi'+caller).style.display=disp;
7539: if (value == 1) {
1.484.2.61 raeburn 7540: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7541: } else {
7542: document.getElementById('more'+caller).innerHTML = '';
7543: }
7544: if (caller == 'actions') {
7545: setClass(value);
7546: setBoxes(value);
7547: }
7548: }
7549: var showButton = multiSettings();
7550: if (showButton != 1) {
7551: showButton = multiActions();
7552: }
7553: if (document.getElementById('multisave')) {
7554: if (showButton == 1) {
7555: document.getElementById('multisave').style.display='block';
7556: } else {
7557: document.getElementById('multisave').style.display='none';
7558: }
7559: }
7560: resize_scrollbox('contentscroll','1','1');
7561: return;
7562: }
7563:
7564: function toggleCheckUncheck(caller,more) {
7565: if (more == 1) {
1.484.2.61 raeburn 7566: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7567: document.getElementById('allfields'+caller).style.display='block';
7568: } else {
1.484.2.61 raeburn 7569: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7570: document.getElementById('allfields'+caller).style.display='none';
7571: }
7572: resize_scrollbox('contentscroll','1','1');
7573: }
7574:
7575: function multiSettings() {
7576: var inuse = 0;
7577: var settingsform = document.togglemultsettings;
7578: if (settingsform.showmultpick.length > 1) {
7579: for (var i=0; i<settingsform.showmultpick.length; i++) {
7580: if (settingsform.showmultpick[i].checked) {
7581: if (settingsform.showmultpick[i].value == 1) {
7582: inuse = 1;
7583: }
7584: }
7585: }
7586: }
7587: return inuse;
7588: }
7589:
7590: function multiActions() {
7591: var inuse = 0;
7592: var actionsform = document.togglemultactions;
7593: if (actionsform.showmultpick.length > 1) {
7594: for (var i=0; i<actionsform.showmultpick.length; i++) {
7595: if (actionsform.showmultpick[i].checked) {
7596: if (actionsform.showmultpick[i].value == 1) {
7597: inuse = 1;
7598: }
7599: }
7600: }
7601: }
7602: return inuse;
7603: }
7604:
7605: function checkSubmits() {
7606: var numchanges = 0;
7607: var form = document.saveactions;
7608: var doactions = multiActions();
7609: var cutwarnings = 0;
7610: var remwarnings = 0;
1.484.2.63 raeburn 7611: var removalinfo = 0;
1.484.2.30 raeburn 7612: if (doactions == 1) {
7613: var remidxlist = document.cumulativeactions.allremoveidx.value;
7614: if ((remidxlist != '') && (remidxlist != null)) {
7615: var remidxs = remidxlist.split(',');
7616: for (var i=0; i<remidxs.length; i++) {
7617: if (document.getElementById('remove_'+remidxs[i])) {
7618: if (document.getElementById('remove_'+remidxs[i]).checked) {
7619: form.multiremove.value += remidxs[i]+',';
7620: numchanges ++;
7621: if (document.getElementById('skip_remove_'+remidxs[i])) {
7622: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7623: remwarnings ++;
7624: }
7625: }
1.484.2.63 raeburn 7626: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7627: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7628: removalinfo ++;
7629: }
7630: }
1.484.2.30 raeburn 7631: }
7632: }
7633: }
7634: }
7635: var cutidxlist = document.cumulativeactions.allcutidx.value;
7636: if ((cutidxlist != '') && (cutidxlist != null)) {
7637: var cutidxs = cutidxlist.split(',');
7638: for (var i=0; i<cutidxs.length; i++) {
7639: if (document.getElementById('cut_'+cutidxs[i])) {
7640: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7641: form.multicut.value += cutidxs[i]+',';
7642: numchanges ++;
7643: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7644: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7645: cutwarnings ++;
7646: }
7647: }
7648: }
7649: }
7650: }
7651: }
7652: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7653: if ((copyidxlist != '') && (copyidxlist != null)) {
7654: var copyidxs = copyidxlist.split(',');
7655: for (var i=0; i<copyidxs.length; i++) {
7656: if (document.getElementById('copy_'+copyidxs[i])) {
7657: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7658: form.multicopy.value += copyidxs[i]+',';
7659: numchanges ++;
7660: }
7661: }
7662: }
7663: }
7664: if (numchanges > 0) {
7665: form.multichange.value = numchanges;
7666: }
7667: }
7668: var dosettings = multiSettings();
7669: var haschanges = 0;
7670: if (dosettings == 1) {
7671: form.allencrypturl.value = '';
7672: form.allhiddenresource.value = '';
7673: form.changeparms.value = 'all';
7674: var patt=new RegExp(",\$");
7675: var allidxlist = document.cumulativesettings.allidx.value;
7676: if ((allidxlist != '') && (allidxlist != null)) {
7677: var allidxs = allidxlist.split(',');
7678: if (allidxs.length > 1) {
7679: for (var i=0; i<allidxs.length; i++) {
7680: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7681: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7682: form.allhiddenresource.value += allidxs[i]+',';
7683: }
7684: }
7685: if (document.getElementById('encrypturl_'+allidxs[i])) {
7686: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7687: form.allencrypturl.value += allidxs[i]+',';
7688: }
1.484.2.29 raeburn 7689: }
7690: }
1.484.2.30 raeburn 7691: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7692: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7693: }
7694: }
7695: form.allrandompick.value = '';
7696: form.allrandomorder.value = '';
7697: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7698: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7699: var allmapidxs = allmapidxlist.split(',');
7700: for (var i=0; i<allmapidxs.length; i++) {
7701: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7702: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7703: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7704: if ((randompick.checked) && (rpicknum.value != '')) {
7705: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7706: }
7707: if (randorder.checked) {
7708: form.allrandomorder.value += allmapidxs[i]+',';
7709: }
7710: }
7711: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7712: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7713: }
7714: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7715: haschanges = 1;
7716: }
7717: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7718: haschanges = 1;
7719: }
7720: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7721: haschanges = 1;
7722: }
7723: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7724: haschanges = 1;
7725: }
7726: }
7727: if (doactions == 1) {
7728: if (numchanges > 0) {
1.484.2.63 raeburn 7729: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7730: if (remwarnings > 0) {
1.484.2.61 raeburn 7731: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7732: return false;
7733: }
7734: }
1.484.2.63 raeburn 7735: if (removalinfo > 0) {
7736: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7737: return false;
7738: }
7739: }
1.484.2.30 raeburn 7740: if (cutwarnings > 0) {
1.484.2.61 raeburn 7741: 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 7742: return false;
1.484.2.29 raeburn 7743: }
7744: }
7745: }
1.484.2.30 raeburn 7746: form.submit();
7747: return true;
7748: }
7749: }
7750: if (dosettings == 1) {
7751: if (haschanges == 1) {
7752: form.submit();
7753: return true;
1.484.2.29 raeburn 7754: }
7755: }
1.484.2.30 raeburn 7756: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7757: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7758: } else {
7759: if (dosettings == 1) {
1.484.2.61 raeburn 7760: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7761: } else {
1.484.2.61 raeburn 7762: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7763: }
7764: }
7765: return false;
7766: }
7767:
7768: function setClass(value) {
7769: var cutclass = 'LC_docs_cut';
7770: var copyclass = 'LC_docs_copy';
7771: var removeclass = 'LC_docs_remove';
7772: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7773: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7774: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7775: var links = document.getElementsByTagName('a');
7776: for (var i=0; i<links.length; i++) {
7777: var classes = links[i].className;
7778: if (cutreg.test(classes)) {
7779: links[i].className = cutclass;
7780: if (value == 1) {
7781: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7782: }
1.484.2.30 raeburn 7783: } else {
7784: if (copyreg.test(classes)) {
7785: links[i].className = copyclass;
7786: if (value == 1) {
7787: links[i].className += " LC_menubuttons_link";
7788: }
7789: } else {
7790: if (removereg.test(classes)) {
7791: links[i].className = removeclass;
7792: if (value == 1) {
7793: links[i].className += " LC_menubuttons_link";
7794: }
7795: }
1.484.2.29 raeburn 7796: }
7797: }
7798: }
1.484.2.30 raeburn 7799: return;
1.484.2.29 raeburn 7800: }
7801:
1.484.2.30 raeburn 7802: function setBoxes(value) {
7803: var remidxlist = document.cumulativeactions.allremoveidx.value;
7804: if ((remidxlist != '') && (remidxlist != null)) {
7805: var remidxs = remidxlist.split(',');
7806: for (var i=0; i<remidxs.length; i++) {
7807: if (document.getElementById('remove_'+remidxs[i])) {
7808: var item = document.getElementById('remove_'+remidxs[i]);
7809: if (value == 1) {
7810: item.className = 'LC_docs_remove';
7811: } else {
7812: item.className = 'LC_hidden';
7813: }
7814: }
1.484.2.29 raeburn 7815: }
7816: }
1.484.2.30 raeburn 7817: var cutidxlist = document.cumulativeactions.allcutidx.value;
7818: if ((cutidxlist != '') && (cutidxlist != null)) {
7819: var cutidxs = cutidxlist.split(',');
7820: for (var i=0; i<cutidxs.length; i++) {
7821: if (document.getElementById('cut_'+cutidxs[i])) {
7822: var item = document.getElementById('cut_'+cutidxs[i]);
7823: if (value == 1) {
7824: item.className = 'LC_docs_cut';
7825: } else {
7826: item.className = 'LC_hidden';
7827: }
7828: }
7829: }
7830: }
7831: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7832: if ((copyidxlist != '') && (copyidxlist != null)) {
7833: var copyidxs = copyidxlist.split(',');
7834: for (var i=0; i<copyidxs.length; i++) {
7835: if (document.getElementById('copy_'+copyidxs[i])) {
7836: var item = document.getElementById('copy_'+copyidxs[i]);
7837: if (value == 1) {
7838: item.className = 'LC_docs_copy';
7839: } else {
7840: item.className = 'LC_hidden';
7841: }
7842: }
1.484.2.29 raeburn 7843: }
7844: }
7845: return;
7846: }
7847:
1.484.2.67 raeburn 7848: ENDSCRIPT
1.329 droeschl 7849: }
1.457 raeburn 7850:
1.483 raeburn 7851: sub history_tab_js {
7852: return <<"ENDHIST";
7853: function toggleHistoryDisp(choice) {
7854: document.docslogform.docslog.value = choice;
7855: document.docslogform.submit();
7856: return;
7857: }
7858:
7859: ENDHIST
7860: }
7861:
1.484 raeburn 7862: sub inject_data_js {
7863: return <<ENDINJECT;
7864:
7865: function injectData(current, hiddenField, name, value) {
7866: currentElement = document.getElementById(hiddenField);
7867: currentElement.name = name;
7868: currentElement.value = value;
7869: current.submit();
7870: }
7871:
7872: ENDINJECT
7873: }
7874:
7875: sub dump_switchserver_js {
7876: my @hosts = @_;
1.484.2.61 raeburn 7877: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7878: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7879: swit => 'Switch server?',
1.484.2.61 raeburn 7880: );
7881: my %html_js_lt = &Apache::lonlocal::texthash(
7882: swit => 'Switch server?',
1.484.2.43 raeburn 7883: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7884: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7885: chos => 'Choose server',
7886: );
1.484.2.61 raeburn 7887: &js_escape(\%js_lt);
7888: &html_escape(\%html_js_lt);
7889: &js_escape(\%html_js_lt);
1.484 raeburn 7890: my $role = $env{'request.role'};
7891: my $js = <<"ENDSWJS";
7892: <script type="text/javascript">
7893: function write_switchserver() {
7894: var server;
7895: if (document.setserver.posshosts.length > 0) {
7896: for (var i=0; i<document.setserver.posshosts.length; i++) {
7897: if (document.setserver.posshosts[i].checked) {
7898: server = document.setserver.posshosts[i].value;
7899: }
7900: }
7901: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7902: }
7903: window.close();
7904: }
7905: </script>
7906:
7907: ENDSWJS
7908:
7909: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7910: {'only_body' => 1,
7911: 'js_ready' => 1,});
7912: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7913:
7914: my $hostpicker;
7915: my $count = 0;
7916: foreach my $host (sort(@hosts)) {
7917: my $checked;
7918: if ($count == 0) {
7919: $checked = ' checked="checked"';
7920: }
7921: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7922: $host.'"'.$checked.' />'.$host.'</label> ';
7923: $count++;
7924: }
7925:
7926: return <<"ENDSWITCHJS";
7927:
7928: function dump_needs_switchserver(url) {
7929: if (url!='' && url!= null) {
1.484.2.61 raeburn 7930: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7931: go(url);
7932: }
7933: }
7934: return;
7935: }
7936:
7937: function choose_switchserver_window() {
7938: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7939: newWindow.document.open();
7940: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7941: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7942: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7943: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7944: '<form name="setserver" method="post" action="" \\/>\\n'+
7945: '$hostpicker\\n'+
7946: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7947: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7948: 'onclick="write_switchserver();" \\/>\\n'+
7949: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7950: newWindow.document.writeln('$endpage');
7951: newWindow.document.close();
7952: newWindow.focus();
7953: }
7954:
7955: ENDSWITCHJS
7956: }
7957:
7958: sub makedocslogform {
7959: my ($formelems,$docslog) = @_;
7960: return <<"LOGSFORM";
7961: <form action="/adm/coursedocs" method="post" name="docslogform">
7962: <input type="hidden" name="docslog" value="$docslog" />
7963: $formelems
7964: </form>
7965: LOGSFORM
7966: }
7967:
7968: sub makesimpleeditform {
7969: my ($formelems) = @_;
7970: return <<"SIMPFORM";
7971: <form name="simpleedit" method="post" action="/adm/coursedocs">
7972: <input type="hidden" name="importdetail" value="" />
7973: $formelems
7974: </form>
7975: SIMPFORM
7976: }
7977:
1.329 droeschl 7978: 1;
7979: __END__
7980:
7981:
7982: =head1 NAME
7983:
7984: Apache::londocs.pm
7985:
7986: =head1 SYNOPSIS
7987:
7988: This is part of the LearningOnline Network with CAPA project
7989: described at http://www.lon-capa.org.
7990:
7991: =head1 SUBROUTINES
7992:
7993: =over
7994:
7995: =item %help=()
7996:
7997: Available help topics
7998:
7999: =item mapread()
8000:
1.344 bisitz 8001: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8002: @order and @resources, determines status
8003: sets @order - pointer to resources in right order
8004: sets @resources - array with the resources with correct idx
8005:
8006: =item authorhosts()
8007:
8008: Return hash with valid author names
8009:
8010: =item clean()
8011:
8012: =item dumpcourse()
8013:
8014: Actually dump course
8015:
8016: =item group_import()
8017:
8018: Imports the given (name, url) resources into the course
8019: coursenum, coursedom, and folder must precede the list
8020:
8021: =item breadcrumbs()
8022:
8023: =item log_docs()
8024:
8025: =item docs_change_log()
8026:
8027: =item update_paste_buffer()
8028:
8029: =item print_paste_buffer()
8030:
8031: =item do_paste_from_buffer()
8032:
1.484.2.30 raeburn 8033: =item do_buffer_empty()
8034:
8035: =item clear_from_buffer()
8036:
1.484.2.7 raeburn 8037: =item get_newmap_url()
8038:
8039: =item dbcopy()
8040:
8041: =item uniqueness_check()
8042:
8043: =item contained_map_check()
8044:
8045: =item url_paste_fixups()
8046:
8047: =item apply_fixups()
8048:
8049: =item copy_dependencies()
8050:
1.329 droeschl 8051: =item update_parameter()
8052:
8053: =item handle_edit_cmd()
8054:
8055: =item editor()
8056:
8057: =item process_file_upload()
8058:
8059: =item process_secondary_uploads()
8060:
8061: =item is_supplemental_title()
8062:
8063: =item entryline()
8064:
8065: =item tiehash()
8066:
8067: =item untiehash()
8068:
8069: =item checkonthis()
8070:
8071: check on this
8072:
8073: =item verifycontent()
8074:
8075: Verify Content
8076:
1.484.2.78 raeburn 8077: =item devalidateversioncache()
8078:
8079: =item checkversions()
1.329 droeschl 8080:
8081: Check Versions
8082:
8083: =item mark_hash_old()
8084:
8085: =item is_hash_old()
8086:
8087: =item changewarning()
8088:
8089: =item init_breadcrumbs()
8090:
8091: Breadcrumbs for special functions
8092:
1.484 raeburn 8093: =item create_list_elements()
8094:
8095: =item create_form_ul()
8096:
8097: =item startContentScreen()
8098:
8099: =item endContentScreen()
8100:
8101: =item supplemental_base()
8102:
8103: =item embedded_form_elems()
8104:
8105: =item embedded_destination()
8106:
8107: =item return_to_editor()
8108:
8109: =item decompression_info()
8110:
8111: =item decompression_phase_one()
8112:
8113: =item decompression_phase_two()
8114:
8115: =item remove_archive()
8116:
8117: =item generate_admin_menu()
8118:
8119: =item generate_edit_table()
8120:
8121: =item editing_js()
8122:
8123: =item history_tab_js()
8124:
8125: =item inject_data_js()
8126:
8127: =item dump_switchserver_js()
8128:
1.484.2.3 raeburn 8129: =item resize_scrollbox_js()
1.484 raeburn 8130:
8131: =item makedocslogform()
8132:
1.484.2.3 raeburn 8133: =item makesimpleeditform()
8134:
1.329 droeschl 8135: =back
8136:
8137: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>