Annotation of loncom/interface/londocs.pm, revision 1.626
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.626 ! raeburn 4: # $Id: londocs.pm,v 1.625 2017/05/07 13:57:58 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.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.329 droeschl 48: use HTML::Entities;
1.488 raeburn 49: use HTML::TokeParser;
1.329 droeschl 50: use GDBM_File;
1.578 raeburn 51: use File::MMagic;
1.606 raeburn 52: use File::Copy;
1.329 droeschl 53: use Apache::lonlocal;
54: use Cwd;
55: use LONCAPA qw(:DEFAULT :match);
56:
57: my $iconpath;
58:
59: my %hash;
60:
61: my $hashtied;
62: my %alreadyseen=();
63:
64: my $hadchanges;
1.557 raeburn 65: my $suppchanges;
1.329 droeschl 66:
67:
68: my %help=();
69:
70:
71: sub mapread {
72: my ($coursenum,$coursedom,$map)=@_;
73: return
74: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
75: $map);
76: }
77:
78: sub storemap {
1.492 raeburn 79: my ($coursenum,$coursedom,$map,$contentchg)=@_;
80: my $report;
81: if (($contentchg) && ($map =~ /^default/)) {
82: $report = 1;
83: }
1.329 droeschl 84: my ($outtext,$errtext)=
85: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 86: $map,1,$report);
1.329 droeschl 87: if ($errtext) { return ($errtext,2); }
1.364 bisitz 88:
1.557 raeburn 89: if ($map =~ /^default/) {
90: $hadchanges=1;
91: } else {
92: $suppchanges=1;
93: }
1.329 droeschl 94: return ($errtext,0);
95: }
96:
97:
98:
99: sub authorhosts {
100: my %outhash=();
101: my $home=0;
102: my $other=0;
103: foreach my $key (keys(%env)) {
104: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
105: my $role=$1;
106: my $realm=$2;
107: my ($start,$end)=split(/\./,$env{$key});
108: if (($start) && ($start>time)) { next; }
109: if (($end) && (time>$end)) { next; }
110: my ($ca,$cd);
111: if ($1 eq 'au') {
112: $ca=$env{'user.name'};
113: $cd=$env{'user.domain'};
114: } else {
115: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
116: }
117: my $allowed=0;
118: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
119: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 120: foreach my $id (@ids) {
121: if ($id eq $myhome) {
122: $allowed=1;
123: last;
124: }
125: }
1.329 droeschl 126: if ($allowed) {
127: $home++;
1.484 raeburn 128: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 129: } else {
1.484 raeburn 130: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 131: $other++;
132: }
133: }
134: }
135: return ($home,$other,%outhash);
136: }
137:
138:
139: sub clean {
140: my ($title)=@_;
141: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 142: return $title;
1.329 droeschl 143: }
144:
1.617 raeburn 145: sub default_folderpath {
146: my ($coursenum,$coursedom,$navmapref) = @_;
147: return unless ($coursenum && $coursedom && ref($navmapref));
148: # Check if entire course is hidden and/or encrypted
149: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
150: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
151: unless (ref($$navmapref)) {
152: $$navmapref = Apache::lonnavmaps::navmap->new();
153: }
154: if (ref($$navmapref)) {
155: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
156: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
157: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
158: unless (@resources) {
159: $hiddenmap = 1;
160: unless ($env{'request.role.adv'}) {
161: $hiddentop = 1;
162: if ($env{'form.folder'}) {
163: undef($env{'form.folder'});
164: }
165: }
166: }
167: }
168: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
169: $encryptmap = 1;
170: }
171: }
172: unless ($hiddentop) {
173: $folderpath='default&'.&escape(&mt('Main Content')).
174: '::'.$hiddenmap.':'.$encryptmap.'::';
175: }
176: if (wantarray) {
177: return ($folderpath,$hiddentop);
178: } else {
179: return $folderpath;
180: }
181: }
1.329 droeschl 182:
183: sub dumpcourse {
184: my ($r) = @_;
1.408 raeburn 185: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 186: my ($starthash,$js);
187: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
188: $js = <<"ENDJS";
189: <script type="text/javascript">
190: // <![CDATA[
191:
192: function hide_searching() {
193: if (document.getElementById('searching')) {
194: document.getElementById('searching').style.display = 'none';
195: }
196: return;
197: }
198:
199: // ]]>
200: </script>
201: ENDJS
202: $starthash = {
203: add_entries => {'onload' => "hide_searching();"},
204: };
205: }
1.568 raeburn 206: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
207: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 208: $r->print(&startContentScreen('tools'));
1.329 droeschl 209: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 210: unless ($home) {
211: $r->print(&endContentScreen());
212: return '';
213: }
1.329 droeschl 214: my $origcrsid=$env{'request.course.id'};
215: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
216: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
217: # Do the dumping
1.484 raeburn 218: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
219: $r->print(&endContentScreen());
220: return '';
221: }
1.531 raeburn 222: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 223: $r->print('<h3>'.&mt('Copying Files').'</h3>');
224: my $title=$env{'form.authorfolder'};
225: $title=&clean($title);
1.567 raeburn 226: my ($navmap,$errormsg) =
227: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
228: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
229: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
230: my (%maps,%resources,%titles);
231: if (!ref($navmap)) {
232: $r->print($errormsg.
233: &endContentScreen());
234: return '';
235: } else {
236: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
237: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 238: }
1.567 raeburn 239: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
240: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
241: %newcontent,%has_simpleprobs);
242: foreach my $item (sort {$a <=> $b} (@todump)) {
243: my $name = $env{'form.namefor_'.$item};
244: if ($resources{$item}) {
245: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
246: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
247: $tocopy{$1} = $name;
248: $display{$item} = $1;
249: $lookup{$1} = $item;
250: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
251: $simpleproblems{$item} = {
252: symb => $resources{$item},
253: name => $name,
254: };
255: $display{$item} = 'simpleproblem_'.$name;
256: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
257: $has_simpleprobs{$1}{$id} = $item;
258: }
259: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
260: my $marker = $1;
261: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
262: $simplepages{$item} = {
263: res => $res,
264: title => $titles{$item},
265: db => $db_name,
266: marker => $marker,
267: symb => $resources{$item},
268: name => $name,
269: };
270: $display{$item} = '/'.$res;
271: }
272: } elsif ($maps{$item}) {
273: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
274: $tocopy{$1} = $name;
275: $display{$item} = $1;
276: $lookup{$1} = $item;
277: }
278: } else {
279: next;
280: }
281: }
1.329 droeschl 282: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
283: $crs=~s/\_/\//g;
1.567 raeburn 284: my $mm = new File::MMagic;
285: my $prefix = "/uploaded/$cdom/$cnum/";
286: %replacehash = %tocopy;
287: foreach my $item (sort(keys(%simpleproblems))) {
288: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
289: $newcontent{$display{$item}} = $content;
290: }
291: my $gateway = Apache::lonhtmlgateway->new('web');
292: foreach my $item (sort(keys(%simplepages))) {
293: if (ref($simplepages{$item}) eq 'HASH') {
294: my $pagetitle = $simplepages{$item}{'title'};
295: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
296: my %contents;
297: foreach my $field (keys(%fields)) {
298: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
299: my $name = $1;
300: my $msg = $fields{$field};
301: if ($name eq 'webreferences') {
302: if ($msg =~ m{^https?://}) {
303: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
304: }
305: } else {
306: $msg = &Encode::decode('utf8',$msg);
307: $msg = $gateway->process_outgoing_html($msg,1);
308: $contents{$name} = $msg;
309: }
310: } elsif ($field eq 'uploaded.photourl') {
311: my $marker = $simplepages{$item}{marker};
312: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
313: my $filepath = $1;
314: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
315: if ($fname ne '') {
316: $fname=~s/\.(\w+)$//;
317: my $ext=$1;
318: $fname = &clean($fname);
319: $fname.='.'.$ext;
320: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
321: $replacehash{$filepath} = $relpath.$fname;
322: $deps{$item}{$filepath} = 1;
323: }
324: }
325: }
326: }
327: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
328: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
329: my $content = '
330: <html>
331: <head>
332: <title>'.$pagetitle.'</title>
333: </head>
334: <body bgcolor="#ffffff">';
335: if ($contents{title}) {
336: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
337: }
338: if ($contents{image}) {
339: $content .= "\n".$contents{image};
340: }
341: if ($contents{content}) {
342: $content .= '
343: <div class="LC_Box">
1.577 bisitz 344: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 345: $contents{content}.'
346: </div>';
347: }
348: if ($contents{webreferences}) {
349: $content .= '
350: <div class="LC_Box">
1.577 bisitz 351: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 352: $contents{webreferences}.'
353: </div>';
354: }
355: $content .= '
356: </body>
357: </html>
358: ';
359: $newcontent{'/'.$simplepages{$item}{res}} = $content;
360: }
361: }
362: foreach my $item (keys(%tocopy)) {
363: unless ($item=~/\.(sequence|page)$/) {
364: my $currurlpath = $prefix.$item;
365: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
366: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
367: }
368: }
369: foreach my $num (sort {$a <=> $b} (@todump)) {
370: my $src = $display{$num};
371: next if ($src eq '');
372: my @needcopy = ();
373: if ($replacehash{$src}) {
374: push(@needcopy,$src);
375: if (ref($deps{$num}) eq 'HASH') {
376: foreach my $dep (sort(keys(%{$deps{$num}}))) {
377: if ($replacehash{$dep}) {
378: push(@needcopy,$dep);
379: }
380: }
381: }
382: } elsif ($src =~ /^simpleproblem_/) {
383: push(@needcopy,$src);
384: }
385: next if (@needcopy == 0);
386: my ($result,$depresult);
387: for (my $i=0; $i<@needcopy; $i++) {
388: my $item = $needcopy[$i];
389: my $newfilename;
390: if ($simpleproblems{$num}) {
391: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
392: } else {
393: $newfilename=$title.'/'.$replacehash{$item};
394: }
395: $newfilename=~s/\.(\w+)$//;
396: my $ext=$1;
397: $newfilename=&clean($newfilename);
398: $newfilename.='.'.$ext;
399: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
400: if ($newrelpath ne $replacehash{$item}) {
401: $replacehash{$item} = $newrelpath;
402: }
403: my @dirs=split(/\//,$newfilename);
404: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
405: my $makepath=$path;
406: my $fail;
407: my $origin;
408: for (my $i=0;$i<$#dirs;$i++) {
409: $makepath.='/'.$dirs[$i];
410: unless (-e $makepath) {
411: unless(mkdir($makepath,0755)) {
412: $fail = &mt('Directory creation failed.');
413: }
414: }
415: }
416: if ($i == 0) {
417: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
418: } else {
419: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
420: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
421: &mt('(dependency)').'</span>: ';
422: }
423: if (-e $path.'/'.$newfilename) {
424: $fail = &mt('Destination already exists -- not overwriting.');
425: } else {
426: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
427: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
428: ($item =~ /^simpleproblem_/)) {
429: print $fh $newcontent{$item};
430: } else {
431: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
432: if (-e $fileloc) {
433: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
434: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
435: (ref($has_simpleprobs{$item}) eq 'HASH')) {
436: my %changes = %{$has_simpleprobs{$item}};
437: my $content = &Apache::lonclonecourse::rewritefile(
438: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
439: (%replacehash,$crs => '')
440: );
441: my $updatedcontent = '';
442: my $parser = HTML::TokeParser->new(\$content);
443: $parser->attr_encoded(1);
444: while (my $token = $parser->get_token) {
445: if ($token->[0] eq 'S') {
446: if (($token->[1] eq 'resource') &&
447: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
448: ($changes{$token->[2]->{'id'}})) {
449: my $id = $token->[2]->{'id'};
450: $updatedcontent .= '<'.$token->[1];
451: foreach my $attrib (@{$token->[3]}) {
452: next unless ($attrib =~ /^(src|type|title|id)$/);
453: if ($attrib eq 'src') {
454: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
455: if ($file) {
456: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: } else {
461: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
462: }
463: }
464: $updatedcontent .= ' />'."\n";
465: } else {
466: $updatedcontent .= $token->[4]."\n";
467: }
468: } else {
469: $updatedcontent .= $token->[2];
470: }
471: }
472: print $fh $updatedcontent;
473: } else {
474: print $fh &Apache::lonclonecourse::rewritefile(
475: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
476: (%replacehash,$crs => '')
477: );
478: }
479: } else {
480: print $fh
481: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
482: }
483: } else {
484: $fail = &mt('Source does not exist.');
485: }
486: }
487: $fh->close();
488: } else {
489: $fail = &mt('Could not write to destination.');
490: }
491: }
492: my $text;
493: if ($fail) {
494: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
495: } else {
496: $text = '<span class="LC_success">'.&mt('ok').'</span>';
497: }
498: if ($i == 0) {
499: $result .= $text;
500: } else {
501: $depresult .= $text.'</li>';
502: }
503: }
504: $r->print($result);
505: if ($depresult) {
506: $r->print('<ul>'.$depresult.'</ul>');
507: }
508: }
509: } else {
510: my ($navmap,$errormsg) =
511: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
512: if (!ref($navmap)) {
513: $r->print($errormsg);
514: } else {
515: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
516: $r->rflush();
517: my ($preamble,$formname);
518: $formname = 'dumpdoc';
519: unless ($home==1) {
520: $preamble = '<div class="LC_left_float">'.
521: '<fieldset><legend>'.
522: &mt('Select the Authoring Space').
523: '</legend><select name="authorspace">';
1.329 droeschl 524: }
1.567 raeburn 525: my @orderspaces = ();
526: foreach my $key (sort(keys(%outhash))) {
527: if ($key=~/^home_(.+)$/) {
528: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
529: unshift(@orderspaces,$1);
530: } else {
531: push(@orderspaces,$1);
532: }
533: }
534: }
1.569 raeburn 535: if ($home>1) {
536: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
537: }
1.567 raeburn 538: foreach my $user (@orderspaces) {
1.329 droeschl 539: if ($home==1) {
1.567 raeburn 540: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 541: } else {
1.567 raeburn 542: $preamble .= '<option value="'.$user.'">'.$user.' - '.
543: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
544: }
1.329 droeschl 545: }
1.567 raeburn 546: unless ($home==1) {
547: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 548: }
1.567 raeburn 549: my $title=$origcrsdata{'description'};
550: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 551: $title=&clean($title);
1.567 raeburn 552: $preamble .= '<div class="LC_left_float">'.
553: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
554: '<input type="text" size="50" name="authorfolder" value="'.
555: $title.'" />'.
556: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
557: my %uploadedfiles;
558: &tiehash();
559: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
560: my ($ext)=($file=~/\.(\w+)$/);
561: # FIXME Check supplemental here
562: my $title=$hash{'title_'.$hash{
563: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
564: if (!$title) {
565: $title=$file;
566: } else {
567: $title=~s|/|_|g;
568: }
569: $title=~s/\.(\w+)$//;
570: $title=&clean($title);
571: $title.='.'.$ext;
572: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
573: $uploadedfiles{$file} = $title;
574: }
575: &untiehash();
576: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
577: undef,undef,$preamble,$home,\%uploadedfiles));
578: }
1.329 droeschl 579: }
1.484 raeburn 580: $r->print(&endContentScreen());
1.329 droeschl 581: }
582:
1.567 raeburn 583: sub recurse_html {
584: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
585: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
586: my (%allfiles,%codebase);
587: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
588: if (keys(%allfiles)) {
589: foreach my $dependency (keys(%allfiles)) {
590: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
591: my ($depurl,$relfile,$newcontainer);
592: if ($dependency =~ m{^/}) {
593: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
594: $relfile = $1;
595: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
596: $newcontainer = $1;
597: next if ($replacehash->{$newcontainer});
598: }
599: $depurl = $dependency;
600: } else {
601: next;
602: }
603: } else {
604: $relfile = $dependency;
605: $depurl = $currurlpath;
606: $depurl =~ s{[^/]+$}{};
607: $depurl .= $dependency;
608: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
609: }
610: next if ($relfile eq '');
611: my $newname = $replacehash->{$container};
612: $newname =~ s{[^/]+$}{};
613: $replacehash->{$newcontainer} = $newname.$relfile;
614: $deps->{$item}{$newcontainer} = 1;
615: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
616: my $depfile = &Apache::lonnet::filelocation('',$depurl);
617: my $type = $mm->checktype_filename($depfile);
618: if ($type eq 'text/html') {
619: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
620: }
621: }
622: }
623: }
624: return;
625: }
626:
1.329 droeschl 627: sub group_import {
1.598 raeburn 628: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 629: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
630: %removeparam,$importuploaded,$fixuperrors);
631: $allmaps = {};
1.329 droeschl 632: while (@files) {
633: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 634: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 635: && ($caller eq 'londocs')
636: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 637:
1.329 droeschl 638: my $errtext = '';
639: my $fatal = 0;
640: my $newmapstr = '<map>'."\n".
641: '<resource id="1" src="" type="start"></resource>'."\n".
642: '<link from="1" to="2" index="1"></link>'."\n".
643: '<resource id="2" src="" type="finish"></resource>'."\n".
644: '</map>';
645: $env{'form.output'}=$newmapstr;
646: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
647: 'output',$1.$2);
1.534 raeburn 648: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 649: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
650: $fatal = 2;
651: }
652: if ($fatal) {
653: return ($errtext,$fatal);
654: }
655: }
656: if ($url) {
1.626 ! raeburn 657: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 658: $url = $1;
659: my $marker = $2;
660: my $info = $3;
1.604 raeburn 661: my ($toolid,%toolhash,%toolsettings);
1.624 raeburn 662: my @extras = ('linktext','explanation','crslabel','crstitle');
1.598 raeburn 663: my @toolinfo = split(/:/,$info);
664: if ($residx) {
1.604 raeburn 665: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 666: $toolid = $toolsettings{'id'};
667: } else {
1.604 raeburn 668: $toolid = shift(@toolinfo);
1.598 raeburn 669: }
670: $toolid =~ s/\D//g;
1.604 raeburn 671: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.624 raeburn 672: $toolhash{'linktext'},$toolhash{'explanation'},
1.604 raeburn 673: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
1.624 raeburn 674: foreach my $item (@extras) {
675: $toolhash{$item} = &unescape($toolhash{$item});
676: }
1.598 raeburn 677: if (ref($ltitoolsref) eq 'HASH') {
1.604 raeburn 678: my @deleted;
1.598 raeburn 679: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
680: $toolhash{'id'} = $toolid;
1.604 raeburn 681: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
682: if ($toolhash{'target'} eq 'window') {
683: foreach my $item ('width','height') {
684: $toolhash{$item} =~ s/^\s+//;
685: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 686: if ($toolhash{$item} =~ /\D/) {
687: delete($toolhash{$item});
688: if ($residx) {
689: if ($toolsettings{$item}) {
690: push(@deleted,$item);
691: }
692: }
693: }
1.604 raeburn 694: }
695: }
696: } elsif ($residx) {
697: $toolhash{'target'} = $toolsettings{'target'};
698: if ($toolhash{'target'} eq 'window') {
1.624 raeburn 699: foreach my $item ('width','height') {
700: $toolhash{$item} = $toolsettings{$item};
701: }
1.604 raeburn 702: }
703: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
704: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
705: if ($toolhash{'target'} eq 'window') {
706: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
707: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
708: }
709: }
1.598 raeburn 710: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 711: foreach my $item ('width','height','linktext','explanation') {
712: delete($toolhash{$item});
713: if ($residx) {
714: if ($toolsettings{$item}) {
715: push(@deleted,$item);
716: }
1.604 raeburn 717: }
718: }
719: }
720: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 721: foreach my $item ('label','title','linktext','explanation') {
722: my $crsitem;
723: if (($item eq 'label') || ($item eq 'title')) {
724: $crsitem = 'crs'.$item;
725: } else {
726: $crsitem = $item;
727: }
1.604 raeburn 728: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 729: $toolhash{$crsitem} =~ s/^\s+//;
730: $toolhash{$crsitem} =~ s/\s+$//;
731: if ($toolhash{$crsitem} eq '') {
732: delete($toolhash{$crsitem});
1.604 raeburn 733: }
734: } else {
1.624 raeburn 735: delete($toolhash{$crsitem});
1.604 raeburn 736: }
1.624 raeburn 737: if (($residx) && (exists($toolsettings{$crsitem}))) {
738: unless (exists($toolhash{$crsitem})) {
739: push(@deleted,$crsitem);
1.604 raeburn 740: }
741: }
1.598 raeburn 742: }
743: }
744: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 745: if ($putres eq 'ok') {
746: if (@deleted) {
747: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
748: }
749: }
1.598 raeburn 750: }
751: }
752: }
1.529 raeburn 753: if (($caller eq 'londocs') &&
754: ($folder =~ /^default/)) {
1.534 raeburn 755: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 756: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
757: my $cid = $coursedom.'_'.$coursenum;
758: $allmaps =
759: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
760: $chome,$cid);
761: $donechk = 1;
762: }
763: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
764: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
765: \%addedmaps,\%hierarchy,\%titles,$allmaps);
766: $importuploaded = 1;
767: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
768: next if ($allmaps->{$url});
769: }
770: }
1.344 bisitz 771: if (!$residx
1.329 droeschl 772: || defined($LONCAPA::map::zombies[$residx])) {
773: $residx = &LONCAPA::map::getresidx($url,$residx);
774: push(@LONCAPA::map::order, $residx);
775: }
776: my $ext = 'false';
777: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
778: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 779: if ($name eq '') {
1.538 raeburn 780: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 781: }
782: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
783: my $filepath = $1;
784: my $fname = $name;
785: if ($fname =~ /^\W+$/) {
786: $fname = 'web';
787: } else {
788: $fname =~ s/\W/_/g;
789: }
1.599 damieng 790: if (length($fname) > 15) {
1.534 raeburn 791: $fname = substr($fname,0,14);
792: }
793: my $initialtext = &mt('Replace with your own content.');
794: my $newhtml = <<END;
1.545 raeburn 795: <html>
1.534 raeburn 796: <head>
797: <title>$name</title>
798: </head>
799: <body bgcolor="#ffffff">
800: $initialtext
801: </body>
802: </html>
803: END
804: $env{'form.output'}=$newhtml;
805: my $result =
806: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
807: 'output',
808: "$filepath/$residx/$fname.html");
809: if ($result =~ m{^/uploaded/}) {
810: $url = $result;
811: if ($filepath =~ /^supplemental/) {
812: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
813: $env{'user.domain'}.'___&&&___'.$name;
814: }
815: } else {
816: return (&mt('Failed to save new web page.'),1);
817: }
818: }
1.538 raeburn 819: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 820: $LONCAPA::map::resources[$residx] =
1.329 droeschl 821: join(':', ($name, $url, $ext, 'normal', 'res'));
822: }
823: }
1.529 raeburn 824: if ($importuploaded) {
825: my %import_errors;
826: my %updated = (
827: removefrommap => \%removefrommap,
828: removeparam => \%removeparam,
829: );
1.533 raeburn 830: my ($result,$msgsarray,$lockerror) =
831: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 832: if (keys(%import_errors) > 0) {
1.530 raeburn 833: $fixuperrors =
1.529 raeburn 834: '<p span class="LC_warning">'."\n".
835: &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".
836: '<ul>'."\n";
837: foreach my $key (sort(keys(%import_errors))) {
838: $fixuperrors .= '<li>'.$key.'</li>'."\n";
839: }
840: $fixuperrors .= '</ul></p>'."\n";
841: }
1.533 raeburn 842: if (ref($msgsarray) eq 'ARRAY') {
843: if (@{$msgsarray} > 0) {
844: $fixuperrors .= '<p class="LC_info">'.
845: join('<br />',@{$msgsarray}).
846: '</p>';
847: }
848: }
849: if ($lockerror) {
850: $fixuperrors .= '<p class="LC_error">'.
851: $lockerror.
852: '</p>';
853: }
1.529 raeburn 854: }
855: my ($errtext,$fatal) =
856: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 857: unless ($fatal) {
858: if ($folder =~ /^supplemental/) {
859: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 860: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
861: $folder.'.'.$container);
1.557 raeburn 862: }
863: }
1.529 raeburn 864: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 865: }
866:
867: sub log_docs {
1.494 raeburn 868: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 869: }
870:
871: {
872: my @oldresources=();
873: my @oldorder=();
874: my $parmidx;
875: my %parmaction=();
876: my %parmvalue=();
877: my $changedflag;
878:
879: sub snapshotbefore {
880: @oldresources=@LONCAPA::map::resources;
881: @oldorder=@LONCAPA::map::order;
882: $parmidx=undef;
883: %parmaction=();
884: %parmvalue=();
885: $changedflag=0;
886: }
887:
888: sub remember_parms {
889: my ($idx,$parameter,$action,$value)=@_;
890: $parmidx=$idx;
891: $parmaction{$parameter}=$action;
892: $parmvalue{$parameter}=$value;
893: $changedflag=1;
894: }
895:
896: sub log_differences {
897: my ($plain)=@_;
898: my %storehash=('folder' => $plain,
899: 'currentfolder' => $env{'form.folder'});
900: if ($parmidx) {
901: $storehash{'parameter_res'}=$oldresources[$parmidx];
902: foreach my $parm (keys(%parmaction)) {
903: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
904: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
905: }
906: }
907: my $maxidx=$#oldresources;
908: if ($#LONCAPA::map::resources>$#oldresources) {
909: $maxidx=$#LONCAPA::map::resources;
910: }
911: for (my $idx=0; $idx<=$maxidx; $idx++) {
912: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
913: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
914: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
915: $changedflag=1;
916: }
917: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
918: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
919: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
920: $changedflag=1;
921: }
922: }
923: $storehash{'maxidx'}=$maxidx;
924: if ($changedflag) { &log_docs(\%storehash); }
925: }
926: }
927:
928: sub docs_change_log {
1.611 raeburn 929: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 930: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 931: my $navmap;
1.483 raeburn 932: my $js = '<script type="text/javascript">'."\n".
933: '// <![CDATA['."\n".
934: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 935: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 936: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 937: &history_tab_js()."\n".
1.484 raeburn 938: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 939: '// ]]>'."\n".
940: '</script>'."\n";
1.484 raeburn 941: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
942: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 943: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 944: my %orderhash;
945: my $container='sequence';
946: my $pathitem;
1.519 raeburn 947: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 948: $container='page';
949: }
1.519 raeburn 950: my $folderpath=$env{'form.folderpath'};
951: if ($folderpath eq '') {
1.617 raeburn 952: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 953: }
1.617 raeburn 954: undef($navmap);
1.519 raeburn 955: $pathitem = '<input type="hidden" name="folderpath" value="'.
956: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 957: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
958: my $jumpto = $readfile;
959: $jumpto =~ s{^/}{};
960: my $tid = 1;
1.489 raeburn 961: if ($supplementalflag) {
962: $tid = 2;
963: }
1.509 raeburn 964: my ($breadcrumbtrail) =
965: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 966: $r->print($breadcrumbtrail.
967: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
968: $readfile));
1.329 droeschl 969: my %docslog=&Apache::lonnet::dump('nohist_docslog',
970: $env{'course.'.$env{'request.course.id'}.'.domain'},
971: $env{'course.'.$env{'request.course.id'}.'.num'});
972:
973: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
974:
975: my %saveable_parameters = ('show' => 'scalar',);
976: &Apache::loncommon::store_course_settings('docs_log',
977: \%saveable_parameters);
978: &Apache::loncommon::restore_course_settings('docs_log',
979: \%saveable_parameters);
980: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 981: # FIXME: internationalization seems wrong here
1.329 droeschl 982: my %lt=('hiddenresource' => 'Resources hidden',
983: 'encrypturl' => 'URL hidden',
984: 'randompick' => 'Randomly pick',
985: 'randomorder' => 'Randomly ordered',
986: 'set' => 'set to',
987: 'del' => 'deleted');
1.484 raeburn 988: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
989: $pathitem."\n".
990: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
991: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
992: $r->print('<div class="LC_left_float">'.
993: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
994: &makedocslogform($filter,1).
995: '</fieldset></div><br clear="all" />');
1.329 droeschl 996: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
997: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
998: &mt('After').'</th>'.
999: &Apache::loncommon::end_data_table_header_row());
1000: my $shown=0;
1001: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1002: if ($env{'form.displayfilter'} eq 'currentfolder') {
1003: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1004: }
1005: my @changes=keys(%{$docslog{$id}{'logentry'}});
1006: if ($env{'form.displayfilter'} eq 'containing') {
1007: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1008: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1009: foreach my $key (@changes) {
1010: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1011: }
1.344 bisitz 1012: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1013: }
1014: my $count = 0;
1015: my $time =
1016: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1017: my $plainname =
1018: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1019: $docslog{$id}{'exe_udom'});
1020: my $about_me_link =
1021: &Apache::loncommon::aboutmewrapper($plainname,
1022: $docslog{$id}{'exe_uname'},
1023: $docslog{$id}{'exe_udom'});
1024: my $send_msg_link='';
1025: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1026: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1027: $send_msg_link ='<br />'.
1028: &Apache::loncommon::messagewrapper(&mt('Send message'),
1029: $docslog{$id}{'exe_uname'},
1030: $docslog{$id}{'exe_udom'});
1031: }
1032: $r->print(&Apache::loncommon::start_data_table_row());
1033: $r->print('<td>'.$time.'</td>
1034: <td>'.$about_me_link.
1035: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1036: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1037: $send_msg_link.'</td><td>'.
1038: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1039: my $is_supp = 0;
1040: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1041: $is_supp = 1;
1042: }
1.329 droeschl 1043: # Before
1044: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1045: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1046: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1047: if ($oldname ne $newname) {
1.488 raeburn 1048: my $shown = &LONCAPA::map::qtescape($oldname);
1049: if ($is_supp) {
1050: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1051: }
1052: $r->print($shown);
1.329 droeschl 1053: }
1054: }
1055: $r->print('<ul>');
1056: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1057: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1058: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1059: if ($is_supp) {
1060: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1061: }
1062: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1063: }
1064: }
1065: $r->print('</ul>');
1066: # After
1067: $r->print('</td><td>');
1068:
1069: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1070: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1071: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1072: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1073: my $shown = &LONCAPA::map::qtescape($newname);
1074: if ($is_supp) {
1075: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1076: }
1077: $r->print($shown);
1.329 droeschl 1078: }
1.364 bisitz 1079: }
1.329 droeschl 1080: $r->print('<ul>');
1081: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1082: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1083: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1084: if ($is_supp) {
1085: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1086: }
1087: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1088: }
1089: }
1090: $r->print('</ul>');
1091: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1092: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1093: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1094: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1095: # FIXME: internationalization seems wrong here
1.329 droeschl 1096: $r->print('<li>'.
1097: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1098: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1099: .'</li>');
1100: }
1101: }
1102: $r->print('</ul>');
1103: }
1104: # End
1105: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1106: $shown++;
1107: if (!($env{'form.show'} eq &mt('all')
1108: || $shown<=$env{'form.show'})) { last; }
1109: }
1.484 raeburn 1110: $r->print(&Apache::loncommon::end_data_table()."\n".
1111: &makesimpleeditform($pathitem)."\n".
1112: '</div></div>');
1113: $r->print(&endContentScreen());
1.329 droeschl 1114: }
1115:
1116: sub update_paste_buffer {
1.492 raeburn 1117: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1118: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1119: if ($env{'form.multiremove'}) {
1120: $env{'form.multiremove'} =~ s/,$//;
1121: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1122: }
1123: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1124: if ($env{'form.multicut'}) {
1125: $env{'form.multicut'} =~ s/,$//;
1126: foreach my $item (split(/,/,$env{'form.multicut'})) {
1127: unless ($removals{$item}) {
1128: $cuts{$item} = 1;
1129: push(@possibles,$item.':cut');
1130: }
1131: }
1132: }
1133: if ($env{'form.multicopy'}) {
1134: $env{'form.multicopy'} =~ s/,$//;
1135: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1136: unless ($removals{$item} || $cuts{$item}) {
1137: push(@possibles,$item.':copy');
1138: }
1139: }
1140: }
1141: } elsif ($env{'form.markcopy'}) {
1142: @possibles = split(/,/,$env{'form.markcopy'});
1143: }
1.329 droeschl 1144:
1.538 raeburn 1145: return if (@possibles == 0);
1.329 droeschl 1146: return if (!defined($env{'form.copyfolder'}));
1147:
1148: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1149: $env{'form.copyfolder'});
1.538 raeburn 1150: return if ($fatal);
1151:
1152: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1153:
1.538 raeburn 1154: # Retrieve current paste buffer suffixes.
1155: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1156: my (%pasteurls,@newpaste);
1157:
1158: # Construct identifiers for current contents of user's paste buffer
1159: if (@currpaste) {
1160: foreach my $suffix (@currpaste) {
1161: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1162: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1163: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1164: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1165: ($url ne '')) {
1.597 raeburn 1166: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1167: }
1168: }
1169: }
1170:
1171: # Mark items for copying (skip any items already in user's paste buffer)
1172: my %addtoenv;
1.597 raeburn 1173:
1174: my @pathitems = split(/\&/,$env{'form.folderpath'});
1175: my @folderconf = split(/\:/,$pathitems[-1]);
1176: my $ispage = $folderconf[4];
1177:
1.538 raeburn 1178: foreach my $item (@possibles) {
1179: my ($orderidx,$cmd) = split(/:/,$item);
1180: next if ($orderidx =~ /\D/);
1181: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1182: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1183: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1184: my %denied = &action_restrictions($coursenum,$coursedom,
1185: &LONCAPA::map::qtescape($url),
1186: $env{'form.folderpath'},\%curr_groups);
1187: next if ($denied{'copy'});
1188: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1189: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1190: my ($suffix,$errortxt,$locknotfreed) =
1191: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1192: if ($suffix ne '') {
1193: push(@newpaste,$suffix);
1194: } else {
1195: if ($locknotfreed) {
1196: return $locknotfreed;
1197: }
1.538 raeburn 1198: }
1199: if (&is_supplemental_title($title)) {
1200: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1201: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1202: }
1.329 droeschl 1203:
1.538 raeburn 1204: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1205: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1206: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1207: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1208: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1209: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1210: my $prefix = $1;
1211: my $subdir =$2;
1212: if ($subdir eq '') {
1213: $subdir = $prefix;
1.492 raeburn 1214: }
1.538 raeburn 1215: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1216: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1217: \%hierarchy,\%titles,\%allmaps);
1218: if (ref($hierarchy{$url}) eq 'HASH') {
1219: my ($nested,$nestednames);
1220: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1221: $nested =~ s/\&$//;
1222: $nestednames =~ s/\Q___&&&___\E$//;
1223: if ($nested ne '') {
1224: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1225: }
1226: if ($nestednames ne '') {
1227: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1228: }
1.492 raeburn 1229: }
1230: }
1.591 raeburn 1231: if ($locknotfreed) {
1232: $output = $locknotfreed;
1233: last;
1234: }
1.492 raeburn 1235: }
1.538 raeburn 1236: if (@newpaste) {
1237: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1238: }
1.492 raeburn 1239: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1240: delete($env{'form.markcopy'});
1.591 raeburn 1241: return $output;
1.329 droeschl 1242: }
1243:
1.492 raeburn 1244: sub recurse_uploaded_maps {
1245: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1246: if (ref($hierarchy->{$url}) eq 'HASH') {
1247: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1248: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1249: my (@uploaded,@names,%shorter);
1250: for (my $i=0; $i<@maps; $i++) {
1251: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1252: if ($inner ne '') {
1253: push(@uploaded,$inner);
1254: push(@names,&escape($titles[$i]));
1255: $shorter{$maps[$i]} = $inner;
1256: }
1257: }
1258: $$nestref .= "$dir:".join(',',@uploaded).'&';
1259: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1260: foreach my $map (@maps) {
1261: if ($shorter{$map} ne '') {
1262: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1263: }
1264: }
1265: }
1266: return;
1267: }
1268:
1.329 droeschl 1269: sub print_paste_buffer {
1.492 raeburn 1270: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1271: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1272:
1.538 raeburn 1273: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1274: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1275: }
1276:
1.538 raeburn 1277: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1278: my ($pasteitems,@pasteable);
1.575 raeburn 1279: my $clipboardcount = 0;
1.488 raeburn 1280:
1.538 raeburn 1281: # Construct identifiers for current contents of user's paste buffer
1282: foreach my $suffix (@currpaste) {
1283: next if ($suffix =~ /\D/);
1284: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1285: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1286: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1287: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1288: ($url ne '')) {
1.575 raeburn 1289: $clipboardcount ++;
1.538 raeburn 1290: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1291: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1292: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1293: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1294: $is_external = 1;
1.626 ! raeburn 1295: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1296: $is_exttool = 1;
1.538 raeburn 1297: }
1298: if ($folder =~ /^supplemental/) {
1299: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1300: unless ($canpaste) {
1301: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1302: }
1303: } else {
1304: $canpaste = 1;
1305: }
1306: if ($canpaste) {
1307: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1308: my $srcdom = $1;
1309: my $srcnum = $2;
1310: my $rem = $3;
1311: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1312: $othercourse = 1;
1313: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1314: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1315: } else {
1316: $canpaste = 0;
1317: $nopaste = &mt('Paste from another course unavailable.');
1318: }
1319: }
1320: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1321: my $prefix = $1;
1322: $parent = $2;
1323: if ($folder !~ /^\Q$prefix\E/) {
1324: $areachange = 1;
1325: }
1326: $is_uploaded_map = 1;
1.492 raeburn 1327: }
1.597 raeburn 1328: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1329: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1330: if ($cid ne $env{'request.course.id'}) {
1331: my ($srcdom,$srcnum) = split(/_/,$cid);
1332: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1333: $othercrs = '<br />'.&mt('(from another course)');
1334: } else {
1335: $canpaste = 0;
1336: $nopaste = &mt('Paste from another course unavailable.');
1337: }
1338: }
1.492 raeburn 1339: }
1.596 raeburn 1340: if ($canpaste) {
1341: push(@pasteable,$suffix);
1342: }
1.538 raeburn 1343: }
1344: my $buffer;
1.598 raeburn 1345: if (($is_external) || ($is_exttool)) {
1.538 raeburn 1346: $buffer = &mt('External Resource').': '.
1347: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1348: &LONCAPA::map::qtescape($url).')';
1349: } else {
1350: my $icon = &Apache::loncommon::icon($extension);
1351: if ($extension eq 'sequence' &&
1352: $url =~ m{/default_\d+\.sequence$}x) {
1353: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1354: $icon .= '/navmap.folder.closed.gif';
1355: }
1.589 raeburn 1356: my $title = $env{'docs.markedcopy_title_'.$suffix};
1357: if ($title eq '') {
1358: ($title) = ($url =~ m{/([^/]+)$});
1359: }
1.538 raeburn 1360: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1361: ': '.
1362: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1363: &LONCAPA::map::qtescape($title));
1.538 raeburn 1364: }
1365: $pasteitems .= '<div class="LC_left_float">';
1366: my ($options,$onclick);
1367: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1368: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1369: if (($is_uploaded_map) ||
1370: ($url =~ /(bulletinboard|smppg)$/) ||
1371: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1372: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1373: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1374: }
1375: }
1376: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1377: if ($nopaste) {
1378: $pasteitems .= $nopaste;
1379: } else {
1380: if ($othercrs) {
1381: $pasteitems .= $othercrs;
1382: }
1383: if ($options) {
1384: $pasteitems .= $options;
1.492 raeburn 1385: }
1386: }
1.538 raeburn 1387: $pasteitems .= '</div>';
1388: }
1389: }
1390: if ($pasteitems eq '') {
1391: &Apache::lonnet::delenv('docs.markedcopies');
1392: }
1393: my ($pasteform,$form_start,$buttons,$form_end);
1394: if ($pasteitems) {
1395: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1396: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1397: if (@pasteable) {
1.575 raeburn 1398: my $value = &mt('Paste to current folder');
1399: if ($container eq 'page') {
1400: $value = &mt('Paste to current page');
1401: }
1402: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1403: }
1404: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1405: if ($clipboardcount > 1) {
1406: $buttons .=
1407: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1408: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1409: (' 'x2).
1410: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1411: (' 'x2);
1.492 raeburn 1412: }
1.575 raeburn 1413: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1414: '</form>';
1.538 raeburn 1415: } else {
1416: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1417: }
1.538 raeburn 1418: $r->print($form_start
1419: .'<fieldset>'
1420: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1421: .$pasteitems
1422: .'</fieldset>'
1423: .$form_end);
1424: }
1425:
1426: sub paste_options {
1427: my ($suffix,$is_uploaded_map,$parent) = @_;
1428: my ($copytext,$movetext);
1429: if ($is_uploaded_map) {
1430: $copytext = &mt('Copy to new folder');
1431: $movetext = &mt('Move old');
1432: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1433: $copytext = &mt('Copy to new board');
1434: $movetext = &mt('Move (not posts)');
1435: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1436: $copytext = &mt('Copy to new page');
1437: $movetext = &mt('Move');
1.533 raeburn 1438: } else {
1.538 raeburn 1439: $copytext = &mt('Copy to new file');
1440: $movetext = &mt('Move');
1441: }
1442: my $output = '<br />'.
1443: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1444: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1445: '<label>'.
1446: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1447: $copytext.'</label></span>'.(' 'x2).' '.
1448: '<span class="LC_nobreak"><label>'.
1449: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1450: $movetext.'</label></span>';
1451: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1452: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1453: '</legend><table border="0">';
1454: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1455: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1456: my $lastdir = $parent;
1457: my %depths = (
1458: $lastdir => 0,
1459: );
1460: my (%display,%deps);
1461: for (my $i=0; $i<@pastemaps; $i++) {
1462: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1463: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1464: my @subfolders = split(/,/,$subfolderstr);
1465: $deps{$lastdir} = \@subfolders;
1466: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1467: my $depth = $depths{$lastdir} + 1;
1468: my $offset = int($depth * 4);
1469: my $indent = (' ' x $offset);
1470: for (my $j=0; $j<@subfolders; $j++) {
1471: $depths{$subfolders[$j]} = $depth;
1472: $display{$subfolders[$j]} =
1473: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1474: '<td><label>'.
1475: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1476: '<label>'.
1477: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1478: &mt('Move old').'</label>'.
1479: '</td></tr>';
1480: }
1.492 raeburn 1481: }
1.538 raeburn 1482: &recurse_print(\$output,$parent,\%deps,\%display);
1483: $output .= '</table></fieldset>';
1.329 droeschl 1484: }
1.538 raeburn 1485: $output .= '</div>';
1486: return $output;
1.488 raeburn 1487: }
1488:
1.492 raeburn 1489: sub recurse_print {
1.538 raeburn 1490: my ($outputref,$dir,$deps,$display) = @_;
1491: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1492: if (ref($deps->{$dir}) eq 'ARRAY') {
1493: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1494: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1495: }
1496: }
1497: }
1498:
1.488 raeburn 1499: sub supp_pasteable {
1500: my ($url) = @_;
1501: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1502: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1503: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1504: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1505: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 ! raeburn 1506: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1507: return 1;
1508: }
1509: return;
1.329 droeschl 1510: }
1511:
1.492 raeburn 1512: sub paste_popup_js {
1.594 damieng 1513: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1514: show => 'Show Options',
1515: hide => 'Hide Options',
1.594 damieng 1516: );
1517: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1518: none => 'No items selected from clipboard.',
1.492 raeburn 1519: );
1.594 damieng 1520: &html_escape(\%html_js_lt);
1521: &js_escape(\%html_js_lt);
1522: &js_escape(\%js_lt);
1.492 raeburn 1523: return <<"END";
1524:
1.538 raeburn 1525: function showPasteOptions(suffix) {
1526: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1527: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1528: return;
1529: }
1530:
1.538 raeburn 1531: function hidePasteOptions(suffix) {
1532: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1533: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1534: return;
1535: }
1536:
1537: function showOptions(caller,suffix) {
1538: if (document.getElementById('pasteoptionstext_'+suffix)) {
1539: if (caller.checked) {
1.594 damieng 1540: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1541: } else {
1542: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1543: }
1544: if (document.getElementById('pasteoptions_'+suffix)) {
1545: document.getElementById('pasteoptions_'+suffix).style.display='none';
1546: }
1547: }
1.492 raeburn 1548: return;
1549: }
1550:
1.541 raeburn 1551: function validateClipboard() {
1552: var numchk = 0;
1553: if (document.pasteform.pasting.length > 1) {
1554: for (var i=0; i<document.pasteform.pasting.length; i++) {
1555: if (document.pasteform.pasting[i].checked) {
1556: numchk ++;
1557: }
1558: }
1559: } else {
1560: if (document.pasteform.pasting.type == 'checkbox') {
1561: if (document.pasteform.pasting.checked) {
1562: numchk ++;
1563: }
1564: }
1565: }
1566: if (numchk > 0) {
1567: return true;
1568: } else {
1.594 damieng 1569: alert("$js_lt{'none'}");
1.541 raeburn 1570: return false;
1571: }
1572: }
1573:
1.575 raeburn 1574: function checkClipboard() {
1575: if (document.pasteform.pasting.length > 1) {
1576: for (var i=0; i<document.pasteform.pasting.length; i++) {
1577: document.pasteform.pasting[i].checked = true;
1578: }
1579: }
1580: return;
1581: }
1582:
1583: function uncheckClipboard() {
1584: if (document.pasteform.pasting.length >1) {
1585: for (var i=0; i<document.pasteform.pasting.length; i++) {
1586: document.pasteform.pasting[i].checked = false;
1587: }
1588: }
1589: return;
1590: }
1591:
1.492 raeburn 1592: END
1593:
1594: }
1595:
1.329 droeschl 1596: sub do_paste_from_buffer {
1.492 raeburn 1597: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1598:
1.538 raeburn 1599: # Array of items in paste buffer
1600: my (@currpaste,%pastebuffer,%allerrors);
1601: @currpaste = split(/,/,$env{'docs.markedcopies'});
1602:
1.492 raeburn 1603: # Early out if paste buffer is empty
1.538 raeburn 1604: if (@currpaste == 0) {
1.492 raeburn 1605: return ();
1.538 raeburn 1606: }
1607: map { $pastebuffer{$_} = 1; } @currpaste;
1608:
1609: # Array of items selected items to paste
1610: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1611:
1612: # Early out if nothing selected to paste
1613: if (@reqpaste == 0) {
1614: return();
1615: }
1616: my @topaste;
1617: foreach my $suffix (@reqpaste) {
1618: next if ($suffix =~ /\D/);
1619: next unless (exists($pastebuffer{$suffix}));
1620: push(@topaste,$suffix);
1621: }
1622:
1623: # Early out if nothing available to paste
1624: if (@topaste == 0) {
1625: return();
1.329 droeschl 1626: }
1627:
1.538 raeburn 1628: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.597 raeburn 1629: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1630:
1631: foreach my $suffix (@topaste) {
1632: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1633: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1634: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1635: # Supplemental content may only include certain types of content
1636: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1637: if ($folder =~ /^supplemental/) {
1638: unless (&supp_pasteable($url)) {
1639: $notinsupp{$suffix} = 1;
1640: next;
1641: }
1.492 raeburn 1642: }
1.538 raeburn 1643: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1644: my $srcd = $1;
1645: my $srcn = $2;
1.492 raeburn 1646: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1647: # check for mdc privilege in the course from which the resource was pasted
1648: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1649: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1650: $notincrs{$suffix} = 1;
1651: next;
1652: }
1.491 raeburn 1653: }
1.538 raeburn 1654: $srcdom{$suffix} = $srcd;
1655: $srcnum{$suffix} = $srcn;
1.597 raeburn 1656: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1657: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1658: my ($srcd,$srcn) = split(/_/,$cid);
1659: # When paste buffer was populated using an active role in a different course
1660: # check for mdc privilege in the course from which the resource was pasted
1661: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1662: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1663: $notincrs{$suffix} = 1;
1664: next;
1665: }
1666: }
1667: $srcdom{$suffix} = $srcd;
1668: $srcnum{$suffix} = $srcn;
1.491 raeburn 1669: }
1.597 raeburn 1670: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1671: push(@dopaste,$suffix);
1672: if ($url=~/\.(page|sequence)$/) {
1673: $is_map{$suffix} = 1;
1674: }
1675:
1676: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1677: my $oldprefix = $1;
1.492 raeburn 1678: # When pasting content from Main Content to Supplemental Content and vice versa
1679: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1680: # a folder/page or a document).
1.538 raeburn 1681: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1682: $prefixchg{$suffix} = 'docstosupp';
1683: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1684: $prefixchg{$suffix} = 'supptodocs';
1685: }
1.491 raeburn 1686:
1.492 raeburn 1687: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1688: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1689: my @nested;
1690: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1691: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1692: my @deps = map { /\d+:([\d,]+$)/ } @items;
1693: foreach my $dep (@deps) {
1694: if ($dep =~ /,/) {
1695: push(@nested,split(/,/,$dep));
1696: } else {
1697: push(@nested,$dep);
1698: }
1.492 raeburn 1699: }
1.538 raeburn 1700: foreach my $item (@nested) {
1701: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1702: push(@{$marktomove{$suffix}},$type.'_'.$item);
1703: }
1.492 raeburn 1704: }
1705: }
1.488 raeburn 1706: }
1707: }
1708:
1.538 raeburn 1709: # Early out if nothing available to paste
1710: if (@dopaste == 0) {
1711: return ();
1712: }
1713:
1714: # Populate message hash and hashes used for main content <=> supplemental content
1715: # changes
1716:
1717: %msgs = &Apache::lonlocal::texthash (
1718: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1719: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1720: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1721: );
1722:
1723: %before = (
1724: docstosupp => {
1725: map => 'default',
1726: doc => 'docs',
1727: },
1728: supptodocs => {
1729: map => 'supplemental',
1730: doc => 'supplemental',
1731: },
1732: );
1733:
1734: %after = (
1735: docstosupp => {
1736: map => 'supplemental',
1737: doc => 'supplemental'
1738: },
1739: supptodocs => {
1740: map => 'default',
1741: doc => 'docs',
1742: },
1743: );
1744:
1745: # Retrieve information about all course maps in main content area
1746:
1747: my $allmaps = {};
1748: if ($folder =~ /^default/) {
1749: $allmaps =
1750: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1751: $env{"course.$env{'request.course.id'}.home"},
1752: $env{'request.course.id'});
1753: }
1754:
1755: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1756:
1757: # Loop over the items to paste
1758: foreach my $suffix (@dopaste) {
1.329 droeschl 1759: # Maps need to be copied first
1.538 raeburn 1760: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1761: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1762: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1763: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1764: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1765: }
1766: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1767: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1768: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1769: my $oldurl = $url;
1770: if ($is_map{$suffix}) {
1.491 raeburn 1771: # If pasting a map, check if map contains other maps
1.538 raeburn 1772: my (%hierarchy,%titles);
1773: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1774: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1775: if ($url=~ m{^/uploaded/}) {
1776: my $newurl;
1777: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1778: ($newurl,my $error) =
1779: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1780: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1781: \$title,$allmaps,\%newurls);
1782: if ($error) {
1783: $allerrors{$suffix} = $error;
1784: next;
1785: }
1786: if ($newurl ne '') {
1787: if ($newurl ne $url) {
1788: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1789: $newsubdir{$url} = $1;
1790: }
1791: $mapchanges{$url} = 1;
1.492 raeburn 1792: }
1.538 raeburn 1793: }
1794: }
1795: if (($srcdom{$suffix} ne $coursedom) ||
1796: ($srcnum{$suffix} ne $coursenum) ||
1797: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1798: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1799: $coursedom,$coursenum,$srcdom{$suffix},
1800: $srcnum{$suffix},$allmaps,\%rewrites,
1801: \%retitles,\%copies,\%dbcopies,
1802: \%zombies,\%params,\%mapmoves,
1803: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1804: \%newurls,\%resdatacopy)) {
1.538 raeburn 1805: $mapmoves{$url} = 1;
1806: }
1807: $url = $newurl;
1808: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1809: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1810: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1811: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1812: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1813: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1814: }
1815: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1816: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1817: push(@toclear,$suffix);
1818: # if pasting published map (main content area only) check map not already in course
1819: if ($folder =~ /^default/) {
1820: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1821: $duplicate{$suffix} = 1;
1822: next;
1.492 raeburn 1823: }
1.491 raeburn 1824: }
1825: }
1.538 raeburn 1826: }
1827: if ($url=~ m{/(bulletinboard|smppg)$}) {
1828: my $prefix = $1;
1.596 raeburn 1829: my $fromothercrs;
1.538 raeburn 1830: #need to copy the db contents to a new one, unless this is a move.
1831: my %info = (
1832: src => $url,
1833: cdom => $coursedom,
1834: cnum => $coursenum,
1.596 raeburn 1835: );
1836: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1837: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1838: $fromothercrs = 1;
1839: $info{'cdom'} = $srcdom{$suffix};
1840: $info{'cnum'} = $srcnum{$suffix};
1841: }
1842: }
1843: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.538 raeburn 1844: my (%lockerr,$msg);
1845: my ($newurl,$result,$errtext) =
1846: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1847: if ($result eq 'ok') {
1848: $url = $newurl;
1849: $title=&mt('Copy of').' '.$title;
1850: } else {
1851: if ($prefix eq 'smppg') {
1852: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1853: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1854: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.538 raeburn 1855: }
1856: $results{$suffix} = $result;
1857: $msgerrs{$suffix} = $msg;
1858: $lockerrs{$suffix} = $lockerr{$prefix};
1859: next;
1860: }
1861: if ($lockerr{$prefix}) {
1862: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1863: }
1.489 raeburn 1864: }
1865: }
1.538 raeburn 1866: $title = &LONCAPA::map::qtunescape($title);
1867: my $ext='false';
1868: if ($url=~m{^http(|s)://}) { $ext='true'; }
1869: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1870: if ($folder !~ /^supplemental/) {
1871: (undef,undef,$title) =
1872: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1873: }
1874: } else {
1875: if ($folder=~/^supplemental/) {
1876: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1877: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1878: }
1.533 raeburn 1879: }
1.491 raeburn 1880:
1881: # For uploaded files (excluding pages/sequences) path in copied file is changed
1882: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1883: # courses.
1884:
1.538 raeburn 1885: unless ($is_map{$suffix}) {
1886: my $newidx;
1.492 raeburn 1887: # Now insert the URL at the bottom
1.538 raeburn 1888: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1889: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1890: my $relpath = $1;
1891: if ($relpath ne '') {
1892: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1893: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1894: my $newprefix = $newloc;
1895: if ($newloc eq 'default') {
1896: $newprefix = 'docs';
1897: }
1898: if ($newdocsdir eq '') {
1899: $newdocsdir = 'default';
1900: }
1901: if (($prefixchg{$suffix}) ||
1902: ($srcdom{$suffix} ne $coursedom) ||
1903: ($srcnum{$suffix} ne $coursenum) ||
1904: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1905: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1906: $url =
1907: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1908: &Apache::lonnet::getfile($oldurl));
1909: if ($url eq '/adm/notfound.html') {
1910: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1911: next;
1912: } else {
1913: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1914: $newsubpath =~ s{/+$}{/};
1915: $docmoves{$oldurl} = $newsubpath;
1916: }
1.491 raeburn 1917: }
1918: }
1.597 raeburn 1919: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1920: my $template = $1;
1921: if ($newidx) {
1922: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1923: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1924: }
1.491 raeburn 1925: }
1.538 raeburn 1926: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1927: ':'.$ext.':normal:res';
1928: push(@LONCAPA::map::order,$newidx);
1929: # Store the result
1930: my ($errtext,$fatal) =
1931: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1932: if ($fatal) {
1933: $save_err .= $errtext;
1934: $allresult = 'fail';
1935: }
1.488 raeburn 1936: }
1.538 raeburn 1937:
1.597 raeburn 1938: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1939: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1940: unless ($allresult eq 'fail') {
1941: my %updated = (
1942: rewrites => \%rewrites,
1943: zombies => \%zombies,
1944: removefrommap => \%removefrommap,
1945: removeparam => \%removeparam,
1946: dbcopies => \%dbcopies,
1.597 raeburn 1947: resdatacopy => \%resdatacopy,
1.538 raeburn 1948: retitles => \%retitles,
1949: );
1950: my %info = (
1951: newsubdir => \%newsubdir,
1952: params => \%params,
1953: );
1954: if ($prefixchg{$suffix}) {
1955: $info{'before'} = $before{$prefixchg{$suffix}};
1956: $info{'after'} = $after{$prefixchg{$suffix}};
1957: }
1958: my %moves = (
1959: copies => \%copies,
1960: docmoves => \%docmoves,
1961: mapmoves => \%mapmoves,
1962: );
1963: (my $result,$msgs{$suffix},my $lockerror) =
1964: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1965: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1966: $url,'paste');
1967: $lockerrors .= $lockerror;
1968: if ($result eq 'ok') {
1969: if ($is_map{$suffix}) {
1970: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1971: $folder.'.'.$container);
1972: if ($fatal) {
1973: $allresult = 'failread';
1974: } else {
1975: if ($#LONCAPA::map::order<1) {
1976: my $idx=&LONCAPA::map::getresidx();
1977: if ($idx<=0) { $idx=1; }
1978: $LONCAPA::map::order[0]=$idx;
1979: $LONCAPA::map::resources[$idx]='';
1980: }
1981: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1982: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1983: ':'.$ext.':normal:res';
1984: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 1985:
1986: # Store the result
1.538 raeburn 1987: my ($errtext,$fatal) =
1988: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1989: if ($fatal) {
1990: $save_err .= $errtext;
1991: $allresult = 'failstore';
1992: }
1993: }
1994: }
1995: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1996: push(@toclear,$suffix);
1997: }
1998: }
1.492 raeburn 1999: }
2000: }
1.538 raeburn 2001: &clear_from_buffer(\@toclear,\@currpaste);
2002: my $msgsarray;
2003: foreach my $suffix (keys(%msgs)) {
2004: if (ref($msgs{$suffix}) eq 'ARRAY') {
2005: $msgsarray .= join(',',@{$msgs{$suffix}});
2006: }
2007: }
2008: return ($allresult,$save_err,$msgsarray,$lockerrors);
2009: }
1.533 raeburn 2010:
1.538 raeburn 2011: sub do_buffer_empty {
2012: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2013: if (@currpaste == 0) {
2014: return &mt('Clipboard is already empty');
2015: }
2016: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2017: if (@toclear == 0) {
2018: return &mt('Nothing selected to clear from clipboard');
2019: }
2020: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2021: if ($numdel) {
2022: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2023: } else {
2024: return &mt('Clipboard unchanged');
1.492 raeburn 2025: }
1.538 raeburn 2026: return;
2027: }
2028:
2029: sub clear_from_buffer {
2030: my ($toclear,$currpaste) = @_;
2031: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2032: my %pastebuffer;
2033: map { $pastebuffer{$_} = 1; } @{$currpaste};
2034: my $numdel = 0;
2035: foreach my $suffix (@{$toclear}) {
2036: next if ($suffix =~ /\D/);
2037: next unless (exists($pastebuffer{$suffix}));
2038: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2039: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2040: delete($pastebuffer{$suffix});
2041: $numdel ++;
2042: }
2043: }
2044: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2045: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2046: return $numdel;
1.492 raeburn 2047: }
2048:
2049: sub get_newmap_url {
2050: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2051: $titleref,$allmaps,$newurls) = @_;
2052: my $newurl;
2053: if ($url=~ m{^/uploaded/}) {
2054: $$titleref=&mt('Copy of').' '.$$titleref;
2055: }
2056: my $now = time;
2057: my $suffix=$$.int(rand(100)).$now;
2058: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2059: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2060: my $path = $1;
2061: my $prefix = $2;
2062: my $ancestor = $3;
2063: if (length($ancestor) > 10) {
2064: $ancestor = substr($ancestor,-10,10);
2065: }
2066: my $newid;
2067: if ($prefixchg) {
2068: if ($folder =~ /^supplemental/) {
2069: $prefix =~ s/^default/supplemental/;
2070: } else {
2071: $prefix =~ s/^supplemental/default/;
2072: }
2073: }
2074: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2075: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2076: } else {
2077: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2078: }
2079: my $counter = 0;
2080: my $is_unique = &uniqueness_check($newurl);
2081: if ($folder =~ /^default/) {
2082: if ($allmaps->{$newurl}) {
2083: $is_unique = 0;
2084: }
2085: }
2086: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2087: $counter ++;
2088: $suffix ++;
2089: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2090: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2091: } else {
2092: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2093: }
2094: $is_unique = &uniqueness_check($newurl);
2095: }
2096: if ($is_unique) {
2097: $newurls->{$newurl} = 1;
2098: } else {
2099: if ($url=~/\.page$/) {
2100: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2101: } else {
2102: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2103: }
2104: }
1.329 droeschl 2105: }
1.492 raeburn 2106: return ($newurl);
1.329 droeschl 2107: }
2108:
1.488 raeburn 2109: sub dbcopy {
1.533 raeburn 2110: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2111: my ($url,$result,$errtext);
2112: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2113: $url = $dbref->{'src'};
1.533 raeburn 2114: if ($url =~ m{/(smppg|bulletinboard)$}) {
2115: my $prefix = $1;
2116: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2117: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2118: my $db_name;
2119: my $marker = (split(m{/},$url))[4];
2120: $marker=~s/\D//g;
2121: if ($dbref->{'src'} =~ m{/smppg$}) {
2122: $db_name =
2123: &Apache::lonsimplepage::get_db_name($url,$marker,
2124: $dbref->{'cdom'},
2125: $dbref->{'cnum'});
2126: } else {
2127: $db_name = 'bulletinpage_'.$marker;
2128: }
2129: my ($suffix,$freedlock,$error) =
2130: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2131: $coursedom,$coursenum,
2132: 'concat');
2133: if (!$suffix) {
2134: if ($prefix eq 'smppg') {
2135: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2136: } else {
1.565 bisitz 2137: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2138: }
2139: if ($error) {
2140: $errtext .= '<br />'.$error;
2141: }
2142: } else {
2143: #need to copy the db contents to a new one.
2144: my %contents=&Apache::lonnet::dump($db_name,
2145: $dbref->{'cdom'},
2146: $dbref->{'cnum'});
2147: if (exists($contents{'uploaded.photourl'})) {
2148: my $photo = $contents{'uploaded.photourl'};
2149: my ($subdir,$fname) =
2150: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2151: my $newphoto;
1.533 raeburn 2152: if ($fname ne '') {
2153: my $content = &Apache::lonnet::getfile($photo);
2154: unless ($content eq '-1') {
2155: $env{'form.'.$suffix.'.photourl'} = $content;
2156: $newphoto =
2157: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2158: delete($env{'form.'.$suffix.'.photourl'});
2159: }
2160: }
2161: if ($newphoto =~ m{^/uploaded/}) {
2162: $contents{'uploaded.photourl'} = $newphoto;
2163: }
2164: }
2165: $db_name =~ s{_\d*$ }{_$suffix}x;
2166: $result=&Apache::lonnet::put($db_name,\%contents,
2167: $coursedom,$coursenum);
2168: if ($result eq 'ok') {
2169: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2170: }
2171: }
2172: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2173: $lockerrorsref->{$prefix} =
1.533 raeburn 2174: '<div class="LC_error">'.
2175: &mt('There was a problem removing a lockfile.');
2176: if ($prefix eq 'smppg') {
1.560 raeburn 2177: $lockerrorsref->{$prefix} .=
1.559 raeburn 2178: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.533 raeburn 2179: } else {
1.565 bisitz 2180: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2181: }
1.560 raeburn 2182: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2183: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2184: '</div>';
1.533 raeburn 2185: }
2186: }
2187: } elsif ($url =~ m{/syllabus$}) {
2188: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2189: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2190: if (($dbref->{'cdom'} ne $coursedom) ||
2191: ($dbref->{'cnum'} ne $coursenum)) {
2192: my %contents=&Apache::lonnet::dump('syllabus',
2193: $dbref->{'cdom'},
2194: $dbref->{'cnum'});
2195: $result=&Apache::lonnet::put('syllabus',\%contents,
2196: $coursedom,$coursenum);
2197: }
2198: }
1.488 raeburn 2199: }
2200: }
1.533 raeburn 2201: return ($url,$result,$errtext);
1.488 raeburn 2202: }
2203:
1.597 raeburn 2204: sub copy_templated_files {
2205: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2206: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2207: my $srccontainer = 'sequence';
2208: if ($srcwaspage) {
2209: $srccontainer = 'page';
2210: }
2211: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2212: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2213: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2214: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2215: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2216: $template.'.problem';
2217: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2218: if ($template eq 'simpleproblem') {
2219: $srcprefix .= '.0.';
2220: my $weightprefix = $newprefix;
2221: $newprefix .= '.0.';
2222: my @simpleprobqtypes = qw(radio option string essay numerical);
2223: my $qtype=$srcparms{$srcprefix.'questiontype'};
2224: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2225: my %newdata;
2226: foreach my $type (@simpleprobqtypes) {
2227: if ($type eq $qtype) {
2228: $newdata{"$weightprefix.$type.weight"}=1;
2229: } else {
2230: $newdata{"$weightprefix.$type.weight"}=0;
2231: }
2232: }
2233: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2234: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2235: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2236: if ($qtype eq 'numerical') {
2237: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2238: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2239: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2240: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2241: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2242: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2243: unless (defined($maxfoils)) { $maxfoils=10; }
2244: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2245: if ($maxfoils<=0) { $maxfoils=10; }
2246: my $randomize=$srcparms{$srcprefix.'randomize'};
2247: unless (defined($randomize)) { $randomize='yes'; }
2248: unless ($randomize eq 'no') { $randomize='yes'; }
2249: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2250: $newdata{$newprefix.'randomize'} = $randomize;
2251: if ($qtype eq 'option') {
2252: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2253: }
2254: for (my $i=1; $i<=10; $i++) {
2255: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2256: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2257: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2258: }
2259:
2260: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2261: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2262: unless (defined($maxfoils)) { $maxfoils=10; }
2263: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2264: if ($maxfoils<=0) { $maxfoils=10; }
2265: my $randomize=$srcparms{$srcprefix.'randomize'};
2266: unless (defined($randomize)) { $randomize='yes'; }
2267: unless ($randomize eq 'no') { $randomize='yes'; }
2268: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2269: $newdata{$newprefix.'randomize'} = $randomize;
2270: if ($qtype eq 'option') {
2271: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2272: }
2273: for (my $i=1; $i<=10; $i++) {
2274: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2275: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2276: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2277: }
2278: } elsif ($qtype eq 'string') {
2279: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2280: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2281: }
2282: if (keys(%newdata)) {
2283: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2284: $coursenum);
2285: if ($putres eq 'ok') {
2286: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2287: }
2288: }
2289: }
2290: }
2291: }
2292:
1.329 droeschl 2293: sub uniqueness_check {
2294: my ($newurl) = @_;
2295: my $unique = 1;
2296: foreach my $res (@LONCAPA::map::order) {
2297: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2298: $url=&LONCAPA::map::qtescape($url);
2299: if ($newurl eq $url) {
2300: $unique = 0;
1.344 bisitz 2301: last;
1.329 droeschl 2302: }
2303: }
2304: return $unique;
2305: }
2306:
1.488 raeburn 2307: sub contained_map_check {
1.492 raeburn 2308: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2309: $allmaps) = @_;
1.488 raeburn 2310: my $content = &Apache::lonnet::getfile($url);
2311: unless ($content eq '-1') {
2312: my $parser = HTML::TokeParser->new(\$content);
2313: $parser->attr_encoded(1);
2314: while (my $token = $parser->get_token) {
2315: next if ($token->[0] ne 'S');
2316: if ($token->[1] eq 'resource') {
2317: next if ($token->[2]->{'type'} eq 'zombie');
2318: my $ressrc = $token->[2]->{'src'};
2319: if ($folder =~ /^supplemental/) {
2320: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2321: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2322: next;
2323: }
2324: }
1.492 raeburn 2325: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2326: if ($1 eq 'uploaded') {
2327: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2328: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2329: } else {
1.492 raeburn 2330: if ($allmaps->{$ressrc}) {
1.529 raeburn 2331: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2332: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2333: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2334: } else {
2335: $addedmaps->{$ressrc} = [$url];
2336: }
1.488 raeburn 2337: }
1.492 raeburn 2338: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2339: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2340: }
1.492 raeburn 2341: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2342: if ($folder =~ /^supplemental/) {
1.492 raeburn 2343: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2344: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2345: } else {
2346: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2347: }
1.488 raeburn 2348: }
2349: }
2350: }
2351: }
2352: return;
2353: }
2354:
2355: sub url_paste_fixups {
1.533 raeburn 2356: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2357: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2358: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2359: my $checktitle;
2360: if (($prefixchg) &&
1.492 raeburn 2361: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2362: $checktitle = 1;
2363: }
1.492 raeburn 2364: my $skip;
2365: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2366: my $mapid = $1.$2;
2367: if ($tomove->{$mapid}) {
2368: $skip = 1;
2369: }
2370: }
1.491 raeburn 2371: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2372: return if ($file eq '-1');
2373: my $parser = HTML::TokeParser->new(\$file);
2374: $parser->attr_encoded(1);
1.491 raeburn 2375: my $changed = 0;
1.488 raeburn 2376: while (my $token = $parser->get_token) {
2377: next if ($token->[0] ne 'S');
2378: if ($token->[1] eq 'resource') {
2379: my $ressrc = $token->[2]->{'src'};
2380: next if ($ressrc eq '');
1.491 raeburn 2381: my $id = $token->[2]->{'id'};
1.492 raeburn 2382: my $title = $token->[2]->{'title'};
1.491 raeburn 2383: if ($checktitle) {
2384: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2385: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2386: }
2387: }
1.488 raeburn 2388: next if ($token->[2]->{'type'} eq 'external');
2389: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2390: next if ($skip);
1.532 raeburn 2391: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2392: $changed = 1;
2393: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2394: my $srcdom = $1;
2395: my $srcnum = $2;
1.488 raeburn 2396: my $rem = $3;
1.492 raeburn 2397: my $newurl;
2398: my $mapname;
2399: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2400: my $prefix = $1;
2401: $mapname = $prefix.$2;
2402: if ($tomove->{$mapname}) {
1.533 raeburn 2403: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2404: $srcdom,$srcnum,$allmaps,$rewrites,
2405: $retitles,$copies,$dbcopies,$zombies,
2406: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2407: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2408: next;
2409: } else {
2410: ($newurl,my $error) =
2411: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2412: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2413: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2414: $newsubdir->{$ressrc} = $1;
2415: }
2416: if ($error) {
2417: next;
2418: }
2419: }
2420: }
2421: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2422: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2423:
1.488 raeburn 2424: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2425: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2426: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2427: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2428: $cnum,$srcdom,$srcnum,$allmaps,
2429: $rewrites,$retitles,$copies,$dbcopies,
2430: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2431: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2432: $mapmoves->{$ressrc} = 1;
2433: }
2434: $changed = 1;
1.488 raeburn 2435: } else {
1.532 raeburn 2436: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2437: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2438: $changed = 1;
1.488 raeburn 2439: }
2440: }
1.533 raeburn 2441: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2442: next if ($skip);
1.492 raeburn 2443: my $srcdom = $1;
2444: my $srcnum = $2;
2445: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2446: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2447: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2448: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2449: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2450: $changed = 1;
2451: }
2452: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2453: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2454: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2455: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2456: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2457: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2458: $changed = 1;
1.488 raeburn 2459: }
1.597 raeburn 2460: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2461: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2462: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2463: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2464: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2465: }
1.488 raeburn 2466: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2467: next if ($skip);
2468: my $srcdom = $1;
2469: my $srcnum = $2;
2470: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2471: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2472: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2473: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2474: $changed = 1;
1.488 raeburn 2475: }
2476: }
2477: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2478: next if ($skip);
1.488 raeburn 2479: my $to = $token->[2]->{'to'};
2480: if ($to ne '') {
2481: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2482: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2483: } else {
2484: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2485: }
2486: }
2487: }
2488: }
1.491 raeburn 2489: return $changed;
1.488 raeburn 2490: }
2491:
2492: sub apply_fixups {
1.529 raeburn 2493: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2494: $oldurl,$url,$caller) = @_;
2495: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2496: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2497: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2498: if (ref($updated) eq 'HASH') {
2499: if (ref($updated->{'rewrites'}) eq 'HASH') {
2500: %rewrites = %{$updated->{'rewrites'}};
2501: }
2502: if (ref($updated->{'zombies'}) eq 'HASH') {
2503: %zombies = %{$updated->{'zombies'}};
2504: }
2505: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2506: %removefrommap = %{$updated->{'removefrommap'}};
2507: }
2508: if (ref($updated->{'removeparam'}) eq 'HASH') {
2509: %removeparam = %{$updated->{'removeparam'}};
2510: }
2511: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2512: %dbcopies = %{$updated->{'dbcopies'}};
2513: }
2514: if (ref($updated->{'retitles'}) eq 'HASH') {
2515: %retitles = %{$updated->{'retitles'}};
2516: }
1.597 raeburn 2517: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2518: %resdatacopy = %{$updated->{'resdatacopy'}};
2519: }
1.529 raeburn 2520: }
2521: if (ref($info) eq 'HASH') {
2522: if (ref($info->{'newsubdir'}) eq 'HASH') {
2523: %newsubdir = %{$info->{'newsubdir'}};
2524: }
2525: if (ref($info->{'params'}) eq 'HASH') {
2526: %params = %{$info->{'params'}};
2527: }
2528: if (ref($info->{'before'}) eq 'HASH') {
2529: %before = %{$info->{'before'}};
2530: }
2531: if (ref($info->{'after'}) eq 'HASH') {
2532: %after = %{$info->{'after'}};
2533: }
2534: }
2535: if (ref($moves) eq 'HASH') {
2536: if (ref($moves->{'copies'}) eq 'HASH') {
2537: %copies = %{$moves->{'copies'}};
2538: }
2539: if (ref($moves->{'docmoves'}) eq 'HASH') {
2540: %docmoves = %{$moves->{'docmoves'}};
2541: }
2542: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2543: %mapmoves = %{$moves->{'mapmoves'}};
2544: }
2545: }
2546: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2547: my @allcopies;
1.529 raeburn 2548: if (exists($copies{$key})) {
2549: if (ref($copies{$key}) eq 'HASH') {
2550: my %added;
2551: foreach my $innerkey (keys(%{$copies{$key}})) {
2552: if (($innerkey ne '') && (!$added{$innerkey})) {
2553: push(@allcopies,$innerkey);
2554: $added{$innerkey} = 1;
2555: }
1.491 raeburn 2556: }
1.529 raeburn 2557: undef(%added);
1.491 raeburn 2558: }
2559: }
2560: if ($key eq $oldurl) {
1.529 raeburn 2561: if ((exists($docmoves{$key}))) {
1.532 raeburn 2562: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2563: push(@allcopies,$oldurl);
2564: }
2565: }
2566: }
2567: if (@allcopies > 0) {
2568: foreach my $item (@allcopies) {
1.492 raeburn 2569: my ($relpath,$oldsubdir,$fname) =
2570: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2571: if ($fname ne '') {
2572: my $content = &Apache::lonnet::getfile($item);
2573: unless ($content eq '-1') {
2574: my $storefn;
1.529 raeburn 2575: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2576: $storefn = $docmoves{$key};
1.491 raeburn 2577: } else {
2578: $storefn = $relpath;
2579: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2580: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2581: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2582: }
1.529 raeburn 2583: if ($newsubdir{$key}) {
1.532 raeburn 2584: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2585: }
2586: }
2587: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2588: my $copyurl =
2589: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2590: $storefn.$fname,$content);
2591: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2592: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2593: return &mt('Paste failed: an error occurred copying the file.');
2594: } elsif (ref($errors) eq 'HASH') {
2595: $errors->{$item} = 1;
1.489 raeburn 2596: }
2597: }
1.488 raeburn 2598: }
2599: }
1.491 raeburn 2600: }
2601: }
2602: }
1.529 raeburn 2603: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2604: my $storefn=$key;
2605: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2606: if ($prefixchg && $before{'map'} && $after{'map'}) {
2607: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2608: }
1.529 raeburn 2609: if ($newsubdir{$key}) {
2610: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2611: }
1.491 raeburn 2612: my $mapcontent = &Apache::lonnet::getfile($key);
2613: if ($mapcontent eq '-1') {
2614: if (ref($errors) eq 'HASH') {
2615: $errors->{$key} = 1;
2616: }
2617: } else {
2618: my $newmap =
2619: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2620: $mapcontent);
2621: if ($newmap eq '/adm/notfound.html') {
2622: if (ref($errors) eq 'HASH') {
2623: $errors->{$key} = 1;
1.489 raeburn 2624: }
1.488 raeburn 2625: }
2626: }
2627: }
1.491 raeburn 2628: my %updates;
2629: if ($is_map) {
1.529 raeburn 2630: if (ref($updated) eq 'HASH') {
2631: foreach my $type (keys(%{$updated})) {
2632: if (ref($updated->{$type}) eq 'HASH') {
2633: foreach my $key (keys(%{$updated->{$type}})) {
2634: $updates{$key} = 1;
2635: }
2636: }
2637: }
1.491 raeburn 2638: }
2639: foreach my $key (keys(%updates)) {
1.492 raeburn 2640: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2641: if (ref($rewrites{$key}) eq 'HASH') {
2642: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2643: }
1.529 raeburn 2644: if (ref($retitles{$key}) eq 'HASH') {
2645: %toretitle = %{$retitles{$key}};
1.491 raeburn 2646: }
1.529 raeburn 2647: if (ref($removefrommap{$key}) eq 'HASH') {
2648: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2649: }
1.529 raeburn 2650: if (ref($removeparam{$key}) eq 'HASH') {
2651: %remparam = %{$removeparam{$key}};
1.492 raeburn 2652: }
1.529 raeburn 2653: if (ref($zombies{$key}) eq 'HASH') {
2654: %zombie = %{$zombies{$key}};
1.491 raeburn 2655: }
1.529 raeburn 2656: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2657: foreach my $idx (keys(%{$dbcopies{$key}})) {
2658: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2659: my ($newurl,$result,$errtext) =
2660: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2661: if ($result eq 'ok') {
2662: $newdb{$idx} = $newurl;
2663: } elsif (ref($errors) eq 'HASH') {
2664: $errors->{$key} = 1;
2665: }
2666: push(@msgs,$errtext);
2667: }
1.491 raeburn 2668: }
2669: }
1.597 raeburn 2670: if (ref($resdatacopy{$key}) eq 'HASH') {
2671: if ($newsubdir{$key}) {
2672:
2673: }
2674: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2675: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2676: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2677: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2678: my $template = $1;
2679: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2680: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2681: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2682: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2683: my ($newmapname) = ($key =~ m{/([^/]+)$});
2684: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2685: my $srcmapinfo = $srcfolder.':'.$idx;
2686: if ($srccontainer eq 'page') {
2687: $srcmapinfo .= ':1';
2688: }
2689: if ($newsubdir{$key}) {
2690: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2691: }
2692: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2693: $cnum,$template,$idx,$newmapname);
2694: }
2695: }
2696: }
2697: }
2698: }
1.529 raeburn 2699: if (ref($params{$key}) eq 'HASH') {
2700: %currparam = %{$params{$key}};
1.492 raeburn 2701: }
2702: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2703: if ($fatal) {
1.533 raeburn 2704: return ($errtext);
1.492 raeburn 2705: }
2706: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2707: if (defined($LONCAPA::map::zombies[$i])) {
2708: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2709: if ($zombie{$i} eq $src) {
1.492 raeburn 2710: undef($LONCAPA::map::zombies[$i]);
2711: }
2712: }
2713: }
1.529 raeburn 2714: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2715: my $idx = $LONCAPA::map::order[$i];
2716: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2717: my $changed;
1.529 raeburn 2718: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2719: if ((exists($toremove{$idx})) &&
2720: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2721: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2722: if (ref($currparam{$idx}) eq 'ARRAY') {
2723: foreach my $name (@{$currparam{$idx}}) {
2724: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2725: }
2726: }
2727: next;
2728: }
2729: my $origsrc = $src;
1.532 raeburn 2730: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2731: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2732: $changed = 1;
1.491 raeburn 2733: }
1.492 raeburn 2734: }
1.532 raeburn 2735: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2736: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2737: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2738: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2739: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2740: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2741: } else {
1.529 raeburn 2742: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2743: }
1.491 raeburn 2744: }
1.532 raeburn 2745: if ($origsrc =~ /\.(page|sequence)$/) {
2746: if ($newsubdir{$origsrc}) {
1.529 raeburn 2747: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2748: }
1.532 raeburn 2749: } elsif ($newsubdir{$key}) {
2750: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2751: }
2752: }
1.492 raeburn 2753: $changed = 1;
1.533 raeburn 2754: } elsif ($newdb{$idx} ne '') {
2755: $src = $newdb{$idx};
1.492 raeburn 2756: $changed = 1;
2757: }
2758: if ($changed) {
1.538 raeburn 2759: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2760: }
2761: }
2762: }
2763: foreach my $idx (keys(%remparam)) {
2764: if (ref($remparam{$idx}) eq 'ARRAY') {
2765: foreach my $name (@{$remparam{$idx}}) {
2766: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2767: }
2768: }
2769: }
1.533 raeburn 2770: if (values(%lockerrors) > 0) {
2771: $lockmsg = join('<br />',values(%lockerrors));
2772: }
1.491 raeburn 2773: my $storefn;
2774: if ($key eq $oldurl) {
2775: $storefn = $url;
2776: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2777: } else {
2778: $storefn = $key;
2779: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2780: if ($prefixchg && $before{'map'} && $after{'map'}) {
2781: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2782: }
1.529 raeburn 2783: if ($newsubdir{$key}) {
2784: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2785: }
1.491 raeburn 2786: }
1.492 raeburn 2787: my $report;
2788: if ($folder !~ /^supplemental/) {
2789: $report = 1;
2790: }
1.527 raeburn 2791: (my $outtext,$errtext) =
1.492 raeburn 2792: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2793: if ($errtext) {
1.529 raeburn 2794: if ($caller eq 'paste') {
1.533 raeburn 2795: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2796: }
1.491 raeburn 2797: }
2798: }
2799: }
1.533 raeburn 2800: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2801: }
2802:
2803: sub copy_dependencies {
2804: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2805: my $content;
2806: if (ref($contentref)) {
2807: $content = $$contentref;
2808: } else {
2809: $content = &Apache::lonnet::getfile($item);
2810: }
2811: unless ($content eq '-1') {
2812: my $mm = new File::MMagic;
2813: my $mimetype = $mm->checktype_contents($content);
2814: if ($mimetype eq 'text/html') {
2815: my (%allfiles,%codebase,$state);
2816: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2817: if ($res eq 'ok') {
2818: my ($numexisting,$numpathchanges,$existing);
2819: (undef,$numexisting,$numpathchanges,$existing) =
2820: &Apache::loncommon::ask_for_embedded_content(
2821: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2822: {'error_on_invalid_names' => 1,
2823: 'ignore_remote_references' => 1,
2824: 'docs_url' => $item,
2825: 'context' => 'paste'});
2826: if ($numexisting > 0) {
2827: if (ref($existing) eq 'HASH') {
2828: foreach my $dep (keys(%{$existing})) {
2829: my $depfile = $dep;
2830: unless ($depfile =~ m{^\Q$relpath\E}) {
2831: $depfile = $relpath.$dep;
2832: }
2833: my $depcontent = &Apache::lonnet::getfile($depfile);
2834: unless ($depcontent eq '-1') {
2835: my $storedep = $dep;
2836: $storedep =~ s{^\Q$relpath\E}{};
2837: my $dep_url =
2838: &Apache::lonclonecourse::writefile(
2839: $env{'request.course.id'},
2840: $storefn.$storedep,$depcontent);
2841: if ($dep_url eq '/adm/notfound.html') {
2842: if (ref($errors) eq 'HASH') {
2843: $errors->{$depfile} = 1;
2844: }
2845: } else {
2846: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2847: }
2848: }
2849: }
1.488 raeburn 2850: }
2851: }
2852: }
2853: }
2854: }
2855: return;
2856: }
2857:
1.329 droeschl 2858: my %parameter_type = ( 'randompick' => 'int_pos',
2859: 'hiddenresource' => 'string_yesno',
2860: 'encrypturl' => 'string_yesno',
2861: 'randomorder' => 'string_yesno',);
2862: my $valid_parameters_re = join('|',keys(%parameter_type));
2863: # set parameters
2864: sub update_parameter {
1.537 raeburn 2865: if ($env{'form.changeparms'} eq 'all') {
2866: my (@allidx,@allmapidx,%allchecked,%currchecked);
2867: %allchecked = (
2868: 'hiddenresource' => {},
2869: 'encrypturl' => {},
2870: 'randompick' => {},
2871: 'randomorder' => {},
2872: );
2873: foreach my $which (keys(%allchecked)) {
2874: $env{'form.all'.$which} =~ s/,$//;
2875: if ($which eq 'randompick') {
2876: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2877: my ($res,$value) = split(/:/,$item);
2878: if ($value =~ /^\d+$/) {
2879: $allchecked{$which}{$res} = $value;
2880: }
2881: }
2882: } else {
1.539 raeburn 2883: if ($env{'form.all'.$which}) {
2884: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2885: }
1.537 raeburn 2886: }
2887: }
2888: my $haschanges = 0;
2889: foreach my $res (@LONCAPA::map::order) {
2890: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2891: $name=&LONCAPA::map::qtescape($name);
2892: $url=&LONCAPA::map::qtescape($url);
2893: next unless ($name && $url);
2894: my $is_map;
2895: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2896: $is_map = 1;
2897: }
2898: foreach my $which (keys(%allchecked)) {
2899: if (($which eq 'randompick' || $which eq 'randomorder')) {
2900: next if (!$is_map);
2901: }
2902: my $oldvalue = 0;
2903: my $newvalue = 0;
2904: if ($allchecked{$which}{$res}) {
2905: $newvalue = $allchecked{$which}{$res};
2906: }
2907: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2908: if ($which eq 'randompick') {
2909: if ($current =~ /^(\d+)$/) {
2910: $oldvalue = $1;
2911: }
2912: } else {
2913: if ($current =~ /^yes$/i) {
2914: $oldvalue = 1;
2915: }
2916: }
2917: if ($oldvalue ne $newvalue) {
2918: $haschanges = 1;
2919: if ($newvalue) {
2920: my $storeval = 'yes';
2921: if ($which eq 'randompick') {
2922: $storeval = $newvalue;
2923: }
2924: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2925: $storeval,
2926: $parameter_type{$which});
2927: &remember_parms($res,$which,'set',$storeval);
2928: } elsif ($oldvalue) {
2929: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2930: &remember_parms($res,$which,'del');
2931: }
2932: }
2933: }
2934: }
2935: return $haschanges;
2936: } else {
1.588 raeburn 2937: my $haschanges = 0;
2938: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2939:
1.537 raeburn 2940: my $which = $env{'form.changeparms'};
2941: my $idx = $env{'form.setparms'};
1.588 raeburn 2942: my $oldvalue = 0;
2943: my $newvalue = 0;
2944: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2945: if ($which eq 'randompick') {
2946: if ($current =~ /^(\d+)$/) {
2947: $oldvalue = $1;
2948: }
2949: } elsif ($current =~ /^yes$/i) {
2950: $oldvalue = 1;
2951: }
1.537 raeburn 2952: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2953: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2954: : 1;
2955: }
2956: if ($oldvalue ne $newvalue) {
2957: $haschanges = 1;
2958: if ($newvalue) {
2959: my $storeval = 'yes';
2960: if ($which eq 'randompick') {
2961: $storeval = $newvalue;
2962: }
2963: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2964: $parameter_type{$which});
2965: &remember_parms($idx,$which,'set',$storeval);
2966: } else {
2967: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2968: &remember_parms($idx,$which,'del');
2969: }
1.537 raeburn 2970: }
1.588 raeburn 2971: return $haschanges;
1.329 droeschl 2972: }
2973: }
2974:
2975: sub handle_edit_cmd {
2976: my ($coursenum,$coursedom) =@_;
1.543 raeburn 2977: if ($env{'form.cmd'} eq '') {
2978: return 0;
2979: }
1.329 droeschl 2980: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2981:
2982: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2983: my ($title, $url, @rrest) = split(':', $ratstr);
2984:
1.538 raeburn 2985: if ($cmd eq 'remove') {
1.329 droeschl 2986: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2987: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2988: &Apache::lonnet::removeuploadedurl($url);
2989: } else {
2990: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2991: }
2992: splice(@LONCAPA::map::order, $idx, 1);
2993:
2994: } elsif ($cmd eq 'cut') {
2995: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2996: splice(@LONCAPA::map::order, $idx, 1);
2997:
1.344 bisitz 2998: } elsif ($cmd eq 'up'
1.329 droeschl 2999: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3000: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3001:
3002: } elsif ($cmd eq 'down'
3003: && defined($LONCAPA::map::order[$idx+1])) {
3004: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3005:
3006: } elsif ($cmd eq 'rename') {
3007: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3008: if ($comment=~/\S/) {
3009: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3010: $comment.':'.join(':', $url, @rrest);
3011: }
3012: # Devalidate title cache
3013: my $renamed_url=&LONCAPA::map::qtescape($url);
3014: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 3015:
1.329 droeschl 3016: } else {
3017: return 0;
3018: }
3019: return 1;
3020: }
3021:
3022: sub editor {
1.458 raeburn 3023: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3024: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3025: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3026: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3027: if ($allowed) {
1.519 raeburn 3028: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3029: $is_random_order,$container) =
1.510 raeburn 3030: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3031: $r->print($breadcrumbtrail);
1.519 raeburn 3032: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3033: $container = 'page';
3034: } else {
3035: $container = 'sequence';
1.510 raeburn 3036: }
1.484 raeburn 3037:
1.525 raeburn 3038: my $jumpto;
3039:
3040: unless ($supplementalflag) {
1.546 raeburn 3041: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3042: }
1.484 raeburn 3043:
3044: unless ($allowed) {
3045: $randompick = -1;
3046: }
3047:
1.615 raeburn 3048: my ($errtext,$fatal);
3049: if (($folder eq '') && (!$supplementalflag)) {
3050: if (@LONCAPA::map::order) {
3051: undef(@LONCAPA::map::order);
3052: undef(@LONCAPA::map::resources);
3053: undef(@LONCAPA::map::resparms);
3054: undef(@LONCAPA::map::zombies);
3055: }
3056: $folder = 'default';
3057: $container = 'sequence';
3058: } else {
3059: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3060: $folder.'.'.$container);
3061: return $errtext if ($fatal);
3062: }
1.329 droeschl 3063:
3064: if ($#LONCAPA::map::order<1) {
3065: my $idx=&LONCAPA::map::getresidx();
3066: if ($idx<=0) { $idx=1; }
3067: $LONCAPA::map::order[0]=$idx;
3068: $LONCAPA::map::resources[$idx]='';
3069: }
1.364 bisitz 3070:
1.329 droeschl 3071: # ------------------------------------------------------------ Process commands
3072:
3073: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3074: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3075: # set parameters and change order
3076: &snapshotbefore();
3077:
3078: if (&update_parameter()) {
1.588 raeburn 3079: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3080: return $errtext if ($fatal);
3081: }
3082:
3083: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3084: # change order
3085: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3086: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3087:
3088: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3089: return $errtext if ($fatal);
3090: }
1.364 bisitz 3091:
1.329 droeschl 3092: if ($env{'form.pastemarked'}) {
1.491 raeburn 3093: my %paste_errors;
1.533 raeburn 3094: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3095: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3096: \%paste_errors);
1.541 raeburn 3097: if (ref($pastemsgarray) eq 'ARRAY') {
3098: if (@{$pastemsgarray} > 0) {
3099: $r->print('<p class="LC_info">'.
3100: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3101: '</p>');
3102: }
1.541 raeburn 3103: }
3104: if ($lockerror) {
3105: $r->print('<p class="LC_error">'.
3106: $lockerror.
3107: '</p>');
3108: }
3109: if ($save_error ne '') {
3110: return $save_error;
3111: }
3112: if ($paste_res) {
3113: my %errortext = &Apache::lonlocal::texthash (
3114: fail => 'Storage of folder contents failed',
3115: failread => 'Reading folder contents failed',
3116: failstore => 'Storage of folder contents failed',
3117: );
3118: if ($errortext{$paste_res}) {
3119: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3120: }
1.329 droeschl 3121: }
1.491 raeburn 3122: if (keys(%paste_errors) > 0) {
1.538 raeburn 3123: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3124: &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".
3125: '<ul>'."\n");
3126: foreach my $key (sort(keys(%paste_errors))) {
3127: $r->print('<li>'.$key.'</li>'."\n");
3128: }
3129: $r->print('</ul></p>'."\n");
3130: }
1.538 raeburn 3131: } elsif ($env{'form.clearmarked'}) {
3132: my $output = &do_buffer_empty();
3133: if ($output) {
3134: $r->print('<p class="LC_info">'.$output.'</p>');
3135: }
3136: }
1.329 droeschl 3137:
3138: $r->print($upload_output);
3139:
1.538 raeburn 3140: # Rename, cut, copy or remove a single resource
1.602 raeburn 3141: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3142: my $contentchg;
1.592 raeburn 3143: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 3144: $contentchg = 1;
3145: }
3146: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3147: return $errtext if ($fatal);
3148: }
1.538 raeburn 3149:
3150: # Cut, copy and/or remove multiple resources
3151: if ($env{'form.multichange'}) {
3152: my %allchecked = (
3153: cut => {},
3154: remove => {},
3155: );
3156: my $needsupdate;
3157: foreach my $which (keys(%allchecked)) {
3158: $env{'form.multi'.$which} =~ s/,$//;
3159: if ($env{'form.multi'.$which}) {
3160: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3161: if (ref($allchecked{$which}) eq 'HASH') {
3162: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3163: }
3164: }
3165: }
3166: if ($needsupdate) {
3167: my $haschanges = 0;
3168: my %curr_groups = &Apache::longroup::coursegroups();
3169: my $total = scalar(@LONCAPA::map::order) - 1;
3170: for (my $i=$total; $i>=0; $i--) {
3171: my $res = $LONCAPA::map::order[$i];
3172: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3173: $name=&LONCAPA::map::qtescape($name);
3174: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3175: next unless $url;
1.538 raeburn 3176: my %denied =
3177: &action_restrictions($coursenum,$coursedom,$url,
3178: $env{'form.folderpath'},\%curr_groups);
3179: foreach my $which (keys(%allchecked)) {
3180: next if ($denied{$which});
3181: next unless ($allchecked{$which}{$res});
3182: if ($which eq 'remove') {
3183: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3184: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3185: &Apache::lonnet::removeuploadedurl($url);
3186: } else {
3187: &LONCAPA::map::makezombie($res);
3188: }
3189: splice(@LONCAPA::map::order,$i,1);
3190: $haschanges ++;
3191: } elsif ($which eq 'cut') {
3192: &LONCAPA::map::makezombie($res);
3193: splice(@LONCAPA::map::order,$i,1);
3194: $haschanges ++;
3195: }
3196: }
3197: }
3198: if ($haschanges) {
3199: ($errtext,$fatal) =
3200: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3201: return $errtext if ($fatal);
3202: }
3203: }
3204: }
3205:
1.329 droeschl 3206: # Group import/search
3207: if ($env{'form.importdetail'}) {
3208: my @imports;
3209: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3210: if (defined($item)) {
3211: my ($name,$url,$residx)=
1.533 raeburn 3212: map { &unescape($_); } split(/\=/,$item);
3213: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3214: my ($suffix,$errortxt,$locknotfreed) =
3215: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3216: if ($locknotfreed) {
3217: $r->print($locknotfreed);
3218: }
3219: if ($suffix) {
3220: $url =~ s/_new\./_$suffix./;
3221: } else {
3222: return $errortxt;
3223: }
1.533 raeburn 3224: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3225: my $type = $1;
3226: my ($suffix,$errortxt,$locknotfreed) =
3227: &new_timebased_suffix($coursedom,$coursenum,$type);
3228: if ($locknotfreed) {
3229: $r->print($locknotfreed);
3230: }
3231: if ($suffix) {
3232: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3233: } else {
3234: return $errortxt;
3235: }
1.626 ! raeburn 3236: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3237: my ($suffix,$errortxt,$locknotfreed) =
3238: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3239: if ($locknotfreed) {
3240: $r->print($locknotfreed);
3241: }
3242: if ($suffix) {
3243: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3244: } else {
3245: return $errortxt;
3246: }
1.534 raeburn 3247: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3248: if ($supplementalflag) {
3249: next unless ($1 eq 'supplemental');
3250: if ($folder eq 'supplemental') {
3251: next unless ($2 eq 'default');
3252: } else {
3253: next unless ($folder eq 'supplemental_'.$2);
3254: }
3255: } else {
3256: next unless ($1 eq 'docs');
3257: if ($folder eq 'default') {
3258: next unless ($2 eq 'default');
3259: } else {
3260: next unless ($folder eq 'default_'.$2);
3261: }
3262: }
1.504 raeburn 3263: }
1.329 droeschl 3264: push(@imports, [$name, $url, $residx]);
3265: }
3266: }
1.530 raeburn 3267: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3268: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3269: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3270: return $errtext if ($fatal);
1.529 raeburn 3271: if ($fixuperrors) {
3272: $r->print($fixuperrors);
3273: }
1.329 droeschl 3274: }
3275: # Loading a complete map
3276: if ($env{'form.loadmap'}) {
3277: if ($env{'form.importmap'}=~/\w/) {
3278: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3279: my ($title,$url,$ext,$type)=split(/\:/,$res);
3280: my $idx=&LONCAPA::map::getresidx($url);
3281: $LONCAPA::map::resources[$idx]=$res;
3282: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3283: }
3284: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3285: $folder.'.'.$container,1);
1.329 droeschl 3286: return $errtext if ($fatal);
3287: } else {
3288: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3289:
1.329 droeschl 3290: }
3291: }
3292: &log_differences($plain);
3293: }
3294: # ---------------------------------------------------------------- End commands
3295: # ---------------------------------------------------------------- Print screen
3296: my $idx=0;
3297: my $shown=0;
3298: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3299: $r->print('<div class="LC_Box">'.
1.432 raeburn 3300: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3301: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3302: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3303: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3304: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3305: '</ol>');
1.381 bisitz 3306: if ($randompick>=0) {
3307: $r->print('<p class="LC_warning">'
3308: .&mt('Caution: this folder is set to randomly pick a subset'
3309: .' of resources. Adding or removing resources from this'
3310: .' folder will change the set of resources that the'
3311: .' students see, resulting in spurious or missing credit'
3312: .' for completed problems, not limited to ones you'
3313: .' modify. Do not modify the contents of this folder if'
3314: .' it is in active student use.')
3315: .'</p>'
3316: );
3317: }
3318: if ($is_random_order) {
3319: $r->print('<p class="LC_warning">'
3320: .&mt('Caution: this folder is set to randomly order its'
3321: .' contents. Adding or removing resources from this folder'
3322: .' will change the order of resources shown.')
3323: .'</p>'
3324: );
3325: }
3326: $r->print('</div>');
1.364 bisitz 3327: }
1.381 bisitz 3328:
1.538 raeburn 3329: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3330: %filters = (
1.543 raeburn 3331: canremove => [],
3332: cancut => [],
3333: cancopy => [],
3334: hiddenresource => [],
3335: encrypturl => [],
3336: randomorder => [],
3337: randompick => [],
1.538 raeburn 3338: );
3339: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3340: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3341: foreach my $res (@LONCAPA::map::order) {
3342: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3343: $name=&LONCAPA::map::qtescape($name);
3344: $url=&LONCAPA::map::qtescape($url);
3345: unless ($name) { $name=(split(/\//,$url))[-1]; }
3346: unless ($name) { $idx++; next; }
1.537 raeburn 3347: push(@allidx,$res);
3348: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3349: push(@allmapidx,$res);
3350: }
1.617 raeburn 3351:
1.381 bisitz 3352: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3353: $coursenum,$coursedom,$crstype,
1.538 raeburn 3354: $pathitem,$supplementalflag,$container,
1.620 raeburn 3355: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3356: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3357: $idx++;
3358: $shown++;
1.329 droeschl 3359: }
1.424 onken 3360: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3361:
1.538 raeburn 3362: my $need_save;
1.611 raeburn 3363: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3364: my $toolslink;
1.611 raeburn 3365: if ($allowed) {
1.544 raeburn 3366: $toolslink = '<table><tr><td>'
1.520 raeburn 3367: .&Apache::loncommon::help_open_menu('Navigation Screen',
3368: 'Navigation_Screen',undef,'RAT')
3369: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3370: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3371: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3372: .'id="LC_content_toolbar_edittoplevel" '
3373: .'class="LC_toolbarItem" '
3374: .'title="'.&mt('Supplemental Content Editor').'">'
3375: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3376: }
1.510 raeburn 3377: if ($shown) {
3378: if ($allowed) {
3379: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3380: .&Apache::loncommon::start_data_table(undef,'contentlist')
3381: .&Apache::loncommon::start_data_table_header_row()
3382: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3383: .'<th colspan="2">'.&mt('Actions').'</th>'
3384: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3385: if ($folder !~ /^supplemental/) {
3386: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3387: }
1.537 raeburn 3388: $to_show .= &Apache::loncommon::end_data_table_header_row();
3389: if ($folder !~ /^supplemental/) {
1.538 raeburn 3390: $lists{'canhide'} = join(',',@allidx);
3391: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3392: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3393: 'randomorder','randompick');
3394: foreach my $item (@possfilters) {
1.538 raeburn 3395: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3396: if (@{$filters{$item}} > 0) {
3397: $lists{$item} = join(',',@{$filters{$item}});
3398: }
1.538 raeburn 3399: }
3400: }
1.537 raeburn 3401: if (@allidx > 0) {
3402: my $path;
3403: if ($env{'form.folderpath'}) {
3404: $path =
3405: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3406: }
1.538 raeburn 3407: if (@allidx > 1) {
3408: $to_show .=
3409: &Apache::loncommon::continue_data_table_row().
3410: '<td colspan="2"> </td>'.
3411: '<td>'.
1.611 raeburn 3412: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3413: '</td>'.
3414: '<td> </td>'.
3415: '<td> </td>'.
3416: '<td colspan="4">'.
1.611 raeburn 3417: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3418: '</td>'.
3419: &Apache::loncommon::end_data_table_row();
3420: $need_save = 1;
3421: }
1.537 raeburn 3422: }
3423: }
3424: $to_show .= $output.' '
1.510 raeburn 3425: .&Apache::loncommon::end_data_table()
3426: .'<br style="line-height:2px;" />'
3427: .&Apache::loncommon::end_scrollbox();
3428: } else {
1.520 raeburn 3429: $to_show .= $toolslink
1.510 raeburn 3430: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3431: .$output.' '
3432: .&Apache::loncommon::end_data_table();
1.393 raeburn 3433: }
1.510 raeburn 3434: } else {
1.520 raeburn 3435: if (!$allowed) {
3436: $to_show .= $toolslink;
3437: }
1.615 raeburn 3438: my $noresmsg;
3439: if ($allowed && $hiddentop && !$supplementalflag) {
3440: $noresmsg = &mt('Main Content Hidden');
3441: } else {
3442: $noresmsg = &mt('Currently empty');
3443: }
1.510 raeburn 3444: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3445: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3446: .$noresmsg
1.510 raeburn 3447: .'</div>'
3448: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3449: }
3450: } else {
1.510 raeburn 3451: if ($shown) {
3452: $to_show = '<div>'
3453: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3454: .$output
3455: .&Apache::loncommon::end_data_table()
3456: .'</div>';
3457: } else {
3458: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3459: .&mt('Currently empty')
1.510 raeburn 3460: .'</div>'
3461: }
1.458 raeburn 3462: }
3463: my $tid = 1;
3464: if ($supplementalflag) {
3465: $tid = 2;
1.329 droeschl 3466: }
3467: if ($allowed) {
1.484 raeburn 3468: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3469: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3470: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3471: if ($canedit) {
3472: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3473: }
1.460 raeburn 3474: } else {
3475: $r->print($to_show);
1.329 droeschl 3476: }
3477: return;
3478: }
3479:
1.538 raeburn 3480: sub multiple_check_form {
1.611 raeburn 3481: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3482: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3483: my $disabled;
3484: unless ($canedit) {
3485: $disabled = 'disabled="disabled"';
3486: }
1.538 raeburn 3487: my $output =
3488: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3489: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3490: '<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>'.
3491: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3492: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3493: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3494: if ($caller eq 'settings') {
3495: $output .=
3496: '<table><tr>'.
3497: '<td class="LC_docs_entry_parameter">'.
3498: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3499: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3500: '</label></span></td>'.
3501: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3502: '<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.538 raeburn 3503: '</span></td>'.
3504: '</tr>'."\n".
3505: '<tr>'.
3506: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3507: '<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.538 raeburn 3508: '</label></span>'.
3509: '</td></tr></table>'."\n";
3510: } else {
3511: $output .=
3512: '<table><tr>'.
3513: '<td class="LC_docs_entry_parameter">'.
3514: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3515: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3516: '</label></span></td>'.
3517: '<td class="LC_docs_entry_parameter">'.
3518: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3519: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3520: '</label></span></td>'."\n".
3521: '<td class="LC_docs_entry_parameter">'.
3522: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3523: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3524: '</label></span></td>'.
3525: '</tr></table>'."\n";
3526: }
3527: $output .=
3528: '</fieldset>'.
3529: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3530: if ($caller eq 'settings') {
3531: $output .=
1.543 raeburn 3532: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3533: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3534: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3535: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3536: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3537: } elsif ($caller eq 'actions') {
3538: $output .=
3539: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3540: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3541: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3542: }
3543: $output .=
3544: '</form>'.
3545: '</div>';
3546: return $output;
3547: }
3548:
1.329 droeschl 3549: sub process_file_upload {
1.552 raeburn 3550: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3551: # upload a file, if present
1.552 raeburn 3552: my $filesize = length($env{'form.uploaddoc'});
3553: if (!$filesize) {
3554: $$upload_output = '<div class="LC_error">'.
3555: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3556: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3557: $filesize).'<br />'.
3558: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3559: '</div>';
3560: return;
3561: }
3562: my $quotatype = 'unofficial';
3563: if ($crstype eq 'Community') {
1.601 raeburn 3564: $quotatype = 'community';
3565: } elsif ($crstype eq 'Placement') {
3566: $quotatype = 'placement';
1.580 raeburn 3567: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3568: $quotatype = 'official';
1.573 raeburn 3569: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3570: $quotatype = 'textbook';
1.552 raeburn 3571: }
3572: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3573: $filesize = int($filesize/1000); #expressed in kb
3574: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3575: $env{'form.uploaddoc.filename'},$filesize,
3576: 'upload',$quotatype);
1.552 raeburn 3577: return if ($$upload_output);
3578: }
1.440 raeburn 3579: my ($parseaction,$showupload,$nextphase,$mimetype);
3580: if ($env{'form.parserflag'}) {
1.329 droeschl 3581: $parseaction = 'parse';
3582: }
3583: my $folder=$env{'form.folder'};
3584: if ($folder eq '') {
3585: $folder='default';
3586: }
3587: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3588: my $errtext='';
3589: my $fatal=0;
3590: my $container='sequence';
1.519 raeburn 3591: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3592: $container='page';
3593: }
3594: ($errtext,$fatal)=
1.534 raeburn 3595: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3596: if ($#LONCAPA::map::order<1) {
3597: $LONCAPA::map::order[0]=1;
3598: $LONCAPA::map::resources[1]='';
3599: }
3600: my $destination = 'docs/';
3601: if ($folder =~ /^supplemental/) {
3602: $destination = 'supplemental/';
3603: }
3604: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3605: $destination .= 'default/';
3606: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3607: $destination .= $2.'/';
3608: }
1.534 raeburn 3609: if ($fatal) {
3610: $$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>';
3611: return;
3612: }
1.440 raeburn 3613: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3614: my $newidx=&LONCAPA::map::getresidx();
3615: $destination .= $newidx;
1.439 raeburn 3616: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3617: $parseaction,$allfiles,
1.440 raeburn 3618: $codebase,undef,undef,undef,undef,
3619: undef,undef,\$mimetype);
3620: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3621: my $stored = $1;
3622: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3623: $stored.'</span>').'</p>';
3624: } else {
3625: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3626:
1.457 raeburn 3627: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3628: return;
3629: }
1.329 droeschl 3630: my $ext='false';
3631: if ($url=~m{^http://}) { $ext='true'; }
3632: $url = &LONCAPA::map::qtunescape($url);
3633: my $comment=$env{'form.comment'};
3634: $comment = &LONCAPA::map::qtunescape($comment);
3635: if ($folder=~/^supplemental/) {
3636: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3637: $env{'user.domain'}.'___&&&___'.$comment;
3638: }
3639:
3640: $LONCAPA::map::resources[$newidx]=
3641: $comment.':'.$url.':'.$ext.':normal:res';
3642: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3643: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3644: $folder.'.'.$container,1);
1.329 droeschl 3645: if ($fatal) {
1.457 raeburn 3646: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3647: return;
1.329 droeschl 3648: } else {
1.440 raeburn 3649: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3650: $$upload_output = $showupload;
1.384 raeburn 3651: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3652: if ($total_embedded > 0) {
1.440 raeburn 3653: my $uploadphase = 'upload_embedded';
3654: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3655: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3656: my ($embedded,$num) =
3657: &Apache::loncommon::ask_for_embedded_content(
3658: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3659: if ($embedded) {
3660: if ($num) {
3661: $$upload_output .=
3662: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3663: $nextphase = $uploadphase;
3664: } else {
3665: $$upload_output .= $embedded;
3666: }
3667: } else {
3668: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3669: }
1.329 droeschl 3670: } else {
1.440 raeburn 3671: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3672: }
1.457 raeburn 3673: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3674: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3675: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3676: $nextphase = 'decompress_uploaded';
3677: my $position = scalar(@LONCAPA::map::order)-1;
3678: my $noextract = &return_to_editor();
3679: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3680: my %archiveitems = (
3681: folderpath => $env{'form.folderpath'},
3682: cmd => $nextphase,
3683: newidx => $newidx,
3684: position => $position,
3685: phase => $nextphase,
1.477 raeburn 3686: comment => $comment,
1.480 raeburn 3687: );
3688: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3689: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3690: $$upload_output = $showupload.
3691: &Apache::loncommon::decompress_form($mimetype,
3692: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3693: \%archiveitems,\@current);
1.329 droeschl 3694: }
3695: }
3696: }
1.440 raeburn 3697: return $nextphase;
1.329 droeschl 3698: }
3699:
1.480 raeburn 3700: sub get_dir_list {
3701: my ($url,$coursenum,$coursedom,$newidx) = @_;
3702: my ($destination,$dir_root) = &embedded_destination();
3703: my ($dirlistref,$listerror) =
3704: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3705: my @dir_lines;
3706: my $dirptr=16384;
3707: if (ref($dirlistref) eq 'ARRAY') {
3708: foreach my $dir_line (sort
3709: {
3710: my ($afile)=split('&',$a,2);
3711: my ($bfile)=split('&',$b,2);
3712: return (lc($afile) cmp lc($bfile));
3713: } (@{$dirlistref})) {
3714: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3715: $filename =~ s/\s+$//;
3716: next if ($filename =~ /^\.\.?$/);
3717: my $isdir = 0;
3718: if ($dirptr&$testdir) {
3719: $isdir = 1;
3720: }
3721: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3722: }
3723: }
3724: return @dir_lines;
3725: }
3726:
1.329 droeschl 3727: sub is_supplemental_title {
3728: my ($title) = @_;
3729: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3730: }
3731:
3732: # --------------------------------------------------------------- An entry line
3733:
3734: sub entryline {
1.501 raeburn 3735: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3736: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3737: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3738: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3739: if (&is_supplemental_title($title)) {
1.488 raeburn 3740: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3741: } else {
3742: $title=&HTML::Entities::encode($title,'"<>&\'');
3743: $renametitle=$title;
3744: $foldertitle=$title;
3745: }
3746:
1.611 raeburn 3747: my ($disabled,$readonly,$js_lt);
3748: unless ($canedit) {
3749: $disabled = 'disabled="disabled"';
3750: $readonly = 1;
3751: }
3752:
1.329 droeschl 3753: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3754:
1.329 droeschl 3755: $renametitle=~s/\\/\\\\/g;
3756: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3757: $renametitle=~s/"/%22/g;
1.581 raeburn 3758: $renametitle=~s/ /%20/g;
3759: $oldtitle = $renametitle;
1.576 raeburn 3760: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3761: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3762: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3763: # Edit commands
1.535 raeburn 3764: my ($esc_path, $path, $symb);
1.329 droeschl 3765: if ($env{'form.folderpath'}) {
3766: $esc_path=&escape($env{'form.folderpath'});
3767: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3768: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3769: }
1.505 raeburn 3770: my $isexternal;
1.510 raeburn 3771: if ($residx) {
1.501 raeburn 3772: my $currurl = $url;
3773: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3774: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3775: $isexternal = 1;
3776: }
1.510 raeburn 3777: if (!$supplementalflag) {
3778: my $path = 'uploaded/'.
3779: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3780: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3781: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3782: $residx,
3783: &Apache::lonnet::declutter($currurl));
3784: }
1.501 raeburn 3785: }
1.538 raeburn 3786: my ($renamelink,%lt,$ishash);
3787: if (ref($filtersref) eq 'HASH') {
3788: $ishash = 1;
3789: }
3790:
1.329 droeschl 3791: if ($allowed) {
1.538 raeburn 3792: $form_start = '
3793: <form action="/adm/coursedocs" method="post">
3794: ';
3795: $form_common=(<<END);
3796: <input type="hidden" name="folderpath" value="$path" />
3797: <input type="hidden" name="symb" value="$symb" />
3798: END
3799: $form_param=(<<END);
3800: <input type="hidden" name="setparms" value="$orderidx" />
3801: <input type="hidden" name="changeparms" value="0" />
3802: END
3803: $form_end = '</form>';
3804:
1.329 droeschl 3805: my $incindex=$index+1;
3806: my $selectbox='';
1.471 raeburn 3807: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3808: ((split(/\:/,
1.344 bisitz 3809: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3810: ne '') &&
1.329 droeschl 3811: ((split(/\:/,
1.344 bisitz 3812: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3813: ne '')) {
3814: $selectbox=
3815: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3816: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3817: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3818: if ($i==$incindex) {
1.358 bisitz 3819: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3820: } else {
3821: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3822: }
3823: }
3824: $selectbox.='</select>';
3825: }
1.501 raeburn 3826: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3827: 'up' => 'Move Up',
3828: 'dw' => 'Move Down',
3829: 'rm' => 'Remove',
3830: 'ct' => 'Cut',
3831: 'rn' => 'Rename',
1.501 raeburn 3832: 'cp' => 'Copy',
3833: 'ex' => 'External Resource',
1.598 raeburn 3834: 'et' => 'External Tool',
1.501 raeburn 3835: 'ed' => 'Edit',
3836: 'pr' => 'Preview',
3837: 'sv' => 'Save',
3838: 'ul' => 'URL',
1.611 raeburn 3839: 'ti' => 'Title',
1.618 raeburn 3840: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3841: );
1.538 raeburn 3842: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3843: $env{'form.folderpath'},
3844: $currgroups);
1.517 raeburn 3845: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3846: my $skip_confirm = 0;
1.603 raeburn 3847: my $confirm_removal = 0;
1.329 droeschl 3848: if ( $folder =~ /^supplemental/
3849: || ($url =~ m{( /smppg$
3850: |/syllabus$
3851: |/aboutme$
3852: |/navmaps$
3853: |/bulletinboard$
1.626 ! raeburn 3854: |/ext\.tool$
1.505 raeburn 3855: |\.html$)}x)
3856: || $isexternal) {
1.329 droeschl 3857: $skip_confirm = 1;
3858: }
1.603 raeburn 3859: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3860: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3861: $confirm_removal = 1;
3862: }
1.329 droeschl 3863:
1.538 raeburn 3864: if ($denied{'copy'}) {
1.543 raeburn 3865: $copylink=(<<ENDCOPY)
1.507 raeburn 3866: <span style="visibility: hidden;">$lt{'cp'}</span>
3867: ENDCOPY
3868: } else {
1.538 raeburn 3869: my $formname = 'edit_copy_'.$orderidx;
3870: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3871: $copylink=(<<ENDCOPY);
1.538 raeburn 3872: <form name="$formname" method="post" action="/adm/coursedocs">
3873: $form_common
1.611 raeburn 3874: <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.538 raeburn 3875: $form_end
1.329 droeschl 3876: ENDCOPY
1.538 raeburn 3877: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3878: push(@{$filtersref->{'cancopy'}},$orderidx);
3879: }
1.329 droeschl 3880: }
1.538 raeburn 3881: if ($denied{'cut'}) {
1.507 raeburn 3882: $cutlink=(<<ENDCUT);
3883: <span style="visibility: hidden;">$lt{'ct'}</span>
3884: ENDCUT
3885: } else {
1.538 raeburn 3886: my $formname = 'edit_cut_'.$orderidx;
3887: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3888: $cutlink=(<<ENDCUT);
1.538 raeburn 3889: <form name="$formname" method="post" action="/adm/coursedocs">
3890: $form_common
1.542 raeburn 3891: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3892: <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.538 raeburn 3893: $form_end
1.329 droeschl 3894: ENDCUT
1.538 raeburn 3895: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3896: push(@{$filtersref->{'cancut'}},$orderidx);
3897: }
1.329 droeschl 3898: }
1.538 raeburn 3899: if ($denied{'remove'}) {
1.507 raeburn 3900: $removelink=(<<ENDREM);
3901: <span style="visibility: hidden;">$lt{'rm'}</a>
3902: ENDREM
3903: } else {
1.538 raeburn 3904: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3905: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3906: $removelink=(<<ENDREM);
1.538 raeburn 3907: <form name="$formname" method="post" action="/adm/coursedocs">
3908: $form_common
1.542 raeburn 3909: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3910: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 3911: <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.538 raeburn 3912: $form_end
1.497 raeburn 3913: ENDREM
1.538 raeburn 3914: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3915: push(@{$filtersref->{'canremove'}},$orderidx);
3916: }
1.497 raeburn 3917: }
1.551 raeburn 3918: $renamelink=(<<ENDREN);
1.581 raeburn 3919: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3920: ENDREN
1.611 raeburn 3921: my ($uplink,$downlink);
3922: if ($canedit) {
3923: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3924: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3925: } else {
3926: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3927: $downlink = $uplink;
3928: }
1.329 droeschl 3929: $line.=(<<END);
3930: <td>
1.379 bisitz 3931: <div class="LC_docs_entry_move">
1.611 raeburn 3932: <a href="$uplink">
1.501 raeburn 3933: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3934: </a>
3935: </div>
3936: <div class="LC_docs_entry_move">
1.611 raeburn 3937: <a href="$downlink">
1.501 raeburn 3938: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3939: </a>
3940: </div>
1.329 droeschl 3941: </td>
3942: <td>
3943: $form_start
1.538 raeburn 3944: $form_param
1.478 raeburn 3945: $form_common
1.329 droeschl 3946: $selectbox
3947: $form_end
3948: </td>
1.540 raeburn 3949: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3950: $removelink
1.329 droeschl 3951: $cutlink
3952: $copylink
3953: </td>
3954: END
3955: }
3956: # Figure out what kind of a resource this is
3957: my ($extension)=($url=~/\.(\w+)$/);
3958: my $uploaded=($url=~/^\/*uploaded\//);
3959: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3960: my $isfolder;
3961: my $ispage;
3962: my $containerarg;
1.615 raeburn 3963: my $folderurl;
1.329 droeschl 3964: if ($uploaded) {
1.472 raeburn 3965: if (($extension eq 'sequence') || ($extension eq 'page')) {
3966: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3967: $containerarg = $1;
1.472 raeburn 3968: if ($extension eq 'sequence') {
3969: $icon=$iconpath.'navmap.folder.closed.gif';
3970: $isfolder=1;
3971: } else {
3972: $icon=$iconpath.'page.gif';
3973: $ispage=1;
3974: }
1.615 raeburn 3975: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3976: if ($allowed) {
3977: $url='/adm/coursedocs?';
3978: } else {
3979: $url='/adm/supplemental?';
3980: }
1.329 droeschl 3981: } else {
3982: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3983: }
3984: }
1.364 bisitz 3985:
1.621 raeburn 3986: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3987: my $orig_url = $url;
1.340 raeburn 3988: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 3989: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 3990: if (!$supplementalflag && $residx && $symb) {
3991: if ((!$isfolder) && (!$ispage)) {
3992: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3993: $url=&Apache::lonnet::clutter($url);
3994: if ($url=~/^\/*uploaded\//) {
3995: $url=~/\.(\w+)$/;
3996: my $embstyle=&Apache::loncommon::fileembstyle($1);
3997: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3998: $url='/adm/wrapper'.$url;
3999: } elsif ($embstyle eq 'ssi') {
4000: #do nothing with these
4001: } elsif ($url!~/\.(sequence|page)$/) {
4002: $url='/adm/coursedocs/showdoc'.$url;
4003: }
1.623 raeburn 4004: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4005: my $wrapped = $1;
4006: my $exturl = $2;
4007: if ($wrapped eq '') {
4008: $url='/adm/wrapper'.$url;
4009: }
4010: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4011: $nomodal = 1;
4012: }
1.626 ! raeburn 4013: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4014: $url='/adm/wrapper'.$url;
1.621 raeburn 4015: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4016: if (($ENV{'SERVER_PORT'} == 443) &&
4017: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4018: $url .= '?usehttp=1';
4019: $nomodal = 1;
4020: }
1.598 raeburn 4021: }
1.501 raeburn 4022: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4023: my $shownsymb = $symb;
4024: if ($isexternal) {
4025: if ($url =~ /^([^#]+)#([^#]+)$/) {
4026: $url = $1;
4027: $anchor = $2;
4028: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4029: $shownsymb = $1.&escape('#').$anchor;
4030: }
4031: }
4032: }
1.617 raeburn 4033: unless ($env{'request.role.adv'}) {
4034: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4035: $url = '';
4036: }
4037: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4038: $url = '';
4039: $hiddenres = 1;
4040: }
4041: }
4042: if ($url ne '') {
4043: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4044: }
1.615 raeburn 4045: } elsif (!$env{'request.role.adv'}) {
4046: my $checkencrypt;
4047: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4048: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4049: $checkencrypt = 1;
1.620 raeburn 4050: } elsif (ref($navmapref)) {
1.615 raeburn 4051: unless (ref($$navmapref)) {
4052: $$navmapref = Apache::lonnavmaps::navmap->new();
4053: }
4054: if (ref($$navmapref)) {
4055: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4056: $checkencrypt = 1;
4057: }
4058: }
4059: }
4060: if ($checkencrypt) {
4061: my $shownsymb = &Apache::lonenc::encrypted($symb);
4062: my $shownurl = &Apache::lonenc::encrypted($url);
4063: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4064: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4065: if ($env{'request.enc'} ne '') {
4066: delete($env{'request.enc'});
4067: }
4068: } else {
4069: $url='';
1.613 raeburn 4070: }
1.612 raeburn 4071: } else {
4072: $url='';
4073: }
1.501 raeburn 4074: } else {
4075: $url='';
4076: }
1.329 droeschl 4077: }
1.621 raeburn 4078: } elsif ($supplementalflag) {
1.610 raeburn 4079: if ($isexternal) {
4080: if ($url =~ /^([^#]+)#([^#]+)$/) {
4081: $url = $1;
4082: $anchor = $2;
1.623 raeburn 4083: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4084: if ($hostname ne '') {
4085: $url = 'http://'.$hostname.$url;
4086: }
4087: $nomodal = 1;
4088: }
1.610 raeburn 4089: }
1.621 raeburn 4090: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4091: if (($ENV{'SERVER_PORT'} == 443) &&
4092: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.622 raeburn 4093: if ($hostname ne '') {
4094: $url = 'http://'.$hostname.$url;
4095: }
1.621 raeburn 4096: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4097: $nomodal = 1;
4098: }
1.610 raeburn 4099: }
1.329 droeschl 4100: }
1.615 raeburn 4101: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4102: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4103: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4104: my $foldername=&escape($foldertitle);
4105: my $folderpath=$env{'form.folderpath'};
4106: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4107: if (!$allowed && $supplementalflag) {
1.519 raeburn 4108: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4109: $url.='folderpath='.&escape($folderpath);
4110: } else {
1.617 raeburn 4111: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4112: 'parameter_randompick'))[0];
4113: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4114: 'parameter_randomorder'))[0]=~/^yes$/i);
4115: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4116: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4117: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4118: 'parameter_encrypturl'))[0]=~/^yes$/i);
4119: unless ($hiddenmap) {
1.620 raeburn 4120: if (ref($navmapref)) {
4121: unless (ref($$navmapref)) {
4122: $$navmapref = Apache::lonnavmaps::navmap->new();
4123: }
4124: if (ref($$navmapref)) {
4125: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4126: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4127: unless (@resources) {
4128: $hiddenmap = 1;
4129: unless ($env{'request.role.adv'}) {
4130: $url = '';
4131: $hiddenfolder = 1;
4132: }
1.617 raeburn 4133: }
1.615 raeburn 4134: }
4135: }
4136: }
4137: }
1.617 raeburn 4138: unless ($encryptmap) {
1.620 raeburn 4139: if ((ref($navmapref)) && (ref($$navmapref))) {
4140: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4141: $encryptmap = 1;
4142: }
1.617 raeburn 4143: }
4144: }
4145:
4146: # Append randompick number, hidden, and encrypted with ":" to foldername,
4147: # so it gets transferred between levels
4148: $folderpath.=$containerarg.'&'.$foldername.
4149: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4150: unless ($url eq '') {
1.612 raeburn 4151: $url.='folderpath='.&escape($folderpath);
4152: }
1.510 raeburn 4153: my $rpckchk;
4154: if ($rpicknum) {
4155: $rpckchk = ' checked="checked"';
1.543 raeburn 4156: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4157: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4158: }
1.510 raeburn 4159: }
1.537 raeburn 4160: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4161: $rand_pick_text =
1.478 raeburn 4162: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4163: $form_param."\n".
1.478 raeburn 4164: $form_common."\n".
1.611 raeburn 4165: '<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.510 raeburn 4166: if ($rpicknum ne '') {
4167: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4168: }
1.537 raeburn 4169: $rand_pick_text .= '</span></span>'.
4170: $form_end;
1.543 raeburn 4171: my $ro_set;
1.617 raeburn 4172: if ($randorder) {
1.543 raeburn 4173: $ro_set = 'checked="checked"';
4174: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4175: push(@{$filtersref->{'randomorder'}},$orderidx);
4176: }
4177: }
1.564 raeburn 4178: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4179: $rand_order_text =
1.537 raeburn 4180: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4181: $form_param."\n".
1.537 raeburn 4182: $form_common."\n".
1.611 raeburn 4183: '<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.537 raeburn 4184: $form_end;
1.510 raeburn 4185: }
1.509 raeburn 4186: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4187: my $isexttool;
1.626 ! raeburn 4188: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4189: $url='/adm/wrapper'.$url;
4190: $isexttool = 1;
4191: }
1.510 raeburn 4192: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4193: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4194: if ($title) {
4195: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4196: }
1.598 raeburn 4197: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4198: $url .= '&idx='.$orderidx;
4199: }
1.610 raeburn 4200: if ($anchor ne '') {
4201: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4202: }
1.329 droeschl 4203: }
1.519 raeburn 4204: my ($tdalign,$tdwidth);
1.501 raeburn 4205: if ($allowed) {
4206: my $fileloc =
4207: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4208: if ($isexternal) {
1.518 raeburn 4209: ($editlink,$extresform) =
1.611 raeburn 4210: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4211: undef,undef,undef,undef,undef,undef,
4212: undef,$disabled);
1.626 ! raeburn 4213: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4214: ($editlink,$extresform) =
4215: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4216: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4217: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4218: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4219: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4220: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4221: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4222: my $suppanchor;
4223: if ($supplementalflag) {
4224: $suppanchor = $anchor;
4225: }
1.501 raeburn 4226: my $jscall =
4227: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4228: $switchserver,
1.503 raeburn 4229: $forceedit,
1.511 raeburn 4230: undef,$symb,
4231: &escape($env{'form.folderpath'}),
1.622 raeburn 4232: $renametitle,$hostname,
4233: '','',1,$suppanchor);
1.501 raeburn 4234: if ($jscall) {
1.518 raeburn 4235: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4236: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4237: }
4238: }
4239: }
1.519 raeburn 4240: $tdalign = ' align="right" valign="top"';
4241: $tdwidth = ' width="80%"';
1.329 droeschl 4242: }
1.408 raeburn 4243: my $reinit;
4244: if ($crstype eq 'Community') {
4245: $reinit = &mt('(re-initialize community to access)');
4246: } else {
4247: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4248: }
4249: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.621 raeburn 4250: my $link;
1.472 raeburn 4251: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4252: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4253: } elsif ($url) {
1.610 raeburn 4254: if ($anchor ne '') {
4255: if ($supplementalflag) {
4256: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4257: } else {
4258: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4259: }
4260: }
1.622 raeburn 4261: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4262: $link = 'http://'.$hostname.$url;
4263: } else {
4264: $link = $url;
4265: }
4266: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.621 raeburn 4267: (($anchor ne '')?$anchor:''));
4268: if ($nomodal) {
4269: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4270: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4271: } else {
4272: $line.=&Apache::loncommon::modal_link($link,
4273: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4274: }
1.469 www 4275: } else {
4276: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4277: }
1.519 raeburn 4278: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4279: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4280: $line.='<a href="'.$url.'">'.$title.'</a>';
4281: } elsif ($url) {
1.621 raeburn 4282: if ($nomodal) {
4283: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4284: $title.'</a>';
4285: } else {
4286: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4287: }
1.617 raeburn 4288: } elsif (($hiddenfolder) || ($hiddenres)) {
1.615 raeburn 4289: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
1.469 www 4290: } else {
4291: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4292: }
1.518 raeburn 4293: $line.="$extresform</td>";
1.478 raeburn 4294: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4295: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4296: if (($allowed) && ($folder!~/^supplemental/)) {
4297: my %lt=&Apache::lonlocal::texthash(
4298: 'hd' => 'Hidden',
4299: 'ec' => 'URL hidden');
1.543 raeburn 4300: my ($enctext,$hidtext);
4301: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4302: $enctext = ' checked="checked"';
4303: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4304: push(@{$filtersref->{'encrypturl'}},$orderidx);
4305: }
4306: }
4307: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4308: $hidtext = ' checked="checked"';
4309: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4310: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4311: }
4312: }
1.537 raeburn 4313: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4314: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4315: $line.=(<<ENDPARMS);
4316: <td class="LC_docs_entry_parameter">
1.537 raeburn 4317: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4318: $form_param
1.478 raeburn 4319: $form_common
1.611 raeburn 4320: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4321: $form_end
1.458 raeburn 4322: <br />
1.537 raeburn 4323: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4324: $form_param
1.478 raeburn 4325: $form_common
1.611 raeburn 4326: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4327: $form_end
4328: </td>
1.478 raeburn 4329: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4330: $rand_order_text</td>
1.329 droeschl 4331: ENDPARMS
4332: }
1.379 bisitz 4333: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4334: return $line;
4335: }
4336:
1.538 raeburn 4337: sub action_restrictions {
4338: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4339: my %denied = (
4340: cut => 0,
4341: copy => 0,
4342: remove => 0,
4343: );
4344: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4345: # no copy for published maps
4346: $denied{'copy'} = 1;
1.597 raeburn 4347: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4348: unless ($1 eq 'simpleproblem') {
4349: $denied{'copy'} = 1;
4350: }
4351: $denied{'cut'} = 1;
1.538 raeburn 4352: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4353: if ($folderpath =~ /^default&[^\&]+$/) {
4354: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4355: $denied{'remove'} = 1;
4356: }
4357: $denied{'cut'} = 1;
4358: $denied{'copy'} = 1;
4359: }
4360: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4361: my $group = $1;
4362: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4363: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4364: $denied{'remove'} = 1;
4365: }
4366: }
4367: $denied{'cut'} = 1;
4368: $denied{'copy'} = 1;
4369: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4370: my $group = $1;
4371: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4372: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4373: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4374: if (keys(%groupsettings) > 0) {
4375: $denied{'remove'} = 1;
4376: }
4377: $denied{'cut'} = 1;
4378: $denied{'copy'} = 1;
4379: }
4380: }
4381: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4382: my $group = $1;
4383: if ($url =~ /group_boards_\Q$group\E/) {
4384: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4385: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4386: if (keys(%groupsettings) > 0) {
4387: if (ref($groupsettings{'functions'}) eq 'HASH') {
4388: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4389: $denied{'remove'} = 1;
4390: }
4391: }
4392: }
4393: $denied{'cut'} = 1;
4394: $denied{'copy'} = 1;
4395: }
4396: }
4397: }
4398: return %denied;
4399: }
4400:
1.533 raeburn 4401: sub new_timebased_suffix {
1.538 raeburn 4402: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4403: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4404: if ($type eq 'paste') {
4405: $prefix = $type;
4406: $namespace = 'courseeditor';
1.587 raeburn 4407: $idtype = 'addcode';
1.538 raeburn 4408: } elsif ($type eq 'map') {
1.533 raeburn 4409: $prefix = 'docs';
4410: if ($area eq 'supplemental') {
4411: $prefix = 'supp';
4412: }
4413: $prefix .= $container;
4414: $namespace = 'uploadedmaps';
4415: } else {
4416: $prefix = $type;
4417: $namespace = 'templated';
1.504 raeburn 4418: }
4419: my ($suffix,$freedlock,$error) =
1.587 raeburn 4420: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4421: if (!$suffix) {
1.538 raeburn 4422: if ($type eq 'paste') {
4423: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4424: } elsif ($type eq 'map') {
1.533 raeburn 4425: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4426: } elsif ($type eq 'smppg') {
4427: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 ! raeburn 4428: } elsif ($type eq 'exttool') {
! 4429: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4430: } else {
1.565 bisitz 4431: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4432: }
1.504 raeburn 4433: if ($error) {
4434: $errtext .= '<br />'.$error;
4435: }
4436: }
4437: if ($freedlock ne 'ok') {
1.533 raeburn 4438: $locknotfreed =
4439: '<div class="LC_error">'.
4440: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4441: if ($type eq 'paste') {
1.591 raeburn 4442: if ($freedlock eq 'nolock') {
4443: $locknotfreed =
4444: '<div class="LC_error">'.
4445: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4446:
1.593 droeschl 4447: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4448: } else {
4449: $locknotfreed .=
4450: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4451: }
1.538 raeburn 4452: } elsif ($type eq 'map') {
1.591 raeburn 4453: $locknotfreed .=
4454: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4455: } elsif ($type eq 'smppg') {
4456: $locknotfreed .=
4457: &mt('This will prevent creation of additional simple pages in this course.');
1.626 ! raeburn 4458: } elsif ($type eq 'exttool') {
! 4459: $locknotfreed .=
! 4460: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4461: } else {
4462: $locknotfreed .=
1.565 bisitz 4463: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4464: }
1.538 raeburn 4465: unless ($type eq 'paste') {
4466: $locknotfreed .=
1.560 raeburn 4467: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4468: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4469: }
4470: $locknotfreed .= '</div>';
1.504 raeburn 4471: }
4472: return ($suffix,$errtext,$locknotfreed);
4473: }
4474:
1.329 droeschl 4475: =pod
4476:
4477: =item tiehash()
4478:
4479: tie the hash
4480:
4481: =cut
4482:
4483: sub tiehash {
4484: my ($mode)=@_;
4485: $hashtied=0;
4486: if ($env{'request.course.fn'}) {
4487: if ($mode eq 'write') {
4488: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4489: &GDBM_WRCREAT(),0640)) {
4490: $hashtied=2;
4491: }
4492: } else {
4493: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4494: &GDBM_READER(),0640)) {
4495: $hashtied=1;
4496: }
4497: }
1.364 bisitz 4498: }
1.329 droeschl 4499: }
4500:
4501: sub untiehash {
4502: if ($hashtied) { untie %hash; }
4503: $hashtied=0;
4504: return OK;
4505: }
4506:
4507:
4508:
4509:
4510: sub checkonthis {
4511: my ($r,$url,$level,$title)=@_;
4512: $url=&unescape($url);
4513: $alreadyseen{$url}=1;
4514: $r->rflush();
4515: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4516: $r->print("\n<br />");
4517: if ($level==0) {
4518: $r->print("<br />");
4519: }
4520: for (my $i=0;$i<=$level*5;$i++) {
4521: $r->print(' ');
4522: }
4523: $r->print('<a href="'.$url.'" target="cat">'.
4524: ($title?$title:$url).'</a> ');
4525: if ($url=~/^\/res\//) {
4526: my $result=&Apache::lonnet::repcopy(
4527: &Apache::lonnet::filelocation('',$url));
4528: if ($result eq 'ok') {
4529: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4530: $r->rflush();
4531: &Apache::lonnet::countacc($url);
4532: $url=~/\.(\w+)$/;
4533: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4534: $r->print('<br />');
4535: $r->rflush();
4536: for (my $i=0;$i<=$level*5;$i++) {
4537: $r->print(' ');
4538: }
4539: $r->print('- '.&mt('Rendering:').' ');
4540: my ($errorcount,$warningcount)=split(/:/,
4541: &Apache::lonnet::ssi_body($url,
4542: ('grade_target'=>'web',
4543: 'return_only_error_and_warning_counts' => 1)));
4544: if (($errorcount) ||
4545: ($warningcount)) {
4546: if ($errorcount) {
1.369 bisitz 4547: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4548: &mt('[quant,_1,error]',$errorcount).'</span>');
4549: }
4550: if ($warningcount) {
4551: $r->print('<span class="LC_warning">'.
4552: &mt('[quant,_1,warning]',$warningcount).'</span>');
4553: }
4554: } else {
4555: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4556: }
4557: $r->rflush();
4558: }
4559: my $dependencies=
4560: &Apache::lonnet::metadata($url,'dependencies');
4561: foreach my $dep (split(/\,/,$dependencies)) {
4562: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4563: &checkonthis($r,$dep,$level+1);
4564: }
4565: }
4566: } elsif ($result eq 'unavailable') {
4567: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4568: } elsif ($result eq 'not_found') {
4569: unless ($url=~/\$/) {
1.521 bisitz 4570: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4571: } else {
1.366 bisitz 4572: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4573: }
4574: } else {
4575: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4576: }
4577: }
4578: }
4579: }
4580:
4581:
4582:
4583: =pod
4584:
4585: =item list_symbs()
4586:
1.485 raeburn 4587: List Content Identifiers
1.329 droeschl 4588:
4589: =cut
4590:
4591: sub list_symbs {
4592: my ($r) = @_;
4593:
1.408 raeburn 4594: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4595: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4596: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4597: $r->print(&startContentScreen('tools'));
1.329 droeschl 4598: my $navmap = Apache::lonnavmaps::navmap->new();
4599: if (!defined($navmap)) {
4600: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4601: '<div class="LC_error">'.
4602: &mt('Unable to retrieve information about course contents').
4603: '</div>');
1.408 raeburn 4604: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4605: } else {
1.484 raeburn 4606: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4607: &Apache::loncommon::start_data_table().
4608: &Apache::loncommon::start_data_table_header_row().
4609: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4610: &Apache::loncommon::end_data_table_header_row()."\n");
4611: my $count;
1.329 droeschl 4612: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4613: $r->print(&Apache::loncommon::start_data_table_row().
4614: '<td>'.$res->compTitle().'</td>'.
4615: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4616: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4617: $count ++;
4618: }
4619: if (!$count) {
4620: $r->print(&Apache::loncommon::start_data_table_row().
4621: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4622: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4623: }
1.484 raeburn 4624: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4625: }
1.521 bisitz 4626: $r->print(&endContentScreen());
1.329 droeschl 4627: }
4628:
4629:
4630: sub verifycontent {
4631: my ($r) = @_;
1.408 raeburn 4632: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4633: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4634: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4635: $r->print(&startContentScreen('tools'));
4636: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4637: $hashtied=0;
4638: undef %alreadyseen;
4639: %alreadyseen=();
4640: &tiehash();
1.484 raeburn 4641:
1.329 droeschl 4642: foreach my $key (keys(%hash)) {
4643: if ($hash{$key}=~/\.(page|sequence)$/) {
4644: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4645: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4646: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4647: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4648: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4649: }
4650: }
4651: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4652: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4653: }
4654: }
4655: &untiehash();
1.442 www 4656: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4657: $r->print(&endContentScreen());
1.329 droeschl 4658: }
4659:
4660:
4661: sub devalidateversioncache {
4662: my $src=shift;
4663: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4664: &Apache::lonnet::clutter($src));
4665: }
4666:
4667: sub checkversions {
1.611 raeburn 4668: my ($r,$canedit) = @_;
1.408 raeburn 4669: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4670: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4671: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4672: $r->print(&startContentScreen('tools'));
1.442 www 4673:
1.329 droeschl 4674: my $header='';
4675: my $startsel='';
4676: my $monthsel='';
4677: my $weeksel='';
4678: my $daysel='';
4679: my $allsel='';
4680: my %changes=();
4681: my $starttime=0;
4682: my $haschanged=0;
4683: my %setversions=&Apache::lonnet::dump('resourceversions',
4684: $env{'course.'.$env{'request.course.id'}.'.domain'},
4685: $env{'course.'.$env{'request.course.id'}.'.num'});
4686:
4687: $hashtied=0;
4688: &tiehash();
1.611 raeburn 4689: if ($canedit) {
4690: my %newsetversions=();
4691: if ($env{'form.setmostrecent'}) {
4692: $haschanged=1;
4693: foreach my $key (keys(%hash)) {
4694: if ($key=~/^ids\_(\/res\/.+)$/) {
4695: $newsetversions{$1}='mostrecent';
4696: &devalidateversioncache($1);
4697: }
4698: }
4699: } elsif ($env{'form.setcurrent'}) {
4700: $haschanged=1;
4701: foreach my $key (keys(%hash)) {
4702: if ($key=~/^ids\_(\/res\/.+)$/) {
4703: my $getvers=&Apache::lonnet::getversion($1);
4704: if ($getvers>0) {
4705: $newsetversions{$1}=$getvers;
4706: &devalidateversioncache($1);
4707: }
4708: }
1.329 droeschl 4709: }
1.611 raeburn 4710: } elsif ($env{'form.setversions'}) {
4711: $haschanged=1;
4712: foreach my $key (keys(%env)) {
4713: if ($key=~/^form\.set_version_(.+)$/) {
4714: my $src=$1;
4715: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4716: $newsetversions{$src}=$env{$key};
4717: &devalidateversioncache($src);
4718: }
4719: }
1.329 droeschl 4720: }
1.611 raeburn 4721: }
4722: if ($haschanged) {
4723: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4724: $env{'course.'.$env{'request.course.id'}.'.domain'},
4725: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4726: $r->print(&Apache::loncommon::confirmwrapper(
4727: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4728: } else {
4729: $r->print(&Apache::loncommon::confirmwrapper(
4730: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4731: }
1.611 raeburn 4732: &mark_hash_old();
4733: }
4734: &changewarning($r,'');
1.329 droeschl 4735: }
4736: if ($env{'form.timerange'} eq 'all') {
4737: # show all documents
1.549 raeburn 4738: $header=&mt('All content in '.$crstype);
1.521 bisitz 4739: $allsel=' selected="selected"';
1.329 droeschl 4740: foreach my $key (keys(%hash)) {
4741: if ($key=~/^ids\_(\/res\/.+)$/) {
4742: my $src=$1;
4743: $changes{$src}=1;
4744: }
4745: }
4746: } else {
4747: # show documents which changed
4748: %changes=&Apache::lonnet::dump
4749: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4750: $env{'course.'.$env{'request.course.id'}.'.num'});
4751: my $firstkey=(keys(%changes))[0];
4752: unless ($firstkey=~/^error\:/) {
4753: unless ($env{'form.timerange'}) {
4754: $env{'form.timerange'}=604800;
4755: }
4756: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4757: .&mt('seconds');
4758: if ($env{'form.timerange'}==-1) {
4759: $seltext='since start of course';
1.521 bisitz 4760: $startsel=' selected="selected"';
1.329 droeschl 4761: $env{'form.timerange'}=time;
4762: }
4763: $starttime=time-$env{'form.timerange'};
4764: if ($env{'form.timerange'}==2592000) {
4765: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4766: $monthsel=' selected="selected"';
1.329 droeschl 4767: } elsif ($env{'form.timerange'}==604800) {
4768: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4769: $weeksel=' selected="selected"';
1.329 droeschl 4770: } elsif ($env{'form.timerange'}==86400) {
4771: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4772: $daysel=' selected="selected"';
1.329 droeschl 4773: }
4774: $header=&mt('Content changed').' '.$seltext;
4775: } else {
4776: $header=&mt('No content modifications yet.');
4777: }
4778: }
4779: %setversions=&Apache::lonnet::dump('resourceversions',
4780: $env{'course.'.$env{'request.course.id'}.'.domain'},
4781: $env{'course.'.$env{'request.course.id'}.'.num'});
4782: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4783: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4784: 'lm' => 'Version changes since last Month',
4785: 'lw' => 'Version changes since last Week',
4786: 'sy' => 'Version changes since Yesterday',
4787: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4788: 'cd' => 'Change display',
1.329 droeschl 4789: 'sd' => 'Display',
4790: 'fi' => 'File',
4791: 'md' => 'Modification Date',
4792: 'mr' => 'Most recently published Version',
1.408 raeburn 4793: 've' => 'Version used in '.$crstype,
4794: 'vu' => 'Set Version to be used in '.$crstype,
4795: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4796: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4797: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4798: 'di' => 'Differences',
1.484 raeburn 4799: 'save' => 'Save changes',
4800: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4801: 'act' => 'Actions');
1.611 raeburn 4802: my ($disabled,$readonly);
4803: unless ($canedit) {
4804: $disabled = 'disabled="disabled"';
4805: $readonly = 1;
4806: }
1.329 droeschl 4807: $r->print(<<ENDHEADERS);
1.484 raeburn 4808: <h4 class="LC_info">$header</h4>
1.329 droeschl 4809: <form action="/adm/coursedocs" method="post">
4810: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4811: <div class="LC_left_float">
1.479 golterma 4812: <fieldset>
1.484 raeburn 4813: <legend>$lt{'cd'}</legend>
1.329 droeschl 4814: <select name="timerange">
1.521 bisitz 4815: <option value='all'$allsel>$lt{'al'}</option>
4816: <option value="-1"$startsel>$lt{'st'}</option>
4817: <option value="2592000"$monthsel>$lt{'lm'}</option>
4818: <option value="604800"$weeksel>$lt{'lw'}</option>
4819: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4820: </select>
4821: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4822: </fieldset>
4823: </div>
4824: <div class="LC_left_float">
4825: <fieldset>
4826: <legend>$lt{'act'}</legend>
1.611 raeburn 4827: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4828: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4829: </fieldset>
4830: </div>
4831: <br clear="all" />
4832: <hr />
4833: <h4>$lt{'vers'}</h4>
1.329 droeschl 4834: ENDHEADERS
1.479 golterma 4835: #number of columns for version history
1.571 raeburn 4836: my %changedbytime;
4837: foreach my $key (keys(%changes)) {
4838: #excludes not versionable problems from resource version history:
4839: next if ($key =~ /^\/res\/lib\/templates/);
4840: my $chg;
4841: if ($env{'form.timerange'} eq 'all') {
4842: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4843: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4844: } else {
4845: $chg = $changes{$key};
4846: next if ($chg < $starttime);
4847: }
4848: push(@{$changedbytime{$chg}},$key);
4849: }
4850: if (keys(%changedbytime) == 0) {
4851: &untiehash();
4852: $r->print(&mt('No content changes in imported content in specified time frame').
4853: &endContentScreen());
4854: return;
4855: }
1.479 golterma 4856: $r->print(
1.611 raeburn 4857: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4858: &Apache::loncommon::start_data_table().
4859: &Apache::loncommon::start_data_table_header_row().
4860: '<th>'.&mt('Resources').'</th>'.
4861: "<th>$lt{'mr'}</th>".
4862: "<th>$lt{'ve'}</th>".
4863: "<th>$lt{'vu'}</th>".
4864: '<th>'.&mt('History').'</th>'.
4865: &Apache::loncommon::end_data_table_header_row()
4866: );
1.571 raeburn 4867: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4868: foreach my $key (sort(@{$changedbytime{$chg}})) {
4869: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4870: my $currentversion=&Apache::lonnet::getversion($key);
4871: if ($currentversion<0) {
4872: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4873: }
4874: my $linkurl=&Apache::lonnet::clutter($key);
4875: $r->print(
4876: &Apache::loncommon::start_data_table_row().
4877: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4878: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4879: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4880: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4881: '<td align="right">'
4882: );
4883: # Used in course
4884: my $usedversion=$hash{'version_'.$linkurl};
4885: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4886: if ($usedversion != $currentversion) {
1.479 golterma 4887: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4888: } else {
1.479 golterma 4889: $r->print($usedversion);
4890: }
1.329 droeschl 4891: } else {
1.521 bisitz 4892: $r->print($currentversion);
1.329 droeschl 4893: }
1.571 raeburn 4894: $r->print('</td><td title="'.$lt{'vu'}.'">');
4895: # Set version
4896: $r->print(&Apache::loncommon::select_form(
4897: $setversions{$linkurl},
4898: 'set_version_'.$linkurl,
4899: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4900: '' => '',
4901: 'mostrecent' => &mt('most recent'),
1.611 raeburn 4902: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 4903: my $lastold=1;
4904: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4905: my $url=$root.'.'.$prevvers.'.'.$extension;
4906: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4907: $lastold=$prevvers;
4908: }
4909: }
4910: $r->print('</td>');
4911: # List all available versions
4912: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4913: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4914: my $url=$root.'.'.$prevvers.'.'.$extension;
4915: $r->print(
4916: '<span class="LC_nobreak">'
4917: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4918: .&mt('Version [_1]',$prevvers).'</a>'
4919: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4920: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4921: .')');
4922: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4923: $r->print(
4924: ' <a href="/adm/diff?filename='.
4925: &Apache::lonnet::clutter($root.'.'.$extension).
4926: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4927: '" target="diffs">'.&mt('Diffs').'</a>');
4928: }
4929: $r->print('</span><br />');
1.329 droeschl 4930: }
1.571 raeburn 4931: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4932: }
1.329 droeschl 4933: }
1.521 bisitz 4934: $r->print(
4935: &Apache::loncommon::end_data_table().
1.611 raeburn 4936: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4937: '</form>'
4938: );
1.329 droeschl 4939:
4940: &untiehash();
1.521 bisitz 4941: $r->print(&endContentScreen());
1.571 raeburn 4942: return;
1.329 droeschl 4943: }
4944:
4945: sub mark_hash_old {
4946: my $retie_hash=0;
4947: if ($hashtied) {
4948: $retie_hash=1;
4949: &untiehash();
4950: }
4951: &tiehash('write');
4952: $hash{'old'}=1;
4953: &untiehash();
4954: if ($retie_hash) { &tiehash(); }
4955: }
4956:
4957: sub is_hash_old {
4958: my $untie_hash=0;
4959: if (!$hashtied) {
4960: $untie_hash=1;
4961: &tiehash();
4962: }
4963: my $return=$hash{'old'};
4964: if ($untie_hash) { &untiehash(); }
4965: return $return;
4966: }
4967:
4968: sub changewarning {
4969: my ($r,$postexec,$message,$url)=@_;
4970: if (!&is_hash_old()) { return; }
4971: my $pathvar='folderpath';
4972: my $path=&escape($env{'form.folderpath'});
4973: if (!defined($url)) {
4974: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4975: }
4976: my $course_type = &Apache::loncommon::course_type();
4977: if (!defined($message)) {
4978: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4979: }
4980: $r->print("\n\n".
1.372 bisitz 4981: '<script type="text/javascript">'."\n".
4982: '// <![CDATA['."\n".
4983: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4984: '// ]]>'."\n".
1.369 bisitz 4985: '</script>'."\n".
1.375 tempelho 4986: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4987: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4988: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4989: &mt($message,' <input type="hidden" name="'.
4990: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4991: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4992: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4993: }
4994:
4995:
4996: sub init_breadcrumbs {
1.571 raeburn 4997: my ($form,$text,$help)=@_;
1.329 droeschl 4998: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4999: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5000: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5001: faq=>273,
5002: bug=>'Instructor Interface',
1.571 raeburn 5003: help => $help});
1.329 droeschl 5004: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5005: text=>$text,
5006: faq=>273,
5007: bug=>'Instructor Interface'});
5008: }
5009:
1.441 www 5010: # subroutine to list form elements
5011: sub create_list_elements {
5012: my @formarr = @_;
5013: my $list = '';
1.501 raeburn 5014: foreach my $button (@formarr){
5015: foreach my $picture (keys(%{$button})) {
5016: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5017: }
5018: }
5019: return $list;
5020: }
1.329 droeschl 5021:
1.441 www 5022: # subroutine to create ul from list elements
5023: sub create_form_ul {
5024: my $list = shift;
5025: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5026: return $ul;
5027: }
1.329 droeschl 5028:
1.442 www 5029: #
5030: # Start tabs
5031: #
5032:
5033: sub startContentScreen {
1.484 raeburn 5034: my ($mode) = @_;
5035: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5036: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5037: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5038: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5039: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5040: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5041: } else {
1.549 raeburn 5042: $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 5043: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5044: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5045: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5046: }
5047: $output .= "\n".'</ul>'."\n";
5048: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5049: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5050: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5051: return $output;
1.442 www 5052: }
5053:
5054: #
5055: # End tabs
5056: #
5057:
5058: sub endContentScreen {
1.484 raeburn 5059: return '</div></div></div>';
1.442 www 5060: }
1.329 droeschl 5061:
1.446 www 5062: sub supplemental_base {
1.548 raeburn 5063: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5064: }
5065:
1.329 droeschl 5066: sub handler {
5067: my $r = shift;
5068: &Apache::loncommon::content_type($r,'text/html');
5069: $r->send_http_header;
5070: return OK if $r->header_only;
1.484 raeburn 5071:
5072: # get course data
1.408 raeburn 5073: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5074: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5075: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5076:
1.606 raeburn 5077: # get docroot
5078: my $londocroot = $r->dir_config('lonDocRoot');
5079:
1.484 raeburn 5080: # graphics settings
5081: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5082:
1.443 www 5083: #
1.329 droeschl 5084: # --------------------------------------------- Initialize help topics for this
5085: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5086: 'Adding_External_Resource','Navigate_Content',
5087: 'Adding_Folders','Docs_Overview', 'Load_Map',
5088: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 5089: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.571 raeburn 5090: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
1.572 raeburn 5091: 'Dropbox','Simple_Problem') {
1.329 droeschl 5092: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5093: }
5094: # Composite help files
5095: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5096: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5097: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5098: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5099: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5100: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5101: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5102: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5103: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5104: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5105:
1.611 raeburn 5106: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5107: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5108: unless ($r->uri eq '/adm/supplemental') {
5109: # does this user have privileges to modify content.
1.611 raeburn 5110: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5111: $allowed = 1;
5112: $canedit = 1;
5113: $canview = 1;
5114: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5115: $allowed = 1;
5116: $canview = 1;
5117: }
5118: }
5119: unless ($canedit) {
5120: $disabled = ' disabled="disabled"';
1.472 raeburn 5121: }
1.582 raeburn 5122: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5123: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5124: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 5125: &verifycontent($r);
5126: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5127: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5128: &list_symbs($r);
5129: } elsif ($allowed && $env{'form.docslog'}) {
5130: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5131: my $folder = $env{'form.folder'};
5132: if ($folder eq '') {
5133: $folder='default';
5134: }
1.611 raeburn 5135: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5136: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5137: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5138: &checkversions($r,$canedit);
5139: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5140: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5141: &dumpcourse($r);
1.611 raeburn 5142: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5143: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5144: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5145: } else {
1.611 raeburn 5146: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5147: $noendpage = 1;
5148: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5149: if ($redirect) {
5150: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5151: my $container = 'sequence';
5152: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5153: $is_random_order,$container) =
5154: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5155: my (@folders)=split('&',$env{'form.folderpath'});
5156: $env{'form.foldername'}=&unescape(pop(@folders));
5157: my $folder=pop(@folders);
5158: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5159: $folder.'.'.$container);
5160: my $warning;
5161: if ($fatal) {
5162: if ($container eq 'page') {
5163: $warning = &mt('An error occurred retrieving the contents of the current page.');
5164: } else {
5165: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5166: }
5167: } else {
5168: my $url = $redirect;
5169: my $srcfile = $londocroot.$url;
5170: $url =~ s{^/priv/}{/res/};
5171: my $targetfile = $londocroot.$url;
5172: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5173: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5174: $env{'form.folder'} = $folder;
5175: &snapshotbefore();
5176: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5177: my $ext = 'false';
5178: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5179: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5180: ':'.$ext.':normal:res';
5181: push(@LONCAPA::map::order,$newidx);
5182: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5183: 'string_yesno');
5184: &remember_parms($newidx,'hiddenresource','set','yes');
5185: ($errtext,$fatal) =
5186: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5187: &log_differences($plain);
5188: &mark_hash_old();
5189: $r->internal_redirect($redirect);
5190: return OK;
5191: }
5192: }
5193: }
5194: }
1.445 www 5195: #
5196: # Done catching special calls
1.484 raeburn 5197: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5198: # Get the parameters that may be needed
5199: #
5200: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5201: ['folderpath',
5202: 'forcesupplement','forcestandard',
1.510 raeburn 5203: 'tools','symb','command','supppath']);
1.445 www 5204:
5205: # standard=1: this is a "new-style" course with an uploaded map as top level
5206: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5207:
5208: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5209:
1.484 raeburn 5210: # Decide whether this should display supplemental or main content or utilities
1.445 www 5211: # supplementalflag=1: show supplemental documents
5212: # supplementalflag=0: show standard documents
1.484 raeburn 5213: # toolsflag=1: show utilities
1.445 www 5214:
1.561 raeburn 5215: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5216: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5217: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5218: $supplementalflag=0;
5219: }
5220: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5221: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5222: unless ($allowed) { $supplementalflag=1; }
5223: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5224: my $toolsflag=0;
5225: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5226:
1.329 droeschl 5227: my $script='';
5228: my $showdoc=0;
1.457 raeburn 5229: my $addentries = {};
1.475 raeburn 5230: my $container;
1.329 droeschl 5231: my $containertag;
1.508 raeburn 5232: my $pathitem;
1.598 raeburn 5233: my %ltitools;
1.617 raeburn 5234: my $hiddentop;
1.615 raeburn 5235: my $navmap;
1.617 raeburn 5236: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5237:
1.464 www 5238: # Do we directly jump somewhere?
1.525 raeburn 5239: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5240: if ($env{'form.symb'} ne '') {
1.522 raeburn 5241: $env{'form.folderpath'}=
1.617 raeburn 5242: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5243: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5244: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5245: } elsif ($env{'form.supppath'} ne '') {
5246: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5247: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5248: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5249: }
1.472 raeburn 5250: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5251: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5252: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5253: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5254: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5255: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5256: } elsif ($env{'form.command'} eq 'contents') {
5257: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5258: } elsif ($env{'form.command'} eq 'home') {
5259: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5260: }
5261:
1.525 raeburn 5262:
1.445 www 5263: # Where do we store these for when we come back?
5264: my $stored_folderpath='docs_folderpath';
5265: if ($supplementalflag) {
5266: $stored_folderpath='docs_sup_folderpath';
5267: }
1.464 www 5268:
1.519 raeburn 5269: # No folderpath, and in edit mode, see if we have something stored
5270: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5271: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5272: {'folderpath' => 'scalar'});
1.615 raeburn 5273:
5274: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5275: if ($supplementalflag) {
5276: undef($env{'form.folderpath'}) if ($1 eq 'default');
5277: } else {
5278: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5279: }
5280: } else {
1.523 raeburn 5281: undef($env{'form.folderpath'});
5282: }
1.329 droeschl 5283: }
1.446 www 5284:
5285: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5286: if (!$allowed) {
1.446 www 5287: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5288: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5289: }
5290: }
1.446 www 5291: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5292: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5293: $env{'form.folderpath'} = &supplemental_base()
5294: .'&'.
1.329 droeschl 5295: $env{'form.folderpath'};
5296: }
1.615 raeburn 5297: # If allowed and user's role is not advanced check folderpath is not hidden
5298: if (($allowed) && (!$env{'request.role.adv'}) &&
5299: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5300: my $folderurl;
5301: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5302: my $folder = $pathitems[-2];
5303: if ($folder eq '') {
5304: undef($env{'form.folderpath'});
5305: } else {
5306: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5307: if ((split(/\:/,$pathitems[-1]))[4]) {
5308: $folderurl .= '.page';
5309: } else {
5310: $folderurl .= '.sequence';
5311: }
1.617 raeburn 5312: unless (ref($navmap)) {
5313: $navmap = Apache::lonnavmaps::navmap->new();
5314: }
1.615 raeburn 5315: if (ref($navmap)) {
5316: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5317: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5318: unless (@resources) {
5319: undef($env{'form.folderpath'});
5320: }
1.615 raeburn 5321: }
5322: }
5323: }
5324: }
5325:
5326:
1.446 www 5327: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5328: unless ($env{'form.folderpath'}) {
1.446 www 5329: if ($supplementalflag) {
5330: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5331: } elsif ($allowed) {
5332: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5333: }
1.472 raeburn 5334: }
1.446 www 5335:
1.445 www 5336: # Store this
1.484 raeburn 5337: unless ($toolsflag) {
1.615 raeburn 5338: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5339: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5340: {'folderpath' => 'scalar'});
1.510 raeburn 5341: }
1.519 raeburn 5342: my $folderpath;
1.484 raeburn 5343: if ($env{'form.folderpath'}) {
1.519 raeburn 5344: $folderpath = $env{'form.folderpath'};
5345: my (@folders)=split('&',$env{'form.folderpath'});
5346: $env{'form.foldername'}=&unescape(pop(@folders));
5347: if ($env{'form.foldername'} =~ /\:1$/) {
5348: $container = 'page';
5349: } else {
5350: $container = 'sequence';
5351: }
5352: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5353: } else {
1.519 raeburn 5354: if ($env{'form.folder'} eq '' ||
5355: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5356: if ($env{'form.folder'} eq 'supplemental') {
5357: $folderpath=&supplemental_base();
5358: } elsif (!$hiddentop) {
5359: $folderpath='default&'.
5360: &escape(&mt('Main Content').':::::');
5361: }
1.484 raeburn 5362: }
5363: }
1.519 raeburn 5364: $containertag = '<input type="hidden" name="folderpath" value="" />';
5365: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5366: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5367: $showdoc='/'.$1;
5368: }
5369: if ($showdoc) { # got called in sequence from course
5370: $allowed=0;
5371: } else {
1.611 raeburn 5372: if ($canedit) {
1.484 raeburn 5373: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5374: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5375: }
5376: }
1.329 droeschl 5377: }
5378:
1.344 bisitz 5379: # get personal data
1.329 droeschl 5380: my $uname=$env{'user.name'};
5381: my $udom=$env{'user.domain'};
5382: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5383:
5384: if ($allowed) {
1.484 raeburn 5385: if ($toolsflag) {
5386: $script .= &inject_data_js();
5387: my ($home,$other,%outhash)=&authorhosts();
5388: if (!$home && $other) {
5389: my @hosts;
5390: foreach my $aurole (keys(%outhash)) {
5391: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5392: push(@hosts,$outhash{$aurole});
5393: }
5394: }
5395: $script .= &dump_switchserver_js(@hosts);
5396: }
1.458 raeburn 5397: } else {
1.570 raeburn 5398: my $tid = 1;
1.484 raeburn 5399: my @tabids;
5400: if ($supplementalflag) {
5401: @tabids = ('002','ee2','ff2');
1.570 raeburn 5402: $tid = 2;
1.484 raeburn 5403: } else {
5404: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5405: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5406: unshift(@tabids,'001');
5407: push(@tabids,('dd1','ee1'));
5408: }
1.458 raeburn 5409: }
1.484 raeburn 5410: my $tabidstr = join("','",@tabids);
1.598 raeburn 5411: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5412: my $posslti = keys(%ltitools);
1.622 raeburn 5413: my $hostname = $r->hostname();
1.606 raeburn 5414: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5415: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5416: &history_tab_js().
5417: &inject_data_js().
1.570 raeburn 5418: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5419: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5420: $addentries = {
1.485 raeburn 5421: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5422: };
1.458 raeburn 5423: }
1.538 raeburn 5424: $script .= &paste_popup_js();
1.501 raeburn 5425: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5426: &mt('Switch server?');
5427:
5428:
1.329 droeschl 5429: }
5430: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5431: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5432: .'// <![CDATA['."\n"
5433: .$script."\n"
5434: .'// ]]>'."\n"
1.595 musolffc 5435: .'</script>'."\n"
5436: .'<script type="text/javascript"
5437: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5438:
5439: # Breadcrumbs
5440: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5441:
5442: if ($showdoc) {
5443: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5444: {'force_register' => $showdoc,}));
1.571 raeburn 5445: } elsif ($toolsflag) {
1.611 raeburn 5446: my ($breadtext,$breadtitle);
1.617 raeburn 5447: $breadtext = "$crstype Editor";
1.611 raeburn 5448: if ($canedit) {
5449: $breadtitle = 'Editing '.$crstype.' Contents';
5450: } else {
5451: $breadtext .= ' (View-only mode)';
5452: $breadtitle = 'Viewing '.$crstype.' Contents';
5453: }
1.571 raeburn 5454: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5455: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5456: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5457: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5458: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5459: $breadtitle)
1.571 raeburn 5460: );
1.510 raeburn 5461: } elsif ($r->uri eq '/adm/supplemental') {
5462: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5463: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5464: {'bread_crumbs' => $brcrum,}));
5465: } else {
1.611 raeburn 5466: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5467: $breadtext = "$crstype Editor";
1.611 raeburn 5468: if ($canedit) {
5469: $breadtitle = 'Editing '.$crstype.' Contents';
5470: $helpitem = 'Docs_Adding_Course_Doc';
5471: } else {
5472: $breadtext .= ' (View-only mode)';
5473: $breadtitle = 'Viewing '.$crstype.' Contents';
5474: $helpitem = 'Docs_Viewing_Course_Doc';
5475: }
1.392 raeburn 5476: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5477: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5478: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5479: {'add_entries' => $addentries}
5480: )
1.392 raeburn 5481: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5482: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5483: $breadtitle,
5484: $helpitem)
1.392 raeburn 5485: );
5486: }
1.364 bisitz 5487:
1.329 droeschl 5488: my %allfiles = ();
5489: my %codebase = ();
1.440 raeburn 5490: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5491: if ($canedit) {
1.329 droeschl 5492: if (($env{'form.uploaddoc.filename'}) &&
5493: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5494: my $context = $1;
5495: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5496: undef($hadchanges);
1.440 raeburn 5497: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5498: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5499: if ($hadchanges) {
5500: &mark_hash_old();
5501: }
1.440 raeburn 5502: $r->print($upload_output);
5503: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5504: # Process file upload - phase two - upload embedded objects
5505: $uploadphase = 'check_embedded';
5506: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5507: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5508: $env{'form.newidx'});
5509: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5510: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5511: my ($destination,$dir_root) = &embedded_destination();
5512: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5513: my $actionurl = '/adm/coursedocs';
5514: my ($result,$flag) =
5515: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5516: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5517: $actionurl);
5518: $r->print($result.&return_to_editor());
5519: } elsif ($env{'form.phase'} eq 'check_embedded') {
5520: # Process file upload - phase three - modify references in HTML file
5521: $uploadphase = 'modified_orightml';
5522: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5523: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5524: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5525: my $result =
5526: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5527: $docuname,$docudom,undef,
5528: $dir_root);
5529: $r->print($result.&return_to_editor());
1.476 raeburn 5530: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5531: $uploadphase = 'decompress_phase_one';
5532: $r->print(&decompression_phase_one().
5533: &return_to_editor());
5534: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5535: $uploadphase = 'decompress_phase_two';
5536: $r->print(&decompression_phase_two().
5537: &return_to_editor());
1.329 droeschl 5538: }
5539: }
5540:
1.484 raeburn 5541: if ($allowed && $toolsflag) {
5542: $r->print(&startContentScreen('tools'));
1.611 raeburn 5543: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5544: $r->print(&endContentScreen());
5545: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5546: # -----------------------------------------------------------------------------
5547: my %lt=&Apache::lonlocal::texthash(
5548: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5549: 'upfi' => 'Upload File',
1.553 raeburn 5550: 'upld' => 'Upload Content',
1.329 droeschl 5551: 'srch' => 'Search',
5552: 'impo' => 'Import',
1.487 raeburn 5553: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5554: 'impm' => 'Import from Assembled Map',
1.606 raeburn 5555: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5556: 'extr' => 'External Resource',
5557: 'extt' => 'External Tool',
1.329 droeschl 5558: 'selm' => 'Select Map',
5559: 'load' => 'Load Map',
5560: 'newf' => 'New Folder',
5561: 'newp' => 'New Composite Page',
5562: 'syll' => 'Syllabus',
1.425 raeburn 5563: 'navc' => 'Table of Contents',
1.343 biermanm 5564: 'sipa' => 'Simple Course Page',
1.329 droeschl 5565: 'sipr' => 'Simple Problem',
1.534 raeburn 5566: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5567: 'stpr' => 'Standard Problem',
5568: 'news' => 'New sub-directory',
5569: 'crpr' => 'Create Problem',
1.329 droeschl 5570: 'drbx' => 'Drop Box',
1.451 www 5571: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5572: 'bull' => 'Discussion Board',
1.347 weissno 5573: 'mypi' => 'My Personal Information Page',
1.353 weissno 5574: 'grpo' => 'Group Portfolio',
1.329 droeschl 5575: 'rost' => 'Course Roster',
1.528 raeburn 5576: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5577: 'imsf' => 'IMS Upload',
5578: 'imsl' => 'Upload IMS package',
1.501 raeburn 5579: 'cms' => 'Origin of IMS package',
5580: 'se' => 'Select',
1.329 droeschl 5581: 'file' => 'File',
5582: 'title' => 'Title',
1.606 raeburn 5583: 'addp' => 'Add Placeholder to course?',
5584: 'uste' => 'Use Template?',
5585: 'fnam' => 'File Name:',
5586: 'loca' => 'Location:',
5587: 'dire' => 'Directory:',
5588: 'cate' => 'Category:',
5589: 'tmpl' => 'Template:',
1.329 droeschl 5590: 'comment' => 'Comment',
1.403 raeburn 5591: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5592: 'bb5' => 'Blackboard 5',
5593: 'bb6' => 'Blackboard 6',
5594: 'angel5' => 'ANGEL 5.5',
5595: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5596: 'yes' => 'Yes',
5597: 'no' => 'No',
1.618 raeburn 5598: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5599: );
1.329 droeschl 5600: # -----------------------------------------------------------------------------
1.595 musolffc 5601:
5602: # Calculate free quota space for a user or course. A javascript function checks
5603: # file size to determine if upload should be allowed.
5604: my $quotatype = 'unofficial';
5605: if ($crstype eq 'Community') {
1.601 raeburn 5606: $quotatype = 'community';
5607: } elsif ($crstype eq 'Placement') {
5608: $quotatype = 'placement';
1.595 musolffc 5609: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5610: $quotatype = 'official';
5611: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5612: $quotatype = 'textbook';
5613: }
5614: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5615: 'course',$quotatype); # expressed in MB
5616: my $current_disk_usage = 0;
5617: foreach my $subdir ('docs','supplemental') {
5618: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5619: "userfiles/$subdir",1); # expressed in kB
5620: }
5621: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5622: my $usage = $current_disk_usage/1024; # in MB
5623: my $quota = $disk_quota;
5624: my $percent;
5625: if ($disk_quota == 0) {
5626: $percent = 100.0;
5627: } else {
1.619 raeburn 5628: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5629: }
5630: $usage = sprintf("%.2f",$usage);
5631: $quota = sprintf("%.2f",$quota);
5632: $percent = sprintf("%.0f",$percent);
5633: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5634: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5635:
1.329 droeschl 5636: my $fileupload=(<<FIUP);
1.605 raeburn 5637: $quotainfo
1.329 droeschl 5638: $lt{'file'}:<br />
1.611 raeburn 5639: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5640: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5641: FIUP
5642:
5643: my $checkbox=(<<CHBO);
5644: <!-- <label>$lt{'parse'}?
5645: <input type="checkbox" name="parserflag" />
5646: </label> -->
5647: <label>
1.611 raeburn 5648: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5649: </label>
5650: CHBO
1.501 raeburn 5651: my $imsfolder = $env{'form.folder'};
5652: if ($imsfolder eq '') {
5653: $imsfolder = 'default';
5654: }
5655: my $imspform=(<<IMSFORM);
5656: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5657: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5658: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5659: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5660: <legend>$lt{'imsf'}</legend>
5661: $fileupload
5662: <br />
5663: <p>
5664: $lt{'cms'}:
1.611 raeburn 5665: <select name="source" $disabled>
1.501 raeburn 5666: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5667: <option value="bb5">$lt{'bb5'}</option>
5668: <option value="bb6">$lt{'bb6'}</option>
5669: <option value="angel5">$lt{'angel5'}</option>
5670: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5671: </select>
5672: <input type="hidden" name="folder" value="$imsfolder" />
5673: </p>
5674: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5675: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5676: </fieldset>
5677: </form>
5678: IMSFORM
1.329 droeschl 5679:
5680: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5681: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5682: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5683: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5684: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5685: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5686: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5687: $fileupload
1.329 droeschl 5688: <br />
5689: $lt{'title'}:<br />
1.611 raeburn 5690: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5691: $pathitem
1.329 droeschl 5692: <input type="hidden" name="cmd" value="upload_default" />
5693: <br />
1.458 raeburn 5694: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5695: $checkbox
5696: </span>
1.501 raeburn 5697: <br clear="all" />
1.611 raeburn 5698: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5699: </fieldset>
5700: </form>
1.383 tempelho 5701: FUFORM
1.329 droeschl 5702:
1.611 raeburn 5703: my $mapimportjs;
5704: if ($canedit) {
5705: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5706: } else {
5707: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5708: }
1.502 raeburn 5709: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5710: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5711: $lt{'impm'}</a>$help{'Load_Map'}
5712: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5713: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5714: <legend>$lt{'impm'}</legend>
1.371 tempelho 5715: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5716: $lt{'copm'}<br />
5717: <span class="LC_nobreak">
5718: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5719: onfocus="this.blur();$mapimportjs" $disabled />
5720: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5721: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5722: </fieldset>
5723: </form>
5724:
1.383 tempelho 5725: SEDFFORM
1.606 raeburn 5726: my $importcrsresform;
1.608 raeburn 5727: my ($numdirs,$pickfile) =
5728: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5729: "resize_scrollbox('contentscroll','1','0');",
5730: undef,'res');
1.606 raeburn 5731: if ($pickfile) {
5732: $importcrsresform=(<<CRSFORM);
5733: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5734: $lt{'imcr'}</a>$help{'Course_Resources'}
5735: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5736: <fieldset id="importcrsresform" style="display: none;">
5737: <legend>$lt{'imcr'}</legend>
5738: <input type="hidden" name="active" value="bb" />
5739: $pickfile
5740: <p>
1.611 raeburn 5741: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5742: </p>
5743: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5744: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5745: </fieldset>
5746: </form>
5747: CRSFORM
5748: }
5749:
1.611 raeburn 5750: my $fromstoredjs;
5751: if ($canedit) {
5752: $fromstoredjs = 'open_StoredLinks_Import()';
5753: } else {
5754: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5755: }
5756:
1.502 raeburn 5757: my @importpubforma = (
1.508 raeburn 5758: { '<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 5759: { '<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.611 raeburn 5760: { '<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.606 raeburn 5761: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5762: );
5763: if ($pickfile) {
5764: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5765: }
1.502 raeburn 5766: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5767: my $extresourcesform =
5768: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5769: $help{'Adding_External_Resource'},
5770: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5771: my $exttoolform =
5772: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5773: $help{'Adding_External_Tool'},undef,
5774: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5775: \%ltitools,$disabled);
1.329 droeschl 5776: if ($allowed) {
1.492 raeburn 5777: my $folder = $env{'form.folder'};
5778: if ($folder eq '') {
5779: $folder='default';
5780: }
1.615 raeburn 5781: if ($canedit) {
5782: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5783: if ($output) {
5784: $r->print($output);
5785: }
1.538 raeburn 5786: }
1.337 ehlerst 5787: $r->print(<<HIDDENFORM);
5788: <form name="renameform" method="post" action="/adm/coursedocs">
5789: <input type="hidden" name="title" />
5790: <input type="hidden" name="cmd" />
5791: <input type="hidden" name="markcopy" />
5792: <input type="hidden" name="copyfolder" />
5793: $containertag
5794: </form>
1.484 raeburn 5795:
1.337 ehlerst 5796: HIDDENFORM
1.508 raeburn 5797: $r->print(&makesimpleeditform($pathitem)."\n".
5798: &makedocslogform($pathitem."\n".
1.484 raeburn 5799: '<input type="hidden" name="folder" value="'.
5800: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5801: }
1.442 www 5802:
5803: # Generate the tabs
1.510 raeburn 5804: my ($mode,$needs_end);
1.472 raeburn 5805: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5806: my @folders = split('&',$env{'form.folderpath'});
5807: unless (@folders > 2) {
5808: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5809: $needs_end = 1;
5810: }
1.472 raeburn 5811: } else {
1.484 raeburn 5812: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5813: $needs_end = 1;
1.472 raeburn 5814: }
1.443 www 5815:
1.442 www 5816: #
1.622 raeburn 5817: my $hostname = $r->hostname();
1.442 www 5818: my $savefolderpath;
5819:
1.395 raeburn 5820: if ($allowed) {
1.329 droeschl 5821: my $folder=$env{'form.folder'};
1.615 raeburn 5822: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5823: $folder='default';
1.356 tempelho 5824: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5825: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5826: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5827: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5828: }
5829: my $postexec='';
5830: if ($folder eq 'default') {
1.372 bisitz 5831: $r->print('<script type="text/javascript">'."\n"
5832: .'// <![CDATA['."\n"
5833: .'this.window.name="loncapaclient";'."\n"
5834: .'// ]]>'."\n"
5835: .'</script>'."\n"
1.369 bisitz 5836: );
1.329 droeschl 5837: } else {
5838: #$postexec='self.close();';
5839: }
1.504 raeburn 5840: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5841: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5842: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5843:
5844: my $newnavform=(<<NNFORM);
5845: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5846: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5847: $pathitem
1.329 droeschl 5848: <input type="hidden" name="importdetail"
5849: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 5850: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5851: $help{'Navigate_Content'}
5852: </form>
5853: NNFORM
5854: my $newsmppageform=(<<NSPFORM);
5855: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5856: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5857: $pathitem
1.329 droeschl 5858: <input type="hidden" name="importdetail" value="" />
1.423 onken 5859: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5860: $help{'Simple Page'}
1.329 droeschl 5861: </form>
5862: NSPFORM
5863:
5864: my $newsmpproblemform=(<<NSPROBFORM);
5865: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5866: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5867: $pathitem
1.329 droeschl 5868: <input type="hidden" name="importdetail" value="" />
1.423 onken 5869: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5870: $help{'Simple_Problem'}
1.329 droeschl 5871: </form>
5872:
5873: NSPROBFORM
5874:
5875: my $newdropboxform=(<<NDBFORM);
5876: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5877: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5878: $pathitem
1.329 droeschl 5879: <input type="hidden" name="importdetail" value="" />
1.423 onken 5880: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5881: $help{'Dropbox'}
1.344 bisitz 5882: </form>
1.329 droeschl 5883: NDBFORM
5884:
5885: my $newexuploadform=(<<NEXUFORM);
5886: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5887: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5888: $pathitem
1.329 droeschl 5889: <input type="hidden" name="importdetail" value="" />
1.423 onken 5890: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5891: $help{'Score_Upload_Form'}
5892: </form>
5893: NEXUFORM
5894:
5895: my $newbulform=(<<NBFORM);
5896: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5897: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5898: $pathitem
1.329 droeschl 5899: <input type="hidden" name="importdetail" value="" />
1.423 onken 5900: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5901: $help{'Bulletin Board'}
5902: </form>
5903: NBFORM
5904:
5905: my $newaboutmeform=(<<NAMFORM);
5906: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5907: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5908: $pathitem
1.329 droeschl 5909: <input type="hidden" name="importdetail"
5910: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 5911: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5912: $help{'My Personal Information Page'}
1.329 droeschl 5913: </form>
5914: NAMFORM
5915:
5916: my $newaboutsomeoneform=(<<NASOFORM);
5917: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5918: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5919: $pathitem
1.329 droeschl 5920: <input type="hidden" name="importdetail" value="" />
1.423 onken 5921: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5922: </form>
5923: NASOFORM
5924:
5925: my $newrosterform=(<<NROSTFORM);
5926: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5927: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5928: $pathitem
1.329 droeschl 5929: <input type="hidden" name="importdetail"
5930: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 5931: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 5932: $help{'Course_Roster'}
1.329 droeschl 5933: </form>
5934: NROSTFORM
5935:
1.534 raeburn 5936: my $newwebpage;
5937: if ($folder =~ /^default_?(\d*)$/) {
5938: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5939: if ($1) {
5940: $newwebpage .= $1;
5941: } else {
5942: $newwebpage .= 'default';
5943: }
5944: $newwebpage .= '/new.html';
5945: }
5946: my $newwebpageform =(<<NWEBFORM);
5947: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5948: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5949: $pathitem
5950: <input type="hidden" name="importdetail" value="$newwebpage" />
5951: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5952: $help{'Web_Page'}
1.534 raeburn 5953: </form>
5954: NWEBFORM
1.604 raeburn 5955:
1.606 raeburn 5956: my @ids=&Apache::lonnet::current_machine_ids();
5957: my %select_menus;
5958: my $numauthor = 0;
5959: my $numcrsdirs = 0;
5960: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5961: if ($env{'user.author'}) {
5962: $numauthor ++;
5963: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5964: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5965: my $is_home = 1;
5966: my %subdirs;
1.608 raeburn 5967: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5968: $select_menus{'author'}->{'default'} = '/';
5969: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5970: my @ordered = ('/');
5971: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5972: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5973: push(@ordered,$relpath);
5974: }
5975: $select_menus{'author'}->{'order'} = \@ordered;
5976: } else {
5977: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5978: $select_menus{'author'}->{'default'} = 'switch';
5979: $select_menus{'author'}->{'order'} = ['switch'];
5980: }
5981: }
5982: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5983: ['active'],['ca','aa']);
5984: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5985: my %by_roletype;
5986: if (keys(%roleshash)) {
5987: foreach my $entry (keys(%roleshash)) {
5988: my ($auname,$audom,$roletype) = split(/:/,$entry);
5989: my $key = $entry;
5990: $key =~ s/:/___/g;
5991: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5992: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5993: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5994: if (grep(/^\Q$rolehome\E$/,@ids)) {
5995: my $is_home = 1;
5996: my (%subdirs,@ordered);
5997: my $toppath="/priv/$audom/$auname";
1.608 raeburn 5998: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5999: $select_menus{$key}->{'default'} = '/';
6000: $select_menus{$key}->{'select2'}->{'/'} = '/';
6001: my @ordered = ('/');
6002: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6003: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6004: push(@ordered,$relpath);
6005: }
6006: $select_menus{$key}->{'order'} = \@ordered;
6007: } else {
6008: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6009: $select_menus{$key}->{'default'} = 'switch';
6010: $select_menus{$key}->{'order'} = ['switch'];
6011: }
6012: $numauthor ++;
6013: }
6014: }
6015: my ($pickdir,$showtitle);;
6016: if ($numauthor) {
6017: my @order;
6018: my $defrole;
6019: if ($env{'user.author'}) {
6020: push(@order,'author');
6021: $defrole = 'author';
6022: }
6023: if (keys(%by_roletype)) {
6024: foreach my $possrole ('ca','aa') {
6025: if (ref($by_roletype{$possrole}) eq 'HASH') {
6026: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6027: unless ($defrole) {
6028: $defrole = $author;
6029: }
6030: push(@order,$author.'___'.$possrole);
6031: }
6032: }
6033: }
6034: }
6035: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6036: if (grep(/^\Q$crshome\E$/,@ids)) {
6037: my $is_home = 1;
6038: my %subdirs;
6039: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6040: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6041: $numcrsdirs = keys(%subdirs);
6042: $select_menus{'course'}->{'default'} = '/';
6043: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6044: my @ordered = ('/');
6045: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6046: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6047: push(@ordered,$relpath);
6048: }
6049: $select_menus{'course'}->{'order'} = \@ordered;
6050: } else {
6051: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6052: $select_menus{'course'}->{'default'} = 'switch';
6053: $select_menus{'course'}->{'order'} = ['switch'];
6054: }
6055: push(@order,'course');
6056: $pickdir = $lt{'loca'}.
6057: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6058: $defrole,'authorrole','authorpath',
6059: \%select_menus,\@order,'toggleCrsResTitle();',
6060: '','priv').'<br />';
6061: $showtitle = 'none';
6062: } else {
6063: my $is_home;
6064: $showtitle = 'inline';
6065: if (grep(/^\Q$crshome\E$/,@ids)) {
6066: $is_home = 1;
6067: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6068: my $toppath="/priv/$coursedom/$coursenum'}";
6069: my %subdirs;
1.608 raeburn 6070: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6071: $numcrsdirs = keys(%subdirs);
6072: if ($numcrsdirs) {
6073: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6074: '<option value="/">/</option>'."\n";
6075: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6076: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6077: }
6078: $pickdir .= '</select>';
6079: } else {
6080: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6081: }
6082: }
6083: }
6084:
6085: my %seltemplate_menus;
6086: my @files = &Apache::lonhomework::get_template_list('problem');
6087: my @noexamplelink = ('blank.problem','blank.library','script.library');
6088: my $currentcategory = '';
6089: my @ordered = ('');
6090: my %templatehelp;
6091: my $defcategory = '';
6092: my @catorder = ($defcategory);
6093: $seltemplate_menus{$defcategory}->{'order'} = [''];
6094: $seltemplate_menus{$defcategory}->{'text'} = '';
6095: foreach my $file (@files) {
6096: if (ref($file) eq 'ARRAY') {
6097: my ($path,$title,$category,$help) = @{$file};
6098: next if ($title !~ /\S/);
6099: if (&js_escape($category) ne $currentcategory) {
6100: $currentcategory = &js_escape($category);
6101: push(@catorder,&js_escape($currentcategory));
6102: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6103: $seltemplate_menus{$currentcategory}->{'default'} = '';
6104: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6105: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6106: }
6107: if ($path) {
6108: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6109: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6110: if ($help) {
6111: $templatehelp{$path} = $help;
6112: }
6113: }
6114: }
6115: }
6116:
6117: my $templates = $lt{'cate'}.' '.
6118: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6119: $defcategory,'tempcategory','template',
6120: \%seltemplate_menus,\@catorder,
6121: "resize_scrollbox('contentscroll','1','0');",
6122: "toggleExampleText();",'template').'<br />';
6123: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6124: '<span id="newresexample">'.&mt('Example').'<span></a>';
6125: my $crsresform=(<<RESFORM);
6126: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6127: $lt{'stpr'}</a>$help{'Course_Resource'}
6128: <form action="/adm/coursedocs" method="post" name="courseresform">
6129: <fieldset id="crsresform" style="display:none;">
6130: <legend>$lt{'stpr'}</legend>
6131: <input type="hidden" name="active" value="ee" />
6132: <p>
6133: $pickdir
6134: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6135: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6136:
1.611 raeburn 6137: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6138: </span><span id="newsubdir"></span>
6139: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6140: </p>
6141: $lt{'fnam'}
1.611 raeburn 6142: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6143: <p>
6144: <div id="newresource" style="display:$showtitle">
6145: $lt{'addp'}
1.611 raeburn 6146: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6147: $lt{'no'}</label>
1.611 raeburn 6148: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6149: $lt{'yes'}</label>
6150: <span id="newrestitle"></span>
1.611 raeburn 6151: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6152: </div>
6153: </p>
6154: <p>
6155: $lt{'uste'}
1.611 raeburn 6156: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6157: $lt{'no'}</label>
1.611 raeburn 6158: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6159: $lt{'yes'}</label>
6160: <div id="newrestemplate" style="display:none">
6161: $templates
6162: $templatepreview
6163: </div>
6164: </p>
6165: <span class="LC_nobreak">
6166: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6167: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6168: </span>
6169: </fieldset>
6170: </form>
6171:
6172: RESFORM
1.534 raeburn 6173:
1.342 ehlerst 6174: my $specialdocumentsform;
1.383 tempelho 6175: my @specialdocumentsforma;
1.451 www 6176: my $gradingform;
6177: my @gradingforma;
6178: my $communityform;
6179: my @communityforma;
1.351 ehlerst 6180: my $newfolderform;
1.390 tempelho 6181: my $newfolderb;
1.342 ehlerst 6182:
1.451 www 6183: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6184:
1.329 droeschl 6185: my $newpageform=(<<NPFORM);
6186: <form action="/adm/coursedocs" method="post" name="newpage">
6187: <input type="hidden" name="folderpath" value="$path" />
6188: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6189: <input type="hidden" name="active" value="ee" />
1.423 onken 6190: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6191: $help{'Adding_Pages'}
1.329 droeschl 6192: </form>
6193: NPFORM
1.390 tempelho 6194:
6195:
1.351 ehlerst 6196: $newfolderform=(<<NFFORM);
1.329 droeschl 6197: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6198: $pathitem
1.329 droeschl 6199: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6200: <input type="hidden" name="active" value="" />
1.422 onken 6201: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6202: </form>
6203: NFFORM
6204:
6205: my $newsylform=(<<NSYLFORM);
6206: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6207: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6208: $pathitem
1.329 droeschl 6209: <input type="hidden" name="importdetail"
6210: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6211: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6212: $help{'Syllabus'}
1.383 tempelho 6213:
1.329 droeschl 6214: </form>
6215: NSYLFORM
1.364 bisitz 6216:
1.329 droeschl 6217: my $newgroupfileform=(<<NGFFORM);
6218: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6219: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6220: $pathitem
1.329 droeschl 6221: <input type="hidden" name="importdetail"
6222: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6223: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6224: $help{'Group Portfolio'}
1.329 droeschl 6225: </form>
6226: NGFFORM
1.383 tempelho 6227: @specialdocumentsforma=(
1.421 onken 6228: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.618 raeburn 6229: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6230: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6231: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6232: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6233: );
6234: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6235:
1.434 raeburn 6236:
6237: my @importdoc = (
1.519 raeburn 6238: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6239: );
1.598 raeburn 6240: if (keys(%ltitools)) {
6241: push(@importdoc,
6242: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6243: );
6244: }
1.519 raeburn 6245: unless ($container eq 'page') {
6246: push(@importdoc,
6247: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6248: );
6249: }
6250: push(@importdoc,
1.558 raeburn 6251: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6252: );
1.501 raeburn 6253: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6254:
1.451 www 6255: @gradingforma=(
6256: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6257: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6258: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6259: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
1.451 www 6260: );
6261: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6262:
6263: @communityforma=(
6264: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6265: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6266: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6267: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6268: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6269: );
6270: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6271:
1.330 tempelho 6272: my %orderhash = (
1.553 raeburn 6273: 'aa' => ['Upload',$fileuploadform],
6274: 'bb' => ['Import',$importpubform],
6275: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6276: );
1.519 raeburn 6277: unless ($container eq 'page') {
1.434 raeburn 6278: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6279: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6280: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6281: }
6282:
1.341 ehlerst 6283: $hadchanges=0;
1.484 raeburn 6284: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6285: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6286: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6287: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6288: undef($navmap);
1.443 www 6289: if ($error) {
6290: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6291: }
6292: if ($hadchanges) {
6293: &mark_hash_old();
6294: }
1.341 ehlerst 6295:
1.443 www 6296: &changewarning($r,'');
6297: }
1.458 raeburn 6298: }
1.442 www 6299:
1.443 www 6300: # Supplemental documents start here
6301:
1.329 droeschl 6302: my $folder=$env{'form.folder'};
1.443 www 6303: unless ($supplementalflag) {
1.329 droeschl 6304: $folder='supplemental';
6305: }
6306: if ($folder =~ /^supplemental$/ &&
6307: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6308: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6309: } elsif ($allowed) {
1.356 tempelho 6310: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6311: }
1.508 raeburn 6312: $pathitem = '<input type="hidden" name="folderpath" value="'.
6313: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6314: if ($allowed) {
6315: my $folderseq=
1.504 raeburn 6316: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6317:
6318: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6319: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6320: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6321: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6322: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6323: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6324: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6325: $fileupload
6326: <br />
6327: <br />
6328: <span class="LC_nobreak">
6329: $checkbox
6330: </span>
6331: <br /><br />
6332: $lt{'comment'}:<br />
1.383 tempelho 6333: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6334: <br />
1.508 raeburn 6335: $pathitem
1.329 droeschl 6336: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6337: <input type='submit' value="$lt{'upld'}" />
6338: </form>
1.329 droeschl 6339: SUPDOCFORM
6340:
6341: my $supnewfolderform=(<<SNFFORM);
6342: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6343: <input type="hidden" name="active" value="" />
1.508 raeburn 6344: $pathitem
1.329 droeschl 6345: <input type="hidden" name="importdetail" value="" />
1.423 onken 6346: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6347: $help{'Adding_Folders'}
1.329 droeschl 6348: </form>
6349: SNFFORM
1.383 tempelho 6350:
1.510 raeburn 6351: my $supextform =
6352: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6353: $help{'Adding_External_Resource'},
6354: undef,undef,undef,undef,undef,undef,
6355: $disabled);
1.329 droeschl 6356:
1.598 raeburn 6357: my $supexttoolform =
6358: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6359: $help{'Adding_External_Tool'},
6360: undef,undef,'tool',$coursedom,
1.611 raeburn 6361: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6362:
1.329 droeschl 6363: my $supnewsylform=(<<SNSFORM);
6364: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6365: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6366: $pathitem
1.329 droeschl 6367: <input type="hidden" name="importdetail"
6368: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6369: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6370: $help{'Syllabus'}
6371: </form>
6372: SNSFORM
6373:
6374: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6375: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6376: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6377: $pathitem
1.329 droeschl 6378: <input type="hidden" name="importdetail"
6379: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6380: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6381: $help{'My Personal Information Page'}
1.329 droeschl 6382: </form>
6383: SNAMFORM
6384:
1.534 raeburn 6385: my $supwebpage;
6386: if ($folder =~ /^supplemental_?(\d*)$/) {
6387: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6388: if ($1) {
6389: $supwebpage .= $1;
6390: } else {
6391: $supwebpage .= 'default';
6392: }
6393: $supwebpage .= '/new.html';
6394: }
6395: my $supwebpageform =(<<SWEBFORM);
6396: <form action="/adm/coursedocs" method="post" name="supwebpage">
6397: <input type="hidden" name="active" value="cc" />
6398: $pathitem
6399: <input type="hidden" name="importdetail" value="$supwebpage" />
6400: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6401: $help{'Web_Page'}
1.534 raeburn 6402: </form>
6403: SWEBFORM
6404:
1.333 muellerd 6405:
1.383 tempelho 6406: my @specialdocs = (
1.618 raeburn 6407: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6408: =>$supnewsylform},
1.611 raeburn 6409: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6410: =>$supnewaboutmeform},
1.534 raeburn 6411: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6412:
1.383 tempelho 6413: );
1.417 droeschl 6414: my @supimportdoc = (
1.515 raeburn 6415: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6416: =>$supextform});
6417: if (keys(%ltitools)) {
6418: push(@supimportdoc,
6419: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6420: =>$supexttoolform});
6421: }
6422: push(@supimportdoc,
6423: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6424: =>$supupdocform},
1.598 raeburn 6425: );
1.501 raeburn 6426:
6427: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6428: my %suporderhash = (
1.390 tempelho 6429: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6430: 'ee' => ['Upload',$supupdocform],
6431: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6432: );
1.443 www 6433: if ($supplementalflag) {
1.458 raeburn 6434: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6435: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6436: \%ltitools,$canedit,$hostname);
1.443 www 6437: if ($error) {
6438: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6439: } else {
6440: if ($suppchanges) {
6441: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6442: my @ids=&Apache::lonnet::current_machine_ids();
6443: foreach my $server (keys(%servers)) {
6444: next if (grep(/^\Q$server\E$/,@ids));
6445: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6446: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6447: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6448: }
6449: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6450: undef($suppchanges);
6451: }
6452: }
1.393 raeburn 6453: }
1.443 www 6454: } elsif ($supplementalflag) {
1.458 raeburn 6455: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6456: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6457: if ($error) {
6458: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6459: }
1.393 raeburn 6460: }
1.389 tempelho 6461:
1.510 raeburn 6462: if ($needs_end) {
6463: $r->print(&endContentScreen());
6464: }
1.383 tempelho 6465:
1.329 droeschl 6466: if ($allowed) {
6467: $r->print('
6468: <form method="post" name="extimport" action="/adm/coursedocs">
6469: <input type="hidden" name="title" />
6470: <input type="hidden" name="url" />
6471: <input type="hidden" name="useform" />
6472: <input type="hidden" name="residx" />
6473: </form>');
6474: }
1.484 raeburn 6475: } elsif ($showdoc) {
1.329 droeschl 6476: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6477: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6478: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6479: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6480: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6481: }
6482: }
1.606 raeburn 6483: unless ($noendpage) {
6484: $r->print(&Apache::loncommon::end_page());
6485: }
1.329 droeschl 6486: return OK;
1.364 bisitz 6487: }
1.329 droeschl 6488:
1.440 raeburn 6489: sub embedded_form_elems {
6490: my ($phase,$primaryurl,$newidx) = @_;
6491: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6492: return <<STATE;
6493: <input type="hidden" name="folderpath" value="$folderpath" />
6494: <input type="hidden" name="cmd" value="upload_embedded" />
6495: <input type="hidden" name="newidx" value="$newidx" />
6496: <input type="hidden" name="phase" value="$phase" />
6497: <input type="hidden" name="primaryurl" value="$primaryurl" />
6498: STATE
6499: }
6500:
6501: sub embedded_destination {
6502: my $folder=$env{'form.folder'};
6503: my $destination = 'docs/';
6504: if ($folder =~ /^supplemental/) {
6505: $destination = 'supplemental/';
6506: }
6507: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6508: $destination .= 'default/';
6509: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6510: $destination .= $2.'/';
6511: }
6512: $destination .= $env{'form.newidx'};
6513: my $dir_root = '/userfiles';
6514: return ($destination,$dir_root);
6515: }
6516:
6517: sub return_to_editor {
6518: my $actionurl = '/adm/coursedocs';
6519: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6520: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6521: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6522: '</a></p>';
6523: }
6524:
1.476 raeburn 6525: sub decompression_info {
6526: my ($destination,$dir_root) = &embedded_destination();
6527: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6528: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6529: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6530: my $container='sequence';
1.480 raeburn 6531: my ($pathitem,$hiddenelem);
1.583 raeburn 6532: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6533: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6534: $container='page';
6535: }
1.480 raeburn 6536: unshift(@hiddens,$pathitem);
6537: foreach my $item (@hiddens) {
6538: if ($env{'form.'.$item}) {
6539: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6540: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6541: }
1.477 raeburn 6542: }
1.476 raeburn 6543: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6544: $hiddenelem);
6545: }
6546:
6547: sub decompression_phase_one {
6548: my ($dir,$file,$warning,$error,$output);
6549: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6550: &decompression_info();
1.490 raeburn 6551: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6552: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6553: } else {
6554: my $file = $1;
1.481 raeburn 6555: $output =
6556: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6557: $destination,$dir_root,
6558: $hiddenelem);
6559: if ($env{'form.autoextract_camtasia'}) {
6560: $output .= &remove_archive($docudom,$docuname,$container);
6561: }
1.476 raeburn 6562: }
6563: if ($error) {
6564: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6565: $error.'</p>'."\n";
6566: }
6567: if ($warning) {
6568: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6569: }
6570: return $output;
6571: }
6572:
6573: sub decompression_phase_two {
6574: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6575: &decompression_info();
1.481 raeburn 6576: my $output;
1.480 raeburn 6577: if ($env{'form.archivedelete'}) {
1.481 raeburn 6578: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6579: }
6580: $output .=
1.481 raeburn 6581: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6582: $destination,$dir_root,$hiddenelem);
6583: return $output;
6584: }
6585:
1.480 raeburn 6586: sub remove_archive {
6587: my ($docudom,$docuname,$container) = @_;
6588: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6589: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6590: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6591: if ($fatal) {
6592: if ($container eq 'page') {
6593: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6594: } else {
6595: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6596: }
1.583 raeburn 6597: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6598: } else {
6599: my $currcmd = $env{'form.cmd'};
6600: my $position = $env{'form.position'};
1.583 raeburn 6601: my $archiveidx = $position;
1.563 raeburn 6602: if ($position > 0) {
1.583 raeburn 6603: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6604: $archiveidx = $position-1;
6605: }
6606: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6607: my ($title,$url,@rrest) =
1.583 raeburn 6608: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6609: if ($url eq $env{'form.archiveurl'}) {
6610: if (&handle_edit_cmd($docuname,$docudom)) {
6611: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6612: if ($fatal) {
6613: if ($container eq 'page') {
6614: $delwarning = &mt('An error occurred updating the contents of the current page.');
6615: } else {
6616: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6617: }
1.480 raeburn 6618: } else {
1.583 raeburn 6619: $delresult = &mt('Archive file removed.');
1.480 raeburn 6620: }
6621: }
1.583 raeburn 6622: } else {
6623: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6624: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6625: }
6626: }
6627: $env{'form.cmd'} = $currcmd;
6628: }
6629: if ($delwarning) {
6630: $output = '<p class="LC_warning">'.
6631: $delwarning.
6632: '</p>';
6633: }
6634: if ($delresult) {
6635: $output .= '<p class="LC_info">'.
6636: $delresult.
6637: '</p>';
6638: }
1.481 raeburn 6639: return $output;
1.480 raeburn 6640: }
6641:
1.484 raeburn 6642: sub generate_admin_menu {
1.611 raeburn 6643: my ($crstype,$canedit) = @_;
1.484 raeburn 6644: my $lc_crstype = lc($crstype);
6645: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6646: my %lt= ( # do not translate here
1.484 raeburn 6647: 'vc' => 'Verify Content',
6648: 'cv' => 'Check/Set Resource Versions',
6649: 'ls' => 'List Resource Identifiers',
6650: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6651: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6652: );
1.484 raeburn 6653: my ($candump,$dumpurl);
6654: if ($home + $other > 0) {
6655: $candump = 'F';
6656: if ($home) {
6657: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6658: } else {
6659: my @hosts;
6660: foreach my $aurole (keys(%outhash)) {
6661: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6662: push(@hosts,$outhash{$aurole});
1.538 raeburn 6663: }
1.484 raeburn 6664: }
6665: if (@hosts == 1) {
6666: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6667: '&role='.
6668: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6669: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6670: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6671: } else {
6672: $dumpurl = "javascript:choose_switchserver_window()";
6673: }
6674: }
6675: }
6676: my @menu=
6677: ({ categorytitle=>'Administration',
6678: items =>[
6679: { linktext => $lt{'vc'},
6680: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6681: permission => 'F',
1.571 raeburn 6682: help => 'Docs_Verify_Content',
1.484 raeburn 6683: icon => 'verify.png',
6684: linktitle => 'Verify contents can be retrieved/rendered',
6685: },
6686: { linktext => $lt{'cv'},
6687: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6688: permission => 'F',
1.571 raeburn 6689: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6690: icon => 'resversion.png',
6691: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6692: },
6693: { linktext => $lt{'ls'},
6694: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6695: permission => 'F',
6696: #help => '',
6697: icon => 'symbs.png',
6698: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6699: },
6700: ]
1.611 raeburn 6701: });
6702: if ($canedit) {
6703: push(@menu,
1.484 raeburn 6704: { categorytitle=>'Export',
6705: items =>[
6706: { linktext => $lt{'imse'},
6707: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6708: permission => 'F',
6709: help => 'Docs_Export_Course_Docs',
6710: icon => 'imsexport.png',
6711: linktitle => $lt{'imse'},
6712: },
6713: { linktext => $lt{'dcd'},
6714: url => $dumpurl,
6715: permission => $candump,
1.571 raeburn 6716: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6717: icon => 'dump.png',
6718: linktitle => $lt{'dcd'},
6719: },
6720: ]
6721: });
1.611 raeburn 6722: }
1.484 raeburn 6723: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6724: '<input type="hidden" id="dummy" />'."\n".
6725: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6726: '</form>';
1.329 droeschl 6727: }
6728:
6729: sub generate_edit_table {
1.538 raeburn 6730: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6731: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6732: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6733: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6734: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6735: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6736: $activetab = $env{'form.active'};
6737: }
1.611 raeburn 6738: unless ($canedit) {
6739: $disabled = ' disabled="disabled"';
6740: }
1.472 raeburn 6741: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6742: my $backtext = &mt('Exit Editor');
1.458 raeburn 6743: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6744: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6745: '<li class="goback">'.
1.546 raeburn 6746: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6747: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6748: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6749: '<li>'.
6750: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6751: &mt('Undo Delete').'</a></li>'."\n";
6752: if ($env{'form.docslog'}) {
6753: $form .= '<li class="active">';
6754: } else {
6755: $form .= '<li>';
6756: }
6757: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6758: &mt('History').'</a></li>'."\n";
6759: if ($env{'form.docslog'}) {
6760: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6761: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6762: }
1.458 raeburn 6763: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6764: if($name ne '00'){
1.371 tempelho 6765: if($activetab eq '' || $activetab ne $name){
6766: $active = '';
6767: }elsif($activetab eq $name){
6768: $active = 'class="active"';
6769: }
1.458 raeburn 6770: $form .= '<li style="float:right" '.$active
1.484 raeburn 6771: .' 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 6772: } else {
1.570 raeburn 6773: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6774:
6775: }
1.329 droeschl 6776: }
1.484 raeburn 6777: $form .= '</ul>'."\n";
6778: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6779:
6780: if ($to_show ne '') {
1.538 raeburn 6781: my $saveform;
6782: if ($need_save) {
6783: my $button = &mt('Make changes');
6784: my $path;
6785: if ($env{'form.folderpath'}) {
6786: $path =
6787: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6788: }
6789: $saveform = <<"END";
6790: <div id="multisave" style="display:none; clear:both;" >
6791: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6792: <input type="hidden" name="folderpath" value="$path" />
6793: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6794: <input type="hidden" name="allhiddenresource" value="" />
6795: <input type="hidden" name="allencrypturl" value="" />
6796: <input type="hidden" name="allrandompick" value="" />
6797: <input type="hidden" name="allrandomorder" value="" />
6798: <input type="hidden" name="changeparms" value="" />
6799: <input type="hidden" name="multiremove" value="" />
6800: <input type="hidden" name="multicut" value="" />
6801: <input type="hidden" name="multicopy" value="" />
6802: <input type="hidden" name="multichange" value="" />
6803: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 6804: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 6805: </form>
6806: </div>
6807: END
6808: }
6809: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6810: }
1.363 ehlerst 6811: foreach my $field (keys(%orderhash)){
1.390 tempelho 6812: if($field ne '00'){
1.422 onken 6813: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6814: $active = 'style="display: none;float:left"';
1.422 onken 6815: }elsif($activetab eq $field){
1.458 raeburn 6816: $active = 'style="display:block;float:left"';
1.422 onken 6817: }
6818: $form .= '<div id="'.$field.$tid.'"'
6819: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6820: .'</div>'."\n";
1.363 ehlerst 6821: }
6822: }
1.484 raeburn 6823: unless ($env{'form.docslog'}) {
6824: $form .= '</div></div>'."\n";
6825: }
1.329 droeschl 6826: return $form;
6827: }
6828:
6829: sub editing_js {
1.622 raeburn 6830: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
6831: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 6832: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6833: p_mnf => 'Name of New Folder',
6834: t_mnf => 'New Folder',
6835: p_mnp => 'Name of New Page',
6836: t_mnp => 'New Page',
1.451 www 6837: p_mxu => 'Title for the External Score',
1.349 biermanm 6838: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6839: p_msb => 'Title for the Problem',
6840: p_mdb => 'Title for the Drop Box',
1.336 schafran 6841: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 6842: p_mwp => 'Title for Web Page',
1.606 raeburn 6843: p_mnr => 'Title for the Resource',
1.348 weissno 6844: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6845: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6846: p_mab_alrt1 => 'Not a valid user:domain',
6847: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6848: p_chn => 'New Title',
6849: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 6850: p_rmr2a => 'Remove',
6851: p_rmr2b => '?',
6852: p_rmr3a => 'Remove those',
6853: p_rmr3b => 'items?',
6854: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6855: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6856: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6857: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 6858: p_ctr2a => 'Cut',
6859: p_ctr2b => '?',
6860: p_ctr3a => 'Cut those',
6861: p_ctr3b => 'items?',
1.478 raeburn 6862: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6863: imsfile => 'You must choose an IMS package for import',
6864: imscms => 'You must select which Course Management System was the source of the IMS package',
6865: invurl => 'Invalid URL',
6866: titbl => 'Title is blank',
1.538 raeburn 6867: more => '(More ...)',
6868: less => '(Less ...)',
1.543 raeburn 6869: noor => 'No actions selected or changes to settings specified.',
6870: noch => 'No changes to settings specified.',
6871: noac => 'No actions selected.',
1.606 raeburn 6872: nofi => 'No file selected',
6873: tinc => 'Title in course',
6874: sunm => 'Sub-directory name',
1.618 raeburn 6875: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6876: );
1.594 damieng 6877: &js_escape(\%js_lt);
1.433 raeburn 6878: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6879: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6880: my $main_container_page;
1.519 raeburn 6881: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6882: $main_container_page = 1;
1.434 raeburn 6883: }
1.617 raeburn 6884: my $backtourl;
6885: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6886: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6887:
1.530 raeburn 6888: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6889: my $caller = $1;
1.525 raeburn 6890: if ($caller =~ /^supplemental/) {
6891: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6892: } else {
6893: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6894: $res = &Apache::lonnet::clutter($res);
6895: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 6896: my ($url,$anchor);
6897: if ($res =~ /^([^#]+)#([^#]+)$/) {
6898: $url = $1;
6899: $anchor = $2;
6900: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6901: $caller = $1.&escape('#').$anchor;
6902: }
1.614 raeburn 6903: } else {
6904: $url = $res;
1.609 raeburn 6905: }
6906: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 6907: &HTML::Entities::encode($caller,'<>&"');
1.622 raeburn 6908: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6909: if (($ENV{'SERVER_PORT'} == 443) &&
6910: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6911: if ($hostname ne '') {
6912: $backtourl = 'http://'.$hostname.$backtourl;
6913: }
6914: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6915: }
1.623 raeburn 6916: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6917: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6918: $backtourl = 'http://'.$hostname.$backtourl;
6919: }
1.622 raeburn 6920: }
1.609 raeburn 6921: if ($anchor ne '') {
6922: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6923: }
1.590 raeburn 6924: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6925: } else {
6926: $backtourl = '/adm/navmaps';
1.525 raeburn 6927: }
6928: }
6929: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6930: $backtourl = '/adm/menu';
6931: } elsif ($supplementalflag) {
1.472 raeburn 6932: $backtourl = '/adm/supplemental';
1.525 raeburn 6933: } else {
6934: $backtourl = '/adm/navmaps';
1.472 raeburn 6935: }
6936:
1.600 raeburn 6937: my $fieldsets = "'ext','doc'";
6938: if ($posslti) {
6939: $fieldsets .= ",'tool'";
6940: }
1.519 raeburn 6941: unless ($main_container_page) {
6942: $fieldsets .=",'ims'";
6943: }
1.501 raeburn 6944: if ($supplementalflag) {
1.600 raeburn 6945: $fieldsets = "'suppext','suppdoc'";
6946: if ($posslti) {
6947: $fieldsets .= ",'supptool'";
6948: }
1.501 raeburn 6949: }
1.611 raeburn 6950:
6951: my $jsmakefunctions;
6952: if ($canedit) {
6953: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6954: function makenewfolder(targetform,folderseq) {
1.594 damieng 6955: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6956: if (foldername) {
6957: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6958: targetform.submit();
6959: }
6960: }
6961:
6962: function makenewpage(targetform,folderseq) {
1.594 damieng 6963: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6964: if (pagename) {
6965: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6966: targetform.submit();
6967: }
6968: }
6969:
6970: function makeexamupload() {
1.594 damieng 6971: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6972: if (title) {
1.329 droeschl 6973: this.document.forms.newexamupload.importdetail.value=
6974: escape(title)+'=/res/lib/templates/examupload.problem';
6975: this.document.forms.newexamupload.submit();
6976: }
6977: }
6978:
6979: function makesmppage() {
1.594 damieng 6980: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6981: if (title) {
1.329 droeschl 6982: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 6983: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6984: this.document.forms.newsmppg.submit();
6985: }
6986: }
6987:
1.534 raeburn 6988: function makewebpage(type) {
1.594 damieng 6989: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 6990: var formname;
6991: if (type == 'supp') {
6992: formname = this.document.forms.supwebpage;
6993: } else {
6994: formname = this.document.forms.newwebpage;
6995: }
6996: if (title) {
6997: var webpage = formname.importdetail.value;
6998: formname.importdetail.value = escape(title)+'='+webpage;
6999: formname.submit();
7000: }
7001: }
7002:
1.329 droeschl 7003: function makesmpproblem() {
1.594 damieng 7004: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7005: if (title) {
1.329 droeschl 7006: this.document.forms.newsmpproblem.importdetail.value=
7007: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7008: this.document.forms.newsmpproblem.submit();
7009: }
7010: }
7011:
7012: function makedropbox() {
1.594 damieng 7013: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7014: if (title) {
1.329 droeschl 7015: this.document.forms.newdropbox.importdetail.value=
7016: escape(title)+'=/res/lib/templates/DropBox.problem';
7017: this.document.forms.newdropbox.submit();
7018: }
7019: }
7020:
7021: function makebulboard() {
1.594 damieng 7022: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7023: if (title) {
7024: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7025: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7026: this.document.forms.newbul.submit();
7027: }
7028: }
7029:
7030: function makeabout() {
1.594 damieng 7031: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7032: if (user) {
7033: var comp=new Array();
7034: comp=user.split(':');
7035: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7036: if ((comp[0]) && (comp[1])) {
7037: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7038: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7039: this.document.forms.newaboutsomeone.submit();
7040: } else {
7041: alert("$js_lt{'p_mab_alrt1'}");
7042: }
7043: } else {
7044: alert("$js_lt{'p_mab_alrt2'}");
7045: }
7046: }
7047: }
7048:
7049: function makenew(targetform) {
7050: targetform.submit();
7051: }
7052:
7053: function changename(folderpath,index,oldtitle) {
7054: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7055: if (title) {
7056: this.document.forms.renameform.markcopy.value='';
7057: this.document.forms.renameform.title.value=title;
7058: this.document.forms.renameform.cmd.value='rename_'+index;
7059: this.document.forms.renameform.folderpath.value=folderpath;
7060: this.document.forms.renameform.submit();
7061: }
7062: }
7063:
7064: ENDNEWSCRIPT
7065: } else {
7066: $jsmakefunctions = <<ENDNEWSCRIPT;
7067:
7068: function makenewfolder() {
7069: alert("$js_lt{'edri'}");
7070: }
7071:
7072: function makenewpage() {
7073: alert("$js_lt{'edri'}");
7074: }
7075:
7076: function makeexamupload() {
7077: alert("$js_lt{'edri'}");
7078: }
7079:
7080: function makesmppage() {
7081: alert("$js_lt{'edri'}");
7082: }
7083:
7084: function makewebpage(type) {
7085: alert("$js_lt{'edri'}");
7086: }
7087:
7088: function makesmpproblem() {
7089: alert("$js_lt{'edri'}");
7090: }
7091:
7092: function makedropbox() {
7093: alert("$js_lt{'edri'}");
7094: }
7095:
7096: function makebulboard() {
7097: alert("$js_lt{'edri'}");
7098: }
7099:
7100: function makeabout() {
7101: alert("$js_lt{'edri'}");
7102: }
7103:
7104: function changename() {
7105: alert("$js_lt{'edri'}");
7106: }
7107:
7108: function makenew() {
7109: alert("$js_lt{'edri'}");
7110: }
7111:
7112: function groupimport() {
7113: alert("$js_lt{'edri'}");
1.335 ehlerst 7114: }
1.611 raeburn 7115:
7116: function groupsearch() {
7117: alert("$js_lt{'edri'}");
1.335 ehlerst 7118: }
1.611 raeburn 7119:
7120: function groupopen(url,recover) {
7121: var options="scrollbars=1,resizable=1,menubar=0";
7122: idxflag=1;
7123: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7124: idx.focus();
1.329 droeschl 7125: }
7126:
1.611 raeburn 7127: ENDNEWSCRIPT
7128:
7129: }
7130: return <<ENDSCRIPT;
7131:
7132: $jsmakefunctions
7133:
1.501 raeburn 7134: function toggleUpload(caller) {
7135: var blocks = Array($fieldsets);
7136: for (var i=0; i<blocks.length; i++) {
7137: var disp = 'none';
7138: if (caller == blocks[i]) {
7139: var curr = document.getElementById('upload'+caller+'form').style.display;
7140: if (curr == 'none') {
7141: disp='block';
7142: }
7143: }
7144: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7145: if ((caller == 'tool') || (caller == 'supptool')) {
7146: if (disp == 'block') {
7147: if (document.getElementById('LC_exttoolid')) {
7148: var toolselector = document.getElementById('LC_exttoolid');
7149: var suppflag = 0;
7150: if (caller == 'supptool') {
7151: suppflag = 1;
7152: }
7153: currForm = document.getElementById('new'+caller);
7154: updateExttool(toolselector,currForm,suppflag);
7155: }
7156: }
7157: }
1.501 raeburn 7158: }
1.502 raeburn 7159: resize_scrollbox('contentscroll','1','1');
7160: return;
7161: }
7162:
1.514 raeburn 7163: function toggleMap(caller) {
1.502 raeburn 7164: var disp = 'none';
1.510 raeburn 7165: if (document.getElementById('importmapform')) {
1.514 raeburn 7166: if (caller == 'map') {
7167: var curr = document.getElementById('importmapform').style.display;
7168: if (curr == 'none') {
7169: disp='block';
7170: }
1.510 raeburn 7171: }
7172: document.getElementById('importmapform').style.display=disp;
7173: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7174: }
1.501 raeburn 7175: return;
1.329 droeschl 7176: }
7177:
1.606 raeburn 7178: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7179: var disp = 'none';
7180: if (document.getElementById('crsresform')) {
7181: if (caller == 'res') {
7182: var curr = document.getElementById('crsresform').style.display;
7183: if (curr == 'none') {
7184: disp='block';
7185: numauthor = parseInt(numauthorrole);
7186: if (numauthor > 0) {
7187: document.courseresform.authorrole.selectedIndex = 0;
7188: select1priv_changed();
7189: document.courseresform.authorpath.selectedIndex = 0;
7190: document.courseresform.newresourceadd.selectedIndex = 0;
7191: toggleNewInCourse(document.courseresform);
7192: if (document.getElementById('newresource')) {
7193: document.getElementById('newresource').style.display = 'none';
7194: }
7195: } else {
7196: if (numcrsdirs) {
7197: document.courseresform.authorpath.selectedIndex = 0;
7198: }
7199: }
7200: if (document.courseresform.newresusetemp.length) {
7201: document.courseresform.newresusetemp[0].checked = true;
7202: toggleWithTemplate(document.courseresform);
7203: }
7204: document.courseresform.newresourcename.value = '';
7205: }
7206: }
7207: if (document.courseresform.newsubdir.length) {
7208: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7209: if (document.courseresform.newsubdir[j].value == 0) {
7210: document.courseresform.newsubdir[j].checked = true;
7211: }
7212: break;
7213: }
7214: if (document.getElementById('newsubdirname')) {
7215: document.getElementById('newsubdirname').type = "hidden";
7216: document.getElementById('newsubdirname').value = "";
7217: }
7218: if (document.getElementById('newsubdir')) {
7219: document.getElementById('newsubdir').innerHTML = "";
7220: }
7221: }
7222: document.getElementById('crsresform').style.display=disp;
7223: resize_scrollbox('contentscroll','1','0');
7224: }
7225: return;
7226: }
7227:
7228: function toggleNewsubdir(form) {
7229: if (form.newsubdir.length) {
7230: for (var j=0; j<form.newsubdir.length; j++) {
7231: if (form.newsubdir[j].checked) {
7232: if (document.getElementById('newsubdirname')) {
7233: if (form.newsubdir[j].value == '1') {
7234: document.getElementById('newsubdirname').type = "text";
7235: if (document.getElementById('newsubdir')) {
7236: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7237: }
7238: } else {
7239: document.getElementById('newsubdirname').type = "hidden";
7240: document.getElementById('newsubdirname').value = "";
7241: document.getElementById('newsubdir').innerHTML = "";
7242: }
7243: }
7244: break;
7245: }
7246: }
7247: }
7248: }
7249:
7250: function toggleCrsResTitle() {
7251: if (document.getElementById('newresource')) {
7252: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7253: document.getElementById('newresource').style.display = 'inline';
7254: document.courseresform.newresourceadd[0].checked = true;
7255: toggleNewInCourse(document.courseresform);
7256: } else {
7257: document.getElementById('newresource').style.display = 'none';
7258: }
7259: }
7260: }
7261:
7262: function toggleNewInCourse(form) {
7263: if (form.newresourceadd.length) {
7264: for (var i=0; i<form.newresourceadd.length; i++) {
7265: if (form.newresourceadd[i].checked) {
7266: if (document.getElementById('newresourcetitle')) {
7267: if (form.newresourceadd[i].value == '1') {
7268: document.getElementById('newresourcetitle').type = 'text';
7269: if (document.getElementById('newrestitle')) {
7270: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7271: }
7272: } else {
7273: document.getElementById('newresourcetitle').type = 'hidden';
7274: document.getElementById('newresourcetitle').value = '';
7275: if (document.getElementById('newrestitle')) {
7276: document.getElementById('newrestitle').innerHTML = '';
7277: }
7278: }
7279: }
7280: break;
7281: }
7282: }
7283: }
7284: }
7285:
7286: function toggleWithTemplate(form) {
7287: if (form.newresusetemp.length) {
7288: for (var i=0; i<form.newresusetemp.length; i++) {
7289: if (form.newresusetemp[i].checked) {
7290: if (document.getElementById('newrestemplate')) {
7291: if (form.newresusetemp[i].value == '1') {
7292: document.getElementById('newrestemplate').style.display = 'inline';
7293: toggleExampleText();
7294: } else {
7295: form.tempcategory.selectedIndex = 0;
7296: select1template_changed();
7297: document.getElementById('newrestemplate').style.display = 'none';
7298: }
7299: }
7300: }
7301: }
7302: }
7303: }
7304:
7305: function toggleExampleText() {
7306: if (document.getElementById('newresexample')) {
7307: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7308: if (url == '') {
7309: document.getElementById('newresexample').style.fontWeight = 'normal';
7310: } else {
7311: document.getElementById('newresexample').style.fontWeight = 'bold';
7312: }
7313: }
7314: }
7315:
7316: function getExample(width,height,scrolling,transparency) {
7317: var url;
7318: if (document.courseresform.newresusetemp.length) {
7319: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7320: if (document.courseresform.newresusetemp[i].checked) {
7321: if (document.courseresform.newresusetemp[i].value == '1') {
7322: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7323: if (url == '') {
7324: alert('Pick a category and template');
7325: } else {
7326: url = url.replace("$londocroot","");
7327: url += '?inhibitmenu=yes';
7328: }
7329: }
7330: break;
7331: }
7332: }
7333: }
7334: if (url != '') {
7335: openMyModal(url,width,height,scrolling,transparency,'');
7336: }
7337: }
7338:
7339: function toggleImportCrsres(caller,dircount) {
7340: var disp = 'none';
7341: if (document.getElementById('importcrsresform')) {
7342: if (caller == 'res') {
7343: var numdirs = parseInt(dircount);
7344: var curr = document.getElementById('importcrsresform').style.display;
7345: if (curr == 'none') {
7346: disp='block';
7347: if (numdirs > 1) {
7348: select1res_changed();
7349: }
7350: }
7351: }
7352: document.getElementById('importcrsresform').style.display=disp;
7353: resize_scrollbox('contentscroll','1','0');
7354: }
7355: return;
7356: }
7357:
1.501 raeburn 7358: function makeims(imsform) {
7359: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7360: alert("$js_lt{'imsfile'}");
1.501 raeburn 7361: return;
7362: }
7363: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7364: alert("$js_lt{'imscms'}");
1.501 raeburn 7365: return;
7366: }
7367: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7368: imsform.submit();
7369: }
7370:
1.478 raeburn 7371: function updatePick(targetform,index,caller) {
1.537 raeburn 7372: var pickitem;
7373: var picknumitem;
7374: var picknumtext;
7375: if (index == 'all') {
7376: pickitem = document.getElementById('randompickall');
7377: picknumitem = document.getElementById('rpicknumall');
7378: picknumtext = document.getElementById('rpicktextall');
7379: } else {
7380: pickitem = document.getElementById('randompick_'+index);
7381: picknumitem = document.getElementById('rpicknum_'+index);
7382: picknumtext = document.getElementById('randompicknum_'+index);
7383: }
1.478 raeburn 7384: if (pickitem.checked) {
1.594 damieng 7385: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7386: if (picknum == '' || picknum == null) {
7387: if (caller == 'check') {
7388: pickitem.checked=false;
1.537 raeburn 7389: if (index == 'all') {
7390: picknumtext.innerHTML = '';
7391: if (caller == 'link') {
7392: propagateState(targetform,'rpicknum');
7393: }
7394: } else {
1.538 raeburn 7395: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7396: }
1.478 raeburn 7397: }
7398: } else {
7399: picknum.toString();
7400: var regexdigit=/^\\d+\$/;
7401: if (regexdigit.test(picknum)) {
7402: picknumitem.value = picknum;
1.537 raeburn 7403: if (index == 'all') {
1.538 raeburn 7404: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7405: if (caller == 'link') {
7406: propagateState(targetform,'rpicknum');
7407: }
7408: } else {
7409: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7410: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7411: }
1.478 raeburn 7412: } else {
7413: if (caller == 'check') {
1.537 raeburn 7414: if (index == 'all') {
7415: picknumtext.innerHTML = '';
7416: if (caller == 'link') {
7417: propagateState(targetform,'rpicknum');
7418: }
7419: } else {
7420: pickitem.checked=false;
1.538 raeburn 7421: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7422: }
1.478 raeburn 7423: }
7424: return;
7425: }
7426: }
7427: } else {
1.537 raeburn 7428: picknumitem.value = '';
7429: picknumtext.innerHTML = '';
7430: if (index == 'all') {
7431: if (caller == 'link') {
7432: propagateState(targetform,'rpicknum');
7433: }
7434: } else {
1.538 raeburn 7435: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7436: }
7437: }
7438: }
7439:
7440: function propagateState(form,param) {
7441: if (document.getElementById(param+'all')) {
7442: var setcheck = 0;
7443: var rpick = 0;
7444: if (param == 'rpicknum') {
7445: if (document.getElementById('randompickall')) {
7446: if (document.getElementById('randompickall').checked) {
7447: if (document.getElementById('rpicknumall')) {
7448: rpick = document.getElementById('rpicknumall').value;
7449: }
7450: }
7451: }
7452: } else {
7453: if (document.getElementById(param+'all').checked) {
7454: setcheck = 1;
7455: }
7456: }
1.538 raeburn 7457: var allidxlist;
7458: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7459: if (document.getElementById('all'+param+'idx')) {
7460: allidxlist = document.getElementById('all'+param+'idx').value;
7461: }
7462: var actions = new Array ('remove','cut','copy');
7463: for (var i=0; i<actions.length; i++) {
7464: if (actions[i] != param) {
7465: if (document.getElementById(actions[i]+'all')) {
7466: document.getElementById(actions[i]+'all').checked = false;
7467: }
7468: }
7469: }
7470: }
1.537 raeburn 7471: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7472: allidxlist = form.allidx.value;
7473: }
7474: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7475: allidxlist = form.allmapidx.value;
7476: }
7477: if ((allidxlist != '') && (allidxlist != null)) {
7478: var allidxs = allidxlist.split(',');
7479: if (allidxs.length > 1) {
7480: for (var i=0; i<allidxs.length; i++) {
7481: if (document.getElementById(param+'_'+allidxs[i])) {
7482: if (param == 'rpicknum') {
7483: if (document.getElementById('randompick_'+allidxs[i])) {
7484: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7485: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7486: if (rpick > 0) {
7487: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7488: } else {
7489: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7490: }
7491: }
7492: }
7493: } else {
1.537 raeburn 7494: if (setcheck == 1) {
7495: document.getElementById(param+'_'+allidxs[i]).checked = true;
7496: } else {
7497: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7498: if (param == 'randompick') {
7499: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7500: }
1.537 raeburn 7501: }
7502: }
7503: }
7504: }
1.538 raeburn 7505: if (setcheck == 1) {
7506: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7507: var actions = new Array('copy','cut','remove');
7508: for (var i=0; i<actions.length; i++) {
7509: var otheractions;
7510: var otheridxs;
7511: if (actions[i] === param) {
7512: continue;
7513: } else {
7514: if (document.getElementById('all'+actions[i]+'idx')) {
7515: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7516: otheridxs = otheractions.split(',');
7517: if (otheridxs.length > 1) {
7518: for (var j=0; j<otheridxs.length; j++) {
7519: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7520: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7521: }
1.537 raeburn 7522: }
7523: }
7524: }
1.538 raeburn 7525: }
7526: }
7527: }
7528: }
7529: }
7530: }
7531: }
7532: return;
7533: }
7534:
1.603 raeburn 7535: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7536: var canedit = '$canedit';
7537: if (canedit == '') {
7538: alert("$js_lt{'edri'}");
7539: return;
7540: }
1.539 raeburn 7541: var dosettings;
7542: var doaction;
1.538 raeburn 7543: var control = document.togglemultsettings;
7544: if (context == 'actions') {
7545: control = document.togglemultactions;
1.539 raeburn 7546: doaction = 1;
7547: } else {
7548: dosettings = 1;
1.538 raeburn 7549: }
1.539 raeburn 7550: if (control) {
7551: if (control.showmultpick.length) {
7552: for (var i=0; i<control.showmultpick.length; i++) {
7553: if (control.showmultpick[i].checked) {
7554: if (control.showmultpick[i].value == 1) {
7555: if (context == 'settings') {
7556: dosettings = 0;
7557: } else {
7558: doaction = 0;
1.538 raeburn 7559: }
7560: }
7561: }
1.537 raeburn 7562: }
7563: }
1.539 raeburn 7564: }
7565: if (context == 'settings') {
7566: if (dosettings == 1) {
1.538 raeburn 7567: targetform.changeparms.value=param;
7568: targetform.submit();
7569: }
1.537 raeburn 7570: }
1.539 raeburn 7571: if (context == 'actions') {
7572: if (doaction == 1) {
7573: targetform.cmd.value=param+'_'+index;
7574: targetform.folderpath.value=folderpath;
7575: targetform.markcopy.value=idx+':'+param;
7576: targetform.copyfolder.value=folder+'.'+container;
7577: if (param == 'remove') {
1.603 raeburn 7578: var doremove = 0;
7579: if (skip_confirm) {
7580: if (confirm_removal) {
7581: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7582: doremove = 1;
7583: }
7584: } else {
7585: doremove = 1;
7586: }
7587: } else {
7588: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7589: doremove = 1;
7590: }
7591: }
7592: if (doremove) {
1.539 raeburn 7593: targetform.markcopy.value='';
7594: targetform.copyfolder.value='';
7595: targetform.submit();
7596: }
7597: }
7598: if (param == 'cut') {
1.594 damieng 7599: 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.539 raeburn 7600: targetform.submit();
7601: return;
7602: }
7603: }
7604: if (param == 'copy') {
7605: targetform.submit();
7606: return;
7607: }
7608: targetform.markcopy.value='';
7609: targetform.copyfolder.value='';
7610: targetform.cmd.value='';
7611: targetform.folderpath.value='';
7612: return;
7613: } else {
7614: if (document.getElementById(param+'_'+idx)) {
7615: item = document.getElementById(param+'_'+idx);
7616: if (item.type == 'checkbox') {
7617: if (item.checked) {
7618: item.checked = false;
7619: } else {
7620: item.checked = true;
7621: singleCheck(item,idx,param);
7622: }
7623: }
7624: }
7625: }
7626: }
1.537 raeburn 7627: return;
7628: }
7629:
1.538 raeburn 7630: function singleCheck(caller,idx,action) {
7631: actions = new Array('cut','copy','remove');
7632: if (caller.checked) {
7633: for (var i=0; i<actions.length; i++) {
7634: if (actions[i] != action) {
7635: if (document.getElementById(actions[i]+'_'+idx)) {
7636: if (document.getElementById(actions[i]+'_'+idx).checked) {
7637: document.getElementById(actions[i]+'_'+idx).checked = false;
7638: }
1.537 raeburn 7639: }
7640: }
7641: }
1.478 raeburn 7642: }
1.537 raeburn 7643: return;
1.478 raeburn 7644: }
7645:
1.334 muellerd 7646: function unselectInactive(nav) {
1.335 ehlerst 7647: currentNav = document.getElementById(nav);
7648: currentLis = currentNav.getElementsByTagName('LI');
7649: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7650: if (currentLis[i].className == 'goback') {
7651: currentLis[i].className = 'goback';
7652: } else {
7653: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7654: currentLis[i].className = 'right';
1.472 raeburn 7655: } else {
1.374 tempelho 7656: currentLis[i].className = 'i';
1.472 raeburn 7657: }
7658: }
1.335 ehlerst 7659: }
1.332 tempelho 7660: }
7661:
1.334 muellerd 7662: function hideAll(current, nav, data) {
1.335 ehlerst 7663: unselectInactive(nav);
1.570 raeburn 7664: if (current) {
7665: if (current.className == 'right'){
7666: current.className = 'right active'
7667: } else {
7668: current.className = 'active';
7669: }
1.374 tempelho 7670: }
1.335 ehlerst 7671: currentData = document.getElementById(data);
7672: currentDivs = currentData.getElementsByTagName('DIV');
7673: for (i = 0; i < currentDivs.length; i++) {
7674: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7675: currentDivs[i].style.display = 'none';
1.330 tempelho 7676: }
7677: }
1.335 ehlerst 7678: }
1.330 tempelho 7679:
1.374 tempelho 7680: function openTabs(pageId) {
7681: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7682: if(tabnav.length > 2 ){
1.389 tempelho 7683: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7684: currentLis = currentNav.getElementsByTagName('LI');
7685: for(i = 0; i< currentLis.length; i++){
7686: if(currentLis[i].className == 'active') {
1.375 tempelho 7687: funcString = currentLis[i].onclick.toString();
7688: tab = funcString.split('"');
1.420 onken 7689: if(tab.length < 2) {
7690: tab = funcString.split("'");
7691: }
1.375 tempelho 7692: currentData = document.getElementById(tab[1]);
7693: currentData.style.display = 'block';
1.374 tempelho 7694: }
7695: }
7696: }
7697: }
7698:
1.334 muellerd 7699: function showPage(current, pageId, nav, data) {
1.570 raeburn 7700: currstate = current.className;
1.334 muellerd 7701: hideAll(current, nav, data);
1.375 tempelho 7702: openTabs(pageId);
1.334 muellerd 7703: unselectInactive(nav);
1.570 raeburn 7704: if ((currstate == 'active') || (currstate == 'right active')) {
7705: if (currstate == 'active') {
7706: current.className = '';
7707: } else {
7708: current.className = 'right';
7709: }
7710: activeTab = '';
7711: toggleUpload();
7712: toggleMap();
1.606 raeburn 7713: toggleCrsRes();
7714: toggleImportCrsres();
1.570 raeburn 7715: resize_scrollbox('contentscroll','1','0');
7716: return;
7717: } else {
7718: current.className = 'active';
7719: }
1.330 tempelho 7720: currentData = document.getElementById(pageId);
7721: currentData.style.display = 'block';
1.458 raeburn 7722: activeTab = pageId;
1.501 raeburn 7723: toggleUpload();
1.503 raeburn 7724: toggleMap();
1.606 raeburn 7725: toggleCrsRes();
7726: toggleImportCrsres();
1.433 raeburn 7727: if (nav == 'mainnav') {
7728: var storedpath = "$docs_folderpath";
1.434 raeburn 7729: var storedpage = "$main_container_page";
1.433 raeburn 7730: var reg = new RegExp("^supplemental");
7731: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7732: if (storedpage == 1) {
7733: document.simpleedit.folderpath.value = '';
7734: document.uploaddocument.folderpath.value = '';
7735: } else {
7736: if (reg.test(storedpath)) {
7737: document.simpleedit.folderpath.value = '$toplevelmain';
7738: document.uploaddocument.folderpath.value = '$toplevelmain';
7739: document.newext.folderpath.value = '$toplevelmain';
7740: } else {
7741: document.simpleedit.folderpath.value = storedpath;
7742: document.uploaddocument.folderpath.value = storedpath;
7743: document.newext.folderpath.value = storedpath;
7744: }
1.433 raeburn 7745: }
7746: } else {
1.434 raeburn 7747: if (reg.test(storedpath)) {
7748: document.simpleedit.folderpath.value = storedpath;
7749: document.supuploaddocument.folderpath.value = storedpath;
7750: document.supnewext.folderpath.value = storedpath;
7751: } else {
1.433 raeburn 7752: document.simpleedit.folderpath.value = '$toplevelsupp';
7753: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7754: document.supnewext.folderpath.value = '$toplevelsupp';
7755: }
7756: }
7757: }
1.485 raeburn 7758: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7759: return false;
7760: }
1.329 droeschl 7761:
1.472 raeburn 7762: function toContents(jumpto) {
7763: var newurl = '$backtourl';
1.525 raeburn 7764: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7765: newurl = newurl+'?postdata='+jumpto;
7766: }
7767: location.href=newurl;
7768: }
7769:
1.538 raeburn 7770: function togglePick(caller,value) {
7771: var disp = 'none';
7772: if (document.getElementById('multi'+caller)) {
7773: var curr = document.getElementById('multi'+caller).style.display;
7774: if (value == 1) {
7775: disp='block';
7776: }
7777: if (curr == disp) {
7778: return;
7779: }
7780: document.getElementById('multi'+caller).style.display=disp;
7781: if (value == 1) {
1.594 damieng 7782: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7783: } else {
7784: document.getElementById('more'+caller).innerHTML = '';
7785: }
7786: if (caller == 'actions') {
7787: setClass(value);
7788: setBoxes(value);
7789: }
7790: }
7791: var showButton = multiSettings();
7792: if (showButton != 1) {
7793: showButton = multiActions();
7794: }
7795: if (document.getElementById('multisave')) {
7796: if (showButton == 1) {
7797: document.getElementById('multisave').style.display='block';
7798: } else {
7799: document.getElementById('multisave').style.display='none';
7800: }
7801: }
7802: resize_scrollbox('contentscroll','1','1');
7803: return;
7804: }
7805:
7806: function toggleCheckUncheck(caller,more) {
7807: if (more == 1) {
1.594 damieng 7808: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 7809: document.getElementById('allfields'+caller).style.display='block';
7810: } else {
1.594 damieng 7811: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7812: document.getElementById('allfields'+caller).style.display='none';
7813: }
7814: resize_scrollbox('contentscroll','1','1');
7815: }
7816:
7817: function multiSettings() {
7818: var inuse = 0;
7819: var settingsform = document.togglemultsettings;
7820: if (settingsform.showmultpick.length > 1) {
7821: for (var i=0; i<settingsform.showmultpick.length; i++) {
7822: if (settingsform.showmultpick[i].checked) {
7823: if (settingsform.showmultpick[i].value == 1) {
7824: inuse = 1;
7825: }
7826: }
7827: }
7828: }
7829: return inuse;
7830: }
7831:
7832: function multiActions() {
7833: var inuse = 0;
7834: var actionsform = document.togglemultactions;
7835: if (actionsform.showmultpick.length > 1) {
7836: for (var i=0; i<actionsform.showmultpick.length; i++) {
7837: if (actionsform.showmultpick[i].checked) {
7838: if (actionsform.showmultpick[i].value == 1) {
7839: inuse = 1;
7840: }
7841: }
7842: }
7843: }
7844: return inuse;
7845: }
7846:
7847: function checkSubmits() {
7848: var numchanges = 0;
7849: var form = document.saveactions;
7850: var doactions = multiActions();
1.542 raeburn 7851: var cutwarnings = 0;
7852: var remwarnings = 0;
1.603 raeburn 7853: var removalinfo = 0;
1.538 raeburn 7854: if (doactions == 1) {
7855: var remidxlist = document.cumulativeactions.allremoveidx.value;
7856: if ((remidxlist != '') && (remidxlist != null)) {
7857: var remidxs = remidxlist.split(',');
7858: for (var i=0; i<remidxs.length; i++) {
7859: if (document.getElementById('remove_'+remidxs[i])) {
7860: if (document.getElementById('remove_'+remidxs[i]).checked) {
7861: form.multiremove.value += remidxs[i]+',';
7862: numchanges ++;
1.542 raeburn 7863: if (document.getElementById('skip_remove_'+remidxs[i])) {
7864: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7865: remwarnings ++;
7866: }
7867: }
1.603 raeburn 7868: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7869: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7870: removalinfo ++;
7871: }
7872: }
1.537 raeburn 7873: }
7874: }
1.538 raeburn 7875: }
7876: }
7877: var cutidxlist = document.cumulativeactions.allcutidx.value;
7878: if ((cutidxlist != '') && (cutidxlist != null)) {
7879: var cutidxs = cutidxlist.split(',');
7880: for (var i=0; i<cutidxs.length; i++) {
7881: if (document.getElementById('cut_'+cutidxs[i])) {
7882: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7883: form.multicut.value += cutidxs[i]+',';
7884: numchanges ++;
1.542 raeburn 7885: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7886: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7887: cutwarnings ++;
7888: }
7889: }
1.537 raeburn 7890: }
7891: }
7892: }
7893: }
1.538 raeburn 7894: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7895: if ((copyidxlist != '') && (copyidxlist != null)) {
7896: var copyidxs = copyidxlist.split(',');
7897: for (var i=0; i<copyidxs.length; i++) {
7898: if (document.getElementById('copy_'+copyidxs[i])) {
7899: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7900: form.multicopy.value += copyidxs[i]+',';
7901: numchanges ++;
7902: }
7903: }
7904: }
7905: }
7906: if (numchanges > 0) {
7907: form.multichange.value = numchanges;
7908: }
1.537 raeburn 7909: }
1.538 raeburn 7910: var dosettings = multiSettings();
1.543 raeburn 7911: var haschanges = 0;
1.538 raeburn 7912: if (dosettings == 1) {
7913: form.allencrypturl.value = '';
7914: form.allhiddenresource.value = '';
1.543 raeburn 7915: form.changeparms.value = 'all';
7916: var patt=new RegExp(",\$");
1.538 raeburn 7917: var allidxlist = document.cumulativesettings.allidx.value;
7918: if ((allidxlist != '') && (allidxlist != null)) {
7919: var allidxs = allidxlist.split(',');
7920: if (allidxs.length > 1) {
7921: for (var i=0; i<allidxs.length; i++) {
7922: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7923: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7924: form.allhiddenresource.value += allidxs[i]+',';
7925: }
7926: }
7927: if (document.getElementById('encrypturl_'+allidxs[i])) {
7928: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7929: form.allencrypturl.value += allidxs[i]+',';
7930: }
7931: }
7932: }
1.543 raeburn 7933: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7934: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 7935: }
1.538 raeburn 7936: }
7937: form.allrandompick.value = '';
7938: form.allrandomorder.value = '';
7939: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7940: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7941: var allmapidxs = allmapidxlist.split(',');
7942: for (var i=0; i<allmapidxs.length; i++) {
7943: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7944: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7945: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7946: if ((randompick.checked) && (rpicknum.value != '')) {
7947: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7948: }
7949: if (randorder.checked) {
7950: form.allrandomorder.value += allmapidxs[i]+',';
7951: }
1.537 raeburn 7952: }
1.543 raeburn 7953: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7954: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7955: }
7956: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7957: haschanges = 1;
7958: }
7959: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7960: haschanges = 1;
7961: }
7962: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7963: haschanges = 1;
7964: }
7965: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7966: haschanges = 1;
1.537 raeburn 7967: }
7968: }
1.543 raeburn 7969: if (doactions == 1) {
1.542 raeburn 7970: if (numchanges > 0) {
1.603 raeburn 7971: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 7972: if (remwarnings > 0) {
1.594 damieng 7973: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 7974: return false;
7975: }
7976: }
1.603 raeburn 7977: if (removalinfo > 0) {
7978: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7979: return false;
7980: }
7981: }
1.542 raeburn 7982: if (cutwarnings > 0) {
1.594 damieng 7983: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
1.542 raeburn 7984: return false;
7985: }
7986: }
7987: }
7988: form.submit();
7989: return true;
1.543 raeburn 7990: }
7991: }
7992: if (dosettings == 1) {
7993: if (haschanges == 1) {
1.542 raeburn 7994: form.submit();
7995: return true;
7996: }
1.543 raeburn 7997: }
7998: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 7999: alert("$js_lt{'noor'}");
1.543 raeburn 8000: } else {
8001: if (dosettings == 1) {
1.594 damieng 8002: alert("$js_lt{'noch'}");
1.543 raeburn 8003: } else {
1.594 damieng 8004: alert("$js_lt{'noac'}");
1.543 raeburn 8005: }
8006: }
1.538 raeburn 8007: return false;
8008: }
8009:
8010: function setClass(value) {
8011: var cutclass = 'LC_docs_cut';
8012: var copyclass = 'LC_docs_copy';
8013: var removeclass = 'LC_docs_remove';
8014: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8015: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8016: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8017: var links = document.getElementsByTagName('a');
8018: for (var i=0; i<links.length; i++) {
8019: var classes = links[i].className;
8020: if (cutreg.test(classes)) {
8021: links[i].className = cutclass;
8022: if (value == 1) {
8023: links[i].className += " LC_menubuttons_link";
8024: }
8025: } else {
8026: if (copyreg.test(classes)) {
8027: links[i].className = copyclass;
8028: if (value == 1) {
8029: links[i].className += " LC_menubuttons_link";
8030: }
8031: } else {
8032: if (removereg.test(classes)) {
8033: links[i].className = removeclass;
8034: if (value == 1) {
8035: links[i].className += " LC_menubuttons_link";
8036: }
8037: }
8038: }
8039: }
8040: }
8041: return;
1.537 raeburn 8042: }
8043:
1.538 raeburn 8044: function setBoxes(value) {
8045: var remidxlist = document.cumulativeactions.allremoveidx.value;
8046: if ((remidxlist != '') && (remidxlist != null)) {
8047: var remidxs = remidxlist.split(',');
8048: for (var i=0; i<remidxs.length; i++) {
8049: if (document.getElementById('remove_'+remidxs[i])) {
8050: var item = document.getElementById('remove_'+remidxs[i]);
8051: if (value == 1) {
8052: item.className = 'LC_docs_remove';
8053: } else {
8054: item.className = 'LC_hidden';
8055: }
8056: }
8057: }
8058: }
8059: var cutidxlist = document.cumulativeactions.allcutidx.value;
8060: if ((cutidxlist != '') && (cutidxlist != null)) {
8061: var cutidxs = cutidxlist.split(',');
8062: for (var i=0; i<cutidxs.length; i++) {
8063: if (document.getElementById('cut_'+cutidxs[i])) {
8064: var item = document.getElementById('cut_'+cutidxs[i]);
8065: if (value == 1) {
8066: item.className = 'LC_docs_cut';
8067: } else {
8068: item.className = 'LC_hidden';
8069: }
8070: }
1.537 raeburn 8071: }
8072: }
1.538 raeburn 8073: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8074: if ((copyidxlist != '') && (copyidxlist != null)) {
8075: var copyidxs = copyidxlist.split(',');
8076: for (var i=0; i<copyidxs.length; i++) {
8077: if (document.getElementById('copy_'+copyidxs[i])) {
8078: var item = document.getElementById('copy_'+copyidxs[i]);
8079: if (value == 1) {
8080: item.className = 'LC_docs_copy';
8081: } else {
8082: item.className = 'LC_hidden';
8083: }
8084: }
1.537 raeburn 8085: }
8086: }
8087: return;
8088: }
8089:
1.606 raeburn 8090: function validImportCrsRes() {
8091: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8092: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8093: if ((fname == '') || (fname == null)) {
8094: alert("$js_lt{'nofi'}");
8095: return false;
8096: }
8097: var url = '/res/$coursedom/$coursenum/';
8098: if (path && path != '/') {
8099: url += path+'/';
8100: }
8101: if (fname != '') {
8102: url += fname;
8103: }
8104: var title = document.crsresimportform.crsrestitle.value;
8105: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8106: return true;
8107: }
8108:
8109: function validateNewRes(caller) {
8110: if (caller == 'single') {
8111: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8112: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8113: var resname = document.courseresform.newresourcename.value;
8114: }
8115: }
8116:
1.611 raeburn 8117: ENDSCRIPT
1.329 droeschl 8118: }
1.457 raeburn 8119:
1.483 raeburn 8120: sub history_tab_js {
8121: return <<"ENDHIST";
8122: function toggleHistoryDisp(choice) {
8123: document.docslogform.docslog.value = choice;
8124: document.docslogform.submit();
8125: return;
8126: }
8127:
8128: ENDHIST
8129: }
8130:
1.484 raeburn 8131: sub inject_data_js {
8132: return <<ENDINJECT;
8133:
8134: function injectData(current, hiddenField, name, value) {
8135: currentElement = document.getElementById(hiddenField);
8136: currentElement.name = name;
8137: currentElement.value = value;
8138: current.submit();
8139: }
8140:
8141: ENDINJECT
8142: }
8143:
8144: sub dump_switchserver_js {
8145: my @hosts = @_;
1.594 damieng 8146: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8147: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8148: swit => 'Switch server?',
1.594 damieng 8149: );
8150: my %html_js_lt = &Apache::lonlocal::texthash(
8151: swit => 'Switch server?',
1.568 raeburn 8152: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8153: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8154: chos => 'Choose server',
8155: );
1.594 damieng 8156: &js_escape(\%js_lt);
8157: &html_escape(\%html_js_lt);
8158: &js_escape(\%html_js_lt);
1.484 raeburn 8159: my $role = $env{'request.role'};
8160: my $js = <<"ENDSWJS";
8161: <script type="text/javascript">
8162: function write_switchserver() {
8163: var server;
8164: if (document.setserver.posshosts.length > 0) {
8165: for (var i=0; i<document.setserver.posshosts.length; i++) {
8166: if (document.setserver.posshosts[i].checked) {
8167: server = document.setserver.posshosts[i].value;
8168: }
8169: }
8170: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8171: }
8172: window.close();
8173: }
8174: </script>
8175:
8176: ENDSWJS
8177:
8178: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8179: {'only_body' => 1,
8180: 'js_ready' => 1,});
8181: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8182:
8183: my $hostpicker;
8184: my $count = 0;
8185: foreach my $host (sort(@hosts)) {
8186: my $checked;
8187: if ($count == 0) {
8188: $checked = ' checked="checked"';
8189: }
8190: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8191: $host.'"'.$checked.' />'.$host.'</label> ';
8192: $count++;
8193: }
8194:
8195: return <<"ENDSWITCHJS";
8196:
8197: function dump_needs_switchserver(url) {
8198: if (url!='' && url!= null) {
1.594 damieng 8199: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8200: go(url);
8201: }
8202: }
8203: return;
8204: }
8205:
8206: function choose_switchserver_window() {
8207: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8208: newWindow.document.open();
8209: newWindow.document.writeln('$startpage');
1.594 damieng 8210: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8211: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8212: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8213: '<form name="setserver" method="post" action="" \\/>\\n'+
8214: '$hostpicker\\n'+
8215: '<br \\/><br \\/>\\n'+
1.594 damieng 8216: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8217: 'onclick="write_switchserver();" \\/>\\n'+
8218: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8219: newWindow.document.writeln('$endpage');
8220: newWindow.document.close();
8221: newWindow.focus();
8222: }
8223:
8224: ENDSWITCHJS
8225: }
8226:
8227: sub makedocslogform {
8228: my ($formelems,$docslog) = @_;
8229: return <<"LOGSFORM";
8230: <form action="/adm/coursedocs" method="post" name="docslogform">
8231: <input type="hidden" name="docslog" value="$docslog" />
8232: $formelems
8233: </form>
8234: LOGSFORM
8235: }
8236:
8237: sub makesimpleeditform {
8238: my ($formelems) = @_;
8239: return <<"SIMPFORM";
8240: <form name="simpleedit" method="post" action="/adm/coursedocs">
8241: <input type="hidden" name="importdetail" value="" />
8242: $formelems
8243: </form>
8244: SIMPFORM
8245: }
8246:
1.606 raeburn 8247: sub makenewproblem {
8248: my ($r,$coursedom,$coursenum) = @_;
8249: # Creating a new problem
8250: my ($redirect,$error);
8251: if ($env{'form.authorrole'}) {
8252: my ($newsubdir,$filename);
8253: if ($env{'form.newsubdir'}) {
8254: if ($env{'form.newsubdirname'} ne '') {
8255: $newsubdir = $env{'form.newsubdirname'};
8256: }
8257: }
8258: if ($env{'form.newresourcename'}) {
8259: $filename = $env{'form.newresourcename'};
8260: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8261: $filename =~ s/`//g;
8262: $filename =~ s{/\.\./}{_}g;
8263: $filename =~ s/\.+/./g;
8264: $filename =~ s{/+}{_}g;
8265: if ($filename ne '') {
8266: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8267: if (($ext) && ($ext ne '.problem')) {
8268: $filename = $name.'.problem';
8269: } elsif ($ext eq '') {
8270: $filename .= '.problem';
8271: }
8272: my $docroot = $r->dir_config('lonDocRoot');
8273: my @ids=&Apache::lonnet::current_machine_ids();
8274: if ($env{'form.authorrole'} eq 'author') {
8275: if ($env{'user.author'}) {
8276: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8277: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8278: my $path = $docroot.$url;
8279: my $subdir = $env{'form.authorpath'};
8280: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8281: }
8282: }
8283: } elsif ($env{'form.authorrole'} eq 'course') {
8284: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8285: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8286: my $url = "/priv/$coursedom/$coursenum";
8287: my $path=$docroot.$url;
8288: my $subdir = $env{'form.authorpath'};
8289: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8290: if ($redirect) {
8291: my $rightsfile = 'default.rights';
8292: my $sourcerights = "$path/$rightsfile";
8293: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8294: my $now = time;
8295: if (!-e $sourcerights) {
8296: my $cid = $coursedom.'_'.$coursenum;
8297: if (open(my $fh,">$sourcerights")) {
8298: print $fh <<END;
8299: <accessrule effect="deny" realm="" type="course" role="" />
8300: <accessrule effect="allow" realm="$cid" type="course" role="" />
8301: END
8302: close($fh);
8303: }
8304: }
8305: if (!-e "$sourcerights.meta") {
8306: if (open(my $fh,">$sourcerights.meta")) {
8307: my $author=$env{'environment.firstname'}.' '.
8308: $env{'environment.middlename'}.' '.
8309: $env{'environment.lastname'}.' '.
8310: $env{'environment.generation'};
8311: $author =~ s/\s+$//;
8312: print $fh <<"END";
8313:
8314: <abstract></abstract>
8315: <author>$author</author>
8316: <authorspace>$coursenum:$coursedom</authorspace>
8317: <copyright>private</copyright>
8318: <creationdate>$now</creationdate>
8319: <customdistributionfile></customdistributionfile>
8320: <dependencies></dependencies>
8321: <domain>$coursedom</domain>
8322: <highestgradelevel>0</highestgradelevel>
8323: <keywords></keywords>
8324: <language>notset </language>
8325: <lastrevisiondate>$now</lastrevisiondate>
8326: <lowestgradelevel>0</lowestgradelevel>
8327: <mime>rights</mime>
8328: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8329: <notes></notes>
8330: <obsolete></obsolete>
8331: <obsoletereplacement></obsoletereplacement>
8332: <owner>$coursenum:$coursedom</owner>
8333: <rule>deny:::course,allow:$cid::course</rule>
8334: <sourceavail></sourceavail>
8335: <standards></standards>
8336: <subject></subject>
8337: <title></title>
8338: END
8339: close($fh);
8340: }
8341: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8342: if (!-e "$docroot/res/$coursedom") {
8343: mkdir("$docroot/res/$coursedom",0755);
8344: }
8345: if (!-e "$docroot/res/$coursedom/$coursenum") {
8346: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8347: }
8348: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8349: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8350: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8351: }
8352: }
8353: }
8354: if ($env{'form.newresourceadd'}) {
8355: my $template = $env{'form.template'};
8356: my $source = $docroot.$redirect;
8357: my $target = $redirect;
8358: $target =~ s{^/priv/}{/res/};
8359: $target = $docroot.$target;
8360: if (!-e $source) {
8361: my $copyfrom;
8362: if ($template) {
8363: my %templates;
8364: my @files = &Apache::lonhomework::get_template_list('problem');
8365: foreach my $poss (@files) {
8366: if (ref($poss) eq 'ARRAY') {
8367: if ($template eq $poss->[0]) {
8368: $templates{$template} = 1;
8369: last;
8370: }
8371: }
8372: }
8373: if ($templates{$template}) {
8374: $copyfrom = $template;
8375: }
8376: }
8377: unless ($copyfrom) {
8378: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8379: }
8380: &File::Copy::copy($copyfrom,$source);
8381: }
8382: if (!-e "$source.meta") {
8383: my $cid = $coursedom.'_'.$coursenum;
8384: my $now = time;
8385: if (open(my $fh,">$source.meta")) {
8386: my $author=$env{'environment.firstname'}.' '.
8387: $env{'environment.middlename'}.' '.
8388: $env{'environment.lastname'}.' '.
8389: $env{'environment.generation'};
8390: $author =~ s/\s+$//;
8391: my $title = $env{'form.newresourcetitle'};
8392: $title =~ s/^\s+|\s+$//g;
8393: print $fh <<END;
8394:
8395: <abstract></abstract>
8396: <author>$author</author>
8397: <authorspace>$coursenum:$coursedom</authorspace>
8398: <copyright>custom</copyright>
8399: <creationdate>$now</creationdate>
8400: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8401: <dependencies></dependencies>
8402: <domain>$coursedom</domain>
8403: <highestgradelevel>0</highestgradelevel>
8404: <keywords></keywords>
8405: <language>notset </language>
8406: <lastrevisiondate>$now</lastrevisiondate>
8407: <lowestgradelevel>0</lowestgradelevel>
8408: <mime>problem</mime>
8409: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8410: <notes></notes>
8411: <obsolete></obsolete>
8412: <obsoletereplacement></obsoletereplacement>
8413: <owner>$coursenum:$coursedom</owner>
8414: <sourceavail></sourceavail>
8415: <standards></standards>
8416: <subject></subject>
8417: <title>$title</title>
8418: END
8419: close($fh);
8420: }
8421: }
8422: }
8423: }
8424: }
8425: } else {
8426: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8427: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8428: if (grep(/^\Q$rolehome\E$/,@ids)) {
8429: my $now = time;
8430: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8431: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8432: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8433: my $url = "/priv/$audom/$auname";
8434: my $path = $r->dir_config('lonDocRoot').$url;
8435: my $subdir = $env{'form.authorpath'};
8436: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8437: }
8438: }
8439: }
8440: }
8441: }
8442: }
8443: }
8444: return ($redirect,$error);
8445: }
8446:
8447: sub finishnewprob {
8448: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8449: unless (-d $path) {
8450: unless (mkdir($path,02770)) {
8451: return;
8452: }
8453: }
1.606 raeburn 8454: my $redirect;
8455: if ($subdir ne '/') {
8456: $subdir = &cleandir($subdir);
8457: if (($subdir ne '') && (-d "$path/$subdir")) {
8458: $path .= "/$subdir";
8459: $url .= "/$subdir";
8460: }
8461: }
8462: my $dest;
8463: if ($newsubdir ne '') {
8464: $newsubdir = &cleandir($newsubdir);
8465: }
8466: if ($newsubdir ne '') {
8467: if (-d "$path/$newsubdir") {
8468: $dest = "$path/$newsubdir/$filename";
8469: } else {
8470: my $dirok;
8471: unless (-e "$path/$newsubdir") {
8472: if (mkdir("$path/$newsubdir",02770)) {
8473: if (chmod(02770,"$path/$newsubdir")) {
8474: $dirok = 1;
8475: }
8476: }
8477: }
8478: if ($dirok) {
8479: $dest = "$path/$newsubdir/$filename";
8480: }
8481: }
8482: if (($dest ne '') && (!-e $dest)) {
8483: $redirect = "$url/$newsubdir/$filename";
8484: }
8485: } else {
8486: $dest = "$path/$filename";
8487: if (($dest ne '') && (!-e $dest)) {
8488: $redirect = "$url/$filename";
8489: }
8490: }
8491: return $redirect;
8492: }
8493:
8494: sub cleandir {
8495: my ($dir) = @_;
8496: $dir =~ s/^\s+//;
8497: $dir =~ s/\s+$//;
8498: $dir =~ s/\.+//g;
8499: $dir =~ s/[\#\?&%\":]//g;
8500: return $dir;
8501: }
8502:
1.329 droeschl 8503: 1;
8504: __END__
8505:
8506:
8507: =head1 NAME
8508:
8509: Apache::londocs.pm
8510:
8511: =head1 SYNOPSIS
8512:
8513: This is part of the LearningOnline Network with CAPA project
8514: described at http://www.lon-capa.org.
8515:
8516: =head1 SUBROUTINES
8517:
8518: =over
8519:
8520: =item %help=()
8521:
8522: Available help topics
8523:
8524: =item mapread()
8525:
1.344 bisitz 8526: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8527: @order and @resources, determines status
8528: sets @order - pointer to resources in right order
8529: sets @resources - array with the resources with correct idx
8530:
8531: =item authorhosts()
8532:
8533: Return hash with valid author names
8534:
8535: =item clean()
8536:
8537: =item dumpcourse()
8538:
8539: Actually dump course
8540:
8541: =item group_import()
8542:
8543: Imports the given (name, url) resources into the course
8544: coursenum, coursedom, and folder must precede the list
8545:
8546: =item breadcrumbs()
8547:
8548: =item log_docs()
8549:
8550: =item docs_change_log()
8551:
8552: =item update_paste_buffer()
8553:
8554: =item print_paste_buffer()
8555:
8556: =item do_paste_from_buffer()
8557:
1.538 raeburn 8558: =item do_buffer_empty()
8559:
8560: =item clear_from_buffer()
8561:
1.492 raeburn 8562: =item get_newmap_url()
8563:
8564: =item dbcopy()
8565:
8566: =item uniqueness_check()
8567:
8568: =item contained_map_check()
8569:
8570: =item url_paste_fixups()
8571:
8572: =item apply_fixups()
8573:
8574: =item copy_dependencies()
8575:
1.329 droeschl 8576: =item update_parameter()
8577:
8578: =item handle_edit_cmd()
8579:
8580: =item editor()
8581:
8582: =item process_file_upload()
8583:
8584: =item process_secondary_uploads()
8585:
8586: =item is_supplemental_title()
8587:
8588: =item entryline()
8589:
8590: =item tiehash()
8591:
8592: =item untiehash()
8593:
8594: =item checkonthis()
8595:
8596: check on this
8597:
8598: =item verifycontent()
8599:
8600: Verify Content
8601:
8602: =item devalidateversioncache() & checkversions()
8603:
8604: Check Versions
8605:
8606: =item mark_hash_old()
8607:
8608: =item is_hash_old()
8609:
8610: =item changewarning()
8611:
8612: =item init_breadcrumbs()
8613:
8614: Breadcrumbs for special functions
8615:
1.484 raeburn 8616: =item create_list_elements()
8617:
8618: =item create_form_ul()
8619:
8620: =item startContentScreen()
8621:
8622: =item endContentScreen()
8623:
8624: =item supplemental_base()
8625:
8626: =item embedded_form_elems()
8627:
8628: =item embedded_destination()
8629:
8630: =item return_to_editor()
8631:
8632: =item decompression_info()
8633:
8634: =item decompression_phase_one()
8635:
8636: =item decompression_phase_two()
8637:
8638: =item remove_archive()
8639:
8640: =item generate_admin_menu()
8641:
8642: =item generate_edit_table()
8643:
8644: =item editing_js()
8645:
8646: =item history_tab_js()
8647:
8648: =item inject_data_js()
8649:
8650: =item dump_switchserver_js()
8651:
1.485 raeburn 8652: =item resize_scrollbox_js()
1.484 raeburn 8653:
8654: =item makedocslogform()
8655:
1.485 raeburn 8656: =item makesimpleeditform()
8657:
1.329 droeschl 8658: =back
8659:
8660: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>