Annotation of loncom/interface/londocs.pm, revision 1.484.2.92
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.92! raeburn 4: # $Id: londocs.pm,v 1.484.2.91 2021/02/10 12:46:11 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.329 droeschl 46: use HTML::Entities;
1.484.2.7 raeburn 47: use HTML::TokeParser;
1.329 droeschl 48: use GDBM_File;
1.484.2.51 raeburn 49: use File::MMagic;
1.329 droeschl 50: use Apache::lonlocal;
51: use Cwd;
52: use LONCAPA qw(:DEFAULT :match);
53:
54: my $iconpath;
55:
56: my %hash;
57:
58: my $hashtied;
59: my %alreadyseen=();
60:
61: my $hadchanges;
1.484.2.37 raeburn 62: my $suppchanges;
1.329 droeschl 63:
64:
65: my %help=();
66:
67:
68: sub mapread {
69: my ($coursenum,$coursedom,$map)=@_;
70: return
71: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
72: $map);
73: }
74:
75: sub storemap {
1.484.2.7 raeburn 76: my ($coursenum,$coursedom,$map,$contentchg)=@_;
77: my $report;
78: if (($contentchg) && ($map =~ /^default/)) {
79: $report = 1;
80: }
1.329 droeschl 81: my ($outtext,$errtext)=
82: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 83: $map,1,$report);
1.329 droeschl 84: if ($errtext) { return ($errtext,2); }
1.364 bisitz 85:
1.484.2.37 raeburn 86: if ($map =~ /^default/) {
87: $hadchanges=1;
88: } else {
89: $suppchanges=1;
90: }
1.329 droeschl 91: return ($errtext,0);
92: }
93:
94:
95:
96: sub authorhosts {
97: my %outhash=();
98: my $home=0;
99: my $other=0;
100: foreach my $key (keys(%env)) {
101: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
102: my $role=$1;
103: my $realm=$2;
104: my ($start,$end)=split(/\./,$env{$key});
105: if (($start) && ($start>time)) { next; }
106: if (($end) && (time>$end)) { next; }
107: my ($ca,$cd);
108: if ($1 eq 'au') {
109: $ca=$env{'user.name'};
110: $cd=$env{'user.domain'};
111: } else {
112: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
113: }
114: my $allowed=0;
115: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
116: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 117: foreach my $id (@ids) {
118: if ($id eq $myhome) {
119: $allowed=1;
120: last;
121: }
122: }
1.329 droeschl 123: if ($allowed) {
124: $home++;
1.484 raeburn 125: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 126: } else {
1.484 raeburn 127: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 128: $other++;
129: }
130: }
131: }
132: return ($home,$other,%outhash);
133: }
134:
135:
136: sub clean {
137: my ($title)=@_;
138: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 139: return $title;
1.329 droeschl 140: }
141:
1.484.2.67 raeburn 142: sub default_folderpath {
143: my ($coursenum,$coursedom,$navmapref) = @_;
144: return unless ($coursenum && $coursedom && ref($navmapref));
145: # Check if entire course is hidden and/or encrypted
146: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
147: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
148: unless (ref($$navmapref)) {
149: $$navmapref = Apache::lonnavmaps::navmap->new();
150: }
151: if (ref($$navmapref)) {
152: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
153: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
154: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
155: unless (@resources) {
156: $hiddenmap = 1;
157: unless ($env{'request.role.adv'}) {
158: $hiddentop = 1;
159: if ($env{'form.folder'}) {
160: undef($env{'form.folder'});
161: }
162: }
163: }
164: }
165: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
166: $encryptmap = 1;
167: }
168: }
169: unless ($hiddentop) {
170: $folderpath='default&'.&escape(&mt('Main Content')).
171: '::'.$hiddenmap.':'.$encryptmap.'::';
172: }
173: if (wantarray) {
174: return ($folderpath,$hiddentop);
175: } else {
176: return $folderpath;
177: }
178: }
1.329 droeschl 179:
1.484.2.92! raeburn 180: sub validate_folderpath {
! 181: my ($supplementalflag) = @_;
! 182: if ($env{'form.folderpath'} ne '') {
! 183: my @items = split(/\&/,$env{'form.folderpath'});
! 184: my $badpath;
! 185: for (my $i=0; $i<@items; $i++) {
! 186: my $odd = $i%2;
! 187: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
! 188: $badpath = 1;
! 189: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
! 190: $badpath = 1;
! 191: }
! 192: last if ($badpath);
! 193: }
! 194: if ($badpath) {
! 195: delete($env{'form.folderpath'});
! 196: }
! 197: }
! 198: return;
! 199: }
! 200:
! 201: sub validate_suppath {
! 202: if ($env{'form.supppath'} ne '') {
! 203: my @items = split(/\&/,$env{'form.supppath'});
! 204: my $badpath;
! 205: for (my $i=0; $i<@items; $i++) {
! 206: my $odd = $i%2;
! 207: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
! 208: $badpath = 1;
! 209: }
! 210: last if ($badpath);
! 211: }
! 212: if ($badpath) {
! 213: delete($env{'form.supppath'});
! 214: }
! 215: }
! 216: return;
! 217: }
! 218:
1.329 droeschl 219: sub dumpcourse {
220: my ($r) = @_;
1.408 raeburn 221: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 222: my ($starthash,$js);
223: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
224: $js = <<"ENDJS";
225: <script type="text/javascript">
226: // <![CDATA[
227:
228: function hide_searching() {
229: if (document.getElementById('searching')) {
230: document.getElementById('searching').style.display = 'none';
231: }
232: return;
233: }
234:
235: // ]]>
236: </script>
237: ENDJS
238: $starthash = {
239: add_entries => {'onload' => "hide_searching();"},
240: };
241: }
242: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
243: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 244: $r->print(&startContentScreen('tools'));
1.329 droeschl 245: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 246: unless ($home) {
247: $r->print(&endContentScreen());
248: return '';
249: }
1.329 droeschl 250: my $origcrsid=$env{'request.course.id'};
251: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
252: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
253: # Do the dumping
1.484 raeburn 254: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
255: $r->print(&endContentScreen());
256: return '';
257: }
1.484.2.24 raeburn 258: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 259: $r->print('<h3>'.&mt('Copying Files').'</h3>');
260: my $title=$env{'form.authorfolder'};
261: $title=&clean($title);
1.484.2.43 raeburn 262: my ($navmap,$errormsg) =
263: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
264: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
265: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
266: my (%maps,%resources,%titles);
267: if (!ref($navmap)) {
268: $r->print($errormsg.
269: &endContentScreen());
270: return '';
271: } else {
272: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
273: 'dumpdocs',$cdom,$cnum);
274: }
275: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
276: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
277: %newcontent,%has_simpleprobs);
278: foreach my $item (sort {$a <=> $b} (@todump)) {
279: my $name = $env{'form.namefor_'.$item};
280: if ($resources{$item}) {
281: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
282: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
283: $tocopy{$1} = $name;
284: $display{$item} = $1;
285: $lookup{$1} = $item;
286: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
287: $simpleproblems{$item} = {
288: symb => $resources{$item},
289: name => $name,
290: };
291: $display{$item} = 'simpleproblem_'.$name;
292: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
293: $has_simpleprobs{$1}{$id} = $item;
294: }
295: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
296: my $marker = $1;
297: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
298: $simplepages{$item} = {
299: res => $res,
300: title => $titles{$item},
301: db => $db_name,
302: marker => $marker,
303: symb => $resources{$item},
304: name => $name,
305: };
306: $display{$item} = '/'.$res;
307: }
308: } elsif ($maps{$item}) {
309: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
310: $tocopy{$1} = $name;
311: $display{$item} = $1;
312: $lookup{$1} = $item;
313: }
314: } else {
315: next;
316: }
317: }
1.329 droeschl 318: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
319: $crs=~s/\_/\//g;
1.484.2.43 raeburn 320: my $mm = new File::MMagic;
321: my $prefix = "/uploaded/$cdom/$cnum/";
322: %replacehash = %tocopy;
323: foreach my $item (sort(keys(%simpleproblems))) {
324: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
325: $newcontent{$display{$item}} = $content;
326: }
327: my $gateway = Apache::lonhtmlgateway->new('web');
328: foreach my $item (sort(keys(%simplepages))) {
329: if (ref($simplepages{$item}) eq 'HASH') {
330: my $pagetitle = $simplepages{$item}{'title'};
331: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
332: my %contents;
333: foreach my $field (keys(%fields)) {
334: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
335: my $name = $1;
336: my $msg = $fields{$field};
337: if ($name eq 'webreferences') {
338: if ($msg =~ m{^https?://}) {
339: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
340: }
341: } else {
342: $msg = &Encode::decode('utf8',$msg);
343: $msg = $gateway->process_outgoing_html($msg,1);
344: $contents{$name} = $msg;
345: }
346: } elsif ($field eq 'uploaded.photourl') {
347: my $marker = $simplepages{$item}{marker};
348: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
349: my $filepath = $1;
350: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
351: if ($fname ne '') {
352: $fname=~s/\.(\w+)$//;
353: my $ext=$1;
354: $fname = &clean($fname);
355: $fname.='.'.$ext;
356: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
357: $replacehash{$filepath} = $relpath.$fname;
358: $deps{$item}{$filepath} = 1;
359: }
360: }
361: }
362: }
363: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
364: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
365: my $content = '
366: <html>
367: <head>
368: <title>'.$pagetitle.'</title>
369: </head>
370: <body bgcolor="#ffffff">';
371: if ($contents{title}) {
372: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
373: }
374: if ($contents{image}) {
375: $content .= "\n".$contents{image};
376: }
377: if ($contents{content}) {
378: $content .= '
379: <div class="LC_Box">
1.484.2.50 raeburn 380: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 381: $contents{content}.'
382: </div>';
383: }
384: if ($contents{webreferences}) {
385: $content .= '
386: <div class="LC_Box">
1.484.2.50 raeburn 387: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 388: $contents{webreferences}.'
389: </div>';
390: }
391: $content .= '
392: </body>
393: </html>
394: ';
395: $newcontent{'/'.$simplepages{$item}{res}} = $content;
396: }
397: }
398: foreach my $item (keys(%tocopy)) {
399: unless ($item=~/\.(sequence|page)$/) {
400: my $currurlpath = $prefix.$item;
401: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
402: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
403: }
404: }
405: foreach my $num (sort {$a <=> $b} (@todump)) {
406: my $src = $display{$num};
407: next if ($src eq '');
408: my @needcopy = ();
409: if ($replacehash{$src}) {
410: push(@needcopy,$src);
411: if (ref($deps{$num}) eq 'HASH') {
412: foreach my $dep (sort(keys(%{$deps{$num}}))) {
413: if ($replacehash{$dep}) {
414: push(@needcopy,$dep);
415: }
416: }
417: }
418: } elsif ($src =~ /^simpleproblem_/) {
419: push(@needcopy,$src);
420: }
421: next if (@needcopy == 0);
422: my ($result,$depresult);
423: for (my $i=0; $i<@needcopy; $i++) {
424: my $item = $needcopy[$i];
425: my $newfilename;
426: if ($simpleproblems{$num}) {
427: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
428: } else {
429: $newfilename=$title.'/'.$replacehash{$item};
430: }
431: $newfilename=~s/\.(\w+)$//;
432: my $ext=$1;
433: $newfilename=&clean($newfilename);
434: $newfilename.='.'.$ext;
435: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
436: if ($newrelpath ne $replacehash{$item}) {
437: $replacehash{$item} = $newrelpath;
438: }
439: my @dirs=split(/\//,$newfilename);
440: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
441: my $makepath=$path;
442: my $fail;
443: my $origin;
444: for (my $i=0;$i<$#dirs;$i++) {
445: $makepath.='/'.$dirs[$i];
446: unless (-e $makepath) {
447: unless(mkdir($makepath,0755)) {
448: $fail = &mt('Directory creation failed.');
449: }
450: }
451: }
452: if ($i == 0) {
453: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
454: } else {
455: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
456: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
457: &mt('(dependency)').'</span>: ';
458: }
459: if (-e $path.'/'.$newfilename) {
460: $fail = &mt('Destination already exists -- not overwriting.');
461: } else {
462: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
463: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
464: ($item =~ /^simpleproblem_/)) {
465: print $fh $newcontent{$item};
466: } else {
467: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
468: if (-e $fileloc) {
469: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
470: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
471: (ref($has_simpleprobs{$item}) eq 'HASH')) {
472: my %changes = %{$has_simpleprobs{$item}};
473: my $content = &Apache::lonclonecourse::rewritefile(
474: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
475: (%replacehash,$crs => '')
476: );
477: my $updatedcontent = '';
478: my $parser = HTML::TokeParser->new(\$content);
479: $parser->attr_encoded(1);
480: while (my $token = $parser->get_token) {
481: if ($token->[0] eq 'S') {
482: if (($token->[1] eq 'resource') &&
483: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
484: ($changes{$token->[2]->{'id'}})) {
485: my $id = $token->[2]->{'id'};
486: $updatedcontent .= '<'.$token->[1];
487: foreach my $attrib (@{$token->[3]}) {
488: next unless ($attrib =~ /^(src|type|title|id)$/);
489: if ($attrib eq 'src') {
490: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
491: if ($file) {
492: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
493: } else {
494: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
495: }
496: } else {
497: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
498: }
499: }
500: $updatedcontent .= ' />'."\n";
501: } else {
502: $updatedcontent .= $token->[4]."\n";
503: }
504: } else {
505: $updatedcontent .= $token->[2];
506: }
507: }
508: print $fh $updatedcontent;
509: } else {
510: print $fh &Apache::lonclonecourse::rewritefile(
511: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
512: (%replacehash,$crs => '')
513: );
514: }
515: } else {
516: print $fh
517: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
518: }
519: } else {
520: $fail = &mt('Source does not exist.');
521: }
522: }
523: $fh->close();
524: } else {
525: $fail = &mt('Could not write to destination.');
526: }
527: }
528: my $text;
529: if ($fail) {
530: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
531: } else {
532: $text = '<span class="LC_success">'.&mt('ok').'</span>';
533: }
534: if ($i == 0) {
535: $result .= $text;
536: } else {
537: $depresult .= $text.'</li>';
538: }
539: }
540: $r->print($result);
541: if ($depresult) {
542: $r->print('<ul>'.$depresult.'</ul>');
543: }
544: }
1.329 droeschl 545: } else {
1.484.2.43 raeburn 546: my ($navmap,$errormsg) =
547: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
548: if (!ref($navmap)) {
549: $r->print($errormsg);
550: } else {
551: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
552: $r->rflush();
553: my ($preamble,$formname);
554: $formname = 'dumpdoc';
555: unless ($home==1) {
556: $preamble = '<div class="LC_left_float">'.
557: '<fieldset><legend>'.
558: &mt('Select the Authoring Space').
559: '</legend><select name="authorspace">';
560: }
561: my @orderspaces = ();
562: foreach my $key (sort(keys(%outhash))) {
563: if ($key=~/^home_(.+)$/) {
564: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
565: unshift(@orderspaces,$1);
566: } else {
567: push(@orderspaces,$1);
568: }
569: }
570: }
571: if ($home>1) {
572: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
573: }
574: foreach my $user (@orderspaces) {
575: if ($home==1) {
576: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
577: } else {
578: $preamble .= '<option value="'.$user.'">'.$user.' - '.
579: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
580: }
581: }
582: unless ($home==1) {
583: $preamble .= '</select></fieldset></div>'."\n";
584: }
585: my $title=$origcrsdata{'description'};
586: $title=~s/[\/\s]+/\_/gs;
587: $title=&clean($title);
588: $preamble .= '<div class="LC_left_float">'.
589: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
590: '<input type="text" size="50" name="authorfolder" value="'.
591: $title.'" />'.
592: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
593: my %uploadedfiles;
594: &tiehash();
595: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
596: my ($ext)=($file=~/\.(\w+)$/);
597: # FIXME Check supplemental here
598: my $title=$hash{'title_'.$hash{
599: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
600: if (!$title) {
601: $title=$file;
602: } else {
603: $title=~s|/|_|g;
604: }
605: $title=~s/\.(\w+)$//;
606: $title=&clean($title);
607: $title.='.'.$ext;
608: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
609: $uploadedfiles{$file} = $title;
610: }
611: &untiehash();
612: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
613: undef,undef,$preamble,$home,\%uploadedfiles));
614: }
1.329 droeschl 615: }
1.484 raeburn 616: $r->print(&endContentScreen());
1.329 droeschl 617: }
618:
1.484.2.43 raeburn 619: sub recurse_html {
620: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
621: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
622: my (%allfiles,%codebase);
623: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
624: if (keys(%allfiles)) {
625: foreach my $dependency (keys(%allfiles)) {
626: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
627: my ($depurl,$relfile,$newcontainer);
628: if ($dependency =~ m{^/}) {
629: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
630: $relfile = $1;
631: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
632: $newcontainer = $1;
633: next if ($replacehash->{$newcontainer});
634: }
635: $depurl = $dependency;
636: } else {
637: next;
638: }
639: } else {
640: $relfile = $dependency;
641: $depurl = $currurlpath;
642: $depurl =~ s{[^/]+$}{};
643: $depurl .= $dependency;
644: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
645: }
646: next if ($relfile eq '');
647: my $newname = $replacehash->{$container};
648: $newname =~ s{[^/]+$}{};
649: $replacehash->{$newcontainer} = $newname.$relfile;
650: $deps->{$item}{$newcontainer} = 1;
651: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
652: my $depfile = &Apache::lonnet::filelocation('',$depurl);
653: my $type = $mm->checktype_filename($depfile);
654: if ($type eq 'text/html') {
655: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
656: }
657: }
658: }
659: }
660: return;
661: }
662:
1.329 droeschl 663: sub group_import {
664: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
1.484.2.23 raeburn 665: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
666: %removeparam,$importuploaded,$fixuperrors);
667: $allmaps = {};
1.329 droeschl 668: while (@files) {
669: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 670: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 671: && ($caller eq 'londocs')
672: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 673:
1.329 droeschl 674: my $errtext = '';
675: my $fatal = 0;
676: my $newmapstr = '<map>'."\n".
677: '<resource id="1" src="" type="start"></resource>'."\n".
678: '<link from="1" to="2" index="1"></link>'."\n".
679: '<resource id="2" src="" type="finish"></resource>'."\n".
680: '</map>';
681: $env{'form.output'}=$newmapstr;
682: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
683: 'output',$1.$2);
1.484.2.27 raeburn 684: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 685: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
686: $fatal = 2;
687: }
688: if ($fatal) {
689: return ($errtext,$fatal);
690: }
691: }
692: if ($url) {
1.484.2.23 raeburn 693: if (($caller eq 'londocs') &&
694: ($folder =~ /^default/)) {
1.484.2.27 raeburn 695: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 696: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
697: my $cid = $coursedom.'_'.$coursenum;
698: $allmaps =
699: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
700: $chome,$cid);
701: $donechk = 1;
702: }
703: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
704: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
705: \%addedmaps,\%hierarchy,\%titles,$allmaps);
706: $importuploaded = 1;
707: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
708: next if ($allmaps->{$url});
709: }
710: }
1.344 bisitz 711: if (!$residx
1.329 droeschl 712: || defined($LONCAPA::map::zombies[$residx])) {
713: $residx = &LONCAPA::map::getresidx($url,$residx);
714: push(@LONCAPA::map::order, $residx);
715: }
716: my $ext = 'false';
717: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.484.2.27 raeburn 718: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
719: my $filepath = $1;
1.484.2.91 raeburn 720: my $fname;
721: if ($name eq '') {
722: $name = &mt('Web Page');
1.484.2.27 raeburn 723: $fname = 'web';
724: } else {
1.484.2.91 raeburn 725: $fname = $name;
726: $fname=&Apache::lonnet::clean_filename($fname);
727: if ($fname eq '') {
728: $fname = 'web';
729: } elsif (length($fname) > 15) {
730: $fname = substr($fname,0,14);
731: }
1.484.2.27 raeburn 732: }
1.484.2.91 raeburn 733: my $title = &Apache::loncommon::cleanup_html($name);
1.484.2.27 raeburn 734: my $initialtext = &mt('Replace with your own content.');
735: my $newhtml = <<END;
1.484.2.31 raeburn 736: <html>
1.484.2.27 raeburn 737: <head>
1.484.2.91 raeburn 738: <title>$title</title>
1.484.2.27 raeburn 739: </head>
740: <body bgcolor="#ffffff">
741: $initialtext
742: </body>
743: </html>
744: END
745: $env{'form.output'}=$newhtml;
746: my $result =
747: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
748: 'output',
749: "$filepath/$residx/$fname.html");
750: if ($result =~ m{^/uploaded/}) {
751: $url = $result;
752: if ($filepath =~ /^supplemental/) {
753: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
754: $env{'user.domain'}.'___&&&___'.$name;
755: }
756: } else {
757: return (&mt('Failed to save new web page.'),1);
758: }
759: }
1.484.2.91 raeburn 760: $name = &LONCAPA::map::qtunescape($name);
1.484.2.30 raeburn 761: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 762: $LONCAPA::map::resources[$residx] =
1.329 droeschl 763: join(':', ($name, $url, $ext, 'normal', 'res'));
764: }
765: }
1.484.2.23 raeburn 766: if ($importuploaded) {
767: my %import_errors;
768: my %updated = (
769: removefrommap => \%removefrommap,
770: removeparam => \%removeparam,
771: );
1.484.2.26 raeburn 772: my ($result,$msgsarray,$lockerror) =
773: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 774: if (keys(%import_errors) > 0) {
775: $fixuperrors =
776: '<p span class="LC_warning">'."\n".
777: &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".
778: '<ul>'."\n";
779: foreach my $key (sort(keys(%import_errors))) {
780: $fixuperrors .= '<li>'.$key.'</li>'."\n";
781: }
782: $fixuperrors .= '</ul></p>'."\n";
783: }
1.484.2.26 raeburn 784: if (ref($msgsarray) eq 'ARRAY') {
785: if (@{$msgsarray} > 0) {
786: $fixuperrors .= '<p class="LC_info">'.
787: join('<br />',@{$msgsarray}).
788: '</p>';
789: }
790: }
791: if ($lockerror) {
792: $fixuperrors .= '<p class="LC_error">'.
793: $lockerror.
794: '</p>';
795: }
1.484.2.23 raeburn 796: }
797: my ($errtext,$fatal) =
798: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 799: unless ($fatal) {
800: if ($folder =~ /^supplemental/) {
801: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 802: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
803: $folder.'.'.$container);
1.484.2.37 raeburn 804: }
805: }
1.484.2.23 raeburn 806: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 807: }
808:
809: sub log_docs {
1.484.2.8 raeburn 810: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 811: }
812:
813: {
814: my @oldresources=();
815: my @oldorder=();
816: my $parmidx;
817: my %parmaction=();
818: my %parmvalue=();
819: my $changedflag;
820:
821: sub snapshotbefore {
822: @oldresources=@LONCAPA::map::resources;
823: @oldorder=@LONCAPA::map::order;
824: $parmidx=undef;
825: %parmaction=();
826: %parmvalue=();
827: $changedflag=0;
828: }
829:
830: sub remember_parms {
831: my ($idx,$parameter,$action,$value)=@_;
832: $parmidx=$idx;
833: $parmaction{$parameter}=$action;
834: $parmvalue{$parameter}=$value;
835: $changedflag=1;
836: }
837:
838: sub log_differences {
839: my ($plain)=@_;
840: my %storehash=('folder' => $plain,
841: 'currentfolder' => $env{'form.folder'});
842: if ($parmidx) {
843: $storehash{'parameter_res'}=$oldresources[$parmidx];
844: foreach my $parm (keys(%parmaction)) {
845: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
846: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
847: }
848: }
849: my $maxidx=$#oldresources;
850: if ($#LONCAPA::map::resources>$#oldresources) {
851: $maxidx=$#LONCAPA::map::resources;
852: }
853: for (my $idx=0; $idx<=$maxidx; $idx++) {
854: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
855: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
856: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
857: $changedflag=1;
858: }
859: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
860: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
861: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
862: $changedflag=1;
863: }
864: }
865: $storehash{'maxidx'}=$maxidx;
866: if ($changedflag) { &log_docs(\%storehash); }
867: }
868: }
869:
870: sub docs_change_log {
1.484.2.67 raeburn 871: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 872: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 873: my $navmap;
1.483 raeburn 874: my $js = '<script type="text/javascript">'."\n".
875: '// <![CDATA['."\n".
876: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 877: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.80 raeburn 878: $coursedom,$coursenum,$canedit,'',\$navmap)."\n".
1.483 raeburn 879: &history_tab_js()."\n".
1.484 raeburn 880: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 881: '// ]]>'."\n".
882: '</script>'."\n";
1.484 raeburn 883: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
884: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 885: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 886: my %orderhash;
887: my $container='sequence';
888: my $pathitem;
1.484.2.19 raeburn 889: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 890: $container='page';
891: }
1.484.2.19 raeburn 892: my $folderpath=$env{'form.folderpath'};
893: if ($folderpath eq '') {
1.484.2.67 raeburn 894: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 895: }
1.484.2.67 raeburn 896: undef($navmap);
1.484.2.19 raeburn 897: $pathitem = '<input type="hidden" name="folderpath" value="'.
898: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 899: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
900: my $jumpto = $readfile;
901: $jumpto =~ s{^/}{};
902: my $tid = 1;
1.484.2.7 raeburn 903: if ($supplementalflag) {
904: $tid = 2;
905: }
1.484.2.19 raeburn 906: my ($breadcrumbtrail) =
1.484.2.18 raeburn 907: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 908: $r->print($breadcrumbtrail.
909: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
910: $readfile));
1.329 droeschl 911: my %docslog=&Apache::lonnet::dump('nohist_docslog',
912: $env{'course.'.$env{'request.course.id'}.'.domain'},
913: $env{'course.'.$env{'request.course.id'}.'.num'});
914:
915: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
916:
917: my %saveable_parameters = ('show' => 'scalar',);
918: &Apache::loncommon::store_course_settings('docs_log',
919: \%saveable_parameters);
920: &Apache::loncommon::restore_course_settings('docs_log',
921: \%saveable_parameters);
922: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 923: # FIXME: internationalization seems wrong here
1.329 droeschl 924: my %lt=('hiddenresource' => 'Resources hidden',
925: 'encrypturl' => 'URL hidden',
926: 'randompick' => 'Randomly pick',
927: 'randomorder' => 'Randomly ordered',
928: 'set' => 'set to',
929: 'del' => 'deleted');
1.484 raeburn 930: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
931: $pathitem."\n".
932: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
933: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
934: $r->print('<div class="LC_left_float">'.
935: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
936: &makedocslogform($filter,1).
937: '</fieldset></div><br clear="all" />');
1.329 droeschl 938: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
939: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
940: &mt('After').'</th>'.
941: &Apache::loncommon::end_data_table_header_row());
942: my $shown=0;
943: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
944: if ($env{'form.displayfilter'} eq 'currentfolder') {
945: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
946: }
947: my @changes=keys(%{$docslog{$id}{'logentry'}});
948: if ($env{'form.displayfilter'} eq 'containing') {
949: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
950: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
951: foreach my $key (@changes) {
952: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
953: }
1.344 bisitz 954: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 955: }
956: my $count = 0;
957: my $time =
958: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
959: my $plainname =
960: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
961: $docslog{$id}{'exe_udom'});
962: my $about_me_link =
963: &Apache::loncommon::aboutmewrapper($plainname,
964: $docslog{$id}{'exe_uname'},
965: $docslog{$id}{'exe_udom'});
966: my $send_msg_link='';
967: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
968: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
969: $send_msg_link ='<br />'.
970: &Apache::loncommon::messagewrapper(&mt('Send message'),
971: $docslog{$id}{'exe_uname'},
972: $docslog{$id}{'exe_udom'});
973: }
974: $r->print(&Apache::loncommon::start_data_table_row());
975: $r->print('<td>'.$time.'</td>
976: <td>'.$about_me_link.
977: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
978: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
979: $send_msg_link.'</td><td>'.
980: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 981: my $is_supp = 0;
1.484.2.7 raeburn 982: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
983: $is_supp = 1;
984: }
1.329 droeschl 985: # Before
986: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
987: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
988: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
989: if ($oldname ne $newname) {
1.484.2.7 raeburn 990: my $shown = &LONCAPA::map::qtescape($oldname);
991: if ($is_supp) {
992: $shown = &Apache::loncommon::parse_supplemental_title($shown);
993: }
994: $r->print($shown);
1.329 droeschl 995: }
996: }
997: $r->print('<ul>');
998: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
999: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 1000: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1001: if ($is_supp) {
1002: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1003: }
1.484.2.19 raeburn 1004: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1005: }
1006: }
1007: $r->print('</ul>');
1008: # After
1009: $r->print('</td><td>');
1010:
1011: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1012: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1013: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1014: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 1015: my $shown = &LONCAPA::map::qtescape($newname);
1016: if ($is_supp) {
1017: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1018: }
1019: $r->print($shown);
1.329 droeschl 1020: }
1.364 bisitz 1021: }
1.329 droeschl 1022: $r->print('<ul>');
1023: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1024: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 1025: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1026: if ($is_supp) {
1027: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1028: }
1029: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1030: }
1031: }
1032: $r->print('</ul>');
1033: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1034: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1035: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1036: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1037: # FIXME: internationalization seems wrong here
1.329 droeschl 1038: $r->print('<li>'.
1039: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1040: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1041: .'</li>');
1042: }
1043: }
1044: $r->print('</ul>');
1045: }
1046: # End
1047: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1048: $shown++;
1049: if (!($env{'form.show'} eq &mt('all')
1050: || $shown<=$env{'form.show'})) { last; }
1051: }
1.484 raeburn 1052: $r->print(&Apache::loncommon::end_data_table()."\n".
1053: &makesimpleeditform($pathitem)."\n".
1054: '</div></div>');
1055: $r->print(&endContentScreen());
1.329 droeschl 1056: }
1057:
1058: sub update_paste_buffer {
1.484.2.7 raeburn 1059: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1060: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1061: if ($env{'form.multiremove'}) {
1062: $env{'form.multiremove'} =~ s/,$//;
1063: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1064: }
1065: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1066: if ($env{'form.multicut'}) {
1067: $env{'form.multicut'} =~ s/,$//;
1068: foreach my $item (split(/,/,$env{'form.multicut'})) {
1069: unless ($removals{$item}) {
1070: $cuts{$item} = 1;
1071: push(@possibles,$item.':cut');
1072: }
1073: }
1074: }
1075: if ($env{'form.multicopy'}) {
1076: $env{'form.multicopy'} =~ s/,$//;
1077: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1078: unless ($removals{$item} || $cuts{$item}) {
1079: push(@possibles,$item.':copy');
1080: }
1081: }
1082: }
1083: } elsif ($env{'form.markcopy'}) {
1084: @possibles = split(/,/,$env{'form.markcopy'});
1085: }
1.329 droeschl 1086:
1.484.2.30 raeburn 1087: return if (@possibles == 0);
1.329 droeschl 1088: return if (!defined($env{'form.copyfolder'}));
1089:
1090: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1091: $env{'form.copyfolder'});
1092: return if ($fatal);
1093:
1.484.2.30 raeburn 1094: my %curr_groups = &Apache::longroup::coursegroups();
1095:
1096: # Retrieve current paste buffer suffixes.
1097: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1098: my (%pasteurls,@newpaste);
1099:
1100: # Construct identifiers for current contents of user's paste buffer
1101: if (@currpaste) {
1102: foreach my $suffix (@currpaste) {
1.484.2.87 raeburn 1103: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1104: my $url = $env{'docs.markedcopy_url_'.$suffix};
1105: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1106: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1107: ($url ne '')) {
1108: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1109: $pasteurls{$cid.'_'.$mapidx} = 1;
1110: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1111: $pasteurls{$url} = 1;
1112: } else {
1113: $pasteurls{$cid.'_'.$url} = 1;
1114: }
1115: }
1.484.2.30 raeburn 1116: }
1117: }
1118:
1119: # Mark items for copying (skip any items already in user's paste buffer)
1120: my %addtoenv;
1.484.2.82 raeburn 1121:
1122: my @pathitems = split(/\&/,$env{'form.folderpath'});
1123: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.87 raeburn 1124: my $ispage = $folderconf[5];
1.484.2.82 raeburn 1125:
1.484.2.30 raeburn 1126: foreach my $item (@possibles) {
1127: my ($orderidx,$cmd) = split(/:/,$item);
1128: next if ($orderidx =~ /\D/);
1129: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1130: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1131: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1132: my %denied = &action_restrictions($coursenum,$coursedom,
1133: &LONCAPA::map::qtescape($url),
1134: $env{'form.folderpath'},\%curr_groups);
1135: next if ($denied{'copy'});
1136: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 1137: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1138: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1139: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1140: next if (exists($pasteurls{$url}));
1141: } else {
1142: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1143: }
1.484.2.30 raeburn 1144: my ($suffix,$errortxt,$locknotfreed) =
1145: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1146: if ($suffix ne '') {
1147: push(@newpaste,$suffix);
1148: } else {
1149: if ($locknotfreed) {
1150: return $locknotfreed;
1151: }
1.484.2.30 raeburn 1152: }
1153: if (&is_supplemental_title($title)) {
1154: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1155: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1156: }
1157:
1158: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1159: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1160: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1161: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1162: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1163: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1164: my $prefix = $1;
1165: my $subdir =$2;
1166: if ($subdir eq '') {
1167: $subdir = $prefix;
1.484.2.7 raeburn 1168: }
1.484.2.30 raeburn 1169: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1170: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1171: \%hierarchy,\%titles,\%allmaps);
1172: if (ref($hierarchy{$url}) eq 'HASH') {
1173: my ($nested,$nestednames);
1174: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1175: $nested =~ s/\&$//;
1176: $nestednames =~ s/\Q___&&&___\E$//;
1177: if ($nested ne '') {
1178: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1179: }
1180: if ($nestednames ne '') {
1181: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1182: }
1.484.2.7 raeburn 1183: }
1184: }
1.484.2.57 raeburn 1185: if ($locknotfreed) {
1186: $output = $locknotfreed;
1187: last;
1188: }
1.484.2.7 raeburn 1189: }
1.484.2.30 raeburn 1190: if (@newpaste) {
1191: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1192: }
1.484.2.7 raeburn 1193: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1194: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1195: return $output;
1.329 droeschl 1196: }
1197:
1.484.2.7 raeburn 1198: sub recurse_uploaded_maps {
1199: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1200: if (ref($hierarchy->{$url}) eq 'HASH') {
1201: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1202: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1203: my (@uploaded,@names,%shorter);
1204: for (my $i=0; $i<@maps; $i++) {
1205: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1206: if ($inner ne '') {
1207: push(@uploaded,$inner);
1208: push(@names,&escape($titles[$i]));
1209: $shorter{$maps[$i]} = $inner;
1210: }
1211: }
1212: $$nestref .= "$dir:".join(',',@uploaded).'&';
1213: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1214: foreach my $map (@maps) {
1215: if ($shorter{$map} ne '') {
1216: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1217: }
1218: }
1219: }
1220: return;
1221: }
1222:
1.329 droeschl 1223: sub print_paste_buffer {
1.484.2.7 raeburn 1224: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1225: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1226:
1.484.2.30 raeburn 1227: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1228: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1229: }
1230:
1.484.2.30 raeburn 1231: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1232: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1233: my $clipboardcount = 0;
1.484.2.7 raeburn 1234:
1.484.2.30 raeburn 1235: # Construct identifiers for current contents of user's paste buffer
1236: foreach my $suffix (@currpaste) {
1237: next if ($suffix =~ /\D/);
1238: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1239: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1240: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1241: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1242: ($url ne '')) {
1.484.2.47 raeburn 1243: $clipboardcount ++;
1.484.2.30 raeburn 1244: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1245: $canpaste,$nopaste,$othercrs,$areachange);
1246: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1247: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1248: $is_external = 1;
1.484.2.7 raeburn 1249: }
1.484.2.30 raeburn 1250: if ($folder =~ /^supplemental/) {
1251: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1252: unless ($canpaste) {
1253: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1254: }
1.484.2.30 raeburn 1255: } else {
1256: $canpaste = 1;
1.484.2.7 raeburn 1257: }
1.484.2.30 raeburn 1258: if ($canpaste) {
1259: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1260: my $srcdom = $1;
1261: my $srcnum = $2;
1262: my $rem = $3;
1263: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1264: $othercourse = 1;
1265: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1266: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1267: } else {
1268: $canpaste = 0;
1269: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1270: }
1271: }
1.484.2.30 raeburn 1272: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1273: my $prefix = $1;
1274: $parent = $2;
1275: if ($folder !~ /^\Q$prefix\E/) {
1276: $areachange = 1;
1277: }
1278: $is_uploaded_map = 1;
1279: }
1.484.2.82 raeburn 1280: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1281: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1282: if ($cid ne $env{'request.course.id'}) {
1283: my ($srcdom,$srcnum) = split(/_/,$cid);
1284: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1285: $othercrs = '<br />'.&mt('(from another course)');
1286: } else {
1287: $canpaste = 0;
1288: $nopaste = &mt('Paste from another course unavailable.');
1289: }
1290: }
1291: }
1292: if ($canpaste) {
1293: push(@pasteable,$suffix);
1.484.2.30 raeburn 1294: }
1295: }
1296: my $buffer;
1297: if ($is_external) {
1298: $buffer = &mt('External Resource').': '.
1299: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1300: &LONCAPA::map::qtescape($url).')';
1301: } else {
1302: my $icon = &Apache::loncommon::icon($extension);
1303: if ($extension eq 'sequence' &&
1304: $url =~ m{/default_\d+\.sequence$}x) {
1305: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1306: $icon .= '/navmap.folder.closed.gif';
1307: }
1.484.2.57 raeburn 1308: my $title = $env{'docs.markedcopy_title_'.$suffix};
1309: if ($title eq '') {
1310: ($title) = ($url =~ m{/([^/]+)$});
1311: }
1.484.2.30 raeburn 1312: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1313: ': '.
1314: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1315: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1316: }
1317: $pasteitems .= '<div class="LC_left_float">';
1318: my ($options,$onclick);
1319: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1320: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1321: if (($is_uploaded_map) ||
1322: ($url =~ /(bulletinboard|smppg)$/) ||
1323: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1324: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1325: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1326: }
1327: }
1328: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1329: if ($nopaste) {
1330: $pasteitems .= $nopaste;
1331: } else {
1332: if ($othercrs) {
1333: $pasteitems .= $othercrs;
1334: }
1335: if ($options) {
1336: $pasteitems .= $options;
1.484.2.7 raeburn 1337: }
1338: }
1.484.2.30 raeburn 1339: $pasteitems .= '</div>';
1340: }
1341: }
1342: if ($pasteitems eq '') {
1343: &Apache::lonnet::delenv('docs.markedcopies');
1344: }
1345: my ($pasteform,$form_start,$buttons,$form_end);
1346: if ($pasteitems) {
1347: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1348: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1349: if (@pasteable) {
1.484.2.47 raeburn 1350: my $value = &mt('Paste to current folder');
1351: if ($container eq 'page') {
1352: $value = &mt('Paste to current page');
1353: }
1354: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1355: }
1356: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.(' 'x2);
1357: if ($clipboardcount > 1) {
1358: $buttons .=
1359: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1360: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1361: (' 'x2).
1362: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1363: (' 'x2);
1.484.2.7 raeburn 1364: }
1.484.2.48 raeburn 1365: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1366: '</form>';
1.484.2.30 raeburn 1367: } else {
1368: $pasteitems = &mt('Clipboard is empty');
1369: }
1370: $r->print($form_start
1371: .'<fieldset>'
1372: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1373: .$pasteitems
1374: .'</fieldset>'
1375: .$form_end);
1376: }
1377:
1378: sub paste_options {
1379: my ($suffix,$is_uploaded_map,$parent) = @_;
1380: my ($copytext,$movetext);
1381: if ($is_uploaded_map) {
1382: $copytext = &mt('Copy to new folder');
1383: $movetext = &mt('Move old');
1384: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1385: $copytext = &mt('Copy to new board');
1386: $movetext = &mt('Move (not posts)');
1387: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1388: $copytext = &mt('Copy to new page');
1389: $movetext = &mt('Move');
1.484.2.7 raeburn 1390: } else {
1.484.2.30 raeburn 1391: $copytext = &mt('Copy to new file');
1392: $movetext = &mt('Move');
1393: }
1394: my $output = '<br />'.
1395: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1396: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1397: '<label>'.
1398: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1399: $copytext.'</label></span>'.(' 'x2).' '.
1400: '<span class="LC_nobreak"><label>'.
1401: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1402: $movetext.'</label></span>';
1403: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1404: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1405: '</legend><table border="0">';
1406: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1407: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1408: my $lastdir = $parent;
1409: my %depths = (
1410: $lastdir => 0,
1411: );
1412: my (%display,%deps);
1413: for (my $i=0; $i<@pastemaps; $i++) {
1414: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1415: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1416: my @subfolders = split(/,/,$subfolderstr);
1417: $deps{$lastdir} = \@subfolders;
1418: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1419: my $depth = $depths{$lastdir} + 1;
1420: my $offset = int($depth * 4);
1421: my $indent = (' ' x $offset);
1422: for (my $j=0; $j<@subfolders; $j++) {
1423: $depths{$subfolders[$j]} = $depth;
1424: $display{$subfolders[$j]} =
1425: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1426: '<td><label>'.
1427: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1428: '<label>'.
1429: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1430: &mt('Move old').'</label>'.
1431: '</td></tr>';
1432: }
1433: }
1434: &recurse_print(\$output,$parent,\%deps,\%display);
1435: $output .= '</table></fieldset>';
1.329 droeschl 1436: }
1.484.2.30 raeburn 1437: $output .= '</div>';
1438: return $output;
1.329 droeschl 1439: }
1440:
1.484.2.7 raeburn 1441: sub recurse_print {
1.484.2.30 raeburn 1442: my ($outputref,$dir,$deps,$display) = @_;
1443: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1444: if (ref($deps->{$dir}) eq 'ARRAY') {
1445: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1446: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1447: }
1448: }
1449: }
1450:
1451: sub supp_pasteable {
1452: my ($url) = @_;
1453: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1454: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1455: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1456: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1457: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1458: return 1;
1459: }
1460: return;
1461: }
1462:
1463: sub paste_popup_js {
1.484.2.61 raeburn 1464: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1465: show => 'Show Options',
1466: hide => 'Hide Options',
1.484.2.61 raeburn 1467: );
1468: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1469: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1470: );
1.484.2.61 raeburn 1471: &html_escape(\%html_js_lt);
1472: &js_escape(\%html_js_lt);
1473: &js_escape(\%js_lt);
1.484.2.7 raeburn 1474: return <<"END";
1475:
1.484.2.30 raeburn 1476: function showPasteOptions(suffix) {
1477: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1478: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1479: return;
1480: }
1481:
1.484.2.30 raeburn 1482: function hidePasteOptions(suffix) {
1483: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1484: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1485: return;
1486: }
1487:
1.484.2.30 raeburn 1488: function showOptions(caller,suffix) {
1489: if (document.getElementById('pasteoptionstext_'+suffix)) {
1490: if (caller.checked) {
1.484.2.61 raeburn 1491: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1492: } else {
1493: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1494: }
1495: if (document.getElementById('pasteoptions_'+suffix)) {
1496: document.getElementById('pasteoptions_'+suffix).style.display='none';
1497: }
1498: }
1499: return;
1500: }
1.484.2.7 raeburn 1501:
1.484.2.30 raeburn 1502: function validateClipboard() {
1503: var numchk = 0;
1504: if (document.pasteform.pasting.length > 1) {
1505: for (var i=0; i<document.pasteform.pasting.length; i++) {
1506: if (document.pasteform.pasting[i].checked) {
1507: numchk ++;
1508: }
1509: }
1510: } else {
1511: if (document.pasteform.pasting.type == 'checkbox') {
1512: if (document.pasteform.pasting.checked) {
1513: numchk ++;
1514: }
1515: }
1516: }
1517: if (numchk > 0) {
1518: return true;
1519: } else {
1.484.2.61 raeburn 1520: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1521: return false;
1522: }
1.484.2.7 raeburn 1523: }
1524:
1.484.2.47 raeburn 1525: function checkClipboard() {
1526: if (document.pasteform.pasting.length > 1) {
1527: for (var i=0; i<document.pasteform.pasting.length; i++) {
1528: document.pasteform.pasting[i].checked = true;
1529: }
1530: }
1531: return;
1532: }
1533:
1534: function uncheckClipboard() {
1535: if (document.pasteform.pasting.length >1) {
1536: for (var i=0; i<document.pasteform.pasting.length; i++) {
1537: document.pasteform.pasting[i].checked = false;
1538: }
1539: }
1540: return;
1541: }
1542:
1.484.2.30 raeburn 1543: END
1544:
1545: }
1.484.2.7 raeburn 1546:
1.329 droeschl 1547: sub do_paste_from_buffer {
1.484.2.7 raeburn 1548: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1549:
1.484.2.30 raeburn 1550: # Array of items in paste buffer
1551: my (@currpaste,%pastebuffer,%allerrors);
1552: @currpaste = split(/,/,$env{'docs.markedcopies'});
1553:
1.484.2.7 raeburn 1554: # Early out if paste buffer is empty
1.484.2.30 raeburn 1555: if (@currpaste == 0) {
1.484.2.7 raeburn 1556: return ();
1.484.2.30 raeburn 1557: }
1558: map { $pastebuffer{$_} = 1; } @currpaste;
1559:
1560: # Array of items selected items to paste
1561: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1562:
1563: # Early out if nothing selected to paste
1564: if (@reqpaste == 0) {
1565: return();
1566: }
1567: my @topaste;
1568: foreach my $suffix (@reqpaste) {
1569: next if ($suffix =~ /\D/);
1570: next unless (exists($pastebuffer{$suffix}));
1571: push(@topaste,$suffix);
1.484.2.7 raeburn 1572: }
1573:
1.484.2.30 raeburn 1574: # Early out if nothing available to paste
1575: if (@topaste == 0) {
1576: return();
1.329 droeschl 1577: }
1578:
1.484.2.30 raeburn 1579: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.484.2.82 raeburn 1580: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1581:
1.484.2.30 raeburn 1582: foreach my $suffix (@topaste) {
1583: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1584: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1585: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1586: # Supplemental content may only include certain types of content
1587: # Early out if pasted content is not supported in Supplemental area
1588: if ($folder =~ /^supplemental/) {
1589: unless (&supp_pasteable($url)) {
1590: $notinsupp{$suffix} = 1;
1591: next;
1592: }
1593: }
1594: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1595: my $srcd = $1;
1596: my $srcn = $2;
1.484.2.7 raeburn 1597: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1598: # check for mdc privilege in the course from which the resource was pasted
1599: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1600: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1601: $notincrs{$suffix} = 1;
1602: next;
1603: }
1.329 droeschl 1604: }
1.484.2.30 raeburn 1605: $srcdom{$suffix} = $srcd;
1606: $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1607: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1608: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1609: my ($srcd,$srcn) = split(/_/,$cid);
1610: # When paste buffer was populated using an active role in a different course
1611: # check for mdc privilege in the course from which the resource was pasted
1612: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1613: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1614: $notincrs{$suffix} = 1;
1615: next;
1616: }
1617: }
1618: $srcdom{$suffix} = $srcd;
1619: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1620: }
1.484.2.82 raeburn 1621: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1622: push(@dopaste,$suffix);
1623: if ($url=~/\.(page|sequence)$/) {
1624: $is_map{$suffix} = 1;
1.329 droeschl 1625: }
1.484.2.30 raeburn 1626:
1627: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1628: my $oldprefix = $1;
1.484.2.19 raeburn 1629: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1630: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1631: # a folder/page or a document).
1.484.2.30 raeburn 1632: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1633: $prefixchg{$suffix} = 'docstosupp';
1634: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1635: $prefixchg{$suffix} = 'supptodocs';
1636: }
1.484.2.7 raeburn 1637:
1638: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1639: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1640: my @nested;
1641: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1642: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1643: my @deps = map { /\d+:([\d,]+$)/ } @items;
1644: foreach my $dep (@deps) {
1645: if ($dep =~ /,/) {
1646: push(@nested,split(/,/,$dep));
1647: } else {
1648: push(@nested,$dep);
1649: }
1.484.2.7 raeburn 1650: }
1.484.2.30 raeburn 1651: foreach my $item (@nested) {
1652: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1653: push(@{$marktomove{$suffix}},$type.'_'.$item);
1654: }
1.484.2.7 raeburn 1655: }
1656: }
1.329 droeschl 1657: }
1.484.2.7 raeburn 1658: }
1659:
1.484.2.30 raeburn 1660: # Early out if nothing available to paste
1661: if (@dopaste == 0) {
1662: return ();
1663: }
1664:
1665: # Populate message hash and hashes used for main content <=> supplemental content
1666: # changes
1667:
1668: %msgs = &Apache::lonlocal::texthash (
1669: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1670: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1671: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1672: );
1673:
1674: %before = (
1675: docstosupp => {
1676: map => 'default',
1677: doc => 'docs',
1678: },
1679: supptodocs => {
1680: map => 'supplemental',
1681: doc => 'supplemental',
1682: },
1683: );
1684:
1685: %after = (
1686: docstosupp => {
1687: map => 'supplemental',
1688: doc => 'supplemental'
1689: },
1690: supptodocs => {
1691: map => 'default',
1692: doc => 'docs',
1693: },
1694: );
1695:
1696: # Retrieve information about all course maps in main content area
1697:
1698: my $allmaps = {};
1.484.2.79 raeburn 1699: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1700:
1701: # Loop over the items to paste
1702: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1703: # Maps need to be copied first
1.484.2.30 raeburn 1704: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1705: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1706: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1707: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1708: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1709: }
1710: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1711: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1712: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1713: my $oldurl = $url;
1714: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1715: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1716: my (%hierarchy,%titles);
1.484.2.79 raeburn 1717: if (($folder =~ /^default/) && (!$donechk)) {
1718: $allmaps =
1719: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1720: $env{"course.$env{'request.course.id'}.home"},
1721: $env{'request.course.id'});
1722: $donechk = 1;
1723: }
1.484.2.30 raeburn 1724: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1725: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1726: if ($url=~ m{^/uploaded/}) {
1727: my $newurl;
1728: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1729: ($newurl,my $error) =
1730: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1731: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1732: \$title,$allmaps,\%newurls);
1733: if ($error) {
1734: $allerrors{$suffix} = $error;
1735: next;
1736: }
1737: if ($newurl ne '') {
1738: if ($newurl ne $url) {
1739: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1740: $newsubdir{$url} = $1;
1741: }
1742: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1743: }
1744: }
1745: }
1.484.2.30 raeburn 1746: if (($srcdom{$suffix} ne $coursedom) ||
1747: ($srcnum{$suffix} ne $coursenum) ||
1748: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1749: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1750: $coursedom,$coursenum,$srcdom{$suffix},
1751: $srcnum{$suffix},$allmaps,\%rewrites,
1752: \%retitles,\%copies,\%dbcopies,
1753: \%zombies,\%params,\%mapmoves,
1754: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1755: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1756: $mapmoves{$url} = 1;
1757: }
1758: $url = $newurl;
1759: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1760: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1761: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1762: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1763: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1764: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1765: }
1766: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1767: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1768: push(@toclear,$suffix);
1769: # if pasting published map (main content area only) check map not already in course
1770: if ($folder =~ /^default/) {
1771: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1772: $duplicate{$suffix} = 1;
1773: next;
1774: }
1.484.2.7 raeburn 1775: }
1776: }
1777: }
1.484.2.30 raeburn 1778: if ($url=~ m{/(bulletinboard|smppg)$}) {
1779: my $prefix = $1;
1.484.2.76 raeburn 1780: my $fromothercrs;
1.484.2.30 raeburn 1781: #need to copy the db contents to a new one, unless this is a move.
1782: my %info = (
1783: src => $url,
1784: cdom => $coursedom,
1785: cnum => $coursenum,
1.484.2.76 raeburn 1786: );
1787: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1788: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1789: $fromothercrs = 1;
1790: $info{'cdom'} = $srcdom{$suffix};
1791: $info{'cnum'} = $srcnum{$suffix};
1792: }
1793: }
1794: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1795: my (%lockerr,$msg);
1796: my ($newurl,$result,$errtext) =
1797: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1798: if ($result eq 'ok') {
1799: $url = $newurl;
1800: $title=&mt('Copy of').' '.$title;
1801: } else {
1802: if ($prefix eq 'smppg') {
1803: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1804: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1805: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.30 raeburn 1806: }
1807: $results{$suffix} = $result;
1808: $msgerrs{$suffix} = $msg;
1809: $lockerrs{$suffix} = $lockerr{$prefix};
1810: next;
1811: }
1812: if ($lockerr{$prefix}) {
1813: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1814: }
1.484.2.7 raeburn 1815: }
1.484.2.30 raeburn 1816: }
1817: $title = &LONCAPA::map::qtunescape($title);
1818: my $ext='false';
1819: if ($url=~m{^http(|s)://}) { $ext='true'; }
1820: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1821: if ($folder !~ /^supplemental/) {
1822: (undef,undef,$title) =
1823: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1824: }
1825: } else {
1826: if ($folder=~/^supplemental/) {
1827: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1828: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1829: }
1830: }
1.484.2.7 raeburn 1831:
1832: # For uploaded files (excluding pages/sequences) path in copied file is changed
1833: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1834: # courses.
1835:
1.484.2.30 raeburn 1836: unless ($is_map{$suffix}) {
1837: my $newidx;
1.329 droeschl 1838: # Now insert the URL at the bottom
1.484.2.30 raeburn 1839: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1840: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1841: my $relpath = $1;
1842: if ($relpath ne '') {
1843: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1844: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1845: my $newprefix = $newloc;
1846: if ($newloc eq 'default') {
1847: $newprefix = 'docs';
1848: }
1849: if ($newdocsdir eq '') {
1850: $newdocsdir = 'default';
1851: }
1852: if (($prefixchg{$suffix}) ||
1853: ($srcdom{$suffix} ne $coursedom) ||
1854: ($srcnum{$suffix} ne $coursenum) ||
1855: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1856: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1857: $url =
1858: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1859: &Apache::lonnet::getfile($oldurl));
1860: if ($url eq '/adm/notfound.html') {
1861: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1862: next;
1863: } else {
1864: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1865: $newsubpath =~ s{/+$}{/};
1866: $docmoves{$oldurl} = $newsubpath;
1867: }
1.484.2.7 raeburn 1868: }
1869: }
1.484.2.82 raeburn 1870: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1871: my $template = $1;
1872: if ($newidx) {
1873: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1874: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1875: }
1.484.2.7 raeburn 1876: }
1.484.2.30 raeburn 1877: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1878: ':'.$ext.':normal:res';
1879: push(@LONCAPA::map::order,$newidx);
1880: # Store the result
1881: my ($errtext,$fatal) =
1882: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1883: if ($fatal) {
1884: $save_err .= $errtext;
1885: $allresult = 'fail';
1.484.2.7 raeburn 1886: }
1.329 droeschl 1887: }
1.484.2.30 raeburn 1888:
1.484.2.82 raeburn 1889: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1890: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 1891: unless ($allresult eq 'fail') {
1892: my %updated = (
1893: rewrites => \%rewrites,
1894: zombies => \%zombies,
1895: removefrommap => \%removefrommap,
1896: removeparam => \%removeparam,
1897: dbcopies => \%dbcopies,
1.484.2.82 raeburn 1898: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 1899: retitles => \%retitles,
1900: );
1901: my %info = (
1902: newsubdir => \%newsubdir,
1903: params => \%params,
1904: );
1905: if ($prefixchg{$suffix}) {
1906: $info{'before'} = $before{$prefixchg{$suffix}};
1907: $info{'after'} = $after{$prefixchg{$suffix}};
1908: }
1909: my %moves = (
1910: copies => \%copies,
1911: docmoves => \%docmoves,
1912: mapmoves => \%mapmoves,
1913: );
1914: (my $result,$msgs{$suffix},my $lockerror) =
1915: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1916: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1917: $url,'paste');
1918: $lockerrors .= $lockerror;
1919: if ($result eq 'ok') {
1920: if ($is_map{$suffix}) {
1921: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1922: $folder.'.'.$container);
1923: if ($fatal) {
1924: $allresult = 'failread';
1925: } else {
1926: if ($#LONCAPA::map::order<1) {
1927: my $idx=&LONCAPA::map::getresidx();
1928: if ($idx<=0) { $idx=1; }
1929: $LONCAPA::map::order[0]=$idx;
1930: $LONCAPA::map::resources[$idx]='';
1931: }
1932: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1933: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1934: ':'.$ext.':normal:res';
1935: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 1936:
1937: # Store the result
1.484.2.30 raeburn 1938: my ($errtext,$fatal) =
1939: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1940: if ($fatal) {
1941: $save_err .= $errtext;
1942: $allresult = 'failstore';
1943: }
1944: }
1945: }
1946: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1947: push(@toclear,$suffix);
1948: }
1949: }
1.329 droeschl 1950: }
1951: }
1.484.2.30 raeburn 1952: &clear_from_buffer(\@toclear,\@currpaste);
1953: my $msgsarray;
1954: foreach my $suffix (keys(%msgs)) {
1955: if (ref($msgs{$suffix}) eq 'ARRAY') {
1956: $msgsarray .= join(',',@{$msgs{$suffix}});
1957: }
1958: }
1959: return ($allresult,$save_err,$msgsarray,$lockerrors);
1960: }
1961:
1962: sub do_buffer_empty {
1963: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1964: if (@currpaste == 0) {
1965: return &mt('Clipboard is already empty');
1966: }
1967: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1968: if (@toclear == 0) {
1969: return &mt('Nothing selected to clear from clipboard');
1970: }
1971: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1972: if ($numdel) {
1973: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1974: } else {
1975: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 1976: }
1.484.2.30 raeburn 1977: return;
1978: }
1979:
1980: sub clear_from_buffer {
1981: my ($toclear,$currpaste) = @_;
1982: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1983: my %pastebuffer;
1984: map { $pastebuffer{$_} = 1; } @{$currpaste};
1985: my $numdel = 0;
1986: foreach my $suffix (@{$toclear}) {
1987: next if ($suffix =~ /\D/);
1988: next unless (exists($pastebuffer{$suffix}));
1989: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1990: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1991: delete($pastebuffer{$suffix});
1992: $numdel ++;
1993: }
1994: }
1995: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1996: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1997: return $numdel;
1.484.2.7 raeburn 1998: }
1999:
2000: sub get_newmap_url {
2001: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2002: $titleref,$allmaps,$newurls) = @_;
2003: my $newurl;
2004: if ($url=~ m{^/uploaded/}) {
2005: $$titleref=&mt('Copy of').' '.$$titleref;
2006: }
2007: my $now = time;
2008: my $suffix=$$.int(rand(100)).$now;
2009: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2010: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2011: my $path = $1;
2012: my $prefix = $2;
2013: my $ancestor = $3;
2014: if (length($ancestor) > 10) {
2015: $ancestor = substr($ancestor,-10,10);
2016: }
2017: my $newid;
2018: if ($prefixchg) {
2019: if ($folder =~ /^supplemental/) {
2020: $prefix =~ s/^default/supplemental/;
2021: } else {
2022: $prefix =~ s/^supplemental/default/;
2023: }
2024: }
2025: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2026: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2027: } else {
2028: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2029: }
2030: my $counter = 0;
2031: my $is_unique = &uniqueness_check($newurl);
2032: if ($folder =~ /^default/) {
2033: if ($allmaps->{$newurl}) {
2034: $is_unique = 0;
2035: }
2036: }
2037: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2038: $counter ++;
2039: $suffix ++;
2040: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2041: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2042: } else {
2043: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2044: }
2045: $is_unique = &uniqueness_check($newurl);
2046: }
2047: if ($is_unique) {
2048: $newurls->{$newurl} = 1;
2049: } else {
2050: if ($url=~/\.page$/) {
2051: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2052: } else {
2053: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2054: }
2055: }
2056: }
2057: return ($newurl);
2058: }
2059:
2060: sub dbcopy {
1.484.2.26 raeburn 2061: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2062: my ($url,$result,$errtext);
2063: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2064: $url = $dbref->{'src'};
1.484.2.26 raeburn 2065: if ($url =~ m{/(smppg|bulletinboard)$}) {
2066: my $prefix = $1;
2067: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2068: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2069: my $db_name;
2070: my $marker = (split(m{/},$url))[4];
2071: $marker=~s/\D//g;
2072: if ($dbref->{'src'} =~ m{/smppg$}) {
2073: $db_name =
2074: &Apache::lonsimplepage::get_db_name($url,$marker,
2075: $dbref->{'cdom'},
2076: $dbref->{'cnum'});
2077: } else {
2078: $db_name = 'bulletinpage_'.$marker;
2079: }
2080: my ($suffix,$freedlock,$error) =
2081: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2082: $coursedom,$coursenum,
2083: 'concat');
2084: if (!$suffix) {
2085: if ($prefix eq 'smppg') {
2086: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2087: } else {
1.484.2.42 raeburn 2088: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2089: }
2090: if ($error) {
2091: $errtext .= '<br />'.$error;
2092: }
2093: } else {
2094: #need to copy the db contents to a new one.
2095: my %contents=&Apache::lonnet::dump($db_name,
2096: $dbref->{'cdom'},
2097: $dbref->{'cnum'});
2098: if (exists($contents{'uploaded.photourl'})) {
2099: my $photo = $contents{'uploaded.photourl'};
2100: my ($subdir,$fname) =
2101: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2102: my $newphoto;
2103: if ($fname ne '') {
2104: my $content = &Apache::lonnet::getfile($photo);
2105: unless ($content eq '-1') {
2106: $env{'form.'.$suffix.'.photourl'} = $content;
2107: $newphoto =
2108: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2109: delete($env{'form.'.$suffix.'.photourl'});
2110: }
2111: }
2112: if ($newphoto =~ m{^/uploaded/}) {
2113: $contents{'uploaded.photourl'} = $newphoto;
2114: }
2115: }
2116: $db_name =~ s{_\d*$ }{_$suffix}x;
2117: $result=&Apache::lonnet::put($db_name,\%contents,
2118: $coursedom,$coursenum);
2119: if ($result eq 'ok') {
2120: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2121: }
2122: }
2123: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2124: $lockerrorsref->{$prefix} =
2125: '<div class="LC_error">'.
2126: &mt('There was a problem removing a lockfile.');
2127: if ($prefix eq 'smppg') {
2128: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2129: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.26 raeburn 2130: } else {
1.484.2.42 raeburn 2131: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2132: }
1.484.2.38 raeburn 2133: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2134: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2135: '</div>';
1.484.2.26 raeburn 2136: }
2137: }
2138: } elsif ($url =~ m{/syllabus$}) {
2139: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2140: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2141: if (($dbref->{'cdom'} ne $coursedom) ||
2142: ($dbref->{'cnum'} ne $coursenum)) {
2143: my %contents=&Apache::lonnet::dump('syllabus',
2144: $dbref->{'cdom'},
2145: $dbref->{'cnum'});
2146: $result=&Apache::lonnet::put('syllabus',\%contents,
2147: $coursedom,$coursenum);
2148: }
2149: }
1.484.2.7 raeburn 2150: }
2151: }
1.484.2.26 raeburn 2152: return ($url,$result,$errtext);
1.329 droeschl 2153: }
2154:
1.484.2.82 raeburn 2155: sub copy_templated_files {
2156: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2157: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2158: my $srccontainer = 'sequence';
2159: if ($srcwaspage) {
2160: $srccontainer = 'page';
2161: }
2162: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2163: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2164: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2165: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2166: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2167: $template.'.problem';
2168: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2169: if ($template eq 'simpleproblem') {
2170: $srcprefix .= '.0.';
2171: my $weightprefix = $newprefix;
2172: $newprefix .= '.0.';
2173: my @simpleprobqtypes = qw(radio option string essay numerical);
2174: my $qtype=$srcparms{$srcprefix.'questiontype'};
2175: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2176: my %newdata = (
2177: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2178: );
1.484.2.82 raeburn 2179: foreach my $type (@simpleprobqtypes) {
2180: if ($type eq $qtype) {
2181: $newdata{"$weightprefix.$type.weight"}=1;
2182: } else {
2183: $newdata{"$weightprefix.$type.weight"}=0;
2184: }
2185: }
2186: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2187: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2188: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2189: if ($qtype eq 'numerical') {
2190: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2191: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2192: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2193: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2194: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2195: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2196: unless (defined($maxfoils)) { $maxfoils=10; }
2197: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2198: if ($maxfoils<=0) { $maxfoils=10; }
2199: my $randomize=$srcparms{$srcprefix.'randomize'};
2200: unless (defined($randomize)) { $randomize='yes'; }
2201: unless ($randomize eq 'no') { $randomize='yes'; }
2202: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2203: $newdata{$newprefix.'randomize'} = $randomize;
2204: if ($qtype eq 'option') {
2205: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2206: }
2207: for (my $i=1; $i<=10; $i++) {
2208: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2209: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2210: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2211: }
2212:
2213: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2214: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2215: unless (defined($maxfoils)) { $maxfoils=10; }
2216: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2217: if ($maxfoils<=0) { $maxfoils=10; }
2218: my $randomize=$srcparms{$srcprefix.'randomize'};
2219: unless (defined($randomize)) { $randomize='yes'; }
2220: unless ($randomize eq 'no') { $randomize='yes'; }
2221: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2222: $newdata{$newprefix.'randomize'} = $randomize;
2223: if ($qtype eq 'option') {
2224: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2225: }
2226: for (my $i=1; $i<=10; $i++) {
2227: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2228: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2229: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2230: }
2231: } elsif ($qtype eq 'string') {
2232: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2233: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2234: }
2235: if (keys(%newdata)) {
2236: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2237: $coursenum);
2238: if ($putres eq 'ok') {
2239: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2240: }
2241: }
2242: }
2243: }
2244: }
2245:
1.329 droeschl 2246: sub uniqueness_check {
2247: my ($newurl) = @_;
2248: my $unique = 1;
2249: foreach my $res (@LONCAPA::map::order) {
2250: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2251: $url=&LONCAPA::map::qtescape($url);
2252: if ($newurl eq $url) {
2253: $unique = 0;
1.344 bisitz 2254: last;
1.329 droeschl 2255: }
2256: }
2257: return $unique;
2258: }
2259:
1.484.2.7 raeburn 2260: sub contained_map_check {
2261: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2262: $allmaps) = @_;
2263: my $content = &Apache::lonnet::getfile($url);
2264: unless ($content eq '-1') {
2265: my $parser = HTML::TokeParser->new(\$content);
2266: $parser->attr_encoded(1);
2267: while (my $token = $parser->get_token) {
2268: next if ($token->[0] ne 'S');
2269: if ($token->[1] eq 'resource') {
2270: next if ($token->[2]->{'type'} eq 'zombie');
2271: my $ressrc = $token->[2]->{'src'};
2272: if ($folder =~ /^supplemental/) {
2273: unless (&supp_pasteable($ressrc)) {
2274: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2275: next;
2276: }
2277: }
2278: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2279: if ($1 eq 'uploaded') {
2280: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2281: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2282: } else {
2283: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2284: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2285: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2286: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2287: } else {
2288: $addedmaps->{$ressrc} = [$url];
2289: }
2290: }
2291: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2292: $addedmaps,$hierarchy,$titles,$allmaps);
2293: }
2294: } elsif ($token->[1] eq 'param') {
2295: if ($folder =~ /^supplemental/) {
2296: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2297: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2298: } else {
1.484.2.19 raeburn 2299: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2300: }
2301: }
2302: }
2303: }
2304: }
2305: return;
2306: }
2307:
2308: sub url_paste_fixups {
1.484.2.26 raeburn 2309: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2310: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2311: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2312: my $checktitle;
2313: if (($prefixchg) &&
2314: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2315: $checktitle = 1;
2316: }
2317: my $skip;
2318: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2319: my $mapid = $1.$2;
2320: if ($tomove->{$mapid}) {
2321: $skip = 1;
2322: }
2323: }
2324: my $file = &Apache::lonnet::getfile($oldurl);
2325: return if ($file eq '-1');
2326: my $parser = HTML::TokeParser->new(\$file);
2327: $parser->attr_encoded(1);
2328: my $changed = 0;
2329: while (my $token = $parser->get_token) {
2330: next if ($token->[0] ne 'S');
2331: if ($token->[1] eq 'resource') {
2332: my $ressrc = $token->[2]->{'src'};
2333: next if ($ressrc eq '');
2334: my $id = $token->[2]->{'id'};
2335: my $title = $token->[2]->{'title'};
2336: if ($checktitle) {
2337: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2338: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2339: }
2340: }
2341: next if ($token->[2]->{'type'} eq 'external');
2342: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2343: next if ($skip);
1.484.2.25 raeburn 2344: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2345: $changed = 1;
2346: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2347: my $srcdom = $1;
2348: my $srcnum = $2;
2349: my $rem = $3;
2350: my $newurl;
2351: my $mapname;
2352: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2353: my $prefix = $1;
2354: $mapname = $prefix.$2;
2355: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2356: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2357: $srcdom,$srcnum,$allmaps,$rewrites,
2358: $retitles,$copies,$dbcopies,$zombies,
2359: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2360: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2361: next;
2362: } else {
2363: ($newurl,my $error) =
2364: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2365: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2366: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2367: $newsubdir->{$ressrc} = $1;
2368: }
2369: if ($error) {
2370: next;
2371: }
2372: }
2373: }
2374: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2375: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2376:
1.484.2.7 raeburn 2377: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2378: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2379: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2380: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2381: $cnum,$srcdom,$srcnum,$allmaps,
2382: $rewrites,$retitles,$copies,$dbcopies,
2383: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2384: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2385: $mapmoves->{$ressrc} = 1;
2386: }
2387: $changed = 1;
2388: } else {
1.484.2.25 raeburn 2389: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2390: $copies->{$oldurl}{$ressrc} = $id;
2391: $changed = 1;
2392: }
2393: }
1.484.2.26 raeburn 2394: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2395: next if ($skip);
1.484.2.7 raeburn 2396: my $srcdom = $1;
2397: my $srcnum = $2;
2398: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2399: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2400: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2401: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2402: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2403: $changed = 1;
2404: }
2405: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2406: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2407: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2408: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2409: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2410: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2411: $changed = 1;
2412: }
1.484.2.82 raeburn 2413: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2414: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2415: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2416: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2417: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2418: }
1.484.2.7 raeburn 2419: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2420: next if ($skip);
2421: my $srcdom = $1;
2422: my $srcnum = $2;
2423: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2424: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2425: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2426: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2427: $changed = 1;
2428: }
2429: }
2430: } elsif ($token->[1] eq 'param') {
2431: next if ($skip);
1.484.2.19 raeburn 2432: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2433: if ($to ne '') {
2434: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2435: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2436: } else {
2437: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2438: }
2439: }
2440: }
2441: }
2442: return $changed;
2443: }
2444:
2445: sub apply_fixups {
1.484.2.23 raeburn 2446: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2447: $oldurl,$url,$caller) = @_;
2448: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2449: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2450: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2451: if (ref($updated) eq 'HASH') {
2452: if (ref($updated->{'rewrites'}) eq 'HASH') {
2453: %rewrites = %{$updated->{'rewrites'}};
2454: }
2455: if (ref($updated->{'zombies'}) eq 'HASH') {
2456: %zombies = %{$updated->{'zombies'}};
2457: }
2458: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2459: %removefrommap = %{$updated->{'removefrommap'}};
2460: }
2461: if (ref($updated->{'removeparam'}) eq 'HASH') {
2462: %removeparam = %{$updated->{'removeparam'}};
2463: }
2464: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2465: %dbcopies = %{$updated->{'dbcopies'}};
2466: }
2467: if (ref($updated->{'retitles'}) eq 'HASH') {
2468: %retitles = %{$updated->{'retitles'}};
2469: }
1.484.2.82 raeburn 2470: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2471: %resdatacopy = %{$updated->{'resdatacopy'}};
2472: }
1.484.2.23 raeburn 2473: }
2474: if (ref($info) eq 'HASH') {
2475: if (ref($info->{'newsubdir'}) eq 'HASH') {
2476: %newsubdir = %{$info->{'newsubdir'}};
2477: }
2478: if (ref($info->{'params'}) eq 'HASH') {
2479: %params = %{$info->{'params'}};
2480: }
2481: if (ref($info->{'before'}) eq 'HASH') {
2482: %before = %{$info->{'before'}};
2483: }
2484: if (ref($info->{'after'}) eq 'HASH') {
2485: %after = %{$info->{'after'}};
2486: }
2487: }
2488: if (ref($moves) eq 'HASH') {
2489: if (ref($moves->{'copies'}) eq 'HASH') {
2490: %copies = %{$moves->{'copies'}};
2491: }
2492: if (ref($moves->{'docmoves'}) eq 'HASH') {
2493: %docmoves = %{$moves->{'docmoves'}};
2494: }
2495: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2496: %mapmoves = %{$moves->{'mapmoves'}};
2497: }
2498: }
2499: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2500: my @allcopies;
1.484.2.23 raeburn 2501: if (exists($copies{$key})) {
2502: if (ref($copies{$key}) eq 'HASH') {
2503: my %added;
2504: foreach my $innerkey (keys(%{$copies{$key}})) {
2505: if (($innerkey ne '') && (!$added{$innerkey})) {
2506: push(@allcopies,$innerkey);
2507: $added{$innerkey} = 1;
2508: }
1.484.2.7 raeburn 2509: }
1.484.2.23 raeburn 2510: undef(%added);
1.484.2.7 raeburn 2511: }
2512: }
2513: if ($key eq $oldurl) {
1.484.2.23 raeburn 2514: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2515: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2516: push(@allcopies,$oldurl);
2517: }
2518: }
2519: }
2520: if (@allcopies > 0) {
2521: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2522: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2523: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2524: if ($fname ne '') {
2525: my $content = &Apache::lonnet::getfile($item);
2526: unless ($content eq '-1') {
2527: my $storefn;
1.484.2.23 raeburn 2528: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2529: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2530: } else {
2531: $storefn = $relpath;
2532: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2533: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2534: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2535: }
1.484.2.23 raeburn 2536: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2537: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2538: }
2539: }
2540: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2541: my $copyurl =
1.484.2.7 raeburn 2542: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2543: $storefn.$fname,$content);
2544: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2545: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2546: return &mt('Paste failed: an error occurred copying the file.');
2547: } elsif (ref($errors) eq 'HASH') {
2548: $errors->{$item} = 1;
2549: }
2550: }
2551: }
2552: }
2553: }
2554: }
2555: }
1.484.2.23 raeburn 2556: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2557: my $storefn=$key;
2558: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2559: if ($prefixchg && $before{'map'} && $after{'map'}) {
2560: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2561: }
1.484.2.23 raeburn 2562: if ($newsubdir{$key}) {
2563: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2564: }
2565: my $mapcontent = &Apache::lonnet::getfile($key);
2566: if ($mapcontent eq '-1') {
2567: if (ref($errors) eq 'HASH') {
2568: $errors->{$key} = 1;
2569: }
2570: } else {
2571: my $newmap =
2572: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2573: $mapcontent);
2574: if ($newmap eq '/adm/notfound.html') {
2575: if (ref($errors) eq 'HASH') {
2576: $errors->{$key} = 1;
2577: }
2578: }
2579: }
2580: }
2581: my %updates;
2582: if ($is_map) {
1.484.2.23 raeburn 2583: if (ref($updated) eq 'HASH') {
2584: foreach my $type (keys(%{$updated})) {
2585: if (ref($updated->{$type}) eq 'HASH') {
2586: foreach my $key (keys(%{$updated->{$type}})) {
2587: $updates{$key} = 1;
2588: }
2589: }
2590: }
1.484.2.7 raeburn 2591: }
2592: foreach my $key (keys(%updates)) {
2593: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2594: if (ref($rewrites{$key}) eq 'HASH') {
2595: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2596: }
1.484.2.23 raeburn 2597: if (ref($retitles{$key}) eq 'HASH') {
2598: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2599: }
1.484.2.23 raeburn 2600: if (ref($removefrommap{$key}) eq 'HASH') {
2601: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2602: }
1.484.2.23 raeburn 2603: if (ref($removeparam{$key}) eq 'HASH') {
2604: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2605: }
1.484.2.23 raeburn 2606: if (ref($zombies{$key}) eq 'HASH') {
2607: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2608: }
1.484.2.23 raeburn 2609: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2610: foreach my $idx (keys(%{$dbcopies{$key}})) {
2611: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2612: my ($newurl,$result,$errtext) =
2613: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2614: if ($result eq 'ok') {
2615: $newdb{$idx} = $newurl;
2616: } elsif (ref($errors) eq 'HASH') {
2617: $errors->{$key} = 1;
2618: }
2619: push(@msgs,$errtext);
2620: }
1.484.2.7 raeburn 2621: }
2622: }
1.484.2.82 raeburn 2623: if (ref($resdatacopy{$key}) eq 'HASH') {
2624: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2625: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2626: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2627: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2628: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2629: my $template = $1;
2630: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2631: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2632: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2633: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2634: unless ($gotnewmapname) {
2635: ($newmapname) = ($key =~ m{/([^/]+)$});
2636: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2637: if ($newsubdir{$key}) {
2638: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2639: }
2640: $gotnewmapname = 1;
2641: }
2642: my $srcmapinfo = $srcfolder.':'.$idx;
2643: if ($srccontainer eq 'page') {
2644: $srcmapinfo .= ':1';
2645: }
2646: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2647: $cnum,$template,$idx,$newmapname);
2648: }
2649: }
2650: }
2651: }
2652: }
1.484.2.23 raeburn 2653: if (ref($params{$key}) eq 'HASH') {
2654: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2655: }
2656: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2657: if ($fatal) {
1.484.2.26 raeburn 2658: return ($errtext);
1.484.2.7 raeburn 2659: }
2660: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2661: if (defined($LONCAPA::map::zombies[$i])) {
2662: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2663: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2664: undef($LONCAPA::map::zombies[$i]);
2665: }
2666: }
2667: }
1.484.2.77 raeburn 2668: my $total = scalar(@LONCAPA::map::order) - 1;
2669: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2670: my $idx = $LONCAPA::map::order[$i];
2671: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2672: my $changed;
1.484.2.23 raeburn 2673: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2674: if ((exists($toremove{$idx})) &&
2675: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2676: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2677: if (ref($currparam{$idx}) eq 'ARRAY') {
2678: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2679: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2680: }
2681: }
2682: next;
2683: }
2684: my $origsrc = $src;
1.484.2.25 raeburn 2685: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2686: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2687: $changed = 1;
2688: }
2689: }
1.484.2.25 raeburn 2690: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2691: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2692: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2693: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2694: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2695: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2696: } else {
1.484.2.23 raeburn 2697: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2698: }
2699: }
1.484.2.25 raeburn 2700: if ($origsrc =~ /\.(page|sequence)$/) {
2701: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2702: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2703: }
1.484.2.25 raeburn 2704: } elsif ($newsubdir{$key}) {
2705: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2706: }
2707: }
2708: $changed = 1;
1.484.2.26 raeburn 2709: } elsif ($newdb{$idx} ne '') {
2710: $src = $newdb{$idx};
1.484.2.7 raeburn 2711: $changed = 1;
2712: }
2713: if ($changed) {
1.484.2.30 raeburn 2714: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2715: }
2716: }
2717: }
2718: foreach my $idx (keys(%remparam)) {
2719: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2720: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2721: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2722: }
2723: }
2724: }
1.484.2.26 raeburn 2725: if (values(%lockerrors) > 0) {
2726: $lockmsg = join('<br />',values(%lockerrors));
2727: }
1.484.2.7 raeburn 2728: my $storefn;
2729: if ($key eq $oldurl) {
2730: $storefn = $url;
2731: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2732: } else {
2733: $storefn = $key;
2734: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2735: if ($prefixchg && $before{'map'} && $after{'map'}) {
2736: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2737: }
1.484.2.23 raeburn 2738: if ($newsubdir{$key}) {
2739: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2740: }
2741: }
2742: my $report;
2743: if ($folder !~ /^supplemental/) {
2744: $report = 1;
2745: }
1.484.2.20 raeburn 2746: (my $outtext,$errtext) =
1.484.2.7 raeburn 2747: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2748: if ($errtext) {
1.484.2.23 raeburn 2749: if ($caller eq 'paste') {
1.484.2.26 raeburn 2750: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2751: }
1.484.2.7 raeburn 2752: }
2753: }
2754: }
1.484.2.26 raeburn 2755: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2756: }
2757:
2758: sub copy_dependencies {
2759: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2760: my $content;
2761: if (ref($contentref)) {
2762: $content = $$contentref;
2763: } else {
2764: $content = &Apache::lonnet::getfile($item);
2765: }
2766: unless ($content eq '-1') {
2767: my $mm = new File::MMagic;
2768: my $mimetype = $mm->checktype_contents($content);
2769: if ($mimetype eq 'text/html') {
2770: my (%allfiles,%codebase,$state);
2771: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2772: if ($res eq 'ok') {
2773: my ($numexisting,$numpathchanges,$existing);
2774: (undef,$numexisting,$numpathchanges,$existing) =
2775: &Apache::loncommon::ask_for_embedded_content(
2776: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2777: {'error_on_invalid_names' => 1,
2778: 'ignore_remote_references' => 1,
2779: 'docs_url' => $item,
2780: 'context' => 'paste'});
2781: if ($numexisting > 0) {
2782: if (ref($existing) eq 'HASH') {
2783: foreach my $dep (keys(%{$existing})) {
2784: my $depfile = $dep;
2785: unless ($depfile =~ m{^\Q$relpath\E}) {
2786: $depfile = $relpath.$dep;
2787: }
2788: my $depcontent = &Apache::lonnet::getfile($depfile);
2789: unless ($depcontent eq '-1') {
2790: my $storedep = $dep;
2791: $storedep =~ s{^\Q$relpath\E}{};
2792: my $dep_url =
2793: &Apache::lonclonecourse::writefile(
2794: $env{'request.course.id'},
2795: $storefn.$storedep,$depcontent);
2796: if ($dep_url eq '/adm/notfound.html') {
2797: if (ref($errors) eq 'HASH') {
2798: $errors->{$depfile} = 1;
2799: }
2800: } else {
2801: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2802: }
2803: }
2804: }
2805: }
2806: }
2807: }
2808: }
2809: }
2810: return;
2811: }
2812:
1.329 droeschl 2813: my %parameter_type = ( 'randompick' => 'int_pos',
2814: 'hiddenresource' => 'string_yesno',
2815: 'encrypturl' => 'string_yesno',
2816: 'randomorder' => 'string_yesno',);
2817: my $valid_parameters_re = join('|',keys(%parameter_type));
2818: # set parameters
2819: sub update_parameter {
1.484.2.29 raeburn 2820: if ($env{'form.changeparms'} eq 'all') {
2821: my (@allidx,@allmapidx,%allchecked,%currchecked);
2822: %allchecked = (
2823: 'hiddenresource' => {},
2824: 'encrypturl' => {},
2825: 'randompick' => {},
2826: 'randomorder' => {},
2827: );
2828: foreach my $which (keys(%allchecked)) {
2829: $env{'form.all'.$which} =~ s/,$//;
2830: if ($which eq 'randompick') {
2831: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2832: my ($res,$value) = split(/:/,$item);
2833: if ($value =~ /^\d+$/) {
2834: $allchecked{$which}{$res} = $value;
2835: }
2836: }
2837: } else {
1.484.2.30 raeburn 2838: if ($env{'form.all'.$which}) {
2839: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2840: }
1.484.2.29 raeburn 2841: }
2842: }
2843: my $haschanges = 0;
2844: foreach my $res (@LONCAPA::map::order) {
2845: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2846: $name=&LONCAPA::map::qtescape($name);
2847: $url=&LONCAPA::map::qtescape($url);
2848: next unless ($name && $url);
2849: my $is_map;
2850: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2851: $is_map = 1;
2852: }
2853: foreach my $which (keys(%allchecked)) {
2854: if (($which eq 'randompick' || $which eq 'randomorder')) {
2855: next if (!$is_map);
2856: }
2857: my $oldvalue = 0;
2858: my $newvalue = 0;
2859: if ($allchecked{$which}{$res}) {
2860: $newvalue = $allchecked{$which}{$res};
2861: }
2862: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2863: if ($which eq 'randompick') {
2864: if ($current =~ /^(\d+)$/) {
2865: $oldvalue = $1;
2866: }
2867: } else {
2868: if ($current =~ /^yes$/i) {
2869: $oldvalue = 1;
2870: }
2871: }
2872: if ($oldvalue ne $newvalue) {
2873: $haschanges = 1;
2874: if ($newvalue) {
2875: my $storeval = 'yes';
2876: if ($which eq 'randompick') {
2877: $storeval = $newvalue;
2878: }
2879: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2880: $storeval,
2881: $parameter_type{$which});
2882: &remember_parms($res,$which,'set',$storeval);
2883: } elsif ($oldvalue) {
2884: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2885: &remember_parms($res,$which,'del');
2886: }
2887: }
2888: }
2889: }
2890: return $haschanges;
1.329 droeschl 2891: } else {
1.484.2.59 raeburn 2892: my $haschanges = 0;
2893: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 2894:
1.484.2.29 raeburn 2895: my $which = $env{'form.changeparms'};
2896: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 2897: my $oldvalue = 0;
2898: my $newvalue = 0;
2899: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2900: if ($which eq 'randompick') {
2901: if ($current =~ /^(\d+)$/) {
2902: $oldvalue = $1;
2903: }
2904: } elsif ($current =~ /^yes$/i) {
2905: $oldvalue = 1;
2906: }
1.484.2.29 raeburn 2907: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 2908: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2909: : 1;
1.484.2.29 raeburn 2910: }
1.484.2.59 raeburn 2911: if ($oldvalue ne $newvalue) {
2912: $haschanges = 1;
2913: if ($newvalue) {
2914: my $storeval = 'yes';
2915: if ($which eq 'randompick') {
2916: $storeval = $newvalue;
2917: }
2918: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2919: $parameter_type{$which});
2920: &remember_parms($idx,$which,'set',$storeval);
2921: } else {
2922: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2923: &remember_parms($idx,$which,'del');
2924: }
2925: }
2926: return $haschanges;
1.329 droeschl 2927: }
1.484.2.59 raeburn 2928: return;
1.329 droeschl 2929: }
2930:
2931: sub handle_edit_cmd {
2932: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 2933: if ($env{'form.cmd'} eq '') {
2934: return 0;
2935: }
1.329 droeschl 2936: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2937:
2938: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2939: my ($title, $url, @rrest) = split(':', $ratstr);
2940:
1.484.2.30 raeburn 2941: if ($cmd eq 'remove') {
1.329 droeschl 2942: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2943: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2944: &Apache::lonnet::removeuploadedurl($url);
2945: } else {
2946: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2947: }
2948: splice(@LONCAPA::map::order, $idx, 1);
2949:
2950: } elsif ($cmd eq 'cut') {
2951: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2952: splice(@LONCAPA::map::order, $idx, 1);
2953:
1.344 bisitz 2954: } elsif ($cmd eq 'up'
1.329 droeschl 2955: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2956: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2957:
2958: } elsif ($cmd eq 'down'
2959: && defined($LONCAPA::map::order[$idx+1])) {
2960: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2961:
2962: } elsif ($cmd eq 'rename') {
2963: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2964: if ($comment=~/\S/) {
2965: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2966: $comment.':'.join(':', $url, @rrest);
2967: }
2968: # Devalidate title cache
2969: my $renamed_url=&LONCAPA::map::qtescape($url);
2970: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 2971:
1.329 droeschl 2972: } else {
2973: return 0;
2974: }
2975: return 1;
2976: }
2977:
2978: sub editor {
1.458 raeburn 2979: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.80 raeburn 2980: $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,
2981: $hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 2982: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2983: if ($allowed) {
2984: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2985: $is_random_order,$container) =
2986: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2987: $r->print($breadcrumbtrail);
2988: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2989: $container = 'page';
2990: } else {
2991: $container = 'sequence';
2992: }
1.484 raeburn 2993:
1.484.2.21 raeburn 2994: my $jumpto;
2995:
2996: unless ($supplementalflag) {
1.484.2.32 raeburn 2997: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 2998: }
1.484 raeburn 2999:
3000: unless ($allowed) {
3001: $randompick = -1;
3002: }
3003:
1.484.2.67 raeburn 3004: my ($errtext,$fatal);
3005: if (($folder eq '') && (!$supplementalflag)) {
3006: if (@LONCAPA::map::order) {
3007: undef(@LONCAPA::map::order);
3008: undef(@LONCAPA::map::resources);
3009: undef(@LONCAPA::map::resparms);
3010: undef(@LONCAPA::map::zombies);
3011: }
3012: $folder = 'default';
3013: $container = 'sequence';
3014: } else {
3015: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3016: $folder.'.'.$container);
3017: return $errtext if ($fatal);
3018: }
1.329 droeschl 3019:
3020: if ($#LONCAPA::map::order<1) {
3021: my $idx=&LONCAPA::map::getresidx();
3022: if ($idx<=0) { $idx=1; }
3023: $LONCAPA::map::order[0]=$idx;
3024: $LONCAPA::map::resources[$idx]='';
3025: }
1.364 bisitz 3026:
1.329 droeschl 3027: # ------------------------------------------------------------ Process commands
3028:
3029: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 3030: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3031: # set parameters and change order
3032: &snapshotbefore();
3033:
3034: if (&update_parameter()) {
1.484.2.59 raeburn 3035: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3036: return $errtext if ($fatal);
3037: }
3038:
3039: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3040: # change order
3041: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3042: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3043:
3044: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3045: return $errtext if ($fatal);
3046: }
1.364 bisitz 3047:
1.329 droeschl 3048: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3049: my %paste_errors;
1.484.2.26 raeburn 3050: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3051: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3052: \%paste_errors);
1.484.2.30 raeburn 3053: if (ref($pastemsgarray) eq 'ARRAY') {
3054: if (@{$pastemsgarray} > 0) {
3055: $r->print('<p class="LC_info">'.
3056: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3057: '</p>');
3058: }
1.484.2.30 raeburn 3059: }
3060: if ($lockerror) {
3061: $r->print('<p class="LC_error">'.
3062: $lockerror.
3063: '</p>');
3064: }
3065: if ($save_error ne '') {
3066: return $save_error;
3067: }
3068: if ($paste_res) {
3069: my %errortext = &Apache::lonlocal::texthash (
3070: fail => 'Storage of folder contents failed',
3071: failread => 'Reading folder contents failed',
3072: failstore => 'Storage of folder contents failed',
3073: );
3074: if ($errortext{$paste_res}) {
3075: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3076: }
1.329 droeschl 3077: }
1.484.2.7 raeburn 3078: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3079: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3080: &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".
3081: '<ul>'."\n");
3082: foreach my $key (sort(keys(%paste_errors))) {
3083: $r->print('<li>'.$key.'</li>'."\n");
3084: }
3085: $r->print('</ul></p>'."\n");
3086: }
1.484.2.30 raeburn 3087: } elsif ($env{'form.clearmarked'}) {
3088: my $output = &do_buffer_empty();
3089: if ($output) {
3090: $r->print('<p class="LC_info">'.$output.'</p>');
3091: }
3092: }
1.329 droeschl 3093:
3094: $r->print($upload_output);
3095:
1.484.2.30 raeburn 3096: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3097: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3098: my $contentchg;
1.484.2.58 raeburn 3099: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3100: $contentchg = 1;
3101: }
3102: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3103: return $errtext if ($fatal);
3104: }
1.484.2.30 raeburn 3105:
3106: # Cut, copy and/or remove multiple resources
3107: if ($env{'form.multichange'}) {
3108: my %allchecked = (
3109: cut => {},
3110: remove => {},
3111: );
3112: my $needsupdate;
3113: foreach my $which (keys(%allchecked)) {
3114: $env{'form.multi'.$which} =~ s/,$//;
3115: if ($env{'form.multi'.$which}) {
3116: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3117: if (ref($allchecked{$which}) eq 'HASH') {
3118: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3119: }
3120: }
3121: }
3122: if ($needsupdate) {
3123: my $haschanges = 0;
3124: my %curr_groups = &Apache::longroup::coursegroups();
3125: my $total = scalar(@LONCAPA::map::order) - 1;
3126: for (my $i=$total; $i>=0; $i--) {
3127: my $res = $LONCAPA::map::order[$i];
3128: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3129: $name=&LONCAPA::map::qtescape($name);
3130: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3131: next unless $url;
1.484.2.30 raeburn 3132: my %denied =
3133: &action_restrictions($coursenum,$coursedom,$url,
3134: $env{'form.folderpath'},\%curr_groups);
3135: foreach my $which (keys(%allchecked)) {
3136: next if ($denied{$which});
3137: next unless ($allchecked{$which}{$res});
3138: if ($which eq 'remove') {
3139: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3140: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3141: &Apache::lonnet::removeuploadedurl($url);
3142: } else {
3143: &LONCAPA::map::makezombie($res);
3144: }
3145: splice(@LONCAPA::map::order,$i,1);
3146: $haschanges ++;
3147: } elsif ($which eq 'cut') {
3148: &LONCAPA::map::makezombie($res);
3149: splice(@LONCAPA::map::order,$i,1);
3150: $haschanges ++;
3151: }
3152: }
3153: }
3154: if ($haschanges) {
3155: ($errtext,$fatal) =
3156: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3157: return $errtext if ($fatal);
3158: }
3159: }
3160: }
3161:
1.329 droeschl 3162: # Group import/search
3163: if ($env{'form.importdetail'}) {
3164: my @imports;
3165: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3166: if (defined($item)) {
3167: my ($name,$url,$residx)=
1.484.2.26 raeburn 3168: map { &unescape($_); } split(/\=/,$item);
3169: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3170: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3171: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3172: if ($locknotfreed) {
3173: $r->print($locknotfreed);
3174: }
3175: if ($suffix) {
1.484.2.19 raeburn 3176: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3177: } else {
3178: return $errortxt;
3179: }
1.484.2.26 raeburn 3180: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3181: my $type = $1;
3182: my ($suffix,$errortxt,$locknotfreed) =
3183: &new_timebased_suffix($coursedom,$coursenum,$type);
3184: if ($locknotfreed) {
3185: $r->print($locknotfreed);
3186: }
3187: if ($suffix) {
3188: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3189: } else {
3190: return $errortxt;
3191: }
1.484.2.27 raeburn 3192: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3193: if ($supplementalflag) {
3194: next unless ($1 eq 'supplemental');
3195: if ($folder eq 'supplemental') {
3196: next unless ($2 eq 'default');
3197: } else {
3198: next unless ($folder eq 'supplemental_'.$2);
3199: }
3200: } else {
3201: next unless ($1 eq 'docs');
3202: if ($folder eq 'default') {
3203: next unless ($2 eq 'default');
3204: } else {
3205: next unless ($folder eq 'default_'.$2);
3206: }
3207: }
1.484.2.15 raeburn 3208: }
1.329 droeschl 3209: push(@imports, [$name, $url, $residx]);
3210: }
3211: }
1.484.2.23 raeburn 3212: ($errtext,$fatal,my $fixuperrors) =
3213: &group_import($coursenum, $coursedom, $folder,$container,
3214: 'londocs',@imports);
1.329 droeschl 3215: return $errtext if ($fatal);
1.484.2.23 raeburn 3216: if ($fixuperrors) {
3217: $r->print($fixuperrors);
3218: }
1.329 droeschl 3219: }
3220: # Loading a complete map
3221: if ($env{'form.loadmap'}) {
3222: if ($env{'form.importmap'}=~/\w/) {
3223: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3224: my ($title,$url,$ext,$type)=split(/\:/,$res);
3225: my $idx=&LONCAPA::map::getresidx($url);
3226: $LONCAPA::map::resources[$idx]=$res;
3227: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3228: }
3229: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3230: $folder.'.'.$container,1);
1.329 droeschl 3231: return $errtext if ($fatal);
3232: } else {
3233: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3234:
1.329 droeschl 3235: }
3236: }
3237: &log_differences($plain);
3238: }
3239: # ---------------------------------------------------------------- End commands
3240: # ---------------------------------------------------------------- Print screen
3241: my $idx=0;
3242: my $shown=0;
3243: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3244: $r->print('<div class="LC_Box">'.
1.432 raeburn 3245: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3246: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3247: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3248: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3249: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3250: '</ol>');
1.381 bisitz 3251: if ($randompick>=0) {
3252: $r->print('<p class="LC_warning">'
3253: .&mt('Caution: this folder is set to randomly pick a subset'
3254: .' of resources. Adding or removing resources from this'
3255: .' folder will change the set of resources that the'
3256: .' students see, resulting in spurious or missing credit'
3257: .' for completed problems, not limited to ones you'
3258: .' modify. Do not modify the contents of this folder if'
3259: .' it is in active student use.')
3260: .'</p>'
3261: );
3262: }
3263: if ($is_random_order) {
3264: $r->print('<p class="LC_warning">'
3265: .&mt('Caution: this folder is set to randomly order its'
3266: .' contents. Adding or removing resources from this folder'
3267: .' will change the order of resources shown.')
3268: .'</p>'
3269: );
3270: }
3271: $r->print('</div>');
1.364 bisitz 3272: }
1.381 bisitz 3273:
1.484.2.30 raeburn 3274: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3275: %filters = (
3276: canremove => [],
3277: cancut => [],
3278: cancopy => [],
3279: hiddenresource => [],
3280: encrypturl => [],
3281: randomorder => [],
3282: randompick => [],
3283: );
3284: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3285: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3286: foreach my $res (@LONCAPA::map::order) {
3287: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3288: $name=&LONCAPA::map::qtescape($name);
3289: $url=&LONCAPA::map::qtescape($url);
3290: unless ($name) { $name=(split(/\//,$url))[-1]; }
3291: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3292: push(@allidx,$res);
3293: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3294: push(@allmapidx,$res);
3295: }
1.484.2.67 raeburn 3296:
1.381 bisitz 3297: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3298: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3299: $pathitem,$supplementalflag,$container,
1.484.2.70 raeburn 3300: \%filters,\%curr_groups,$canedit,
1.484.2.80 raeburn 3301: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3302: $idx++;
3303: $shown++;
1.329 droeschl 3304: }
1.424 onken 3305: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3306:
1.484.2.30 raeburn 3307: my $need_save;
1.484.2.67 raeburn 3308: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3309: my $toolslink;
1.484.2.67 raeburn 3310: if ($allowed) {
1.484.2.31 raeburn 3311: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3312: .&Apache::loncommon::help_open_menu('Navigation Screen',
3313: 'Navigation_Screen',undef,'RAT')
3314: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3315: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3316: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3317: .'id="LC_content_toolbar_edittoplevel" '
3318: .'class="LC_toolbarItem" '
3319: .'title="'.&mt('Supplemental Content Editor').'">'
3320: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3321: }
1.484.2.19 raeburn 3322: if ($shown) {
3323: if ($allowed) {
3324: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3325: .&Apache::loncommon::start_data_table(undef,'contentlist')
3326: .&Apache::loncommon::start_data_table_header_row()
3327: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3328: .'<th colspan="2">'.&mt('Actions').'</th>'
3329: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3330: if ($folder !~ /^supplemental/) {
3331: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3332: }
1.484.2.29 raeburn 3333: $to_show .= &Apache::loncommon::end_data_table_header_row();
3334: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3335: $lists{'canhide'} = join(',',@allidx);
3336: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3337: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3338: 'randomorder','randompick');
3339: foreach my $item (@possfilters) {
3340: if (ref($filters{$item}) eq 'ARRAY') {
3341: if (@{$filters{$item}} > 0) {
3342: $lists{$item} = join(',',@{$filters{$item}});
3343: }
3344: }
3345: }
1.484.2.29 raeburn 3346: if (@allidx > 0) {
3347: my $path;
3348: if ($env{'form.folderpath'}) {
3349: $path =
3350: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3351: }
1.484.2.30 raeburn 3352: if (@allidx > 1) {
3353: $to_show .=
3354: &Apache::loncommon::continue_data_table_row().
3355: '<td colspan="2"> </td>'.
3356: '<td>'.
1.484.2.67 raeburn 3357: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3358: '</td>'.
3359: '<td> </td>'.
3360: '<td> </td>'.
3361: '<td colspan="4">'.
1.484.2.67 raeburn 3362: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3363: '</td>'.
3364: &Apache::loncommon::end_data_table_row();
3365: $need_save = 1;
3366: }
1.484.2.29 raeburn 3367: }
3368: }
3369: $to_show .= $output.' '
1.484.2.19 raeburn 3370: .&Apache::loncommon::end_data_table()
3371: .'<br style="line-height:2px;" />'
3372: .&Apache::loncommon::end_scrollbox();
3373: } else {
3374: $to_show .= $toolslink
3375: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3376: .$output.' '
3377: .&Apache::loncommon::end_data_table();
3378: }
3379: } else {
3380: if (!$allowed) {
3381: $to_show .= $toolslink;
1.393 raeburn 3382: }
1.484.2.67 raeburn 3383: my $noresmsg;
3384: if ($allowed && $hiddentop && !$supplementalflag) {
3385: $noresmsg = &mt('Main Content Hidden');
3386: } else {
3387: $noresmsg = &mt('Currently empty');
3388: }
1.484.2.19 raeburn 3389: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3390: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3391: .$noresmsg
1.484.2.19 raeburn 3392: .'</div>'
3393: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3394: }
3395: } else {
1.484.2.19 raeburn 3396: if ($shown) {
3397: $to_show = '<div>'
3398: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3399: .$output
3400: .&Apache::loncommon::end_data_table()
3401: .'</div>';
3402: } else {
3403: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3404: .&mt('Currently empty')
1.484.2.19 raeburn 3405: .'</div>'
3406: }
1.458 raeburn 3407: }
3408: my $tid = 1;
3409: if ($supplementalflag) {
3410: $tid = 2;
1.329 droeschl 3411: }
3412: if ($allowed) {
1.484 raeburn 3413: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3414: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3415: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3416: if ($canedit) {
1.484.2.67 raeburn 3417: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3418: }
1.460 raeburn 3419: } else {
3420: $r->print($to_show);
1.329 droeschl 3421: }
3422: return;
3423: }
3424:
1.484.2.30 raeburn 3425: sub multiple_check_form {
1.484.2.67 raeburn 3426: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3427: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3428: my $disabled;
3429: unless ($canedit) {
3430: $disabled = 'disabled="disabled"';
3431: }
1.484.2.30 raeburn 3432: my $output =
3433: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3434: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3435: '<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>'.
3436: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3437: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3438: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3439: if ($caller eq 'settings') {
3440: $output .=
3441: '<table><tr>'.
3442: '<td class="LC_docs_entry_parameter">'.
3443: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3444: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3445: '</label></span></td>'.
3446: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3447: '<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 3448: '</span></td>'.
3449: '</tr>'."\n".
3450: '<tr>'.
3451: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3452: '<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 3453: '</label></span>'.
3454: '</td></tr></table>'."\n";
3455: } else {
3456: $output .=
3457: '<table><tr>'.
3458: '<td class="LC_docs_entry_parameter">'.
3459: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3460: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3461: '</label></span></td>'.
3462: '<td class="LC_docs_entry_parameter">'.
3463: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3464: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3465: '</label></span></td>'."\n".
3466: '<td class="LC_docs_entry_parameter">'.
3467: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3468: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3469: '</label></span></td>'.
3470: '</tr></table>'."\n";
3471: }
3472: $output .=
3473: '</fieldset>'.
3474: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3475: if ($caller eq 'settings') {
3476: $output .=
3477: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3478: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3479: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3480: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3481: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3482: } elsif ($caller eq 'actions') {
3483: $output .=
3484: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3485: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3486: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3487: }
3488: $output .=
3489: '</form>'.
3490: '</div>';
3491: return $output;
3492: }
3493:
1.329 droeschl 3494: sub process_file_upload {
1.484.2.36 raeburn 3495: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3496: # upload a file, if present
1.484.2.36 raeburn 3497: my $filesize = length($env{'form.uploaddoc'});
3498: if (!$filesize) {
3499: $$upload_output = '<div class="LC_error">'.
3500: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3501: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3502: $filesize).'<br />'.
3503: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3504: '</div>';
3505: return;
3506: }
3507: my $quotatype = 'unofficial';
3508: if ($crstype eq 'Community') {
3509: $quotatype = 'community';
1.484.2.51 raeburn 3510: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3511: $quotatype = 'official';
1.484.2.45 raeburn 3512: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3513: $quotatype = 'textbook';
1.484.2.36 raeburn 3514: }
3515: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3516: $filesize = int($filesize/1000); #expressed in kb
3517: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3518: $env{'form.uploaddoc.filename'},$filesize,
3519: 'upload',$quotatype);
1.484.2.36 raeburn 3520: return if ($$upload_output);
3521: }
1.440 raeburn 3522: my ($parseaction,$showupload,$nextphase,$mimetype);
3523: if ($env{'form.parserflag'}) {
1.329 droeschl 3524: $parseaction = 'parse';
3525: }
3526: my $folder=$env{'form.folder'};
3527: if ($folder eq '') {
3528: $folder='default';
3529: }
3530: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3531: my $errtext='';
3532: my $fatal=0;
3533: my $container='sequence';
1.484.2.19 raeburn 3534: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3535: $container='page';
3536: }
3537: ($errtext,$fatal)=
1.484.2.27 raeburn 3538: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3539: if ($#LONCAPA::map::order<1) {
3540: $LONCAPA::map::order[0]=1;
3541: $LONCAPA::map::resources[1]='';
3542: }
3543: my $destination = 'docs/';
3544: if ($folder =~ /^supplemental/) {
3545: $destination = 'supplemental/';
3546: }
3547: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3548: $destination .= 'default/';
3549: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3550: $destination .= $2.'/';
3551: }
1.484.2.27 raeburn 3552: if ($fatal) {
3553: $$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>';
3554: return;
3555: }
1.440 raeburn 3556: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3557: my $newidx=&LONCAPA::map::getresidx();
3558: $destination .= $newidx;
1.439 raeburn 3559: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3560: $parseaction,$allfiles,
1.440 raeburn 3561: $codebase,undef,undef,undef,undef,
3562: undef,undef,\$mimetype);
3563: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3564: my $stored = $1;
3565: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3566: $stored.'</span>').'</p>';
3567: } else {
3568: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3569:
1.457 raeburn 3570: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3571: return;
3572: }
1.329 droeschl 3573: my $ext='false';
3574: if ($url=~m{^http://}) { $ext='true'; }
3575: $url = &LONCAPA::map::qtunescape($url);
3576: my $comment=$env{'form.comment'};
3577: $comment = &LONCAPA::map::qtunescape($comment);
3578: if ($folder=~/^supplemental/) {
3579: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3580: $env{'user.domain'}.'___&&&___'.$comment;
3581: }
3582:
3583: $LONCAPA::map::resources[$newidx]=
3584: $comment.':'.$url.':'.$ext.':normal:res';
3585: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3586: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3587: $folder.'.'.$container,1);
1.329 droeschl 3588: if ($fatal) {
1.457 raeburn 3589: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3590: return;
1.329 droeschl 3591: } else {
1.440 raeburn 3592: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3593: $$upload_output = $showupload;
1.384 raeburn 3594: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3595: if ($total_embedded > 0) {
1.440 raeburn 3596: my $uploadphase = 'upload_embedded';
3597: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3598: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3599: my ($embedded,$num) =
3600: &Apache::loncommon::ask_for_embedded_content(
3601: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3602: if ($embedded) {
3603: if ($num) {
3604: $$upload_output .=
3605: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3606: $nextphase = $uploadphase;
3607: } else {
3608: $$upload_output .= $embedded;
3609: }
3610: } else {
3611: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3612: }
1.329 droeschl 3613: } else {
1.440 raeburn 3614: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3615: }
1.457 raeburn 3616: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3617: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3618: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3619: $nextphase = 'decompress_uploaded';
3620: my $position = scalar(@LONCAPA::map::order)-1;
3621: my $noextract = &return_to_editor();
3622: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3623: my %archiveitems = (
3624: folderpath => $env{'form.folderpath'},
3625: cmd => $nextphase,
3626: newidx => $newidx,
3627: position => $position,
3628: phase => $nextphase,
1.477 raeburn 3629: comment => $comment,
1.480 raeburn 3630: );
3631: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3632: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3633: $$upload_output = $showupload.
3634: &Apache::loncommon::decompress_form($mimetype,
3635: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3636: \%archiveitems,\@current);
1.329 droeschl 3637: }
3638: }
3639: }
1.440 raeburn 3640: return $nextphase;
1.329 droeschl 3641: }
3642:
1.480 raeburn 3643: sub get_dir_list {
3644: my ($url,$coursenum,$coursedom,$newidx) = @_;
3645: my ($destination,$dir_root) = &embedded_destination();
3646: my ($dirlistref,$listerror) =
3647: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3648: my @dir_lines;
3649: my $dirptr=16384;
3650: if (ref($dirlistref) eq 'ARRAY') {
3651: foreach my $dir_line (sort
3652: {
3653: my ($afile)=split('&',$a,2);
3654: my ($bfile)=split('&',$b,2);
3655: return (lc($afile) cmp lc($bfile));
3656: } (@{$dirlistref})) {
3657: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3658: $filename =~ s/\s+$//;
3659: next if ($filename =~ /^\.\.?$/);
3660: my $isdir = 0;
3661: if ($dirptr&$testdir) {
3662: $isdir = 1;
3663: }
3664: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3665: }
3666: }
3667: return @dir_lines;
3668: }
3669:
1.329 droeschl 3670: sub is_supplemental_title {
3671: my ($title) = @_;
3672: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3673: }
3674:
3675: # --------------------------------------------------------------- An entry line
3676:
3677: sub entryline {
1.484.2.12 raeburn 3678: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3679: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.80 raeburn 3680: $canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3681: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3682: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3683: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3684: } else {
3685: $title=&HTML::Entities::encode($title,'"<>&\'');
3686: $renametitle=$title;
3687: $foldertitle=$title;
3688: }
3689:
1.484.2.67 raeburn 3690: my ($disabled,$readonly,$js_lt);
3691: unless ($canedit) {
3692: $disabled = 'disabled="disabled"';
3693: $readonly = 1;
3694: }
3695:
1.329 droeschl 3696: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3697:
1.329 droeschl 3698: $renametitle=~s/\\/\\\\/g;
3699: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3700: $renametitle=~s/"/%22/g;
1.329 droeschl 3701: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3702: $oldtitle = $renametitle;
3703: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3704: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3705: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3706: # Edit commands
1.484.2.28 raeburn 3707: my ($esc_path, $path, $symb);
1.329 droeschl 3708: if ($env{'form.folderpath'}) {
3709: $esc_path=&escape($env{'form.folderpath'});
3710: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3711: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3712: }
1.484.2.16 raeburn 3713: my $isexternal;
1.484.2.19 raeburn 3714: if ($residx) {
1.484.2.12 raeburn 3715: my $currurl = $url;
3716: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3717: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3718: $isexternal = 1;
3719: }
1.484.2.19 raeburn 3720: if (!$supplementalflag) {
3721: my $path = 'uploaded/'.
3722: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3723: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3724: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3725: $residx,
3726: &Apache::lonnet::declutter($currurl));
3727: }
1.484.2.12 raeburn 3728: }
1.484.2.30 raeburn 3729: my ($renamelink,%lt,$ishash);
3730: if (ref($filtersref) eq 'HASH') {
3731: $ishash = 1;
3732: }
3733:
1.329 droeschl 3734: if ($allowed) {
1.484.2.30 raeburn 3735: $form_start = '
3736: <form action="/adm/coursedocs" method="post">
3737: ';
3738: $form_common=(<<END);
3739: <input type="hidden" name="folderpath" value="$path" />
3740: <input type="hidden" name="symb" value="$symb" />
3741: END
3742: $form_param=(<<END);
3743: <input type="hidden" name="setparms" value="$orderidx" />
3744: <input type="hidden" name="changeparms" value="0" />
3745: END
3746: $form_end = '</form>';
3747:
1.329 droeschl 3748: my $incindex=$index+1;
3749: my $selectbox='';
1.471 raeburn 3750: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3751: ((split(/\:/,
1.344 bisitz 3752: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3753: ne '') &&
1.329 droeschl 3754: ((split(/\:/,
1.344 bisitz 3755: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3756: ne '')) {
3757: $selectbox=
3758: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3759: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3760: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3761: if ($i==$incindex) {
1.358 bisitz 3762: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3763: } else {
3764: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3765: }
3766: }
3767: $selectbox.='</select>';
3768: }
1.484.2.12 raeburn 3769: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3770: 'up' => 'Move Up',
3771: 'dw' => 'Move Down',
3772: 'rm' => 'Remove',
3773: 'ct' => 'Cut',
3774: 'rn' => 'Rename',
1.484.2.12 raeburn 3775: 'cp' => 'Copy',
3776: 'ex' => 'External Resource',
3777: 'ed' => 'Edit',
3778: 'pr' => 'Preview',
3779: 'sv' => 'Save',
3780: 'ul' => 'URL',
1.484.2.67 raeburn 3781: 'ti' => 'Title',
3782: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3783: );
1.484.2.30 raeburn 3784: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3785: $env{'form.folderpath'},
3786: $currgroups);
1.484.2.19 raeburn 3787: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3788: my $skip_confirm = 0;
1.484.2.63 raeburn 3789: my $confirm_removal = 0;
1.329 droeschl 3790: if ( $folder =~ /^supplemental/
3791: || ($url =~ m{( /smppg$
3792: |/syllabus$
3793: |/aboutme$
3794: |/navmaps$
3795: |/bulletinboard$
1.484.2.16 raeburn 3796: |\.html$)}x)
1.484.2.19 raeburn 3797: || $isexternal) {
1.329 droeschl 3798: $skip_confirm = 1;
3799: }
1.484.2.63 raeburn 3800: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3801: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3802: $confirm_removal = 1;
3803: }
1.484.2.19 raeburn 3804:
1.484.2.30 raeburn 3805: if ($denied{'copy'}) {
3806: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3807: <span style="visibility: hidden;">$lt{'cp'}</span>
3808: ENDCOPY
3809: } else {
1.484.2.30 raeburn 3810: my $formname = 'edit_copy_'.$orderidx;
3811: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3812: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3813: <form name="$formname" method="post" action="/adm/coursedocs">
3814: $form_common
1.484.2.67 raeburn 3815: <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 3816: $form_end
1.329 droeschl 3817: ENDCOPY
1.484.2.30 raeburn 3818: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3819: push(@{$filtersref->{'cancopy'}},$orderidx);
3820: }
1.329 droeschl 3821: }
1.484.2.30 raeburn 3822: if ($denied{'cut'}) {
1.484.2.16 raeburn 3823: $cutlink=(<<ENDCUT);
3824: <span style="visibility: hidden;">$lt{'ct'}</span>
3825: ENDCUT
3826: } else {
1.484.2.30 raeburn 3827: my $formname = 'edit_cut_'.$orderidx;
3828: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3829: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3830: <form name="$formname" method="post" action="/adm/coursedocs">
3831: $form_common
3832: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3833: <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 3834: $form_end
1.329 droeschl 3835: ENDCUT
1.484.2.30 raeburn 3836: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3837: push(@{$filtersref->{'cancut'}},$orderidx);
3838: }
1.329 droeschl 3839: }
1.484.2.30 raeburn 3840: if ($denied{'remove'}) {
1.484.2.16 raeburn 3841: $removelink=(<<ENDREM);
3842: <span style="visibility: hidden;">$lt{'rm'}</a>
3843: ENDREM
3844: } else {
1.484.2.30 raeburn 3845: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3846: 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 3847: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3848: <form name="$formname" method="post" action="/adm/coursedocs">
3849: $form_common
3850: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3851: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3852: <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 3853: $form_end
1.484.2.9 raeburn 3854: ENDREM
1.484.2.30 raeburn 3855: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3856: push(@{$filtersref->{'canremove'}},$orderidx);
3857: }
1.484.2.9 raeburn 3858: }
1.484.2.35 raeburn 3859: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3860: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3861: ENDREN
1.484.2.67 raeburn 3862: my ($uplink,$downlink);
3863: if ($canedit) {
3864: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3865: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3866: } else {
3867: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3868: $downlink = $uplink;
3869: }
1.329 droeschl 3870: $line.=(<<END);
3871: <td>
1.379 bisitz 3872: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3873: <a href="$uplink">
1.484.2.12 raeburn 3874: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3875: </a>
3876: </div>
3877: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3878: <a href="$downlink">
1.484.2.12 raeburn 3879: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3880: </a>
3881: </div>
1.329 droeschl 3882: </td>
3883: <td>
3884: $form_start
1.484.2.30 raeburn 3885: $form_param
1.478 raeburn 3886: $form_common
1.329 droeschl 3887: $selectbox
3888: $form_end
3889: </td>
1.484.2.30 raeburn 3890: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3891: $removelink
1.329 droeschl 3892: $cutlink
3893: $copylink
3894: </td>
3895: END
3896: }
3897: # Figure out what kind of a resource this is
3898: my ($extension)=($url=~/\.(\w+)$/);
3899: my $uploaded=($url=~/^\/*uploaded\//);
3900: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3901: my $isfolder;
3902: my $ispage;
3903: my $containerarg;
1.484.2.67 raeburn 3904: my $folderurl;
1.329 droeschl 3905: if ($uploaded) {
1.472 raeburn 3906: if (($extension eq 'sequence') || ($extension eq 'page')) {
3907: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3908: $containerarg = $1;
1.472 raeburn 3909: if ($extension eq 'sequence') {
3910: $icon=$iconpath.'navmap.folder.closed.gif';
3911: $isfolder=1;
3912: } else {
3913: $icon=$iconpath.'page.gif';
3914: $ispage=1;
3915: }
1.484.2.67 raeburn 3916: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3917: if ($allowed) {
3918: $url='/adm/coursedocs?';
3919: } else {
3920: $url='/adm/supplemental?';
3921: }
1.329 droeschl 3922: } else {
3923: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3924: }
3925: }
1.364 bisitz 3926:
1.484.2.70 raeburn 3927: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3928: my $orig_url = $url;
1.340 raeburn 3929: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 3930: if ($container eq 'page') {
3931: $url=~s{^http(|s)(:|:)//}{/ext/};
3932: } else {
3933: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3934: }
1.484.2.12 raeburn 3935: if (!$supplementalflag && $residx && $symb) {
3936: if ((!$isfolder) && (!$ispage)) {
3937: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.87 raeburn 3938: if (($url =~ m{^ext/}) && ($container eq 'page')) {
3939: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
3940: } else {
3941: $url=&Apache::lonnet::clutter($url);
3942: }
1.484.2.12 raeburn 3943: if ($url=~/^\/*uploaded\//) {
3944: $url=~/\.(\w+)$/;
3945: my $embstyle=&Apache::loncommon::fileembstyle($1);
3946: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3947: $url='/adm/wrapper'.$url;
3948: } elsif ($embstyle eq 'ssi') {
3949: #do nothing with these
3950: } elsif ($url!~/\.(sequence|page)$/) {
3951: $url='/adm/coursedocs/showdoc'.$url;
3952: }
1.484.2.70 raeburn 3953: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
3954: my $wrapped = $1;
3955: my $exturl = $2;
1.484.2.87 raeburn 3956: if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 3957: $url='/adm/wrapper'.$url;
3958: }
3959: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
3960: $nomodal = 1;
3961: }
3962: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3963: if (($ENV{'SERVER_PORT'} == 443) &&
3964: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 3965: unless (&Apache::lonnet::uses_sts()) {
3966: $url .= '?usehttp=1';
3967: }
1.484.2.70 raeburn 3968: $nomodal = 1;
3969: }
1.484.2.19 raeburn 3970: }
1.484.2.12 raeburn 3971: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3972: my $shownsymb = $symb;
3973: if ($isexternal) {
1.484.2.88 raeburn 3974: $url =~ s/\#[^#]+$//;
1.484.2.87 raeburn 3975: if ($container eq 'page') {
3976: $url = &Apache::lonnet::clutter($url);
3977: }
1.484.2.66 raeburn 3978: }
1.484.2.67 raeburn 3979: unless ($env{'request.role.adv'}) {
3980: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3981: $url = '';
3982: }
3983: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3984: $url = '';
3985: $hiddenres = 1;
3986: }
3987: }
3988: if ($url ne '') {
1.484.2.75 raeburn 3989: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3990: }
3991: } elsif (!$env{'request.role.adv'}) {
3992: my $checkencrypt;
3993: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3994: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3995: $checkencrypt = 1;
1.484.2.70 raeburn 3996: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3997: unless (ref($$navmapref)) {
3998: $$navmapref = Apache::lonnavmaps::navmap->new();
3999: }
4000: if (ref($$navmapref)) {
4001: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4002: $checkencrypt = 1;
4003: }
4004: }
4005: }
4006: if ($checkencrypt) {
4007: my $shownsymb = &Apache::lonenc::encrypted($symb);
4008: my $shownurl = &Apache::lonenc::encrypted($url);
4009: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 4010: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 4011: if ($env{'request.enc'} ne '') {
4012: delete($env{'request.enc'});
4013: }
4014: } else {
4015: $url='';
4016: }
4017: } else {
4018: $url='';
4019: }
1.484.2.12 raeburn 4020: } else {
4021: $url='';
4022: }
1.484.2.19 raeburn 4023: }
1.484.2.66 raeburn 4024: } elsif ($supplementalflag) {
4025: if ($isexternal) {
4026: if ($url =~ /^([^#]+)#([^#]+)$/) {
4027: $url = $1;
4028: $anchor = $2;
1.484.2.70 raeburn 4029: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.80 raeburn 4030: unless (&Apache::lonnet::uses_sts()) {
4031: if ($hostname ne '') {
4032: $url = 'http://'.$hostname.$url;
4033: }
4034: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4035: }
1.484.2.70 raeburn 4036: $nomodal = 1;
4037: }
4038: }
4039: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4040: if (($ENV{'SERVER_PORT'} == 443) &&
4041: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 4042: unless (&Apache::lonnet::uses_sts()) {
4043: if ($hostname ne '') {
4044: $url = 'http://'.$hostname.$url;
4045: }
4046: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4047: }
1.484.2.70 raeburn 4048: $nomodal = 1;
1.484.2.66 raeburn 4049: }
4050: }
1.329 droeschl 4051: }
1.484.2.67 raeburn 4052: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4053: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4054: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4055: my $foldername=&escape($foldertitle);
4056: my $folderpath=$env{'form.folderpath'};
4057: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4058: if (!$allowed && $supplementalflag) {
4059: $folderpath.=$containerarg.'&'.$foldername;
4060: $url.='folderpath='.&escape($folderpath);
4061: } else {
4062: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4063: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4064: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4065: 'parameter_randomorder'))[0]=~/^yes$/i);
4066: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4067: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4068: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4069: 'parameter_encrypturl'))[0]=~/^yes$/i);
4070: unless ($hiddenmap) {
1.484.2.70 raeburn 4071: if (ref($navmapref)) {
4072: unless (ref($$navmapref)) {
4073: $$navmapref = Apache::lonnavmaps::navmap->new();
4074: }
4075: if (ref($$navmapref)) {
4076: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4077: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4078: unless (@resources) {
4079: $hiddenmap = 1;
4080: unless ($env{'request.role.adv'}) {
4081: $url = '';
4082: $hiddenfolder = 1;
4083: }
1.484.2.67 raeburn 4084: }
4085: }
4086: }
4087: }
4088: }
4089: unless ($encryptmap) {
1.484.2.70 raeburn 4090: if ((ref($navmapref)) && (ref($$navmapref))) {
4091: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4092: $encryptmap = 1;
4093: }
1.484.2.67 raeburn 4094: }
4095: }
4096:
4097: # Append randompick number, hidden, and encrypted with ":" to foldername,
4098: # so it gets transferred between levels
4099: $folderpath.=$containerarg.'&'.$foldername.
4100: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4101: unless ($url eq '') {
4102: $url.='folderpath='.&escape($folderpath);
4103: }
1.484.2.19 raeburn 4104: my $rpckchk;
4105: if ($rpicknum) {
4106: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4107: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4108: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4109: }
1.484.2.19 raeburn 4110: }
1.484.2.29 raeburn 4111: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4112: $rand_pick_text =
1.478 raeburn 4113: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4114: $form_param."\n".
1.478 raeburn 4115: $form_common."\n".
1.484.2.67 raeburn 4116: '<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 4117: if ($rpicknum ne '') {
4118: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4119: }
1.484.2.29 raeburn 4120: $rand_pick_text .= '</span></span>'.
4121: $form_end;
1.484.2.30 raeburn 4122: my $ro_set;
1.484.2.67 raeburn 4123: if ($randorder) {
1.484.2.30 raeburn 4124: $ro_set = 'checked="checked"';
4125: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4126: push(@{$filtersref->{'randomorder'}},$orderidx);
4127: }
4128: }
1.484.2.41 raeburn 4129: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4130: $rand_order_text =
1.484.2.29 raeburn 4131: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4132: $form_param."\n".
1.484.2.29 raeburn 4133: $form_common."\n".
1.484.2.67 raeburn 4134: '<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 4135: $form_end;
1.484.2.19 raeburn 4136: }
1.484.2.18 raeburn 4137: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 4138: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4139: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4140: if ($title) {
4141: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4142: }
4143: if ($isexternal && $orderidx) {
4144: $url .= '&idx='.$orderidx;
4145: }
1.484.2.66 raeburn 4146: if ($anchor ne '') {
4147: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4148: }
1.329 droeschl 4149: }
1.484.2.19 raeburn 4150: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4151: if ($allowed) {
1.484.2.19 raeburn 4152: my $fileloc =
1.484.2.12 raeburn 4153: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4154: if ($isexternal) {
4155: ($editlink,$extresform) =
1.484.2.67 raeburn 4156: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4157: undef,undef,undef,$disabled);
1.484.2.19 raeburn 4158: } elsif (!$isfolder && !$ispage) {
4159: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4160: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4161: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4162: my $suppanchor;
4163: if ($supplementalflag) {
4164: $suppanchor = $anchor;
4165: }
1.484.2.19 raeburn 4166: my $jscall =
1.484.2.12 raeburn 4167: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4168: $switchserver,
1.484.2.14 raeburn 4169: $forceedit,
1.484.2.19 raeburn 4170: undef,$symb,
4171: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4172: $renametitle,$hostname,
4173: '','',1,$suppanchor);
1.484.2.12 raeburn 4174: if ($jscall) {
1.484.2.19 raeburn 4175: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4176: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4177: }
4178: }
4179: }
1.484.2.19 raeburn 4180: $tdalign = ' align="right" valign="top"';
4181: $tdwidth = ' width="80%"';
1.329 droeschl 4182: }
1.408 raeburn 4183: my $reinit;
4184: if ($crstype eq 'Community') {
4185: $reinit = &mt('(re-initialize community to access)');
4186: } else {
4187: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4188: }
4189: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4190: my $link;
1.472 raeburn 4191: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4192: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4193: } elsif ($url) {
1.484.2.66 raeburn 4194: if ($anchor ne '') {
4195: if ($supplementalflag) {
4196: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4197: } else {
4198: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4199: }
4200: }
1.484.2.80 raeburn 4201:
4202: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4203: $link = 'http://'.$hostname.$url;
4204: } else {
4205: $link = $url;
4206: }
4207: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4208: if ($nomodal) {
4209: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4210: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4211: } else {
4212: $line.=&Apache::loncommon::modal_link($link,
4213: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4214: }
1.469 www 4215: } else {
4216: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4217: }
1.484.2.19 raeburn 4218: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4219: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4220: $line.='<a href="'.$url.'">'.$title.'</a>';
4221: } elsif ($url) {
1.484.2.70 raeburn 4222: if ($nomodal) {
4223: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4224: $title.'</a>';
4225: } else {
4226: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4227: }
1.484.2.67 raeburn 4228: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4229: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4230: } else {
4231: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4232: }
1.484.2.19 raeburn 4233: $line.="$extresform</td>";
1.478 raeburn 4234: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4235: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4236: if (($allowed) && ($folder!~/^supplemental/)) {
4237: my %lt=&Apache::lonlocal::texthash(
4238: 'hd' => 'Hidden',
4239: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4240: my ($enctext,$hidtext);
4241: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4242: $enctext = ' checked="checked"';
4243: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4244: push(@{$filtersref->{'encrypturl'}},$orderidx);
4245: }
4246: }
4247: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4248: $hidtext = ' checked="checked"';
4249: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4250: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4251: }
4252: }
1.484.2.29 raeburn 4253: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4254: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4255: $line.=(<<ENDPARMS);
4256: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4257: <form action="/adm/coursedocs" method="post" name="$formhidden">
4258: $form_param
1.478 raeburn 4259: $form_common
1.484.2.67 raeburn 4260: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4261: $form_end
1.458 raeburn 4262: <br />
1.484.2.29 raeburn 4263: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4264: $form_param
1.478 raeburn 4265: $form_common
1.484.2.67 raeburn 4266: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4267: $form_end
4268: </td>
1.478 raeburn 4269: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4270: $rand_order_text</td>
1.329 droeschl 4271: ENDPARMS
4272: }
1.379 bisitz 4273: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4274: return $line;
4275: }
4276:
1.484.2.30 raeburn 4277: sub action_restrictions {
4278: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4279: my %denied = (
4280: cut => 0,
4281: copy => 0,
4282: remove => 0,
4283: );
4284: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4285: # no copy for published maps
4286: $denied{'copy'} = 1;
1.484.2.82 raeburn 4287: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4288: unless ($1 eq 'simpleproblem') {
4289: $denied{'copy'} = 1;
4290: }
4291: $denied{'cut'} = 1;
1.484.2.30 raeburn 4292: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4293: if ($folderpath =~ /^default&[^\&]+$/) {
4294: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4295: $denied{'remove'} = 1;
4296: }
4297: $denied{'cut'} = 1;
4298: $denied{'copy'} = 1;
4299: }
4300: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4301: my $group = $1;
4302: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4303: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4304: $denied{'remove'} = 1;
4305: }
4306: }
4307: $denied{'cut'} = 1;
4308: $denied{'copy'} = 1;
4309: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4310: my $group = $1;
4311: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4312: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4313: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4314: if (keys(%groupsettings) > 0) {
4315: $denied{'remove'} = 1;
4316: }
4317: $denied{'cut'} = 1;
4318: $denied{'copy'} = 1;
4319: }
4320: }
4321: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4322: my $group = $1;
4323: if ($url =~ /group_boards_\Q$group\E/) {
4324: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4325: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4326: if (keys(%groupsettings) > 0) {
4327: if (ref($groupsettings{'functions'}) eq 'HASH') {
4328: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4329: $denied{'remove'} = 1;
4330: }
4331: }
4332: }
4333: $denied{'cut'} = 1;
4334: $denied{'copy'} = 1;
4335: }
4336: }
4337: }
4338: return %denied;
4339: }
4340:
1.484.2.26 raeburn 4341: sub new_timebased_suffix {
1.484.2.30 raeburn 4342: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4343: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4344: if ($type eq 'paste') {
4345: $prefix = $type;
4346: $namespace = 'courseeditor';
1.484.2.56 raeburn 4347: $idtype = 'addcode';
1.484.2.30 raeburn 4348: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4349: $prefix = 'docs';
4350: if ($area eq 'supplemental') {
4351: $prefix = 'supp';
4352: }
4353: $prefix .= $container;
4354: $namespace = 'uploadedmaps';
4355: } else {
4356: $prefix = $type;
4357: $namespace = 'templated';
1.484.2.15 raeburn 4358: }
4359: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4360: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4361: if (!$suffix) {
1.484.2.30 raeburn 4362: if ($type eq 'paste') {
4363: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4364: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4365: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4366: } elsif ($type eq 'smppg') {
4367: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4368: } else {
1.484.2.42 raeburn 4369: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4370: }
1.484.2.15 raeburn 4371: if ($error) {
4372: $errtext .= '<br />'.$error;
4373: }
4374: }
4375: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4376: $locknotfreed =
4377: '<div class="LC_error">'.
4378: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4379: if ($type eq 'paste') {
1.484.2.57 raeburn 4380: if ($freedlock eq 'nolock') {
4381: $locknotfreed =
4382: '<div class="LC_error">'.
4383: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4384:
1.484.2.60 raeburn 4385: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4386: } else {
4387: $locknotfreed .=
4388: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4389: }
1.484.2.30 raeburn 4390: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4391: $locknotfreed .=
4392: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4393: } elsif ($type eq 'smppg') {
4394: $locknotfreed .=
4395: &mt('This will prevent creation of additional simple pages in this course.');
4396: } else {
4397: $locknotfreed .=
1.484.2.42 raeburn 4398: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4399: }
1.484.2.30 raeburn 4400: unless ($type eq 'paste') {
4401: $locknotfreed .=
1.484.2.38 raeburn 4402: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4403: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4404: }
4405: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4406: }
4407: return ($suffix,$errtext,$locknotfreed);
4408: }
4409:
1.329 droeschl 4410: =pod
4411:
4412: =item tiehash()
4413:
4414: tie the hash
4415:
4416: =cut
4417:
4418: sub tiehash {
4419: my ($mode)=@_;
4420: $hashtied=0;
4421: if ($env{'request.course.fn'}) {
4422: if ($mode eq 'write') {
4423: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4424: &GDBM_WRCREAT(),0640)) {
4425: $hashtied=2;
4426: }
4427: } else {
4428: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4429: &GDBM_READER(),0640)) {
4430: $hashtied=1;
4431: }
4432: }
1.364 bisitz 4433: }
1.329 droeschl 4434: }
4435:
4436: sub untiehash {
4437: if ($hashtied) { untie %hash; }
4438: $hashtied=0;
4439: return OK;
4440: }
4441:
4442:
4443:
4444:
4445: sub checkonthis {
1.484.2.78 raeburn 4446: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4447: $url=&unescape($url);
4448: $alreadyseen{$url}=1;
4449: $r->rflush();
4450: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4451: $r->print("\n<br />");
4452: if ($level==0) {
4453: $r->print("<br />");
4454: }
4455: for (my $i=0;$i<=$level*5;$i++) {
4456: $r->print(' ');
4457: }
4458: $r->print('<a href="'.$url.'" target="cat">'.
4459: ($title?$title:$url).'</a> ');
4460: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4461: my $updated;
4462: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4463: ($url !~ /\.\d+\.\w+$/)) {
4464: $updated = &Apache::lonnet::remove_stale_resfile($url);
4465: }
1.329 droeschl 4466: my $result=&Apache::lonnet::repcopy(
4467: &Apache::lonnet::filelocation('',$url));
4468: if ($result eq 'ok') {
4469: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4470: if ($updated) {
4471: $r->print('<br />');
4472: for (my $i=0;$i<=$level*5;$i++) {
4473: $r->print(' ');
4474: }
4475: $r->print('- '.&mt('Outdated copy removed'));
4476: }
1.329 droeschl 4477: $r->rflush();
4478: &Apache::lonnet::countacc($url);
4479: $url=~/\.(\w+)$/;
4480: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4481: $r->print('<br />');
4482: $r->rflush();
4483: for (my $i=0;$i<=$level*5;$i++) {
4484: $r->print(' ');
4485: }
4486: $r->print('- '.&mt('Rendering:').' ');
4487: my ($errorcount,$warningcount)=split(/:/,
4488: &Apache::lonnet::ssi_body($url,
4489: ('grade_target'=>'web',
4490: 'return_only_error_and_warning_counts' => 1)));
4491: if (($errorcount) ||
4492: ($warningcount)) {
4493: if ($errorcount) {
1.369 bisitz 4494: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4495: &mt('[quant,_1,error]',$errorcount).'</span>');
4496: }
4497: if ($warningcount) {
4498: $r->print('<span class="LC_warning">'.
4499: &mt('[quant,_1,warning]',$warningcount).'</span>');
4500: }
4501: } else {
4502: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4503: }
4504: $r->rflush();
4505: }
4506: my $dependencies=
4507: &Apache::lonnet::metadata($url,'dependencies');
4508: foreach my $dep (split(/\,/,$dependencies)) {
4509: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4510: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4511: }
4512: }
4513: } elsif ($result eq 'unavailable') {
4514: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4515: } elsif ($result eq 'not_found') {
4516: unless ($url=~/\$/) {
1.484.2.19 raeburn 4517: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4518: } else {
1.366 bisitz 4519: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4520: }
4521: } else {
4522: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4523: }
1.484.2.78 raeburn 4524: if (($updated) && ($result ne 'ok')) {
4525: $r->print('<br />'.&mt('Outdated copy removed'));
4526: }
1.329 droeschl 4527: }
4528: }
4529: }
4530:
4531:
4532:
4533: =pod
4534:
4535: =item list_symbs()
4536:
1.484.2.3 raeburn 4537: List Content Identifiers
1.329 droeschl 4538:
4539: =cut
4540:
4541: sub list_symbs {
4542: my ($r) = @_;
4543:
1.408 raeburn 4544: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4545: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4546: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4547: $r->print(&startContentScreen('tools'));
1.329 droeschl 4548: my $navmap = Apache::lonnavmaps::navmap->new();
4549: if (!defined($navmap)) {
4550: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4551: '<div class="LC_error">'.
4552: &mt('Unable to retrieve information about course contents').
4553: '</div>');
1.408 raeburn 4554: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4555: } else {
1.484 raeburn 4556: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4557: &Apache::loncommon::start_data_table().
4558: &Apache::loncommon::start_data_table_header_row().
4559: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4560: &Apache::loncommon::end_data_table_header_row()."\n");
4561: my $count;
1.329 droeschl 4562: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4563: $r->print(&Apache::loncommon::start_data_table_row().
4564: '<td>'.$res->compTitle().'</td>'.
4565: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4566: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4567: $count ++;
4568: }
4569: if (!$count) {
4570: $r->print(&Apache::loncommon::start_data_table_row().
4571: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4572: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4573: }
1.484 raeburn 4574: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4575: }
1.484.2.19 raeburn 4576: $r->print(&endContentScreen());
1.329 droeschl 4577: }
4578:
1.484.2.78 raeburn 4579: sub contentverifyform {
4580: my ($r) = @_;
4581: my $crstype = &Apache::loncommon::course_type();
4582: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4583: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4584: $r->print(&startContentScreen('tools'));
4585: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4586: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4587: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4588: ' <span class="LC_nobreak">'.
4589: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4590: &mt('No').'</label>'.(' 'x2).
4591: '<label><input type="radio" name="checkstale" value="1" />'.
4592: &mt('Yes').'</label></span></p><p>'.
1.484.2.90 raeburn 4593: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4594: '<input type="hidden" value="1" name="tools" />'.
4595: '<input type="hidden" value="1" name="verify" /></p></form>');
4596: $r->print(&endContentScreen());
4597: return;
4598: }
1.329 droeschl 4599:
4600: sub verifycontent {
1.484.2.78 raeburn 4601: my ($r,$checkstale) = @_;
1.408 raeburn 4602: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4603: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4604: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4605: $r->print(&startContentScreen('tools'));
4606: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4607: $hashtied=0;
4608: undef %alreadyseen;
4609: %alreadyseen=();
4610: &tiehash();
1.484 raeburn 4611:
1.329 droeschl 4612: foreach my $key (keys(%hash)) {
4613: if ($hash{$key}=~/\.(page|sequence)$/) {
4614: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4615: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4616: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4617: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4618: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4619: }
4620: }
4621: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4622: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4623: }
4624: }
4625: &untiehash();
1.442 www 4626: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4627: $r->print(&endContentScreen());
1.329 droeschl 4628: }
4629:
4630:
4631: sub devalidateversioncache {
4632: my $src=shift;
4633: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4634: &Apache::lonnet::clutter($src));
4635: }
4636:
4637: sub checkversions {
1.484.2.67 raeburn 4638: my ($r,$canedit) = @_;
1.408 raeburn 4639: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4640: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4641: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4642: $r->print(&startContentScreen('tools'));
1.442 www 4643:
1.329 droeschl 4644: my $header='';
4645: my $startsel='';
4646: my $monthsel='';
4647: my $weeksel='';
4648: my $daysel='';
4649: my $allsel='';
4650: my %changes=();
4651: my $starttime=0;
4652: my $haschanged=0;
4653: my %setversions=&Apache::lonnet::dump('resourceversions',
4654: $env{'course.'.$env{'request.course.id'}.'.domain'},
4655: $env{'course.'.$env{'request.course.id'}.'.num'});
4656:
4657: $hashtied=0;
4658: &tiehash();
1.484.2.67 raeburn 4659: if ($canedit) {
4660: my %newsetversions=();
4661: if ($env{'form.setmostrecent'}) {
4662: $haschanged=1;
4663: foreach my $key (keys(%hash)) {
4664: if ($key=~/^ids\_(\/res\/.+)$/) {
4665: $newsetversions{$1}='mostrecent';
4666: &devalidateversioncache($1);
4667: }
1.329 droeschl 4668: }
1.484.2.67 raeburn 4669: } elsif ($env{'form.setcurrent'}) {
4670: $haschanged=1;
4671: foreach my $key (keys(%hash)) {
4672: if ($key=~/^ids\_(\/res\/.+)$/) {
4673: my $getvers=&Apache::lonnet::getversion($1);
4674: if ($getvers>0) {
4675: $newsetversions{$1}=$getvers;
4676: &devalidateversioncache($1);
4677: }
4678: }
1.329 droeschl 4679: }
1.484.2.67 raeburn 4680: } elsif ($env{'form.setversions'}) {
4681: $haschanged=1;
4682: foreach my $key (keys(%env)) {
4683: if ($key=~/^form\.set_version_(.+)$/) {
4684: my $src=$1;
4685: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4686: $newsetversions{$src}=$env{$key};
4687: &devalidateversioncache($src);
4688: }
4689: }
1.329 droeschl 4690: }
1.484.2.67 raeburn 4691: }
4692: if ($haschanged) {
4693: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4694: $env{'course.'.$env{'request.course.id'}.'.domain'},
4695: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4696: $r->print(&Apache::loncommon::confirmwrapper(
4697: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4698: } else {
4699: $r->print(&Apache::loncommon::confirmwrapper(
4700: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4701: }
4702: &mark_hash_old();
4703: }
4704: &changewarning($r,'');
1.329 droeschl 4705: }
4706: if ($env{'form.timerange'} eq 'all') {
4707: # show all documents
1.484.2.34 raeburn 4708: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4709: $allsel=' selected="selected"';
1.329 droeschl 4710: foreach my $key (keys(%hash)) {
4711: if ($key=~/^ids\_(\/res\/.+)$/) {
4712: my $src=$1;
4713: $changes{$src}=1;
4714: }
4715: }
4716: } else {
4717: # show documents which changed
4718: %changes=&Apache::lonnet::dump
4719: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4720: $env{'course.'.$env{'request.course.id'}.'.num'});
4721: my $firstkey=(keys(%changes))[0];
4722: unless ($firstkey=~/^error\:/) {
4723: unless ($env{'form.timerange'}) {
4724: $env{'form.timerange'}=604800;
4725: }
4726: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4727: .&mt('seconds');
4728: if ($env{'form.timerange'}==-1) {
4729: $seltext='since start of course';
1.484.2.19 raeburn 4730: $startsel=' selected="selected"';
1.329 droeschl 4731: $env{'form.timerange'}=time;
4732: }
4733: $starttime=time-$env{'form.timerange'};
4734: if ($env{'form.timerange'}==2592000) {
4735: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4736: $monthsel=' selected="selected"';
1.329 droeschl 4737: } elsif ($env{'form.timerange'}==604800) {
4738: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4739: $weeksel=' selected="selected"';
1.329 droeschl 4740: } elsif ($env{'form.timerange'}==86400) {
4741: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4742: $daysel=' selected="selected"';
1.329 droeschl 4743: }
4744: $header=&mt('Content changed').' '.$seltext;
4745: } else {
4746: $header=&mt('No content modifications yet.');
4747: }
4748: }
4749: %setversions=&Apache::lonnet::dump('resourceversions',
4750: $env{'course.'.$env{'request.course.id'}.'.domain'},
4751: $env{'course.'.$env{'request.course.id'}.'.num'});
4752: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4753: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4754: 'lm' => 'Version changes since last Month',
4755: 'lw' => 'Version changes since last Week',
4756: 'sy' => 'Version changes since Yesterday',
4757: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4758: 'cd' => 'Change display',
1.329 droeschl 4759: 'sd' => 'Display',
4760: 'fi' => 'File',
4761: 'md' => 'Modification Date',
4762: 'mr' => 'Most recently published Version',
1.408 raeburn 4763: 've' => 'Version used in '.$crstype,
4764: 'vu' => 'Set Version to be used in '.$crstype,
4765: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4766: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4767: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4768: 'di' => 'Differences',
1.484 raeburn 4769: 'save' => 'Save changes',
4770: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4771: 'act' => 'Actions');
1.484.2.67 raeburn 4772: my ($disabled,$readonly);
4773: unless ($canedit) {
4774: $disabled = 'disabled="disabled"';
4775: $readonly = 1;
4776: }
1.329 droeschl 4777: $r->print(<<ENDHEADERS);
1.484 raeburn 4778: <h4 class="LC_info">$header</h4>
1.329 droeschl 4779: <form action="/adm/coursedocs" method="post">
4780: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4781: <div class="LC_left_float">
1.479 golterma 4782: <fieldset>
1.484 raeburn 4783: <legend>$lt{'cd'}</legend>
1.329 droeschl 4784: <select name="timerange">
1.484.2.19 raeburn 4785: <option value='all'$allsel>$lt{'al'}</option>
4786: <option value="-1"$startsel>$lt{'st'}</option>
4787: <option value="2592000"$monthsel>$lt{'lm'}</option>
4788: <option value="604800"$weeksel>$lt{'lw'}</option>
4789: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4790: </select>
4791: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4792: </fieldset>
4793: </div>
4794: <div class="LC_left_float">
4795: <fieldset>
4796: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4797: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4798: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4799: </fieldset>
4800: </div>
4801: <br clear="all" />
4802: <hr />
4803: <h4>$lt{'vers'}</h4>
1.329 droeschl 4804: ENDHEADERS
1.479 golterma 4805: #number of columns for version history
1.484.2.44 raeburn 4806: my %changedbytime;
4807: foreach my $key (keys(%changes)) {
4808: #excludes not versionable problems from resource version history:
4809: next if ($key =~ /^\/res\/lib\/templates/);
4810: my $chg;
4811: if ($env{'form.timerange'} eq 'all') {
4812: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4813: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4814: } else {
4815: $chg = $changes{$key};
4816: next if ($chg < $starttime);
4817: }
4818: push(@{$changedbytime{$chg}},$key);
4819: }
4820: if (keys(%changedbytime) == 0) {
4821: &untiehash();
4822: $r->print(&mt('No content changes in imported content in specified time frame').
4823: &endContentScreen());
4824: return;
4825: }
1.479 golterma 4826: $r->print(
1.484.2.67 raeburn 4827: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4828: &Apache::loncommon::start_data_table().
4829: &Apache::loncommon::start_data_table_header_row().
4830: '<th>'.&mt('Resources').'</th>'.
4831: "<th>$lt{'mr'}</th>".
4832: "<th>$lt{'ve'}</th>".
4833: "<th>$lt{'vu'}</th>".
4834: '<th>'.&mt('History').'</th>'.
4835: &Apache::loncommon::end_data_table_header_row()
4836: );
1.484.2.44 raeburn 4837: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4838: foreach my $key (sort(@{$changedbytime{$chg}})) {
4839: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4840: my $currentversion=&Apache::lonnet::getversion($key);
4841: if ($currentversion<0) {
4842: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4843: }
4844: my $linkurl=&Apache::lonnet::clutter($key);
4845: $r->print(
4846: &Apache::loncommon::start_data_table_row().
4847: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4848: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4849: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4850: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4851: '<td align="right">'
4852: );
4853: # Used in course
4854: my $usedversion=$hash{'version_'.$linkurl};
4855: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4856: if ($usedversion != $currentversion) {
1.479 golterma 4857: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4858: } else {
1.479 golterma 4859: $r->print($usedversion);
4860: }
1.329 droeschl 4861: } else {
1.484.2.19 raeburn 4862: $r->print($currentversion);
1.329 droeschl 4863: }
1.484.2.44 raeburn 4864: $r->print('</td><td title="'.$lt{'vu'}.'">');
4865: # Set version
4866: $r->print(&Apache::loncommon::select_form(
4867: $setversions{$linkurl},
4868: 'set_version_'.$linkurl,
4869: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4870: '' => '',
4871: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4872: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4873: my $lastold=1;
4874: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4875: my $url=$root.'.'.$prevvers.'.'.$extension;
4876: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4877: $lastold=$prevvers;
4878: }
4879: }
4880: $r->print('</td>');
4881: # List all available versions
4882: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4883: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4884: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4885: $r->print(
1.484.2.44 raeburn 4886: '<span class="LC_nobreak">'
4887: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4888: .&mt('Version [_1]',$prevvers).'</a>'
4889: .' ('.&Apache::lonlocal::locallocaltime(
4890: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4891: .')');
4892: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4893: $r->print(
4894: ' <a href="/adm/diff?filename='.
4895: &Apache::lonnet::clutter($root.'.'.$extension).
4896: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4897: '" target="diffs">'.&mt('Diffs').'</a>');
4898: }
4899: $r->print('</span><br />');
1.329 droeschl 4900: }
1.484.2.44 raeburn 4901: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4902: }
1.329 droeschl 4903: }
1.484.2.19 raeburn 4904: $r->print(
4905: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4906: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4907: '</form>'
4908: );
1.329 droeschl 4909:
4910: &untiehash();
1.484.2.19 raeburn 4911: $r->print(&endContentScreen());
1.484.2.44 raeburn 4912: return;
1.329 droeschl 4913: }
4914:
4915: sub mark_hash_old {
4916: my $retie_hash=0;
4917: if ($hashtied) {
4918: $retie_hash=1;
4919: &untiehash();
4920: }
4921: &tiehash('write');
4922: $hash{'old'}=1;
4923: &untiehash();
4924: if ($retie_hash) { &tiehash(); }
4925: }
4926:
4927: sub is_hash_old {
4928: my $untie_hash=0;
4929: if (!$hashtied) {
4930: $untie_hash=1;
4931: &tiehash();
4932: }
4933: my $return=$hash{'old'};
4934: if ($untie_hash) { &untiehash(); }
4935: return $return;
4936: }
4937:
4938: sub changewarning {
4939: my ($r,$postexec,$message,$url)=@_;
4940: if (!&is_hash_old()) { return; }
4941: my $pathvar='folderpath';
4942: my $path=&escape($env{'form.folderpath'});
4943: if (!defined($url)) {
4944: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4945: }
4946: my $course_type = &Apache::loncommon::course_type();
4947: if (!defined($message)) {
4948: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4949: }
4950: $r->print("\n\n".
1.372 bisitz 4951: '<script type="text/javascript">'."\n".
4952: '// <![CDATA['."\n".
4953: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4954: '// ]]>'."\n".
1.369 bisitz 4955: '</script>'."\n".
1.375 tempelho 4956: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4957: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4958: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4959: &mt($message,' <input type="hidden" name="'.
4960: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4961: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4962: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4963: }
4964:
4965:
4966: sub init_breadcrumbs {
1.484.2.44 raeburn 4967: my ($form,$text,$help)=@_;
1.329 droeschl 4968: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4969: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4970: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4971: faq=>273,
4972: bug=>'Instructor Interface',
1.484.2.44 raeburn 4973: help => $help});
1.329 droeschl 4974: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4975: text=>$text,
4976: faq=>273,
4977: bug=>'Instructor Interface'});
4978: }
4979:
1.441 www 4980: # subroutine to list form elements
4981: sub create_list_elements {
4982: my @formarr = @_;
4983: my $list = '';
1.484.2.12 raeburn 4984: foreach my $button (@formarr){
4985: foreach my $picture (keys(%{$button})) {
4986: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4987: }
4988: }
4989: return $list;
4990: }
1.329 droeschl 4991:
1.441 www 4992: # subroutine to create ul from list elements
4993: sub create_form_ul {
4994: my $list = shift;
4995: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4996: return $ul;
4997: }
1.329 droeschl 4998:
1.442 www 4999: #
5000: # Start tabs
5001: #
5002:
5003: sub startContentScreen {
1.484 raeburn 5004: my ($mode) = @_;
5005: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5006: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5007: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5008: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5009: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5010: } else {
1.484.2.34 raeburn 5011: $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 5012: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5013: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5014: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5015: }
5016: $output .= "\n".'</ul>'."\n";
5017: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5018: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5019: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5020: return $output;
1.442 www 5021: }
5022:
5023: #
5024: # End tabs
5025: #
5026:
5027: sub endContentScreen {
1.484 raeburn 5028: return '</div></div></div>';
1.442 www 5029: }
1.329 droeschl 5030:
1.446 www 5031: sub supplemental_base {
1.484.2.33 raeburn 5032: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5033: }
5034:
1.329 droeschl 5035: sub handler {
5036: my $r = shift;
5037: &Apache::loncommon::content_type($r,'text/html');
5038: $r->send_http_header;
5039: return OK if $r->header_only;
1.484 raeburn 5040:
5041: # get course data
1.408 raeburn 5042: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5043: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5044: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5045:
5046: # graphics settings
5047: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5048:
1.443 www 5049: #
1.329 droeschl 5050: # --------------------------------------------- Initialize help topics for this
5051: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5052: 'Adding_External_Resource','Navigate_Content',
5053: 'Adding_Folders','Docs_Overview', 'Load_Map',
5054: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 5055: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 5056: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
5057: 'Dropbox','Simple_Problem') {
1.329 droeschl 5058: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5059: }
5060: # Composite help files
5061: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5062: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5063: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5064: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5065: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5066: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5067: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5068: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5069: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5070: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5071:
1.484.2.67 raeburn 5072: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5073: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5074: unless ($r->uri eq '/adm/supplemental') {
5075: # does this user have privileges to modify content.
1.484.2.67 raeburn 5076: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5077: $allowed = 1;
5078: $canedit = 1;
5079: $canview = 1;
5080: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5081: $allowed = 1;
5082: $canview = 1;
5083: }
5084: }
5085: unless ($canedit) {
5086: $disabled = ' disabled="disabled"';
1.472 raeburn 5087: }
1.484.2.53 raeburn 5088: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5089: if ($env{'form.inhibitmenu'}) {
5090: unless ($env{'form.inhibitmenu'} eq 'yes') {
5091: delete($env{'form.inhibitmenu'});
5092: }
5093: }
5094:
1.484.2.53 raeburn 5095: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5096: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5097: if (!$canedit) {
5098: &verifycontent($r);
5099: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5100: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5101: text=>'Results',
5102: faq=>273,
5103: bug=>'Instructor Interface'});
5104: &verifycontent($r,$env{'form.checkstale'});
5105: } else {
5106: &contentverifyform($r);
5107: }
1.329 droeschl 5108: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5109: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5110: &list_symbs($r);
5111: } elsif ($allowed && $env{'form.docslog'}) {
5112: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5113: my $folder = $env{'form.folder'};
5114: if ($folder eq '') {
5115: $folder='default';
5116: }
1.484.2.67 raeburn 5117: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5118: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5119: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5120: &checkversions($r,$canedit);
5121: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5122: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5123: &dumpcourse($r);
5124: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5125: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5126: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5127: } else {
1.445 www 5128: #
5129: # Done catching special calls
1.484 raeburn 5130: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5131: # Get the parameters that may be needed
5132: #
5133: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5134: ['folderpath',
5135: 'forcesupplement','forcestandard',
5136: 'tools','symb','command','supppath']);
1.445 www 5137:
1.484.2.78 raeburn 5138: foreach my $item ('forcesupplement','forcestandard','tools') {
5139: next if ($env{'form.'.$item} eq '');
5140: unless ($env{'form.'.$item} eq '1') {
5141: delete($env{'form.'.$item});
5142: }
5143: }
5144:
5145: if ($env{'form.command'}) {
5146: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5147: delete($env{'form.command'});
5148: }
5149: }
5150:
5151: if ($env{'form.symb'}) {
5152: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5153: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5154: delete($env{'form.symb'});
5155: }
5156: }
5157:
1.445 www 5158: # standard=1: this is a "new-style" course with an uploaded map as top level
5159: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5160:
5161: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5162:
1.484 raeburn 5163: # Decide whether this should display supplemental or main content or utilities
1.445 www 5164: # supplementalflag=1: show supplemental documents
5165: # supplementalflag=0: show standard documents
1.484 raeburn 5166: # toolsflag=1: show utilities
1.445 www 5167:
1.484.2.39 raeburn 5168: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5169: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5170: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5171: $supplementalflag=0;
5172: }
5173: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5174: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5175: unless ($allowed) { $supplementalflag=1; }
5176: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5177: my $toolsflag=0;
5178: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5179:
1.484.2.78 raeburn 5180: if ($env{'form.folderpath'} ne '') {
1.484.2.92! raeburn 5181: &validate_folderpath($supplementalflag);
1.484.2.78 raeburn 5182: }
5183:
5184: if ($env{'form.supppath'} ne '') {
1.484.2.92! raeburn 5185: &validate_suppath();
1.484.2.78 raeburn 5186: }
5187:
1.329 droeschl 5188: my $script='';
5189: my $showdoc=0;
1.457 raeburn 5190: my $addentries = {};
1.475 raeburn 5191: my $container;
1.329 droeschl 5192: my $containertag;
1.484.2.17 raeburn 5193: my $pathitem;
1.484.2.67 raeburn 5194: my $hiddentop;
5195: my $navmap;
5196: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5197:
1.464 www 5198: # Do we directly jump somewhere?
1.484.2.21 raeburn 5199: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5200: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5201: $env{'form.folderpath'}=
1.484.2.67 raeburn 5202: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5203: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5204: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5205: } elsif ($env{'form.supppath'} ne '') {
5206: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5207: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5208: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5209: }
1.472 raeburn 5210: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5211: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5212: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5213: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5214: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5215: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5216: } elsif ($env{'form.command'} eq 'contents') {
5217: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5218: } elsif ($env{'form.command'} eq 'home') {
5219: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5220: }
5221:
1.484.2.23 raeburn 5222:
1.445 www 5223: # Where do we store these for when we come back?
5224: my $stored_folderpath='docs_folderpath';
5225: if ($supplementalflag) {
5226: $stored_folderpath='docs_sup_folderpath';
5227: }
1.464 www 5228:
1.484.2.19 raeburn 5229: # No folderpath, and in edit mode, see if we have something stored
5230: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5231: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5232: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5233:
5234: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5235: if ($supplementalflag) {
5236: undef($env{'form.folderpath'}) if ($1 eq 'default');
5237: } else {
5238: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5239: }
5240: } else {
1.484.2.19 raeburn 5241: undef($env{'form.folderpath'});
5242: }
1.484.2.92! raeburn 5243: if ($env{'form.folderpath'} ne '') {
! 5244: &validate_folderpath($supplementalflag);
! 5245: }
1.329 droeschl 5246: }
1.446 www 5247:
5248: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5249: if (!$allowed) {
1.446 www 5250: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5251: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5252: }
5253: }
1.446 www 5254: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5255: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5256: $env{'form.folderpath'} = &supplemental_base()
5257: .'&'.
1.329 droeschl 5258: $env{'form.folderpath'};
5259: }
1.484.2.67 raeburn 5260: # If allowed and user's role is not advanced check folderpath is not hidden
5261: if (($allowed) && (!$env{'request.role.adv'}) &&
5262: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5263: my $folderurl;
5264: my @pathitems = split(/\&/,$env{'form.folderpath'});
5265: my $folder = $pathitems[-2];
5266: if ($folder eq '') {
5267: undef($env{'form.folderpath'});
5268: } else {
5269: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87 raeburn 5270: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5271: $folderurl .= '.page';
5272: } else {
5273: $folderurl .= '.sequence';
5274: }
5275: unless (ref($navmap)) {
5276: $navmap = Apache::lonnavmaps::navmap->new();
5277: }
5278: if (ref($navmap)) {
5279: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5280: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5281: unless (@resources) {
5282: undef($env{'form.folderpath'});
5283: }
5284: }
5285: }
5286: }
5287: }
5288:
5289:
1.446 www 5290: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5291: unless ($env{'form.folderpath'}) {
1.446 www 5292: if ($supplementalflag) {
5293: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5294: } elsif ($allowed) {
5295: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5296: }
1.472 raeburn 5297: }
1.446 www 5298:
1.445 www 5299: # Store this
1.484 raeburn 5300: unless ($toolsflag) {
1.484.2.67 raeburn 5301: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5302: &Apache::loncommon::store_course_settings($stored_folderpath,
5303: {'folderpath' => 'scalar'});
5304: }
5305: my $folderpath;
1.484 raeburn 5306: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5307: $folderpath = $env{'form.folderpath'};
5308: my (@folders)=split('&',$env{'form.folderpath'});
5309: $env{'form.foldername'}=&unescape(pop(@folders));
5310: if ($env{'form.foldername'} =~ /\:1$/) {
5311: $container = 'page';
5312: } else {
5313: $container = 'sequence';
5314: }
5315: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5316: } else {
1.484.2.19 raeburn 5317: if ($env{'form.folder'} eq '' ||
5318: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5319: if ($env{'form.folder'} eq 'supplemental') {
5320: $folderpath=&supplemental_base();
5321: } elsif (!$hiddentop) {
5322: $folderpath='default&'.
5323: &escape(&mt('Main Content').':::::');
5324: }
1.484 raeburn 5325: }
5326: }
1.484.2.19 raeburn 5327: $containertag = '<input type="hidden" name="folderpath" value="" />';
5328: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5329: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5330: $showdoc='/'.$1;
5331: }
5332: if ($showdoc) { # got called in sequence from course
5333: $allowed=0;
5334: } else {
1.484.2.67 raeburn 5335: if ($canedit) {
1.484 raeburn 5336: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5337: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5338: }
5339: }
1.329 droeschl 5340: }
5341:
1.344 bisitz 5342: # get personal data
1.329 droeschl 5343: my $uname=$env{'user.name'};
5344: my $udom=$env{'user.domain'};
5345: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5346:
5347: if ($allowed) {
1.484 raeburn 5348: if ($toolsflag) {
5349: $script .= &inject_data_js();
5350: my ($home,$other,%outhash)=&authorhosts();
5351: if (!$home && $other) {
5352: my @hosts;
5353: foreach my $aurole (keys(%outhash)) {
5354: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5355: push(@hosts,$outhash{$aurole});
5356: }
5357: }
5358: $script .= &dump_switchserver_js(@hosts);
5359: }
1.458 raeburn 5360: } else {
1.484.2.43 raeburn 5361: my $tid = 1;
1.484 raeburn 5362: my @tabids;
5363: if ($supplementalflag) {
5364: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5365: $tid = 2;
1.484 raeburn 5366: } else {
5367: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5368: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5369: unshift(@tabids,'001');
5370: push(@tabids,('dd1','ee1'));
5371: }
1.458 raeburn 5372: }
1.484 raeburn 5373: my $tabidstr = join("','",@tabids);
1.484.2.80 raeburn 5374: my $hostname = $r->hostname();
1.484.2.68 raeburn 5375: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.80 raeburn 5376: $canedit,$hostname,\$navmap).
1.484 raeburn 5377: &history_tab_js().
5378: &inject_data_js().
1.484.2.43 raeburn 5379: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5380: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5381: $addentries = {
1.484.2.3 raeburn 5382: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5383: };
1.458 raeburn 5384: }
1.484.2.30 raeburn 5385: $script .= &paste_popup_js();
1.484.2.12 raeburn 5386: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5387: &mt('Switch server?');
1.484.2.19 raeburn 5388:
5389:
1.329 droeschl 5390: }
5391: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5392: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5393: .'// <![CDATA['."\n"
5394: .$script."\n"
5395: .'// ]]>'."\n"
1.484.2.81 raeburn 5396: .'</script>'."\n"
5397: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5398:
5399: # Breadcrumbs
5400: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5401:
5402: if ($showdoc) {
5403: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5404: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5405: } elsif ($toolsflag) {
1.484.2.67 raeburn 5406: my ($breadtext,$breadtitle);
5407: $breadtext = "$crstype Editor";
5408: if ($canedit) {
5409: $breadtitle = 'Editing '.$crstype.' Contents';
5410: } else {
5411: $breadtext .= ' (View-only mode)';
5412: $breadtitle = 'Viewing '.$crstype.' Contents';
5413: }
1.484.2.44 raeburn 5414: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5415: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5416: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5417: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5418: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5419: $breadtitle)
1.484.2.44 raeburn 5420: );
1.484.2.19 raeburn 5421: } elsif ($r->uri eq '/adm/supplemental') {
5422: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5423: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5424: {'bread_crumbs' => $brcrum,}));
5425: } else {
1.484.2.67 raeburn 5426: my ($breadtext,$breadtitle,$helpitem);
5427: $breadtext = "$crstype Editor";
5428: if ($canedit) {
5429: $breadtitle = 'Editing '.$crstype.' Contents';
5430: $helpitem = 'Docs_Adding_Course_Doc';
5431: } else {
5432: $breadtext .= ' (View-only mode)';
5433: $breadtitle = 'Viewing '.$crstype.' Contents';
5434: $helpitem = 'Docs_Viewing_Course_Doc';
5435: }
1.392 raeburn 5436: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5437: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5438: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5439: {'add_entries' => $addentries}
5440: )
1.392 raeburn 5441: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5442: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5443: $breadtitle,
5444: $helpitem)
1.392 raeburn 5445: );
5446: }
1.364 bisitz 5447:
1.329 droeschl 5448: my %allfiles = ();
5449: my %codebase = ();
1.440 raeburn 5450: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5451: if ($canedit) {
1.329 droeschl 5452: if (($env{'form.uploaddoc.filename'}) &&
5453: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5454: my $context = $1;
5455: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5456: undef($hadchanges);
1.440 raeburn 5457: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5458: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5459: undef($navmap);
1.329 droeschl 5460: if ($hadchanges) {
5461: &mark_hash_old();
5462: }
1.440 raeburn 5463: $r->print($upload_output);
5464: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5465: # Process file upload - phase two - upload embedded objects
5466: $uploadphase = 'check_embedded';
5467: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5468: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5469: $env{'form.newidx'});
5470: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5471: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5472: my ($destination,$dir_root) = &embedded_destination();
5473: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5474: my $actionurl = '/adm/coursedocs';
5475: my ($result,$flag) =
5476: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5477: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5478: $actionurl);
5479: $r->print($result.&return_to_editor());
5480: } elsif ($env{'form.phase'} eq 'check_embedded') {
5481: # Process file upload - phase three - modify references in HTML file
5482: $uploadphase = 'modified_orightml';
5483: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5484: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5485: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5486: my $result =
5487: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5488: $docuname,$docudom,undef,
5489: $dir_root);
5490: $r->print($result.&return_to_editor());
1.476 raeburn 5491: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5492: $uploadphase = 'decompress_phase_one';
5493: $r->print(&decompression_phase_one().
5494: &return_to_editor());
5495: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5496: $uploadphase = 'decompress_phase_two';
5497: $r->print(&decompression_phase_two().
5498: &return_to_editor());
1.329 droeschl 5499: }
5500: }
5501:
1.484 raeburn 5502: if ($allowed && $toolsflag) {
5503: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5504: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5505: $r->print(&endContentScreen());
5506: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5507: # -----------------------------------------------------------------------------
5508: my %lt=&Apache::lonlocal::texthash(
5509: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5510: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5511: 'upld' => 'Upload Content',
1.329 droeschl 5512: 'srch' => 'Search',
5513: 'impo' => 'Import',
1.484.2.19 raeburn 5514: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5515: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5516: 'selm' => 'Select Map',
5517: 'load' => 'Load Map',
5518: 'newf' => 'New Folder',
5519: 'newp' => 'New Composite Page',
5520: 'syll' => 'Syllabus',
1.425 raeburn 5521: 'navc' => 'Table of Contents',
1.343 biermanm 5522: 'sipa' => 'Simple Course Page',
1.329 droeschl 5523: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5524: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5525: 'drbx' => 'Drop Box',
1.451 www 5526: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5527: 'bull' => 'Discussion Board',
1.347 weissno 5528: 'mypi' => 'My Personal Information Page',
1.353 weissno 5529: 'grpo' => 'Group Portfolio',
1.329 droeschl 5530: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5531: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5532: 'imsf' => 'IMS Upload',
5533: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5534: 'cms' => 'Origin of IMS package',
5535: 'se' => 'Select',
1.484.2.19 raeburn 5536: 'file' => 'File',
1.329 droeschl 5537: 'title' => 'Title',
5538: 'comment' => 'Comment',
1.403 raeburn 5539: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5540: 'bb5' => 'Blackboard 5',
5541: 'bb6' => 'Blackboard 6',
5542: 'angel5' => 'ANGEL 5.5',
5543: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5544: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5545: );
1.329 droeschl 5546: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5547: # Calculate free quota space for a user or course. A javascript function checks
5548: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5549: my $quotatype = 'unofficial';
5550: if ($crstype eq 'Community') {
5551: $quotatype = 'community';
5552: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5553: $quotatype = 'official';
5554: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5555: $quotatype = 'textbook';
5556: }
5557: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5558: 'course',$quotatype); # expressed in MB
5559: my $current_disk_usage = 0;
5560: foreach my $subdir ('docs','supplemental') {
5561: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5562: "userfiles/$subdir",1); # expressed in kB
5563: }
5564: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5565: my $usage = $current_disk_usage/1024; # in MB
5566: my $quota = $disk_quota;
5567: my $percent;
5568: if ($disk_quota == 0) {
5569: $percent = 100.0;
5570: } else {
1.484.2.69 raeburn 5571: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5572: }
5573: $usage = sprintf("%.2f",$usage);
5574: $quota = sprintf("%.2f",$quota);
5575: $percent = sprintf("%.0f",$percent);
5576: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5577: $percent.'%',$quota.' MB').'</p>';
5578:
1.329 droeschl 5579: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5580: $quotainfo
1.329 droeschl 5581: $lt{'file'}:<br />
1.484.2.81 raeburn 5582: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5583: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5584: FIUP
5585:
5586: my $checkbox=(<<CHBO);
5587: <!-- <label>$lt{'parse'}?
5588: <input type="checkbox" name="parserflag" />
5589: </label> -->
5590: <label>
1.484.2.67 raeburn 5591: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5592: </label>
5593: CHBO
1.484.2.12 raeburn 5594: my $imsfolder = $env{'form.folder'};
5595: if ($imsfolder eq '') {
1.484.2.19 raeburn 5596: $imsfolder = 'default';
1.484.2.12 raeburn 5597: }
5598: my $imspform=(<<IMSFORM);
5599: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5600: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5601: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5602: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5603: <legend>$lt{'imsf'}</legend>
5604: $fileupload
5605: <br />
5606: <p>
1.484.2.19 raeburn 5607: $lt{'cms'}:
1.484.2.67 raeburn 5608: <select name="source" $disabled>
1.484.2.12 raeburn 5609: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5610: <option value="bb5">$lt{'bb5'}</option>
5611: <option value="bb6">$lt{'bb6'}</option>
5612: <option value="angel5">$lt{'angel5'}</option>
5613: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5614: </select>
5615: <input type="hidden" name="folder" value="$imsfolder" />
5616: </p>
5617: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5618: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5619: </fieldset>
5620: </form>
5621: IMSFORM
5622:
1.484.2.19 raeburn 5623: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5624: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5625: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5626: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5627: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5628: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5629: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5630: $fileupload
5631: <br />
5632: $lt{'title'}:<br />
1.484.2.67 raeburn 5633: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5634: $pathitem
1.329 droeschl 5635: <input type="hidden" name="cmd" value="upload_default" />
5636: <br />
1.458 raeburn 5637: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5638: $checkbox
5639: </span>
1.484.2.12 raeburn 5640: <br clear="all" />
1.484.2.67 raeburn 5641: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5642: </fieldset>
5643: </form>
1.383 tempelho 5644: FUFORM
1.329 droeschl 5645:
1.484.2.67 raeburn 5646: my $mapimportjs;
5647: if ($canedit) {
5648: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5649: } else {
5650: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5651: }
1.484.2.19 raeburn 5652: my $importpubform=(<<SEDFFORM);
5653: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5654: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5655: <form action="/adm/coursedocs" method="post" name="mapimportform">
5656: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5657: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5658: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5659: $lt{'copm'}<br />
5660: <span class="LC_nobreak">
1.484.2.19 raeburn 5661: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5662: onfocus="this.blur();$mapimportjs" $disabled />
5663: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5664: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5665: </fieldset>
5666: </form>
5667:
1.383 tempelho 5668: SEDFFORM
1.484.2.67 raeburn 5669:
5670: my $fromstoredjs;
5671: if ($canedit) {
5672: $fromstoredjs = 'open_StoredLinks_Import()';
5673: } else {
5674: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5675: }
5676:
1.484.2.19 raeburn 5677: my @importpubforma = (
5678: { '<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 5679: { '<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 5680: { '<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 5681: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5682: );
5683: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5684: my $extresourcesform =
5685: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5686: $help{'Adding_External_Resource'},
5687: undef,undef,$disabled);
1.329 droeschl 5688: if ($allowed) {
1.484.2.7 raeburn 5689: my $folder = $env{'form.folder'};
5690: if ($folder eq '') {
5691: $folder='default';
5692: }
1.484.2.67 raeburn 5693: if ($canedit) {
5694: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5695: if ($output) {
5696: $r->print($output);
5697: }
1.484.2.30 raeburn 5698: }
1.337 ehlerst 5699: $r->print(<<HIDDENFORM);
5700: <form name="renameform" method="post" action="/adm/coursedocs">
5701: <input type="hidden" name="title" />
5702: <input type="hidden" name="cmd" />
5703: <input type="hidden" name="markcopy" />
5704: <input type="hidden" name="copyfolder" />
5705: $containertag
5706: </form>
1.484 raeburn 5707:
1.337 ehlerst 5708: HIDDENFORM
1.484.2.17 raeburn 5709: $r->print(&makesimpleeditform($pathitem)."\n".
5710: &makedocslogform($pathitem."\n".
1.484 raeburn 5711: '<input type="hidden" name="folder" value="'.
5712: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5713: }
1.442 www 5714:
5715: # Generate the tabs
1.484.2.19 raeburn 5716: my ($mode,$needs_end);
1.472 raeburn 5717: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5718: my @folders = split('&',$env{'form.folderpath'});
5719: unless (@folders > 2) {
5720: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5721: $needs_end = 1;
5722: }
1.472 raeburn 5723: } else {
1.484 raeburn 5724: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5725: $needs_end = 1;
1.472 raeburn 5726: }
1.443 www 5727:
1.442 www 5728: #
5729:
5730: my $savefolderpath;
1.484.2.86 raeburn 5731: my $hostname = $r->hostname();
1.442 www 5732:
1.395 raeburn 5733: if ($allowed) {
1.329 droeschl 5734: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5735: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5736: $folder='default';
1.356 tempelho 5737: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5738: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5739: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5740: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5741: }
5742: my $postexec='';
5743: if ($folder eq 'default') {
1.372 bisitz 5744: $r->print('<script type="text/javascript">'."\n"
5745: .'// <![CDATA['."\n"
5746: .'this.window.name="loncapaclient";'."\n"
5747: .'// ]]>'."\n"
5748: .'</script>'."\n"
1.369 bisitz 5749: );
1.329 droeschl 5750: } else {
5751: #$postexec='self.close();';
5752: }
1.484.2.15 raeburn 5753: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5754: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5755: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5756:
5757: my $newnavform=(<<NNFORM);
5758: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5759: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5760: $pathitem
1.329 droeschl 5761: <input type="hidden" name="importdetail"
5762: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5763: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5764: $help{'Navigate_Content'}
5765: </form>
5766: NNFORM
5767: my $newsmppageform=(<<NSPFORM);
5768: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5769: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5770: $pathitem
1.329 droeschl 5771: <input type="hidden" name="importdetail" value="" />
1.423 onken 5772: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5773: $help{'Simple Page'}
1.329 droeschl 5774: </form>
5775: NSPFORM
5776:
5777: my $newsmpproblemform=(<<NSPROBFORM);
5778: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5779: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5780: $pathitem
1.329 droeschl 5781: <input type="hidden" name="importdetail" value="" />
1.423 onken 5782: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5783: $help{'Simple_Problem'}
1.329 droeschl 5784: </form>
5785:
5786: NSPROBFORM
5787:
5788: my $newdropboxform=(<<NDBFORM);
5789: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5790: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5791: $pathitem
1.329 droeschl 5792: <input type="hidden" name="importdetail" value="" />
1.423 onken 5793: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5794: $help{'Dropbox'}
1.344 bisitz 5795: </form>
1.329 droeschl 5796: NDBFORM
5797:
5798: my $newexuploadform=(<<NEXUFORM);
5799: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5800: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5801: $pathitem
1.329 droeschl 5802: <input type="hidden" name="importdetail" value="" />
1.423 onken 5803: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5804: $help{'Score_Upload_Form'}
5805: </form>
5806: NEXUFORM
5807:
5808: my $newbulform=(<<NBFORM);
5809: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5810: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5811: $pathitem
1.329 droeschl 5812: <input type="hidden" name="importdetail" value="" />
1.423 onken 5813: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5814: $help{'Bulletin Board'}
5815: </form>
5816: NBFORM
5817:
5818: my $newaboutmeform=(<<NAMFORM);
5819: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5820: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5821: $pathitem
1.329 droeschl 5822: <input type="hidden" name="importdetail"
5823: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5824: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5825: $help{'My Personal Information Page'}
1.329 droeschl 5826: </form>
5827: NAMFORM
5828:
5829: my $newaboutsomeoneform=(<<NASOFORM);
5830: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5831: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5832: $pathitem
1.329 droeschl 5833: <input type="hidden" name="importdetail" value="" />
1.423 onken 5834: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5835: </form>
5836: NASOFORM
5837:
5838: my $newrosterform=(<<NROSTFORM);
5839: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5840: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5841: $pathitem
1.329 droeschl 5842: <input type="hidden" name="importdetail"
5843: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5844: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5845: $help{'Course_Roster'}
1.329 droeschl 5846: </form>
5847: NROSTFORM
5848:
1.484.2.27 raeburn 5849: my $newwebpage;
5850: if ($folder =~ /^default_?(\d*)$/) {
5851: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5852: if ($1) {
5853: $newwebpage .= $1;
5854: } else {
5855: $newwebpage .= 'default';
5856: }
5857: $newwebpage .= '/new.html';
5858: }
5859: my $newwebpageform =(<<NWEBFORM);
5860: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5861: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5862: $pathitem
5863: <input type="hidden" name="importdetail" value="$newwebpage" />
5864: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5865: $help{'Web_Page'}
1.484.2.27 raeburn 5866: </form>
5867: NWEBFORM
1.484.2.30 raeburn 5868:
1.484.2.27 raeburn 5869:
1.342 ehlerst 5870: my $specialdocumentsform;
1.383 tempelho 5871: my @specialdocumentsforma;
1.451 www 5872: my $gradingform;
5873: my @gradingforma;
5874: my $communityform;
5875: my @communityforma;
1.351 ehlerst 5876: my $newfolderform;
1.390 tempelho 5877: my $newfolderb;
1.342 ehlerst 5878:
1.451 www 5879: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5880:
1.329 droeschl 5881: my $newpageform=(<<NPFORM);
5882: <form action="/adm/coursedocs" method="post" name="newpage">
5883: <input type="hidden" name="folderpath" value="$path" />
5884: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5885: <input type="hidden" name="active" value="ee" />
1.423 onken 5886: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5887: $help{'Adding_Pages'}
1.329 droeschl 5888: </form>
5889: NPFORM
1.390 tempelho 5890:
5891:
1.351 ehlerst 5892: $newfolderform=(<<NFFORM);
1.329 droeschl 5893: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5894: $pathitem
1.329 droeschl 5895: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5896: <input type="hidden" name="active" value="" />
1.422 onken 5897: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5898: </form>
5899: NFFORM
5900:
5901: my $newsylform=(<<NSYLFORM);
5902: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5903: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5904: $pathitem
1.329 droeschl 5905: <input type="hidden" name="importdetail"
5906: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5907: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5908: $help{'Syllabus'}
1.383 tempelho 5909:
1.329 droeschl 5910: </form>
5911: NSYLFORM
1.364 bisitz 5912:
1.329 droeschl 5913: my $newgroupfileform=(<<NGFFORM);
5914: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5915: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5916: $pathitem
1.329 droeschl 5917: <input type="hidden" name="importdetail"
5918: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5919: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5920: $help{'Group Portfolio'}
1.329 droeschl 5921: </form>
5922: NGFFORM
1.484.2.89 raeburn 5923: if ($container eq 'page') {
5924: @specialdocumentsforma=(
5925: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
5926: );
5927: } else {
5928: @specialdocumentsforma=(
1.421 onken 5929: {'<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 5930: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5931: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5932: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5933: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.89 raeburn 5934: );
5935: }
1.451 www 5936: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5937:
1.434 raeburn 5938:
5939: my @importdoc = (
1.484.2.19 raeburn 5940: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5941: );
5942: unless ($container eq 'page') {
5943: push(@importdoc,
5944: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5945: );
5946: }
5947: push(@importdoc,
1.484.2.38 raeburn 5948: {'<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 5949: );
1.484.2.12 raeburn 5950: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5951:
1.451 www 5952: @gradingforma=(
5953: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5954: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5955: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5956:
5957: );
5958: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5959:
5960: @communityforma=(
5961: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5962: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5963: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5964: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5965: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5966: );
5967: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5968:
1.330 tempelho 5969: my %orderhash = (
1.484.2.36 raeburn 5970: 'aa' => ['Upload',$fileuploadform],
5971: 'bb' => ['Import',$importpubform],
5972: 'cc' => ['Grading',$gradingform],
1.484.2.89 raeburn 5973: 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 5974: );
1.484.2.19 raeburn 5975: unless ($container eq 'page') {
1.434 raeburn 5976: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5977: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 5978: }
5979:
1.341 ehlerst 5980: $hadchanges=0;
1.484 raeburn 5981: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5982: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5983: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.85 raeburn 5984: $canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 5985: undef($navmap);
1.443 www 5986: if ($error) {
5987: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5988: }
5989: if ($hadchanges) {
1.484.2.73 raeburn 5990: unless (&is_hash_old()) {
5991: &mark_hash_old();
5992: }
1.443 www 5993: }
1.341 ehlerst 5994:
1.443 www 5995: &changewarning($r,'');
5996: }
1.458 raeburn 5997: }
1.442 www 5998:
1.443 www 5999: # Supplemental documents start here
6000:
1.329 droeschl 6001: my $folder=$env{'form.folder'};
1.443 www 6002: unless ($supplementalflag) {
1.329 droeschl 6003: $folder='supplemental';
6004: }
6005: if ($folder =~ /^supplemental$/ &&
6006: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6007: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6008: } elsif ($allowed) {
1.356 tempelho 6009: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6010: }
1.484.2.17 raeburn 6011: $pathitem = '<input type="hidden" name="folderpath" value="'.
6012: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6013: if ($allowed) {
6014: my $folderseq=
1.484.2.15 raeburn 6015: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6016:
6017: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6018: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6019: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6020: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6021: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6022: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6023: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6024: $fileupload
6025: <br />
6026: <br />
6027: <span class="LC_nobreak">
6028: $checkbox
6029: </span>
6030: <br /><br />
6031: $lt{'comment'}:<br />
1.383 tempelho 6032: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6033: <br />
1.484.2.19 raeburn 6034: $pathitem
1.329 droeschl 6035: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6036: <input type='submit' value="$lt{'upld'}" />
6037: </form>
1.484.2.19 raeburn 6038: SUPDOCFORM
1.329 droeschl 6039:
6040: my $supnewfolderform=(<<SNFFORM);
6041: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6042: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6043: $pathitem
1.329 droeschl 6044: <input type="hidden" name="importdetail" value="" />
1.423 onken 6045: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6046: $help{'Adding_Folders'}
1.329 droeschl 6047: </form>
6048: SNFFORM
1.383 tempelho 6049:
1.484.2.19 raeburn 6050: my $supextform =
6051: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6052: $help{'Adding_External_Resource'},
6053: undef,undef,$disabled);
1.329 droeschl 6054:
6055: my $supnewsylform=(<<SNSFORM);
6056: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6057: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6058: $pathitem
1.329 droeschl 6059: <input type="hidden" name="importdetail"
6060: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6061: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6062: $help{'Syllabus'}
6063: </form>
6064: SNSFORM
6065:
6066: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6067: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6068: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6069: $pathitem
1.329 droeschl 6070: <input type="hidden" name="importdetail"
6071: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6072: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6073: $help{'My Personal Information Page'}
1.329 droeschl 6074: </form>
6075: SNAMFORM
6076:
1.484.2.27 raeburn 6077: my $supwebpage;
6078: if ($folder =~ /^supplemental_?(\d*)$/) {
6079: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6080: if ($1) {
6081: $supwebpage .= $1;
6082: } else {
6083: $supwebpage .= 'default';
6084: }
6085: $supwebpage .= '/new.html';
6086: }
6087: my $supwebpageform =(<<SWEBFORM);
6088: <form action="/adm/coursedocs" method="post" name="supwebpage">
6089: <input type="hidden" name="active" value="cc" />
6090: $pathitem
6091: <input type="hidden" name="importdetail" value="$supwebpage" />
6092: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6093: $help{'Web_Page'}
1.484.2.27 raeburn 6094: </form>
6095: SWEBFORM
6096:
1.333 muellerd 6097:
1.383 tempelho 6098: my @specialdocs = (
1.484.2.67 raeburn 6099: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6100: =>$supnewsylform},
1.484.2.67 raeburn 6101: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6102: =>$supnewaboutmeform},
1.484.2.27 raeburn 6103: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6104:
1.383 tempelho 6105: );
1.417 droeschl 6106: my @supimportdoc = (
1.484.2.19 raeburn 6107: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 6108: =>$supextform},
6109: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6110: =>$supupdocform},
1.484.2.19 raeburn 6111: );
6112:
1.484.2.12 raeburn 6113: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6114: my %suporderhash = (
1.390 tempelho 6115: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6116: 'ee' => ['Upload',$supupdocform],
6117: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6118: );
1.443 www 6119: if ($supplementalflag) {
1.458 raeburn 6120: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6121: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.85 raeburn 6122: $canedit,$hostname);
1.443 www 6123: if ($error) {
6124: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6125: } else {
6126: if ($suppchanges) {
6127: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6128: my @ids=&Apache::lonnet::current_machine_ids();
6129: foreach my $server (keys(%servers)) {
6130: next if (grep(/^\Q$server\E$/,@ids));
6131: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6132: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6133: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6134: }
6135: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6136: undef($suppchanges);
6137: }
1.443 www 6138: }
1.393 raeburn 6139: }
1.443 www 6140: } elsif ($supplementalflag) {
1.458 raeburn 6141: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6142: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6143: if ($error) {
6144: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6145: }
1.393 raeburn 6146: }
1.389 tempelho 6147:
1.484.2.19 raeburn 6148: if ($needs_end) {
6149: $r->print(&endContentScreen());
6150: }
1.383 tempelho 6151:
1.329 droeschl 6152: if ($allowed) {
6153: $r->print('
6154: <form method="post" name="extimport" action="/adm/coursedocs">
6155: <input type="hidden" name="title" />
6156: <input type="hidden" name="url" />
6157: <input type="hidden" name="useform" />
6158: <input type="hidden" name="residx" />
6159: </form>');
6160: }
1.484 raeburn 6161: } elsif ($showdoc) {
1.329 droeschl 6162: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6163: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6164: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6165: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6166: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6167: }
6168: }
6169: $r->print(&Apache::loncommon::end_page());
6170: return OK;
1.364 bisitz 6171: }
1.329 droeschl 6172:
1.440 raeburn 6173: sub embedded_form_elems {
6174: my ($phase,$primaryurl,$newidx) = @_;
6175: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6176: $newidx =~s /\D+//g;
1.440 raeburn 6177: return <<STATE;
6178: <input type="hidden" name="folderpath" value="$folderpath" />
6179: <input type="hidden" name="cmd" value="upload_embedded" />
6180: <input type="hidden" name="newidx" value="$newidx" />
6181: <input type="hidden" name="phase" value="$phase" />
6182: <input type="hidden" name="primaryurl" value="$primaryurl" />
6183: STATE
6184: }
6185:
6186: sub embedded_destination {
6187: my $folder=$env{'form.folder'};
6188: my $destination = 'docs/';
6189: if ($folder =~ /^supplemental/) {
6190: $destination = 'supplemental/';
6191: }
6192: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6193: $destination .= 'default/';
6194: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6195: $destination .= $2.'/';
6196: }
1.484.2.78 raeburn 6197: my $newidx = $env{'form.newidx'};
6198: $newidx =~s /\D+//g;
6199: if ($newidx) {
6200: $destination .= $newidx;
6201: }
1.440 raeburn 6202: my $dir_root = '/userfiles';
6203: return ($destination,$dir_root);
6204: }
6205:
6206: sub return_to_editor {
6207: my $actionurl = '/adm/coursedocs';
6208: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6209: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6210: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6211: '</a></p>';
6212: }
6213:
1.476 raeburn 6214: sub decompression_info {
6215: my ($destination,$dir_root) = &embedded_destination();
6216: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6217: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6218: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6219: my $container='sequence';
1.480 raeburn 6220: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6221: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6222: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6223: $container='page';
6224: }
1.480 raeburn 6225: unshift(@hiddens,$pathitem);
6226: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6227: if ($item eq 'newidx') {
6228: next if ($env{'form.'.$item} =~ /\D/);
6229: }
1.480 raeburn 6230: if ($env{'form.'.$item}) {
6231: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6232: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6233: }
1.477 raeburn 6234: }
1.476 raeburn 6235: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6236: $hiddenelem);
6237: }
6238:
6239: sub decompression_phase_one {
6240: my ($dir,$file,$warning,$error,$output);
6241: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6242: &decompression_info();
1.484.2.7 raeburn 6243: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6244: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6245: } else {
6246: my $file = $1;
1.481 raeburn 6247: $output =
6248: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6249: $destination,$dir_root,
6250: $hiddenelem);
6251: if ($env{'form.autoextract_camtasia'}) {
6252: $output .= &remove_archive($docudom,$docuname,$container);
6253: }
1.476 raeburn 6254: }
6255: if ($error) {
6256: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6257: $error.'</p>'."\n";
6258: }
6259: if ($warning) {
6260: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6261: }
6262: return $output;
6263: }
6264:
6265: sub decompression_phase_two {
6266: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6267: &decompression_info();
1.481 raeburn 6268: my $output;
1.480 raeburn 6269: if ($env{'form.archivedelete'}) {
1.481 raeburn 6270: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6271: }
6272: $output .=
1.481 raeburn 6273: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6274: $destination,$dir_root,$hiddenelem);
6275: return $output;
6276: }
6277:
1.480 raeburn 6278: sub remove_archive {
6279: my ($docudom,$docuname,$container) = @_;
6280: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6281: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6282: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6283: if ($fatal) {
6284: if ($container eq 'page') {
6285: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6286: } else {
6287: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6288: }
1.484.2.54 raeburn 6289: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6290: } else {
6291: my $currcmd = $env{'form.cmd'};
6292: my $position = $env{'form.position'};
1.484.2.54 raeburn 6293: my $archiveidx = $position;
6294: if ($position > 0) {
6295: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6296: $archiveidx = $position-1;
6297: }
6298: $env{'form.cmd'} = 'remove_'.$archiveidx;
6299: my ($title,$url,@rrest) =
6300: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6301: if ($url eq $env{'form.archiveurl'}) {
6302: if (&handle_edit_cmd($docuname,$docudom)) {
6303: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6304: if ($fatal) {
6305: if ($container eq 'page') {
6306: $delwarning = &mt('An error occurred updating the contents of the current page.');
6307: } else {
6308: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6309: }
1.480 raeburn 6310: } else {
1.484.2.54 raeburn 6311: $delresult = &mt('Archive file removed.');
1.480 raeburn 6312: }
6313: }
1.484.2.54 raeburn 6314: } else {
6315: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6316: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6317: }
6318: }
6319: $env{'form.cmd'} = $currcmd;
6320: }
6321: if ($delwarning) {
6322: $output = '<p class="LC_warning">'.
6323: $delwarning.
6324: '</p>';
6325: }
6326: if ($delresult) {
6327: $output .= '<p class="LC_info">'.
6328: $delresult.
6329: '</p>';
6330: }
1.481 raeburn 6331: return $output;
1.480 raeburn 6332: }
6333:
1.484 raeburn 6334: sub generate_admin_menu {
1.484.2.67 raeburn 6335: my ($crstype,$canedit) = @_;
1.484 raeburn 6336: my $lc_crstype = lc($crstype);
6337: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6338: my %lt= ( # do not translate here
1.484 raeburn 6339: 'vc' => 'Verify Content',
6340: 'cv' => 'Check/Set Resource Versions',
6341: 'ls' => 'List Resource Identifiers',
6342: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6343: 'dcd' => "Copy $crstype Content to Authoring Space",
6344: );
1.484 raeburn 6345: my ($candump,$dumpurl);
6346: if ($home + $other > 0) {
6347: $candump = 'F';
6348: if ($home) {
6349: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6350: } else {
6351: my @hosts;
6352: foreach my $aurole (keys(%outhash)) {
6353: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6354: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6355: }
1.484 raeburn 6356: }
6357: if (@hosts == 1) {
6358: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6359: '&role='.
6360: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6361: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6362: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6363: } else {
6364: $dumpurl = "javascript:choose_switchserver_window()";
6365: }
6366: }
6367: }
6368: my @menu=
6369: ({ categorytitle=>'Administration',
6370: items =>[
6371: { linktext => $lt{'vc'},
6372: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6373: permission => 'F',
1.484.2.44 raeburn 6374: help => 'Docs_Verify_Content',
1.484 raeburn 6375: icon => 'verify.png',
6376: linktitle => 'Verify contents can be retrieved/rendered',
6377: },
6378: { linktext => $lt{'cv'},
6379: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6380: permission => 'F',
1.484.2.44 raeburn 6381: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6382: icon => 'resversion.png',
6383: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6384: },
6385: { linktext => $lt{'ls'},
6386: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6387: permission => 'F',
6388: #help => '',
6389: icon => 'symbs.png',
6390: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6391: },
6392: ]
1.484.2.67 raeburn 6393: });
6394: if ($canedit) {
6395: push(@menu,
1.484 raeburn 6396: { categorytitle=>'Export',
6397: items =>[
6398: { linktext => $lt{'imse'},
6399: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6400: permission => 'F',
6401: help => 'Docs_Export_Course_Docs',
6402: icon => 'imsexport.png',
6403: linktitle => $lt{'imse'},
6404: },
6405: { linktext => $lt{'dcd'},
6406: url => $dumpurl,
6407: permission => $candump,
1.484.2.44 raeburn 6408: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6409: icon => 'dump.png',
6410: linktitle => $lt{'dcd'},
6411: },
6412: ]
6413: });
1.484.2.67 raeburn 6414: }
1.484 raeburn 6415: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6416: '<input type="hidden" id="dummy" />'."\n".
6417: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6418: '</form>';
1.329 droeschl 6419: }
6420:
6421: sub generate_edit_table {
1.484.2.30 raeburn 6422: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6423: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6424: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6425: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6426: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6427: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6428: $activetab = $env{'form.active'};
6429: }
1.484.2.67 raeburn 6430: unless ($canedit) {
6431: $disabled = ' disabled="disabled"';
6432: }
1.472 raeburn 6433: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6434: my $backtext = &mt('Exit Editor');
1.458 raeburn 6435: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6436: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6437: '<li class="goback">'.
1.484.2.32 raeburn 6438: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6439: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6440: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6441: '<li>'.
6442: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6443: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6444: if ($env{'form.docslog'}) {
6445: $form .= '<li class="active">';
6446: } else {
6447: $form .= '<li>';
6448: }
6449: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6450: &mt('History').'</a></li>'."\n";
6451: if ($env{'form.docslog'}) {
6452: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6453: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6454: }
1.458 raeburn 6455: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6456: if($name ne '00'){
1.371 tempelho 6457: if($activetab eq '' || $activetab ne $name){
6458: $active = '';
6459: }elsif($activetab eq $name){
6460: $active = 'class="active"';
6461: }
1.458 raeburn 6462: $form .= '<li style="float:right" '.$active
1.484 raeburn 6463: .' 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 6464: } else {
1.484.2.43 raeburn 6465: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6466:
6467: }
1.329 droeschl 6468: }
1.484 raeburn 6469: $form .= '</ul>'."\n";
6470: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6471:
6472: if ($to_show ne '') {
1.484.2.30 raeburn 6473: my $saveform;
6474: if ($need_save) {
6475: my $button = &mt('Make changes');
6476: my $path;
6477: if ($env{'form.folderpath'}) {
6478: $path =
6479: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6480: }
6481: $saveform = <<"END";
6482: <div id="multisave" style="display:none; clear:both;" >
6483: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6484: <input type="hidden" name="folderpath" value="$path" />
6485: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6486: <input type="hidden" name="allhiddenresource" value="" />
6487: <input type="hidden" name="allencrypturl" value="" />
6488: <input type="hidden" name="allrandompick" value="" />
6489: <input type="hidden" name="allrandomorder" value="" />
6490: <input type="hidden" name="changeparms" value="" />
6491: <input type="hidden" name="multiremove" value="" />
6492: <input type="hidden" name="multicut" value="" />
6493: <input type="hidden" name="multicopy" value="" />
6494: <input type="hidden" name="multichange" value="" />
6495: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6496: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6497: </form>
6498: </div>
6499: END
6500: }
6501: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6502: }
1.363 ehlerst 6503: foreach my $field (keys(%orderhash)){
1.390 tempelho 6504: if($field ne '00'){
1.422 onken 6505: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6506: $active = 'style="display: none;float:left"';
1.422 onken 6507: }elsif($activetab eq $field){
1.458 raeburn 6508: $active = 'style="display:block;float:left"';
1.422 onken 6509: }
6510: $form .= '<div id="'.$field.$tid.'"'
6511: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6512: .'</div>'."\n";
1.363 ehlerst 6513: }
6514: }
1.484 raeburn 6515: unless ($env{'form.docslog'}) {
6516: $form .= '</div></div>'."\n";
6517: }
1.329 droeschl 6518: return $form;
6519: }
6520:
6521: sub editing_js {
1.484.2.80 raeburn 6522: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,
6523: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6524: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6525: p_mnf => 'Name of New Folder',
6526: t_mnf => 'New Folder',
6527: p_mnp => 'Name of New Page',
6528: t_mnp => 'New Page',
1.451 www 6529: p_mxu => 'Title for the External Score',
1.349 biermanm 6530: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6531: p_msb => 'Title for the Problem',
6532: p_mdb => 'Title for the Drop Box',
1.336 schafran 6533: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6534: p_mwp => 'Title for Web Page',
1.348 weissno 6535: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6536: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6537: p_mab_alrt1 => 'Not a valid user:domain',
6538: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6539: p_chn => 'New Title',
6540: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6541: p_rmr2a => 'Remove',
6542: p_rmr2b => '?',
6543: p_rmr3a => 'Remove those',
6544: p_rmr3b => 'items?',
6545: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6546: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6547: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6548: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6549: p_ctr2a => 'Cut',
6550: p_ctr2b => '?',
6551: p_ctr3a => 'Cut those',
6552: p_ctr3b => 'items?',
1.478 raeburn 6553: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6554: imsfile => 'You must choose an IMS package for import',
6555: imscms => 'You must select which Course Management System was the source of the IMS package',
6556: invurl => 'Invalid URL',
6557: titbl => 'Title is blank',
1.484.2.30 raeburn 6558: more => '(More ...)',
6559: less => '(Less ...)',
6560: noor => 'No actions selected or changes to settings specified.',
6561: noch => 'No changes to settings specified.',
6562: noac => 'No actions selected.',
1.484.2.67 raeburn 6563: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6564: );
6565:
1.484.2.61 raeburn 6566: &js_escape(\%js_lt);
1.433 raeburn 6567: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6568: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6569: my $main_container_page;
1.484.2.19 raeburn 6570: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6571: $main_container_page = 1;
1.434 raeburn 6572: }
1.484.2.67 raeburn 6573: my $backtourl;
6574: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6575: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6576:
1.484.2.21 raeburn 6577: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6578: my $caller = $1;
6579: if ($caller =~ /^supplemental/) {
6580: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6581: } else {
6582: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6583: $res = &Apache::lonnet::clutter($res);
6584: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6585: my ($url,$anchor);
6586: if ($res =~ /^([^#]+)#([^#]+)$/) {
6587: $url = $1;
6588: $anchor = $2;
6589: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6590: $caller = $1.&escape('#').$anchor;
6591: }
1.484.2.67 raeburn 6592: } else {
6593: $url = $res;
1.484.2.66 raeburn 6594: }
1.484.2.83 raeburn 6595: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6596: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6597: $backtourl .= '?navmap=1';
6598: } else {
6599: $backtourl .= '?symb='.
6600: &HTML::Entities::encode($caller,'<>&"');
6601: }
1.484.2.80 raeburn 6602: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6603: if (($ENV{'SERVER_PORT'} == 443) &&
6604: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6605: unless (&Apache::lonnet::uses_sts()) {
6606: if ($hostname ne '') {
6607: $backtourl = 'http://'.$hostname.$backtourl;
6608: }
6609: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6610: }
6611: }
6612: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6613: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6614: unless (&Apache::lonnet::uses_sts()) {
6615: if ($hostname ne '') {
6616: $backtourl = 'http://'.$hostname.$backtourl;
6617: }
6618: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6619: }
6620: }
6621: }
1.484.2.66 raeburn 6622: if ($anchor ne '') {
6623: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6624: }
1.484.2.57 raeburn 6625: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6626: } else {
6627: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6628: }
6629: }
6630: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6631: $backtourl = '/adm/menu';
6632: } elsif ($supplementalflag) {
1.472 raeburn 6633: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6634: } else {
6635: $backtourl = '/adm/navmaps';
1.472 raeburn 6636: }
6637:
1.484.2.19 raeburn 6638: my $fieldsets = "'ext','doc'";
6639: unless ($main_container_page) {
6640: $fieldsets .=",'ims'";
6641: }
1.484.2.12 raeburn 6642: if ($supplementalflag) {
6643: $fieldsets = "'suppext','suppdoc'";
6644: }
6645:
1.484.2.67 raeburn 6646: my $jsmakefunctions;
6647: if ($canedit) {
6648: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6649: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6650: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6651: if (foldername) {
1.484.2.91 raeburn 6652: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 6653: targetform.submit();
6654: }
6655: }
6656:
6657: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6658: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6659: if (pagename) {
1.484.2.91 raeburn 6660: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 6661: targetform.submit();
6662: }
6663: }
6664:
6665: function makeexamupload() {
1.484.2.61 raeburn 6666: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6667: if (title) {
1.329 droeschl 6668: this.document.forms.newexamupload.importdetail.value=
1.484.2.91 raeburn 6669: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 6670: this.document.forms.newexamupload.submit();
6671: }
6672: }
6673:
6674: function makesmppage() {
1.484.2.61 raeburn 6675: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6676: if (title) {
1.329 droeschl 6677: this.document.forms.newsmppg.importdetail.value=
1.484.2.91 raeburn 6678: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6679: this.document.forms.newsmppg.submit();
6680: }
6681: }
6682:
1.484.2.27 raeburn 6683: function makewebpage(type) {
1.484.2.61 raeburn 6684: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6685: var formname;
6686: if (type == 'supp') {
6687: formname = this.document.forms.supwebpage;
6688: } else {
6689: formname = this.document.forms.newwebpage;
6690: }
6691: if (title) {
6692: var webpage = formname.importdetail.value;
1.484.2.91 raeburn 6693: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 6694: formname.submit();
6695: }
6696: }
6697:
1.329 droeschl 6698: function makesmpproblem() {
1.484.2.61 raeburn 6699: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6700: if (title) {
1.329 droeschl 6701: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.91 raeburn 6702: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 6703: this.document.forms.newsmpproblem.submit();
6704: }
6705: }
6706:
6707: function makedropbox() {
1.484.2.61 raeburn 6708: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6709: if (title) {
1.329 droeschl 6710: this.document.forms.newdropbox.importdetail.value=
1.484.2.91 raeburn 6711: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 6712: this.document.forms.newdropbox.submit();
6713: }
6714: }
6715:
6716: function makebulboard() {
1.484.2.61 raeburn 6717: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6718: if (title) {
6719: this.document.forms.newbul.importdetail.value=
1.484.2.91 raeburn 6720: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6721: this.document.forms.newbul.submit();
6722: }
6723: }
6724:
6725: function makeabout() {
1.484.2.61 raeburn 6726: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6727: if (user) {
6728: var comp=new Array();
6729: comp=user.split(':');
6730: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6731: if ((comp[0]) && (comp[1])) {
6732: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6733: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6734: this.document.forms.newaboutsomeone.submit();
6735: } else {
6736: alert("$js_lt{'p_mab_alrt1'}");
6737: }
6738: } else {
6739: alert("$js_lt{'p_mab_alrt2'}");
6740: }
6741: }
1.335 ehlerst 6742: }
1.484.2.67 raeburn 6743:
6744: function makenew(targetform) {
6745: targetform.submit();
1.335 ehlerst 6746: }
1.484.2.67 raeburn 6747:
6748: function changename(folderpath,index,oldtitle) {
6749: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6750: if (title) {
6751: this.document.forms.renameform.markcopy.value='';
6752: this.document.forms.renameform.title.value=title;
6753: this.document.forms.renameform.cmd.value='rename_'+index;
6754: this.document.forms.renameform.folderpath.value=folderpath;
6755: this.document.forms.renameform.submit();
6756: }
1.329 droeschl 6757: }
6758:
1.484.2.67 raeburn 6759: ENDNEWSCRIPT
6760: } else {
6761: $jsmakefunctions = <<ENDNEWSCRIPT;
6762:
6763: function makenewfolder() {
6764: alert("$js_lt{'edri'}");
6765: }
6766:
6767: function makenewpage() {
6768: alert("$js_lt{'edri'}");
6769: }
6770:
6771: function makeexamupload() {
6772: alert("$js_lt{'edri'}");
6773: }
6774:
6775: function makesmppage() {
6776: alert("$js_lt{'edri'}");
6777: }
6778:
6779: function makewebpage(type) {
6780: alert("$js_lt{'edri'}");
6781: }
6782:
6783: function makesmpproblem() {
6784: alert("$js_lt{'edri'}");
6785: }
6786:
6787: function makedropbox() {
6788: alert("$js_lt{'edri'}");
6789: }
6790:
6791: function makebulboard() {
6792: alert("$js_lt{'edri'}");
6793: }
6794:
6795: function makeabout() {
6796: alert("$js_lt{'edri'}");
6797: }
6798:
6799: function changename() {
6800: alert("$js_lt{'edri'}");
6801: }
6802:
6803: function makenew() {
6804: alert("$js_lt{'edri'}");
6805: }
6806:
6807: function groupimport() {
6808: alert("$js_lt{'edri'}");
6809: }
6810:
6811: function groupsearch() {
6812: alert("$js_lt{'edri'}");
6813: }
6814:
6815: function groupopen(url,recover) {
6816: var options="scrollbars=1,resizable=1,menubar=0";
6817: idxflag=1;
6818: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6819: idx.focus();
6820: }
6821:
6822: ENDNEWSCRIPT
6823:
6824: }
6825: return <<ENDSCRIPT;
6826:
6827: $jsmakefunctions
6828:
1.484.2.13 raeburn 6829: function toggleUpload(caller) {
6830: var blocks = Array($fieldsets);
6831: for (var i=0; i<blocks.length; i++) {
6832: var disp = 'none';
6833: if (caller == blocks[i]) {
6834: var curr = document.getElementById('upload'+caller+'form').style.display;
6835: if (curr == 'none') {
6836: disp='block';
6837: }
6838: }
6839: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6840: }
6841: resize_scrollbox('contentscroll','1','1');
6842: return;
6843: }
6844:
1.484.2.19 raeburn 6845: function toggleMap(caller) {
1.484.2.13 raeburn 6846: var disp = 'none';
1.484.2.19 raeburn 6847: if (document.getElementById('importmapform')) {
6848: if (caller == 'map') {
6849: var curr = document.getElementById('importmapform').style.display;
6850: if (curr == 'none') {
6851: disp='block';
6852: }
1.484.2.12 raeburn 6853: }
1.484.2.19 raeburn 6854: document.getElementById('importmapform').style.display=disp;
6855: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6856: }
1.484.2.19 raeburn 6857: return;
1.329 droeschl 6858: }
6859:
1.484.2.12 raeburn 6860: function makeims(imsform) {
6861: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6862: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6863: return;
6864: }
6865: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6866: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6867: return;
6868: }
6869: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6870: imsform.submit();
6871: }
6872:
1.478 raeburn 6873: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6874: var pickitem;
6875: var picknumitem;
6876: var picknumtext;
6877: if (index == 'all') {
6878: pickitem = document.getElementById('randompickall');
6879: picknumitem = document.getElementById('rpicknumall');
6880: picknumtext = document.getElementById('rpicktextall');
6881: } else {
6882: pickitem = document.getElementById('randompick_'+index);
6883: picknumitem = document.getElementById('rpicknum_'+index);
6884: picknumtext = document.getElementById('randompicknum_'+index);
6885: }
1.478 raeburn 6886: if (pickitem.checked) {
1.484.2.61 raeburn 6887: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6888: if (picknum == '' || picknum == null) {
6889: if (caller == 'check') {
6890: pickitem.checked=false;
1.484.2.29 raeburn 6891: if (index == 'all') {
6892: picknumtext.innerHTML = '';
6893: if (caller == 'link') {
6894: propagateState(targetform,'rpicknum');
6895: }
6896: } else {
1.484.2.30 raeburn 6897: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6898: }
1.478 raeburn 6899: }
6900: } else {
6901: picknum.toString();
6902: var regexdigit=/^\\d+\$/;
6903: if (regexdigit.test(picknum)) {
6904: picknumitem.value = picknum;
1.484.2.29 raeburn 6905: if (index == 'all') {
1.484.2.30 raeburn 6906: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6907: if (caller == 'link') {
6908: propagateState(targetform,'rpicknum');
6909: }
6910: } else {
6911: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6912: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6913: }
1.478 raeburn 6914: } else {
6915: if (caller == 'check') {
1.484.2.29 raeburn 6916: if (index == 'all') {
6917: picknumtext.innerHTML = '';
6918: if (caller == 'link') {
6919: propagateState(targetform,'rpicknum');
6920: }
6921: } else {
6922: pickitem.checked=false;
1.484.2.30 raeburn 6923: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6924: }
1.478 raeburn 6925: }
6926: return;
6927: }
6928: }
6929: } else {
1.484.2.29 raeburn 6930: picknumitem.value = '';
6931: picknumtext.innerHTML = '';
6932: if (index == 'all') {
6933: if (caller == 'link') {
6934: propagateState(targetform,'rpicknum');
6935: }
6936: } else {
1.484.2.30 raeburn 6937: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6938: }
6939: }
6940: }
6941:
6942: function propagateState(form,param) {
6943: if (document.getElementById(param+'all')) {
6944: var setcheck = 0;
6945: var rpick = 0;
6946: if (param == 'rpicknum') {
6947: if (document.getElementById('randompickall')) {
6948: if (document.getElementById('randompickall').checked) {
6949: if (document.getElementById('rpicknumall')) {
6950: rpick = document.getElementById('rpicknumall').value;
6951: }
6952: }
6953: }
6954: } else {
6955: if (document.getElementById(param+'all').checked) {
6956: setcheck = 1;
6957: }
6958: }
1.484.2.30 raeburn 6959: var allidxlist;
6960: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6961: if (document.getElementById('all'+param+'idx')) {
6962: allidxlist = document.getElementById('all'+param+'idx').value;
6963: }
6964: var actions = new Array ('remove','cut','copy');
6965: for (var i=0; i<actions.length; i++) {
6966: if (actions[i] != param) {
6967: if (document.getElementById(actions[i]+'all')) {
6968: document.getElementById(actions[i]+'all').checked = false;
6969: }
6970: }
6971: }
6972: }
1.484.2.29 raeburn 6973: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6974: allidxlist = form.allidx.value;
6975: }
6976: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6977: allidxlist = form.allmapidx.value;
6978: }
6979: if ((allidxlist != '') && (allidxlist != null)) {
6980: var allidxs = allidxlist.split(',');
6981: if (allidxs.length > 1) {
6982: for (var i=0; i<allidxs.length; i++) {
6983: if (document.getElementById(param+'_'+allidxs[i])) {
6984: if (param == 'rpicknum') {
6985: if (document.getElementById('randompick_'+allidxs[i])) {
6986: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6987: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6988: if (rpick > 0) {
6989: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6990: } else {
6991: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6992: }
6993: }
6994: }
6995: } else {
1.484.2.29 raeburn 6996: if (setcheck == 1) {
6997: document.getElementById(param+'_'+allidxs[i]).checked = true;
6998: } else {
6999: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 7000: if (param == 'randompick') {
7001: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7002: }
1.484.2.29 raeburn 7003: }
7004: }
7005: }
7006: }
1.484.2.30 raeburn 7007: if (setcheck == 1) {
7008: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7009: var actions = new Array('copy','cut','remove');
7010: for (var i=0; i<actions.length; i++) {
7011: var otheractions;
7012: var otheridxs;
7013: if (actions[i] === param) {
7014: continue;
7015: } else {
7016: if (document.getElementById('all'+actions[i]+'idx')) {
7017: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7018: otheridxs = otheractions.split(',');
7019: if (otheridxs.length > 1) {
7020: for (var j=0; j<otheridxs.length; j++) {
7021: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7022: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7023: }
1.484.2.29 raeburn 7024: }
7025: }
7026: }
7027: }
1.484.2.30 raeburn 7028: }
1.484.2.29 raeburn 7029: }
7030: }
7031: }
7032: }
1.478 raeburn 7033: }
1.484.2.29 raeburn 7034: return;
7035: }
7036:
1.484.2.63 raeburn 7037: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7038: var canedit = '$canedit';
7039: if (canedit == '') {
7040: alert("$js_lt{'edri'}");
7041: return;
7042: }
1.484.2.30 raeburn 7043: var dosettings;
7044: var doaction;
7045: var control = document.togglemultsettings;
7046: if (context == 'actions') {
7047: control = document.togglemultactions;
7048: doaction = 1;
7049: } else {
7050: dosettings = 1;
7051: }
7052: if (control) {
7053: if (control.showmultpick.length) {
7054: for (var i=0; i<control.showmultpick.length; i++) {
7055: if (control.showmultpick[i].checked) {
7056: if (control.showmultpick[i].value == 1) {
7057: if (context == 'settings') {
7058: dosettings = 0;
7059: } else {
7060: doaction = 0;
7061: }
7062: }
7063: }
7064: }
7065: }
7066: }
7067: if (context == 'settings') {
7068: if (dosettings == 1) {
7069: targetform.changeparms.value=param;
7070: targetform.submit();
7071: }
7072: }
7073: if (context == 'actions') {
7074: if (doaction == 1) {
7075: targetform.cmd.value=param+'_'+index;
7076: targetform.folderpath.value=folderpath;
7077: targetform.markcopy.value=idx+':'+param;
7078: targetform.copyfolder.value=folder+'.'+container;
7079: if (param == 'remove') {
1.484.2.63 raeburn 7080: var doremove = 0;
7081: if (skip_confirm) {
7082: if (confirm_removal) {
7083: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7084: doremove = 1;
7085: }
7086: } else {
7087: doremove = 1;
7088: }
7089: } else {
7090: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7091: doremove = 1;
7092: }
7093: }
7094: if (doremove) {
1.484.2.30 raeburn 7095: targetform.markcopy.value='';
7096: targetform.copyfolder.value='';
1.484.2.29 raeburn 7097: targetform.submit();
7098: }
7099: }
1.484.2.30 raeburn 7100: if (param == 'cut') {
1.484.2.61 raeburn 7101: 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 7102: targetform.submit();
7103: return;
7104: }
7105: }
7106: if (param == 'copy') {
7107: targetform.submit();
7108: return;
7109: }
7110: targetform.markcopy.value='';
7111: targetform.copyfolder.value='';
7112: targetform.cmd.value='';
7113: targetform.folderpath.value='';
7114: return;
7115: } else {
7116: if (document.getElementById(param+'_'+idx)) {
7117: item = document.getElementById(param+'_'+idx);
7118: if (item.type == 'checkbox') {
7119: if (item.checked) {
7120: item.checked = false;
7121: } else {
7122: item.checked = true;
7123: singleCheck(item,idx,param);
7124: }
7125: }
7126: }
7127: }
7128: }
7129: return;
7130: }
7131:
7132: function singleCheck(caller,idx,action) {
7133: actions = new Array('cut','copy','remove');
7134: if (caller.checked) {
7135: for (var i=0; i<actions.length; i++) {
7136: if (actions[i] != action) {
7137: if (document.getElementById(actions[i]+'_'+idx)) {
7138: if (document.getElementById(actions[i]+'_'+idx).checked) {
7139: document.getElementById(actions[i]+'_'+idx).checked = false;
7140: }
7141: }
7142: }
1.484.2.29 raeburn 7143: }
7144: }
7145: return;
1.478 raeburn 7146: }
7147:
1.334 muellerd 7148: function unselectInactive(nav) {
1.335 ehlerst 7149: currentNav = document.getElementById(nav);
7150: currentLis = currentNav.getElementsByTagName('LI');
7151: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7152: if (currentLis[i].className == 'goback') {
7153: currentLis[i].className = 'goback';
7154: } else {
7155: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7156: currentLis[i].className = 'right';
1.472 raeburn 7157: } else {
1.374 tempelho 7158: currentLis[i].className = 'i';
1.472 raeburn 7159: }
7160: }
1.335 ehlerst 7161: }
1.332 tempelho 7162: }
7163:
1.334 muellerd 7164: function hideAll(current, nav, data) {
1.335 ehlerst 7165: unselectInactive(nav);
1.484.2.43 raeburn 7166: if (current) {
7167: if (current.className == 'right'){
1.374 tempelho 7168: current.className = 'right active'
1.484.2.43 raeburn 7169: } else {
1.374 tempelho 7170: current.className = 'active';
1.484.2.43 raeburn 7171: }
1.374 tempelho 7172: }
1.335 ehlerst 7173: currentData = document.getElementById(data);
7174: currentDivs = currentData.getElementsByTagName('DIV');
7175: for (i = 0; i < currentDivs.length; i++) {
7176: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7177: currentDivs[i].style.display = 'none';
1.330 tempelho 7178: }
7179: }
1.335 ehlerst 7180: }
1.330 tempelho 7181:
1.374 tempelho 7182: function openTabs(pageId) {
7183: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7184: if(tabnav.length > 2 ){
1.389 tempelho 7185: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7186: currentLis = currentNav.getElementsByTagName('LI');
7187: for(i = 0; i< currentLis.length; i++){
7188: if(currentLis[i].className == 'active') {
1.375 tempelho 7189: funcString = currentLis[i].onclick.toString();
7190: tab = funcString.split('"');
1.420 onken 7191: if(tab.length < 2) {
7192: tab = funcString.split("'");
7193: }
1.375 tempelho 7194: currentData = document.getElementById(tab[1]);
7195: currentData.style.display = 'block';
1.374 tempelho 7196: }
7197: }
7198: }
7199: }
7200:
1.334 muellerd 7201: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7202: currstate = current.className;
1.334 muellerd 7203: hideAll(current, nav, data);
1.375 tempelho 7204: openTabs(pageId);
1.334 muellerd 7205: unselectInactive(nav);
1.484.2.43 raeburn 7206: if ((currstate == 'active') || (currstate == 'right active')) {
7207: if (currstate == 'active') {
7208: current.className = '';
7209: } else {
7210: current.className = 'right';
7211: }
7212: activeTab = '';
7213: toggleUpload();
7214: toggleMap();
7215: resize_scrollbox('contentscroll','1','0');
7216: return;
7217: } else {
7218: current.className = 'active';
7219: }
1.330 tempelho 7220: currentData = document.getElementById(pageId);
7221: currentData.style.display = 'block';
1.458 raeburn 7222: activeTab = pageId;
1.484.2.12 raeburn 7223: toggleUpload();
1.484.2.14 raeburn 7224: toggleMap();
1.433 raeburn 7225: if (nav == 'mainnav') {
7226: var storedpath = "$docs_folderpath";
1.434 raeburn 7227: var storedpage = "$main_container_page";
1.433 raeburn 7228: var reg = new RegExp("^supplemental");
7229: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7230: if (storedpage == 1) {
7231: document.simpleedit.folderpath.value = '';
7232: document.uploaddocument.folderpath.value = '';
7233: } else {
7234: if (reg.test(storedpath)) {
7235: document.simpleedit.folderpath.value = '$toplevelmain';
7236: document.uploaddocument.folderpath.value = '$toplevelmain';
7237: document.newext.folderpath.value = '$toplevelmain';
7238: } else {
7239: document.simpleedit.folderpath.value = storedpath;
7240: document.uploaddocument.folderpath.value = storedpath;
7241: document.newext.folderpath.value = storedpath;
7242: }
1.433 raeburn 7243: }
7244: } else {
1.434 raeburn 7245: if (reg.test(storedpath)) {
7246: document.simpleedit.folderpath.value = storedpath;
7247: document.supuploaddocument.folderpath.value = storedpath;
7248: document.supnewext.folderpath.value = storedpath;
7249: } else {
1.433 raeburn 7250: document.simpleedit.folderpath.value = '$toplevelsupp';
7251: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7252: document.supnewext.folderpath.value = '$toplevelsupp';
7253: }
7254: }
7255: }
1.484.2.3 raeburn 7256: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7257: return false;
7258: }
1.329 droeschl 7259:
1.472 raeburn 7260: function toContents(jumpto) {
7261: var newurl = '$backtourl';
1.484.2.21 raeburn 7262: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7263: newurl = newurl+'?postdata='+jumpto;
7264: }
7265: location.href=newurl;
7266: }
7267:
1.484.2.30 raeburn 7268: function togglePick(caller,value) {
7269: var disp = 'none';
7270: if (document.getElementById('multi'+caller)) {
7271: var curr = document.getElementById('multi'+caller).style.display;
7272: if (value == 1) {
7273: disp='block';
7274: }
7275: if (curr == disp) {
7276: return;
7277: }
7278: document.getElementById('multi'+caller).style.display=disp;
7279: if (value == 1) {
1.484.2.61 raeburn 7280: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7281: } else {
7282: document.getElementById('more'+caller).innerHTML = '';
7283: }
7284: if (caller == 'actions') {
7285: setClass(value);
7286: setBoxes(value);
7287: }
7288: }
7289: var showButton = multiSettings();
7290: if (showButton != 1) {
7291: showButton = multiActions();
7292: }
7293: if (document.getElementById('multisave')) {
7294: if (showButton == 1) {
7295: document.getElementById('multisave').style.display='block';
7296: } else {
7297: document.getElementById('multisave').style.display='none';
7298: }
7299: }
7300: resize_scrollbox('contentscroll','1','1');
7301: return;
7302: }
7303:
7304: function toggleCheckUncheck(caller,more) {
7305: if (more == 1) {
1.484.2.61 raeburn 7306: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7307: document.getElementById('allfields'+caller).style.display='block';
7308: } else {
1.484.2.61 raeburn 7309: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7310: document.getElementById('allfields'+caller).style.display='none';
7311: }
7312: resize_scrollbox('contentscroll','1','1');
7313: }
7314:
7315: function multiSettings() {
7316: var inuse = 0;
7317: var settingsform = document.togglemultsettings;
7318: if (settingsform.showmultpick.length > 1) {
7319: for (var i=0; i<settingsform.showmultpick.length; i++) {
7320: if (settingsform.showmultpick[i].checked) {
7321: if (settingsform.showmultpick[i].value == 1) {
7322: inuse = 1;
7323: }
7324: }
7325: }
7326: }
7327: return inuse;
7328: }
7329:
7330: function multiActions() {
7331: var inuse = 0;
7332: var actionsform = document.togglemultactions;
7333: if (actionsform.showmultpick.length > 1) {
7334: for (var i=0; i<actionsform.showmultpick.length; i++) {
7335: if (actionsform.showmultpick[i].checked) {
7336: if (actionsform.showmultpick[i].value == 1) {
7337: inuse = 1;
7338: }
7339: }
7340: }
7341: }
7342: return inuse;
7343: }
7344:
7345: function checkSubmits() {
7346: var numchanges = 0;
7347: var form = document.saveactions;
7348: var doactions = multiActions();
7349: var cutwarnings = 0;
7350: var remwarnings = 0;
1.484.2.63 raeburn 7351: var removalinfo = 0;
1.484.2.30 raeburn 7352: if (doactions == 1) {
7353: var remidxlist = document.cumulativeactions.allremoveidx.value;
7354: if ((remidxlist != '') && (remidxlist != null)) {
7355: var remidxs = remidxlist.split(',');
7356: for (var i=0; i<remidxs.length; i++) {
7357: if (document.getElementById('remove_'+remidxs[i])) {
7358: if (document.getElementById('remove_'+remidxs[i]).checked) {
7359: form.multiremove.value += remidxs[i]+',';
7360: numchanges ++;
7361: if (document.getElementById('skip_remove_'+remidxs[i])) {
7362: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7363: remwarnings ++;
7364: }
7365: }
1.484.2.63 raeburn 7366: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7367: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7368: removalinfo ++;
7369: }
7370: }
1.484.2.30 raeburn 7371: }
7372: }
7373: }
7374: }
7375: var cutidxlist = document.cumulativeactions.allcutidx.value;
7376: if ((cutidxlist != '') && (cutidxlist != null)) {
7377: var cutidxs = cutidxlist.split(',');
7378: for (var i=0; i<cutidxs.length; i++) {
7379: if (document.getElementById('cut_'+cutidxs[i])) {
7380: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7381: form.multicut.value += cutidxs[i]+',';
7382: numchanges ++;
7383: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7384: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7385: cutwarnings ++;
7386: }
7387: }
7388: }
7389: }
7390: }
7391: }
7392: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7393: if ((copyidxlist != '') && (copyidxlist != null)) {
7394: var copyidxs = copyidxlist.split(',');
7395: for (var i=0; i<copyidxs.length; i++) {
7396: if (document.getElementById('copy_'+copyidxs[i])) {
7397: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7398: form.multicopy.value += copyidxs[i]+',';
7399: numchanges ++;
7400: }
7401: }
7402: }
7403: }
7404: if (numchanges > 0) {
7405: form.multichange.value = numchanges;
7406: }
7407: }
7408: var dosettings = multiSettings();
7409: var haschanges = 0;
7410: if (dosettings == 1) {
7411: form.allencrypturl.value = '';
7412: form.allhiddenresource.value = '';
7413: form.changeparms.value = 'all';
7414: var patt=new RegExp(",\$");
7415: var allidxlist = document.cumulativesettings.allidx.value;
7416: if ((allidxlist != '') && (allidxlist != null)) {
7417: var allidxs = allidxlist.split(',');
7418: if (allidxs.length > 1) {
7419: for (var i=0; i<allidxs.length; i++) {
7420: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7421: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7422: form.allhiddenresource.value += allidxs[i]+',';
7423: }
7424: }
7425: if (document.getElementById('encrypturl_'+allidxs[i])) {
7426: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7427: form.allencrypturl.value += allidxs[i]+',';
7428: }
1.484.2.29 raeburn 7429: }
7430: }
1.484.2.30 raeburn 7431: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7432: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7433: }
7434: }
7435: form.allrandompick.value = '';
7436: form.allrandomorder.value = '';
7437: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7438: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7439: var allmapidxs = allmapidxlist.split(',');
7440: for (var i=0; i<allmapidxs.length; i++) {
7441: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7442: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7443: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7444: if ((randompick.checked) && (rpicknum.value != '')) {
7445: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7446: }
7447: if (randorder.checked) {
7448: form.allrandomorder.value += allmapidxs[i]+',';
7449: }
7450: }
7451: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7452: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7453: }
7454: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7455: haschanges = 1;
7456: }
7457: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7458: haschanges = 1;
7459: }
7460: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7461: haschanges = 1;
7462: }
7463: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7464: haschanges = 1;
7465: }
7466: }
7467: if (doactions == 1) {
7468: if (numchanges > 0) {
1.484.2.63 raeburn 7469: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7470: if (remwarnings > 0) {
1.484.2.61 raeburn 7471: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7472: return false;
7473: }
7474: }
1.484.2.63 raeburn 7475: if (removalinfo > 0) {
7476: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7477: return false;
7478: }
7479: }
1.484.2.30 raeburn 7480: if (cutwarnings > 0) {
1.484.2.61 raeburn 7481: 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 7482: return false;
1.484.2.29 raeburn 7483: }
7484: }
7485: }
1.484.2.30 raeburn 7486: form.submit();
7487: return true;
7488: }
7489: }
7490: if (dosettings == 1) {
7491: if (haschanges == 1) {
7492: form.submit();
7493: return true;
1.484.2.29 raeburn 7494: }
7495: }
1.484.2.30 raeburn 7496: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7497: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7498: } else {
7499: if (dosettings == 1) {
1.484.2.61 raeburn 7500: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7501: } else {
1.484.2.61 raeburn 7502: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7503: }
7504: }
7505: return false;
7506: }
7507:
7508: function setClass(value) {
7509: var cutclass = 'LC_docs_cut';
7510: var copyclass = 'LC_docs_copy';
7511: var removeclass = 'LC_docs_remove';
7512: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7513: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7514: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7515: var links = document.getElementsByTagName('a');
7516: for (var i=0; i<links.length; i++) {
7517: var classes = links[i].className;
7518: if (cutreg.test(classes)) {
7519: links[i].className = cutclass;
7520: if (value == 1) {
7521: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7522: }
1.484.2.30 raeburn 7523: } else {
7524: if (copyreg.test(classes)) {
7525: links[i].className = copyclass;
7526: if (value == 1) {
7527: links[i].className += " LC_menubuttons_link";
7528: }
7529: } else {
7530: if (removereg.test(classes)) {
7531: links[i].className = removeclass;
7532: if (value == 1) {
7533: links[i].className += " LC_menubuttons_link";
7534: }
7535: }
1.484.2.29 raeburn 7536: }
7537: }
7538: }
1.484.2.30 raeburn 7539: return;
1.484.2.29 raeburn 7540: }
7541:
1.484.2.30 raeburn 7542: function setBoxes(value) {
7543: var remidxlist = document.cumulativeactions.allremoveidx.value;
7544: if ((remidxlist != '') && (remidxlist != null)) {
7545: var remidxs = remidxlist.split(',');
7546: for (var i=0; i<remidxs.length; i++) {
7547: if (document.getElementById('remove_'+remidxs[i])) {
7548: var item = document.getElementById('remove_'+remidxs[i]);
7549: if (value == 1) {
7550: item.className = 'LC_docs_remove';
7551: } else {
7552: item.className = 'LC_hidden';
7553: }
7554: }
1.484.2.29 raeburn 7555: }
7556: }
1.484.2.30 raeburn 7557: var cutidxlist = document.cumulativeactions.allcutidx.value;
7558: if ((cutidxlist != '') && (cutidxlist != null)) {
7559: var cutidxs = cutidxlist.split(',');
7560: for (var i=0; i<cutidxs.length; i++) {
7561: if (document.getElementById('cut_'+cutidxs[i])) {
7562: var item = document.getElementById('cut_'+cutidxs[i]);
7563: if (value == 1) {
7564: item.className = 'LC_docs_cut';
7565: } else {
7566: item.className = 'LC_hidden';
7567: }
7568: }
7569: }
7570: }
7571: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7572: if ((copyidxlist != '') && (copyidxlist != null)) {
7573: var copyidxs = copyidxlist.split(',');
7574: for (var i=0; i<copyidxs.length; i++) {
7575: if (document.getElementById('copy_'+copyidxs[i])) {
7576: var item = document.getElementById('copy_'+copyidxs[i]);
7577: if (value == 1) {
7578: item.className = 'LC_docs_copy';
7579: } else {
7580: item.className = 'LC_hidden';
7581: }
7582: }
1.484.2.29 raeburn 7583: }
7584: }
7585: return;
7586: }
7587:
1.484.2.67 raeburn 7588: ENDSCRIPT
1.329 droeschl 7589: }
1.457 raeburn 7590:
1.483 raeburn 7591: sub history_tab_js {
7592: return <<"ENDHIST";
7593: function toggleHistoryDisp(choice) {
7594: document.docslogform.docslog.value = choice;
7595: document.docslogform.submit();
7596: return;
7597: }
7598:
7599: ENDHIST
7600: }
7601:
1.484 raeburn 7602: sub inject_data_js {
7603: return <<ENDINJECT;
7604:
7605: function injectData(current, hiddenField, name, value) {
7606: currentElement = document.getElementById(hiddenField);
7607: currentElement.name = name;
7608: currentElement.value = value;
7609: current.submit();
7610: }
7611:
7612: ENDINJECT
7613: }
7614:
7615: sub dump_switchserver_js {
7616: my @hosts = @_;
1.484.2.61 raeburn 7617: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7618: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7619: swit => 'Switch server?',
1.484.2.61 raeburn 7620: );
7621: my %html_js_lt = &Apache::lonlocal::texthash(
7622: swit => 'Switch server?',
1.484.2.43 raeburn 7623: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7624: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7625: chos => 'Choose server',
7626: );
1.484.2.61 raeburn 7627: &js_escape(\%js_lt);
7628: &html_escape(\%html_js_lt);
7629: &js_escape(\%html_js_lt);
1.484 raeburn 7630: my $role = $env{'request.role'};
7631: my $js = <<"ENDSWJS";
7632: <script type="text/javascript">
7633: function write_switchserver() {
7634: var server;
7635: if (document.setserver.posshosts.length > 0) {
7636: for (var i=0; i<document.setserver.posshosts.length; i++) {
7637: if (document.setserver.posshosts[i].checked) {
7638: server = document.setserver.posshosts[i].value;
7639: }
7640: }
7641: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7642: }
7643: window.close();
7644: }
7645: </script>
7646:
7647: ENDSWJS
7648:
7649: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7650: {'only_body' => 1,
7651: 'js_ready' => 1,});
7652: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7653:
7654: my $hostpicker;
7655: my $count = 0;
7656: foreach my $host (sort(@hosts)) {
7657: my $checked;
7658: if ($count == 0) {
7659: $checked = ' checked="checked"';
7660: }
7661: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7662: $host.'"'.$checked.' />'.$host.'</label> ';
7663: $count++;
7664: }
7665:
7666: return <<"ENDSWITCHJS";
7667:
7668: function dump_needs_switchserver(url) {
7669: if (url!='' && url!= null) {
1.484.2.61 raeburn 7670: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7671: go(url);
7672: }
7673: }
7674: return;
7675: }
7676:
7677: function choose_switchserver_window() {
7678: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7679: newWindow.document.open();
7680: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7681: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7682: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7683: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7684: '<form name="setserver" method="post" action="" \\/>\\n'+
7685: '$hostpicker\\n'+
7686: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7687: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7688: 'onclick="write_switchserver();" \\/>\\n'+
7689: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7690: newWindow.document.writeln('$endpage');
7691: newWindow.document.close();
7692: newWindow.focus();
7693: }
7694:
7695: ENDSWITCHJS
7696: }
7697:
7698: sub makedocslogform {
7699: my ($formelems,$docslog) = @_;
7700: return <<"LOGSFORM";
7701: <form action="/adm/coursedocs" method="post" name="docslogform">
7702: <input type="hidden" name="docslog" value="$docslog" />
7703: $formelems
7704: </form>
7705: LOGSFORM
7706: }
7707:
7708: sub makesimpleeditform {
7709: my ($formelems) = @_;
7710: return <<"SIMPFORM";
7711: <form name="simpleedit" method="post" action="/adm/coursedocs">
7712: <input type="hidden" name="importdetail" value="" />
7713: $formelems
7714: </form>
7715: SIMPFORM
7716: }
7717:
1.329 droeschl 7718: 1;
7719: __END__
7720:
7721:
7722: =head1 NAME
7723:
7724: Apache::londocs.pm
7725:
7726: =head1 SYNOPSIS
7727:
7728: This is part of the LearningOnline Network with CAPA project
7729: described at http://www.lon-capa.org.
7730:
7731: =head1 SUBROUTINES
7732:
7733: =over
7734:
7735: =item %help=()
7736:
7737: Available help topics
7738:
7739: =item mapread()
7740:
1.344 bisitz 7741: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7742: @order and @resources, determines status
7743: sets @order - pointer to resources in right order
7744: sets @resources - array with the resources with correct idx
7745:
7746: =item authorhosts()
7747:
7748: Return hash with valid author names
7749:
7750: =item clean()
7751:
7752: =item dumpcourse()
7753:
7754: Actually dump course
7755:
7756: =item group_import()
7757:
7758: Imports the given (name, url) resources into the course
7759: coursenum, coursedom, and folder must precede the list
7760:
7761: =item breadcrumbs()
7762:
7763: =item log_docs()
7764:
7765: =item docs_change_log()
7766:
7767: =item update_paste_buffer()
7768:
7769: =item print_paste_buffer()
7770:
7771: =item do_paste_from_buffer()
7772:
1.484.2.30 raeburn 7773: =item do_buffer_empty()
7774:
7775: =item clear_from_buffer()
7776:
1.484.2.7 raeburn 7777: =item get_newmap_url()
7778:
7779: =item dbcopy()
7780:
7781: =item uniqueness_check()
7782:
7783: =item contained_map_check()
7784:
7785: =item url_paste_fixups()
7786:
7787: =item apply_fixups()
7788:
7789: =item copy_dependencies()
7790:
1.329 droeschl 7791: =item update_parameter()
7792:
7793: =item handle_edit_cmd()
7794:
7795: =item editor()
7796:
7797: =item process_file_upload()
7798:
7799: =item process_secondary_uploads()
7800:
7801: =item is_supplemental_title()
7802:
7803: =item entryline()
7804:
7805: =item tiehash()
7806:
7807: =item untiehash()
7808:
7809: =item checkonthis()
7810:
7811: check on this
7812:
7813: =item verifycontent()
7814:
7815: Verify Content
7816:
1.484.2.78 raeburn 7817: =item devalidateversioncache()
7818:
7819: =item checkversions()
1.329 droeschl 7820:
7821: Check Versions
7822:
7823: =item mark_hash_old()
7824:
7825: =item is_hash_old()
7826:
7827: =item changewarning()
7828:
7829: =item init_breadcrumbs()
7830:
7831: Breadcrumbs for special functions
7832:
1.484 raeburn 7833: =item create_list_elements()
7834:
7835: =item create_form_ul()
7836:
7837: =item startContentScreen()
7838:
7839: =item endContentScreen()
7840:
7841: =item supplemental_base()
7842:
7843: =item embedded_form_elems()
7844:
7845: =item embedded_destination()
7846:
7847: =item return_to_editor()
7848:
7849: =item decompression_info()
7850:
7851: =item decompression_phase_one()
7852:
7853: =item decompression_phase_two()
7854:
7855: =item remove_archive()
7856:
7857: =item generate_admin_menu()
7858:
7859: =item generate_edit_table()
7860:
7861: =item editing_js()
7862:
7863: =item history_tab_js()
7864:
7865: =item inject_data_js()
7866:
7867: =item dump_switchserver_js()
7868:
1.484.2.3 raeburn 7869: =item resize_scrollbox_js()
1.484 raeburn 7870:
7871: =item makedocslogform()
7872:
1.484.2.3 raeburn 7873: =item makesimpleeditform()
7874:
1.329 droeschl 7875: =back
7876:
7877: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>