Annotation of loncom/interface/londocs.pm, revision 1.484.2.83
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.83! raeburn 4: # $Id: londocs.pm,v 1.484.2.82 2019/08/16 16:12:37 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 {
625: my ($coursenum, $coursedom, $folder, $container, $caller, @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.23 raeburn 654: if (($caller eq 'londocs') &&
655: ($folder =~ /^default/)) {
1.484.2.27 raeburn 656: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 657: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
658: my $cid = $coursedom.'_'.$coursenum;
659: $allmaps =
660: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
661: $chome,$cid);
662: $donechk = 1;
663: }
664: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
665: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
666: \%addedmaps,\%hierarchy,\%titles,$allmaps);
667: $importuploaded = 1;
668: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
669: next if ($allmaps->{$url});
670: }
671: }
1.344 bisitz 672: if (!$residx
1.329 droeschl 673: || defined($LONCAPA::map::zombies[$residx])) {
674: $residx = &LONCAPA::map::getresidx($url,$residx);
675: push(@LONCAPA::map::order, $residx);
676: }
677: my $ext = 'false';
678: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
679: $name = &LONCAPA::map::qtunescape($name);
1.484.2.27 raeburn 680: if ($name eq '') {
1.484.2.30 raeburn 681: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.484.2.27 raeburn 682: }
683: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
684: my $filepath = $1;
685: my $fname = $name;
686: if ($fname =~ /^\W+$/) {
687: $fname = 'web';
688: } else {
689: $fname =~ s/\W/_/g;
690: }
1.484.2.62 raeburn 691: if (length($fname) > 15) {
1.484.2.27 raeburn 692: $fname = substr($fname,0,14);
693: }
694: my $initialtext = &mt('Replace with your own content.');
695: my $newhtml = <<END;
1.484.2.31 raeburn 696: <html>
1.484.2.27 raeburn 697: <head>
698: <title>$name</title>
699: </head>
700: <body bgcolor="#ffffff">
701: $initialtext
702: </body>
703: </html>
704: END
705: $env{'form.output'}=$newhtml;
706: my $result =
707: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
708: 'output',
709: "$filepath/$residx/$fname.html");
710: if ($result =~ m{^/uploaded/}) {
711: $url = $result;
712: if ($filepath =~ /^supplemental/) {
713: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
714: $env{'user.domain'}.'___&&&___'.$name;
715: }
716: } else {
717: return (&mt('Failed to save new web page.'),1);
718: }
719: }
1.484.2.30 raeburn 720: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 721: $LONCAPA::map::resources[$residx] =
1.329 droeschl 722: join(':', ($name, $url, $ext, 'normal', 'res'));
723: }
724: }
1.484.2.23 raeburn 725: if ($importuploaded) {
726: my %import_errors;
727: my %updated = (
728: removefrommap => \%removefrommap,
729: removeparam => \%removeparam,
730: );
1.484.2.26 raeburn 731: my ($result,$msgsarray,$lockerror) =
732: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 733: if (keys(%import_errors) > 0) {
734: $fixuperrors =
735: '<p span class="LC_warning">'."\n".
736: &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".
737: '<ul>'."\n";
738: foreach my $key (sort(keys(%import_errors))) {
739: $fixuperrors .= '<li>'.$key.'</li>'."\n";
740: }
741: $fixuperrors .= '</ul></p>'."\n";
742: }
1.484.2.26 raeburn 743: if (ref($msgsarray) eq 'ARRAY') {
744: if (@{$msgsarray} > 0) {
745: $fixuperrors .= '<p class="LC_info">'.
746: join('<br />',@{$msgsarray}).
747: '</p>';
748: }
749: }
750: if ($lockerror) {
751: $fixuperrors .= '<p class="LC_error">'.
752: $lockerror.
753: '</p>';
754: }
1.484.2.23 raeburn 755: }
756: my ($errtext,$fatal) =
757: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 758: unless ($fatal) {
759: if ($folder =~ /^supplemental/) {
760: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 761: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
762: $folder.'.'.$container);
1.484.2.37 raeburn 763: }
764: }
1.484.2.23 raeburn 765: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 766: }
767:
768: sub log_docs {
1.484.2.8 raeburn 769: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 770: }
771:
772: {
773: my @oldresources=();
774: my @oldorder=();
775: my $parmidx;
776: my %parmaction=();
777: my %parmvalue=();
778: my $changedflag;
779:
780: sub snapshotbefore {
781: @oldresources=@LONCAPA::map::resources;
782: @oldorder=@LONCAPA::map::order;
783: $parmidx=undef;
784: %parmaction=();
785: %parmvalue=();
786: $changedflag=0;
787: }
788:
789: sub remember_parms {
790: my ($idx,$parameter,$action,$value)=@_;
791: $parmidx=$idx;
792: $parmaction{$parameter}=$action;
793: $parmvalue{$parameter}=$value;
794: $changedflag=1;
795: }
796:
797: sub log_differences {
798: my ($plain)=@_;
799: my %storehash=('folder' => $plain,
800: 'currentfolder' => $env{'form.folder'});
801: if ($parmidx) {
802: $storehash{'parameter_res'}=$oldresources[$parmidx];
803: foreach my $parm (keys(%parmaction)) {
804: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
805: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
806: }
807: }
808: my $maxidx=$#oldresources;
809: if ($#LONCAPA::map::resources>$#oldresources) {
810: $maxidx=$#LONCAPA::map::resources;
811: }
812: for (my $idx=0; $idx<=$maxidx; $idx++) {
813: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
814: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
815: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
816: $changedflag=1;
817: }
818: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
819: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
820: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
821: $changedflag=1;
822: }
823: }
824: $storehash{'maxidx'}=$maxidx;
825: if ($changedflag) { &log_docs(\%storehash); }
826: }
827: }
828:
829: sub docs_change_log {
1.484.2.67 raeburn 830: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 831: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 832: my $navmap;
1.483 raeburn 833: my $js = '<script type="text/javascript">'."\n".
834: '// <![CDATA['."\n".
835: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 836: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.80 raeburn 837: $coursedom,$coursenum,$canedit,'',\$navmap)."\n".
1.483 raeburn 838: &history_tab_js()."\n".
1.484 raeburn 839: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 840: '// ]]>'."\n".
841: '</script>'."\n";
1.484 raeburn 842: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
843: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 844: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 845: my %orderhash;
846: my $container='sequence';
847: my $pathitem;
1.484.2.19 raeburn 848: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 849: $container='page';
850: }
1.484.2.19 raeburn 851: my $folderpath=$env{'form.folderpath'};
852: if ($folderpath eq '') {
1.484.2.67 raeburn 853: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 854: }
1.484.2.67 raeburn 855: undef($navmap);
1.484.2.19 raeburn 856: $pathitem = '<input type="hidden" name="folderpath" value="'.
857: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 858: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
859: my $jumpto = $readfile;
860: $jumpto =~ s{^/}{};
861: my $tid = 1;
1.484.2.7 raeburn 862: if ($supplementalflag) {
863: $tid = 2;
864: }
1.484.2.19 raeburn 865: my ($breadcrumbtrail) =
1.484.2.18 raeburn 866: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 867: $r->print($breadcrumbtrail.
868: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
869: $readfile));
1.329 droeschl 870: my %docslog=&Apache::lonnet::dump('nohist_docslog',
871: $env{'course.'.$env{'request.course.id'}.'.domain'},
872: $env{'course.'.$env{'request.course.id'}.'.num'});
873:
874: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
875:
876: my %saveable_parameters = ('show' => 'scalar',);
877: &Apache::loncommon::store_course_settings('docs_log',
878: \%saveable_parameters);
879: &Apache::loncommon::restore_course_settings('docs_log',
880: \%saveable_parameters);
881: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 882: # FIXME: internationalization seems wrong here
1.329 droeschl 883: my %lt=('hiddenresource' => 'Resources hidden',
884: 'encrypturl' => 'URL hidden',
885: 'randompick' => 'Randomly pick',
886: 'randomorder' => 'Randomly ordered',
887: 'set' => 'set to',
888: 'del' => 'deleted');
1.484 raeburn 889: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
890: $pathitem."\n".
891: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
892: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
893: $r->print('<div class="LC_left_float">'.
894: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
895: &makedocslogform($filter,1).
896: '</fieldset></div><br clear="all" />');
1.329 droeschl 897: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
898: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
899: &mt('After').'</th>'.
900: &Apache::loncommon::end_data_table_header_row());
901: my $shown=0;
902: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
903: if ($env{'form.displayfilter'} eq 'currentfolder') {
904: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
905: }
906: my @changes=keys(%{$docslog{$id}{'logentry'}});
907: if ($env{'form.displayfilter'} eq 'containing') {
908: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
909: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
910: foreach my $key (@changes) {
911: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
912: }
1.344 bisitz 913: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 914: }
915: my $count = 0;
916: my $time =
917: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
918: my $plainname =
919: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
920: $docslog{$id}{'exe_udom'});
921: my $about_me_link =
922: &Apache::loncommon::aboutmewrapper($plainname,
923: $docslog{$id}{'exe_uname'},
924: $docslog{$id}{'exe_udom'});
925: my $send_msg_link='';
926: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
927: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
928: $send_msg_link ='<br />'.
929: &Apache::loncommon::messagewrapper(&mt('Send message'),
930: $docslog{$id}{'exe_uname'},
931: $docslog{$id}{'exe_udom'});
932: }
933: $r->print(&Apache::loncommon::start_data_table_row());
934: $r->print('<td>'.$time.'</td>
935: <td>'.$about_me_link.
936: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
937: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
938: $send_msg_link.'</td><td>'.
939: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 940: my $is_supp = 0;
1.484.2.7 raeburn 941: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
942: $is_supp = 1;
943: }
1.329 droeschl 944: # Before
945: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
946: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
947: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
948: if ($oldname ne $newname) {
1.484.2.7 raeburn 949: my $shown = &LONCAPA::map::qtescape($oldname);
950: if ($is_supp) {
951: $shown = &Apache::loncommon::parse_supplemental_title($shown);
952: }
953: $r->print($shown);
1.329 droeschl 954: }
955: }
956: $r->print('<ul>');
957: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
958: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 959: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
960: if ($is_supp) {
961: $shown = &Apache::loncommon::parse_supplemental_title($shown);
962: }
1.484.2.19 raeburn 963: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 964: }
965: }
966: $r->print('</ul>');
967: # After
968: $r->print('</td><td>');
969:
970: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
971: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
972: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
973: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 974: my $shown = &LONCAPA::map::qtescape($newname);
975: if ($is_supp) {
976: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
977: }
978: $r->print($shown);
1.329 droeschl 979: }
1.364 bisitz 980: }
1.329 droeschl 981: $r->print('<ul>');
982: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
983: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 984: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
985: if ($is_supp) {
986: $shown = &Apache::loncommon::parse_supplemental_title($shown);
987: }
988: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 989: }
990: }
991: $r->print('</ul>');
992: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
993: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
994: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
995: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 996: # FIXME: internationalization seems wrong here
1.329 droeschl 997: $r->print('<li>'.
998: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
999: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1000: .'</li>');
1001: }
1002: }
1003: $r->print('</ul>');
1004: }
1005: # End
1006: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1007: $shown++;
1008: if (!($env{'form.show'} eq &mt('all')
1009: || $shown<=$env{'form.show'})) { last; }
1010: }
1.484 raeburn 1011: $r->print(&Apache::loncommon::end_data_table()."\n".
1012: &makesimpleeditform($pathitem)."\n".
1013: '</div></div>');
1014: $r->print(&endContentScreen());
1.329 droeschl 1015: }
1016:
1017: sub update_paste_buffer {
1.484.2.7 raeburn 1018: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1019: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1020: if ($env{'form.multiremove'}) {
1021: $env{'form.multiremove'} =~ s/,$//;
1022: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1023: }
1024: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1025: if ($env{'form.multicut'}) {
1026: $env{'form.multicut'} =~ s/,$//;
1027: foreach my $item (split(/,/,$env{'form.multicut'})) {
1028: unless ($removals{$item}) {
1029: $cuts{$item} = 1;
1030: push(@possibles,$item.':cut');
1031: }
1032: }
1033: }
1034: if ($env{'form.multicopy'}) {
1035: $env{'form.multicopy'} =~ s/,$//;
1036: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1037: unless ($removals{$item} || $cuts{$item}) {
1038: push(@possibles,$item.':copy');
1039: }
1040: }
1041: }
1042: } elsif ($env{'form.markcopy'}) {
1043: @possibles = split(/,/,$env{'form.markcopy'});
1044: }
1.329 droeschl 1045:
1.484.2.30 raeburn 1046: return if (@possibles == 0);
1.329 droeschl 1047: return if (!defined($env{'form.copyfolder'}));
1048:
1049: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1050: $env{'form.copyfolder'});
1051: return if ($fatal);
1052:
1.484.2.30 raeburn 1053: my %curr_groups = &Apache::longroup::coursegroups();
1054:
1055: # Retrieve current paste buffer suffixes.
1056: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1057: my (%pasteurls,@newpaste);
1058:
1059: # Construct identifiers for current contents of user's paste buffer
1060: if (@currpaste) {
1061: foreach my $suffix (@currpaste) {
1062: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1063: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1064: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1065: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1066: ($url ne '')) {
1.484.2.82 raeburn 1067: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.484.2.30 raeburn 1068: }
1069: }
1070: }
1071:
1072: # Mark items for copying (skip any items already in user's paste buffer)
1073: my %addtoenv;
1.484.2.82 raeburn 1074:
1075: my @pathitems = split(/\&/,$env{'form.folderpath'});
1076: my @folderconf = split(/\:/,$pathitems[-1]);
1077: my $ispage = $folderconf[4];
1078:
1.484.2.30 raeburn 1079: foreach my $item (@possibles) {
1080: my ($orderidx,$cmd) = split(/:/,$item);
1081: next if ($orderidx =~ /\D/);
1082: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1083: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1084: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1085: my %denied = &action_restrictions($coursenum,$coursedom,
1086: &LONCAPA::map::qtescape($url),
1087: $env{'form.folderpath'},\%curr_groups);
1088: next if ($denied{'copy'});
1089: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.82 raeburn 1090: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.484.2.30 raeburn 1091: my ($suffix,$errortxt,$locknotfreed) =
1092: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1093: if ($suffix ne '') {
1094: push(@newpaste,$suffix);
1095: } else {
1096: if ($locknotfreed) {
1097: return $locknotfreed;
1098: }
1.484.2.30 raeburn 1099: }
1100: if (&is_supplemental_title($title)) {
1101: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1102: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1103: }
1104:
1105: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1106: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1107: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1108: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1109: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1110: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1111: my $prefix = $1;
1112: my $subdir =$2;
1113: if ($subdir eq '') {
1114: $subdir = $prefix;
1.484.2.7 raeburn 1115: }
1.484.2.30 raeburn 1116: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1117: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1118: \%hierarchy,\%titles,\%allmaps);
1119: if (ref($hierarchy{$url}) eq 'HASH') {
1120: my ($nested,$nestednames);
1121: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1122: $nested =~ s/\&$//;
1123: $nestednames =~ s/\Q___&&&___\E$//;
1124: if ($nested ne '') {
1125: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1126: }
1127: if ($nestednames ne '') {
1128: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1129: }
1.484.2.7 raeburn 1130: }
1131: }
1.484.2.57 raeburn 1132: if ($locknotfreed) {
1133: $output = $locknotfreed;
1134: last;
1135: }
1.484.2.7 raeburn 1136: }
1.484.2.30 raeburn 1137: if (@newpaste) {
1138: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1139: }
1.484.2.7 raeburn 1140: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1141: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1142: return $output;
1.329 droeschl 1143: }
1144:
1.484.2.7 raeburn 1145: sub recurse_uploaded_maps {
1146: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1147: if (ref($hierarchy->{$url}) eq 'HASH') {
1148: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1149: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1150: my (@uploaded,@names,%shorter);
1151: for (my $i=0; $i<@maps; $i++) {
1152: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1153: if ($inner ne '') {
1154: push(@uploaded,$inner);
1155: push(@names,&escape($titles[$i]));
1156: $shorter{$maps[$i]} = $inner;
1157: }
1158: }
1159: $$nestref .= "$dir:".join(',',@uploaded).'&';
1160: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1161: foreach my $map (@maps) {
1162: if ($shorter{$map} ne '') {
1163: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1164: }
1165: }
1166: }
1167: return;
1168: }
1169:
1.329 droeschl 1170: sub print_paste_buffer {
1.484.2.7 raeburn 1171: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1172: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1173:
1.484.2.30 raeburn 1174: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1175: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1176: }
1177:
1.484.2.30 raeburn 1178: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1179: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1180: my $clipboardcount = 0;
1.484.2.7 raeburn 1181:
1.484.2.30 raeburn 1182: # Construct identifiers for current contents of user's paste buffer
1183: foreach my $suffix (@currpaste) {
1184: next if ($suffix =~ /\D/);
1185: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1186: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1187: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1188: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1189: ($url ne '')) {
1.484.2.47 raeburn 1190: $clipboardcount ++;
1.484.2.30 raeburn 1191: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1192: $canpaste,$nopaste,$othercrs,$areachange);
1193: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1194: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1195: $is_external = 1;
1.484.2.7 raeburn 1196: }
1.484.2.30 raeburn 1197: if ($folder =~ /^supplemental/) {
1198: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1199: unless ($canpaste) {
1200: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1201: }
1.484.2.30 raeburn 1202: } else {
1203: $canpaste = 1;
1.484.2.7 raeburn 1204: }
1.484.2.30 raeburn 1205: if ($canpaste) {
1206: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1207: my $srcdom = $1;
1208: my $srcnum = $2;
1209: my $rem = $3;
1210: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1211: $othercourse = 1;
1212: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1213: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1214: } else {
1215: $canpaste = 0;
1216: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1217: }
1218: }
1.484.2.30 raeburn 1219: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1220: my $prefix = $1;
1221: $parent = $2;
1222: if ($folder !~ /^\Q$prefix\E/) {
1223: $areachange = 1;
1224: }
1225: $is_uploaded_map = 1;
1226: }
1.484.2.82 raeburn 1227: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1228: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1229: if ($cid ne $env{'request.course.id'}) {
1230: my ($srcdom,$srcnum) = split(/_/,$cid);
1231: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1232: $othercrs = '<br />'.&mt('(from another course)');
1233: } else {
1234: $canpaste = 0;
1235: $nopaste = &mt('Paste from another course unavailable.');
1236: }
1237: }
1238: }
1239: if ($canpaste) {
1240: push(@pasteable,$suffix);
1.484.2.30 raeburn 1241: }
1242: }
1243: my $buffer;
1244: if ($is_external) {
1245: $buffer = &mt('External Resource').': '.
1246: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1247: &LONCAPA::map::qtescape($url).')';
1248: } else {
1249: my $icon = &Apache::loncommon::icon($extension);
1250: if ($extension eq 'sequence' &&
1251: $url =~ m{/default_\d+\.sequence$}x) {
1252: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1253: $icon .= '/navmap.folder.closed.gif';
1254: }
1.484.2.57 raeburn 1255: my $title = $env{'docs.markedcopy_title_'.$suffix};
1256: if ($title eq '') {
1257: ($title) = ($url =~ m{/([^/]+)$});
1258: }
1.484.2.30 raeburn 1259: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1260: ': '.
1261: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1262: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1263: }
1264: $pasteitems .= '<div class="LC_left_float">';
1265: my ($options,$onclick);
1266: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1267: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1268: if (($is_uploaded_map) ||
1269: ($url =~ /(bulletinboard|smppg)$/) ||
1270: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1271: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1272: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1273: }
1274: }
1275: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1276: if ($nopaste) {
1277: $pasteitems .= $nopaste;
1278: } else {
1279: if ($othercrs) {
1280: $pasteitems .= $othercrs;
1281: }
1282: if ($options) {
1283: $pasteitems .= $options;
1.484.2.7 raeburn 1284: }
1285: }
1.484.2.30 raeburn 1286: $pasteitems .= '</div>';
1287: }
1288: }
1289: if ($pasteitems eq '') {
1290: &Apache::lonnet::delenv('docs.markedcopies');
1291: }
1292: my ($pasteform,$form_start,$buttons,$form_end);
1293: if ($pasteitems) {
1294: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1295: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1296: if (@pasteable) {
1.484.2.47 raeburn 1297: my $value = &mt('Paste to current folder');
1298: if ($container eq 'page') {
1299: $value = &mt('Paste to current page');
1300: }
1301: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1302: }
1303: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.(' 'x2);
1304: if ($clipboardcount > 1) {
1305: $buttons .=
1306: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1307: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1308: (' 'x2).
1309: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1310: (' 'x2);
1.484.2.7 raeburn 1311: }
1.484.2.48 raeburn 1312: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1313: '</form>';
1.484.2.30 raeburn 1314: } else {
1315: $pasteitems = &mt('Clipboard is empty');
1316: }
1317: $r->print($form_start
1318: .'<fieldset>'
1319: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1320: .$pasteitems
1321: .'</fieldset>'
1322: .$form_end);
1323: }
1324:
1325: sub paste_options {
1326: my ($suffix,$is_uploaded_map,$parent) = @_;
1327: my ($copytext,$movetext);
1328: if ($is_uploaded_map) {
1329: $copytext = &mt('Copy to new folder');
1330: $movetext = &mt('Move old');
1331: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1332: $copytext = &mt('Copy to new board');
1333: $movetext = &mt('Move (not posts)');
1334: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1335: $copytext = &mt('Copy to new page');
1336: $movetext = &mt('Move');
1.484.2.7 raeburn 1337: } else {
1.484.2.30 raeburn 1338: $copytext = &mt('Copy to new file');
1339: $movetext = &mt('Move');
1340: }
1341: my $output = '<br />'.
1342: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1343: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1344: '<label>'.
1345: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1346: $copytext.'</label></span>'.(' 'x2).' '.
1347: '<span class="LC_nobreak"><label>'.
1348: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1349: $movetext.'</label></span>';
1350: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1351: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1352: '</legend><table border="0">';
1353: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1354: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1355: my $lastdir = $parent;
1356: my %depths = (
1357: $lastdir => 0,
1358: );
1359: my (%display,%deps);
1360: for (my $i=0; $i<@pastemaps; $i++) {
1361: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1362: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1363: my @subfolders = split(/,/,$subfolderstr);
1364: $deps{$lastdir} = \@subfolders;
1365: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1366: my $depth = $depths{$lastdir} + 1;
1367: my $offset = int($depth * 4);
1368: my $indent = (' ' x $offset);
1369: for (my $j=0; $j<@subfolders; $j++) {
1370: $depths{$subfolders[$j]} = $depth;
1371: $display{$subfolders[$j]} =
1372: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1373: '<td><label>'.
1374: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1375: '<label>'.
1376: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1377: &mt('Move old').'</label>'.
1378: '</td></tr>';
1379: }
1380: }
1381: &recurse_print(\$output,$parent,\%deps,\%display);
1382: $output .= '</table></fieldset>';
1.329 droeschl 1383: }
1.484.2.30 raeburn 1384: $output .= '</div>';
1385: return $output;
1.329 droeschl 1386: }
1387:
1.484.2.7 raeburn 1388: sub recurse_print {
1.484.2.30 raeburn 1389: my ($outputref,$dir,$deps,$display) = @_;
1390: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1391: if (ref($deps->{$dir}) eq 'ARRAY') {
1392: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1393: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1394: }
1395: }
1396: }
1397:
1398: sub supp_pasteable {
1399: my ($url) = @_;
1400: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1401: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1402: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1403: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1404: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1405: return 1;
1406: }
1407: return;
1408: }
1409:
1410: sub paste_popup_js {
1.484.2.61 raeburn 1411: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1412: show => 'Show Options',
1413: hide => 'Hide Options',
1.484.2.61 raeburn 1414: );
1415: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1416: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1417: );
1.484.2.61 raeburn 1418: &html_escape(\%html_js_lt);
1419: &js_escape(\%html_js_lt);
1420: &js_escape(\%js_lt);
1.484.2.7 raeburn 1421: return <<"END";
1422:
1.484.2.30 raeburn 1423: function showPasteOptions(suffix) {
1424: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1425: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1426: return;
1427: }
1428:
1.484.2.30 raeburn 1429: function hidePasteOptions(suffix) {
1430: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1431: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1432: return;
1433: }
1434:
1.484.2.30 raeburn 1435: function showOptions(caller,suffix) {
1436: if (document.getElementById('pasteoptionstext_'+suffix)) {
1437: if (caller.checked) {
1.484.2.61 raeburn 1438: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1439: } else {
1440: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1441: }
1442: if (document.getElementById('pasteoptions_'+suffix)) {
1443: document.getElementById('pasteoptions_'+suffix).style.display='none';
1444: }
1445: }
1446: return;
1447: }
1.484.2.7 raeburn 1448:
1.484.2.30 raeburn 1449: function validateClipboard() {
1450: var numchk = 0;
1451: if (document.pasteform.pasting.length > 1) {
1452: for (var i=0; i<document.pasteform.pasting.length; i++) {
1453: if (document.pasteform.pasting[i].checked) {
1454: numchk ++;
1455: }
1456: }
1457: } else {
1458: if (document.pasteform.pasting.type == 'checkbox') {
1459: if (document.pasteform.pasting.checked) {
1460: numchk ++;
1461: }
1462: }
1463: }
1464: if (numchk > 0) {
1465: return true;
1466: } else {
1.484.2.61 raeburn 1467: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1468: return false;
1469: }
1.484.2.7 raeburn 1470: }
1471:
1.484.2.47 raeburn 1472: function checkClipboard() {
1473: if (document.pasteform.pasting.length > 1) {
1474: for (var i=0; i<document.pasteform.pasting.length; i++) {
1475: document.pasteform.pasting[i].checked = true;
1476: }
1477: }
1478: return;
1479: }
1480:
1481: function uncheckClipboard() {
1482: if (document.pasteform.pasting.length >1) {
1483: for (var i=0; i<document.pasteform.pasting.length; i++) {
1484: document.pasteform.pasting[i].checked = false;
1485: }
1486: }
1487: return;
1488: }
1489:
1.484.2.30 raeburn 1490: END
1491:
1492: }
1.484.2.7 raeburn 1493:
1.329 droeschl 1494: sub do_paste_from_buffer {
1.484.2.7 raeburn 1495: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1496:
1.484.2.30 raeburn 1497: # Array of items in paste buffer
1498: my (@currpaste,%pastebuffer,%allerrors);
1499: @currpaste = split(/,/,$env{'docs.markedcopies'});
1500:
1.484.2.7 raeburn 1501: # Early out if paste buffer is empty
1.484.2.30 raeburn 1502: if (@currpaste == 0) {
1.484.2.7 raeburn 1503: return ();
1.484.2.30 raeburn 1504: }
1505: map { $pastebuffer{$_} = 1; } @currpaste;
1506:
1507: # Array of items selected items to paste
1508: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1509:
1510: # Early out if nothing selected to paste
1511: if (@reqpaste == 0) {
1512: return();
1513: }
1514: my @topaste;
1515: foreach my $suffix (@reqpaste) {
1516: next if ($suffix =~ /\D/);
1517: next unless (exists($pastebuffer{$suffix}));
1518: push(@topaste,$suffix);
1.484.2.7 raeburn 1519: }
1520:
1.484.2.30 raeburn 1521: # Early out if nothing available to paste
1522: if (@topaste == 0) {
1523: return();
1.329 droeschl 1524: }
1525:
1.484.2.30 raeburn 1526: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.484.2.82 raeburn 1527: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1528:
1.484.2.30 raeburn 1529: foreach my $suffix (@topaste) {
1530: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1531: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1532: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1533: # Supplemental content may only include certain types of content
1534: # Early out if pasted content is not supported in Supplemental area
1535: if ($folder =~ /^supplemental/) {
1536: unless (&supp_pasteable($url)) {
1537: $notinsupp{$suffix} = 1;
1538: next;
1539: }
1540: }
1541: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1542: my $srcd = $1;
1543: my $srcn = $2;
1.484.2.7 raeburn 1544: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1545: # check for mdc privilege in the course from which the resource was pasted
1546: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1547: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1548: $notincrs{$suffix} = 1;
1549: next;
1550: }
1.329 droeschl 1551: }
1.484.2.30 raeburn 1552: $srcdom{$suffix} = $srcd;
1553: $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1554: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1555: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1556: my ($srcd,$srcn) = split(/_/,$cid);
1557: # When paste buffer was populated using an active role in a different course
1558: # check for mdc privilege in the course from which the resource was pasted
1559: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1560: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1561: $notincrs{$suffix} = 1;
1562: next;
1563: }
1564: }
1565: $srcdom{$suffix} = $srcd;
1566: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1567: }
1.484.2.82 raeburn 1568: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1569: push(@dopaste,$suffix);
1570: if ($url=~/\.(page|sequence)$/) {
1571: $is_map{$suffix} = 1;
1.329 droeschl 1572: }
1.484.2.30 raeburn 1573:
1574: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1575: my $oldprefix = $1;
1.484.2.19 raeburn 1576: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1577: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1578: # a folder/page or a document).
1.484.2.30 raeburn 1579: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1580: $prefixchg{$suffix} = 'docstosupp';
1581: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1582: $prefixchg{$suffix} = 'supptodocs';
1583: }
1.484.2.7 raeburn 1584:
1585: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1586: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1587: my @nested;
1588: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1589: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1590: my @deps = map { /\d+:([\d,]+$)/ } @items;
1591: foreach my $dep (@deps) {
1592: if ($dep =~ /,/) {
1593: push(@nested,split(/,/,$dep));
1594: } else {
1595: push(@nested,$dep);
1596: }
1.484.2.7 raeburn 1597: }
1.484.2.30 raeburn 1598: foreach my $item (@nested) {
1599: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1600: push(@{$marktomove{$suffix}},$type.'_'.$item);
1601: }
1.484.2.7 raeburn 1602: }
1603: }
1.329 droeschl 1604: }
1.484.2.7 raeburn 1605: }
1606:
1.484.2.30 raeburn 1607: # Early out if nothing available to paste
1608: if (@dopaste == 0) {
1609: return ();
1610: }
1611:
1612: # Populate message hash and hashes used for main content <=> supplemental content
1613: # changes
1614:
1615: %msgs = &Apache::lonlocal::texthash (
1616: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1617: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1618: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1619: );
1620:
1621: %before = (
1622: docstosupp => {
1623: map => 'default',
1624: doc => 'docs',
1625: },
1626: supptodocs => {
1627: map => 'supplemental',
1628: doc => 'supplemental',
1629: },
1630: );
1631:
1632: %after = (
1633: docstosupp => {
1634: map => 'supplemental',
1635: doc => 'supplemental'
1636: },
1637: supptodocs => {
1638: map => 'default',
1639: doc => 'docs',
1640: },
1641: );
1642:
1643: # Retrieve information about all course maps in main content area
1644:
1645: my $allmaps = {};
1.484.2.79 raeburn 1646: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1647:
1648: # Loop over the items to paste
1649: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1650: # Maps need to be copied first
1.484.2.30 raeburn 1651: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1652: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1653: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1654: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1655: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1656: }
1657: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1658: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1659: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1660: my $oldurl = $url;
1661: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1662: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1663: my (%hierarchy,%titles);
1.484.2.79 raeburn 1664: if (($folder =~ /^default/) && (!$donechk)) {
1665: $allmaps =
1666: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1667: $env{"course.$env{'request.course.id'}.home"},
1668: $env{'request.course.id'});
1669: $donechk = 1;
1670: }
1.484.2.30 raeburn 1671: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1672: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1673: if ($url=~ m{^/uploaded/}) {
1674: my $newurl;
1675: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1676: ($newurl,my $error) =
1677: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1678: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1679: \$title,$allmaps,\%newurls);
1680: if ($error) {
1681: $allerrors{$suffix} = $error;
1682: next;
1683: }
1684: if ($newurl ne '') {
1685: if ($newurl ne $url) {
1686: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1687: $newsubdir{$url} = $1;
1688: }
1689: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1690: }
1691: }
1692: }
1.484.2.30 raeburn 1693: if (($srcdom{$suffix} ne $coursedom) ||
1694: ($srcnum{$suffix} ne $coursenum) ||
1695: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1696: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1697: $coursedom,$coursenum,$srcdom{$suffix},
1698: $srcnum{$suffix},$allmaps,\%rewrites,
1699: \%retitles,\%copies,\%dbcopies,
1700: \%zombies,\%params,\%mapmoves,
1701: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1702: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1703: $mapmoves{$url} = 1;
1704: }
1705: $url = $newurl;
1706: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1707: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1708: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1709: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1710: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1711: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1712: }
1713: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1714: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1715: push(@toclear,$suffix);
1716: # if pasting published map (main content area only) check map not already in course
1717: if ($folder =~ /^default/) {
1718: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1719: $duplicate{$suffix} = 1;
1720: next;
1721: }
1.484.2.7 raeburn 1722: }
1723: }
1724: }
1.484.2.30 raeburn 1725: if ($url=~ m{/(bulletinboard|smppg)$}) {
1726: my $prefix = $1;
1.484.2.76 raeburn 1727: my $fromothercrs;
1.484.2.30 raeburn 1728: #need to copy the db contents to a new one, unless this is a move.
1729: my %info = (
1730: src => $url,
1731: cdom => $coursedom,
1732: cnum => $coursenum,
1.484.2.76 raeburn 1733: );
1734: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1735: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1736: $fromothercrs = 1;
1737: $info{'cdom'} = $srcdom{$suffix};
1738: $info{'cnum'} = $srcnum{$suffix};
1739: }
1740: }
1741: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1742: my (%lockerr,$msg);
1743: my ($newurl,$result,$errtext) =
1744: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1745: if ($result eq 'ok') {
1746: $url = $newurl;
1747: $title=&mt('Copy of').' '.$title;
1748: } else {
1749: if ($prefix eq 'smppg') {
1750: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1751: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1752: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.30 raeburn 1753: }
1754: $results{$suffix} = $result;
1755: $msgerrs{$suffix} = $msg;
1756: $lockerrs{$suffix} = $lockerr{$prefix};
1757: next;
1758: }
1759: if ($lockerr{$prefix}) {
1760: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1761: }
1.484.2.7 raeburn 1762: }
1.484.2.30 raeburn 1763: }
1764: $title = &LONCAPA::map::qtunescape($title);
1765: my $ext='false';
1766: if ($url=~m{^http(|s)://}) { $ext='true'; }
1767: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1768: if ($folder !~ /^supplemental/) {
1769: (undef,undef,$title) =
1770: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1771: }
1772: } else {
1773: if ($folder=~/^supplemental/) {
1774: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1775: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1776: }
1777: }
1.484.2.7 raeburn 1778:
1779: # For uploaded files (excluding pages/sequences) path in copied file is changed
1780: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1781: # courses.
1782:
1.484.2.30 raeburn 1783: unless ($is_map{$suffix}) {
1784: my $newidx;
1.329 droeschl 1785: # Now insert the URL at the bottom
1.484.2.30 raeburn 1786: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1787: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1788: my $relpath = $1;
1789: if ($relpath ne '') {
1790: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1791: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1792: my $newprefix = $newloc;
1793: if ($newloc eq 'default') {
1794: $newprefix = 'docs';
1795: }
1796: if ($newdocsdir eq '') {
1797: $newdocsdir = 'default';
1798: }
1799: if (($prefixchg{$suffix}) ||
1800: ($srcdom{$suffix} ne $coursedom) ||
1801: ($srcnum{$suffix} ne $coursenum) ||
1802: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1803: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1804: $url =
1805: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1806: &Apache::lonnet::getfile($oldurl));
1807: if ($url eq '/adm/notfound.html') {
1808: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1809: next;
1810: } else {
1811: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1812: $newsubpath =~ s{/+$}{/};
1813: $docmoves{$oldurl} = $newsubpath;
1814: }
1.484.2.7 raeburn 1815: }
1816: }
1.484.2.82 raeburn 1817: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1818: my $template = $1;
1819: if ($newidx) {
1820: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1821: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1822: }
1.484.2.7 raeburn 1823: }
1.484.2.30 raeburn 1824: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1825: ':'.$ext.':normal:res';
1826: push(@LONCAPA::map::order,$newidx);
1827: # Store the result
1828: my ($errtext,$fatal) =
1829: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1830: if ($fatal) {
1831: $save_err .= $errtext;
1832: $allresult = 'fail';
1.484.2.7 raeburn 1833: }
1.329 droeschl 1834: }
1.484.2.30 raeburn 1835:
1.484.2.82 raeburn 1836: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1837: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 1838: unless ($allresult eq 'fail') {
1839: my %updated = (
1840: rewrites => \%rewrites,
1841: zombies => \%zombies,
1842: removefrommap => \%removefrommap,
1843: removeparam => \%removeparam,
1844: dbcopies => \%dbcopies,
1.484.2.82 raeburn 1845: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 1846: retitles => \%retitles,
1847: );
1848: my %info = (
1849: newsubdir => \%newsubdir,
1850: params => \%params,
1851: );
1852: if ($prefixchg{$suffix}) {
1853: $info{'before'} = $before{$prefixchg{$suffix}};
1854: $info{'after'} = $after{$prefixchg{$suffix}};
1855: }
1856: my %moves = (
1857: copies => \%copies,
1858: docmoves => \%docmoves,
1859: mapmoves => \%mapmoves,
1860: );
1861: (my $result,$msgs{$suffix},my $lockerror) =
1862: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1863: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1864: $url,'paste');
1865: $lockerrors .= $lockerror;
1866: if ($result eq 'ok') {
1867: if ($is_map{$suffix}) {
1868: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1869: $folder.'.'.$container);
1870: if ($fatal) {
1871: $allresult = 'failread';
1872: } else {
1873: if ($#LONCAPA::map::order<1) {
1874: my $idx=&LONCAPA::map::getresidx();
1875: if ($idx<=0) { $idx=1; }
1876: $LONCAPA::map::order[0]=$idx;
1877: $LONCAPA::map::resources[$idx]='';
1878: }
1879: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1880: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1881: ':'.$ext.':normal:res';
1882: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 1883:
1884: # Store the result
1.484.2.30 raeburn 1885: my ($errtext,$fatal) =
1886: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1887: if ($fatal) {
1888: $save_err .= $errtext;
1889: $allresult = 'failstore';
1890: }
1891: }
1892: }
1893: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1894: push(@toclear,$suffix);
1895: }
1896: }
1.329 droeschl 1897: }
1898: }
1.484.2.30 raeburn 1899: &clear_from_buffer(\@toclear,\@currpaste);
1900: my $msgsarray;
1901: foreach my $suffix (keys(%msgs)) {
1902: if (ref($msgs{$suffix}) eq 'ARRAY') {
1903: $msgsarray .= join(',',@{$msgs{$suffix}});
1904: }
1905: }
1906: return ($allresult,$save_err,$msgsarray,$lockerrors);
1907: }
1908:
1909: sub do_buffer_empty {
1910: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1911: if (@currpaste == 0) {
1912: return &mt('Clipboard is already empty');
1913: }
1914: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1915: if (@toclear == 0) {
1916: return &mt('Nothing selected to clear from clipboard');
1917: }
1918: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1919: if ($numdel) {
1920: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1921: } else {
1922: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 1923: }
1.484.2.30 raeburn 1924: return;
1925: }
1926:
1927: sub clear_from_buffer {
1928: my ($toclear,$currpaste) = @_;
1929: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1930: my %pastebuffer;
1931: map { $pastebuffer{$_} = 1; } @{$currpaste};
1932: my $numdel = 0;
1933: foreach my $suffix (@{$toclear}) {
1934: next if ($suffix =~ /\D/);
1935: next unless (exists($pastebuffer{$suffix}));
1936: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1937: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1938: delete($pastebuffer{$suffix});
1939: $numdel ++;
1940: }
1941: }
1942: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1943: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1944: return $numdel;
1.484.2.7 raeburn 1945: }
1946:
1947: sub get_newmap_url {
1948: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1949: $titleref,$allmaps,$newurls) = @_;
1950: my $newurl;
1951: if ($url=~ m{^/uploaded/}) {
1952: $$titleref=&mt('Copy of').' '.$$titleref;
1953: }
1954: my $now = time;
1955: my $suffix=$$.int(rand(100)).$now;
1956: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1957: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1958: my $path = $1;
1959: my $prefix = $2;
1960: my $ancestor = $3;
1961: if (length($ancestor) > 10) {
1962: $ancestor = substr($ancestor,-10,10);
1963: }
1964: my $newid;
1965: if ($prefixchg) {
1966: if ($folder =~ /^supplemental/) {
1967: $prefix =~ s/^default/supplemental/;
1968: } else {
1969: $prefix =~ s/^supplemental/default/;
1970: }
1971: }
1972: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1973: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1974: } else {
1975: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1976: }
1977: my $counter = 0;
1978: my $is_unique = &uniqueness_check($newurl);
1979: if ($folder =~ /^default/) {
1980: if ($allmaps->{$newurl}) {
1981: $is_unique = 0;
1982: }
1983: }
1984: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1985: $counter ++;
1986: $suffix ++;
1987: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1988: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1989: } else {
1990: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
1991: }
1992: $is_unique = &uniqueness_check($newurl);
1993: }
1994: if ($is_unique) {
1995: $newurls->{$newurl} = 1;
1996: } else {
1997: if ($url=~/\.page$/) {
1998: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
1999: } else {
2000: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2001: }
2002: }
2003: }
2004: return ($newurl);
2005: }
2006:
2007: sub dbcopy {
1.484.2.26 raeburn 2008: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2009: my ($url,$result,$errtext);
2010: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2011: $url = $dbref->{'src'};
1.484.2.26 raeburn 2012: if ($url =~ m{/(smppg|bulletinboard)$}) {
2013: my $prefix = $1;
2014: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2015: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2016: my $db_name;
2017: my $marker = (split(m{/},$url))[4];
2018: $marker=~s/\D//g;
2019: if ($dbref->{'src'} =~ m{/smppg$}) {
2020: $db_name =
2021: &Apache::lonsimplepage::get_db_name($url,$marker,
2022: $dbref->{'cdom'},
2023: $dbref->{'cnum'});
2024: } else {
2025: $db_name = 'bulletinpage_'.$marker;
2026: }
2027: my ($suffix,$freedlock,$error) =
2028: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2029: $coursedom,$coursenum,
2030: 'concat');
2031: if (!$suffix) {
2032: if ($prefix eq 'smppg') {
2033: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2034: } else {
1.484.2.42 raeburn 2035: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2036: }
2037: if ($error) {
2038: $errtext .= '<br />'.$error;
2039: }
2040: } else {
2041: #need to copy the db contents to a new one.
2042: my %contents=&Apache::lonnet::dump($db_name,
2043: $dbref->{'cdom'},
2044: $dbref->{'cnum'});
2045: if (exists($contents{'uploaded.photourl'})) {
2046: my $photo = $contents{'uploaded.photourl'};
2047: my ($subdir,$fname) =
2048: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2049: my $newphoto;
2050: if ($fname ne '') {
2051: my $content = &Apache::lonnet::getfile($photo);
2052: unless ($content eq '-1') {
2053: $env{'form.'.$suffix.'.photourl'} = $content;
2054: $newphoto =
2055: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2056: delete($env{'form.'.$suffix.'.photourl'});
2057: }
2058: }
2059: if ($newphoto =~ m{^/uploaded/}) {
2060: $contents{'uploaded.photourl'} = $newphoto;
2061: }
2062: }
2063: $db_name =~ s{_\d*$ }{_$suffix}x;
2064: $result=&Apache::lonnet::put($db_name,\%contents,
2065: $coursedom,$coursenum);
2066: if ($result eq 'ok') {
2067: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2068: }
2069: }
2070: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2071: $lockerrorsref->{$prefix} =
2072: '<div class="LC_error">'.
2073: &mt('There was a problem removing a lockfile.');
2074: if ($prefix eq 'smppg') {
2075: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2076: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.26 raeburn 2077: } else {
1.484.2.42 raeburn 2078: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2079: }
1.484.2.38 raeburn 2080: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2081: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2082: '</div>';
1.484.2.26 raeburn 2083: }
2084: }
2085: } elsif ($url =~ m{/syllabus$}) {
2086: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2087: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2088: if (($dbref->{'cdom'} ne $coursedom) ||
2089: ($dbref->{'cnum'} ne $coursenum)) {
2090: my %contents=&Apache::lonnet::dump('syllabus',
2091: $dbref->{'cdom'},
2092: $dbref->{'cnum'});
2093: $result=&Apache::lonnet::put('syllabus',\%contents,
2094: $coursedom,$coursenum);
2095: }
2096: }
1.484.2.7 raeburn 2097: }
2098: }
1.484.2.26 raeburn 2099: return ($url,$result,$errtext);
1.329 droeschl 2100: }
2101:
1.484.2.82 raeburn 2102: sub copy_templated_files {
2103: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2104: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2105: my $srccontainer = 'sequence';
2106: if ($srcwaspage) {
2107: $srccontainer = 'page';
2108: }
2109: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2110: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2111: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2112: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2113: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2114: $template.'.problem';
2115: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2116: if ($template eq 'simpleproblem') {
2117: $srcprefix .= '.0.';
2118: my $weightprefix = $newprefix;
2119: $newprefix .= '.0.';
2120: my @simpleprobqtypes = qw(radio option string essay numerical);
2121: my $qtype=$srcparms{$srcprefix.'questiontype'};
2122: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2123: my %newdata = (
2124: $newprefix.'questiontype' => $qtype,
2125: )
2126: foreach my $type (@simpleprobqtypes) {
2127: if ($type eq $qtype) {
2128: $newdata{"$weightprefix.$type.weight"}=1;
2129: } else {
2130: $newdata{"$weightprefix.$type.weight"}=0;
2131: }
2132: }
2133: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2134: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2135: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2136: if ($qtype eq 'numerical') {
2137: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2138: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2139: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2140: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2141: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2142: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2143: unless (defined($maxfoils)) { $maxfoils=10; }
2144: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2145: if ($maxfoils<=0) { $maxfoils=10; }
2146: my $randomize=$srcparms{$srcprefix.'randomize'};
2147: unless (defined($randomize)) { $randomize='yes'; }
2148: unless ($randomize eq 'no') { $randomize='yes'; }
2149: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2150: $newdata{$newprefix.'randomize'} = $randomize;
2151: if ($qtype eq 'option') {
2152: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2153: }
2154: for (my $i=1; $i<=10; $i++) {
2155: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2156: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2157: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2158: }
2159:
2160: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2161: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2162: unless (defined($maxfoils)) { $maxfoils=10; }
2163: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2164: if ($maxfoils<=0) { $maxfoils=10; }
2165: my $randomize=$srcparms{$srcprefix.'randomize'};
2166: unless (defined($randomize)) { $randomize='yes'; }
2167: unless ($randomize eq 'no') { $randomize='yes'; }
2168: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2169: $newdata{$newprefix.'randomize'} = $randomize;
2170: if ($qtype eq 'option') {
2171: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2172: }
2173: for (my $i=1; $i<=10; $i++) {
2174: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2175: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2176: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2177: }
2178: } elsif ($qtype eq 'string') {
2179: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2180: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2181: }
2182: if (keys(%newdata)) {
2183: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2184: $coursenum);
2185: if ($putres eq 'ok') {
2186: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2187: }
2188: }
2189: }
2190: }
2191: }
2192:
1.329 droeschl 2193: sub uniqueness_check {
2194: my ($newurl) = @_;
2195: my $unique = 1;
2196: foreach my $res (@LONCAPA::map::order) {
2197: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2198: $url=&LONCAPA::map::qtescape($url);
2199: if ($newurl eq $url) {
2200: $unique = 0;
1.344 bisitz 2201: last;
1.329 droeschl 2202: }
2203: }
2204: return $unique;
2205: }
2206:
1.484.2.7 raeburn 2207: sub contained_map_check {
2208: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2209: $allmaps) = @_;
2210: my $content = &Apache::lonnet::getfile($url);
2211: unless ($content eq '-1') {
2212: my $parser = HTML::TokeParser->new(\$content);
2213: $parser->attr_encoded(1);
2214: while (my $token = $parser->get_token) {
2215: next if ($token->[0] ne 'S');
2216: if ($token->[1] eq 'resource') {
2217: next if ($token->[2]->{'type'} eq 'zombie');
2218: my $ressrc = $token->[2]->{'src'};
2219: if ($folder =~ /^supplemental/) {
2220: unless (&supp_pasteable($ressrc)) {
2221: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2222: next;
2223: }
2224: }
2225: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2226: if ($1 eq 'uploaded') {
2227: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2228: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2229: } else {
2230: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2231: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2232: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2233: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2234: } else {
2235: $addedmaps->{$ressrc} = [$url];
2236: }
2237: }
2238: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2239: $addedmaps,$hierarchy,$titles,$allmaps);
2240: }
2241: } elsif ($token->[1] eq 'param') {
2242: if ($folder =~ /^supplemental/) {
2243: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2244: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2245: } else {
1.484.2.19 raeburn 2246: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2247: }
2248: }
2249: }
2250: }
2251: }
2252: return;
2253: }
2254:
2255: sub url_paste_fixups {
1.484.2.26 raeburn 2256: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2257: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2258: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2259: my $checktitle;
2260: if (($prefixchg) &&
2261: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2262: $checktitle = 1;
2263: }
2264: my $skip;
2265: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2266: my $mapid = $1.$2;
2267: if ($tomove->{$mapid}) {
2268: $skip = 1;
2269: }
2270: }
2271: my $file = &Apache::lonnet::getfile($oldurl);
2272: return if ($file eq '-1');
2273: my $parser = HTML::TokeParser->new(\$file);
2274: $parser->attr_encoded(1);
2275: my $changed = 0;
2276: while (my $token = $parser->get_token) {
2277: next if ($token->[0] ne 'S');
2278: if ($token->[1] eq 'resource') {
2279: my $ressrc = $token->[2]->{'src'};
2280: next if ($ressrc eq '');
2281: my $id = $token->[2]->{'id'};
2282: my $title = $token->[2]->{'title'};
2283: if ($checktitle) {
2284: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2285: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2286: }
2287: }
2288: next if ($token->[2]->{'type'} eq 'external');
2289: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2290: next if ($skip);
1.484.2.25 raeburn 2291: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2292: $changed = 1;
2293: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2294: my $srcdom = $1;
2295: my $srcnum = $2;
2296: my $rem = $3;
2297: my $newurl;
2298: my $mapname;
2299: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2300: my $prefix = $1;
2301: $mapname = $prefix.$2;
2302: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2303: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2304: $srcdom,$srcnum,$allmaps,$rewrites,
2305: $retitles,$copies,$dbcopies,$zombies,
2306: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2307: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2308: next;
2309: } else {
2310: ($newurl,my $error) =
2311: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2312: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2313: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2314: $newsubdir->{$ressrc} = $1;
2315: }
2316: if ($error) {
2317: next;
2318: }
2319: }
2320: }
2321: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2322: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2323:
1.484.2.7 raeburn 2324: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2325: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2326: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2327: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2328: $cnum,$srcdom,$srcnum,$allmaps,
2329: $rewrites,$retitles,$copies,$dbcopies,
2330: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2331: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2332: $mapmoves->{$ressrc} = 1;
2333: }
2334: $changed = 1;
2335: } else {
1.484.2.25 raeburn 2336: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2337: $copies->{$oldurl}{$ressrc} = $id;
2338: $changed = 1;
2339: }
2340: }
1.484.2.26 raeburn 2341: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2342: next if ($skip);
1.484.2.7 raeburn 2343: my $srcdom = $1;
2344: my $srcnum = $2;
2345: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2346: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2347: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2348: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2349: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2350: $changed = 1;
2351: }
2352: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2353: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2354: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2355: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2356: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2357: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2358: $changed = 1;
2359: }
1.484.2.82 raeburn 2360: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2361: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2362: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2363: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2364: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2365: }
1.484.2.7 raeburn 2366: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2367: next if ($skip);
2368: my $srcdom = $1;
2369: my $srcnum = $2;
2370: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2371: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2372: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2373: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2374: $changed = 1;
2375: }
2376: }
2377: } elsif ($token->[1] eq 'param') {
2378: next if ($skip);
1.484.2.19 raeburn 2379: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2380: if ($to ne '') {
2381: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2382: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2383: } else {
2384: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2385: }
2386: }
2387: }
2388: }
2389: return $changed;
2390: }
2391:
2392: sub apply_fixups {
1.484.2.23 raeburn 2393: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2394: $oldurl,$url,$caller) = @_;
2395: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2396: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2397: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2398: if (ref($updated) eq 'HASH') {
2399: if (ref($updated->{'rewrites'}) eq 'HASH') {
2400: %rewrites = %{$updated->{'rewrites'}};
2401: }
2402: if (ref($updated->{'zombies'}) eq 'HASH') {
2403: %zombies = %{$updated->{'zombies'}};
2404: }
2405: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2406: %removefrommap = %{$updated->{'removefrommap'}};
2407: }
2408: if (ref($updated->{'removeparam'}) eq 'HASH') {
2409: %removeparam = %{$updated->{'removeparam'}};
2410: }
2411: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2412: %dbcopies = %{$updated->{'dbcopies'}};
2413: }
2414: if (ref($updated->{'retitles'}) eq 'HASH') {
2415: %retitles = %{$updated->{'retitles'}};
2416: }
1.484.2.82 raeburn 2417: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2418: %resdatacopy = %{$updated->{'resdatacopy'}};
2419: }
1.484.2.23 raeburn 2420: }
2421: if (ref($info) eq 'HASH') {
2422: if (ref($info->{'newsubdir'}) eq 'HASH') {
2423: %newsubdir = %{$info->{'newsubdir'}};
2424: }
2425: if (ref($info->{'params'}) eq 'HASH') {
2426: %params = %{$info->{'params'}};
2427: }
2428: if (ref($info->{'before'}) eq 'HASH') {
2429: %before = %{$info->{'before'}};
2430: }
2431: if (ref($info->{'after'}) eq 'HASH') {
2432: %after = %{$info->{'after'}};
2433: }
2434: }
2435: if (ref($moves) eq 'HASH') {
2436: if (ref($moves->{'copies'}) eq 'HASH') {
2437: %copies = %{$moves->{'copies'}};
2438: }
2439: if (ref($moves->{'docmoves'}) eq 'HASH') {
2440: %docmoves = %{$moves->{'docmoves'}};
2441: }
2442: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2443: %mapmoves = %{$moves->{'mapmoves'}};
2444: }
2445: }
2446: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2447: my @allcopies;
1.484.2.23 raeburn 2448: if (exists($copies{$key})) {
2449: if (ref($copies{$key}) eq 'HASH') {
2450: my %added;
2451: foreach my $innerkey (keys(%{$copies{$key}})) {
2452: if (($innerkey ne '') && (!$added{$innerkey})) {
2453: push(@allcopies,$innerkey);
2454: $added{$innerkey} = 1;
2455: }
1.484.2.7 raeburn 2456: }
1.484.2.23 raeburn 2457: undef(%added);
1.484.2.7 raeburn 2458: }
2459: }
2460: if ($key eq $oldurl) {
1.484.2.23 raeburn 2461: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2462: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2463: push(@allcopies,$oldurl);
2464: }
2465: }
2466: }
2467: if (@allcopies > 0) {
2468: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2469: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2470: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2471: if ($fname ne '') {
2472: my $content = &Apache::lonnet::getfile($item);
2473: unless ($content eq '-1') {
2474: my $storefn;
1.484.2.23 raeburn 2475: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2476: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2477: } else {
2478: $storefn = $relpath;
2479: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2480: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2481: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2482: }
1.484.2.23 raeburn 2483: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2484: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2485: }
2486: }
2487: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2488: my $copyurl =
1.484.2.7 raeburn 2489: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2490: $storefn.$fname,$content);
2491: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2492: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2493: return &mt('Paste failed: an error occurred copying the file.');
2494: } elsif (ref($errors) eq 'HASH') {
2495: $errors->{$item} = 1;
2496: }
2497: }
2498: }
2499: }
2500: }
2501: }
2502: }
1.484.2.23 raeburn 2503: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2504: my $storefn=$key;
2505: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2506: if ($prefixchg && $before{'map'} && $after{'map'}) {
2507: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2508: }
1.484.2.23 raeburn 2509: if ($newsubdir{$key}) {
2510: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2511: }
2512: my $mapcontent = &Apache::lonnet::getfile($key);
2513: if ($mapcontent eq '-1') {
2514: if (ref($errors) eq 'HASH') {
2515: $errors->{$key} = 1;
2516: }
2517: } else {
2518: my $newmap =
2519: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2520: $mapcontent);
2521: if ($newmap eq '/adm/notfound.html') {
2522: if (ref($errors) eq 'HASH') {
2523: $errors->{$key} = 1;
2524: }
2525: }
2526: }
2527: }
2528: my %updates;
2529: if ($is_map) {
1.484.2.23 raeburn 2530: if (ref($updated) eq 'HASH') {
2531: foreach my $type (keys(%{$updated})) {
2532: if (ref($updated->{$type}) eq 'HASH') {
2533: foreach my $key (keys(%{$updated->{$type}})) {
2534: $updates{$key} = 1;
2535: }
2536: }
2537: }
1.484.2.7 raeburn 2538: }
2539: foreach my $key (keys(%updates)) {
2540: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2541: if (ref($rewrites{$key}) eq 'HASH') {
2542: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2543: }
1.484.2.23 raeburn 2544: if (ref($retitles{$key}) eq 'HASH') {
2545: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2546: }
1.484.2.23 raeburn 2547: if (ref($removefrommap{$key}) eq 'HASH') {
2548: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2549: }
1.484.2.23 raeburn 2550: if (ref($removeparam{$key}) eq 'HASH') {
2551: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2552: }
1.484.2.23 raeburn 2553: if (ref($zombies{$key}) eq 'HASH') {
2554: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2555: }
1.484.2.23 raeburn 2556: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2557: foreach my $idx (keys(%{$dbcopies{$key}})) {
2558: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2559: my ($newurl,$result,$errtext) =
2560: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2561: if ($result eq 'ok') {
2562: $newdb{$idx} = $newurl;
2563: } elsif (ref($errors) eq 'HASH') {
2564: $errors->{$key} = 1;
2565: }
2566: push(@msgs,$errtext);
2567: }
1.484.2.7 raeburn 2568: }
2569: }
1.484.2.82 raeburn 2570: if (ref($resdatacopy{$key}) eq 'HASH') {
2571: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2572: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2573: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2574: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2575: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2576: my $template = $1;
2577: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2578: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2579: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2580: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2581: unless ($gotnewmapname) {
2582: ($newmapname) = ($key =~ m{/([^/]+)$});
2583: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2584: if ($newsubdir{$key}) {
2585: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2586: }
2587: $gotnewmapname = 1;
2588: }
2589: my $srcmapinfo = $srcfolder.':'.$idx;
2590: if ($srccontainer eq 'page') {
2591: $srcmapinfo .= ':1';
2592: }
2593: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2594: $cnum,$template,$idx,$newmapname);
2595: }
2596: }
2597: }
2598: }
2599: }
1.484.2.23 raeburn 2600: if (ref($params{$key}) eq 'HASH') {
2601: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2602: }
2603: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2604: if ($fatal) {
1.484.2.26 raeburn 2605: return ($errtext);
1.484.2.7 raeburn 2606: }
2607: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2608: if (defined($LONCAPA::map::zombies[$i])) {
2609: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2610: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2611: undef($LONCAPA::map::zombies[$i]);
2612: }
2613: }
2614: }
1.484.2.77 raeburn 2615: my $total = scalar(@LONCAPA::map::order) - 1;
2616: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2617: my $idx = $LONCAPA::map::order[$i];
2618: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2619: my $changed;
1.484.2.23 raeburn 2620: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2621: if ((exists($toremove{$idx})) &&
2622: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2623: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2624: if (ref($currparam{$idx}) eq 'ARRAY') {
2625: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2626: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2627: }
2628: }
2629: next;
2630: }
2631: my $origsrc = $src;
1.484.2.25 raeburn 2632: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2633: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2634: $changed = 1;
2635: }
2636: }
1.484.2.25 raeburn 2637: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2638: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2639: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2640: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2641: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2642: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2643: } else {
1.484.2.23 raeburn 2644: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2645: }
2646: }
1.484.2.25 raeburn 2647: if ($origsrc =~ /\.(page|sequence)$/) {
2648: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2649: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2650: }
1.484.2.25 raeburn 2651: } elsif ($newsubdir{$key}) {
2652: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2653: }
2654: }
2655: $changed = 1;
1.484.2.26 raeburn 2656: } elsif ($newdb{$idx} ne '') {
2657: $src = $newdb{$idx};
1.484.2.7 raeburn 2658: $changed = 1;
2659: }
2660: if ($changed) {
1.484.2.30 raeburn 2661: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2662: }
2663: }
2664: }
2665: foreach my $idx (keys(%remparam)) {
2666: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2667: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2668: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2669: }
2670: }
2671: }
1.484.2.26 raeburn 2672: if (values(%lockerrors) > 0) {
2673: $lockmsg = join('<br />',values(%lockerrors));
2674: }
1.484.2.7 raeburn 2675: my $storefn;
2676: if ($key eq $oldurl) {
2677: $storefn = $url;
2678: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2679: } else {
2680: $storefn = $key;
2681: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2682: if ($prefixchg && $before{'map'} && $after{'map'}) {
2683: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2684: }
1.484.2.23 raeburn 2685: if ($newsubdir{$key}) {
2686: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2687: }
2688: }
2689: my $report;
2690: if ($folder !~ /^supplemental/) {
2691: $report = 1;
2692: }
1.484.2.20 raeburn 2693: (my $outtext,$errtext) =
1.484.2.7 raeburn 2694: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2695: if ($errtext) {
1.484.2.23 raeburn 2696: if ($caller eq 'paste') {
1.484.2.26 raeburn 2697: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2698: }
1.484.2.7 raeburn 2699: }
2700: }
2701: }
1.484.2.26 raeburn 2702: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2703: }
2704:
2705: sub copy_dependencies {
2706: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2707: my $content;
2708: if (ref($contentref)) {
2709: $content = $$contentref;
2710: } else {
2711: $content = &Apache::lonnet::getfile($item);
2712: }
2713: unless ($content eq '-1') {
2714: my $mm = new File::MMagic;
2715: my $mimetype = $mm->checktype_contents($content);
2716: if ($mimetype eq 'text/html') {
2717: my (%allfiles,%codebase,$state);
2718: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2719: if ($res eq 'ok') {
2720: my ($numexisting,$numpathchanges,$existing);
2721: (undef,$numexisting,$numpathchanges,$existing) =
2722: &Apache::loncommon::ask_for_embedded_content(
2723: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2724: {'error_on_invalid_names' => 1,
2725: 'ignore_remote_references' => 1,
2726: 'docs_url' => $item,
2727: 'context' => 'paste'});
2728: if ($numexisting > 0) {
2729: if (ref($existing) eq 'HASH') {
2730: foreach my $dep (keys(%{$existing})) {
2731: my $depfile = $dep;
2732: unless ($depfile =~ m{^\Q$relpath\E}) {
2733: $depfile = $relpath.$dep;
2734: }
2735: my $depcontent = &Apache::lonnet::getfile($depfile);
2736: unless ($depcontent eq '-1') {
2737: my $storedep = $dep;
2738: $storedep =~ s{^\Q$relpath\E}{};
2739: my $dep_url =
2740: &Apache::lonclonecourse::writefile(
2741: $env{'request.course.id'},
2742: $storefn.$storedep,$depcontent);
2743: if ($dep_url eq '/adm/notfound.html') {
2744: if (ref($errors) eq 'HASH') {
2745: $errors->{$depfile} = 1;
2746: }
2747: } else {
2748: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2749: }
2750: }
2751: }
2752: }
2753: }
2754: }
2755: }
2756: }
2757: return;
2758: }
2759:
1.329 droeschl 2760: my %parameter_type = ( 'randompick' => 'int_pos',
2761: 'hiddenresource' => 'string_yesno',
2762: 'encrypturl' => 'string_yesno',
2763: 'randomorder' => 'string_yesno',);
2764: my $valid_parameters_re = join('|',keys(%parameter_type));
2765: # set parameters
2766: sub update_parameter {
1.484.2.29 raeburn 2767: if ($env{'form.changeparms'} eq 'all') {
2768: my (@allidx,@allmapidx,%allchecked,%currchecked);
2769: %allchecked = (
2770: 'hiddenresource' => {},
2771: 'encrypturl' => {},
2772: 'randompick' => {},
2773: 'randomorder' => {},
2774: );
2775: foreach my $which (keys(%allchecked)) {
2776: $env{'form.all'.$which} =~ s/,$//;
2777: if ($which eq 'randompick') {
2778: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2779: my ($res,$value) = split(/:/,$item);
2780: if ($value =~ /^\d+$/) {
2781: $allchecked{$which}{$res} = $value;
2782: }
2783: }
2784: } else {
1.484.2.30 raeburn 2785: if ($env{'form.all'.$which}) {
2786: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2787: }
1.484.2.29 raeburn 2788: }
2789: }
2790: my $haschanges = 0;
2791: foreach my $res (@LONCAPA::map::order) {
2792: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2793: $name=&LONCAPA::map::qtescape($name);
2794: $url=&LONCAPA::map::qtescape($url);
2795: next unless ($name && $url);
2796: my $is_map;
2797: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2798: $is_map = 1;
2799: }
2800: foreach my $which (keys(%allchecked)) {
2801: if (($which eq 'randompick' || $which eq 'randomorder')) {
2802: next if (!$is_map);
2803: }
2804: my $oldvalue = 0;
2805: my $newvalue = 0;
2806: if ($allchecked{$which}{$res}) {
2807: $newvalue = $allchecked{$which}{$res};
2808: }
2809: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2810: if ($which eq 'randompick') {
2811: if ($current =~ /^(\d+)$/) {
2812: $oldvalue = $1;
2813: }
2814: } else {
2815: if ($current =~ /^yes$/i) {
2816: $oldvalue = 1;
2817: }
2818: }
2819: if ($oldvalue ne $newvalue) {
2820: $haschanges = 1;
2821: if ($newvalue) {
2822: my $storeval = 'yes';
2823: if ($which eq 'randompick') {
2824: $storeval = $newvalue;
2825: }
2826: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2827: $storeval,
2828: $parameter_type{$which});
2829: &remember_parms($res,$which,'set',$storeval);
2830: } elsif ($oldvalue) {
2831: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2832: &remember_parms($res,$which,'del');
2833: }
2834: }
2835: }
2836: }
2837: return $haschanges;
1.329 droeschl 2838: } else {
1.484.2.59 raeburn 2839: my $haschanges = 0;
2840: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 2841:
1.484.2.29 raeburn 2842: my $which = $env{'form.changeparms'};
2843: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 2844: my $oldvalue = 0;
2845: my $newvalue = 0;
2846: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2847: if ($which eq 'randompick') {
2848: if ($current =~ /^(\d+)$/) {
2849: $oldvalue = $1;
2850: }
2851: } elsif ($current =~ /^yes$/i) {
2852: $oldvalue = 1;
2853: }
1.484.2.29 raeburn 2854: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 2855: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2856: : 1;
1.484.2.29 raeburn 2857: }
1.484.2.59 raeburn 2858: if ($oldvalue ne $newvalue) {
2859: $haschanges = 1;
2860: if ($newvalue) {
2861: my $storeval = 'yes';
2862: if ($which eq 'randompick') {
2863: $storeval = $newvalue;
2864: }
2865: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2866: $parameter_type{$which});
2867: &remember_parms($idx,$which,'set',$storeval);
2868: } else {
2869: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2870: &remember_parms($idx,$which,'del');
2871: }
2872: }
2873: return $haschanges;
1.329 droeschl 2874: }
1.484.2.59 raeburn 2875: return;
1.329 droeschl 2876: }
2877:
2878: sub handle_edit_cmd {
2879: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 2880: if ($env{'form.cmd'} eq '') {
2881: return 0;
2882: }
1.329 droeschl 2883: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2884:
2885: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2886: my ($title, $url, @rrest) = split(':', $ratstr);
2887:
1.484.2.30 raeburn 2888: if ($cmd eq 'remove') {
1.329 droeschl 2889: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2890: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2891: &Apache::lonnet::removeuploadedurl($url);
2892: } else {
2893: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2894: }
2895: splice(@LONCAPA::map::order, $idx, 1);
2896:
2897: } elsif ($cmd eq 'cut') {
2898: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2899: splice(@LONCAPA::map::order, $idx, 1);
2900:
1.344 bisitz 2901: } elsif ($cmd eq 'up'
1.329 droeschl 2902: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2903: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2904:
2905: } elsif ($cmd eq 'down'
2906: && defined($LONCAPA::map::order[$idx+1])) {
2907: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2908:
2909: } elsif ($cmd eq 'rename') {
2910: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2911: if ($comment=~/\S/) {
2912: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2913: $comment.':'.join(':', $url, @rrest);
2914: }
2915: # Devalidate title cache
2916: my $renamed_url=&LONCAPA::map::qtescape($url);
2917: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 2918:
1.329 droeschl 2919: } else {
2920: return 0;
2921: }
2922: return 1;
2923: }
2924:
2925: sub editor {
1.458 raeburn 2926: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.80 raeburn 2927: $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,
2928: $hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 2929: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2930: if ($allowed) {
2931: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2932: $is_random_order,$container) =
2933: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2934: $r->print($breadcrumbtrail);
2935: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2936: $container = 'page';
2937: } else {
2938: $container = 'sequence';
2939: }
1.484 raeburn 2940:
1.484.2.21 raeburn 2941: my $jumpto;
2942:
2943: unless ($supplementalflag) {
1.484.2.32 raeburn 2944: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 2945: }
1.484 raeburn 2946:
2947: unless ($allowed) {
2948: $randompick = -1;
2949: }
2950:
1.484.2.67 raeburn 2951: my ($errtext,$fatal);
2952: if (($folder eq '') && (!$supplementalflag)) {
2953: if (@LONCAPA::map::order) {
2954: undef(@LONCAPA::map::order);
2955: undef(@LONCAPA::map::resources);
2956: undef(@LONCAPA::map::resparms);
2957: undef(@LONCAPA::map::zombies);
2958: }
2959: $folder = 'default';
2960: $container = 'sequence';
2961: } else {
2962: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2963: $folder.'.'.$container);
2964: return $errtext if ($fatal);
2965: }
1.329 droeschl 2966:
2967: if ($#LONCAPA::map::order<1) {
2968: my $idx=&LONCAPA::map::getresidx();
2969: if ($idx<=0) { $idx=1; }
2970: $LONCAPA::map::order[0]=$idx;
2971: $LONCAPA::map::resources[$idx]='';
2972: }
1.364 bisitz 2973:
1.329 droeschl 2974: # ------------------------------------------------------------ Process commands
2975:
2976: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 2977: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 2978: # set parameters and change order
2979: &snapshotbefore();
2980:
2981: if (&update_parameter()) {
1.484.2.59 raeburn 2982: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 2983: return $errtext if ($fatal);
2984: }
2985:
2986: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2987: # change order
2988: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
2989: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
2990:
2991: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2992: return $errtext if ($fatal);
2993: }
1.364 bisitz 2994:
1.329 droeschl 2995: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 2996: my %paste_errors;
1.484.2.26 raeburn 2997: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 2998: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
2999: \%paste_errors);
1.484.2.30 raeburn 3000: if (ref($pastemsgarray) eq 'ARRAY') {
3001: if (@{$pastemsgarray} > 0) {
3002: $r->print('<p class="LC_info">'.
3003: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3004: '</p>');
3005: }
1.484.2.30 raeburn 3006: }
3007: if ($lockerror) {
3008: $r->print('<p class="LC_error">'.
3009: $lockerror.
3010: '</p>');
3011: }
3012: if ($save_error ne '') {
3013: return $save_error;
3014: }
3015: if ($paste_res) {
3016: my %errortext = &Apache::lonlocal::texthash (
3017: fail => 'Storage of folder contents failed',
3018: failread => 'Reading folder contents failed',
3019: failstore => 'Storage of folder contents failed',
3020: );
3021: if ($errortext{$paste_res}) {
3022: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3023: }
1.329 droeschl 3024: }
1.484.2.7 raeburn 3025: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3026: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3027: &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".
3028: '<ul>'."\n");
3029: foreach my $key (sort(keys(%paste_errors))) {
3030: $r->print('<li>'.$key.'</li>'."\n");
3031: }
3032: $r->print('</ul></p>'."\n");
3033: }
1.484.2.30 raeburn 3034: } elsif ($env{'form.clearmarked'}) {
3035: my $output = &do_buffer_empty();
3036: if ($output) {
3037: $r->print('<p class="LC_info">'.$output.'</p>');
3038: }
3039: }
1.329 droeschl 3040:
3041: $r->print($upload_output);
3042:
1.484.2.30 raeburn 3043: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3044: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3045: my $contentchg;
1.484.2.58 raeburn 3046: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3047: $contentchg = 1;
3048: }
3049: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3050: return $errtext if ($fatal);
3051: }
1.484.2.30 raeburn 3052:
3053: # Cut, copy and/or remove multiple resources
3054: if ($env{'form.multichange'}) {
3055: my %allchecked = (
3056: cut => {},
3057: remove => {},
3058: );
3059: my $needsupdate;
3060: foreach my $which (keys(%allchecked)) {
3061: $env{'form.multi'.$which} =~ s/,$//;
3062: if ($env{'form.multi'.$which}) {
3063: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3064: if (ref($allchecked{$which}) eq 'HASH') {
3065: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3066: }
3067: }
3068: }
3069: if ($needsupdate) {
3070: my $haschanges = 0;
3071: my %curr_groups = &Apache::longroup::coursegroups();
3072: my $total = scalar(@LONCAPA::map::order) - 1;
3073: for (my $i=$total; $i>=0; $i--) {
3074: my $res = $LONCAPA::map::order[$i];
3075: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3076: $name=&LONCAPA::map::qtescape($name);
3077: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3078: next unless $url;
1.484.2.30 raeburn 3079: my %denied =
3080: &action_restrictions($coursenum,$coursedom,$url,
3081: $env{'form.folderpath'},\%curr_groups);
3082: foreach my $which (keys(%allchecked)) {
3083: next if ($denied{$which});
3084: next unless ($allchecked{$which}{$res});
3085: if ($which eq 'remove') {
3086: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3087: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3088: &Apache::lonnet::removeuploadedurl($url);
3089: } else {
3090: &LONCAPA::map::makezombie($res);
3091: }
3092: splice(@LONCAPA::map::order,$i,1);
3093: $haschanges ++;
3094: } elsif ($which eq 'cut') {
3095: &LONCAPA::map::makezombie($res);
3096: splice(@LONCAPA::map::order,$i,1);
3097: $haschanges ++;
3098: }
3099: }
3100: }
3101: if ($haschanges) {
3102: ($errtext,$fatal) =
3103: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3104: return $errtext if ($fatal);
3105: }
3106: }
3107: }
3108:
1.329 droeschl 3109: # Group import/search
3110: if ($env{'form.importdetail'}) {
3111: my @imports;
3112: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3113: if (defined($item)) {
3114: my ($name,$url,$residx)=
1.484.2.26 raeburn 3115: map { &unescape($_); } split(/\=/,$item);
3116: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3117: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3118: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3119: if ($locknotfreed) {
3120: $r->print($locknotfreed);
3121: }
3122: if ($suffix) {
1.484.2.19 raeburn 3123: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3124: } else {
3125: return $errortxt;
3126: }
1.484.2.26 raeburn 3127: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3128: my $type = $1;
3129: my ($suffix,$errortxt,$locknotfreed) =
3130: &new_timebased_suffix($coursedom,$coursenum,$type);
3131: if ($locknotfreed) {
3132: $r->print($locknotfreed);
3133: }
3134: if ($suffix) {
3135: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3136: } else {
3137: return $errortxt;
3138: }
1.484.2.27 raeburn 3139: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3140: if ($supplementalflag) {
3141: next unless ($1 eq 'supplemental');
3142: if ($folder eq 'supplemental') {
3143: next unless ($2 eq 'default');
3144: } else {
3145: next unless ($folder eq 'supplemental_'.$2);
3146: }
3147: } else {
3148: next unless ($1 eq 'docs');
3149: if ($folder eq 'default') {
3150: next unless ($2 eq 'default');
3151: } else {
3152: next unless ($folder eq 'default_'.$2);
3153: }
3154: }
1.484.2.15 raeburn 3155: }
1.329 droeschl 3156: push(@imports, [$name, $url, $residx]);
3157: }
3158: }
1.484.2.23 raeburn 3159: ($errtext,$fatal,my $fixuperrors) =
3160: &group_import($coursenum, $coursedom, $folder,$container,
3161: 'londocs',@imports);
1.329 droeschl 3162: return $errtext if ($fatal);
1.484.2.23 raeburn 3163: if ($fixuperrors) {
3164: $r->print($fixuperrors);
3165: }
1.329 droeschl 3166: }
3167: # Loading a complete map
3168: if ($env{'form.loadmap'}) {
3169: if ($env{'form.importmap'}=~/\w/) {
3170: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3171: my ($title,$url,$ext,$type)=split(/\:/,$res);
3172: my $idx=&LONCAPA::map::getresidx($url);
3173: $LONCAPA::map::resources[$idx]=$res;
3174: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3175: }
3176: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3177: $folder.'.'.$container,1);
1.329 droeschl 3178: return $errtext if ($fatal);
3179: } else {
3180: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3181:
1.329 droeschl 3182: }
3183: }
3184: &log_differences($plain);
3185: }
3186: # ---------------------------------------------------------------- End commands
3187: # ---------------------------------------------------------------- Print screen
3188: my $idx=0;
3189: my $shown=0;
3190: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3191: $r->print('<div class="LC_Box">'.
1.432 raeburn 3192: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3193: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3194: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3195: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3196: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3197: '</ol>');
1.381 bisitz 3198: if ($randompick>=0) {
3199: $r->print('<p class="LC_warning">'
3200: .&mt('Caution: this folder is set to randomly pick a subset'
3201: .' of resources. Adding or removing resources from this'
3202: .' folder will change the set of resources that the'
3203: .' students see, resulting in spurious or missing credit'
3204: .' for completed problems, not limited to ones you'
3205: .' modify. Do not modify the contents of this folder if'
3206: .' it is in active student use.')
3207: .'</p>'
3208: );
3209: }
3210: if ($is_random_order) {
3211: $r->print('<p class="LC_warning">'
3212: .&mt('Caution: this folder is set to randomly order its'
3213: .' contents. Adding or removing resources from this folder'
3214: .' will change the order of resources shown.')
3215: .'</p>'
3216: );
3217: }
3218: $r->print('</div>');
1.364 bisitz 3219: }
1.381 bisitz 3220:
1.484.2.30 raeburn 3221: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3222: %filters = (
3223: canremove => [],
3224: cancut => [],
3225: cancopy => [],
3226: hiddenresource => [],
3227: encrypturl => [],
3228: randomorder => [],
3229: randompick => [],
3230: );
3231: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3232: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3233: foreach my $res (@LONCAPA::map::order) {
3234: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3235: $name=&LONCAPA::map::qtescape($name);
3236: $url=&LONCAPA::map::qtescape($url);
3237: unless ($name) { $name=(split(/\//,$url))[-1]; }
3238: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3239: push(@allidx,$res);
3240: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3241: push(@allmapidx,$res);
3242: }
1.484.2.67 raeburn 3243:
1.381 bisitz 3244: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3245: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3246: $pathitem,$supplementalflag,$container,
1.484.2.70 raeburn 3247: \%filters,\%curr_groups,$canedit,
1.484.2.80 raeburn 3248: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3249: $idx++;
3250: $shown++;
1.329 droeschl 3251: }
1.424 onken 3252: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3253:
1.484.2.30 raeburn 3254: my $need_save;
1.484.2.67 raeburn 3255: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3256: my $toolslink;
1.484.2.67 raeburn 3257: if ($allowed) {
1.484.2.31 raeburn 3258: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3259: .&Apache::loncommon::help_open_menu('Navigation Screen',
3260: 'Navigation_Screen',undef,'RAT')
3261: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3262: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3263: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3264: .'id="LC_content_toolbar_edittoplevel" '
3265: .'class="LC_toolbarItem" '
3266: .'title="'.&mt('Supplemental Content Editor').'">'
3267: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3268: }
1.484.2.19 raeburn 3269: if ($shown) {
3270: if ($allowed) {
3271: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3272: .&Apache::loncommon::start_data_table(undef,'contentlist')
3273: .&Apache::loncommon::start_data_table_header_row()
3274: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3275: .'<th colspan="2">'.&mt('Actions').'</th>'
3276: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3277: if ($folder !~ /^supplemental/) {
3278: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3279: }
1.484.2.29 raeburn 3280: $to_show .= &Apache::loncommon::end_data_table_header_row();
3281: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3282: $lists{'canhide'} = join(',',@allidx);
3283: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3284: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3285: 'randomorder','randompick');
3286: foreach my $item (@possfilters) {
3287: if (ref($filters{$item}) eq 'ARRAY') {
3288: if (@{$filters{$item}} > 0) {
3289: $lists{$item} = join(',',@{$filters{$item}});
3290: }
3291: }
3292: }
1.484.2.29 raeburn 3293: if (@allidx > 0) {
3294: my $path;
3295: if ($env{'form.folderpath'}) {
3296: $path =
3297: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3298: }
1.484.2.30 raeburn 3299: if (@allidx > 1) {
3300: $to_show .=
3301: &Apache::loncommon::continue_data_table_row().
3302: '<td colspan="2"> </td>'.
3303: '<td>'.
1.484.2.67 raeburn 3304: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3305: '</td>'.
3306: '<td> </td>'.
3307: '<td> </td>'.
3308: '<td colspan="4">'.
1.484.2.67 raeburn 3309: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3310: '</td>'.
3311: &Apache::loncommon::end_data_table_row();
3312: $need_save = 1;
3313: }
1.484.2.29 raeburn 3314: }
3315: }
3316: $to_show .= $output.' '
1.484.2.19 raeburn 3317: .&Apache::loncommon::end_data_table()
3318: .'<br style="line-height:2px;" />'
3319: .&Apache::loncommon::end_scrollbox();
3320: } else {
3321: $to_show .= $toolslink
3322: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3323: .$output.' '
3324: .&Apache::loncommon::end_data_table();
3325: }
3326: } else {
3327: if (!$allowed) {
3328: $to_show .= $toolslink;
1.393 raeburn 3329: }
1.484.2.67 raeburn 3330: my $noresmsg;
3331: if ($allowed && $hiddentop && !$supplementalflag) {
3332: $noresmsg = &mt('Main Content Hidden');
3333: } else {
3334: $noresmsg = &mt('Currently empty');
3335: }
1.484.2.19 raeburn 3336: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3337: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3338: .$noresmsg
1.484.2.19 raeburn 3339: .'</div>'
3340: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3341: }
3342: } else {
1.484.2.19 raeburn 3343: if ($shown) {
3344: $to_show = '<div>'
3345: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3346: .$output
3347: .&Apache::loncommon::end_data_table()
3348: .'</div>';
3349: } else {
3350: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3351: .&mt('Currently empty')
1.484.2.19 raeburn 3352: .'</div>'
3353: }
1.458 raeburn 3354: }
3355: my $tid = 1;
3356: if ($supplementalflag) {
3357: $tid = 2;
1.329 droeschl 3358: }
3359: if ($allowed) {
1.484 raeburn 3360: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3361: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3362: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3363: if ($canedit) {
1.484.2.67 raeburn 3364: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3365: }
1.460 raeburn 3366: } else {
3367: $r->print($to_show);
1.329 droeschl 3368: }
3369: return;
3370: }
3371:
1.484.2.30 raeburn 3372: sub multiple_check_form {
1.484.2.67 raeburn 3373: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3374: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3375: my $disabled;
3376: unless ($canedit) {
3377: $disabled = 'disabled="disabled"';
3378: }
1.484.2.30 raeburn 3379: my $output =
3380: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3381: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3382: '<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>'.
3383: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3384: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3385: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3386: if ($caller eq 'settings') {
3387: $output .=
3388: '<table><tr>'.
3389: '<td class="LC_docs_entry_parameter">'.
3390: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3391: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3392: '</label></span></td>'.
3393: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3394: '<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 3395: '</span></td>'.
3396: '</tr>'."\n".
3397: '<tr>'.
3398: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3399: '<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 3400: '</label></span>'.
3401: '</td></tr></table>'."\n";
3402: } else {
3403: $output .=
3404: '<table><tr>'.
3405: '<td class="LC_docs_entry_parameter">'.
3406: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3407: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3408: '</label></span></td>'.
3409: '<td class="LC_docs_entry_parameter">'.
3410: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3411: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3412: '</label></span></td>'."\n".
3413: '<td class="LC_docs_entry_parameter">'.
3414: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3415: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3416: '</label></span></td>'.
3417: '</tr></table>'."\n";
3418: }
3419: $output .=
3420: '</fieldset>'.
3421: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3422: if ($caller eq 'settings') {
3423: $output .=
3424: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3425: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3426: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3427: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3428: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3429: } elsif ($caller eq 'actions') {
3430: $output .=
3431: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3432: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3433: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3434: }
3435: $output .=
3436: '</form>'.
3437: '</div>';
3438: return $output;
3439: }
3440:
1.329 droeschl 3441: sub process_file_upload {
1.484.2.36 raeburn 3442: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3443: # upload a file, if present
1.484.2.36 raeburn 3444: my $filesize = length($env{'form.uploaddoc'});
3445: if (!$filesize) {
3446: $$upload_output = '<div class="LC_error">'.
3447: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3448: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3449: $filesize).'<br />'.
3450: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3451: '</div>';
3452: return;
3453: }
3454: my $quotatype = 'unofficial';
3455: if ($crstype eq 'Community') {
3456: $quotatype = 'community';
1.484.2.51 raeburn 3457: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3458: $quotatype = 'official';
1.484.2.45 raeburn 3459: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3460: $quotatype = 'textbook';
1.484.2.36 raeburn 3461: }
3462: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3463: $filesize = int($filesize/1000); #expressed in kb
3464: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3465: $env{'form.uploaddoc.filename'},$filesize,
3466: 'upload',$quotatype);
1.484.2.36 raeburn 3467: return if ($$upload_output);
3468: }
1.440 raeburn 3469: my ($parseaction,$showupload,$nextphase,$mimetype);
3470: if ($env{'form.parserflag'}) {
1.329 droeschl 3471: $parseaction = 'parse';
3472: }
3473: my $folder=$env{'form.folder'};
3474: if ($folder eq '') {
3475: $folder='default';
3476: }
3477: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3478: my $errtext='';
3479: my $fatal=0;
3480: my $container='sequence';
1.484.2.19 raeburn 3481: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3482: $container='page';
3483: }
3484: ($errtext,$fatal)=
1.484.2.27 raeburn 3485: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3486: if ($#LONCAPA::map::order<1) {
3487: $LONCAPA::map::order[0]=1;
3488: $LONCAPA::map::resources[1]='';
3489: }
3490: my $destination = 'docs/';
3491: if ($folder =~ /^supplemental/) {
3492: $destination = 'supplemental/';
3493: }
3494: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3495: $destination .= 'default/';
3496: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3497: $destination .= $2.'/';
3498: }
1.484.2.27 raeburn 3499: if ($fatal) {
3500: $$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>';
3501: return;
3502: }
1.440 raeburn 3503: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3504: my $newidx=&LONCAPA::map::getresidx();
3505: $destination .= $newidx;
1.439 raeburn 3506: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3507: $parseaction,$allfiles,
1.440 raeburn 3508: $codebase,undef,undef,undef,undef,
3509: undef,undef,\$mimetype);
3510: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3511: my $stored = $1;
3512: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3513: $stored.'</span>').'</p>';
3514: } else {
3515: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3516:
1.457 raeburn 3517: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3518: return;
3519: }
1.329 droeschl 3520: my $ext='false';
3521: if ($url=~m{^http://}) { $ext='true'; }
3522: $url = &LONCAPA::map::qtunescape($url);
3523: my $comment=$env{'form.comment'};
3524: $comment = &LONCAPA::map::qtunescape($comment);
3525: if ($folder=~/^supplemental/) {
3526: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3527: $env{'user.domain'}.'___&&&___'.$comment;
3528: }
3529:
3530: $LONCAPA::map::resources[$newidx]=
3531: $comment.':'.$url.':'.$ext.':normal:res';
3532: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3533: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3534: $folder.'.'.$container,1);
1.329 droeschl 3535: if ($fatal) {
1.457 raeburn 3536: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3537: return;
1.329 droeschl 3538: } else {
1.440 raeburn 3539: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3540: $$upload_output = $showupload;
1.384 raeburn 3541: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3542: if ($total_embedded > 0) {
1.440 raeburn 3543: my $uploadphase = 'upload_embedded';
3544: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3545: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3546: my ($embedded,$num) =
3547: &Apache::loncommon::ask_for_embedded_content(
3548: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3549: if ($embedded) {
3550: if ($num) {
3551: $$upload_output .=
3552: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3553: $nextphase = $uploadphase;
3554: } else {
3555: $$upload_output .= $embedded;
3556: }
3557: } else {
3558: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3559: }
1.329 droeschl 3560: } else {
1.440 raeburn 3561: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3562: }
1.457 raeburn 3563: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3564: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3565: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3566: $nextphase = 'decompress_uploaded';
3567: my $position = scalar(@LONCAPA::map::order)-1;
3568: my $noextract = &return_to_editor();
3569: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3570: my %archiveitems = (
3571: folderpath => $env{'form.folderpath'},
3572: cmd => $nextphase,
3573: newidx => $newidx,
3574: position => $position,
3575: phase => $nextphase,
1.477 raeburn 3576: comment => $comment,
1.480 raeburn 3577: );
3578: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3579: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3580: $$upload_output = $showupload.
3581: &Apache::loncommon::decompress_form($mimetype,
3582: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3583: \%archiveitems,\@current);
1.329 droeschl 3584: }
3585: }
3586: }
1.440 raeburn 3587: return $nextphase;
1.329 droeschl 3588: }
3589:
1.480 raeburn 3590: sub get_dir_list {
3591: my ($url,$coursenum,$coursedom,$newidx) = @_;
3592: my ($destination,$dir_root) = &embedded_destination();
3593: my ($dirlistref,$listerror) =
3594: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3595: my @dir_lines;
3596: my $dirptr=16384;
3597: if (ref($dirlistref) eq 'ARRAY') {
3598: foreach my $dir_line (sort
3599: {
3600: my ($afile)=split('&',$a,2);
3601: my ($bfile)=split('&',$b,2);
3602: return (lc($afile) cmp lc($bfile));
3603: } (@{$dirlistref})) {
3604: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3605: $filename =~ s/\s+$//;
3606: next if ($filename =~ /^\.\.?$/);
3607: my $isdir = 0;
3608: if ($dirptr&$testdir) {
3609: $isdir = 1;
3610: }
3611: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3612: }
3613: }
3614: return @dir_lines;
3615: }
3616:
1.329 droeschl 3617: sub is_supplemental_title {
3618: my ($title) = @_;
3619: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3620: }
3621:
3622: # --------------------------------------------------------------- An entry line
3623:
3624: sub entryline {
1.484.2.12 raeburn 3625: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3626: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.80 raeburn 3627: $canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3628: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3629: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3630: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3631: } else {
3632: $title=&HTML::Entities::encode($title,'"<>&\'');
3633: $renametitle=$title;
3634: $foldertitle=$title;
3635: }
3636:
1.484.2.67 raeburn 3637: my ($disabled,$readonly,$js_lt);
3638: unless ($canedit) {
3639: $disabled = 'disabled="disabled"';
3640: $readonly = 1;
3641: }
3642:
1.329 droeschl 3643: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3644:
1.329 droeschl 3645: $renametitle=~s/\\/\\\\/g;
3646: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3647: $renametitle=~s/"/%22/g;
1.329 droeschl 3648: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3649: $oldtitle = $renametitle;
3650: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3651: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3652: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3653: # Edit commands
1.484.2.28 raeburn 3654: my ($esc_path, $path, $symb);
1.329 droeschl 3655: if ($env{'form.folderpath'}) {
3656: $esc_path=&escape($env{'form.folderpath'});
3657: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3658: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3659: }
1.484.2.16 raeburn 3660: my $isexternal;
1.484.2.19 raeburn 3661: if ($residx) {
1.484.2.12 raeburn 3662: my $currurl = $url;
3663: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3664: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3665: $isexternal = 1;
3666: }
1.484.2.19 raeburn 3667: if (!$supplementalflag) {
3668: my $path = 'uploaded/'.
3669: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3670: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3671: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3672: $residx,
3673: &Apache::lonnet::declutter($currurl));
3674: }
1.484.2.12 raeburn 3675: }
1.484.2.30 raeburn 3676: my ($renamelink,%lt,$ishash);
3677: if (ref($filtersref) eq 'HASH') {
3678: $ishash = 1;
3679: }
3680:
1.329 droeschl 3681: if ($allowed) {
1.484.2.30 raeburn 3682: $form_start = '
3683: <form action="/adm/coursedocs" method="post">
3684: ';
3685: $form_common=(<<END);
3686: <input type="hidden" name="folderpath" value="$path" />
3687: <input type="hidden" name="symb" value="$symb" />
3688: END
3689: $form_param=(<<END);
3690: <input type="hidden" name="setparms" value="$orderidx" />
3691: <input type="hidden" name="changeparms" value="0" />
3692: END
3693: $form_end = '</form>';
3694:
1.329 droeschl 3695: my $incindex=$index+1;
3696: my $selectbox='';
1.471 raeburn 3697: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3698: ((split(/\:/,
1.344 bisitz 3699: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3700: ne '') &&
1.329 droeschl 3701: ((split(/\:/,
1.344 bisitz 3702: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3703: ne '')) {
3704: $selectbox=
3705: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3706: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3707: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3708: if ($i==$incindex) {
1.358 bisitz 3709: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3710: } else {
3711: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3712: }
3713: }
3714: $selectbox.='</select>';
3715: }
1.484.2.12 raeburn 3716: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3717: 'up' => 'Move Up',
3718: 'dw' => 'Move Down',
3719: 'rm' => 'Remove',
3720: 'ct' => 'Cut',
3721: 'rn' => 'Rename',
1.484.2.12 raeburn 3722: 'cp' => 'Copy',
3723: 'ex' => 'External Resource',
3724: 'ed' => 'Edit',
3725: 'pr' => 'Preview',
3726: 'sv' => 'Save',
3727: 'ul' => 'URL',
1.484.2.67 raeburn 3728: 'ti' => 'Title',
3729: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3730: );
1.484.2.30 raeburn 3731: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3732: $env{'form.folderpath'},
3733: $currgroups);
1.484.2.19 raeburn 3734: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3735: my $skip_confirm = 0;
1.484.2.63 raeburn 3736: my $confirm_removal = 0;
1.329 droeschl 3737: if ( $folder =~ /^supplemental/
3738: || ($url =~ m{( /smppg$
3739: |/syllabus$
3740: |/aboutme$
3741: |/navmaps$
3742: |/bulletinboard$
1.484.2.16 raeburn 3743: |\.html$)}x)
1.484.2.19 raeburn 3744: || $isexternal) {
1.329 droeschl 3745: $skip_confirm = 1;
3746: }
1.484.2.63 raeburn 3747: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3748: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3749: $confirm_removal = 1;
3750: }
1.484.2.19 raeburn 3751:
1.484.2.30 raeburn 3752: if ($denied{'copy'}) {
3753: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3754: <span style="visibility: hidden;">$lt{'cp'}</span>
3755: ENDCOPY
3756: } else {
1.484.2.30 raeburn 3757: my $formname = 'edit_copy_'.$orderidx;
3758: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3759: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3760: <form name="$formname" method="post" action="/adm/coursedocs">
3761: $form_common
1.484.2.67 raeburn 3762: <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 3763: $form_end
1.329 droeschl 3764: ENDCOPY
1.484.2.30 raeburn 3765: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3766: push(@{$filtersref->{'cancopy'}},$orderidx);
3767: }
1.329 droeschl 3768: }
1.484.2.30 raeburn 3769: if ($denied{'cut'}) {
1.484.2.16 raeburn 3770: $cutlink=(<<ENDCUT);
3771: <span style="visibility: hidden;">$lt{'ct'}</span>
3772: ENDCUT
3773: } else {
1.484.2.30 raeburn 3774: my $formname = 'edit_cut_'.$orderidx;
3775: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3776: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3777: <form name="$formname" method="post" action="/adm/coursedocs">
3778: $form_common
3779: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3780: <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 3781: $form_end
1.329 droeschl 3782: ENDCUT
1.484.2.30 raeburn 3783: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3784: push(@{$filtersref->{'cancut'}},$orderidx);
3785: }
1.329 droeschl 3786: }
1.484.2.30 raeburn 3787: if ($denied{'remove'}) {
1.484.2.16 raeburn 3788: $removelink=(<<ENDREM);
3789: <span style="visibility: hidden;">$lt{'rm'}</a>
3790: ENDREM
3791: } else {
1.484.2.30 raeburn 3792: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3793: 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 3794: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3795: <form name="$formname" method="post" action="/adm/coursedocs">
3796: $form_common
3797: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3798: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3799: <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 3800: $form_end
1.484.2.9 raeburn 3801: ENDREM
1.484.2.30 raeburn 3802: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3803: push(@{$filtersref->{'canremove'}},$orderidx);
3804: }
1.484.2.9 raeburn 3805: }
1.484.2.35 raeburn 3806: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3807: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3808: ENDREN
1.484.2.67 raeburn 3809: my ($uplink,$downlink);
3810: if ($canedit) {
3811: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3812: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3813: } else {
3814: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3815: $downlink = $uplink;
3816: }
1.329 droeschl 3817: $line.=(<<END);
3818: <td>
1.379 bisitz 3819: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3820: <a href="$uplink">
1.484.2.12 raeburn 3821: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3822: </a>
3823: </div>
3824: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3825: <a href="$downlink">
1.484.2.12 raeburn 3826: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3827: </a>
3828: </div>
1.329 droeschl 3829: </td>
3830: <td>
3831: $form_start
1.484.2.30 raeburn 3832: $form_param
1.478 raeburn 3833: $form_common
1.329 droeschl 3834: $selectbox
3835: $form_end
3836: </td>
1.484.2.30 raeburn 3837: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3838: $removelink
1.329 droeschl 3839: $cutlink
3840: $copylink
3841: </td>
3842: END
3843: }
3844: # Figure out what kind of a resource this is
3845: my ($extension)=($url=~/\.(\w+)$/);
3846: my $uploaded=($url=~/^\/*uploaded\//);
3847: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3848: my $isfolder;
3849: my $ispage;
3850: my $containerarg;
1.484.2.67 raeburn 3851: my $folderurl;
1.329 droeschl 3852: if ($uploaded) {
1.472 raeburn 3853: if (($extension eq 'sequence') || ($extension eq 'page')) {
3854: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3855: $containerarg = $1;
1.472 raeburn 3856: if ($extension eq 'sequence') {
3857: $icon=$iconpath.'navmap.folder.closed.gif';
3858: $isfolder=1;
3859: } else {
3860: $icon=$iconpath.'page.gif';
3861: $ispage=1;
3862: }
1.484.2.67 raeburn 3863: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3864: if ($allowed) {
3865: $url='/adm/coursedocs?';
3866: } else {
3867: $url='/adm/supplemental?';
3868: }
1.329 droeschl 3869: } else {
3870: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3871: }
3872: }
1.364 bisitz 3873:
1.484.2.70 raeburn 3874: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3875: my $orig_url = $url;
1.340 raeburn 3876: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.19 raeburn 3877: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.12 raeburn 3878: if (!$supplementalflag && $residx && $symb) {
3879: if ((!$isfolder) && (!$ispage)) {
3880: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3881: $url=&Apache::lonnet::clutter($url);
3882: if ($url=~/^\/*uploaded\//) {
3883: $url=~/\.(\w+)$/;
3884: my $embstyle=&Apache::loncommon::fileembstyle($1);
3885: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3886: $url='/adm/wrapper'.$url;
3887: } elsif ($embstyle eq 'ssi') {
3888: #do nothing with these
3889: } elsif ($url!~/\.(sequence|page)$/) {
3890: $url='/adm/coursedocs/showdoc'.$url;
3891: }
1.484.2.70 raeburn 3892: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
3893: my $wrapped = $1;
3894: my $exturl = $2;
3895: if ($wrapped eq '') {
3896: $url='/adm/wrapper'.$url;
3897: }
3898: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
3899: $nomodal = 1;
3900: }
3901: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3902: if (($ENV{'SERVER_PORT'} == 443) &&
3903: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 3904: unless (&Apache::lonnet::uses_sts()) {
3905: $url .= '?usehttp=1';
3906: }
1.484.2.70 raeburn 3907: $nomodal = 1;
3908: }
1.484.2.19 raeburn 3909: }
1.484.2.12 raeburn 3910: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3911: my $shownsymb = $symb;
3912: if ($isexternal) {
3913: if ($url =~ /^([^#]+)#([^#]+)$/) {
3914: $url = $1;
3915: $anchor = $2;
1.484.2.80 raeburn 3916: my $escan = &escape('#');
3917: $shownsymb =~ s/^([^\#]+)#([^\#]+)$/$1$escan$2/;
1.484.2.66 raeburn 3918: }
3919: }
1.484.2.67 raeburn 3920: unless ($env{'request.role.adv'}) {
3921: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3922: $url = '';
3923: }
3924: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3925: $url = '';
3926: $hiddenres = 1;
3927: }
3928: }
3929: if ($url ne '') {
1.484.2.75 raeburn 3930: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3931: }
3932: } elsif (!$env{'request.role.adv'}) {
3933: my $checkencrypt;
3934: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3935: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3936: $checkencrypt = 1;
1.484.2.70 raeburn 3937: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3938: unless (ref($$navmapref)) {
3939: $$navmapref = Apache::lonnavmaps::navmap->new();
3940: }
3941: if (ref($$navmapref)) {
3942: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
3943: $checkencrypt = 1;
3944: }
3945: }
3946: }
3947: if ($checkencrypt) {
3948: my $shownsymb = &Apache::lonenc::encrypted($symb);
3949: my $shownurl = &Apache::lonenc::encrypted($url);
3950: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 3951: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3952: if ($env{'request.enc'} ne '') {
3953: delete($env{'request.enc'});
3954: }
3955: } else {
3956: $url='';
3957: }
3958: } else {
3959: $url='';
3960: }
1.484.2.12 raeburn 3961: } else {
3962: $url='';
3963: }
1.484.2.19 raeburn 3964: }
1.484.2.66 raeburn 3965: } elsif ($supplementalflag) {
3966: if ($isexternal) {
3967: if ($url =~ /^([^#]+)#([^#]+)$/) {
3968: $url = $1;
3969: $anchor = $2;
1.484.2.70 raeburn 3970: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.80 raeburn 3971: unless (&Apache::lonnet::uses_sts()) {
3972: if ($hostname ne '') {
3973: $url = 'http://'.$hostname.$url;
3974: }
3975: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
3976: }
1.484.2.70 raeburn 3977: $nomodal = 1;
3978: }
3979: }
3980: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
3981: if (($ENV{'SERVER_PORT'} == 443) &&
3982: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 3983: unless (&Apache::lonnet::uses_sts()) {
3984: if ($hostname ne '') {
3985: $url = 'http://'.$hostname.$url;
3986: }
3987: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
3988: }
1.484.2.70 raeburn 3989: $nomodal = 1;
1.484.2.66 raeburn 3990: }
3991: }
1.329 droeschl 3992: }
1.484.2.67 raeburn 3993: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
3994: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 3995: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3996: my $foldername=&escape($foldertitle);
3997: my $folderpath=$env{'form.folderpath'};
3998: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 3999: if (!$allowed && $supplementalflag) {
4000: $folderpath.=$containerarg.'&'.$foldername;
4001: $url.='folderpath='.&escape($folderpath);
4002: } else {
4003: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4004: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4005: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4006: 'parameter_randomorder'))[0]=~/^yes$/i);
4007: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4008: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4009: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4010: 'parameter_encrypturl'))[0]=~/^yes$/i);
4011: unless ($hiddenmap) {
1.484.2.70 raeburn 4012: if (ref($navmapref)) {
4013: unless (ref($$navmapref)) {
4014: $$navmapref = Apache::lonnavmaps::navmap->new();
4015: }
4016: if (ref($$navmapref)) {
4017: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4018: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4019: unless (@resources) {
4020: $hiddenmap = 1;
4021: unless ($env{'request.role.adv'}) {
4022: $url = '';
4023: $hiddenfolder = 1;
4024: }
1.484.2.67 raeburn 4025: }
4026: }
4027: }
4028: }
4029: }
4030: unless ($encryptmap) {
1.484.2.70 raeburn 4031: if ((ref($navmapref)) && (ref($$navmapref))) {
4032: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4033: $encryptmap = 1;
4034: }
1.484.2.67 raeburn 4035: }
4036: }
4037:
4038: # Append randompick number, hidden, and encrypted with ":" to foldername,
4039: # so it gets transferred between levels
4040: $folderpath.=$containerarg.'&'.$foldername.
4041: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4042: unless ($url eq '') {
4043: $url.='folderpath='.&escape($folderpath);
4044: }
1.484.2.19 raeburn 4045: my $rpckchk;
4046: if ($rpicknum) {
4047: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4048: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4049: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4050: }
1.484.2.19 raeburn 4051: }
1.484.2.29 raeburn 4052: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4053: $rand_pick_text =
1.478 raeburn 4054: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4055: $form_param."\n".
1.478 raeburn 4056: $form_common."\n".
1.484.2.67 raeburn 4057: '<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 4058: if ($rpicknum ne '') {
4059: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4060: }
1.484.2.29 raeburn 4061: $rand_pick_text .= '</span></span>'.
4062: $form_end;
1.484.2.30 raeburn 4063: my $ro_set;
1.484.2.67 raeburn 4064: if ($randorder) {
1.484.2.30 raeburn 4065: $ro_set = 'checked="checked"';
4066: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4067: push(@{$filtersref->{'randomorder'}},$orderidx);
4068: }
4069: }
1.484.2.41 raeburn 4070: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4071: $rand_order_text =
1.484.2.29 raeburn 4072: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4073: $form_param."\n".
1.484.2.29 raeburn 4074: $form_common."\n".
1.484.2.67 raeburn 4075: '<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 4076: $form_end;
1.484.2.19 raeburn 4077: }
1.484.2.18 raeburn 4078: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 4079: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4080: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4081: if ($title) {
4082: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4083: }
4084: if ($isexternal && $orderidx) {
4085: $url .= '&idx='.$orderidx;
4086: }
1.484.2.66 raeburn 4087: if ($anchor ne '') {
4088: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4089: }
1.329 droeschl 4090: }
1.484.2.19 raeburn 4091: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4092: if ($allowed) {
1.484.2.19 raeburn 4093: my $fileloc =
1.484.2.12 raeburn 4094: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4095: if ($isexternal) {
4096: ($editlink,$extresform) =
1.484.2.67 raeburn 4097: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4098: undef,undef,undef,$disabled);
1.484.2.19 raeburn 4099: } elsif (!$isfolder && !$ispage) {
4100: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4101: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4102: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4103: my $suppanchor;
4104: if ($supplementalflag) {
4105: $suppanchor = $anchor;
4106: }
1.484.2.19 raeburn 4107: my $jscall =
1.484.2.12 raeburn 4108: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4109: $switchserver,
1.484.2.14 raeburn 4110: $forceedit,
1.484.2.19 raeburn 4111: undef,$symb,
4112: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4113: $renametitle,$hostname,
4114: '','',1,$suppanchor);
1.484.2.12 raeburn 4115: if ($jscall) {
1.484.2.19 raeburn 4116: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4117: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4118: }
4119: }
4120: }
1.484.2.19 raeburn 4121: $tdalign = ' align="right" valign="top"';
4122: $tdwidth = ' width="80%"';
1.329 droeschl 4123: }
1.408 raeburn 4124: my $reinit;
4125: if ($crstype eq 'Community') {
4126: $reinit = &mt('(re-initialize community to access)');
4127: } else {
4128: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4129: }
4130: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4131: my $link;
1.472 raeburn 4132: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4133: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4134: } elsif ($url) {
1.484.2.66 raeburn 4135: if ($anchor ne '') {
4136: if ($supplementalflag) {
4137: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4138: } else {
4139: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4140: }
4141: }
1.484.2.80 raeburn 4142:
4143: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4144: $link = 'http://'.$hostname.$url;
4145: } else {
4146: $link = $url;
4147: }
4148: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4149: if ($nomodal) {
4150: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4151: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4152: } else {
4153: $line.=&Apache::loncommon::modal_link($link,
4154: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4155: }
1.469 www 4156: } else {
4157: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4158: }
1.484.2.19 raeburn 4159: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4160: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4161: $line.='<a href="'.$url.'">'.$title.'</a>';
4162: } elsif ($url) {
1.484.2.70 raeburn 4163: if ($nomodal) {
4164: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4165: $title.'</a>';
4166: } else {
4167: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4168: }
1.484.2.67 raeburn 4169: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4170: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4171: } else {
4172: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4173: }
1.484.2.19 raeburn 4174: $line.="$extresform</td>";
1.478 raeburn 4175: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4176: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4177: if (($allowed) && ($folder!~/^supplemental/)) {
4178: my %lt=&Apache::lonlocal::texthash(
4179: 'hd' => 'Hidden',
4180: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4181: my ($enctext,$hidtext);
4182: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4183: $enctext = ' checked="checked"';
4184: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4185: push(@{$filtersref->{'encrypturl'}},$orderidx);
4186: }
4187: }
4188: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4189: $hidtext = ' checked="checked"';
4190: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4191: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4192: }
4193: }
1.484.2.29 raeburn 4194: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4195: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4196: $line.=(<<ENDPARMS);
4197: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4198: <form action="/adm/coursedocs" method="post" name="$formhidden">
4199: $form_param
1.478 raeburn 4200: $form_common
1.484.2.67 raeburn 4201: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4202: $form_end
1.458 raeburn 4203: <br />
1.484.2.29 raeburn 4204: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4205: $form_param
1.478 raeburn 4206: $form_common
1.484.2.67 raeburn 4207: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4208: $form_end
4209: </td>
1.478 raeburn 4210: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4211: $rand_order_text</td>
1.329 droeschl 4212: ENDPARMS
4213: }
1.379 bisitz 4214: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4215: return $line;
4216: }
4217:
1.484.2.30 raeburn 4218: sub action_restrictions {
4219: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4220: my %denied = (
4221: cut => 0,
4222: copy => 0,
4223: remove => 0,
4224: );
4225: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4226: # no copy for published maps
4227: $denied{'copy'} = 1;
1.484.2.82 raeburn 4228: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4229: unless ($1 eq 'simpleproblem') {
4230: $denied{'copy'} = 1;
4231: }
4232: $denied{'cut'} = 1;
1.484.2.30 raeburn 4233: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4234: if ($folderpath =~ /^default&[^\&]+$/) {
4235: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4236: $denied{'remove'} = 1;
4237: }
4238: $denied{'cut'} = 1;
4239: $denied{'copy'} = 1;
4240: }
4241: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4242: my $group = $1;
4243: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4244: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4245: $denied{'remove'} = 1;
4246: }
4247: }
4248: $denied{'cut'} = 1;
4249: $denied{'copy'} = 1;
4250: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4251: my $group = $1;
4252: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4253: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4254: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4255: if (keys(%groupsettings) > 0) {
4256: $denied{'remove'} = 1;
4257: }
4258: $denied{'cut'} = 1;
4259: $denied{'copy'} = 1;
4260: }
4261: }
4262: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4263: my $group = $1;
4264: if ($url =~ /group_boards_\Q$group\E/) {
4265: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4266: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4267: if (keys(%groupsettings) > 0) {
4268: if (ref($groupsettings{'functions'}) eq 'HASH') {
4269: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4270: $denied{'remove'} = 1;
4271: }
4272: }
4273: }
4274: $denied{'cut'} = 1;
4275: $denied{'copy'} = 1;
4276: }
4277: }
4278: }
4279: return %denied;
4280: }
4281:
1.484.2.26 raeburn 4282: sub new_timebased_suffix {
1.484.2.30 raeburn 4283: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4284: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4285: if ($type eq 'paste') {
4286: $prefix = $type;
4287: $namespace = 'courseeditor';
1.484.2.56 raeburn 4288: $idtype = 'addcode';
1.484.2.30 raeburn 4289: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4290: $prefix = 'docs';
4291: if ($area eq 'supplemental') {
4292: $prefix = 'supp';
4293: }
4294: $prefix .= $container;
4295: $namespace = 'uploadedmaps';
4296: } else {
4297: $prefix = $type;
4298: $namespace = 'templated';
1.484.2.15 raeburn 4299: }
4300: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4301: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4302: if (!$suffix) {
1.484.2.30 raeburn 4303: if ($type eq 'paste') {
4304: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4305: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4306: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4307: } elsif ($type eq 'smppg') {
4308: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4309: } else {
1.484.2.42 raeburn 4310: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4311: }
1.484.2.15 raeburn 4312: if ($error) {
4313: $errtext .= '<br />'.$error;
4314: }
4315: }
4316: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4317: $locknotfreed =
4318: '<div class="LC_error">'.
4319: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4320: if ($type eq 'paste') {
1.484.2.57 raeburn 4321: if ($freedlock eq 'nolock') {
4322: $locknotfreed =
4323: '<div class="LC_error">'.
4324: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4325:
1.484.2.60 raeburn 4326: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4327: } else {
4328: $locknotfreed .=
4329: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4330: }
1.484.2.30 raeburn 4331: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4332: $locknotfreed .=
4333: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4334: } elsif ($type eq 'smppg') {
4335: $locknotfreed .=
4336: &mt('This will prevent creation of additional simple pages in this course.');
4337: } else {
4338: $locknotfreed .=
1.484.2.42 raeburn 4339: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4340: }
1.484.2.30 raeburn 4341: unless ($type eq 'paste') {
4342: $locknotfreed .=
1.484.2.38 raeburn 4343: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4344: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4345: }
4346: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4347: }
4348: return ($suffix,$errtext,$locknotfreed);
4349: }
4350:
1.329 droeschl 4351: =pod
4352:
4353: =item tiehash()
4354:
4355: tie the hash
4356:
4357: =cut
4358:
4359: sub tiehash {
4360: my ($mode)=@_;
4361: $hashtied=0;
4362: if ($env{'request.course.fn'}) {
4363: if ($mode eq 'write') {
4364: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4365: &GDBM_WRCREAT(),0640)) {
4366: $hashtied=2;
4367: }
4368: } else {
4369: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4370: &GDBM_READER(),0640)) {
4371: $hashtied=1;
4372: }
4373: }
1.364 bisitz 4374: }
1.329 droeschl 4375: }
4376:
4377: sub untiehash {
4378: if ($hashtied) { untie %hash; }
4379: $hashtied=0;
4380: return OK;
4381: }
4382:
4383:
4384:
4385:
4386: sub checkonthis {
1.484.2.78 raeburn 4387: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4388: $url=&unescape($url);
4389: $alreadyseen{$url}=1;
4390: $r->rflush();
4391: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4392: $r->print("\n<br />");
4393: if ($level==0) {
4394: $r->print("<br />");
4395: }
4396: for (my $i=0;$i<=$level*5;$i++) {
4397: $r->print(' ');
4398: }
4399: $r->print('<a href="'.$url.'" target="cat">'.
4400: ($title?$title:$url).'</a> ');
4401: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4402: my $updated;
4403: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4404: ($url !~ /\.\d+\.\w+$/)) {
4405: $updated = &Apache::lonnet::remove_stale_resfile($url);
4406: }
1.329 droeschl 4407: my $result=&Apache::lonnet::repcopy(
4408: &Apache::lonnet::filelocation('',$url));
4409: if ($result eq 'ok') {
4410: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4411: if ($updated) {
4412: $r->print('<br />');
4413: for (my $i=0;$i<=$level*5;$i++) {
4414: $r->print(' ');
4415: }
4416: $r->print('- '.&mt('Outdated copy removed'));
4417: }
1.329 droeschl 4418: $r->rflush();
4419: &Apache::lonnet::countacc($url);
4420: $url=~/\.(\w+)$/;
4421: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4422: $r->print('<br />');
4423: $r->rflush();
4424: for (my $i=0;$i<=$level*5;$i++) {
4425: $r->print(' ');
4426: }
4427: $r->print('- '.&mt('Rendering:').' ');
4428: my ($errorcount,$warningcount)=split(/:/,
4429: &Apache::lonnet::ssi_body($url,
4430: ('grade_target'=>'web',
4431: 'return_only_error_and_warning_counts' => 1)));
4432: if (($errorcount) ||
4433: ($warningcount)) {
4434: if ($errorcount) {
1.369 bisitz 4435: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4436: &mt('[quant,_1,error]',$errorcount).'</span>');
4437: }
4438: if ($warningcount) {
4439: $r->print('<span class="LC_warning">'.
4440: &mt('[quant,_1,warning]',$warningcount).'</span>');
4441: }
4442: } else {
4443: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4444: }
4445: $r->rflush();
4446: }
4447: my $dependencies=
4448: &Apache::lonnet::metadata($url,'dependencies');
4449: foreach my $dep (split(/\,/,$dependencies)) {
4450: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4451: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4452: }
4453: }
4454: } elsif ($result eq 'unavailable') {
4455: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4456: } elsif ($result eq 'not_found') {
4457: unless ($url=~/\$/) {
1.484.2.19 raeburn 4458: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4459: } else {
1.366 bisitz 4460: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4461: }
4462: } else {
4463: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4464: }
1.484.2.78 raeburn 4465: if (($updated) && ($result ne 'ok')) {
4466: $r->print('<br />'.&mt('Outdated copy removed'));
4467: }
1.329 droeschl 4468: }
4469: }
4470: }
4471:
4472:
4473:
4474: =pod
4475:
4476: =item list_symbs()
4477:
1.484.2.3 raeburn 4478: List Content Identifiers
1.329 droeschl 4479:
4480: =cut
4481:
4482: sub list_symbs {
4483: my ($r) = @_;
4484:
1.408 raeburn 4485: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4486: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4487: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4488: $r->print(&startContentScreen('tools'));
1.329 droeschl 4489: my $navmap = Apache::lonnavmaps::navmap->new();
4490: if (!defined($navmap)) {
4491: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4492: '<div class="LC_error">'.
4493: &mt('Unable to retrieve information about course contents').
4494: '</div>');
1.408 raeburn 4495: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4496: } else {
1.484 raeburn 4497: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4498: &Apache::loncommon::start_data_table().
4499: &Apache::loncommon::start_data_table_header_row().
4500: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4501: &Apache::loncommon::end_data_table_header_row()."\n");
4502: my $count;
1.329 droeschl 4503: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4504: $r->print(&Apache::loncommon::start_data_table_row().
4505: '<td>'.$res->compTitle().'</td>'.
4506: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4507: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4508: $count ++;
4509: }
4510: if (!$count) {
4511: $r->print(&Apache::loncommon::start_data_table_row().
4512: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4513: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4514: }
1.484 raeburn 4515: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4516: }
1.484.2.19 raeburn 4517: $r->print(&endContentScreen());
1.329 droeschl 4518: }
4519:
1.484.2.78 raeburn 4520: sub contentverifyform {
4521: my ($r) = @_;
4522: my $crstype = &Apache::loncommon::course_type();
4523: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4524: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4525: $r->print(&startContentScreen('tools'));
4526: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4527: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4528: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4529: ' <span class="LC_nobreak">'.
4530: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4531: &mt('No').'</label>'.(' 'x2).
4532: '<label><input type="radio" name="checkstale" value="1" />'.
4533: &mt('Yes').'</label></span></p><p>'.
4534: '<input type="submit" value="'.&mt('Verify content').' "/>'.
4535: '<input type="hidden" value="1" name="tools" />'.
4536: '<input type="hidden" value="1" name="verify" /></p></form>');
4537: $r->print(&endContentScreen());
4538: return;
4539: }
1.329 droeschl 4540:
4541: sub verifycontent {
1.484.2.78 raeburn 4542: my ($r,$checkstale) = @_;
1.408 raeburn 4543: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4544: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4545: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4546: $r->print(&startContentScreen('tools'));
4547: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4548: $hashtied=0;
4549: undef %alreadyseen;
4550: %alreadyseen=();
4551: &tiehash();
1.484 raeburn 4552:
1.329 droeschl 4553: foreach my $key (keys(%hash)) {
4554: if ($hash{$key}=~/\.(page|sequence)$/) {
4555: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4556: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4557: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4558: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4559: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4560: }
4561: }
4562: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4563: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4564: }
4565: }
4566: &untiehash();
1.442 www 4567: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4568: $r->print(&endContentScreen());
1.329 droeschl 4569: }
4570:
4571:
4572: sub devalidateversioncache {
4573: my $src=shift;
4574: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4575: &Apache::lonnet::clutter($src));
4576: }
4577:
4578: sub checkversions {
1.484.2.67 raeburn 4579: my ($r,$canedit) = @_;
1.408 raeburn 4580: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4581: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4582: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4583: $r->print(&startContentScreen('tools'));
1.442 www 4584:
1.329 droeschl 4585: my $header='';
4586: my $startsel='';
4587: my $monthsel='';
4588: my $weeksel='';
4589: my $daysel='';
4590: my $allsel='';
4591: my %changes=();
4592: my $starttime=0;
4593: my $haschanged=0;
4594: my %setversions=&Apache::lonnet::dump('resourceversions',
4595: $env{'course.'.$env{'request.course.id'}.'.domain'},
4596: $env{'course.'.$env{'request.course.id'}.'.num'});
4597:
4598: $hashtied=0;
4599: &tiehash();
1.484.2.67 raeburn 4600: if ($canedit) {
4601: my %newsetversions=();
4602: if ($env{'form.setmostrecent'}) {
4603: $haschanged=1;
4604: foreach my $key (keys(%hash)) {
4605: if ($key=~/^ids\_(\/res\/.+)$/) {
4606: $newsetversions{$1}='mostrecent';
4607: &devalidateversioncache($1);
4608: }
1.329 droeschl 4609: }
1.484.2.67 raeburn 4610: } elsif ($env{'form.setcurrent'}) {
4611: $haschanged=1;
4612: foreach my $key (keys(%hash)) {
4613: if ($key=~/^ids\_(\/res\/.+)$/) {
4614: my $getvers=&Apache::lonnet::getversion($1);
4615: if ($getvers>0) {
4616: $newsetversions{$1}=$getvers;
4617: &devalidateversioncache($1);
4618: }
4619: }
1.329 droeschl 4620: }
1.484.2.67 raeburn 4621: } elsif ($env{'form.setversions'}) {
4622: $haschanged=1;
4623: foreach my $key (keys(%env)) {
4624: if ($key=~/^form\.set_version_(.+)$/) {
4625: my $src=$1;
4626: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4627: $newsetversions{$src}=$env{$key};
4628: &devalidateversioncache($src);
4629: }
4630: }
1.329 droeschl 4631: }
1.484.2.67 raeburn 4632: }
4633: if ($haschanged) {
4634: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4635: $env{'course.'.$env{'request.course.id'}.'.domain'},
4636: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4637: $r->print(&Apache::loncommon::confirmwrapper(
4638: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4639: } else {
4640: $r->print(&Apache::loncommon::confirmwrapper(
4641: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4642: }
4643: &mark_hash_old();
4644: }
4645: &changewarning($r,'');
1.329 droeschl 4646: }
4647: if ($env{'form.timerange'} eq 'all') {
4648: # show all documents
1.484.2.34 raeburn 4649: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4650: $allsel=' selected="selected"';
1.329 droeschl 4651: foreach my $key (keys(%hash)) {
4652: if ($key=~/^ids\_(\/res\/.+)$/) {
4653: my $src=$1;
4654: $changes{$src}=1;
4655: }
4656: }
4657: } else {
4658: # show documents which changed
4659: %changes=&Apache::lonnet::dump
4660: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4661: $env{'course.'.$env{'request.course.id'}.'.num'});
4662: my $firstkey=(keys(%changes))[0];
4663: unless ($firstkey=~/^error\:/) {
4664: unless ($env{'form.timerange'}) {
4665: $env{'form.timerange'}=604800;
4666: }
4667: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4668: .&mt('seconds');
4669: if ($env{'form.timerange'}==-1) {
4670: $seltext='since start of course';
1.484.2.19 raeburn 4671: $startsel=' selected="selected"';
1.329 droeschl 4672: $env{'form.timerange'}=time;
4673: }
4674: $starttime=time-$env{'form.timerange'};
4675: if ($env{'form.timerange'}==2592000) {
4676: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4677: $monthsel=' selected="selected"';
1.329 droeschl 4678: } elsif ($env{'form.timerange'}==604800) {
4679: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4680: $weeksel=' selected="selected"';
1.329 droeschl 4681: } elsif ($env{'form.timerange'}==86400) {
4682: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4683: $daysel=' selected="selected"';
1.329 droeschl 4684: }
4685: $header=&mt('Content changed').' '.$seltext;
4686: } else {
4687: $header=&mt('No content modifications yet.');
4688: }
4689: }
4690: %setversions=&Apache::lonnet::dump('resourceversions',
4691: $env{'course.'.$env{'request.course.id'}.'.domain'},
4692: $env{'course.'.$env{'request.course.id'}.'.num'});
4693: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4694: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4695: 'lm' => 'Version changes since last Month',
4696: 'lw' => 'Version changes since last Week',
4697: 'sy' => 'Version changes since Yesterday',
4698: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4699: 'cd' => 'Change display',
1.329 droeschl 4700: 'sd' => 'Display',
4701: 'fi' => 'File',
4702: 'md' => 'Modification Date',
4703: 'mr' => 'Most recently published Version',
1.408 raeburn 4704: 've' => 'Version used in '.$crstype,
4705: 'vu' => 'Set Version to be used in '.$crstype,
4706: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4707: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4708: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4709: 'di' => 'Differences',
1.484 raeburn 4710: 'save' => 'Save changes',
4711: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4712: 'act' => 'Actions');
1.484.2.67 raeburn 4713: my ($disabled,$readonly);
4714: unless ($canedit) {
4715: $disabled = 'disabled="disabled"';
4716: $readonly = 1;
4717: }
1.329 droeschl 4718: $r->print(<<ENDHEADERS);
1.484 raeburn 4719: <h4 class="LC_info">$header</h4>
1.329 droeschl 4720: <form action="/adm/coursedocs" method="post">
4721: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4722: <div class="LC_left_float">
1.479 golterma 4723: <fieldset>
1.484 raeburn 4724: <legend>$lt{'cd'}</legend>
1.329 droeschl 4725: <select name="timerange">
1.484.2.19 raeburn 4726: <option value='all'$allsel>$lt{'al'}</option>
4727: <option value="-1"$startsel>$lt{'st'}</option>
4728: <option value="2592000"$monthsel>$lt{'lm'}</option>
4729: <option value="604800"$weeksel>$lt{'lw'}</option>
4730: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4731: </select>
4732: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4733: </fieldset>
4734: </div>
4735: <div class="LC_left_float">
4736: <fieldset>
4737: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4738: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4739: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4740: </fieldset>
4741: </div>
4742: <br clear="all" />
4743: <hr />
4744: <h4>$lt{'vers'}</h4>
1.329 droeschl 4745: ENDHEADERS
1.479 golterma 4746: #number of columns for version history
1.484.2.44 raeburn 4747: my %changedbytime;
4748: foreach my $key (keys(%changes)) {
4749: #excludes not versionable problems from resource version history:
4750: next if ($key =~ /^\/res\/lib\/templates/);
4751: my $chg;
4752: if ($env{'form.timerange'} eq 'all') {
4753: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4754: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4755: } else {
4756: $chg = $changes{$key};
4757: next if ($chg < $starttime);
4758: }
4759: push(@{$changedbytime{$chg}},$key);
4760: }
4761: if (keys(%changedbytime) == 0) {
4762: &untiehash();
4763: $r->print(&mt('No content changes in imported content in specified time frame').
4764: &endContentScreen());
4765: return;
4766: }
1.479 golterma 4767: $r->print(
1.484.2.67 raeburn 4768: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4769: &Apache::loncommon::start_data_table().
4770: &Apache::loncommon::start_data_table_header_row().
4771: '<th>'.&mt('Resources').'</th>'.
4772: "<th>$lt{'mr'}</th>".
4773: "<th>$lt{'ve'}</th>".
4774: "<th>$lt{'vu'}</th>".
4775: '<th>'.&mt('History').'</th>'.
4776: &Apache::loncommon::end_data_table_header_row()
4777: );
1.484.2.44 raeburn 4778: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4779: foreach my $key (sort(@{$changedbytime{$chg}})) {
4780: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4781: my $currentversion=&Apache::lonnet::getversion($key);
4782: if ($currentversion<0) {
4783: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4784: }
4785: my $linkurl=&Apache::lonnet::clutter($key);
4786: $r->print(
4787: &Apache::loncommon::start_data_table_row().
4788: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4789: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4790: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4791: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4792: '<td align="right">'
4793: );
4794: # Used in course
4795: my $usedversion=$hash{'version_'.$linkurl};
4796: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4797: if ($usedversion != $currentversion) {
1.479 golterma 4798: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4799: } else {
1.479 golterma 4800: $r->print($usedversion);
4801: }
1.329 droeschl 4802: } else {
1.484.2.19 raeburn 4803: $r->print($currentversion);
1.329 droeschl 4804: }
1.484.2.44 raeburn 4805: $r->print('</td><td title="'.$lt{'vu'}.'">');
4806: # Set version
4807: $r->print(&Apache::loncommon::select_form(
4808: $setversions{$linkurl},
4809: 'set_version_'.$linkurl,
4810: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4811: '' => '',
4812: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4813: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4814: my $lastold=1;
4815: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4816: my $url=$root.'.'.$prevvers.'.'.$extension;
4817: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4818: $lastold=$prevvers;
4819: }
4820: }
4821: $r->print('</td>');
4822: # List all available versions
4823: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4824: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4825: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4826: $r->print(
1.484.2.44 raeburn 4827: '<span class="LC_nobreak">'
4828: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4829: .&mt('Version [_1]',$prevvers).'</a>'
4830: .' ('.&Apache::lonlocal::locallocaltime(
4831: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4832: .')');
4833: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4834: $r->print(
4835: ' <a href="/adm/diff?filename='.
4836: &Apache::lonnet::clutter($root.'.'.$extension).
4837: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4838: '" target="diffs">'.&mt('Diffs').'</a>');
4839: }
4840: $r->print('</span><br />');
1.329 droeschl 4841: }
1.484.2.44 raeburn 4842: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4843: }
1.329 droeschl 4844: }
1.484.2.19 raeburn 4845: $r->print(
4846: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4847: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4848: '</form>'
4849: );
1.329 droeschl 4850:
4851: &untiehash();
1.484.2.19 raeburn 4852: $r->print(&endContentScreen());
1.484.2.44 raeburn 4853: return;
1.329 droeschl 4854: }
4855:
4856: sub mark_hash_old {
4857: my $retie_hash=0;
4858: if ($hashtied) {
4859: $retie_hash=1;
4860: &untiehash();
4861: }
4862: &tiehash('write');
4863: $hash{'old'}=1;
4864: &untiehash();
4865: if ($retie_hash) { &tiehash(); }
4866: }
4867:
4868: sub is_hash_old {
4869: my $untie_hash=0;
4870: if (!$hashtied) {
4871: $untie_hash=1;
4872: &tiehash();
4873: }
4874: my $return=$hash{'old'};
4875: if ($untie_hash) { &untiehash(); }
4876: return $return;
4877: }
4878:
4879: sub changewarning {
4880: my ($r,$postexec,$message,$url)=@_;
4881: if (!&is_hash_old()) { return; }
4882: my $pathvar='folderpath';
4883: my $path=&escape($env{'form.folderpath'});
4884: if (!defined($url)) {
4885: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4886: }
4887: my $course_type = &Apache::loncommon::course_type();
4888: if (!defined($message)) {
4889: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4890: }
4891: $r->print("\n\n".
1.372 bisitz 4892: '<script type="text/javascript">'."\n".
4893: '// <![CDATA['."\n".
4894: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4895: '// ]]>'."\n".
1.369 bisitz 4896: '</script>'."\n".
1.375 tempelho 4897: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4898: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4899: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4900: &mt($message,' <input type="hidden" name="'.
4901: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4902: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4903: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4904: }
4905:
4906:
4907: sub init_breadcrumbs {
1.484.2.44 raeburn 4908: my ($form,$text,$help)=@_;
1.329 droeschl 4909: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4910: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4911: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4912: faq=>273,
4913: bug=>'Instructor Interface',
1.484.2.44 raeburn 4914: help => $help});
1.329 droeschl 4915: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4916: text=>$text,
4917: faq=>273,
4918: bug=>'Instructor Interface'});
4919: }
4920:
1.441 www 4921: # subroutine to list form elements
4922: sub create_list_elements {
4923: my @formarr = @_;
4924: my $list = '';
1.484.2.12 raeburn 4925: foreach my $button (@formarr){
4926: foreach my $picture (keys(%{$button})) {
4927: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4928: }
4929: }
4930: return $list;
4931: }
1.329 droeschl 4932:
1.441 www 4933: # subroutine to create ul from list elements
4934: sub create_form_ul {
4935: my $list = shift;
4936: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4937: return $ul;
4938: }
1.329 droeschl 4939:
1.442 www 4940: #
4941: # Start tabs
4942: #
4943:
4944: sub startContentScreen {
1.484 raeburn 4945: my ($mode) = @_;
4946: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4947: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4948: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4949: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4950: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4951: } else {
1.484.2.34 raeburn 4952: $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 4953: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4954: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4955: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4956: }
4957: $output .= "\n".'</ul>'."\n";
4958: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4959: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4960: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4961: return $output;
1.442 www 4962: }
4963:
4964: #
4965: # End tabs
4966: #
4967:
4968: sub endContentScreen {
1.484 raeburn 4969: return '</div></div></div>';
1.442 www 4970: }
1.329 droeschl 4971:
1.446 www 4972: sub supplemental_base {
1.484.2.33 raeburn 4973: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4974: }
4975:
1.329 droeschl 4976: sub handler {
4977: my $r = shift;
4978: &Apache::loncommon::content_type($r,'text/html');
4979: $r->send_http_header;
4980: return OK if $r->header_only;
1.484 raeburn 4981:
4982: # get course data
1.408 raeburn 4983: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4984: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4985: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4986:
4987: # graphics settings
4988: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4989:
1.443 www 4990: #
1.329 droeschl 4991: # --------------------------------------------- Initialize help topics for this
4992: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4993: 'Adding_External_Resource','Navigate_Content',
4994: 'Adding_Folders','Docs_Overview', 'Load_Map',
4995: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 4996: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 4997: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
4998: 'Dropbox','Simple_Problem') {
1.329 droeschl 4999: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5000: }
5001: # Composite help files
5002: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5003: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5004: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5005: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5006: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5007: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5008: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5009: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5010: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5011: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5012:
1.484.2.67 raeburn 5013: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5014: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5015: unless ($r->uri eq '/adm/supplemental') {
5016: # does this user have privileges to modify content.
1.484.2.67 raeburn 5017: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5018: $allowed = 1;
5019: $canedit = 1;
5020: $canview = 1;
5021: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5022: $allowed = 1;
5023: $canview = 1;
5024: }
5025: }
5026: unless ($canedit) {
5027: $disabled = ' disabled="disabled"';
1.472 raeburn 5028: }
1.484.2.53 raeburn 5029: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5030: if ($env{'form.inhibitmenu'}) {
5031: unless ($env{'form.inhibitmenu'} eq 'yes') {
5032: delete($env{'form.inhibitmenu'});
5033: }
5034: }
5035:
1.484.2.53 raeburn 5036: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5037: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5038: if (!$canedit) {
5039: &verifycontent($r);
5040: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5041: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5042: text=>'Results',
5043: faq=>273,
5044: bug=>'Instructor Interface'});
5045: &verifycontent($r,$env{'form.checkstale'});
5046: } else {
5047: &contentverifyform($r);
5048: }
1.329 droeschl 5049: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5050: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5051: &list_symbs($r);
5052: } elsif ($allowed && $env{'form.docslog'}) {
5053: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5054: my $folder = $env{'form.folder'};
5055: if ($folder eq '') {
5056: $folder='default';
5057: }
1.484.2.67 raeburn 5058: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5059: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5060: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5061: &checkversions($r,$canedit);
5062: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5063: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5064: &dumpcourse($r);
5065: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5066: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5067: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5068: } else {
1.445 www 5069: #
5070: # Done catching special calls
1.484 raeburn 5071: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5072: # Get the parameters that may be needed
5073: #
5074: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5075: ['folderpath',
5076: 'forcesupplement','forcestandard',
5077: 'tools','symb','command','supppath']);
1.445 www 5078:
1.484.2.78 raeburn 5079: foreach my $item ('forcesupplement','forcestandard','tools') {
5080: next if ($env{'form.'.$item} eq '');
5081: unless ($env{'form.'.$item} eq '1') {
5082: delete($env{'form.'.$item});
5083: }
5084: }
5085:
5086: if ($env{'form.command'}) {
5087: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5088: delete($env{'form.command'});
5089: }
5090: }
5091:
5092: if ($env{'form.symb'}) {
5093: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5094: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5095: delete($env{'form.symb'});
5096: }
5097: }
5098:
1.445 www 5099: # standard=1: this is a "new-style" course with an uploaded map as top level
5100: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5101:
5102: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5103:
1.484 raeburn 5104: # Decide whether this should display supplemental or main content or utilities
1.445 www 5105: # supplementalflag=1: show supplemental documents
5106: # supplementalflag=0: show standard documents
1.484 raeburn 5107: # toolsflag=1: show utilities
1.445 www 5108:
1.484.2.39 raeburn 5109: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5110: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5111: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5112: $supplementalflag=0;
5113: }
5114: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5115: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5116: unless ($allowed) { $supplementalflag=1; }
5117: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5118: my $toolsflag=0;
5119: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5120:
1.484.2.78 raeburn 5121: if ($env{'form.folderpath'} ne '') {
5122: my @items = split(/\&/,$env{'form.folderpath'});
5123: my $badpath;
5124: for (my $i=0; $i<@items; $i++) {
5125: my $odd = $i%2;
5126: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5127: $badpath = 1;
5128: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5129: $badpath = 1;
5130: }
5131: last if ($badpath);
5132: }
5133: if ($badpath) {
5134: delete($env{'form.folderpath'});
5135: }
5136: }
5137:
5138: if ($env{'form.supppath'} ne '') {
5139: my @items = split(/\&/,$env{'form.supppath'});
5140: my $badpath;
5141: for (my $i=0; $i<@items; $i++) {
5142: my $odd = $i%2;
5143: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5144: $badpath = 1;
5145: }
5146: last if ($badpath);
5147: }
5148: if ($badpath) {
5149: delete($env{'form.supppath'});
5150: }
5151: }
5152:
1.329 droeschl 5153: my $script='';
5154: my $showdoc=0;
1.457 raeburn 5155: my $addentries = {};
1.475 raeburn 5156: my $container;
1.329 droeschl 5157: my $containertag;
1.484.2.17 raeburn 5158: my $pathitem;
1.484.2.67 raeburn 5159: my $hiddentop;
5160: my $navmap;
5161: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5162:
1.464 www 5163: # Do we directly jump somewhere?
1.484.2.21 raeburn 5164: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5165: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5166: $env{'form.folderpath'}=
1.484.2.67 raeburn 5167: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5168: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5169: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5170: } elsif ($env{'form.supppath'} ne '') {
5171: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5172: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5173: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5174: }
1.472 raeburn 5175: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5176: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5177: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5178: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5179: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5180: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5181: } elsif ($env{'form.command'} eq 'contents') {
5182: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5183: } elsif ($env{'form.command'} eq 'home') {
5184: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5185: }
5186:
1.484.2.23 raeburn 5187:
1.445 www 5188: # Where do we store these for when we come back?
5189: my $stored_folderpath='docs_folderpath';
5190: if ($supplementalflag) {
5191: $stored_folderpath='docs_sup_folderpath';
5192: }
1.464 www 5193:
1.484.2.19 raeburn 5194: # No folderpath, and in edit mode, see if we have something stored
5195: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5196: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5197: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5198:
5199: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5200: if ($supplementalflag) {
5201: undef($env{'form.folderpath'}) if ($1 eq 'default');
5202: } else {
5203: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5204: }
5205: } else {
1.484.2.19 raeburn 5206: undef($env{'form.folderpath'});
5207: }
1.329 droeschl 5208: }
1.446 www 5209:
5210: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5211: if (!$allowed) {
1.446 www 5212: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5213: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5214: }
5215: }
1.446 www 5216: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5217: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5218: $env{'form.folderpath'} = &supplemental_base()
5219: .'&'.
1.329 droeschl 5220: $env{'form.folderpath'};
5221: }
1.484.2.67 raeburn 5222: # If allowed and user's role is not advanced check folderpath is not hidden
5223: if (($allowed) && (!$env{'request.role.adv'}) &&
5224: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5225: my $folderurl;
5226: my @pathitems = split(/\&/,$env{'form.folderpath'});
5227: my $folder = $pathitems[-2];
5228: if ($folder eq '') {
5229: undef($env{'form.folderpath'});
5230: } else {
5231: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5232: if ((split(/\:/,$pathitems[-1]))[4]) {
5233: $folderurl .= '.page';
5234: } else {
5235: $folderurl .= '.sequence';
5236: }
5237: unless (ref($navmap)) {
5238: $navmap = Apache::lonnavmaps::navmap->new();
5239: }
5240: if (ref($navmap)) {
5241: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5242: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5243: unless (@resources) {
5244: undef($env{'form.folderpath'});
5245: }
5246: }
5247: }
5248: }
5249: }
5250:
5251:
1.446 www 5252: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5253: unless ($env{'form.folderpath'}) {
1.446 www 5254: if ($supplementalflag) {
5255: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5256: } elsif ($allowed) {
5257: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5258: }
1.472 raeburn 5259: }
1.446 www 5260:
1.445 www 5261: # Store this
1.484 raeburn 5262: unless ($toolsflag) {
1.484.2.67 raeburn 5263: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5264: &Apache::loncommon::store_course_settings($stored_folderpath,
5265: {'folderpath' => 'scalar'});
5266: }
5267: my $folderpath;
1.484 raeburn 5268: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5269: $folderpath = $env{'form.folderpath'};
5270: my (@folders)=split('&',$env{'form.folderpath'});
5271: $env{'form.foldername'}=&unescape(pop(@folders));
5272: if ($env{'form.foldername'} =~ /\:1$/) {
5273: $container = 'page';
5274: } else {
5275: $container = 'sequence';
5276: }
5277: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5278: } else {
1.484.2.19 raeburn 5279: if ($env{'form.folder'} eq '' ||
5280: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5281: if ($env{'form.folder'} eq 'supplemental') {
5282: $folderpath=&supplemental_base();
5283: } elsif (!$hiddentop) {
5284: $folderpath='default&'.
5285: &escape(&mt('Main Content').':::::');
5286: }
1.484 raeburn 5287: }
5288: }
1.484.2.19 raeburn 5289: $containertag = '<input type="hidden" name="folderpath" value="" />';
5290: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5291: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5292: $showdoc='/'.$1;
5293: }
5294: if ($showdoc) { # got called in sequence from course
5295: $allowed=0;
5296: } else {
1.484.2.67 raeburn 5297: if ($canedit) {
1.484 raeburn 5298: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5299: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5300: }
5301: }
1.329 droeschl 5302: }
5303:
1.344 bisitz 5304: # get personal data
1.329 droeschl 5305: my $uname=$env{'user.name'};
5306: my $udom=$env{'user.domain'};
5307: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5308:
5309: if ($allowed) {
1.484 raeburn 5310: if ($toolsflag) {
5311: $script .= &inject_data_js();
5312: my ($home,$other,%outhash)=&authorhosts();
5313: if (!$home && $other) {
5314: my @hosts;
5315: foreach my $aurole (keys(%outhash)) {
5316: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5317: push(@hosts,$outhash{$aurole});
5318: }
5319: }
5320: $script .= &dump_switchserver_js(@hosts);
5321: }
1.458 raeburn 5322: } else {
1.484.2.43 raeburn 5323: my $tid = 1;
1.484 raeburn 5324: my @tabids;
5325: if ($supplementalflag) {
5326: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5327: $tid = 2;
1.484 raeburn 5328: } else {
5329: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5330: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5331: unshift(@tabids,'001');
5332: push(@tabids,('dd1','ee1'));
5333: }
1.458 raeburn 5334: }
1.484 raeburn 5335: my $tabidstr = join("','",@tabids);
1.484.2.80 raeburn 5336: my $hostname = $r->hostname();
1.484.2.68 raeburn 5337: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.80 raeburn 5338: $canedit,$hostname,\$navmap).
1.484 raeburn 5339: &history_tab_js().
5340: &inject_data_js().
1.484.2.43 raeburn 5341: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5342: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5343: $addentries = {
1.484.2.3 raeburn 5344: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5345: };
1.458 raeburn 5346: }
1.484.2.30 raeburn 5347: $script .= &paste_popup_js();
1.484.2.12 raeburn 5348: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5349: &mt('Switch server?');
1.484.2.19 raeburn 5350:
5351:
1.329 droeschl 5352: }
5353: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5354: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5355: .'// <![CDATA['."\n"
5356: .$script."\n"
5357: .'// ]]>'."\n"
1.484.2.81 raeburn 5358: .'</script>'."\n"
5359: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5360:
5361: # Breadcrumbs
5362: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5363:
5364: if ($showdoc) {
5365: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5366: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5367: } elsif ($toolsflag) {
1.484.2.67 raeburn 5368: my ($breadtext,$breadtitle);
5369: $breadtext = "$crstype Editor";
5370: if ($canedit) {
5371: $breadtitle = 'Editing '.$crstype.' Contents';
5372: } else {
5373: $breadtext .= ' (View-only mode)';
5374: $breadtitle = 'Viewing '.$crstype.' Contents';
5375: }
1.484.2.44 raeburn 5376: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5377: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5378: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5379: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5380: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5381: $breadtitle)
1.484.2.44 raeburn 5382: );
1.484.2.19 raeburn 5383: } elsif ($r->uri eq '/adm/supplemental') {
5384: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5385: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5386: {'bread_crumbs' => $brcrum,}));
5387: } else {
1.484.2.67 raeburn 5388: my ($breadtext,$breadtitle,$helpitem);
5389: $breadtext = "$crstype Editor";
5390: if ($canedit) {
5391: $breadtitle = 'Editing '.$crstype.' Contents';
5392: $helpitem = 'Docs_Adding_Course_Doc';
5393: } else {
5394: $breadtext .= ' (View-only mode)';
5395: $breadtitle = 'Viewing '.$crstype.' Contents';
5396: $helpitem = 'Docs_Viewing_Course_Doc';
5397: }
1.392 raeburn 5398: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5399: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5400: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5401: {'add_entries' => $addentries}
5402: )
1.392 raeburn 5403: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5404: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5405: $breadtitle,
5406: $helpitem)
1.392 raeburn 5407: );
5408: }
1.364 bisitz 5409:
1.329 droeschl 5410: my %allfiles = ();
5411: my %codebase = ();
1.440 raeburn 5412: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5413: if ($canedit) {
1.329 droeschl 5414: if (($env{'form.uploaddoc.filename'}) &&
5415: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5416: my $context = $1;
5417: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5418: undef($hadchanges);
1.440 raeburn 5419: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5420: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5421: undef($navmap);
1.329 droeschl 5422: if ($hadchanges) {
5423: &mark_hash_old();
5424: }
1.440 raeburn 5425: $r->print($upload_output);
5426: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5427: # Process file upload - phase two - upload embedded objects
5428: $uploadphase = 'check_embedded';
5429: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5430: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5431: $env{'form.newidx'});
5432: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5433: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5434: my ($destination,$dir_root) = &embedded_destination();
5435: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5436: my $actionurl = '/adm/coursedocs';
5437: my ($result,$flag) =
5438: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5439: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5440: $actionurl);
5441: $r->print($result.&return_to_editor());
5442: } elsif ($env{'form.phase'} eq 'check_embedded') {
5443: # Process file upload - phase three - modify references in HTML file
5444: $uploadphase = 'modified_orightml';
5445: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5446: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5447: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5448: my $result =
5449: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5450: $docuname,$docudom,undef,
5451: $dir_root);
5452: $r->print($result.&return_to_editor());
1.476 raeburn 5453: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5454: $uploadphase = 'decompress_phase_one';
5455: $r->print(&decompression_phase_one().
5456: &return_to_editor());
5457: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5458: $uploadphase = 'decompress_phase_two';
5459: $r->print(&decompression_phase_two().
5460: &return_to_editor());
1.329 droeschl 5461: }
5462: }
5463:
1.484 raeburn 5464: if ($allowed && $toolsflag) {
5465: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5466: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5467: $r->print(&endContentScreen());
5468: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5469: # -----------------------------------------------------------------------------
5470: my %lt=&Apache::lonlocal::texthash(
5471: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5472: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5473: 'upld' => 'Upload Content',
1.329 droeschl 5474: 'srch' => 'Search',
5475: 'impo' => 'Import',
1.484.2.19 raeburn 5476: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5477: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5478: 'selm' => 'Select Map',
5479: 'load' => 'Load Map',
5480: 'newf' => 'New Folder',
5481: 'newp' => 'New Composite Page',
5482: 'syll' => 'Syllabus',
1.425 raeburn 5483: 'navc' => 'Table of Contents',
1.343 biermanm 5484: 'sipa' => 'Simple Course Page',
1.329 droeschl 5485: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5486: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5487: 'drbx' => 'Drop Box',
1.451 www 5488: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5489: 'bull' => 'Discussion Board',
1.347 weissno 5490: 'mypi' => 'My Personal Information Page',
1.353 weissno 5491: 'grpo' => 'Group Portfolio',
1.329 droeschl 5492: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5493: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5494: 'imsf' => 'IMS Upload',
5495: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5496: 'cms' => 'Origin of IMS package',
5497: 'se' => 'Select',
1.484.2.19 raeburn 5498: 'file' => 'File',
1.329 droeschl 5499: 'title' => 'Title',
5500: 'comment' => 'Comment',
1.403 raeburn 5501: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5502: 'bb5' => 'Blackboard 5',
5503: 'bb6' => 'Blackboard 6',
5504: 'angel5' => 'ANGEL 5.5',
5505: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5506: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5507: );
1.329 droeschl 5508: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5509: # Calculate free quota space for a user or course. A javascript function checks
5510: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5511: my $quotatype = 'unofficial';
5512: if ($crstype eq 'Community') {
5513: $quotatype = 'community';
5514: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5515: $quotatype = 'official';
5516: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5517: $quotatype = 'textbook';
5518: }
5519: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5520: 'course',$quotatype); # expressed in MB
5521: my $current_disk_usage = 0;
5522: foreach my $subdir ('docs','supplemental') {
5523: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5524: "userfiles/$subdir",1); # expressed in kB
5525: }
5526: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5527: my $usage = $current_disk_usage/1024; # in MB
5528: my $quota = $disk_quota;
5529: my $percent;
5530: if ($disk_quota == 0) {
5531: $percent = 100.0;
5532: } else {
1.484.2.69 raeburn 5533: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5534: }
5535: $usage = sprintf("%.2f",$usage);
5536: $quota = sprintf("%.2f",$quota);
5537: $percent = sprintf("%.0f",$percent);
5538: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5539: $percent.'%',$quota.' MB').'</p>';
5540:
1.329 droeschl 5541: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5542: $quotainfo
1.329 droeschl 5543: $lt{'file'}:<br />
1.484.2.81 raeburn 5544: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5545: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5546: FIUP
5547:
5548: my $checkbox=(<<CHBO);
5549: <!-- <label>$lt{'parse'}?
5550: <input type="checkbox" name="parserflag" />
5551: </label> -->
5552: <label>
1.484.2.67 raeburn 5553: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5554: </label>
5555: CHBO
1.484.2.12 raeburn 5556: my $imsfolder = $env{'form.folder'};
5557: if ($imsfolder eq '') {
1.484.2.19 raeburn 5558: $imsfolder = 'default';
1.484.2.12 raeburn 5559: }
5560: my $imspform=(<<IMSFORM);
5561: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5562: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5563: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5564: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5565: <legend>$lt{'imsf'}</legend>
5566: $fileupload
5567: <br />
5568: <p>
1.484.2.19 raeburn 5569: $lt{'cms'}:
1.484.2.67 raeburn 5570: <select name="source" $disabled>
1.484.2.12 raeburn 5571: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5572: <option value="bb5">$lt{'bb5'}</option>
5573: <option value="bb6">$lt{'bb6'}</option>
5574: <option value="angel5">$lt{'angel5'}</option>
5575: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5576: </select>
5577: <input type="hidden" name="folder" value="$imsfolder" />
5578: </p>
5579: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5580: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5581: </fieldset>
5582: </form>
5583: IMSFORM
5584:
1.484.2.19 raeburn 5585: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5586: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5587: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5588: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5589: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5590: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5591: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5592: $fileupload
5593: <br />
5594: $lt{'title'}:<br />
1.484.2.67 raeburn 5595: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5596: $pathitem
1.329 droeschl 5597: <input type="hidden" name="cmd" value="upload_default" />
5598: <br />
1.458 raeburn 5599: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5600: $checkbox
5601: </span>
1.484.2.12 raeburn 5602: <br clear="all" />
1.484.2.67 raeburn 5603: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5604: </fieldset>
5605: </form>
1.383 tempelho 5606: FUFORM
1.329 droeschl 5607:
1.484.2.67 raeburn 5608: my $mapimportjs;
5609: if ($canedit) {
5610: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5611: } else {
5612: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5613: }
1.484.2.19 raeburn 5614: my $importpubform=(<<SEDFFORM);
5615: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5616: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5617: <form action="/adm/coursedocs" method="post" name="mapimportform">
5618: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5619: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5620: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5621: $lt{'copm'}<br />
5622: <span class="LC_nobreak">
1.484.2.19 raeburn 5623: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5624: onfocus="this.blur();$mapimportjs" $disabled />
5625: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5626: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5627: </fieldset>
5628: </form>
5629:
1.383 tempelho 5630: SEDFFORM
1.484.2.67 raeburn 5631:
5632: my $fromstoredjs;
5633: if ($canedit) {
5634: $fromstoredjs = 'open_StoredLinks_Import()';
5635: } else {
5636: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5637: }
5638:
1.484.2.19 raeburn 5639: my @importpubforma = (
5640: { '<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 5641: { '<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 5642: { '<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 5643: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5644: );
5645: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5646: my $extresourcesform =
5647: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5648: $help{'Adding_External_Resource'},
5649: undef,undef,$disabled);
1.329 droeschl 5650: if ($allowed) {
1.484.2.7 raeburn 5651: my $folder = $env{'form.folder'};
5652: if ($folder eq '') {
5653: $folder='default';
5654: }
1.484.2.67 raeburn 5655: if ($canedit) {
5656: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5657: if ($output) {
5658: $r->print($output);
5659: }
1.484.2.30 raeburn 5660: }
1.337 ehlerst 5661: $r->print(<<HIDDENFORM);
5662: <form name="renameform" method="post" action="/adm/coursedocs">
5663: <input type="hidden" name="title" />
5664: <input type="hidden" name="cmd" />
5665: <input type="hidden" name="markcopy" />
5666: <input type="hidden" name="copyfolder" />
5667: $containertag
5668: </form>
1.484 raeburn 5669:
1.337 ehlerst 5670: HIDDENFORM
1.484.2.17 raeburn 5671: $r->print(&makesimpleeditform($pathitem)."\n".
5672: &makedocslogform($pathitem."\n".
1.484 raeburn 5673: '<input type="hidden" name="folder" value="'.
5674: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5675: }
1.442 www 5676:
5677: # Generate the tabs
1.484.2.19 raeburn 5678: my ($mode,$needs_end);
1.472 raeburn 5679: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5680: my @folders = split('&',$env{'form.folderpath'});
5681: unless (@folders > 2) {
5682: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5683: $needs_end = 1;
5684: }
1.472 raeburn 5685: } else {
1.484 raeburn 5686: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5687: $needs_end = 1;
1.472 raeburn 5688: }
1.443 www 5689:
1.442 www 5690: #
5691:
5692: my $savefolderpath;
5693:
1.395 raeburn 5694: if ($allowed) {
1.329 droeschl 5695: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5696: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5697: $folder='default';
1.356 tempelho 5698: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5699: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5700: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5701: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5702: }
5703: my $postexec='';
5704: if ($folder eq 'default') {
1.372 bisitz 5705: $r->print('<script type="text/javascript">'."\n"
5706: .'// <![CDATA['."\n"
5707: .'this.window.name="loncapaclient";'."\n"
5708: .'// ]]>'."\n"
5709: .'</script>'."\n"
1.369 bisitz 5710: );
1.329 droeschl 5711: } else {
5712: #$postexec='self.close();';
5713: }
1.484.2.15 raeburn 5714: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5715: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5716: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5717:
5718: my $newnavform=(<<NNFORM);
5719: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5720: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5721: $pathitem
1.329 droeschl 5722: <input type="hidden" name="importdetail"
5723: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5724: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5725: $help{'Navigate_Content'}
5726: </form>
5727: NNFORM
5728: my $newsmppageform=(<<NSPFORM);
5729: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5730: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5731: $pathitem
1.329 droeschl 5732: <input type="hidden" name="importdetail" value="" />
1.423 onken 5733: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5734: $help{'Simple Page'}
1.329 droeschl 5735: </form>
5736: NSPFORM
5737:
5738: my $newsmpproblemform=(<<NSPROBFORM);
5739: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5740: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5741: $pathitem
1.329 droeschl 5742: <input type="hidden" name="importdetail" value="" />
1.423 onken 5743: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5744: $help{'Simple_Problem'}
1.329 droeschl 5745: </form>
5746:
5747: NSPROBFORM
5748:
5749: my $newdropboxform=(<<NDBFORM);
5750: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5751: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5752: $pathitem
1.329 droeschl 5753: <input type="hidden" name="importdetail" value="" />
1.423 onken 5754: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5755: $help{'Dropbox'}
1.344 bisitz 5756: </form>
1.329 droeschl 5757: NDBFORM
5758:
5759: my $newexuploadform=(<<NEXUFORM);
5760: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5761: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5762: $pathitem
1.329 droeschl 5763: <input type="hidden" name="importdetail" value="" />
1.423 onken 5764: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5765: $help{'Score_Upload_Form'}
5766: </form>
5767: NEXUFORM
5768:
5769: my $newbulform=(<<NBFORM);
5770: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5771: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5772: $pathitem
1.329 droeschl 5773: <input type="hidden" name="importdetail" value="" />
1.423 onken 5774: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5775: $help{'Bulletin Board'}
5776: </form>
5777: NBFORM
5778:
5779: my $newaboutmeform=(<<NAMFORM);
5780: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5781: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5782: $pathitem
1.329 droeschl 5783: <input type="hidden" name="importdetail"
5784: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5785: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5786: $help{'My Personal Information Page'}
1.329 droeschl 5787: </form>
5788: NAMFORM
5789:
5790: my $newaboutsomeoneform=(<<NASOFORM);
5791: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5792: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5793: $pathitem
1.329 droeschl 5794: <input type="hidden" name="importdetail" value="" />
1.423 onken 5795: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5796: </form>
5797: NASOFORM
5798:
5799: my $newrosterform=(<<NROSTFORM);
5800: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5801: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5802: $pathitem
1.329 droeschl 5803: <input type="hidden" name="importdetail"
5804: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5805: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5806: $help{'Course_Roster'}
1.329 droeschl 5807: </form>
5808: NROSTFORM
5809:
1.484.2.27 raeburn 5810: my $newwebpage;
5811: if ($folder =~ /^default_?(\d*)$/) {
5812: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5813: if ($1) {
5814: $newwebpage .= $1;
5815: } else {
5816: $newwebpage .= 'default';
5817: }
5818: $newwebpage .= '/new.html';
5819: }
5820: my $newwebpageform =(<<NWEBFORM);
5821: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5822: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5823: $pathitem
5824: <input type="hidden" name="importdetail" value="$newwebpage" />
5825: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5826: $help{'Web_Page'}
1.484.2.27 raeburn 5827: </form>
5828: NWEBFORM
1.484.2.30 raeburn 5829:
1.484.2.27 raeburn 5830:
1.342 ehlerst 5831: my $specialdocumentsform;
1.383 tempelho 5832: my @specialdocumentsforma;
1.451 www 5833: my $gradingform;
5834: my @gradingforma;
5835: my $communityform;
5836: my @communityforma;
1.351 ehlerst 5837: my $newfolderform;
1.390 tempelho 5838: my $newfolderb;
1.342 ehlerst 5839:
1.451 www 5840: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5841:
1.329 droeschl 5842: my $newpageform=(<<NPFORM);
5843: <form action="/adm/coursedocs" method="post" name="newpage">
5844: <input type="hidden" name="folderpath" value="$path" />
5845: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5846: <input type="hidden" name="active" value="ee" />
1.423 onken 5847: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5848: $help{'Adding_Pages'}
1.329 droeschl 5849: </form>
5850: NPFORM
1.390 tempelho 5851:
5852:
1.351 ehlerst 5853: $newfolderform=(<<NFFORM);
1.329 droeschl 5854: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5855: $pathitem
1.329 droeschl 5856: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5857: <input type="hidden" name="active" value="" />
1.422 onken 5858: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5859: </form>
5860: NFFORM
5861:
5862: my $newsylform=(<<NSYLFORM);
5863: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5864: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5865: $pathitem
1.329 droeschl 5866: <input type="hidden" name="importdetail"
5867: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5868: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5869: $help{'Syllabus'}
1.383 tempelho 5870:
1.329 droeschl 5871: </form>
5872: NSYLFORM
1.364 bisitz 5873:
1.329 droeschl 5874: my $newgroupfileform=(<<NGFFORM);
5875: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5876: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5877: $pathitem
1.329 droeschl 5878: <input type="hidden" name="importdetail"
5879: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5880: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5881: $help{'Group Portfolio'}
1.329 droeschl 5882: </form>
5883: NGFFORM
1.383 tempelho 5884: @specialdocumentsforma=(
1.421 onken 5885: {'<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 5886: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5887: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5888: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5889: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5890: );
5891: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5892:
1.434 raeburn 5893:
5894: my @importdoc = (
1.484.2.19 raeburn 5895: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5896: );
5897: unless ($container eq 'page') {
5898: push(@importdoc,
5899: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5900: );
5901: }
5902: push(@importdoc,
1.484.2.38 raeburn 5903: {'<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 5904: );
1.484.2.12 raeburn 5905: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5906:
1.451 www 5907: @gradingforma=(
5908: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5909: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5910: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5911:
5912: );
5913: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5914:
5915: @communityforma=(
5916: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5917: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5918: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5919: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5920: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5921: );
5922: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5923:
1.330 tempelho 5924: my %orderhash = (
1.484.2.36 raeburn 5925: 'aa' => ['Upload',$fileuploadform],
5926: 'bb' => ['Import',$importpubform],
5927: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5928: );
1.484.2.19 raeburn 5929: unless ($container eq 'page') {
1.434 raeburn 5930: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5931: $orderhash{'dd'} = ['Collaboration',$communityform];
1.484.2.36 raeburn 5932: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5933: }
5934:
1.341 ehlerst 5935: $hadchanges=0;
1.484 raeburn 5936: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5937: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5938: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.68 raeburn 5939: $canedit,\$navmap,$hiddentop);
1.484.2.67 raeburn 5940: undef($navmap);
1.443 www 5941: if ($error) {
5942: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5943: }
5944: if ($hadchanges) {
1.484.2.73 raeburn 5945: unless (&is_hash_old()) {
5946: &mark_hash_old();
5947: }
1.443 www 5948: }
1.341 ehlerst 5949:
1.443 www 5950: &changewarning($r,'');
5951: }
1.458 raeburn 5952: }
1.442 www 5953:
1.443 www 5954: # Supplemental documents start here
5955:
1.329 droeschl 5956: my $folder=$env{'form.folder'};
1.443 www 5957: unless ($supplementalflag) {
1.329 droeschl 5958: $folder='supplemental';
5959: }
5960: if ($folder =~ /^supplemental$/ &&
5961: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5962: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5963: } elsif ($allowed) {
1.356 tempelho 5964: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5965: }
1.484.2.17 raeburn 5966: $pathitem = '<input type="hidden" name="folderpath" value="'.
5967: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5968: if ($allowed) {
5969: my $folderseq=
1.484.2.15 raeburn 5970: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5971:
5972: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 5973: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5974: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5975: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 5976: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 5977: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5978: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5979: $fileupload
5980: <br />
5981: <br />
5982: <span class="LC_nobreak">
5983: $checkbox
5984: </span>
5985: <br /><br />
5986: $lt{'comment'}:<br />
1.383 tempelho 5987: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5988: <br />
1.484.2.19 raeburn 5989: $pathitem
1.329 droeschl 5990: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 5991: <input type='submit' value="$lt{'upld'}" />
5992: </form>
1.484.2.19 raeburn 5993: SUPDOCFORM
1.329 droeschl 5994:
5995: my $supnewfolderform=(<<SNFFORM);
5996: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 5997: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 5998: $pathitem
1.329 droeschl 5999: <input type="hidden" name="importdetail" value="" />
1.423 onken 6000: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6001: $help{'Adding_Folders'}
1.329 droeschl 6002: </form>
6003: SNFFORM
1.383 tempelho 6004:
1.484.2.19 raeburn 6005: my $supextform =
6006: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6007: $help{'Adding_External_Resource'},
6008: undef,undef,$disabled);
1.329 droeschl 6009:
6010: my $supnewsylform=(<<SNSFORM);
6011: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6012: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6013: $pathitem
1.329 droeschl 6014: <input type="hidden" name="importdetail"
6015: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6016: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6017: $help{'Syllabus'}
6018: </form>
6019: SNSFORM
6020:
6021: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6022: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6023: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6024: $pathitem
1.329 droeschl 6025: <input type="hidden" name="importdetail"
6026: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6027: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6028: $help{'My Personal Information Page'}
1.329 droeschl 6029: </form>
6030: SNAMFORM
6031:
1.484.2.27 raeburn 6032: my $supwebpage;
6033: if ($folder =~ /^supplemental_?(\d*)$/) {
6034: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6035: if ($1) {
6036: $supwebpage .= $1;
6037: } else {
6038: $supwebpage .= 'default';
6039: }
6040: $supwebpage .= '/new.html';
6041: }
6042: my $supwebpageform =(<<SWEBFORM);
6043: <form action="/adm/coursedocs" method="post" name="supwebpage">
6044: <input type="hidden" name="active" value="cc" />
6045: $pathitem
6046: <input type="hidden" name="importdetail" value="$supwebpage" />
6047: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6048: $help{'Web_Page'}
1.484.2.27 raeburn 6049: </form>
6050: SWEBFORM
6051:
1.333 muellerd 6052:
1.383 tempelho 6053: my @specialdocs = (
1.484.2.67 raeburn 6054: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6055: =>$supnewsylform},
1.484.2.67 raeburn 6056: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6057: =>$supnewaboutmeform},
1.484.2.27 raeburn 6058: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6059:
1.383 tempelho 6060: );
1.417 droeschl 6061: my @supimportdoc = (
1.484.2.19 raeburn 6062: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 6063: =>$supextform},
6064: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6065: =>$supupdocform},
1.484.2.19 raeburn 6066: );
6067:
1.484.2.12 raeburn 6068: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6069: my %suporderhash = (
1.390 tempelho 6070: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6071: 'ee' => ['Upload',$supupdocform],
6072: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6073: );
1.443 www 6074: if ($supplementalflag) {
1.458 raeburn 6075: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6076: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6077: $canedit);
1.443 www 6078: if ($error) {
6079: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6080: } else {
6081: if ($suppchanges) {
6082: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6083: my @ids=&Apache::lonnet::current_machine_ids();
6084: foreach my $server (keys(%servers)) {
6085: next if (grep(/^\Q$server\E$/,@ids));
6086: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6087: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6088: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6089: }
6090: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6091: undef($suppchanges);
6092: }
1.443 www 6093: }
1.393 raeburn 6094: }
1.443 www 6095: } elsif ($supplementalflag) {
1.458 raeburn 6096: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 6097: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 6098: if ($error) {
6099: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6100: }
1.393 raeburn 6101: }
1.389 tempelho 6102:
1.484.2.19 raeburn 6103: if ($needs_end) {
6104: $r->print(&endContentScreen());
6105: }
1.383 tempelho 6106:
1.329 droeschl 6107: if ($allowed) {
6108: $r->print('
6109: <form method="post" name="extimport" action="/adm/coursedocs">
6110: <input type="hidden" name="title" />
6111: <input type="hidden" name="url" />
6112: <input type="hidden" name="useform" />
6113: <input type="hidden" name="residx" />
6114: </form>');
6115: }
1.484 raeburn 6116: } elsif ($showdoc) {
1.329 droeschl 6117: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6118: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6119: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6120: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6121: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6122: }
6123: }
6124: $r->print(&Apache::loncommon::end_page());
6125: return OK;
1.364 bisitz 6126: }
1.329 droeschl 6127:
1.440 raeburn 6128: sub embedded_form_elems {
6129: my ($phase,$primaryurl,$newidx) = @_;
6130: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6131: $newidx =~s /\D+//g;
1.440 raeburn 6132: return <<STATE;
6133: <input type="hidden" name="folderpath" value="$folderpath" />
6134: <input type="hidden" name="cmd" value="upload_embedded" />
6135: <input type="hidden" name="newidx" value="$newidx" />
6136: <input type="hidden" name="phase" value="$phase" />
6137: <input type="hidden" name="primaryurl" value="$primaryurl" />
6138: STATE
6139: }
6140:
6141: sub embedded_destination {
6142: my $folder=$env{'form.folder'};
6143: my $destination = 'docs/';
6144: if ($folder =~ /^supplemental/) {
6145: $destination = 'supplemental/';
6146: }
6147: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6148: $destination .= 'default/';
6149: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6150: $destination .= $2.'/';
6151: }
1.484.2.78 raeburn 6152: my $newidx = $env{'form.newidx'};
6153: $newidx =~s /\D+//g;
6154: if ($newidx) {
6155: $destination .= $newidx;
6156: }
1.440 raeburn 6157: my $dir_root = '/userfiles';
6158: return ($destination,$dir_root);
6159: }
6160:
6161: sub return_to_editor {
6162: my $actionurl = '/adm/coursedocs';
6163: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6164: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6165: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6166: '</a></p>';
6167: }
6168:
1.476 raeburn 6169: sub decompression_info {
6170: my ($destination,$dir_root) = &embedded_destination();
6171: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6172: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6173: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6174: my $container='sequence';
1.480 raeburn 6175: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6176: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6177: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6178: $container='page';
6179: }
1.480 raeburn 6180: unshift(@hiddens,$pathitem);
6181: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6182: if ($item eq 'newidx') {
6183: next if ($env{'form.'.$item} =~ /\D/);
6184: }
1.480 raeburn 6185: if ($env{'form.'.$item}) {
6186: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6187: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6188: }
1.477 raeburn 6189: }
1.476 raeburn 6190: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6191: $hiddenelem);
6192: }
6193:
6194: sub decompression_phase_one {
6195: my ($dir,$file,$warning,$error,$output);
6196: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6197: &decompression_info();
1.484.2.7 raeburn 6198: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6199: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6200: } else {
6201: my $file = $1;
1.481 raeburn 6202: $output =
6203: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6204: $destination,$dir_root,
6205: $hiddenelem);
6206: if ($env{'form.autoextract_camtasia'}) {
6207: $output .= &remove_archive($docudom,$docuname,$container);
6208: }
1.476 raeburn 6209: }
6210: if ($error) {
6211: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6212: $error.'</p>'."\n";
6213: }
6214: if ($warning) {
6215: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6216: }
6217: return $output;
6218: }
6219:
6220: sub decompression_phase_two {
6221: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6222: &decompression_info();
1.481 raeburn 6223: my $output;
1.480 raeburn 6224: if ($env{'form.archivedelete'}) {
1.481 raeburn 6225: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6226: }
6227: $output .=
1.481 raeburn 6228: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6229: $destination,$dir_root,$hiddenelem);
6230: return $output;
6231: }
6232:
1.480 raeburn 6233: sub remove_archive {
6234: my ($docudom,$docuname,$container) = @_;
6235: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6236: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6237: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6238: if ($fatal) {
6239: if ($container eq 'page') {
6240: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6241: } else {
6242: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6243: }
1.484.2.54 raeburn 6244: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6245: } else {
6246: my $currcmd = $env{'form.cmd'};
6247: my $position = $env{'form.position'};
1.484.2.54 raeburn 6248: my $archiveidx = $position;
6249: if ($position > 0) {
6250: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6251: $archiveidx = $position-1;
6252: }
6253: $env{'form.cmd'} = 'remove_'.$archiveidx;
6254: my ($title,$url,@rrest) =
6255: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6256: if ($url eq $env{'form.archiveurl'}) {
6257: if (&handle_edit_cmd($docuname,$docudom)) {
6258: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6259: if ($fatal) {
6260: if ($container eq 'page') {
6261: $delwarning = &mt('An error occurred updating the contents of the current page.');
6262: } else {
6263: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6264: }
1.480 raeburn 6265: } else {
1.484.2.54 raeburn 6266: $delresult = &mt('Archive file removed.');
1.480 raeburn 6267: }
6268: }
1.484.2.54 raeburn 6269: } else {
6270: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6271: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6272: }
6273: }
6274: $env{'form.cmd'} = $currcmd;
6275: }
6276: if ($delwarning) {
6277: $output = '<p class="LC_warning">'.
6278: $delwarning.
6279: '</p>';
6280: }
6281: if ($delresult) {
6282: $output .= '<p class="LC_info">'.
6283: $delresult.
6284: '</p>';
6285: }
1.481 raeburn 6286: return $output;
1.480 raeburn 6287: }
6288:
1.484 raeburn 6289: sub generate_admin_menu {
1.484.2.67 raeburn 6290: my ($crstype,$canedit) = @_;
1.484 raeburn 6291: my $lc_crstype = lc($crstype);
6292: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6293: my %lt= ( # do not translate here
1.484 raeburn 6294: 'vc' => 'Verify Content',
6295: 'cv' => 'Check/Set Resource Versions',
6296: 'ls' => 'List Resource Identifiers',
6297: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6298: 'dcd' => "Copy $crstype Content to Authoring Space",
6299: );
1.484 raeburn 6300: my ($candump,$dumpurl);
6301: if ($home + $other > 0) {
6302: $candump = 'F';
6303: if ($home) {
6304: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6305: } else {
6306: my @hosts;
6307: foreach my $aurole (keys(%outhash)) {
6308: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6309: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6310: }
1.484 raeburn 6311: }
6312: if (@hosts == 1) {
6313: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6314: '&role='.
6315: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6316: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6317: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6318: } else {
6319: $dumpurl = "javascript:choose_switchserver_window()";
6320: }
6321: }
6322: }
6323: my @menu=
6324: ({ categorytitle=>'Administration',
6325: items =>[
6326: { linktext => $lt{'vc'},
6327: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6328: permission => 'F',
1.484.2.44 raeburn 6329: help => 'Docs_Verify_Content',
1.484 raeburn 6330: icon => 'verify.png',
6331: linktitle => 'Verify contents can be retrieved/rendered',
6332: },
6333: { linktext => $lt{'cv'},
6334: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6335: permission => 'F',
1.484.2.44 raeburn 6336: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6337: icon => 'resversion.png',
6338: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6339: },
6340: { linktext => $lt{'ls'},
6341: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6342: permission => 'F',
6343: #help => '',
6344: icon => 'symbs.png',
6345: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6346: },
6347: ]
1.484.2.67 raeburn 6348: });
6349: if ($canedit) {
6350: push(@menu,
1.484 raeburn 6351: { categorytitle=>'Export',
6352: items =>[
6353: { linktext => $lt{'imse'},
6354: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6355: permission => 'F',
6356: help => 'Docs_Export_Course_Docs',
6357: icon => 'imsexport.png',
6358: linktitle => $lt{'imse'},
6359: },
6360: { linktext => $lt{'dcd'},
6361: url => $dumpurl,
6362: permission => $candump,
1.484.2.44 raeburn 6363: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6364: icon => 'dump.png',
6365: linktitle => $lt{'dcd'},
6366: },
6367: ]
6368: });
1.484.2.67 raeburn 6369: }
1.484 raeburn 6370: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6371: '<input type="hidden" id="dummy" />'."\n".
6372: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6373: '</form>';
1.329 droeschl 6374: }
6375:
6376: sub generate_edit_table {
1.484.2.30 raeburn 6377: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6378: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6379: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6380: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6381: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6382: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6383: $activetab = $env{'form.active'};
6384: }
1.484.2.67 raeburn 6385: unless ($canedit) {
6386: $disabled = ' disabled="disabled"';
6387: }
1.472 raeburn 6388: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6389: my $backtext = &mt('Exit Editor');
1.458 raeburn 6390: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6391: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6392: '<li class="goback">'.
1.484.2.32 raeburn 6393: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6394: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6395: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6396: '<li>'.
6397: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6398: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6399: if ($env{'form.docslog'}) {
6400: $form .= '<li class="active">';
6401: } else {
6402: $form .= '<li>';
6403: }
6404: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6405: &mt('History').'</a></li>'."\n";
6406: if ($env{'form.docslog'}) {
6407: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6408: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6409: }
1.458 raeburn 6410: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6411: if($name ne '00'){
1.371 tempelho 6412: if($activetab eq '' || $activetab ne $name){
6413: $active = '';
6414: }elsif($activetab eq $name){
6415: $active = 'class="active"';
6416: }
1.458 raeburn 6417: $form .= '<li style="float:right" '.$active
1.484 raeburn 6418: .' 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 6419: } else {
1.484.2.43 raeburn 6420: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6421:
6422: }
1.329 droeschl 6423: }
1.484 raeburn 6424: $form .= '</ul>'."\n";
6425: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6426:
6427: if ($to_show ne '') {
1.484.2.30 raeburn 6428: my $saveform;
6429: if ($need_save) {
6430: my $button = &mt('Make changes');
6431: my $path;
6432: if ($env{'form.folderpath'}) {
6433: $path =
6434: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6435: }
6436: $saveform = <<"END";
6437: <div id="multisave" style="display:none; clear:both;" >
6438: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6439: <input type="hidden" name="folderpath" value="$path" />
6440: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6441: <input type="hidden" name="allhiddenresource" value="" />
6442: <input type="hidden" name="allencrypturl" value="" />
6443: <input type="hidden" name="allrandompick" value="" />
6444: <input type="hidden" name="allrandomorder" value="" />
6445: <input type="hidden" name="changeparms" value="" />
6446: <input type="hidden" name="multiremove" value="" />
6447: <input type="hidden" name="multicut" value="" />
6448: <input type="hidden" name="multicopy" value="" />
6449: <input type="hidden" name="multichange" value="" />
6450: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6451: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6452: </form>
6453: </div>
6454: END
6455: }
6456: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6457: }
1.363 ehlerst 6458: foreach my $field (keys(%orderhash)){
1.390 tempelho 6459: if($field ne '00'){
1.422 onken 6460: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6461: $active = 'style="display: none;float:left"';
1.422 onken 6462: }elsif($activetab eq $field){
1.458 raeburn 6463: $active = 'style="display:block;float:left"';
1.422 onken 6464: }
6465: $form .= '<div id="'.$field.$tid.'"'
6466: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6467: .'</div>'."\n";
1.363 ehlerst 6468: }
6469: }
1.484 raeburn 6470: unless ($env{'form.docslog'}) {
6471: $form .= '</div></div>'."\n";
6472: }
1.329 droeschl 6473: return $form;
6474: }
6475:
6476: sub editing_js {
1.484.2.80 raeburn 6477: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,
6478: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6479: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6480: p_mnf => 'Name of New Folder',
6481: t_mnf => 'New Folder',
6482: p_mnp => 'Name of New Page',
6483: t_mnp => 'New Page',
1.451 www 6484: p_mxu => 'Title for the External Score',
1.349 biermanm 6485: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6486: p_msb => 'Title for the Problem',
6487: p_mdb => 'Title for the Drop Box',
1.336 schafran 6488: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6489: p_mwp => 'Title for Web Page',
1.348 weissno 6490: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6491: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6492: p_mab_alrt1 => 'Not a valid user:domain',
6493: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6494: p_chn => 'New Title',
6495: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6496: p_rmr2a => 'Remove',
6497: p_rmr2b => '?',
6498: p_rmr3a => 'Remove those',
6499: p_rmr3b => 'items?',
6500: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6501: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6502: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6503: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6504: p_ctr2a => 'Cut',
6505: p_ctr2b => '?',
6506: p_ctr3a => 'Cut those',
6507: p_ctr3b => 'items?',
1.478 raeburn 6508: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6509: imsfile => 'You must choose an IMS package for import',
6510: imscms => 'You must select which Course Management System was the source of the IMS package',
6511: invurl => 'Invalid URL',
6512: titbl => 'Title is blank',
1.484.2.30 raeburn 6513: more => '(More ...)',
6514: less => '(Less ...)',
6515: noor => 'No actions selected or changes to settings specified.',
6516: noch => 'No changes to settings specified.',
6517: noac => 'No actions selected.',
1.484.2.67 raeburn 6518: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6519: );
6520:
1.484.2.61 raeburn 6521: &js_escape(\%js_lt);
1.433 raeburn 6522: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6523: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6524: my $main_container_page;
1.484.2.19 raeburn 6525: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6526: $main_container_page = 1;
1.434 raeburn 6527: }
1.484.2.67 raeburn 6528: my $backtourl;
6529: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6530: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6531:
1.484.2.21 raeburn 6532: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6533: my $caller = $1;
6534: if ($caller =~ /^supplemental/) {
6535: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6536: } else {
6537: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6538: $res = &Apache::lonnet::clutter($res);
6539: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6540: my ($url,$anchor);
6541: if ($res =~ /^([^#]+)#([^#]+)$/) {
6542: $url = $1;
6543: $anchor = $2;
6544: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6545: $caller = $1.&escape('#').$anchor;
6546: }
1.484.2.67 raeburn 6547: } else {
6548: $url = $res;
1.484.2.66 raeburn 6549: }
1.484.2.83! raeburn 6550: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
! 6551: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
! 6552: $backtourl .= '?navmap=1';
! 6553: } else {
! 6554: $backtourl .= '?symb='.
! 6555: &HTML::Entities::encode($caller,'<>&"');
! 6556: }
1.484.2.80 raeburn 6557: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6558: if (($ENV{'SERVER_PORT'} == 443) &&
6559: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6560: unless (&Apache::lonnet::uses_sts()) {
6561: if ($hostname ne '') {
6562: $backtourl = 'http://'.$hostname.$backtourl;
6563: }
6564: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6565: }
6566: }
6567: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6568: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6569: unless (&Apache::lonnet::uses_sts()) {
6570: if ($hostname ne '') {
6571: $backtourl = 'http://'.$hostname.$backtourl;
6572: }
6573: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6574: }
6575: }
6576: }
1.484.2.66 raeburn 6577: if ($anchor ne '') {
6578: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6579: }
1.484.2.57 raeburn 6580: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6581: } else {
6582: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6583: }
6584: }
6585: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6586: $backtourl = '/adm/menu';
6587: } elsif ($supplementalflag) {
1.472 raeburn 6588: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6589: } else {
6590: $backtourl = '/adm/navmaps';
1.472 raeburn 6591: }
6592:
1.484.2.19 raeburn 6593: my $fieldsets = "'ext','doc'";
6594: unless ($main_container_page) {
6595: $fieldsets .=",'ims'";
6596: }
1.484.2.12 raeburn 6597: if ($supplementalflag) {
6598: $fieldsets = "'suppext','suppdoc'";
6599: }
6600:
1.484.2.67 raeburn 6601: my $jsmakefunctions;
6602: if ($canedit) {
6603: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6604: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6605: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6606: if (foldername) {
6607: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6608: targetform.submit();
6609: }
6610: }
6611:
6612: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6613: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6614: if (pagename) {
6615: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6616: targetform.submit();
6617: }
6618: }
6619:
6620: function makeexamupload() {
1.484.2.61 raeburn 6621: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6622: if (title) {
1.329 droeschl 6623: this.document.forms.newexamupload.importdetail.value=
6624: escape(title)+'=/res/lib/templates/examupload.problem';
6625: this.document.forms.newexamupload.submit();
6626: }
6627: }
6628:
6629: function makesmppage() {
1.484.2.61 raeburn 6630: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6631: if (title) {
1.329 droeschl 6632: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6633: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6634: this.document.forms.newsmppg.submit();
6635: }
6636: }
6637:
1.484.2.27 raeburn 6638: function makewebpage(type) {
1.484.2.61 raeburn 6639: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6640: var formname;
6641: if (type == 'supp') {
6642: formname = this.document.forms.supwebpage;
6643: } else {
6644: formname = this.document.forms.newwebpage;
6645: }
6646: if (title) {
6647: var webpage = formname.importdetail.value;
6648: formname.importdetail.value = escape(title)+'='+webpage;
6649: formname.submit();
6650: }
6651: }
6652:
1.329 droeschl 6653: function makesmpproblem() {
1.484.2.61 raeburn 6654: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6655: if (title) {
1.329 droeschl 6656: this.document.forms.newsmpproblem.importdetail.value=
6657: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6658: this.document.forms.newsmpproblem.submit();
6659: }
6660: }
6661:
6662: function makedropbox() {
1.484.2.61 raeburn 6663: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6664: if (title) {
1.329 droeschl 6665: this.document.forms.newdropbox.importdetail.value=
6666: escape(title)+'=/res/lib/templates/DropBox.problem';
6667: this.document.forms.newdropbox.submit();
6668: }
6669: }
6670:
6671: function makebulboard() {
1.484.2.61 raeburn 6672: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6673: if (title) {
6674: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6675: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6676: this.document.forms.newbul.submit();
6677: }
6678: }
6679:
6680: function makeabout() {
1.484.2.61 raeburn 6681: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6682: if (user) {
6683: var comp=new Array();
6684: comp=user.split(':');
6685: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6686: if ((comp[0]) && (comp[1])) {
6687: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6688: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6689: this.document.forms.newaboutsomeone.submit();
6690: } else {
6691: alert("$js_lt{'p_mab_alrt1'}");
6692: }
6693: } else {
6694: alert("$js_lt{'p_mab_alrt2'}");
6695: }
6696: }
1.335 ehlerst 6697: }
1.484.2.67 raeburn 6698:
6699: function makenew(targetform) {
6700: targetform.submit();
1.335 ehlerst 6701: }
1.484.2.67 raeburn 6702:
6703: function changename(folderpath,index,oldtitle) {
6704: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6705: if (title) {
6706: this.document.forms.renameform.markcopy.value='';
6707: this.document.forms.renameform.title.value=title;
6708: this.document.forms.renameform.cmd.value='rename_'+index;
6709: this.document.forms.renameform.folderpath.value=folderpath;
6710: this.document.forms.renameform.submit();
6711: }
1.329 droeschl 6712: }
6713:
1.484.2.67 raeburn 6714: ENDNEWSCRIPT
6715: } else {
6716: $jsmakefunctions = <<ENDNEWSCRIPT;
6717:
6718: function makenewfolder() {
6719: alert("$js_lt{'edri'}");
6720: }
6721:
6722: function makenewpage() {
6723: alert("$js_lt{'edri'}");
6724: }
6725:
6726: function makeexamupload() {
6727: alert("$js_lt{'edri'}");
6728: }
6729:
6730: function makesmppage() {
6731: alert("$js_lt{'edri'}");
6732: }
6733:
6734: function makewebpage(type) {
6735: alert("$js_lt{'edri'}");
6736: }
6737:
6738: function makesmpproblem() {
6739: alert("$js_lt{'edri'}");
6740: }
6741:
6742: function makedropbox() {
6743: alert("$js_lt{'edri'}");
6744: }
6745:
6746: function makebulboard() {
6747: alert("$js_lt{'edri'}");
6748: }
6749:
6750: function makeabout() {
6751: alert("$js_lt{'edri'}");
6752: }
6753:
6754: function changename() {
6755: alert("$js_lt{'edri'}");
6756: }
6757:
6758: function makenew() {
6759: alert("$js_lt{'edri'}");
6760: }
6761:
6762: function groupimport() {
6763: alert("$js_lt{'edri'}");
6764: }
6765:
6766: function groupsearch() {
6767: alert("$js_lt{'edri'}");
6768: }
6769:
6770: function groupopen(url,recover) {
6771: var options="scrollbars=1,resizable=1,menubar=0";
6772: idxflag=1;
6773: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6774: idx.focus();
6775: }
6776:
6777: ENDNEWSCRIPT
6778:
6779: }
6780: return <<ENDSCRIPT;
6781:
6782: $jsmakefunctions
6783:
1.484.2.13 raeburn 6784: function toggleUpload(caller) {
6785: var blocks = Array($fieldsets);
6786: for (var i=0; i<blocks.length; i++) {
6787: var disp = 'none';
6788: if (caller == blocks[i]) {
6789: var curr = document.getElementById('upload'+caller+'form').style.display;
6790: if (curr == 'none') {
6791: disp='block';
6792: }
6793: }
6794: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6795: }
6796: resize_scrollbox('contentscroll','1','1');
6797: return;
6798: }
6799:
1.484.2.19 raeburn 6800: function toggleMap(caller) {
1.484.2.13 raeburn 6801: var disp = 'none';
1.484.2.19 raeburn 6802: if (document.getElementById('importmapform')) {
6803: if (caller == 'map') {
6804: var curr = document.getElementById('importmapform').style.display;
6805: if (curr == 'none') {
6806: disp='block';
6807: }
1.484.2.12 raeburn 6808: }
1.484.2.19 raeburn 6809: document.getElementById('importmapform').style.display=disp;
6810: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6811: }
1.484.2.19 raeburn 6812: return;
1.329 droeschl 6813: }
6814:
1.484.2.12 raeburn 6815: function makeims(imsform) {
6816: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6817: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6818: return;
6819: }
6820: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6821: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6822: return;
6823: }
6824: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6825: imsform.submit();
6826: }
6827:
1.478 raeburn 6828: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6829: var pickitem;
6830: var picknumitem;
6831: var picknumtext;
6832: if (index == 'all') {
6833: pickitem = document.getElementById('randompickall');
6834: picknumitem = document.getElementById('rpicknumall');
6835: picknumtext = document.getElementById('rpicktextall');
6836: } else {
6837: pickitem = document.getElementById('randompick_'+index);
6838: picknumitem = document.getElementById('rpicknum_'+index);
6839: picknumtext = document.getElementById('randompicknum_'+index);
6840: }
1.478 raeburn 6841: if (pickitem.checked) {
1.484.2.61 raeburn 6842: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6843: if (picknum == '' || picknum == null) {
6844: if (caller == 'check') {
6845: pickitem.checked=false;
1.484.2.29 raeburn 6846: if (index == 'all') {
6847: picknumtext.innerHTML = '';
6848: if (caller == 'link') {
6849: propagateState(targetform,'rpicknum');
6850: }
6851: } else {
1.484.2.30 raeburn 6852: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6853: }
1.478 raeburn 6854: }
6855: } else {
6856: picknum.toString();
6857: var regexdigit=/^\\d+\$/;
6858: if (regexdigit.test(picknum)) {
6859: picknumitem.value = picknum;
1.484.2.29 raeburn 6860: if (index == 'all') {
1.484.2.30 raeburn 6861: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6862: if (caller == 'link') {
6863: propagateState(targetform,'rpicknum');
6864: }
6865: } else {
6866: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6867: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6868: }
1.478 raeburn 6869: } else {
6870: if (caller == 'check') {
1.484.2.29 raeburn 6871: if (index == 'all') {
6872: picknumtext.innerHTML = '';
6873: if (caller == 'link') {
6874: propagateState(targetform,'rpicknum');
6875: }
6876: } else {
6877: pickitem.checked=false;
1.484.2.30 raeburn 6878: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6879: }
1.478 raeburn 6880: }
6881: return;
6882: }
6883: }
6884: } else {
1.484.2.29 raeburn 6885: picknumitem.value = '';
6886: picknumtext.innerHTML = '';
6887: if (index == 'all') {
6888: if (caller == 'link') {
6889: propagateState(targetform,'rpicknum');
6890: }
6891: } else {
1.484.2.30 raeburn 6892: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6893: }
6894: }
6895: }
6896:
6897: function propagateState(form,param) {
6898: if (document.getElementById(param+'all')) {
6899: var setcheck = 0;
6900: var rpick = 0;
6901: if (param == 'rpicknum') {
6902: if (document.getElementById('randompickall')) {
6903: if (document.getElementById('randompickall').checked) {
6904: if (document.getElementById('rpicknumall')) {
6905: rpick = document.getElementById('rpicknumall').value;
6906: }
6907: }
6908: }
6909: } else {
6910: if (document.getElementById(param+'all').checked) {
6911: setcheck = 1;
6912: }
6913: }
1.484.2.30 raeburn 6914: var allidxlist;
6915: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6916: if (document.getElementById('all'+param+'idx')) {
6917: allidxlist = document.getElementById('all'+param+'idx').value;
6918: }
6919: var actions = new Array ('remove','cut','copy');
6920: for (var i=0; i<actions.length; i++) {
6921: if (actions[i] != param) {
6922: if (document.getElementById(actions[i]+'all')) {
6923: document.getElementById(actions[i]+'all').checked = false;
6924: }
6925: }
6926: }
6927: }
1.484.2.29 raeburn 6928: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6929: allidxlist = form.allidx.value;
6930: }
6931: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6932: allidxlist = form.allmapidx.value;
6933: }
6934: if ((allidxlist != '') && (allidxlist != null)) {
6935: var allidxs = allidxlist.split(',');
6936: if (allidxs.length > 1) {
6937: for (var i=0; i<allidxs.length; i++) {
6938: if (document.getElementById(param+'_'+allidxs[i])) {
6939: if (param == 'rpicknum') {
6940: if (document.getElementById('randompick_'+allidxs[i])) {
6941: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6942: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6943: if (rpick > 0) {
6944: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6945: } else {
6946: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6947: }
6948: }
6949: }
6950: } else {
1.484.2.29 raeburn 6951: if (setcheck == 1) {
6952: document.getElementById(param+'_'+allidxs[i]).checked = true;
6953: } else {
6954: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6955: if (param == 'randompick') {
6956: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6957: }
1.484.2.29 raeburn 6958: }
6959: }
6960: }
6961: }
1.484.2.30 raeburn 6962: if (setcheck == 1) {
6963: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6964: var actions = new Array('copy','cut','remove');
6965: for (var i=0; i<actions.length; i++) {
6966: var otheractions;
6967: var otheridxs;
6968: if (actions[i] === param) {
6969: continue;
6970: } else {
6971: if (document.getElementById('all'+actions[i]+'idx')) {
6972: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6973: otheridxs = otheractions.split(',');
6974: if (otheridxs.length > 1) {
6975: for (var j=0; j<otheridxs.length; j++) {
6976: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6977: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6978: }
1.484.2.29 raeburn 6979: }
6980: }
6981: }
6982: }
1.484.2.30 raeburn 6983: }
1.484.2.29 raeburn 6984: }
6985: }
6986: }
6987: }
1.478 raeburn 6988: }
1.484.2.29 raeburn 6989: return;
6990: }
6991:
1.484.2.63 raeburn 6992: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 6993: var canedit = '$canedit';
6994: if (canedit == '') {
6995: alert("$js_lt{'edri'}");
6996: return;
6997: }
1.484.2.30 raeburn 6998: var dosettings;
6999: var doaction;
7000: var control = document.togglemultsettings;
7001: if (context == 'actions') {
7002: control = document.togglemultactions;
7003: doaction = 1;
7004: } else {
7005: dosettings = 1;
7006: }
7007: if (control) {
7008: if (control.showmultpick.length) {
7009: for (var i=0; i<control.showmultpick.length; i++) {
7010: if (control.showmultpick[i].checked) {
7011: if (control.showmultpick[i].value == 1) {
7012: if (context == 'settings') {
7013: dosettings = 0;
7014: } else {
7015: doaction = 0;
7016: }
7017: }
7018: }
7019: }
7020: }
7021: }
7022: if (context == 'settings') {
7023: if (dosettings == 1) {
7024: targetform.changeparms.value=param;
7025: targetform.submit();
7026: }
7027: }
7028: if (context == 'actions') {
7029: if (doaction == 1) {
7030: targetform.cmd.value=param+'_'+index;
7031: targetform.folderpath.value=folderpath;
7032: targetform.markcopy.value=idx+':'+param;
7033: targetform.copyfolder.value=folder+'.'+container;
7034: if (param == 'remove') {
1.484.2.63 raeburn 7035: var doremove = 0;
7036: if (skip_confirm) {
7037: if (confirm_removal) {
7038: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7039: doremove = 1;
7040: }
7041: } else {
7042: doremove = 1;
7043: }
7044: } else {
7045: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7046: doremove = 1;
7047: }
7048: }
7049: if (doremove) {
1.484.2.30 raeburn 7050: targetform.markcopy.value='';
7051: targetform.copyfolder.value='';
1.484.2.29 raeburn 7052: targetform.submit();
7053: }
7054: }
1.484.2.30 raeburn 7055: if (param == 'cut') {
1.484.2.61 raeburn 7056: 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 7057: targetform.submit();
7058: return;
7059: }
7060: }
7061: if (param == 'copy') {
7062: targetform.submit();
7063: return;
7064: }
7065: targetform.markcopy.value='';
7066: targetform.copyfolder.value='';
7067: targetform.cmd.value='';
7068: targetform.folderpath.value='';
7069: return;
7070: } else {
7071: if (document.getElementById(param+'_'+idx)) {
7072: item = document.getElementById(param+'_'+idx);
7073: if (item.type == 'checkbox') {
7074: if (item.checked) {
7075: item.checked = false;
7076: } else {
7077: item.checked = true;
7078: singleCheck(item,idx,param);
7079: }
7080: }
7081: }
7082: }
7083: }
7084: return;
7085: }
7086:
7087: function singleCheck(caller,idx,action) {
7088: actions = new Array('cut','copy','remove');
7089: if (caller.checked) {
7090: for (var i=0; i<actions.length; i++) {
7091: if (actions[i] != action) {
7092: if (document.getElementById(actions[i]+'_'+idx)) {
7093: if (document.getElementById(actions[i]+'_'+idx).checked) {
7094: document.getElementById(actions[i]+'_'+idx).checked = false;
7095: }
7096: }
7097: }
1.484.2.29 raeburn 7098: }
7099: }
7100: return;
1.478 raeburn 7101: }
7102:
1.334 muellerd 7103: function unselectInactive(nav) {
1.335 ehlerst 7104: currentNav = document.getElementById(nav);
7105: currentLis = currentNav.getElementsByTagName('LI');
7106: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7107: if (currentLis[i].className == 'goback') {
7108: currentLis[i].className = 'goback';
7109: } else {
7110: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7111: currentLis[i].className = 'right';
1.472 raeburn 7112: } else {
1.374 tempelho 7113: currentLis[i].className = 'i';
1.472 raeburn 7114: }
7115: }
1.335 ehlerst 7116: }
1.332 tempelho 7117: }
7118:
1.334 muellerd 7119: function hideAll(current, nav, data) {
1.335 ehlerst 7120: unselectInactive(nav);
1.484.2.43 raeburn 7121: if (current) {
7122: if (current.className == 'right'){
1.374 tempelho 7123: current.className = 'right active'
1.484.2.43 raeburn 7124: } else {
1.374 tempelho 7125: current.className = 'active';
1.484.2.43 raeburn 7126: }
1.374 tempelho 7127: }
1.335 ehlerst 7128: currentData = document.getElementById(data);
7129: currentDivs = currentData.getElementsByTagName('DIV');
7130: for (i = 0; i < currentDivs.length; i++) {
7131: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7132: currentDivs[i].style.display = 'none';
1.330 tempelho 7133: }
7134: }
1.335 ehlerst 7135: }
1.330 tempelho 7136:
1.374 tempelho 7137: function openTabs(pageId) {
7138: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7139: if(tabnav.length > 2 ){
1.389 tempelho 7140: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7141: currentLis = currentNav.getElementsByTagName('LI');
7142: for(i = 0; i< currentLis.length; i++){
7143: if(currentLis[i].className == 'active') {
1.375 tempelho 7144: funcString = currentLis[i].onclick.toString();
7145: tab = funcString.split('"');
1.420 onken 7146: if(tab.length < 2) {
7147: tab = funcString.split("'");
7148: }
1.375 tempelho 7149: currentData = document.getElementById(tab[1]);
7150: currentData.style.display = 'block';
1.374 tempelho 7151: }
7152: }
7153: }
7154: }
7155:
1.334 muellerd 7156: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7157: currstate = current.className;
1.334 muellerd 7158: hideAll(current, nav, data);
1.375 tempelho 7159: openTabs(pageId);
1.334 muellerd 7160: unselectInactive(nav);
1.484.2.43 raeburn 7161: if ((currstate == 'active') || (currstate == 'right active')) {
7162: if (currstate == 'active') {
7163: current.className = '';
7164: } else {
7165: current.className = 'right';
7166: }
7167: activeTab = '';
7168: toggleUpload();
7169: toggleMap();
7170: resize_scrollbox('contentscroll','1','0');
7171: return;
7172: } else {
7173: current.className = 'active';
7174: }
1.330 tempelho 7175: currentData = document.getElementById(pageId);
7176: currentData.style.display = 'block';
1.458 raeburn 7177: activeTab = pageId;
1.484.2.12 raeburn 7178: toggleUpload();
1.484.2.14 raeburn 7179: toggleMap();
1.433 raeburn 7180: if (nav == 'mainnav') {
7181: var storedpath = "$docs_folderpath";
1.434 raeburn 7182: var storedpage = "$main_container_page";
1.433 raeburn 7183: var reg = new RegExp("^supplemental");
7184: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7185: if (storedpage == 1) {
7186: document.simpleedit.folderpath.value = '';
7187: document.uploaddocument.folderpath.value = '';
7188: } else {
7189: if (reg.test(storedpath)) {
7190: document.simpleedit.folderpath.value = '$toplevelmain';
7191: document.uploaddocument.folderpath.value = '$toplevelmain';
7192: document.newext.folderpath.value = '$toplevelmain';
7193: } else {
7194: document.simpleedit.folderpath.value = storedpath;
7195: document.uploaddocument.folderpath.value = storedpath;
7196: document.newext.folderpath.value = storedpath;
7197: }
1.433 raeburn 7198: }
7199: } else {
1.434 raeburn 7200: if (reg.test(storedpath)) {
7201: document.simpleedit.folderpath.value = storedpath;
7202: document.supuploaddocument.folderpath.value = storedpath;
7203: document.supnewext.folderpath.value = storedpath;
7204: } else {
1.433 raeburn 7205: document.simpleedit.folderpath.value = '$toplevelsupp';
7206: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7207: document.supnewext.folderpath.value = '$toplevelsupp';
7208: }
7209: }
7210: }
1.484.2.3 raeburn 7211: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7212: return false;
7213: }
1.329 droeschl 7214:
1.472 raeburn 7215: function toContents(jumpto) {
7216: var newurl = '$backtourl';
1.484.2.21 raeburn 7217: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7218: newurl = newurl+'?postdata='+jumpto;
7219: }
7220: location.href=newurl;
7221: }
7222:
1.484.2.30 raeburn 7223: function togglePick(caller,value) {
7224: var disp = 'none';
7225: if (document.getElementById('multi'+caller)) {
7226: var curr = document.getElementById('multi'+caller).style.display;
7227: if (value == 1) {
7228: disp='block';
7229: }
7230: if (curr == disp) {
7231: return;
7232: }
7233: document.getElementById('multi'+caller).style.display=disp;
7234: if (value == 1) {
1.484.2.61 raeburn 7235: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7236: } else {
7237: document.getElementById('more'+caller).innerHTML = '';
7238: }
7239: if (caller == 'actions') {
7240: setClass(value);
7241: setBoxes(value);
7242: }
7243: }
7244: var showButton = multiSettings();
7245: if (showButton != 1) {
7246: showButton = multiActions();
7247: }
7248: if (document.getElementById('multisave')) {
7249: if (showButton == 1) {
7250: document.getElementById('multisave').style.display='block';
7251: } else {
7252: document.getElementById('multisave').style.display='none';
7253: }
7254: }
7255: resize_scrollbox('contentscroll','1','1');
7256: return;
7257: }
7258:
7259: function toggleCheckUncheck(caller,more) {
7260: if (more == 1) {
1.484.2.61 raeburn 7261: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7262: document.getElementById('allfields'+caller).style.display='block';
7263: } else {
1.484.2.61 raeburn 7264: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7265: document.getElementById('allfields'+caller).style.display='none';
7266: }
7267: resize_scrollbox('contentscroll','1','1');
7268: }
7269:
7270: function multiSettings() {
7271: var inuse = 0;
7272: var settingsform = document.togglemultsettings;
7273: if (settingsform.showmultpick.length > 1) {
7274: for (var i=0; i<settingsform.showmultpick.length; i++) {
7275: if (settingsform.showmultpick[i].checked) {
7276: if (settingsform.showmultpick[i].value == 1) {
7277: inuse = 1;
7278: }
7279: }
7280: }
7281: }
7282: return inuse;
7283: }
7284:
7285: function multiActions() {
7286: var inuse = 0;
7287: var actionsform = document.togglemultactions;
7288: if (actionsform.showmultpick.length > 1) {
7289: for (var i=0; i<actionsform.showmultpick.length; i++) {
7290: if (actionsform.showmultpick[i].checked) {
7291: if (actionsform.showmultpick[i].value == 1) {
7292: inuse = 1;
7293: }
7294: }
7295: }
7296: }
7297: return inuse;
7298: }
7299:
7300: function checkSubmits() {
7301: var numchanges = 0;
7302: var form = document.saveactions;
7303: var doactions = multiActions();
7304: var cutwarnings = 0;
7305: var remwarnings = 0;
1.484.2.63 raeburn 7306: var removalinfo = 0;
1.484.2.30 raeburn 7307: if (doactions == 1) {
7308: var remidxlist = document.cumulativeactions.allremoveidx.value;
7309: if ((remidxlist != '') && (remidxlist != null)) {
7310: var remidxs = remidxlist.split(',');
7311: for (var i=0; i<remidxs.length; i++) {
7312: if (document.getElementById('remove_'+remidxs[i])) {
7313: if (document.getElementById('remove_'+remidxs[i]).checked) {
7314: form.multiremove.value += remidxs[i]+',';
7315: numchanges ++;
7316: if (document.getElementById('skip_remove_'+remidxs[i])) {
7317: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7318: remwarnings ++;
7319: }
7320: }
1.484.2.63 raeburn 7321: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7322: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7323: removalinfo ++;
7324: }
7325: }
1.484.2.30 raeburn 7326: }
7327: }
7328: }
7329: }
7330: var cutidxlist = document.cumulativeactions.allcutidx.value;
7331: if ((cutidxlist != '') && (cutidxlist != null)) {
7332: var cutidxs = cutidxlist.split(',');
7333: for (var i=0; i<cutidxs.length; i++) {
7334: if (document.getElementById('cut_'+cutidxs[i])) {
7335: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7336: form.multicut.value += cutidxs[i]+',';
7337: numchanges ++;
7338: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7339: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7340: cutwarnings ++;
7341: }
7342: }
7343: }
7344: }
7345: }
7346: }
7347: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7348: if ((copyidxlist != '') && (copyidxlist != null)) {
7349: var copyidxs = copyidxlist.split(',');
7350: for (var i=0; i<copyidxs.length; i++) {
7351: if (document.getElementById('copy_'+copyidxs[i])) {
7352: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7353: form.multicopy.value += copyidxs[i]+',';
7354: numchanges ++;
7355: }
7356: }
7357: }
7358: }
7359: if (numchanges > 0) {
7360: form.multichange.value = numchanges;
7361: }
7362: }
7363: var dosettings = multiSettings();
7364: var haschanges = 0;
7365: if (dosettings == 1) {
7366: form.allencrypturl.value = '';
7367: form.allhiddenresource.value = '';
7368: form.changeparms.value = 'all';
7369: var patt=new RegExp(",\$");
7370: var allidxlist = document.cumulativesettings.allidx.value;
7371: if ((allidxlist != '') && (allidxlist != null)) {
7372: var allidxs = allidxlist.split(',');
7373: if (allidxs.length > 1) {
7374: for (var i=0; i<allidxs.length; i++) {
7375: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7376: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7377: form.allhiddenresource.value += allidxs[i]+',';
7378: }
7379: }
7380: if (document.getElementById('encrypturl_'+allidxs[i])) {
7381: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7382: form.allencrypturl.value += allidxs[i]+',';
7383: }
1.484.2.29 raeburn 7384: }
7385: }
1.484.2.30 raeburn 7386: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7387: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7388: }
7389: }
7390: form.allrandompick.value = '';
7391: form.allrandomorder.value = '';
7392: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7393: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7394: var allmapidxs = allmapidxlist.split(',');
7395: for (var i=0; i<allmapidxs.length; i++) {
7396: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7397: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7398: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7399: if ((randompick.checked) && (rpicknum.value != '')) {
7400: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7401: }
7402: if (randorder.checked) {
7403: form.allrandomorder.value += allmapidxs[i]+',';
7404: }
7405: }
7406: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7407: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7408: }
7409: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7410: haschanges = 1;
7411: }
7412: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7413: haschanges = 1;
7414: }
7415: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7416: haschanges = 1;
7417: }
7418: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7419: haschanges = 1;
7420: }
7421: }
7422: if (doactions == 1) {
7423: if (numchanges > 0) {
1.484.2.63 raeburn 7424: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7425: if (remwarnings > 0) {
1.484.2.61 raeburn 7426: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7427: return false;
7428: }
7429: }
1.484.2.63 raeburn 7430: if (removalinfo > 0) {
7431: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7432: return false;
7433: }
7434: }
1.484.2.30 raeburn 7435: if (cutwarnings > 0) {
1.484.2.61 raeburn 7436: 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 7437: return false;
1.484.2.29 raeburn 7438: }
7439: }
7440: }
1.484.2.30 raeburn 7441: form.submit();
7442: return true;
7443: }
7444: }
7445: if (dosettings == 1) {
7446: if (haschanges == 1) {
7447: form.submit();
7448: return true;
1.484.2.29 raeburn 7449: }
7450: }
1.484.2.30 raeburn 7451: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7452: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7453: } else {
7454: if (dosettings == 1) {
1.484.2.61 raeburn 7455: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7456: } else {
1.484.2.61 raeburn 7457: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7458: }
7459: }
7460: return false;
7461: }
7462:
7463: function setClass(value) {
7464: var cutclass = 'LC_docs_cut';
7465: var copyclass = 'LC_docs_copy';
7466: var removeclass = 'LC_docs_remove';
7467: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7468: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7469: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7470: var links = document.getElementsByTagName('a');
7471: for (var i=0; i<links.length; i++) {
7472: var classes = links[i].className;
7473: if (cutreg.test(classes)) {
7474: links[i].className = cutclass;
7475: if (value == 1) {
7476: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7477: }
1.484.2.30 raeburn 7478: } else {
7479: if (copyreg.test(classes)) {
7480: links[i].className = copyclass;
7481: if (value == 1) {
7482: links[i].className += " LC_menubuttons_link";
7483: }
7484: } else {
7485: if (removereg.test(classes)) {
7486: links[i].className = removeclass;
7487: if (value == 1) {
7488: links[i].className += " LC_menubuttons_link";
7489: }
7490: }
1.484.2.29 raeburn 7491: }
7492: }
7493: }
1.484.2.30 raeburn 7494: return;
1.484.2.29 raeburn 7495: }
7496:
1.484.2.30 raeburn 7497: function setBoxes(value) {
7498: var remidxlist = document.cumulativeactions.allremoveidx.value;
7499: if ((remidxlist != '') && (remidxlist != null)) {
7500: var remidxs = remidxlist.split(',');
7501: for (var i=0; i<remidxs.length; i++) {
7502: if (document.getElementById('remove_'+remidxs[i])) {
7503: var item = document.getElementById('remove_'+remidxs[i]);
7504: if (value == 1) {
7505: item.className = 'LC_docs_remove';
7506: } else {
7507: item.className = 'LC_hidden';
7508: }
7509: }
1.484.2.29 raeburn 7510: }
7511: }
1.484.2.30 raeburn 7512: var cutidxlist = document.cumulativeactions.allcutidx.value;
7513: if ((cutidxlist != '') && (cutidxlist != null)) {
7514: var cutidxs = cutidxlist.split(',');
7515: for (var i=0; i<cutidxs.length; i++) {
7516: if (document.getElementById('cut_'+cutidxs[i])) {
7517: var item = document.getElementById('cut_'+cutidxs[i]);
7518: if (value == 1) {
7519: item.className = 'LC_docs_cut';
7520: } else {
7521: item.className = 'LC_hidden';
7522: }
7523: }
7524: }
7525: }
7526: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7527: if ((copyidxlist != '') && (copyidxlist != null)) {
7528: var copyidxs = copyidxlist.split(',');
7529: for (var i=0; i<copyidxs.length; i++) {
7530: if (document.getElementById('copy_'+copyidxs[i])) {
7531: var item = document.getElementById('copy_'+copyidxs[i]);
7532: if (value == 1) {
7533: item.className = 'LC_docs_copy';
7534: } else {
7535: item.className = 'LC_hidden';
7536: }
7537: }
1.484.2.29 raeburn 7538: }
7539: }
7540: return;
7541: }
7542:
1.484.2.67 raeburn 7543: ENDSCRIPT
1.329 droeschl 7544: }
1.457 raeburn 7545:
1.483 raeburn 7546: sub history_tab_js {
7547: return <<"ENDHIST";
7548: function toggleHistoryDisp(choice) {
7549: document.docslogform.docslog.value = choice;
7550: document.docslogform.submit();
7551: return;
7552: }
7553:
7554: ENDHIST
7555: }
7556:
1.484 raeburn 7557: sub inject_data_js {
7558: return <<ENDINJECT;
7559:
7560: function injectData(current, hiddenField, name, value) {
7561: currentElement = document.getElementById(hiddenField);
7562: currentElement.name = name;
7563: currentElement.value = value;
7564: current.submit();
7565: }
7566:
7567: ENDINJECT
7568: }
7569:
7570: sub dump_switchserver_js {
7571: my @hosts = @_;
1.484.2.61 raeburn 7572: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7573: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7574: swit => 'Switch server?',
1.484.2.61 raeburn 7575: );
7576: my %html_js_lt = &Apache::lonlocal::texthash(
7577: swit => 'Switch server?',
1.484.2.43 raeburn 7578: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7579: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7580: chos => 'Choose server',
7581: );
1.484.2.61 raeburn 7582: &js_escape(\%js_lt);
7583: &html_escape(\%html_js_lt);
7584: &js_escape(\%html_js_lt);
1.484 raeburn 7585: my $role = $env{'request.role'};
7586: my $js = <<"ENDSWJS";
7587: <script type="text/javascript">
7588: function write_switchserver() {
7589: var server;
7590: if (document.setserver.posshosts.length > 0) {
7591: for (var i=0; i<document.setserver.posshosts.length; i++) {
7592: if (document.setserver.posshosts[i].checked) {
7593: server = document.setserver.posshosts[i].value;
7594: }
7595: }
7596: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7597: }
7598: window.close();
7599: }
7600: </script>
7601:
7602: ENDSWJS
7603:
7604: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7605: {'only_body' => 1,
7606: 'js_ready' => 1,});
7607: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7608:
7609: my $hostpicker;
7610: my $count = 0;
7611: foreach my $host (sort(@hosts)) {
7612: my $checked;
7613: if ($count == 0) {
7614: $checked = ' checked="checked"';
7615: }
7616: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7617: $host.'"'.$checked.' />'.$host.'</label> ';
7618: $count++;
7619: }
7620:
7621: return <<"ENDSWITCHJS";
7622:
7623: function dump_needs_switchserver(url) {
7624: if (url!='' && url!= null) {
1.484.2.61 raeburn 7625: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7626: go(url);
7627: }
7628: }
7629: return;
7630: }
7631:
7632: function choose_switchserver_window() {
7633: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7634: newWindow.document.open();
7635: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7636: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7637: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7638: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7639: '<form name="setserver" method="post" action="" \\/>\\n'+
7640: '$hostpicker\\n'+
7641: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7642: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7643: 'onclick="write_switchserver();" \\/>\\n'+
7644: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7645: newWindow.document.writeln('$endpage');
7646: newWindow.document.close();
7647: newWindow.focus();
7648: }
7649:
7650: ENDSWITCHJS
7651: }
7652:
7653: sub makedocslogform {
7654: my ($formelems,$docslog) = @_;
7655: return <<"LOGSFORM";
7656: <form action="/adm/coursedocs" method="post" name="docslogform">
7657: <input type="hidden" name="docslog" value="$docslog" />
7658: $formelems
7659: </form>
7660: LOGSFORM
7661: }
7662:
7663: sub makesimpleeditform {
7664: my ($formelems) = @_;
7665: return <<"SIMPFORM";
7666: <form name="simpleedit" method="post" action="/adm/coursedocs">
7667: <input type="hidden" name="importdetail" value="" />
7668: $formelems
7669: </form>
7670: SIMPFORM
7671: }
7672:
1.329 droeschl 7673: 1;
7674: __END__
7675:
7676:
7677: =head1 NAME
7678:
7679: Apache::londocs.pm
7680:
7681: =head1 SYNOPSIS
7682:
7683: This is part of the LearningOnline Network with CAPA project
7684: described at http://www.lon-capa.org.
7685:
7686: =head1 SUBROUTINES
7687:
7688: =over
7689:
7690: =item %help=()
7691:
7692: Available help topics
7693:
7694: =item mapread()
7695:
1.344 bisitz 7696: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7697: @order and @resources, determines status
7698: sets @order - pointer to resources in right order
7699: sets @resources - array with the resources with correct idx
7700:
7701: =item authorhosts()
7702:
7703: Return hash with valid author names
7704:
7705: =item clean()
7706:
7707: =item dumpcourse()
7708:
7709: Actually dump course
7710:
7711: =item group_import()
7712:
7713: Imports the given (name, url) resources into the course
7714: coursenum, coursedom, and folder must precede the list
7715:
7716: =item breadcrumbs()
7717:
7718: =item log_docs()
7719:
7720: =item docs_change_log()
7721:
7722: =item update_paste_buffer()
7723:
7724: =item print_paste_buffer()
7725:
7726: =item do_paste_from_buffer()
7727:
1.484.2.30 raeburn 7728: =item do_buffer_empty()
7729:
7730: =item clear_from_buffer()
7731:
1.484.2.7 raeburn 7732: =item get_newmap_url()
7733:
7734: =item dbcopy()
7735:
7736: =item uniqueness_check()
7737:
7738: =item contained_map_check()
7739:
7740: =item url_paste_fixups()
7741:
7742: =item apply_fixups()
7743:
7744: =item copy_dependencies()
7745:
1.329 droeschl 7746: =item update_parameter()
7747:
7748: =item handle_edit_cmd()
7749:
7750: =item editor()
7751:
7752: =item process_file_upload()
7753:
7754: =item process_secondary_uploads()
7755:
7756: =item is_supplemental_title()
7757:
7758: =item entryline()
7759:
7760: =item tiehash()
7761:
7762: =item untiehash()
7763:
7764: =item checkonthis()
7765:
7766: check on this
7767:
7768: =item verifycontent()
7769:
7770: Verify Content
7771:
1.484.2.78 raeburn 7772: =item devalidateversioncache()
7773:
7774: =item checkversions()
1.329 droeschl 7775:
7776: Check Versions
7777:
7778: =item mark_hash_old()
7779:
7780: =item is_hash_old()
7781:
7782: =item changewarning()
7783:
7784: =item init_breadcrumbs()
7785:
7786: Breadcrumbs for special functions
7787:
1.484 raeburn 7788: =item create_list_elements()
7789:
7790: =item create_form_ul()
7791:
7792: =item startContentScreen()
7793:
7794: =item endContentScreen()
7795:
7796: =item supplemental_base()
7797:
7798: =item embedded_form_elems()
7799:
7800: =item embedded_destination()
7801:
7802: =item return_to_editor()
7803:
7804: =item decompression_info()
7805:
7806: =item decompression_phase_one()
7807:
7808: =item decompression_phase_two()
7809:
7810: =item remove_archive()
7811:
7812: =item generate_admin_menu()
7813:
7814: =item generate_edit_table()
7815:
7816: =item editing_js()
7817:
7818: =item history_tab_js()
7819:
7820: =item inject_data_js()
7821:
7822: =item dump_switchserver_js()
7823:
1.484.2.3 raeburn 7824: =item resize_scrollbox_js()
1.484 raeburn 7825:
7826: =item makedocslogform()
7827:
1.484.2.3 raeburn 7828: =item makesimpleeditform()
7829:
1.329 droeschl 7830: =back
7831:
7832: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>