Annotation of loncom/interface/londocs.pm, revision 1.637
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.637 ! raeburn 4: # $Id: londocs.pm,v 1.636 2017/08/27 02:23:02 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;
1.630 raeburn 606: $depurl =~ s{[^/]+$}{};
1.567 raeburn 607: $depurl .= $dependency;
1.630 raeburn 608: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 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.628 raeburn 681: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
682: ($toolhash{'target'} eq 'window')) {
1.604 raeburn 683: if ($toolhash{'target'} eq 'window') {
684: foreach my $item ('width','height') {
685: $toolhash{$item} =~ s/^\s+//;
686: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 687: if ($toolhash{$item} =~ /\D/) {
688: delete($toolhash{$item});
689: if ($residx) {
690: if ($toolsettings{$item}) {
691: push(@deleted,$item);
692: }
693: }
694: }
1.604 raeburn 695: }
696: }
697: } elsif ($residx) {
698: $toolhash{'target'} = $toolsettings{'target'};
699: if ($toolhash{'target'} eq 'window') {
1.630 raeburn 700: foreach my $item ('width','height') {
1.624 raeburn 701: $toolhash{$item} = $toolsettings{$item};
702: }
1.604 raeburn 703: }
704: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
705: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
706: if ($toolhash{'target'} eq 'window') {
707: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
708: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
709: }
710: }
1.598 raeburn 711: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 712: foreach my $item ('width','height','linktext','explanation') {
713: delete($toolhash{$item});
714: if ($residx) {
715: if ($toolsettings{$item}) {
716: push(@deleted,$item);
717: }
1.604 raeburn 718: }
719: }
1.628 raeburn 720: } elsif ($toolhash{'target'} eq 'tab') {
721: foreach my $item ('width','height') {
722: delete($toolhash{$item});
723: if ($residx) {
724: if ($toolsettings{$item}) {
725: push(@deleted,$item);
726: }
727: }
728: }
1.604 raeburn 729: }
730: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 731: foreach my $item ('label','title','linktext','explanation') {
732: my $crsitem;
733: if (($item eq 'label') || ($item eq 'title')) {
734: $crsitem = 'crs'.$item;
735: } else {
736: $crsitem = $item;
737: }
1.604 raeburn 738: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 739: $toolhash{$crsitem} =~ s/^\s+//;
740: $toolhash{$crsitem} =~ s/\s+$//;
741: if ($toolhash{$crsitem} eq '') {
742: delete($toolhash{$crsitem});
1.604 raeburn 743: }
744: } else {
1.624 raeburn 745: delete($toolhash{$crsitem});
1.604 raeburn 746: }
1.624 raeburn 747: if (($residx) && (exists($toolsettings{$crsitem}))) {
748: unless (exists($toolhash{$crsitem})) {
749: push(@deleted,$crsitem);
1.604 raeburn 750: }
751: }
1.598 raeburn 752: }
753: }
754: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 755: if ($putres eq 'ok') {
756: if (@deleted) {
757: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
758: }
759: }
1.598 raeburn 760: }
761: }
762: }
1.529 raeburn 763: if (($caller eq 'londocs') &&
764: ($folder =~ /^default/)) {
1.534 raeburn 765: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 766: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
767: my $cid = $coursedom.'_'.$coursenum;
768: $allmaps =
769: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
770: $chome,$cid);
771: $donechk = 1;
772: }
773: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 774: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
775: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 776: $importuploaded = 1;
777: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
778: next if ($allmaps->{$url});
779: }
780: }
1.344 bisitz 781: if (!$residx
1.329 droeschl 782: || defined($LONCAPA::map::zombies[$residx])) {
783: $residx = &LONCAPA::map::getresidx($url,$residx);
784: push(@LONCAPA::map::order, $residx);
785: }
786: my $ext = 'false';
787: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
788: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 789: if ($name eq '') {
1.538 raeburn 790: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 791: }
792: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
793: my $filepath = $1;
794: my $fname = $name;
795: if ($fname =~ /^\W+$/) {
796: $fname = 'web';
797: } else {
798: $fname =~ s/\W/_/g;
799: }
1.599 damieng 800: if (length($fname) > 15) {
1.534 raeburn 801: $fname = substr($fname,0,14);
802: }
803: my $initialtext = &mt('Replace with your own content.');
804: my $newhtml = <<END;
1.545 raeburn 805: <html>
1.534 raeburn 806: <head>
807: <title>$name</title>
808: </head>
809: <body bgcolor="#ffffff">
810: $initialtext
811: </body>
812: </html>
813: END
814: $env{'form.output'}=$newhtml;
1.630 raeburn 815: my $result =
1.534 raeburn 816: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
817: 'output',
818: "$filepath/$residx/$fname.html");
819: if ($result =~ m{^/uploaded/}) {
820: $url = $result;
821: if ($filepath =~ /^supplemental/) {
822: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
823: $env{'user.domain'}.'___&&&___'.$name;
824: }
825: } else {
826: return (&mt('Failed to save new web page.'),1);
827: }
828: }
1.538 raeburn 829: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 830: $LONCAPA::map::resources[$residx] =
1.329 droeschl 831: join(':', ($name, $url, $ext, 'normal', 'res'));
832: }
833: }
1.529 raeburn 834: if ($importuploaded) {
835: my %import_errors;
836: my %updated = (
837: removefrommap => \%removefrommap,
838: removeparam => \%removeparam,
839: );
1.533 raeburn 840: my ($result,$msgsarray,$lockerror) =
841: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 842: if (keys(%import_errors) > 0) {
1.530 raeburn 843: $fixuperrors =
1.529 raeburn 844: '<p span class="LC_warning">'."\n".
845: &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".
846: '<ul>'."\n";
847: foreach my $key (sort(keys(%import_errors))) {
848: $fixuperrors .= '<li>'.$key.'</li>'."\n";
849: }
850: $fixuperrors .= '</ul></p>'."\n";
851: }
1.533 raeburn 852: if (ref($msgsarray) eq 'ARRAY') {
853: if (@{$msgsarray} > 0) {
854: $fixuperrors .= '<p class="LC_info">'.
855: join('<br />',@{$msgsarray}).
856: '</p>';
857: }
858: }
859: if ($lockerror) {
860: $fixuperrors .= '<p class="LC_error">'.
861: $lockerror.
862: '</p>';
863: }
1.529 raeburn 864: }
865: my ($errtext,$fatal) =
866: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 867: unless ($fatal) {
868: if ($folder =~ /^supplemental/) {
869: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 870: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
871: $folder.'.'.$container);
1.557 raeburn 872: }
873: }
1.529 raeburn 874: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 875: }
876:
877: sub log_docs {
1.494 raeburn 878: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 879: }
880:
881: {
882: my @oldresources=();
883: my @oldorder=();
884: my $parmidx;
885: my %parmaction=();
886: my %parmvalue=();
887: my $changedflag;
888:
889: sub snapshotbefore {
890: @oldresources=@LONCAPA::map::resources;
891: @oldorder=@LONCAPA::map::order;
892: $parmidx=undef;
893: %parmaction=();
894: %parmvalue=();
895: $changedflag=0;
896: }
897:
898: sub remember_parms {
899: my ($idx,$parameter,$action,$value)=@_;
900: $parmidx=$idx;
901: $parmaction{$parameter}=$action;
902: $parmvalue{$parameter}=$value;
903: $changedflag=1;
904: }
905:
906: sub log_differences {
907: my ($plain)=@_;
908: my %storehash=('folder' => $plain,
909: 'currentfolder' => $env{'form.folder'});
910: if ($parmidx) {
911: $storehash{'parameter_res'}=$oldresources[$parmidx];
912: foreach my $parm (keys(%parmaction)) {
913: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
914: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
915: }
916: }
917: my $maxidx=$#oldresources;
918: if ($#LONCAPA::map::resources>$#oldresources) {
919: $maxidx=$#LONCAPA::map::resources;
920: }
921: for (my $idx=0; $idx<=$maxidx; $idx++) {
922: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
923: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
924: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
925: $changedflag=1;
926: }
927: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
928: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
929: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
930: $changedflag=1;
931: }
932: }
933: $storehash{'maxidx'}=$maxidx;
934: if ($changedflag) { &log_docs(\%storehash); }
935: }
936: }
937:
938: sub docs_change_log {
1.611 raeburn 939: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 940: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 941: my $navmap;
1.483 raeburn 942: my $js = '<script type="text/javascript">'."\n".
943: '// <![CDATA['."\n".
944: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 945: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 946: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 947: &history_tab_js()."\n".
1.484 raeburn 948: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 949: '// ]]>'."\n".
950: '</script>'."\n";
1.484 raeburn 951: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
952: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 953: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 954: my %orderhash;
955: my $container='sequence';
956: my $pathitem;
1.519 raeburn 957: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 958: $container='page';
959: }
1.519 raeburn 960: my $folderpath=$env{'form.folderpath'};
961: if ($folderpath eq '') {
1.617 raeburn 962: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 963: }
1.617 raeburn 964: undef($navmap);
1.519 raeburn 965: $pathitem = '<input type="hidden" name="folderpath" value="'.
966: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 967: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
968: my $jumpto = $readfile;
969: $jumpto =~ s{^/}{};
970: my $tid = 1;
1.489 raeburn 971: if ($supplementalflag) {
972: $tid = 2;
973: }
1.630 raeburn 974: my ($breadcrumbtrail) =
1.509 raeburn 975: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 976: $r->print($breadcrumbtrail.
977: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
978: $readfile));
1.329 droeschl 979: my %docslog=&Apache::lonnet::dump('nohist_docslog',
980: $env{'course.'.$env{'request.course.id'}.'.domain'},
981: $env{'course.'.$env{'request.course.id'}.'.num'});
982:
983: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
984:
985: my %saveable_parameters = ('show' => 'scalar',);
986: &Apache::loncommon::store_course_settings('docs_log',
987: \%saveable_parameters);
988: &Apache::loncommon::restore_course_settings('docs_log',
989: \%saveable_parameters);
990: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 991: # FIXME: internationalization seems wrong here
1.329 droeschl 992: my %lt=('hiddenresource' => 'Resources hidden',
993: 'encrypturl' => 'URL hidden',
994: 'randompick' => 'Randomly pick',
995: 'randomorder' => 'Randomly ordered',
996: 'set' => 'set to',
997: 'del' => 'deleted');
1.484 raeburn 998: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
999: $pathitem."\n".
1000: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1001: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1002: $r->print('<div class="LC_left_float">'.
1003: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1004: &makedocslogform($filter,1).
1005: '</fieldset></div><br clear="all" />');
1.329 droeschl 1006: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1007: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1008: &mt('After').'</th>'.
1009: &Apache::loncommon::end_data_table_header_row());
1010: my $shown=0;
1011: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1012: if ($env{'form.displayfilter'} eq 'currentfolder') {
1013: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1014: }
1015: my @changes=keys(%{$docslog{$id}{'logentry'}});
1016: if ($env{'form.displayfilter'} eq 'containing') {
1017: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1018: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1019: foreach my $key (@changes) {
1020: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1021: }
1.344 bisitz 1022: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1023: }
1024: my $count = 0;
1025: my $time =
1026: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1027: my $plainname =
1028: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1029: $docslog{$id}{'exe_udom'});
1030: my $about_me_link =
1031: &Apache::loncommon::aboutmewrapper($plainname,
1032: $docslog{$id}{'exe_uname'},
1033: $docslog{$id}{'exe_udom'});
1034: my $send_msg_link='';
1035: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1036: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1037: $send_msg_link ='<br />'.
1038: &Apache::loncommon::messagewrapper(&mt('Send message'),
1039: $docslog{$id}{'exe_uname'},
1040: $docslog{$id}{'exe_udom'});
1041: }
1042: $r->print(&Apache::loncommon::start_data_table_row());
1043: $r->print('<td>'.$time.'</td>
1044: <td>'.$about_me_link.
1045: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1046: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1047: $send_msg_link.'</td><td>'.
1048: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1049: my $is_supp = 0;
1050: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1051: $is_supp = 1;
1052: }
1.329 droeschl 1053: # Before
1054: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1055: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1056: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1057: if ($oldname ne $newname) {
1.488 raeburn 1058: my $shown = &LONCAPA::map::qtescape($oldname);
1059: if ($is_supp) {
1060: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1061: }
1062: $r->print($shown);
1.329 droeschl 1063: }
1064: }
1065: $r->print('<ul>');
1066: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1067: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1068: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1069: if ($is_supp) {
1070: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1071: }
1072: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1073: }
1074: }
1075: $r->print('</ul>');
1076: # After
1077: $r->print('</td><td>');
1078:
1079: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1080: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1081: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1082: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1083: my $shown = &LONCAPA::map::qtescape($newname);
1084: if ($is_supp) {
1085: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1086: }
1087: $r->print($shown);
1.329 droeschl 1088: }
1.364 bisitz 1089: }
1.329 droeschl 1090: $r->print('<ul>');
1091: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1092: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1093: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1094: if ($is_supp) {
1095: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1096: }
1097: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1098: }
1099: }
1100: $r->print('</ul>');
1101: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1102: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1103: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1104: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1105: # FIXME: internationalization seems wrong here
1.329 droeschl 1106: $r->print('<li>'.
1107: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1108: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1109: .'</li>');
1110: }
1111: }
1112: $r->print('</ul>');
1113: }
1114: # End
1115: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1116: $shown++;
1117: if (!($env{'form.show'} eq &mt('all')
1118: || $shown<=$env{'form.show'})) { last; }
1119: }
1.484 raeburn 1120: $r->print(&Apache::loncommon::end_data_table()."\n".
1121: &makesimpleeditform($pathitem)."\n".
1122: '</div></div>');
1123: $r->print(&endContentScreen());
1.329 droeschl 1124: }
1125:
1126: sub update_paste_buffer {
1.492 raeburn 1127: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1128: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1129: if ($env{'form.multiremove'}) {
1130: $env{'form.multiremove'} =~ s/,$//;
1131: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1132: }
1133: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1134: if ($env{'form.multicut'}) {
1135: $env{'form.multicut'} =~ s/,$//;
1136: foreach my $item (split(/,/,$env{'form.multicut'})) {
1137: unless ($removals{$item}) {
1138: $cuts{$item} = 1;
1139: push(@possibles,$item.':cut');
1140: }
1141: }
1142: }
1143: if ($env{'form.multicopy'}) {
1144: $env{'form.multicopy'} =~ s/,$//;
1145: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1146: unless ($removals{$item} || $cuts{$item}) {
1147: push(@possibles,$item.':copy');
1148: }
1149: }
1150: }
1151: } elsif ($env{'form.markcopy'}) {
1152: @possibles = split(/,/,$env{'form.markcopy'});
1153: }
1.329 droeschl 1154:
1.538 raeburn 1155: return if (@possibles == 0);
1.329 droeschl 1156: return if (!defined($env{'form.copyfolder'}));
1157:
1158: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1159: $env{'form.copyfolder'});
1.538 raeburn 1160: return if ($fatal);
1161:
1162: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1163:
1.538 raeburn 1164: # Retrieve current paste buffer suffixes.
1165: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1166: my (%pasteurls,@newpaste);
1167:
1168: # Construct identifiers for current contents of user's paste buffer
1169: if (@currpaste) {
1170: foreach my $suffix (@currpaste) {
1171: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1172: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.630 raeburn 1173: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1174: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1175: ($url ne '')) {
1.597 raeburn 1176: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1177: }
1178: }
1179: }
1180:
1181: # Mark items for copying (skip any items already in user's paste buffer)
1182: my %addtoenv;
1.597 raeburn 1183:
1184: my @pathitems = split(/\&/,$env{'form.folderpath'});
1185: my @folderconf = split(/\:/,$pathitems[-1]);
1186: my $ispage = $folderconf[4];
1187:
1.538 raeburn 1188: foreach my $item (@possibles) {
1189: my ($orderidx,$cmd) = split(/:/,$item);
1190: next if ($orderidx =~ /\D/);
1191: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1192: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1193: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1194: my %denied = &action_restrictions($coursenum,$coursedom,
1195: &LONCAPA::map::qtescape($url),
1196: $env{'form.folderpath'},\%curr_groups);
1197: next if ($denied{'copy'});
1198: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1199: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1200: my ($suffix,$errortxt,$locknotfreed) =
1201: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1202: if ($suffix ne '') {
1203: push(@newpaste,$suffix);
1204: } else {
1205: if ($locknotfreed) {
1206: return $locknotfreed;
1207: }
1.538 raeburn 1208: }
1209: if (&is_supplemental_title($title)) {
1210: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1211: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1212: }
1.329 droeschl 1213:
1.538 raeburn 1214: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1215: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1216: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1217: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1218: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1219: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1220: my $prefix = $1;
1221: my $subdir =$2;
1222: if ($subdir eq '') {
1223: $subdir = $prefix;
1.492 raeburn 1224: }
1.538 raeburn 1225: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1226: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1227: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1228: if (ref($hierarchy{$url}) eq 'HASH') {
1229: my ($nested,$nestednames);
1230: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1231: $nested =~ s/\&$//;
1232: $nestednames =~ s/\Q___&&&___\E$//;
1233: if ($nested ne '') {
1234: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1235: }
1236: if ($nestednames ne '') {
1237: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1238: }
1.492 raeburn 1239: }
1240: }
1.591 raeburn 1241: if ($locknotfreed) {
1242: $output = $locknotfreed;
1243: last;
1244: }
1.492 raeburn 1245: }
1.538 raeburn 1246: if (@newpaste) {
1247: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1248: }
1.492 raeburn 1249: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1250: delete($env{'form.markcopy'});
1.591 raeburn 1251: return $output;
1.329 droeschl 1252: }
1253:
1.492 raeburn 1254: sub recurse_uploaded_maps {
1255: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1256: if (ref($hierarchy->{$url}) eq 'HASH') {
1257: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1258: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1259: my (@uploaded,@names,%shorter);
1260: for (my $i=0; $i<@maps; $i++) {
1261: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1262: if ($inner ne '') {
1263: push(@uploaded,$inner);
1264: push(@names,&escape($titles[$i]));
1265: $shorter{$maps[$i]} = $inner;
1266: }
1267: }
1268: $$nestref .= "$dir:".join(',',@uploaded).'&';
1269: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1270: foreach my $map (@maps) {
1271: if ($shorter{$map} ne '') {
1272: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1273: }
1274: }
1275: }
1276: return;
1277: }
1278:
1.329 droeschl 1279: sub print_paste_buffer {
1.492 raeburn 1280: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1281: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1282:
1.538 raeburn 1283: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1284: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1285: }
1286:
1.538 raeburn 1287: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1288: my ($pasteitems,@pasteable);
1.575 raeburn 1289: my $clipboardcount = 0;
1.488 raeburn 1290:
1.538 raeburn 1291: # Construct identifiers for current contents of user's paste buffer
1292: foreach my $suffix (@currpaste) {
1293: next if ($suffix =~ /\D/);
1294: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1295: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1296: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1297: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1298: ($url ne '')) {
1.575 raeburn 1299: $clipboardcount ++;
1.538 raeburn 1300: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1301: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1302: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1303: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1304: $is_external = 1;
1.626 raeburn 1305: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1306: $is_exttool = 1;
1.538 raeburn 1307: }
1308: if ($folder =~ /^supplemental/) {
1309: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1310: unless ($canpaste) {
1311: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1312: }
1313: } else {
1314: $canpaste = 1;
1315: }
1316: if ($canpaste) {
1317: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1318: my $srcdom = $1;
1319: my $srcnum = $2;
1320: my $rem = $3;
1321: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1322: $othercourse = 1;
1323: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1324: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1325: } else {
1326: $canpaste = 0;
1327: $nopaste = &mt('Paste from another course unavailable.');
1328: }
1329: }
1330: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1331: my $prefix = $1;
1332: $parent = $2;
1333: if ($folder !~ /^\Q$prefix\E/) {
1334: $areachange = 1;
1335: }
1336: $is_uploaded_map = 1;
1.492 raeburn 1337: }
1.597 raeburn 1338: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1339: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1340: if ($cid ne $env{'request.course.id'}) {
1341: my ($srcdom,$srcnum) = split(/_/,$cid);
1342: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1343: if (($is_exttool) && ($srcdom ne $coursedom)) {
1344: $canpaste = 0;
1345: $nopaste = &mt('Paste from another domain unavailable.');
1346: } else {
1347: $othercrs = '<br />'.&mt('(from another course)');
1348: }
1.596 raeburn 1349: } else {
1350: $canpaste = 0;
1351: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1352: }
1.596 raeburn 1353: }
1.492 raeburn 1354: }
1.596 raeburn 1355: if ($canpaste) {
1356: push(@pasteable,$suffix);
1.629 raeburn 1357: }
1.538 raeburn 1358: }
1359: my $buffer;
1.627 raeburn 1360: if ($is_external) {
1.538 raeburn 1361: $buffer = &mt('External Resource').': '.
1362: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1363: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1364: } elsif ($is_exttool) {
1365: $buffer = &mt('External Tool').': '.
1366: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1367: } else {
1368: my $icon = &Apache::loncommon::icon($extension);
1369: if ($extension eq 'sequence' &&
1370: $url =~ m{/default_\d+\.sequence$}x) {
1371: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1372: $icon .= '/navmap.folder.closed.gif';
1373: }
1.589 raeburn 1374: my $title = $env{'docs.markedcopy_title_'.$suffix};
1375: if ($title eq '') {
1376: ($title) = ($url =~ m{/([^/]+)$});
1377: }
1.538 raeburn 1378: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1379: ': '.
1380: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1381: &LONCAPA::map::qtescape($title));
1.538 raeburn 1382: }
1383: $pasteitems .= '<div class="LC_left_float">';
1384: my ($options,$onclick);
1385: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1386: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1387: if (($is_uploaded_map) ||
1388: ($url =~ /(bulletinboard|smppg)$/) ||
1389: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1390: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1391: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1392: }
1393: }
1394: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1395: if ($nopaste) {
1396: $pasteitems .= $nopaste;
1397: } else {
1398: if ($othercrs) {
1399: $pasteitems .= $othercrs;
1400: }
1401: if ($options) {
1402: $pasteitems .= $options;
1.492 raeburn 1403: }
1404: }
1.538 raeburn 1405: $pasteitems .= '</div>';
1406: }
1407: }
1408: if ($pasteitems eq '') {
1409: &Apache::lonnet::delenv('docs.markedcopies');
1410: }
1411: my ($pasteform,$form_start,$buttons,$form_end);
1412: if ($pasteitems) {
1413: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1414: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1415: if (@pasteable) {
1.575 raeburn 1416: my $value = &mt('Paste to current folder');
1417: if ($container eq 'page') {
1418: $value = &mt('Paste to current page');
1419: }
1420: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1421: }
1422: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1423: if ($clipboardcount > 1) {
1424: $buttons .=
1425: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1426: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1427: (' 'x2).
1428: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1429: (' 'x2);
1.492 raeburn 1430: }
1.575 raeburn 1431: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1432: '</form>';
1.538 raeburn 1433: } else {
1434: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1435: }
1.538 raeburn 1436: $r->print($form_start
1437: .'<fieldset>'
1438: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1439: .$pasteitems
1440: .'</fieldset>'
1441: .$form_end);
1442: }
1443:
1444: sub paste_options {
1445: my ($suffix,$is_uploaded_map,$parent) = @_;
1446: my ($copytext,$movetext);
1447: if ($is_uploaded_map) {
1448: $copytext = &mt('Copy to new folder');
1449: $movetext = &mt('Move old');
1450: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1451: $copytext = &mt('Copy to new board');
1452: $movetext = &mt('Move (not posts)');
1453: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1454: $copytext = &mt('Copy to new page');
1455: $movetext = &mt('Move');
1.533 raeburn 1456: } else {
1.538 raeburn 1457: $copytext = &mt('Copy to new file');
1458: $movetext = &mt('Move');
1459: }
1460: my $output = '<br />'.
1461: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1462: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1463: '<label>'.
1464: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1465: $copytext.'</label></span>'.(' 'x2).' '.
1466: '<span class="LC_nobreak"><label>'.
1467: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1468: $movetext.'</label></span>';
1469: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1470: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1471: '</legend><table border="0">';
1472: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1473: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1474: my $lastdir = $parent;
1475: my %depths = (
1476: $lastdir => 0,
1477: );
1478: my (%display,%deps);
1479: for (my $i=0; $i<@pastemaps; $i++) {
1480: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1481: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1482: my @subfolders = split(/,/,$subfolderstr);
1483: $deps{$lastdir} = \@subfolders;
1484: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1485: my $depth = $depths{$lastdir} + 1;
1486: my $offset = int($depth * 4);
1487: my $indent = (' ' x $offset);
1488: for (my $j=0; $j<@subfolders; $j++) {
1489: $depths{$subfolders[$j]} = $depth;
1490: $display{$subfolders[$j]} =
1491: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1492: '<td><label>'.
1493: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1494: '<label>'.
1495: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1496: &mt('Move old').'</label>'.
1497: '</td></tr>';
1498: }
1.492 raeburn 1499: }
1.538 raeburn 1500: &recurse_print(\$output,$parent,\%deps,\%display);
1501: $output .= '</table></fieldset>';
1.329 droeschl 1502: }
1.538 raeburn 1503: $output .= '</div>';
1504: return $output;
1.488 raeburn 1505: }
1506:
1.492 raeburn 1507: sub recurse_print {
1.538 raeburn 1508: my ($outputref,$dir,$deps,$display) = @_;
1509: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1510: if (ref($deps->{$dir}) eq 'ARRAY') {
1511: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1512: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1513: }
1514: }
1515: }
1516:
1.488 raeburn 1517: sub supp_pasteable {
1518: my ($url) = @_;
1519: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1520: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1521: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1522: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1523: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1524: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1525: return 1;
1526: }
1527: return;
1.329 droeschl 1528: }
1529:
1.492 raeburn 1530: sub paste_popup_js {
1.594 damieng 1531: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1532: show => 'Show Options',
1533: hide => 'Hide Options',
1.594 damieng 1534: );
1535: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1536: none => 'No items selected from clipboard.',
1.492 raeburn 1537: );
1.594 damieng 1538: &html_escape(\%html_js_lt);
1539: &js_escape(\%html_js_lt);
1540: &js_escape(\%js_lt);
1.492 raeburn 1541: return <<"END";
1542:
1.538 raeburn 1543: function showPasteOptions(suffix) {
1544: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1545: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1546: return;
1547: }
1548:
1.538 raeburn 1549: function hidePasteOptions(suffix) {
1550: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1551: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1552: return;
1553: }
1554:
1555: function showOptions(caller,suffix) {
1556: if (document.getElementById('pasteoptionstext_'+suffix)) {
1557: if (caller.checked) {
1.594 damieng 1558: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1559: } else {
1560: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1561: }
1562: if (document.getElementById('pasteoptions_'+suffix)) {
1563: document.getElementById('pasteoptions_'+suffix).style.display='none';
1564: }
1565: }
1.492 raeburn 1566: return;
1567: }
1568:
1.541 raeburn 1569: function validateClipboard() {
1570: var numchk = 0;
1571: if (document.pasteform.pasting.length > 1) {
1572: for (var i=0; i<document.pasteform.pasting.length; i++) {
1573: if (document.pasteform.pasting[i].checked) {
1574: numchk ++;
1575: }
1576: }
1577: } else {
1578: if (document.pasteform.pasting.type == 'checkbox') {
1579: if (document.pasteform.pasting.checked) {
1580: numchk ++;
1581: }
1582: }
1583: }
1584: if (numchk > 0) {
1585: return true;
1586: } else {
1.594 damieng 1587: alert("$js_lt{'none'}");
1.541 raeburn 1588: return false;
1589: }
1590: }
1591:
1.575 raeburn 1592: function checkClipboard() {
1593: if (document.pasteform.pasting.length > 1) {
1594: for (var i=0; i<document.pasteform.pasting.length; i++) {
1595: document.pasteform.pasting[i].checked = true;
1596: }
1597: }
1598: return;
1599: }
1600:
1601: function uncheckClipboard() {
1602: if (document.pasteform.pasting.length >1) {
1603: for (var i=0; i<document.pasteform.pasting.length; i++) {
1604: document.pasteform.pasting[i].checked = false;
1605: }
1606: }
1607: return;
1608: }
1609:
1.492 raeburn 1610: END
1611:
1612: }
1613:
1.329 droeschl 1614: sub do_paste_from_buffer {
1.492 raeburn 1615: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1616:
1.538 raeburn 1617: # Array of items in paste buffer
1618: my (@currpaste,%pastebuffer,%allerrors);
1619: @currpaste = split(/,/,$env{'docs.markedcopies'});
1620:
1.492 raeburn 1621: # Early out if paste buffer is empty
1.538 raeburn 1622: if (@currpaste == 0) {
1.492 raeburn 1623: return ();
1.538 raeburn 1624: }
1625: map { $pastebuffer{$_} = 1; } @currpaste;
1626:
1627: # Array of items selected items to paste
1628: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1629:
1630: # Early out if nothing selected to paste
1631: if (@reqpaste == 0) {
1632: return();
1633: }
1634: my @topaste;
1635: foreach my $suffix (@reqpaste) {
1636: next if ($suffix =~ /\D/);
1637: next unless (exists($pastebuffer{$suffix}));
1638: push(@topaste,$suffix);
1639: }
1640:
1641: # Early out if nothing available to paste
1642: if (@topaste == 0) {
1643: return();
1.329 droeschl 1644: }
1645:
1.627 raeburn 1646: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1647: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1648:
1649: foreach my $suffix (@topaste) {
1650: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1651: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1652: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1653: # Supplemental content may only include certain types of content
1654: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1655: if ($folder =~ /^supplemental/) {
1656: unless (&supp_pasteable($url)) {
1657: $notinsupp{$suffix} = 1;
1658: next;
1659: }
1.492 raeburn 1660: }
1.538 raeburn 1661: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1662: my $srcd = $1;
1663: my $srcn = $2;
1.492 raeburn 1664: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1665: # check for mdc privilege in the course from which the resource was pasted
1666: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1667: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1668: $notincrs{$suffix} = 1;
1669: next;
1670: }
1.491 raeburn 1671: }
1.538 raeburn 1672: $srcdom{$suffix} = $srcd;
1673: $srcnum{$suffix} = $srcn;
1.597 raeburn 1674: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1675: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1676: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1677: my ($srcd,$srcn) = split(/_/,$cid);
1678: # When paste buffer was populated using an active role in a different course
1679: # check for mdc privilege in the course from which the resource was pasted
1680: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1681: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1682: $notincrs{$suffix} = 1;
1683: next;
1684: }
1685: }
1.632 raeburn 1686: # When buffer was populated using an active role in a different course
1687: # disallow pasting of External Tool if course is in a different domain.
1688: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1689: $notindom{$suffix} = 1;
1690: next;
1691: }
1.596 raeburn 1692: $srcdom{$suffix} = $srcd;
1693: $srcnum{$suffix} = $srcn;
1.491 raeburn 1694: }
1.597 raeburn 1695: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1696: push(@dopaste,$suffix);
1697: if ($url=~/\.(page|sequence)$/) {
1698: $is_map{$suffix} = 1;
1699: }
1700: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1701: my $oldprefix = $1;
1.492 raeburn 1702: # When pasting content from Main Content to Supplemental Content and vice versa
1703: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1704: # a folder/page or a document).
1.538 raeburn 1705: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1706: $prefixchg{$suffix} = 'docstosupp';
1707: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1708: $prefixchg{$suffix} = 'supptodocs';
1709: }
1.491 raeburn 1710:
1.492 raeburn 1711: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1712: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1713: my @nested;
1714: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1715: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1716: my @deps = map { /\d+:([\d,]+$)/ } @items;
1717: foreach my $dep (@deps) {
1718: if ($dep =~ /,/) {
1719: push(@nested,split(/,/,$dep));
1720: } else {
1721: push(@nested,$dep);
1722: }
1.492 raeburn 1723: }
1.538 raeburn 1724: foreach my $item (@nested) {
1725: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1726: push(@{$marktomove{$suffix}},$type.'_'.$item);
1727: }
1.492 raeburn 1728: }
1729: }
1.488 raeburn 1730: }
1731: }
1732:
1.538 raeburn 1733: # Early out if nothing available to paste
1734: if (@dopaste == 0) {
1735: return ();
1736: }
1737:
1738: # Populate message hash and hashes used for main content <=> supplemental content
1739: # changes
1740:
1741: %msgs = &Apache::lonlocal::texthash (
1742: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1743: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.627 raeburn 1744: notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.538 raeburn 1745: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1746: );
1747:
1748: %before = (
1749: docstosupp => {
1750: map => 'default',
1751: doc => 'docs',
1752: },
1753: supptodocs => {
1754: map => 'supplemental',
1755: doc => 'supplemental',
1756: },
1757: );
1758:
1759: %after = (
1760: docstosupp => {
1761: map => 'supplemental',
1762: doc => 'supplemental'
1763: },
1764: supptodocs => {
1765: map => 'default',
1766: doc => 'docs',
1767: },
1768: );
1769:
1770: # Retrieve information about all course maps in main content area
1771:
1772: my $allmaps = {};
1773: if ($folder =~ /^default/) {
1774: $allmaps =
1775: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1776: $env{"course.$env{'request.course.id'}.home"},
1777: $env{'request.course.id'});
1778: }
1779:
1780: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1781:
1782: # Loop over the items to paste
1783: foreach my $suffix (@dopaste) {
1.329 droeschl 1784: # Maps need to be copied first
1.538 raeburn 1785: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1786: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1787: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1788: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1789: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1790: }
1791: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1792: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1793: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1794: my $oldurl = $url;
1795: if ($is_map{$suffix}) {
1.491 raeburn 1796: # If pasting a map, check if map contains other maps
1.538 raeburn 1797: my (%hierarchy,%titles);
1.627 raeburn 1798: &contained_map_check($url,$folder,$coursenum,$coursedom,
1799: \%removefrommap,\%removeparam,\%addedmaps,
1800: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1801: if ($url=~ m{^/uploaded/}) {
1802: my $newurl;
1803: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1804: ($newurl,my $error) =
1805: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1806: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1807: \$title,$allmaps,\%newurls);
1808: if ($error) {
1809: $allerrors{$suffix} = $error;
1810: next;
1811: }
1812: if ($newurl ne '') {
1813: if ($newurl ne $url) {
1814: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1815: $newsubdir{$url} = $1;
1816: }
1817: $mapchanges{$url} = 1;
1.492 raeburn 1818: }
1.538 raeburn 1819: }
1820: }
1821: if (($srcdom{$suffix} ne $coursedom) ||
1822: ($srcnum{$suffix} ne $coursenum) ||
1823: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1824: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1825: $coursedom,$coursenum,$srcdom{$suffix},
1826: $srcnum{$suffix},$allmaps,\%rewrites,
1827: \%retitles,\%copies,\%dbcopies,
1828: \%zombies,\%params,\%mapmoves,
1829: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1830: \%newurls,\%resdatacopy)) {
1.538 raeburn 1831: $mapmoves{$url} = 1;
1832: }
1833: $url = $newurl;
1834: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1835: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1836: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1837: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1838: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1839: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1840: }
1841: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1842: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1843: push(@toclear,$suffix);
1844: # if pasting published map (main content area only) check map not already in course
1845: if ($folder =~ /^default/) {
1846: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1847: $duplicate{$suffix} = 1;
1848: next;
1.492 raeburn 1849: }
1.491 raeburn 1850: }
1851: }
1.538 raeburn 1852: }
1.627 raeburn 1853: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1854: my $prefix = $1;
1.596 raeburn 1855: my $fromothercrs;
1.538 raeburn 1856: #need to copy the db contents to a new one, unless this is a move.
1857: my %info = (
1858: src => $url,
1859: cdom => $coursedom,
1860: cnum => $coursenum,
1.596 raeburn 1861: );
1862: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1863: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1864: $fromothercrs = 1;
1865: $info{'cdom'} = $srcdom{$suffix};
1866: $info{'cnum'} = $srcnum{$suffix};
1867: }
1868: }
1869: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 1870: my (%lockerr,$msg);
1.538 raeburn 1871: my ($newurl,$result,$errtext) =
1872: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1873: if ($result eq 'ok') {
1874: $url = $newurl;
1875: $title=&mt('Copy of').' '.$title;
1876: } else {
1877: if ($prefix eq 'smppg') {
1878: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1879: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1880: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 1881: } elsif ($prefix eq 'ext.tool') {
1882: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 1883: }
1884: $results{$suffix} = $result;
1885: $msgerrs{$suffix} = $msg;
1886: $lockerrs{$suffix} = $lockerr{$prefix};
1887: next;
1888: }
1889: if ($lockerr{$prefix}) {
1890: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1891: }
1.489 raeburn 1892: }
1893: }
1.538 raeburn 1894: $title = &LONCAPA::map::qtunescape($title);
1895: my $ext='false';
1896: if ($url=~m{^http(|s)://}) { $ext='true'; }
1897: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1898: if ($folder !~ /^supplemental/) {
1899: (undef,undef,$title) =
1900: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1901: }
1902: } else {
1903: if ($folder=~/^supplemental/) {
1904: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1905: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1906: }
1.533 raeburn 1907: }
1.491 raeburn 1908:
1909: # For uploaded files (excluding pages/sequences) path in copied file is changed
1910: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1911: # courses.
1912:
1.538 raeburn 1913: unless ($is_map{$suffix}) {
1914: my $newidx;
1.492 raeburn 1915: # Now insert the URL at the bottom
1.538 raeburn 1916: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1917: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1918: my $relpath = $1;
1919: if ($relpath ne '') {
1920: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1921: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1922: my $newprefix = $newloc;
1923: if ($newloc eq 'default') {
1924: $newprefix = 'docs';
1925: }
1926: if ($newdocsdir eq '') {
1927: $newdocsdir = 'default';
1928: }
1.630 raeburn 1929: if (($prefixchg{$suffix}) ||
1930: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 1931: ($srcnum{$suffix} ne $coursenum) ||
1932: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1933: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1934: $url =
1935: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1936: &Apache::lonnet::getfile($oldurl));
1937: if ($url eq '/adm/notfound.html') {
1938: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1939: next;
1940: } else {
1941: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1942: $newsubpath =~ s{/+$}{/};
1943: $docmoves{$oldurl} = $newsubpath;
1944: }
1.491 raeburn 1945: }
1946: }
1.597 raeburn 1947: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1948: my $template = $1;
1949: if ($newidx) {
1950: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1951: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1952: }
1.491 raeburn 1953: }
1.538 raeburn 1954: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1955: ':'.$ext.':normal:res';
1956: push(@LONCAPA::map::order,$newidx);
1957: # Store the result
1958: my ($errtext,$fatal) =
1959: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1960: if ($fatal) {
1961: $save_err .= $errtext;
1962: $allresult = 'fail';
1963: }
1.488 raeburn 1964: }
1.538 raeburn 1965:
1.597 raeburn 1966: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1967: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1968: unless ($allresult eq 'fail') {
1969: my %updated = (
1970: rewrites => \%rewrites,
1971: zombies => \%zombies,
1972: removefrommap => \%removefrommap,
1973: removeparam => \%removeparam,
1974: dbcopies => \%dbcopies,
1.597 raeburn 1975: resdatacopy => \%resdatacopy,
1.538 raeburn 1976: retitles => \%retitles,
1977: );
1978: my %info = (
1979: newsubdir => \%newsubdir,
1980: params => \%params,
1981: );
1982: if ($prefixchg{$suffix}) {
1983: $info{'before'} = $before{$prefixchg{$suffix}};
1984: $info{'after'} = $after{$prefixchg{$suffix}};
1985: }
1986: my %moves = (
1987: copies => \%copies,
1988: docmoves => \%docmoves,
1989: mapmoves => \%mapmoves,
1990: );
1991: (my $result,$msgs{$suffix},my $lockerror) =
1992: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1993: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1994: $url,'paste');
1995: $lockerrors .= $lockerror;
1996: if ($result eq 'ok') {
1997: if ($is_map{$suffix}) {
1998: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1999: $folder.'.'.$container);
2000: if ($fatal) {
2001: $allresult = 'failread';
2002: } else {
2003: if ($#LONCAPA::map::order<1) {
2004: my $idx=&LONCAPA::map::getresidx();
2005: if ($idx<=0) { $idx=1; }
2006: $LONCAPA::map::order[0]=$idx;
2007: $LONCAPA::map::resources[$idx]='';
2008: }
2009: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2010: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2011: ':'.$ext.':normal:res';
2012: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2013:
2014: # Store the result
1.538 raeburn 2015: my ($errtext,$fatal) =
2016: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2017: if ($fatal) {
2018: $save_err .= $errtext;
2019: $allresult = 'failstore';
2020: }
2021: }
2022: }
2023: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2024: push(@toclear,$suffix);
2025: }
2026: }
1.492 raeburn 2027: }
2028: }
1.538 raeburn 2029: &clear_from_buffer(\@toclear,\@currpaste);
2030: my $msgsarray;
2031: foreach my $suffix (keys(%msgs)) {
2032: if (ref($msgs{$suffix}) eq 'ARRAY') {
2033: $msgsarray .= join(',',@{$msgs{$suffix}});
2034: }
2035: }
2036: return ($allresult,$save_err,$msgsarray,$lockerrors);
2037: }
1.533 raeburn 2038:
1.538 raeburn 2039: sub do_buffer_empty {
2040: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2041: if (@currpaste == 0) {
2042: return &mt('Clipboard is already empty');
2043: }
2044: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2045: if (@toclear == 0) {
2046: return &mt('Nothing selected to clear from clipboard');
2047: }
2048: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2049: if ($numdel) {
2050: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2051: } else {
2052: return &mt('Clipboard unchanged');
1.492 raeburn 2053: }
1.538 raeburn 2054: return;
2055: }
2056:
2057: sub clear_from_buffer {
2058: my ($toclear,$currpaste) = @_;
2059: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2060: my %pastebuffer;
2061: map { $pastebuffer{$_} = 1; } @{$currpaste};
2062: my $numdel = 0;
2063: foreach my $suffix (@{$toclear}) {
2064: next if ($suffix =~ /\D/);
2065: next unless (exists($pastebuffer{$suffix}));
2066: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2067: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2068: delete($pastebuffer{$suffix});
2069: $numdel ++;
2070: }
2071: }
2072: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2073: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2074: return $numdel;
1.492 raeburn 2075: }
2076:
2077: sub get_newmap_url {
2078: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2079: $titleref,$allmaps,$newurls) = @_;
2080: my $newurl;
2081: if ($url=~ m{^/uploaded/}) {
2082: $$titleref=&mt('Copy of').' '.$$titleref;
2083: }
2084: my $now = time;
2085: my $suffix=$$.int(rand(100)).$now;
2086: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2087: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2088: my $path = $1;
2089: my $prefix = $2;
2090: my $ancestor = $3;
2091: if (length($ancestor) > 10) {
2092: $ancestor = substr($ancestor,-10,10);
2093: }
2094: my $newid;
2095: if ($prefixchg) {
2096: if ($folder =~ /^supplemental/) {
2097: $prefix =~ s/^default/supplemental/;
2098: } else {
2099: $prefix =~ s/^supplemental/default/;
2100: }
2101: }
2102: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2103: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2104: } else {
2105: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2106: }
2107: my $counter = 0;
2108: my $is_unique = &uniqueness_check($newurl);
2109: if ($folder =~ /^default/) {
2110: if ($allmaps->{$newurl}) {
2111: $is_unique = 0;
2112: }
2113: }
2114: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2115: $counter ++;
2116: $suffix ++;
2117: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2118: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2119: } else {
2120: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2121: }
2122: $is_unique = &uniqueness_check($newurl);
2123: }
2124: if ($is_unique) {
2125: $newurls->{$newurl} = 1;
2126: } else {
2127: if ($url=~/\.page$/) {
2128: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2129: } else {
2130: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2131: }
2132: }
1.329 droeschl 2133: }
1.492 raeburn 2134: return ($newurl);
1.329 droeschl 2135: }
2136:
1.488 raeburn 2137: sub dbcopy {
1.533 raeburn 2138: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2139: my ($url,$result,$errtext);
2140: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2141: $url = $dbref->{'src'};
1.627 raeburn 2142: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2143: my $prefix = $1;
1.627 raeburn 2144: if ($prefix eq 'ext.tool') {
2145: $prefix = 'exttool';
2146: }
1.533 raeburn 2147: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2148: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2149: my $db_name;
2150: my $marker = (split(m{/},$url))[4];
2151: $marker=~s/\D//g;
2152: if ($dbref->{'src'} =~ m{/smppg$}) {
2153: $db_name =
2154: &Apache::lonsimplepage::get_db_name($url,$marker,
2155: $dbref->{'cdom'},
2156: $dbref->{'cnum'});
1.627 raeburn 2157: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2158: $db_name = 'exttool_'.$marker;
1.533 raeburn 2159: } else {
2160: $db_name = 'bulletinpage_'.$marker;
2161: }
2162: my ($suffix,$freedlock,$error) =
2163: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2164: $coursedom,$coursenum,
2165: 'concat');
2166: if (!$suffix) {
2167: if ($prefix eq 'smppg') {
2168: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2169: } elsif ($prefix eq 'exttool') {
2170: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2171: } else {
1.565 bisitz 2172: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2173: }
2174: if ($error) {
2175: $errtext .= '<br />'.$error;
2176: }
2177: } else {
2178: #need to copy the db contents to a new one.
2179: my %contents=&Apache::lonnet::dump($db_name,
2180: $dbref->{'cdom'},
2181: $dbref->{'cnum'});
2182: if (exists($contents{'uploaded.photourl'})) {
2183: my $photo = $contents{'uploaded.photourl'};
2184: my ($subdir,$fname) =
2185: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2186: my $newphoto;
1.533 raeburn 2187: if ($fname ne '') {
2188: my $content = &Apache::lonnet::getfile($photo);
2189: unless ($content eq '-1') {
2190: $env{'form.'.$suffix.'.photourl'} = $content;
2191: $newphoto =
2192: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2193: delete($env{'form.'.$suffix.'.photourl'});
2194: }
2195: }
2196: if ($newphoto =~ m{^/uploaded/}) {
2197: $contents{'uploaded.photourl'} = $newphoto;
2198: }
2199: }
2200: $db_name =~ s{_\d*$ }{_$suffix}x;
2201: $result=&Apache::lonnet::put($db_name,\%contents,
2202: $coursedom,$coursenum);
2203: if ($result eq 'ok') {
1.627 raeburn 2204: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2205: }
2206: }
2207: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2208: $lockerrorsref->{$prefix} =
1.533 raeburn 2209: '<div class="LC_error">'.
2210: &mt('There was a problem removing a lockfile.');
2211: if ($prefix eq 'smppg') {
1.560 raeburn 2212: $lockerrorsref->{$prefix} .=
1.559 raeburn 2213: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2214: } elsif ($prefix eq 'exttool') {
2215: $lockerrorsref->{$prefix} .=
2216: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2217: } else {
1.565 bisitz 2218: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2219: }
1.560 raeburn 2220: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2221: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2222: '</div>';
1.533 raeburn 2223: }
2224: }
2225: } elsif ($url =~ m{/syllabus$}) {
2226: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2227: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2228: if (($dbref->{'cdom'} ne $coursedom) ||
2229: ($dbref->{'cnum'} ne $coursenum)) {
2230: my %contents=&Apache::lonnet::dump('syllabus',
2231: $dbref->{'cdom'},
2232: $dbref->{'cnum'});
2233: $result=&Apache::lonnet::put('syllabus',\%contents,
2234: $coursedom,$coursenum);
2235: }
2236: }
1.488 raeburn 2237: }
2238: }
1.533 raeburn 2239: return ($url,$result,$errtext);
1.488 raeburn 2240: }
2241:
1.597 raeburn 2242: sub copy_templated_files {
2243: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2244: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2245: my $srccontainer = 'sequence';
2246: if ($srcwaspage) {
2247: $srccontainer = 'page';
2248: }
2249: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2250: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2251: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2252: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2253: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2254: $template.'.problem';
2255: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2256: if ($template eq 'simpleproblem') {
2257: $srcprefix .= '.0.';
2258: my $weightprefix = $newprefix;
2259: $newprefix .= '.0.';
2260: my @simpleprobqtypes = qw(radio option string essay numerical);
2261: my $qtype=$srcparms{$srcprefix.'questiontype'};
2262: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2263: my %newdata;
2264: foreach my $type (@simpleprobqtypes) {
2265: if ($type eq $qtype) {
2266: $newdata{"$weightprefix.$type.weight"}=1;
2267: } else {
2268: $newdata{"$weightprefix.$type.weight"}=0;
2269: }
2270: }
2271: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2272: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2273: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2274: if ($qtype eq 'numerical') {
2275: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2276: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2277: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2278: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2279: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2280: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2281: unless (defined($maxfoils)) { $maxfoils=10; }
2282: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2283: if ($maxfoils<=0) { $maxfoils=10; }
2284: my $randomize=$srcparms{$srcprefix.'randomize'};
2285: unless (defined($randomize)) { $randomize='yes'; }
2286: unless ($randomize eq 'no') { $randomize='yes'; }
2287: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2288: $newdata{$newprefix.'randomize'} = $randomize;
2289: if ($qtype eq 'option') {
2290: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2291: }
2292: for (my $i=1; $i<=10; $i++) {
2293: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2294: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2295: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2296: }
2297:
2298: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2299: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2300: unless (defined($maxfoils)) { $maxfoils=10; }
2301: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2302: if ($maxfoils<=0) { $maxfoils=10; }
2303: my $randomize=$srcparms{$srcprefix.'randomize'};
2304: unless (defined($randomize)) { $randomize='yes'; }
2305: unless ($randomize eq 'no') { $randomize='yes'; }
2306: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2307: $newdata{$newprefix.'randomize'} = $randomize;
2308: if ($qtype eq 'option') {
2309: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2310: }
2311: for (my $i=1; $i<=10; $i++) {
2312: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2313: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2314: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2315: }
2316: } elsif ($qtype eq 'string') {
2317: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2318: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2319: }
2320: if (keys(%newdata)) {
2321: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2322: $coursenum);
2323: if ($putres eq 'ok') {
2324: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2325: }
2326: }
2327: }
2328: }
2329: }
2330:
1.329 droeschl 2331: sub uniqueness_check {
2332: my ($newurl) = @_;
2333: my $unique = 1;
2334: foreach my $res (@LONCAPA::map::order) {
2335: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2336: $url=&LONCAPA::map::qtescape($url);
2337: if ($newurl eq $url) {
2338: $unique = 0;
1.344 bisitz 2339: last;
1.329 droeschl 2340: }
2341: }
2342: return $unique;
2343: }
2344:
1.488 raeburn 2345: sub contained_map_check {
1.627 raeburn 2346: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2347: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2348: my $content = &Apache::lonnet::getfile($url);
2349: unless ($content eq '-1') {
2350: my $parser = HTML::TokeParser->new(\$content);
2351: $parser->attr_encoded(1);
2352: while (my $token = $parser->get_token) {
2353: next if ($token->[0] ne 'S');
2354: if ($token->[1] eq 'resource') {
2355: next if ($token->[2]->{'type'} eq 'zombie');
2356: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2357: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2358: my $srcdom = $1;
2359: unless ($srcdom eq $coursedom) {
2360: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2361: next;
2362: }
2363: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2364: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2365: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2366: next;
2367: }
2368: }
1.492 raeburn 2369: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2370: if ($1 eq 'uploaded') {
2371: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2372: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2373: } else {
1.492 raeburn 2374: if ($allmaps->{$ressrc}) {
1.529 raeburn 2375: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2376: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2377: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2378: } else {
2379: $addedmaps->{$ressrc} = [$url];
2380: }
1.488 raeburn 2381: }
1.627 raeburn 2382: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2383: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2384: }
1.492 raeburn 2385: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2386: if ($folder =~ /^supplemental/) {
1.492 raeburn 2387: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2388: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2389: } else {
2390: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2391: }
1.488 raeburn 2392: }
2393: }
2394: }
2395: }
2396: return;
2397: }
2398:
2399: sub url_paste_fixups {
1.533 raeburn 2400: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2401: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2402: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2403: my $checktitle;
2404: if (($prefixchg) &&
1.492 raeburn 2405: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2406: $checktitle = 1;
2407: }
1.492 raeburn 2408: my $skip;
2409: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2410: my $mapid = $1.$2;
2411: if ($tomove->{$mapid}) {
2412: $skip = 1;
2413: }
2414: }
1.491 raeburn 2415: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2416: return if ($file eq '-1');
2417: my $parser = HTML::TokeParser->new(\$file);
2418: $parser->attr_encoded(1);
1.491 raeburn 2419: my $changed = 0;
1.488 raeburn 2420: while (my $token = $parser->get_token) {
2421: next if ($token->[0] ne 'S');
2422: if ($token->[1] eq 'resource') {
2423: my $ressrc = $token->[2]->{'src'};
2424: next if ($ressrc eq '');
1.491 raeburn 2425: my $id = $token->[2]->{'id'};
1.492 raeburn 2426: my $title = $token->[2]->{'title'};
1.491 raeburn 2427: if ($checktitle) {
2428: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2429: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2430: }
2431: }
1.488 raeburn 2432: next if ($token->[2]->{'type'} eq 'external');
2433: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2434: next if ($skip);
1.532 raeburn 2435: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2436: $changed = 1;
2437: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2438: my $srcdom = $1;
2439: my $srcnum = $2;
1.488 raeburn 2440: my $rem = $3;
1.492 raeburn 2441: my $newurl;
2442: my $mapname;
2443: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2444: my $prefix = $1;
2445: $mapname = $prefix.$2;
2446: if ($tomove->{$mapname}) {
1.533 raeburn 2447: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2448: $srcdom,$srcnum,$allmaps,$rewrites,
2449: $retitles,$copies,$dbcopies,$zombies,
2450: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2451: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2452: next;
2453: } else {
2454: ($newurl,my $error) =
2455: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2456: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2457: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2458: $newsubdir->{$ressrc} = $1;
2459: }
2460: if ($error) {
2461: next;
2462: }
2463: }
2464: }
2465: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2466: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2467:
1.488 raeburn 2468: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2469: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2470: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2471: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2472: $cnum,$srcdom,$srcnum,$allmaps,
2473: $rewrites,$retitles,$copies,$dbcopies,
2474: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2475: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2476: $mapmoves->{$ressrc} = 1;
2477: }
2478: $changed = 1;
1.488 raeburn 2479: } else {
1.532 raeburn 2480: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2481: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2482: $changed = 1;
1.488 raeburn 2483: }
2484: }
1.533 raeburn 2485: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2486: next if ($skip);
1.492 raeburn 2487: my $srcdom = $1;
2488: my $srcnum = $2;
2489: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2490: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2491: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2492: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2493: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2494: $changed = 1;
2495: }
2496: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2497: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2498: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2499: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2500: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2501: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2502: $changed = 1;
1.488 raeburn 2503: }
1.597 raeburn 2504: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2505: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2506: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2507: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2508: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2509: }
1.488 raeburn 2510: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2511: next if ($skip);
2512: my $srcdom = $1;
2513: my $srcnum = $2;
2514: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2515: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2516: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2517: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2518: $changed = 1;
1.488 raeburn 2519: }
2520: }
2521: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2522: next if ($skip);
1.488 raeburn 2523: my $to = $token->[2]->{'to'};
2524: if ($to ne '') {
2525: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2526: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2527: } else {
2528: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2529: }
2530: }
2531: }
2532: }
1.491 raeburn 2533: return $changed;
1.488 raeburn 2534: }
2535:
2536: sub apply_fixups {
1.529 raeburn 2537: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2538: $oldurl,$url,$caller) = @_;
2539: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2540: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2541: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2542: if (ref($updated) eq 'HASH') {
2543: if (ref($updated->{'rewrites'}) eq 'HASH') {
2544: %rewrites = %{$updated->{'rewrites'}};
2545: }
2546: if (ref($updated->{'zombies'}) eq 'HASH') {
2547: %zombies = %{$updated->{'zombies'}};
2548: }
2549: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2550: %removefrommap = %{$updated->{'removefrommap'}};
2551: }
2552: if (ref($updated->{'removeparam'}) eq 'HASH') {
2553: %removeparam = %{$updated->{'removeparam'}};
2554: }
2555: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2556: %dbcopies = %{$updated->{'dbcopies'}};
2557: }
2558: if (ref($updated->{'retitles'}) eq 'HASH') {
2559: %retitles = %{$updated->{'retitles'}};
2560: }
1.597 raeburn 2561: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2562: %resdatacopy = %{$updated->{'resdatacopy'}};
2563: }
1.529 raeburn 2564: }
2565: if (ref($info) eq 'HASH') {
2566: if (ref($info->{'newsubdir'}) eq 'HASH') {
2567: %newsubdir = %{$info->{'newsubdir'}};
2568: }
2569: if (ref($info->{'params'}) eq 'HASH') {
2570: %params = %{$info->{'params'}};
2571: }
2572: if (ref($info->{'before'}) eq 'HASH') {
2573: %before = %{$info->{'before'}};
2574: }
2575: if (ref($info->{'after'}) eq 'HASH') {
2576: %after = %{$info->{'after'}};
2577: }
2578: }
2579: if (ref($moves) eq 'HASH') {
2580: if (ref($moves->{'copies'}) eq 'HASH') {
2581: %copies = %{$moves->{'copies'}};
2582: }
2583: if (ref($moves->{'docmoves'}) eq 'HASH') {
2584: %docmoves = %{$moves->{'docmoves'}};
2585: }
2586: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2587: %mapmoves = %{$moves->{'mapmoves'}};
2588: }
2589: }
2590: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2591: my @allcopies;
1.529 raeburn 2592: if (exists($copies{$key})) {
2593: if (ref($copies{$key}) eq 'HASH') {
2594: my %added;
2595: foreach my $innerkey (keys(%{$copies{$key}})) {
2596: if (($innerkey ne '') && (!$added{$innerkey})) {
2597: push(@allcopies,$innerkey);
2598: $added{$innerkey} = 1;
2599: }
1.491 raeburn 2600: }
1.529 raeburn 2601: undef(%added);
1.491 raeburn 2602: }
2603: }
2604: if ($key eq $oldurl) {
1.529 raeburn 2605: if ((exists($docmoves{$key}))) {
1.532 raeburn 2606: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2607: push(@allcopies,$oldurl);
2608: }
2609: }
2610: }
2611: if (@allcopies > 0) {
2612: foreach my $item (@allcopies) {
1.492 raeburn 2613: my ($relpath,$oldsubdir,$fname) =
2614: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2615: if ($fname ne '') {
2616: my $content = &Apache::lonnet::getfile($item);
2617: unless ($content eq '-1') {
2618: my $storefn;
1.529 raeburn 2619: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2620: $storefn = $docmoves{$key};
1.491 raeburn 2621: } else {
2622: $storefn = $relpath;
2623: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2624: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2625: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2626: }
1.529 raeburn 2627: if ($newsubdir{$key}) {
1.532 raeburn 2628: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2629: }
2630: }
2631: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2632: my $copyurl =
2633: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2634: $storefn.$fname,$content);
2635: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2636: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2637: return &mt('Paste failed: an error occurred copying the file.');
2638: } elsif (ref($errors) eq 'HASH') {
2639: $errors->{$item} = 1;
1.489 raeburn 2640: }
2641: }
1.488 raeburn 2642: }
2643: }
1.491 raeburn 2644: }
2645: }
2646: }
1.529 raeburn 2647: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2648: my $storefn=$key;
2649: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2650: if ($prefixchg && $before{'map'} && $after{'map'}) {
2651: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2652: }
1.529 raeburn 2653: if ($newsubdir{$key}) {
2654: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2655: }
1.491 raeburn 2656: my $mapcontent = &Apache::lonnet::getfile($key);
2657: if ($mapcontent eq '-1') {
2658: if (ref($errors) eq 'HASH') {
2659: $errors->{$key} = 1;
2660: }
2661: } else {
2662: my $newmap =
2663: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2664: $mapcontent);
2665: if ($newmap eq '/adm/notfound.html') {
2666: if (ref($errors) eq 'HASH') {
2667: $errors->{$key} = 1;
1.489 raeburn 2668: }
1.488 raeburn 2669: }
2670: }
2671: }
1.491 raeburn 2672: my %updates;
2673: if ($is_map) {
1.529 raeburn 2674: if (ref($updated) eq 'HASH') {
2675: foreach my $type (keys(%{$updated})) {
2676: if (ref($updated->{$type}) eq 'HASH') {
2677: foreach my $key (keys(%{$updated->{$type}})) {
2678: $updates{$key} = 1;
2679: }
2680: }
2681: }
1.491 raeburn 2682: }
2683: foreach my $key (keys(%updates)) {
1.492 raeburn 2684: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2685: if (ref($rewrites{$key}) eq 'HASH') {
2686: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2687: }
1.529 raeburn 2688: if (ref($retitles{$key}) eq 'HASH') {
2689: %toretitle = %{$retitles{$key}};
1.491 raeburn 2690: }
1.529 raeburn 2691: if (ref($removefrommap{$key}) eq 'HASH') {
2692: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2693: }
1.529 raeburn 2694: if (ref($removeparam{$key}) eq 'HASH') {
2695: %remparam = %{$removeparam{$key}};
1.492 raeburn 2696: }
1.529 raeburn 2697: if (ref($zombies{$key}) eq 'HASH') {
2698: %zombie = %{$zombies{$key}};
1.491 raeburn 2699: }
1.529 raeburn 2700: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2701: foreach my $idx (keys(%{$dbcopies{$key}})) {
2702: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2703: my ($newurl,$result,$errtext) =
2704: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2705: if ($result eq 'ok') {
2706: $newdb{$idx} = $newurl;
2707: } elsif (ref($errors) eq 'HASH') {
2708: $errors->{$key} = 1;
2709: }
2710: push(@msgs,$errtext);
2711: }
1.491 raeburn 2712: }
2713: }
1.597 raeburn 2714: if (ref($resdatacopy{$key}) eq 'HASH') {
2715: if ($newsubdir{$key}) {
2716:
2717: }
2718: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2719: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2720: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2721: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2722: my $template = $1;
2723: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2724: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2725: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2726: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2727: my ($newmapname) = ($key =~ m{/([^/]+)$});
2728: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2729: my $srcmapinfo = $srcfolder.':'.$idx;
2730: if ($srccontainer eq 'page') {
2731: $srcmapinfo .= ':1';
2732: }
2733: if ($newsubdir{$key}) {
2734: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2735: }
2736: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2737: $cnum,$template,$idx,$newmapname);
2738: }
2739: }
2740: }
2741: }
2742: }
1.529 raeburn 2743: if (ref($params{$key}) eq 'HASH') {
2744: %currparam = %{$params{$key}};
1.492 raeburn 2745: }
2746: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2747: if ($fatal) {
1.533 raeburn 2748: return ($errtext);
1.492 raeburn 2749: }
2750: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2751: if (defined($LONCAPA::map::zombies[$i])) {
2752: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2753: if ($zombie{$i} eq $src) {
1.492 raeburn 2754: undef($LONCAPA::map::zombies[$i]);
2755: }
2756: }
2757: }
1.529 raeburn 2758: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2759: my $idx = $LONCAPA::map::order[$i];
2760: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2761: my $changed;
1.529 raeburn 2762: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2763: if ((exists($toremove{$idx})) &&
2764: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2765: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2766: if (ref($currparam{$idx}) eq 'ARRAY') {
2767: foreach my $name (@{$currparam{$idx}}) {
2768: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2769: }
2770: }
2771: next;
2772: }
2773: my $origsrc = $src;
1.532 raeburn 2774: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2775: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2776: $changed = 1;
1.491 raeburn 2777: }
1.492 raeburn 2778: }
1.532 raeburn 2779: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2780: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2781: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2782: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2783: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2784: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2785: } else {
1.529 raeburn 2786: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2787: }
1.491 raeburn 2788: }
1.532 raeburn 2789: if ($origsrc =~ /\.(page|sequence)$/) {
2790: if ($newsubdir{$origsrc}) {
1.529 raeburn 2791: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2792: }
1.532 raeburn 2793: } elsif ($newsubdir{$key}) {
2794: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2795: }
2796: }
1.492 raeburn 2797: $changed = 1;
1.533 raeburn 2798: } elsif ($newdb{$idx} ne '') {
2799: $src = $newdb{$idx};
1.492 raeburn 2800: $changed = 1;
2801: }
2802: if ($changed) {
1.538 raeburn 2803: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2804: }
2805: }
2806: }
2807: foreach my $idx (keys(%remparam)) {
2808: if (ref($remparam{$idx}) eq 'ARRAY') {
2809: foreach my $name (@{$remparam{$idx}}) {
2810: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2811: }
2812: }
2813: }
1.533 raeburn 2814: if (values(%lockerrors) > 0) {
2815: $lockmsg = join('<br />',values(%lockerrors));
2816: }
1.491 raeburn 2817: my $storefn;
2818: if ($key eq $oldurl) {
2819: $storefn = $url;
2820: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2821: } else {
2822: $storefn = $key;
2823: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2824: if ($prefixchg && $before{'map'} && $after{'map'}) {
2825: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2826: }
1.529 raeburn 2827: if ($newsubdir{$key}) {
2828: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2829: }
1.491 raeburn 2830: }
1.492 raeburn 2831: my $report;
2832: if ($folder !~ /^supplemental/) {
2833: $report = 1;
2834: }
1.527 raeburn 2835: (my $outtext,$errtext) =
1.492 raeburn 2836: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2837: if ($errtext) {
1.529 raeburn 2838: if ($caller eq 'paste') {
1.533 raeburn 2839: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2840: }
1.491 raeburn 2841: }
2842: }
2843: }
1.533 raeburn 2844: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2845: }
2846:
2847: sub copy_dependencies {
2848: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2849: my $content;
2850: if (ref($contentref)) {
2851: $content = $$contentref;
2852: } else {
2853: $content = &Apache::lonnet::getfile($item);
2854: }
2855: unless ($content eq '-1') {
2856: my $mm = new File::MMagic;
2857: my $mimetype = $mm->checktype_contents($content);
2858: if ($mimetype eq 'text/html') {
2859: my (%allfiles,%codebase,$state);
2860: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2861: if ($res eq 'ok') {
2862: my ($numexisting,$numpathchanges,$existing);
2863: (undef,$numexisting,$numpathchanges,$existing) =
2864: &Apache::loncommon::ask_for_embedded_content(
2865: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2866: {'error_on_invalid_names' => 1,
2867: 'ignore_remote_references' => 1,
2868: 'docs_url' => $item,
2869: 'context' => 'paste'});
2870: if ($numexisting > 0) {
2871: if (ref($existing) eq 'HASH') {
2872: foreach my $dep (keys(%{$existing})) {
2873: my $depfile = $dep;
2874: unless ($depfile =~ m{^\Q$relpath\E}) {
2875: $depfile = $relpath.$dep;
2876: }
2877: my $depcontent = &Apache::lonnet::getfile($depfile);
2878: unless ($depcontent eq '-1') {
2879: my $storedep = $dep;
2880: $storedep =~ s{^\Q$relpath\E}{};
2881: my $dep_url =
2882: &Apache::lonclonecourse::writefile(
2883: $env{'request.course.id'},
2884: $storefn.$storedep,$depcontent);
2885: if ($dep_url eq '/adm/notfound.html') {
2886: if (ref($errors) eq 'HASH') {
2887: $errors->{$depfile} = 1;
2888: }
2889: } else {
2890: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2891: }
2892: }
2893: }
1.488 raeburn 2894: }
2895: }
2896: }
2897: }
2898: }
2899: return;
2900: }
2901:
1.329 droeschl 2902: my %parameter_type = ( 'randompick' => 'int_pos',
2903: 'hiddenresource' => 'string_yesno',
2904: 'encrypturl' => 'string_yesno',
2905: 'randomorder' => 'string_yesno',);
2906: my $valid_parameters_re = join('|',keys(%parameter_type));
2907: # set parameters
2908: sub update_parameter {
1.537 raeburn 2909: if ($env{'form.changeparms'} eq 'all') {
2910: my (@allidx,@allmapidx,%allchecked,%currchecked);
2911: %allchecked = (
2912: 'hiddenresource' => {},
2913: 'encrypturl' => {},
2914: 'randompick' => {},
2915: 'randomorder' => {},
2916: );
2917: foreach my $which (keys(%allchecked)) {
1.630 raeburn 2918: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 2919: if ($which eq 'randompick') {
2920: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2921: my ($res,$value) = split(/:/,$item);
2922: if ($value =~ /^\d+$/) {
2923: $allchecked{$which}{$res} = $value;
2924: }
2925: }
2926: } else {
1.539 raeburn 2927: if ($env{'form.all'.$which}) {
2928: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2929: }
1.537 raeburn 2930: }
2931: }
2932: my $haschanges = 0;
2933: foreach my $res (@LONCAPA::map::order) {
2934: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2935: $name=&LONCAPA::map::qtescape($name);
2936: $url=&LONCAPA::map::qtescape($url);
2937: next unless ($name && $url);
2938: my $is_map;
2939: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2940: $is_map = 1;
2941: }
2942: foreach my $which (keys(%allchecked)) {
2943: if (($which eq 'randompick' || $which eq 'randomorder')) {
2944: next if (!$is_map);
2945: }
2946: my $oldvalue = 0;
2947: my $newvalue = 0;
2948: if ($allchecked{$which}{$res}) {
2949: $newvalue = $allchecked{$which}{$res};
2950: }
2951: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2952: if ($which eq 'randompick') {
2953: if ($current =~ /^(\d+)$/) {
2954: $oldvalue = $1;
2955: }
2956: } else {
2957: if ($current =~ /^yes$/i) {
2958: $oldvalue = 1;
2959: }
2960: }
2961: if ($oldvalue ne $newvalue) {
2962: $haschanges = 1;
2963: if ($newvalue) {
2964: my $storeval = 'yes';
2965: if ($which eq 'randompick') {
2966: $storeval = $newvalue;
2967: }
2968: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2969: $storeval,
2970: $parameter_type{$which});
2971: &remember_parms($res,$which,'set',$storeval);
2972: } elsif ($oldvalue) {
2973: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2974: &remember_parms($res,$which,'del');
2975: }
2976: }
2977: }
2978: }
2979: return $haschanges;
2980: } else {
1.588 raeburn 2981: my $haschanges = 0;
2982: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2983:
1.537 raeburn 2984: my $which = $env{'form.changeparms'};
2985: my $idx = $env{'form.setparms'};
1.588 raeburn 2986: my $oldvalue = 0;
2987: my $newvalue = 0;
2988: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2989: if ($which eq 'randompick') {
2990: if ($current =~ /^(\d+)$/) {
2991: $oldvalue = $1;
2992: }
2993: } elsif ($current =~ /^yes$/i) {
2994: $oldvalue = 1;
2995: }
1.537 raeburn 2996: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2997: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2998: : 1;
2999: }
3000: if ($oldvalue ne $newvalue) {
3001: $haschanges = 1;
3002: if ($newvalue) {
3003: my $storeval = 'yes';
3004: if ($which eq 'randompick') {
3005: $storeval = $newvalue;
3006: }
3007: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3008: $parameter_type{$which});
3009: &remember_parms($idx,$which,'set',$storeval);
3010: } else {
3011: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3012: &remember_parms($idx,$which,'del');
3013: }
1.537 raeburn 3014: }
1.588 raeburn 3015: return $haschanges;
1.329 droeschl 3016: }
3017: }
3018:
3019: sub handle_edit_cmd {
3020: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3021: my $haschanges = 0;
1.543 raeburn 3022: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3023: return $haschanges;
1.543 raeburn 3024: }
1.329 droeschl 3025: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3026:
3027: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3028: my ($title, $url, @rrest) = split(':', $ratstr);
3029:
1.538 raeburn 3030: if ($cmd eq 'remove') {
1.329 droeschl 3031: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3032: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3033: &Apache::lonnet::removeuploadedurl($url);
3034: } else {
3035: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3036: }
3037: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3038: $haschanges = 1;
1.329 droeschl 3039: } elsif ($cmd eq 'cut') {
3040: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3041: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3042: $haschanges = 1;
1.344 bisitz 3043: } elsif ($cmd eq 'up'
1.329 droeschl 3044: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3045: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3046: $haschanges = 1;
1.329 droeschl 3047: } elsif ($cmd eq 'down'
3048: && defined($LONCAPA::map::order[$idx+1])) {
3049: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3050: $haschanges = 1;
1.329 droeschl 3051: } elsif ($cmd eq 'rename') {
3052: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3053: if ($comment=~/\S/) {
3054: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3055: $comment.':'.join(':', $url, @rrest);
3056: }
3057: # Devalidate title cache
3058: my $renamed_url=&LONCAPA::map::qtescape($url);
3059: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3060: $haschanges = 1;
3061: } elsif ($cmd eq 'setalias') {
3062: my $newvalue = $env{'form.alias'};
3063: if ($newvalue ne '') {
3064: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3065: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3066: 'string');
3067: &remember_parms($idx,'mapalias','set',$newvalue);
3068: $haschanges = 1;
3069: }
3070: }
3071: } elsif ($cmd eq 'delalias') {
3072: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3073: if ($current ne '') {
3074: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3075: &remember_parms($idx,'mapalias','del');
3076: $haschanges = 1;
3077: }
1.329 droeschl 3078: }
1.633 raeburn 3079: return $haschanges;
1.329 droeschl 3080: }
3081:
3082: sub editor {
1.458 raeburn 3083: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3084: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3085: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3086: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3087: if ($allowed) {
1.519 raeburn 3088: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3089: $is_random_order,$container) =
1.510 raeburn 3090: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3091: $r->print($breadcrumbtrail);
1.519 raeburn 3092: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3093: $container = 'page';
3094: } else {
3095: $container = 'sequence';
1.510 raeburn 3096: }
1.484 raeburn 3097:
1.525 raeburn 3098: my $jumpto;
3099:
3100: unless ($supplementalflag) {
1.546 raeburn 3101: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3102: }
1.484 raeburn 3103:
3104: unless ($allowed) {
3105: $randompick = -1;
3106: }
3107:
1.615 raeburn 3108: my ($errtext,$fatal);
3109: if (($folder eq '') && (!$supplementalflag)) {
3110: if (@LONCAPA::map::order) {
3111: undef(@LONCAPA::map::order);
3112: undef(@LONCAPA::map::resources);
3113: undef(@LONCAPA::map::resparms);
3114: undef(@LONCAPA::map::zombies);
3115: }
3116: $folder = 'default';
3117: $container = 'sequence';
3118: } else {
3119: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3120: $folder.'.'.$container);
3121: return $errtext if ($fatal);
3122: }
1.329 droeschl 3123:
3124: if ($#LONCAPA::map::order<1) {
3125: my $idx=&LONCAPA::map::getresidx();
3126: if ($idx<=0) { $idx=1; }
3127: $LONCAPA::map::order[0]=$idx;
3128: $LONCAPA::map::resources[$idx]='';
3129: }
1.364 bisitz 3130:
1.329 droeschl 3131: # ------------------------------------------------------------ Process commands
3132:
3133: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3134: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3135: # set parameters and change order
3136: &snapshotbefore();
3137:
3138: if (&update_parameter()) {
1.588 raeburn 3139: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3140: return $errtext if ($fatal);
3141: }
3142:
3143: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3144: # change order
3145: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3146: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3147:
3148: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3149: return $errtext if ($fatal);
3150: }
1.364 bisitz 3151:
1.329 droeschl 3152: if ($env{'form.pastemarked'}) {
1.491 raeburn 3153: my %paste_errors;
1.533 raeburn 3154: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3155: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3156: \%paste_errors);
1.541 raeburn 3157: if (ref($pastemsgarray) eq 'ARRAY') {
3158: if (@{$pastemsgarray} > 0) {
3159: $r->print('<p class="LC_info">'.
3160: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3161: '</p>');
3162: }
1.541 raeburn 3163: }
3164: if ($lockerror) {
3165: $r->print('<p class="LC_error">'.
3166: $lockerror.
3167: '</p>');
3168: }
3169: if ($save_error ne '') {
3170: return $save_error;
3171: }
3172: if ($paste_res) {
3173: my %errortext = &Apache::lonlocal::texthash (
3174: fail => 'Storage of folder contents failed',
3175: failread => 'Reading folder contents failed',
3176: failstore => 'Storage of folder contents failed',
3177: );
3178: if ($errortext{$paste_res}) {
3179: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3180: }
1.329 droeschl 3181: }
1.491 raeburn 3182: if (keys(%paste_errors) > 0) {
1.538 raeburn 3183: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3184: &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".
3185: '<ul>'."\n");
3186: foreach my $key (sort(keys(%paste_errors))) {
3187: $r->print('<li>'.$key.'</li>'."\n");
3188: }
3189: $r->print('</ul></p>'."\n");
3190: }
1.538 raeburn 3191: } elsif ($env{'form.clearmarked'}) {
3192: my $output = &do_buffer_empty();
3193: if ($output) {
3194: $r->print('<p class="LC_info">'.$output.'</p>');
3195: }
3196: }
1.329 droeschl 3197:
3198: $r->print($upload_output);
3199:
1.538 raeburn 3200: # Rename, cut, copy or remove a single resource
1.602 raeburn 3201: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3202: my $contentchg;
1.633 raeburn 3203: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3204: $contentchg = 1;
3205: }
3206: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3207: return $errtext if ($fatal);
3208: }
1.538 raeburn 3209:
3210: # Cut, copy and/or remove multiple resources
3211: if ($env{'form.multichange'}) {
3212: my %allchecked = (
3213: cut => {},
3214: remove => {},
3215: );
3216: my $needsupdate;
3217: foreach my $which (keys(%allchecked)) {
3218: $env{'form.multi'.$which} =~ s/,$//;
3219: if ($env{'form.multi'.$which}) {
3220: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3221: if (ref($allchecked{$which}) eq 'HASH') {
3222: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3223: }
3224: }
3225: }
3226: if ($needsupdate) {
3227: my $haschanges = 0;
3228: my %curr_groups = &Apache::longroup::coursegroups();
3229: my $total = scalar(@LONCAPA::map::order) - 1;
3230: for (my $i=$total; $i>=0; $i--) {
3231: my $res = $LONCAPA::map::order[$i];
3232: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3233: $name=&LONCAPA::map::qtescape($name);
3234: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3235: next unless $url;
1.538 raeburn 3236: my %denied =
3237: &action_restrictions($coursenum,$coursedom,$url,
3238: $env{'form.folderpath'},\%curr_groups);
3239: foreach my $which (keys(%allchecked)) {
3240: next if ($denied{$which});
3241: next unless ($allchecked{$which}{$res});
3242: if ($which eq 'remove') {
3243: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3244: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3245: &Apache::lonnet::removeuploadedurl($url);
3246: } else {
3247: &LONCAPA::map::makezombie($res);
3248: }
3249: splice(@LONCAPA::map::order,$i,1);
3250: $haschanges ++;
3251: } elsif ($which eq 'cut') {
3252: &LONCAPA::map::makezombie($res);
3253: splice(@LONCAPA::map::order,$i,1);
3254: $haschanges ++;
3255: }
3256: }
3257: }
3258: if ($haschanges) {
3259: ($errtext,$fatal) =
3260: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3261: return $errtext if ($fatal);
3262: }
3263: }
3264: }
3265:
1.329 droeschl 3266: # Group import/search
3267: if ($env{'form.importdetail'}) {
3268: my @imports;
3269: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3270: if (defined($item)) {
3271: my ($name,$url,$residx)=
1.533 raeburn 3272: map { &unescape($_); } split(/\=/,$item);
3273: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3274: my ($suffix,$errortxt,$locknotfreed) =
3275: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3276: if ($locknotfreed) {
3277: $r->print($locknotfreed);
3278: }
3279: if ($suffix) {
3280: $url =~ s/_new\./_$suffix./;
3281: } else {
3282: return $errortxt;
3283: }
1.533 raeburn 3284: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3285: my $type = $1;
3286: my ($suffix,$errortxt,$locknotfreed) =
3287: &new_timebased_suffix($coursedom,$coursenum,$type);
3288: if ($locknotfreed) {
3289: $r->print($locknotfreed);
3290: }
3291: if ($suffix) {
3292: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3293: } else {
3294: return $errortxt;
3295: }
1.626 raeburn 3296: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3297: my ($suffix,$errortxt,$locknotfreed) =
3298: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3299: if ($locknotfreed) {
3300: $r->print($locknotfreed);
3301: }
3302: if ($suffix) {
3303: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3304: } else {
3305: return $errortxt;
3306: }
1.534 raeburn 3307: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3308: if ($supplementalflag) {
3309: next unless ($1 eq 'supplemental');
3310: if ($folder eq 'supplemental') {
3311: next unless ($2 eq 'default');
3312: } else {
3313: next unless ($folder eq 'supplemental_'.$2);
3314: }
3315: } else {
3316: next unless ($1 eq 'docs');
3317: if ($folder eq 'default') {
3318: next unless ($2 eq 'default');
3319: } else {
3320: next unless ($folder eq 'default_'.$2);
3321: }
3322: }
1.504 raeburn 3323: }
1.329 droeschl 3324: push(@imports, [$name, $url, $residx]);
3325: }
3326: }
1.530 raeburn 3327: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3328: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3329: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3330: return $errtext if ($fatal);
1.529 raeburn 3331: if ($fixuperrors) {
3332: $r->print($fixuperrors);
3333: }
1.329 droeschl 3334: }
3335: # Loading a complete map
3336: if ($env{'form.loadmap'}) {
3337: if ($env{'form.importmap'}=~/\w/) {
3338: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3339: my ($title,$url,$ext,$type)=split(/\:/,$res);
3340: my $idx=&LONCAPA::map::getresidx($url);
3341: $LONCAPA::map::resources[$idx]=$res;
3342: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3343: }
3344: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3345: $folder.'.'.$container,1);
1.329 droeschl 3346: return $errtext if ($fatal);
3347: } else {
3348: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3349:
1.329 droeschl 3350: }
3351: }
3352: &log_differences($plain);
3353: }
3354: # ---------------------------------------------------------------- End commands
3355: # ---------------------------------------------------------------- Print screen
3356: my $idx=0;
3357: my $shown=0;
3358: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3359: $r->print('<div class="LC_Box">'.
1.432 raeburn 3360: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3361: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3362: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3363: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3364: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3365: '</ol>');
1.381 bisitz 3366: if ($randompick>=0) {
3367: $r->print('<p class="LC_warning">'
3368: .&mt('Caution: this folder is set to randomly pick a subset'
3369: .' of resources. Adding or removing resources from this'
3370: .' folder will change the set of resources that the'
3371: .' students see, resulting in spurious or missing credit'
3372: .' for completed problems, not limited to ones you'
3373: .' modify. Do not modify the contents of this folder if'
3374: .' it is in active student use.')
3375: .'</p>'
3376: );
3377: }
3378: if ($is_random_order) {
3379: $r->print('<p class="LC_warning">'
3380: .&mt('Caution: this folder is set to randomly order its'
3381: .' contents. Adding or removing resources from this folder'
3382: .' will change the order of resources shown.')
3383: .'</p>'
3384: );
3385: }
3386: $r->print('</div>');
1.364 bisitz 3387: }
1.381 bisitz 3388:
1.538 raeburn 3389: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3390: %filters = (
1.543 raeburn 3391: canremove => [],
3392: cancut => [],
3393: cancopy => [],
3394: hiddenresource => [],
3395: encrypturl => [],
3396: randomorder => [],
3397: randompick => [],
1.538 raeburn 3398: );
3399: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3400: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3401: foreach my $res (@LONCAPA::map::order) {
3402: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3403: $name=&LONCAPA::map::qtescape($name);
3404: $url=&LONCAPA::map::qtescape($url);
3405: unless ($name) { $name=(split(/\//,$url))[-1]; }
3406: unless ($name) { $idx++; next; }
1.537 raeburn 3407: push(@allidx,$res);
3408: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3409: push(@allmapidx,$res);
3410: }
1.617 raeburn 3411:
1.381 bisitz 3412: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3413: $coursenum,$coursedom,$crstype,
1.538 raeburn 3414: $pathitem,$supplementalflag,$container,
1.620 raeburn 3415: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3416: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3417: $idx++;
3418: $shown++;
1.329 droeschl 3419: }
1.424 onken 3420: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3421:
1.538 raeburn 3422: my $need_save;
1.611 raeburn 3423: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3424: my $toolslink;
1.611 raeburn 3425: if ($allowed) {
1.544 raeburn 3426: $toolslink = '<table><tr><td>'
1.520 raeburn 3427: .&Apache::loncommon::help_open_menu('Navigation Screen',
3428: 'Navigation_Screen',undef,'RAT')
3429: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3430: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3431: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3432: .'id="LC_content_toolbar_edittoplevel" '
3433: .'class="LC_toolbarItem" '
3434: .'title="'.&mt('Supplemental Content Editor').'">'
3435: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3436: }
1.510 raeburn 3437: if ($shown) {
3438: if ($allowed) {
3439: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3440: .&Apache::loncommon::start_data_table(undef,'contentlist')
3441: .&Apache::loncommon::start_data_table_header_row()
3442: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3443: .'<th colspan="3">'.&mt('Actions').'</th>'
1.538 raeburn 3444: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3445: if ($folder !~ /^supplemental/) {
1.633 raeburn 3446: $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
1.510 raeburn 3447: }
1.537 raeburn 3448: $to_show .= &Apache::loncommon::end_data_table_header_row();
3449: if ($folder !~ /^supplemental/) {
1.538 raeburn 3450: $lists{'canhide'} = join(',',@allidx);
3451: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3452: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3453: 'randomorder','randompick');
3454: foreach my $item (@possfilters) {
1.538 raeburn 3455: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3456: if (@{$filters{$item}} > 0) {
3457: $lists{$item} = join(',',@{$filters{$item}});
3458: }
1.538 raeburn 3459: }
3460: }
1.537 raeburn 3461: if (@allidx > 0) {
3462: my $path;
3463: if ($env{'form.folderpath'}) {
1.630 raeburn 3464: $path =
1.537 raeburn 3465: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3466: }
1.538 raeburn 3467: if (@allidx > 1) {
1.630 raeburn 3468: $to_show .=
1.538 raeburn 3469: &Apache::loncommon::continue_data_table_row().
3470: '<td colspan="2"> </td>'.
3471: '<td>'.
1.611 raeburn 3472: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3473: '</td>'.
1.633 raeburn 3474: '<td colspan="3"> </td>'.
3475: '<td colspan="2">'.
1.611 raeburn 3476: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3477: '</td>'.
3478: &Apache::loncommon::end_data_table_row();
3479: $need_save = 1;
3480: }
1.537 raeburn 3481: }
3482: }
3483: $to_show .= $output.' '
1.510 raeburn 3484: .&Apache::loncommon::end_data_table()
3485: .'<br style="line-height:2px;" />'
3486: .&Apache::loncommon::end_scrollbox();
3487: } else {
1.520 raeburn 3488: $to_show .= $toolslink
1.510 raeburn 3489: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3490: .$output.' '
3491: .&Apache::loncommon::end_data_table();
1.393 raeburn 3492: }
1.510 raeburn 3493: } else {
1.520 raeburn 3494: if (!$allowed) {
3495: $to_show .= $toolslink;
3496: }
1.615 raeburn 3497: my $noresmsg;
3498: if ($allowed && $hiddentop && !$supplementalflag) {
3499: $noresmsg = &mt('Main Content Hidden');
3500: } else {
3501: $noresmsg = &mt('Currently empty');
3502: }
1.510 raeburn 3503: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3504: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3505: .$noresmsg
1.510 raeburn 3506: .'</div>'
3507: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3508: }
3509: } else {
1.510 raeburn 3510: if ($shown) {
3511: $to_show = '<div>'
3512: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3513: .$output
3514: .&Apache::loncommon::end_data_table()
3515: .'</div>';
3516: } else {
3517: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3518: .&mt('Currently empty')
1.510 raeburn 3519: .'</div>'
3520: }
1.458 raeburn 3521: }
3522: my $tid = 1;
3523: if ($supplementalflag) {
3524: $tid = 2;
1.329 droeschl 3525: }
3526: if ($allowed) {
1.484 raeburn 3527: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3528: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3529: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3530: if ($canedit) {
3531: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3532: }
1.460 raeburn 3533: } else {
3534: $r->print($to_show);
1.329 droeschl 3535: }
3536: return;
3537: }
3538:
1.538 raeburn 3539: sub multiple_check_form {
1.611 raeburn 3540: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3541: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3542: my $disabled;
3543: unless ($canedit) {
3544: $disabled = 'disabled="disabled"';
3545: }
1.538 raeburn 3546: my $output =
3547: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3548: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3549: '<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>'.
3550: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3551: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3552: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3553: if ($caller eq 'settings') {
3554: $output .=
3555: '<table><tr>'.
3556: '<td class="LC_docs_entry_parameter">'.
3557: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3558: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3559: '</label></span></td>'.
3560: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3561: '<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 3562: '</span></td>'.
3563: '</tr>'."\n".
3564: '<tr>'.
3565: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3566: '<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 3567: '</label></span>'.
3568: '</td></tr></table>'."\n";
3569: } else {
3570: $output .=
3571: '<table><tr>'.
3572: '<td class="LC_docs_entry_parameter">'.
3573: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3574: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3575: '</label></span></td>'.
3576: '<td class="LC_docs_entry_parameter">'.
3577: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3578: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3579: '</label></span></td>'."\n".
3580: '<td class="LC_docs_entry_parameter">'.
3581: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3582: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3583: '</label></span></td>'.
3584: '</tr></table>'."\n";
3585: }
3586: $output .=
3587: '</fieldset>'.
3588: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3589: if ($caller eq 'settings') {
3590: $output .=
1.543 raeburn 3591: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3592: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3593: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3594: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3595: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3596: } elsif ($caller eq 'actions') {
3597: $output .=
3598: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3599: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3600: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3601: }
3602: $output .=
3603: '</form>'.
3604: '</div>';
3605: return $output;
3606: }
3607:
1.329 droeschl 3608: sub process_file_upload {
1.552 raeburn 3609: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3610: # upload a file, if present
1.552 raeburn 3611: my $filesize = length($env{'form.uploaddoc'});
3612: if (!$filesize) {
3613: $$upload_output = '<div class="LC_error">'.
3614: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3615: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3616: $filesize).'<br />'.
3617: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3618: '</div>';
3619: return;
3620: }
3621: my $quotatype = 'unofficial';
3622: if ($crstype eq 'Community') {
1.601 raeburn 3623: $quotatype = 'community';
3624: } elsif ($crstype eq 'Placement') {
3625: $quotatype = 'placement';
1.580 raeburn 3626: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3627: $quotatype = 'official';
1.573 raeburn 3628: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3629: $quotatype = 'textbook';
1.552 raeburn 3630: }
3631: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3632: $filesize = int($filesize/1000); #expressed in kb
3633: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3634: $env{'form.uploaddoc.filename'},$filesize,
3635: 'upload',$quotatype);
1.552 raeburn 3636: return if ($$upload_output);
3637: }
1.440 raeburn 3638: my ($parseaction,$showupload,$nextphase,$mimetype);
3639: if ($env{'form.parserflag'}) {
1.329 droeschl 3640: $parseaction = 'parse';
3641: }
3642: my $folder=$env{'form.folder'};
3643: if ($folder eq '') {
3644: $folder='default';
3645: }
3646: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3647: my $errtext='';
3648: my $fatal=0;
3649: my $container='sequence';
1.519 raeburn 3650: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3651: $container='page';
3652: }
3653: ($errtext,$fatal)=
1.534 raeburn 3654: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3655: if ($#LONCAPA::map::order<1) {
3656: $LONCAPA::map::order[0]=1;
3657: $LONCAPA::map::resources[1]='';
3658: }
3659: my $destination = 'docs/';
3660: if ($folder =~ /^supplemental/) {
3661: $destination = 'supplemental/';
3662: }
3663: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3664: $destination .= 'default/';
3665: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3666: $destination .= $2.'/';
3667: }
1.534 raeburn 3668: if ($fatal) {
3669: $$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>';
3670: return;
3671: }
1.440 raeburn 3672: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3673: my $newidx=&LONCAPA::map::getresidx();
3674: $destination .= $newidx;
1.439 raeburn 3675: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3676: $parseaction,$allfiles,
1.440 raeburn 3677: $codebase,undef,undef,undef,undef,
3678: undef,undef,\$mimetype);
3679: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3680: my $stored = $1;
3681: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3682: $stored.'</span>').'</p>';
3683: } else {
3684: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3685:
1.457 raeburn 3686: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3687: return;
3688: }
1.329 droeschl 3689: my $ext='false';
3690: if ($url=~m{^http://}) { $ext='true'; }
3691: $url = &LONCAPA::map::qtunescape($url);
3692: my $comment=$env{'form.comment'};
3693: $comment = &LONCAPA::map::qtunescape($comment);
3694: if ($folder=~/^supplemental/) {
3695: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3696: $env{'user.domain'}.'___&&&___'.$comment;
3697: }
3698:
3699: $LONCAPA::map::resources[$newidx]=
3700: $comment.':'.$url.':'.$ext.':normal:res';
3701: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3702: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3703: $folder.'.'.$container,1);
1.329 droeschl 3704: if ($fatal) {
1.457 raeburn 3705: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3706: return;
1.329 droeschl 3707: } else {
1.440 raeburn 3708: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3709: $$upload_output = $showupload;
1.384 raeburn 3710: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3711: if ($total_embedded > 0) {
1.440 raeburn 3712: my $uploadphase = 'upload_embedded';
3713: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3714: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3715: my ($embedded,$num) =
1.440 raeburn 3716: &Apache::loncommon::ask_for_embedded_content(
3717: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3718: if ($embedded) {
3719: if ($num) {
3720: $$upload_output .=
3721: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3722: $nextphase = $uploadphase;
3723: } else {
3724: $$upload_output .= $embedded;
3725: }
3726: } else {
3727: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3728: }
1.329 droeschl 3729: } else {
1.440 raeburn 3730: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3731: }
1.457 raeburn 3732: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3733: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3734: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3735: $nextphase = 'decompress_uploaded';
3736: my $position = scalar(@LONCAPA::map::order)-1;
3737: my $noextract = &return_to_editor();
3738: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3739: my %archiveitems = (
3740: folderpath => $env{'form.folderpath'},
3741: cmd => $nextphase,
3742: newidx => $newidx,
3743: position => $position,
3744: phase => $nextphase,
1.477 raeburn 3745: comment => $comment,
1.480 raeburn 3746: );
3747: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3748: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3749: $$upload_output = $showupload.
3750: &Apache::loncommon::decompress_form($mimetype,
3751: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3752: \%archiveitems,\@current);
1.329 droeschl 3753: }
3754: }
3755: }
1.440 raeburn 3756: return $nextphase;
1.329 droeschl 3757: }
3758:
1.480 raeburn 3759: sub get_dir_list {
3760: my ($url,$coursenum,$coursedom,$newidx) = @_;
3761: my ($destination,$dir_root) = &embedded_destination();
3762: my ($dirlistref,$listerror) =
3763: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3764: my @dir_lines;
3765: my $dirptr=16384;
3766: if (ref($dirlistref) eq 'ARRAY') {
3767: foreach my $dir_line (sort
3768: {
3769: my ($afile)=split('&',$a,2);
3770: my ($bfile)=split('&',$b,2);
3771: return (lc($afile) cmp lc($bfile));
3772: } (@{$dirlistref})) {
3773: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3774: $filename =~ s/\s+$//;
3775: next if ($filename =~ /^\.\.?$/);
3776: my $isdir = 0;
3777: if ($dirptr&$testdir) {
3778: $isdir = 1;
3779: }
3780: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3781: }
3782: }
3783: return @dir_lines;
3784: }
3785:
1.329 droeschl 3786: sub is_supplemental_title {
3787: my ($title) = @_;
3788: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3789: }
3790:
3791: # --------------------------------------------------------------- An entry line
3792:
3793: sub entryline {
1.501 raeburn 3794: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3795: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3796: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3797: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3798: if (&is_supplemental_title($title)) {
1.488 raeburn 3799: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3800: } else {
3801: $title=&HTML::Entities::encode($title,'"<>&\'');
3802: $renametitle=$title;
3803: $foldertitle=$title;
3804: }
3805:
1.611 raeburn 3806: my ($disabled,$readonly,$js_lt);
3807: unless ($canedit) {
3808: $disabled = 'disabled="disabled"';
3809: $readonly = 1;
3810: }
3811:
1.329 droeschl 3812: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3813:
1.329 droeschl 3814: $renametitle=~s/\\/\\\\/g;
3815: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3816: $renametitle=~s/"/%22/g;
1.581 raeburn 3817: $renametitle=~s/ /%20/g;
3818: $oldtitle = $renametitle;
1.576 raeburn 3819: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3820: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3821: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3822: # Edit commands
1.633 raeburn 3823: my ($esc_path, $path, $symb, $curralias);
1.329 droeschl 3824: if ($env{'form.folderpath'}) {
3825: $esc_path=&escape($env{'form.folderpath'});
3826: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3827: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3828: }
1.505 raeburn 3829: my $isexternal;
1.510 raeburn 3830: if ($residx) {
1.501 raeburn 3831: my $currurl = $url;
3832: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3833: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3834: $isexternal = 1;
3835: }
1.510 raeburn 3836: if (!$supplementalflag) {
3837: my $path = 'uploaded/'.
3838: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3839: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3840: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3841: $residx,
3842: &Apache::lonnet::declutter($currurl));
3843: }
1.501 raeburn 3844: }
1.538 raeburn 3845: my ($renamelink,%lt,$ishash);
3846: if (ref($filtersref) eq 'HASH') {
3847: $ishash = 1;
3848: }
3849:
1.329 droeschl 3850: if ($allowed) {
1.538 raeburn 3851: $form_start = '
3852: <form action="/adm/coursedocs" method="post">
3853: ';
3854: $form_common=(<<END);
3855: <input type="hidden" name="folderpath" value="$path" />
3856: <input type="hidden" name="symb" value="$symb" />
3857: END
3858: $form_param=(<<END);
3859: <input type="hidden" name="setparms" value="$orderidx" />
3860: <input type="hidden" name="changeparms" value="0" />
3861: END
3862: $form_end = '</form>';
3863:
1.329 droeschl 3864: my $incindex=$index+1;
3865: my $selectbox='';
1.471 raeburn 3866: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3867: ((split(/\:/,
1.344 bisitz 3868: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3869: ne '') &&
1.329 droeschl 3870: ((split(/\:/,
1.344 bisitz 3871: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3872: ne '')) {
3873: $selectbox=
3874: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3875: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3876: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3877: if ($i==$incindex) {
1.358 bisitz 3878: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3879: } else {
3880: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3881: }
3882: }
3883: $selectbox.='</select>';
3884: }
1.501 raeburn 3885: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3886: 'up' => 'Move Up',
3887: 'dw' => 'Move Down',
3888: 'rm' => 'Remove',
3889: 'ct' => 'Cut',
3890: 'rn' => 'Rename',
1.501 raeburn 3891: 'cp' => 'Copy',
1.633 raeburn 3892: 'da' => 'Unset alias',
3893: 'sa' => 'Set alias',
1.501 raeburn 3894: 'ex' => 'External Resource',
1.598 raeburn 3895: 'et' => 'External Tool',
1.501 raeburn 3896: 'ed' => 'Edit',
3897: 'pr' => 'Preview',
3898: 'sv' => 'Save',
3899: 'ul' => 'URL',
1.611 raeburn 3900: 'ti' => 'Title',
1.618 raeburn 3901: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3902: );
1.538 raeburn 3903: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3904: $env{'form.folderpath'},
3905: $currgroups);
1.517 raeburn 3906: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3907: my $skip_confirm = 0;
1.603 raeburn 3908: my $confirm_removal = 0;
1.329 droeschl 3909: if ( $folder =~ /^supplemental/
3910: || ($url =~ m{( /smppg$
3911: |/syllabus$
3912: |/aboutme$
3913: |/navmaps$
3914: |/bulletinboard$
1.626 raeburn 3915: |/ext\.tool$
1.505 raeburn 3916: |\.html$)}x)
3917: || $isexternal) {
1.329 droeschl 3918: $skip_confirm = 1;
3919: }
1.603 raeburn 3920: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3921: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3922: $confirm_removal = 1;
3923: }
1.633 raeburn 3924: if ($url =~ /$LONCAPA::assess_re/) {
3925: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
3926: }
1.329 droeschl 3927:
1.538 raeburn 3928: if ($denied{'copy'}) {
1.543 raeburn 3929: $copylink=(<<ENDCOPY)
1.507 raeburn 3930: <span style="visibility: hidden;">$lt{'cp'}</span>
3931: ENDCOPY
3932: } else {
1.538 raeburn 3933: my $formname = 'edit_copy_'.$orderidx;
3934: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3935: $copylink=(<<ENDCOPY);
1.538 raeburn 3936: <form name="$formname" method="post" action="/adm/coursedocs">
3937: $form_common
1.611 raeburn 3938: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.538 raeburn 3939: $form_end
1.329 droeschl 3940: ENDCOPY
1.538 raeburn 3941: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3942: push(@{$filtersref->{'cancopy'}},$orderidx);
3943: }
1.329 droeschl 3944: }
1.538 raeburn 3945: if ($denied{'cut'}) {
1.507 raeburn 3946: $cutlink=(<<ENDCUT);
3947: <span style="visibility: hidden;">$lt{'ct'}</span>
3948: ENDCUT
3949: } else {
1.538 raeburn 3950: my $formname = 'edit_cut_'.$orderidx;
3951: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3952: $cutlink=(<<ENDCUT);
1.538 raeburn 3953: <form name="$formname" method="post" action="/adm/coursedocs">
3954: $form_common
1.542 raeburn 3955: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3956: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.538 raeburn 3957: $form_end
1.329 droeschl 3958: ENDCUT
1.538 raeburn 3959: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3960: push(@{$filtersref->{'cancut'}},$orderidx);
3961: }
1.329 droeschl 3962: }
1.538 raeburn 3963: if ($denied{'remove'}) {
1.507 raeburn 3964: $removelink=(<<ENDREM);
3965: <span style="visibility: hidden;">$lt{'rm'}</a>
3966: ENDREM
3967: } else {
1.538 raeburn 3968: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3969: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3970: $removelink=(<<ENDREM);
1.538 raeburn 3971: <form name="$formname" method="post" action="/adm/coursedocs">
3972: $form_common
1.542 raeburn 3973: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3974: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 3975: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.538 raeburn 3976: $form_end
1.497 raeburn 3977: ENDREM
1.538 raeburn 3978: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3979: push(@{$filtersref->{'canremove'}},$orderidx);
3980: }
1.497 raeburn 3981: }
1.551 raeburn 3982: $renamelink=(<<ENDREN);
1.581 raeburn 3983: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3984: ENDREN
1.611 raeburn 3985: my ($uplink,$downlink);
3986: if ($canedit) {
3987: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3988: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3989: } else {
3990: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3991: $downlink = $uplink;
3992: }
1.329 droeschl 3993: $line.=(<<END);
3994: <td>
1.379 bisitz 3995: <div class="LC_docs_entry_move">
1.611 raeburn 3996: <a href="$uplink">
1.501 raeburn 3997: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3998: </a>
3999: </div>
4000: <div class="LC_docs_entry_move">
1.611 raeburn 4001: <a href="$downlink">
1.501 raeburn 4002: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4003: </a>
4004: </div>
1.329 droeschl 4005: </td>
4006: <td>
4007: $form_start
1.538 raeburn 4008: $form_param
1.478 raeburn 4009: $form_common
1.329 droeschl 4010: $selectbox
4011: $form_end
4012: </td>
1.540 raeburn 4013: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4014: $removelink
1.329 droeschl 4015: $cutlink
4016: $copylink
4017: </td>
4018: END
4019: }
4020: # Figure out what kind of a resource this is
4021: my ($extension)=($url=~/\.(\w+)$/);
4022: my $uploaded=($url=~/^\/*uploaded\//);
4023: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4024: my $isfolder;
4025: my $ispage;
4026: my $containerarg;
1.615 raeburn 4027: my $folderurl;
1.329 droeschl 4028: if ($uploaded) {
1.472 raeburn 4029: if (($extension eq 'sequence') || ($extension eq 'page')) {
4030: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4031: $containerarg = $1;
1.472 raeburn 4032: if ($extension eq 'sequence') {
4033: $icon=$iconpath.'navmap.folder.closed.gif';
4034: $isfolder=1;
4035: } else {
4036: $icon=$iconpath.'page.gif';
4037: $ispage=1;
4038: }
1.615 raeburn 4039: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4040: if ($allowed) {
4041: $url='/adm/coursedocs?';
4042: } else {
4043: $url='/adm/supplemental?';
4044: }
1.329 droeschl 4045: } else {
4046: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4047: }
4048: }
1.364 bisitz 4049:
1.621 raeburn 4050: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4051: my $orig_url = $url;
1.340 raeburn 4052: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 4053: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 4054: if (!$supplementalflag && $residx && $symb) {
4055: if ((!$isfolder) && (!$ispage)) {
4056: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4057: $url=&Apache::lonnet::clutter($url);
4058: if ($url=~/^\/*uploaded\//) {
4059: $url=~/\.(\w+)$/;
4060: my $embstyle=&Apache::loncommon::fileembstyle($1);
4061: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4062: $url='/adm/wrapper'.$url;
4063: } elsif ($embstyle eq 'ssi') {
4064: #do nothing with these
4065: } elsif ($url!~/\.(sequence|page)$/) {
4066: $url='/adm/coursedocs/showdoc'.$url;
4067: }
1.623 raeburn 4068: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4069: my $wrapped = $1;
4070: my $exturl = $2;
4071: if ($wrapped eq '') {
4072: $url='/adm/wrapper'.$url;
4073: }
4074: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4075: $nomodal = 1;
4076: }
1.626 raeburn 4077: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4078: $url='/adm/wrapper'.$url;
1.621 raeburn 4079: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4080: if (($ENV{'SERVER_PORT'} == 443) &&
4081: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4082: $url .= '?usehttp=1';
4083: $nomodal = 1;
4084: }
1.598 raeburn 4085: }
1.501 raeburn 4086: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4087: my $shownsymb = $symb;
4088: if ($isexternal) {
4089: if ($url =~ /^([^#]+)#([^#]+)$/) {
4090: $url = $1;
4091: $anchor = $2;
4092: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4093: $shownsymb = $1.&escape('#').$anchor;
4094: }
4095: }
4096: }
1.617 raeburn 4097: unless ($env{'request.role.adv'}) {
4098: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4099: $url = '';
4100: }
4101: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4102: $url = '';
4103: $hiddenres = 1;
4104: }
4105: }
4106: if ($url ne '') {
4107: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4108: }
1.615 raeburn 4109: } elsif (!$env{'request.role.adv'}) {
4110: my $checkencrypt;
4111: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4112: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4113: $checkencrypt = 1;
1.620 raeburn 4114: } elsif (ref($navmapref)) {
1.615 raeburn 4115: unless (ref($$navmapref)) {
4116: $$navmapref = Apache::lonnavmaps::navmap->new();
4117: }
4118: if (ref($$navmapref)) {
4119: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4120: $checkencrypt = 1;
4121: }
4122: }
4123: }
4124: if ($checkencrypt) {
4125: my $shownsymb = &Apache::lonenc::encrypted($symb);
4126: my $shownurl = &Apache::lonenc::encrypted($url);
4127: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4128: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4129: if ($env{'request.enc'} ne '') {
4130: delete($env{'request.enc'});
4131: }
4132: } else {
4133: $url='';
1.613 raeburn 4134: }
1.612 raeburn 4135: } else {
4136: $url='';
4137: }
1.501 raeburn 4138: } else {
4139: $url='';
4140: }
1.329 droeschl 4141: }
1.621 raeburn 4142: } elsif ($supplementalflag) {
1.610 raeburn 4143: if ($isexternal) {
4144: if ($url =~ /^([^#]+)#([^#]+)$/) {
4145: $url = $1;
4146: $anchor = $2;
1.623 raeburn 4147: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4148: if ($hostname ne '') {
4149: $url = 'http://'.$hostname.$url;
4150: }
4151: $nomodal = 1;
4152: }
1.610 raeburn 4153: }
1.621 raeburn 4154: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4155: if (($ENV{'SERVER_PORT'} == 443) &&
4156: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.622 raeburn 4157: if ($hostname ne '') {
4158: $url = 'http://'.$hostname.$url;
4159: }
1.621 raeburn 4160: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4161: $nomodal = 1;
4162: }
1.610 raeburn 4163: }
1.329 droeschl 4164: }
1.615 raeburn 4165: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4166: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4167: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4168: my $foldername=&escape($foldertitle);
4169: my $folderpath=$env{'form.folderpath'};
4170: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4171: if (!$allowed && $supplementalflag) {
1.519 raeburn 4172: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4173: $url.='folderpath='.&escape($folderpath);
4174: } else {
1.617 raeburn 4175: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4176: 'parameter_randompick'))[0];
4177: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4178: 'parameter_randomorder'))[0]=~/^yes$/i);
4179: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4180: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4181: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4182: 'parameter_encrypturl'))[0]=~/^yes$/i);
4183: unless ($hiddenmap) {
1.620 raeburn 4184: if (ref($navmapref)) {
4185: unless (ref($$navmapref)) {
4186: $$navmapref = Apache::lonnavmaps::navmap->new();
4187: }
4188: if (ref($$navmapref)) {
4189: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4190: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4191: unless (@resources) {
4192: $hiddenmap = 1;
4193: unless ($env{'request.role.adv'}) {
4194: $url = '';
4195: $hiddenfolder = 1;
4196: }
1.617 raeburn 4197: }
1.615 raeburn 4198: }
4199: }
4200: }
4201: }
1.617 raeburn 4202: unless ($encryptmap) {
1.620 raeburn 4203: if ((ref($navmapref)) && (ref($$navmapref))) {
4204: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4205: $encryptmap = 1;
4206: }
1.617 raeburn 4207: }
4208: }
1.630 raeburn 4209:
1.617 raeburn 4210: # Append randompick number, hidden, and encrypted with ":" to foldername,
4211: # so it gets transferred between levels
4212: $folderpath.=$containerarg.'&'.$foldername.
4213: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4214: unless ($url eq '') {
1.612 raeburn 4215: $url.='folderpath='.&escape($folderpath);
4216: }
1.510 raeburn 4217: my $rpckchk;
4218: if ($rpicknum) {
4219: $rpckchk = ' checked="checked"';
1.543 raeburn 4220: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4221: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4222: }
1.510 raeburn 4223: }
1.537 raeburn 4224: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4225: $rand_pick_text =
1.478 raeburn 4226: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4227: $form_param."\n".
1.478 raeburn 4228: $form_common."\n".
1.611 raeburn 4229: '<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 4230: if ($rpicknum ne '') {
4231: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4232: }
1.537 raeburn 4233: $rand_pick_text .= '</span></span>'.
4234: $form_end;
1.543 raeburn 4235: my $ro_set;
1.617 raeburn 4236: if ($randorder) {
1.543 raeburn 4237: $ro_set = 'checked="checked"';
4238: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4239: push(@{$filtersref->{'randomorder'}},$orderidx);
4240: }
4241: }
1.564 raeburn 4242: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4243: $rand_order_text =
1.537 raeburn 4244: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4245: $form_param."\n".
1.537 raeburn 4246: $form_common."\n".
1.611 raeburn 4247: '<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 4248: $form_end;
1.510 raeburn 4249: }
1.509 raeburn 4250: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4251: my $isexttool;
1.626 raeburn 4252: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4253: $url='/adm/wrapper'.$url;
4254: $isexttool = 1;
4255: }
1.510 raeburn 4256: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4257: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4258: if ($title) {
4259: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4260: }
1.598 raeburn 4261: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4262: $url .= '&idx='.$orderidx;
4263: }
1.610 raeburn 4264: if ($anchor ne '') {
4265: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4266: }
1.329 droeschl 4267: }
1.519 raeburn 4268: my ($tdalign,$tdwidth);
1.501 raeburn 4269: if ($allowed) {
1.630 raeburn 4270: my $fileloc =
1.501 raeburn 4271: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4272: if ($isexternal) {
1.630 raeburn 4273: ($editlink,$extresform) =
1.611 raeburn 4274: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4275: undef,undef,undef,undef,undef,undef,
4276: undef,$disabled);
1.626 raeburn 4277: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4278: ($editlink,$extresform) =
4279: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4280: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4281: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4282: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4283: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4284: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4285: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4286: my $suppanchor;
4287: if ($supplementalflag) {
4288: $suppanchor = $anchor;
4289: }
1.630 raeburn 4290: my $jscall =
1.501 raeburn 4291: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4292: $switchserver,
1.503 raeburn 4293: $forceedit,
1.511 raeburn 4294: undef,$symb,
4295: &escape($env{'form.folderpath'}),
1.622 raeburn 4296: $renametitle,$hostname,
4297: '','',1,$suppanchor);
1.501 raeburn 4298: if ($jscall) {
1.518 raeburn 4299: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4300: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4301: }
4302: }
4303: }
1.519 raeburn 4304: $tdalign = ' align="right" valign="top"';
4305: $tdwidth = ' width="80%"';
1.329 droeschl 4306: }
1.408 raeburn 4307: my $reinit;
4308: if ($crstype eq 'Community') {
4309: $reinit = &mt('(re-initialize community to access)');
4310: } else {
4311: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4312: }
4313: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.633 raeburn 4314: if ($url =~ /$LONCAPA::assess_re/) {
4315: $line.= '<br />';
4316: if ($curralias ne '') {
4317: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4318: $lt{'da'}.'</a></span>';
4319: } else {
4320: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4321: $lt{'sa'}.'</a></span>';
4322: }
4323: }
4324: $line.='</td><td>';
1.621 raeburn 4325: my $link;
1.472 raeburn 4326: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4327: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4328: } elsif ($url) {
1.610 raeburn 4329: if ($anchor ne '') {
4330: if ($supplementalflag) {
4331: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4332: } else {
4333: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4334: }
4335: }
1.622 raeburn 4336: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4337: $link = 'http://'.$hostname.$url;
4338: } else {
4339: $link = $url;
4340: }
4341: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.621 raeburn 4342: (($anchor ne '')?$anchor:''));
4343: if ($nomodal) {
4344: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4345: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4346: } else {
4347: $line.=&Apache::loncommon::modal_link($link,
4348: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4349: }
1.469 www 4350: } else {
4351: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4352: }
1.519 raeburn 4353: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4354: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4355: $line.='<a href="'.$url.'">'.$title.'</a>';
4356: } elsif ($url) {
1.621 raeburn 4357: if ($nomodal) {
4358: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4359: $title.'</a>';
4360: } else {
4361: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4362: }
1.617 raeburn 4363: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4364: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4365: } else {
4366: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4367: }
1.633 raeburn 4368: if (($allowed) && ($curralias ne '')) {
4369: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4370: } else {
4371: $line .= $extresform;
4372: }
4373: $line .= '</td>';
1.478 raeburn 4374: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4375: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4376: if (($allowed) && ($folder!~/^supplemental/)) {
4377: my %lt=&Apache::lonlocal::texthash(
4378: 'hd' => 'Hidden',
4379: 'ec' => 'URL hidden');
1.543 raeburn 4380: my ($enctext,$hidtext);
4381: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4382: $enctext = ' checked="checked"';
4383: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4384: push(@{$filtersref->{'encrypturl'}},$orderidx);
4385: }
4386: }
4387: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4388: $hidtext = ' checked="checked"';
4389: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4390: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4391: }
4392: }
1.537 raeburn 4393: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4394: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4395: $line.=(<<ENDPARMS);
4396: <td class="LC_docs_entry_parameter">
1.537 raeburn 4397: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4398: $form_param
1.478 raeburn 4399: $form_common
1.611 raeburn 4400: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4401: $form_end
1.458 raeburn 4402: <br />
1.537 raeburn 4403: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4404: $form_param
1.478 raeburn 4405: $form_common
1.611 raeburn 4406: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4407: $form_end
4408: </td>
1.478 raeburn 4409: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4410: $rand_order_text</td>
1.329 droeschl 4411: ENDPARMS
4412: }
1.379 bisitz 4413: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4414: return $line;
4415: }
4416:
1.538 raeburn 4417: sub action_restrictions {
4418: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4419: my %denied = (
4420: cut => 0,
4421: copy => 0,
4422: remove => 0,
4423: );
4424: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4425: # no copy for published maps
4426: $denied{'copy'} = 1;
1.597 raeburn 4427: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4428: unless ($1 eq 'simpleproblem') {
4429: $denied{'copy'} = 1;
4430: }
4431: $denied{'cut'} = 1;
1.538 raeburn 4432: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4433: if ($folderpath =~ /^default&[^\&]+$/) {
4434: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4435: $denied{'remove'} = 1;
4436: }
4437: $denied{'cut'} = 1;
4438: $denied{'copy'} = 1;
4439: }
4440: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4441: my $group = $1;
4442: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4443: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4444: $denied{'remove'} = 1;
4445: }
4446: }
4447: $denied{'cut'} = 1;
4448: $denied{'copy'} = 1;
4449: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4450: my $group = $1;
4451: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4452: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4453: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4454: if (keys(%groupsettings) > 0) {
4455: $denied{'remove'} = 1;
4456: }
4457: $denied{'cut'} = 1;
4458: $denied{'copy'} = 1;
4459: }
4460: }
4461: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4462: my $group = $1;
4463: if ($url =~ /group_boards_\Q$group\E/) {
4464: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4465: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4466: if (keys(%groupsettings) > 0) {
4467: if (ref($groupsettings{'functions'}) eq 'HASH') {
4468: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4469: $denied{'remove'} = 1;
4470: }
4471: }
4472: }
4473: $denied{'cut'} = 1;
4474: $denied{'copy'} = 1;
4475: }
4476: }
4477: }
4478: return %denied;
4479: }
4480:
1.533 raeburn 4481: sub new_timebased_suffix {
1.538 raeburn 4482: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4483: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4484: if ($type eq 'paste') {
4485: $prefix = $type;
4486: $namespace = 'courseeditor';
1.587 raeburn 4487: $idtype = 'addcode';
1.538 raeburn 4488: } elsif ($type eq 'map') {
1.533 raeburn 4489: $prefix = 'docs';
4490: if ($area eq 'supplemental') {
4491: $prefix = 'supp';
4492: }
4493: $prefix .= $container;
4494: $namespace = 'uploadedmaps';
4495: } else {
4496: $prefix = $type;
4497: $namespace = 'templated';
1.504 raeburn 4498: }
4499: my ($suffix,$freedlock,$error) =
1.587 raeburn 4500: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4501: if (!$suffix) {
1.538 raeburn 4502: if ($type eq 'paste') {
4503: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4504: } elsif ($type eq 'map') {
1.533 raeburn 4505: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4506: } elsif ($type eq 'smppg') {
4507: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4508: } elsif ($type eq 'exttool') {
4509: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4510: } else {
1.565 bisitz 4511: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4512: }
1.504 raeburn 4513: if ($error) {
4514: $errtext .= '<br />'.$error;
4515: }
4516: }
4517: if ($freedlock ne 'ok') {
1.630 raeburn 4518: $locknotfreed =
1.533 raeburn 4519: '<div class="LC_error">'.
4520: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4521: if ($type eq 'paste') {
1.591 raeburn 4522: if ($freedlock eq 'nolock') {
4523: $locknotfreed =
4524: '<div class="LC_error">'.
4525: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4526:
1.593 droeschl 4527: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4528: } else {
4529: $locknotfreed .=
4530: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4531: }
1.538 raeburn 4532: } elsif ($type eq 'map') {
1.591 raeburn 4533: $locknotfreed .=
4534: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4535: } elsif ($type eq 'smppg') {
4536: $locknotfreed .=
4537: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4538: } elsif ($type eq 'exttool') {
4539: $locknotfreed .=
4540: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4541: } else {
4542: $locknotfreed .=
1.565 bisitz 4543: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4544: }
1.538 raeburn 4545: unless ($type eq 'paste') {
4546: $locknotfreed .=
1.560 raeburn 4547: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4548: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4549: }
4550: $locknotfreed .= '</div>';
1.504 raeburn 4551: }
4552: return ($suffix,$errtext,$locknotfreed);
4553: }
4554:
1.329 droeschl 4555: =pod
4556:
4557: =item tiehash()
4558:
4559: tie the hash
4560:
4561: =cut
4562:
4563: sub tiehash {
4564: my ($mode)=@_;
4565: $hashtied=0;
4566: if ($env{'request.course.fn'}) {
4567: if ($mode eq 'write') {
4568: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4569: &GDBM_WRCREAT(),0640)) {
4570: $hashtied=2;
4571: }
4572: } else {
4573: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4574: &GDBM_READER(),0640)) {
4575: $hashtied=1;
4576: }
4577: }
1.364 bisitz 4578: }
1.329 droeschl 4579: }
4580:
4581: sub untiehash {
4582: if ($hashtied) { untie %hash; }
4583: $hashtied=0;
4584: return OK;
4585: }
4586:
4587:
4588:
4589:
4590: sub checkonthis {
1.637 ! raeburn 4591: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4592: $url=&unescape($url);
4593: $alreadyseen{$url}=1;
4594: $r->rflush();
4595: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4596: $r->print("\n<br />");
4597: if ($level==0) {
4598: $r->print("<br />");
4599: }
4600: for (my $i=0;$i<=$level*5;$i++) {
4601: $r->print(' ');
4602: }
4603: $r->print('<a href="'.$url.'" target="cat">'.
4604: ($title?$title:$url).'</a> ');
4605: if ($url=~/^\/res\//) {
1.637 ! raeburn 4606: my $updated;
! 4607: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
! 4608: ($url !~ /\.\d+\.\w+$/)) {
! 4609: $updated = &Apache::lonnet::remove_stale_resfile($url);
! 4610: }
1.329 droeschl 4611: my $result=&Apache::lonnet::repcopy(
4612: &Apache::lonnet::filelocation('',$url));
4613: if ($result eq 'ok') {
4614: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 ! raeburn 4615: if ($updated) {
! 4616: $r->print('<br />');
! 4617: for (my $i=0;$i<=$level*5;$i++) {
! 4618: $r->print(' ');
! 4619: }
! 4620: $r->print('- '.&mt('Outdated copy removed'));
! 4621: }
1.329 droeschl 4622: $r->rflush();
4623: &Apache::lonnet::countacc($url);
4624: $url=~/\.(\w+)$/;
4625: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4626: $r->print('<br />');
4627: $r->rflush();
4628: for (my $i=0;$i<=$level*5;$i++) {
4629: $r->print(' ');
4630: }
4631: $r->print('- '.&mt('Rendering:').' ');
4632: my ($errorcount,$warningcount)=split(/:/,
4633: &Apache::lonnet::ssi_body($url,
4634: ('grade_target'=>'web',
4635: 'return_only_error_and_warning_counts' => 1)));
4636: if (($errorcount) ||
4637: ($warningcount)) {
4638: if ($errorcount) {
1.369 bisitz 4639: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4640: &mt('[quant,_1,error]',$errorcount).'</span>');
4641: }
4642: if ($warningcount) {
4643: $r->print('<span class="LC_warning">'.
4644: &mt('[quant,_1,warning]',$warningcount).'</span>');
4645: }
4646: } else {
4647: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4648: }
4649: $r->rflush();
4650: }
4651: my $dependencies=
4652: &Apache::lonnet::metadata($url,'dependencies');
4653: foreach my $dep (split(/\,/,$dependencies)) {
4654: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 ! raeburn 4655: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4656: }
4657: }
4658: } elsif ($result eq 'unavailable') {
4659: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4660: } elsif ($result eq 'not_found') {
4661: unless ($url=~/\$/) {
1.521 bisitz 4662: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4663: } else {
1.366 bisitz 4664: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4665: }
4666: } else {
4667: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4668: }
1.637 ! raeburn 4669: if (($updated) && ($result ne 'ok')) {
! 4670: $r->print('<br />'.&mt('Outdated copy removed'));
! 4671: }
1.329 droeschl 4672: }
4673: }
4674: }
4675:
4676:
4677:
4678: =pod
4679:
4680: =item list_symbs()
4681:
1.485 raeburn 4682: List Content Identifiers
1.329 droeschl 4683:
4684: =cut
4685:
4686: sub list_symbs {
4687: my ($r) = @_;
4688:
1.408 raeburn 4689: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4690: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4691: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4692: $r->print(&startContentScreen('tools'));
1.329 droeschl 4693: my $navmap = Apache::lonnavmaps::navmap->new();
4694: if (!defined($navmap)) {
4695: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4696: '<div class="LC_error">'.
4697: &mt('Unable to retrieve information about course contents').
4698: '</div>');
1.408 raeburn 4699: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4700: } else {
1.484 raeburn 4701: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4702: &Apache::loncommon::start_data_table().
4703: &Apache::loncommon::start_data_table_header_row().
4704: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4705: &Apache::loncommon::end_data_table_header_row()."\n");
4706: my $count;
1.329 droeschl 4707: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4708: $r->print(&Apache::loncommon::start_data_table_row().
4709: '<td>'.$res->compTitle().'</td>'.
4710: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4711: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4712: $count ++;
4713: }
4714: if (!$count) {
4715: $r->print(&Apache::loncommon::start_data_table_row().
4716: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4717: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4718: }
1.484 raeburn 4719: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4720: }
1.521 bisitz 4721: $r->print(&endContentScreen());
1.329 droeschl 4722: }
4723:
1.637 ! raeburn 4724: sub contentverifyform {
! 4725: my ($r) = @_;
! 4726: my $crstype = &Apache::loncommon::course_type();
! 4727: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
! 4728: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
! 4729: $r->print(&startContentScreen('tools'));
! 4730: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
! 4731: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
! 4732: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
! 4733: ' <span class="LC_nobreak">'.
! 4734: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
! 4735: &mt('No').'</label>'.(' 'x2).
! 4736: '<label><input type="radio" name="checkstale" value="1" />'.
! 4737: &mt('Yes').'</label></span></p><p>'.
! 4738: '<input type="submit" value="'.&mt('Verify content').' "/>'.
! 4739: '<input type="hidden" value="1" name="tools" />'.
! 4740: '<input type="hidden" value="1" name="verify" /></p></form>');
! 4741: $r->print(&endContentScreen());
! 4742: return;
! 4743: }
1.329 droeschl 4744:
4745: sub verifycontent {
1.637 ! raeburn 4746: my ($r,$checkstale) = @_;
1.408 raeburn 4747: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4748: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4749: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4750: $r->print(&startContentScreen('tools'));
4751: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4752: $hashtied=0;
4753: undef %alreadyseen;
4754: %alreadyseen=();
4755: &tiehash();
1.484 raeburn 4756:
1.329 droeschl 4757: foreach my $key (keys(%hash)) {
4758: if ($hash{$key}=~/\.(page|sequence)$/) {
4759: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4760: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4761: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4762: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4763: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4764: }
4765: }
4766: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 ! raeburn 4767: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4768: }
4769: }
4770: &untiehash();
1.442 www 4771: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4772: $r->print(&endContentScreen());
1.329 droeschl 4773: }
4774:
4775: sub devalidateversioncache {
4776: my $src=shift;
4777: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4778: &Apache::lonnet::clutter($src));
4779: }
4780:
4781: sub checkversions {
1.611 raeburn 4782: my ($r,$canedit) = @_;
1.408 raeburn 4783: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4784: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4785: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4786: $r->print(&startContentScreen('tools'));
1.442 www 4787:
1.329 droeschl 4788: my $header='';
4789: my $startsel='';
4790: my $monthsel='';
4791: my $weeksel='';
4792: my $daysel='';
4793: my $allsel='';
4794: my %changes=();
4795: my $starttime=0;
4796: my $haschanged=0;
4797: my %setversions=&Apache::lonnet::dump('resourceversions',
4798: $env{'course.'.$env{'request.course.id'}.'.domain'},
4799: $env{'course.'.$env{'request.course.id'}.'.num'});
4800:
4801: $hashtied=0;
4802: &tiehash();
1.611 raeburn 4803: if ($canedit) {
4804: my %newsetversions=();
4805: if ($env{'form.setmostrecent'}) {
4806: $haschanged=1;
4807: foreach my $key (keys(%hash)) {
4808: if ($key=~/^ids\_(\/res\/.+)$/) {
4809: $newsetversions{$1}='mostrecent';
4810: &devalidateversioncache($1);
4811: }
4812: }
4813: } elsif ($env{'form.setcurrent'}) {
4814: $haschanged=1;
4815: foreach my $key (keys(%hash)) {
4816: if ($key=~/^ids\_(\/res\/.+)$/) {
4817: my $getvers=&Apache::lonnet::getversion($1);
4818: if ($getvers>0) {
4819: $newsetversions{$1}=$getvers;
4820: &devalidateversioncache($1);
4821: }
4822: }
1.329 droeschl 4823: }
1.611 raeburn 4824: } elsif ($env{'form.setversions'}) {
4825: $haschanged=1;
4826: foreach my $key (keys(%env)) {
4827: if ($key=~/^form\.set_version_(.+)$/) {
4828: my $src=$1;
4829: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4830: $newsetversions{$src}=$env{$key};
4831: &devalidateversioncache($src);
4832: }
4833: }
1.329 droeschl 4834: }
1.611 raeburn 4835: }
4836: if ($haschanged) {
4837: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4838: $env{'course.'.$env{'request.course.id'}.'.domain'},
4839: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4840: $r->print(&Apache::loncommon::confirmwrapper(
4841: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4842: } else {
4843: $r->print(&Apache::loncommon::confirmwrapper(
4844: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4845: }
1.611 raeburn 4846: &mark_hash_old();
4847: }
4848: &changewarning($r,'');
1.329 droeschl 4849: }
4850: if ($env{'form.timerange'} eq 'all') {
4851: # show all documents
1.549 raeburn 4852: $header=&mt('All content in '.$crstype);
1.521 bisitz 4853: $allsel=' selected="selected"';
1.329 droeschl 4854: foreach my $key (keys(%hash)) {
4855: if ($key=~/^ids\_(\/res\/.+)$/) {
4856: my $src=$1;
4857: $changes{$src}=1;
4858: }
4859: }
4860: } else {
4861: # show documents which changed
4862: %changes=&Apache::lonnet::dump
4863: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4864: $env{'course.'.$env{'request.course.id'}.'.num'});
4865: my $firstkey=(keys(%changes))[0];
4866: unless ($firstkey=~/^error\:/) {
4867: unless ($env{'form.timerange'}) {
4868: $env{'form.timerange'}=604800;
4869: }
4870: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4871: .&mt('seconds');
4872: if ($env{'form.timerange'}==-1) {
4873: $seltext='since start of course';
1.521 bisitz 4874: $startsel=' selected="selected"';
1.329 droeschl 4875: $env{'form.timerange'}=time;
4876: }
4877: $starttime=time-$env{'form.timerange'};
4878: if ($env{'form.timerange'}==2592000) {
4879: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4880: $monthsel=' selected="selected"';
1.329 droeschl 4881: } elsif ($env{'form.timerange'}==604800) {
4882: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4883: $weeksel=' selected="selected"';
1.329 droeschl 4884: } elsif ($env{'form.timerange'}==86400) {
4885: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4886: $daysel=' selected="selected"';
1.329 droeschl 4887: }
4888: $header=&mt('Content changed').' '.$seltext;
4889: } else {
4890: $header=&mt('No content modifications yet.');
4891: }
4892: }
4893: %setversions=&Apache::lonnet::dump('resourceversions',
4894: $env{'course.'.$env{'request.course.id'}.'.domain'},
4895: $env{'course.'.$env{'request.course.id'}.'.num'});
4896: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4897: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4898: 'lm' => 'Version changes since last Month',
4899: 'lw' => 'Version changes since last Week',
4900: 'sy' => 'Version changes since Yesterday',
4901: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4902: 'cd' => 'Change display',
1.329 droeschl 4903: 'sd' => 'Display',
4904: 'fi' => 'File',
4905: 'md' => 'Modification Date',
4906: 'mr' => 'Most recently published Version',
1.408 raeburn 4907: 've' => 'Version used in '.$crstype,
4908: 'vu' => 'Set Version to be used in '.$crstype,
4909: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4910: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4911: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4912: 'di' => 'Differences',
1.484 raeburn 4913: 'save' => 'Save changes',
4914: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4915: 'act' => 'Actions');
1.611 raeburn 4916: my ($disabled,$readonly);
4917: unless ($canedit) {
4918: $disabled = 'disabled="disabled"';
4919: $readonly = 1;
4920: }
1.329 droeschl 4921: $r->print(<<ENDHEADERS);
1.484 raeburn 4922: <h4 class="LC_info">$header</h4>
1.329 droeschl 4923: <form action="/adm/coursedocs" method="post">
4924: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4925: <div class="LC_left_float">
1.479 golterma 4926: <fieldset>
1.484 raeburn 4927: <legend>$lt{'cd'}</legend>
1.329 droeschl 4928: <select name="timerange">
1.521 bisitz 4929: <option value='all'$allsel>$lt{'al'}</option>
4930: <option value="-1"$startsel>$lt{'st'}</option>
4931: <option value="2592000"$monthsel>$lt{'lm'}</option>
4932: <option value="604800"$weeksel>$lt{'lw'}</option>
4933: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4934: </select>
4935: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4936: </fieldset>
4937: </div>
4938: <div class="LC_left_float">
4939: <fieldset>
4940: <legend>$lt{'act'}</legend>
1.611 raeburn 4941: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4942: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4943: </fieldset>
4944: </div>
4945: <br clear="all" />
4946: <hr />
4947: <h4>$lt{'vers'}</h4>
1.329 droeschl 4948: ENDHEADERS
1.479 golterma 4949: #number of columns for version history
1.571 raeburn 4950: my %changedbytime;
4951: foreach my $key (keys(%changes)) {
4952: #excludes not versionable problems from resource version history:
4953: next if ($key =~ /^\/res\/lib\/templates/);
4954: my $chg;
4955: if ($env{'form.timerange'} eq 'all') {
4956: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4957: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4958: } else {
4959: $chg = $changes{$key};
4960: next if ($chg < $starttime);
4961: }
4962: push(@{$changedbytime{$chg}},$key);
4963: }
4964: if (keys(%changedbytime) == 0) {
4965: &untiehash();
4966: $r->print(&mt('No content changes in imported content in specified time frame').
4967: &endContentScreen());
4968: return;
4969: }
1.479 golterma 4970: $r->print(
1.611 raeburn 4971: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4972: &Apache::loncommon::start_data_table().
4973: &Apache::loncommon::start_data_table_header_row().
4974: '<th>'.&mt('Resources').'</th>'.
4975: "<th>$lt{'mr'}</th>".
4976: "<th>$lt{'ve'}</th>".
4977: "<th>$lt{'vu'}</th>".
4978: '<th>'.&mt('History').'</th>'.
4979: &Apache::loncommon::end_data_table_header_row()
4980: );
1.571 raeburn 4981: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4982: foreach my $key (sort(@{$changedbytime{$chg}})) {
4983: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4984: my $currentversion=&Apache::lonnet::getversion($key);
4985: if ($currentversion<0) {
4986: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4987: }
4988: my $linkurl=&Apache::lonnet::clutter($key);
4989: $r->print(
4990: &Apache::loncommon::start_data_table_row().
4991: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4992: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4993: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4994: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4995: '<td align="right">'
4996: );
4997: # Used in course
4998: my $usedversion=$hash{'version_'.$linkurl};
4999: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5000: if ($usedversion != $currentversion) {
1.479 golterma 5001: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5002: } else {
1.479 golterma 5003: $r->print($usedversion);
5004: }
1.329 droeschl 5005: } else {
1.521 bisitz 5006: $r->print($currentversion);
1.329 droeschl 5007: }
1.571 raeburn 5008: $r->print('</td><td title="'.$lt{'vu'}.'">');
5009: # Set version
5010: $r->print(&Apache::loncommon::select_form(
5011: $setversions{$linkurl},
5012: 'set_version_'.$linkurl,
5013: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5014: '' => '',
5015: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5016: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5017: my $lastold=1;
5018: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5019: my $url=$root.'.'.$prevvers.'.'.$extension;
5020: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5021: $lastold=$prevvers;
5022: }
5023: }
5024: $r->print('</td>');
5025: # List all available versions
5026: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5027: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5028: my $url=$root.'.'.$prevvers.'.'.$extension;
5029: $r->print(
5030: '<span class="LC_nobreak">'
5031: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5032: .&mt('Version [_1]',$prevvers).'</a>'
5033: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5034: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5035: .')');
5036: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5037: $r->print(
5038: ' <a href="/adm/diff?filename='.
5039: &Apache::lonnet::clutter($root.'.'.$extension).
5040: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5041: '" target="diffs">'.&mt('Diffs').'</a>');
5042: }
5043: $r->print('</span><br />');
1.329 droeschl 5044: }
1.571 raeburn 5045: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5046: }
1.329 droeschl 5047: }
1.521 bisitz 5048: $r->print(
5049: &Apache::loncommon::end_data_table().
1.611 raeburn 5050: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5051: '</form>'
5052: );
1.329 droeschl 5053:
5054: &untiehash();
1.521 bisitz 5055: $r->print(&endContentScreen());
1.571 raeburn 5056: return;
1.329 droeschl 5057: }
5058:
5059: sub mark_hash_old {
5060: my $retie_hash=0;
5061: if ($hashtied) {
5062: $retie_hash=1;
5063: &untiehash();
5064: }
5065: &tiehash('write');
5066: $hash{'old'}=1;
5067: &untiehash();
5068: if ($retie_hash) { &tiehash(); }
5069: }
5070:
5071: sub is_hash_old {
5072: my $untie_hash=0;
5073: if (!$hashtied) {
5074: $untie_hash=1;
5075: &tiehash();
5076: }
5077: my $return=$hash{'old'};
5078: if ($untie_hash) { &untiehash(); }
5079: return $return;
5080: }
5081:
5082: sub changewarning {
5083: my ($r,$postexec,$message,$url)=@_;
5084: if (!&is_hash_old()) { return; }
5085: my $pathvar='folderpath';
5086: my $path=&escape($env{'form.folderpath'});
5087: if (!defined($url)) {
5088: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5089: }
5090: my $course_type = &Apache::loncommon::course_type();
5091: if (!defined($message)) {
5092: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5093: }
5094: $r->print("\n\n".
1.372 bisitz 5095: '<script type="text/javascript">'."\n".
5096: '// <![CDATA['."\n".
5097: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5098: '// ]]>'."\n".
1.369 bisitz 5099: '</script>'."\n".
1.375 tempelho 5100: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5101: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5102: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5103: &mt($message,' <input type="hidden" name="'.
5104: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5105: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5106: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5107: }
5108:
5109:
5110: sub init_breadcrumbs {
1.571 raeburn 5111: my ($form,$text,$help)=@_;
1.329 droeschl 5112: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5113: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5114: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5115: faq=>273,
5116: bug=>'Instructor Interface',
1.571 raeburn 5117: help => $help});
1.329 droeschl 5118: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5119: text=>$text,
5120: faq=>273,
5121: bug=>'Instructor Interface'});
5122: }
5123:
1.441 www 5124: # subroutine to list form elements
5125: sub create_list_elements {
5126: my @formarr = @_;
5127: my $list = '';
1.501 raeburn 5128: foreach my $button (@formarr){
5129: foreach my $picture (keys(%{$button})) {
5130: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5131: }
5132: }
5133: return $list;
5134: }
1.329 droeschl 5135:
1.441 www 5136: # subroutine to create ul from list elements
5137: sub create_form_ul {
5138: my $list = shift;
5139: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5140: return $ul;
5141: }
1.329 droeschl 5142:
1.442 www 5143: #
5144: # Start tabs
5145: #
5146:
5147: sub startContentScreen {
1.484 raeburn 5148: my ($mode) = @_;
5149: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5150: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5151: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5152: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5153: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5154: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5155: } else {
1.549 raeburn 5156: $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 5157: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5158: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5159: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5160: }
5161: $output .= "\n".'</ul>'."\n";
5162: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5163: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5164: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5165: return $output;
1.442 www 5166: }
5167:
5168: #
5169: # End tabs
5170: #
5171:
5172: sub endContentScreen {
1.484 raeburn 5173: return '</div></div></div>';
1.442 www 5174: }
1.329 droeschl 5175:
1.446 www 5176: sub supplemental_base {
1.548 raeburn 5177: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5178: }
5179:
1.329 droeschl 5180: sub handler {
5181: my $r = shift;
5182: &Apache::loncommon::content_type($r,'text/html');
5183: $r->send_http_header;
5184: return OK if $r->header_only;
1.484 raeburn 5185:
5186: # get course data
1.408 raeburn 5187: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5188: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5189: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5190:
1.606 raeburn 5191: # get docroot
5192: my $londocroot = $r->dir_config('lonDocRoot');
5193:
1.484 raeburn 5194: # graphics settings
5195: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5196:
1.443 www 5197: #
1.329 droeschl 5198: # --------------------------------------------- Initialize help topics for this
5199: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5200: 'Adding_External_Resource','Adding_External_Tool',
5201: 'Navigate_Content','Adding_Folders','Docs_Overview',
5202: 'Load_Map','Supplemental','Score_Upload_Form',
5203: 'Adding_Pages','Importing_LON-CAPA_Resource',
5204: 'Importing_IMS_Course','Uploading_From_Harddrive',
5205: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5206: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5207: }
5208: # Composite help files
5209: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5210: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5211: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5212: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5213: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5214: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5215: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5216: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5217: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5218: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5219:
1.611 raeburn 5220: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5221: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5222: unless ($r->uri eq '/adm/supplemental') {
5223: # does this user have privileges to modify content.
1.611 raeburn 5224: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5225: $allowed = 1;
5226: $canedit = 1;
5227: $canview = 1;
5228: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5229: $allowed = 1;
5230: $canview = 1;
5231: }
5232: }
5233: unless ($canedit) {
5234: $disabled = ' disabled="disabled"';
1.472 raeburn 5235: }
1.582 raeburn 5236: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5237: if ($env{'form.inhibitmenu'}) {
5238: unless ($env{'form.inhibitmenu'} eq 'yes') {
5239: delete($env{'form.inhibitmenu'});
5240: }
5241: }
5242:
1.582 raeburn 5243: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5244: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 ! raeburn 5245: if (!$canedit) {
! 5246: &verifycontent($r);
! 5247: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
! 5248: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
! 5249: text=>'Results',
! 5250: faq=>273,
! 5251: bug=>'Instructor Interface'});
! 5252: &verifycontent($r,$env{'form.checkstale'});
! 5253: } else {
! 5254: &contentverifyform($r);
! 5255: }
1.329 droeschl 5256: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5257: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5258: &list_symbs($r);
5259: } elsif ($allowed && $env{'form.docslog'}) {
5260: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5261: my $folder = $env{'form.folder'};
5262: if ($folder eq '') {
5263: $folder='default';
5264: }
1.611 raeburn 5265: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5266: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5267: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5268: &checkversions($r,$canedit);
5269: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5270: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5271: &dumpcourse($r);
1.611 raeburn 5272: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5273: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5274: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5275: } else {
1.611 raeburn 5276: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5277: $noendpage = 1;
5278: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5279: if ($redirect) {
5280: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5281: my $container = 'sequence';
5282: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5283: $is_random_order,$container) =
5284: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5285: my (@folders)=split('&',$env{'form.folderpath'});
5286: $env{'form.foldername'}=&unescape(pop(@folders));
5287: my $folder=pop(@folders);
5288: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5289: $folder.'.'.$container);
5290: my $warning;
5291: if ($fatal) {
5292: if ($container eq 'page') {
5293: $warning = &mt('An error occurred retrieving the contents of the current page.');
5294: } else {
5295: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5296: }
5297: } else {
5298: my $url = $redirect;
5299: my $srcfile = $londocroot.$url;
5300: $url =~ s{^/priv/}{/res/};
5301: my $targetfile = $londocroot.$url;
5302: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5303: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5304: $env{'form.folder'} = $folder;
5305: &snapshotbefore();
5306: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5307: my $ext = 'false';
5308: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5309: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5310: ':'.$ext.':normal:res';
5311: push(@LONCAPA::map::order,$newidx);
5312: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5313: 'string_yesno');
5314: &remember_parms($newidx,'hiddenresource','set','yes');
5315: ($errtext,$fatal) =
5316: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5317: &log_differences($plain);
5318: &mark_hash_old();
5319: $r->internal_redirect($redirect);
5320: return OK;
5321: }
5322: }
5323: }
5324: }
1.445 www 5325: #
5326: # Done catching special calls
1.484 raeburn 5327: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5328: # Get the parameters that may be needed
5329: #
5330: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5331: ['folderpath',
5332: 'forcesupplement','forcestandard',
1.510 raeburn 5333: 'tools','symb','command','supppath']);
1.445 www 5334:
1.635 raeburn 5335: foreach my $item ('forcesupplement','forcestandard','tools') {
5336: next if ($env{'form.'.$item} eq '');
5337: unless ($env{'form.'.$item} eq '1') {
5338: delete($env{'form.'.$item});
5339: }
5340: }
5341:
5342: if ($env{'form.command'}) {
5343: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5344: delete($env{'form.command'});
5345: }
5346: }
5347:
5348: if ($env{'form.symb'}) {
5349: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5350: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5351: delete($env{'form.symb'});
5352: }
5353: }
5354:
1.445 www 5355: # standard=1: this is a "new-style" course with an uploaded map as top level
5356: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5357:
5358: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5359:
1.484 raeburn 5360: # Decide whether this should display supplemental or main content or utilities
1.445 www 5361: # supplementalflag=1: show supplemental documents
5362: # supplementalflag=0: show standard documents
1.484 raeburn 5363: # toolsflag=1: show utilities
1.445 www 5364:
1.561 raeburn 5365: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5366: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5367: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5368: $supplementalflag=0;
5369: }
5370: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5371: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5372: unless ($allowed) { $supplementalflag=1; }
5373: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5374: my $toolsflag=0;
5375: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5376:
1.635 raeburn 5377: if ($env{'form.folderpath'} ne '') {
5378: my @items = split(/\&/,$env{'form.folderpath'});
5379: my $badpath;
5380: for (my $i=0; $i<@items; $i++) {
5381: my $odd = $i%2;
5382: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5383: $badpath = 1;
5384: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5385: $badpath = 1;
5386: }
5387: last if ($badpath);
5388: }
5389: if ($badpath) {
5390: delete($env{'form.folderpath'});
5391: }
5392: }
5393:
5394: if ($env{'form.supppath'} ne '') {
5395: my @items = split(/\&/,$env{'form.supppath'});
5396: my $badpath;
5397: for (my $i=0; $i<@items; $i++) {
5398: my $odd = $i%2;
5399: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5400: $badpath = 1;
5401: }
5402: last if ($badpath);
5403: }
5404: if ($badpath) {
5405: delete($env{'form.supppath'});
5406: }
5407: }
5408:
1.329 droeschl 5409: my $script='';
5410: my $showdoc=0;
1.457 raeburn 5411: my $addentries = {};
1.475 raeburn 5412: my $container;
1.329 droeschl 5413: my $containertag;
1.508 raeburn 5414: my $pathitem;
1.598 raeburn 5415: my %ltitools;
1.617 raeburn 5416: my $hiddentop;
1.615 raeburn 5417: my $navmap;
1.617 raeburn 5418: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5419:
1.464 www 5420: # Do we directly jump somewhere?
1.525 raeburn 5421: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5422: if ($env{'form.symb'} ne '') {
1.522 raeburn 5423: $env{'form.folderpath'}=
1.617 raeburn 5424: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5425: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5426: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5427: } elsif ($env{'form.supppath'} ne '') {
5428: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5429: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5430: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5431: }
1.472 raeburn 5432: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5433: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5434: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5435: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5436: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5437: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5438: } elsif ($env{'form.command'} eq 'contents') {
5439: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5440: } elsif ($env{'form.command'} eq 'home') {
5441: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5442: }
5443:
1.525 raeburn 5444:
1.445 www 5445: # Where do we store these for when we come back?
5446: my $stored_folderpath='docs_folderpath';
5447: if ($supplementalflag) {
5448: $stored_folderpath='docs_sup_folderpath';
5449: }
1.464 www 5450:
1.519 raeburn 5451: # No folderpath, and in edit mode, see if we have something stored
5452: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5453: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5454: {'folderpath' => 'scalar'});
1.615 raeburn 5455:
5456: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5457: if ($supplementalflag) {
5458: undef($env{'form.folderpath'}) if ($1 eq 'default');
5459: } else {
5460: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5461: }
5462: } else {
1.523 raeburn 5463: undef($env{'form.folderpath'});
5464: }
1.329 droeschl 5465: }
1.446 www 5466:
5467: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5468: if (!$allowed) {
1.446 www 5469: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5470: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5471: }
5472: }
1.446 www 5473: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5474: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5475: $env{'form.folderpath'} = &supplemental_base()
5476: .'&'.
1.329 droeschl 5477: $env{'form.folderpath'};
5478: }
1.615 raeburn 5479: # If allowed and user's role is not advanced check folderpath is not hidden
5480: if (($allowed) && (!$env{'request.role.adv'}) &&
5481: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5482: my $folderurl;
5483: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5484: my $folder = $pathitems[-2];
5485: if ($folder eq '') {
5486: undef($env{'form.folderpath'});
5487: } else {
5488: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5489: if ((split(/\:/,$pathitems[-1]))[4]) {
5490: $folderurl .= '.page';
5491: } else {
5492: $folderurl .= '.sequence';
5493: }
1.617 raeburn 5494: unless (ref($navmap)) {
5495: $navmap = Apache::lonnavmaps::navmap->new();
5496: }
1.615 raeburn 5497: if (ref($navmap)) {
5498: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5499: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5500: unless (@resources) {
5501: undef($env{'form.folderpath'});
5502: }
1.615 raeburn 5503: }
5504: }
5505: }
5506: }
5507:
5508:
1.446 www 5509: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5510: unless ($env{'form.folderpath'}) {
1.446 www 5511: if ($supplementalflag) {
5512: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5513: } elsif ($allowed) {
5514: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5515: }
1.472 raeburn 5516: }
1.446 www 5517:
1.445 www 5518: # Store this
1.484 raeburn 5519: unless ($toolsflag) {
1.615 raeburn 5520: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5521: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5522: {'folderpath' => 'scalar'});
1.510 raeburn 5523: }
1.519 raeburn 5524: my $folderpath;
1.484 raeburn 5525: if ($env{'form.folderpath'}) {
1.519 raeburn 5526: $folderpath = $env{'form.folderpath'};
5527: my (@folders)=split('&',$env{'form.folderpath'});
5528: $env{'form.foldername'}=&unescape(pop(@folders));
5529: if ($env{'form.foldername'} =~ /\:1$/) {
5530: $container = 'page';
5531: } else {
5532: $container = 'sequence';
5533: }
5534: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5535: } else {
1.519 raeburn 5536: if ($env{'form.folder'} eq '' ||
5537: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5538: if ($env{'form.folder'} eq 'supplemental') {
5539: $folderpath=&supplemental_base();
5540: } elsif (!$hiddentop) {
5541: $folderpath='default&'.
5542: &escape(&mt('Main Content').':::::');
5543: }
1.484 raeburn 5544: }
5545: }
1.519 raeburn 5546: $containertag = '<input type="hidden" name="folderpath" value="" />';
5547: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5548: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5549: $showdoc='/'.$1;
5550: }
5551: if ($showdoc) { # got called in sequence from course
5552: $allowed=0;
5553: } else {
1.611 raeburn 5554: if ($canedit) {
1.484 raeburn 5555: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5556: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5557: }
5558: }
1.329 droeschl 5559: }
5560:
1.344 bisitz 5561: # get personal data
1.329 droeschl 5562: my $uname=$env{'user.name'};
5563: my $udom=$env{'user.domain'};
5564: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5565:
5566: if ($allowed) {
1.484 raeburn 5567: if ($toolsflag) {
5568: $script .= &inject_data_js();
5569: my ($home,$other,%outhash)=&authorhosts();
5570: if (!$home && $other) {
5571: my @hosts;
5572: foreach my $aurole (keys(%outhash)) {
5573: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5574: push(@hosts,$outhash{$aurole});
5575: }
5576: }
5577: $script .= &dump_switchserver_js(@hosts);
5578: }
1.458 raeburn 5579: } else {
1.570 raeburn 5580: my $tid = 1;
1.484 raeburn 5581: my @tabids;
5582: if ($supplementalflag) {
5583: @tabids = ('002','ee2','ff2');
1.570 raeburn 5584: $tid = 2;
1.484 raeburn 5585: } else {
5586: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5587: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5588: unshift(@tabids,'001');
5589: push(@tabids,('dd1','ee1'));
5590: }
1.458 raeburn 5591: }
1.484 raeburn 5592: my $tabidstr = join("','",@tabids);
1.598 raeburn 5593: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5594: my $posslti = keys(%ltitools);
1.622 raeburn 5595: my $hostname = $r->hostname();
1.606 raeburn 5596: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5597: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5598: &history_tab_js().
5599: &inject_data_js().
1.570 raeburn 5600: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5601: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5602: $addentries = {
1.485 raeburn 5603: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5604: };
1.458 raeburn 5605: }
1.538 raeburn 5606: $script .= &paste_popup_js();
1.501 raeburn 5607: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5608: &mt('Switch server?');
5609:
5610:
1.329 droeschl 5611: }
5612: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5613: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5614: .'// <![CDATA['."\n"
5615: .$script."\n"
5616: .'// ]]>'."\n"
1.595 musolffc 5617: .'</script>'."\n"
5618: .'<script type="text/javascript"
5619: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5620:
5621: # Breadcrumbs
5622: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5623:
5624: if ($showdoc) {
5625: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5626: {'force_register' => $showdoc,}));
1.571 raeburn 5627: } elsif ($toolsflag) {
1.611 raeburn 5628: my ($breadtext,$breadtitle);
1.617 raeburn 5629: $breadtext = "$crstype Editor";
1.611 raeburn 5630: if ($canedit) {
5631: $breadtitle = 'Editing '.$crstype.' Contents';
5632: } else {
5633: $breadtext .= ' (View-only mode)';
5634: $breadtitle = 'Viewing '.$crstype.' Contents';
5635: }
1.571 raeburn 5636: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5637: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5638: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5639: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5640: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5641: $breadtitle)
1.571 raeburn 5642: );
1.510 raeburn 5643: } elsif ($r->uri eq '/adm/supplemental') {
5644: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5645: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5646: {'bread_crumbs' => $brcrum,}));
5647: } else {
1.611 raeburn 5648: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5649: $breadtext = "$crstype Editor";
1.611 raeburn 5650: if ($canedit) {
5651: $breadtitle = 'Editing '.$crstype.' Contents';
5652: $helpitem = 'Docs_Adding_Course_Doc';
5653: } else {
5654: $breadtext .= ' (View-only mode)';
5655: $breadtitle = 'Viewing '.$crstype.' Contents';
5656: $helpitem = 'Docs_Viewing_Course_Doc';
5657: }
1.392 raeburn 5658: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5659: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5660: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5661: {'add_entries' => $addentries}
5662: )
1.392 raeburn 5663: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5664: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5665: $breadtitle,
5666: $helpitem)
1.392 raeburn 5667: );
5668: }
1.364 bisitz 5669:
1.329 droeschl 5670: my %allfiles = ();
5671: my %codebase = ();
1.440 raeburn 5672: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5673: if ($canedit) {
1.329 droeschl 5674: if (($env{'form.uploaddoc.filename'}) &&
5675: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5676: my $context = $1;
5677: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5678: undef($hadchanges);
1.440 raeburn 5679: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5680: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5681: if ($hadchanges) {
5682: &mark_hash_old();
5683: }
1.440 raeburn 5684: $r->print($upload_output);
5685: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5686: # Process file upload - phase two - upload embedded objects
5687: $uploadphase = 'check_embedded';
5688: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5689: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5690: $env{'form.newidx'});
5691: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5692: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5693: my ($destination,$dir_root) = &embedded_destination();
5694: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5695: my $actionurl = '/adm/coursedocs';
1.630 raeburn 5696: my ($result,$flag) =
1.440 raeburn 5697: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5698: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5699: $actionurl);
5700: $r->print($result.&return_to_editor());
5701: } elsif ($env{'form.phase'} eq 'check_embedded') {
5702: # Process file upload - phase three - modify references in HTML file
5703: $uploadphase = 'modified_orightml';
5704: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5705: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5706: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 5707: my $result =
1.482 raeburn 5708: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5709: $docuname,$docudom,undef,
5710: $dir_root);
1.630 raeburn 5711: $r->print($result.&return_to_editor());
1.476 raeburn 5712: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5713: $uploadphase = 'decompress_phase_one';
5714: $r->print(&decompression_phase_one().
5715: &return_to_editor());
5716: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5717: $uploadphase = 'decompress_phase_two';
5718: $r->print(&decompression_phase_two().
5719: &return_to_editor());
1.329 droeschl 5720: }
5721: }
5722:
1.484 raeburn 5723: if ($allowed && $toolsflag) {
5724: $r->print(&startContentScreen('tools'));
1.611 raeburn 5725: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5726: $r->print(&endContentScreen());
5727: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5728: # -----------------------------------------------------------------------------
5729: my %lt=&Apache::lonlocal::texthash(
5730: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5731: 'upfi' => 'Upload File',
1.553 raeburn 5732: 'upld' => 'Upload Content',
1.329 droeschl 5733: 'srch' => 'Search',
5734: 'impo' => 'Import',
1.487 raeburn 5735: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5736: 'impm' => 'Import from Assembled Map',
1.630 raeburn 5737: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5738: 'extr' => 'External Resource',
5739: 'extt' => 'External Tool',
1.329 droeschl 5740: 'selm' => 'Select Map',
5741: 'load' => 'Load Map',
5742: 'newf' => 'New Folder',
5743: 'newp' => 'New Composite Page',
5744: 'syll' => 'Syllabus',
1.425 raeburn 5745: 'navc' => 'Table of Contents',
1.343 biermanm 5746: 'sipa' => 'Simple Course Page',
1.329 droeschl 5747: 'sipr' => 'Simple Problem',
1.630 raeburn 5748: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5749: 'stpr' => 'Standard Problem',
5750: 'news' => 'New sub-directory',
5751: 'crpr' => 'Create Problem',
1.329 droeschl 5752: 'drbx' => 'Drop Box',
1.451 www 5753: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5754: 'bull' => 'Discussion Board',
1.347 weissno 5755: 'mypi' => 'My Personal Information Page',
1.353 weissno 5756: 'grpo' => 'Group Portfolio',
1.329 droeschl 5757: 'rost' => 'Course Roster',
1.528 raeburn 5758: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5759: 'imsf' => 'IMS Upload',
5760: 'imsl' => 'Upload IMS package',
1.501 raeburn 5761: 'cms' => 'Origin of IMS package',
5762: 'se' => 'Select',
1.329 droeschl 5763: 'file' => 'File',
5764: 'title' => 'Title',
1.606 raeburn 5765: 'addp' => 'Add Placeholder to course?',
5766: 'uste' => 'Use Template?',
5767: 'fnam' => 'File Name:',
5768: 'loca' => 'Location:',
5769: 'dire' => 'Directory:',
5770: 'cate' => 'Category:',
5771: 'tmpl' => 'Template:',
1.329 droeschl 5772: 'comment' => 'Comment',
1.403 raeburn 5773: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5774: 'bb5' => 'Blackboard 5',
5775: 'bb6' => 'Blackboard 6',
5776: 'angel5' => 'ANGEL 5.5',
5777: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5778: 'yes' => 'Yes',
5779: 'no' => 'No',
1.618 raeburn 5780: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5781: );
1.329 droeschl 5782: # -----------------------------------------------------------------------------
1.595 musolffc 5783:
5784: # Calculate free quota space for a user or course. A javascript function checks
5785: # file size to determine if upload should be allowed.
5786: my $quotatype = 'unofficial';
5787: if ($crstype eq 'Community') {
1.601 raeburn 5788: $quotatype = 'community';
5789: } elsif ($crstype eq 'Placement') {
5790: $quotatype = 'placement';
1.595 musolffc 5791: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5792: $quotatype = 'official';
5793: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5794: $quotatype = 'textbook';
5795: }
5796: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5797: 'course',$quotatype); # expressed in MB
5798: my $current_disk_usage = 0;
5799: foreach my $subdir ('docs','supplemental') {
5800: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5801: "userfiles/$subdir",1); # expressed in kB
5802: }
5803: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5804: my $usage = $current_disk_usage/1024; # in MB
5805: my $quota = $disk_quota;
5806: my $percent;
5807: if ($disk_quota == 0) {
5808: $percent = 100.0;
5809: } else {
1.619 raeburn 5810: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5811: }
5812: $usage = sprintf("%.2f",$usage);
5813: $quota = sprintf("%.2f",$quota);
5814: $percent = sprintf("%.0f",$percent);
5815: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5816: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5817:
1.329 droeschl 5818: my $fileupload=(<<FIUP);
1.605 raeburn 5819: $quotainfo
1.329 droeschl 5820: $lt{'file'}:<br />
1.611 raeburn 5821: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5822: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5823: FIUP
5824:
5825: my $checkbox=(<<CHBO);
5826: <!-- <label>$lt{'parse'}?
5827: <input type="checkbox" name="parserflag" />
5828: </label> -->
5829: <label>
1.611 raeburn 5830: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5831: </label>
5832: CHBO
1.501 raeburn 5833: my $imsfolder = $env{'form.folder'};
5834: if ($imsfolder eq '') {
5835: $imsfolder = 'default';
5836: }
5837: my $imspform=(<<IMSFORM);
5838: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5839: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5840: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5841: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5842: <legend>$lt{'imsf'}</legend>
5843: $fileupload
5844: <br />
5845: <p>
5846: $lt{'cms'}:
1.611 raeburn 5847: <select name="source" $disabled>
1.501 raeburn 5848: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5849: <option value="bb5">$lt{'bb5'}</option>
5850: <option value="bb6">$lt{'bb6'}</option>
5851: <option value="angel5">$lt{'angel5'}</option>
5852: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5853: </select>
5854: <input type="hidden" name="folder" value="$imsfolder" />
5855: </p>
5856: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5857: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5858: </fieldset>
5859: </form>
5860: IMSFORM
1.329 droeschl 5861:
5862: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5863: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5864: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5865: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5866: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5867: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5868: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5869: $fileupload
1.329 droeschl 5870: <br />
5871: $lt{'title'}:<br />
1.611 raeburn 5872: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5873: $pathitem
1.329 droeschl 5874: <input type="hidden" name="cmd" value="upload_default" />
5875: <br />
1.458 raeburn 5876: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5877: $checkbox
5878: </span>
1.501 raeburn 5879: <br clear="all" />
1.611 raeburn 5880: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5881: </fieldset>
5882: </form>
1.383 tempelho 5883: FUFORM
1.329 droeschl 5884:
1.611 raeburn 5885: my $mapimportjs;
5886: if ($canedit) {
5887: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5888: } else {
5889: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5890: }
1.502 raeburn 5891: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5892: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5893: $lt{'impm'}</a>$help{'Load_Map'}
5894: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5895: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5896: <legend>$lt{'impm'}</legend>
1.371 tempelho 5897: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5898: $lt{'copm'}<br />
5899: <span class="LC_nobreak">
5900: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5901: onfocus="this.blur();$mapimportjs" $disabled />
5902: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5903: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5904: </fieldset>
5905: </form>
5906:
1.383 tempelho 5907: SEDFFORM
1.606 raeburn 5908: my $importcrsresform;
1.608 raeburn 5909: my ($numdirs,$pickfile) =
5910: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5911: "resize_scrollbox('contentscroll','1','0');",
5912: undef,'res');
1.606 raeburn 5913: if ($pickfile) {
5914: $importcrsresform=(<<CRSFORM);
5915: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5916: $lt{'imcr'}</a>$help{'Course_Resources'}
5917: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5918: <fieldset id="importcrsresform" style="display: none;">
5919: <legend>$lt{'imcr'}</legend>
5920: <input type="hidden" name="active" value="bb" />
5921: $pickfile
5922: <p>
1.611 raeburn 5923: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5924: </p>
5925: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5926: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5927: </fieldset>
5928: </form>
5929: CRSFORM
5930: }
5931:
1.611 raeburn 5932: my $fromstoredjs;
5933: if ($canedit) {
5934: $fromstoredjs = 'open_StoredLinks_Import()';
5935: } else {
5936: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5937: }
5938:
1.502 raeburn 5939: my @importpubforma = (
1.508 raeburn 5940: { '<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 5941: { '<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 5942: { '<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 5943: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5944: );
5945: if ($pickfile) {
5946: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5947: }
1.502 raeburn 5948: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5949: my $extresourcesform =
5950: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5951: $help{'Adding_External_Resource'},
5952: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5953: my $exttoolform =
5954: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5955: $help{'Adding_External_Tool'},undef,
5956: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5957: \%ltitools,$disabled);
1.329 droeschl 5958: if ($allowed) {
1.492 raeburn 5959: my $folder = $env{'form.folder'};
5960: if ($folder eq '') {
5961: $folder='default';
5962: }
1.615 raeburn 5963: if ($canedit) {
5964: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5965: if ($output) {
5966: $r->print($output);
5967: }
1.538 raeburn 5968: }
1.337 ehlerst 5969: $r->print(<<HIDDENFORM);
5970: <form name="renameform" method="post" action="/adm/coursedocs">
5971: <input type="hidden" name="title" />
5972: <input type="hidden" name="cmd" />
5973: <input type="hidden" name="markcopy" />
5974: <input type="hidden" name="copyfolder" />
5975: $containertag
5976: </form>
1.633 raeburn 5977: <form name="aliasform" method="post" action="/adm/coursedocs">
5978: <input type="hidden" name="alias" />
5979: <input type="hidden" name="cmd" />
5980: $containertag
5981: </form>
1.484 raeburn 5982:
1.337 ehlerst 5983: HIDDENFORM
1.508 raeburn 5984: $r->print(&makesimpleeditform($pathitem)."\n".
5985: &makedocslogform($pathitem."\n".
1.484 raeburn 5986: '<input type="hidden" name="folder" value="'.
5987: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5988: }
1.442 www 5989:
5990: # Generate the tabs
1.510 raeburn 5991: my ($mode,$needs_end);
1.472 raeburn 5992: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5993: my @folders = split('&',$env{'form.folderpath'});
5994: unless (@folders > 2) {
5995: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5996: $needs_end = 1;
5997: }
1.472 raeburn 5998: } else {
1.484 raeburn 5999: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6000: $needs_end = 1;
1.472 raeburn 6001: }
1.443 www 6002:
1.442 www 6003: #
1.622 raeburn 6004: my $hostname = $r->hostname();
1.442 www 6005: my $savefolderpath;
6006:
1.395 raeburn 6007: if ($allowed) {
1.329 droeschl 6008: my $folder=$env{'form.folder'};
1.615 raeburn 6009: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6010: $folder='default';
1.356 tempelho 6011: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6012: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6013: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6014: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6015: }
6016: my $postexec='';
6017: if ($folder eq 'default') {
1.372 bisitz 6018: $r->print('<script type="text/javascript">'."\n"
6019: .'// <![CDATA['."\n"
6020: .'this.window.name="loncapaclient";'."\n"
6021: .'// ]]>'."\n"
6022: .'</script>'."\n"
1.369 bisitz 6023: );
1.329 droeschl 6024: } else {
6025: #$postexec='self.close();';
6026: }
1.504 raeburn 6027: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6028: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6029: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6030:
6031: my $newnavform=(<<NNFORM);
6032: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 6033: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6034: $pathitem
1.329 droeschl 6035: <input type="hidden" name="importdetail"
6036: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6037: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6038: $help{'Navigate_Content'}
6039: </form>
6040: NNFORM
6041: my $newsmppageform=(<<NSPFORM);
6042: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 6043: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6044: $pathitem
1.329 droeschl 6045: <input type="hidden" name="importdetail" value="" />
1.423 onken 6046: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6047: $help{'Simple Page'}
1.329 droeschl 6048: </form>
6049: NSPFORM
6050:
6051: my $newsmpproblemform=(<<NSPROBFORM);
6052: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6053: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6054: $pathitem
1.329 droeschl 6055: <input type="hidden" name="importdetail" value="" />
1.423 onken 6056: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6057: $help{'Simple_Problem'}
1.329 droeschl 6058: </form>
6059:
6060: NSPROBFORM
6061:
6062: my $newdropboxform=(<<NDBFORM);
6063: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6064: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6065: $pathitem
1.329 droeschl 6066: <input type="hidden" name="importdetail" value="" />
1.423 onken 6067: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6068: $help{'Dropbox'}
1.344 bisitz 6069: </form>
1.329 droeschl 6070: NDBFORM
6071:
6072: my $newexuploadform=(<<NEXUFORM);
6073: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6074: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6075: $pathitem
1.329 droeschl 6076: <input type="hidden" name="importdetail" value="" />
1.423 onken 6077: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6078: $help{'Score_Upload_Form'}
6079: </form>
6080: NEXUFORM
6081:
6082: my $newbulform=(<<NBFORM);
6083: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 6084: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6085: $pathitem
1.329 droeschl 6086: <input type="hidden" name="importdetail" value="" />
1.423 onken 6087: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6088: $help{'Bulletin Board'}
6089: </form>
6090: NBFORM
6091:
6092: my $newaboutmeform=(<<NAMFORM);
6093: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 6094: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6095: $pathitem
1.329 droeschl 6096: <input type="hidden" name="importdetail"
6097: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6098: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6099: $help{'My Personal Information Page'}
1.329 droeschl 6100: </form>
6101: NAMFORM
6102:
6103: my $newaboutsomeoneform=(<<NASOFORM);
6104: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 6105: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6106: $pathitem
1.329 droeschl 6107: <input type="hidden" name="importdetail" value="" />
1.423 onken 6108: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6109: </form>
6110: NASOFORM
6111:
6112: my $newrosterform=(<<NROSTFORM);
6113: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 6114: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6115: $pathitem
1.329 droeschl 6116: <input type="hidden" name="importdetail"
6117: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6118: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6119: $help{'Course_Roster'}
1.329 droeschl 6120: </form>
6121: NROSTFORM
6122:
1.534 raeburn 6123: my $newwebpage;
6124: if ($folder =~ /^default_?(\d*)$/) {
6125: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6126: if ($1) {
6127: $newwebpage .= $1;
6128: } else {
6129: $newwebpage .= 'default';
6130: }
6131: $newwebpage .= '/new.html';
6132: }
6133: my $newwebpageform =(<<NWEBFORM);
6134: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 6135: <input type="hidden" name="active" value="ee" />
1.534 raeburn 6136: $pathitem
6137: <input type="hidden" name="importdetail" value="$newwebpage" />
6138: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6139: $help{'Web_Page'}
1.534 raeburn 6140: </form>
6141: NWEBFORM
1.604 raeburn 6142:
1.606 raeburn 6143: my @ids=&Apache::lonnet::current_machine_ids();
6144: my %select_menus;
6145: my $numauthor = 0;
6146: my $numcrsdirs = 0;
6147: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6148: if ($env{'user.author'}) {
6149: $numauthor ++;
6150: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6151: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6152: my $is_home = 1;
6153: my %subdirs;
1.608 raeburn 6154: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6155: $select_menus{'author'}->{'default'} = '/';
6156: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6157: my @ordered = ('/');
6158: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6159: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6160: push(@ordered,$relpath);
6161: }
6162: $select_menus{'author'}->{'order'} = \@ordered;
6163: } else {
6164: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6165: $select_menus{'author'}->{'default'} = 'switch';
6166: $select_menus{'author'}->{'order'} = ['switch'];
6167: }
6168: }
6169: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6170: ['active'],['ca','aa']);
6171: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6172: my %by_roletype;
6173: if (keys(%roleshash)) {
6174: foreach my $entry (keys(%roleshash)) {
6175: my ($auname,$audom,$roletype) = split(/:/,$entry);
6176: my $key = $entry;
6177: $key =~ s/:/___/g;
6178: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6179: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6180: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6181: if (grep(/^\Q$rolehome\E$/,@ids)) {
6182: my $is_home = 1;
6183: my (%subdirs,@ordered);
6184: my $toppath="/priv/$audom/$auname";
1.608 raeburn 6185: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6186: $select_menus{$key}->{'default'} = '/';
6187: $select_menus{$key}->{'select2'}->{'/'} = '/';
6188: my @ordered = ('/');
6189: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6190: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6191: push(@ordered,$relpath);
6192: }
6193: $select_menus{$key}->{'order'} = \@ordered;
6194: } else {
6195: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6196: $select_menus{$key}->{'default'} = 'switch';
6197: $select_menus{$key}->{'order'} = ['switch'];
6198: }
6199: $numauthor ++;
6200: }
6201: }
1.631 raeburn 6202: my ($pickdir,$showtitle);
1.606 raeburn 6203: if ($numauthor) {
6204: my @order;
6205: my $defrole;
6206: if ($env{'user.author'}) {
6207: push(@order,'author');
6208: $defrole = 'author';
6209: }
6210: if (keys(%by_roletype)) {
6211: foreach my $possrole ('ca','aa') {
6212: if (ref($by_roletype{$possrole}) eq 'HASH') {
6213: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6214: unless ($defrole) {
6215: $defrole = $author;
6216: }
6217: push(@order,$author.'___'.$possrole);
6218: }
6219: }
6220: }
6221: }
6222: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6223: if (grep(/^\Q$crshome\E$/,@ids)) {
6224: my $is_home = 1;
6225: my %subdirs;
6226: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6227: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6228: $numcrsdirs = keys(%subdirs);
6229: $select_menus{'course'}->{'default'} = '/';
6230: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6231: my @ordered = ('/');
6232: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6233: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6234: push(@ordered,$relpath);
6235: }
6236: $select_menus{'course'}->{'order'} = \@ordered;
6237: } else {
6238: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6239: $select_menus{'course'}->{'default'} = 'switch';
6240: $select_menus{'course'}->{'order'} = ['switch'];
6241: }
6242: push(@order,'course');
6243: $pickdir = $lt{'loca'}.
6244: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6245: $defrole,'authorrole','authorpath',
6246: \%select_menus,\@order,'toggleCrsResTitle();',
6247: '','priv').'<br />';
6248: $showtitle = 'none';
6249: } else {
6250: my $is_home;
6251: $showtitle = 'inline';
6252: if (grep(/^\Q$crshome\E$/,@ids)) {
6253: $is_home = 1;
6254: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6255: my $toppath="/priv/$coursedom/$coursenum'}";
6256: my %subdirs;
1.608 raeburn 6257: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6258: $numcrsdirs = keys(%subdirs);
6259: if ($numcrsdirs) {
6260: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6261: '<option value="/">/</option>'."\n";
6262: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6263: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6264: }
6265: $pickdir .= '</select>';
6266: } else {
6267: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6268: }
6269: }
6270: }
6271:
6272: my %seltemplate_menus;
6273: my @files = &Apache::lonhomework::get_template_list('problem');
6274: my @noexamplelink = ('blank.problem','blank.library','script.library');
6275: my $currentcategory = '';
6276: my @ordered = ('');
6277: my %templatehelp;
6278: my $defcategory = '';
6279: my @catorder = ($defcategory);
6280: $seltemplate_menus{$defcategory}->{'order'} = [''];
6281: $seltemplate_menus{$defcategory}->{'text'} = '';
6282: foreach my $file (@files) {
6283: if (ref($file) eq 'ARRAY') {
6284: my ($path,$title,$category,$help) = @{$file};
6285: next if ($title !~ /\S/);
6286: if (&js_escape($category) ne $currentcategory) {
6287: $currentcategory = &js_escape($category);
6288: push(@catorder,&js_escape($currentcategory));
6289: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6290: $seltemplate_menus{$currentcategory}->{'default'} = '';
6291: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6292: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6293: }
6294: if ($path) {
6295: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6296: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6297: if ($help) {
6298: $templatehelp{$path} = $help;
6299: }
6300: }
6301: }
6302: }
6303:
6304: my $templates = $lt{'cate'}.' '.
6305: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6306: $defcategory,'tempcategory','template',
6307: \%seltemplate_menus,\@catorder,
6308: "resize_scrollbox('contentscroll','1','0');",
6309: "toggleExampleText();",'template').'<br />';
6310: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6311: '<span id="newresexample">'.&mt('Example').'<span></a>';
6312: my $crsresform=(<<RESFORM);
6313: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6314: $lt{'stpr'}</a>$help{'Course_Resource'}
6315: <form action="/adm/coursedocs" method="post" name="courseresform">
6316: <fieldset id="crsresform" style="display:none;">
6317: <legend>$lt{'stpr'}</legend>
6318: <input type="hidden" name="active" value="ee" />
6319: <p>
6320: $pickdir
6321: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6322: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6323:
1.611 raeburn 6324: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6325: </span><span id="newsubdir"></span>
6326: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6327: </p>
6328: $lt{'fnam'}
1.611 raeburn 6329: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6330: <p>
6331: <div id="newresource" style="display:$showtitle">
6332: $lt{'addp'}
1.611 raeburn 6333: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6334: $lt{'no'}</label>
1.611 raeburn 6335: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6336: $lt{'yes'}</label>
6337: <span id="newrestitle"></span>
1.611 raeburn 6338: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6339: </div>
6340: </p>
6341: <p>
6342: $lt{'uste'}
1.611 raeburn 6343: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6344: $lt{'no'}</label>
1.611 raeburn 6345: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6346: $lt{'yes'}</label>
6347: <div id="newrestemplate" style="display:none">
6348: $templates
6349: $templatepreview
6350: </div>
6351: </p>
6352: <span class="LC_nobreak">
6353: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6354: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6355: </span>
6356: </fieldset>
6357: </form>
6358:
6359: RESFORM
1.534 raeburn 6360:
1.342 ehlerst 6361: my $specialdocumentsform;
1.383 tempelho 6362: my @specialdocumentsforma;
1.451 www 6363: my $gradingform;
6364: my @gradingforma;
6365: my $communityform;
6366: my @communityforma;
1.351 ehlerst 6367: my $newfolderform;
1.390 tempelho 6368: my $newfolderb;
1.342 ehlerst 6369:
1.451 www 6370: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6371:
1.329 droeschl 6372: my $newpageform=(<<NPFORM);
6373: <form action="/adm/coursedocs" method="post" name="newpage">
6374: <input type="hidden" name="folderpath" value="$path" />
6375: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6376: <input type="hidden" name="active" value="ee" />
1.423 onken 6377: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6378: $help{'Adding_Pages'}
1.329 droeschl 6379: </form>
6380: NPFORM
1.390 tempelho 6381:
6382:
1.351 ehlerst 6383: $newfolderform=(<<NFFORM);
1.329 droeschl 6384: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6385: $pathitem
1.329 droeschl 6386: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6387: <input type="hidden" name="active" value="" />
1.422 onken 6388: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6389: </form>
6390: NFFORM
6391:
6392: my $newsylform=(<<NSYLFORM);
6393: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6394: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6395: $pathitem
1.329 droeschl 6396: <input type="hidden" name="importdetail"
6397: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6398: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6399: $help{'Syllabus'}
1.383 tempelho 6400:
1.329 droeschl 6401: </form>
6402: NSYLFORM
1.364 bisitz 6403:
1.329 droeschl 6404: my $newgroupfileform=(<<NGFFORM);
6405: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6406: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6407: $pathitem
1.329 droeschl 6408: <input type="hidden" name="importdetail"
6409: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6410: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6411: $help{'Group Portfolio'}
1.329 droeschl 6412: </form>
6413: NGFFORM
1.383 tempelho 6414: @specialdocumentsforma=(
1.421 onken 6415: {'<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 6416: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6417: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6418: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6419: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6420: );
6421: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6422:
1.434 raeburn 6423:
6424: my @importdoc = (
1.519 raeburn 6425: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6426: );
1.598 raeburn 6427: if (keys(%ltitools)) {
6428: push(@importdoc,
1.627 raeburn 6429: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
1.598 raeburn 6430: );
6431: }
1.519 raeburn 6432: unless ($container eq 'page') {
6433: push(@importdoc,
6434: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6435: );
6436: }
6437: push(@importdoc,
1.558 raeburn 6438: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6439: );
1.501 raeburn 6440: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6441:
1.451 www 6442: @gradingforma=(
6443: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6444: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6445: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6446: {'<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 6447: );
6448: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6449:
6450: @communityforma=(
6451: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6452: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6453: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6454: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6455: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6456: );
6457: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6458:
1.330 tempelho 6459: my %orderhash = (
1.553 raeburn 6460: 'aa' => ['Upload',$fileuploadform],
6461: 'bb' => ['Import',$importpubform],
6462: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6463: );
1.519 raeburn 6464: unless ($container eq 'page') {
1.434 raeburn 6465: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6466: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6467: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6468: }
6469:
1.341 ehlerst 6470: $hadchanges=0;
1.484 raeburn 6471: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6472: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6473: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6474: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6475: undef($navmap);
1.443 www 6476: if ($error) {
6477: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6478: }
6479: if ($hadchanges) {
6480: &mark_hash_old();
6481: }
1.341 ehlerst 6482:
1.443 www 6483: &changewarning($r,'');
6484: }
1.458 raeburn 6485: }
1.442 www 6486:
1.443 www 6487: # Supplemental documents start here
6488:
1.329 droeschl 6489: my $folder=$env{'form.folder'};
1.443 www 6490: unless ($supplementalflag) {
1.329 droeschl 6491: $folder='supplemental';
6492: }
6493: if ($folder =~ /^supplemental$/ &&
6494: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6495: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6496: } elsif ($allowed) {
1.356 tempelho 6497: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6498: }
1.508 raeburn 6499: $pathitem = '<input type="hidden" name="folderpath" value="'.
6500: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6501: if ($allowed) {
6502: my $folderseq=
1.504 raeburn 6503: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6504:
6505: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6506: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6507: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6508: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6509: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6510: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6511: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6512: $fileupload
6513: <br />
6514: <br />
6515: <span class="LC_nobreak">
6516: $checkbox
6517: </span>
6518: <br /><br />
6519: $lt{'comment'}:<br />
1.383 tempelho 6520: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6521: <br />
1.508 raeburn 6522: $pathitem
1.329 droeschl 6523: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6524: <input type='submit' value="$lt{'upld'}" />
6525: </form>
1.329 droeschl 6526: SUPDOCFORM
6527:
6528: my $supnewfolderform=(<<SNFFORM);
6529: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6530: <input type="hidden" name="active" value="" />
1.508 raeburn 6531: $pathitem
1.329 droeschl 6532: <input type="hidden" name="importdetail" value="" />
1.423 onken 6533: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6534: $help{'Adding_Folders'}
1.329 droeschl 6535: </form>
6536: SNFFORM
1.383 tempelho 6537:
1.510 raeburn 6538: my $supextform =
6539: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6540: $help{'Adding_External_Resource'},
6541: undef,undef,undef,undef,undef,undef,
6542: $disabled);
1.329 droeschl 6543:
1.598 raeburn 6544: my $supexttoolform =
6545: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6546: $help{'Adding_External_Tool'},
6547: undef,undef,'tool',$coursedom,
1.611 raeburn 6548: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6549:
1.329 droeschl 6550: my $supnewsylform=(<<SNSFORM);
6551: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6552: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6553: $pathitem
1.329 droeschl 6554: <input type="hidden" name="importdetail"
6555: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6556: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6557: $help{'Syllabus'}
6558: </form>
6559: SNSFORM
6560:
6561: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6562: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6563: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6564: $pathitem
1.329 droeschl 6565: <input type="hidden" name="importdetail"
6566: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6567: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6568: $help{'My Personal Information Page'}
1.329 droeschl 6569: </form>
6570: SNAMFORM
6571:
1.534 raeburn 6572: my $supwebpage;
6573: if ($folder =~ /^supplemental_?(\d*)$/) {
6574: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6575: if ($1) {
6576: $supwebpage .= $1;
6577: } else {
6578: $supwebpage .= 'default';
6579: }
6580: $supwebpage .= '/new.html';
6581: }
6582: my $supwebpageform =(<<SWEBFORM);
6583: <form action="/adm/coursedocs" method="post" name="supwebpage">
6584: <input type="hidden" name="active" value="cc" />
6585: $pathitem
6586: <input type="hidden" name="importdetail" value="$supwebpage" />
6587: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6588: $help{'Web_Page'}
1.534 raeburn 6589: </form>
6590: SWEBFORM
6591:
1.333 muellerd 6592:
1.383 tempelho 6593: my @specialdocs = (
1.618 raeburn 6594: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6595: =>$supnewsylform},
1.611 raeburn 6596: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6597: =>$supnewaboutmeform},
1.534 raeburn 6598: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6599:
1.383 tempelho 6600: );
1.417 droeschl 6601: my @supimportdoc = (
1.515 raeburn 6602: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6603: =>$supextform});
6604: if (keys(%ltitools)) {
6605: push(@supimportdoc,
1.627 raeburn 6606: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
1.598 raeburn 6607: =>$supexttoolform});
6608: }
6609: push(@supimportdoc,
6610: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6611: =>$supupdocform},
1.598 raeburn 6612: );
1.501 raeburn 6613:
6614: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6615: my %suporderhash = (
1.390 tempelho 6616: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6617: 'ee' => ['Upload',$supupdocform],
6618: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6619: );
1.443 www 6620: if ($supplementalflag) {
1.458 raeburn 6621: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6622: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6623: \%ltitools,$canedit,$hostname);
1.443 www 6624: if ($error) {
6625: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6626: } else {
6627: if ($suppchanges) {
6628: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6629: my @ids=&Apache::lonnet::current_machine_ids();
6630: foreach my $server (keys(%servers)) {
6631: next if (grep(/^\Q$server\E$/,@ids));
6632: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6633: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6634: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6635: }
6636: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6637: undef($suppchanges);
1.630 raeburn 6638: }
6639: }
1.393 raeburn 6640: }
1.443 www 6641: } elsif ($supplementalflag) {
1.458 raeburn 6642: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6643: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6644: if ($error) {
6645: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6646: }
1.393 raeburn 6647: }
1.389 tempelho 6648:
1.510 raeburn 6649: if ($needs_end) {
6650: $r->print(&endContentScreen());
6651: }
1.383 tempelho 6652:
1.329 droeschl 6653: if ($allowed) {
6654: $r->print('
6655: <form method="post" name="extimport" action="/adm/coursedocs">
6656: <input type="hidden" name="title" />
6657: <input type="hidden" name="url" />
6658: <input type="hidden" name="useform" />
6659: <input type="hidden" name="residx" />
6660: </form>');
6661: }
1.484 raeburn 6662: } elsif ($showdoc) {
1.329 droeschl 6663: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6664: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6665: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6666: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6667: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6668: }
6669: }
1.630 raeburn 6670: unless ($noendpage) {
1.606 raeburn 6671: $r->print(&Apache::loncommon::end_page());
6672: }
1.329 droeschl 6673: return OK;
1.364 bisitz 6674: }
1.329 droeschl 6675:
1.440 raeburn 6676: sub embedded_form_elems {
6677: my ($phase,$primaryurl,$newidx) = @_;
6678: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 6679: $newidx =~s /\D+//g;
1.440 raeburn 6680: return <<STATE;
6681: <input type="hidden" name="folderpath" value="$folderpath" />
6682: <input type="hidden" name="cmd" value="upload_embedded" />
6683: <input type="hidden" name="newidx" value="$newidx" />
6684: <input type="hidden" name="phase" value="$phase" />
6685: <input type="hidden" name="primaryurl" value="$primaryurl" />
6686: STATE
6687: }
6688:
6689: sub embedded_destination {
6690: my $folder=$env{'form.folder'};
6691: my $destination = 'docs/';
6692: if ($folder =~ /^supplemental/) {
6693: $destination = 'supplemental/';
6694: }
6695: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6696: $destination .= 'default/';
6697: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6698: $destination .= $2.'/';
6699: }
1.634 raeburn 6700: my $newidx = $env{'form.newidx'};
6701: $newidx =~s /\D+//g;
6702: if ($newidx) {
6703: $destination .= $newidx;
6704: }
1.440 raeburn 6705: my $dir_root = '/userfiles';
6706: return ($destination,$dir_root);
6707: }
6708:
6709: sub return_to_editor {
6710: my $actionurl = '/adm/coursedocs';
6711: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6712: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6713: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6714: '</a></p>';
6715: }
6716:
1.476 raeburn 6717: sub decompression_info {
6718: my ($destination,$dir_root) = &embedded_destination();
6719: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6720: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6721: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6722: my $container='sequence';
1.480 raeburn 6723: my ($pathitem,$hiddenelem);
1.583 raeburn 6724: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6725: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6726: $container='page';
6727: }
1.480 raeburn 6728: unshift(@hiddens,$pathitem);
6729: foreach my $item (@hiddens) {
1.634 raeburn 6730: if ($item eq 'newidx') {
6731: next if ($env{'form.'.$item} =~ /\D/);
6732: }
1.480 raeburn 6733: if ($env{'form.'.$item}) {
6734: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6735: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6736: }
1.477 raeburn 6737: }
1.476 raeburn 6738: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6739: $hiddenelem);
6740: }
6741:
6742: sub decompression_phase_one {
6743: my ($dir,$file,$warning,$error,$output);
6744: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6745: &decompression_info();
1.490 raeburn 6746: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6747: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6748: } else {
6749: my $file = $1;
1.630 raeburn 6750: $output =
1.481 raeburn 6751: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6752: $destination,$dir_root,
6753: $hiddenelem);
6754: if ($env{'form.autoextract_camtasia'}) {
6755: $output .= &remove_archive($docudom,$docuname,$container);
6756: }
1.476 raeburn 6757: }
6758: if ($error) {
6759: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6760: $error.'</p>'."\n";
6761: }
6762: if ($warning) {
6763: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6764: }
6765: return $output;
6766: }
6767:
6768: sub decompression_phase_two {
6769: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6770: &decompression_info();
1.481 raeburn 6771: my $output;
1.480 raeburn 6772: if ($env{'form.archivedelete'}) {
1.481 raeburn 6773: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6774: }
6775: $output .=
1.481 raeburn 6776: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6777: $destination,$dir_root,$hiddenelem);
6778: return $output;
6779: }
6780:
1.480 raeburn 6781: sub remove_archive {
6782: my ($docudom,$docuname,$container) = @_;
6783: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6784: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6785: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6786: if ($fatal) {
6787: if ($container eq 'page') {
6788: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6789: } else {
6790: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6791: }
1.583 raeburn 6792: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6793: } else {
6794: my $currcmd = $env{'form.cmd'};
6795: my $position = $env{'form.position'};
1.583 raeburn 6796: my $archiveidx = $position;
1.563 raeburn 6797: if ($position > 0) {
1.583 raeburn 6798: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6799: $archiveidx = $position-1;
6800: }
6801: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6802: my ($title,$url,@rrest) =
1.583 raeburn 6803: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6804: if ($url eq $env{'form.archiveurl'}) {
6805: if (&handle_edit_cmd($docuname,$docudom)) {
6806: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6807: if ($fatal) {
6808: if ($container eq 'page') {
6809: $delwarning = &mt('An error occurred updating the contents of the current page.');
6810: } else {
6811: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6812: }
1.480 raeburn 6813: } else {
1.583 raeburn 6814: $delresult = &mt('Archive file removed.');
1.480 raeburn 6815: }
6816: }
1.583 raeburn 6817: } else {
6818: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6819: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6820: }
6821: }
6822: $env{'form.cmd'} = $currcmd;
6823: }
6824: if ($delwarning) {
6825: $output = '<p class="LC_warning">'.
6826: $delwarning.
6827: '</p>';
6828: }
6829: if ($delresult) {
6830: $output .= '<p class="LC_info">'.
6831: $delresult.
6832: '</p>';
6833: }
1.481 raeburn 6834: return $output;
1.480 raeburn 6835: }
6836:
1.484 raeburn 6837: sub generate_admin_menu {
1.611 raeburn 6838: my ($crstype,$canedit) = @_;
1.484 raeburn 6839: my $lc_crstype = lc($crstype);
6840: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6841: my %lt= ( # do not translate here
1.484 raeburn 6842: 'vc' => 'Verify Content',
6843: 'cv' => 'Check/Set Resource Versions',
6844: 'ls' => 'List Resource Identifiers',
6845: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6846: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6847: );
1.484 raeburn 6848: my ($candump,$dumpurl);
6849: if ($home + $other > 0) {
6850: $candump = 'F';
6851: if ($home) {
6852: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6853: } else {
6854: my @hosts;
6855: foreach my $aurole (keys(%outhash)) {
6856: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6857: push(@hosts,$outhash{$aurole});
1.538 raeburn 6858: }
1.484 raeburn 6859: }
6860: if (@hosts == 1) {
6861: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6862: '&role='.
6863: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6864: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6865: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6866: } else {
6867: $dumpurl = "javascript:choose_switchserver_window()";
6868: }
6869: }
6870: }
6871: my @menu=
6872: ({ categorytitle=>'Administration',
6873: items =>[
6874: { linktext => $lt{'vc'},
6875: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6876: permission => 'F',
1.571 raeburn 6877: help => 'Docs_Verify_Content',
1.484 raeburn 6878: icon => 'verify.png',
6879: linktitle => 'Verify contents can be retrieved/rendered',
6880: },
6881: { linktext => $lt{'cv'},
6882: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6883: permission => 'F',
1.571 raeburn 6884: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6885: icon => 'resversion.png',
6886: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6887: },
6888: { linktext => $lt{'ls'},
6889: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6890: permission => 'F',
6891: #help => '',
6892: icon => 'symbs.png',
6893: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6894: },
6895: ]
1.611 raeburn 6896: });
6897: if ($canedit) {
6898: push(@menu,
1.484 raeburn 6899: { categorytitle=>'Export',
6900: items =>[
6901: { linktext => $lt{'imse'},
6902: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6903: permission => 'F',
6904: help => 'Docs_Export_Course_Docs',
6905: icon => 'imsexport.png',
6906: linktitle => $lt{'imse'},
6907: },
6908: { linktext => $lt{'dcd'},
6909: url => $dumpurl,
6910: permission => $candump,
1.571 raeburn 6911: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6912: icon => 'dump.png',
6913: linktitle => $lt{'dcd'},
6914: },
6915: ]
6916: });
1.611 raeburn 6917: }
1.484 raeburn 6918: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6919: '<input type="hidden" id="dummy" />'."\n".
6920: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6921: '</form>';
1.329 droeschl 6922: }
6923:
6924: sub generate_edit_table {
1.538 raeburn 6925: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6926: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6927: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6928: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6929: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6930: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6931: $activetab = $env{'form.active'};
6932: }
1.611 raeburn 6933: unless ($canedit) {
6934: $disabled = ' disabled="disabled"';
6935: }
1.472 raeburn 6936: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6937: my $backtext = &mt('Exit Editor');
1.458 raeburn 6938: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6939: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6940: '<li class="goback">'.
1.546 raeburn 6941: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6942: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6943: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6944: '<li>'.
6945: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6946: &mt('Undo Delete').'</a></li>'."\n";
6947: if ($env{'form.docslog'}) {
6948: $form .= '<li class="active">';
6949: } else {
6950: $form .= '<li>';
6951: }
6952: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6953: &mt('History').'</a></li>'."\n";
6954: if ($env{'form.docslog'}) {
6955: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6956: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6957: }
1.458 raeburn 6958: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6959: if($name ne '00'){
1.371 tempelho 6960: if($activetab eq '' || $activetab ne $name){
6961: $active = '';
6962: }elsif($activetab eq $name){
6963: $active = 'class="active"';
6964: }
1.458 raeburn 6965: $form .= '<li style="float:right" '.$active
1.484 raeburn 6966: .' 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 6967: } else {
1.570 raeburn 6968: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6969:
6970: }
1.329 droeschl 6971: }
1.484 raeburn 6972: $form .= '</ul>'."\n";
6973: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6974:
6975: if ($to_show ne '') {
1.538 raeburn 6976: my $saveform;
6977: if ($need_save) {
6978: my $button = &mt('Make changes');
6979: my $path;
6980: if ($env{'form.folderpath'}) {
6981: $path =
6982: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6983: }
6984: $saveform = <<"END";
6985: <div id="multisave" style="display:none; clear:both;" >
6986: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6987: <input type="hidden" name="folderpath" value="$path" />
6988: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6989: <input type="hidden" name="allhiddenresource" value="" />
6990: <input type="hidden" name="allencrypturl" value="" />
6991: <input type="hidden" name="allrandompick" value="" />
6992: <input type="hidden" name="allrandomorder" value="" />
6993: <input type="hidden" name="changeparms" value="" />
6994: <input type="hidden" name="multiremove" value="" />
6995: <input type="hidden" name="multicut" value="" />
6996: <input type="hidden" name="multicopy" value="" />
6997: <input type="hidden" name="multichange" value="" />
6998: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 6999: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7000: </form>
7001: </div>
7002: END
7003: }
7004: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7005: }
1.363 ehlerst 7006: foreach my $field (keys(%orderhash)){
1.390 tempelho 7007: if($field ne '00'){
1.422 onken 7008: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7009: $active = 'style="display: none;float:left"';
1.422 onken 7010: }elsif($activetab eq $field){
1.458 raeburn 7011: $active = 'style="display:block;float:left"';
1.422 onken 7012: }
7013: $form .= '<div id="'.$field.$tid.'"'
7014: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7015: .'</div>'."\n";
1.363 ehlerst 7016: }
7017: }
1.484 raeburn 7018: unless ($env{'form.docslog'}) {
7019: $form .= '</div></div>'."\n";
7020: }
1.329 droeschl 7021: return $form;
7022: }
7023:
7024: sub editing_js {
1.622 raeburn 7025: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7026: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7027: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7028: p_mnf => 'Name of New Folder',
7029: t_mnf => 'New Folder',
7030: p_mnp => 'Name of New Page',
7031: t_mnp => 'New Page',
1.451 www 7032: p_mxu => 'Title for the External Score',
1.349 biermanm 7033: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7034: p_msb => 'Title for the Problem',
7035: p_mdb => 'Title for the Drop Box',
1.336 schafran 7036: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7037: p_mwp => 'Title for Web Page',
1.606 raeburn 7038: p_mnr => 'Title for the Resource',
1.348 weissno 7039: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7040: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7041: p_mab_alrt1 => 'Not a valid user:domain',
7042: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7043: p_chn => 'New Title',
7044: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7045: p_rmr2a => 'Remove',
7046: p_rmr2b => '?',
7047: p_rmr3a => 'Remove those',
7048: p_rmr3b => 'items?',
7049: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7050: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7051: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7052: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7053: p_ctr2a => 'Cut',
7054: p_ctr2b => '?',
7055: p_ctr3a => 'Cut those',
7056: p_ctr3b => 'items?',
1.633 raeburn 7057: setal => 'Enter a (unique) alias',
7058: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7059: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7060: imsfile => 'You must choose an IMS package for import',
7061: imscms => 'You must select which Course Management System was the source of the IMS package',
7062: invurl => 'Invalid URL',
7063: titbl => 'Title is blank',
1.538 raeburn 7064: more => '(More ...)',
7065: less => '(Less ...)',
1.543 raeburn 7066: noor => 'No actions selected or changes to settings specified.',
7067: noch => 'No changes to settings specified.',
7068: noac => 'No actions selected.',
1.606 raeburn 7069: nofi => 'No file selected',
7070: tinc => 'Title in course',
7071: sunm => 'Sub-directory name',
1.618 raeburn 7072: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7073: );
1.594 damieng 7074: &js_escape(\%js_lt);
1.433 raeburn 7075: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7076: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7077: my $main_container_page;
1.519 raeburn 7078: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7079: $main_container_page = 1;
1.434 raeburn 7080: }
1.617 raeburn 7081: my $backtourl;
7082: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7083: my $toplevelsupp = &supplemental_base();
1.433 raeburn 7084:
1.530 raeburn 7085: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7086: my $caller = $1;
1.525 raeburn 7087: if ($caller =~ /^supplemental/) {
7088: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7089: } else {
7090: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7091: $res = &Apache::lonnet::clutter($res);
7092: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7093: my ($url,$anchor);
7094: if ($res =~ /^([^#]+)#([^#]+)$/) {
7095: $url = $1;
7096: $anchor = $2;
7097: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7098: $caller = $1.&escape('#').$anchor;
7099: }
1.614 raeburn 7100: } else {
7101: $url = $res;
1.609 raeburn 7102: }
7103: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 7104: &HTML::Entities::encode($caller,'<>&"');
1.622 raeburn 7105: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7106: if (($ENV{'SERVER_PORT'} == 443) &&
7107: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
7108: if ($hostname ne '') {
7109: $backtourl = 'http://'.$hostname.$backtourl;
7110: }
1.627 raeburn 7111: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7112: }
1.623 raeburn 7113: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7114: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
7115: $backtourl = 'http://'.$hostname.$backtourl;
7116: }
1.622 raeburn 7117: }
1.609 raeburn 7118: if ($anchor ne '') {
7119: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7120: }
1.590 raeburn 7121: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7122: } else {
7123: $backtourl = '/adm/navmaps';
1.525 raeburn 7124: }
7125: }
7126: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7127: $backtourl = '/adm/menu';
7128: } elsif ($supplementalflag) {
1.472 raeburn 7129: $backtourl = '/adm/supplemental';
1.525 raeburn 7130: } else {
7131: $backtourl = '/adm/navmaps';
1.472 raeburn 7132: }
7133:
1.600 raeburn 7134: my $fieldsets = "'ext','doc'";
7135: if ($posslti) {
7136: $fieldsets .= ",'tool'";
7137: }
1.519 raeburn 7138: unless ($main_container_page) {
7139: $fieldsets .=",'ims'";
7140: }
1.501 raeburn 7141: if ($supplementalflag) {
1.600 raeburn 7142: $fieldsets = "'suppext','suppdoc'";
7143: if ($posslti) {
7144: $fieldsets .= ",'supptool'";
7145: }
1.501 raeburn 7146: }
1.611 raeburn 7147:
7148: my $jsmakefunctions;
7149: if ($canedit) {
7150: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7151: function makenewfolder(targetform,folderseq) {
1.594 damieng 7152: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7153: if (foldername) {
7154: targetform.importdetail.value=escape(foldername)+"="+folderseq;
7155: targetform.submit();
7156: }
7157: }
7158:
7159: function makenewpage(targetform,folderseq) {
1.594 damieng 7160: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7161: if (pagename) {
7162: targetform.importdetail.value=escape(pagename)+"="+folderseq;
7163: targetform.submit();
7164: }
7165: }
7166:
7167: function makeexamupload() {
1.594 damieng 7168: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7169: if (title) {
1.329 droeschl 7170: this.document.forms.newexamupload.importdetail.value=
7171: escape(title)+'=/res/lib/templates/examupload.problem';
7172: this.document.forms.newexamupload.submit();
7173: }
7174: }
7175:
7176: function makesmppage() {
1.594 damieng 7177: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7178: if (title) {
1.329 droeschl 7179: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 7180: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7181: this.document.forms.newsmppg.submit();
7182: }
7183: }
7184:
1.534 raeburn 7185: function makewebpage(type) {
1.594 damieng 7186: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7187: var formname;
7188: if (type == 'supp') {
7189: formname = this.document.forms.supwebpage;
7190: } else {
7191: formname = this.document.forms.newwebpage;
7192: }
7193: if (title) {
7194: var webpage = formname.importdetail.value;
7195: formname.importdetail.value = escape(title)+'='+webpage;
7196: formname.submit();
7197: }
7198: }
7199:
1.329 droeschl 7200: function makesmpproblem() {
1.594 damieng 7201: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7202: if (title) {
1.329 droeschl 7203: this.document.forms.newsmpproblem.importdetail.value=
7204: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7205: this.document.forms.newsmpproblem.submit();
7206: }
7207: }
7208:
7209: function makedropbox() {
1.594 damieng 7210: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7211: if (title) {
1.329 droeschl 7212: this.document.forms.newdropbox.importdetail.value=
7213: escape(title)+'=/res/lib/templates/DropBox.problem';
7214: this.document.forms.newdropbox.submit();
7215: }
7216: }
7217:
7218: function makebulboard() {
1.594 damieng 7219: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7220: if (title) {
7221: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7222: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7223: this.document.forms.newbul.submit();
7224: }
7225: }
7226:
7227: function makeabout() {
1.594 damieng 7228: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7229: if (user) {
7230: var comp=new Array();
7231: comp=user.split(':');
7232: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7233: if ((comp[0]) && (comp[1])) {
7234: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7235: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7236: this.document.forms.newaboutsomeone.submit();
7237: } else {
7238: alert("$js_lt{'p_mab_alrt1'}");
7239: }
7240: } else {
7241: alert("$js_lt{'p_mab_alrt2'}");
7242: }
7243: }
7244: }
7245:
7246: function makenew(targetform) {
7247: targetform.submit();
7248: }
7249:
7250: function changename(folderpath,index,oldtitle) {
7251: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7252: if (title) {
7253: this.document.forms.renameform.markcopy.value='';
7254: this.document.forms.renameform.title.value=title;
7255: this.document.forms.renameform.cmd.value='rename_'+index;
7256: this.document.forms.renameform.folderpath.value=folderpath;
7257: this.document.forms.renameform.submit();
7258: }
7259: }
7260:
1.633 raeburn 7261: function setalias(folderpath,index) {
7262: var alias = prompt('$js_lt{"setal"}');
7263: if ((alias != null) && (alias != '')) {
7264: this.document.forms.aliasform.alias.value=alias;
7265: this.document.forms.aliasform.cmd.value='setalias_'+index;
7266: this.document.forms.aliasform.folderpath.value=folderpath;
7267: this.document.forms.aliasform.submit();
7268: }
7269: }
7270:
7271: function delalias(folderpath,index) {
7272: if (confirm('$js_lt{"delal"}')) {
7273: this.document.forms.aliasform.cmd.value='delalias_'+index;
7274: this.document.forms.aliasform.folderpath.value=folderpath;
7275: this.document.forms.aliasform.submit();
7276: }
7277: }
7278:
1.611 raeburn 7279: ENDNEWSCRIPT
7280: } else {
7281: $jsmakefunctions = <<ENDNEWSCRIPT;
7282:
7283: function makenewfolder() {
7284: alert("$js_lt{'edri'}");
7285: }
7286:
7287: function makenewpage() {
7288: alert("$js_lt{'edri'}");
7289: }
7290:
7291: function makeexamupload() {
7292: alert("$js_lt{'edri'}");
7293: }
7294:
7295: function makesmppage() {
7296: alert("$js_lt{'edri'}");
7297: }
7298:
7299: function makewebpage(type) {
7300: alert("$js_lt{'edri'}");
7301: }
7302:
7303: function makesmpproblem() {
7304: alert("$js_lt{'edri'}");
7305: }
7306:
7307: function makedropbox() {
7308: alert("$js_lt{'edri'}");
7309: }
7310:
7311: function makebulboard() {
7312: alert("$js_lt{'edri'}");
7313: }
7314:
7315: function makeabout() {
7316: alert("$js_lt{'edri'}");
7317: }
7318:
7319: function changename() {
7320: alert("$js_lt{'edri'}");
7321: }
7322:
1.633 raeburn 7323: function setalias() {
7324: alert("$js_lt{'edri'}");
7325: }
7326:
7327: function delalias() {
7328: alert("$js_lt{'edri'}");
7329: }
7330:
1.611 raeburn 7331: function makenew() {
7332: alert("$js_lt{'edri'}");
7333: }
7334:
7335: function groupimport() {
7336: alert("$js_lt{'edri'}");
1.335 ehlerst 7337: }
1.611 raeburn 7338:
7339: function groupsearch() {
7340: alert("$js_lt{'edri'}");
1.335 ehlerst 7341: }
1.611 raeburn 7342:
7343: function groupopen(url,recover) {
7344: var options="scrollbars=1,resizable=1,menubar=0";
7345: idxflag=1;
7346: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7347: idx.focus();
1.329 droeschl 7348: }
7349:
1.611 raeburn 7350: ENDNEWSCRIPT
7351:
7352: }
7353: return <<ENDSCRIPT;
7354:
7355: $jsmakefunctions
7356:
1.501 raeburn 7357: function toggleUpload(caller) {
7358: var blocks = Array($fieldsets);
7359: for (var i=0; i<blocks.length; i++) {
7360: var disp = 'none';
7361: if (caller == blocks[i]) {
7362: var curr = document.getElementById('upload'+caller+'form').style.display;
7363: if (curr == 'none') {
7364: disp='block';
7365: }
7366: }
7367: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7368: if ((caller == 'tool') || (caller == 'supptool')) {
7369: if (disp == 'block') {
7370: if (document.getElementById('LC_exttoolid')) {
7371: var toolselector = document.getElementById('LC_exttoolid');
7372: var suppflag = 0;
7373: if (caller == 'supptool') {
7374: suppflag = 1;
7375: }
7376: currForm = document.getElementById('new'+caller);
7377: updateExttool(toolselector,currForm,suppflag);
7378: }
7379: }
7380: }
1.501 raeburn 7381: }
1.502 raeburn 7382: resize_scrollbox('contentscroll','1','1');
7383: return;
7384: }
7385:
1.514 raeburn 7386: function toggleMap(caller) {
1.502 raeburn 7387: var disp = 'none';
1.510 raeburn 7388: if (document.getElementById('importmapform')) {
1.514 raeburn 7389: if (caller == 'map') {
7390: var curr = document.getElementById('importmapform').style.display;
7391: if (curr == 'none') {
7392: disp='block';
7393: }
1.510 raeburn 7394: }
7395: document.getElementById('importmapform').style.display=disp;
7396: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7397: }
1.501 raeburn 7398: return;
1.329 droeschl 7399: }
7400:
1.606 raeburn 7401: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7402: var disp = 'none';
7403: if (document.getElementById('crsresform')) {
7404: if (caller == 'res') {
7405: var curr = document.getElementById('crsresform').style.display;
7406: if (curr == 'none') {
7407: disp='block';
7408: numauthor = parseInt(numauthorrole);
7409: if (numauthor > 0) {
7410: document.courseresform.authorrole.selectedIndex = 0;
7411: select1priv_changed();
7412: document.courseresform.authorpath.selectedIndex = 0;
7413: document.courseresform.newresourceadd.selectedIndex = 0;
7414: toggleNewInCourse(document.courseresform);
7415: if (document.getElementById('newresource')) {
7416: document.getElementById('newresource').style.display = 'none';
7417: }
7418: } else {
7419: if (numcrsdirs) {
7420: document.courseresform.authorpath.selectedIndex = 0;
7421: }
7422: }
7423: if (document.courseresform.newresusetemp.length) {
7424: document.courseresform.newresusetemp[0].checked = true;
7425: toggleWithTemplate(document.courseresform);
7426: }
7427: document.courseresform.newresourcename.value = '';
7428: }
7429: }
7430: if (document.courseresform.newsubdir.length) {
7431: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7432: if (document.courseresform.newsubdir[j].value == 0) {
7433: document.courseresform.newsubdir[j].checked = true;
7434: }
7435: break;
7436: }
7437: if (document.getElementById('newsubdirname')) {
7438: document.getElementById('newsubdirname').type = "hidden";
7439: document.getElementById('newsubdirname').value = "";
7440: }
7441: if (document.getElementById('newsubdir')) {
7442: document.getElementById('newsubdir').innerHTML = "";
7443: }
7444: }
7445: document.getElementById('crsresform').style.display=disp;
7446: resize_scrollbox('contentscroll','1','0');
7447: }
7448: return;
7449: }
7450:
7451: function toggleNewsubdir(form) {
7452: if (form.newsubdir.length) {
7453: for (var j=0; j<form.newsubdir.length; j++) {
7454: if (form.newsubdir[j].checked) {
7455: if (document.getElementById('newsubdirname')) {
7456: if (form.newsubdir[j].value == '1') {
7457: document.getElementById('newsubdirname').type = "text";
7458: if (document.getElementById('newsubdir')) {
7459: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7460: }
7461: } else {
7462: document.getElementById('newsubdirname').type = "hidden";
7463: document.getElementById('newsubdirname').value = "";
7464: document.getElementById('newsubdir').innerHTML = "";
7465: }
7466: }
7467: break;
7468: }
7469: }
7470: }
7471: }
7472:
7473: function toggleCrsResTitle() {
7474: if (document.getElementById('newresource')) {
7475: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7476: document.getElementById('newresource').style.display = 'inline';
7477: document.courseresform.newresourceadd[0].checked = true;
7478: toggleNewInCourse(document.courseresform);
7479: } else {
7480: document.getElementById('newresource').style.display = 'none';
7481: }
7482: }
7483: }
7484:
7485: function toggleNewInCourse(form) {
7486: if (form.newresourceadd.length) {
7487: for (var i=0; i<form.newresourceadd.length; i++) {
7488: if (form.newresourceadd[i].checked) {
7489: if (document.getElementById('newresourcetitle')) {
7490: if (form.newresourceadd[i].value == '1') {
7491: document.getElementById('newresourcetitle').type = 'text';
7492: if (document.getElementById('newrestitle')) {
7493: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7494: }
7495: } else {
7496: document.getElementById('newresourcetitle').type = 'hidden';
7497: document.getElementById('newresourcetitle').value = '';
7498: if (document.getElementById('newrestitle')) {
7499: document.getElementById('newrestitle').innerHTML = '';
7500: }
7501: }
7502: }
7503: break;
7504: }
7505: }
7506: }
7507: }
7508:
7509: function toggleWithTemplate(form) {
7510: if (form.newresusetemp.length) {
7511: for (var i=0; i<form.newresusetemp.length; i++) {
7512: if (form.newresusetemp[i].checked) {
7513: if (document.getElementById('newrestemplate')) {
7514: if (form.newresusetemp[i].value == '1') {
7515: document.getElementById('newrestemplate').style.display = 'inline';
7516: toggleExampleText();
7517: } else {
7518: form.tempcategory.selectedIndex = 0;
7519: select1template_changed();
7520: document.getElementById('newrestemplate').style.display = 'none';
7521: }
7522: }
7523: }
7524: }
7525: }
7526: }
7527:
7528: function toggleExampleText() {
7529: if (document.getElementById('newresexample')) {
7530: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7531: if (url == '') {
7532: document.getElementById('newresexample').style.fontWeight = 'normal';
7533: } else {
7534: document.getElementById('newresexample').style.fontWeight = 'bold';
7535: }
7536: }
7537: }
7538:
7539: function getExample(width,height,scrolling,transparency) {
7540: var url;
7541: if (document.courseresform.newresusetemp.length) {
7542: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7543: if (document.courseresform.newresusetemp[i].checked) {
7544: if (document.courseresform.newresusetemp[i].value == '1') {
7545: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7546: if (url == '') {
7547: alert('Pick a category and template');
7548: } else {
7549: url = url.replace("$londocroot","");
7550: url += '?inhibitmenu=yes';
7551: }
7552: }
7553: break;
7554: }
7555: }
7556: }
7557: if (url != '') {
7558: openMyModal(url,width,height,scrolling,transparency,'');
7559: }
7560: }
7561:
7562: function toggleImportCrsres(caller,dircount) {
7563: var disp = 'none';
7564: if (document.getElementById('importcrsresform')) {
7565: if (caller == 'res') {
7566: var numdirs = parseInt(dircount);
7567: var curr = document.getElementById('importcrsresform').style.display;
7568: if (curr == 'none') {
7569: disp='block';
7570: if (numdirs > 1) {
7571: select1res_changed();
7572: }
7573: }
7574: }
7575: document.getElementById('importcrsresform').style.display=disp;
7576: resize_scrollbox('contentscroll','1','0');
7577: }
7578: return;
7579: }
7580:
1.501 raeburn 7581: function makeims(imsform) {
7582: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7583: alert("$js_lt{'imsfile'}");
1.501 raeburn 7584: return;
7585: }
7586: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7587: alert("$js_lt{'imscms'}");
1.501 raeburn 7588: return;
7589: }
7590: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7591: imsform.submit();
7592: }
7593:
1.478 raeburn 7594: function updatePick(targetform,index,caller) {
1.537 raeburn 7595: var pickitem;
7596: var picknumitem;
7597: var picknumtext;
7598: if (index == 'all') {
7599: pickitem = document.getElementById('randompickall');
7600: picknumitem = document.getElementById('rpicknumall');
7601: picknumtext = document.getElementById('rpicktextall');
7602: } else {
7603: pickitem = document.getElementById('randompick_'+index);
7604: picknumitem = document.getElementById('rpicknum_'+index);
7605: picknumtext = document.getElementById('randompicknum_'+index);
7606: }
1.478 raeburn 7607: if (pickitem.checked) {
1.594 damieng 7608: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7609: if (picknum == '' || picknum == null) {
7610: if (caller == 'check') {
7611: pickitem.checked=false;
1.537 raeburn 7612: if (index == 'all') {
7613: picknumtext.innerHTML = '';
7614: if (caller == 'link') {
7615: propagateState(targetform,'rpicknum');
7616: }
7617: } else {
1.538 raeburn 7618: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7619: }
1.478 raeburn 7620: }
7621: } else {
7622: picknum.toString();
7623: var regexdigit=/^\\d+\$/;
7624: if (regexdigit.test(picknum)) {
7625: picknumitem.value = picknum;
1.537 raeburn 7626: if (index == 'all') {
1.538 raeburn 7627: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7628: if (caller == 'link') {
7629: propagateState(targetform,'rpicknum');
7630: }
7631: } else {
7632: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7633: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7634: }
1.478 raeburn 7635: } else {
7636: if (caller == 'check') {
1.537 raeburn 7637: if (index == 'all') {
7638: picknumtext.innerHTML = '';
7639: if (caller == 'link') {
7640: propagateState(targetform,'rpicknum');
7641: }
7642: } else {
7643: pickitem.checked=false;
1.538 raeburn 7644: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7645: }
1.478 raeburn 7646: }
7647: return;
7648: }
7649: }
7650: } else {
1.537 raeburn 7651: picknumitem.value = '';
7652: picknumtext.innerHTML = '';
7653: if (index == 'all') {
7654: if (caller == 'link') {
7655: propagateState(targetform,'rpicknum');
7656: }
7657: } else {
1.538 raeburn 7658: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7659: }
7660: }
7661: }
7662:
7663: function propagateState(form,param) {
7664: if (document.getElementById(param+'all')) {
7665: var setcheck = 0;
7666: var rpick = 0;
7667: if (param == 'rpicknum') {
7668: if (document.getElementById('randompickall')) {
7669: if (document.getElementById('randompickall').checked) {
7670: if (document.getElementById('rpicknumall')) {
7671: rpick = document.getElementById('rpicknumall').value;
7672: }
7673: }
7674: }
7675: } else {
7676: if (document.getElementById(param+'all').checked) {
7677: setcheck = 1;
7678: }
7679: }
1.538 raeburn 7680: var allidxlist;
7681: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7682: if (document.getElementById('all'+param+'idx')) {
7683: allidxlist = document.getElementById('all'+param+'idx').value;
7684: }
7685: var actions = new Array ('remove','cut','copy');
7686: for (var i=0; i<actions.length; i++) {
7687: if (actions[i] != param) {
7688: if (document.getElementById(actions[i]+'all')) {
7689: document.getElementById(actions[i]+'all').checked = false;
7690: }
7691: }
7692: }
7693: }
1.537 raeburn 7694: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7695: allidxlist = form.allidx.value;
7696: }
7697: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7698: allidxlist = form.allmapidx.value;
7699: }
7700: if ((allidxlist != '') && (allidxlist != null)) {
7701: var allidxs = allidxlist.split(',');
7702: if (allidxs.length > 1) {
7703: for (var i=0; i<allidxs.length; i++) {
7704: if (document.getElementById(param+'_'+allidxs[i])) {
7705: if (param == 'rpicknum') {
7706: if (document.getElementById('randompick_'+allidxs[i])) {
7707: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7708: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7709: if (rpick > 0) {
7710: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7711: } else {
7712: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7713: }
7714: }
7715: }
7716: } else {
1.537 raeburn 7717: if (setcheck == 1) {
7718: document.getElementById(param+'_'+allidxs[i]).checked = true;
7719: } else {
7720: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7721: if (param == 'randompick') {
7722: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7723: }
1.537 raeburn 7724: }
7725: }
7726: }
7727: }
1.538 raeburn 7728: if (setcheck == 1) {
7729: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7730: var actions = new Array('copy','cut','remove');
7731: for (var i=0; i<actions.length; i++) {
7732: var otheractions;
7733: var otheridxs;
7734: if (actions[i] === param) {
7735: continue;
7736: } else {
7737: if (document.getElementById('all'+actions[i]+'idx')) {
7738: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7739: otheridxs = otheractions.split(',');
7740: if (otheridxs.length > 1) {
7741: for (var j=0; j<otheridxs.length; j++) {
7742: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7743: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7744: }
1.537 raeburn 7745: }
7746: }
7747: }
1.538 raeburn 7748: }
7749: }
7750: }
7751: }
7752: }
7753: }
7754: }
7755: return;
7756: }
7757:
1.603 raeburn 7758: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7759: var canedit = '$canedit';
7760: if (canedit == '') {
7761: alert("$js_lt{'edri'}");
7762: return;
7763: }
1.539 raeburn 7764: var dosettings;
7765: var doaction;
1.538 raeburn 7766: var control = document.togglemultsettings;
7767: if (context == 'actions') {
7768: control = document.togglemultactions;
1.539 raeburn 7769: doaction = 1;
7770: } else {
7771: dosettings = 1;
1.538 raeburn 7772: }
1.539 raeburn 7773: if (control) {
7774: if (control.showmultpick.length) {
7775: for (var i=0; i<control.showmultpick.length; i++) {
7776: if (control.showmultpick[i].checked) {
7777: if (control.showmultpick[i].value == 1) {
7778: if (context == 'settings') {
7779: dosettings = 0;
7780: } else {
7781: doaction = 0;
1.538 raeburn 7782: }
7783: }
7784: }
1.537 raeburn 7785: }
7786: }
1.539 raeburn 7787: }
7788: if (context == 'settings') {
7789: if (dosettings == 1) {
1.538 raeburn 7790: targetform.changeparms.value=param;
7791: targetform.submit();
7792: }
1.537 raeburn 7793: }
1.539 raeburn 7794: if (context == 'actions') {
7795: if (doaction == 1) {
7796: targetform.cmd.value=param+'_'+index;
7797: targetform.folderpath.value=folderpath;
7798: targetform.markcopy.value=idx+':'+param;
7799: targetform.copyfolder.value=folder+'.'+container;
7800: if (param == 'remove') {
1.603 raeburn 7801: var doremove = 0;
7802: if (skip_confirm) {
7803: if (confirm_removal) {
7804: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7805: doremove = 1;
7806: }
7807: } else {
7808: doremove = 1;
7809: }
7810: } else {
7811: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7812: doremove = 1;
7813: }
7814: }
7815: if (doremove) {
1.539 raeburn 7816: targetform.markcopy.value='';
7817: targetform.copyfolder.value='';
7818: targetform.submit();
7819: }
7820: }
7821: if (param == 'cut') {
1.594 damieng 7822: 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 7823: targetform.submit();
7824: return;
7825: }
7826: }
7827: if (param == 'copy') {
7828: targetform.submit();
7829: return;
7830: }
7831: targetform.markcopy.value='';
7832: targetform.copyfolder.value='';
7833: targetform.cmd.value='';
7834: targetform.folderpath.value='';
7835: return;
7836: } else {
7837: if (document.getElementById(param+'_'+idx)) {
7838: item = document.getElementById(param+'_'+idx);
7839: if (item.type == 'checkbox') {
7840: if (item.checked) {
7841: item.checked = false;
7842: } else {
7843: item.checked = true;
7844: singleCheck(item,idx,param);
7845: }
7846: }
7847: }
7848: }
7849: }
1.537 raeburn 7850: return;
7851: }
7852:
1.538 raeburn 7853: function singleCheck(caller,idx,action) {
7854: actions = new Array('cut','copy','remove');
7855: if (caller.checked) {
7856: for (var i=0; i<actions.length; i++) {
7857: if (actions[i] != action) {
7858: if (document.getElementById(actions[i]+'_'+idx)) {
7859: if (document.getElementById(actions[i]+'_'+idx).checked) {
7860: document.getElementById(actions[i]+'_'+idx).checked = false;
7861: }
1.537 raeburn 7862: }
7863: }
7864: }
1.478 raeburn 7865: }
1.537 raeburn 7866: return;
1.478 raeburn 7867: }
7868:
1.334 muellerd 7869: function unselectInactive(nav) {
1.335 ehlerst 7870: currentNav = document.getElementById(nav);
7871: currentLis = currentNav.getElementsByTagName('LI');
7872: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7873: if (currentLis[i].className == 'goback') {
7874: currentLis[i].className = 'goback';
7875: } else {
7876: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7877: currentLis[i].className = 'right';
1.472 raeburn 7878: } else {
1.374 tempelho 7879: currentLis[i].className = 'i';
1.472 raeburn 7880: }
7881: }
1.335 ehlerst 7882: }
1.332 tempelho 7883: }
7884:
1.334 muellerd 7885: function hideAll(current, nav, data) {
1.335 ehlerst 7886: unselectInactive(nav);
1.570 raeburn 7887: if (current) {
7888: if (current.className == 'right'){
7889: current.className = 'right active'
7890: } else {
7891: current.className = 'active';
7892: }
1.374 tempelho 7893: }
1.335 ehlerst 7894: currentData = document.getElementById(data);
7895: currentDivs = currentData.getElementsByTagName('DIV');
7896: for (i = 0; i < currentDivs.length; i++) {
7897: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7898: currentDivs[i].style.display = 'none';
1.330 tempelho 7899: }
7900: }
1.335 ehlerst 7901: }
1.330 tempelho 7902:
1.374 tempelho 7903: function openTabs(pageId) {
7904: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7905: if(tabnav.length > 2 ){
1.389 tempelho 7906: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7907: currentLis = currentNav.getElementsByTagName('LI');
7908: for(i = 0; i< currentLis.length; i++){
7909: if(currentLis[i].className == 'active') {
1.375 tempelho 7910: funcString = currentLis[i].onclick.toString();
7911: tab = funcString.split('"');
1.420 onken 7912: if(tab.length < 2) {
7913: tab = funcString.split("'");
7914: }
1.375 tempelho 7915: currentData = document.getElementById(tab[1]);
7916: currentData.style.display = 'block';
1.374 tempelho 7917: }
7918: }
7919: }
7920: }
7921:
1.334 muellerd 7922: function showPage(current, pageId, nav, data) {
1.570 raeburn 7923: currstate = current.className;
1.334 muellerd 7924: hideAll(current, nav, data);
1.375 tempelho 7925: openTabs(pageId);
1.334 muellerd 7926: unselectInactive(nav);
1.570 raeburn 7927: if ((currstate == 'active') || (currstate == 'right active')) {
7928: if (currstate == 'active') {
7929: current.className = '';
7930: } else {
7931: current.className = 'right';
7932: }
7933: activeTab = '';
7934: toggleUpload();
7935: toggleMap();
1.606 raeburn 7936: toggleCrsRes();
7937: toggleImportCrsres();
1.570 raeburn 7938: resize_scrollbox('contentscroll','1','0');
7939: return;
7940: } else {
7941: current.className = 'active';
7942: }
1.330 tempelho 7943: currentData = document.getElementById(pageId);
7944: currentData.style.display = 'block';
1.458 raeburn 7945: activeTab = pageId;
1.501 raeburn 7946: toggleUpload();
1.503 raeburn 7947: toggleMap();
1.606 raeburn 7948: toggleCrsRes();
7949: toggleImportCrsres();
1.433 raeburn 7950: if (nav == 'mainnav') {
7951: var storedpath = "$docs_folderpath";
1.434 raeburn 7952: var storedpage = "$main_container_page";
1.433 raeburn 7953: var reg = new RegExp("^supplemental");
7954: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7955: if (storedpage == 1) {
7956: document.simpleedit.folderpath.value = '';
7957: document.uploaddocument.folderpath.value = '';
7958: } else {
7959: if (reg.test(storedpath)) {
7960: document.simpleedit.folderpath.value = '$toplevelmain';
7961: document.uploaddocument.folderpath.value = '$toplevelmain';
7962: document.newext.folderpath.value = '$toplevelmain';
7963: } else {
7964: document.simpleedit.folderpath.value = storedpath;
7965: document.uploaddocument.folderpath.value = storedpath;
7966: document.newext.folderpath.value = storedpath;
7967: }
1.433 raeburn 7968: }
7969: } else {
1.434 raeburn 7970: if (reg.test(storedpath)) {
7971: document.simpleedit.folderpath.value = storedpath;
7972: document.supuploaddocument.folderpath.value = storedpath;
7973: document.supnewext.folderpath.value = storedpath;
7974: } else {
1.433 raeburn 7975: document.simpleedit.folderpath.value = '$toplevelsupp';
7976: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7977: document.supnewext.folderpath.value = '$toplevelsupp';
7978: }
7979: }
7980: }
1.485 raeburn 7981: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7982: return false;
7983: }
1.329 droeschl 7984:
1.472 raeburn 7985: function toContents(jumpto) {
7986: var newurl = '$backtourl';
1.525 raeburn 7987: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7988: newurl = newurl+'?postdata='+jumpto;
7989: }
7990: location.href=newurl;
7991: }
7992:
1.538 raeburn 7993: function togglePick(caller,value) {
7994: var disp = 'none';
7995: if (document.getElementById('multi'+caller)) {
7996: var curr = document.getElementById('multi'+caller).style.display;
7997: if (value == 1) {
7998: disp='block';
7999: }
8000: if (curr == disp) {
8001: return;
8002: }
8003: document.getElementById('multi'+caller).style.display=disp;
8004: if (value == 1) {
1.594 damieng 8005: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8006: } else {
8007: document.getElementById('more'+caller).innerHTML = '';
8008: }
8009: if (caller == 'actions') {
8010: setClass(value);
8011: setBoxes(value);
8012: }
8013: }
8014: var showButton = multiSettings();
8015: if (showButton != 1) {
8016: showButton = multiActions();
8017: }
8018: if (document.getElementById('multisave')) {
8019: if (showButton == 1) {
8020: document.getElementById('multisave').style.display='block';
8021: } else {
8022: document.getElementById('multisave').style.display='none';
8023: }
8024: }
8025: resize_scrollbox('contentscroll','1','1');
8026: return;
8027: }
8028:
8029: function toggleCheckUncheck(caller,more) {
8030: if (more == 1) {
1.594 damieng 8031: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8032: document.getElementById('allfields'+caller).style.display='block';
8033: } else {
1.594 damieng 8034: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8035: document.getElementById('allfields'+caller).style.display='none';
8036: }
8037: resize_scrollbox('contentscroll','1','1');
8038: }
8039:
8040: function multiSettings() {
8041: var inuse = 0;
8042: var settingsform = document.togglemultsettings;
8043: if (settingsform.showmultpick.length > 1) {
8044: for (var i=0; i<settingsform.showmultpick.length; i++) {
8045: if (settingsform.showmultpick[i].checked) {
8046: if (settingsform.showmultpick[i].value == 1) {
8047: inuse = 1;
8048: }
8049: }
8050: }
8051: }
8052: return inuse;
8053: }
8054:
8055: function multiActions() {
8056: var inuse = 0;
8057: var actionsform = document.togglemultactions;
8058: if (actionsform.showmultpick.length > 1) {
8059: for (var i=0; i<actionsform.showmultpick.length; i++) {
8060: if (actionsform.showmultpick[i].checked) {
8061: if (actionsform.showmultpick[i].value == 1) {
8062: inuse = 1;
8063: }
8064: }
8065: }
8066: }
8067: return inuse;
8068: }
8069:
8070: function checkSubmits() {
8071: var numchanges = 0;
8072: var form = document.saveactions;
8073: var doactions = multiActions();
1.542 raeburn 8074: var cutwarnings = 0;
8075: var remwarnings = 0;
1.603 raeburn 8076: var removalinfo = 0;
1.538 raeburn 8077: if (doactions == 1) {
8078: var remidxlist = document.cumulativeactions.allremoveidx.value;
8079: if ((remidxlist != '') && (remidxlist != null)) {
8080: var remidxs = remidxlist.split(',');
8081: for (var i=0; i<remidxs.length; i++) {
8082: if (document.getElementById('remove_'+remidxs[i])) {
8083: if (document.getElementById('remove_'+remidxs[i]).checked) {
8084: form.multiremove.value += remidxs[i]+',';
8085: numchanges ++;
1.542 raeburn 8086: if (document.getElementById('skip_remove_'+remidxs[i])) {
8087: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8088: remwarnings ++;
8089: }
8090: }
1.603 raeburn 8091: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8092: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8093: removalinfo ++;
8094: }
8095: }
1.537 raeburn 8096: }
8097: }
1.538 raeburn 8098: }
8099: }
8100: var cutidxlist = document.cumulativeactions.allcutidx.value;
8101: if ((cutidxlist != '') && (cutidxlist != null)) {
8102: var cutidxs = cutidxlist.split(',');
8103: for (var i=0; i<cutidxs.length; i++) {
8104: if (document.getElementById('cut_'+cutidxs[i])) {
8105: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8106: form.multicut.value += cutidxs[i]+',';
8107: numchanges ++;
1.542 raeburn 8108: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8109: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8110: cutwarnings ++;
8111: }
8112: }
1.537 raeburn 8113: }
8114: }
8115: }
8116: }
1.538 raeburn 8117: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8118: if ((copyidxlist != '') && (copyidxlist != null)) {
8119: var copyidxs = copyidxlist.split(',');
8120: for (var i=0; i<copyidxs.length; i++) {
8121: if (document.getElementById('copy_'+copyidxs[i])) {
8122: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8123: form.multicopy.value += copyidxs[i]+',';
8124: numchanges ++;
8125: }
8126: }
8127: }
8128: }
8129: if (numchanges > 0) {
8130: form.multichange.value = numchanges;
8131: }
1.537 raeburn 8132: }
1.538 raeburn 8133: var dosettings = multiSettings();
1.543 raeburn 8134: var haschanges = 0;
1.538 raeburn 8135: if (dosettings == 1) {
8136: form.allencrypturl.value = '';
8137: form.allhiddenresource.value = '';
1.543 raeburn 8138: form.changeparms.value = 'all';
8139: var patt=new RegExp(",\$");
1.538 raeburn 8140: var allidxlist = document.cumulativesettings.allidx.value;
8141: if ((allidxlist != '') && (allidxlist != null)) {
8142: var allidxs = allidxlist.split(',');
8143: if (allidxs.length > 1) {
8144: for (var i=0; i<allidxs.length; i++) {
8145: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8146: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8147: form.allhiddenresource.value += allidxs[i]+',';
8148: }
8149: }
8150: if (document.getElementById('encrypturl_'+allidxs[i])) {
8151: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8152: form.allencrypturl.value += allidxs[i]+',';
8153: }
8154: }
8155: }
1.543 raeburn 8156: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8157: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8158: }
1.538 raeburn 8159: }
8160: form.allrandompick.value = '';
8161: form.allrandomorder.value = '';
8162: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8163: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8164: var allmapidxs = allmapidxlist.split(',');
8165: for (var i=0; i<allmapidxs.length; i++) {
8166: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8167: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8168: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8169: if ((randompick.checked) && (rpicknum.value != '')) {
8170: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8171: }
8172: if (randorder.checked) {
8173: form.allrandomorder.value += allmapidxs[i]+',';
8174: }
1.537 raeburn 8175: }
1.543 raeburn 8176: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8177: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8178: }
8179: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8180: haschanges = 1;
8181: }
8182: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8183: haschanges = 1;
8184: }
8185: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8186: haschanges = 1;
8187: }
8188: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8189: haschanges = 1;
1.537 raeburn 8190: }
8191: }
1.543 raeburn 8192: if (doactions == 1) {
1.542 raeburn 8193: if (numchanges > 0) {
1.603 raeburn 8194: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8195: if (remwarnings > 0) {
1.594 damieng 8196: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8197: return false;
8198: }
8199: }
1.603 raeburn 8200: if (removalinfo > 0) {
8201: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8202: return false;
8203: }
8204: }
1.542 raeburn 8205: if (cutwarnings > 0) {
1.594 damieng 8206: 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 8207: return false;
8208: }
8209: }
8210: }
8211: form.submit();
8212: return true;
1.543 raeburn 8213: }
8214: }
8215: if (dosettings == 1) {
8216: if (haschanges == 1) {
1.542 raeburn 8217: form.submit();
8218: return true;
8219: }
1.543 raeburn 8220: }
8221: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8222: alert("$js_lt{'noor'}");
1.543 raeburn 8223: } else {
8224: if (dosettings == 1) {
1.594 damieng 8225: alert("$js_lt{'noch'}");
1.543 raeburn 8226: } else {
1.594 damieng 8227: alert("$js_lt{'noac'}");
1.543 raeburn 8228: }
8229: }
1.538 raeburn 8230: return false;
8231: }
8232:
8233: function setClass(value) {
8234: var cutclass = 'LC_docs_cut';
8235: var copyclass = 'LC_docs_copy';
8236: var removeclass = 'LC_docs_remove';
8237: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8238: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8239: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8240: var links = document.getElementsByTagName('a');
8241: for (var i=0; i<links.length; i++) {
8242: var classes = links[i].className;
8243: if (cutreg.test(classes)) {
8244: links[i].className = cutclass;
8245: if (value == 1) {
8246: links[i].className += " LC_menubuttons_link";
8247: }
8248: } else {
8249: if (copyreg.test(classes)) {
8250: links[i].className = copyclass;
8251: if (value == 1) {
8252: links[i].className += " LC_menubuttons_link";
8253: }
8254: } else {
8255: if (removereg.test(classes)) {
8256: links[i].className = removeclass;
8257: if (value == 1) {
8258: links[i].className += " LC_menubuttons_link";
8259: }
8260: }
8261: }
8262: }
8263: }
8264: return;
1.537 raeburn 8265: }
8266:
1.538 raeburn 8267: function setBoxes(value) {
8268: var remidxlist = document.cumulativeactions.allremoveidx.value;
8269: if ((remidxlist != '') && (remidxlist != null)) {
8270: var remidxs = remidxlist.split(',');
8271: for (var i=0; i<remidxs.length; i++) {
8272: if (document.getElementById('remove_'+remidxs[i])) {
8273: var item = document.getElementById('remove_'+remidxs[i]);
8274: if (value == 1) {
8275: item.className = 'LC_docs_remove';
8276: } else {
8277: item.className = 'LC_hidden';
8278: }
8279: }
8280: }
8281: }
8282: var cutidxlist = document.cumulativeactions.allcutidx.value;
8283: if ((cutidxlist != '') && (cutidxlist != null)) {
8284: var cutidxs = cutidxlist.split(',');
8285: for (var i=0; i<cutidxs.length; i++) {
8286: if (document.getElementById('cut_'+cutidxs[i])) {
8287: var item = document.getElementById('cut_'+cutidxs[i]);
8288: if (value == 1) {
8289: item.className = 'LC_docs_cut';
8290: } else {
8291: item.className = 'LC_hidden';
8292: }
8293: }
1.537 raeburn 8294: }
8295: }
1.538 raeburn 8296: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8297: if ((copyidxlist != '') && (copyidxlist != null)) {
8298: var copyidxs = copyidxlist.split(',');
8299: for (var i=0; i<copyidxs.length; i++) {
8300: if (document.getElementById('copy_'+copyidxs[i])) {
8301: var item = document.getElementById('copy_'+copyidxs[i]);
8302: if (value == 1) {
8303: item.className = 'LC_docs_copy';
8304: } else {
8305: item.className = 'LC_hidden';
8306: }
8307: }
1.537 raeburn 8308: }
8309: }
8310: return;
8311: }
8312:
1.606 raeburn 8313: function validImportCrsRes() {
8314: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8315: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8316: if ((fname == '') || (fname == null)) {
8317: alert("$js_lt{'nofi'}");
8318: return false;
8319: }
8320: var url = '/res/$coursedom/$coursenum/';
8321: if (path && path != '/') {
8322: url += path+'/';
8323: }
8324: if (fname != '') {
8325: url += fname;
8326: }
8327: var title = document.crsresimportform.crsrestitle.value;
8328: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8329: return true;
8330: }
8331:
8332: function validateNewRes(caller) {
8333: if (caller == 'single') {
8334: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8335: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8336: var resname = document.courseresform.newresourcename.value;
8337: }
8338: }
8339:
1.611 raeburn 8340: ENDSCRIPT
1.329 droeschl 8341: }
1.457 raeburn 8342:
1.483 raeburn 8343: sub history_tab_js {
8344: return <<"ENDHIST";
8345: function toggleHistoryDisp(choice) {
8346: document.docslogform.docslog.value = choice;
8347: document.docslogform.submit();
8348: return;
8349: }
8350:
8351: ENDHIST
8352: }
8353:
1.484 raeburn 8354: sub inject_data_js {
8355: return <<ENDINJECT;
8356:
8357: function injectData(current, hiddenField, name, value) {
8358: currentElement = document.getElementById(hiddenField);
8359: currentElement.name = name;
8360: currentElement.value = value;
8361: current.submit();
8362: }
8363:
8364: ENDINJECT
8365: }
8366:
8367: sub dump_switchserver_js {
8368: my @hosts = @_;
1.594 damieng 8369: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8370: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8371: swit => 'Switch server?',
1.594 damieng 8372: );
8373: my %html_js_lt = &Apache::lonlocal::texthash(
8374: swit => 'Switch server?',
1.568 raeburn 8375: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8376: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8377: chos => 'Choose server',
8378: );
1.594 damieng 8379: &js_escape(\%js_lt);
8380: &html_escape(\%html_js_lt);
8381: &js_escape(\%html_js_lt);
1.484 raeburn 8382: my $role = $env{'request.role'};
8383: my $js = <<"ENDSWJS";
8384: <script type="text/javascript">
8385: function write_switchserver() {
8386: var server;
8387: if (document.setserver.posshosts.length > 0) {
8388: for (var i=0; i<document.setserver.posshosts.length; i++) {
8389: if (document.setserver.posshosts[i].checked) {
8390: server = document.setserver.posshosts[i].value;
8391: }
8392: }
8393: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8394: }
8395: window.close();
8396: }
8397: </script>
8398:
8399: ENDSWJS
8400:
8401: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8402: {'only_body' => 1,
8403: 'js_ready' => 1,});
8404: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8405:
8406: my $hostpicker;
8407: my $count = 0;
8408: foreach my $host (sort(@hosts)) {
8409: my $checked;
8410: if ($count == 0) {
8411: $checked = ' checked="checked"';
8412: }
8413: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8414: $host.'"'.$checked.' />'.$host.'</label> ';
8415: $count++;
8416: }
8417:
8418: return <<"ENDSWITCHJS";
8419:
8420: function dump_needs_switchserver(url) {
8421: if (url!='' && url!= null) {
1.594 damieng 8422: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8423: go(url);
8424: }
8425: }
8426: return;
8427: }
8428:
8429: function choose_switchserver_window() {
8430: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8431: newWindow.document.open();
8432: newWindow.document.writeln('$startpage');
1.594 damieng 8433: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8434: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8435: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8436: '<form name="setserver" method="post" action="" \\/>\\n'+
8437: '$hostpicker\\n'+
8438: '<br \\/><br \\/>\\n'+
1.594 damieng 8439: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8440: 'onclick="write_switchserver();" \\/>\\n'+
8441: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8442: newWindow.document.writeln('$endpage');
8443: newWindow.document.close();
8444: newWindow.focus();
8445: }
8446:
8447: ENDSWITCHJS
8448: }
8449:
8450: sub makedocslogform {
8451: my ($formelems,$docslog) = @_;
8452: return <<"LOGSFORM";
8453: <form action="/adm/coursedocs" method="post" name="docslogform">
8454: <input type="hidden" name="docslog" value="$docslog" />
8455: $formelems
8456: </form>
8457: LOGSFORM
8458: }
8459:
8460: sub makesimpleeditform {
8461: my ($formelems) = @_;
8462: return <<"SIMPFORM";
8463: <form name="simpleedit" method="post" action="/adm/coursedocs">
8464: <input type="hidden" name="importdetail" value="" />
8465: $formelems
8466: </form>
8467: SIMPFORM
8468: }
8469:
1.606 raeburn 8470: sub makenewproblem {
8471: my ($r,$coursedom,$coursenum) = @_;
8472: # Creating a new problem
8473: my ($redirect,$error);
8474: if ($env{'form.authorrole'}) {
8475: my ($newsubdir,$filename);
8476: if ($env{'form.newsubdir'}) {
8477: if ($env{'form.newsubdirname'} ne '') {
8478: $newsubdir = $env{'form.newsubdirname'};
8479: }
8480: }
8481: if ($env{'form.newresourcename'}) {
8482: $filename = $env{'form.newresourcename'};
8483: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8484: $filename =~ s/`//g;
8485: $filename =~ s{/\.\./}{_}g;
8486: $filename =~ s/\.+/./g;
8487: $filename =~ s{/+}{_}g;
8488: if ($filename ne '') {
8489: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8490: if (($ext) && ($ext ne '.problem')) {
8491: $filename = $name.'.problem';
8492: } elsif ($ext eq '') {
8493: $filename .= '.problem';
8494: }
8495: my $docroot = $r->dir_config('lonDocRoot');
8496: my @ids=&Apache::lonnet::current_machine_ids();
8497: if ($env{'form.authorrole'} eq 'author') {
8498: if ($env{'user.author'}) {
8499: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8500: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8501: my $path = $docroot.$url;
8502: my $subdir = $env{'form.authorpath'};
8503: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8504: }
8505: }
8506: } elsif ($env{'form.authorrole'} eq 'course') {
8507: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8508: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8509: my $url = "/priv/$coursedom/$coursenum";
8510: my $path=$docroot.$url;
8511: my $subdir = $env{'form.authorpath'};
8512: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8513: if ($redirect) {
8514: my $rightsfile = 'default.rights';
8515: my $sourcerights = "$path/$rightsfile";
8516: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8517: my $now = time;
8518: if (!-e $sourcerights) {
8519: my $cid = $coursedom.'_'.$coursenum;
8520: if (open(my $fh,">$sourcerights")) {
8521: print $fh <<END;
8522: <accessrule effect="deny" realm="" type="course" role="" />
8523: <accessrule effect="allow" realm="$cid" type="course" role="" />
8524: END
8525: close($fh);
8526: }
8527: }
8528: if (!-e "$sourcerights.meta") {
8529: if (open(my $fh,">$sourcerights.meta")) {
8530: my $author=$env{'environment.firstname'}.' '.
8531: $env{'environment.middlename'}.' '.
8532: $env{'environment.lastname'}.' '.
8533: $env{'environment.generation'};
8534: $author =~ s/\s+$//;
8535: print $fh <<"END";
8536:
8537: <abstract></abstract>
8538: <author>$author</author>
8539: <authorspace>$coursenum:$coursedom</authorspace>
8540: <copyright>private</copyright>
8541: <creationdate>$now</creationdate>
8542: <customdistributionfile></customdistributionfile>
8543: <dependencies></dependencies>
8544: <domain>$coursedom</domain>
8545: <highestgradelevel>0</highestgradelevel>
8546: <keywords></keywords>
8547: <language>notset </language>
8548: <lastrevisiondate>$now</lastrevisiondate>
8549: <lowestgradelevel>0</lowestgradelevel>
8550: <mime>rights</mime>
8551: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8552: <notes></notes>
8553: <obsolete></obsolete>
8554: <obsoletereplacement></obsoletereplacement>
8555: <owner>$coursenum:$coursedom</owner>
8556: <rule>deny:::course,allow:$cid::course</rule>
8557: <sourceavail></sourceavail>
8558: <standards></standards>
8559: <subject></subject>
8560: <title></title>
8561: END
8562: close($fh);
8563: }
8564: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8565: if (!-e "$docroot/res/$coursedom") {
8566: mkdir("$docroot/res/$coursedom",0755);
8567: }
8568: if (!-e "$docroot/res/$coursedom/$coursenum") {
8569: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8570: }
8571: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8572: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8573: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8574: }
8575: }
8576: }
8577: if ($env{'form.newresourceadd'}) {
8578: my $template = $env{'form.template'};
8579: my $source = $docroot.$redirect;
8580: my $target = $redirect;
8581: $target =~ s{^/priv/}{/res/};
8582: $target = $docroot.$target;
8583: if (!-e $source) {
8584: my $copyfrom;
8585: if ($template) {
8586: my %templates;
8587: my @files = &Apache::lonhomework::get_template_list('problem');
8588: foreach my $poss (@files) {
8589: if (ref($poss) eq 'ARRAY') {
8590: if ($template eq $poss->[0]) {
8591: $templates{$template} = 1;
8592: last;
8593: }
8594: }
8595: }
8596: if ($templates{$template}) {
8597: $copyfrom = $template;
8598: }
8599: }
8600: unless ($copyfrom) {
8601: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8602: }
8603: &File::Copy::copy($copyfrom,$source);
8604: }
8605: if (!-e "$source.meta") {
8606: my $cid = $coursedom.'_'.$coursenum;
8607: my $now = time;
8608: if (open(my $fh,">$source.meta")) {
8609: my $author=$env{'environment.firstname'}.' '.
8610: $env{'environment.middlename'}.' '.
8611: $env{'environment.lastname'}.' '.
8612: $env{'environment.generation'};
8613: $author =~ s/\s+$//;
8614: my $title = $env{'form.newresourcetitle'};
8615: $title =~ s/^\s+|\s+$//g;
8616: print $fh <<END;
8617:
8618: <abstract></abstract>
8619: <author>$author</author>
8620: <authorspace>$coursenum:$coursedom</authorspace>
8621: <copyright>custom</copyright>
8622: <creationdate>$now</creationdate>
8623: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8624: <dependencies></dependencies>
8625: <domain>$coursedom</domain>
8626: <highestgradelevel>0</highestgradelevel>
8627: <keywords></keywords>
8628: <language>notset </language>
8629: <lastrevisiondate>$now</lastrevisiondate>
8630: <lowestgradelevel>0</lowestgradelevel>
8631: <mime>problem</mime>
8632: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8633: <notes></notes>
8634: <obsolete></obsolete>
8635: <obsoletereplacement></obsoletereplacement>
8636: <owner>$coursenum:$coursedom</owner>
8637: <sourceavail></sourceavail>
8638: <standards></standards>
8639: <subject></subject>
8640: <title>$title</title>
8641: END
8642: close($fh);
8643: }
8644: }
8645: }
8646: }
8647: }
8648: } else {
8649: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8650: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8651: if (grep(/^\Q$rolehome\E$/,@ids)) {
8652: my $now = time;
8653: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8654: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8655: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8656: my $url = "/priv/$audom/$auname";
8657: my $path = $r->dir_config('lonDocRoot').$url;
8658: my $subdir = $env{'form.authorpath'};
8659: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8660: }
8661: }
8662: }
8663: }
8664: }
8665: }
8666: }
8667: return ($redirect,$error);
8668: }
8669:
8670: sub finishnewprob {
8671: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8672: unless (-d $path) {
8673: unless (mkdir($path,02770)) {
8674: return;
8675: }
8676: }
1.606 raeburn 8677: my $redirect;
8678: if ($subdir ne '/') {
8679: $subdir = &cleandir($subdir);
8680: if (($subdir ne '') && (-d "$path/$subdir")) {
8681: $path .= "/$subdir";
8682: $url .= "/$subdir";
8683: }
8684: }
8685: my $dest;
8686: if ($newsubdir ne '') {
8687: $newsubdir = &cleandir($newsubdir);
8688: }
8689: if ($newsubdir ne '') {
8690: if (-d "$path/$newsubdir") {
8691: $dest = "$path/$newsubdir/$filename";
8692: } else {
8693: my $dirok;
8694: unless (-e "$path/$newsubdir") {
8695: if (mkdir("$path/$newsubdir",02770)) {
8696: if (chmod(02770,"$path/$newsubdir")) {
8697: $dirok = 1;
8698: }
8699: }
8700: }
8701: if ($dirok) {
8702: $dest = "$path/$newsubdir/$filename";
8703: }
8704: }
8705: if (($dest ne '') && (!-e $dest)) {
8706: $redirect = "$url/$newsubdir/$filename";
8707: }
8708: } else {
8709: $dest = "$path/$filename";
8710: if (($dest ne '') && (!-e $dest)) {
8711: $redirect = "$url/$filename";
8712: }
8713: }
8714: return $redirect;
8715: }
8716:
8717: sub cleandir {
8718: my ($dir) = @_;
8719: $dir =~ s/^\s+//;
8720: $dir =~ s/\s+$//;
8721: $dir =~ s/\.+//g;
8722: $dir =~ s/[\#\?&%\":]//g;
8723: return $dir;
8724: }
8725:
1.329 droeschl 8726: 1;
8727: __END__
8728:
8729:
8730: =head1 NAME
8731:
8732: Apache::londocs.pm
8733:
8734: =head1 SYNOPSIS
8735:
8736: This is part of the LearningOnline Network with CAPA project
8737: described at http://www.lon-capa.org.
8738:
8739: =head1 SUBROUTINES
8740:
8741: =over
8742:
8743: =item %help=()
8744:
8745: Available help topics
8746:
8747: =item mapread()
8748:
1.344 bisitz 8749: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8750: @order and @resources, determines status
8751: sets @order - pointer to resources in right order
8752: sets @resources - array with the resources with correct idx
8753:
8754: =item authorhosts()
8755:
8756: Return hash with valid author names
8757:
8758: =item clean()
8759:
8760: =item dumpcourse()
8761:
8762: Actually dump course
8763:
8764: =item group_import()
8765:
8766: Imports the given (name, url) resources into the course
8767: coursenum, coursedom, and folder must precede the list
8768:
8769: =item breadcrumbs()
8770:
8771: =item log_docs()
8772:
8773: =item docs_change_log()
8774:
8775: =item update_paste_buffer()
8776:
8777: =item print_paste_buffer()
8778:
8779: =item do_paste_from_buffer()
8780:
1.538 raeburn 8781: =item do_buffer_empty()
8782:
8783: =item clear_from_buffer()
8784:
1.492 raeburn 8785: =item get_newmap_url()
8786:
8787: =item dbcopy()
8788:
8789: =item uniqueness_check()
8790:
8791: =item contained_map_check()
8792:
8793: =item url_paste_fixups()
8794:
8795: =item apply_fixups()
8796:
8797: =item copy_dependencies()
8798:
1.329 droeschl 8799: =item update_parameter()
8800:
8801: =item handle_edit_cmd()
8802:
8803: =item editor()
8804:
8805: =item process_file_upload()
8806:
8807: =item process_secondary_uploads()
8808:
8809: =item is_supplemental_title()
8810:
8811: =item entryline()
8812:
8813: =item tiehash()
8814:
8815: =item untiehash()
8816:
8817: =item checkonthis()
8818:
8819: check on this
8820:
8821: =item verifycontent()
8822:
8823: Verify Content
8824:
1.636 raeburn 8825: =item devalidateversioncache()
8826:
8827: =item checkversions()
1.329 droeschl 8828:
8829: Check Versions
8830:
8831: =item mark_hash_old()
8832:
8833: =item is_hash_old()
8834:
8835: =item changewarning()
8836:
8837: =item init_breadcrumbs()
8838:
8839: Breadcrumbs for special functions
8840:
1.484 raeburn 8841: =item create_list_elements()
8842:
8843: =item create_form_ul()
8844:
8845: =item startContentScreen()
8846:
8847: =item endContentScreen()
8848:
8849: =item supplemental_base()
8850:
8851: =item embedded_form_elems()
8852:
8853: =item embedded_destination()
8854:
8855: =item return_to_editor()
8856:
8857: =item decompression_info()
8858:
8859: =item decompression_phase_one()
8860:
8861: =item decompression_phase_two()
8862:
8863: =item remove_archive()
8864:
8865: =item generate_admin_menu()
8866:
8867: =item generate_edit_table()
8868:
8869: =item editing_js()
8870:
8871: =item history_tab_js()
8872:
8873: =item inject_data_js()
8874:
8875: =item dump_switchserver_js()
8876:
1.485 raeburn 8877: =item resize_scrollbox_js()
1.484 raeburn 8878:
8879: =item makedocslogform()
8880:
1.485 raeburn 8881: =item makesimpleeditform()
8882:
1.329 droeschl 8883: =back
8884:
8885: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>