Annotation of loncom/interface/londocs.pm, revision 1.484.2.72.2.5
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.72.2. (raeburn 4:): # $Id: londocs.pm,v 1.484.2.72.2.4 2017/11/16 23:45:03 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:
180: sub dumpcourse {
181: my ($r) = @_;
1.408 raeburn 182: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 183: my ($starthash,$js);
184: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
185: $js = <<"ENDJS";
186: <script type="text/javascript">
187: // <![CDATA[
188:
189: function hide_searching() {
190: if (document.getElementById('searching')) {
191: document.getElementById('searching').style.display = 'none';
192: }
193: return;
194: }
195:
196: // ]]>
197: </script>
198: ENDJS
199: $starthash = {
200: add_entries => {'onload' => "hide_searching();"},
201: };
202: }
203: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
204: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 205: $r->print(&startContentScreen('tools'));
1.329 droeschl 206: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 207: unless ($home) {
208: $r->print(&endContentScreen());
209: return '';
210: }
1.329 droeschl 211: my $origcrsid=$env{'request.course.id'};
212: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
213: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
214: # Do the dumping
1.484 raeburn 215: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
216: $r->print(&endContentScreen());
217: return '';
218: }
1.484.2.24 raeburn 219: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 220: $r->print('<h3>'.&mt('Copying Files').'</h3>');
221: my $title=$env{'form.authorfolder'};
222: $title=&clean($title);
1.484.2.43 raeburn 223: my ($navmap,$errormsg) =
224: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
225: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
226: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
227: my (%maps,%resources,%titles);
228: if (!ref($navmap)) {
229: $r->print($errormsg.
230: &endContentScreen());
231: return '';
232: } else {
233: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
234: 'dumpdocs',$cdom,$cnum);
235: }
236: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
237: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
238: %newcontent,%has_simpleprobs);
239: foreach my $item (sort {$a <=> $b} (@todump)) {
240: my $name = $env{'form.namefor_'.$item};
241: if ($resources{$item}) {
242: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
243: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
244: $tocopy{$1} = $name;
245: $display{$item} = $1;
246: $lookup{$1} = $item;
247: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
248: $simpleproblems{$item} = {
249: symb => $resources{$item},
250: name => $name,
251: };
252: $display{$item} = 'simpleproblem_'.$name;
253: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
254: $has_simpleprobs{$1}{$id} = $item;
255: }
256: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
257: my $marker = $1;
258: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
259: $simplepages{$item} = {
260: res => $res,
261: title => $titles{$item},
262: db => $db_name,
263: marker => $marker,
264: symb => $resources{$item},
265: name => $name,
266: };
267: $display{$item} = '/'.$res;
268: }
269: } elsif ($maps{$item}) {
270: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
271: $tocopy{$1} = $name;
272: $display{$item} = $1;
273: $lookup{$1} = $item;
274: }
275: } else {
276: next;
277: }
278: }
1.329 droeschl 279: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
280: $crs=~s/\_/\//g;
1.484.2.43 raeburn 281: my $mm = new File::MMagic;
282: my $prefix = "/uploaded/$cdom/$cnum/";
283: %replacehash = %tocopy;
284: foreach my $item (sort(keys(%simpleproblems))) {
285: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
286: $newcontent{$display{$item}} = $content;
287: }
288: my $gateway = Apache::lonhtmlgateway->new('web');
289: foreach my $item (sort(keys(%simplepages))) {
290: if (ref($simplepages{$item}) eq 'HASH') {
291: my $pagetitle = $simplepages{$item}{'title'};
292: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
293: my %contents;
294: foreach my $field (keys(%fields)) {
295: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
296: my $name = $1;
297: my $msg = $fields{$field};
298: if ($name eq 'webreferences') {
299: if ($msg =~ m{^https?://}) {
300: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
301: }
302: } else {
303: $msg = &Encode::decode('utf8',$msg);
304: $msg = $gateway->process_outgoing_html($msg,1);
305: $contents{$name} = $msg;
306: }
307: } elsif ($field eq 'uploaded.photourl') {
308: my $marker = $simplepages{$item}{marker};
309: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
310: my $filepath = $1;
311: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
312: if ($fname ne '') {
313: $fname=~s/\.(\w+)$//;
314: my $ext=$1;
315: $fname = &clean($fname);
316: $fname.='.'.$ext;
317: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
318: $replacehash{$filepath} = $relpath.$fname;
319: $deps{$item}{$filepath} = 1;
320: }
321: }
322: }
323: }
324: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
325: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
326: my $content = '
327: <html>
328: <head>
329: <title>'.$pagetitle.'</title>
330: </head>
331: <body bgcolor="#ffffff">';
332: if ($contents{title}) {
333: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
334: }
335: if ($contents{image}) {
336: $content .= "\n".$contents{image};
337: }
338: if ($contents{content}) {
339: $content .= '
340: <div class="LC_Box">
1.484.2.50 raeburn 341: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 342: $contents{content}.'
343: </div>';
344: }
345: if ($contents{webreferences}) {
346: $content .= '
347: <div class="LC_Box">
1.484.2.50 raeburn 348: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 349: $contents{webreferences}.'
350: </div>';
351: }
352: $content .= '
353: </body>
354: </html>
355: ';
356: $newcontent{'/'.$simplepages{$item}{res}} = $content;
357: }
358: }
359: foreach my $item (keys(%tocopy)) {
360: unless ($item=~/\.(sequence|page)$/) {
361: my $currurlpath = $prefix.$item;
362: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
363: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
364: }
365: }
366: foreach my $num (sort {$a <=> $b} (@todump)) {
367: my $src = $display{$num};
368: next if ($src eq '');
369: my @needcopy = ();
370: if ($replacehash{$src}) {
371: push(@needcopy,$src);
372: if (ref($deps{$num}) eq 'HASH') {
373: foreach my $dep (sort(keys(%{$deps{$num}}))) {
374: if ($replacehash{$dep}) {
375: push(@needcopy,$dep);
376: }
377: }
378: }
379: } elsif ($src =~ /^simpleproblem_/) {
380: push(@needcopy,$src);
381: }
382: next if (@needcopy == 0);
383: my ($result,$depresult);
384: for (my $i=0; $i<@needcopy; $i++) {
385: my $item = $needcopy[$i];
386: my $newfilename;
387: if ($simpleproblems{$num}) {
388: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
389: } else {
390: $newfilename=$title.'/'.$replacehash{$item};
391: }
392: $newfilename=~s/\.(\w+)$//;
393: my $ext=$1;
394: $newfilename=&clean($newfilename);
395: $newfilename.='.'.$ext;
396: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
397: if ($newrelpath ne $replacehash{$item}) {
398: $replacehash{$item} = $newrelpath;
399: }
400: my @dirs=split(/\//,$newfilename);
401: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
402: my $makepath=$path;
403: my $fail;
404: my $origin;
405: for (my $i=0;$i<$#dirs;$i++) {
406: $makepath.='/'.$dirs[$i];
407: unless (-e $makepath) {
408: unless(mkdir($makepath,0755)) {
409: $fail = &mt('Directory creation failed.');
410: }
411: }
412: }
413: if ($i == 0) {
414: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
415: } else {
416: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
417: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
418: &mt('(dependency)').'</span>: ';
419: }
420: if (-e $path.'/'.$newfilename) {
421: $fail = &mt('Destination already exists -- not overwriting.');
422: } else {
423: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
424: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
425: ($item =~ /^simpleproblem_/)) {
426: print $fh $newcontent{$item};
427: } else {
428: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
429: if (-e $fileloc) {
430: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
431: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
432: (ref($has_simpleprobs{$item}) eq 'HASH')) {
433: my %changes = %{$has_simpleprobs{$item}};
434: my $content = &Apache::lonclonecourse::rewritefile(
435: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
436: (%replacehash,$crs => '')
437: );
438: my $updatedcontent = '';
439: my $parser = HTML::TokeParser->new(\$content);
440: $parser->attr_encoded(1);
441: while (my $token = $parser->get_token) {
442: if ($token->[0] eq 'S') {
443: if (($token->[1] eq 'resource') &&
444: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
445: ($changes{$token->[2]->{'id'}})) {
446: my $id = $token->[2]->{'id'};
447: $updatedcontent .= '<'.$token->[1];
448: foreach my $attrib (@{$token->[3]}) {
449: next unless ($attrib =~ /^(src|type|title|id)$/);
450: if ($attrib eq 'src') {
451: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
452: if ($file) {
453: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
454: } else {
455: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
456: }
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: }
461: $updatedcontent .= ' />'."\n";
462: } else {
463: $updatedcontent .= $token->[4]."\n";
464: }
465: } else {
466: $updatedcontent .= $token->[2];
467: }
468: }
469: print $fh $updatedcontent;
470: } else {
471: print $fh &Apache::lonclonecourse::rewritefile(
472: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
473: (%replacehash,$crs => '')
474: );
475: }
476: } else {
477: print $fh
478: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
479: }
480: } else {
481: $fail = &mt('Source does not exist.');
482: }
483: }
484: $fh->close();
485: } else {
486: $fail = &mt('Could not write to destination.');
487: }
488: }
489: my $text;
490: if ($fail) {
491: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
492: } else {
493: $text = '<span class="LC_success">'.&mt('ok').'</span>';
494: }
495: if ($i == 0) {
496: $result .= $text;
497: } else {
498: $depresult .= $text.'</li>';
499: }
500: }
501: $r->print($result);
502: if ($depresult) {
503: $r->print('<ul>'.$depresult.'</ul>');
504: }
505: }
1.329 droeschl 506: } else {
1.484.2.43 raeburn 507: my ($navmap,$errormsg) =
508: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
509: if (!ref($navmap)) {
510: $r->print($errormsg);
511: } else {
512: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
513: $r->rflush();
514: my ($preamble,$formname);
515: $formname = 'dumpdoc';
516: unless ($home==1) {
517: $preamble = '<div class="LC_left_float">'.
518: '<fieldset><legend>'.
519: &mt('Select the Authoring Space').
520: '</legend><select name="authorspace">';
521: }
522: my @orderspaces = ();
523: foreach my $key (sort(keys(%outhash))) {
524: if ($key=~/^home_(.+)$/) {
525: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
526: unshift(@orderspaces,$1);
527: } else {
528: push(@orderspaces,$1);
529: }
530: }
531: }
532: if ($home>1) {
533: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
534: }
535: foreach my $user (@orderspaces) {
536: if ($home==1) {
537: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
538: } else {
539: $preamble .= '<option value="'.$user.'">'.$user.' - '.
540: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
541: }
542: }
543: unless ($home==1) {
544: $preamble .= '</select></fieldset></div>'."\n";
545: }
546: my $title=$origcrsdata{'description'};
547: $title=~s/[\/\s]+/\_/gs;
548: $title=&clean($title);
549: $preamble .= '<div class="LC_left_float">'.
550: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
551: '<input type="text" size="50" name="authorfolder" value="'.
552: $title.'" />'.
553: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
554: my %uploadedfiles;
555: &tiehash();
556: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
557: my ($ext)=($file=~/\.(\w+)$/);
558: # FIXME Check supplemental here
559: my $title=$hash{'title_'.$hash{
560: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
561: if (!$title) {
562: $title=$file;
563: } else {
564: $title=~s|/|_|g;
565: }
566: $title=~s/\.(\w+)$//;
567: $title=&clean($title);
568: $title.='.'.$ext;
569: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
570: $uploadedfiles{$file} = $title;
571: }
572: &untiehash();
573: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
574: undef,undef,$preamble,$home,\%uploadedfiles));
575: }
1.329 droeschl 576: }
1.484 raeburn 577: $r->print(&endContentScreen());
1.329 droeschl 578: }
579:
1.484.2.43 raeburn 580: sub recurse_html {
581: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
582: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
583: my (%allfiles,%codebase);
584: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
585: if (keys(%allfiles)) {
586: foreach my $dependency (keys(%allfiles)) {
587: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
588: my ($depurl,$relfile,$newcontainer);
589: if ($dependency =~ m{^/}) {
590: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
591: $relfile = $1;
592: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
593: $newcontainer = $1;
594: next if ($replacehash->{$newcontainer});
595: }
596: $depurl = $dependency;
597: } else {
598: next;
599: }
600: } else {
601: $relfile = $dependency;
602: $depurl = $currurlpath;
603: $depurl =~ s{[^/]+$}{};
604: $depurl .= $dependency;
605: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
606: }
607: next if ($relfile eq '');
608: my $newname = $replacehash->{$container};
609: $newname =~ s{[^/]+$}{};
610: $replacehash->{$newcontainer} = $newname.$relfile;
611: $deps->{$item}{$newcontainer} = 1;
612: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
613: my $depfile = &Apache::lonnet::filelocation('',$depurl);
614: my $type = $mm->checktype_filename($depfile);
615: if ($type eq 'text/html') {
616: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
617: }
618: }
619: }
620: }
621: return;
622: }
623:
1.329 droeschl 624: sub group_import {
1.484.2.72.2. (raeburn 625:): my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.484.2.23 raeburn 626: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
627: %removeparam,$importuploaded,$fixuperrors);
628: $allmaps = {};
1.329 droeschl 629: while (@files) {
630: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 631: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 632: && ($caller eq 'londocs')
633: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 634:
1.329 droeschl 635: my $errtext = '';
636: my $fatal = 0;
637: my $newmapstr = '<map>'."\n".
638: '<resource id="1" src="" type="start"></resource>'."\n".
639: '<link from="1" to="2" index="1"></link>'."\n".
640: '<resource id="2" src="" type="finish"></resource>'."\n".
641: '</map>';
642: $env{'form.output'}=$newmapstr;
643: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
644: 'output',$1.$2);
1.484.2.27 raeburn 645: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 646: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
647: $fatal = 2;
648: }
649: if ($fatal) {
650: return ($errtext,$fatal);
651: }
652: }
653: if ($url) {
1.484.2.72.2. (raeburn 654:): if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
655:): $url = $1;
656:): my $marker = $2;
657:): my $info = $3;
658:): my ($toolid,%toolhash,%toolsettings);
659:): my @extras = ('linktext','explanation','crslabel','crstitle');
660:): my @toolinfo = split(/:/,$info);
661:): if ($residx) {
662:): %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
663:): $toolid = $toolsettings{'id'};
664:): } else {
665:): $toolid = shift(@toolinfo);
666:): }
667:): $toolid =~ s/\D//g;
668:): ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
669:): $toolhash{'linktext'},$toolhash{'explanation'},
670:): $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
671:): foreach my $item (@extras) {
672:): $toolhash{$item} = &unescape($toolhash{$item});
673:): }
674:): if (ref($ltitoolsref) eq 'HASH') {
675:): my @deleted;
676:): if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
677:): $toolhash{'id'} = $toolid;
678:): if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
679:): ($toolhash{'target'} eq 'window')) {
680:): if ($toolhash{'target'} eq 'window') {
681:): foreach my $item ('width','height') {
682:): $toolhash{$item} =~ s/^\s+//;
683:): $toolhash{$item} =~ s/\s+$//;
684:): if ($toolhash{$item} =~ /\D/) {
685:): delete($toolhash{$item});
686:): if ($residx) {
687:): if ($toolsettings{$item}) {
688:): push(@deleted,$item);
689:): }
690:): }
691:): }
692:): }
693:): }
694:): } elsif ($residx) {
695:): $toolhash{'target'} = $toolsettings{'target'};
696:): if ($toolhash{'target'} eq 'window') {
697:): foreach my $item ('width','height') {
698:): $toolhash{$item} = $toolsettings{$item};
699:): }
700:): }
701:): } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
702:): $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
703:): if ($toolhash{'target'} eq 'window') {
704:): $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
705:): $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
706:): }
707:): }
708:): if ($toolhash{'target'} eq 'iframe') {
709:): foreach my $item ('width','height','linktext','explanation') {
710:): delete($toolhash{$item});
711:): if ($residx) {
712:): if ($toolsettings{$item}) {
713:): push(@deleted,$item);
714:): }
715:): }
716:): }
717:): } elsif ($toolhash{'target'} eq 'tab') {
718:): foreach my $item ('width','height') {
719:): delete($toolhash{$item});
720:): if ($residx) {
721:): if ($toolsettings{$item}) {
722:): push(@deleted,$item);
723:): }
724:): }
725:): }
726:): }
727:): if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
728:): foreach my $item ('label','title','linktext','explanation') {
729:): my $crsitem;
730:): if (($item eq 'label') || ($item eq 'title')) {
731:): $crsitem = 'crs'.$item;
732:): } else {
733:): $crsitem = $item;
734:): }
735:): if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
736:): $toolhash{$crsitem} =~ s/^\s+//;
737:): $toolhash{$crsitem} =~ s/\s+$//;
738:): if ($toolhash{$crsitem} eq '') {
739:): delete($toolhash{$crsitem});
740:): }
741:): } else {
742:): delete($toolhash{$crsitem});
743:): }
744:): if (($residx) && (exists($toolsettings{$crsitem}))) {
745:): unless (exists($toolhash{$crsitem})) {
746:): push(@deleted,$crsitem);
747:): }
748:): }
749:): }
750:): }
751:): my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
752:): if ($putres eq 'ok') {
753:): if (@deleted) {
754:): &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
755:): }
756:): }
757:): }
758:): }
759:): }
1.484.2.23 raeburn 760: if (($caller eq 'londocs') &&
761: ($folder =~ /^default/)) {
1.484.2.27 raeburn 762: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 763: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
764: my $cid = $coursedom.'_'.$coursenum;
765: $allmaps =
766: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
767: $chome,$cid);
768: $donechk = 1;
769: }
770: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.484.2.72.2. (raeburn 771:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
772:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.484.2.23 raeburn 773: $importuploaded = 1;
774: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
775: next if ($allmaps->{$url});
776: }
777: }
1.344 bisitz 778: if (!$residx
1.329 droeschl 779: || defined($LONCAPA::map::zombies[$residx])) {
780: $residx = &LONCAPA::map::getresidx($url,$residx);
781: push(@LONCAPA::map::order, $residx);
782: }
783: my $ext = 'false';
784: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
785: $name = &LONCAPA::map::qtunescape($name);
1.484.2.27 raeburn 786: if ($name eq '') {
1.484.2.30 raeburn 787: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.484.2.27 raeburn 788: }
789: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
790: my $filepath = $1;
791: my $fname = $name;
792: if ($fname =~ /^\W+$/) {
793: $fname = 'web';
794: } else {
795: $fname =~ s/\W/_/g;
796: }
1.484.2.62 raeburn 797: if (length($fname) > 15) {
1.484.2.27 raeburn 798: $fname = substr($fname,0,14);
799: }
800: my $initialtext = &mt('Replace with your own content.');
801: my $newhtml = <<END;
1.484.2.31 raeburn 802: <html>
1.484.2.27 raeburn 803: <head>
804: <title>$name</title>
805: </head>
806: <body bgcolor="#ffffff">
807: $initialtext
808: </body>
809: </html>
810: END
811: $env{'form.output'}=$newhtml;
812: my $result =
813: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
814: 'output',
815: "$filepath/$residx/$fname.html");
816: if ($result =~ m{^/uploaded/}) {
817: $url = $result;
818: if ($filepath =~ /^supplemental/) {
819: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
820: $env{'user.domain'}.'___&&&___'.$name;
821: }
822: } else {
823: return (&mt('Failed to save new web page.'),1);
824: }
825: }
1.484.2.30 raeburn 826: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 827: $LONCAPA::map::resources[$residx] =
1.329 droeschl 828: join(':', ($name, $url, $ext, 'normal', 'res'));
829: }
830: }
1.484.2.23 raeburn 831: if ($importuploaded) {
832: my %import_errors;
833: my %updated = (
834: removefrommap => \%removefrommap,
835: removeparam => \%removeparam,
836: );
1.484.2.26 raeburn 837: my ($result,$msgsarray,$lockerror) =
838: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 839: if (keys(%import_errors) > 0) {
840: $fixuperrors =
841: '<p span class="LC_warning">'."\n".
842: &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".
843: '<ul>'."\n";
844: foreach my $key (sort(keys(%import_errors))) {
845: $fixuperrors .= '<li>'.$key.'</li>'."\n";
846: }
847: $fixuperrors .= '</ul></p>'."\n";
848: }
1.484.2.26 raeburn 849: if (ref($msgsarray) eq 'ARRAY') {
850: if (@{$msgsarray} > 0) {
851: $fixuperrors .= '<p class="LC_info">'.
852: join('<br />',@{$msgsarray}).
853: '</p>';
854: }
855: }
856: if ($lockerror) {
857: $fixuperrors .= '<p class="LC_error">'.
858: $lockerror.
859: '</p>';
860: }
1.484.2.23 raeburn 861: }
862: my ($errtext,$fatal) =
863: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 864: unless ($fatal) {
865: if ($folder =~ /^supplemental/) {
866: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 867: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
868: $folder.'.'.$container);
1.484.2.37 raeburn 869: }
870: }
1.484.2.23 raeburn 871: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 872: }
873:
874: sub log_docs {
1.484.2.8 raeburn 875: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 876: }
877:
878: {
879: my @oldresources=();
880: my @oldorder=();
881: my $parmidx;
882: my %parmaction=();
883: my %parmvalue=();
884: my $changedflag;
885:
886: sub snapshotbefore {
887: @oldresources=@LONCAPA::map::resources;
888: @oldorder=@LONCAPA::map::order;
889: $parmidx=undef;
890: %parmaction=();
891: %parmvalue=();
892: $changedflag=0;
893: }
894:
895: sub remember_parms {
896: my ($idx,$parameter,$action,$value)=@_;
897: $parmidx=$idx;
898: $parmaction{$parameter}=$action;
899: $parmvalue{$parameter}=$value;
900: $changedflag=1;
901: }
902:
903: sub log_differences {
904: my ($plain)=@_;
905: my %storehash=('folder' => $plain,
906: 'currentfolder' => $env{'form.folder'});
907: if ($parmidx) {
908: $storehash{'parameter_res'}=$oldresources[$parmidx];
909: foreach my $parm (keys(%parmaction)) {
910: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
911: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
912: }
913: }
914: my $maxidx=$#oldresources;
915: if ($#LONCAPA::map::resources>$#oldresources) {
916: $maxidx=$#LONCAPA::map::resources;
917: }
918: for (my $idx=0; $idx<=$maxidx; $idx++) {
919: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
920: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
921: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
922: $changedflag=1;
923: }
924: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
925: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
926: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
927: $changedflag=1;
928: }
929: }
930: $storehash{'maxidx'}=$maxidx;
931: if ($changedflag) { &log_docs(\%storehash); }
932: }
933: }
934:
935: sub docs_change_log {
1.484.2.67 raeburn 936: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 937: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 938: my $navmap;
1.483 raeburn 939: my $js = '<script type="text/javascript">'."\n".
940: '// <![CDATA['."\n".
941: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 942: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.72.2. (raeburn 943:): $coursedom,$coursenum,'',$canedit,\$navmap)."\n".
1.483 raeburn 944: &history_tab_js()."\n".
1.484 raeburn 945: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 946: '// ]]>'."\n".
947: '</script>'."\n";
1.484 raeburn 948: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
949: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 950: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 951: my %orderhash;
952: my $container='sequence';
953: my $pathitem;
1.484.2.19 raeburn 954: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 955: $container='page';
956: }
1.484.2.19 raeburn 957: my $folderpath=$env{'form.folderpath'};
958: if ($folderpath eq '') {
1.484.2.67 raeburn 959: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 960: }
1.484.2.67 raeburn 961: undef($navmap);
1.484.2.19 raeburn 962: $pathitem = '<input type="hidden" name="folderpath" value="'.
963: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 964: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
965: my $jumpto = $readfile;
966: $jumpto =~ s{^/}{};
967: my $tid = 1;
1.484.2.7 raeburn 968: if ($supplementalflag) {
969: $tid = 2;
970: }
1.484.2.19 raeburn 971: my ($breadcrumbtrail) =
1.484.2.18 raeburn 972: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 973: $r->print($breadcrumbtrail.
974: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
975: $readfile));
1.329 droeschl 976: my %docslog=&Apache::lonnet::dump('nohist_docslog',
977: $env{'course.'.$env{'request.course.id'}.'.domain'},
978: $env{'course.'.$env{'request.course.id'}.'.num'});
979:
980: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
981:
982: my %saveable_parameters = ('show' => 'scalar',);
983: &Apache::loncommon::store_course_settings('docs_log',
984: \%saveable_parameters);
985: &Apache::loncommon::restore_course_settings('docs_log',
986: \%saveable_parameters);
987: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 988: # FIXME: internationalization seems wrong here
1.329 droeschl 989: my %lt=('hiddenresource' => 'Resources hidden',
990: 'encrypturl' => 'URL hidden',
991: 'randompick' => 'Randomly pick',
992: 'randomorder' => 'Randomly ordered',
993: 'set' => 'set to',
994: 'del' => 'deleted');
1.484 raeburn 995: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
996: $pathitem."\n".
997: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
998: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
999: $r->print('<div class="LC_left_float">'.
1000: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1001: &makedocslogform($filter,1).
1002: '</fieldset></div><br clear="all" />');
1.329 droeschl 1003: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1004: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1005: &mt('After').'</th>'.
1006: &Apache::loncommon::end_data_table_header_row());
1007: my $shown=0;
1008: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1009: if ($env{'form.displayfilter'} eq 'currentfolder') {
1010: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1011: }
1012: my @changes=keys(%{$docslog{$id}{'logentry'}});
1013: if ($env{'form.displayfilter'} eq 'containing') {
1014: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1015: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1016: foreach my $key (@changes) {
1017: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1018: }
1.344 bisitz 1019: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1020: }
1021: my $count = 0;
1022: my $time =
1023: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1024: my $plainname =
1025: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1026: $docslog{$id}{'exe_udom'});
1027: my $about_me_link =
1028: &Apache::loncommon::aboutmewrapper($plainname,
1029: $docslog{$id}{'exe_uname'},
1030: $docslog{$id}{'exe_udom'});
1031: my $send_msg_link='';
1032: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1033: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1034: $send_msg_link ='<br />'.
1035: &Apache::loncommon::messagewrapper(&mt('Send message'),
1036: $docslog{$id}{'exe_uname'},
1037: $docslog{$id}{'exe_udom'});
1038: }
1039: $r->print(&Apache::loncommon::start_data_table_row());
1040: $r->print('<td>'.$time.'</td>
1041: <td>'.$about_me_link.
1042: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1043: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1044: $send_msg_link.'</td><td>'.
1045: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 1046: my $is_supp = 0;
1.484.2.7 raeburn 1047: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1048: $is_supp = 1;
1049: }
1.329 droeschl 1050: # Before
1051: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1052: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1053: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1054: if ($oldname ne $newname) {
1.484.2.7 raeburn 1055: my $shown = &LONCAPA::map::qtescape($oldname);
1056: if ($is_supp) {
1057: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1058: }
1059: $r->print($shown);
1.329 droeschl 1060: }
1061: }
1062: $r->print('<ul>');
1063: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1064: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 1065: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1066: if ($is_supp) {
1067: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1068: }
1.484.2.19 raeburn 1069: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1070: }
1071: }
1072: $r->print('</ul>');
1073: # After
1074: $r->print('</td><td>');
1075:
1076: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1077: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1078: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1079: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 1080: my $shown = &LONCAPA::map::qtescape($newname);
1081: if ($is_supp) {
1082: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1083: }
1084: $r->print($shown);
1.329 droeschl 1085: }
1.364 bisitz 1086: }
1.329 droeschl 1087: $r->print('<ul>');
1088: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1089: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 1090: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1091: if ($is_supp) {
1092: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1093: }
1094: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1095: }
1096: }
1097: $r->print('</ul>');
1098: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1099: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1100: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1101: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1102: # FIXME: internationalization seems wrong here
1.329 droeschl 1103: $r->print('<li>'.
1104: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1105: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1106: .'</li>');
1107: }
1108: }
1109: $r->print('</ul>');
1110: }
1111: # End
1112: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1113: $shown++;
1114: if (!($env{'form.show'} eq &mt('all')
1115: || $shown<=$env{'form.show'})) { last; }
1116: }
1.484 raeburn 1117: $r->print(&Apache::loncommon::end_data_table()."\n".
1118: &makesimpleeditform($pathitem)."\n".
1119: '</div></div>');
1120: $r->print(&endContentScreen());
1.329 droeschl 1121: }
1122:
1123: sub update_paste_buffer {
1.484.2.7 raeburn 1124: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1125: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1126: if ($env{'form.multiremove'}) {
1127: $env{'form.multiremove'} =~ s/,$//;
1128: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1129: }
1130: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1131: if ($env{'form.multicut'}) {
1132: $env{'form.multicut'} =~ s/,$//;
1133: foreach my $item (split(/,/,$env{'form.multicut'})) {
1134: unless ($removals{$item}) {
1135: $cuts{$item} = 1;
1136: push(@possibles,$item.':cut');
1137: }
1138: }
1139: }
1140: if ($env{'form.multicopy'}) {
1141: $env{'form.multicopy'} =~ s/,$//;
1142: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1143: unless ($removals{$item} || $cuts{$item}) {
1144: push(@possibles,$item.':copy');
1145: }
1146: }
1147: }
1148: } elsif ($env{'form.markcopy'}) {
1149: @possibles = split(/,/,$env{'form.markcopy'});
1150: }
1.329 droeschl 1151:
1.484.2.30 raeburn 1152: return if (@possibles == 0);
1.329 droeschl 1153: return if (!defined($env{'form.copyfolder'}));
1154:
1155: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1156: $env{'form.copyfolder'});
1157: return if ($fatal);
1158:
1.484.2.30 raeburn 1159: my %curr_groups = &Apache::longroup::coursegroups();
1160:
1161: # Retrieve current paste buffer suffixes.
1162: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1163: my (%pasteurls,@newpaste);
1164:
1165: # Construct identifiers for current contents of user's paste buffer
1166: if (@currpaste) {
1167: foreach my $suffix (@currpaste) {
1168: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1169: my $url = $env{'docs.markedcopy_url_'.$suffix};
1170: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1171: ($url ne '')) {
1.484.2.41 raeburn 1172: $pasteurls{$cid.'_'.$url} = 1;
1.484.2.30 raeburn 1173: }
1174: }
1175: }
1176:
1177: # Mark items for copying (skip any items already in user's paste buffer)
1178: my %addtoenv;
1179:
1180: foreach my $item (@possibles) {
1181: my ($orderidx,$cmd) = split(/:/,$item);
1182: next if ($orderidx =~ /\D/);
1183: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1184: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1185: my %denied = &action_restrictions($coursenum,$coursedom,
1186: &LONCAPA::map::qtescape($url),
1187: $env{'form.folderpath'},\%curr_groups);
1188: next if ($denied{'copy'});
1189: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1190: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1191: my ($suffix,$errortxt,$locknotfreed) =
1192: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1193: if ($suffix ne '') {
1194: push(@newpaste,$suffix);
1195: } else {
1196: if ($locknotfreed) {
1197: return $locknotfreed;
1198: }
1.484.2.30 raeburn 1199: }
1200: if (&is_supplemental_title($title)) {
1201: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1202: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1203: }
1204:
1205: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1206: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1207: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1208: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1209:
1210: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1211: my $prefix = $1;
1212: my $subdir =$2;
1213: if ($subdir eq '') {
1214: $subdir = $prefix;
1.484.2.7 raeburn 1215: }
1.484.2.30 raeburn 1216: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.484.2.72.2. (raeburn 1217:): &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1218:): \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.484.2.30 raeburn 1219: if (ref($hierarchy{$url}) eq 'HASH') {
1220: my ($nested,$nestednames);
1221: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1222: $nested =~ s/\&$//;
1223: $nestednames =~ s/\Q___&&&___\E$//;
1224: if ($nested ne '') {
1225: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1226: }
1227: if ($nestednames ne '') {
1228: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1229: }
1.484.2.7 raeburn 1230: }
1231: }
1.484.2.57 raeburn 1232: if ($locknotfreed) {
1233: $output = $locknotfreed;
1234: last;
1235: }
1.484.2.7 raeburn 1236: }
1.484.2.30 raeburn 1237: if (@newpaste) {
1238: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1239: }
1.484.2.7 raeburn 1240: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1241: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1242: return $output;
1.329 droeschl 1243: }
1244:
1.484.2.7 raeburn 1245: sub recurse_uploaded_maps {
1246: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1247: if (ref($hierarchy->{$url}) eq 'HASH') {
1248: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1249: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1250: my (@uploaded,@names,%shorter);
1251: for (my $i=0; $i<@maps; $i++) {
1252: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1253: if ($inner ne '') {
1254: push(@uploaded,$inner);
1255: push(@names,&escape($titles[$i]));
1256: $shorter{$maps[$i]} = $inner;
1257: }
1258: }
1259: $$nestref .= "$dir:".join(',',@uploaded).'&';
1260: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1261: foreach my $map (@maps) {
1262: if ($shorter{$map} ne '') {
1263: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1264: }
1265: }
1266: }
1267: return;
1268: }
1269:
1.329 droeschl 1270: sub print_paste_buffer {
1.484.2.7 raeburn 1271: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1272: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1273:
1.484.2.30 raeburn 1274: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1275: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1276: }
1277:
1.484.2.30 raeburn 1278: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1279: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1280: my $clipboardcount = 0;
1.484.2.7 raeburn 1281:
1.484.2.30 raeburn 1282: # Construct identifiers for current contents of user's paste buffer
1283: foreach my $suffix (@currpaste) {
1284: next if ($suffix =~ /\D/);
1285: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1286: my $url = $env{'docs.markedcopy_url_'.$suffix};
1287: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1288: ($url ne '')) {
1.484.2.47 raeburn 1289: $clipboardcount ++;
1.484.2.30 raeburn 1290: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.484.2.72.2. (raeburn 1291:): $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.484.2.30 raeburn 1292: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1293: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1294: $is_external = 1;
1.484.2.72.2. (raeburn 1295:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1296:): $is_exttool = 1;
1.484.2.7 raeburn 1297: }
1.484.2.30 raeburn 1298: if ($folder =~ /^supplemental/) {
1299: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1300: unless ($canpaste) {
1301: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1302: }
1.484.2.30 raeburn 1303: } else {
1304: $canpaste = 1;
1.484.2.7 raeburn 1305: }
1.484.2.30 raeburn 1306: if ($canpaste) {
1307: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1308: my $srcdom = $1;
1309: my $srcnum = $2;
1310: my $rem = $3;
1311: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1312: $othercourse = 1;
1313: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.72.2. (raeburn 1314:): $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1315: } else {
1316: $canpaste = 0;
1317: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1318: }
1319: }
1.484.2.30 raeburn 1320: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1321: my $prefix = $1;
1322: $parent = $2;
1323: if ($folder !~ /^\Q$prefix\E/) {
1324: $areachange = 1;
1325: }
1326: $is_uploaded_map = 1;
1327: }
1.484.2.72.2. (raeburn 1328:): } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1329:): ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1330:): if ($cid ne $env{'request.course.id'}) {
1331:): my ($srcdom,$srcnum) = split(/_/,$cid);
1332:): if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1333:): if (($is_exttool) && ($srcdom ne $coursedom)) {
1334:): $canpaste = 0;
1335:): $nopaste = &mt('Paste from another domain unavailable.');
1336:): } else {
1337:): $othercrs = '<br />'.&mt('(from another course)');
1338:): }
1339:): } else {
1340:): $canpaste = 0;
1341:): $nopaste = &mt('Paste from another course unavailable.');
1342:): }
1343:): }
1.484.2.30 raeburn 1344: }
1345: }
1346: if ($canpaste) {
1347: push(@pasteable,$suffix);
1348: }
1349: my $buffer;
1.484.2.72.2. (raeburn 1350:): if ($is_external) {
1.484.2.30 raeburn 1351: $buffer = &mt('External Resource').': '.
1352: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1353: &LONCAPA::map::qtescape($url).')';
1.484.2.72.2. (raeburn 1354:): } elsif ($is_exttool) {
1355:): $buffer = &mt('External Tool').': '.
1356:): &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.30 raeburn 1357: } else {
1358: my $icon = &Apache::loncommon::icon($extension);
1359: if ($extension eq 'sequence' &&
1360: $url =~ m{/default_\d+\.sequence$}x) {
1361: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1362: $icon .= '/navmap.folder.closed.gif';
1363: }
1.484.2.57 raeburn 1364: my $title = $env{'docs.markedcopy_title_'.$suffix};
1365: if ($title eq '') {
1366: ($title) = ($url =~ m{/([^/]+)$});
1367: }
1.484.2.30 raeburn 1368: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1369: ': '.
1370: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1371: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1372: }
1373: $pasteitems .= '<div class="LC_left_float">';
1374: my ($options,$onclick);
1375: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1376: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1377: if (($is_uploaded_map) ||
1378: ($url =~ /(bulletinboard|smppg)$/) ||
1379: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1380: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1381: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1382: }
1383: }
1384: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1385: if ($nopaste) {
1386: $pasteitems .= $nopaste;
1387: } else {
1388: if ($othercrs) {
1389: $pasteitems .= $othercrs;
1390: }
1391: if ($options) {
1392: $pasteitems .= $options;
1.484.2.7 raeburn 1393: }
1394: }
1.484.2.30 raeburn 1395: $pasteitems .= '</div>';
1396: }
1397: }
1398: if ($pasteitems eq '') {
1399: &Apache::lonnet::delenv('docs.markedcopies');
1400: }
1401: my ($pasteform,$form_start,$buttons,$form_end);
1402: if ($pasteitems) {
1403: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1404: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1405: if (@pasteable) {
1.484.2.47 raeburn 1406: my $value = &mt('Paste to current folder');
1407: if ($container eq 'page') {
1408: $value = &mt('Paste to current page');
1409: }
1410: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1411: }
1.484.2.72.2. (raeburn 1412:): $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1.484.2.47 raeburn 1413: if ($clipboardcount > 1) {
1414: $buttons .=
1415: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1416: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1417: (' 'x2).
1418: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1419: (' 'x2);
1.484.2.7 raeburn 1420: }
1.484.2.48 raeburn 1421: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1422: '</form>';
1.484.2.30 raeburn 1423: } else {
1424: $pasteitems = &mt('Clipboard is empty');
1425: }
1426: $r->print($form_start
1427: .'<fieldset>'
1428: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1429: .$pasteitems
1430: .'</fieldset>'
1431: .$form_end);
1432: }
1433:
1434: sub paste_options {
1435: my ($suffix,$is_uploaded_map,$parent) = @_;
1436: my ($copytext,$movetext);
1437: if ($is_uploaded_map) {
1438: $copytext = &mt('Copy to new folder');
1439: $movetext = &mt('Move old');
1440: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1441: $copytext = &mt('Copy to new board');
1442: $movetext = &mt('Move (not posts)');
1443: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1444: $copytext = &mt('Copy to new page');
1445: $movetext = &mt('Move');
1.484.2.7 raeburn 1446: } else {
1.484.2.30 raeburn 1447: $copytext = &mt('Copy to new file');
1448: $movetext = &mt('Move');
1449: }
1450: my $output = '<br />'.
1451: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1452: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1453: '<label>'.
1454: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1455: $copytext.'</label></span>'.(' 'x2).' '.
1456: '<span class="LC_nobreak"><label>'.
1457: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1458: $movetext.'</label></span>';
1459: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1460: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1461: '</legend><table border="0">';
1462: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1463: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1464: my $lastdir = $parent;
1465: my %depths = (
1466: $lastdir => 0,
1467: );
1468: my (%display,%deps);
1469: for (my $i=0; $i<@pastemaps; $i++) {
1470: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1471: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1472: my @subfolders = split(/,/,$subfolderstr);
1473: $deps{$lastdir} = \@subfolders;
1474: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1475: my $depth = $depths{$lastdir} + 1;
1476: my $offset = int($depth * 4);
1477: my $indent = (' ' x $offset);
1478: for (my $j=0; $j<@subfolders; $j++) {
1479: $depths{$subfolders[$j]} = $depth;
1480: $display{$subfolders[$j]} =
1481: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1482: '<td><label>'.
1483: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1484: '<label>'.
1485: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1486: &mt('Move old').'</label>'.
1487: '</td></tr>';
1488: }
1489: }
1490: &recurse_print(\$output,$parent,\%deps,\%display);
1491: $output .= '</table></fieldset>';
1.329 droeschl 1492: }
1.484.2.30 raeburn 1493: $output .= '</div>';
1494: return $output;
1.329 droeschl 1495: }
1496:
1.484.2.7 raeburn 1497: sub recurse_print {
1.484.2.30 raeburn 1498: my ($outputref,$dir,$deps,$display) = @_;
1499: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1500: if (ref($deps->{$dir}) eq 'ARRAY') {
1501: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1502: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1503: }
1504: }
1505: }
1506:
1507: sub supp_pasteable {
1508: my ($url) = @_;
1509: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1510: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1511: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1512: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.484.2.72.2. (raeburn 1513:): ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1514:): ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.484.2.7 raeburn 1515: return 1;
1516: }
1517: return;
1518: }
1519:
1520: sub paste_popup_js {
1.484.2.61 raeburn 1521: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1522: show => 'Show Options',
1523: hide => 'Hide Options',
1.484.2.61 raeburn 1524: );
1525: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1526: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1527: );
1.484.2.61 raeburn 1528: &html_escape(\%html_js_lt);
1529: &js_escape(\%html_js_lt);
1530: &js_escape(\%js_lt);
1.484.2.7 raeburn 1531: return <<"END";
1532:
1.484.2.30 raeburn 1533: function showPasteOptions(suffix) {
1534: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1535: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1536: return;
1537: }
1538:
1.484.2.30 raeburn 1539: function hidePasteOptions(suffix) {
1540: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1541: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1542: return;
1543: }
1544:
1.484.2.30 raeburn 1545: function showOptions(caller,suffix) {
1546: if (document.getElementById('pasteoptionstext_'+suffix)) {
1547: if (caller.checked) {
1.484.2.61 raeburn 1548: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1549: } else {
1550: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1551: }
1552: if (document.getElementById('pasteoptions_'+suffix)) {
1553: document.getElementById('pasteoptions_'+suffix).style.display='none';
1554: }
1555: }
1556: return;
1557: }
1.484.2.7 raeburn 1558:
1.484.2.30 raeburn 1559: function validateClipboard() {
1560: var numchk = 0;
1561: if (document.pasteform.pasting.length > 1) {
1562: for (var i=0; i<document.pasteform.pasting.length; i++) {
1563: if (document.pasteform.pasting[i].checked) {
1564: numchk ++;
1565: }
1566: }
1567: } else {
1568: if (document.pasteform.pasting.type == 'checkbox') {
1569: if (document.pasteform.pasting.checked) {
1570: numchk ++;
1571: }
1572: }
1573: }
1574: if (numchk > 0) {
1575: return true;
1576: } else {
1.484.2.61 raeburn 1577: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1578: return false;
1579: }
1.484.2.7 raeburn 1580: }
1581:
1.484.2.47 raeburn 1582: function checkClipboard() {
1583: if (document.pasteform.pasting.length > 1) {
1584: for (var i=0; i<document.pasteform.pasting.length; i++) {
1585: document.pasteform.pasting[i].checked = true;
1586: }
1587: }
1588: return;
1589: }
1590:
1591: function uncheckClipboard() {
1592: if (document.pasteform.pasting.length >1) {
1593: for (var i=0; i<document.pasteform.pasting.length; i++) {
1594: document.pasteform.pasting[i].checked = false;
1595: }
1596: }
1597: return;
1598: }
1599:
1.484.2.30 raeburn 1600: END
1601:
1602: }
1.484.2.7 raeburn 1603:
1.329 droeschl 1604: sub do_paste_from_buffer {
1.484.2.7 raeburn 1605: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1606:
1.484.2.30 raeburn 1607: # Array of items in paste buffer
1608: my (@currpaste,%pastebuffer,%allerrors);
1609: @currpaste = split(/,/,$env{'docs.markedcopies'});
1610:
1.484.2.7 raeburn 1611: # Early out if paste buffer is empty
1.484.2.30 raeburn 1612: if (@currpaste == 0) {
1.484.2.7 raeburn 1613: return ();
1.484.2.30 raeburn 1614: }
1615: map { $pastebuffer{$_} = 1; } @currpaste;
1616:
1617: # Array of items selected items to paste
1618: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1619:
1620: # Early out if nothing selected to paste
1621: if (@reqpaste == 0) {
1622: return();
1623: }
1624: my @topaste;
1625: foreach my $suffix (@reqpaste) {
1626: next if ($suffix =~ /\D/);
1627: next unless (exists($pastebuffer{$suffix}));
1628: push(@topaste,$suffix);
1.484.2.7 raeburn 1629: }
1630:
1.484.2.30 raeburn 1631: # Early out if nothing available to paste
1632: if (@topaste == 0) {
1633: return();
1.329 droeschl 1634: }
1635:
1.484.2.72.2. (raeburn 1636:): my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.484.2.41 raeburn 1637: %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1638:
1.484.2.30 raeburn 1639: foreach my $suffix (@topaste) {
1640: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.72.2. (raeburn 1641:): my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1642: # Supplemental content may only include certain types of content
1643: # Early out if pasted content is not supported in Supplemental area
1644: if ($folder =~ /^supplemental/) {
1645: unless (&supp_pasteable($url)) {
1646: $notinsupp{$suffix} = 1;
1647: next;
1648: }
1649: }
1650: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1651: my $srcd = $1;
1652: my $srcn = $2;
1.484.2.7 raeburn 1653: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1654: # check for mdc privilege in the course from which the resource was pasted
1655: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1656: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1657: $notincrs{$suffix} = 1;
1658: next;
1659: }
1.329 droeschl 1660: }
1.484.2.30 raeburn 1661: $srcdom{$suffix} = $srcd;
1662: $srcnum{$suffix} = $srcn;
1.484.2.72.2. (raeburn 1663:): } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1664:): my ($srcd,$srcn) = split(/_/,$cid);
1665:): # When paste buffer was populated using an active role in a different course
1666:): # check for mdc privilege in the course from which the resource was pasted
1667:): if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1668:): unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1669:): $notincrs{$suffix} = 1;
1670:): next;
1671:): }
1672:): }
1673:): # When buffer was populated using an active role in a different course
1674:): # disallow pasting of External Tool if course is in a different domain.
1675:): if ($srcd ne $coursedom) {
1676:): $notindom{$suffix} = 1;
1677:): next;
1678:): }
1679:): $srcdom{$suffix} = $srcd;
1680:): $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1681: }
1682: push(@dopaste,$suffix);
1683: if ($url=~/\.(page|sequence)$/) {
1684: $is_map{$suffix} = 1;
1.329 droeschl 1685: }
1.484.2.30 raeburn 1686:
1687: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1688: my $oldprefix = $1;
1.484.2.19 raeburn 1689: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1690: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.72.2. (raeburn 1691:): # a folder/page or a document).
1.484.2.30 raeburn 1692: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1693: $prefixchg{$suffix} = 'docstosupp';
1694: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1695: $prefixchg{$suffix} = 'supptodocs';
1696: }
1.484.2.7 raeburn 1697:
1698: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1699: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1700: my @nested;
1701: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1702: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1703: my @deps = map { /\d+:([\d,]+$)/ } @items;
1704: foreach my $dep (@deps) {
1705: if ($dep =~ /,/) {
1706: push(@nested,split(/,/,$dep));
1707: } else {
1708: push(@nested,$dep);
1709: }
1.484.2.7 raeburn 1710: }
1.484.2.30 raeburn 1711: foreach my $item (@nested) {
1712: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1713: push(@{$marktomove{$suffix}},$type.'_'.$item);
1714: }
1.484.2.7 raeburn 1715: }
1716: }
1.329 droeschl 1717: }
1.484.2.7 raeburn 1718: }
1719:
1.484.2.30 raeburn 1720: # Early out if nothing available to paste
1721: if (@dopaste == 0) {
1722: return ();
1723: }
1724:
1725: # Populate message hash and hashes used for main content <=> supplemental content
1726: # changes
1727:
1728: %msgs = &Apache::lonlocal::texthash (
1729: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1730: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.484.2.72.2. (raeburn 1731:): notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.484.2.30 raeburn 1732: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1733: );
1734:
1735: %before = (
1736: docstosupp => {
1737: map => 'default',
1738: doc => 'docs',
1739: },
1740: supptodocs => {
1741: map => 'supplemental',
1742: doc => 'supplemental',
1743: },
1744: );
1745:
1746: %after = (
1747: docstosupp => {
1748: map => 'supplemental',
1749: doc => 'supplemental'
1750: },
1751: supptodocs => {
1752: map => 'default',
1753: doc => 'docs',
1754: },
1755: );
1756:
1757: # Retrieve information about all course maps in main content area
1758:
1759: my $allmaps = {};
1760: if ($folder =~ /^default/) {
1761: $allmaps =
1762: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1763: $env{"course.$env{'request.course.id'}.home"},
1764: $env{'request.course.id'});
1765: }
1766:
1767: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1768:
1769: # Loop over the items to paste
1770: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1771: # Maps need to be copied first
1.484.2.30 raeburn 1772: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1773: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1774: %newurls,%tomove);
1775: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1776: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1777: }
1778: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1779: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.72.2. (raeburn 1780:): my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1781: my $oldurl = $url;
1782: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1783: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1784: my (%hierarchy,%titles);
1.484.2.72.2. (raeburn 1785:): &contained_map_check($url,$folder,$coursenum,$coursedom,
1786:): \%removefrommap,\%removeparam,\%addedmaps,
1787:): \%hierarchy,\%titles,$allmaps);
1.484.2.30 raeburn 1788: if ($url=~ m{^/uploaded/}) {
1789: my $newurl;
1790: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1791: ($newurl,my $error) =
1792: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1793: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1794: \$title,$allmaps,\%newurls);
1795: if ($error) {
1796: $allerrors{$suffix} = $error;
1797: next;
1798: }
1799: if ($newurl ne '') {
1800: if ($newurl ne $url) {
1801: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1802: $newsubdir{$url} = $1;
1803: }
1804: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1805: }
1806: }
1807: }
1.484.2.30 raeburn 1808: if (($srcdom{$suffix} ne $coursedom) ||
1809: ($srcnum{$suffix} ne $coursenum) ||
1810: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1811: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1812: $coursedom,$coursenum,$srcdom{$suffix},
1813: $srcnum{$suffix},$allmaps,\%rewrites,
1814: \%retitles,\%copies,\%dbcopies,
1815: \%zombies,\%params,\%mapmoves,
1816: \%mapchanges,\%tomove,\%newsubdir,
1817: \%newurls)) {
1818: $mapmoves{$url} = 1;
1819: }
1820: $url = $newurl;
1821: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1822: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1823: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1824: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1825: \%zombies,\%params,\%mapmoves,\%mapchanges,
1826: \%tomove,\%newsubdir,\%newurls);
1827: }
1828: } elsif ($url=~m {^/res/}) {
1.484.2.72.2. (raeburn 1829:): # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1830: push(@toclear,$suffix);
1831: # if pasting published map (main content area only) check map not already in course
1832: if ($folder =~ /^default/) {
1833: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1834: $duplicate{$suffix} = 1;
1835: next;
1836: }
1.484.2.7 raeburn 1837: }
1838: }
1839: }
1.484.2.72.2. (raeburn 1840:): if ($url=~ m{/(ext\.tool)$}) {
1.484.2.30 raeburn 1841: my $prefix = $1;
1.484.2.72.2. (raeburn 1842:): my $fromothercrs;
1.484.2.30 raeburn 1843: #need to copy the db contents to a new one, unless this is a move.
1844: my %info = (
1845: src => $url,
1846: cdom => $coursedom,
1847: cnum => $coursenum,
1848: );
1.484.2.72.2. (raeburn 1849:): if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1850:): unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1851:): $fromothercrs = 1;
1852:): $info{'cdom'} = $srcdom{$suffix};
1853:): $info{'cnum'} = $srcnum{$suffix};
1854:): }
1855:): }
1856:): unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1857: my (%lockerr,$msg);
1858: my ($newurl,$result,$errtext) =
1859: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1860: if ($result eq 'ok') {
1861: $url = $newurl;
1862: $title=&mt('Copy of').' '.$title;
1863: } else {
1.484.2.72.2. (raeburn 1864:): if ($prefix eq 'ext.tool') {
1865:): $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.484.2.30 raeburn 1866: }
1867: $results{$suffix} = $result;
1868: $msgerrs{$suffix} = $msg;
1869: $lockerrs{$suffix} = $lockerr{$prefix};
1870: next;
1871: }
1872: if ($lockerr{$prefix}) {
1873: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1874: }
1.484.2.7 raeburn 1875: }
1.484.2.30 raeburn 1876: }
1877: $title = &LONCAPA::map::qtunescape($title);
1878: my $ext='false';
1879: if ($url=~m{^http(|s)://}) { $ext='true'; }
1880: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1881: if ($folder !~ /^supplemental/) {
1882: (undef,undef,$title) =
1883: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1884: }
1885: } else {
1886: if ($folder=~/^supplemental/) {
1887: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1888: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1889: }
1890: }
1.484.2.7 raeburn 1891:
1892: # For uploaded files (excluding pages/sequences) path in copied file is changed
1893: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1894: # courses.
1895:
1.484.2.30 raeburn 1896: unless ($is_map{$suffix}) {
1897: my $newidx;
1.329 droeschl 1898: # Now insert the URL at the bottom
1.484.2.30 raeburn 1899: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1900: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1901: my $relpath = $1;
1902: if ($relpath ne '') {
1903: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1904: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1905: my $newprefix = $newloc;
1906: if ($newloc eq 'default') {
1907: $newprefix = 'docs';
1908: }
1909: if ($newdocsdir eq '') {
1910: $newdocsdir = 'default';
1911: }
1912: if (($prefixchg{$suffix}) ||
1913: ($srcdom{$suffix} ne $coursedom) ||
1914: ($srcnum{$suffix} ne $coursenum) ||
1915: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1916: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1917: $url =
1918: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1919: &Apache::lonnet::getfile($oldurl));
1920: if ($url eq '/adm/notfound.html') {
1921: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1922: next;
1923: } else {
1924: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1925: $newsubpath =~ s{/+$}{/};
1926: $docmoves{$oldurl} = $newsubpath;
1927: }
1.484.2.7 raeburn 1928: }
1929: }
1930: }
1.484.2.30 raeburn 1931: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1932: ':'.$ext.':normal:res';
1933: push(@LONCAPA::map::order,$newidx);
1934: # Store the result
1935: my ($errtext,$fatal) =
1936: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1937: if ($fatal) {
1938: $save_err .= $errtext;
1939: $allresult = 'fail';
1.484.2.7 raeburn 1940: }
1.329 droeschl 1941: }
1.484.2.30 raeburn 1942:
1943: # Apply any changes to maps, or copy dependencies for uploaded HTML pages
1944: unless ($allresult eq 'fail') {
1945: my %updated = (
1946: rewrites => \%rewrites,
1947: zombies => \%zombies,
1948: removefrommap => \%removefrommap,
1949: removeparam => \%removeparam,
1950: dbcopies => \%dbcopies,
1951: retitles => \%retitles,
1952: );
1953: my %info = (
1954: newsubdir => \%newsubdir,
1955: params => \%params,
1956: );
1957: if ($prefixchg{$suffix}) {
1958: $info{'before'} = $before{$prefixchg{$suffix}};
1959: $info{'after'} = $after{$prefixchg{$suffix}};
1960: }
1961: my %moves = (
1962: copies => \%copies,
1963: docmoves => \%docmoves,
1964: mapmoves => \%mapmoves,
1965: );
1966: (my $result,$msgs{$suffix},my $lockerror) =
1967: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1968: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1969: $url,'paste');
1970: $lockerrors .= $lockerror;
1971: if ($result eq 'ok') {
1972: if ($is_map{$suffix}) {
1973: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1974: $folder.'.'.$container);
1975: if ($fatal) {
1976: $allresult = 'failread';
1977: } else {
1978: if ($#LONCAPA::map::order<1) {
1979: my $idx=&LONCAPA::map::getresidx();
1980: if ($idx<=0) { $idx=1; }
1981: $LONCAPA::map::order[0]=$idx;
1982: $LONCAPA::map::resources[$idx]='';
1983: }
1984: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1985: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1986: ':'.$ext.':normal:res';
1987: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 1988:
1989: # Store the result
1.484.2.30 raeburn 1990: my ($errtext,$fatal) =
1991: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1992: if ($fatal) {
1993: $save_err .= $errtext;
1994: $allresult = 'failstore';
1995: }
1996: }
1997: }
1998: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1999: push(@toclear,$suffix);
2000: }
2001: }
1.329 droeschl 2002: }
2003: }
1.484.2.30 raeburn 2004: &clear_from_buffer(\@toclear,\@currpaste);
2005: my $msgsarray;
2006: foreach my $suffix (keys(%msgs)) {
2007: if (ref($msgs{$suffix}) eq 'ARRAY') {
2008: $msgsarray .= join(',',@{$msgs{$suffix}});
2009: }
2010: }
2011: return ($allresult,$save_err,$msgsarray,$lockerrors);
2012: }
2013:
2014: sub do_buffer_empty {
2015: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2016: if (@currpaste == 0) {
2017: return &mt('Clipboard is already empty');
2018: }
2019: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2020: if (@toclear == 0) {
2021: return &mt('Nothing selected to clear from clipboard');
2022: }
2023: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2024: if ($numdel) {
2025: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2026: } else {
2027: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 2028: }
1.484.2.30 raeburn 2029: return;
2030: }
2031:
2032: sub clear_from_buffer {
2033: my ($toclear,$currpaste) = @_;
2034: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2035: my %pastebuffer;
2036: map { $pastebuffer{$_} = 1; } @{$currpaste};
2037: my $numdel = 0;
2038: foreach my $suffix (@{$toclear}) {
2039: next if ($suffix =~ /\D/);
2040: next unless (exists($pastebuffer{$suffix}));
2041: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2042: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2043: delete($pastebuffer{$suffix});
2044: $numdel ++;
2045: }
2046: }
2047: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2048: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2049: return $numdel;
1.484.2.7 raeburn 2050: }
2051:
2052: sub get_newmap_url {
2053: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2054: $titleref,$allmaps,$newurls) = @_;
2055: my $newurl;
2056: if ($url=~ m{^/uploaded/}) {
2057: $$titleref=&mt('Copy of').' '.$$titleref;
2058: }
2059: my $now = time;
2060: my $suffix=$$.int(rand(100)).$now;
2061: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2062: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2063: my $path = $1;
2064: my $prefix = $2;
2065: my $ancestor = $3;
2066: if (length($ancestor) > 10) {
2067: $ancestor = substr($ancestor,-10,10);
2068: }
2069: my $newid;
2070: if ($prefixchg) {
2071: if ($folder =~ /^supplemental/) {
2072: $prefix =~ s/^default/supplemental/;
2073: } else {
2074: $prefix =~ s/^supplemental/default/;
2075: }
2076: }
2077: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2078: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2079: } else {
2080: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2081: }
2082: my $counter = 0;
2083: my $is_unique = &uniqueness_check($newurl);
2084: if ($folder =~ /^default/) {
2085: if ($allmaps->{$newurl}) {
2086: $is_unique = 0;
2087: }
2088: }
2089: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2090: $counter ++;
2091: $suffix ++;
2092: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2093: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2094: } else {
2095: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2096: }
2097: $is_unique = &uniqueness_check($newurl);
2098: }
2099: if ($is_unique) {
2100: $newurls->{$newurl} = 1;
2101: } else {
2102: if ($url=~/\.page$/) {
2103: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2104: } else {
2105: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2106: }
2107: }
2108: }
2109: return ($newurl);
2110: }
2111:
2112: sub dbcopy {
1.484.2.26 raeburn 2113: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2114: my ($url,$result,$errtext);
2115: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2116: $url = $dbref->{'src'};
1.484.2.72.2. (raeburn 2117:): if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.484.2.26 raeburn 2118: my $prefix = $1;
1.484.2.72.2. (raeburn 2119:): if ($prefix eq 'ext.tool') {
2120:): $prefix = 'exttool';
2121:): }
1.484.2.26 raeburn 2122: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2123: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2124: my $db_name;
2125: my $marker = (split(m{/},$url))[4];
2126: $marker=~s/\D//g;
2127: if ($dbref->{'src'} =~ m{/smppg$}) {
2128: $db_name =
2129: &Apache::lonsimplepage::get_db_name($url,$marker,
2130: $dbref->{'cdom'},
2131: $dbref->{'cnum'});
1.484.2.72.2. (raeburn 2132:): } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2133:): $db_name = 'exttool_'.$marker;
1.484.2.26 raeburn 2134: } else {
2135: $db_name = 'bulletinpage_'.$marker;
2136: }
2137: my ($suffix,$freedlock,$error) =
2138: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2139: $coursedom,$coursenum,
2140: 'concat');
2141: if (!$suffix) {
2142: if ($prefix eq 'smppg') {
2143: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.484.2.72.2. (raeburn 2144:): } elsif ($prefix eq 'exttool') {
2145:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.484.2.26 raeburn 2146: } else {
1.484.2.42 raeburn 2147: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2148: }
2149: if ($error) {
2150: $errtext .= '<br />'.$error;
2151: }
2152: } else {
2153: #need to copy the db contents to a new one.
2154: my %contents=&Apache::lonnet::dump($db_name,
2155: $dbref->{'cdom'},
2156: $dbref->{'cnum'});
2157: if (exists($contents{'uploaded.photourl'})) {
2158: my $photo = $contents{'uploaded.photourl'};
2159: my ($subdir,$fname) =
2160: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2161: my $newphoto;
2162: if ($fname ne '') {
2163: my $content = &Apache::lonnet::getfile($photo);
2164: unless ($content eq '-1') {
2165: $env{'form.'.$suffix.'.photourl'} = $content;
2166: $newphoto =
2167: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2168: delete($env{'form.'.$suffix.'.photourl'});
2169: }
2170: }
2171: if ($newphoto =~ m{^/uploaded/}) {
2172: $contents{'uploaded.photourl'} = $newphoto;
2173: }
2174: }
2175: $db_name =~ s{_\d*$ }{_$suffix}x;
2176: $result=&Apache::lonnet::put($db_name,\%contents,
2177: $coursedom,$coursenum);
2178: if ($result eq 'ok') {
1.484.2.72.2. (raeburn 2179:): $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.484.2.26 raeburn 2180: }
2181: }
2182: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2183: $lockerrorsref->{$prefix} =
2184: '<div class="LC_error">'.
2185: &mt('There was a problem removing a lockfile.');
2186: if ($prefix eq 'smppg') {
2187: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2188: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.72.2. (raeburn 2189:): } elsif ($prefix eq 'exttool') {
2190:): $lockerrorsref->{$prefix} .=
2191:): ' '.&mt('This will prevent addition of more external tools to this course.');
1.484.2.26 raeburn 2192: } else {
1.484.2.42 raeburn 2193: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2194: }
1.484.2.38 raeburn 2195: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2196: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2197: '</div>';
1.484.2.26 raeburn 2198: }
2199: }
2200: } elsif ($url =~ m{/syllabus$}) {
2201: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2202: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2203: if (($dbref->{'cdom'} ne $coursedom) ||
2204: ($dbref->{'cnum'} ne $coursenum)) {
2205: my %contents=&Apache::lonnet::dump('syllabus',
2206: $dbref->{'cdom'},
2207: $dbref->{'cnum'});
2208: $result=&Apache::lonnet::put('syllabus',\%contents,
2209: $coursedom,$coursenum);
2210: }
2211: }
1.484.2.7 raeburn 2212: }
2213: }
1.484.2.26 raeburn 2214: return ($url,$result,$errtext);
1.329 droeschl 2215: }
2216:
2217: sub uniqueness_check {
2218: my ($newurl) = @_;
2219: my $unique = 1;
2220: foreach my $res (@LONCAPA::map::order) {
2221: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2222: $url=&LONCAPA::map::qtescape($url);
2223: if ($newurl eq $url) {
2224: $unique = 0;
1.344 bisitz 2225: last;
1.329 droeschl 2226: }
2227: }
2228: return $unique;
2229: }
2230:
1.484.2.7 raeburn 2231: sub contained_map_check {
1.484.2.72.2. (raeburn 2232:): my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2233:): $hierarchy,$titles,$allmaps) = @_;
1.484.2.7 raeburn 2234: my $content = &Apache::lonnet::getfile($url);
2235: unless ($content eq '-1') {
2236: my $parser = HTML::TokeParser->new(\$content);
2237: $parser->attr_encoded(1);
2238: while (my $token = $parser->get_token) {
2239: next if ($token->[0] ne 'S');
2240: if ($token->[1] eq 'resource') {
2241: next if ($token->[2]->{'type'} eq 'zombie');
2242: my $ressrc = $token->[2]->{'src'};
2243: if ($folder =~ /^supplemental/) {
2244: unless (&supp_pasteable($ressrc)) {
2245: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2246: next;
2247: }
2248: }
2249: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2250: if ($1 eq 'uploaded') {
2251: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2252: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2253: } else {
2254: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2255: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2256: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2257: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2258: } else {
2259: $addedmaps->{$ressrc} = [$url];
2260: }
2261: }
1.484.2.72.2. (raeburn 2262:): &contained_map_check($ressrc,$folder,$coursenum,$coursedom,
2263:): $removefrommap,$removeparam,
1.484.2.7 raeburn 2264: $addedmaps,$hierarchy,$titles,$allmaps);
2265: }
2266: } elsif ($token->[1] eq 'param') {
2267: if ($folder =~ /^supplemental/) {
2268: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2269: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2270: } else {
1.484.2.19 raeburn 2271: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2272: }
2273: }
2274: }
2275: }
2276: }
2277: return;
2278: }
2279:
2280: sub url_paste_fixups {
1.484.2.26 raeburn 2281: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2282: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2283: $mapchanges,$tomove,$newsubdir,$newurls) = @_;
1.484.2.7 raeburn 2284: my $checktitle;
2285: if (($prefixchg) &&
2286: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2287: $checktitle = 1;
2288: }
2289: my $skip;
2290: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2291: my $mapid = $1.$2;
2292: if ($tomove->{$mapid}) {
2293: $skip = 1;
2294: }
2295: }
2296: my $file = &Apache::lonnet::getfile($oldurl);
2297: return if ($file eq '-1');
2298: my $parser = HTML::TokeParser->new(\$file);
2299: $parser->attr_encoded(1);
2300: my $changed = 0;
2301: while (my $token = $parser->get_token) {
2302: next if ($token->[0] ne 'S');
2303: if ($token->[1] eq 'resource') {
2304: my $ressrc = $token->[2]->{'src'};
2305: next if ($ressrc eq '');
2306: my $id = $token->[2]->{'id'};
2307: my $title = $token->[2]->{'title'};
2308: if ($checktitle) {
2309: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2310: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2311: }
2312: }
2313: next if ($token->[2]->{'type'} eq 'external');
2314: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2315: next if ($skip);
1.484.2.25 raeburn 2316: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2317: $changed = 1;
2318: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2319: my $srcdom = $1;
2320: my $srcnum = $2;
2321: my $rem = $3;
2322: my $newurl;
2323: my $mapname;
2324: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2325: my $prefix = $1;
2326: $mapname = $prefix.$2;
2327: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2328: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2329: $srcdom,$srcnum,$allmaps,$rewrites,
2330: $retitles,$copies,$dbcopies,$zombies,
2331: $params,$mapmoves,$mapchanges,$tomove,
2332: $newsubdir,$newurls);
1.484.2.7 raeburn 2333: next;
2334: } else {
2335: ($newurl,my $error) =
2336: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2337: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2338: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2339: $newsubdir->{$ressrc} = $1;
2340: }
2341: if ($error) {
2342: next;
2343: }
2344: }
2345: }
2346: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2347: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2348:
1.484.2.7 raeburn 2349: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2350: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2351: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2352: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2353: $cnum,$srcdom,$srcnum,$allmaps,
2354: $rewrites,$retitles,$copies,$dbcopies,
2355: $zombies,$params,$mapmoves,$mapchanges,
2356: $tomove,$newsubdir,$newurls)) {
1.484.2.7 raeburn 2357: $mapmoves->{$ressrc} = 1;
2358: }
2359: $changed = 1;
2360: } else {
1.484.2.25 raeburn 2361: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2362: $copies->{$oldurl}{$ressrc} = $id;
2363: $changed = 1;
2364: }
2365: }
1.484.2.26 raeburn 2366: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2367: next if ($skip);
1.484.2.7 raeburn 2368: my $srcdom = $1;
2369: my $srcnum = $2;
2370: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2371: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2372: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2373: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2374: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2375: $changed = 1;
2376: }
2377: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2378: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2379: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2380: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2381: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2382: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2383: $changed = 1;
2384: }
2385: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2386: next if ($skip);
2387: my $srcdom = $1;
2388: my $srcnum = $2;
2389: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2390: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2391: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2392: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2393: $changed = 1;
2394: }
2395: }
2396: } elsif ($token->[1] eq 'param') {
2397: next if ($skip);
1.484.2.19 raeburn 2398: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2399: if ($to ne '') {
2400: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2401: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2402: } else {
2403: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2404: }
2405: }
2406: }
2407: }
2408: return $changed;
2409: }
2410:
2411: sub apply_fixups {
1.484.2.23 raeburn 2412: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2413: $oldurl,$url,$caller) = @_;
2414: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2415: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2416: %lockerrors,$lockmsg);
1.484.2.23 raeburn 2417: if (ref($updated) eq 'HASH') {
2418: if (ref($updated->{'rewrites'}) eq 'HASH') {
2419: %rewrites = %{$updated->{'rewrites'}};
2420: }
2421: if (ref($updated->{'zombies'}) eq 'HASH') {
2422: %zombies = %{$updated->{'zombies'}};
2423: }
2424: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2425: %removefrommap = %{$updated->{'removefrommap'}};
2426: }
2427: if (ref($updated->{'removeparam'}) eq 'HASH') {
2428: %removeparam = %{$updated->{'removeparam'}};
2429: }
2430: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2431: %dbcopies = %{$updated->{'dbcopies'}};
2432: }
2433: if (ref($updated->{'retitles'}) eq 'HASH') {
2434: %retitles = %{$updated->{'retitles'}};
2435: }
2436: }
2437: if (ref($info) eq 'HASH') {
2438: if (ref($info->{'newsubdir'}) eq 'HASH') {
2439: %newsubdir = %{$info->{'newsubdir'}};
2440: }
2441: if (ref($info->{'params'}) eq 'HASH') {
2442: %params = %{$info->{'params'}};
2443: }
2444: if (ref($info->{'before'}) eq 'HASH') {
2445: %before = %{$info->{'before'}};
2446: }
2447: if (ref($info->{'after'}) eq 'HASH') {
2448: %after = %{$info->{'after'}};
2449: }
2450: }
2451: if (ref($moves) eq 'HASH') {
2452: if (ref($moves->{'copies'}) eq 'HASH') {
2453: %copies = %{$moves->{'copies'}};
2454: }
2455: if (ref($moves->{'docmoves'}) eq 'HASH') {
2456: %docmoves = %{$moves->{'docmoves'}};
2457: }
2458: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2459: %mapmoves = %{$moves->{'mapmoves'}};
2460: }
2461: }
2462: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2463: my @allcopies;
1.484.2.23 raeburn 2464: if (exists($copies{$key})) {
2465: if (ref($copies{$key}) eq 'HASH') {
2466: my %added;
2467: foreach my $innerkey (keys(%{$copies{$key}})) {
2468: if (($innerkey ne '') && (!$added{$innerkey})) {
2469: push(@allcopies,$innerkey);
2470: $added{$innerkey} = 1;
2471: }
1.484.2.7 raeburn 2472: }
1.484.2.23 raeburn 2473: undef(%added);
1.484.2.7 raeburn 2474: }
2475: }
2476: if ($key eq $oldurl) {
1.484.2.23 raeburn 2477: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2478: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2479: push(@allcopies,$oldurl);
2480: }
2481: }
2482: }
2483: if (@allcopies > 0) {
2484: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2485: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2486: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2487: if ($fname ne '') {
2488: my $content = &Apache::lonnet::getfile($item);
2489: unless ($content eq '-1') {
2490: my $storefn;
1.484.2.23 raeburn 2491: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2492: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2493: } else {
2494: $storefn = $relpath;
2495: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2496: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2497: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2498: }
1.484.2.23 raeburn 2499: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2500: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2501: }
2502: }
2503: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2504: my $copyurl =
1.484.2.7 raeburn 2505: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2506: $storefn.$fname,$content);
2507: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2508: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2509: return &mt('Paste failed: an error occurred copying the file.');
2510: } elsif (ref($errors) eq 'HASH') {
2511: $errors->{$item} = 1;
2512: }
2513: }
2514: }
2515: }
2516: }
2517: }
2518: }
1.484.2.23 raeburn 2519: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2520: my $storefn=$key;
2521: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2522: if ($prefixchg && $before{'map'} && $after{'map'}) {
2523: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2524: }
1.484.2.23 raeburn 2525: if ($newsubdir{$key}) {
2526: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2527: }
2528: my $mapcontent = &Apache::lonnet::getfile($key);
2529: if ($mapcontent eq '-1') {
2530: if (ref($errors) eq 'HASH') {
2531: $errors->{$key} = 1;
2532: }
2533: } else {
2534: my $newmap =
2535: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2536: $mapcontent);
2537: if ($newmap eq '/adm/notfound.html') {
2538: if (ref($errors) eq 'HASH') {
2539: $errors->{$key} = 1;
2540: }
2541: }
2542: }
2543: }
2544: my %updates;
2545: if ($is_map) {
1.484.2.23 raeburn 2546: if (ref($updated) eq 'HASH') {
2547: foreach my $type (keys(%{$updated})) {
2548: if (ref($updated->{$type}) eq 'HASH') {
2549: foreach my $key (keys(%{$updated->{$type}})) {
2550: $updates{$key} = 1;
2551: }
2552: }
2553: }
1.484.2.7 raeburn 2554: }
2555: foreach my $key (keys(%updates)) {
2556: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2557: if (ref($rewrites{$key}) eq 'HASH') {
2558: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2559: }
1.484.2.23 raeburn 2560: if (ref($retitles{$key}) eq 'HASH') {
2561: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2562: }
1.484.2.23 raeburn 2563: if (ref($removefrommap{$key}) eq 'HASH') {
2564: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2565: }
1.484.2.23 raeburn 2566: if (ref($removeparam{$key}) eq 'HASH') {
2567: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2568: }
1.484.2.23 raeburn 2569: if (ref($zombies{$key}) eq 'HASH') {
2570: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2571: }
1.484.2.23 raeburn 2572: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2573: foreach my $idx (keys(%{$dbcopies{$key}})) {
2574: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2575: my ($newurl,$result,$errtext) =
2576: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2577: if ($result eq 'ok') {
2578: $newdb{$idx} = $newurl;
2579: } elsif (ref($errors) eq 'HASH') {
2580: $errors->{$key} = 1;
2581: }
2582: push(@msgs,$errtext);
2583: }
1.484.2.7 raeburn 2584: }
2585: }
1.484.2.23 raeburn 2586: if (ref($params{$key}) eq 'HASH') {
2587: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2588: }
2589: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2590: if ($fatal) {
1.484.2.26 raeburn 2591: return ($errtext);
1.484.2.7 raeburn 2592: }
2593: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2594: if (defined($LONCAPA::map::zombies[$i])) {
2595: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2596: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2597: undef($LONCAPA::map::zombies[$i]);
2598: }
2599: }
2600: }
1.484.2.72.2. (raeburn 2601:): my $total = scalar(@LONCAPA::map::order) - 1;
2602:): for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2603: my $idx = $LONCAPA::map::order[$i];
2604: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2605: my $changed;
1.484.2.23 raeburn 2606: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2607: if ((exists($toremove{$idx})) &&
2608: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2609: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2610: if (ref($currparam{$idx}) eq 'ARRAY') {
2611: foreach my $name (@{$currparam{$idx}}) {
1.484.2.72.2. (raeburn 2612:): &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2613: }
2614: }
2615: next;
2616: }
2617: my $origsrc = $src;
1.484.2.25 raeburn 2618: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2619: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2620: $changed = 1;
2621: }
2622: }
1.484.2.25 raeburn 2623: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2624: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2625: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2626: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2627: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2628: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2629: } else {
1.484.2.23 raeburn 2630: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2631: }
2632: }
1.484.2.25 raeburn 2633: if ($origsrc =~ /\.(page|sequence)$/) {
2634: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2635: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2636: }
1.484.2.25 raeburn 2637: } elsif ($newsubdir{$key}) {
2638: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2639: }
2640: }
2641: $changed = 1;
1.484.2.26 raeburn 2642: } elsif ($newdb{$idx} ne '') {
2643: $src = $newdb{$idx};
1.484.2.7 raeburn 2644: $changed = 1;
2645: }
2646: if ($changed) {
1.484.2.30 raeburn 2647: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2648: }
2649: }
2650: }
2651: foreach my $idx (keys(%remparam)) {
2652: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2653: foreach my $name (@{$remparam{$idx}}) {
1.484.2.72.2. (raeburn 2654:): &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2655: }
2656: }
2657: }
1.484.2.26 raeburn 2658: if (values(%lockerrors) > 0) {
2659: $lockmsg = join('<br />',values(%lockerrors));
2660: }
1.484.2.7 raeburn 2661: my $storefn;
2662: if ($key eq $oldurl) {
2663: $storefn = $url;
2664: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2665: } else {
2666: $storefn = $key;
2667: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2668: if ($prefixchg && $before{'map'} && $after{'map'}) {
2669: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2670: }
1.484.2.23 raeburn 2671: if ($newsubdir{$key}) {
2672: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2673: }
2674: }
2675: my $report;
2676: if ($folder !~ /^supplemental/) {
2677: $report = 1;
2678: }
1.484.2.20 raeburn 2679: (my $outtext,$errtext) =
1.484.2.7 raeburn 2680: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2681: if ($errtext) {
1.484.2.23 raeburn 2682: if ($caller eq 'paste') {
1.484.2.26 raeburn 2683: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2684: }
1.484.2.7 raeburn 2685: }
2686: }
2687: }
1.484.2.26 raeburn 2688: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2689: }
2690:
2691: sub copy_dependencies {
2692: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2693: my $content;
2694: if (ref($contentref)) {
2695: $content = $$contentref;
2696: } else {
2697: $content = &Apache::lonnet::getfile($item);
2698: }
2699: unless ($content eq '-1') {
2700: my $mm = new File::MMagic;
2701: my $mimetype = $mm->checktype_contents($content);
2702: if ($mimetype eq 'text/html') {
2703: my (%allfiles,%codebase,$state);
2704: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2705: if ($res eq 'ok') {
2706: my ($numexisting,$numpathchanges,$existing);
2707: (undef,$numexisting,$numpathchanges,$existing) =
2708: &Apache::loncommon::ask_for_embedded_content(
2709: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2710: {'error_on_invalid_names' => 1,
2711: 'ignore_remote_references' => 1,
2712: 'docs_url' => $item,
2713: 'context' => 'paste'});
2714: if ($numexisting > 0) {
2715: if (ref($existing) eq 'HASH') {
2716: foreach my $dep (keys(%{$existing})) {
2717: my $depfile = $dep;
2718: unless ($depfile =~ m{^\Q$relpath\E}) {
2719: $depfile = $relpath.$dep;
2720: }
2721: my $depcontent = &Apache::lonnet::getfile($depfile);
2722: unless ($depcontent eq '-1') {
2723: my $storedep = $dep;
2724: $storedep =~ s{^\Q$relpath\E}{};
2725: my $dep_url =
2726: &Apache::lonclonecourse::writefile(
2727: $env{'request.course.id'},
2728: $storefn.$storedep,$depcontent);
2729: if ($dep_url eq '/adm/notfound.html') {
2730: if (ref($errors) eq 'HASH') {
2731: $errors->{$depfile} = 1;
2732: }
2733: } else {
2734: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2735: }
2736: }
2737: }
2738: }
2739: }
2740: }
2741: }
2742: }
2743: return;
2744: }
2745:
1.329 droeschl 2746: my %parameter_type = ( 'randompick' => 'int_pos',
2747: 'hiddenresource' => 'string_yesno',
2748: 'encrypturl' => 'string_yesno',
2749: 'randomorder' => 'string_yesno',);
2750: my $valid_parameters_re = join('|',keys(%parameter_type));
2751: # set parameters
2752: sub update_parameter {
1.484.2.29 raeburn 2753: if ($env{'form.changeparms'} eq 'all') {
2754: my (@allidx,@allmapidx,%allchecked,%currchecked);
2755: %allchecked = (
2756: 'hiddenresource' => {},
2757: 'encrypturl' => {},
2758: 'randompick' => {},
2759: 'randomorder' => {},
2760: );
2761: foreach my $which (keys(%allchecked)) {
2762: $env{'form.all'.$which} =~ s/,$//;
2763: if ($which eq 'randompick') {
2764: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2765: my ($res,$value) = split(/:/,$item);
2766: if ($value =~ /^\d+$/) {
2767: $allchecked{$which}{$res} = $value;
2768: }
2769: }
2770: } else {
1.484.2.30 raeburn 2771: if ($env{'form.all'.$which}) {
2772: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2773: }
1.484.2.29 raeburn 2774: }
2775: }
2776: my $haschanges = 0;
2777: foreach my $res (@LONCAPA::map::order) {
2778: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2779: $name=&LONCAPA::map::qtescape($name);
2780: $url=&LONCAPA::map::qtescape($url);
2781: next unless ($name && $url);
2782: my $is_map;
2783: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2784: $is_map = 1;
2785: }
2786: foreach my $which (keys(%allchecked)) {
2787: if (($which eq 'randompick' || $which eq 'randomorder')) {
2788: next if (!$is_map);
2789: }
2790: my $oldvalue = 0;
2791: my $newvalue = 0;
2792: if ($allchecked{$which}{$res}) {
2793: $newvalue = $allchecked{$which}{$res};
2794: }
2795: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2796: if ($which eq 'randompick') {
2797: if ($current =~ /^(\d+)$/) {
2798: $oldvalue = $1;
2799: }
2800: } else {
2801: if ($current =~ /^yes$/i) {
2802: $oldvalue = 1;
2803: }
2804: }
2805: if ($oldvalue ne $newvalue) {
2806: $haschanges = 1;
2807: if ($newvalue) {
2808: my $storeval = 'yes';
2809: if ($which eq 'randompick') {
2810: $storeval = $newvalue;
2811: }
2812: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2813: $storeval,
2814: $parameter_type{$which});
2815: &remember_parms($res,$which,'set',$storeval);
2816: } elsif ($oldvalue) {
2817: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2818: &remember_parms($res,$which,'del');
2819: }
2820: }
2821: }
2822: }
2823: return $haschanges;
1.329 droeschl 2824: } else {
1.484.2.59 raeburn 2825: my $haschanges = 0;
2826: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 2827:
1.484.2.29 raeburn 2828: my $which = $env{'form.changeparms'};
2829: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 2830: my $oldvalue = 0;
2831: my $newvalue = 0;
2832: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2833: if ($which eq 'randompick') {
2834: if ($current =~ /^(\d+)$/) {
2835: $oldvalue = $1;
2836: }
2837: } elsif ($current =~ /^yes$/i) {
2838: $oldvalue = 1;
2839: }
1.484.2.29 raeburn 2840: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 2841: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2842: : 1;
1.484.2.29 raeburn 2843: }
1.484.2.59 raeburn 2844: if ($oldvalue ne $newvalue) {
2845: $haschanges = 1;
2846: if ($newvalue) {
2847: my $storeval = 'yes';
2848: if ($which eq 'randompick') {
2849: $storeval = $newvalue;
2850: }
2851: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2852: $parameter_type{$which});
2853: &remember_parms($idx,$which,'set',$storeval);
2854: } else {
2855: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2856: &remember_parms($idx,$which,'del');
2857: }
2858: }
2859: return $haschanges;
1.329 droeschl 2860: }
1.484.2.59 raeburn 2861: return;
1.329 droeschl 2862: }
2863:
2864: sub handle_edit_cmd {
2865: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 2866: if ($env{'form.cmd'} eq '') {
2867: return 0;
2868: }
1.329 droeschl 2869: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2870:
2871: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2872: my ($title, $url, @rrest) = split(':', $ratstr);
2873:
1.484.2.30 raeburn 2874: if ($cmd eq 'remove') {
1.329 droeschl 2875: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2876: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2877: &Apache::lonnet::removeuploadedurl($url);
2878: } else {
2879: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2880: }
2881: splice(@LONCAPA::map::order, $idx, 1);
2882:
2883: } elsif ($cmd eq 'cut') {
2884: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2885: splice(@LONCAPA::map::order, $idx, 1);
2886:
1.344 bisitz 2887: } elsif ($cmd eq 'up'
1.329 droeschl 2888: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2889: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2890:
2891: } elsif ($cmd eq 'down'
2892: && defined($LONCAPA::map::order[$idx+1])) {
2893: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2894:
2895: } elsif ($cmd eq 'rename') {
2896: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2897: if ($comment=~/\S/) {
2898: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2899: $comment.':'.join(':', $url, @rrest);
2900: }
2901: # Devalidate title cache
2902: my $renamed_url=&LONCAPA::map::qtescape($url);
2903: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 2904:
1.329 droeschl 2905: } else {
2906: return 0;
2907: }
2908: return 1;
2909: }
2910:
2911: sub editor {
1.458 raeburn 2912: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.72.2. (raeburn 2913:): $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
2914:): $canedit,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 2915: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2916: if ($allowed) {
2917: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2918: $is_random_order,$container) =
2919: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2920: $r->print($breadcrumbtrail);
2921: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2922: $container = 'page';
2923: } else {
2924: $container = 'sequence';
2925: }
1.484 raeburn 2926:
1.484.2.21 raeburn 2927: my $jumpto;
2928:
2929: unless ($supplementalflag) {
1.484.2.32 raeburn 2930: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 2931: }
1.484 raeburn 2932:
2933: unless ($allowed) {
2934: $randompick = -1;
2935: }
2936:
1.484.2.67 raeburn 2937: my ($errtext,$fatal);
2938: if (($folder eq '') && (!$supplementalflag)) {
2939: if (@LONCAPA::map::order) {
2940: undef(@LONCAPA::map::order);
2941: undef(@LONCAPA::map::resources);
2942: undef(@LONCAPA::map::resparms);
2943: undef(@LONCAPA::map::zombies);
2944: }
2945: $folder = 'default';
2946: $container = 'sequence';
2947: } else {
2948: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2949: $folder.'.'.$container);
2950: return $errtext if ($fatal);
2951: }
1.329 droeschl 2952:
2953: if ($#LONCAPA::map::order<1) {
2954: my $idx=&LONCAPA::map::getresidx();
2955: if ($idx<=0) { $idx=1; }
2956: $LONCAPA::map::order[0]=$idx;
2957: $LONCAPA::map::resources[$idx]='';
2958: }
1.364 bisitz 2959:
1.329 droeschl 2960: # ------------------------------------------------------------ Process commands
2961:
2962: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 2963: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 2964: # set parameters and change order
2965: &snapshotbefore();
2966:
2967: if (&update_parameter()) {
1.484.2.59 raeburn 2968: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 2969: return $errtext if ($fatal);
2970: }
2971:
2972: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2973: # change order
2974: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
2975: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
2976:
2977: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2978: return $errtext if ($fatal);
2979: }
1.364 bisitz 2980:
1.329 droeschl 2981: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 2982: my %paste_errors;
1.484.2.26 raeburn 2983: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 2984: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
2985: \%paste_errors);
1.484.2.30 raeburn 2986: if (ref($pastemsgarray) eq 'ARRAY') {
2987: if (@{$pastemsgarray} > 0) {
2988: $r->print('<p class="LC_info">'.
2989: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 2990: '</p>');
2991: }
1.484.2.30 raeburn 2992: }
2993: if ($lockerror) {
2994: $r->print('<p class="LC_error">'.
2995: $lockerror.
2996: '</p>');
2997: }
2998: if ($save_error ne '') {
2999: return $save_error;
3000: }
3001: if ($paste_res) {
3002: my %errortext = &Apache::lonlocal::texthash (
3003: fail => 'Storage of folder contents failed',
3004: failread => 'Reading folder contents failed',
3005: failstore => 'Storage of folder contents failed',
3006: );
3007: if ($errortext{$paste_res}) {
3008: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3009: }
1.329 droeschl 3010: }
1.484.2.7 raeburn 3011: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3012: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3013: &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".
3014: '<ul>'."\n");
3015: foreach my $key (sort(keys(%paste_errors))) {
3016: $r->print('<li>'.$key.'</li>'."\n");
3017: }
3018: $r->print('</ul></p>'."\n");
3019: }
1.484.2.30 raeburn 3020: } elsif ($env{'form.clearmarked'}) {
3021: my $output = &do_buffer_empty();
3022: if ($output) {
3023: $r->print('<p class="LC_info">'.$output.'</p>');
3024: }
3025: }
1.329 droeschl 3026:
3027: $r->print($upload_output);
3028:
1.484.2.30 raeburn 3029: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3030: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3031: my $contentchg;
1.484.2.58 raeburn 3032: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3033: $contentchg = 1;
3034: }
3035: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3036: return $errtext if ($fatal);
3037: }
1.484.2.30 raeburn 3038:
3039: # Cut, copy and/or remove multiple resources
3040: if ($env{'form.multichange'}) {
3041: my %allchecked = (
3042: cut => {},
3043: remove => {},
3044: );
3045: my $needsupdate;
3046: foreach my $which (keys(%allchecked)) {
3047: $env{'form.multi'.$which} =~ s/,$//;
3048: if ($env{'form.multi'.$which}) {
3049: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3050: if (ref($allchecked{$which}) eq 'HASH') {
3051: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3052: }
3053: }
3054: }
3055: if ($needsupdate) {
3056: my $haschanges = 0;
3057: my %curr_groups = &Apache::longroup::coursegroups();
3058: my $total = scalar(@LONCAPA::map::order) - 1;
3059: for (my $i=$total; $i>=0; $i--) {
3060: my $res = $LONCAPA::map::order[$i];
3061: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3062: $name=&LONCAPA::map::qtescape($name);
3063: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3064: next unless $url;
1.484.2.30 raeburn 3065: my %denied =
3066: &action_restrictions($coursenum,$coursedom,$url,
3067: $env{'form.folderpath'},\%curr_groups);
3068: foreach my $which (keys(%allchecked)) {
3069: next if ($denied{$which});
3070: next unless ($allchecked{$which}{$res});
3071: if ($which eq 'remove') {
3072: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3073: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3074: &Apache::lonnet::removeuploadedurl($url);
3075: } else {
3076: &LONCAPA::map::makezombie($res);
3077: }
3078: splice(@LONCAPA::map::order,$i,1);
3079: $haschanges ++;
3080: } elsif ($which eq 'cut') {
3081: &LONCAPA::map::makezombie($res);
3082: splice(@LONCAPA::map::order,$i,1);
3083: $haschanges ++;
3084: }
3085: }
3086: }
3087: if ($haschanges) {
3088: ($errtext,$fatal) =
3089: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3090: return $errtext if ($fatal);
3091: }
3092: }
3093: }
3094:
1.329 droeschl 3095: # Group import/search
3096: if ($env{'form.importdetail'}) {
3097: my @imports;
3098: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3099: if (defined($item)) {
3100: my ($name,$url,$residx)=
1.484.2.26 raeburn 3101: map { &unescape($_); } split(/\=/,$item);
3102: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3103: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3104: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3105: if ($locknotfreed) {
3106: $r->print($locknotfreed);
3107: }
3108: if ($suffix) {
1.484.2.19 raeburn 3109: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3110: } else {
3111: return $errortxt;
3112: }
1.484.2.26 raeburn 3113: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3114: my $type = $1;
3115: my ($suffix,$errortxt,$locknotfreed) =
3116: &new_timebased_suffix($coursedom,$coursenum,$type);
3117: if ($locknotfreed) {
3118: $r->print($locknotfreed);
3119: }
3120: if ($suffix) {
3121: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3122: } else {
3123: return $errortxt;
3124: }
1.484.2.72.2. (raeburn 3125:): } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3126:): my ($suffix,$errortxt,$locknotfreed) =
3127:): &new_timebased_suffix($coursedom,$coursenum,'exttool');
3128:): if ($locknotfreed) {
3129:): $r->print($locknotfreed);
3130:): }
3131:): if ($suffix) {
3132:): $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3133:): } else {
3134:): return $errortxt;
3135:): }
1.484.2.27 raeburn 3136: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3137: if ($supplementalflag) {
3138: next unless ($1 eq 'supplemental');
3139: if ($folder eq 'supplemental') {
3140: next unless ($2 eq 'default');
3141: } else {
3142: next unless ($folder eq 'supplemental_'.$2);
3143: }
3144: } else {
3145: next unless ($1 eq 'docs');
3146: if ($folder eq 'default') {
3147: next unless ($2 eq 'default');
3148: } else {
3149: next unless ($folder eq 'default_'.$2);
3150: }
3151: }
1.484.2.15 raeburn 3152: }
1.329 droeschl 3153: push(@imports, [$name, $url, $residx]);
3154: }
3155: }
1.484.2.23 raeburn 3156: ($errtext,$fatal,my $fixuperrors) =
3157: &group_import($coursenum, $coursedom, $folder,$container,
1.484.2.72.2. (raeburn 3158:): 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3159: return $errtext if ($fatal);
1.484.2.23 raeburn 3160: if ($fixuperrors) {
3161: $r->print($fixuperrors);
3162: }
1.329 droeschl 3163: }
3164: # Loading a complete map
3165: if ($env{'form.loadmap'}) {
3166: if ($env{'form.importmap'}=~/\w/) {
3167: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3168: my ($title,$url,$ext,$type)=split(/\:/,$res);
3169: my $idx=&LONCAPA::map::getresidx($url);
3170: $LONCAPA::map::resources[$idx]=$res;
3171: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3172: }
3173: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3174: $folder.'.'.$container,1);
1.329 droeschl 3175: return $errtext if ($fatal);
3176: } else {
3177: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3178:
1.329 droeschl 3179: }
3180: }
3181: &log_differences($plain);
3182: }
3183: # ---------------------------------------------------------------- End commands
3184: # ---------------------------------------------------------------- Print screen
3185: my $idx=0;
3186: my $shown=0;
3187: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3188: $r->print('<div class="LC_Box">'.
1.432 raeburn 3189: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3190: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3191: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3192: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3193: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3194: '</ol>');
1.381 bisitz 3195: if ($randompick>=0) {
3196: $r->print('<p class="LC_warning">'
3197: .&mt('Caution: this folder is set to randomly pick a subset'
3198: .' of resources. Adding or removing resources from this'
3199: .' folder will change the set of resources that the'
3200: .' students see, resulting in spurious or missing credit'
3201: .' for completed problems, not limited to ones you'
3202: .' modify. Do not modify the contents of this folder if'
3203: .' it is in active student use.')
3204: .'</p>'
3205: );
3206: }
3207: if ($is_random_order) {
3208: $r->print('<p class="LC_warning">'
3209: .&mt('Caution: this folder is set to randomly order its'
3210: .' contents. Adding or removing resources from this folder'
3211: .' will change the order of resources shown.')
3212: .'</p>'
3213: );
3214: }
3215: $r->print('</div>');
1.364 bisitz 3216: }
1.381 bisitz 3217:
1.484.2.30 raeburn 3218: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3219: %filters = (
3220: canremove => [],
3221: cancut => [],
3222: cancopy => [],
3223: hiddenresource => [],
3224: encrypturl => [],
3225: randomorder => [],
3226: randompick => [],
3227: );
3228: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3229: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3230: foreach my $res (@LONCAPA::map::order) {
3231: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3232: $name=&LONCAPA::map::qtescape($name);
3233: $url=&LONCAPA::map::qtescape($url);
3234: unless ($name) { $name=(split(/\//,$url))[-1]; }
3235: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3236: push(@allidx,$res);
3237: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3238: push(@allmapidx,$res);
3239: }
1.484.2.67 raeburn 3240:
1.381 bisitz 3241: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3242: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3243: $pathitem,$supplementalflag,$container,
1.484.2.72.2. (raeburn 3244:): \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.484.2.70 raeburn 3245: $isencrypted,$navmapref);
1.381 bisitz 3246: $idx++;
3247: $shown++;
1.329 droeschl 3248: }
1.424 onken 3249: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3250:
1.484.2.30 raeburn 3251: my $need_save;
1.484.2.67 raeburn 3252: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3253: my $toolslink;
1.484.2.67 raeburn 3254: if ($allowed) {
1.484.2.31 raeburn 3255: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3256: .&Apache::loncommon::help_open_menu('Navigation Screen',
3257: 'Navigation_Screen',undef,'RAT')
3258: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3259: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3260: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3261: .'id="LC_content_toolbar_edittoplevel" '
3262: .'class="LC_toolbarItem" '
3263: .'title="'.&mt('Supplemental Content Editor').'">'
3264: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3265: }
1.484.2.19 raeburn 3266: if ($shown) {
3267: if ($allowed) {
3268: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3269: .&Apache::loncommon::start_data_table(undef,'contentlist')
3270: .&Apache::loncommon::start_data_table_header_row()
3271: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3272: .'<th colspan="2">'.&mt('Actions').'</th>'
3273: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3274: if ($folder !~ /^supplemental/) {
3275: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3276: }
1.484.2.29 raeburn 3277: $to_show .= &Apache::loncommon::end_data_table_header_row();
3278: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3279: $lists{'canhide'} = join(',',@allidx);
3280: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3281: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3282: 'randomorder','randompick');
3283: foreach my $item (@possfilters) {
3284: if (ref($filters{$item}) eq 'ARRAY') {
3285: if (@{$filters{$item}} > 0) {
3286: $lists{$item} = join(',',@{$filters{$item}});
3287: }
3288: }
3289: }
1.484.2.29 raeburn 3290: if (@allidx > 0) {
3291: my $path;
3292: if ($env{'form.folderpath'}) {
3293: $path =
3294: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3295: }
1.484.2.30 raeburn 3296: if (@allidx > 1) {
3297: $to_show .=
3298: &Apache::loncommon::continue_data_table_row().
3299: '<td colspan="2"> </td>'.
3300: '<td>'.
1.484.2.67 raeburn 3301: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3302: '</td>'.
3303: '<td> </td>'.
3304: '<td> </td>'.
3305: '<td colspan="4">'.
1.484.2.67 raeburn 3306: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3307: '</td>'.
3308: &Apache::loncommon::end_data_table_row();
3309: $need_save = 1;
3310: }
1.484.2.29 raeburn 3311: }
3312: }
3313: $to_show .= $output.' '
1.484.2.19 raeburn 3314: .&Apache::loncommon::end_data_table()
3315: .'<br style="line-height:2px;" />'
3316: .&Apache::loncommon::end_scrollbox();
3317: } else {
3318: $to_show .= $toolslink
3319: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3320: .$output.' '
3321: .&Apache::loncommon::end_data_table();
3322: }
3323: } else {
3324: if (!$allowed) {
3325: $to_show .= $toolslink;
1.393 raeburn 3326: }
1.484.2.67 raeburn 3327: my $noresmsg;
3328: if ($allowed && $hiddentop && !$supplementalflag) {
3329: $noresmsg = &mt('Main Content Hidden');
3330: } else {
3331: $noresmsg = &mt('Currently empty');
3332: }
1.484.2.19 raeburn 3333: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3334: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3335: .$noresmsg
1.484.2.19 raeburn 3336: .'</div>'
3337: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3338: }
3339: } else {
1.484.2.19 raeburn 3340: if ($shown) {
3341: $to_show = '<div>'
3342: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3343: .$output
3344: .&Apache::loncommon::end_data_table()
3345: .'</div>';
3346: } else {
3347: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3348: .&mt('Currently empty')
1.484.2.19 raeburn 3349: .'</div>'
3350: }
1.458 raeburn 3351: }
3352: my $tid = 1;
3353: if ($supplementalflag) {
3354: $tid = 2;
1.329 droeschl 3355: }
3356: if ($allowed) {
1.484 raeburn 3357: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3358: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3359: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3360: if ($canedit) {
1.484.2.67 raeburn 3361: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3362: }
1.460 raeburn 3363: } else {
3364: $r->print($to_show);
1.329 droeschl 3365: }
3366: return;
3367: }
3368:
1.484.2.30 raeburn 3369: sub multiple_check_form {
1.484.2.67 raeburn 3370: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3371: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3372: my $disabled;
3373: unless ($canedit) {
3374: $disabled = 'disabled="disabled"';
3375: }
1.484.2.30 raeburn 3376: my $output =
3377: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3378: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3379: '<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>'.
3380: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3381: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3382: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3383: if ($caller eq 'settings') {
3384: $output .=
3385: '<table><tr>'.
3386: '<td class="LC_docs_entry_parameter">'.
3387: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3388: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3389: '</label></span></td>'.
3390: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3391: '<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 3392: '</span></td>'.
3393: '</tr>'."\n".
3394: '<tr>'.
3395: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3396: '<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 3397: '</label></span>'.
3398: '</td></tr></table>'."\n";
3399: } else {
3400: $output .=
3401: '<table><tr>'.
3402: '<td class="LC_docs_entry_parameter">'.
3403: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3404: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3405: '</label></span></td>'.
3406: '<td class="LC_docs_entry_parameter">'.
3407: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3408: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3409: '</label></span></td>'."\n".
3410: '<td class="LC_docs_entry_parameter">'.
3411: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3412: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3413: '</label></span></td>'.
3414: '</tr></table>'."\n";
3415: }
3416: $output .=
3417: '</fieldset>'.
3418: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3419: if ($caller eq 'settings') {
3420: $output .=
3421: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3422: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3423: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3424: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3425: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3426: } elsif ($caller eq 'actions') {
3427: $output .=
3428: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3429: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3430: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3431: }
3432: $output .=
3433: '</form>'.
3434: '</div>';
3435: return $output;
3436: }
3437:
1.329 droeschl 3438: sub process_file_upload {
1.484.2.36 raeburn 3439: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3440: # upload a file, if present
1.484.2.36 raeburn 3441: my $filesize = length($env{'form.uploaddoc'});
3442: if (!$filesize) {
3443: $$upload_output = '<div class="LC_error">'.
3444: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3445: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3446: $filesize).'<br />'.
3447: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3448: '</div>';
3449: return;
3450: }
3451: my $quotatype = 'unofficial';
3452: if ($crstype eq 'Community') {
3453: $quotatype = 'community';
1.484.2.51 raeburn 3454: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3455: $quotatype = 'official';
1.484.2.45 raeburn 3456: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3457: $quotatype = 'textbook';
1.484.2.36 raeburn 3458: }
3459: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3460: $filesize = int($filesize/1000); #expressed in kb
3461: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3462: $env{'form.uploaddoc.filename'},$filesize,
3463: 'upload',$quotatype);
1.484.2.36 raeburn 3464: return if ($$upload_output);
3465: }
1.440 raeburn 3466: my ($parseaction,$showupload,$nextphase,$mimetype);
3467: if ($env{'form.parserflag'}) {
1.329 droeschl 3468: $parseaction = 'parse';
3469: }
3470: my $folder=$env{'form.folder'};
3471: if ($folder eq '') {
3472: $folder='default';
3473: }
3474: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3475: my $errtext='';
3476: my $fatal=0;
3477: my $container='sequence';
1.484.2.19 raeburn 3478: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3479: $container='page';
3480: }
3481: ($errtext,$fatal)=
1.484.2.27 raeburn 3482: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3483: if ($#LONCAPA::map::order<1) {
3484: $LONCAPA::map::order[0]=1;
3485: $LONCAPA::map::resources[1]='';
3486: }
3487: my $destination = 'docs/';
3488: if ($folder =~ /^supplemental/) {
3489: $destination = 'supplemental/';
3490: }
3491: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3492: $destination .= 'default/';
3493: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3494: $destination .= $2.'/';
3495: }
1.484.2.27 raeburn 3496: if ($fatal) {
3497: $$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>';
3498: return;
3499: }
1.440 raeburn 3500: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3501: my $newidx=&LONCAPA::map::getresidx();
3502: $destination .= $newidx;
1.439 raeburn 3503: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3504: $parseaction,$allfiles,
1.440 raeburn 3505: $codebase,undef,undef,undef,undef,
3506: undef,undef,\$mimetype);
3507: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3508: my $stored = $1;
3509: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3510: $stored.'</span>').'</p>';
3511: } else {
3512: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3513:
1.457 raeburn 3514: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3515: return;
3516: }
1.329 droeschl 3517: my $ext='false';
3518: if ($url=~m{^http://}) { $ext='true'; }
3519: $url = &LONCAPA::map::qtunescape($url);
3520: my $comment=$env{'form.comment'};
3521: $comment = &LONCAPA::map::qtunescape($comment);
3522: if ($folder=~/^supplemental/) {
3523: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3524: $env{'user.domain'}.'___&&&___'.$comment;
3525: }
3526:
3527: $LONCAPA::map::resources[$newidx]=
3528: $comment.':'.$url.':'.$ext.':normal:res';
3529: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3530: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3531: $folder.'.'.$container,1);
1.329 droeschl 3532: if ($fatal) {
1.457 raeburn 3533: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3534: return;
1.329 droeschl 3535: } else {
1.440 raeburn 3536: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3537: $$upload_output = $showupload;
1.384 raeburn 3538: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3539: if ($total_embedded > 0) {
1.440 raeburn 3540: my $uploadphase = 'upload_embedded';
3541: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3542: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3543: my ($embedded,$num) =
3544: &Apache::loncommon::ask_for_embedded_content(
3545: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3546: if ($embedded) {
3547: if ($num) {
3548: $$upload_output .=
3549: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3550: $nextphase = $uploadphase;
3551: } else {
3552: $$upload_output .= $embedded;
3553: }
3554: } else {
3555: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3556: }
1.329 droeschl 3557: } else {
1.440 raeburn 3558: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3559: }
1.457 raeburn 3560: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3561: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3562: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3563: $nextphase = 'decompress_uploaded';
3564: my $position = scalar(@LONCAPA::map::order)-1;
3565: my $noextract = &return_to_editor();
3566: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3567: my %archiveitems = (
3568: folderpath => $env{'form.folderpath'},
3569: cmd => $nextphase,
3570: newidx => $newidx,
3571: position => $position,
3572: phase => $nextphase,
1.477 raeburn 3573: comment => $comment,
1.480 raeburn 3574: );
3575: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3576: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3577: $$upload_output = $showupload.
3578: &Apache::loncommon::decompress_form($mimetype,
3579: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3580: \%archiveitems,\@current);
1.329 droeschl 3581: }
3582: }
3583: }
1.440 raeburn 3584: return $nextphase;
1.329 droeschl 3585: }
3586:
1.480 raeburn 3587: sub get_dir_list {
3588: my ($url,$coursenum,$coursedom,$newidx) = @_;
3589: my ($destination,$dir_root) = &embedded_destination();
3590: my ($dirlistref,$listerror) =
3591: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3592: my @dir_lines;
3593: my $dirptr=16384;
3594: if (ref($dirlistref) eq 'ARRAY') {
3595: foreach my $dir_line (sort
3596: {
3597: my ($afile)=split('&',$a,2);
3598: my ($bfile)=split('&',$b,2);
3599: return (lc($afile) cmp lc($bfile));
3600: } (@{$dirlistref})) {
3601: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3602: $filename =~ s/\s+$//;
3603: next if ($filename =~ /^\.\.?$/);
3604: my $isdir = 0;
3605: if ($dirptr&$testdir) {
3606: $isdir = 1;
3607: }
3608: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3609: }
3610: }
3611: return @dir_lines;
3612: }
3613:
1.329 droeschl 3614: sub is_supplemental_title {
3615: my ($title) = @_;
3616: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3617: }
3618:
3619: # --------------------------------------------------------------- An entry line
3620:
3621: sub entryline {
1.484.2.12 raeburn 3622: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3623: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.72.2. (raeburn 3624:): $ltitoolsref,$canedit,$isencrypted,$navmapref)=@_;
1.484.2.52 raeburn 3625: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3626: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3627: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3628: } else {
3629: $title=&HTML::Entities::encode($title,'"<>&\'');
3630: $renametitle=$title;
3631: $foldertitle=$title;
3632: }
3633:
1.484.2.67 raeburn 3634: my ($disabled,$readonly,$js_lt);
3635: unless ($canedit) {
3636: $disabled = 'disabled="disabled"';
3637: $readonly = 1;
3638: }
3639:
1.329 droeschl 3640: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3641:
1.329 droeschl 3642: $renametitle=~s/\\/\\\\/g;
3643: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3644: $renametitle=~s/"/%22/g;
1.329 droeschl 3645: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3646: $oldtitle = $renametitle;
3647: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3648: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3649: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3650: # Edit commands
1.484.2.28 raeburn 3651: my ($esc_path, $path, $symb);
1.329 droeschl 3652: if ($env{'form.folderpath'}) {
3653: $esc_path=&escape($env{'form.folderpath'});
3654: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3655: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3656: }
1.484.2.16 raeburn 3657: my $isexternal;
1.484.2.19 raeburn 3658: if ($residx) {
1.484.2.12 raeburn 3659: my $currurl = $url;
3660: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3661: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3662: $isexternal = 1;
3663: }
1.484.2.19 raeburn 3664: if (!$supplementalflag) {
3665: my $path = 'uploaded/'.
3666: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3667: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3668: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3669: $residx,
3670: &Apache::lonnet::declutter($currurl));
3671: }
1.484.2.12 raeburn 3672: }
1.484.2.30 raeburn 3673: my ($renamelink,%lt,$ishash);
3674: if (ref($filtersref) eq 'HASH') {
3675: $ishash = 1;
3676: }
3677:
1.329 droeschl 3678: if ($allowed) {
1.484.2.30 raeburn 3679: $form_start = '
3680: <form action="/adm/coursedocs" method="post">
3681: ';
3682: $form_common=(<<END);
3683: <input type="hidden" name="folderpath" value="$path" />
3684: <input type="hidden" name="symb" value="$symb" />
3685: END
3686: $form_param=(<<END);
3687: <input type="hidden" name="setparms" value="$orderidx" />
3688: <input type="hidden" name="changeparms" value="0" />
3689: END
3690: $form_end = '</form>';
3691:
1.329 droeschl 3692: my $incindex=$index+1;
3693: my $selectbox='';
1.471 raeburn 3694: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3695: ((split(/\:/,
1.344 bisitz 3696: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3697: ne '') &&
1.329 droeschl 3698: ((split(/\:/,
1.344 bisitz 3699: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3700: ne '')) {
3701: $selectbox=
3702: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3703: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3704: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3705: if ($i==$incindex) {
1.358 bisitz 3706: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3707: } else {
3708: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3709: }
3710: }
3711: $selectbox.='</select>';
3712: }
1.484.2.12 raeburn 3713: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3714: 'up' => 'Move Up',
3715: 'dw' => 'Move Down',
3716: 'rm' => 'Remove',
3717: 'ct' => 'Cut',
3718: 'rn' => 'Rename',
1.484.2.12 raeburn 3719: 'cp' => 'Copy',
3720: 'ex' => 'External Resource',
1.484.2.72.2. (raeburn 3721:): 'et' => 'External Tool',
1.484.2.12 raeburn 3722: 'ed' => 'Edit',
3723: 'pr' => 'Preview',
3724: 'sv' => 'Save',
3725: 'ul' => 'URL',
1.484.2.67 raeburn 3726: 'ti' => 'Title',
3727: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3728: );
1.484.2.30 raeburn 3729: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3730: $env{'form.folderpath'},
3731: $currgroups);
1.484.2.19 raeburn 3732: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3733: my $skip_confirm = 0;
1.484.2.63 raeburn 3734: my $confirm_removal = 0;
1.329 droeschl 3735: if ( $folder =~ /^supplemental/
3736: || ($url =~ m{( /smppg$
3737: |/syllabus$
3738: |/aboutme$
3739: |/navmaps$
3740: |/bulletinboard$
1.484.2.72.2. (raeburn 3741:): |/ext\.tool$
1.484.2.16 raeburn 3742: |\.html$)}x)
1.484.2.19 raeburn 3743: || $isexternal) {
1.329 droeschl 3744: $skip_confirm = 1;
3745: }
1.484.2.63 raeburn 3746: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3747: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3748: $confirm_removal = 1;
3749: }
1.484.2.19 raeburn 3750:
1.484.2.30 raeburn 3751: if ($denied{'copy'}) {
3752: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3753: <span style="visibility: hidden;">$lt{'cp'}</span>
3754: ENDCOPY
3755: } else {
1.484.2.30 raeburn 3756: my $formname = 'edit_copy_'.$orderidx;
3757: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3758: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3759: <form name="$formname" method="post" action="/adm/coursedocs">
3760: $form_common
1.484.2.67 raeburn 3761: <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 3762: $form_end
1.329 droeschl 3763: ENDCOPY
1.484.2.30 raeburn 3764: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3765: push(@{$filtersref->{'cancopy'}},$orderidx);
3766: }
1.329 droeschl 3767: }
1.484.2.30 raeburn 3768: if ($denied{'cut'}) {
1.484.2.16 raeburn 3769: $cutlink=(<<ENDCUT);
3770: <span style="visibility: hidden;">$lt{'ct'}</span>
3771: ENDCUT
3772: } else {
1.484.2.30 raeburn 3773: my $formname = 'edit_cut_'.$orderidx;
3774: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3775: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3776: <form name="$formname" method="post" action="/adm/coursedocs">
3777: $form_common
3778: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3779: <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 3780: $form_end
1.329 droeschl 3781: ENDCUT
1.484.2.30 raeburn 3782: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3783: push(@{$filtersref->{'cancut'}},$orderidx);
3784: }
1.329 droeschl 3785: }
1.484.2.30 raeburn 3786: if ($denied{'remove'}) {
1.484.2.16 raeburn 3787: $removelink=(<<ENDREM);
3788: <span style="visibility: hidden;">$lt{'rm'}</a>
3789: ENDREM
3790: } else {
1.484.2.30 raeburn 3791: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3792: 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 3793: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3794: <form name="$formname" method="post" action="/adm/coursedocs">
3795: $form_common
3796: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3797: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3798: <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 3799: $form_end
1.484.2.9 raeburn 3800: ENDREM
1.484.2.30 raeburn 3801: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3802: push(@{$filtersref->{'canremove'}},$orderidx);
3803: }
1.484.2.9 raeburn 3804: }
1.484.2.35 raeburn 3805: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3806: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3807: ENDREN
1.484.2.67 raeburn 3808: my ($uplink,$downlink);
3809: if ($canedit) {
3810: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3811: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3812: } else {
3813: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3814: $downlink = $uplink;
3815: }
1.329 droeschl 3816: $line.=(<<END);
3817: <td>
1.379 bisitz 3818: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3819: <a href="$uplink">
1.484.2.12 raeburn 3820: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3821: </a>
3822: </div>
3823: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3824: <a href="$downlink">
1.484.2.12 raeburn 3825: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3826: </a>
3827: </div>
1.329 droeschl 3828: </td>
3829: <td>
3830: $form_start
1.484.2.30 raeburn 3831: $form_param
1.478 raeburn 3832: $form_common
1.329 droeschl 3833: $selectbox
3834: $form_end
3835: </td>
1.484.2.30 raeburn 3836: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3837: $removelink
1.329 droeschl 3838: $cutlink
3839: $copylink
3840: </td>
3841: END
3842: }
3843: # Figure out what kind of a resource this is
3844: my ($extension)=($url=~/\.(\w+)$/);
3845: my $uploaded=($url=~/^\/*uploaded\//);
3846: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3847: my $isfolder;
3848: my $ispage;
3849: my $containerarg;
1.484.2.67 raeburn 3850: my $folderurl;
1.329 droeschl 3851: if ($uploaded) {
1.472 raeburn 3852: if (($extension eq 'sequence') || ($extension eq 'page')) {
3853: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3854: $containerarg = $1;
1.472 raeburn 3855: if ($extension eq 'sequence') {
3856: $icon=$iconpath.'navmap.folder.closed.gif';
3857: $isfolder=1;
3858: } else {
3859: $icon=$iconpath.'page.gif';
3860: $ispage=1;
3861: }
1.484.2.67 raeburn 3862: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3863: if ($allowed) {
3864: $url='/adm/coursedocs?';
3865: } else {
3866: $url='/adm/supplemental?';
3867: }
1.329 droeschl 3868: } else {
3869: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3870: }
3871: }
1.364 bisitz 3872:
1.484.2.70 raeburn 3873: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3874: my $orig_url = $url;
1.340 raeburn 3875: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.19 raeburn 3876: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.12 raeburn 3877: if (!$supplementalflag && $residx && $symb) {
3878: if ((!$isfolder) && (!$ispage)) {
3879: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3880: $url=&Apache::lonnet::clutter($url);
3881: if ($url=~/^\/*uploaded\//) {
3882: $url=~/\.(\w+)$/;
3883: my $embstyle=&Apache::loncommon::fileembstyle($1);
3884: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3885: $url='/adm/wrapper'.$url;
3886: } elsif ($embstyle eq 'ssi') {
3887: #do nothing with these
3888: } elsif ($url!~/\.(sequence|page)$/) {
3889: $url='/adm/coursedocs/showdoc'.$url;
3890: }
1.484.2.70 raeburn 3891: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
3892: my $wrapped = $1;
3893: my $exturl = $2;
3894: if ($wrapped eq '') {
3895: $url='/adm/wrapper'.$url;
3896: }
3897: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
3898: $nomodal = 1;
3899: }
1.484.2.72.2. (raeburn 3900:): } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
3901:): $url='/adm/wrapper'.$url;
1.484.2.70 raeburn 3902: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3903: if (($ENV{'SERVER_PORT'} == 443) &&
3904: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
3905: $nomodal = 1;
3906: }
1.484.2.19 raeburn 3907: }
1.484.2.12 raeburn 3908: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3909: my $shownsymb = $symb;
3910: if ($isexternal) {
3911: if ($url =~ /^([^#]+)#([^#]+)$/) {
3912: $url = $1;
3913: $anchor = $2;
3914: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
3915: $shownsymb = $1.&escape('#').$anchor;
3916: }
3917: }
3918: }
1.484.2.67 raeburn 3919: unless ($env{'request.role.adv'}) {
3920: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3921: $url = '';
3922: }
3923: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3924: $url = '';
3925: $hiddenres = 1;
3926: }
3927: }
3928: if ($url ne '') {
1.484.2.72.2. (raeburn 3929:): $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3930: }
3931: } elsif (!$env{'request.role.adv'}) {
3932: my $checkencrypt;
3933: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3934: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3935: $checkencrypt = 1;
1.484.2.70 raeburn 3936: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3937: unless (ref($$navmapref)) {
3938: $$navmapref = Apache::lonnavmaps::navmap->new();
3939: }
3940: if (ref($$navmapref)) {
3941: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
3942: $checkencrypt = 1;
3943: }
3944: }
3945: }
3946: if ($checkencrypt) {
3947: my $shownsymb = &Apache::lonenc::encrypted($symb);
3948: my $shownurl = &Apache::lonenc::encrypted($url);
3949: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.72.2. (raeburn 3950:): $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3951: if ($env{'request.enc'} ne '') {
3952: delete($env{'request.enc'});
3953: }
3954: } else {
3955: $url='';
3956: }
3957: } else {
3958: $url='';
3959: }
1.484.2.12 raeburn 3960: } else {
3961: $url='';
3962: }
1.484.2.19 raeburn 3963: }
1.484.2.66 raeburn 3964: } elsif ($supplementalflag) {
3965: if ($isexternal) {
3966: if ($url =~ /^([^#]+)#([^#]+)$/) {
3967: $url = $1;
3968: $anchor = $2;
1.484.2.70 raeburn 3969: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
3970: $nomodal = 1;
3971: }
3972: }
3973: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
3974: if (($ENV{'SERVER_PORT'} == 443) &&
3975: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
3976: $nomodal = 1;
1.484.2.66 raeburn 3977: }
3978: }
1.329 droeschl 3979: }
1.484.2.67 raeburn 3980: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
3981: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 3982: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3983: my $foldername=&escape($foldertitle);
3984: my $folderpath=$env{'form.folderpath'};
3985: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 3986: if (!$allowed && $supplementalflag) {
3987: $folderpath.=$containerarg.'&'.$foldername;
3988: $url.='folderpath='.&escape($folderpath);
3989: } else {
3990: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3991: 'parameter_randompick'))[0];
1.484.2.67 raeburn 3992: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
3993: 'parameter_randomorder'))[0]=~/^yes$/i);
3994: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
3995: 'parameter_hiddenresource'))[0]=~/^yes$/i);
3996: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
3997: 'parameter_encrypturl'))[0]=~/^yes$/i);
3998: unless ($hiddenmap) {
1.484.2.70 raeburn 3999: if (ref($navmapref)) {
4000: unless (ref($$navmapref)) {
4001: $$navmapref = Apache::lonnavmaps::navmap->new();
4002: }
4003: if (ref($$navmapref)) {
4004: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4005: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4006: unless (@resources) {
4007: $hiddenmap = 1;
4008: unless ($env{'request.role.adv'}) {
4009: $url = '';
4010: $hiddenfolder = 1;
4011: }
1.484.2.67 raeburn 4012: }
4013: }
4014: }
4015: }
4016: }
4017: unless ($encryptmap) {
1.484.2.70 raeburn 4018: if ((ref($navmapref)) && (ref($$navmapref))) {
4019: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4020: $encryptmap = 1;
4021: }
1.484.2.67 raeburn 4022: }
4023: }
4024:
4025: # Append randompick number, hidden, and encrypted with ":" to foldername,
4026: # so it gets transferred between levels
4027: $folderpath.=$containerarg.'&'.$foldername.
4028: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4029: unless ($url eq '') {
4030: $url.='folderpath='.&escape($folderpath);
4031: }
1.484.2.19 raeburn 4032: my $rpckchk;
4033: if ($rpicknum) {
4034: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4035: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4036: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4037: }
1.484.2.19 raeburn 4038: }
1.484.2.29 raeburn 4039: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4040: $rand_pick_text =
1.478 raeburn 4041: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4042: $form_param."\n".
1.478 raeburn 4043: $form_common."\n".
1.484.2.67 raeburn 4044: '<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 4045: if ($rpicknum ne '') {
4046: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4047: }
1.484.2.29 raeburn 4048: $rand_pick_text .= '</span></span>'.
4049: $form_end;
1.484.2.30 raeburn 4050: my $ro_set;
1.484.2.67 raeburn 4051: if ($randorder) {
1.484.2.30 raeburn 4052: $ro_set = 'checked="checked"';
4053: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4054: push(@{$filtersref->{'randomorder'}},$orderidx);
4055: }
4056: }
1.484.2.41 raeburn 4057: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4058: $rand_order_text =
1.484.2.29 raeburn 4059: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4060: $form_param."\n".
1.484.2.29 raeburn 4061: $form_common."\n".
1.484.2.67 raeburn 4062: '<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 4063: $form_end;
1.484.2.19 raeburn 4064: }
1.484.2.18 raeburn 4065: } elsif ($supplementalflag && !$allowed) {
1.484.2.72.2. (raeburn 4066:): my $isexttool;
4067:): if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4068:): $url='/adm/wrapper'.$url;
4069:): $isexttool = 1;
4070:): }
1.484.2.19 raeburn 4071: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4072: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4073: if ($title) {
4074: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4075: }
1.484.2.72.2. (raeburn 4076:): if ((($isexternal) || ($isexttool)) && $orderidx) {
1.484.2.19 raeburn 4077: $url .= '&idx='.$orderidx;
4078: }
1.484.2.66 raeburn 4079: if ($anchor ne '') {
4080: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4081: }
1.329 droeschl 4082: }
1.484.2.19 raeburn 4083: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4084: if ($allowed) {
1.484.2.19 raeburn 4085: my $fileloc =
1.484.2.12 raeburn 4086: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4087: if ($isexternal) {
4088: ($editlink,$extresform) =
1.484.2.67 raeburn 4089: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4090: undef,undef,undef,$disabled);
1.484.2.72.2. (raeburn 4091:): } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4092:): ($editlink,$extresform) =
4093:): &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4094:): undef,undef,undef,'tool',$coursedom,
4095:): $coursenum,$ltitoolsref,$disabled);
1.484.2.19 raeburn 4096: } elsif (!$isfolder && !$ispage) {
4097: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4098: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4099: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4100: my $suppanchor;
4101: if ($supplementalflag) {
4102: $suppanchor = $anchor;
4103: }
1.484.2.19 raeburn 4104: my $jscall =
1.484.2.12 raeburn 4105: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4106: $switchserver,
1.484.2.14 raeburn 4107: $forceedit,
1.484.2.19 raeburn 4108: undef,$symb,
4109: &escape($env{'form.folderpath'}),
1.484.2.66 raeburn 4110: $renametitle,'','',1,$suppanchor);
1.484.2.12 raeburn 4111: if ($jscall) {
1.484.2.19 raeburn 4112: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4113: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4114: }
4115: }
4116: }
1.484.2.19 raeburn 4117: $tdalign = ' align="right" valign="top"';
4118: $tdwidth = ' width="80%"';
1.329 droeschl 4119: }
1.408 raeburn 4120: my $reinit;
4121: if ($crstype eq 'Community') {
4122: $reinit = &mt('(re-initialize community to access)');
4123: } else {
4124: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4125: }
4126: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4127: my $link;
1.472 raeburn 4128: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4129: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4130: } elsif ($url) {
1.484.2.66 raeburn 4131: if ($anchor ne '') {
4132: if ($supplementalflag) {
4133: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4134: } else {
4135: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4136: }
4137: }
1.484.2.70 raeburn 4138: $link = &js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
4139: (($anchor ne '')?$anchor:''));
4140: if ($nomodal) {
4141: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4142: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4143: } else {
4144: $line.=&Apache::loncommon::modal_link($link,
4145: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4146: }
1.469 www 4147: } else {
4148: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4149: }
1.484.2.19 raeburn 4150: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4151: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4152: $line.='<a href="'.$url.'">'.$title.'</a>';
4153: } elsif ($url) {
1.484.2.70 raeburn 4154: if ($nomodal) {
4155: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4156: $title.'</a>';
4157: } else {
4158: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4159: }
1.484.2.67 raeburn 4160: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4161: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4162: } else {
4163: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4164: }
1.484.2.19 raeburn 4165: $line.="$extresform</td>";
1.478 raeburn 4166: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4167: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4168: if (($allowed) && ($folder!~/^supplemental/)) {
4169: my %lt=&Apache::lonlocal::texthash(
4170: 'hd' => 'Hidden',
4171: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4172: my ($enctext,$hidtext);
4173: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4174: $enctext = ' checked="checked"';
4175: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4176: push(@{$filtersref->{'encrypturl'}},$orderidx);
4177: }
4178: }
4179: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4180: $hidtext = ' checked="checked"';
4181: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4182: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4183: }
4184: }
1.484.2.29 raeburn 4185: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4186: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4187: $line.=(<<ENDPARMS);
4188: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4189: <form action="/adm/coursedocs" method="post" name="$formhidden">
4190: $form_param
1.478 raeburn 4191: $form_common
1.484.2.67 raeburn 4192: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4193: $form_end
1.458 raeburn 4194: <br />
1.484.2.29 raeburn 4195: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4196: $form_param
1.478 raeburn 4197: $form_common
1.484.2.67 raeburn 4198: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4199: $form_end
4200: </td>
1.478 raeburn 4201: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4202: $rand_order_text</td>
1.329 droeschl 4203: ENDPARMS
4204: }
1.379 bisitz 4205: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4206: return $line;
4207: }
4208:
1.484.2.30 raeburn 4209: sub action_restrictions {
4210: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4211: my %denied = (
4212: cut => 0,
4213: copy => 0,
4214: remove => 0,
4215: );
4216: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4217: # no copy for published maps
4218: $denied{'copy'} = 1;
4219: } elsif ($url=~m{^/res/lib/templates/}) {
4220: $denied{'copy'} = 1;
4221: $denied{'cut'} = 1;
4222: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4223: if ($folderpath =~ /^default&[^\&]+$/) {
4224: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4225: $denied{'remove'} = 1;
4226: }
4227: $denied{'cut'} = 1;
4228: $denied{'copy'} = 1;
4229: }
4230: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4231: my $group = $1;
4232: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4233: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4234: $denied{'remove'} = 1;
4235: }
4236: }
4237: $denied{'cut'} = 1;
4238: $denied{'copy'} = 1;
4239: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4240: my $group = $1;
4241: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4242: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4243: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4244: if (keys(%groupsettings) > 0) {
4245: $denied{'remove'} = 1;
4246: }
4247: $denied{'cut'} = 1;
4248: $denied{'copy'} = 1;
4249: }
4250: }
4251: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4252: my $group = $1;
4253: if ($url =~ /group_boards_\Q$group\E/) {
4254: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4255: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4256: if (keys(%groupsettings) > 0) {
4257: if (ref($groupsettings{'functions'}) eq 'HASH') {
4258: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4259: $denied{'remove'} = 1;
4260: }
4261: }
4262: }
4263: $denied{'cut'} = 1;
4264: $denied{'copy'} = 1;
4265: }
4266: }
4267: }
4268: return %denied;
4269: }
4270:
1.484.2.26 raeburn 4271: sub new_timebased_suffix {
1.484.2.30 raeburn 4272: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4273: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4274: if ($type eq 'paste') {
4275: $prefix = $type;
4276: $namespace = 'courseeditor';
1.484.2.56 raeburn 4277: $idtype = 'addcode';
1.484.2.30 raeburn 4278: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4279: $prefix = 'docs';
4280: if ($area eq 'supplemental') {
4281: $prefix = 'supp';
4282: }
4283: $prefix .= $container;
4284: $namespace = 'uploadedmaps';
4285: } else {
4286: $prefix = $type;
4287: $namespace = 'templated';
1.484.2.15 raeburn 4288: }
4289: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4290: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4291: if (!$suffix) {
1.484.2.30 raeburn 4292: if ($type eq 'paste') {
4293: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4294: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4295: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4296: } elsif ($type eq 'smppg') {
4297: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.484.2.72.2. (raeburn 4298:): } elsif ($type eq 'exttool') {
4299:): $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.484.2.26 raeburn 4300: } else {
1.484.2.42 raeburn 4301: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4302: }
1.484.2.15 raeburn 4303: if ($error) {
4304: $errtext .= '<br />'.$error;
4305: }
4306: }
4307: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4308: $locknotfreed =
4309: '<div class="LC_error">'.
4310: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4311: if ($type eq 'paste') {
1.484.2.57 raeburn 4312: if ($freedlock eq 'nolock') {
4313: $locknotfreed =
4314: '<div class="LC_error">'.
4315: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4316:
1.484.2.60 raeburn 4317: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4318: } else {
4319: $locknotfreed .=
4320: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4321: }
1.484.2.30 raeburn 4322: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4323: $locknotfreed .=
4324: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4325: } elsif ($type eq 'smppg') {
4326: $locknotfreed .=
4327: &mt('This will prevent creation of additional simple pages in this course.');
1.484.2.72.2. (raeburn 4328:): } elsif ($type eq 'exttool') {
4329:): $locknotfreed .=
4330:): &mt('This will prevent creation of additional external tools in this course.');
1.484.2.26 raeburn 4331: } else {
4332: $locknotfreed .=
1.484.2.42 raeburn 4333: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4334: }
1.484.2.30 raeburn 4335: unless ($type eq 'paste') {
4336: $locknotfreed .=
1.484.2.38 raeburn 4337: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4338: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4339: }
4340: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4341: }
4342: return ($suffix,$errtext,$locknotfreed);
4343: }
4344:
1.329 droeschl 4345: =pod
4346:
4347: =item tiehash()
4348:
4349: tie the hash
4350:
4351: =cut
4352:
4353: sub tiehash {
4354: my ($mode)=@_;
4355: $hashtied=0;
4356: if ($env{'request.course.fn'}) {
4357: if ($mode eq 'write') {
4358: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4359: &GDBM_WRCREAT(),0640)) {
4360: $hashtied=2;
4361: }
4362: } else {
4363: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4364: &GDBM_READER(),0640)) {
4365: $hashtied=1;
4366: }
4367: }
1.364 bisitz 4368: }
1.329 droeschl 4369: }
4370:
4371: sub untiehash {
4372: if ($hashtied) { untie %hash; }
4373: $hashtied=0;
4374: return OK;
4375: }
4376:
4377:
4378:
4379:
4380: sub checkonthis {
4381: my ($r,$url,$level,$title)=@_;
4382: $url=&unescape($url);
4383: $alreadyseen{$url}=1;
4384: $r->rflush();
4385: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4386: $r->print("\n<br />");
4387: if ($level==0) {
4388: $r->print("<br />");
4389: }
4390: for (my $i=0;$i<=$level*5;$i++) {
4391: $r->print(' ');
4392: }
4393: $r->print('<a href="'.$url.'" target="cat">'.
4394: ($title?$title:$url).'</a> ');
4395: if ($url=~/^\/res\//) {
4396: my $result=&Apache::lonnet::repcopy(
4397: &Apache::lonnet::filelocation('',$url));
4398: if ($result eq 'ok') {
4399: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4400: $r->rflush();
4401: &Apache::lonnet::countacc($url);
4402: $url=~/\.(\w+)$/;
4403: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4404: $r->print('<br />');
4405: $r->rflush();
4406: for (my $i=0;$i<=$level*5;$i++) {
4407: $r->print(' ');
4408: }
4409: $r->print('- '.&mt('Rendering:').' ');
4410: my ($errorcount,$warningcount)=split(/:/,
4411: &Apache::lonnet::ssi_body($url,
4412: ('grade_target'=>'web',
4413: 'return_only_error_and_warning_counts' => 1)));
4414: if (($errorcount) ||
4415: ($warningcount)) {
4416: if ($errorcount) {
1.369 bisitz 4417: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4418: &mt('[quant,_1,error]',$errorcount).'</span>');
4419: }
4420: if ($warningcount) {
4421: $r->print('<span class="LC_warning">'.
4422: &mt('[quant,_1,warning]',$warningcount).'</span>');
4423: }
4424: } else {
4425: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4426: }
4427: $r->rflush();
4428: }
4429: my $dependencies=
4430: &Apache::lonnet::metadata($url,'dependencies');
4431: foreach my $dep (split(/\,/,$dependencies)) {
4432: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4433: &checkonthis($r,$dep,$level+1);
4434: }
4435: }
4436: } elsif ($result eq 'unavailable') {
4437: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4438: } elsif ($result eq 'not_found') {
4439: unless ($url=~/\$/) {
1.484.2.19 raeburn 4440: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4441: } else {
1.366 bisitz 4442: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4443: }
4444: } else {
4445: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4446: }
4447: }
4448: }
4449: }
4450:
4451:
4452:
4453: =pod
4454:
4455: =item list_symbs()
4456:
1.484.2.3 raeburn 4457: List Content Identifiers
1.329 droeschl 4458:
4459: =cut
4460:
4461: sub list_symbs {
4462: my ($r) = @_;
4463:
1.408 raeburn 4464: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4465: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4466: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4467: $r->print(&startContentScreen('tools'));
1.329 droeschl 4468: my $navmap = Apache::lonnavmaps::navmap->new();
4469: if (!defined($navmap)) {
4470: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4471: '<div class="LC_error">'.
4472: &mt('Unable to retrieve information about course contents').
4473: '</div>');
1.408 raeburn 4474: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4475: } else {
1.484 raeburn 4476: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4477: &Apache::loncommon::start_data_table().
4478: &Apache::loncommon::start_data_table_header_row().
4479: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4480: &Apache::loncommon::end_data_table_header_row()."\n");
4481: my $count;
1.329 droeschl 4482: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4483: $r->print(&Apache::loncommon::start_data_table_row().
4484: '<td>'.$res->compTitle().'</td>'.
4485: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4486: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4487: $count ++;
4488: }
4489: if (!$count) {
4490: $r->print(&Apache::loncommon::start_data_table_row().
4491: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4492: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4493: }
1.484 raeburn 4494: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4495: }
1.484.2.19 raeburn 4496: $r->print(&endContentScreen());
1.329 droeschl 4497: }
4498:
4499:
4500: sub verifycontent {
4501: my ($r) = @_;
1.408 raeburn 4502: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4503: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4504: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4505: $r->print(&startContentScreen('tools'));
4506: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4507: $hashtied=0;
4508: undef %alreadyseen;
4509: %alreadyseen=();
4510: &tiehash();
1.484 raeburn 4511:
1.329 droeschl 4512: foreach my $key (keys(%hash)) {
4513: if ($hash{$key}=~/\.(page|sequence)$/) {
4514: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4515: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4516: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4517: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4518: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4519: }
4520: }
4521: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4522: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4523: }
4524: }
4525: &untiehash();
1.442 www 4526: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4527: $r->print(&endContentScreen());
1.329 droeschl 4528: }
4529:
4530:
4531: sub devalidateversioncache {
4532: my $src=shift;
4533: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4534: &Apache::lonnet::clutter($src));
4535: }
4536:
4537: sub checkversions {
1.484.2.67 raeburn 4538: my ($r,$canedit) = @_;
1.408 raeburn 4539: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4540: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4541: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4542: $r->print(&startContentScreen('tools'));
1.442 www 4543:
1.329 droeschl 4544: my $header='';
4545: my $startsel='';
4546: my $monthsel='';
4547: my $weeksel='';
4548: my $daysel='';
4549: my $allsel='';
4550: my %changes=();
4551: my $starttime=0;
4552: my $haschanged=0;
4553: my %setversions=&Apache::lonnet::dump('resourceversions',
4554: $env{'course.'.$env{'request.course.id'}.'.domain'},
4555: $env{'course.'.$env{'request.course.id'}.'.num'});
4556:
4557: $hashtied=0;
4558: &tiehash();
1.484.2.67 raeburn 4559: if ($canedit) {
4560: my %newsetversions=();
4561: if ($env{'form.setmostrecent'}) {
4562: $haschanged=1;
4563: foreach my $key (keys(%hash)) {
4564: if ($key=~/^ids\_(\/res\/.+)$/) {
4565: $newsetversions{$1}='mostrecent';
4566: &devalidateversioncache($1);
4567: }
1.329 droeschl 4568: }
1.484.2.67 raeburn 4569: } elsif ($env{'form.setcurrent'}) {
4570: $haschanged=1;
4571: foreach my $key (keys(%hash)) {
4572: if ($key=~/^ids\_(\/res\/.+)$/) {
4573: my $getvers=&Apache::lonnet::getversion($1);
4574: if ($getvers>0) {
4575: $newsetversions{$1}=$getvers;
4576: &devalidateversioncache($1);
4577: }
4578: }
1.329 droeschl 4579: }
1.484.2.67 raeburn 4580: } elsif ($env{'form.setversions'}) {
4581: $haschanged=1;
4582: foreach my $key (keys(%env)) {
4583: if ($key=~/^form\.set_version_(.+)$/) {
4584: my $src=$1;
4585: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4586: $newsetversions{$src}=$env{$key};
4587: &devalidateversioncache($src);
4588: }
4589: }
1.329 droeschl 4590: }
1.484.2.67 raeburn 4591: }
4592: if ($haschanged) {
4593: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4594: $env{'course.'.$env{'request.course.id'}.'.domain'},
4595: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4596: $r->print(&Apache::loncommon::confirmwrapper(
4597: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4598: } else {
4599: $r->print(&Apache::loncommon::confirmwrapper(
4600: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4601: }
4602: &mark_hash_old();
4603: }
4604: &changewarning($r,'');
1.329 droeschl 4605: }
4606: if ($env{'form.timerange'} eq 'all') {
4607: # show all documents
1.484.2.34 raeburn 4608: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4609: $allsel=' selected="selected"';
1.329 droeschl 4610: foreach my $key (keys(%hash)) {
4611: if ($key=~/^ids\_(\/res\/.+)$/) {
4612: my $src=$1;
4613: $changes{$src}=1;
4614: }
4615: }
4616: } else {
4617: # show documents which changed
4618: %changes=&Apache::lonnet::dump
4619: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4620: $env{'course.'.$env{'request.course.id'}.'.num'});
4621: my $firstkey=(keys(%changes))[0];
4622: unless ($firstkey=~/^error\:/) {
4623: unless ($env{'form.timerange'}) {
4624: $env{'form.timerange'}=604800;
4625: }
4626: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4627: .&mt('seconds');
4628: if ($env{'form.timerange'}==-1) {
4629: $seltext='since start of course';
1.484.2.19 raeburn 4630: $startsel=' selected="selected"';
1.329 droeschl 4631: $env{'form.timerange'}=time;
4632: }
4633: $starttime=time-$env{'form.timerange'};
4634: if ($env{'form.timerange'}==2592000) {
4635: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4636: $monthsel=' selected="selected"';
1.329 droeschl 4637: } elsif ($env{'form.timerange'}==604800) {
4638: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4639: $weeksel=' selected="selected"';
1.329 droeschl 4640: } elsif ($env{'form.timerange'}==86400) {
4641: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4642: $daysel=' selected="selected"';
1.329 droeschl 4643: }
4644: $header=&mt('Content changed').' '.$seltext;
4645: } else {
4646: $header=&mt('No content modifications yet.');
4647: }
4648: }
4649: %setversions=&Apache::lonnet::dump('resourceversions',
4650: $env{'course.'.$env{'request.course.id'}.'.domain'},
4651: $env{'course.'.$env{'request.course.id'}.'.num'});
4652: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4653: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4654: 'lm' => 'Version changes since last Month',
4655: 'lw' => 'Version changes since last Week',
4656: 'sy' => 'Version changes since Yesterday',
4657: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4658: 'cd' => 'Change display',
1.329 droeschl 4659: 'sd' => 'Display',
4660: 'fi' => 'File',
4661: 'md' => 'Modification Date',
4662: 'mr' => 'Most recently published Version',
1.408 raeburn 4663: 've' => 'Version used in '.$crstype,
4664: 'vu' => 'Set Version to be used in '.$crstype,
4665: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4666: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4667: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4668: 'di' => 'Differences',
1.484 raeburn 4669: 'save' => 'Save changes',
4670: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4671: 'act' => 'Actions');
1.484.2.67 raeburn 4672: my ($disabled,$readonly);
4673: unless ($canedit) {
4674: $disabled = 'disabled="disabled"';
4675: $readonly = 1;
4676: }
1.329 droeschl 4677: $r->print(<<ENDHEADERS);
1.484 raeburn 4678: <h4 class="LC_info">$header</h4>
1.329 droeschl 4679: <form action="/adm/coursedocs" method="post">
4680: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4681: <div class="LC_left_float">
1.479 golterma 4682: <fieldset>
1.484 raeburn 4683: <legend>$lt{'cd'}</legend>
1.329 droeschl 4684: <select name="timerange">
1.484.2.19 raeburn 4685: <option value='all'$allsel>$lt{'al'}</option>
4686: <option value="-1"$startsel>$lt{'st'}</option>
4687: <option value="2592000"$monthsel>$lt{'lm'}</option>
4688: <option value="604800"$weeksel>$lt{'lw'}</option>
4689: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4690: </select>
4691: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4692: </fieldset>
4693: </div>
4694: <div class="LC_left_float">
4695: <fieldset>
4696: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4697: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4698: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4699: </fieldset>
4700: </div>
4701: <br clear="all" />
4702: <hr />
4703: <h4>$lt{'vers'}</h4>
1.329 droeschl 4704: ENDHEADERS
1.479 golterma 4705: #number of columns for version history
1.484.2.44 raeburn 4706: my %changedbytime;
4707: foreach my $key (keys(%changes)) {
4708: #excludes not versionable problems from resource version history:
4709: next if ($key =~ /^\/res\/lib\/templates/);
4710: my $chg;
4711: if ($env{'form.timerange'} eq 'all') {
4712: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4713: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4714: } else {
4715: $chg = $changes{$key};
4716: next if ($chg < $starttime);
4717: }
4718: push(@{$changedbytime{$chg}},$key);
4719: }
4720: if (keys(%changedbytime) == 0) {
4721: &untiehash();
4722: $r->print(&mt('No content changes in imported content in specified time frame').
4723: &endContentScreen());
4724: return;
4725: }
1.479 golterma 4726: $r->print(
1.484.2.67 raeburn 4727: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4728: &Apache::loncommon::start_data_table().
4729: &Apache::loncommon::start_data_table_header_row().
4730: '<th>'.&mt('Resources').'</th>'.
4731: "<th>$lt{'mr'}</th>".
4732: "<th>$lt{'ve'}</th>".
4733: "<th>$lt{'vu'}</th>".
4734: '<th>'.&mt('History').'</th>'.
4735: &Apache::loncommon::end_data_table_header_row()
4736: );
1.484.2.44 raeburn 4737: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4738: foreach my $key (sort(@{$changedbytime{$chg}})) {
4739: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4740: my $currentversion=&Apache::lonnet::getversion($key);
4741: if ($currentversion<0) {
4742: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4743: }
4744: my $linkurl=&Apache::lonnet::clutter($key);
4745: $r->print(
4746: &Apache::loncommon::start_data_table_row().
4747: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4748: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4749: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4750: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4751: '<td align="right">'
4752: );
4753: # Used in course
4754: my $usedversion=$hash{'version_'.$linkurl};
4755: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4756: if ($usedversion != $currentversion) {
1.479 golterma 4757: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4758: } else {
1.479 golterma 4759: $r->print($usedversion);
4760: }
1.329 droeschl 4761: } else {
1.484.2.19 raeburn 4762: $r->print($currentversion);
1.329 droeschl 4763: }
1.484.2.44 raeburn 4764: $r->print('</td><td title="'.$lt{'vu'}.'">');
4765: # Set version
4766: $r->print(&Apache::loncommon::select_form(
4767: $setversions{$linkurl},
4768: 'set_version_'.$linkurl,
4769: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4770: '' => '',
4771: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4772: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4773: my $lastold=1;
4774: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4775: my $url=$root.'.'.$prevvers.'.'.$extension;
4776: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4777: $lastold=$prevvers;
4778: }
4779: }
4780: $r->print('</td>');
4781: # List all available versions
4782: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4783: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4784: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4785: $r->print(
1.484.2.44 raeburn 4786: '<span class="LC_nobreak">'
4787: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4788: .&mt('Version [_1]',$prevvers).'</a>'
4789: .' ('.&Apache::lonlocal::locallocaltime(
4790: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4791: .')');
4792: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4793: $r->print(
4794: ' <a href="/adm/diff?filename='.
4795: &Apache::lonnet::clutter($root.'.'.$extension).
4796: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4797: '" target="diffs">'.&mt('Diffs').'</a>');
4798: }
4799: $r->print('</span><br />');
1.329 droeschl 4800: }
1.484.2.44 raeburn 4801: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4802: }
1.329 droeschl 4803: }
1.484.2.19 raeburn 4804: $r->print(
4805: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4806: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4807: '</form>'
4808: );
1.329 droeschl 4809:
4810: &untiehash();
1.484.2.19 raeburn 4811: $r->print(&endContentScreen());
1.484.2.44 raeburn 4812: return;
1.329 droeschl 4813: }
4814:
4815: sub mark_hash_old {
4816: my $retie_hash=0;
4817: if ($hashtied) {
4818: $retie_hash=1;
4819: &untiehash();
4820: }
4821: &tiehash('write');
4822: $hash{'old'}=1;
4823: &untiehash();
4824: if ($retie_hash) { &tiehash(); }
4825: }
4826:
4827: sub is_hash_old {
4828: my $untie_hash=0;
4829: if (!$hashtied) {
4830: $untie_hash=1;
4831: &tiehash();
4832: }
4833: my $return=$hash{'old'};
4834: if ($untie_hash) { &untiehash(); }
4835: return $return;
4836: }
4837:
4838: sub changewarning {
4839: my ($r,$postexec,$message,$url)=@_;
4840: if (!&is_hash_old()) { return; }
4841: my $pathvar='folderpath';
4842: my $path=&escape($env{'form.folderpath'});
4843: if (!defined($url)) {
4844: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4845: }
4846: my $course_type = &Apache::loncommon::course_type();
4847: if (!defined($message)) {
4848: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4849: }
4850: $r->print("\n\n".
1.372 bisitz 4851: '<script type="text/javascript">'."\n".
4852: '// <![CDATA['."\n".
4853: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4854: '// ]]>'."\n".
1.369 bisitz 4855: '</script>'."\n".
1.375 tempelho 4856: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4857: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4858: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4859: &mt($message,' <input type="hidden" name="'.
4860: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4861: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4862: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4863: }
4864:
4865:
4866: sub init_breadcrumbs {
1.484.2.44 raeburn 4867: my ($form,$text,$help)=@_;
1.329 droeschl 4868: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4869: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4870: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4871: faq=>273,
4872: bug=>'Instructor Interface',
1.484.2.44 raeburn 4873: help => $help});
1.329 droeschl 4874: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4875: text=>$text,
4876: faq=>273,
4877: bug=>'Instructor Interface'});
4878: }
4879:
1.441 www 4880: # subroutine to list form elements
4881: sub create_list_elements {
4882: my @formarr = @_;
4883: my $list = '';
1.484.2.12 raeburn 4884: foreach my $button (@formarr){
4885: foreach my $picture (keys(%{$button})) {
4886: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4887: }
4888: }
4889: return $list;
4890: }
1.329 droeschl 4891:
1.441 www 4892: # subroutine to create ul from list elements
4893: sub create_form_ul {
4894: my $list = shift;
4895: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4896: return $ul;
4897: }
1.329 droeschl 4898:
1.442 www 4899: #
4900: # Start tabs
4901: #
4902:
4903: sub startContentScreen {
1.484 raeburn 4904: my ($mode) = @_;
4905: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4906: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4907: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4908: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4909: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4910: } else {
1.484.2.34 raeburn 4911: $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 4912: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4913: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4914: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4915: }
4916: $output .= "\n".'</ul>'."\n";
4917: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4918: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4919: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4920: return $output;
1.442 www 4921: }
4922:
4923: #
4924: # End tabs
4925: #
4926:
4927: sub endContentScreen {
1.484 raeburn 4928: return '</div></div></div>';
1.442 www 4929: }
1.329 droeschl 4930:
1.446 www 4931: sub supplemental_base {
1.484.2.33 raeburn 4932: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4933: }
4934:
1.329 droeschl 4935: sub handler {
4936: my $r = shift;
4937: &Apache::loncommon::content_type($r,'text/html');
4938: $r->send_http_header;
4939: return OK if $r->header_only;
1.484 raeburn 4940:
4941: # get course data
1.408 raeburn 4942: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4943: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4944: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4945:
4946: # graphics settings
4947: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4948:
1.443 www 4949: #
1.329 droeschl 4950: # --------------------------------------------- Initialize help topics for this
4951: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.484.2.72.2. (raeburn 4952:): 'Adding_External_Resource','Adding_External_Tool',
4953:): 'Navigate_Content','Adding_Folders','Docs_Overview',
4954:): 'Load_Map','Supplemental','Score_Upload_Form',
4955:): 'Adding_Pages','Importing_LON-CAPA_Resource',
4956:): 'Importing_IMS_Course','Uploading_From_Harddrive',
4957:): 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 4958: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4959: }
4960: # Composite help files
4961: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4962: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4963: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4964: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4965: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4966: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4967: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4968: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4969: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4970: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 4971:
1.484.2.67 raeburn 4972: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 4973: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4974: unless ($r->uri eq '/adm/supplemental') {
4975: # does this user have privileges to modify content.
1.484.2.67 raeburn 4976: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
4977: $allowed = 1;
4978: $canedit = 1;
4979: $canview = 1;
4980: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
4981: $allowed = 1;
4982: $canview = 1;
4983: }
4984: }
4985: unless ($canedit) {
4986: $disabled = ' disabled="disabled"';
1.472 raeburn 4987: }
1.484.2.53 raeburn 4988: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.72.2. (raeburn 4989:): if ($env{'form.inhibitmenu'}) {
4990:): unless ($env{'form.inhibitmenu'} eq 'yes') {
4991:): delete($env{'form.inhibitmenu'});
4992:): }
4993:): }
1.484.2.53 raeburn 4994: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 4995: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 4996: &verifycontent($r);
4997: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4998: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4999: &list_symbs($r);
5000: } elsif ($allowed && $env{'form.docslog'}) {
5001: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5002: my $folder = $env{'form.folder'};
5003: if ($folder eq '') {
5004: $folder='default';
5005: }
1.484.2.67 raeburn 5006: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5007: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5008: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5009: &checkversions($r,$canedit);
5010: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5011: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5012: &dumpcourse($r);
5013: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5014: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5015: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5016: } else {
1.445 www 5017: #
5018: # Done catching special calls
1.484 raeburn 5019: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5020: # Get the parameters that may be needed
5021: #
5022: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5023: ['folderpath',
5024: 'forcesupplement','forcestandard',
5025: 'tools','symb','command','supppath']);
1.445 www 5026:
1.484.2.72.2. (raeburn 5027:): foreach my $item ('forcesupplement','forcestandard','tools') {
5028:): next if ($env{'form.'.$item} eq '');
5029:): unless ($env{'form.'.$item} eq '1') {
5030:): delete($env{'form.'.$item});
5031:): }
5032:): }
5033:):
5034:): if ($env{'form.command'}) {
5035:): unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5036:): delete($env{'form.command'});
5037:): }
5038:): }
5039:):
5040:): if ($env{'form.symb'}) {
5041:): my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5042:): unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5043:): delete($env{'form.symb'});
5044:): }
5045:): }
1.445 www 5046: # standard=1: this is a "new-style" course with an uploaded map as top level
5047: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5048:
5049: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5050:
1.484 raeburn 5051: # Decide whether this should display supplemental or main content or utilities
1.445 www 5052: # supplementalflag=1: show supplemental documents
5053: # supplementalflag=0: show standard documents
1.484 raeburn 5054: # toolsflag=1: show utilities
1.445 www 5055:
1.484.2.39 raeburn 5056: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5057: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5058: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5059: $supplementalflag=0;
5060: }
5061: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5062: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5063: unless ($allowed) { $supplementalflag=1; }
5064: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5065: my $toolsflag=0;
5066: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5067:
1.484.2.72.2. (raeburn 5068:): if ($env{'form.folderpath'} ne '') {
5069:): my @items = split(/\&/,$env{'form.folderpath'});
5070:): my $badpath;
5071:): for (my $i=0; $i<@items; $i++) {
5072:): my $odd = $i%2;
5073:): if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5074:): $badpath = 1;
5075:): } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5076:): $badpath = 1;
5077:): }
5078:): last if ($badpath);
5079:): }
5080:): if ($badpath) {
5081:): delete($env{'form.folderpath'});
5082:): }
5083:): }
5084:):
5085:): if ($env{'form.supppath'} ne '') {
5086:): my @items = split(/\&/,$env{'form.supppath'});
5087:): my $badpath;
5088:): for (my $i=0; $i<@items; $i++) {
5089:): my $odd = $i%2;
5090:): if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5091:): $badpath = 1;
5092:): }
5093:): last if ($badpath);
5094:): }
5095:): if ($badpath) {
5096:): delete($env{'form.supppath'});
5097:): }
5098:): }
5099:):
1.329 droeschl 5100: my $script='';
5101: my $showdoc=0;
1.457 raeburn 5102: my $addentries = {};
1.475 raeburn 5103: my $container;
1.329 droeschl 5104: my $containertag;
1.484.2.17 raeburn 5105: my $pathitem;
1.484.2.72.2. (raeburn 5106:): my %ltitools;
1.484.2.67 raeburn 5107: my $hiddentop;
5108: my $navmap;
5109: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5110:
1.464 www 5111: # Do we directly jump somewhere?
1.484.2.21 raeburn 5112: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5113: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5114: $env{'form.folderpath'}=
1.484.2.67 raeburn 5115: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5116: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5117: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5118: } elsif ($env{'form.supppath'} ne '') {
5119: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5120: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5121: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5122: }
1.472 raeburn 5123: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5124: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5125: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5126: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5127: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5128: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5129: } elsif ($env{'form.command'} eq 'contents') {
5130: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5131: } elsif ($env{'form.command'} eq 'home') {
5132: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5133: }
5134:
1.484.2.23 raeburn 5135:
1.445 www 5136: # Where do we store these for when we come back?
5137: my $stored_folderpath='docs_folderpath';
5138: if ($supplementalflag) {
5139: $stored_folderpath='docs_sup_folderpath';
5140: }
1.464 www 5141:
1.484.2.19 raeburn 5142: # No folderpath, and in edit mode, see if we have something stored
5143: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5144: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5145: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5146:
5147: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5148: if ($supplementalflag) {
5149: undef($env{'form.folderpath'}) if ($1 eq 'default');
5150: } else {
5151: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5152: }
5153: } else {
1.484.2.19 raeburn 5154: undef($env{'form.folderpath'});
5155: }
1.329 droeschl 5156: }
1.446 www 5157:
5158: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5159: if (!$allowed) {
1.446 www 5160: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5161: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5162: }
5163: }
1.446 www 5164: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5165: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5166: $env{'form.folderpath'} = &supplemental_base()
5167: .'&'.
1.329 droeschl 5168: $env{'form.folderpath'};
5169: }
1.484.2.67 raeburn 5170: # If allowed and user's role is not advanced check folderpath is not hidden
5171: if (($allowed) && (!$env{'request.role.adv'}) &&
5172: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5173: my $folderurl;
5174: my @pathitems = split(/\&/,$env{'form.folderpath'});
5175: my $folder = $pathitems[-2];
5176: if ($folder eq '') {
5177: undef($env{'form.folderpath'});
5178: } else {
5179: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5180: if ((split(/\:/,$pathitems[-1]))[4]) {
5181: $folderurl .= '.page';
5182: } else {
5183: $folderurl .= '.sequence';
5184: }
5185: unless (ref($navmap)) {
5186: $navmap = Apache::lonnavmaps::navmap->new();
5187: }
5188: if (ref($navmap)) {
5189: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5190: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5191: unless (@resources) {
5192: undef($env{'form.folderpath'});
5193: }
5194: }
5195: }
5196: }
5197: }
5198:
5199:
1.446 www 5200: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5201: unless ($env{'form.folderpath'}) {
1.446 www 5202: if ($supplementalflag) {
5203: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5204: } elsif ($allowed) {
5205: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5206: }
1.472 raeburn 5207: }
1.446 www 5208:
1.445 www 5209: # Store this
1.484 raeburn 5210: unless ($toolsflag) {
1.484.2.67 raeburn 5211: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5212: &Apache::loncommon::store_course_settings($stored_folderpath,
5213: {'folderpath' => 'scalar'});
5214: }
5215: my $folderpath;
1.484 raeburn 5216: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5217: $folderpath = $env{'form.folderpath'};
5218: my (@folders)=split('&',$env{'form.folderpath'});
5219: $env{'form.foldername'}=&unescape(pop(@folders));
5220: if ($env{'form.foldername'} =~ /\:1$/) {
5221: $container = 'page';
5222: } else {
5223: $container = 'sequence';
5224: }
5225: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5226: } else {
1.484.2.19 raeburn 5227: if ($env{'form.folder'} eq '' ||
5228: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5229: if ($env{'form.folder'} eq 'supplemental') {
5230: $folderpath=&supplemental_base();
5231: } elsif (!$hiddentop) {
5232: $folderpath='default&'.
5233: &escape(&mt('Main Content').':::::');
5234: }
1.484 raeburn 5235: }
5236: }
1.484.2.19 raeburn 5237: $containertag = '<input type="hidden" name="folderpath" value="" />';
5238: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5239: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5240: $showdoc='/'.$1;
5241: }
5242: if ($showdoc) { # got called in sequence from course
5243: $allowed=0;
5244: } else {
1.484.2.67 raeburn 5245: if ($canedit) {
1.484 raeburn 5246: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5247: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5248: }
5249: }
1.329 droeschl 5250: }
5251:
1.344 bisitz 5252: # get personal data
1.329 droeschl 5253: my $uname=$env{'user.name'};
5254: my $udom=$env{'user.domain'};
5255: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5256:
5257: if ($allowed) {
1.484 raeburn 5258: if ($toolsflag) {
5259: $script .= &inject_data_js();
5260: my ($home,$other,%outhash)=&authorhosts();
5261: if (!$home && $other) {
5262: my @hosts;
5263: foreach my $aurole (keys(%outhash)) {
5264: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5265: push(@hosts,$outhash{$aurole});
5266: }
5267: }
5268: $script .= &dump_switchserver_js(@hosts);
5269: }
1.458 raeburn 5270: } else {
1.484.2.43 raeburn 5271: my $tid = 1;
1.484 raeburn 5272: my @tabids;
5273: if ($supplementalflag) {
5274: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5275: $tid = 2;
1.484 raeburn 5276: } else {
5277: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5278: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5279: unshift(@tabids,'001');
5280: push(@tabids,('dd1','ee1'));
5281: }
1.458 raeburn 5282: }
1.484 raeburn 5283: my $tabidstr = join("','",@tabids);
1.484.2.72.2. (raeburn 5284:): %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
5285:): my $posslti = keys(%ltitools);
5286:): $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.484.2.67 raeburn 5287: $canedit,\$navmap).
1.484 raeburn 5288: &history_tab_js().
5289: &inject_data_js().
1.484.2.43 raeburn 5290: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.72.2. (raeburn 5291:): &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5292: $addentries = {
1.484.2.3 raeburn 5293: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5294: };
1.458 raeburn 5295: }
1.484.2.30 raeburn 5296: $script .= &paste_popup_js();
1.484.2.12 raeburn 5297: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5298: &mt('Switch server?');
1.484.2.19 raeburn 5299:
5300:
1.329 droeschl 5301: }
5302: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5303: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5304: .'// <![CDATA['."\n"
5305: .$script."\n"
5306: .'// ]]>'."\n"
5307: .'</script>'."\n";
1.385 bisitz 5308:
5309: # Breadcrumbs
5310: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5311:
5312: if ($showdoc) {
5313: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5314: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5315: } elsif ($toolsflag) {
1.484.2.67 raeburn 5316: my ($breadtext,$breadtitle);
5317: $breadtext = "$crstype Editor";
5318: if ($canedit) {
5319: $breadtitle = 'Editing '.$crstype.' Contents';
5320: } else {
5321: $breadtext .= ' (View-only mode)';
5322: $breadtitle = 'Viewing '.$crstype.' Contents';
5323: }
1.484.2.44 raeburn 5324: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5325: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5326: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5327: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5328: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5329: $breadtitle)
1.484.2.44 raeburn 5330: );
1.484.2.19 raeburn 5331: } elsif ($r->uri eq '/adm/supplemental') {
5332: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5333: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5334: {'bread_crumbs' => $brcrum,}));
5335: } else {
1.484.2.67 raeburn 5336: my ($breadtext,$breadtitle,$helpitem);
5337: $breadtext = "$crstype Editor";
5338: if ($canedit) {
5339: $breadtitle = 'Editing '.$crstype.' Contents';
5340: $helpitem = 'Docs_Adding_Course_Doc';
5341: } else {
5342: $breadtext .= ' (View-only mode)';
5343: $breadtitle = 'Viewing '.$crstype.' Contents';
5344: $helpitem = 'Docs_Viewing_Course_Doc';
5345: }
1.392 raeburn 5346: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5347: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5348: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5349: {'add_entries' => $addentries}
5350: )
1.392 raeburn 5351: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5352: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5353: $breadtitle,
5354: $helpitem)
1.392 raeburn 5355: );
5356: }
1.364 bisitz 5357:
1.329 droeschl 5358: my %allfiles = ();
5359: my %codebase = ();
1.440 raeburn 5360: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5361: if ($canedit) {
1.329 droeschl 5362: if (($env{'form.uploaddoc.filename'}) &&
5363: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5364: my $context = $1;
5365: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5366: undef($hadchanges);
1.440 raeburn 5367: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5368: \%allfiles,\%codebase,$context,$crstype);
1.484.2.72.2. (raeburn 5369:): undef($navmap);
1.329 droeschl 5370: if ($hadchanges) {
5371: &mark_hash_old();
5372: }
1.440 raeburn 5373: $r->print($upload_output);
5374: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5375: # Process file upload - phase two - upload embedded objects
5376: $uploadphase = 'check_embedded';
5377: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5378: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5379: $env{'form.newidx'});
5380: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5381: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5382: my ($destination,$dir_root) = &embedded_destination();
5383: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5384: my $actionurl = '/adm/coursedocs';
5385: my ($result,$flag) =
5386: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5387: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5388: $actionurl);
5389: $r->print($result.&return_to_editor());
5390: } elsif ($env{'form.phase'} eq 'check_embedded') {
5391: # Process file upload - phase three - modify references in HTML file
5392: $uploadphase = 'modified_orightml';
5393: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5394: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5395: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5396: my $result =
5397: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5398: $docuname,$docudom,undef,
5399: $dir_root);
5400: $r->print($result.&return_to_editor());
1.476 raeburn 5401: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5402: $uploadphase = 'decompress_phase_one';
5403: $r->print(&decompression_phase_one().
5404: &return_to_editor());
5405: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5406: $uploadphase = 'decompress_phase_two';
5407: $r->print(&decompression_phase_two().
5408: &return_to_editor());
1.329 droeschl 5409: }
5410: }
5411:
1.484 raeburn 5412: if ($allowed && $toolsflag) {
5413: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5414: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5415: $r->print(&endContentScreen());
5416: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5417: # -----------------------------------------------------------------------------
5418: my %lt=&Apache::lonlocal::texthash(
5419: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5420: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5421: 'upld' => 'Upload Content',
1.329 droeschl 5422: 'srch' => 'Search',
5423: 'impo' => 'Import',
1.484.2.19 raeburn 5424: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5425: 'impm' => 'Import from Assembled Map',
1.484.2.72.2. (raeburn 5426:): 'extr' => 'External Resource',
5427:): 'extt' => 'External Tool',
1.329 droeschl 5428: 'selm' => 'Select Map',
5429: 'load' => 'Load Map',
5430: 'newf' => 'New Folder',
5431: 'newp' => 'New Composite Page',
5432: 'syll' => 'Syllabus',
1.425 raeburn 5433: 'navc' => 'Table of Contents',
1.343 biermanm 5434: 'sipa' => 'Simple Course Page',
1.329 droeschl 5435: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5436: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5437: 'drbx' => 'Drop Box',
1.451 www 5438: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5439: 'bull' => 'Discussion Board',
1.347 weissno 5440: 'mypi' => 'My Personal Information Page',
1.353 weissno 5441: 'grpo' => 'Group Portfolio',
1.329 droeschl 5442: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5443: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5444: 'imsf' => 'IMS Upload',
5445: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5446: 'cms' => 'Origin of IMS package',
5447: 'se' => 'Select',
1.484.2.19 raeburn 5448: 'file' => 'File',
1.329 droeschl 5449: 'title' => 'Title',
5450: 'comment' => 'Comment',
1.403 raeburn 5451: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5452: 'bb5' => 'Blackboard 5',
5453: 'bb6' => 'Blackboard 6',
5454: 'angel5' => 'ANGEL 5.5',
5455: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5456: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5457: );
1.329 droeschl 5458: # -----------------------------------------------------------------------------
1.484.2.64 raeburn 5459: # Calculate free quota space for a user or course.
5460: my $quotatype = 'unofficial';
5461: if ($crstype eq 'Community') {
5462: $quotatype = 'community';
5463: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5464: $quotatype = 'official';
5465: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5466: $quotatype = 'textbook';
5467: }
5468: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5469: 'course',$quotatype); # expressed in MB
5470: my $current_disk_usage = 0;
5471: foreach my $subdir ('docs','supplemental') {
5472: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5473: "userfiles/$subdir",1); # expressed in kB
5474: }
5475: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5476: my $usage = $current_disk_usage/1024; # in MB
5477: my $quota = $disk_quota;
5478: my $percent;
5479: if ($disk_quota == 0) {
5480: $percent = 100.0;
5481: } else {
1.484.2.69 raeburn 5482: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5483: }
5484: $usage = sprintf("%.2f",$usage);
5485: $quota = sprintf("%.2f",$quota);
5486: $percent = sprintf("%.0f",$percent);
5487: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5488: $percent.'%',$quota.' MB').'</p>';
5489:
1.329 droeschl 5490: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5491: $quotainfo
1.329 droeschl 5492: $lt{'file'}:<br />
1.484.2.67 raeburn 5493: <input type="file" name="uploaddoc" size="40" $disabled />
1.329 droeschl 5494: FIUP
5495:
5496: my $checkbox=(<<CHBO);
5497: <!-- <label>$lt{'parse'}?
5498: <input type="checkbox" name="parserflag" />
5499: </label> -->
5500: <label>
1.484.2.67 raeburn 5501: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5502: </label>
5503: CHBO
1.484.2.12 raeburn 5504: my $imsfolder = $env{'form.folder'};
5505: if ($imsfolder eq '') {
1.484.2.19 raeburn 5506: $imsfolder = 'default';
1.484.2.12 raeburn 5507: }
5508: my $imspform=(<<IMSFORM);
5509: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5510: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5511: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5512: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5513: <legend>$lt{'imsf'}</legend>
5514: $fileupload
5515: <br />
5516: <p>
1.484.2.19 raeburn 5517: $lt{'cms'}:
1.484.2.67 raeburn 5518: <select name="source" $disabled>
1.484.2.12 raeburn 5519: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5520: <option value="bb5">$lt{'bb5'}</option>
5521: <option value="bb6">$lt{'bb6'}</option>
5522: <option value="angel5">$lt{'angel5'}</option>
5523: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5524: </select>
5525: <input type="hidden" name="folder" value="$imsfolder" />
5526: </p>
5527: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5528: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5529: </fieldset>
5530: </form>
5531: IMSFORM
5532:
1.484.2.19 raeburn 5533: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5534: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5535: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5536: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5537: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5538: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5539: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5540: $fileupload
5541: <br />
5542: $lt{'title'}:<br />
1.484.2.67 raeburn 5543: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5544: $pathitem
1.329 droeschl 5545: <input type="hidden" name="cmd" value="upload_default" />
5546: <br />
1.458 raeburn 5547: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5548: $checkbox
5549: </span>
1.484.2.12 raeburn 5550: <br clear="all" />
1.484.2.67 raeburn 5551: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5552: </fieldset>
5553: </form>
1.383 tempelho 5554: FUFORM
1.329 droeschl 5555:
1.484.2.67 raeburn 5556: my $mapimportjs;
5557: if ($canedit) {
5558: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5559: } else {
5560: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5561: }
1.484.2.19 raeburn 5562: my $importpubform=(<<SEDFFORM);
5563: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5564: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5565: <form action="/adm/coursedocs" method="post" name="mapimportform">
5566: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5567: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5568: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5569: $lt{'copm'}<br />
5570: <span class="LC_nobreak">
1.484.2.19 raeburn 5571: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5572: onfocus="this.blur();$mapimportjs" $disabled />
5573: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5574: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5575: </fieldset>
5576: </form>
5577:
1.383 tempelho 5578: SEDFFORM
1.484.2.67 raeburn 5579:
5580: my $fromstoredjs;
5581: if ($canedit) {
5582: $fromstoredjs = 'open_StoredLinks_Import()';
5583: } else {
5584: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5585: }
5586:
1.484.2.19 raeburn 5587: my @importpubforma = (
5588: { '<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 5589: { '<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 5590: { '<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 5591: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5592: );
5593: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5594: my $extresourcesform =
5595: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5596: $help{'Adding_External_Resource'},
5597: undef,undef,$disabled);
1.484.2.72.2. (raeburn 5598:): my $exttoolform =
5599:): &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5600:): $help{'Adding_External_Tool'},undef,
5601:): undef,'tool',$coursedom,$coursenum,
5602:): \%ltitools,$disabled);
1.329 droeschl 5603: if ($allowed) {
1.484.2.7 raeburn 5604: my $folder = $env{'form.folder'};
5605: if ($folder eq '') {
5606: $folder='default';
5607: }
1.484.2.67 raeburn 5608: if ($canedit) {
5609: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5610: if ($output) {
5611: $r->print($output);
5612: }
1.484.2.30 raeburn 5613: }
1.337 ehlerst 5614: $r->print(<<HIDDENFORM);
5615: <form name="renameform" method="post" action="/adm/coursedocs">
5616: <input type="hidden" name="title" />
5617: <input type="hidden" name="cmd" />
5618: <input type="hidden" name="markcopy" />
5619: <input type="hidden" name="copyfolder" />
5620: $containertag
5621: </form>
1.484 raeburn 5622:
1.337 ehlerst 5623: HIDDENFORM
1.484.2.17 raeburn 5624: $r->print(&makesimpleeditform($pathitem)."\n".
5625: &makedocslogform($pathitem."\n".
1.484 raeburn 5626: '<input type="hidden" name="folder" value="'.
5627: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5628: }
1.442 www 5629:
5630: # Generate the tabs
1.484.2.19 raeburn 5631: my ($mode,$needs_end);
1.472 raeburn 5632: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5633: my @folders = split('&',$env{'form.folderpath'});
5634: unless (@folders > 2) {
5635: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5636: $needs_end = 1;
5637: }
1.472 raeburn 5638: } else {
1.484 raeburn 5639: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5640: $needs_end = 1;
1.472 raeburn 5641: }
1.443 www 5642:
1.442 www 5643: #
5644:
5645: my $savefolderpath;
5646:
1.395 raeburn 5647: if ($allowed) {
1.329 droeschl 5648: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5649: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5650: $folder='default';
1.356 tempelho 5651: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5652: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5653: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5654: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5655: }
5656: my $postexec='';
5657: if ($folder eq 'default') {
1.372 bisitz 5658: $r->print('<script type="text/javascript">'."\n"
5659: .'// <![CDATA['."\n"
5660: .'this.window.name="loncapaclient";'."\n"
5661: .'// ]]>'."\n"
5662: .'</script>'."\n"
1.369 bisitz 5663: );
1.329 droeschl 5664: } else {
5665: #$postexec='self.close();';
5666: }
1.484.2.15 raeburn 5667: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5668: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5669: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5670:
5671: my $newnavform=(<<NNFORM);
5672: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5673: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5674: $pathitem
1.329 droeschl 5675: <input type="hidden" name="importdetail"
5676: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5677: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5678: $help{'Navigate_Content'}
5679: </form>
5680: NNFORM
5681: my $newsmppageform=(<<NSPFORM);
5682: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5683: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5684: $pathitem
1.329 droeschl 5685: <input type="hidden" name="importdetail" value="" />
1.423 onken 5686: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5687: $help{'Simple Page'}
1.329 droeschl 5688: </form>
5689: NSPFORM
5690:
5691: my $newsmpproblemform=(<<NSPROBFORM);
5692: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5693: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5694: $pathitem
1.329 droeschl 5695: <input type="hidden" name="importdetail" value="" />
1.423 onken 5696: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5697: $help{'Simple_Problem'}
1.329 droeschl 5698: </form>
5699:
5700: NSPROBFORM
5701:
5702: my $newdropboxform=(<<NDBFORM);
5703: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5704: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5705: $pathitem
1.329 droeschl 5706: <input type="hidden" name="importdetail" value="" />
1.423 onken 5707: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5708: $help{'Dropbox'}
1.344 bisitz 5709: </form>
1.329 droeschl 5710: NDBFORM
5711:
5712: my $newexuploadform=(<<NEXUFORM);
5713: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5714: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5715: $pathitem
1.329 droeschl 5716: <input type="hidden" name="importdetail" value="" />
1.423 onken 5717: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5718: $help{'Score_Upload_Form'}
5719: </form>
5720: NEXUFORM
5721:
5722: my $newbulform=(<<NBFORM);
5723: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5724: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5725: $pathitem
1.329 droeschl 5726: <input type="hidden" name="importdetail" value="" />
1.423 onken 5727: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5728: $help{'Bulletin Board'}
5729: </form>
5730: NBFORM
5731:
5732: my $newaboutmeform=(<<NAMFORM);
5733: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5734: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5735: $pathitem
1.329 droeschl 5736: <input type="hidden" name="importdetail"
5737: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5738: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5739: $help{'My Personal Information Page'}
1.329 droeschl 5740: </form>
5741: NAMFORM
5742:
5743: my $newaboutsomeoneform=(<<NASOFORM);
5744: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5745: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5746: $pathitem
1.329 droeschl 5747: <input type="hidden" name="importdetail" value="" />
1.423 onken 5748: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5749: </form>
5750: NASOFORM
5751:
5752: my $newrosterform=(<<NROSTFORM);
5753: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5754: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5755: $pathitem
1.329 droeschl 5756: <input type="hidden" name="importdetail"
5757: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5758: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5759: $help{'Course_Roster'}
1.329 droeschl 5760: </form>
5761: NROSTFORM
5762:
1.484.2.27 raeburn 5763: my $newwebpage;
5764: if ($folder =~ /^default_?(\d*)$/) {
5765: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5766: if ($1) {
5767: $newwebpage .= $1;
5768: } else {
5769: $newwebpage .= 'default';
5770: }
5771: $newwebpage .= '/new.html';
5772: }
5773: my $newwebpageform =(<<NWEBFORM);
5774: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5775: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5776: $pathitem
5777: <input type="hidden" name="importdetail" value="$newwebpage" />
5778: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5779: $help{'Web_Page'}
1.484.2.27 raeburn 5780: </form>
5781: NWEBFORM
1.484.2.30 raeburn 5782:
1.484.2.27 raeburn 5783:
1.342 ehlerst 5784: my $specialdocumentsform;
1.383 tempelho 5785: my @specialdocumentsforma;
1.451 www 5786: my $gradingform;
5787: my @gradingforma;
5788: my $communityform;
5789: my @communityforma;
1.351 ehlerst 5790: my $newfolderform;
1.390 tempelho 5791: my $newfolderb;
1.342 ehlerst 5792:
1.451 www 5793: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5794:
1.329 droeschl 5795: my $newpageform=(<<NPFORM);
5796: <form action="/adm/coursedocs" method="post" name="newpage">
5797: <input type="hidden" name="folderpath" value="$path" />
5798: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5799: <input type="hidden" name="active" value="ee" />
1.423 onken 5800: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5801: $help{'Adding_Pages'}
1.329 droeschl 5802: </form>
5803: NPFORM
1.390 tempelho 5804:
5805:
1.351 ehlerst 5806: $newfolderform=(<<NFFORM);
1.329 droeschl 5807: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5808: $pathitem
1.329 droeschl 5809: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5810: <input type="hidden" name="active" value="" />
1.422 onken 5811: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5812: </form>
5813: NFFORM
5814:
5815: my $newsylform=(<<NSYLFORM);
5816: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5817: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5818: $pathitem
1.329 droeschl 5819: <input type="hidden" name="importdetail"
5820: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5821: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5822: $help{'Syllabus'}
1.383 tempelho 5823:
1.329 droeschl 5824: </form>
5825: NSYLFORM
1.364 bisitz 5826:
1.329 droeschl 5827: my $newgroupfileform=(<<NGFFORM);
5828: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5829: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5830: $pathitem
1.329 droeschl 5831: <input type="hidden" name="importdetail"
5832: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5833: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5834: $help{'Group Portfolio'}
1.329 droeschl 5835: </form>
5836: NGFFORM
1.383 tempelho 5837: @specialdocumentsforma=(
1.421 onken 5838: {'<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 5839: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5840: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5841: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5842: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5843: );
5844: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5845:
1.434 raeburn 5846:
5847: my @importdoc = (
1.484.2.19 raeburn 5848: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5849: );
1.484.2.72.2. (raeburn 5850:): if (keys(%ltitools)) {
5851:): push(@importdoc,
5852:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
5853:): );
5854:): }
1.484.2.19 raeburn 5855: unless ($container eq 'page') {
5856: push(@importdoc,
5857: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5858: );
5859: }
5860: push(@importdoc,
1.484.2.38 raeburn 5861: {'<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 5862: );
1.484.2.12 raeburn 5863: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5864:
1.451 www 5865: @gradingforma=(
5866: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5867: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5868: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5869:
5870: );
5871: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5872:
5873: @communityforma=(
5874: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5875: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5876: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5877: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5878: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5879: );
5880: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5881:
1.330 tempelho 5882: my %orderhash = (
1.484.2.36 raeburn 5883: 'aa' => ['Upload',$fileuploadform],
5884: 'bb' => ['Import',$importpubform],
5885: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5886: );
1.484.2.19 raeburn 5887: unless ($container eq 'page') {
1.434 raeburn 5888: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5889: $orderhash{'dd'} = ['Collaboration',$communityform];
1.484.2.36 raeburn 5890: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5891: }
5892:
1.341 ehlerst 5893: $hadchanges=0;
1.484 raeburn 5894: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5895: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5896: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.72.2. (raeburn 5897:): \%ltitools,$canedit,\$navmap,$hiddentop);
1.484.2.67 raeburn 5898: undef($navmap);
1.443 www 5899: if ($error) {
5900: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5901: }
5902: if ($hadchanges) {
1.484.2.72.2. (raeburn 5903:): unless (&is_hash_old()) {
5904:): &mark_hash_old();
5905:): }
1.443 www 5906: }
5907: &changewarning($r,'');
5908: }
1.458 raeburn 5909: }
1.442 www 5910:
1.443 www 5911: # Supplemental documents start here
5912:
1.329 droeschl 5913: my $folder=$env{'form.folder'};
1.443 www 5914: unless ($supplementalflag) {
1.329 droeschl 5915: $folder='supplemental';
5916: }
5917: if ($folder =~ /^supplemental$/ &&
5918: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5919: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5920: } elsif ($allowed) {
1.356 tempelho 5921: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5922: }
1.484.2.17 raeburn 5923: $pathitem = '<input type="hidden" name="folderpath" value="'.
5924: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5925: if ($allowed) {
5926: my $folderseq=
1.484.2.15 raeburn 5927: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5928:
5929: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 5930: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5931: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5932: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 5933: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 5934: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5935: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5936: $fileupload
5937: <br />
5938: <br />
5939: <span class="LC_nobreak">
5940: $checkbox
5941: </span>
5942: <br /><br />
5943: $lt{'comment'}:<br />
1.383 tempelho 5944: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5945: <br />
1.484.2.19 raeburn 5946: $pathitem
1.329 droeschl 5947: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 5948: <input type='submit' value="$lt{'upld'}" />
5949: </form>
1.484.2.19 raeburn 5950: SUPDOCFORM
1.329 droeschl 5951:
5952: my $supnewfolderform=(<<SNFFORM);
5953: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 5954: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 5955: $pathitem
1.329 droeschl 5956: <input type="hidden" name="importdetail" value="" />
1.423 onken 5957: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 5958: $help{'Adding_Folders'}
1.329 droeschl 5959: </form>
5960: SNFFORM
1.383 tempelho 5961:
1.484.2.19 raeburn 5962: my $supextform =
5963: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5964: $help{'Adding_External_Resource'},
5965: undef,undef,$disabled);
1.329 droeschl 5966:
1.484.2.72.2. (raeburn 5967:): my $supexttoolform =
5968:): &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
5969:): $help{'Adding_External_Tool'},
5970:): undef,undef,'tool',$coursedom,
5971:): $coursenum,\%ltitools,$disabled);
1.329 droeschl 5972: my $supnewsylform=(<<SNSFORM);
5973: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 5974: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5975: $pathitem
1.329 droeschl 5976: <input type="hidden" name="importdetail"
5977: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5978: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 5979: $help{'Syllabus'}
5980: </form>
5981: SNSFORM
5982:
5983: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 5984: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 5985: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5986: $pathitem
1.329 droeschl 5987: <input type="hidden" name="importdetail"
5988: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5989: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 5990: $help{'My Personal Information Page'}
1.329 droeschl 5991: </form>
5992: SNAMFORM
5993:
1.484.2.27 raeburn 5994: my $supwebpage;
5995: if ($folder =~ /^supplemental_?(\d*)$/) {
5996: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5997: if ($1) {
5998: $supwebpage .= $1;
5999: } else {
6000: $supwebpage .= 'default';
6001: }
6002: $supwebpage .= '/new.html';
6003: }
6004: my $supwebpageform =(<<SWEBFORM);
6005: <form action="/adm/coursedocs" method="post" name="supwebpage">
6006: <input type="hidden" name="active" value="cc" />
6007: $pathitem
6008: <input type="hidden" name="importdetail" value="$supwebpage" />
6009: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6010: $help{'Web_Page'}
1.484.2.27 raeburn 6011: </form>
6012: SWEBFORM
6013:
1.333 muellerd 6014:
1.383 tempelho 6015: my @specialdocs = (
1.484.2.67 raeburn 6016: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6017: =>$supnewsylform},
1.484.2.67 raeburn 6018: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6019: =>$supnewaboutmeform},
1.484.2.27 raeburn 6020: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6021:
1.383 tempelho 6022: );
1.417 droeschl 6023: my @supimportdoc = (
1.484.2.19 raeburn 6024: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.72.2. (raeburn 6025:): =>$supextform});
6026:): if (keys(%ltitools)) {
6027:): push(@supimportdoc,
6028:): {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6029:): =>$supexttoolform});
6030:): }
6031:): push(@supimportdoc,
1.484.2.12 raeburn 6032: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6033: =>$supupdocform},
1.484.2.72.2. (raeburn 6034:): );
1.484.2.19 raeburn 6035:
1.484.2.12 raeburn 6036: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6037: my %suporderhash = (
1.390 tempelho 6038: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6039: 'ee' => ['Upload',$supupdocform],
6040: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6041: );
1.443 www 6042: if ($supplementalflag) {
1.458 raeburn 6043: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6044: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.72.2. (raeburn 6045:): \%ltitools,$canedit);
1.443 www 6046: if ($error) {
6047: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6048: } else {
6049: if ($suppchanges) {
6050: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6051: my @ids=&Apache::lonnet::current_machine_ids();
6052: foreach my $server (keys(%servers)) {
6053: next if (grep(/^\Q$server\E$/,@ids));
6054: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6055: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6056: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6057: }
6058: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6059: undef($suppchanges);
6060: }
1.443 www 6061: }
1.393 raeburn 6062: }
1.443 www 6063: } elsif ($supplementalflag) {
1.458 raeburn 6064: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 6065: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 6066: if ($error) {
6067: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6068: }
1.393 raeburn 6069: }
1.389 tempelho 6070:
1.484.2.19 raeburn 6071: if ($needs_end) {
6072: $r->print(&endContentScreen());
6073: }
1.383 tempelho 6074:
1.329 droeschl 6075: if ($allowed) {
6076: $r->print('
6077: <form method="post" name="extimport" action="/adm/coursedocs">
6078: <input type="hidden" name="title" />
6079: <input type="hidden" name="url" />
6080: <input type="hidden" name="useform" />
6081: <input type="hidden" name="residx" />
6082: </form>');
6083: }
1.484 raeburn 6084: } elsif ($showdoc) {
1.329 droeschl 6085: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6086: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6087: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6088: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6089: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6090: }
6091: }
6092: $r->print(&Apache::loncommon::end_page());
6093: return OK;
1.364 bisitz 6094: }
1.329 droeschl 6095:
1.440 raeburn 6096: sub embedded_form_elems {
6097: my ($phase,$primaryurl,$newidx) = @_;
6098: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.72.2. (raeburn 6099:): $newidx =~s /\D+//g;
1.440 raeburn 6100: return <<STATE;
6101: <input type="hidden" name="folderpath" value="$folderpath" />
6102: <input type="hidden" name="cmd" value="upload_embedded" />
6103: <input type="hidden" name="newidx" value="$newidx" />
6104: <input type="hidden" name="phase" value="$phase" />
6105: <input type="hidden" name="primaryurl" value="$primaryurl" />
6106: STATE
6107: }
6108:
6109: sub embedded_destination {
6110: my $folder=$env{'form.folder'};
6111: my $destination = 'docs/';
6112: if ($folder =~ /^supplemental/) {
6113: $destination = 'supplemental/';
6114: }
6115: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6116: $destination .= 'default/';
6117: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6118: $destination .= $2.'/';
6119: }
1.484.2.72.2. (raeburn 6120:): my $newidx = $env{'form.newidx'};
6121:): $newidx =~s /\D+//g;
6122:): if ($newidx) {
6123:): $destination .= $newidx;
6124:): }
1.440 raeburn 6125: my $dir_root = '/userfiles';
6126: return ($destination,$dir_root);
6127: }
6128:
6129: sub return_to_editor {
6130: my $actionurl = '/adm/coursedocs';
6131: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6132: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6133: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6134: '</a></p>';
6135: }
6136:
1.476 raeburn 6137: sub decompression_info {
6138: my ($destination,$dir_root) = &embedded_destination();
6139: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6140: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6141: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6142: my $container='sequence';
1.480 raeburn 6143: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6144: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6145: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6146: $container='page';
6147: }
1.480 raeburn 6148: unshift(@hiddens,$pathitem);
6149: foreach my $item (@hiddens) {
1.484.2.72.2. (raeburn 6150:): if ($item eq 'newidx') {
6151:): next if ($env{'form.'.$item} =~ /\D/);
6152:): }
1.480 raeburn 6153: if ($env{'form.'.$item}) {
6154: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6155: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6156: }
1.477 raeburn 6157: }
1.476 raeburn 6158: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6159: $hiddenelem);
6160: }
6161:
6162: sub decompression_phase_one {
6163: my ($dir,$file,$warning,$error,$output);
6164: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6165: &decompression_info();
1.484.2.7 raeburn 6166: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6167: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6168: } else {
6169: my $file = $1;
1.481 raeburn 6170: $output =
6171: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6172: $destination,$dir_root,
6173: $hiddenelem);
6174: if ($env{'form.autoextract_camtasia'}) {
6175: $output .= &remove_archive($docudom,$docuname,$container);
6176: }
1.476 raeburn 6177: }
6178: if ($error) {
6179: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6180: $error.'</p>'."\n";
6181: }
6182: if ($warning) {
6183: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6184: }
6185: return $output;
6186: }
6187:
6188: sub decompression_phase_two {
6189: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6190: &decompression_info();
1.481 raeburn 6191: my $output;
1.480 raeburn 6192: if ($env{'form.archivedelete'}) {
1.481 raeburn 6193: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6194: }
6195: $output .=
1.481 raeburn 6196: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6197: $destination,$dir_root,$hiddenelem);
6198: return $output;
6199: }
6200:
1.480 raeburn 6201: sub remove_archive {
6202: my ($docudom,$docuname,$container) = @_;
6203: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6204: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6205: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6206: if ($fatal) {
6207: if ($container eq 'page') {
6208: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6209: } else {
6210: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6211: }
1.484.2.54 raeburn 6212: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6213: } else {
6214: my $currcmd = $env{'form.cmd'};
6215: my $position = $env{'form.position'};
1.484.2.54 raeburn 6216: my $archiveidx = $position;
6217: if ($position > 0) {
6218: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6219: $archiveidx = $position-1;
6220: }
6221: $env{'form.cmd'} = 'remove_'.$archiveidx;
6222: my ($title,$url,@rrest) =
6223: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6224: if ($url eq $env{'form.archiveurl'}) {
6225: if (&handle_edit_cmd($docuname,$docudom)) {
6226: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6227: if ($fatal) {
6228: if ($container eq 'page') {
6229: $delwarning = &mt('An error occurred updating the contents of the current page.');
6230: } else {
6231: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6232: }
1.480 raeburn 6233: } else {
1.484.2.54 raeburn 6234: $delresult = &mt('Archive file removed.');
1.480 raeburn 6235: }
6236: }
1.484.2.54 raeburn 6237: } else {
6238: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6239: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6240: }
6241: }
6242: $env{'form.cmd'} = $currcmd;
6243: }
6244: if ($delwarning) {
6245: $output = '<p class="LC_warning">'.
6246: $delwarning.
6247: '</p>';
6248: }
6249: if ($delresult) {
6250: $output .= '<p class="LC_info">'.
6251: $delresult.
6252: '</p>';
6253: }
1.481 raeburn 6254: return $output;
1.480 raeburn 6255: }
6256:
1.484 raeburn 6257: sub generate_admin_menu {
1.484.2.67 raeburn 6258: my ($crstype,$canedit) = @_;
1.484 raeburn 6259: my $lc_crstype = lc($crstype);
6260: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6261: my %lt= ( # do not translate here
1.484 raeburn 6262: 'vc' => 'Verify Content',
6263: 'cv' => 'Check/Set Resource Versions',
6264: 'ls' => 'List Resource Identifiers',
6265: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6266: 'dcd' => "Copy $crstype Content to Authoring Space",
6267: );
1.484 raeburn 6268: my ($candump,$dumpurl);
6269: if ($home + $other > 0) {
6270: $candump = 'F';
6271: if ($home) {
6272: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6273: } else {
6274: my @hosts;
6275: foreach my $aurole (keys(%outhash)) {
6276: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6277: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6278: }
1.484 raeburn 6279: }
6280: if (@hosts == 1) {
6281: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6282: '&role='.
6283: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6284: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6285: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6286: } else {
6287: $dumpurl = "javascript:choose_switchserver_window()";
6288: }
6289: }
6290: }
6291: my @menu=
6292: ({ categorytitle=>'Administration',
6293: items =>[
6294: { linktext => $lt{'vc'},
6295: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6296: permission => 'F',
1.484.2.44 raeburn 6297: help => 'Docs_Verify_Content',
1.484 raeburn 6298: icon => 'verify.png',
6299: linktitle => 'Verify contents can be retrieved/rendered',
6300: },
6301: { linktext => $lt{'cv'},
6302: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6303: permission => 'F',
1.484.2.44 raeburn 6304: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6305: icon => 'resversion.png',
6306: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6307: },
6308: { linktext => $lt{'ls'},
6309: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6310: permission => 'F',
6311: #help => '',
6312: icon => 'symbs.png',
6313: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6314: },
6315: ]
1.484.2.67 raeburn 6316: });
6317: if ($canedit) {
6318: push(@menu,
1.484 raeburn 6319: { categorytitle=>'Export',
6320: items =>[
6321: { linktext => $lt{'imse'},
6322: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6323: permission => 'F',
6324: help => 'Docs_Export_Course_Docs',
6325: icon => 'imsexport.png',
6326: linktitle => $lt{'imse'},
6327: },
6328: { linktext => $lt{'dcd'},
6329: url => $dumpurl,
6330: permission => $candump,
1.484.2.44 raeburn 6331: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6332: icon => 'dump.png',
6333: linktitle => $lt{'dcd'},
6334: },
6335: ]
6336: });
1.484.2.67 raeburn 6337: }
1.484 raeburn 6338: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6339: '<input type="hidden" id="dummy" />'."\n".
6340: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6341: '</form>';
1.329 droeschl 6342: }
6343:
6344: sub generate_edit_table {
1.484.2.30 raeburn 6345: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6346: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6347: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6348: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6349: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6350: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6351: $activetab = $env{'form.active'};
6352: }
1.484.2.67 raeburn 6353: unless ($canedit) {
6354: $disabled = ' disabled="disabled"';
6355: }
1.472 raeburn 6356: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6357: my $backtext = &mt('Exit Editor');
1.458 raeburn 6358: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6359: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6360: '<li class="goback">'.
1.484.2.32 raeburn 6361: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6362: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6363: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6364: '<li>'.
6365: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6366: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6367: if ($env{'form.docslog'}) {
6368: $form .= '<li class="active">';
6369: } else {
6370: $form .= '<li>';
6371: }
6372: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6373: &mt('History').'</a></li>'."\n";
6374: if ($env{'form.docslog'}) {
6375: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6376: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6377: }
1.458 raeburn 6378: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6379: if($name ne '00'){
1.371 tempelho 6380: if($activetab eq '' || $activetab ne $name){
6381: $active = '';
6382: }elsif($activetab eq $name){
6383: $active = 'class="active"';
6384: }
1.458 raeburn 6385: $form .= '<li style="float:right" '.$active
1.484 raeburn 6386: .' 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 6387: } else {
1.484.2.43 raeburn 6388: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6389:
6390: }
1.329 droeschl 6391: }
1.484 raeburn 6392: $form .= '</ul>'."\n";
6393: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6394:
6395: if ($to_show ne '') {
1.484.2.30 raeburn 6396: my $saveform;
6397: if ($need_save) {
6398: my $button = &mt('Make changes');
6399: my $path;
6400: if ($env{'form.folderpath'}) {
6401: $path =
6402: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6403: }
6404: $saveform = <<"END";
6405: <div id="multisave" style="display:none; clear:both;" >
6406: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6407: <input type="hidden" name="folderpath" value="$path" />
6408: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6409: <input type="hidden" name="allhiddenresource" value="" />
6410: <input type="hidden" name="allencrypturl" value="" />
6411: <input type="hidden" name="allrandompick" value="" />
6412: <input type="hidden" name="allrandomorder" value="" />
6413: <input type="hidden" name="changeparms" value="" />
6414: <input type="hidden" name="multiremove" value="" />
6415: <input type="hidden" name="multicut" value="" />
6416: <input type="hidden" name="multicopy" value="" />
6417: <input type="hidden" name="multichange" value="" />
6418: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6419: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6420: </form>
6421: </div>
6422: END
6423: }
6424: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6425: }
1.363 ehlerst 6426: foreach my $field (keys(%orderhash)){
1.390 tempelho 6427: if($field ne '00'){
1.422 onken 6428: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6429: $active = 'style="display: none;float:left"';
1.422 onken 6430: }elsif($activetab eq $field){
1.458 raeburn 6431: $active = 'style="display:block;float:left"';
1.422 onken 6432: }
6433: $form .= '<div id="'.$field.$tid.'"'
6434: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6435: .'</div>'."\n";
1.363 ehlerst 6436: }
6437: }
1.484 raeburn 6438: unless ($env{'form.docslog'}) {
6439: $form .= '</div></div>'."\n";
6440: }
1.329 droeschl 6441: return $form;
6442: }
6443:
6444: sub editing_js {
1.484.2.72.2. (raeburn 6445:): my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$canedit,$navmapref) = @_;
1.484.2.61 raeburn 6446: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6447: p_mnf => 'Name of New Folder',
6448: t_mnf => 'New Folder',
6449: p_mnp => 'Name of New Page',
6450: t_mnp => 'New Page',
1.451 www 6451: p_mxu => 'Title for the External Score',
1.349 biermanm 6452: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6453: p_msb => 'Title for the Problem',
6454: p_mdb => 'Title for the Drop Box',
1.336 schafran 6455: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6456: p_mwp => 'Title for Web Page',
1.348 weissno 6457: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6458: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6459: p_mab_alrt1 => 'Not a valid user:domain',
6460: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6461: p_chn => 'New Title',
6462: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6463: p_rmr2a => 'Remove',
6464: p_rmr2b => '?',
6465: p_rmr3a => 'Remove those',
6466: p_rmr3b => 'items?',
6467: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6468: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6469: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6470: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6471: p_ctr2a => 'Cut',
6472: p_ctr2b => '?',
6473: p_ctr3a => 'Cut those',
6474: p_ctr3b => 'items?',
1.478 raeburn 6475: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6476: imsfile => 'You must choose an IMS package for import',
6477: imscms => 'You must select which Course Management System was the source of the IMS package',
6478: invurl => 'Invalid URL',
6479: titbl => 'Title is blank',
1.484.2.30 raeburn 6480: more => '(More ...)',
6481: less => '(Less ...)',
6482: noor => 'No actions selected or changes to settings specified.',
6483: noch => 'No changes to settings specified.',
6484: noac => 'No actions selected.',
1.484.2.67 raeburn 6485: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6486: );
6487:
1.484.2.61 raeburn 6488: &js_escape(\%js_lt);
1.433 raeburn 6489: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6490: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6491: my $main_container_page;
1.484.2.19 raeburn 6492: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6493: $main_container_page = 1;
1.434 raeburn 6494: }
1.484.2.67 raeburn 6495: my $backtourl;
6496: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6497: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6498:
1.484.2.21 raeburn 6499: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6500: my $caller = $1;
6501: if ($caller =~ /^supplemental/) {
6502: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6503: } else {
6504: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6505: $res = &Apache::lonnet::clutter($res);
6506: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6507: my ($url,$anchor);
6508: if ($res =~ /^([^#]+)#([^#]+)$/) {
6509: $url = $1;
6510: $anchor = $2;
6511: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6512: $caller = $1.&escape('#').$anchor;
6513: }
1.484.2.67 raeburn 6514: } else {
6515: $url = $res;
1.484.2.66 raeburn 6516: }
1.484.2.72.2. (raeburn 6517:): $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6518:): if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6519:): $backtourl .= '?navmap=1';
6520:): } else {
6521:): $backtourl .= '?symb='.
6522:): &HTML::Entities::encode($caller,'<>&"');
6523:): }
1.484.2.66 raeburn 6524: if ($anchor ne '') {
6525: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6526: }
1.484.2.57 raeburn 6527: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6528: } else {
6529: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6530: }
6531: }
6532: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6533: $backtourl = '/adm/menu';
6534: } elsif ($supplementalflag) {
1.472 raeburn 6535: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6536: } else {
6537: $backtourl = '/adm/navmaps';
1.472 raeburn 6538: }
6539:
1.484.2.19 raeburn 6540: my $fieldsets = "'ext','doc'";
1.484.2.72.2. (raeburn 6541:): if ($posslti) {
6542:): $fieldsets .= ",'tool'";
6543:): }
1.484.2.19 raeburn 6544: unless ($main_container_page) {
6545: $fieldsets .=",'ims'";
6546: }
1.484.2.12 raeburn 6547: if ($supplementalflag) {
6548: $fieldsets = "'suppext','suppdoc'";
1.484.2.72.2. (raeburn 6549:): if ($posslti) {
6550:): $fieldsets .= ",'supptool'";
6551:): }
1.484.2.12 raeburn 6552: }
6553:
1.484.2.67 raeburn 6554: my $jsmakefunctions;
6555: if ($canedit) {
6556: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6557: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6558: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6559: if (foldername) {
6560: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6561: targetform.submit();
6562: }
6563: }
6564:
6565: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6566: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6567: if (pagename) {
6568: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6569: targetform.submit();
6570: }
6571: }
6572:
6573: function makeexamupload() {
1.484.2.61 raeburn 6574: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6575: if (title) {
1.329 droeschl 6576: this.document.forms.newexamupload.importdetail.value=
6577: escape(title)+'=/res/lib/templates/examupload.problem';
6578: this.document.forms.newexamupload.submit();
6579: }
6580: }
6581:
6582: function makesmppage() {
1.484.2.61 raeburn 6583: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6584: if (title) {
1.329 droeschl 6585: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6586: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6587: this.document.forms.newsmppg.submit();
6588: }
6589: }
6590:
1.484.2.27 raeburn 6591: function makewebpage(type) {
1.484.2.61 raeburn 6592: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6593: var formname;
6594: if (type == 'supp') {
6595: formname = this.document.forms.supwebpage;
6596: } else {
6597: formname = this.document.forms.newwebpage;
6598: }
6599: if (title) {
6600: var webpage = formname.importdetail.value;
6601: formname.importdetail.value = escape(title)+'='+webpage;
6602: formname.submit();
6603: }
6604: }
6605:
1.329 droeschl 6606: function makesmpproblem() {
1.484.2.61 raeburn 6607: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6608: if (title) {
1.329 droeschl 6609: this.document.forms.newsmpproblem.importdetail.value=
6610: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6611: this.document.forms.newsmpproblem.submit();
6612: }
6613: }
6614:
6615: function makedropbox() {
1.484.2.61 raeburn 6616: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6617: if (title) {
1.329 droeschl 6618: this.document.forms.newdropbox.importdetail.value=
6619: escape(title)+'=/res/lib/templates/DropBox.problem';
6620: this.document.forms.newdropbox.submit();
6621: }
6622: }
6623:
6624: function makebulboard() {
1.484.2.61 raeburn 6625: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6626: if (title) {
6627: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6628: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6629: this.document.forms.newbul.submit();
6630: }
6631: }
6632:
6633: function makeabout() {
1.484.2.61 raeburn 6634: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6635: if (user) {
6636: var comp=new Array();
6637: comp=user.split(':');
6638: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6639: if ((comp[0]) && (comp[1])) {
6640: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6641: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6642: this.document.forms.newaboutsomeone.submit();
6643: } else {
6644: alert("$js_lt{'p_mab_alrt1'}");
6645: }
6646: } else {
6647: alert("$js_lt{'p_mab_alrt2'}");
6648: }
6649: }
1.335 ehlerst 6650: }
1.484.2.67 raeburn 6651:
6652: function makenew(targetform) {
6653: targetform.submit();
1.335 ehlerst 6654: }
1.484.2.67 raeburn 6655:
6656: function changename(folderpath,index,oldtitle) {
6657: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6658: if (title) {
6659: this.document.forms.renameform.markcopy.value='';
6660: this.document.forms.renameform.title.value=title;
6661: this.document.forms.renameform.cmd.value='rename_'+index;
6662: this.document.forms.renameform.folderpath.value=folderpath;
6663: this.document.forms.renameform.submit();
6664: }
1.329 droeschl 6665: }
6666:
1.484.2.67 raeburn 6667: ENDNEWSCRIPT
6668: } else {
6669: $jsmakefunctions = <<ENDNEWSCRIPT;
6670:
6671: function makenewfolder() {
6672: alert("$js_lt{'edri'}");
6673: }
6674:
6675: function makenewpage() {
6676: alert("$js_lt{'edri'}");
6677: }
6678:
6679: function makeexamupload() {
6680: alert("$js_lt{'edri'}");
6681: }
6682:
6683: function makesmppage() {
6684: alert("$js_lt{'edri'}");
6685: }
6686:
6687: function makewebpage(type) {
6688: alert("$js_lt{'edri'}");
6689: }
6690:
6691: function makesmpproblem() {
6692: alert("$js_lt{'edri'}");
6693: }
6694:
6695: function makedropbox() {
6696: alert("$js_lt{'edri'}");
6697: }
6698:
6699: function makebulboard() {
6700: alert("$js_lt{'edri'}");
6701: }
6702:
6703: function makeabout() {
6704: alert("$js_lt{'edri'}");
6705: }
6706:
6707: function changename() {
6708: alert("$js_lt{'edri'}");
6709: }
6710:
6711: function makenew() {
6712: alert("$js_lt{'edri'}");
6713: }
6714:
6715: function groupimport() {
6716: alert("$js_lt{'edri'}");
6717: }
6718:
6719: function groupsearch() {
6720: alert("$js_lt{'edri'}");
6721: }
6722:
6723: function groupopen(url,recover) {
6724: var options="scrollbars=1,resizable=1,menubar=0";
6725: idxflag=1;
6726: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6727: idx.focus();
6728: }
6729:
6730: ENDNEWSCRIPT
6731:
6732: }
6733: return <<ENDSCRIPT;
6734:
6735: $jsmakefunctions
6736:
1.484.2.13 raeburn 6737: function toggleUpload(caller) {
6738: var blocks = Array($fieldsets);
6739: for (var i=0; i<blocks.length; i++) {
6740: var disp = 'none';
6741: if (caller == blocks[i]) {
6742: var curr = document.getElementById('upload'+caller+'form').style.display;
6743: if (curr == 'none') {
6744: disp='block';
6745: }
6746: }
6747: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.484.2.72.2. (raeburn 6748:): if ((caller == 'tool') || (caller == 'supptool')) {
6749:): if (disp == 'block') {
6750:): if (document.getElementById('LC_exttoolid')) {
6751:): var toolselector = document.getElementById('LC_exttoolid');
6752:): var suppflag = 0;
6753:): if (caller == 'supptool') {
6754:): suppflag = 1;
6755:): }
6756:): currForm = document.getElementById('new'+caller);
6757:): updateExttool(toolselector,currForm,suppflag);
6758:): }
6759:): }
6760:): }
1.484.2.13 raeburn 6761: }
6762: resize_scrollbox('contentscroll','1','1');
6763: return;
6764: }
6765:
1.484.2.19 raeburn 6766: function toggleMap(caller) {
1.484.2.13 raeburn 6767: var disp = 'none';
1.484.2.19 raeburn 6768: if (document.getElementById('importmapform')) {
6769: if (caller == 'map') {
6770: var curr = document.getElementById('importmapform').style.display;
6771: if (curr == 'none') {
6772: disp='block';
6773: }
1.484.2.12 raeburn 6774: }
1.484.2.19 raeburn 6775: document.getElementById('importmapform').style.display=disp;
6776: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6777: }
1.484.2.19 raeburn 6778: return;
1.329 droeschl 6779: }
6780:
1.484.2.12 raeburn 6781: function makeims(imsform) {
6782: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6783: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6784: return;
6785: }
6786: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6787: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6788: return;
6789: }
6790: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6791: imsform.submit();
6792: }
6793:
1.478 raeburn 6794: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6795: var pickitem;
6796: var picknumitem;
6797: var picknumtext;
6798: if (index == 'all') {
6799: pickitem = document.getElementById('randompickall');
6800: picknumitem = document.getElementById('rpicknumall');
6801: picknumtext = document.getElementById('rpicktextall');
6802: } else {
6803: pickitem = document.getElementById('randompick_'+index);
6804: picknumitem = document.getElementById('rpicknum_'+index);
6805: picknumtext = document.getElementById('randompicknum_'+index);
6806: }
1.478 raeburn 6807: if (pickitem.checked) {
1.484.2.61 raeburn 6808: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6809: if (picknum == '' || picknum == null) {
6810: if (caller == 'check') {
6811: pickitem.checked=false;
1.484.2.29 raeburn 6812: if (index == 'all') {
6813: picknumtext.innerHTML = '';
6814: if (caller == 'link') {
6815: propagateState(targetform,'rpicknum');
6816: }
6817: } else {
1.484.2.30 raeburn 6818: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6819: }
1.478 raeburn 6820: }
6821: } else {
6822: picknum.toString();
6823: var regexdigit=/^\\d+\$/;
6824: if (regexdigit.test(picknum)) {
6825: picknumitem.value = picknum;
1.484.2.29 raeburn 6826: if (index == 'all') {
1.484.2.30 raeburn 6827: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6828: if (caller == 'link') {
6829: propagateState(targetform,'rpicknum');
6830: }
6831: } else {
6832: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6833: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6834: }
1.478 raeburn 6835: } else {
6836: if (caller == 'check') {
1.484.2.29 raeburn 6837: if (index == 'all') {
6838: picknumtext.innerHTML = '';
6839: if (caller == 'link') {
6840: propagateState(targetform,'rpicknum');
6841: }
6842: } else {
6843: pickitem.checked=false;
1.484.2.30 raeburn 6844: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6845: }
1.478 raeburn 6846: }
6847: return;
6848: }
6849: }
6850: } else {
1.484.2.29 raeburn 6851: picknumitem.value = '';
6852: picknumtext.innerHTML = '';
6853: if (index == 'all') {
6854: if (caller == 'link') {
6855: propagateState(targetform,'rpicknum');
6856: }
6857: } else {
1.484.2.30 raeburn 6858: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6859: }
6860: }
6861: }
6862:
6863: function propagateState(form,param) {
6864: if (document.getElementById(param+'all')) {
6865: var setcheck = 0;
6866: var rpick = 0;
6867: if (param == 'rpicknum') {
6868: if (document.getElementById('randompickall')) {
6869: if (document.getElementById('randompickall').checked) {
6870: if (document.getElementById('rpicknumall')) {
6871: rpick = document.getElementById('rpicknumall').value;
6872: }
6873: }
6874: }
6875: } else {
6876: if (document.getElementById(param+'all').checked) {
6877: setcheck = 1;
6878: }
6879: }
1.484.2.30 raeburn 6880: var allidxlist;
6881: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6882: if (document.getElementById('all'+param+'idx')) {
6883: allidxlist = document.getElementById('all'+param+'idx').value;
6884: }
6885: var actions = new Array ('remove','cut','copy');
6886: for (var i=0; i<actions.length; i++) {
6887: if (actions[i] != param) {
6888: if (document.getElementById(actions[i]+'all')) {
6889: document.getElementById(actions[i]+'all').checked = false;
6890: }
6891: }
6892: }
6893: }
1.484.2.29 raeburn 6894: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6895: allidxlist = form.allidx.value;
6896: }
6897: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6898: allidxlist = form.allmapidx.value;
6899: }
6900: if ((allidxlist != '') && (allidxlist != null)) {
6901: var allidxs = allidxlist.split(',');
6902: if (allidxs.length > 1) {
6903: for (var i=0; i<allidxs.length; i++) {
6904: if (document.getElementById(param+'_'+allidxs[i])) {
6905: if (param == 'rpicknum') {
6906: if (document.getElementById('randompick_'+allidxs[i])) {
6907: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6908: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6909: if (rpick > 0) {
6910: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6911: } else {
6912: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6913: }
6914: }
6915: }
6916: } else {
1.484.2.29 raeburn 6917: if (setcheck == 1) {
6918: document.getElementById(param+'_'+allidxs[i]).checked = true;
6919: } else {
6920: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6921: if (param == 'randompick') {
6922: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6923: }
1.484.2.29 raeburn 6924: }
6925: }
6926: }
6927: }
1.484.2.30 raeburn 6928: if (setcheck == 1) {
6929: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6930: var actions = new Array('copy','cut','remove');
6931: for (var i=0; i<actions.length; i++) {
6932: var otheractions;
6933: var otheridxs;
6934: if (actions[i] === param) {
6935: continue;
6936: } else {
6937: if (document.getElementById('all'+actions[i]+'idx')) {
6938: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6939: otheridxs = otheractions.split(',');
6940: if (otheridxs.length > 1) {
6941: for (var j=0; j<otheridxs.length; j++) {
6942: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6943: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6944: }
1.484.2.29 raeburn 6945: }
6946: }
6947: }
6948: }
1.484.2.30 raeburn 6949: }
1.484.2.29 raeburn 6950: }
6951: }
6952: }
6953: }
1.478 raeburn 6954: }
1.484.2.29 raeburn 6955: return;
6956: }
6957:
1.484.2.63 raeburn 6958: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 6959: var canedit = '$canedit';
6960: if (canedit == '') {
6961: alert("$js_lt{'edri'}");
6962: return;
6963: }
1.484.2.30 raeburn 6964: var dosettings;
6965: var doaction;
6966: var control = document.togglemultsettings;
6967: if (context == 'actions') {
6968: control = document.togglemultactions;
6969: doaction = 1;
6970: } else {
6971: dosettings = 1;
6972: }
6973: if (control) {
6974: if (control.showmultpick.length) {
6975: for (var i=0; i<control.showmultpick.length; i++) {
6976: if (control.showmultpick[i].checked) {
6977: if (control.showmultpick[i].value == 1) {
6978: if (context == 'settings') {
6979: dosettings = 0;
6980: } else {
6981: doaction = 0;
6982: }
6983: }
6984: }
6985: }
6986: }
6987: }
6988: if (context == 'settings') {
6989: if (dosettings == 1) {
6990: targetform.changeparms.value=param;
6991: targetform.submit();
6992: }
6993: }
6994: if (context == 'actions') {
6995: if (doaction == 1) {
6996: targetform.cmd.value=param+'_'+index;
6997: targetform.folderpath.value=folderpath;
6998: targetform.markcopy.value=idx+':'+param;
6999: targetform.copyfolder.value=folder+'.'+container;
7000: if (param == 'remove') {
1.484.2.63 raeburn 7001: var doremove = 0;
7002: if (skip_confirm) {
7003: if (confirm_removal) {
7004: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7005: doremove = 1;
7006: }
7007: } else {
7008: doremove = 1;
7009: }
7010: } else {
7011: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7012: doremove = 1;
7013: }
7014: }
7015: if (doremove) {
1.484.2.30 raeburn 7016: targetform.markcopy.value='';
7017: targetform.copyfolder.value='';
1.484.2.29 raeburn 7018: targetform.submit();
7019: }
7020: }
1.484.2.30 raeburn 7021: if (param == 'cut') {
1.484.2.61 raeburn 7022: 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 7023: targetform.submit();
7024: return;
7025: }
7026: }
7027: if (param == 'copy') {
7028: targetform.submit();
7029: return;
7030: }
7031: targetform.markcopy.value='';
7032: targetform.copyfolder.value='';
7033: targetform.cmd.value='';
7034: targetform.folderpath.value='';
7035: return;
7036: } else {
7037: if (document.getElementById(param+'_'+idx)) {
7038: item = document.getElementById(param+'_'+idx);
7039: if (item.type == 'checkbox') {
7040: if (item.checked) {
7041: item.checked = false;
7042: } else {
7043: item.checked = true;
7044: singleCheck(item,idx,param);
7045: }
7046: }
7047: }
7048: }
7049: }
7050: return;
7051: }
7052:
7053: function singleCheck(caller,idx,action) {
7054: actions = new Array('cut','copy','remove');
7055: if (caller.checked) {
7056: for (var i=0; i<actions.length; i++) {
7057: if (actions[i] != action) {
7058: if (document.getElementById(actions[i]+'_'+idx)) {
7059: if (document.getElementById(actions[i]+'_'+idx).checked) {
7060: document.getElementById(actions[i]+'_'+idx).checked = false;
7061: }
7062: }
7063: }
1.484.2.29 raeburn 7064: }
7065: }
7066: return;
1.478 raeburn 7067: }
7068:
1.334 muellerd 7069: function unselectInactive(nav) {
1.335 ehlerst 7070: currentNav = document.getElementById(nav);
7071: currentLis = currentNav.getElementsByTagName('LI');
7072: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7073: if (currentLis[i].className == 'goback') {
7074: currentLis[i].className = 'goback';
7075: } else {
7076: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7077: currentLis[i].className = 'right';
1.472 raeburn 7078: } else {
1.374 tempelho 7079: currentLis[i].className = 'i';
1.472 raeburn 7080: }
7081: }
1.335 ehlerst 7082: }
1.332 tempelho 7083: }
7084:
1.334 muellerd 7085: function hideAll(current, nav, data) {
1.335 ehlerst 7086: unselectInactive(nav);
1.484.2.43 raeburn 7087: if (current) {
7088: if (current.className == 'right'){
1.374 tempelho 7089: current.className = 'right active'
1.484.2.43 raeburn 7090: } else {
1.374 tempelho 7091: current.className = 'active';
1.484.2.43 raeburn 7092: }
1.374 tempelho 7093: }
1.335 ehlerst 7094: currentData = document.getElementById(data);
7095: currentDivs = currentData.getElementsByTagName('DIV');
7096: for (i = 0; i < currentDivs.length; i++) {
7097: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7098: currentDivs[i].style.display = 'none';
1.330 tempelho 7099: }
7100: }
1.335 ehlerst 7101: }
1.330 tempelho 7102:
1.374 tempelho 7103: function openTabs(pageId) {
7104: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7105: if(tabnav.length > 2 ){
1.389 tempelho 7106: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7107: currentLis = currentNav.getElementsByTagName('LI');
7108: for(i = 0; i< currentLis.length; i++){
7109: if(currentLis[i].className == 'active') {
1.375 tempelho 7110: funcString = currentLis[i].onclick.toString();
7111: tab = funcString.split('"');
1.420 onken 7112: if(tab.length < 2) {
7113: tab = funcString.split("'");
7114: }
1.375 tempelho 7115: currentData = document.getElementById(tab[1]);
7116: currentData.style.display = 'block';
1.374 tempelho 7117: }
7118: }
7119: }
7120: }
7121:
1.334 muellerd 7122: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7123: currstate = current.className;
1.334 muellerd 7124: hideAll(current, nav, data);
1.375 tempelho 7125: openTabs(pageId);
1.334 muellerd 7126: unselectInactive(nav);
1.484.2.43 raeburn 7127: if ((currstate == 'active') || (currstate == 'right active')) {
7128: if (currstate == 'active') {
7129: current.className = '';
7130: } else {
7131: current.className = 'right';
7132: }
7133: activeTab = '';
7134: toggleUpload();
7135: toggleMap();
7136: resize_scrollbox('contentscroll','1','0');
7137: return;
7138: } else {
7139: current.className = 'active';
7140: }
1.330 tempelho 7141: currentData = document.getElementById(pageId);
7142: currentData.style.display = 'block';
1.458 raeburn 7143: activeTab = pageId;
1.484.2.12 raeburn 7144: toggleUpload();
1.484.2.14 raeburn 7145: toggleMap();
1.433 raeburn 7146: if (nav == 'mainnav') {
7147: var storedpath = "$docs_folderpath";
1.434 raeburn 7148: var storedpage = "$main_container_page";
1.433 raeburn 7149: var reg = new RegExp("^supplemental");
7150: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7151: if (storedpage == 1) {
7152: document.simpleedit.folderpath.value = '';
7153: document.uploaddocument.folderpath.value = '';
7154: } else {
7155: if (reg.test(storedpath)) {
7156: document.simpleedit.folderpath.value = '$toplevelmain';
7157: document.uploaddocument.folderpath.value = '$toplevelmain';
7158: document.newext.folderpath.value = '$toplevelmain';
7159: } else {
7160: document.simpleedit.folderpath.value = storedpath;
7161: document.uploaddocument.folderpath.value = storedpath;
7162: document.newext.folderpath.value = storedpath;
7163: }
1.433 raeburn 7164: }
7165: } else {
1.434 raeburn 7166: if (reg.test(storedpath)) {
7167: document.simpleedit.folderpath.value = storedpath;
7168: document.supuploaddocument.folderpath.value = storedpath;
7169: document.supnewext.folderpath.value = storedpath;
7170: } else {
1.433 raeburn 7171: document.simpleedit.folderpath.value = '$toplevelsupp';
7172: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7173: document.supnewext.folderpath.value = '$toplevelsupp';
7174: }
7175: }
7176: }
1.484.2.3 raeburn 7177: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7178: return false;
7179: }
1.329 droeschl 7180:
1.472 raeburn 7181: function toContents(jumpto) {
7182: var newurl = '$backtourl';
1.484.2.21 raeburn 7183: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7184: newurl = newurl+'?postdata='+jumpto;
7185: }
7186: location.href=newurl;
7187: }
7188:
1.484.2.30 raeburn 7189: function togglePick(caller,value) {
7190: var disp = 'none';
7191: if (document.getElementById('multi'+caller)) {
7192: var curr = document.getElementById('multi'+caller).style.display;
7193: if (value == 1) {
7194: disp='block';
7195: }
7196: if (curr == disp) {
7197: return;
7198: }
7199: document.getElementById('multi'+caller).style.display=disp;
7200: if (value == 1) {
1.484.2.61 raeburn 7201: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7202: } else {
7203: document.getElementById('more'+caller).innerHTML = '';
7204: }
7205: if (caller == 'actions') {
7206: setClass(value);
7207: setBoxes(value);
7208: }
7209: }
7210: var showButton = multiSettings();
7211: if (showButton != 1) {
7212: showButton = multiActions();
7213: }
7214: if (document.getElementById('multisave')) {
7215: if (showButton == 1) {
7216: document.getElementById('multisave').style.display='block';
7217: } else {
7218: document.getElementById('multisave').style.display='none';
7219: }
7220: }
7221: resize_scrollbox('contentscroll','1','1');
7222: return;
7223: }
7224:
7225: function toggleCheckUncheck(caller,more) {
7226: if (more == 1) {
1.484.2.61 raeburn 7227: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7228: document.getElementById('allfields'+caller).style.display='block';
7229: } else {
1.484.2.61 raeburn 7230: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7231: document.getElementById('allfields'+caller).style.display='none';
7232: }
7233: resize_scrollbox('contentscroll','1','1');
7234: }
7235:
7236: function multiSettings() {
7237: var inuse = 0;
7238: var settingsform = document.togglemultsettings;
7239: if (settingsform.showmultpick.length > 1) {
7240: for (var i=0; i<settingsform.showmultpick.length; i++) {
7241: if (settingsform.showmultpick[i].checked) {
7242: if (settingsform.showmultpick[i].value == 1) {
7243: inuse = 1;
7244: }
7245: }
7246: }
7247: }
7248: return inuse;
7249: }
7250:
7251: function multiActions() {
7252: var inuse = 0;
7253: var actionsform = document.togglemultactions;
7254: if (actionsform.showmultpick.length > 1) {
7255: for (var i=0; i<actionsform.showmultpick.length; i++) {
7256: if (actionsform.showmultpick[i].checked) {
7257: if (actionsform.showmultpick[i].value == 1) {
7258: inuse = 1;
7259: }
7260: }
7261: }
7262: }
7263: return inuse;
7264: }
7265:
7266: function checkSubmits() {
7267: var numchanges = 0;
7268: var form = document.saveactions;
7269: var doactions = multiActions();
7270: var cutwarnings = 0;
7271: var remwarnings = 0;
1.484.2.63 raeburn 7272: var removalinfo = 0;
1.484.2.30 raeburn 7273: if (doactions == 1) {
7274: var remidxlist = document.cumulativeactions.allremoveidx.value;
7275: if ((remidxlist != '') && (remidxlist != null)) {
7276: var remidxs = remidxlist.split(',');
7277: for (var i=0; i<remidxs.length; i++) {
7278: if (document.getElementById('remove_'+remidxs[i])) {
7279: if (document.getElementById('remove_'+remidxs[i]).checked) {
7280: form.multiremove.value += remidxs[i]+',';
7281: numchanges ++;
7282: if (document.getElementById('skip_remove_'+remidxs[i])) {
7283: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7284: remwarnings ++;
7285: }
7286: }
1.484.2.63 raeburn 7287: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7288: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7289: removalinfo ++;
7290: }
7291: }
1.484.2.30 raeburn 7292: }
7293: }
7294: }
7295: }
7296: var cutidxlist = document.cumulativeactions.allcutidx.value;
7297: if ((cutidxlist != '') && (cutidxlist != null)) {
7298: var cutidxs = cutidxlist.split(',');
7299: for (var i=0; i<cutidxs.length; i++) {
7300: if (document.getElementById('cut_'+cutidxs[i])) {
7301: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7302: form.multicut.value += cutidxs[i]+',';
7303: numchanges ++;
7304: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7305: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7306: cutwarnings ++;
7307: }
7308: }
7309: }
7310: }
7311: }
7312: }
7313: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7314: if ((copyidxlist != '') && (copyidxlist != null)) {
7315: var copyidxs = copyidxlist.split(',');
7316: for (var i=0; i<copyidxs.length; i++) {
7317: if (document.getElementById('copy_'+copyidxs[i])) {
7318: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7319: form.multicopy.value += copyidxs[i]+',';
7320: numchanges ++;
7321: }
7322: }
7323: }
7324: }
7325: if (numchanges > 0) {
7326: form.multichange.value = numchanges;
7327: }
7328: }
7329: var dosettings = multiSettings();
7330: var haschanges = 0;
7331: if (dosettings == 1) {
7332: form.allencrypturl.value = '';
7333: form.allhiddenresource.value = '';
7334: form.changeparms.value = 'all';
7335: var patt=new RegExp(",\$");
7336: var allidxlist = document.cumulativesettings.allidx.value;
7337: if ((allidxlist != '') && (allidxlist != null)) {
7338: var allidxs = allidxlist.split(',');
7339: if (allidxs.length > 1) {
7340: for (var i=0; i<allidxs.length; i++) {
7341: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7342: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7343: form.allhiddenresource.value += allidxs[i]+',';
7344: }
7345: }
7346: if (document.getElementById('encrypturl_'+allidxs[i])) {
7347: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7348: form.allencrypturl.value += allidxs[i]+',';
7349: }
1.484.2.29 raeburn 7350: }
7351: }
1.484.2.30 raeburn 7352: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7353: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7354: }
7355: }
7356: form.allrandompick.value = '';
7357: form.allrandomorder.value = '';
7358: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7359: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7360: var allmapidxs = allmapidxlist.split(',');
7361: for (var i=0; i<allmapidxs.length; i++) {
7362: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7363: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7364: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7365: if ((randompick.checked) && (rpicknum.value != '')) {
7366: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7367: }
7368: if (randorder.checked) {
7369: form.allrandomorder.value += allmapidxs[i]+',';
7370: }
7371: }
7372: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7373: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7374: }
7375: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7376: haschanges = 1;
7377: }
7378: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7379: haschanges = 1;
7380: }
7381: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7382: haschanges = 1;
7383: }
7384: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7385: haschanges = 1;
7386: }
7387: }
7388: if (doactions == 1) {
7389: if (numchanges > 0) {
1.484.2.63 raeburn 7390: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7391: if (remwarnings > 0) {
1.484.2.61 raeburn 7392: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7393: return false;
7394: }
7395: }
1.484.2.63 raeburn 7396: if (removalinfo > 0) {
7397: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7398: return false;
7399: }
7400: }
1.484.2.30 raeburn 7401: if (cutwarnings > 0) {
1.484.2.61 raeburn 7402: 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 7403: return false;
1.484.2.29 raeburn 7404: }
7405: }
7406: }
1.484.2.30 raeburn 7407: form.submit();
7408: return true;
7409: }
7410: }
7411: if (dosettings == 1) {
7412: if (haschanges == 1) {
7413: form.submit();
7414: return true;
1.484.2.29 raeburn 7415: }
7416: }
1.484.2.30 raeburn 7417: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7418: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7419: } else {
7420: if (dosettings == 1) {
1.484.2.61 raeburn 7421: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7422: } else {
1.484.2.61 raeburn 7423: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7424: }
7425: }
7426: return false;
7427: }
7428:
7429: function setClass(value) {
7430: var cutclass = 'LC_docs_cut';
7431: var copyclass = 'LC_docs_copy';
7432: var removeclass = 'LC_docs_remove';
7433: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7434: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7435: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7436: var links = document.getElementsByTagName('a');
7437: for (var i=0; i<links.length; i++) {
7438: var classes = links[i].className;
7439: if (cutreg.test(classes)) {
7440: links[i].className = cutclass;
7441: if (value == 1) {
7442: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7443: }
1.484.2.30 raeburn 7444: } else {
7445: if (copyreg.test(classes)) {
7446: links[i].className = copyclass;
7447: if (value == 1) {
7448: links[i].className += " LC_menubuttons_link";
7449: }
7450: } else {
7451: if (removereg.test(classes)) {
7452: links[i].className = removeclass;
7453: if (value == 1) {
7454: links[i].className += " LC_menubuttons_link";
7455: }
7456: }
1.484.2.29 raeburn 7457: }
7458: }
7459: }
1.484.2.30 raeburn 7460: return;
1.484.2.29 raeburn 7461: }
7462:
1.484.2.30 raeburn 7463: function setBoxes(value) {
7464: var remidxlist = document.cumulativeactions.allremoveidx.value;
7465: if ((remidxlist != '') && (remidxlist != null)) {
7466: var remidxs = remidxlist.split(',');
7467: for (var i=0; i<remidxs.length; i++) {
7468: if (document.getElementById('remove_'+remidxs[i])) {
7469: var item = document.getElementById('remove_'+remidxs[i]);
7470: if (value == 1) {
7471: item.className = 'LC_docs_remove';
7472: } else {
7473: item.className = 'LC_hidden';
7474: }
7475: }
1.484.2.29 raeburn 7476: }
7477: }
1.484.2.30 raeburn 7478: var cutidxlist = document.cumulativeactions.allcutidx.value;
7479: if ((cutidxlist != '') && (cutidxlist != null)) {
7480: var cutidxs = cutidxlist.split(',');
7481: for (var i=0; i<cutidxs.length; i++) {
7482: if (document.getElementById('cut_'+cutidxs[i])) {
7483: var item = document.getElementById('cut_'+cutidxs[i]);
7484: if (value == 1) {
7485: item.className = 'LC_docs_cut';
7486: } else {
7487: item.className = 'LC_hidden';
7488: }
7489: }
7490: }
7491: }
7492: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7493: if ((copyidxlist != '') && (copyidxlist != null)) {
7494: var copyidxs = copyidxlist.split(',');
7495: for (var i=0; i<copyidxs.length; i++) {
7496: if (document.getElementById('copy_'+copyidxs[i])) {
7497: var item = document.getElementById('copy_'+copyidxs[i]);
7498: if (value == 1) {
7499: item.className = 'LC_docs_copy';
7500: } else {
7501: item.className = 'LC_hidden';
7502: }
7503: }
1.484.2.29 raeburn 7504: }
7505: }
7506: return;
7507: }
7508:
1.484.2.67 raeburn 7509: ENDSCRIPT
1.329 droeschl 7510: }
1.457 raeburn 7511:
1.483 raeburn 7512: sub history_tab_js {
7513: return <<"ENDHIST";
7514: function toggleHistoryDisp(choice) {
7515: document.docslogform.docslog.value = choice;
7516: document.docslogform.submit();
7517: return;
7518: }
7519:
7520: ENDHIST
7521: }
7522:
1.484 raeburn 7523: sub inject_data_js {
7524: return <<ENDINJECT;
7525:
7526: function injectData(current, hiddenField, name, value) {
7527: currentElement = document.getElementById(hiddenField);
7528: currentElement.name = name;
7529: currentElement.value = value;
7530: current.submit();
7531: }
7532:
7533: ENDINJECT
7534: }
7535:
7536: sub dump_switchserver_js {
7537: my @hosts = @_;
1.484.2.61 raeburn 7538: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7539: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7540: swit => 'Switch server?',
1.484.2.61 raeburn 7541: );
7542: my %html_js_lt = &Apache::lonlocal::texthash(
7543: swit => 'Switch server?',
1.484.2.43 raeburn 7544: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7545: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7546: chos => 'Choose server',
7547: );
1.484.2.61 raeburn 7548: &js_escape(\%js_lt);
7549: &html_escape(\%html_js_lt);
7550: &js_escape(\%html_js_lt);
1.484 raeburn 7551: my $role = $env{'request.role'};
7552: my $js = <<"ENDSWJS";
7553: <script type="text/javascript">
7554: function write_switchserver() {
7555: var server;
7556: if (document.setserver.posshosts.length > 0) {
7557: for (var i=0; i<document.setserver.posshosts.length; i++) {
7558: if (document.setserver.posshosts[i].checked) {
7559: server = document.setserver.posshosts[i].value;
7560: }
7561: }
7562: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7563: }
7564: window.close();
7565: }
7566: </script>
7567:
7568: ENDSWJS
7569:
7570: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7571: {'only_body' => 1,
7572: 'js_ready' => 1,});
7573: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7574:
7575: my $hostpicker;
7576: my $count = 0;
7577: foreach my $host (sort(@hosts)) {
7578: my $checked;
7579: if ($count == 0) {
7580: $checked = ' checked="checked"';
7581: }
7582: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7583: $host.'"'.$checked.' />'.$host.'</label> ';
7584: $count++;
7585: }
7586:
7587: return <<"ENDSWITCHJS";
7588:
7589: function dump_needs_switchserver(url) {
7590: if (url!='' && url!= null) {
1.484.2.61 raeburn 7591: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7592: go(url);
7593: }
7594: }
7595: return;
7596: }
7597:
7598: function choose_switchserver_window() {
7599: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7600: newWindow.document.open();
7601: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7602: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7603: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7604: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7605: '<form name="setserver" method="post" action="" \\/>\\n'+
7606: '$hostpicker\\n'+
7607: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7608: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7609: 'onclick="write_switchserver();" \\/>\\n'+
7610: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7611: newWindow.document.writeln('$endpage');
7612: newWindow.document.close();
7613: newWindow.focus();
7614: }
7615:
7616: ENDSWITCHJS
7617: }
7618:
7619: sub makedocslogform {
7620: my ($formelems,$docslog) = @_;
7621: return <<"LOGSFORM";
7622: <form action="/adm/coursedocs" method="post" name="docslogform">
7623: <input type="hidden" name="docslog" value="$docslog" />
7624: $formelems
7625: </form>
7626: LOGSFORM
7627: }
7628:
7629: sub makesimpleeditform {
7630: my ($formelems) = @_;
7631: return <<"SIMPFORM";
7632: <form name="simpleedit" method="post" action="/adm/coursedocs">
7633: <input type="hidden" name="importdetail" value="" />
7634: $formelems
7635: </form>
7636: SIMPFORM
7637: }
7638:
1.329 droeschl 7639: 1;
7640: __END__
7641:
7642:
7643: =head1 NAME
7644:
7645: Apache::londocs.pm
7646:
7647: =head1 SYNOPSIS
7648:
7649: This is part of the LearningOnline Network with CAPA project
7650: described at http://www.lon-capa.org.
7651:
7652: =head1 SUBROUTINES
7653:
7654: =over
7655:
7656: =item %help=()
7657:
7658: Available help topics
7659:
7660: =item mapread()
7661:
1.344 bisitz 7662: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7663: @order and @resources, determines status
7664: sets @order - pointer to resources in right order
7665: sets @resources - array with the resources with correct idx
7666:
7667: =item authorhosts()
7668:
7669: Return hash with valid author names
7670:
7671: =item clean()
7672:
7673: =item dumpcourse()
7674:
7675: Actually dump course
7676:
7677: =item group_import()
7678:
7679: Imports the given (name, url) resources into the course
7680: coursenum, coursedom, and folder must precede the list
7681:
7682: =item breadcrumbs()
7683:
7684: =item log_docs()
7685:
7686: =item docs_change_log()
7687:
7688: =item update_paste_buffer()
7689:
7690: =item print_paste_buffer()
7691:
7692: =item do_paste_from_buffer()
7693:
1.484.2.30 raeburn 7694: =item do_buffer_empty()
7695:
7696: =item clear_from_buffer()
7697:
1.484.2.7 raeburn 7698: =item get_newmap_url()
7699:
7700: =item dbcopy()
7701:
7702: =item uniqueness_check()
7703:
7704: =item contained_map_check()
7705:
7706: =item url_paste_fixups()
7707:
7708: =item apply_fixups()
7709:
7710: =item copy_dependencies()
7711:
1.329 droeschl 7712: =item update_parameter()
7713:
7714: =item handle_edit_cmd()
7715:
7716: =item editor()
7717:
7718: =item process_file_upload()
7719:
7720: =item process_secondary_uploads()
7721:
7722: =item is_supplemental_title()
7723:
7724: =item entryline()
7725:
7726: =item tiehash()
7727:
7728: =item untiehash()
7729:
7730: =item checkonthis()
7731:
7732: check on this
7733:
7734: =item verifycontent()
7735:
7736: Verify Content
7737:
1.484.2.72.2. (raeburn 7738:): =item devalidateversioncache()
7739:):
7740:): =item checkversions()
1.329 droeschl 7741:
7742: Check Versions
7743:
7744: =item mark_hash_old()
7745:
7746: =item is_hash_old()
7747:
7748: =item changewarning()
7749:
7750: =item init_breadcrumbs()
7751:
7752: Breadcrumbs for special functions
7753:
1.484 raeburn 7754: =item create_list_elements()
7755:
7756: =item create_form_ul()
7757:
7758: =item startContentScreen()
7759:
7760: =item endContentScreen()
7761:
7762: =item supplemental_base()
7763:
7764: =item embedded_form_elems()
7765:
7766: =item embedded_destination()
7767:
7768: =item return_to_editor()
7769:
7770: =item decompression_info()
7771:
7772: =item decompression_phase_one()
7773:
7774: =item decompression_phase_two()
7775:
7776: =item remove_archive()
7777:
7778: =item generate_admin_menu()
7779:
7780: =item generate_edit_table()
7781:
7782: =item editing_js()
7783:
7784: =item history_tab_js()
7785:
7786: =item inject_data_js()
7787:
7788: =item dump_switchserver_js()
7789:
1.484.2.3 raeburn 7790: =item resize_scrollbox_js()
1.484 raeburn 7791:
7792: =item makedocslogform()
7793:
1.484.2.3 raeburn 7794: =item makesimpleeditform()
7795:
1.329 droeschl 7796: =back
7797:
7798: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>