Annotation of loncom/interface/londocs.pm, revision 1.620
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.620 ! raeburn 4: # $Id: londocs.pm,v 1.619 2017/01/24 15:52:58 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.329 droeschl 48: use HTML::Entities;
1.488 raeburn 49: use HTML::TokeParser;
1.329 droeschl 50: use GDBM_File;
1.578 raeburn 51: use File::MMagic;
1.606 raeburn 52: use File::Copy;
1.329 droeschl 53: use Apache::lonlocal;
54: use Cwd;
55: use LONCAPA qw(:DEFAULT :match);
56:
57: my $iconpath;
58:
59: my %hash;
60:
61: my $hashtied;
62: my %alreadyseen=();
63:
64: my $hadchanges;
1.557 raeburn 65: my $suppchanges;
1.329 droeschl 66:
67:
68: my %help=();
69:
70:
71: sub mapread {
72: my ($coursenum,$coursedom,$map)=@_;
73: return
74: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
75: $map);
76: }
77:
78: sub storemap {
1.492 raeburn 79: my ($coursenum,$coursedom,$map,$contentchg)=@_;
80: my $report;
81: if (($contentchg) && ($map =~ /^default/)) {
82: $report = 1;
83: }
1.329 droeschl 84: my ($outtext,$errtext)=
85: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 86: $map,1,$report);
1.329 droeschl 87: if ($errtext) { return ($errtext,2); }
1.364 bisitz 88:
1.557 raeburn 89: if ($map =~ /^default/) {
90: $hadchanges=1;
91: } else {
92: $suppchanges=1;
93: }
1.329 droeschl 94: return ($errtext,0);
95: }
96:
97:
98:
99: sub authorhosts {
100: my %outhash=();
101: my $home=0;
102: my $other=0;
103: foreach my $key (keys(%env)) {
104: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
105: my $role=$1;
106: my $realm=$2;
107: my ($start,$end)=split(/\./,$env{$key});
108: if (($start) && ($start>time)) { next; }
109: if (($end) && (time>$end)) { next; }
110: my ($ca,$cd);
111: if ($1 eq 'au') {
112: $ca=$env{'user.name'};
113: $cd=$env{'user.domain'};
114: } else {
115: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
116: }
117: my $allowed=0;
118: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
119: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 120: foreach my $id (@ids) {
121: if ($id eq $myhome) {
122: $allowed=1;
123: last;
124: }
125: }
1.329 droeschl 126: if ($allowed) {
127: $home++;
1.484 raeburn 128: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 129: } else {
1.484 raeburn 130: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 131: $other++;
132: }
133: }
134: }
135: return ($home,$other,%outhash);
136: }
137:
138:
139: sub clean {
140: my ($title)=@_;
141: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 142: return $title;
1.329 droeschl 143: }
144:
1.617 raeburn 145: sub default_folderpath {
146: my ($coursenum,$coursedom,$navmapref) = @_;
147: return unless ($coursenum && $coursedom && ref($navmapref));
148: # Check if entire course is hidden and/or encrypted
149: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
150: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
151: unless (ref($$navmapref)) {
152: $$navmapref = Apache::lonnavmaps::navmap->new();
153: }
154: if (ref($$navmapref)) {
155: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
156: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
157: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
158: unless (@resources) {
159: $hiddenmap = 1;
160: unless ($env{'request.role.adv'}) {
161: $hiddentop = 1;
162: if ($env{'form.folder'}) {
163: undef($env{'form.folder'});
164: }
165: }
166: }
167: }
168: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
169: $encryptmap = 1;
170: }
171: }
172: unless ($hiddentop) {
173: $folderpath='default&'.&escape(&mt('Main Content')).
174: '::'.$hiddenmap.':'.$encryptmap.'::';
175: }
176: if (wantarray) {
177: return ($folderpath,$hiddentop);
178: } else {
179: return $folderpath;
180: }
181: }
1.329 droeschl 182:
183: sub dumpcourse {
184: my ($r) = @_;
1.408 raeburn 185: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 186: my ($starthash,$js);
187: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
188: $js = <<"ENDJS";
189: <script type="text/javascript">
190: // <![CDATA[
191:
192: function hide_searching() {
193: if (document.getElementById('searching')) {
194: document.getElementById('searching').style.display = 'none';
195: }
196: return;
197: }
198:
199: // ]]>
200: </script>
201: ENDJS
202: $starthash = {
203: add_entries => {'onload' => "hide_searching();"},
204: };
205: }
1.568 raeburn 206: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
207: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 208: $r->print(&startContentScreen('tools'));
1.329 droeschl 209: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 210: unless ($home) {
211: $r->print(&endContentScreen());
212: return '';
213: }
1.329 droeschl 214: my $origcrsid=$env{'request.course.id'};
215: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
216: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
217: # Do the dumping
1.484 raeburn 218: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
219: $r->print(&endContentScreen());
220: return '';
221: }
1.531 raeburn 222: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 223: $r->print('<h3>'.&mt('Copying Files').'</h3>');
224: my $title=$env{'form.authorfolder'};
225: $title=&clean($title);
1.567 raeburn 226: my ($navmap,$errormsg) =
227: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
228: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
229: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
230: my (%maps,%resources,%titles);
231: if (!ref($navmap)) {
232: $r->print($errormsg.
233: &endContentScreen());
234: return '';
235: } else {
236: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
237: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 238: }
1.567 raeburn 239: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
240: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
241: %newcontent,%has_simpleprobs);
242: foreach my $item (sort {$a <=> $b} (@todump)) {
243: my $name = $env{'form.namefor_'.$item};
244: if ($resources{$item}) {
245: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
246: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
247: $tocopy{$1} = $name;
248: $display{$item} = $1;
249: $lookup{$1} = $item;
250: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
251: $simpleproblems{$item} = {
252: symb => $resources{$item},
253: name => $name,
254: };
255: $display{$item} = 'simpleproblem_'.$name;
256: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
257: $has_simpleprobs{$1}{$id} = $item;
258: }
259: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
260: my $marker = $1;
261: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
262: $simplepages{$item} = {
263: res => $res,
264: title => $titles{$item},
265: db => $db_name,
266: marker => $marker,
267: symb => $resources{$item},
268: name => $name,
269: };
270: $display{$item} = '/'.$res;
271: }
272: } elsif ($maps{$item}) {
273: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
274: $tocopy{$1} = $name;
275: $display{$item} = $1;
276: $lookup{$1} = $item;
277: }
278: } else {
279: next;
280: }
281: }
1.329 droeschl 282: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
283: $crs=~s/\_/\//g;
1.567 raeburn 284: my $mm = new File::MMagic;
285: my $prefix = "/uploaded/$cdom/$cnum/";
286: %replacehash = %tocopy;
287: foreach my $item (sort(keys(%simpleproblems))) {
288: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
289: $newcontent{$display{$item}} = $content;
290: }
291: my $gateway = Apache::lonhtmlgateway->new('web');
292: foreach my $item (sort(keys(%simplepages))) {
293: if (ref($simplepages{$item}) eq 'HASH') {
294: my $pagetitle = $simplepages{$item}{'title'};
295: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
296: my %contents;
297: foreach my $field (keys(%fields)) {
298: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
299: my $name = $1;
300: my $msg = $fields{$field};
301: if ($name eq 'webreferences') {
302: if ($msg =~ m{^https?://}) {
303: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
304: }
305: } else {
306: $msg = &Encode::decode('utf8',$msg);
307: $msg = $gateway->process_outgoing_html($msg,1);
308: $contents{$name} = $msg;
309: }
310: } elsif ($field eq 'uploaded.photourl') {
311: my $marker = $simplepages{$item}{marker};
312: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
313: my $filepath = $1;
314: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
315: if ($fname ne '') {
316: $fname=~s/\.(\w+)$//;
317: my $ext=$1;
318: $fname = &clean($fname);
319: $fname.='.'.$ext;
320: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
321: $replacehash{$filepath} = $relpath.$fname;
322: $deps{$item}{$filepath} = 1;
323: }
324: }
325: }
326: }
327: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
328: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
329: my $content = '
330: <html>
331: <head>
332: <title>'.$pagetitle.'</title>
333: </head>
334: <body bgcolor="#ffffff">';
335: if ($contents{title}) {
336: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
337: }
338: if ($contents{image}) {
339: $content .= "\n".$contents{image};
340: }
341: if ($contents{content}) {
342: $content .= '
343: <div class="LC_Box">
1.577 bisitz 344: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 345: $contents{content}.'
346: </div>';
347: }
348: if ($contents{webreferences}) {
349: $content .= '
350: <div class="LC_Box">
1.577 bisitz 351: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 352: $contents{webreferences}.'
353: </div>';
354: }
355: $content .= '
356: </body>
357: </html>
358: ';
359: $newcontent{'/'.$simplepages{$item}{res}} = $content;
360: }
361: }
362: foreach my $item (keys(%tocopy)) {
363: unless ($item=~/\.(sequence|page)$/) {
364: my $currurlpath = $prefix.$item;
365: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
366: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
367: }
368: }
369: foreach my $num (sort {$a <=> $b} (@todump)) {
370: my $src = $display{$num};
371: next if ($src eq '');
372: my @needcopy = ();
373: if ($replacehash{$src}) {
374: push(@needcopy,$src);
375: if (ref($deps{$num}) eq 'HASH') {
376: foreach my $dep (sort(keys(%{$deps{$num}}))) {
377: if ($replacehash{$dep}) {
378: push(@needcopy,$dep);
379: }
380: }
381: }
382: } elsif ($src =~ /^simpleproblem_/) {
383: push(@needcopy,$src);
384: }
385: next if (@needcopy == 0);
386: my ($result,$depresult);
387: for (my $i=0; $i<@needcopy; $i++) {
388: my $item = $needcopy[$i];
389: my $newfilename;
390: if ($simpleproblems{$num}) {
391: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
392: } else {
393: $newfilename=$title.'/'.$replacehash{$item};
394: }
395: $newfilename=~s/\.(\w+)$//;
396: my $ext=$1;
397: $newfilename=&clean($newfilename);
398: $newfilename.='.'.$ext;
399: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
400: if ($newrelpath ne $replacehash{$item}) {
401: $replacehash{$item} = $newrelpath;
402: }
403: my @dirs=split(/\//,$newfilename);
404: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
405: my $makepath=$path;
406: my $fail;
407: my $origin;
408: for (my $i=0;$i<$#dirs;$i++) {
409: $makepath.='/'.$dirs[$i];
410: unless (-e $makepath) {
411: unless(mkdir($makepath,0755)) {
412: $fail = &mt('Directory creation failed.');
413: }
414: }
415: }
416: if ($i == 0) {
417: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
418: } else {
419: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
420: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
421: &mt('(dependency)').'</span>: ';
422: }
423: if (-e $path.'/'.$newfilename) {
424: $fail = &mt('Destination already exists -- not overwriting.');
425: } else {
426: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
427: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
428: ($item =~ /^simpleproblem_/)) {
429: print $fh $newcontent{$item};
430: } else {
431: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
432: if (-e $fileloc) {
433: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
434: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
435: (ref($has_simpleprobs{$item}) eq 'HASH')) {
436: my %changes = %{$has_simpleprobs{$item}};
437: my $content = &Apache::lonclonecourse::rewritefile(
438: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
439: (%replacehash,$crs => '')
440: );
441: my $updatedcontent = '';
442: my $parser = HTML::TokeParser->new(\$content);
443: $parser->attr_encoded(1);
444: while (my $token = $parser->get_token) {
445: if ($token->[0] eq 'S') {
446: if (($token->[1] eq 'resource') &&
447: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
448: ($changes{$token->[2]->{'id'}})) {
449: my $id = $token->[2]->{'id'};
450: $updatedcontent .= '<'.$token->[1];
451: foreach my $attrib (@{$token->[3]}) {
452: next unless ($attrib =~ /^(src|type|title|id)$/);
453: if ($attrib eq 'src') {
454: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
455: if ($file) {
456: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: } else {
461: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
462: }
463: }
464: $updatedcontent .= ' />'."\n";
465: } else {
466: $updatedcontent .= $token->[4]."\n";
467: }
468: } else {
469: $updatedcontent .= $token->[2];
470: }
471: }
472: print $fh $updatedcontent;
473: } else {
474: print $fh &Apache::lonclonecourse::rewritefile(
475: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
476: (%replacehash,$crs => '')
477: );
478: }
479: } else {
480: print $fh
481: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
482: }
483: } else {
484: $fail = &mt('Source does not exist.');
485: }
486: }
487: $fh->close();
488: } else {
489: $fail = &mt('Could not write to destination.');
490: }
491: }
492: my $text;
493: if ($fail) {
494: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
495: } else {
496: $text = '<span class="LC_success">'.&mt('ok').'</span>';
497: }
498: if ($i == 0) {
499: $result .= $text;
500: } else {
501: $depresult .= $text.'</li>';
502: }
503: }
504: $r->print($result);
505: if ($depresult) {
506: $r->print('<ul>'.$depresult.'</ul>');
507: }
508: }
509: } else {
510: my ($navmap,$errormsg) =
511: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
512: if (!ref($navmap)) {
513: $r->print($errormsg);
514: } else {
515: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
516: $r->rflush();
517: my ($preamble,$formname);
518: $formname = 'dumpdoc';
519: unless ($home==1) {
520: $preamble = '<div class="LC_left_float">'.
521: '<fieldset><legend>'.
522: &mt('Select the Authoring Space').
523: '</legend><select name="authorspace">';
1.329 droeschl 524: }
1.567 raeburn 525: my @orderspaces = ();
526: foreach my $key (sort(keys(%outhash))) {
527: if ($key=~/^home_(.+)$/) {
528: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
529: unshift(@orderspaces,$1);
530: } else {
531: push(@orderspaces,$1);
532: }
533: }
534: }
1.569 raeburn 535: if ($home>1) {
536: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
537: }
1.567 raeburn 538: foreach my $user (@orderspaces) {
1.329 droeschl 539: if ($home==1) {
1.567 raeburn 540: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 541: } else {
1.567 raeburn 542: $preamble .= '<option value="'.$user.'">'.$user.' - '.
543: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
544: }
1.329 droeschl 545: }
1.567 raeburn 546: unless ($home==1) {
547: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 548: }
1.567 raeburn 549: my $title=$origcrsdata{'description'};
550: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 551: $title=&clean($title);
1.567 raeburn 552: $preamble .= '<div class="LC_left_float">'.
553: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
554: '<input type="text" size="50" name="authorfolder" value="'.
555: $title.'" />'.
556: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
557: my %uploadedfiles;
558: &tiehash();
559: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
560: my ($ext)=($file=~/\.(\w+)$/);
561: # FIXME Check supplemental here
562: my $title=$hash{'title_'.$hash{
563: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
564: if (!$title) {
565: $title=$file;
566: } else {
567: $title=~s|/|_|g;
568: }
569: $title=~s/\.(\w+)$//;
570: $title=&clean($title);
571: $title.='.'.$ext;
572: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
573: $uploadedfiles{$file} = $title;
574: }
575: &untiehash();
576: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
577: undef,undef,$preamble,$home,\%uploadedfiles));
578: }
1.329 droeschl 579: }
1.484 raeburn 580: $r->print(&endContentScreen());
1.329 droeschl 581: }
582:
1.567 raeburn 583: sub recurse_html {
584: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
585: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
586: my (%allfiles,%codebase);
587: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
588: if (keys(%allfiles)) {
589: foreach my $dependency (keys(%allfiles)) {
590: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
591: my ($depurl,$relfile,$newcontainer);
592: if ($dependency =~ m{^/}) {
593: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
594: $relfile = $1;
595: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
596: $newcontainer = $1;
597: next if ($replacehash->{$newcontainer});
598: }
599: $depurl = $dependency;
600: } else {
601: next;
602: }
603: } else {
604: $relfile = $dependency;
605: $depurl = $currurlpath;
606: $depurl =~ s{[^/]+$}{};
607: $depurl .= $dependency;
608: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
609: }
610: next if ($relfile eq '');
611: my $newname = $replacehash->{$container};
612: $newname =~ s{[^/]+$}{};
613: $replacehash->{$newcontainer} = $newname.$relfile;
614: $deps->{$item}{$newcontainer} = 1;
615: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
616: my $depfile = &Apache::lonnet::filelocation('',$depurl);
617: my $type = $mm->checktype_filename($depfile);
618: if ($type eq 'text/html') {
619: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
620: }
621: }
622: }
623: }
624: return;
625: }
626:
1.329 droeschl 627: sub group_import {
1.598 raeburn 628: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 629: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
630: %removeparam,$importuploaded,$fixuperrors);
631: $allmaps = {};
1.329 droeschl 632: while (@files) {
633: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 634: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 635: && ($caller eq 'londocs')
636: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 637:
1.329 droeschl 638: my $errtext = '';
639: my $fatal = 0;
640: my $newmapstr = '<map>'."\n".
641: '<resource id="1" src="" type="start"></resource>'."\n".
642: '<link from="1" to="2" index="1"></link>'."\n".
643: '<resource id="2" src="" type="finish"></resource>'."\n".
644: '</map>';
645: $env{'form.output'}=$newmapstr;
646: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
647: 'output',$1.$2);
1.534 raeburn 648: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 649: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
650: $fatal = 2;
651: }
652: if ($fatal) {
653: return ($errtext,$fatal);
654: }
655: }
656: if ($url) {
1.598 raeburn 657: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) {
658: $url = $1;
659: my $marker = $2;
660: my $info = $3;
1.604 raeburn 661: my ($toolid,%toolhash,%toolsettings);
1.598 raeburn 662: my @toolinfo = split(/:/,$info);
663: if ($residx) {
1.604 raeburn 664: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 665: $toolid = $toolsettings{'id'};
666: } else {
1.604 raeburn 667: $toolid = shift(@toolinfo);
1.598 raeburn 668: }
669: $toolid =~ s/\D//g;
1.604 raeburn 670: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
671: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
672: $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'});
673: $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'});
1.598 raeburn 674: if (ref($ltitoolsref) eq 'HASH') {
1.604 raeburn 675: my @deleted;
1.598 raeburn 676: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
677: if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
678: $url =~ s/exttool$/exttools/;
679: }
680: $toolhash{'id'} = $toolid;
1.604 raeburn 681: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
682: if ($toolhash{'target'} eq 'window') {
683: foreach my $item ('width','height') {
684: $toolhash{$item} =~ s/^\s+//;
685: $toolhash{$item} =~ s/\s+$//;
686: }
687: }
688: } elsif ($residx) {
689: $toolhash{'target'} = $toolsettings{'target'};
690: if ($toolhash{'target'} eq 'window') {
691: $toolhash{'width'} = $toolsettings{'width'};
692: $toolhash{'height'} = $toolsettings{'height'};
693: }
694: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
695: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
696: if ($toolhash{'target'} eq 'window') {
697: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
698: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
699: }
700: }
1.598 raeburn 701: if ($toolhash{'target'} eq 'iframe') {
702: delete($toolhash{'width'});
703: delete($toolhash{'height'});
1.604 raeburn 704: if ($residx) {
705: if ($toolsettings{'width'}) {
706: push(@deleted,'width');
707: }
708: if ($toolsettings{'height'}) {
709: push(@deleted,'height');
710: }
711: }
712: }
713: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
714: foreach my $item ('label','title') {
715: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
716: $toolhash{'crs'.$item} =~ s/^\s+//;
717: $toolhash{'crs'.$item} =~ s/\s+$//;
718: if ($toolhash{'crs'.$item} eq '') {
719: delete($toolhash{'crs'.$item});
720: }
721: } else {
722: delete($toolhash{'crs'.$item});
723: }
724: if (($residx) && (exists($toolsettings{'crs'.$item}))) {
725: unless (exists($toolhash{'crs'.$item})) {
726: push(@deleted,'crs'.$item);
727: }
728: }
1.598 raeburn 729: }
730: }
731: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 732: if ($putres eq 'ok') {
733: if (@deleted) {
734: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
735: }
736: }
1.598 raeburn 737: }
738: }
739: }
1.529 raeburn 740: if (($caller eq 'londocs') &&
741: ($folder =~ /^default/)) {
1.534 raeburn 742: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 743: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
744: my $cid = $coursedom.'_'.$coursenum;
745: $allmaps =
746: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
747: $chome,$cid);
748: $donechk = 1;
749: }
750: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
751: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
752: \%addedmaps,\%hierarchy,\%titles,$allmaps);
753: $importuploaded = 1;
754: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
755: next if ($allmaps->{$url});
756: }
757: }
1.344 bisitz 758: if (!$residx
1.329 droeschl 759: || defined($LONCAPA::map::zombies[$residx])) {
760: $residx = &LONCAPA::map::getresidx($url,$residx);
761: push(@LONCAPA::map::order, $residx);
762: }
763: my $ext = 'false';
764: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
765: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 766: if ($name eq '') {
1.538 raeburn 767: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 768: }
769: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
770: my $filepath = $1;
771: my $fname = $name;
772: if ($fname =~ /^\W+$/) {
773: $fname = 'web';
774: } else {
775: $fname =~ s/\W/_/g;
776: }
1.599 damieng 777: if (length($fname) > 15) {
1.534 raeburn 778: $fname = substr($fname,0,14);
779: }
780: my $initialtext = &mt('Replace with your own content.');
781: my $newhtml = <<END;
1.545 raeburn 782: <html>
1.534 raeburn 783: <head>
784: <title>$name</title>
785: </head>
786: <body bgcolor="#ffffff">
787: $initialtext
788: </body>
789: </html>
790: END
791: $env{'form.output'}=$newhtml;
792: my $result =
793: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
794: 'output',
795: "$filepath/$residx/$fname.html");
796: if ($result =~ m{^/uploaded/}) {
797: $url = $result;
798: if ($filepath =~ /^supplemental/) {
799: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
800: $env{'user.domain'}.'___&&&___'.$name;
801: }
802: } else {
803: return (&mt('Failed to save new web page.'),1);
804: }
805: }
1.538 raeburn 806: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 807: $LONCAPA::map::resources[$residx] =
1.329 droeschl 808: join(':', ($name, $url, $ext, 'normal', 'res'));
809: }
810: }
1.529 raeburn 811: if ($importuploaded) {
812: my %import_errors;
813: my %updated = (
814: removefrommap => \%removefrommap,
815: removeparam => \%removeparam,
816: );
1.533 raeburn 817: my ($result,$msgsarray,$lockerror) =
818: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 819: if (keys(%import_errors) > 0) {
1.530 raeburn 820: $fixuperrors =
1.529 raeburn 821: '<p span class="LC_warning">'."\n".
822: &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".
823: '<ul>'."\n";
824: foreach my $key (sort(keys(%import_errors))) {
825: $fixuperrors .= '<li>'.$key.'</li>'."\n";
826: }
827: $fixuperrors .= '</ul></p>'."\n";
828: }
1.533 raeburn 829: if (ref($msgsarray) eq 'ARRAY') {
830: if (@{$msgsarray} > 0) {
831: $fixuperrors .= '<p class="LC_info">'.
832: join('<br />',@{$msgsarray}).
833: '</p>';
834: }
835: }
836: if ($lockerror) {
837: $fixuperrors .= '<p class="LC_error">'.
838: $lockerror.
839: '</p>';
840: }
1.529 raeburn 841: }
842: my ($errtext,$fatal) =
843: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 844: unless ($fatal) {
845: if ($folder =~ /^supplemental/) {
846: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 847: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
848: $folder.'.'.$container);
1.557 raeburn 849: }
850: }
1.529 raeburn 851: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 852: }
853:
854: sub log_docs {
1.494 raeburn 855: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 856: }
857:
858: {
859: my @oldresources=();
860: my @oldorder=();
861: my $parmidx;
862: my %parmaction=();
863: my %parmvalue=();
864: my $changedflag;
865:
866: sub snapshotbefore {
867: @oldresources=@LONCAPA::map::resources;
868: @oldorder=@LONCAPA::map::order;
869: $parmidx=undef;
870: %parmaction=();
871: %parmvalue=();
872: $changedflag=0;
873: }
874:
875: sub remember_parms {
876: my ($idx,$parameter,$action,$value)=@_;
877: $parmidx=$idx;
878: $parmaction{$parameter}=$action;
879: $parmvalue{$parameter}=$value;
880: $changedflag=1;
881: }
882:
883: sub log_differences {
884: my ($plain)=@_;
885: my %storehash=('folder' => $plain,
886: 'currentfolder' => $env{'form.folder'});
887: if ($parmidx) {
888: $storehash{'parameter_res'}=$oldresources[$parmidx];
889: foreach my $parm (keys(%parmaction)) {
890: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
891: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
892: }
893: }
894: my $maxidx=$#oldresources;
895: if ($#LONCAPA::map::resources>$#oldresources) {
896: $maxidx=$#LONCAPA::map::resources;
897: }
898: for (my $idx=0; $idx<=$maxidx; $idx++) {
899: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
900: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
901: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
902: $changedflag=1;
903: }
904: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
905: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
906: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
907: $changedflag=1;
908: }
909: }
910: $storehash{'maxidx'}=$maxidx;
911: if ($changedflag) { &log_docs(\%storehash); }
912: }
913: }
914:
915: sub docs_change_log {
1.611 raeburn 916: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 917: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 918: my $navmap;
1.483 raeburn 919: my $js = '<script type="text/javascript">'."\n".
920: '// <![CDATA['."\n".
921: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 922: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.617 raeburn 923: $coursedom,$coursenum,'','',$canedit,\$navmap)."\n".
1.483 raeburn 924: &history_tab_js()."\n".
1.484 raeburn 925: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 926: '// ]]>'."\n".
927: '</script>'."\n";
1.484 raeburn 928: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
929: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 930: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 931: my %orderhash;
932: my $container='sequence';
933: my $pathitem;
1.519 raeburn 934: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 935: $container='page';
936: }
1.519 raeburn 937: my $folderpath=$env{'form.folderpath'};
938: if ($folderpath eq '') {
1.617 raeburn 939: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 940: }
1.617 raeburn 941: undef($navmap);
1.519 raeburn 942: $pathitem = '<input type="hidden" name="folderpath" value="'.
943: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 944: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
945: my $jumpto = $readfile;
946: $jumpto =~ s{^/}{};
947: my $tid = 1;
1.489 raeburn 948: if ($supplementalflag) {
949: $tid = 2;
950: }
1.509 raeburn 951: my ($breadcrumbtrail) =
952: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 953: $r->print($breadcrumbtrail.
954: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
955: $readfile));
1.329 droeschl 956: my %docslog=&Apache::lonnet::dump('nohist_docslog',
957: $env{'course.'.$env{'request.course.id'}.'.domain'},
958: $env{'course.'.$env{'request.course.id'}.'.num'});
959:
960: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
961:
962: my %saveable_parameters = ('show' => 'scalar',);
963: &Apache::loncommon::store_course_settings('docs_log',
964: \%saveable_parameters);
965: &Apache::loncommon::restore_course_settings('docs_log',
966: \%saveable_parameters);
967: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 968: # FIXME: internationalization seems wrong here
1.329 droeschl 969: my %lt=('hiddenresource' => 'Resources hidden',
970: 'encrypturl' => 'URL hidden',
971: 'randompick' => 'Randomly pick',
972: 'randomorder' => 'Randomly ordered',
973: 'set' => 'set to',
974: 'del' => 'deleted');
1.484 raeburn 975: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
976: $pathitem."\n".
977: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
978: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
979: $r->print('<div class="LC_left_float">'.
980: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
981: &makedocslogform($filter,1).
982: '</fieldset></div><br clear="all" />');
1.329 droeschl 983: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
984: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
985: &mt('After').'</th>'.
986: &Apache::loncommon::end_data_table_header_row());
987: my $shown=0;
988: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
989: if ($env{'form.displayfilter'} eq 'currentfolder') {
990: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
991: }
992: my @changes=keys(%{$docslog{$id}{'logentry'}});
993: if ($env{'form.displayfilter'} eq 'containing') {
994: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
995: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
996: foreach my $key (@changes) {
997: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
998: }
1.344 bisitz 999: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1000: }
1001: my $count = 0;
1002: my $time =
1003: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1004: my $plainname =
1005: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1006: $docslog{$id}{'exe_udom'});
1007: my $about_me_link =
1008: &Apache::loncommon::aboutmewrapper($plainname,
1009: $docslog{$id}{'exe_uname'},
1010: $docslog{$id}{'exe_udom'});
1011: my $send_msg_link='';
1012: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1013: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1014: $send_msg_link ='<br />'.
1015: &Apache::loncommon::messagewrapper(&mt('Send message'),
1016: $docslog{$id}{'exe_uname'},
1017: $docslog{$id}{'exe_udom'});
1018: }
1019: $r->print(&Apache::loncommon::start_data_table_row());
1020: $r->print('<td>'.$time.'</td>
1021: <td>'.$about_me_link.
1022: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1023: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1024: $send_msg_link.'</td><td>'.
1025: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1026: my $is_supp = 0;
1027: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1028: $is_supp = 1;
1029: }
1.329 droeschl 1030: # Before
1031: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1032: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1033: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1034: if ($oldname ne $newname) {
1.488 raeburn 1035: my $shown = &LONCAPA::map::qtescape($oldname);
1036: if ($is_supp) {
1037: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1038: }
1039: $r->print($shown);
1.329 droeschl 1040: }
1041: }
1042: $r->print('<ul>');
1043: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1044: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1045: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1046: if ($is_supp) {
1047: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1048: }
1049: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1050: }
1051: }
1052: $r->print('</ul>');
1053: # After
1054: $r->print('</td><td>');
1055:
1056: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1057: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1058: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1059: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1060: my $shown = &LONCAPA::map::qtescape($newname);
1061: if ($is_supp) {
1062: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1063: }
1064: $r->print($shown);
1.329 droeschl 1065: }
1.364 bisitz 1066: }
1.329 droeschl 1067: $r->print('<ul>');
1068: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1069: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1070: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1071: if ($is_supp) {
1072: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1073: }
1074: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1075: }
1076: }
1077: $r->print('</ul>');
1078: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1079: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1080: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1081: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1082: # FIXME: internationalization seems wrong here
1.329 droeschl 1083: $r->print('<li>'.
1084: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1085: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1086: .'</li>');
1087: }
1088: }
1089: $r->print('</ul>');
1090: }
1091: # End
1092: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1093: $shown++;
1094: if (!($env{'form.show'} eq &mt('all')
1095: || $shown<=$env{'form.show'})) { last; }
1096: }
1.484 raeburn 1097: $r->print(&Apache::loncommon::end_data_table()."\n".
1098: &makesimpleeditform($pathitem)."\n".
1099: '</div></div>');
1100: $r->print(&endContentScreen());
1.329 droeschl 1101: }
1102:
1103: sub update_paste_buffer {
1.492 raeburn 1104: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1105: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1106: if ($env{'form.multiremove'}) {
1107: $env{'form.multiremove'} =~ s/,$//;
1108: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1109: }
1110: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1111: if ($env{'form.multicut'}) {
1112: $env{'form.multicut'} =~ s/,$//;
1113: foreach my $item (split(/,/,$env{'form.multicut'})) {
1114: unless ($removals{$item}) {
1115: $cuts{$item} = 1;
1116: push(@possibles,$item.':cut');
1117: }
1118: }
1119: }
1120: if ($env{'form.multicopy'}) {
1121: $env{'form.multicopy'} =~ s/,$//;
1122: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1123: unless ($removals{$item} || $cuts{$item}) {
1124: push(@possibles,$item.':copy');
1125: }
1126: }
1127: }
1128: } elsif ($env{'form.markcopy'}) {
1129: @possibles = split(/,/,$env{'form.markcopy'});
1130: }
1.329 droeschl 1131:
1.538 raeburn 1132: return if (@possibles == 0);
1.329 droeschl 1133: return if (!defined($env{'form.copyfolder'}));
1134:
1135: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1136: $env{'form.copyfolder'});
1.538 raeburn 1137: return if ($fatal);
1138:
1139: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1140:
1.538 raeburn 1141: # Retrieve current paste buffer suffixes.
1142: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1143: my (%pasteurls,@newpaste);
1144:
1145: # Construct identifiers for current contents of user's paste buffer
1146: if (@currpaste) {
1147: foreach my $suffix (@currpaste) {
1148: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1149: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1150: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1151: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1152: ($url ne '')) {
1.597 raeburn 1153: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1154: }
1155: }
1156: }
1157:
1158: # Mark items for copying (skip any items already in user's paste buffer)
1159: my %addtoenv;
1.597 raeburn 1160:
1161: my @pathitems = split(/\&/,$env{'form.folderpath'});
1162: my @folderconf = split(/\:/,$pathitems[-1]);
1163: my $ispage = $folderconf[4];
1164:
1.538 raeburn 1165: foreach my $item (@possibles) {
1166: my ($orderidx,$cmd) = split(/:/,$item);
1167: next if ($orderidx =~ /\D/);
1168: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1169: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1170: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1171: my %denied = &action_restrictions($coursenum,$coursedom,
1172: &LONCAPA::map::qtescape($url),
1173: $env{'form.folderpath'},\%curr_groups);
1174: next if ($denied{'copy'});
1175: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1176: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1177: my ($suffix,$errortxt,$locknotfreed) =
1178: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1179: if ($suffix ne '') {
1180: push(@newpaste,$suffix);
1181: } else {
1182: if ($locknotfreed) {
1183: return $locknotfreed;
1184: }
1.538 raeburn 1185: }
1186: if (&is_supplemental_title($title)) {
1187: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1188: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1189: }
1.329 droeschl 1190:
1.538 raeburn 1191: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1192: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1193: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1194: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1195: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1196: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1197: my $prefix = $1;
1198: my $subdir =$2;
1199: if ($subdir eq '') {
1200: $subdir = $prefix;
1.492 raeburn 1201: }
1.538 raeburn 1202: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1203: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1204: \%hierarchy,\%titles,\%allmaps);
1205: if (ref($hierarchy{$url}) eq 'HASH') {
1206: my ($nested,$nestednames);
1207: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1208: $nested =~ s/\&$//;
1209: $nestednames =~ s/\Q___&&&___\E$//;
1210: if ($nested ne '') {
1211: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1212: }
1213: if ($nestednames ne '') {
1214: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1215: }
1.492 raeburn 1216: }
1217: }
1.591 raeburn 1218: if ($locknotfreed) {
1219: $output = $locknotfreed;
1220: last;
1221: }
1.492 raeburn 1222: }
1.538 raeburn 1223: if (@newpaste) {
1224: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1225: }
1.492 raeburn 1226: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1227: delete($env{'form.markcopy'});
1.591 raeburn 1228: return $output;
1.329 droeschl 1229: }
1230:
1.492 raeburn 1231: sub recurse_uploaded_maps {
1232: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1233: if (ref($hierarchy->{$url}) eq 'HASH') {
1234: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1235: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1236: my (@uploaded,@names,%shorter);
1237: for (my $i=0; $i<@maps; $i++) {
1238: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1239: if ($inner ne '') {
1240: push(@uploaded,$inner);
1241: push(@names,&escape($titles[$i]));
1242: $shorter{$maps[$i]} = $inner;
1243: }
1244: }
1245: $$nestref .= "$dir:".join(',',@uploaded).'&';
1246: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1247: foreach my $map (@maps) {
1248: if ($shorter{$map} ne '') {
1249: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1250: }
1251: }
1252: }
1253: return;
1254: }
1255:
1.329 droeschl 1256: sub print_paste_buffer {
1.492 raeburn 1257: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1258: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1259:
1.538 raeburn 1260: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1261: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1262: }
1263:
1.538 raeburn 1264: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1265: my ($pasteitems,@pasteable);
1.575 raeburn 1266: my $clipboardcount = 0;
1.488 raeburn 1267:
1.538 raeburn 1268: # Construct identifiers for current contents of user's paste buffer
1269: foreach my $suffix (@currpaste) {
1270: next if ($suffix =~ /\D/);
1271: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1272: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1273: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1274: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1275: ($url ne '')) {
1.575 raeburn 1276: $clipboardcount ++;
1.538 raeburn 1277: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1278: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1279: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1280: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1281: $is_external = 1;
1.598 raeburn 1282: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
1283: $is_exttool = 1;
1.538 raeburn 1284: }
1285: if ($folder =~ /^supplemental/) {
1286: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1287: unless ($canpaste) {
1288: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1289: }
1290: } else {
1291: $canpaste = 1;
1292: }
1293: if ($canpaste) {
1294: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1295: my $srcdom = $1;
1296: my $srcnum = $2;
1297: my $rem = $3;
1298: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1299: $othercourse = 1;
1300: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1301: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1302: } else {
1303: $canpaste = 0;
1304: $nopaste = &mt('Paste from another course unavailable.');
1305: }
1306: }
1307: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1308: my $prefix = $1;
1309: $parent = $2;
1310: if ($folder !~ /^\Q$prefix\E/) {
1311: $areachange = 1;
1312: }
1313: $is_uploaded_map = 1;
1.492 raeburn 1314: }
1.597 raeburn 1315: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1316: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1317: if ($cid ne $env{'request.course.id'}) {
1318: my ($srcdom,$srcnum) = split(/_/,$cid);
1319: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1320: $othercrs = '<br />'.&mt('(from another course)');
1321: } else {
1322: $canpaste = 0;
1323: $nopaste = &mt('Paste from another course unavailable.');
1324: }
1325: }
1.492 raeburn 1326: }
1.596 raeburn 1327: if ($canpaste) {
1328: push(@pasteable,$suffix);
1329: }
1.538 raeburn 1330: }
1331: my $buffer;
1.598 raeburn 1332: if (($is_external) || ($is_exttool)) {
1.538 raeburn 1333: $buffer = &mt('External Resource').': '.
1334: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1335: &LONCAPA::map::qtescape($url).')';
1336: } else {
1337: my $icon = &Apache::loncommon::icon($extension);
1338: if ($extension eq 'sequence' &&
1339: $url =~ m{/default_\d+\.sequence$}x) {
1340: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1341: $icon .= '/navmap.folder.closed.gif';
1342: }
1.589 raeburn 1343: my $title = $env{'docs.markedcopy_title_'.$suffix};
1344: if ($title eq '') {
1345: ($title) = ($url =~ m{/([^/]+)$});
1346: }
1.538 raeburn 1347: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1348: ': '.
1349: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1350: &LONCAPA::map::qtescape($title));
1.538 raeburn 1351: }
1352: $pasteitems .= '<div class="LC_left_float">';
1353: my ($options,$onclick);
1354: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1355: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1356: if (($is_uploaded_map) ||
1357: ($url =~ /(bulletinboard|smppg)$/) ||
1358: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1359: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1360: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1361: }
1362: }
1363: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1364: if ($nopaste) {
1365: $pasteitems .= $nopaste;
1366: } else {
1367: if ($othercrs) {
1368: $pasteitems .= $othercrs;
1369: }
1370: if ($options) {
1371: $pasteitems .= $options;
1.492 raeburn 1372: }
1373: }
1.538 raeburn 1374: $pasteitems .= '</div>';
1375: }
1376: }
1377: if ($pasteitems eq '') {
1378: &Apache::lonnet::delenv('docs.markedcopies');
1379: }
1380: my ($pasteform,$form_start,$buttons,$form_end);
1381: if ($pasteitems) {
1382: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1383: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1384: if (@pasteable) {
1.575 raeburn 1385: my $value = &mt('Paste to current folder');
1386: if ($container eq 'page') {
1387: $value = &mt('Paste to current page');
1388: }
1389: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1390: }
1391: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1392: if ($clipboardcount > 1) {
1393: $buttons .=
1394: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1395: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1396: (' 'x2).
1397: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1398: (' 'x2);
1.492 raeburn 1399: }
1.575 raeburn 1400: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1401: '</form>';
1.538 raeburn 1402: } else {
1403: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1404: }
1.538 raeburn 1405: $r->print($form_start
1406: .'<fieldset>'
1407: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1408: .$pasteitems
1409: .'</fieldset>'
1410: .$form_end);
1411: }
1412:
1413: sub paste_options {
1414: my ($suffix,$is_uploaded_map,$parent) = @_;
1415: my ($copytext,$movetext);
1416: if ($is_uploaded_map) {
1417: $copytext = &mt('Copy to new folder');
1418: $movetext = &mt('Move old');
1419: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1420: $copytext = &mt('Copy to new board');
1421: $movetext = &mt('Move (not posts)');
1422: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1423: $copytext = &mt('Copy to new page');
1424: $movetext = &mt('Move');
1.533 raeburn 1425: } else {
1.538 raeburn 1426: $copytext = &mt('Copy to new file');
1427: $movetext = &mt('Move');
1428: }
1429: my $output = '<br />'.
1430: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1431: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1432: '<label>'.
1433: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1434: $copytext.'</label></span>'.(' 'x2).' '.
1435: '<span class="LC_nobreak"><label>'.
1436: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1437: $movetext.'</label></span>';
1438: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1439: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1440: '</legend><table border="0">';
1441: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1442: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1443: my $lastdir = $parent;
1444: my %depths = (
1445: $lastdir => 0,
1446: );
1447: my (%display,%deps);
1448: for (my $i=0; $i<@pastemaps; $i++) {
1449: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1450: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1451: my @subfolders = split(/,/,$subfolderstr);
1452: $deps{$lastdir} = \@subfolders;
1453: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1454: my $depth = $depths{$lastdir} + 1;
1455: my $offset = int($depth * 4);
1456: my $indent = (' ' x $offset);
1457: for (my $j=0; $j<@subfolders; $j++) {
1458: $depths{$subfolders[$j]} = $depth;
1459: $display{$subfolders[$j]} =
1460: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1461: '<td><label>'.
1462: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1463: '<label>'.
1464: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1465: &mt('Move old').'</label>'.
1466: '</td></tr>';
1467: }
1.492 raeburn 1468: }
1.538 raeburn 1469: &recurse_print(\$output,$parent,\%deps,\%display);
1470: $output .= '</table></fieldset>';
1.329 droeschl 1471: }
1.538 raeburn 1472: $output .= '</div>';
1473: return $output;
1.488 raeburn 1474: }
1475:
1.492 raeburn 1476: sub recurse_print {
1.538 raeburn 1477: my ($outputref,$dir,$deps,$display) = @_;
1478: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1479: if (ref($deps->{$dir}) eq 'ARRAY') {
1480: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1481: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1482: }
1483: }
1484: }
1485:
1.488 raeburn 1486: sub supp_pasteable {
1487: my ($url) = @_;
1488: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1489: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1490: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1491: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1492: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1493: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
1.488 raeburn 1494: return 1;
1495: }
1496: return;
1.329 droeschl 1497: }
1498:
1.492 raeburn 1499: sub paste_popup_js {
1.594 damieng 1500: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1501: show => 'Show Options',
1502: hide => 'Hide Options',
1.594 damieng 1503: );
1504: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1505: none => 'No items selected from clipboard.',
1.492 raeburn 1506: );
1.594 damieng 1507: &html_escape(\%html_js_lt);
1508: &js_escape(\%html_js_lt);
1509: &js_escape(\%js_lt);
1.492 raeburn 1510: return <<"END";
1511:
1.538 raeburn 1512: function showPasteOptions(suffix) {
1513: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1514: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1515: return;
1516: }
1517:
1.538 raeburn 1518: function hidePasteOptions(suffix) {
1519: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1520: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1521: return;
1522: }
1523:
1524: function showOptions(caller,suffix) {
1525: if (document.getElementById('pasteoptionstext_'+suffix)) {
1526: if (caller.checked) {
1.594 damieng 1527: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1528: } else {
1529: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1530: }
1531: if (document.getElementById('pasteoptions_'+suffix)) {
1532: document.getElementById('pasteoptions_'+suffix).style.display='none';
1533: }
1534: }
1.492 raeburn 1535: return;
1536: }
1537:
1.541 raeburn 1538: function validateClipboard() {
1539: var numchk = 0;
1540: if (document.pasteform.pasting.length > 1) {
1541: for (var i=0; i<document.pasteform.pasting.length; i++) {
1542: if (document.pasteform.pasting[i].checked) {
1543: numchk ++;
1544: }
1545: }
1546: } else {
1547: if (document.pasteform.pasting.type == 'checkbox') {
1548: if (document.pasteform.pasting.checked) {
1549: numchk ++;
1550: }
1551: }
1552: }
1553: if (numchk > 0) {
1554: return true;
1555: } else {
1.594 damieng 1556: alert("$js_lt{'none'}");
1.541 raeburn 1557: return false;
1558: }
1559: }
1560:
1.575 raeburn 1561: function checkClipboard() {
1562: if (document.pasteform.pasting.length > 1) {
1563: for (var i=0; i<document.pasteform.pasting.length; i++) {
1564: document.pasteform.pasting[i].checked = true;
1565: }
1566: }
1567: return;
1568: }
1569:
1570: function uncheckClipboard() {
1571: if (document.pasteform.pasting.length >1) {
1572: for (var i=0; i<document.pasteform.pasting.length; i++) {
1573: document.pasteform.pasting[i].checked = false;
1574: }
1575: }
1576: return;
1577: }
1578:
1.492 raeburn 1579: END
1580:
1581: }
1582:
1.329 droeschl 1583: sub do_paste_from_buffer {
1.492 raeburn 1584: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1585:
1.538 raeburn 1586: # Array of items in paste buffer
1587: my (@currpaste,%pastebuffer,%allerrors);
1588: @currpaste = split(/,/,$env{'docs.markedcopies'});
1589:
1.492 raeburn 1590: # Early out if paste buffer is empty
1.538 raeburn 1591: if (@currpaste == 0) {
1.492 raeburn 1592: return ();
1.538 raeburn 1593: }
1594: map { $pastebuffer{$_} = 1; } @currpaste;
1595:
1596: # Array of items selected items to paste
1597: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1598:
1599: # Early out if nothing selected to paste
1600: if (@reqpaste == 0) {
1601: return();
1602: }
1603: my @topaste;
1604: foreach my $suffix (@reqpaste) {
1605: next if ($suffix =~ /\D/);
1606: next unless (exists($pastebuffer{$suffix}));
1607: push(@topaste,$suffix);
1608: }
1609:
1610: # Early out if nothing available to paste
1611: if (@topaste == 0) {
1612: return();
1.329 droeschl 1613: }
1614:
1.538 raeburn 1615: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.597 raeburn 1616: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1617:
1618: foreach my $suffix (@topaste) {
1619: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1620: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1621: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1622: # Supplemental content may only include certain types of content
1623: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1624: if ($folder =~ /^supplemental/) {
1625: unless (&supp_pasteable($url)) {
1626: $notinsupp{$suffix} = 1;
1627: next;
1628: }
1.492 raeburn 1629: }
1.538 raeburn 1630: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1631: my $srcd = $1;
1632: my $srcn = $2;
1.492 raeburn 1633: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1634: # check for mdc privilege in the course from which the resource was pasted
1635: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1636: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1637: $notincrs{$suffix} = 1;
1638: next;
1639: }
1.491 raeburn 1640: }
1.538 raeburn 1641: $srcdom{$suffix} = $srcd;
1642: $srcnum{$suffix} = $srcn;
1.597 raeburn 1643: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1644: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1645: my ($srcd,$srcn) = split(/_/,$cid);
1646: # When paste buffer was populated using an active role in a different course
1647: # check for mdc privilege in the course from which the resource was pasted
1648: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1649: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1650: $notincrs{$suffix} = 1;
1651: next;
1652: }
1653: }
1654: $srcdom{$suffix} = $srcd;
1655: $srcnum{$suffix} = $srcn;
1.491 raeburn 1656: }
1.597 raeburn 1657: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1658: push(@dopaste,$suffix);
1659: if ($url=~/\.(page|sequence)$/) {
1660: $is_map{$suffix} = 1;
1661: }
1662:
1663: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1664: my $oldprefix = $1;
1.492 raeburn 1665: # When pasting content from Main Content to Supplemental Content and vice versa
1666: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1667: # a folder/page or a document).
1.538 raeburn 1668: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1669: $prefixchg{$suffix} = 'docstosupp';
1670: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1671: $prefixchg{$suffix} = 'supptodocs';
1672: }
1.491 raeburn 1673:
1.492 raeburn 1674: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1675: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1676: my @nested;
1677: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1678: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1679: my @deps = map { /\d+:([\d,]+$)/ } @items;
1680: foreach my $dep (@deps) {
1681: if ($dep =~ /,/) {
1682: push(@nested,split(/,/,$dep));
1683: } else {
1684: push(@nested,$dep);
1685: }
1.492 raeburn 1686: }
1.538 raeburn 1687: foreach my $item (@nested) {
1688: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1689: push(@{$marktomove{$suffix}},$type.'_'.$item);
1690: }
1.492 raeburn 1691: }
1692: }
1.488 raeburn 1693: }
1694: }
1695:
1.538 raeburn 1696: # Early out if nothing available to paste
1697: if (@dopaste == 0) {
1698: return ();
1699: }
1700:
1701: # Populate message hash and hashes used for main content <=> supplemental content
1702: # changes
1703:
1704: %msgs = &Apache::lonlocal::texthash (
1705: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1706: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1707: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1708: );
1709:
1710: %before = (
1711: docstosupp => {
1712: map => 'default',
1713: doc => 'docs',
1714: },
1715: supptodocs => {
1716: map => 'supplemental',
1717: doc => 'supplemental',
1718: },
1719: );
1720:
1721: %after = (
1722: docstosupp => {
1723: map => 'supplemental',
1724: doc => 'supplemental'
1725: },
1726: supptodocs => {
1727: map => 'default',
1728: doc => 'docs',
1729: },
1730: );
1731:
1732: # Retrieve information about all course maps in main content area
1733:
1734: my $allmaps = {};
1735: if ($folder =~ /^default/) {
1736: $allmaps =
1737: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1738: $env{"course.$env{'request.course.id'}.home"},
1739: $env{'request.course.id'});
1740: }
1741:
1742: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1743:
1744: # Loop over the items to paste
1745: foreach my $suffix (@dopaste) {
1.329 droeschl 1746: # Maps need to be copied first
1.538 raeburn 1747: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1748: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1749: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1750: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1751: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1752: }
1753: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1754: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1755: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1756: my $oldurl = $url;
1757: if ($is_map{$suffix}) {
1.491 raeburn 1758: # If pasting a map, check if map contains other maps
1.538 raeburn 1759: my (%hierarchy,%titles);
1760: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1761: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1762: if ($url=~ m{^/uploaded/}) {
1763: my $newurl;
1764: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1765: ($newurl,my $error) =
1766: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1767: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1768: \$title,$allmaps,\%newurls);
1769: if ($error) {
1770: $allerrors{$suffix} = $error;
1771: next;
1772: }
1773: if ($newurl ne '') {
1774: if ($newurl ne $url) {
1775: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1776: $newsubdir{$url} = $1;
1777: }
1778: $mapchanges{$url} = 1;
1.492 raeburn 1779: }
1.538 raeburn 1780: }
1781: }
1782: if (($srcdom{$suffix} ne $coursedom) ||
1783: ($srcnum{$suffix} ne $coursenum) ||
1784: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1785: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1786: $coursedom,$coursenum,$srcdom{$suffix},
1787: $srcnum{$suffix},$allmaps,\%rewrites,
1788: \%retitles,\%copies,\%dbcopies,
1789: \%zombies,\%params,\%mapmoves,
1790: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1791: \%newurls,\%resdatacopy)) {
1.538 raeburn 1792: $mapmoves{$url} = 1;
1793: }
1794: $url = $newurl;
1795: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1796: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1797: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1798: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1799: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1800: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1801: }
1802: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1803: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1804: push(@toclear,$suffix);
1805: # if pasting published map (main content area only) check map not already in course
1806: if ($folder =~ /^default/) {
1807: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1808: $duplicate{$suffix} = 1;
1809: next;
1.492 raeburn 1810: }
1.491 raeburn 1811: }
1812: }
1.538 raeburn 1813: }
1814: if ($url=~ m{/(bulletinboard|smppg)$}) {
1815: my $prefix = $1;
1.596 raeburn 1816: my $fromothercrs;
1.538 raeburn 1817: #need to copy the db contents to a new one, unless this is a move.
1818: my %info = (
1819: src => $url,
1820: cdom => $coursedom,
1821: cnum => $coursenum,
1.596 raeburn 1822: );
1823: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1824: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1825: $fromothercrs = 1;
1826: $info{'cdom'} = $srcdom{$suffix};
1827: $info{'cnum'} = $srcnum{$suffix};
1828: }
1829: }
1830: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.538 raeburn 1831: my (%lockerr,$msg);
1832: my ($newurl,$result,$errtext) =
1833: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1834: if ($result eq 'ok') {
1835: $url = $newurl;
1836: $title=&mt('Copy of').' '.$title;
1837: } else {
1838: if ($prefix eq 'smppg') {
1839: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1840: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1841: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.538 raeburn 1842: }
1843: $results{$suffix} = $result;
1844: $msgerrs{$suffix} = $msg;
1845: $lockerrs{$suffix} = $lockerr{$prefix};
1846: next;
1847: }
1848: if ($lockerr{$prefix}) {
1849: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1850: }
1.489 raeburn 1851: }
1852: }
1.538 raeburn 1853: $title = &LONCAPA::map::qtunescape($title);
1854: my $ext='false';
1855: if ($url=~m{^http(|s)://}) { $ext='true'; }
1856: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1857: if ($folder !~ /^supplemental/) {
1858: (undef,undef,$title) =
1859: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1860: }
1861: } else {
1862: if ($folder=~/^supplemental/) {
1863: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1864: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1865: }
1.533 raeburn 1866: }
1.491 raeburn 1867:
1868: # For uploaded files (excluding pages/sequences) path in copied file is changed
1869: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1870: # courses.
1871:
1.538 raeburn 1872: unless ($is_map{$suffix}) {
1873: my $newidx;
1.492 raeburn 1874: # Now insert the URL at the bottom
1.538 raeburn 1875: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1876: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1877: my $relpath = $1;
1878: if ($relpath ne '') {
1879: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1880: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1881: my $newprefix = $newloc;
1882: if ($newloc eq 'default') {
1883: $newprefix = 'docs';
1884: }
1885: if ($newdocsdir eq '') {
1886: $newdocsdir = 'default';
1887: }
1888: if (($prefixchg{$suffix}) ||
1889: ($srcdom{$suffix} ne $coursedom) ||
1890: ($srcnum{$suffix} ne $coursenum) ||
1891: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1892: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1893: $url =
1894: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1895: &Apache::lonnet::getfile($oldurl));
1896: if ($url eq '/adm/notfound.html') {
1897: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1898: next;
1899: } else {
1900: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1901: $newsubpath =~ s{/+$}{/};
1902: $docmoves{$oldurl} = $newsubpath;
1903: }
1.491 raeburn 1904: }
1905: }
1.597 raeburn 1906: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1907: my $template = $1;
1908: if ($newidx) {
1909: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1910: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1911: }
1.491 raeburn 1912: }
1.538 raeburn 1913: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1914: ':'.$ext.':normal:res';
1915: push(@LONCAPA::map::order,$newidx);
1916: # Store the result
1917: my ($errtext,$fatal) =
1918: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1919: if ($fatal) {
1920: $save_err .= $errtext;
1921: $allresult = 'fail';
1922: }
1.488 raeburn 1923: }
1.538 raeburn 1924:
1.597 raeburn 1925: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1926: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1927: unless ($allresult eq 'fail') {
1928: my %updated = (
1929: rewrites => \%rewrites,
1930: zombies => \%zombies,
1931: removefrommap => \%removefrommap,
1932: removeparam => \%removeparam,
1933: dbcopies => \%dbcopies,
1.597 raeburn 1934: resdatacopy => \%resdatacopy,
1.538 raeburn 1935: retitles => \%retitles,
1936: );
1937: my %info = (
1938: newsubdir => \%newsubdir,
1939: params => \%params,
1940: );
1941: if ($prefixchg{$suffix}) {
1942: $info{'before'} = $before{$prefixchg{$suffix}};
1943: $info{'after'} = $after{$prefixchg{$suffix}};
1944: }
1945: my %moves = (
1946: copies => \%copies,
1947: docmoves => \%docmoves,
1948: mapmoves => \%mapmoves,
1949: );
1950: (my $result,$msgs{$suffix},my $lockerror) =
1951: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1952: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1953: $url,'paste');
1954: $lockerrors .= $lockerror;
1955: if ($result eq 'ok') {
1956: if ($is_map{$suffix}) {
1957: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1958: $folder.'.'.$container);
1959: if ($fatal) {
1960: $allresult = 'failread';
1961: } else {
1962: if ($#LONCAPA::map::order<1) {
1963: my $idx=&LONCAPA::map::getresidx();
1964: if ($idx<=0) { $idx=1; }
1965: $LONCAPA::map::order[0]=$idx;
1966: $LONCAPA::map::resources[$idx]='';
1967: }
1968: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1969: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1970: ':'.$ext.':normal:res';
1971: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 1972:
1973: # Store the result
1.538 raeburn 1974: my ($errtext,$fatal) =
1975: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1976: if ($fatal) {
1977: $save_err .= $errtext;
1978: $allresult = 'failstore';
1979: }
1980: }
1981: }
1982: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1983: push(@toclear,$suffix);
1984: }
1985: }
1.492 raeburn 1986: }
1987: }
1.538 raeburn 1988: &clear_from_buffer(\@toclear,\@currpaste);
1989: my $msgsarray;
1990: foreach my $suffix (keys(%msgs)) {
1991: if (ref($msgs{$suffix}) eq 'ARRAY') {
1992: $msgsarray .= join(',',@{$msgs{$suffix}});
1993: }
1994: }
1995: return ($allresult,$save_err,$msgsarray,$lockerrors);
1996: }
1.533 raeburn 1997:
1.538 raeburn 1998: sub do_buffer_empty {
1999: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2000: if (@currpaste == 0) {
2001: return &mt('Clipboard is already empty');
2002: }
2003: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2004: if (@toclear == 0) {
2005: return &mt('Nothing selected to clear from clipboard');
2006: }
2007: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2008: if ($numdel) {
2009: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2010: } else {
2011: return &mt('Clipboard unchanged');
1.492 raeburn 2012: }
1.538 raeburn 2013: return;
2014: }
2015:
2016: sub clear_from_buffer {
2017: my ($toclear,$currpaste) = @_;
2018: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2019: my %pastebuffer;
2020: map { $pastebuffer{$_} = 1; } @{$currpaste};
2021: my $numdel = 0;
2022: foreach my $suffix (@{$toclear}) {
2023: next if ($suffix =~ /\D/);
2024: next unless (exists($pastebuffer{$suffix}));
2025: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2026: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2027: delete($pastebuffer{$suffix});
2028: $numdel ++;
2029: }
2030: }
2031: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2032: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2033: return $numdel;
1.492 raeburn 2034: }
2035:
2036: sub get_newmap_url {
2037: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2038: $titleref,$allmaps,$newurls) = @_;
2039: my $newurl;
2040: if ($url=~ m{^/uploaded/}) {
2041: $$titleref=&mt('Copy of').' '.$$titleref;
2042: }
2043: my $now = time;
2044: my $suffix=$$.int(rand(100)).$now;
2045: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2046: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2047: my $path = $1;
2048: my $prefix = $2;
2049: my $ancestor = $3;
2050: if (length($ancestor) > 10) {
2051: $ancestor = substr($ancestor,-10,10);
2052: }
2053: my $newid;
2054: if ($prefixchg) {
2055: if ($folder =~ /^supplemental/) {
2056: $prefix =~ s/^default/supplemental/;
2057: } else {
2058: $prefix =~ s/^supplemental/default/;
2059: }
2060: }
2061: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2062: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2063: } else {
2064: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2065: }
2066: my $counter = 0;
2067: my $is_unique = &uniqueness_check($newurl);
2068: if ($folder =~ /^default/) {
2069: if ($allmaps->{$newurl}) {
2070: $is_unique = 0;
2071: }
2072: }
2073: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2074: $counter ++;
2075: $suffix ++;
2076: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2077: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2078: } else {
2079: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2080: }
2081: $is_unique = &uniqueness_check($newurl);
2082: }
2083: if ($is_unique) {
2084: $newurls->{$newurl} = 1;
2085: } else {
2086: if ($url=~/\.page$/) {
2087: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2088: } else {
2089: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2090: }
2091: }
1.329 droeschl 2092: }
1.492 raeburn 2093: return ($newurl);
1.329 droeschl 2094: }
2095:
1.488 raeburn 2096: sub dbcopy {
1.533 raeburn 2097: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2098: my ($url,$result,$errtext);
2099: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2100: $url = $dbref->{'src'};
1.533 raeburn 2101: if ($url =~ m{/(smppg|bulletinboard)$}) {
2102: my $prefix = $1;
2103: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2104: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2105: my $db_name;
2106: my $marker = (split(m{/},$url))[4];
2107: $marker=~s/\D//g;
2108: if ($dbref->{'src'} =~ m{/smppg$}) {
2109: $db_name =
2110: &Apache::lonsimplepage::get_db_name($url,$marker,
2111: $dbref->{'cdom'},
2112: $dbref->{'cnum'});
2113: } else {
2114: $db_name = 'bulletinpage_'.$marker;
2115: }
2116: my ($suffix,$freedlock,$error) =
2117: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2118: $coursedom,$coursenum,
2119: 'concat');
2120: if (!$suffix) {
2121: if ($prefix eq 'smppg') {
2122: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2123: } else {
1.565 bisitz 2124: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2125: }
2126: if ($error) {
2127: $errtext .= '<br />'.$error;
2128: }
2129: } else {
2130: #need to copy the db contents to a new one.
2131: my %contents=&Apache::lonnet::dump($db_name,
2132: $dbref->{'cdom'},
2133: $dbref->{'cnum'});
2134: if (exists($contents{'uploaded.photourl'})) {
2135: my $photo = $contents{'uploaded.photourl'};
2136: my ($subdir,$fname) =
2137: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2138: my $newphoto;
1.533 raeburn 2139: if ($fname ne '') {
2140: my $content = &Apache::lonnet::getfile($photo);
2141: unless ($content eq '-1') {
2142: $env{'form.'.$suffix.'.photourl'} = $content;
2143: $newphoto =
2144: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2145: delete($env{'form.'.$suffix.'.photourl'});
2146: }
2147: }
2148: if ($newphoto =~ m{^/uploaded/}) {
2149: $contents{'uploaded.photourl'} = $newphoto;
2150: }
2151: }
2152: $db_name =~ s{_\d*$ }{_$suffix}x;
2153: $result=&Apache::lonnet::put($db_name,\%contents,
2154: $coursedom,$coursenum);
2155: if ($result eq 'ok') {
2156: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2157: }
2158: }
2159: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2160: $lockerrorsref->{$prefix} =
1.533 raeburn 2161: '<div class="LC_error">'.
2162: &mt('There was a problem removing a lockfile.');
2163: if ($prefix eq 'smppg') {
1.560 raeburn 2164: $lockerrorsref->{$prefix} .=
1.559 raeburn 2165: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.533 raeburn 2166: } else {
1.565 bisitz 2167: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2168: }
1.560 raeburn 2169: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2170: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2171: '</div>';
1.533 raeburn 2172: }
2173: }
2174: } elsif ($url =~ m{/syllabus$}) {
2175: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2176: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2177: if (($dbref->{'cdom'} ne $coursedom) ||
2178: ($dbref->{'cnum'} ne $coursenum)) {
2179: my %contents=&Apache::lonnet::dump('syllabus',
2180: $dbref->{'cdom'},
2181: $dbref->{'cnum'});
2182: $result=&Apache::lonnet::put('syllabus',\%contents,
2183: $coursedom,$coursenum);
2184: }
2185: }
1.488 raeburn 2186: }
2187: }
1.533 raeburn 2188: return ($url,$result,$errtext);
1.488 raeburn 2189: }
2190:
1.597 raeburn 2191: sub copy_templated_files {
2192: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2193: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2194: my $srccontainer = 'sequence';
2195: if ($srcwaspage) {
2196: $srccontainer = 'page';
2197: }
2198: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2199: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2200: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2201: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2202: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2203: $template.'.problem';
2204: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2205: if ($template eq 'simpleproblem') {
2206: $srcprefix .= '.0.';
2207: my $weightprefix = $newprefix;
2208: $newprefix .= '.0.';
2209: my @simpleprobqtypes = qw(radio option string essay numerical);
2210: my $qtype=$srcparms{$srcprefix.'questiontype'};
2211: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2212: my %newdata;
2213: foreach my $type (@simpleprobqtypes) {
2214: if ($type eq $qtype) {
2215: $newdata{"$weightprefix.$type.weight"}=1;
2216: } else {
2217: $newdata{"$weightprefix.$type.weight"}=0;
2218: }
2219: }
2220: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2221: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2222: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2223: if ($qtype eq 'numerical') {
2224: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2225: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2226: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2227: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2228: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2229: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2230: unless (defined($maxfoils)) { $maxfoils=10; }
2231: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2232: if ($maxfoils<=0) { $maxfoils=10; }
2233: my $randomize=$srcparms{$srcprefix.'randomize'};
2234: unless (defined($randomize)) { $randomize='yes'; }
2235: unless ($randomize eq 'no') { $randomize='yes'; }
2236: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2237: $newdata{$newprefix.'randomize'} = $randomize;
2238: if ($qtype eq 'option') {
2239: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2240: }
2241: for (my $i=1; $i<=10; $i++) {
2242: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2243: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2244: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2245: }
2246:
2247: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2248: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2249: unless (defined($maxfoils)) { $maxfoils=10; }
2250: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2251: if ($maxfoils<=0) { $maxfoils=10; }
2252: my $randomize=$srcparms{$srcprefix.'randomize'};
2253: unless (defined($randomize)) { $randomize='yes'; }
2254: unless ($randomize eq 'no') { $randomize='yes'; }
2255: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2256: $newdata{$newprefix.'randomize'} = $randomize;
2257: if ($qtype eq 'option') {
2258: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2259: }
2260: for (my $i=1; $i<=10; $i++) {
2261: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2262: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2263: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2264: }
2265: } elsif ($qtype eq 'string') {
2266: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2267: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2268: }
2269: if (keys(%newdata)) {
2270: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2271: $coursenum);
2272: if ($putres eq 'ok') {
2273: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2274: }
2275: }
2276: }
2277: }
2278: }
2279:
1.329 droeschl 2280: sub uniqueness_check {
2281: my ($newurl) = @_;
2282: my $unique = 1;
2283: foreach my $res (@LONCAPA::map::order) {
2284: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2285: $url=&LONCAPA::map::qtescape($url);
2286: if ($newurl eq $url) {
2287: $unique = 0;
1.344 bisitz 2288: last;
1.329 droeschl 2289: }
2290: }
2291: return $unique;
2292: }
2293:
1.488 raeburn 2294: sub contained_map_check {
1.492 raeburn 2295: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2296: $allmaps) = @_;
1.488 raeburn 2297: my $content = &Apache::lonnet::getfile($url);
2298: unless ($content eq '-1') {
2299: my $parser = HTML::TokeParser->new(\$content);
2300: $parser->attr_encoded(1);
2301: while (my $token = $parser->get_token) {
2302: next if ($token->[0] ne 'S');
2303: if ($token->[1] eq 'resource') {
2304: next if ($token->[2]->{'type'} eq 'zombie');
2305: my $ressrc = $token->[2]->{'src'};
2306: if ($folder =~ /^supplemental/) {
2307: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2308: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2309: next;
2310: }
2311: }
1.492 raeburn 2312: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2313: if ($1 eq 'uploaded') {
2314: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2315: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2316: } else {
1.492 raeburn 2317: if ($allmaps->{$ressrc}) {
1.529 raeburn 2318: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2319: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2320: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2321: } else {
2322: $addedmaps->{$ressrc} = [$url];
2323: }
1.488 raeburn 2324: }
1.492 raeburn 2325: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2326: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2327: }
1.492 raeburn 2328: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2329: if ($folder =~ /^supplemental/) {
1.492 raeburn 2330: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2331: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2332: } else {
2333: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2334: }
1.488 raeburn 2335: }
2336: }
2337: }
2338: }
2339: return;
2340: }
2341:
2342: sub url_paste_fixups {
1.533 raeburn 2343: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2344: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2345: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2346: my $checktitle;
2347: if (($prefixchg) &&
1.492 raeburn 2348: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2349: $checktitle = 1;
2350: }
1.492 raeburn 2351: my $skip;
2352: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2353: my $mapid = $1.$2;
2354: if ($tomove->{$mapid}) {
2355: $skip = 1;
2356: }
2357: }
1.491 raeburn 2358: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2359: return if ($file eq '-1');
2360: my $parser = HTML::TokeParser->new(\$file);
2361: $parser->attr_encoded(1);
1.491 raeburn 2362: my $changed = 0;
1.488 raeburn 2363: while (my $token = $parser->get_token) {
2364: next if ($token->[0] ne 'S');
2365: if ($token->[1] eq 'resource') {
2366: my $ressrc = $token->[2]->{'src'};
2367: next if ($ressrc eq '');
1.491 raeburn 2368: my $id = $token->[2]->{'id'};
1.492 raeburn 2369: my $title = $token->[2]->{'title'};
1.491 raeburn 2370: if ($checktitle) {
2371: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2372: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2373: }
2374: }
1.488 raeburn 2375: next if ($token->[2]->{'type'} eq 'external');
2376: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2377: next if ($skip);
1.532 raeburn 2378: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2379: $changed = 1;
2380: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2381: my $srcdom = $1;
2382: my $srcnum = $2;
1.488 raeburn 2383: my $rem = $3;
1.492 raeburn 2384: my $newurl;
2385: my $mapname;
2386: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2387: my $prefix = $1;
2388: $mapname = $prefix.$2;
2389: if ($tomove->{$mapname}) {
1.533 raeburn 2390: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2391: $srcdom,$srcnum,$allmaps,$rewrites,
2392: $retitles,$copies,$dbcopies,$zombies,
2393: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2394: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2395: next;
2396: } else {
2397: ($newurl,my $error) =
2398: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2399: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2400: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2401: $newsubdir->{$ressrc} = $1;
2402: }
2403: if ($error) {
2404: next;
2405: }
2406: }
2407: }
2408: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2409: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2410:
1.488 raeburn 2411: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2412: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2413: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2414: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2415: $cnum,$srcdom,$srcnum,$allmaps,
2416: $rewrites,$retitles,$copies,$dbcopies,
2417: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2418: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2419: $mapmoves->{$ressrc} = 1;
2420: }
2421: $changed = 1;
1.488 raeburn 2422: } else {
1.532 raeburn 2423: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2424: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2425: $changed = 1;
1.488 raeburn 2426: }
2427: }
1.533 raeburn 2428: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2429: next if ($skip);
1.492 raeburn 2430: my $srcdom = $1;
2431: my $srcnum = $2;
2432: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2433: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2434: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2435: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2436: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2437: $changed = 1;
2438: }
2439: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2440: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2441: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2442: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2443: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2444: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2445: $changed = 1;
1.488 raeburn 2446: }
1.597 raeburn 2447: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2448: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2449: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2450: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2451: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2452: }
1.488 raeburn 2453: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2454: next if ($skip);
2455: my $srcdom = $1;
2456: my $srcnum = $2;
2457: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2458: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2459: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2460: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2461: $changed = 1;
1.488 raeburn 2462: }
2463: }
2464: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2465: next if ($skip);
1.488 raeburn 2466: my $to = $token->[2]->{'to'};
2467: if ($to ne '') {
2468: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2469: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2470: } else {
2471: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2472: }
2473: }
2474: }
2475: }
1.491 raeburn 2476: return $changed;
1.488 raeburn 2477: }
2478:
2479: sub apply_fixups {
1.529 raeburn 2480: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2481: $oldurl,$url,$caller) = @_;
2482: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2483: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2484: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2485: if (ref($updated) eq 'HASH') {
2486: if (ref($updated->{'rewrites'}) eq 'HASH') {
2487: %rewrites = %{$updated->{'rewrites'}};
2488: }
2489: if (ref($updated->{'zombies'}) eq 'HASH') {
2490: %zombies = %{$updated->{'zombies'}};
2491: }
2492: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2493: %removefrommap = %{$updated->{'removefrommap'}};
2494: }
2495: if (ref($updated->{'removeparam'}) eq 'HASH') {
2496: %removeparam = %{$updated->{'removeparam'}};
2497: }
2498: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2499: %dbcopies = %{$updated->{'dbcopies'}};
2500: }
2501: if (ref($updated->{'retitles'}) eq 'HASH') {
2502: %retitles = %{$updated->{'retitles'}};
2503: }
1.597 raeburn 2504: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2505: %resdatacopy = %{$updated->{'resdatacopy'}};
2506: }
1.529 raeburn 2507: }
2508: if (ref($info) eq 'HASH') {
2509: if (ref($info->{'newsubdir'}) eq 'HASH') {
2510: %newsubdir = %{$info->{'newsubdir'}};
2511: }
2512: if (ref($info->{'params'}) eq 'HASH') {
2513: %params = %{$info->{'params'}};
2514: }
2515: if (ref($info->{'before'}) eq 'HASH') {
2516: %before = %{$info->{'before'}};
2517: }
2518: if (ref($info->{'after'}) eq 'HASH') {
2519: %after = %{$info->{'after'}};
2520: }
2521: }
2522: if (ref($moves) eq 'HASH') {
2523: if (ref($moves->{'copies'}) eq 'HASH') {
2524: %copies = %{$moves->{'copies'}};
2525: }
2526: if (ref($moves->{'docmoves'}) eq 'HASH') {
2527: %docmoves = %{$moves->{'docmoves'}};
2528: }
2529: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2530: %mapmoves = %{$moves->{'mapmoves'}};
2531: }
2532: }
2533: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2534: my @allcopies;
1.529 raeburn 2535: if (exists($copies{$key})) {
2536: if (ref($copies{$key}) eq 'HASH') {
2537: my %added;
2538: foreach my $innerkey (keys(%{$copies{$key}})) {
2539: if (($innerkey ne '') && (!$added{$innerkey})) {
2540: push(@allcopies,$innerkey);
2541: $added{$innerkey} = 1;
2542: }
1.491 raeburn 2543: }
1.529 raeburn 2544: undef(%added);
1.491 raeburn 2545: }
2546: }
2547: if ($key eq $oldurl) {
1.529 raeburn 2548: if ((exists($docmoves{$key}))) {
1.532 raeburn 2549: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2550: push(@allcopies,$oldurl);
2551: }
2552: }
2553: }
2554: if (@allcopies > 0) {
2555: foreach my $item (@allcopies) {
1.492 raeburn 2556: my ($relpath,$oldsubdir,$fname) =
2557: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2558: if ($fname ne '') {
2559: my $content = &Apache::lonnet::getfile($item);
2560: unless ($content eq '-1') {
2561: my $storefn;
1.529 raeburn 2562: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2563: $storefn = $docmoves{$key};
1.491 raeburn 2564: } else {
2565: $storefn = $relpath;
2566: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2567: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2568: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2569: }
1.529 raeburn 2570: if ($newsubdir{$key}) {
1.532 raeburn 2571: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2572: }
2573: }
2574: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2575: my $copyurl =
2576: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2577: $storefn.$fname,$content);
2578: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2579: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2580: return &mt('Paste failed: an error occurred copying the file.');
2581: } elsif (ref($errors) eq 'HASH') {
2582: $errors->{$item} = 1;
1.489 raeburn 2583: }
2584: }
1.488 raeburn 2585: }
2586: }
1.491 raeburn 2587: }
2588: }
2589: }
1.529 raeburn 2590: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2591: my $storefn=$key;
2592: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2593: if ($prefixchg && $before{'map'} && $after{'map'}) {
2594: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2595: }
1.529 raeburn 2596: if ($newsubdir{$key}) {
2597: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2598: }
1.491 raeburn 2599: my $mapcontent = &Apache::lonnet::getfile($key);
2600: if ($mapcontent eq '-1') {
2601: if (ref($errors) eq 'HASH') {
2602: $errors->{$key} = 1;
2603: }
2604: } else {
2605: my $newmap =
2606: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2607: $mapcontent);
2608: if ($newmap eq '/adm/notfound.html') {
2609: if (ref($errors) eq 'HASH') {
2610: $errors->{$key} = 1;
1.489 raeburn 2611: }
1.488 raeburn 2612: }
2613: }
2614: }
1.491 raeburn 2615: my %updates;
2616: if ($is_map) {
1.529 raeburn 2617: if (ref($updated) eq 'HASH') {
2618: foreach my $type (keys(%{$updated})) {
2619: if (ref($updated->{$type}) eq 'HASH') {
2620: foreach my $key (keys(%{$updated->{$type}})) {
2621: $updates{$key} = 1;
2622: }
2623: }
2624: }
1.491 raeburn 2625: }
2626: foreach my $key (keys(%updates)) {
1.492 raeburn 2627: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2628: if (ref($rewrites{$key}) eq 'HASH') {
2629: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2630: }
1.529 raeburn 2631: if (ref($retitles{$key}) eq 'HASH') {
2632: %toretitle = %{$retitles{$key}};
1.491 raeburn 2633: }
1.529 raeburn 2634: if (ref($removefrommap{$key}) eq 'HASH') {
2635: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2636: }
1.529 raeburn 2637: if (ref($removeparam{$key}) eq 'HASH') {
2638: %remparam = %{$removeparam{$key}};
1.492 raeburn 2639: }
1.529 raeburn 2640: if (ref($zombies{$key}) eq 'HASH') {
2641: %zombie = %{$zombies{$key}};
1.491 raeburn 2642: }
1.529 raeburn 2643: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2644: foreach my $idx (keys(%{$dbcopies{$key}})) {
2645: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2646: my ($newurl,$result,$errtext) =
2647: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2648: if ($result eq 'ok') {
2649: $newdb{$idx} = $newurl;
2650: } elsif (ref($errors) eq 'HASH') {
2651: $errors->{$key} = 1;
2652: }
2653: push(@msgs,$errtext);
2654: }
1.491 raeburn 2655: }
2656: }
1.597 raeburn 2657: if (ref($resdatacopy{$key}) eq 'HASH') {
2658: if ($newsubdir{$key}) {
2659:
2660: }
2661: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2662: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2663: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2664: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2665: my $template = $1;
2666: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2667: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2668: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2669: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2670: my ($newmapname) = ($key =~ m{/([^/]+)$});
2671: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2672: my $srcmapinfo = $srcfolder.':'.$idx;
2673: if ($srccontainer eq 'page') {
2674: $srcmapinfo .= ':1';
2675: }
2676: if ($newsubdir{$key}) {
2677: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2678: }
2679: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2680: $cnum,$template,$idx,$newmapname);
2681: }
2682: }
2683: }
2684: }
2685: }
1.529 raeburn 2686: if (ref($params{$key}) eq 'HASH') {
2687: %currparam = %{$params{$key}};
1.492 raeburn 2688: }
2689: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2690: if ($fatal) {
1.533 raeburn 2691: return ($errtext);
1.492 raeburn 2692: }
2693: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2694: if (defined($LONCAPA::map::zombies[$i])) {
2695: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2696: if ($zombie{$i} eq $src) {
1.492 raeburn 2697: undef($LONCAPA::map::zombies[$i]);
2698: }
2699: }
2700: }
1.529 raeburn 2701: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2702: my $idx = $LONCAPA::map::order[$i];
2703: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2704: my $changed;
1.529 raeburn 2705: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2706: if ((exists($toremove{$idx})) &&
2707: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2708: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2709: if (ref($currparam{$idx}) eq 'ARRAY') {
2710: foreach my $name (@{$currparam{$idx}}) {
2711: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2712: }
2713: }
2714: next;
2715: }
2716: my $origsrc = $src;
1.532 raeburn 2717: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2718: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2719: $changed = 1;
1.491 raeburn 2720: }
1.492 raeburn 2721: }
1.532 raeburn 2722: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2723: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2724: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2725: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2726: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2727: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2728: } else {
1.529 raeburn 2729: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2730: }
1.491 raeburn 2731: }
1.532 raeburn 2732: if ($origsrc =~ /\.(page|sequence)$/) {
2733: if ($newsubdir{$origsrc}) {
1.529 raeburn 2734: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2735: }
1.532 raeburn 2736: } elsif ($newsubdir{$key}) {
2737: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2738: }
2739: }
1.492 raeburn 2740: $changed = 1;
1.533 raeburn 2741: } elsif ($newdb{$idx} ne '') {
2742: $src = $newdb{$idx};
1.492 raeburn 2743: $changed = 1;
2744: }
2745: if ($changed) {
1.538 raeburn 2746: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2747: }
2748: }
2749: }
2750: foreach my $idx (keys(%remparam)) {
2751: if (ref($remparam{$idx}) eq 'ARRAY') {
2752: foreach my $name (@{$remparam{$idx}}) {
2753: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2754: }
2755: }
2756: }
1.533 raeburn 2757: if (values(%lockerrors) > 0) {
2758: $lockmsg = join('<br />',values(%lockerrors));
2759: }
1.491 raeburn 2760: my $storefn;
2761: if ($key eq $oldurl) {
2762: $storefn = $url;
2763: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2764: } else {
2765: $storefn = $key;
2766: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2767: if ($prefixchg && $before{'map'} && $after{'map'}) {
2768: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2769: }
1.529 raeburn 2770: if ($newsubdir{$key}) {
2771: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2772: }
1.491 raeburn 2773: }
1.492 raeburn 2774: my $report;
2775: if ($folder !~ /^supplemental/) {
2776: $report = 1;
2777: }
1.527 raeburn 2778: (my $outtext,$errtext) =
1.492 raeburn 2779: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2780: if ($errtext) {
1.529 raeburn 2781: if ($caller eq 'paste') {
1.533 raeburn 2782: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2783: }
1.491 raeburn 2784: }
2785: }
2786: }
1.533 raeburn 2787: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2788: }
2789:
2790: sub copy_dependencies {
2791: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2792: my $content;
2793: if (ref($contentref)) {
2794: $content = $$contentref;
2795: } else {
2796: $content = &Apache::lonnet::getfile($item);
2797: }
2798: unless ($content eq '-1') {
2799: my $mm = new File::MMagic;
2800: my $mimetype = $mm->checktype_contents($content);
2801: if ($mimetype eq 'text/html') {
2802: my (%allfiles,%codebase,$state);
2803: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2804: if ($res eq 'ok') {
2805: my ($numexisting,$numpathchanges,$existing);
2806: (undef,$numexisting,$numpathchanges,$existing) =
2807: &Apache::loncommon::ask_for_embedded_content(
2808: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2809: {'error_on_invalid_names' => 1,
2810: 'ignore_remote_references' => 1,
2811: 'docs_url' => $item,
2812: 'context' => 'paste'});
2813: if ($numexisting > 0) {
2814: if (ref($existing) eq 'HASH') {
2815: foreach my $dep (keys(%{$existing})) {
2816: my $depfile = $dep;
2817: unless ($depfile =~ m{^\Q$relpath\E}) {
2818: $depfile = $relpath.$dep;
2819: }
2820: my $depcontent = &Apache::lonnet::getfile($depfile);
2821: unless ($depcontent eq '-1') {
2822: my $storedep = $dep;
2823: $storedep =~ s{^\Q$relpath\E}{};
2824: my $dep_url =
2825: &Apache::lonclonecourse::writefile(
2826: $env{'request.course.id'},
2827: $storefn.$storedep,$depcontent);
2828: if ($dep_url eq '/adm/notfound.html') {
2829: if (ref($errors) eq 'HASH') {
2830: $errors->{$depfile} = 1;
2831: }
2832: } else {
2833: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2834: }
2835: }
2836: }
1.488 raeburn 2837: }
2838: }
2839: }
2840: }
2841: }
2842: return;
2843: }
2844:
1.329 droeschl 2845: my %parameter_type = ( 'randompick' => 'int_pos',
2846: 'hiddenresource' => 'string_yesno',
2847: 'encrypturl' => 'string_yesno',
2848: 'randomorder' => 'string_yesno',);
2849: my $valid_parameters_re = join('|',keys(%parameter_type));
2850: # set parameters
2851: sub update_parameter {
1.537 raeburn 2852: if ($env{'form.changeparms'} eq 'all') {
2853: my (@allidx,@allmapidx,%allchecked,%currchecked);
2854: %allchecked = (
2855: 'hiddenresource' => {},
2856: 'encrypturl' => {},
2857: 'randompick' => {},
2858: 'randomorder' => {},
2859: );
2860: foreach my $which (keys(%allchecked)) {
2861: $env{'form.all'.$which} =~ s/,$//;
2862: if ($which eq 'randompick') {
2863: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2864: my ($res,$value) = split(/:/,$item);
2865: if ($value =~ /^\d+$/) {
2866: $allchecked{$which}{$res} = $value;
2867: }
2868: }
2869: } else {
1.539 raeburn 2870: if ($env{'form.all'.$which}) {
2871: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2872: }
1.537 raeburn 2873: }
2874: }
2875: my $haschanges = 0;
2876: foreach my $res (@LONCAPA::map::order) {
2877: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2878: $name=&LONCAPA::map::qtescape($name);
2879: $url=&LONCAPA::map::qtescape($url);
2880: next unless ($name && $url);
2881: my $is_map;
2882: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2883: $is_map = 1;
2884: }
2885: foreach my $which (keys(%allchecked)) {
2886: if (($which eq 'randompick' || $which eq 'randomorder')) {
2887: next if (!$is_map);
2888: }
2889: my $oldvalue = 0;
2890: my $newvalue = 0;
2891: if ($allchecked{$which}{$res}) {
2892: $newvalue = $allchecked{$which}{$res};
2893: }
2894: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2895: if ($which eq 'randompick') {
2896: if ($current =~ /^(\d+)$/) {
2897: $oldvalue = $1;
2898: }
2899: } else {
2900: if ($current =~ /^yes$/i) {
2901: $oldvalue = 1;
2902: }
2903: }
2904: if ($oldvalue ne $newvalue) {
2905: $haschanges = 1;
2906: if ($newvalue) {
2907: my $storeval = 'yes';
2908: if ($which eq 'randompick') {
2909: $storeval = $newvalue;
2910: }
2911: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2912: $storeval,
2913: $parameter_type{$which});
2914: &remember_parms($res,$which,'set',$storeval);
2915: } elsif ($oldvalue) {
2916: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2917: &remember_parms($res,$which,'del');
2918: }
2919: }
2920: }
2921: }
2922: return $haschanges;
2923: } else {
1.588 raeburn 2924: my $haschanges = 0;
2925: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2926:
1.537 raeburn 2927: my $which = $env{'form.changeparms'};
2928: my $idx = $env{'form.setparms'};
1.588 raeburn 2929: my $oldvalue = 0;
2930: my $newvalue = 0;
2931: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2932: if ($which eq 'randompick') {
2933: if ($current =~ /^(\d+)$/) {
2934: $oldvalue = $1;
2935: }
2936: } elsif ($current =~ /^yes$/i) {
2937: $oldvalue = 1;
2938: }
1.537 raeburn 2939: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2940: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2941: : 1;
2942: }
2943: if ($oldvalue ne $newvalue) {
2944: $haschanges = 1;
2945: if ($newvalue) {
2946: my $storeval = 'yes';
2947: if ($which eq 'randompick') {
2948: $storeval = $newvalue;
2949: }
2950: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2951: $parameter_type{$which});
2952: &remember_parms($idx,$which,'set',$storeval);
2953: } else {
2954: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2955: &remember_parms($idx,$which,'del');
2956: }
1.537 raeburn 2957: }
1.588 raeburn 2958: return $haschanges;
1.329 droeschl 2959: }
2960: }
2961:
2962: sub handle_edit_cmd {
2963: my ($coursenum,$coursedom) =@_;
1.543 raeburn 2964: if ($env{'form.cmd'} eq '') {
2965: return 0;
2966: }
1.329 droeschl 2967: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2968:
2969: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2970: my ($title, $url, @rrest) = split(':', $ratstr);
2971:
1.538 raeburn 2972: if ($cmd eq 'remove') {
1.329 droeschl 2973: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2974: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2975: &Apache::lonnet::removeuploadedurl($url);
2976: } else {
2977: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2978: }
2979: splice(@LONCAPA::map::order, $idx, 1);
2980:
2981: } elsif ($cmd eq 'cut') {
2982: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2983: splice(@LONCAPA::map::order, $idx, 1);
2984:
1.344 bisitz 2985: } elsif ($cmd eq 'up'
1.329 droeschl 2986: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2987: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2988:
2989: } elsif ($cmd eq 'down'
2990: && defined($LONCAPA::map::order[$idx+1])) {
2991: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2992:
2993: } elsif ($cmd eq 'rename') {
2994: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2995: if ($comment=~/\S/) {
2996: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2997: $comment.':'.join(':', $url, @rrest);
2998: }
2999: # Devalidate title cache
3000: my $renamed_url=&LONCAPA::map::qtescape($url);
3001: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 3002:
1.329 droeschl 3003: } else {
3004: return 0;
3005: }
3006: return 1;
3007: }
3008:
3009: sub editor {
1.458 raeburn 3010: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3011: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3012: $canedit,$navmapref,$hiddentop)=@_;
1.519 raeburn 3013: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3014: if ($allowed) {
1.519 raeburn 3015: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3016: $is_random_order,$container) =
1.510 raeburn 3017: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3018: $r->print($breadcrumbtrail);
1.519 raeburn 3019: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3020: $container = 'page';
3021: } else {
3022: $container = 'sequence';
1.510 raeburn 3023: }
1.484 raeburn 3024:
1.525 raeburn 3025: my $jumpto;
3026:
3027: unless ($supplementalflag) {
1.546 raeburn 3028: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3029: }
1.484 raeburn 3030:
3031: unless ($allowed) {
3032: $randompick = -1;
3033: }
3034:
1.615 raeburn 3035: my ($errtext,$fatal);
3036: if (($folder eq '') && (!$supplementalflag)) {
3037: if (@LONCAPA::map::order) {
3038: undef(@LONCAPA::map::order);
3039: undef(@LONCAPA::map::resources);
3040: undef(@LONCAPA::map::resparms);
3041: undef(@LONCAPA::map::zombies);
3042: }
3043: $folder = 'default';
3044: $container = 'sequence';
3045: } else {
3046: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3047: $folder.'.'.$container);
3048: return $errtext if ($fatal);
3049: }
1.329 droeschl 3050:
3051: if ($#LONCAPA::map::order<1) {
3052: my $idx=&LONCAPA::map::getresidx();
3053: if ($idx<=0) { $idx=1; }
3054: $LONCAPA::map::order[0]=$idx;
3055: $LONCAPA::map::resources[$idx]='';
3056: }
1.364 bisitz 3057:
1.329 droeschl 3058: # ------------------------------------------------------------ Process commands
3059:
3060: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3061: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3062: # set parameters and change order
3063: &snapshotbefore();
3064:
3065: if (&update_parameter()) {
1.588 raeburn 3066: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3067: return $errtext if ($fatal);
3068: }
3069:
3070: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3071: # change order
3072: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3073: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3074:
3075: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3076: return $errtext if ($fatal);
3077: }
1.364 bisitz 3078:
1.329 droeschl 3079: if ($env{'form.pastemarked'}) {
1.491 raeburn 3080: my %paste_errors;
1.533 raeburn 3081: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3082: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3083: \%paste_errors);
1.541 raeburn 3084: if (ref($pastemsgarray) eq 'ARRAY') {
3085: if (@{$pastemsgarray} > 0) {
3086: $r->print('<p class="LC_info">'.
3087: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3088: '</p>');
3089: }
1.541 raeburn 3090: }
3091: if ($lockerror) {
3092: $r->print('<p class="LC_error">'.
3093: $lockerror.
3094: '</p>');
3095: }
3096: if ($save_error ne '') {
3097: return $save_error;
3098: }
3099: if ($paste_res) {
3100: my %errortext = &Apache::lonlocal::texthash (
3101: fail => 'Storage of folder contents failed',
3102: failread => 'Reading folder contents failed',
3103: failstore => 'Storage of folder contents failed',
3104: );
3105: if ($errortext{$paste_res}) {
3106: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3107: }
1.329 droeschl 3108: }
1.491 raeburn 3109: if (keys(%paste_errors) > 0) {
1.538 raeburn 3110: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3111: &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".
3112: '<ul>'."\n");
3113: foreach my $key (sort(keys(%paste_errors))) {
3114: $r->print('<li>'.$key.'</li>'."\n");
3115: }
3116: $r->print('</ul></p>'."\n");
3117: }
1.538 raeburn 3118: } elsif ($env{'form.clearmarked'}) {
3119: my $output = &do_buffer_empty();
3120: if ($output) {
3121: $r->print('<p class="LC_info">'.$output.'</p>');
3122: }
3123: }
1.329 droeschl 3124:
3125: $r->print($upload_output);
3126:
1.538 raeburn 3127: # Rename, cut, copy or remove a single resource
1.602 raeburn 3128: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3129: my $contentchg;
1.592 raeburn 3130: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 3131: $contentchg = 1;
3132: }
3133: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3134: return $errtext if ($fatal);
3135: }
1.538 raeburn 3136:
3137: # Cut, copy and/or remove multiple resources
3138: if ($env{'form.multichange'}) {
3139: my %allchecked = (
3140: cut => {},
3141: remove => {},
3142: );
3143: my $needsupdate;
3144: foreach my $which (keys(%allchecked)) {
3145: $env{'form.multi'.$which} =~ s/,$//;
3146: if ($env{'form.multi'.$which}) {
3147: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3148: if (ref($allchecked{$which}) eq 'HASH') {
3149: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3150: }
3151: }
3152: }
3153: if ($needsupdate) {
3154: my $haschanges = 0;
3155: my %curr_groups = &Apache::longroup::coursegroups();
3156: my $total = scalar(@LONCAPA::map::order) - 1;
3157: for (my $i=$total; $i>=0; $i--) {
3158: my $res = $LONCAPA::map::order[$i];
3159: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3160: $name=&LONCAPA::map::qtescape($name);
3161: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3162: next unless $url;
1.538 raeburn 3163: my %denied =
3164: &action_restrictions($coursenum,$coursedom,$url,
3165: $env{'form.folderpath'},\%curr_groups);
3166: foreach my $which (keys(%allchecked)) {
3167: next if ($denied{$which});
3168: next unless ($allchecked{$which}{$res});
3169: if ($which eq 'remove') {
3170: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3171: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3172: &Apache::lonnet::removeuploadedurl($url);
3173: } else {
3174: &LONCAPA::map::makezombie($res);
3175: }
3176: splice(@LONCAPA::map::order,$i,1);
3177: $haschanges ++;
3178: } elsif ($which eq 'cut') {
3179: &LONCAPA::map::makezombie($res);
3180: splice(@LONCAPA::map::order,$i,1);
3181: $haschanges ++;
3182: }
3183: }
3184: }
3185: if ($haschanges) {
3186: ($errtext,$fatal) =
3187: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3188: return $errtext if ($fatal);
3189: }
3190: }
3191: }
3192:
1.329 droeschl 3193: # Group import/search
3194: if ($env{'form.importdetail'}) {
3195: my @imports;
3196: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3197: if (defined($item)) {
3198: my ($name,$url,$residx)=
1.533 raeburn 3199: map { &unescape($_); } split(/\=/,$item);
3200: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3201: my ($suffix,$errortxt,$locknotfreed) =
3202: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3203: if ($locknotfreed) {
3204: $r->print($locknotfreed);
3205: }
3206: if ($suffix) {
3207: $url =~ s/_new\./_$suffix./;
3208: } else {
3209: return $errortxt;
3210: }
1.533 raeburn 3211: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3212: my $type = $1;
3213: my ($suffix,$errortxt,$locknotfreed) =
3214: &new_timebased_suffix($coursedom,$coursenum,$type);
3215: if ($locknotfreed) {
3216: $r->print($locknotfreed);
3217: }
3218: if ($suffix) {
3219: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3220: } else {
3221: return $errortxt;
3222: }
1.598 raeburn 3223: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
3224: my ($suffix,$errortxt,$locknotfreed) =
3225: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3226: if ($locknotfreed) {
3227: $r->print($locknotfreed);
3228: }
3229: if ($suffix) {
3230: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3231: } else {
3232: return $errortxt;
3233: }
1.534 raeburn 3234: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3235: if ($supplementalflag) {
3236: next unless ($1 eq 'supplemental');
3237: if ($folder eq 'supplemental') {
3238: next unless ($2 eq 'default');
3239: } else {
3240: next unless ($folder eq 'supplemental_'.$2);
3241: }
3242: } else {
3243: next unless ($1 eq 'docs');
3244: if ($folder eq 'default') {
3245: next unless ($2 eq 'default');
3246: } else {
3247: next unless ($folder eq 'default_'.$2);
3248: }
3249: }
1.504 raeburn 3250: }
1.329 droeschl 3251: push(@imports, [$name, $url, $residx]);
3252: }
3253: }
1.530 raeburn 3254: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3255: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3256: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3257: return $errtext if ($fatal);
1.529 raeburn 3258: if ($fixuperrors) {
3259: $r->print($fixuperrors);
3260: }
1.329 droeschl 3261: }
3262: # Loading a complete map
3263: if ($env{'form.loadmap'}) {
3264: if ($env{'form.importmap'}=~/\w/) {
3265: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3266: my ($title,$url,$ext,$type)=split(/\:/,$res);
3267: my $idx=&LONCAPA::map::getresidx($url);
3268: $LONCAPA::map::resources[$idx]=$res;
3269: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3270: }
3271: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3272: $folder.'.'.$container,1);
1.329 droeschl 3273: return $errtext if ($fatal);
3274: } else {
3275: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3276:
1.329 droeschl 3277: }
3278: }
3279: &log_differences($plain);
3280: }
3281: # ---------------------------------------------------------------- End commands
3282: # ---------------------------------------------------------------- Print screen
3283: my $idx=0;
3284: my $shown=0;
3285: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3286: $r->print('<div class="LC_Box">'.
1.432 raeburn 3287: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3288: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3289: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3290: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3291: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3292: '</ol>');
1.381 bisitz 3293: if ($randompick>=0) {
3294: $r->print('<p class="LC_warning">'
3295: .&mt('Caution: this folder is set to randomly pick a subset'
3296: .' of resources. Adding or removing resources from this'
3297: .' folder will change the set of resources that the'
3298: .' students see, resulting in spurious or missing credit'
3299: .' for completed problems, not limited to ones you'
3300: .' modify. Do not modify the contents of this folder if'
3301: .' it is in active student use.')
3302: .'</p>'
3303: );
3304: }
3305: if ($is_random_order) {
3306: $r->print('<p class="LC_warning">'
3307: .&mt('Caution: this folder is set to randomly order its'
3308: .' contents. Adding or removing resources from this folder'
3309: .' will change the order of resources shown.')
3310: .'</p>'
3311: );
3312: }
3313: $r->print('</div>');
1.364 bisitz 3314: }
1.381 bisitz 3315:
1.538 raeburn 3316: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3317: %filters = (
1.543 raeburn 3318: canremove => [],
3319: cancut => [],
3320: cancopy => [],
3321: hiddenresource => [],
3322: encrypturl => [],
3323: randomorder => [],
3324: randompick => [],
1.538 raeburn 3325: );
3326: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3327: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3328: foreach my $res (@LONCAPA::map::order) {
3329: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3330: $name=&LONCAPA::map::qtescape($name);
3331: $url=&LONCAPA::map::qtescape($url);
3332: unless ($name) { $name=(split(/\//,$url))[-1]; }
3333: unless ($name) { $idx++; next; }
1.537 raeburn 3334: push(@allidx,$res);
3335: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3336: push(@allmapidx,$res);
3337: }
1.617 raeburn 3338:
1.381 bisitz 3339: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3340: $coursenum,$coursedom,$crstype,
1.538 raeburn 3341: $pathitem,$supplementalflag,$container,
1.620 ! raeburn 3342: \%filters,\%curr_groups,$ltitoolsref,$canedit,
! 3343: $isencrypted,$navmapref);
1.381 bisitz 3344: $idx++;
3345: $shown++;
1.329 droeschl 3346: }
1.424 onken 3347: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3348:
1.538 raeburn 3349: my $need_save;
1.611 raeburn 3350: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3351: my $toolslink;
1.611 raeburn 3352: if ($allowed) {
1.544 raeburn 3353: $toolslink = '<table><tr><td>'
1.520 raeburn 3354: .&Apache::loncommon::help_open_menu('Navigation Screen',
3355: 'Navigation_Screen',undef,'RAT')
3356: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3357: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3358: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3359: .'id="LC_content_toolbar_edittoplevel" '
3360: .'class="LC_toolbarItem" '
3361: .'title="'.&mt('Supplemental Content Editor').'">'
3362: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3363: }
1.510 raeburn 3364: if ($shown) {
3365: if ($allowed) {
3366: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3367: .&Apache::loncommon::start_data_table(undef,'contentlist')
3368: .&Apache::loncommon::start_data_table_header_row()
3369: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3370: .'<th colspan="2">'.&mt('Actions').'</th>'
3371: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3372: if ($folder !~ /^supplemental/) {
3373: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3374: }
1.537 raeburn 3375: $to_show .= &Apache::loncommon::end_data_table_header_row();
3376: if ($folder !~ /^supplemental/) {
1.538 raeburn 3377: $lists{'canhide'} = join(',',@allidx);
3378: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3379: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3380: 'randomorder','randompick');
3381: foreach my $item (@possfilters) {
1.538 raeburn 3382: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3383: if (@{$filters{$item}} > 0) {
3384: $lists{$item} = join(',',@{$filters{$item}});
3385: }
1.538 raeburn 3386: }
3387: }
1.537 raeburn 3388: if (@allidx > 0) {
3389: my $path;
3390: if ($env{'form.folderpath'}) {
3391: $path =
3392: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3393: }
1.538 raeburn 3394: if (@allidx > 1) {
3395: $to_show .=
3396: &Apache::loncommon::continue_data_table_row().
3397: '<td colspan="2"> </td>'.
3398: '<td>'.
1.611 raeburn 3399: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3400: '</td>'.
3401: '<td> </td>'.
3402: '<td> </td>'.
3403: '<td colspan="4">'.
1.611 raeburn 3404: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3405: '</td>'.
3406: &Apache::loncommon::end_data_table_row();
3407: $need_save = 1;
3408: }
1.537 raeburn 3409: }
3410: }
3411: $to_show .= $output.' '
1.510 raeburn 3412: .&Apache::loncommon::end_data_table()
3413: .'<br style="line-height:2px;" />'
3414: .&Apache::loncommon::end_scrollbox();
3415: } else {
1.520 raeburn 3416: $to_show .= $toolslink
1.510 raeburn 3417: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3418: .$output.' '
3419: .&Apache::loncommon::end_data_table();
1.393 raeburn 3420: }
1.510 raeburn 3421: } else {
1.520 raeburn 3422: if (!$allowed) {
3423: $to_show .= $toolslink;
3424: }
1.615 raeburn 3425: my $noresmsg;
3426: if ($allowed && $hiddentop && !$supplementalflag) {
3427: $noresmsg = &mt('Main Content Hidden');
3428: } else {
3429: $noresmsg = &mt('Currently empty');
3430: }
1.510 raeburn 3431: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3432: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3433: .$noresmsg
1.510 raeburn 3434: .'</div>'
3435: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3436: }
3437: } else {
1.510 raeburn 3438: if ($shown) {
3439: $to_show = '<div>'
3440: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3441: .$output
3442: .&Apache::loncommon::end_data_table()
3443: .'</div>';
3444: } else {
3445: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3446: .&mt('Currently empty')
1.510 raeburn 3447: .'</div>'
3448: }
1.458 raeburn 3449: }
3450: my $tid = 1;
3451: if ($supplementalflag) {
3452: $tid = 2;
1.329 droeschl 3453: }
3454: if ($allowed) {
1.484 raeburn 3455: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3456: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3457: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3458: if ($canedit) {
3459: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3460: }
1.460 raeburn 3461: } else {
3462: $r->print($to_show);
1.329 droeschl 3463: }
3464: return;
3465: }
3466:
1.538 raeburn 3467: sub multiple_check_form {
1.611 raeburn 3468: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3469: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3470: my $disabled;
3471: unless ($canedit) {
3472: $disabled = 'disabled="disabled"';
3473: }
1.538 raeburn 3474: my $output =
3475: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3476: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3477: '<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>'.
3478: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3479: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3480: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3481: if ($caller eq 'settings') {
3482: $output .=
3483: '<table><tr>'.
3484: '<td class="LC_docs_entry_parameter">'.
3485: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3486: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3487: '</label></span></td>'.
3488: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3489: '<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 3490: '</span></td>'.
3491: '</tr>'."\n".
3492: '<tr>'.
3493: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3494: '<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 3495: '</label></span>'.
3496: '</td></tr></table>'."\n";
3497: } else {
3498: $output .=
3499: '<table><tr>'.
3500: '<td class="LC_docs_entry_parameter">'.
3501: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3502: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3503: '</label></span></td>'.
3504: '<td class="LC_docs_entry_parameter">'.
3505: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3506: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3507: '</label></span></td>'."\n".
3508: '<td class="LC_docs_entry_parameter">'.
3509: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3510: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3511: '</label></span></td>'.
3512: '</tr></table>'."\n";
3513: }
3514: $output .=
3515: '</fieldset>'.
3516: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3517: if ($caller eq 'settings') {
3518: $output .=
1.543 raeburn 3519: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3520: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3521: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3522: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3523: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3524: } elsif ($caller eq 'actions') {
3525: $output .=
3526: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3527: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3528: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3529: }
3530: $output .=
3531: '</form>'.
3532: '</div>';
3533: return $output;
3534: }
3535:
1.329 droeschl 3536: sub process_file_upload {
1.552 raeburn 3537: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3538: # upload a file, if present
1.552 raeburn 3539: my $filesize = length($env{'form.uploaddoc'});
3540: if (!$filesize) {
3541: $$upload_output = '<div class="LC_error">'.
3542: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3543: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3544: $filesize).'<br />'.
3545: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3546: '</div>';
3547: return;
3548: }
3549: my $quotatype = 'unofficial';
3550: if ($crstype eq 'Community') {
1.601 raeburn 3551: $quotatype = 'community';
3552: } elsif ($crstype eq 'Placement') {
3553: $quotatype = 'placement';
1.580 raeburn 3554: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3555: $quotatype = 'official';
1.573 raeburn 3556: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3557: $quotatype = 'textbook';
1.552 raeburn 3558: }
3559: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3560: $filesize = int($filesize/1000); #expressed in kb
3561: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3562: $env{'form.uploaddoc.filename'},$filesize,
3563: 'upload',$quotatype);
1.552 raeburn 3564: return if ($$upload_output);
3565: }
1.440 raeburn 3566: my ($parseaction,$showupload,$nextphase,$mimetype);
3567: if ($env{'form.parserflag'}) {
1.329 droeschl 3568: $parseaction = 'parse';
3569: }
3570: my $folder=$env{'form.folder'};
3571: if ($folder eq '') {
3572: $folder='default';
3573: }
3574: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3575: my $errtext='';
3576: my $fatal=0;
3577: my $container='sequence';
1.519 raeburn 3578: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3579: $container='page';
3580: }
3581: ($errtext,$fatal)=
1.534 raeburn 3582: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3583: if ($#LONCAPA::map::order<1) {
3584: $LONCAPA::map::order[0]=1;
3585: $LONCAPA::map::resources[1]='';
3586: }
3587: my $destination = 'docs/';
3588: if ($folder =~ /^supplemental/) {
3589: $destination = 'supplemental/';
3590: }
3591: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3592: $destination .= 'default/';
3593: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3594: $destination .= $2.'/';
3595: }
1.534 raeburn 3596: if ($fatal) {
3597: $$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>';
3598: return;
3599: }
1.440 raeburn 3600: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3601: my $newidx=&LONCAPA::map::getresidx();
3602: $destination .= $newidx;
1.439 raeburn 3603: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3604: $parseaction,$allfiles,
1.440 raeburn 3605: $codebase,undef,undef,undef,undef,
3606: undef,undef,\$mimetype);
3607: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3608: my $stored = $1;
3609: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3610: $stored.'</span>').'</p>';
3611: } else {
3612: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3613:
1.457 raeburn 3614: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3615: return;
3616: }
1.329 droeschl 3617: my $ext='false';
3618: if ($url=~m{^http://}) { $ext='true'; }
3619: $url = &LONCAPA::map::qtunescape($url);
3620: my $comment=$env{'form.comment'};
3621: $comment = &LONCAPA::map::qtunescape($comment);
3622: if ($folder=~/^supplemental/) {
3623: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3624: $env{'user.domain'}.'___&&&___'.$comment;
3625: }
3626:
3627: $LONCAPA::map::resources[$newidx]=
3628: $comment.':'.$url.':'.$ext.':normal:res';
3629: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3630: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3631: $folder.'.'.$container,1);
1.329 droeschl 3632: if ($fatal) {
1.457 raeburn 3633: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3634: return;
1.329 droeschl 3635: } else {
1.440 raeburn 3636: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3637: $$upload_output = $showupload;
1.384 raeburn 3638: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3639: if ($total_embedded > 0) {
1.440 raeburn 3640: my $uploadphase = 'upload_embedded';
3641: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3642: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3643: my ($embedded,$num) =
3644: &Apache::loncommon::ask_for_embedded_content(
3645: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3646: if ($embedded) {
3647: if ($num) {
3648: $$upload_output .=
3649: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3650: $nextphase = $uploadphase;
3651: } else {
3652: $$upload_output .= $embedded;
3653: }
3654: } else {
3655: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3656: }
1.329 droeschl 3657: } else {
1.440 raeburn 3658: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3659: }
1.457 raeburn 3660: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3661: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3662: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3663: $nextphase = 'decompress_uploaded';
3664: my $position = scalar(@LONCAPA::map::order)-1;
3665: my $noextract = &return_to_editor();
3666: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3667: my %archiveitems = (
3668: folderpath => $env{'form.folderpath'},
3669: cmd => $nextphase,
3670: newidx => $newidx,
3671: position => $position,
3672: phase => $nextphase,
1.477 raeburn 3673: comment => $comment,
1.480 raeburn 3674: );
3675: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3676: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3677: $$upload_output = $showupload.
3678: &Apache::loncommon::decompress_form($mimetype,
3679: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3680: \%archiveitems,\@current);
1.329 droeschl 3681: }
3682: }
3683: }
1.440 raeburn 3684: return $nextphase;
1.329 droeschl 3685: }
3686:
1.480 raeburn 3687: sub get_dir_list {
3688: my ($url,$coursenum,$coursedom,$newidx) = @_;
3689: my ($destination,$dir_root) = &embedded_destination();
3690: my ($dirlistref,$listerror) =
3691: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3692: my @dir_lines;
3693: my $dirptr=16384;
3694: if (ref($dirlistref) eq 'ARRAY') {
3695: foreach my $dir_line (sort
3696: {
3697: my ($afile)=split('&',$a,2);
3698: my ($bfile)=split('&',$b,2);
3699: return (lc($afile) cmp lc($bfile));
3700: } (@{$dirlistref})) {
3701: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3702: $filename =~ s/\s+$//;
3703: next if ($filename =~ /^\.\.?$/);
3704: my $isdir = 0;
3705: if ($dirptr&$testdir) {
3706: $isdir = 1;
3707: }
3708: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3709: }
3710: }
3711: return @dir_lines;
3712: }
3713:
1.329 droeschl 3714: sub is_supplemental_title {
3715: my ($title) = @_;
3716: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3717: }
3718:
3719: # --------------------------------------------------------------- An entry line
3720:
3721: sub entryline {
1.501 raeburn 3722: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3723: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.615 raeburn 3724: $ltitoolsref,$canedit,$isencrypted,$navmapref)=@_;
1.581 raeburn 3725: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3726: if (&is_supplemental_title($title)) {
1.488 raeburn 3727: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3728: } else {
3729: $title=&HTML::Entities::encode($title,'"<>&\'');
3730: $renametitle=$title;
3731: $foldertitle=$title;
3732: }
3733:
1.611 raeburn 3734: my ($disabled,$readonly,$js_lt);
3735: unless ($canedit) {
3736: $disabled = 'disabled="disabled"';
3737: $readonly = 1;
3738: }
3739:
1.329 droeschl 3740: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3741:
1.329 droeschl 3742: $renametitle=~s/\\/\\\\/g;
3743: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3744: $renametitle=~s/"/%22/g;
1.581 raeburn 3745: $renametitle=~s/ /%20/g;
3746: $oldtitle = $renametitle;
1.576 raeburn 3747: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3748: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3749: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3750: # Edit commands
1.535 raeburn 3751: my ($esc_path, $path, $symb);
1.329 droeschl 3752: if ($env{'form.folderpath'}) {
3753: $esc_path=&escape($env{'form.folderpath'});
3754: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3755: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3756: }
1.505 raeburn 3757: my $isexternal;
1.510 raeburn 3758: if ($residx) {
1.501 raeburn 3759: my $currurl = $url;
3760: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3761: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3762: $isexternal = 1;
3763: }
1.510 raeburn 3764: if (!$supplementalflag) {
3765: my $path = 'uploaded/'.
3766: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3767: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3768: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3769: $residx,
3770: &Apache::lonnet::declutter($currurl));
3771: }
1.501 raeburn 3772: }
1.538 raeburn 3773: my ($renamelink,%lt,$ishash);
3774: if (ref($filtersref) eq 'HASH') {
3775: $ishash = 1;
3776: }
3777:
1.329 droeschl 3778: if ($allowed) {
1.538 raeburn 3779: $form_start = '
3780: <form action="/adm/coursedocs" method="post">
3781: ';
3782: $form_common=(<<END);
3783: <input type="hidden" name="folderpath" value="$path" />
3784: <input type="hidden" name="symb" value="$symb" />
3785: END
3786: $form_param=(<<END);
3787: <input type="hidden" name="setparms" value="$orderidx" />
3788: <input type="hidden" name="changeparms" value="0" />
3789: END
3790: $form_end = '</form>';
3791:
1.329 droeschl 3792: my $incindex=$index+1;
3793: my $selectbox='';
1.471 raeburn 3794: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3795: ((split(/\:/,
1.344 bisitz 3796: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3797: ne '') &&
1.329 droeschl 3798: ((split(/\:/,
1.344 bisitz 3799: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3800: ne '')) {
3801: $selectbox=
3802: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3803: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3804: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3805: if ($i==$incindex) {
1.358 bisitz 3806: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3807: } else {
3808: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3809: }
3810: }
3811: $selectbox.='</select>';
3812: }
1.501 raeburn 3813: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3814: 'up' => 'Move Up',
3815: 'dw' => 'Move Down',
3816: 'rm' => 'Remove',
3817: 'ct' => 'Cut',
3818: 'rn' => 'Rename',
1.501 raeburn 3819: 'cp' => 'Copy',
3820: 'ex' => 'External Resource',
1.598 raeburn 3821: 'et' => 'External Tool',
1.501 raeburn 3822: 'ed' => 'Edit',
3823: 'pr' => 'Preview',
3824: 'sv' => 'Save',
3825: 'ul' => 'URL',
1.611 raeburn 3826: 'ti' => 'Title',
1.618 raeburn 3827: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3828: );
1.538 raeburn 3829: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3830: $env{'form.folderpath'},
3831: $currgroups);
1.517 raeburn 3832: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3833: my $skip_confirm = 0;
1.603 raeburn 3834: my $confirm_removal = 0;
1.329 droeschl 3835: if ( $folder =~ /^supplemental/
3836: || ($url =~ m{( /smppg$
3837: |/syllabus$
3838: |/aboutme$
3839: |/navmaps$
3840: |/bulletinboard$
1.598 raeburn 3841: |/exttools?$
1.505 raeburn 3842: |\.html$)}x)
3843: || $isexternal) {
1.329 droeschl 3844: $skip_confirm = 1;
3845: }
1.603 raeburn 3846: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3847: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3848: $confirm_removal = 1;
3849: }
1.329 droeschl 3850:
1.538 raeburn 3851: if ($denied{'copy'}) {
1.543 raeburn 3852: $copylink=(<<ENDCOPY)
1.507 raeburn 3853: <span style="visibility: hidden;">$lt{'cp'}</span>
3854: ENDCOPY
3855: } else {
1.538 raeburn 3856: my $formname = 'edit_copy_'.$orderidx;
3857: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3858: $copylink=(<<ENDCOPY);
1.538 raeburn 3859: <form name="$formname" method="post" action="/adm/coursedocs">
3860: $form_common
1.611 raeburn 3861: <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 3862: $form_end
1.329 droeschl 3863: ENDCOPY
1.538 raeburn 3864: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3865: push(@{$filtersref->{'cancopy'}},$orderidx);
3866: }
1.329 droeschl 3867: }
1.538 raeburn 3868: if ($denied{'cut'}) {
1.507 raeburn 3869: $cutlink=(<<ENDCUT);
3870: <span style="visibility: hidden;">$lt{'ct'}</span>
3871: ENDCUT
3872: } else {
1.538 raeburn 3873: my $formname = 'edit_cut_'.$orderidx;
3874: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3875: $cutlink=(<<ENDCUT);
1.538 raeburn 3876: <form name="$formname" method="post" action="/adm/coursedocs">
3877: $form_common
1.542 raeburn 3878: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3879: <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 3880: $form_end
1.329 droeschl 3881: ENDCUT
1.538 raeburn 3882: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3883: push(@{$filtersref->{'cancut'}},$orderidx);
3884: }
1.329 droeschl 3885: }
1.538 raeburn 3886: if ($denied{'remove'}) {
1.507 raeburn 3887: $removelink=(<<ENDREM);
3888: <span style="visibility: hidden;">$lt{'rm'}</a>
3889: ENDREM
3890: } else {
1.538 raeburn 3891: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3892: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3893: $removelink=(<<ENDREM);
1.538 raeburn 3894: <form name="$formname" method="post" action="/adm/coursedocs">
3895: $form_common
1.542 raeburn 3896: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3897: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 3898: <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 3899: $form_end
1.497 raeburn 3900: ENDREM
1.538 raeburn 3901: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3902: push(@{$filtersref->{'canremove'}},$orderidx);
3903: }
1.497 raeburn 3904: }
1.551 raeburn 3905: $renamelink=(<<ENDREN);
1.581 raeburn 3906: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3907: ENDREN
1.611 raeburn 3908: my ($uplink,$downlink);
3909: if ($canedit) {
3910: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3911: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3912: } else {
3913: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3914: $downlink = $uplink;
3915: }
1.329 droeschl 3916: $line.=(<<END);
3917: <td>
1.379 bisitz 3918: <div class="LC_docs_entry_move">
1.611 raeburn 3919: <a href="$uplink">
1.501 raeburn 3920: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3921: </a>
3922: </div>
3923: <div class="LC_docs_entry_move">
1.611 raeburn 3924: <a href="$downlink">
1.501 raeburn 3925: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3926: </a>
3927: </div>
1.329 droeschl 3928: </td>
3929: <td>
3930: $form_start
1.538 raeburn 3931: $form_param
1.478 raeburn 3932: $form_common
1.329 droeschl 3933: $selectbox
3934: $form_end
3935: </td>
1.540 raeburn 3936: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3937: $removelink
1.329 droeschl 3938: $cutlink
3939: $copylink
3940: </td>
3941: END
3942: }
3943: # Figure out what kind of a resource this is
3944: my ($extension)=($url=~/\.(\w+)$/);
3945: my $uploaded=($url=~/^\/*uploaded\//);
3946: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3947: my $isfolder;
3948: my $ispage;
3949: my $containerarg;
1.615 raeburn 3950: my $folderurl;
1.329 droeschl 3951: if ($uploaded) {
1.472 raeburn 3952: if (($extension eq 'sequence') || ($extension eq 'page')) {
3953: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3954: $containerarg = $1;
1.472 raeburn 3955: if ($extension eq 'sequence') {
3956: $icon=$iconpath.'navmap.folder.closed.gif';
3957: $isfolder=1;
3958: } else {
3959: $icon=$iconpath.'page.gif';
3960: $ispage=1;
3961: }
1.615 raeburn 3962: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3963: if ($allowed) {
3964: $url='/adm/coursedocs?';
3965: } else {
3966: $url='/adm/supplemental?';
3967: }
1.329 droeschl 3968: } else {
3969: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3970: }
3971: }
1.364 bisitz 3972:
1.617 raeburn 3973: my ($editlink,$extresform,$anchor,$hiddenres);
1.329 droeschl 3974: my $orig_url = $url;
1.340 raeburn 3975: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 3976: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 3977: if (!$supplementalflag && $residx && $symb) {
3978: if ((!$isfolder) && (!$ispage)) {
3979: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3980: $url=&Apache::lonnet::clutter($url);
3981: if ($url=~/^\/*uploaded\//) {
3982: $url=~/\.(\w+)$/;
3983: my $embstyle=&Apache::loncommon::fileembstyle($1);
3984: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3985: $url='/adm/wrapper'.$url;
3986: } elsif ($embstyle eq 'ssi') {
3987: #do nothing with these
3988: } elsif ($url!~/\.(sequence|page)$/) {
3989: $url='/adm/coursedocs/showdoc'.$url;
3990: }
3991: } elsif ($url=~m|^/ext/|) {
3992: $url='/adm/wrapper'.$url;
1.598 raeburn 3993: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3994: $url='/adm/wrapper'.$url;
3995: }
1.501 raeburn 3996: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 3997: my $shownsymb = $symb;
3998: if ($isexternal) {
3999: if ($url =~ /^([^#]+)#([^#]+)$/) {
4000: $url = $1;
4001: $anchor = $2;
4002: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4003: $shownsymb = $1.&escape('#').$anchor;
4004: }
4005: }
4006: }
1.617 raeburn 4007: unless ($env{'request.role.adv'}) {
4008: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4009: $url = '';
4010: }
4011: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4012: $url = '';
4013: $hiddenres = 1;
4014: }
4015: }
4016: if ($url ne '') {
4017: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4018: }
1.615 raeburn 4019: } elsif (!$env{'request.role.adv'}) {
4020: my $checkencrypt;
4021: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4022: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4023: $checkencrypt = 1;
1.620 ! raeburn 4024: } elsif (ref($navmapref)) {
1.615 raeburn 4025: unless (ref($$navmapref)) {
4026: $$navmapref = Apache::lonnavmaps::navmap->new();
4027: }
4028: if (ref($$navmapref)) {
4029: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4030: $checkencrypt = 1;
4031: }
4032: }
4033: }
4034: if ($checkencrypt) {
4035: my $shownsymb = &Apache::lonenc::encrypted($symb);
4036: my $shownurl = &Apache::lonenc::encrypted($url);
4037: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4038: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4039: if ($env{'request.enc'} ne '') {
4040: delete($env{'request.enc'});
4041: }
4042: } else {
4043: $url='';
1.613 raeburn 4044: }
1.612 raeburn 4045: } else {
4046: $url='';
4047: }
1.501 raeburn 4048: } else {
4049: $url='';
4050: }
1.329 droeschl 4051: }
1.610 raeburn 4052: } elsif ($supplementalflag) {
4053: if ($isexternal) {
4054: if ($url =~ /^([^#]+)#([^#]+)$/) {
4055: $url = $1;
4056: $anchor = $2;
4057: }
4058: }
1.329 droeschl 4059: }
1.615 raeburn 4060: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4061: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4062: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4063: my $foldername=&escape($foldertitle);
4064: my $folderpath=$env{'form.folderpath'};
4065: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4066: if (!$allowed && $supplementalflag) {
1.519 raeburn 4067: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4068: $url.='folderpath='.&escape($folderpath);
4069: } else {
1.617 raeburn 4070: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4071: 'parameter_randompick'))[0];
4072: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4073: 'parameter_randomorder'))[0]=~/^yes$/i);
4074: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4075: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4076: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4077: 'parameter_encrypturl'))[0]=~/^yes$/i);
4078: unless ($hiddenmap) {
1.620 ! raeburn 4079: if (ref($navmapref)) {
! 4080: unless (ref($$navmapref)) {
! 4081: $$navmapref = Apache::lonnavmaps::navmap->new();
! 4082: }
! 4083: if (ref($$navmapref)) {
! 4084: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
! 4085: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
! 4086: unless (@resources) {
! 4087: $hiddenmap = 1;
! 4088: unless ($env{'request.role.adv'}) {
! 4089: $url = '';
! 4090: $hiddenfolder = 1;
! 4091: }
1.617 raeburn 4092: }
1.615 raeburn 4093: }
4094: }
4095: }
4096: }
1.617 raeburn 4097: unless ($encryptmap) {
1.620 ! raeburn 4098: if ((ref($navmapref)) && (ref($$navmapref))) {
! 4099: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
! 4100: $encryptmap = 1;
! 4101: }
1.617 raeburn 4102: }
4103: }
4104:
4105: # Append randompick number, hidden, and encrypted with ":" to foldername,
4106: # so it gets transferred between levels
4107: $folderpath.=$containerarg.'&'.$foldername.
4108: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4109: unless ($url eq '') {
1.612 raeburn 4110: $url.='folderpath='.&escape($folderpath);
4111: }
1.510 raeburn 4112: my $rpckchk;
4113: if ($rpicknum) {
4114: $rpckchk = ' checked="checked"';
1.543 raeburn 4115: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4116: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4117: }
1.510 raeburn 4118: }
1.537 raeburn 4119: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4120: $rand_pick_text =
1.478 raeburn 4121: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4122: $form_param."\n".
1.478 raeburn 4123: $form_common."\n".
1.611 raeburn 4124: '<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 4125: if ($rpicknum ne '') {
4126: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4127: }
1.537 raeburn 4128: $rand_pick_text .= '</span></span>'.
4129: $form_end;
1.543 raeburn 4130: my $ro_set;
1.617 raeburn 4131: if ($randorder) {
1.543 raeburn 4132: $ro_set = 'checked="checked"';
4133: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4134: push(@{$filtersref->{'randomorder'}},$orderidx);
4135: }
4136: }
1.564 raeburn 4137: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4138: $rand_order_text =
1.537 raeburn 4139: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4140: $form_param."\n".
1.537 raeburn 4141: $form_common."\n".
1.611 raeburn 4142: '<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 4143: $form_end;
1.510 raeburn 4144: }
1.509 raeburn 4145: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4146: my $isexttool;
4147: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4148: $url='/adm/wrapper'.$url;
4149: $isexttool = 1;
4150: }
1.510 raeburn 4151: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4152: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4153: if ($title) {
4154: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4155: }
1.598 raeburn 4156: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4157: $url .= '&idx='.$orderidx;
4158: }
1.610 raeburn 4159: if ($anchor ne '') {
4160: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4161: }
1.329 droeschl 4162: }
1.519 raeburn 4163: my ($tdalign,$tdwidth);
1.501 raeburn 4164: if ($allowed) {
4165: my $fileloc =
4166: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4167: if ($isexternal) {
1.518 raeburn 4168: ($editlink,$extresform) =
1.611 raeburn 4169: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4170: undef,undef,undef,undef,undef,undef,
4171: undef,$disabled);
1.598 raeburn 4172: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4173: ($editlink,$extresform) =
4174: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4175: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4176: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4177: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4178: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4179: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4180: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4181: my $suppanchor;
4182: if ($supplementalflag) {
4183: $suppanchor = $anchor;
4184: }
1.501 raeburn 4185: my $jscall =
4186: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4187: $switchserver,
1.503 raeburn 4188: $forceedit,
1.511 raeburn 4189: undef,$symb,
4190: &escape($env{'form.folderpath'}),
1.610 raeburn 4191: $renametitle,'','',1,$suppanchor);
1.501 raeburn 4192: if ($jscall) {
1.518 raeburn 4193: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4194: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4195: }
4196: }
4197: }
1.519 raeburn 4198: $tdalign = ' align="right" valign="top"';
4199: $tdwidth = ' width="80%"';
1.329 droeschl 4200: }
1.408 raeburn 4201: my $reinit;
4202: if ($crstype eq 'Community') {
4203: $reinit = &mt('(re-initialize community to access)');
4204: } else {
4205: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4206: }
4207: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.472 raeburn 4208: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4209: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4210: } elsif ($url) {
1.610 raeburn 4211: if ($anchor ne '') {
4212: if ($supplementalflag) {
4213: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4214: } else {
4215: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4216: }
4217: }
1.616 raeburn 4218: $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
4219: (($anchor ne '')?$anchor:'')),
1.470 raeburn 4220: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 4221: } else {
4222: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4223: }
1.519 raeburn 4224: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4225: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4226: $line.='<a href="'.$url.'">'.$title.'</a>';
4227: } elsif ($url) {
1.616 raeburn 4228: $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
4229: (($anchor ne '')?$anchor:'')),
1.470 raeburn 4230: $title,600,500);
1.617 raeburn 4231: } elsif (($hiddenfolder) || ($hiddenres)) {
1.615 raeburn 4232: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
1.469 www 4233: } else {
4234: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4235: }
1.518 raeburn 4236: $line.="$extresform</td>";
1.478 raeburn 4237: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4238: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4239: if (($allowed) && ($folder!~/^supplemental/)) {
4240: my %lt=&Apache::lonlocal::texthash(
4241: 'hd' => 'Hidden',
4242: 'ec' => 'URL hidden');
1.543 raeburn 4243: my ($enctext,$hidtext);
4244: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4245: $enctext = ' checked="checked"';
4246: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4247: push(@{$filtersref->{'encrypturl'}},$orderidx);
4248: }
4249: }
4250: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4251: $hidtext = ' checked="checked"';
4252: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4253: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4254: }
4255: }
1.537 raeburn 4256: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4257: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4258: $line.=(<<ENDPARMS);
4259: <td class="LC_docs_entry_parameter">
1.537 raeburn 4260: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4261: $form_param
1.478 raeburn 4262: $form_common
1.611 raeburn 4263: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4264: $form_end
1.458 raeburn 4265: <br />
1.537 raeburn 4266: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4267: $form_param
1.478 raeburn 4268: $form_common
1.611 raeburn 4269: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4270: $form_end
4271: </td>
1.478 raeburn 4272: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4273: $rand_order_text</td>
1.329 droeschl 4274: ENDPARMS
4275: }
1.379 bisitz 4276: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4277: return $line;
4278: }
4279:
1.538 raeburn 4280: sub action_restrictions {
4281: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4282: my %denied = (
4283: cut => 0,
4284: copy => 0,
4285: remove => 0,
4286: );
4287: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4288: # no copy for published maps
4289: $denied{'copy'} = 1;
1.597 raeburn 4290: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4291: unless ($1 eq 'simpleproblem') {
4292: $denied{'copy'} = 1;
4293: }
4294: $denied{'cut'} = 1;
1.538 raeburn 4295: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4296: if ($folderpath =~ /^default&[^\&]+$/) {
4297: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4298: $denied{'remove'} = 1;
4299: }
4300: $denied{'cut'} = 1;
4301: $denied{'copy'} = 1;
4302: }
4303: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4304: my $group = $1;
4305: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4306: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4307: $denied{'remove'} = 1;
4308: }
4309: }
4310: $denied{'cut'} = 1;
4311: $denied{'copy'} = 1;
4312: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4313: my $group = $1;
4314: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4315: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4316: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4317: if (keys(%groupsettings) > 0) {
4318: $denied{'remove'} = 1;
4319: }
4320: $denied{'cut'} = 1;
4321: $denied{'copy'} = 1;
4322: }
4323: }
4324: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4325: my $group = $1;
4326: if ($url =~ /group_boards_\Q$group\E/) {
4327: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4328: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4329: if (keys(%groupsettings) > 0) {
4330: if (ref($groupsettings{'functions'}) eq 'HASH') {
4331: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4332: $denied{'remove'} = 1;
4333: }
4334: }
4335: }
4336: $denied{'cut'} = 1;
4337: $denied{'copy'} = 1;
4338: }
4339: }
4340: }
4341: return %denied;
4342: }
4343:
1.533 raeburn 4344: sub new_timebased_suffix {
1.538 raeburn 4345: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4346: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4347: if ($type eq 'paste') {
4348: $prefix = $type;
4349: $namespace = 'courseeditor';
1.587 raeburn 4350: $idtype = 'addcode';
1.538 raeburn 4351: } elsif ($type eq 'map') {
1.533 raeburn 4352: $prefix = 'docs';
4353: if ($area eq 'supplemental') {
4354: $prefix = 'supp';
4355: }
4356: $prefix .= $container;
4357: $namespace = 'uploadedmaps';
4358: } else {
4359: $prefix = $type;
4360: $namespace = 'templated';
1.504 raeburn 4361: }
4362: my ($suffix,$freedlock,$error) =
1.587 raeburn 4363: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4364: if (!$suffix) {
1.538 raeburn 4365: if ($type eq 'paste') {
4366: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4367: } elsif ($type eq 'map') {
1.533 raeburn 4368: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4369: } elsif ($type eq 'smppg') {
4370: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4371: } else {
1.565 bisitz 4372: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4373: }
1.504 raeburn 4374: if ($error) {
4375: $errtext .= '<br />'.$error;
4376: }
4377: }
4378: if ($freedlock ne 'ok') {
1.533 raeburn 4379: $locknotfreed =
4380: '<div class="LC_error">'.
4381: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4382: if ($type eq 'paste') {
1.591 raeburn 4383: if ($freedlock eq 'nolock') {
4384: $locknotfreed =
4385: '<div class="LC_error">'.
4386: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4387:
1.593 droeschl 4388: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4389: } else {
4390: $locknotfreed .=
4391: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4392: }
1.538 raeburn 4393: } elsif ($type eq 'map') {
1.591 raeburn 4394: $locknotfreed .=
4395: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4396: } elsif ($type eq 'smppg') {
4397: $locknotfreed .=
4398: &mt('This will prevent creation of additional simple pages in this course.');
4399: } else {
4400: $locknotfreed .=
1.565 bisitz 4401: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4402: }
1.538 raeburn 4403: unless ($type eq 'paste') {
4404: $locknotfreed .=
1.560 raeburn 4405: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4406: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4407: }
4408: $locknotfreed .= '</div>';
1.504 raeburn 4409: }
4410: return ($suffix,$errtext,$locknotfreed);
4411: }
4412:
1.329 droeschl 4413: =pod
4414:
4415: =item tiehash()
4416:
4417: tie the hash
4418:
4419: =cut
4420:
4421: sub tiehash {
4422: my ($mode)=@_;
4423: $hashtied=0;
4424: if ($env{'request.course.fn'}) {
4425: if ($mode eq 'write') {
4426: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4427: &GDBM_WRCREAT(),0640)) {
4428: $hashtied=2;
4429: }
4430: } else {
4431: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4432: &GDBM_READER(),0640)) {
4433: $hashtied=1;
4434: }
4435: }
1.364 bisitz 4436: }
1.329 droeschl 4437: }
4438:
4439: sub untiehash {
4440: if ($hashtied) { untie %hash; }
4441: $hashtied=0;
4442: return OK;
4443: }
4444:
4445:
4446:
4447:
4448: sub checkonthis {
4449: my ($r,$url,$level,$title)=@_;
4450: $url=&unescape($url);
4451: $alreadyseen{$url}=1;
4452: $r->rflush();
4453: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4454: $r->print("\n<br />");
4455: if ($level==0) {
4456: $r->print("<br />");
4457: }
4458: for (my $i=0;$i<=$level*5;$i++) {
4459: $r->print(' ');
4460: }
4461: $r->print('<a href="'.$url.'" target="cat">'.
4462: ($title?$title:$url).'</a> ');
4463: if ($url=~/^\/res\//) {
4464: my $result=&Apache::lonnet::repcopy(
4465: &Apache::lonnet::filelocation('',$url));
4466: if ($result eq 'ok') {
4467: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4468: $r->rflush();
4469: &Apache::lonnet::countacc($url);
4470: $url=~/\.(\w+)$/;
4471: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4472: $r->print('<br />');
4473: $r->rflush();
4474: for (my $i=0;$i<=$level*5;$i++) {
4475: $r->print(' ');
4476: }
4477: $r->print('- '.&mt('Rendering:').' ');
4478: my ($errorcount,$warningcount)=split(/:/,
4479: &Apache::lonnet::ssi_body($url,
4480: ('grade_target'=>'web',
4481: 'return_only_error_and_warning_counts' => 1)));
4482: if (($errorcount) ||
4483: ($warningcount)) {
4484: if ($errorcount) {
1.369 bisitz 4485: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4486: &mt('[quant,_1,error]',$errorcount).'</span>');
4487: }
4488: if ($warningcount) {
4489: $r->print('<span class="LC_warning">'.
4490: &mt('[quant,_1,warning]',$warningcount).'</span>');
4491: }
4492: } else {
4493: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4494: }
4495: $r->rflush();
4496: }
4497: my $dependencies=
4498: &Apache::lonnet::metadata($url,'dependencies');
4499: foreach my $dep (split(/\,/,$dependencies)) {
4500: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4501: &checkonthis($r,$dep,$level+1);
4502: }
4503: }
4504: } elsif ($result eq 'unavailable') {
4505: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4506: } elsif ($result eq 'not_found') {
4507: unless ($url=~/\$/) {
1.521 bisitz 4508: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4509: } else {
1.366 bisitz 4510: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4511: }
4512: } else {
4513: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4514: }
4515: }
4516: }
4517: }
4518:
4519:
4520:
4521: =pod
4522:
4523: =item list_symbs()
4524:
1.485 raeburn 4525: List Content Identifiers
1.329 droeschl 4526:
4527: =cut
4528:
4529: sub list_symbs {
4530: my ($r) = @_;
4531:
1.408 raeburn 4532: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4533: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4534: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4535: $r->print(&startContentScreen('tools'));
1.329 droeschl 4536: my $navmap = Apache::lonnavmaps::navmap->new();
4537: if (!defined($navmap)) {
4538: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4539: '<div class="LC_error">'.
4540: &mt('Unable to retrieve information about course contents').
4541: '</div>');
1.408 raeburn 4542: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4543: } else {
1.484 raeburn 4544: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4545: &Apache::loncommon::start_data_table().
4546: &Apache::loncommon::start_data_table_header_row().
4547: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4548: &Apache::loncommon::end_data_table_header_row()."\n");
4549: my $count;
1.329 droeschl 4550: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4551: $r->print(&Apache::loncommon::start_data_table_row().
4552: '<td>'.$res->compTitle().'</td>'.
4553: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4554: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4555: $count ++;
4556: }
4557: if (!$count) {
4558: $r->print(&Apache::loncommon::start_data_table_row().
4559: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4560: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4561: }
1.484 raeburn 4562: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4563: }
1.521 bisitz 4564: $r->print(&endContentScreen());
1.329 droeschl 4565: }
4566:
4567:
4568: sub verifycontent {
4569: my ($r) = @_;
1.408 raeburn 4570: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4571: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4572: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4573: $r->print(&startContentScreen('tools'));
4574: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4575: $hashtied=0;
4576: undef %alreadyseen;
4577: %alreadyseen=();
4578: &tiehash();
1.484 raeburn 4579:
1.329 droeschl 4580: foreach my $key (keys(%hash)) {
4581: if ($hash{$key}=~/\.(page|sequence)$/) {
4582: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4583: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4584: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4585: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4586: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4587: }
4588: }
4589: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4590: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4591: }
4592: }
4593: &untiehash();
1.442 www 4594: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4595: $r->print(&endContentScreen());
1.329 droeschl 4596: }
4597:
4598:
4599: sub devalidateversioncache {
4600: my $src=shift;
4601: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4602: &Apache::lonnet::clutter($src));
4603: }
4604:
4605: sub checkversions {
1.611 raeburn 4606: my ($r,$canedit) = @_;
1.408 raeburn 4607: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4608: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4609: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4610: $r->print(&startContentScreen('tools'));
1.442 www 4611:
1.329 droeschl 4612: my $header='';
4613: my $startsel='';
4614: my $monthsel='';
4615: my $weeksel='';
4616: my $daysel='';
4617: my $allsel='';
4618: my %changes=();
4619: my $starttime=0;
4620: my $haschanged=0;
4621: my %setversions=&Apache::lonnet::dump('resourceversions',
4622: $env{'course.'.$env{'request.course.id'}.'.domain'},
4623: $env{'course.'.$env{'request.course.id'}.'.num'});
4624:
4625: $hashtied=0;
4626: &tiehash();
1.611 raeburn 4627: if ($canedit) {
4628: my %newsetversions=();
4629: if ($env{'form.setmostrecent'}) {
4630: $haschanged=1;
4631: foreach my $key (keys(%hash)) {
4632: if ($key=~/^ids\_(\/res\/.+)$/) {
4633: $newsetversions{$1}='mostrecent';
4634: &devalidateversioncache($1);
4635: }
4636: }
4637: } elsif ($env{'form.setcurrent'}) {
4638: $haschanged=1;
4639: foreach my $key (keys(%hash)) {
4640: if ($key=~/^ids\_(\/res\/.+)$/) {
4641: my $getvers=&Apache::lonnet::getversion($1);
4642: if ($getvers>0) {
4643: $newsetversions{$1}=$getvers;
4644: &devalidateversioncache($1);
4645: }
4646: }
1.329 droeschl 4647: }
1.611 raeburn 4648: } elsif ($env{'form.setversions'}) {
4649: $haschanged=1;
4650: foreach my $key (keys(%env)) {
4651: if ($key=~/^form\.set_version_(.+)$/) {
4652: my $src=$1;
4653: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4654: $newsetversions{$src}=$env{$key};
4655: &devalidateversioncache($src);
4656: }
4657: }
1.329 droeschl 4658: }
1.611 raeburn 4659: }
4660: if ($haschanged) {
4661: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4662: $env{'course.'.$env{'request.course.id'}.'.domain'},
4663: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4664: $r->print(&Apache::loncommon::confirmwrapper(
4665: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4666: } else {
4667: $r->print(&Apache::loncommon::confirmwrapper(
4668: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4669: }
1.611 raeburn 4670: &mark_hash_old();
4671: }
4672: &changewarning($r,'');
1.329 droeschl 4673: }
4674: if ($env{'form.timerange'} eq 'all') {
4675: # show all documents
1.549 raeburn 4676: $header=&mt('All content in '.$crstype);
1.521 bisitz 4677: $allsel=' selected="selected"';
1.329 droeschl 4678: foreach my $key (keys(%hash)) {
4679: if ($key=~/^ids\_(\/res\/.+)$/) {
4680: my $src=$1;
4681: $changes{$src}=1;
4682: }
4683: }
4684: } else {
4685: # show documents which changed
4686: %changes=&Apache::lonnet::dump
4687: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4688: $env{'course.'.$env{'request.course.id'}.'.num'});
4689: my $firstkey=(keys(%changes))[0];
4690: unless ($firstkey=~/^error\:/) {
4691: unless ($env{'form.timerange'}) {
4692: $env{'form.timerange'}=604800;
4693: }
4694: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4695: .&mt('seconds');
4696: if ($env{'form.timerange'}==-1) {
4697: $seltext='since start of course';
1.521 bisitz 4698: $startsel=' selected="selected"';
1.329 droeschl 4699: $env{'form.timerange'}=time;
4700: }
4701: $starttime=time-$env{'form.timerange'};
4702: if ($env{'form.timerange'}==2592000) {
4703: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4704: $monthsel=' selected="selected"';
1.329 droeschl 4705: } elsif ($env{'form.timerange'}==604800) {
4706: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4707: $weeksel=' selected="selected"';
1.329 droeschl 4708: } elsif ($env{'form.timerange'}==86400) {
4709: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4710: $daysel=' selected="selected"';
1.329 droeschl 4711: }
4712: $header=&mt('Content changed').' '.$seltext;
4713: } else {
4714: $header=&mt('No content modifications yet.');
4715: }
4716: }
4717: %setversions=&Apache::lonnet::dump('resourceversions',
4718: $env{'course.'.$env{'request.course.id'}.'.domain'},
4719: $env{'course.'.$env{'request.course.id'}.'.num'});
4720: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4721: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4722: 'lm' => 'Version changes since last Month',
4723: 'lw' => 'Version changes since last Week',
4724: 'sy' => 'Version changes since Yesterday',
4725: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4726: 'cd' => 'Change display',
1.329 droeschl 4727: 'sd' => 'Display',
4728: 'fi' => 'File',
4729: 'md' => 'Modification Date',
4730: 'mr' => 'Most recently published Version',
1.408 raeburn 4731: 've' => 'Version used in '.$crstype,
4732: 'vu' => 'Set Version to be used in '.$crstype,
4733: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4734: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4735: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4736: 'di' => 'Differences',
1.484 raeburn 4737: 'save' => 'Save changes',
4738: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4739: 'act' => 'Actions');
1.611 raeburn 4740: my ($disabled,$readonly);
4741: unless ($canedit) {
4742: $disabled = 'disabled="disabled"';
4743: $readonly = 1;
4744: }
1.329 droeschl 4745: $r->print(<<ENDHEADERS);
1.484 raeburn 4746: <h4 class="LC_info">$header</h4>
1.329 droeschl 4747: <form action="/adm/coursedocs" method="post">
4748: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4749: <div class="LC_left_float">
1.479 golterma 4750: <fieldset>
1.484 raeburn 4751: <legend>$lt{'cd'}</legend>
1.329 droeschl 4752: <select name="timerange">
1.521 bisitz 4753: <option value='all'$allsel>$lt{'al'}</option>
4754: <option value="-1"$startsel>$lt{'st'}</option>
4755: <option value="2592000"$monthsel>$lt{'lm'}</option>
4756: <option value="604800"$weeksel>$lt{'lw'}</option>
4757: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4758: </select>
4759: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4760: </fieldset>
4761: </div>
4762: <div class="LC_left_float">
4763: <fieldset>
4764: <legend>$lt{'act'}</legend>
1.611 raeburn 4765: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4766: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4767: </fieldset>
4768: </div>
4769: <br clear="all" />
4770: <hr />
4771: <h4>$lt{'vers'}</h4>
1.329 droeschl 4772: ENDHEADERS
1.479 golterma 4773: #number of columns for version history
1.571 raeburn 4774: my %changedbytime;
4775: foreach my $key (keys(%changes)) {
4776: #excludes not versionable problems from resource version history:
4777: next if ($key =~ /^\/res\/lib\/templates/);
4778: my $chg;
4779: if ($env{'form.timerange'} eq 'all') {
4780: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4781: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4782: } else {
4783: $chg = $changes{$key};
4784: next if ($chg < $starttime);
4785: }
4786: push(@{$changedbytime{$chg}},$key);
4787: }
4788: if (keys(%changedbytime) == 0) {
4789: &untiehash();
4790: $r->print(&mt('No content changes in imported content in specified time frame').
4791: &endContentScreen());
4792: return;
4793: }
1.479 golterma 4794: $r->print(
1.611 raeburn 4795: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4796: &Apache::loncommon::start_data_table().
4797: &Apache::loncommon::start_data_table_header_row().
4798: '<th>'.&mt('Resources').'</th>'.
4799: "<th>$lt{'mr'}</th>".
4800: "<th>$lt{'ve'}</th>".
4801: "<th>$lt{'vu'}</th>".
4802: '<th>'.&mt('History').'</th>'.
4803: &Apache::loncommon::end_data_table_header_row()
4804: );
1.571 raeburn 4805: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4806: foreach my $key (sort(@{$changedbytime{$chg}})) {
4807: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4808: my $currentversion=&Apache::lonnet::getversion($key);
4809: if ($currentversion<0) {
4810: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4811: }
4812: my $linkurl=&Apache::lonnet::clutter($key);
4813: $r->print(
4814: &Apache::loncommon::start_data_table_row().
4815: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4816: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4817: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4818: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4819: '<td align="right">'
4820: );
4821: # Used in course
4822: my $usedversion=$hash{'version_'.$linkurl};
4823: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4824: if ($usedversion != $currentversion) {
1.479 golterma 4825: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4826: } else {
1.479 golterma 4827: $r->print($usedversion);
4828: }
1.329 droeschl 4829: } else {
1.521 bisitz 4830: $r->print($currentversion);
1.329 droeschl 4831: }
1.571 raeburn 4832: $r->print('</td><td title="'.$lt{'vu'}.'">');
4833: # Set version
4834: $r->print(&Apache::loncommon::select_form(
4835: $setversions{$linkurl},
4836: 'set_version_'.$linkurl,
4837: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4838: '' => '',
4839: 'mostrecent' => &mt('most recent'),
1.611 raeburn 4840: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 4841: my $lastold=1;
4842: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4843: my $url=$root.'.'.$prevvers.'.'.$extension;
4844: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4845: $lastold=$prevvers;
4846: }
4847: }
4848: $r->print('</td>');
4849: # List all available versions
4850: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4851: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4852: my $url=$root.'.'.$prevvers.'.'.$extension;
4853: $r->print(
4854: '<span class="LC_nobreak">'
4855: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4856: .&mt('Version [_1]',$prevvers).'</a>'
4857: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4858: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4859: .')');
4860: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4861: $r->print(
4862: ' <a href="/adm/diff?filename='.
4863: &Apache::lonnet::clutter($root.'.'.$extension).
4864: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4865: '" target="diffs">'.&mt('Diffs').'</a>');
4866: }
4867: $r->print('</span><br />');
1.329 droeschl 4868: }
1.571 raeburn 4869: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4870: }
1.329 droeschl 4871: }
1.521 bisitz 4872: $r->print(
4873: &Apache::loncommon::end_data_table().
1.611 raeburn 4874: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4875: '</form>'
4876: );
1.329 droeschl 4877:
4878: &untiehash();
1.521 bisitz 4879: $r->print(&endContentScreen());
1.571 raeburn 4880: return;
1.329 droeschl 4881: }
4882:
4883: sub mark_hash_old {
4884: my $retie_hash=0;
4885: if ($hashtied) {
4886: $retie_hash=1;
4887: &untiehash();
4888: }
4889: &tiehash('write');
4890: $hash{'old'}=1;
4891: &untiehash();
4892: if ($retie_hash) { &tiehash(); }
4893: }
4894:
4895: sub is_hash_old {
4896: my $untie_hash=0;
4897: if (!$hashtied) {
4898: $untie_hash=1;
4899: &tiehash();
4900: }
4901: my $return=$hash{'old'};
4902: if ($untie_hash) { &untiehash(); }
4903: return $return;
4904: }
4905:
4906: sub changewarning {
4907: my ($r,$postexec,$message,$url)=@_;
4908: if (!&is_hash_old()) { return; }
4909: my $pathvar='folderpath';
4910: my $path=&escape($env{'form.folderpath'});
4911: if (!defined($url)) {
4912: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4913: }
4914: my $course_type = &Apache::loncommon::course_type();
4915: if (!defined($message)) {
4916: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4917: }
4918: $r->print("\n\n".
1.372 bisitz 4919: '<script type="text/javascript">'."\n".
4920: '// <![CDATA['."\n".
4921: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4922: '// ]]>'."\n".
1.369 bisitz 4923: '</script>'."\n".
1.375 tempelho 4924: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4925: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4926: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4927: &mt($message,' <input type="hidden" name="'.
4928: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4929: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4930: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4931: }
4932:
4933:
4934: sub init_breadcrumbs {
1.571 raeburn 4935: my ($form,$text,$help)=@_;
1.329 droeschl 4936: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4937: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4938: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4939: faq=>273,
4940: bug=>'Instructor Interface',
1.571 raeburn 4941: help => $help});
1.329 droeschl 4942: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4943: text=>$text,
4944: faq=>273,
4945: bug=>'Instructor Interface'});
4946: }
4947:
1.441 www 4948: # subroutine to list form elements
4949: sub create_list_elements {
4950: my @formarr = @_;
4951: my $list = '';
1.501 raeburn 4952: foreach my $button (@formarr){
4953: foreach my $picture (keys(%{$button})) {
4954: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4955: }
4956: }
4957: return $list;
4958: }
1.329 droeschl 4959:
1.441 www 4960: # subroutine to create ul from list elements
4961: sub create_form_ul {
4962: my $list = shift;
4963: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4964: return $ul;
4965: }
1.329 droeschl 4966:
1.442 www 4967: #
4968: # Start tabs
4969: #
4970:
4971: sub startContentScreen {
1.484 raeburn 4972: my ($mode) = @_;
4973: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4974: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4975: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4976: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4977: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
4978: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4979: } else {
1.549 raeburn 4980: $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 4981: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4982: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4983: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4984: }
4985: $output .= "\n".'</ul>'."\n";
4986: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4987: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4988: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4989: return $output;
1.442 www 4990: }
4991:
4992: #
4993: # End tabs
4994: #
4995:
4996: sub endContentScreen {
1.484 raeburn 4997: return '</div></div></div>';
1.442 www 4998: }
1.329 droeschl 4999:
1.446 www 5000: sub supplemental_base {
1.548 raeburn 5001: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5002: }
5003:
1.329 droeschl 5004: sub handler {
5005: my $r = shift;
5006: &Apache::loncommon::content_type($r,'text/html');
5007: $r->send_http_header;
5008: return OK if $r->header_only;
1.484 raeburn 5009:
5010: # get course data
1.408 raeburn 5011: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5012: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5013: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5014:
1.606 raeburn 5015: # get docroot
5016: my $londocroot = $r->dir_config('lonDocRoot');
5017:
1.484 raeburn 5018: # graphics settings
5019: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5020:
1.443 www 5021: #
1.329 droeschl 5022: # --------------------------------------------- Initialize help topics for this
5023: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5024: 'Adding_External_Resource','Navigate_Content',
5025: 'Adding_Folders','Docs_Overview', 'Load_Map',
5026: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 5027: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.571 raeburn 5028: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
1.572 raeburn 5029: 'Dropbox','Simple_Problem') {
1.329 droeschl 5030: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5031: }
5032: # Composite help files
5033: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5034: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5035: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5036: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5037: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5038: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5039: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5040: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5041: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5042: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5043:
1.611 raeburn 5044: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5045: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5046: unless ($r->uri eq '/adm/supplemental') {
5047: # does this user have privileges to modify content.
1.611 raeburn 5048: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5049: $allowed = 1;
5050: $canedit = 1;
5051: $canview = 1;
5052: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5053: $allowed = 1;
5054: $canview = 1;
5055: }
5056: }
5057: unless ($canedit) {
5058: $disabled = ' disabled="disabled"';
1.472 raeburn 5059: }
1.582 raeburn 5060: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5061: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5062: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 5063: &verifycontent($r);
5064: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5065: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5066: &list_symbs($r);
5067: } elsif ($allowed && $env{'form.docslog'}) {
5068: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5069: my $folder = $env{'form.folder'};
5070: if ($folder eq '') {
5071: $folder='default';
5072: }
1.611 raeburn 5073: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5074: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5075: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5076: &checkversions($r,$canedit);
5077: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5078: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5079: &dumpcourse($r);
1.611 raeburn 5080: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5081: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5082: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5083: } else {
1.611 raeburn 5084: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5085: $noendpage = 1;
5086: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5087: if ($redirect) {
5088: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5089: my $container = 'sequence';
5090: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5091: $is_random_order,$container) =
5092: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5093: my (@folders)=split('&',$env{'form.folderpath'});
5094: $env{'form.foldername'}=&unescape(pop(@folders));
5095: my $folder=pop(@folders);
5096: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5097: $folder.'.'.$container);
5098: my $warning;
5099: if ($fatal) {
5100: if ($container eq 'page') {
5101: $warning = &mt('An error occurred retrieving the contents of the current page.');
5102: } else {
5103: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5104: }
5105: } else {
5106: my $url = $redirect;
5107: my $srcfile = $londocroot.$url;
5108: $url =~ s{^/priv/}{/res/};
5109: my $targetfile = $londocroot.$url;
5110: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5111: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5112: $env{'form.folder'} = $folder;
5113: &snapshotbefore();
5114: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5115: my $ext = 'false';
5116: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5117: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5118: ':'.$ext.':normal:res';
5119: push(@LONCAPA::map::order,$newidx);
5120: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5121: 'string_yesno');
5122: &remember_parms($newidx,'hiddenresource','set','yes');
5123: ($errtext,$fatal) =
5124: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5125: &log_differences($plain);
5126: &mark_hash_old();
5127: $r->internal_redirect($redirect);
5128: return OK;
5129: }
5130: }
5131: }
5132: }
1.445 www 5133: #
5134: # Done catching special calls
1.484 raeburn 5135: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5136: # Get the parameters that may be needed
5137: #
5138: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5139: ['folderpath',
5140: 'forcesupplement','forcestandard',
1.510 raeburn 5141: 'tools','symb','command','supppath']);
1.445 www 5142:
5143: # standard=1: this is a "new-style" course with an uploaded map as top level
5144: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5145:
5146: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5147:
1.484 raeburn 5148: # Decide whether this should display supplemental or main content or utilities
1.445 www 5149: # supplementalflag=1: show supplemental documents
5150: # supplementalflag=0: show standard documents
1.484 raeburn 5151: # toolsflag=1: show utilities
1.445 www 5152:
1.561 raeburn 5153: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5154: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5155: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5156: $supplementalflag=0;
5157: }
5158: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5159: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5160: unless ($allowed) { $supplementalflag=1; }
5161: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5162: my $toolsflag=0;
5163: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5164:
1.329 droeschl 5165: my $script='';
5166: my $showdoc=0;
1.457 raeburn 5167: my $addentries = {};
1.475 raeburn 5168: my $container;
1.329 droeschl 5169: my $containertag;
1.508 raeburn 5170: my $pathitem;
1.598 raeburn 5171: my %ltitools;
1.617 raeburn 5172: my $hiddentop;
1.615 raeburn 5173: my $navmap;
1.617 raeburn 5174: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5175:
1.464 www 5176: # Do we directly jump somewhere?
1.525 raeburn 5177: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5178: if ($env{'form.symb'} ne '') {
1.522 raeburn 5179: $env{'form.folderpath'}=
1.617 raeburn 5180: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5181: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5182: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5183: } elsif ($env{'form.supppath'} ne '') {
5184: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5185: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5186: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5187: }
1.472 raeburn 5188: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5189: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5190: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5191: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5192: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5193: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5194: } elsif ($env{'form.command'} eq 'contents') {
5195: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5196: } elsif ($env{'form.command'} eq 'home') {
5197: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5198: }
5199:
1.525 raeburn 5200:
1.445 www 5201: # Where do we store these for when we come back?
5202: my $stored_folderpath='docs_folderpath';
5203: if ($supplementalflag) {
5204: $stored_folderpath='docs_sup_folderpath';
5205: }
1.464 www 5206:
1.519 raeburn 5207: # No folderpath, and in edit mode, see if we have something stored
5208: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5209: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5210: {'folderpath' => 'scalar'});
1.615 raeburn 5211:
5212: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5213: if ($supplementalflag) {
5214: undef($env{'form.folderpath'}) if ($1 eq 'default');
5215: } else {
5216: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5217: }
5218: } else {
1.523 raeburn 5219: undef($env{'form.folderpath'});
5220: }
1.329 droeschl 5221: }
1.446 www 5222:
5223: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5224: if (!$allowed) {
1.446 www 5225: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5226: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5227: }
5228: }
1.446 www 5229: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5230: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5231: $env{'form.folderpath'} = &supplemental_base()
5232: .'&'.
1.329 droeschl 5233: $env{'form.folderpath'};
5234: }
1.615 raeburn 5235: # If allowed and user's role is not advanced check folderpath is not hidden
5236: if (($allowed) && (!$env{'request.role.adv'}) &&
5237: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5238: my $folderurl;
5239: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5240: my $folder = $pathitems[-2];
5241: if ($folder eq '') {
5242: undef($env{'form.folderpath'});
5243: } else {
5244: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5245: if ((split(/\:/,$pathitems[-1]))[4]) {
5246: $folderurl .= '.page';
5247: } else {
5248: $folderurl .= '.sequence';
5249: }
1.617 raeburn 5250: unless (ref($navmap)) {
5251: $navmap = Apache::lonnavmaps::navmap->new();
5252: }
1.615 raeburn 5253: if (ref($navmap)) {
5254: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5255: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5256: unless (@resources) {
5257: undef($env{'form.folderpath'});
5258: }
1.615 raeburn 5259: }
5260: }
5261: }
5262: }
5263:
5264:
1.446 www 5265: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5266: unless ($env{'form.folderpath'}) {
1.446 www 5267: if ($supplementalflag) {
5268: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5269: } elsif ($allowed) {
5270: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5271: }
1.472 raeburn 5272: }
1.446 www 5273:
1.445 www 5274: # Store this
1.484 raeburn 5275: unless ($toolsflag) {
1.615 raeburn 5276: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5277: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5278: {'folderpath' => 'scalar'});
1.510 raeburn 5279: }
1.519 raeburn 5280: my $folderpath;
1.484 raeburn 5281: if ($env{'form.folderpath'}) {
1.519 raeburn 5282: $folderpath = $env{'form.folderpath'};
5283: my (@folders)=split('&',$env{'form.folderpath'});
5284: $env{'form.foldername'}=&unescape(pop(@folders));
5285: if ($env{'form.foldername'} =~ /\:1$/) {
5286: $container = 'page';
5287: } else {
5288: $container = 'sequence';
5289: }
5290: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5291: } else {
1.519 raeburn 5292: if ($env{'form.folder'} eq '' ||
5293: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5294: if ($env{'form.folder'} eq 'supplemental') {
5295: $folderpath=&supplemental_base();
5296: } elsif (!$hiddentop) {
5297: $folderpath='default&'.
5298: &escape(&mt('Main Content').':::::');
5299: }
1.484 raeburn 5300: }
5301: }
1.519 raeburn 5302: $containertag = '<input type="hidden" name="folderpath" value="" />';
5303: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5304: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5305: $showdoc='/'.$1;
5306: }
5307: if ($showdoc) { # got called in sequence from course
5308: $allowed=0;
5309: } else {
1.611 raeburn 5310: if ($canedit) {
1.484 raeburn 5311: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5312: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5313: }
5314: }
1.329 droeschl 5315: }
5316:
1.344 bisitz 5317: # get personal data
1.329 droeschl 5318: my $uname=$env{'user.name'};
5319: my $udom=$env{'user.domain'};
5320: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5321:
5322: if ($allowed) {
1.484 raeburn 5323: if ($toolsflag) {
5324: $script .= &inject_data_js();
5325: my ($home,$other,%outhash)=&authorhosts();
5326: if (!$home && $other) {
5327: my @hosts;
5328: foreach my $aurole (keys(%outhash)) {
5329: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5330: push(@hosts,$outhash{$aurole});
5331: }
5332: }
5333: $script .= &dump_switchserver_js(@hosts);
5334: }
1.458 raeburn 5335: } else {
1.570 raeburn 5336: my $tid = 1;
1.484 raeburn 5337: my @tabids;
5338: if ($supplementalflag) {
5339: @tabids = ('002','ee2','ff2');
1.570 raeburn 5340: $tid = 2;
1.484 raeburn 5341: } else {
5342: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5343: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5344: unshift(@tabids,'001');
5345: push(@tabids,('dd1','ee1'));
5346: }
1.458 raeburn 5347: }
1.484 raeburn 5348: my $tabidstr = join("','",@tabids);
1.598 raeburn 5349: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5350: my $posslti = keys(%ltitools);
1.606 raeburn 5351: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.617 raeburn 5352: $londocroot,$canedit,\$navmap).
1.484 raeburn 5353: &history_tab_js().
5354: &inject_data_js().
1.570 raeburn 5355: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5356: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5357: $addentries = {
1.485 raeburn 5358: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5359: };
1.458 raeburn 5360: }
1.538 raeburn 5361: $script .= &paste_popup_js();
1.501 raeburn 5362: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5363: &mt('Switch server?');
5364:
5365:
1.329 droeschl 5366: }
5367: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5368: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5369: .'// <![CDATA['."\n"
5370: .$script."\n"
5371: .'// ]]>'."\n"
1.595 musolffc 5372: .'</script>'."\n"
5373: .'<script type="text/javascript"
5374: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5375:
5376: # Breadcrumbs
5377: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5378:
5379: if ($showdoc) {
5380: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5381: {'force_register' => $showdoc,}));
1.571 raeburn 5382: } elsif ($toolsflag) {
1.611 raeburn 5383: my ($breadtext,$breadtitle);
1.617 raeburn 5384: $breadtext = "$crstype Editor";
1.611 raeburn 5385: if ($canedit) {
5386: $breadtitle = 'Editing '.$crstype.' Contents';
5387: } else {
5388: $breadtext .= ' (View-only mode)';
5389: $breadtitle = 'Viewing '.$crstype.' Contents';
5390: }
1.571 raeburn 5391: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5392: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5393: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5394: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5395: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5396: $breadtitle)
1.571 raeburn 5397: );
1.510 raeburn 5398: } elsif ($r->uri eq '/adm/supplemental') {
5399: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5400: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5401: {'bread_crumbs' => $brcrum,}));
5402: } else {
1.611 raeburn 5403: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5404: $breadtext = "$crstype Editor";
1.611 raeburn 5405: if ($canedit) {
5406: $breadtitle = 'Editing '.$crstype.' Contents';
5407: $helpitem = 'Docs_Adding_Course_Doc';
5408: } else {
5409: $breadtext .= ' (View-only mode)';
5410: $breadtitle = 'Viewing '.$crstype.' Contents';
5411: $helpitem = 'Docs_Viewing_Course_Doc';
5412: }
1.392 raeburn 5413: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5414: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5415: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5416: {'add_entries' => $addentries}
5417: )
1.392 raeburn 5418: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5419: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5420: $breadtitle,
5421: $helpitem)
1.392 raeburn 5422: );
5423: }
1.364 bisitz 5424:
1.329 droeschl 5425: my %allfiles = ();
5426: my %codebase = ();
1.440 raeburn 5427: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5428: if ($canedit) {
1.329 droeschl 5429: if (($env{'form.uploaddoc.filename'}) &&
5430: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5431: my $context = $1;
5432: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5433: undef($hadchanges);
1.440 raeburn 5434: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5435: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5436: if ($hadchanges) {
5437: &mark_hash_old();
5438: }
1.440 raeburn 5439: $r->print($upload_output);
5440: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5441: # Process file upload - phase two - upload embedded objects
5442: $uploadphase = 'check_embedded';
5443: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5444: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5445: $env{'form.newidx'});
5446: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5447: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5448: my ($destination,$dir_root) = &embedded_destination();
5449: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5450: my $actionurl = '/adm/coursedocs';
5451: my ($result,$flag) =
5452: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5453: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5454: $actionurl);
5455: $r->print($result.&return_to_editor());
5456: } elsif ($env{'form.phase'} eq 'check_embedded') {
5457: # Process file upload - phase three - modify references in HTML file
5458: $uploadphase = 'modified_orightml';
5459: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5460: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5461: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5462: my $result =
5463: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5464: $docuname,$docudom,undef,
5465: $dir_root);
5466: $r->print($result.&return_to_editor());
1.476 raeburn 5467: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5468: $uploadphase = 'decompress_phase_one';
5469: $r->print(&decompression_phase_one().
5470: &return_to_editor());
5471: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5472: $uploadphase = 'decompress_phase_two';
5473: $r->print(&decompression_phase_two().
5474: &return_to_editor());
1.329 droeschl 5475: }
5476: }
5477:
1.484 raeburn 5478: if ($allowed && $toolsflag) {
5479: $r->print(&startContentScreen('tools'));
1.611 raeburn 5480: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5481: $r->print(&endContentScreen());
5482: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5483: # -----------------------------------------------------------------------------
5484: my %lt=&Apache::lonlocal::texthash(
5485: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5486: 'upfi' => 'Upload File',
1.553 raeburn 5487: 'upld' => 'Upload Content',
1.329 droeschl 5488: 'srch' => 'Search',
5489: 'impo' => 'Import',
1.487 raeburn 5490: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5491: 'impm' => 'Import from Assembled Map',
1.606 raeburn 5492: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5493: 'extr' => 'External Resource',
5494: 'extt' => 'External Tool',
1.329 droeschl 5495: 'selm' => 'Select Map',
5496: 'load' => 'Load Map',
5497: 'newf' => 'New Folder',
5498: 'newp' => 'New Composite Page',
5499: 'syll' => 'Syllabus',
1.425 raeburn 5500: 'navc' => 'Table of Contents',
1.343 biermanm 5501: 'sipa' => 'Simple Course Page',
1.329 droeschl 5502: 'sipr' => 'Simple Problem',
1.534 raeburn 5503: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5504: 'stpr' => 'Standard Problem',
5505: 'news' => 'New sub-directory',
5506: 'crpr' => 'Create Problem',
1.329 droeschl 5507: 'drbx' => 'Drop Box',
1.451 www 5508: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5509: 'bull' => 'Discussion Board',
1.347 weissno 5510: 'mypi' => 'My Personal Information Page',
1.353 weissno 5511: 'grpo' => 'Group Portfolio',
1.329 droeschl 5512: 'rost' => 'Course Roster',
1.528 raeburn 5513: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5514: 'imsf' => 'IMS Upload',
5515: 'imsl' => 'Upload IMS package',
1.501 raeburn 5516: 'cms' => 'Origin of IMS package',
5517: 'se' => 'Select',
1.329 droeschl 5518: 'file' => 'File',
5519: 'title' => 'Title',
1.606 raeburn 5520: 'addp' => 'Add Placeholder to course?',
5521: 'uste' => 'Use Template?',
5522: 'fnam' => 'File Name:',
5523: 'loca' => 'Location:',
5524: 'dire' => 'Directory:',
5525: 'cate' => 'Category:',
5526: 'tmpl' => 'Template:',
1.329 droeschl 5527: 'comment' => 'Comment',
1.403 raeburn 5528: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5529: 'bb5' => 'Blackboard 5',
5530: 'bb6' => 'Blackboard 6',
5531: 'angel5' => 'ANGEL 5.5',
5532: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5533: 'yes' => 'Yes',
5534: 'no' => 'No',
1.618 raeburn 5535: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5536: );
1.329 droeschl 5537: # -----------------------------------------------------------------------------
1.595 musolffc 5538:
5539: # Calculate free quota space for a user or course. A javascript function checks
5540: # file size to determine if upload should be allowed.
5541: my $quotatype = 'unofficial';
5542: if ($crstype eq 'Community') {
1.601 raeburn 5543: $quotatype = 'community';
5544: } elsif ($crstype eq 'Placement') {
5545: $quotatype = 'placement';
1.595 musolffc 5546: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5547: $quotatype = 'official';
5548: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5549: $quotatype = 'textbook';
5550: }
5551: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5552: 'course',$quotatype); # expressed in MB
5553: my $current_disk_usage = 0;
5554: foreach my $subdir ('docs','supplemental') {
5555: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5556: "userfiles/$subdir",1); # expressed in kB
5557: }
5558: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5559: my $usage = $current_disk_usage/1024; # in MB
5560: my $quota = $disk_quota;
5561: my $percent;
5562: if ($disk_quota == 0) {
5563: $percent = 100.0;
5564: } else {
1.619 raeburn 5565: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5566: }
5567: $usage = sprintf("%.2f",$usage);
5568: $quota = sprintf("%.2f",$quota);
5569: $percent = sprintf("%.0f",$percent);
5570: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5571: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5572:
1.329 droeschl 5573: my $fileupload=(<<FIUP);
1.605 raeburn 5574: $quotainfo
1.329 droeschl 5575: $lt{'file'}:<br />
1.611 raeburn 5576: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5577: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5578: FIUP
5579:
5580: my $checkbox=(<<CHBO);
5581: <!-- <label>$lt{'parse'}?
5582: <input type="checkbox" name="parserflag" />
5583: </label> -->
5584: <label>
1.611 raeburn 5585: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5586: </label>
5587: CHBO
1.501 raeburn 5588: my $imsfolder = $env{'form.folder'};
5589: if ($imsfolder eq '') {
5590: $imsfolder = 'default';
5591: }
5592: my $imspform=(<<IMSFORM);
5593: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5594: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5595: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5596: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5597: <legend>$lt{'imsf'}</legend>
5598: $fileupload
5599: <br />
5600: <p>
5601: $lt{'cms'}:
1.611 raeburn 5602: <select name="source" $disabled>
1.501 raeburn 5603: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5604: <option value="bb5">$lt{'bb5'}</option>
5605: <option value="bb6">$lt{'bb6'}</option>
5606: <option value="angel5">$lt{'angel5'}</option>
5607: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5608: </select>
5609: <input type="hidden" name="folder" value="$imsfolder" />
5610: </p>
5611: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5612: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5613: </fieldset>
5614: </form>
5615: IMSFORM
1.329 droeschl 5616:
5617: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5618: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5619: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5620: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5621: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5622: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5623: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5624: $fileupload
1.329 droeschl 5625: <br />
5626: $lt{'title'}:<br />
1.611 raeburn 5627: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5628: $pathitem
1.329 droeschl 5629: <input type="hidden" name="cmd" value="upload_default" />
5630: <br />
1.458 raeburn 5631: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5632: $checkbox
5633: </span>
1.501 raeburn 5634: <br clear="all" />
1.611 raeburn 5635: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5636: </fieldset>
5637: </form>
1.383 tempelho 5638: FUFORM
1.329 droeschl 5639:
1.611 raeburn 5640: my $mapimportjs;
5641: if ($canedit) {
5642: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5643: } else {
5644: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5645: }
1.502 raeburn 5646: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5647: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5648: $lt{'impm'}</a>$help{'Load_Map'}
5649: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5650: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5651: <legend>$lt{'impm'}</legend>
1.371 tempelho 5652: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5653: $lt{'copm'}<br />
5654: <span class="LC_nobreak">
5655: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5656: onfocus="this.blur();$mapimportjs" $disabled />
5657: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5658: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5659: </fieldset>
5660: </form>
5661:
1.383 tempelho 5662: SEDFFORM
1.606 raeburn 5663: my $importcrsresform;
1.608 raeburn 5664: my ($numdirs,$pickfile) =
5665: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5666: "resize_scrollbox('contentscroll','1','0');",
5667: undef,'res');
1.606 raeburn 5668: if ($pickfile) {
5669: $importcrsresform=(<<CRSFORM);
5670: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5671: $lt{'imcr'}</a>$help{'Course_Resources'}
5672: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5673: <fieldset id="importcrsresform" style="display: none;">
5674: <legend>$lt{'imcr'}</legend>
5675: <input type="hidden" name="active" value="bb" />
5676: $pickfile
5677: <p>
1.611 raeburn 5678: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5679: </p>
5680: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5681: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5682: </fieldset>
5683: </form>
5684: CRSFORM
5685: }
5686:
1.611 raeburn 5687: my $fromstoredjs;
5688: if ($canedit) {
5689: $fromstoredjs = 'open_StoredLinks_Import()';
5690: } else {
5691: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5692: }
5693:
1.502 raeburn 5694: my @importpubforma = (
1.508 raeburn 5695: { '<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 5696: { '<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 5697: { '<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 5698: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5699: );
5700: if ($pickfile) {
5701: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5702: }
1.502 raeburn 5703: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5704: my $extresourcesform =
5705: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5706: $help{'Adding_External_Resource'},
5707: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5708: my $exttoolform =
5709: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5710: $help{'Adding_External_Tool'},undef,
5711: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5712: \%ltitools,$disabled);
1.329 droeschl 5713: if ($allowed) {
1.492 raeburn 5714: my $folder = $env{'form.folder'};
5715: if ($folder eq '') {
5716: $folder='default';
5717: }
1.615 raeburn 5718: if ($canedit) {
5719: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5720: if ($output) {
5721: $r->print($output);
5722: }
1.538 raeburn 5723: }
1.337 ehlerst 5724: $r->print(<<HIDDENFORM);
5725: <form name="renameform" method="post" action="/adm/coursedocs">
5726: <input type="hidden" name="title" />
5727: <input type="hidden" name="cmd" />
5728: <input type="hidden" name="markcopy" />
5729: <input type="hidden" name="copyfolder" />
5730: $containertag
5731: </form>
1.484 raeburn 5732:
1.337 ehlerst 5733: HIDDENFORM
1.508 raeburn 5734: $r->print(&makesimpleeditform($pathitem)."\n".
5735: &makedocslogform($pathitem."\n".
1.484 raeburn 5736: '<input type="hidden" name="folder" value="'.
5737: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5738: }
1.442 www 5739:
5740: # Generate the tabs
1.510 raeburn 5741: my ($mode,$needs_end);
1.472 raeburn 5742: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5743: my @folders = split('&',$env{'form.folderpath'});
5744: unless (@folders > 2) {
5745: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5746: $needs_end = 1;
5747: }
1.472 raeburn 5748: } else {
1.484 raeburn 5749: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5750: $needs_end = 1;
1.472 raeburn 5751: }
1.443 www 5752:
1.442 www 5753: #
5754:
5755: my $savefolderpath;
5756:
1.395 raeburn 5757: if ($allowed) {
1.329 droeschl 5758: my $folder=$env{'form.folder'};
1.615 raeburn 5759: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5760: $folder='default';
1.356 tempelho 5761: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5762: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5763: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5764: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5765: }
5766: my $postexec='';
5767: if ($folder eq 'default') {
1.372 bisitz 5768: $r->print('<script type="text/javascript">'."\n"
5769: .'// <![CDATA['."\n"
5770: .'this.window.name="loncapaclient";'."\n"
5771: .'// ]]>'."\n"
5772: .'</script>'."\n"
1.369 bisitz 5773: );
1.329 droeschl 5774: } else {
5775: #$postexec='self.close();';
5776: }
1.504 raeburn 5777: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5778: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5779: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5780:
5781: my $newnavform=(<<NNFORM);
5782: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5783: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5784: $pathitem
1.329 droeschl 5785: <input type="hidden" name="importdetail"
5786: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 5787: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5788: $help{'Navigate_Content'}
5789: </form>
5790: NNFORM
5791: my $newsmppageform=(<<NSPFORM);
5792: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5793: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5794: $pathitem
1.329 droeschl 5795: <input type="hidden" name="importdetail" value="" />
1.423 onken 5796: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5797: $help{'Simple Page'}
1.329 droeschl 5798: </form>
5799: NSPFORM
5800:
5801: my $newsmpproblemform=(<<NSPROBFORM);
5802: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5803: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5804: $pathitem
1.329 droeschl 5805: <input type="hidden" name="importdetail" value="" />
1.423 onken 5806: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5807: $help{'Simple_Problem'}
1.329 droeschl 5808: </form>
5809:
5810: NSPROBFORM
5811:
5812: my $newdropboxform=(<<NDBFORM);
5813: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5814: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5815: $pathitem
1.329 droeschl 5816: <input type="hidden" name="importdetail" value="" />
1.423 onken 5817: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5818: $help{'Dropbox'}
1.344 bisitz 5819: </form>
1.329 droeschl 5820: NDBFORM
5821:
5822: my $newexuploadform=(<<NEXUFORM);
5823: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5824: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5825: $pathitem
1.329 droeschl 5826: <input type="hidden" name="importdetail" value="" />
1.423 onken 5827: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5828: $help{'Score_Upload_Form'}
5829: </form>
5830: NEXUFORM
5831:
5832: my $newbulform=(<<NBFORM);
5833: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5834: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5835: $pathitem
1.329 droeschl 5836: <input type="hidden" name="importdetail" value="" />
1.423 onken 5837: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5838: $help{'Bulletin Board'}
5839: </form>
5840: NBFORM
5841:
5842: my $newaboutmeform=(<<NAMFORM);
5843: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5844: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5845: $pathitem
1.329 droeschl 5846: <input type="hidden" name="importdetail"
5847: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 5848: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5849: $help{'My Personal Information Page'}
1.329 droeschl 5850: </form>
5851: NAMFORM
5852:
5853: my $newaboutsomeoneform=(<<NASOFORM);
5854: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5855: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5856: $pathitem
1.329 droeschl 5857: <input type="hidden" name="importdetail" value="" />
1.423 onken 5858: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5859: </form>
5860: NASOFORM
5861:
5862: my $newrosterform=(<<NROSTFORM);
5863: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5864: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5865: $pathitem
1.329 droeschl 5866: <input type="hidden" name="importdetail"
5867: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 5868: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 5869: $help{'Course_Roster'}
1.329 droeschl 5870: </form>
5871: NROSTFORM
5872:
1.534 raeburn 5873: my $newwebpage;
5874: if ($folder =~ /^default_?(\d*)$/) {
5875: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5876: if ($1) {
5877: $newwebpage .= $1;
5878: } else {
5879: $newwebpage .= 'default';
5880: }
5881: $newwebpage .= '/new.html';
5882: }
5883: my $newwebpageform =(<<NWEBFORM);
5884: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5885: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5886: $pathitem
5887: <input type="hidden" name="importdetail" value="$newwebpage" />
5888: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5889: $help{'Web_Page'}
1.534 raeburn 5890: </form>
5891: NWEBFORM
1.604 raeburn 5892:
1.606 raeburn 5893: my @ids=&Apache::lonnet::current_machine_ids();
5894: my %select_menus;
5895: my $numauthor = 0;
5896: my $numcrsdirs = 0;
5897: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5898: if ($env{'user.author'}) {
5899: $numauthor ++;
5900: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5901: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5902: my $is_home = 1;
5903: my %subdirs;
1.608 raeburn 5904: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5905: $select_menus{'author'}->{'default'} = '/';
5906: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5907: my @ordered = ('/');
5908: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5909: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5910: push(@ordered,$relpath);
5911: }
5912: $select_menus{'author'}->{'order'} = \@ordered;
5913: } else {
5914: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5915: $select_menus{'author'}->{'default'} = 'switch';
5916: $select_menus{'author'}->{'order'} = ['switch'];
5917: }
5918: }
5919: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5920: ['active'],['ca','aa']);
5921: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5922: my %by_roletype;
5923: if (keys(%roleshash)) {
5924: foreach my $entry (keys(%roleshash)) {
5925: my ($auname,$audom,$roletype) = split(/:/,$entry);
5926: my $key = $entry;
5927: $key =~ s/:/___/g;
5928: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5929: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5930: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5931: if (grep(/^\Q$rolehome\E$/,@ids)) {
5932: my $is_home = 1;
5933: my (%subdirs,@ordered);
5934: my $toppath="/priv/$audom/$auname";
1.608 raeburn 5935: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5936: $select_menus{$key}->{'default'} = '/';
5937: $select_menus{$key}->{'select2'}->{'/'} = '/';
5938: my @ordered = ('/');
5939: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5940: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
5941: push(@ordered,$relpath);
5942: }
5943: $select_menus{$key}->{'order'} = \@ordered;
5944: } else {
5945: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
5946: $select_menus{$key}->{'default'} = 'switch';
5947: $select_menus{$key}->{'order'} = ['switch'];
5948: }
5949: $numauthor ++;
5950: }
5951: }
5952: my ($pickdir,$showtitle);;
5953: if ($numauthor) {
5954: my @order;
5955: my $defrole;
5956: if ($env{'user.author'}) {
5957: push(@order,'author');
5958: $defrole = 'author';
5959: }
5960: if (keys(%by_roletype)) {
5961: foreach my $possrole ('ca','aa') {
5962: if (ref($by_roletype{$possrole}) eq 'HASH') {
5963: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
5964: unless ($defrole) {
5965: $defrole = $author;
5966: }
5967: push(@order,$author.'___'.$possrole);
5968: }
5969: }
5970: }
5971: }
5972: $select_menus{'course'}->{'text'} = &mt('Course Resource');
5973: if (grep(/^\Q$crshome\E$/,@ids)) {
5974: my $is_home = 1;
5975: my %subdirs;
5976: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 5977: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5978: $numcrsdirs = keys(%subdirs);
5979: $select_menus{'course'}->{'default'} = '/';
5980: $select_menus{'course'}->{'select2'}->{'/'} = '/';
5981: my @ordered = ('/');
5982: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5983: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
5984: push(@ordered,$relpath);
5985: }
5986: $select_menus{'course'}->{'order'} = \@ordered;
5987: } else {
5988: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
5989: $select_menus{'course'}->{'default'} = 'switch';
5990: $select_menus{'course'}->{'order'} = ['switch'];
5991: }
5992: push(@order,'course');
5993: $pickdir = $lt{'loca'}.
5994: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
5995: $defrole,'authorrole','authorpath',
5996: \%select_menus,\@order,'toggleCrsResTitle();',
5997: '','priv').'<br />';
5998: $showtitle = 'none';
5999: } else {
6000: my $is_home;
6001: $showtitle = 'inline';
6002: if (grep(/^\Q$crshome\E$/,@ids)) {
6003: $is_home = 1;
6004: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6005: my $toppath="/priv/$coursedom/$coursenum'}";
6006: my %subdirs;
1.608 raeburn 6007: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6008: $numcrsdirs = keys(%subdirs);
6009: if ($numcrsdirs) {
6010: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6011: '<option value="/">/</option>'."\n";
6012: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6013: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6014: }
6015: $pickdir .= '</select>';
6016: } else {
6017: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6018: }
6019: }
6020: }
6021:
6022: my %seltemplate_menus;
6023: my @files = &Apache::lonhomework::get_template_list('problem');
6024: my @noexamplelink = ('blank.problem','blank.library','script.library');
6025: my $currentcategory = '';
6026: my @ordered = ('');
6027: my %templatehelp;
6028: my $defcategory = '';
6029: my @catorder = ($defcategory);
6030: $seltemplate_menus{$defcategory}->{'order'} = [''];
6031: $seltemplate_menus{$defcategory}->{'text'} = '';
6032: foreach my $file (@files) {
6033: if (ref($file) eq 'ARRAY') {
6034: my ($path,$title,$category,$help) = @{$file};
6035: next if ($title !~ /\S/);
6036: if (&js_escape($category) ne $currentcategory) {
6037: $currentcategory = &js_escape($category);
6038: push(@catorder,&js_escape($currentcategory));
6039: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6040: $seltemplate_menus{$currentcategory}->{'default'} = '';
6041: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6042: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6043: }
6044: if ($path) {
6045: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6046: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6047: if ($help) {
6048: $templatehelp{$path} = $help;
6049: }
6050: }
6051: }
6052: }
6053:
6054: my $templates = $lt{'cate'}.' '.
6055: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6056: $defcategory,'tempcategory','template',
6057: \%seltemplate_menus,\@catorder,
6058: "resize_scrollbox('contentscroll','1','0');",
6059: "toggleExampleText();",'template').'<br />';
6060: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6061: '<span id="newresexample">'.&mt('Example').'<span></a>';
6062: my $crsresform=(<<RESFORM);
6063: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6064: $lt{'stpr'}</a>$help{'Course_Resource'}
6065: <form action="/adm/coursedocs" method="post" name="courseresform">
6066: <fieldset id="crsresform" style="display:none;">
6067: <legend>$lt{'stpr'}</legend>
6068: <input type="hidden" name="active" value="ee" />
6069: <p>
6070: $pickdir
6071: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6072: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6073:
1.611 raeburn 6074: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6075: </span><span id="newsubdir"></span>
6076: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6077: </p>
6078: $lt{'fnam'}
1.611 raeburn 6079: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6080: <p>
6081: <div id="newresource" style="display:$showtitle">
6082: $lt{'addp'}
1.611 raeburn 6083: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6084: $lt{'no'}</label>
1.611 raeburn 6085: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6086: $lt{'yes'}</label>
6087: <span id="newrestitle"></span>
1.611 raeburn 6088: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6089: </div>
6090: </p>
6091: <p>
6092: $lt{'uste'}
1.611 raeburn 6093: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6094: $lt{'no'}</label>
1.611 raeburn 6095: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6096: $lt{'yes'}</label>
6097: <div id="newrestemplate" style="display:none">
6098: $templates
6099: $templatepreview
6100: </div>
6101: </p>
6102: <span class="LC_nobreak">
6103: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6104: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6105: </span>
6106: </fieldset>
6107: </form>
6108:
6109: RESFORM
1.534 raeburn 6110:
1.342 ehlerst 6111: my $specialdocumentsform;
1.383 tempelho 6112: my @specialdocumentsforma;
1.451 www 6113: my $gradingform;
6114: my @gradingforma;
6115: my $communityform;
6116: my @communityforma;
1.351 ehlerst 6117: my $newfolderform;
1.390 tempelho 6118: my $newfolderb;
1.342 ehlerst 6119:
1.451 www 6120: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6121:
1.329 droeschl 6122: my $newpageform=(<<NPFORM);
6123: <form action="/adm/coursedocs" method="post" name="newpage">
6124: <input type="hidden" name="folderpath" value="$path" />
6125: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6126: <input type="hidden" name="active" value="ee" />
1.423 onken 6127: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6128: $help{'Adding_Pages'}
1.329 droeschl 6129: </form>
6130: NPFORM
1.390 tempelho 6131:
6132:
1.351 ehlerst 6133: $newfolderform=(<<NFFORM);
1.329 droeschl 6134: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6135: $pathitem
1.329 droeschl 6136: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6137: <input type="hidden" name="active" value="" />
1.422 onken 6138: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6139: </form>
6140: NFFORM
6141:
6142: my $newsylform=(<<NSYLFORM);
6143: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6144: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6145: $pathitem
1.329 droeschl 6146: <input type="hidden" name="importdetail"
6147: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6148: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6149: $help{'Syllabus'}
1.383 tempelho 6150:
1.329 droeschl 6151: </form>
6152: NSYLFORM
1.364 bisitz 6153:
1.329 droeschl 6154: my $newgroupfileform=(<<NGFFORM);
6155: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6156: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6157: $pathitem
1.329 droeschl 6158: <input type="hidden" name="importdetail"
6159: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6160: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6161: $help{'Group Portfolio'}
1.329 droeschl 6162: </form>
6163: NGFFORM
1.383 tempelho 6164: @specialdocumentsforma=(
1.421 onken 6165: {'<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 6166: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6167: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6168: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6169: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6170: );
6171: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6172:
1.434 raeburn 6173:
6174: my @importdoc = (
1.519 raeburn 6175: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6176: );
1.598 raeburn 6177: if (keys(%ltitools)) {
6178: push(@importdoc,
6179: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6180: );
6181: }
1.519 raeburn 6182: unless ($container eq 'page') {
6183: push(@importdoc,
6184: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6185: );
6186: }
6187: push(@importdoc,
1.558 raeburn 6188: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6189: );
1.501 raeburn 6190: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6191:
1.451 www 6192: @gradingforma=(
6193: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6194: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6195: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6196: {'<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 6197: );
6198: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6199:
6200: @communityforma=(
6201: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6202: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6203: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6204: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6205: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6206: );
6207: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6208:
1.330 tempelho 6209: my %orderhash = (
1.553 raeburn 6210: 'aa' => ['Upload',$fileuploadform],
6211: 'bb' => ['Import',$importpubform],
6212: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6213: );
1.519 raeburn 6214: unless ($container eq 'page') {
1.434 raeburn 6215: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6216: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6217: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6218: }
6219:
1.341 ehlerst 6220: $hadchanges=0;
1.484 raeburn 6221: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6222: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6223: $supplementalflag,\%orderhash,$iconpath,$pathitem,
6224: \%ltitools,$canedit,\$navmap,$hiddentop);
1.617 raeburn 6225: undef($navmap);
1.443 www 6226: if ($error) {
6227: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6228: }
6229: if ($hadchanges) {
6230: &mark_hash_old();
6231: }
1.341 ehlerst 6232:
1.443 www 6233: &changewarning($r,'');
6234: }
1.458 raeburn 6235: }
1.442 www 6236:
1.443 www 6237: # Supplemental documents start here
6238:
1.329 droeschl 6239: my $folder=$env{'form.folder'};
1.443 www 6240: unless ($supplementalflag) {
1.329 droeschl 6241: $folder='supplemental';
6242: }
6243: if ($folder =~ /^supplemental$/ &&
6244: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6245: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6246: } elsif ($allowed) {
1.356 tempelho 6247: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6248: }
1.508 raeburn 6249: $pathitem = '<input type="hidden" name="folderpath" value="'.
6250: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6251: if ($allowed) {
6252: my $folderseq=
1.504 raeburn 6253: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6254:
6255: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6256: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6257: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6258: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6259: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6260: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6261: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6262: $fileupload
6263: <br />
6264: <br />
6265: <span class="LC_nobreak">
6266: $checkbox
6267: </span>
6268: <br /><br />
6269: $lt{'comment'}:<br />
1.383 tempelho 6270: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6271: <br />
1.508 raeburn 6272: $pathitem
1.329 droeschl 6273: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6274: <input type='submit' value="$lt{'upld'}" />
6275: </form>
1.329 droeschl 6276: SUPDOCFORM
6277:
6278: my $supnewfolderform=(<<SNFFORM);
6279: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6280: <input type="hidden" name="active" value="" />
1.508 raeburn 6281: $pathitem
1.329 droeschl 6282: <input type="hidden" name="importdetail" value="" />
1.423 onken 6283: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6284: $help{'Adding_Folders'}
1.329 droeschl 6285: </form>
6286: SNFFORM
1.383 tempelho 6287:
1.510 raeburn 6288: my $supextform =
6289: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6290: $help{'Adding_External_Resource'},
6291: undef,undef,undef,undef,undef,undef,
6292: $disabled);
1.329 droeschl 6293:
1.598 raeburn 6294: my $supexttoolform =
6295: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6296: $help{'Adding_External_Tool'},
6297: undef,undef,'tool',$coursedom,
1.611 raeburn 6298: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6299:
1.329 droeschl 6300: my $supnewsylform=(<<SNSFORM);
6301: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6302: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6303: $pathitem
1.329 droeschl 6304: <input type="hidden" name="importdetail"
6305: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6306: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6307: $help{'Syllabus'}
6308: </form>
6309: SNSFORM
6310:
6311: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6312: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6313: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6314: $pathitem
1.329 droeschl 6315: <input type="hidden" name="importdetail"
6316: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6317: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6318: $help{'My Personal Information Page'}
1.329 droeschl 6319: </form>
6320: SNAMFORM
6321:
1.534 raeburn 6322: my $supwebpage;
6323: if ($folder =~ /^supplemental_?(\d*)$/) {
6324: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6325: if ($1) {
6326: $supwebpage .= $1;
6327: } else {
6328: $supwebpage .= 'default';
6329: }
6330: $supwebpage .= '/new.html';
6331: }
6332: my $supwebpageform =(<<SWEBFORM);
6333: <form action="/adm/coursedocs" method="post" name="supwebpage">
6334: <input type="hidden" name="active" value="cc" />
6335: $pathitem
6336: <input type="hidden" name="importdetail" value="$supwebpage" />
6337: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6338: $help{'Web_Page'}
1.534 raeburn 6339: </form>
6340: SWEBFORM
6341:
1.333 muellerd 6342:
1.383 tempelho 6343: my @specialdocs = (
1.618 raeburn 6344: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6345: =>$supnewsylform},
1.611 raeburn 6346: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6347: =>$supnewaboutmeform},
1.534 raeburn 6348: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6349:
1.383 tempelho 6350: );
1.417 droeschl 6351: my @supimportdoc = (
1.515 raeburn 6352: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6353: =>$supextform});
6354: if (keys(%ltitools)) {
6355: push(@supimportdoc,
6356: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6357: =>$supexttoolform});
6358: }
6359: push(@supimportdoc,
6360: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6361: =>$supupdocform},
1.598 raeburn 6362: );
1.501 raeburn 6363:
6364: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6365: my %suporderhash = (
1.390 tempelho 6366: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6367: 'ee' => ['Upload',$supupdocform],
6368: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6369: );
1.443 www 6370: if ($supplementalflag) {
1.458 raeburn 6371: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6372: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.617 raeburn 6373: \%ltitools,$canedit);
1.443 www 6374: if ($error) {
6375: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6376: } else {
6377: if ($suppchanges) {
6378: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6379: my @ids=&Apache::lonnet::current_machine_ids();
6380: foreach my $server (keys(%servers)) {
6381: next if (grep(/^\Q$server\E$/,@ids));
6382: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6383: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6384: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6385: }
6386: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6387: undef($suppchanges);
6388: }
6389: }
1.393 raeburn 6390: }
1.443 www 6391: } elsif ($supplementalflag) {
1.458 raeburn 6392: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6393: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 6394: if ($error) {
6395: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6396: }
1.393 raeburn 6397: }
1.389 tempelho 6398:
1.510 raeburn 6399: if ($needs_end) {
6400: $r->print(&endContentScreen());
6401: }
1.383 tempelho 6402:
1.329 droeschl 6403: if ($allowed) {
6404: $r->print('
6405: <form method="post" name="extimport" action="/adm/coursedocs">
6406: <input type="hidden" name="title" />
6407: <input type="hidden" name="url" />
6408: <input type="hidden" name="useform" />
6409: <input type="hidden" name="residx" />
6410: </form>');
6411: }
1.484 raeburn 6412: } elsif ($showdoc) {
1.329 droeschl 6413: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6414: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6415: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6416: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6417: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6418: }
6419: }
1.606 raeburn 6420: unless ($noendpage) {
6421: $r->print(&Apache::loncommon::end_page());
6422: }
1.329 droeschl 6423: return OK;
1.364 bisitz 6424: }
1.329 droeschl 6425:
1.440 raeburn 6426: sub embedded_form_elems {
6427: my ($phase,$primaryurl,$newidx) = @_;
6428: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6429: return <<STATE;
6430: <input type="hidden" name="folderpath" value="$folderpath" />
6431: <input type="hidden" name="cmd" value="upload_embedded" />
6432: <input type="hidden" name="newidx" value="$newidx" />
6433: <input type="hidden" name="phase" value="$phase" />
6434: <input type="hidden" name="primaryurl" value="$primaryurl" />
6435: STATE
6436: }
6437:
6438: sub embedded_destination {
6439: my $folder=$env{'form.folder'};
6440: my $destination = 'docs/';
6441: if ($folder =~ /^supplemental/) {
6442: $destination = 'supplemental/';
6443: }
6444: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6445: $destination .= 'default/';
6446: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6447: $destination .= $2.'/';
6448: }
6449: $destination .= $env{'form.newidx'};
6450: my $dir_root = '/userfiles';
6451: return ($destination,$dir_root);
6452: }
6453:
6454: sub return_to_editor {
6455: my $actionurl = '/adm/coursedocs';
6456: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6457: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6458: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6459: '</a></p>';
6460: }
6461:
1.476 raeburn 6462: sub decompression_info {
6463: my ($destination,$dir_root) = &embedded_destination();
6464: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6465: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6466: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6467: my $container='sequence';
1.480 raeburn 6468: my ($pathitem,$hiddenelem);
1.583 raeburn 6469: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6470: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6471: $container='page';
6472: }
1.480 raeburn 6473: unshift(@hiddens,$pathitem);
6474: foreach my $item (@hiddens) {
6475: if ($env{'form.'.$item}) {
6476: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6477: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6478: }
1.477 raeburn 6479: }
1.476 raeburn 6480: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6481: $hiddenelem);
6482: }
6483:
6484: sub decompression_phase_one {
6485: my ($dir,$file,$warning,$error,$output);
6486: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6487: &decompression_info();
1.490 raeburn 6488: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6489: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6490: } else {
6491: my $file = $1;
1.481 raeburn 6492: $output =
6493: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6494: $destination,$dir_root,
6495: $hiddenelem);
6496: if ($env{'form.autoextract_camtasia'}) {
6497: $output .= &remove_archive($docudom,$docuname,$container);
6498: }
1.476 raeburn 6499: }
6500: if ($error) {
6501: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6502: $error.'</p>'."\n";
6503: }
6504: if ($warning) {
6505: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6506: }
6507: return $output;
6508: }
6509:
6510: sub decompression_phase_two {
6511: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6512: &decompression_info();
1.481 raeburn 6513: my $output;
1.480 raeburn 6514: if ($env{'form.archivedelete'}) {
1.481 raeburn 6515: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6516: }
6517: $output .=
1.481 raeburn 6518: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6519: $destination,$dir_root,$hiddenelem);
6520: return $output;
6521: }
6522:
1.480 raeburn 6523: sub remove_archive {
6524: my ($docudom,$docuname,$container) = @_;
6525: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6526: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6527: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6528: if ($fatal) {
6529: if ($container eq 'page') {
6530: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6531: } else {
6532: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6533: }
1.583 raeburn 6534: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6535: } else {
6536: my $currcmd = $env{'form.cmd'};
6537: my $position = $env{'form.position'};
1.583 raeburn 6538: my $archiveidx = $position;
1.563 raeburn 6539: if ($position > 0) {
1.583 raeburn 6540: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6541: $archiveidx = $position-1;
6542: }
6543: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6544: my ($title,$url,@rrest) =
1.583 raeburn 6545: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6546: if ($url eq $env{'form.archiveurl'}) {
6547: if (&handle_edit_cmd($docuname,$docudom)) {
6548: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6549: if ($fatal) {
6550: if ($container eq 'page') {
6551: $delwarning = &mt('An error occurred updating the contents of the current page.');
6552: } else {
6553: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6554: }
1.480 raeburn 6555: } else {
1.583 raeburn 6556: $delresult = &mt('Archive file removed.');
1.480 raeburn 6557: }
6558: }
1.583 raeburn 6559: } else {
6560: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6561: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6562: }
6563: }
6564: $env{'form.cmd'} = $currcmd;
6565: }
6566: if ($delwarning) {
6567: $output = '<p class="LC_warning">'.
6568: $delwarning.
6569: '</p>';
6570: }
6571: if ($delresult) {
6572: $output .= '<p class="LC_info">'.
6573: $delresult.
6574: '</p>';
6575: }
1.481 raeburn 6576: return $output;
1.480 raeburn 6577: }
6578:
1.484 raeburn 6579: sub generate_admin_menu {
1.611 raeburn 6580: my ($crstype,$canedit) = @_;
1.484 raeburn 6581: my $lc_crstype = lc($crstype);
6582: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6583: my %lt= ( # do not translate here
1.484 raeburn 6584: 'vc' => 'Verify Content',
6585: 'cv' => 'Check/Set Resource Versions',
6586: 'ls' => 'List Resource Identifiers',
6587: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6588: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6589: );
1.484 raeburn 6590: my ($candump,$dumpurl);
6591: if ($home + $other > 0) {
6592: $candump = 'F';
6593: if ($home) {
6594: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6595: } else {
6596: my @hosts;
6597: foreach my $aurole (keys(%outhash)) {
6598: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6599: push(@hosts,$outhash{$aurole});
1.538 raeburn 6600: }
1.484 raeburn 6601: }
6602: if (@hosts == 1) {
6603: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6604: '&role='.
6605: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6606: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6607: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6608: } else {
6609: $dumpurl = "javascript:choose_switchserver_window()";
6610: }
6611: }
6612: }
6613: my @menu=
6614: ({ categorytitle=>'Administration',
6615: items =>[
6616: { linktext => $lt{'vc'},
6617: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6618: permission => 'F',
1.571 raeburn 6619: help => 'Docs_Verify_Content',
1.484 raeburn 6620: icon => 'verify.png',
6621: linktitle => 'Verify contents can be retrieved/rendered',
6622: },
6623: { linktext => $lt{'cv'},
6624: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6625: permission => 'F',
1.571 raeburn 6626: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6627: icon => 'resversion.png',
6628: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6629: },
6630: { linktext => $lt{'ls'},
6631: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6632: permission => 'F',
6633: #help => '',
6634: icon => 'symbs.png',
6635: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6636: },
6637: ]
1.611 raeburn 6638: });
6639: if ($canedit) {
6640: push(@menu,
1.484 raeburn 6641: { categorytitle=>'Export',
6642: items =>[
6643: { linktext => $lt{'imse'},
6644: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6645: permission => 'F',
6646: help => 'Docs_Export_Course_Docs',
6647: icon => 'imsexport.png',
6648: linktitle => $lt{'imse'},
6649: },
6650: { linktext => $lt{'dcd'},
6651: url => $dumpurl,
6652: permission => $candump,
1.571 raeburn 6653: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6654: icon => 'dump.png',
6655: linktitle => $lt{'dcd'},
6656: },
6657: ]
6658: });
1.611 raeburn 6659: }
1.484 raeburn 6660: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6661: '<input type="hidden" id="dummy" />'."\n".
6662: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6663: '</form>';
1.329 droeschl 6664: }
6665:
6666: sub generate_edit_table {
1.538 raeburn 6667: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6668: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6669: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6670: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6671: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6672: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6673: $activetab = $env{'form.active'};
6674: }
1.611 raeburn 6675: unless ($canedit) {
6676: $disabled = ' disabled="disabled"';
6677: }
1.472 raeburn 6678: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6679: my $backtext = &mt('Exit Editor');
1.458 raeburn 6680: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6681: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6682: '<li class="goback">'.
1.546 raeburn 6683: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6684: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6685: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6686: '<li>'.
6687: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6688: &mt('Undo Delete').'</a></li>'."\n";
6689: if ($env{'form.docslog'}) {
6690: $form .= '<li class="active">';
6691: } else {
6692: $form .= '<li>';
6693: }
6694: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6695: &mt('History').'</a></li>'."\n";
6696: if ($env{'form.docslog'}) {
6697: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6698: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6699: }
1.458 raeburn 6700: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6701: if($name ne '00'){
1.371 tempelho 6702: if($activetab eq '' || $activetab ne $name){
6703: $active = '';
6704: }elsif($activetab eq $name){
6705: $active = 'class="active"';
6706: }
1.458 raeburn 6707: $form .= '<li style="float:right" '.$active
1.484 raeburn 6708: .' 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 6709: } else {
1.570 raeburn 6710: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6711:
6712: }
1.329 droeschl 6713: }
1.484 raeburn 6714: $form .= '</ul>'."\n";
6715: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6716:
6717: if ($to_show ne '') {
1.538 raeburn 6718: my $saveform;
6719: if ($need_save) {
6720: my $button = &mt('Make changes');
6721: my $path;
6722: if ($env{'form.folderpath'}) {
6723: $path =
6724: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6725: }
6726: $saveform = <<"END";
6727: <div id="multisave" style="display:none; clear:both;" >
6728: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6729: <input type="hidden" name="folderpath" value="$path" />
6730: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6731: <input type="hidden" name="allhiddenresource" value="" />
6732: <input type="hidden" name="allencrypturl" value="" />
6733: <input type="hidden" name="allrandompick" value="" />
6734: <input type="hidden" name="allrandomorder" value="" />
6735: <input type="hidden" name="changeparms" value="" />
6736: <input type="hidden" name="multiremove" value="" />
6737: <input type="hidden" name="multicut" value="" />
6738: <input type="hidden" name="multicopy" value="" />
6739: <input type="hidden" name="multichange" value="" />
6740: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 6741: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 6742: </form>
6743: </div>
6744: END
6745: }
6746: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6747: }
1.363 ehlerst 6748: foreach my $field (keys(%orderhash)){
1.390 tempelho 6749: if($field ne '00'){
1.422 onken 6750: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6751: $active = 'style="display: none;float:left"';
1.422 onken 6752: }elsif($activetab eq $field){
1.458 raeburn 6753: $active = 'style="display:block;float:left"';
1.422 onken 6754: }
6755: $form .= '<div id="'.$field.$tid.'"'
6756: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6757: .'</div>'."\n";
1.363 ehlerst 6758: }
6759: }
1.484 raeburn 6760: unless ($env{'form.docslog'}) {
6761: $form .= '</div></div>'."\n";
6762: }
1.329 droeschl 6763: return $form;
6764: }
6765:
6766: sub editing_js {
1.617 raeburn 6767: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot,$canedit,$navmapref) = @_;
1.594 damieng 6768: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6769: p_mnf => 'Name of New Folder',
6770: t_mnf => 'New Folder',
6771: p_mnp => 'Name of New Page',
6772: t_mnp => 'New Page',
1.451 www 6773: p_mxu => 'Title for the External Score',
1.349 biermanm 6774: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6775: p_msb => 'Title for the Problem',
6776: p_mdb => 'Title for the Drop Box',
1.336 schafran 6777: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 6778: p_mwp => 'Title for Web Page',
1.606 raeburn 6779: p_mnr => 'Title for the Resource',
1.348 weissno 6780: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6781: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6782: p_mab_alrt1 => 'Not a valid user:domain',
6783: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6784: p_chn => 'New Title',
6785: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 6786: p_rmr2a => 'Remove',
6787: p_rmr2b => '?',
6788: p_rmr3a => 'Remove those',
6789: p_rmr3b => 'items?',
6790: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6791: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6792: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6793: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 6794: p_ctr2a => 'Cut',
6795: p_ctr2b => '?',
6796: p_ctr3a => 'Cut those',
6797: p_ctr3b => 'items?',
1.478 raeburn 6798: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6799: imsfile => 'You must choose an IMS package for import',
6800: imscms => 'You must select which Course Management System was the source of the IMS package',
6801: invurl => 'Invalid URL',
6802: titbl => 'Title is blank',
1.538 raeburn 6803: more => '(More ...)',
6804: less => '(Less ...)',
1.543 raeburn 6805: noor => 'No actions selected or changes to settings specified.',
6806: noch => 'No changes to settings specified.',
6807: noac => 'No actions selected.',
1.606 raeburn 6808: nofi => 'No file selected',
6809: tinc => 'Title in course',
6810: sunm => 'Sub-directory name',
1.618 raeburn 6811: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6812: );
1.594 damieng 6813: &js_escape(\%js_lt);
1.433 raeburn 6814: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6815: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6816: my $main_container_page;
1.519 raeburn 6817: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6818: $main_container_page = 1;
1.434 raeburn 6819: }
1.617 raeburn 6820: my $backtourl;
6821: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6822: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6823:
1.530 raeburn 6824: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6825: my $caller = $1;
1.525 raeburn 6826: if ($caller =~ /^supplemental/) {
6827: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6828: } else {
6829: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6830: $res = &Apache::lonnet::clutter($res);
6831: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 6832: my ($url,$anchor);
6833: if ($res =~ /^([^#]+)#([^#]+)$/) {
6834: $url = $1;
6835: $anchor = $2;
6836: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6837: $caller = $1.&escape('#').$anchor;
6838: }
1.614 raeburn 6839: } else {
6840: $url = $res;
1.609 raeburn 6841: }
6842: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 6843: &HTML::Entities::encode($caller,'<>&"');
1.609 raeburn 6844: if ($anchor ne '') {
6845: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6846: }
1.590 raeburn 6847: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6848: } else {
6849: $backtourl = '/adm/navmaps';
1.525 raeburn 6850: }
6851: }
6852: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6853: $backtourl = '/adm/menu';
6854: } elsif ($supplementalflag) {
1.472 raeburn 6855: $backtourl = '/adm/supplemental';
1.525 raeburn 6856: } else {
6857: $backtourl = '/adm/navmaps';
1.472 raeburn 6858: }
6859:
1.600 raeburn 6860: my $fieldsets = "'ext','doc'";
6861: if ($posslti) {
6862: $fieldsets .= ",'tool'";
6863: }
1.519 raeburn 6864: unless ($main_container_page) {
6865: $fieldsets .=",'ims'";
6866: }
1.501 raeburn 6867: if ($supplementalflag) {
1.600 raeburn 6868: $fieldsets = "'suppext','suppdoc'";
6869: if ($posslti) {
6870: $fieldsets .= ",'supptool'";
6871: }
1.501 raeburn 6872: }
1.611 raeburn 6873:
6874: my $jsmakefunctions;
6875: if ($canedit) {
6876: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6877: function makenewfolder(targetform,folderseq) {
1.594 damieng 6878: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6879: if (foldername) {
6880: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6881: targetform.submit();
6882: }
6883: }
6884:
6885: function makenewpage(targetform,folderseq) {
1.594 damieng 6886: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6887: if (pagename) {
6888: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6889: targetform.submit();
6890: }
6891: }
6892:
6893: function makeexamupload() {
1.594 damieng 6894: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6895: if (title) {
1.329 droeschl 6896: this.document.forms.newexamupload.importdetail.value=
6897: escape(title)+'=/res/lib/templates/examupload.problem';
6898: this.document.forms.newexamupload.submit();
6899: }
6900: }
6901:
6902: function makesmppage() {
1.594 damieng 6903: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6904: if (title) {
1.329 droeschl 6905: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 6906: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6907: this.document.forms.newsmppg.submit();
6908: }
6909: }
6910:
1.534 raeburn 6911: function makewebpage(type) {
1.594 damieng 6912: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 6913: var formname;
6914: if (type == 'supp') {
6915: formname = this.document.forms.supwebpage;
6916: } else {
6917: formname = this.document.forms.newwebpage;
6918: }
6919: if (title) {
6920: var webpage = formname.importdetail.value;
6921: formname.importdetail.value = escape(title)+'='+webpage;
6922: formname.submit();
6923: }
6924: }
6925:
1.329 droeschl 6926: function makesmpproblem() {
1.594 damieng 6927: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6928: if (title) {
1.329 droeschl 6929: this.document.forms.newsmpproblem.importdetail.value=
6930: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6931: this.document.forms.newsmpproblem.submit();
6932: }
6933: }
6934:
6935: function makedropbox() {
1.594 damieng 6936: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6937: if (title) {
1.329 droeschl 6938: this.document.forms.newdropbox.importdetail.value=
6939: escape(title)+'=/res/lib/templates/DropBox.problem';
6940: this.document.forms.newdropbox.submit();
6941: }
6942: }
6943:
6944: function makebulboard() {
1.594 damieng 6945: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6946: if (title) {
6947: this.document.forms.newbul.importdetail.value=
1.533 raeburn 6948: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6949: this.document.forms.newbul.submit();
6950: }
6951: }
6952:
6953: function makeabout() {
1.594 damieng 6954: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6955: if (user) {
6956: var comp=new Array();
6957: comp=user.split(':');
6958: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6959: if ((comp[0]) && (comp[1])) {
6960: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 6961: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 6962: this.document.forms.newaboutsomeone.submit();
6963: } else {
6964: alert("$js_lt{'p_mab_alrt1'}");
6965: }
6966: } else {
6967: alert("$js_lt{'p_mab_alrt2'}");
6968: }
6969: }
6970: }
6971:
6972: function makenew(targetform) {
6973: targetform.submit();
6974: }
6975:
6976: function changename(folderpath,index,oldtitle) {
6977: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6978: if (title) {
6979: this.document.forms.renameform.markcopy.value='';
6980: this.document.forms.renameform.title.value=title;
6981: this.document.forms.renameform.cmd.value='rename_'+index;
6982: this.document.forms.renameform.folderpath.value=folderpath;
6983: this.document.forms.renameform.submit();
6984: }
6985: }
6986:
6987: ENDNEWSCRIPT
6988: } else {
6989: $jsmakefunctions = <<ENDNEWSCRIPT;
6990:
6991: function makenewfolder() {
6992: alert("$js_lt{'edri'}");
6993: }
6994:
6995: function makenewpage() {
6996: alert("$js_lt{'edri'}");
6997: }
6998:
6999: function makeexamupload() {
7000: alert("$js_lt{'edri'}");
7001: }
7002:
7003: function makesmppage() {
7004: alert("$js_lt{'edri'}");
7005: }
7006:
7007: function makewebpage(type) {
7008: alert("$js_lt{'edri'}");
7009: }
7010:
7011: function makesmpproblem() {
7012: alert("$js_lt{'edri'}");
7013: }
7014:
7015: function makedropbox() {
7016: alert("$js_lt{'edri'}");
7017: }
7018:
7019: function makebulboard() {
7020: alert("$js_lt{'edri'}");
7021: }
7022:
7023: function makeabout() {
7024: alert("$js_lt{'edri'}");
7025: }
7026:
7027: function changename() {
7028: alert("$js_lt{'edri'}");
7029: }
7030:
7031: function makenew() {
7032: alert("$js_lt{'edri'}");
7033: }
7034:
7035: function groupimport() {
7036: alert("$js_lt{'edri'}");
1.335 ehlerst 7037: }
1.611 raeburn 7038:
7039: function groupsearch() {
7040: alert("$js_lt{'edri'}");
1.335 ehlerst 7041: }
1.611 raeburn 7042:
7043: function groupopen(url,recover) {
7044: var options="scrollbars=1,resizable=1,menubar=0";
7045: idxflag=1;
7046: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7047: idx.focus();
1.329 droeschl 7048: }
7049:
1.611 raeburn 7050: ENDNEWSCRIPT
7051:
7052: }
7053: return <<ENDSCRIPT;
7054:
7055: $jsmakefunctions
7056:
1.501 raeburn 7057: function toggleUpload(caller) {
7058: var blocks = Array($fieldsets);
7059: for (var i=0; i<blocks.length; i++) {
7060: var disp = 'none';
7061: if (caller == blocks[i]) {
7062: var curr = document.getElementById('upload'+caller+'form').style.display;
7063: if (curr == 'none') {
7064: disp='block';
7065: }
7066: }
7067: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7068: if ((caller == 'tool') || (caller == 'supptool')) {
7069: if (disp == 'block') {
7070: if (document.getElementById('LC_exttoolid')) {
7071: var toolselector = document.getElementById('LC_exttoolid');
7072: var suppflag = 0;
7073: if (caller == 'supptool') {
7074: suppflag = 1;
7075: }
7076: currForm = document.getElementById('new'+caller);
7077: updateExttool(toolselector,currForm,suppflag);
7078: }
7079: }
7080: }
1.501 raeburn 7081: }
1.502 raeburn 7082: resize_scrollbox('contentscroll','1','1');
7083: return;
7084: }
7085:
1.514 raeburn 7086: function toggleMap(caller) {
1.502 raeburn 7087: var disp = 'none';
1.510 raeburn 7088: if (document.getElementById('importmapform')) {
1.514 raeburn 7089: if (caller == 'map') {
7090: var curr = document.getElementById('importmapform').style.display;
7091: if (curr == 'none') {
7092: disp='block';
7093: }
1.510 raeburn 7094: }
7095: document.getElementById('importmapform').style.display=disp;
7096: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7097: }
1.501 raeburn 7098: return;
1.329 droeschl 7099: }
7100:
1.606 raeburn 7101: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7102: var disp = 'none';
7103: if (document.getElementById('crsresform')) {
7104: if (caller == 'res') {
7105: var curr = document.getElementById('crsresform').style.display;
7106: if (curr == 'none') {
7107: disp='block';
7108: numauthor = parseInt(numauthorrole);
7109: if (numauthor > 0) {
7110: document.courseresform.authorrole.selectedIndex = 0;
7111: select1priv_changed();
7112: document.courseresform.authorpath.selectedIndex = 0;
7113: document.courseresform.newresourceadd.selectedIndex = 0;
7114: toggleNewInCourse(document.courseresform);
7115: if (document.getElementById('newresource')) {
7116: document.getElementById('newresource').style.display = 'none';
7117: }
7118: } else {
7119: if (numcrsdirs) {
7120: document.courseresform.authorpath.selectedIndex = 0;
7121: }
7122: }
7123: if (document.courseresform.newresusetemp.length) {
7124: document.courseresform.newresusetemp[0].checked = true;
7125: toggleWithTemplate(document.courseresform);
7126: }
7127: document.courseresform.newresourcename.value = '';
7128: }
7129: }
7130: if (document.courseresform.newsubdir.length) {
7131: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7132: if (document.courseresform.newsubdir[j].value == 0) {
7133: document.courseresform.newsubdir[j].checked = true;
7134: }
7135: break;
7136: }
7137: if (document.getElementById('newsubdirname')) {
7138: document.getElementById('newsubdirname').type = "hidden";
7139: document.getElementById('newsubdirname').value = "";
7140: }
7141: if (document.getElementById('newsubdir')) {
7142: document.getElementById('newsubdir').innerHTML = "";
7143: }
7144: }
7145: document.getElementById('crsresform').style.display=disp;
7146: resize_scrollbox('contentscroll','1','0');
7147: }
7148: return;
7149: }
7150:
7151: function toggleNewsubdir(form) {
7152: if (form.newsubdir.length) {
7153: for (var j=0; j<form.newsubdir.length; j++) {
7154: if (form.newsubdir[j].checked) {
7155: if (document.getElementById('newsubdirname')) {
7156: if (form.newsubdir[j].value == '1') {
7157: document.getElementById('newsubdirname').type = "text";
7158: if (document.getElementById('newsubdir')) {
7159: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7160: }
7161: } else {
7162: document.getElementById('newsubdirname').type = "hidden";
7163: document.getElementById('newsubdirname').value = "";
7164: document.getElementById('newsubdir').innerHTML = "";
7165: }
7166: }
7167: break;
7168: }
7169: }
7170: }
7171: }
7172:
7173: function toggleCrsResTitle() {
7174: if (document.getElementById('newresource')) {
7175: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7176: document.getElementById('newresource').style.display = 'inline';
7177: document.courseresform.newresourceadd[0].checked = true;
7178: toggleNewInCourse(document.courseresform);
7179: } else {
7180: document.getElementById('newresource').style.display = 'none';
7181: }
7182: }
7183: }
7184:
7185: function toggleNewInCourse(form) {
7186: if (form.newresourceadd.length) {
7187: for (var i=0; i<form.newresourceadd.length; i++) {
7188: if (form.newresourceadd[i].checked) {
7189: if (document.getElementById('newresourcetitle')) {
7190: if (form.newresourceadd[i].value == '1') {
7191: document.getElementById('newresourcetitle').type = 'text';
7192: if (document.getElementById('newrestitle')) {
7193: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7194: }
7195: } else {
7196: document.getElementById('newresourcetitle').type = 'hidden';
7197: document.getElementById('newresourcetitle').value = '';
7198: if (document.getElementById('newrestitle')) {
7199: document.getElementById('newrestitle').innerHTML = '';
7200: }
7201: }
7202: }
7203: break;
7204: }
7205: }
7206: }
7207: }
7208:
7209: function toggleWithTemplate(form) {
7210: if (form.newresusetemp.length) {
7211: for (var i=0; i<form.newresusetemp.length; i++) {
7212: if (form.newresusetemp[i].checked) {
7213: if (document.getElementById('newrestemplate')) {
7214: if (form.newresusetemp[i].value == '1') {
7215: document.getElementById('newrestemplate').style.display = 'inline';
7216: toggleExampleText();
7217: } else {
7218: form.tempcategory.selectedIndex = 0;
7219: select1template_changed();
7220: document.getElementById('newrestemplate').style.display = 'none';
7221: }
7222: }
7223: }
7224: }
7225: }
7226: }
7227:
7228: function toggleExampleText() {
7229: if (document.getElementById('newresexample')) {
7230: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7231: if (url == '') {
7232: document.getElementById('newresexample').style.fontWeight = 'normal';
7233: } else {
7234: document.getElementById('newresexample').style.fontWeight = 'bold';
7235: }
7236: }
7237: }
7238:
7239: function getExample(width,height,scrolling,transparency) {
7240: var url;
7241: if (document.courseresform.newresusetemp.length) {
7242: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7243: if (document.courseresform.newresusetemp[i].checked) {
7244: if (document.courseresform.newresusetemp[i].value == '1') {
7245: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7246: if (url == '') {
7247: alert('Pick a category and template');
7248: } else {
7249: url = url.replace("$londocroot","");
7250: url += '?inhibitmenu=yes';
7251: }
7252: }
7253: break;
7254: }
7255: }
7256: }
7257: if (url != '') {
7258: openMyModal(url,width,height,scrolling,transparency,'');
7259: }
7260: }
7261:
7262: function toggleImportCrsres(caller,dircount) {
7263: var disp = 'none';
7264: if (document.getElementById('importcrsresform')) {
7265: if (caller == 'res') {
7266: var numdirs = parseInt(dircount);
7267: var curr = document.getElementById('importcrsresform').style.display;
7268: if (curr == 'none') {
7269: disp='block';
7270: if (numdirs > 1) {
7271: select1res_changed();
7272: }
7273: }
7274: }
7275: document.getElementById('importcrsresform').style.display=disp;
7276: resize_scrollbox('contentscroll','1','0');
7277: }
7278: return;
7279: }
7280:
1.501 raeburn 7281: function makeims(imsform) {
7282: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7283: alert("$js_lt{'imsfile'}");
1.501 raeburn 7284: return;
7285: }
7286: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7287: alert("$js_lt{'imscms'}");
1.501 raeburn 7288: return;
7289: }
7290: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7291: imsform.submit();
7292: }
7293:
1.478 raeburn 7294: function updatePick(targetform,index,caller) {
1.537 raeburn 7295: var pickitem;
7296: var picknumitem;
7297: var picknumtext;
7298: if (index == 'all') {
7299: pickitem = document.getElementById('randompickall');
7300: picknumitem = document.getElementById('rpicknumall');
7301: picknumtext = document.getElementById('rpicktextall');
7302: } else {
7303: pickitem = document.getElementById('randompick_'+index);
7304: picknumitem = document.getElementById('rpicknum_'+index);
7305: picknumtext = document.getElementById('randompicknum_'+index);
7306: }
1.478 raeburn 7307: if (pickitem.checked) {
1.594 damieng 7308: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7309: if (picknum == '' || picknum == null) {
7310: if (caller == 'check') {
7311: pickitem.checked=false;
1.537 raeburn 7312: if (index == 'all') {
7313: picknumtext.innerHTML = '';
7314: if (caller == 'link') {
7315: propagateState(targetform,'rpicknum');
7316: }
7317: } else {
1.538 raeburn 7318: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7319: }
1.478 raeburn 7320: }
7321: } else {
7322: picknum.toString();
7323: var regexdigit=/^\\d+\$/;
7324: if (regexdigit.test(picknum)) {
7325: picknumitem.value = picknum;
1.537 raeburn 7326: if (index == 'all') {
1.538 raeburn 7327: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7328: if (caller == 'link') {
7329: propagateState(targetform,'rpicknum');
7330: }
7331: } else {
7332: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7333: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7334: }
1.478 raeburn 7335: } else {
7336: if (caller == 'check') {
1.537 raeburn 7337: if (index == 'all') {
7338: picknumtext.innerHTML = '';
7339: if (caller == 'link') {
7340: propagateState(targetform,'rpicknum');
7341: }
7342: } else {
7343: pickitem.checked=false;
1.538 raeburn 7344: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7345: }
1.478 raeburn 7346: }
7347: return;
7348: }
7349: }
7350: } else {
1.537 raeburn 7351: picknumitem.value = '';
7352: picknumtext.innerHTML = '';
7353: if (index == 'all') {
7354: if (caller == 'link') {
7355: propagateState(targetform,'rpicknum');
7356: }
7357: } else {
1.538 raeburn 7358: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7359: }
7360: }
7361: }
7362:
7363: function propagateState(form,param) {
7364: if (document.getElementById(param+'all')) {
7365: var setcheck = 0;
7366: var rpick = 0;
7367: if (param == 'rpicknum') {
7368: if (document.getElementById('randompickall')) {
7369: if (document.getElementById('randompickall').checked) {
7370: if (document.getElementById('rpicknumall')) {
7371: rpick = document.getElementById('rpicknumall').value;
7372: }
7373: }
7374: }
7375: } else {
7376: if (document.getElementById(param+'all').checked) {
7377: setcheck = 1;
7378: }
7379: }
1.538 raeburn 7380: var allidxlist;
7381: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7382: if (document.getElementById('all'+param+'idx')) {
7383: allidxlist = document.getElementById('all'+param+'idx').value;
7384: }
7385: var actions = new Array ('remove','cut','copy');
7386: for (var i=0; i<actions.length; i++) {
7387: if (actions[i] != param) {
7388: if (document.getElementById(actions[i]+'all')) {
7389: document.getElementById(actions[i]+'all').checked = false;
7390: }
7391: }
7392: }
7393: }
1.537 raeburn 7394: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7395: allidxlist = form.allidx.value;
7396: }
7397: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7398: allidxlist = form.allmapidx.value;
7399: }
7400: if ((allidxlist != '') && (allidxlist != null)) {
7401: var allidxs = allidxlist.split(',');
7402: if (allidxs.length > 1) {
7403: for (var i=0; i<allidxs.length; i++) {
7404: if (document.getElementById(param+'_'+allidxs[i])) {
7405: if (param == 'rpicknum') {
7406: if (document.getElementById('randompick_'+allidxs[i])) {
7407: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7408: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7409: if (rpick > 0) {
7410: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7411: } else {
7412: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7413: }
7414: }
7415: }
7416: } else {
1.537 raeburn 7417: if (setcheck == 1) {
7418: document.getElementById(param+'_'+allidxs[i]).checked = true;
7419: } else {
7420: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7421: if (param == 'randompick') {
7422: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7423: }
1.537 raeburn 7424: }
7425: }
7426: }
7427: }
1.538 raeburn 7428: if (setcheck == 1) {
7429: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7430: var actions = new Array('copy','cut','remove');
7431: for (var i=0; i<actions.length; i++) {
7432: var otheractions;
7433: var otheridxs;
7434: if (actions[i] === param) {
7435: continue;
7436: } else {
7437: if (document.getElementById('all'+actions[i]+'idx')) {
7438: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7439: otheridxs = otheractions.split(',');
7440: if (otheridxs.length > 1) {
7441: for (var j=0; j<otheridxs.length; j++) {
7442: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7443: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7444: }
1.537 raeburn 7445: }
7446: }
7447: }
1.538 raeburn 7448: }
7449: }
7450: }
7451: }
7452: }
7453: }
7454: }
7455: return;
7456: }
7457:
1.603 raeburn 7458: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7459: var canedit = '$canedit';
7460: if (canedit == '') {
7461: alert("$js_lt{'edri'}");
7462: return;
7463: }
1.539 raeburn 7464: var dosettings;
7465: var doaction;
1.538 raeburn 7466: var control = document.togglemultsettings;
7467: if (context == 'actions') {
7468: control = document.togglemultactions;
1.539 raeburn 7469: doaction = 1;
7470: } else {
7471: dosettings = 1;
1.538 raeburn 7472: }
1.539 raeburn 7473: if (control) {
7474: if (control.showmultpick.length) {
7475: for (var i=0; i<control.showmultpick.length; i++) {
7476: if (control.showmultpick[i].checked) {
7477: if (control.showmultpick[i].value == 1) {
7478: if (context == 'settings') {
7479: dosettings = 0;
7480: } else {
7481: doaction = 0;
1.538 raeburn 7482: }
7483: }
7484: }
1.537 raeburn 7485: }
7486: }
1.539 raeburn 7487: }
7488: if (context == 'settings') {
7489: if (dosettings == 1) {
1.538 raeburn 7490: targetform.changeparms.value=param;
7491: targetform.submit();
7492: }
1.537 raeburn 7493: }
1.539 raeburn 7494: if (context == 'actions') {
7495: if (doaction == 1) {
7496: targetform.cmd.value=param+'_'+index;
7497: targetform.folderpath.value=folderpath;
7498: targetform.markcopy.value=idx+':'+param;
7499: targetform.copyfolder.value=folder+'.'+container;
7500: if (param == 'remove') {
1.603 raeburn 7501: var doremove = 0;
7502: if (skip_confirm) {
7503: if (confirm_removal) {
7504: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7505: doremove = 1;
7506: }
7507: } else {
7508: doremove = 1;
7509: }
7510: } else {
7511: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7512: doremove = 1;
7513: }
7514: }
7515: if (doremove) {
1.539 raeburn 7516: targetform.markcopy.value='';
7517: targetform.copyfolder.value='';
7518: targetform.submit();
7519: }
7520: }
7521: if (param == 'cut') {
1.594 damieng 7522: 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 7523: targetform.submit();
7524: return;
7525: }
7526: }
7527: if (param == 'copy') {
7528: targetform.submit();
7529: return;
7530: }
7531: targetform.markcopy.value='';
7532: targetform.copyfolder.value='';
7533: targetform.cmd.value='';
7534: targetform.folderpath.value='';
7535: return;
7536: } else {
7537: if (document.getElementById(param+'_'+idx)) {
7538: item = document.getElementById(param+'_'+idx);
7539: if (item.type == 'checkbox') {
7540: if (item.checked) {
7541: item.checked = false;
7542: } else {
7543: item.checked = true;
7544: singleCheck(item,idx,param);
7545: }
7546: }
7547: }
7548: }
7549: }
1.537 raeburn 7550: return;
7551: }
7552:
1.538 raeburn 7553: function singleCheck(caller,idx,action) {
7554: actions = new Array('cut','copy','remove');
7555: if (caller.checked) {
7556: for (var i=0; i<actions.length; i++) {
7557: if (actions[i] != action) {
7558: if (document.getElementById(actions[i]+'_'+idx)) {
7559: if (document.getElementById(actions[i]+'_'+idx).checked) {
7560: document.getElementById(actions[i]+'_'+idx).checked = false;
7561: }
1.537 raeburn 7562: }
7563: }
7564: }
1.478 raeburn 7565: }
1.537 raeburn 7566: return;
1.478 raeburn 7567: }
7568:
1.334 muellerd 7569: function unselectInactive(nav) {
1.335 ehlerst 7570: currentNav = document.getElementById(nav);
7571: currentLis = currentNav.getElementsByTagName('LI');
7572: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7573: if (currentLis[i].className == 'goback') {
7574: currentLis[i].className = 'goback';
7575: } else {
7576: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7577: currentLis[i].className = 'right';
1.472 raeburn 7578: } else {
1.374 tempelho 7579: currentLis[i].className = 'i';
1.472 raeburn 7580: }
7581: }
1.335 ehlerst 7582: }
1.332 tempelho 7583: }
7584:
1.334 muellerd 7585: function hideAll(current, nav, data) {
1.335 ehlerst 7586: unselectInactive(nav);
1.570 raeburn 7587: if (current) {
7588: if (current.className == 'right'){
7589: current.className = 'right active'
7590: } else {
7591: current.className = 'active';
7592: }
1.374 tempelho 7593: }
1.335 ehlerst 7594: currentData = document.getElementById(data);
7595: currentDivs = currentData.getElementsByTagName('DIV');
7596: for (i = 0; i < currentDivs.length; i++) {
7597: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7598: currentDivs[i].style.display = 'none';
1.330 tempelho 7599: }
7600: }
1.335 ehlerst 7601: }
1.330 tempelho 7602:
1.374 tempelho 7603: function openTabs(pageId) {
7604: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7605: if(tabnav.length > 2 ){
1.389 tempelho 7606: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7607: currentLis = currentNav.getElementsByTagName('LI');
7608: for(i = 0; i< currentLis.length; i++){
7609: if(currentLis[i].className == 'active') {
1.375 tempelho 7610: funcString = currentLis[i].onclick.toString();
7611: tab = funcString.split('"');
1.420 onken 7612: if(tab.length < 2) {
7613: tab = funcString.split("'");
7614: }
1.375 tempelho 7615: currentData = document.getElementById(tab[1]);
7616: currentData.style.display = 'block';
1.374 tempelho 7617: }
7618: }
7619: }
7620: }
7621:
1.334 muellerd 7622: function showPage(current, pageId, nav, data) {
1.570 raeburn 7623: currstate = current.className;
1.334 muellerd 7624: hideAll(current, nav, data);
1.375 tempelho 7625: openTabs(pageId);
1.334 muellerd 7626: unselectInactive(nav);
1.570 raeburn 7627: if ((currstate == 'active') || (currstate == 'right active')) {
7628: if (currstate == 'active') {
7629: current.className = '';
7630: } else {
7631: current.className = 'right';
7632: }
7633: activeTab = '';
7634: toggleUpload();
7635: toggleMap();
1.606 raeburn 7636: toggleCrsRes();
7637: toggleImportCrsres();
1.570 raeburn 7638: resize_scrollbox('contentscroll','1','0');
7639: return;
7640: } else {
7641: current.className = 'active';
7642: }
1.330 tempelho 7643: currentData = document.getElementById(pageId);
7644: currentData.style.display = 'block';
1.458 raeburn 7645: activeTab = pageId;
1.501 raeburn 7646: toggleUpload();
1.503 raeburn 7647: toggleMap();
1.606 raeburn 7648: toggleCrsRes();
7649: toggleImportCrsres();
1.433 raeburn 7650: if (nav == 'mainnav') {
7651: var storedpath = "$docs_folderpath";
1.434 raeburn 7652: var storedpage = "$main_container_page";
1.433 raeburn 7653: var reg = new RegExp("^supplemental");
7654: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7655: if (storedpage == 1) {
7656: document.simpleedit.folderpath.value = '';
7657: document.uploaddocument.folderpath.value = '';
7658: } else {
7659: if (reg.test(storedpath)) {
7660: document.simpleedit.folderpath.value = '$toplevelmain';
7661: document.uploaddocument.folderpath.value = '$toplevelmain';
7662: document.newext.folderpath.value = '$toplevelmain';
7663: } else {
7664: document.simpleedit.folderpath.value = storedpath;
7665: document.uploaddocument.folderpath.value = storedpath;
7666: document.newext.folderpath.value = storedpath;
7667: }
1.433 raeburn 7668: }
7669: } else {
1.434 raeburn 7670: if (reg.test(storedpath)) {
7671: document.simpleedit.folderpath.value = storedpath;
7672: document.supuploaddocument.folderpath.value = storedpath;
7673: document.supnewext.folderpath.value = storedpath;
7674: } else {
1.433 raeburn 7675: document.simpleedit.folderpath.value = '$toplevelsupp';
7676: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7677: document.supnewext.folderpath.value = '$toplevelsupp';
7678: }
7679: }
7680: }
1.485 raeburn 7681: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7682: return false;
7683: }
1.329 droeschl 7684:
1.472 raeburn 7685: function toContents(jumpto) {
7686: var newurl = '$backtourl';
1.525 raeburn 7687: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7688: newurl = newurl+'?postdata='+jumpto;
7689: }
7690: location.href=newurl;
7691: }
7692:
1.538 raeburn 7693: function togglePick(caller,value) {
7694: var disp = 'none';
7695: if (document.getElementById('multi'+caller)) {
7696: var curr = document.getElementById('multi'+caller).style.display;
7697: if (value == 1) {
7698: disp='block';
7699: }
7700: if (curr == disp) {
7701: return;
7702: }
7703: document.getElementById('multi'+caller).style.display=disp;
7704: if (value == 1) {
1.594 damieng 7705: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7706: } else {
7707: document.getElementById('more'+caller).innerHTML = '';
7708: }
7709: if (caller == 'actions') {
7710: setClass(value);
7711: setBoxes(value);
7712: }
7713: }
7714: var showButton = multiSettings();
7715: if (showButton != 1) {
7716: showButton = multiActions();
7717: }
7718: if (document.getElementById('multisave')) {
7719: if (showButton == 1) {
7720: document.getElementById('multisave').style.display='block';
7721: } else {
7722: document.getElementById('multisave').style.display='none';
7723: }
7724: }
7725: resize_scrollbox('contentscroll','1','1');
7726: return;
7727: }
7728:
7729: function toggleCheckUncheck(caller,more) {
7730: if (more == 1) {
1.594 damieng 7731: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 7732: document.getElementById('allfields'+caller).style.display='block';
7733: } else {
1.594 damieng 7734: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7735: document.getElementById('allfields'+caller).style.display='none';
7736: }
7737: resize_scrollbox('contentscroll','1','1');
7738: }
7739:
7740: function multiSettings() {
7741: var inuse = 0;
7742: var settingsform = document.togglemultsettings;
7743: if (settingsform.showmultpick.length > 1) {
7744: for (var i=0; i<settingsform.showmultpick.length; i++) {
7745: if (settingsform.showmultpick[i].checked) {
7746: if (settingsform.showmultpick[i].value == 1) {
7747: inuse = 1;
7748: }
7749: }
7750: }
7751: }
7752: return inuse;
7753: }
7754:
7755: function multiActions() {
7756: var inuse = 0;
7757: var actionsform = document.togglemultactions;
7758: if (actionsform.showmultpick.length > 1) {
7759: for (var i=0; i<actionsform.showmultpick.length; i++) {
7760: if (actionsform.showmultpick[i].checked) {
7761: if (actionsform.showmultpick[i].value == 1) {
7762: inuse = 1;
7763: }
7764: }
7765: }
7766: }
7767: return inuse;
7768: }
7769:
7770: function checkSubmits() {
7771: var numchanges = 0;
7772: var form = document.saveactions;
7773: var doactions = multiActions();
1.542 raeburn 7774: var cutwarnings = 0;
7775: var remwarnings = 0;
1.603 raeburn 7776: var removalinfo = 0;
1.538 raeburn 7777: if (doactions == 1) {
7778: var remidxlist = document.cumulativeactions.allremoveidx.value;
7779: if ((remidxlist != '') && (remidxlist != null)) {
7780: var remidxs = remidxlist.split(',');
7781: for (var i=0; i<remidxs.length; i++) {
7782: if (document.getElementById('remove_'+remidxs[i])) {
7783: if (document.getElementById('remove_'+remidxs[i]).checked) {
7784: form.multiremove.value += remidxs[i]+',';
7785: numchanges ++;
1.542 raeburn 7786: if (document.getElementById('skip_remove_'+remidxs[i])) {
7787: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7788: remwarnings ++;
7789: }
7790: }
1.603 raeburn 7791: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7792: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7793: removalinfo ++;
7794: }
7795: }
1.537 raeburn 7796: }
7797: }
1.538 raeburn 7798: }
7799: }
7800: var cutidxlist = document.cumulativeactions.allcutidx.value;
7801: if ((cutidxlist != '') && (cutidxlist != null)) {
7802: var cutidxs = cutidxlist.split(',');
7803: for (var i=0; i<cutidxs.length; i++) {
7804: if (document.getElementById('cut_'+cutidxs[i])) {
7805: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7806: form.multicut.value += cutidxs[i]+',';
7807: numchanges ++;
1.542 raeburn 7808: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7809: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7810: cutwarnings ++;
7811: }
7812: }
1.537 raeburn 7813: }
7814: }
7815: }
7816: }
1.538 raeburn 7817: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7818: if ((copyidxlist != '') && (copyidxlist != null)) {
7819: var copyidxs = copyidxlist.split(',');
7820: for (var i=0; i<copyidxs.length; i++) {
7821: if (document.getElementById('copy_'+copyidxs[i])) {
7822: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7823: form.multicopy.value += copyidxs[i]+',';
7824: numchanges ++;
7825: }
7826: }
7827: }
7828: }
7829: if (numchanges > 0) {
7830: form.multichange.value = numchanges;
7831: }
1.537 raeburn 7832: }
1.538 raeburn 7833: var dosettings = multiSettings();
1.543 raeburn 7834: var haschanges = 0;
1.538 raeburn 7835: if (dosettings == 1) {
7836: form.allencrypturl.value = '';
7837: form.allhiddenresource.value = '';
1.543 raeburn 7838: form.changeparms.value = 'all';
7839: var patt=new RegExp(",\$");
1.538 raeburn 7840: var allidxlist = document.cumulativesettings.allidx.value;
7841: if ((allidxlist != '') && (allidxlist != null)) {
7842: var allidxs = allidxlist.split(',');
7843: if (allidxs.length > 1) {
7844: for (var i=0; i<allidxs.length; i++) {
7845: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7846: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7847: form.allhiddenresource.value += allidxs[i]+',';
7848: }
7849: }
7850: if (document.getElementById('encrypturl_'+allidxs[i])) {
7851: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7852: form.allencrypturl.value += allidxs[i]+',';
7853: }
7854: }
7855: }
1.543 raeburn 7856: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7857: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 7858: }
1.538 raeburn 7859: }
7860: form.allrandompick.value = '';
7861: form.allrandomorder.value = '';
7862: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7863: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7864: var allmapidxs = allmapidxlist.split(',');
7865: for (var i=0; i<allmapidxs.length; i++) {
7866: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7867: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7868: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7869: if ((randompick.checked) && (rpicknum.value != '')) {
7870: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7871: }
7872: if (randorder.checked) {
7873: form.allrandomorder.value += allmapidxs[i]+',';
7874: }
1.537 raeburn 7875: }
1.543 raeburn 7876: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7877: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7878: }
7879: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7880: haschanges = 1;
7881: }
7882: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7883: haschanges = 1;
7884: }
7885: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7886: haschanges = 1;
7887: }
7888: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7889: haschanges = 1;
1.537 raeburn 7890: }
7891: }
1.543 raeburn 7892: if (doactions == 1) {
1.542 raeburn 7893: if (numchanges > 0) {
1.603 raeburn 7894: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 7895: if (remwarnings > 0) {
1.594 damieng 7896: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 7897: return false;
7898: }
7899: }
1.603 raeburn 7900: if (removalinfo > 0) {
7901: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7902: return false;
7903: }
7904: }
1.542 raeburn 7905: if (cutwarnings > 0) {
1.594 damieng 7906: 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 7907: return false;
7908: }
7909: }
7910: }
7911: form.submit();
7912: return true;
1.543 raeburn 7913: }
7914: }
7915: if (dosettings == 1) {
7916: if (haschanges == 1) {
1.542 raeburn 7917: form.submit();
7918: return true;
7919: }
1.543 raeburn 7920: }
7921: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 7922: alert("$js_lt{'noor'}");
1.543 raeburn 7923: } else {
7924: if (dosettings == 1) {
1.594 damieng 7925: alert("$js_lt{'noch'}");
1.543 raeburn 7926: } else {
1.594 damieng 7927: alert("$js_lt{'noac'}");
1.543 raeburn 7928: }
7929: }
1.538 raeburn 7930: return false;
7931: }
7932:
7933: function setClass(value) {
7934: var cutclass = 'LC_docs_cut';
7935: var copyclass = 'LC_docs_copy';
7936: var removeclass = 'LC_docs_remove';
7937: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7938: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7939: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7940: var links = document.getElementsByTagName('a');
7941: for (var i=0; i<links.length; i++) {
7942: var classes = links[i].className;
7943: if (cutreg.test(classes)) {
7944: links[i].className = cutclass;
7945: if (value == 1) {
7946: links[i].className += " LC_menubuttons_link";
7947: }
7948: } else {
7949: if (copyreg.test(classes)) {
7950: links[i].className = copyclass;
7951: if (value == 1) {
7952: links[i].className += " LC_menubuttons_link";
7953: }
7954: } else {
7955: if (removereg.test(classes)) {
7956: links[i].className = removeclass;
7957: if (value == 1) {
7958: links[i].className += " LC_menubuttons_link";
7959: }
7960: }
7961: }
7962: }
7963: }
7964: return;
1.537 raeburn 7965: }
7966:
1.538 raeburn 7967: function setBoxes(value) {
7968: var remidxlist = document.cumulativeactions.allremoveidx.value;
7969: if ((remidxlist != '') && (remidxlist != null)) {
7970: var remidxs = remidxlist.split(',');
7971: for (var i=0; i<remidxs.length; i++) {
7972: if (document.getElementById('remove_'+remidxs[i])) {
7973: var item = document.getElementById('remove_'+remidxs[i]);
7974: if (value == 1) {
7975: item.className = 'LC_docs_remove';
7976: } else {
7977: item.className = 'LC_hidden';
7978: }
7979: }
7980: }
7981: }
7982: var cutidxlist = document.cumulativeactions.allcutidx.value;
7983: if ((cutidxlist != '') && (cutidxlist != null)) {
7984: var cutidxs = cutidxlist.split(',');
7985: for (var i=0; i<cutidxs.length; i++) {
7986: if (document.getElementById('cut_'+cutidxs[i])) {
7987: var item = document.getElementById('cut_'+cutidxs[i]);
7988: if (value == 1) {
7989: item.className = 'LC_docs_cut';
7990: } else {
7991: item.className = 'LC_hidden';
7992: }
7993: }
1.537 raeburn 7994: }
7995: }
1.538 raeburn 7996: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7997: if ((copyidxlist != '') && (copyidxlist != null)) {
7998: var copyidxs = copyidxlist.split(',');
7999: for (var i=0; i<copyidxs.length; i++) {
8000: if (document.getElementById('copy_'+copyidxs[i])) {
8001: var item = document.getElementById('copy_'+copyidxs[i]);
8002: if (value == 1) {
8003: item.className = 'LC_docs_copy';
8004: } else {
8005: item.className = 'LC_hidden';
8006: }
8007: }
1.537 raeburn 8008: }
8009: }
8010: return;
8011: }
8012:
1.606 raeburn 8013: function validImportCrsRes() {
8014: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8015: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8016: if ((fname == '') || (fname == null)) {
8017: alert("$js_lt{'nofi'}");
8018: return false;
8019: }
8020: var url = '/res/$coursedom/$coursenum/';
8021: if (path && path != '/') {
8022: url += path+'/';
8023: }
8024: if (fname != '') {
8025: url += fname;
8026: }
8027: var title = document.crsresimportform.crsrestitle.value;
8028: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8029: return true;
8030: }
8031:
8032: function validateNewRes(caller) {
8033: if (caller == 'single') {
8034: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8035: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8036: var resname = document.courseresform.newresourcename.value;
8037: }
8038: }
8039:
1.611 raeburn 8040: ENDSCRIPT
1.329 droeschl 8041: }
1.457 raeburn 8042:
1.483 raeburn 8043: sub history_tab_js {
8044: return <<"ENDHIST";
8045: function toggleHistoryDisp(choice) {
8046: document.docslogform.docslog.value = choice;
8047: document.docslogform.submit();
8048: return;
8049: }
8050:
8051: ENDHIST
8052: }
8053:
1.484 raeburn 8054: sub inject_data_js {
8055: return <<ENDINJECT;
8056:
8057: function injectData(current, hiddenField, name, value) {
8058: currentElement = document.getElementById(hiddenField);
8059: currentElement.name = name;
8060: currentElement.value = value;
8061: current.submit();
8062: }
8063:
8064: ENDINJECT
8065: }
8066:
8067: sub dump_switchserver_js {
8068: my @hosts = @_;
1.594 damieng 8069: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8070: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8071: swit => 'Switch server?',
1.594 damieng 8072: );
8073: my %html_js_lt = &Apache::lonlocal::texthash(
8074: swit => 'Switch server?',
1.568 raeburn 8075: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8076: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8077: chos => 'Choose server',
8078: );
1.594 damieng 8079: &js_escape(\%js_lt);
8080: &html_escape(\%html_js_lt);
8081: &js_escape(\%html_js_lt);
1.484 raeburn 8082: my $role = $env{'request.role'};
8083: my $js = <<"ENDSWJS";
8084: <script type="text/javascript">
8085: function write_switchserver() {
8086: var server;
8087: if (document.setserver.posshosts.length > 0) {
8088: for (var i=0; i<document.setserver.posshosts.length; i++) {
8089: if (document.setserver.posshosts[i].checked) {
8090: server = document.setserver.posshosts[i].value;
8091: }
8092: }
8093: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8094: }
8095: window.close();
8096: }
8097: </script>
8098:
8099: ENDSWJS
8100:
8101: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8102: {'only_body' => 1,
8103: 'js_ready' => 1,});
8104: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8105:
8106: my $hostpicker;
8107: my $count = 0;
8108: foreach my $host (sort(@hosts)) {
8109: my $checked;
8110: if ($count == 0) {
8111: $checked = ' checked="checked"';
8112: }
8113: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8114: $host.'"'.$checked.' />'.$host.'</label> ';
8115: $count++;
8116: }
8117:
8118: return <<"ENDSWITCHJS";
8119:
8120: function dump_needs_switchserver(url) {
8121: if (url!='' && url!= null) {
1.594 damieng 8122: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8123: go(url);
8124: }
8125: }
8126: return;
8127: }
8128:
8129: function choose_switchserver_window() {
8130: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8131: newWindow.document.open();
8132: newWindow.document.writeln('$startpage');
1.594 damieng 8133: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8134: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8135: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8136: '<form name="setserver" method="post" action="" \\/>\\n'+
8137: '$hostpicker\\n'+
8138: '<br \\/><br \\/>\\n'+
1.594 damieng 8139: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8140: 'onclick="write_switchserver();" \\/>\\n'+
8141: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8142: newWindow.document.writeln('$endpage');
8143: newWindow.document.close();
8144: newWindow.focus();
8145: }
8146:
8147: ENDSWITCHJS
8148: }
8149:
8150: sub makedocslogform {
8151: my ($formelems,$docslog) = @_;
8152: return <<"LOGSFORM";
8153: <form action="/adm/coursedocs" method="post" name="docslogform">
8154: <input type="hidden" name="docslog" value="$docslog" />
8155: $formelems
8156: </form>
8157: LOGSFORM
8158: }
8159:
8160: sub makesimpleeditform {
8161: my ($formelems) = @_;
8162: return <<"SIMPFORM";
8163: <form name="simpleedit" method="post" action="/adm/coursedocs">
8164: <input type="hidden" name="importdetail" value="" />
8165: $formelems
8166: </form>
8167: SIMPFORM
8168: }
8169:
1.606 raeburn 8170: sub makenewproblem {
8171: my ($r,$coursedom,$coursenum) = @_;
8172: # Creating a new problem
8173: my ($redirect,$error);
8174: if ($env{'form.authorrole'}) {
8175: my ($newsubdir,$filename);
8176: if ($env{'form.newsubdir'}) {
8177: if ($env{'form.newsubdirname'} ne '') {
8178: $newsubdir = $env{'form.newsubdirname'};
8179: }
8180: }
8181: if ($env{'form.newresourcename'}) {
8182: $filename = $env{'form.newresourcename'};
8183: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8184: $filename =~ s/`//g;
8185: $filename =~ s{/\.\./}{_}g;
8186: $filename =~ s/\.+/./g;
8187: $filename =~ s{/+}{_}g;
8188: if ($filename ne '') {
8189: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8190: if (($ext) && ($ext ne '.problem')) {
8191: $filename = $name.'.problem';
8192: } elsif ($ext eq '') {
8193: $filename .= '.problem';
8194: }
8195: my $docroot = $r->dir_config('lonDocRoot');
8196: my @ids=&Apache::lonnet::current_machine_ids();
8197: if ($env{'form.authorrole'} eq 'author') {
8198: if ($env{'user.author'}) {
8199: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8200: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8201: my $path = $docroot.$url;
8202: my $subdir = $env{'form.authorpath'};
8203: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8204: }
8205: }
8206: } elsif ($env{'form.authorrole'} eq 'course') {
8207: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8208: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8209: my $url = "/priv/$coursedom/$coursenum";
8210: my $path=$docroot.$url;
8211: my $subdir = $env{'form.authorpath'};
8212: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8213: if ($redirect) {
8214: my $rightsfile = 'default.rights';
8215: my $sourcerights = "$path/$rightsfile";
8216: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8217: my $now = time;
8218: if (!-e $sourcerights) {
8219: my $cid = $coursedom.'_'.$coursenum;
8220: if (open(my $fh,">$sourcerights")) {
8221: print $fh <<END;
8222: <accessrule effect="deny" realm="" type="course" role="" />
8223: <accessrule effect="allow" realm="$cid" type="course" role="" />
8224: END
8225: close($fh);
8226: }
8227: }
8228: if (!-e "$sourcerights.meta") {
8229: if (open(my $fh,">$sourcerights.meta")) {
8230: my $author=$env{'environment.firstname'}.' '.
8231: $env{'environment.middlename'}.' '.
8232: $env{'environment.lastname'}.' '.
8233: $env{'environment.generation'};
8234: $author =~ s/\s+$//;
8235: print $fh <<"END";
8236:
8237: <abstract></abstract>
8238: <author>$author</author>
8239: <authorspace>$coursenum:$coursedom</authorspace>
8240: <copyright>private</copyright>
8241: <creationdate>$now</creationdate>
8242: <customdistributionfile></customdistributionfile>
8243: <dependencies></dependencies>
8244: <domain>$coursedom</domain>
8245: <highestgradelevel>0</highestgradelevel>
8246: <keywords></keywords>
8247: <language>notset </language>
8248: <lastrevisiondate>$now</lastrevisiondate>
8249: <lowestgradelevel>0</lowestgradelevel>
8250: <mime>rights</mime>
8251: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8252: <notes></notes>
8253: <obsolete></obsolete>
8254: <obsoletereplacement></obsoletereplacement>
8255: <owner>$coursenum:$coursedom</owner>
8256: <rule>deny:::course,allow:$cid::course</rule>
8257: <sourceavail></sourceavail>
8258: <standards></standards>
8259: <subject></subject>
8260: <title></title>
8261: END
8262: close($fh);
8263: }
8264: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8265: if (!-e "$docroot/res/$coursedom") {
8266: mkdir("$docroot/res/$coursedom",0755);
8267: }
8268: if (!-e "$docroot/res/$coursedom/$coursenum") {
8269: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8270: }
8271: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8272: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8273: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8274: }
8275: }
8276: }
8277: if ($env{'form.newresourceadd'}) {
8278: my $template = $env{'form.template'};
8279: my $source = $docroot.$redirect;
8280: my $target = $redirect;
8281: $target =~ s{^/priv/}{/res/};
8282: $target = $docroot.$target;
8283: if (!-e $source) {
8284: my $copyfrom;
8285: if ($template) {
8286: my %templates;
8287: my @files = &Apache::lonhomework::get_template_list('problem');
8288: foreach my $poss (@files) {
8289: if (ref($poss) eq 'ARRAY') {
8290: if ($template eq $poss->[0]) {
8291: $templates{$template} = 1;
8292: last;
8293: }
8294: }
8295: }
8296: if ($templates{$template}) {
8297: $copyfrom = $template;
8298: }
8299: }
8300: unless ($copyfrom) {
8301: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8302: }
8303: &File::Copy::copy($copyfrom,$source);
8304: }
8305: if (!-e "$source.meta") {
8306: my $cid = $coursedom.'_'.$coursenum;
8307: my $now = time;
8308: if (open(my $fh,">$source.meta")) {
8309: my $author=$env{'environment.firstname'}.' '.
8310: $env{'environment.middlename'}.' '.
8311: $env{'environment.lastname'}.' '.
8312: $env{'environment.generation'};
8313: $author =~ s/\s+$//;
8314: my $title = $env{'form.newresourcetitle'};
8315: $title =~ s/^\s+|\s+$//g;
8316: print $fh <<END;
8317:
8318: <abstract></abstract>
8319: <author>$author</author>
8320: <authorspace>$coursenum:$coursedom</authorspace>
8321: <copyright>custom</copyright>
8322: <creationdate>$now</creationdate>
8323: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8324: <dependencies></dependencies>
8325: <domain>$coursedom</domain>
8326: <highestgradelevel>0</highestgradelevel>
8327: <keywords></keywords>
8328: <language>notset </language>
8329: <lastrevisiondate>$now</lastrevisiondate>
8330: <lowestgradelevel>0</lowestgradelevel>
8331: <mime>problem</mime>
8332: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8333: <notes></notes>
8334: <obsolete></obsolete>
8335: <obsoletereplacement></obsoletereplacement>
8336: <owner>$coursenum:$coursedom</owner>
8337: <sourceavail></sourceavail>
8338: <standards></standards>
8339: <subject></subject>
8340: <title>$title</title>
8341: END
8342: close($fh);
8343: }
8344: }
8345: }
8346: }
8347: }
8348: } else {
8349: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8350: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8351: if (grep(/^\Q$rolehome\E$/,@ids)) {
8352: my $now = time;
8353: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8354: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8355: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8356: my $url = "/priv/$audom/$auname";
8357: my $path = $r->dir_config('lonDocRoot').$url;
8358: my $subdir = $env{'form.authorpath'};
8359: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8360: }
8361: }
8362: }
8363: }
8364: }
8365: }
8366: }
8367: return ($redirect,$error);
8368: }
8369:
8370: sub finishnewprob {
8371: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8372: unless (-d $path) {
8373: unless (mkdir($path,02770)) {
8374: return;
8375: }
8376: }
1.606 raeburn 8377: my $redirect;
8378: if ($subdir ne '/') {
8379: $subdir = &cleandir($subdir);
8380: if (($subdir ne '') && (-d "$path/$subdir")) {
8381: $path .= "/$subdir";
8382: $url .= "/$subdir";
8383: }
8384: }
8385: my $dest;
8386: if ($newsubdir ne '') {
8387: $newsubdir = &cleandir($newsubdir);
8388: }
8389: if ($newsubdir ne '') {
8390: if (-d "$path/$newsubdir") {
8391: $dest = "$path/$newsubdir/$filename";
8392: } else {
8393: my $dirok;
8394: unless (-e "$path/$newsubdir") {
8395: if (mkdir("$path/$newsubdir",02770)) {
8396: if (chmod(02770,"$path/$newsubdir")) {
8397: $dirok = 1;
8398: }
8399: }
8400: }
8401: if ($dirok) {
8402: $dest = "$path/$newsubdir/$filename";
8403: }
8404: }
8405: if (($dest ne '') && (!-e $dest)) {
8406: $redirect = "$url/$newsubdir/$filename";
8407: }
8408: } else {
8409: $dest = "$path/$filename";
8410: if (($dest ne '') && (!-e $dest)) {
8411: $redirect = "$url/$filename";
8412: }
8413: }
8414: return $redirect;
8415: }
8416:
8417: sub cleandir {
8418: my ($dir) = @_;
8419: $dir =~ s/^\s+//;
8420: $dir =~ s/\s+$//;
8421: $dir =~ s/\.+//g;
8422: $dir =~ s/[\#\?&%\":]//g;
8423: return $dir;
8424: }
8425:
1.329 droeschl 8426: 1;
8427: __END__
8428:
8429:
8430: =head1 NAME
8431:
8432: Apache::londocs.pm
8433:
8434: =head1 SYNOPSIS
8435:
8436: This is part of the LearningOnline Network with CAPA project
8437: described at http://www.lon-capa.org.
8438:
8439: =head1 SUBROUTINES
8440:
8441: =over
8442:
8443: =item %help=()
8444:
8445: Available help topics
8446:
8447: =item mapread()
8448:
1.344 bisitz 8449: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8450: @order and @resources, determines status
8451: sets @order - pointer to resources in right order
8452: sets @resources - array with the resources with correct idx
8453:
8454: =item authorhosts()
8455:
8456: Return hash with valid author names
8457:
8458: =item clean()
8459:
8460: =item dumpcourse()
8461:
8462: Actually dump course
8463:
8464: =item group_import()
8465:
8466: Imports the given (name, url) resources into the course
8467: coursenum, coursedom, and folder must precede the list
8468:
8469: =item breadcrumbs()
8470:
8471: =item log_docs()
8472:
8473: =item docs_change_log()
8474:
8475: =item update_paste_buffer()
8476:
8477: =item print_paste_buffer()
8478:
8479: =item do_paste_from_buffer()
8480:
1.538 raeburn 8481: =item do_buffer_empty()
8482:
8483: =item clear_from_buffer()
8484:
1.492 raeburn 8485: =item get_newmap_url()
8486:
8487: =item dbcopy()
8488:
8489: =item uniqueness_check()
8490:
8491: =item contained_map_check()
8492:
8493: =item url_paste_fixups()
8494:
8495: =item apply_fixups()
8496:
8497: =item copy_dependencies()
8498:
1.329 droeschl 8499: =item update_parameter()
8500:
8501: =item handle_edit_cmd()
8502:
8503: =item editor()
8504:
8505: =item process_file_upload()
8506:
8507: =item process_secondary_uploads()
8508:
8509: =item is_supplemental_title()
8510:
8511: =item entryline()
8512:
8513: =item tiehash()
8514:
8515: =item untiehash()
8516:
8517: =item checkonthis()
8518:
8519: check on this
8520:
8521: =item verifycontent()
8522:
8523: Verify Content
8524:
8525: =item devalidateversioncache() & checkversions()
8526:
8527: Check Versions
8528:
8529: =item mark_hash_old()
8530:
8531: =item is_hash_old()
8532:
8533: =item changewarning()
8534:
8535: =item init_breadcrumbs()
8536:
8537: Breadcrumbs for special functions
8538:
1.484 raeburn 8539: =item create_list_elements()
8540:
8541: =item create_form_ul()
8542:
8543: =item startContentScreen()
8544:
8545: =item endContentScreen()
8546:
8547: =item supplemental_base()
8548:
8549: =item embedded_form_elems()
8550:
8551: =item embedded_destination()
8552:
8553: =item return_to_editor()
8554:
8555: =item decompression_info()
8556:
8557: =item decompression_phase_one()
8558:
8559: =item decompression_phase_two()
8560:
8561: =item remove_archive()
8562:
8563: =item generate_admin_menu()
8564:
8565: =item generate_edit_table()
8566:
8567: =item editing_js()
8568:
8569: =item history_tab_js()
8570:
8571: =item inject_data_js()
8572:
8573: =item dump_switchserver_js()
8574:
1.485 raeburn 8575: =item resize_scrollbox_js()
1.484 raeburn 8576:
8577: =item makedocslogform()
8578:
1.485 raeburn 8579: =item makesimpleeditform()
8580:
1.329 droeschl 8581: =back
8582:
8583: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>