Annotation of loncom/interface/londocs.pm, revision 1.625
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.625 ! raeburn 4: # $Id: londocs.pm,v 1.624 2017/04/25 22:18:59 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.625 ! raeburn 657: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)\:?(.*)$}) {
1.598 raeburn 658: $url = $1;
659: my $marker = $2;
660: my $info = $3;
1.604 raeburn 661: my ($toolid,%toolhash,%toolsettings);
1.624 raeburn 662: my @extras = ('linktext','explanation','crslabel','crstitle');
1.598 raeburn 663: my @toolinfo = split(/:/,$info);
664: if ($residx) {
1.604 raeburn 665: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 666: $toolid = $toolsettings{'id'};
667: } else {
1.604 raeburn 668: $toolid = shift(@toolinfo);
1.598 raeburn 669: }
670: $toolid =~ s/\D//g;
1.604 raeburn 671: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.624 raeburn 672: $toolhash{'linktext'},$toolhash{'explanation'},
1.604 raeburn 673: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
1.624 raeburn 674: foreach my $item (@extras) {
675: $toolhash{$item} = &unescape($toolhash{$item});
676: }
1.598 raeburn 677: if (ref($ltitoolsref) eq 'HASH') {
1.604 raeburn 678: my @deleted;
1.598 raeburn 679: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
680: $toolhash{'id'} = $toolid;
1.604 raeburn 681: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
682: if ($toolhash{'target'} eq 'window') {
683: foreach my $item ('width','height') {
684: $toolhash{$item} =~ s/^\s+//;
685: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 686: if ($toolhash{$item} =~ /\D/) {
687: delete($toolhash{$item});
688: if ($residx) {
689: if ($toolsettings{$item}) {
690: push(@deleted,$item);
691: }
692: }
693: }
1.604 raeburn 694: }
695: }
696: } elsif ($residx) {
697: $toolhash{'target'} = $toolsettings{'target'};
698: if ($toolhash{'target'} eq 'window') {
1.624 raeburn 699: foreach my $item ('width','height') {
700: $toolhash{$item} = $toolsettings{$item};
701: }
1.604 raeburn 702: }
703: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
704: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
705: if ($toolhash{'target'} eq 'window') {
706: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
707: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
708: }
709: }
1.598 raeburn 710: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 711: foreach my $item ('width','height','linktext','explanation') {
712: delete($toolhash{$item});
713: if ($residx) {
714: if ($toolsettings{$item}) {
715: push(@deleted,$item);
716: }
1.604 raeburn 717: }
718: }
719: }
720: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 721: foreach my $item ('label','title','linktext','explanation') {
722: my $crsitem;
723: if (($item eq 'label') || ($item eq 'title')) {
724: $crsitem = 'crs'.$item;
725: } else {
726: $crsitem = $item;
727: }
1.604 raeburn 728: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 729: $toolhash{$crsitem} =~ s/^\s+//;
730: $toolhash{$crsitem} =~ s/\s+$//;
731: if ($toolhash{$crsitem} eq '') {
732: delete($toolhash{$crsitem});
1.604 raeburn 733: }
734: } else {
1.624 raeburn 735: delete($toolhash{$crsitem});
1.604 raeburn 736: }
1.624 raeburn 737: if (($residx) && (exists($toolsettings{$crsitem}))) {
738: unless (exists($toolhash{$crsitem})) {
739: push(@deleted,$crsitem);
1.604 raeburn 740: }
741: }
1.598 raeburn 742: }
743: }
744: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 745: if ($putres eq 'ok') {
746: if (@deleted) {
747: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
748: }
749: }
1.598 raeburn 750: }
751: }
752: }
1.529 raeburn 753: if (($caller eq 'londocs') &&
754: ($folder =~ /^default/)) {
1.534 raeburn 755: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 756: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
757: my $cid = $coursedom.'_'.$coursenum;
758: $allmaps =
759: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
760: $chome,$cid);
761: $donechk = 1;
762: }
763: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
764: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
765: \%addedmaps,\%hierarchy,\%titles,$allmaps);
766: $importuploaded = 1;
767: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
768: next if ($allmaps->{$url});
769: }
770: }
1.344 bisitz 771: if (!$residx
1.329 droeschl 772: || defined($LONCAPA::map::zombies[$residx])) {
773: $residx = &LONCAPA::map::getresidx($url,$residx);
774: push(@LONCAPA::map::order, $residx);
775: }
776: my $ext = 'false';
777: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
778: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 779: if ($name eq '') {
1.538 raeburn 780: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 781: }
782: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
783: my $filepath = $1;
784: my $fname = $name;
785: if ($fname =~ /^\W+$/) {
786: $fname = 'web';
787: } else {
788: $fname =~ s/\W/_/g;
789: }
1.599 damieng 790: if (length($fname) > 15) {
1.534 raeburn 791: $fname = substr($fname,0,14);
792: }
793: my $initialtext = &mt('Replace with your own content.');
794: my $newhtml = <<END;
1.545 raeburn 795: <html>
1.534 raeburn 796: <head>
797: <title>$name</title>
798: </head>
799: <body bgcolor="#ffffff">
800: $initialtext
801: </body>
802: </html>
803: END
804: $env{'form.output'}=$newhtml;
805: my $result =
806: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
807: 'output',
808: "$filepath/$residx/$fname.html");
809: if ($result =~ m{^/uploaded/}) {
810: $url = $result;
811: if ($filepath =~ /^supplemental/) {
812: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
813: $env{'user.domain'}.'___&&&___'.$name;
814: }
815: } else {
816: return (&mt('Failed to save new web page.'),1);
817: }
818: }
1.538 raeburn 819: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 820: $LONCAPA::map::resources[$residx] =
1.329 droeschl 821: join(':', ($name, $url, $ext, 'normal', 'res'));
822: }
823: }
1.529 raeburn 824: if ($importuploaded) {
825: my %import_errors;
826: my %updated = (
827: removefrommap => \%removefrommap,
828: removeparam => \%removeparam,
829: );
1.533 raeburn 830: my ($result,$msgsarray,$lockerror) =
831: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 832: if (keys(%import_errors) > 0) {
1.530 raeburn 833: $fixuperrors =
1.529 raeburn 834: '<p span class="LC_warning">'."\n".
835: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
836: '<ul>'."\n";
837: foreach my $key (sort(keys(%import_errors))) {
838: $fixuperrors .= '<li>'.$key.'</li>'."\n";
839: }
840: $fixuperrors .= '</ul></p>'."\n";
841: }
1.533 raeburn 842: if (ref($msgsarray) eq 'ARRAY') {
843: if (@{$msgsarray} > 0) {
844: $fixuperrors .= '<p class="LC_info">'.
845: join('<br />',@{$msgsarray}).
846: '</p>';
847: }
848: }
849: if ($lockerror) {
850: $fixuperrors .= '<p class="LC_error">'.
851: $lockerror.
852: '</p>';
853: }
1.529 raeburn 854: }
855: my ($errtext,$fatal) =
856: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 857: unless ($fatal) {
858: if ($folder =~ /^supplemental/) {
859: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 860: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
861: $folder.'.'.$container);
1.557 raeburn 862: }
863: }
1.529 raeburn 864: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 865: }
866:
867: sub log_docs {
1.494 raeburn 868: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 869: }
870:
871: {
872: my @oldresources=();
873: my @oldorder=();
874: my $parmidx;
875: my %parmaction=();
876: my %parmvalue=();
877: my $changedflag;
878:
879: sub snapshotbefore {
880: @oldresources=@LONCAPA::map::resources;
881: @oldorder=@LONCAPA::map::order;
882: $parmidx=undef;
883: %parmaction=();
884: %parmvalue=();
885: $changedflag=0;
886: }
887:
888: sub remember_parms {
889: my ($idx,$parameter,$action,$value)=@_;
890: $parmidx=$idx;
891: $parmaction{$parameter}=$action;
892: $parmvalue{$parameter}=$value;
893: $changedflag=1;
894: }
895:
896: sub log_differences {
897: my ($plain)=@_;
898: my %storehash=('folder' => $plain,
899: 'currentfolder' => $env{'form.folder'});
900: if ($parmidx) {
901: $storehash{'parameter_res'}=$oldresources[$parmidx];
902: foreach my $parm (keys(%parmaction)) {
903: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
904: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
905: }
906: }
907: my $maxidx=$#oldresources;
908: if ($#LONCAPA::map::resources>$#oldresources) {
909: $maxidx=$#LONCAPA::map::resources;
910: }
911: for (my $idx=0; $idx<=$maxidx; $idx++) {
912: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
913: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
914: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
915: $changedflag=1;
916: }
917: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
918: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
919: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
920: $changedflag=1;
921: }
922: }
923: $storehash{'maxidx'}=$maxidx;
924: if ($changedflag) { &log_docs(\%storehash); }
925: }
926: }
927:
928: sub docs_change_log {
1.611 raeburn 929: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 930: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 931: my $navmap;
1.483 raeburn 932: my $js = '<script type="text/javascript">'."\n".
933: '// <![CDATA['."\n".
934: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 935: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 936: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 937: &history_tab_js()."\n".
1.484 raeburn 938: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 939: '// ]]>'."\n".
940: '</script>'."\n";
1.484 raeburn 941: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
942: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 943: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 944: my %orderhash;
945: my $container='sequence';
946: my $pathitem;
1.519 raeburn 947: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 948: $container='page';
949: }
1.519 raeburn 950: my $folderpath=$env{'form.folderpath'};
951: if ($folderpath eq '') {
1.617 raeburn 952: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 953: }
1.617 raeburn 954: undef($navmap);
1.519 raeburn 955: $pathitem = '<input type="hidden" name="folderpath" value="'.
956: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 957: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
958: my $jumpto = $readfile;
959: $jumpto =~ s{^/}{};
960: my $tid = 1;
1.489 raeburn 961: if ($supplementalflag) {
962: $tid = 2;
963: }
1.509 raeburn 964: my ($breadcrumbtrail) =
965: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 966: $r->print($breadcrumbtrail.
967: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
968: $readfile));
1.329 droeschl 969: my %docslog=&Apache::lonnet::dump('nohist_docslog',
970: $env{'course.'.$env{'request.course.id'}.'.domain'},
971: $env{'course.'.$env{'request.course.id'}.'.num'});
972:
973: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
974:
975: my %saveable_parameters = ('show' => 'scalar',);
976: &Apache::loncommon::store_course_settings('docs_log',
977: \%saveable_parameters);
978: &Apache::loncommon::restore_course_settings('docs_log',
979: \%saveable_parameters);
980: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 981: # FIXME: internationalization seems wrong here
1.329 droeschl 982: my %lt=('hiddenresource' => 'Resources hidden',
983: 'encrypturl' => 'URL hidden',
984: 'randompick' => 'Randomly pick',
985: 'randomorder' => 'Randomly ordered',
986: 'set' => 'set to',
987: 'del' => 'deleted');
1.484 raeburn 988: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
989: $pathitem."\n".
990: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
991: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
992: $r->print('<div class="LC_left_float">'.
993: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
994: &makedocslogform($filter,1).
995: '</fieldset></div><br clear="all" />');
1.329 droeschl 996: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
997: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
998: &mt('After').'</th>'.
999: &Apache::loncommon::end_data_table_header_row());
1000: my $shown=0;
1001: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1002: if ($env{'form.displayfilter'} eq 'currentfolder') {
1003: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1004: }
1005: my @changes=keys(%{$docslog{$id}{'logentry'}});
1006: if ($env{'form.displayfilter'} eq 'containing') {
1007: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1008: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1009: foreach my $key (@changes) {
1010: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1011: }
1.344 bisitz 1012: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1013: }
1014: my $count = 0;
1015: my $time =
1016: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1017: my $plainname =
1018: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1019: $docslog{$id}{'exe_udom'});
1020: my $about_me_link =
1021: &Apache::loncommon::aboutmewrapper($plainname,
1022: $docslog{$id}{'exe_uname'},
1023: $docslog{$id}{'exe_udom'});
1024: my $send_msg_link='';
1025: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1026: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1027: $send_msg_link ='<br />'.
1028: &Apache::loncommon::messagewrapper(&mt('Send message'),
1029: $docslog{$id}{'exe_uname'},
1030: $docslog{$id}{'exe_udom'});
1031: }
1032: $r->print(&Apache::loncommon::start_data_table_row());
1033: $r->print('<td>'.$time.'</td>
1034: <td>'.$about_me_link.
1035: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1036: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1037: $send_msg_link.'</td><td>'.
1038: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1039: my $is_supp = 0;
1040: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1041: $is_supp = 1;
1042: }
1.329 droeschl 1043: # Before
1044: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1045: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1046: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1047: if ($oldname ne $newname) {
1.488 raeburn 1048: my $shown = &LONCAPA::map::qtescape($oldname);
1049: if ($is_supp) {
1050: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1051: }
1052: $r->print($shown);
1.329 droeschl 1053: }
1054: }
1055: $r->print('<ul>');
1056: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1057: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1058: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1059: if ($is_supp) {
1060: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1061: }
1062: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1063: }
1064: }
1065: $r->print('</ul>');
1066: # After
1067: $r->print('</td><td>');
1068:
1069: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1070: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1071: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1072: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1073: my $shown = &LONCAPA::map::qtescape($newname);
1074: if ($is_supp) {
1075: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1076: }
1077: $r->print($shown);
1.329 droeschl 1078: }
1.364 bisitz 1079: }
1.329 droeschl 1080: $r->print('<ul>');
1081: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1082: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1083: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1084: if ($is_supp) {
1085: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1086: }
1087: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1088: }
1089: }
1090: $r->print('</ul>');
1091: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1092: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1093: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1094: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1095: # FIXME: internationalization seems wrong here
1.329 droeschl 1096: $r->print('<li>'.
1097: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1098: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1099: .'</li>');
1100: }
1101: }
1102: $r->print('</ul>');
1103: }
1104: # End
1105: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1106: $shown++;
1107: if (!($env{'form.show'} eq &mt('all')
1108: || $shown<=$env{'form.show'})) { last; }
1109: }
1.484 raeburn 1110: $r->print(&Apache::loncommon::end_data_table()."\n".
1111: &makesimpleeditform($pathitem)."\n".
1112: '</div></div>');
1113: $r->print(&endContentScreen());
1.329 droeschl 1114: }
1115:
1116: sub update_paste_buffer {
1.492 raeburn 1117: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1118: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1119: if ($env{'form.multiremove'}) {
1120: $env{'form.multiremove'} =~ s/,$//;
1121: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1122: }
1123: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1124: if ($env{'form.multicut'}) {
1125: $env{'form.multicut'} =~ s/,$//;
1126: foreach my $item (split(/,/,$env{'form.multicut'})) {
1127: unless ($removals{$item}) {
1128: $cuts{$item} = 1;
1129: push(@possibles,$item.':cut');
1130: }
1131: }
1132: }
1133: if ($env{'form.multicopy'}) {
1134: $env{'form.multicopy'} =~ s/,$//;
1135: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1136: unless ($removals{$item} || $cuts{$item}) {
1137: push(@possibles,$item.':copy');
1138: }
1139: }
1140: }
1141: } elsif ($env{'form.markcopy'}) {
1142: @possibles = split(/,/,$env{'form.markcopy'});
1143: }
1.329 droeschl 1144:
1.538 raeburn 1145: return if (@possibles == 0);
1.329 droeschl 1146: return if (!defined($env{'form.copyfolder'}));
1147:
1148: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1149: $env{'form.copyfolder'});
1.538 raeburn 1150: return if ($fatal);
1151:
1152: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1153:
1.538 raeburn 1154: # Retrieve current paste buffer suffixes.
1155: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1156: my (%pasteurls,@newpaste);
1157:
1158: # Construct identifiers for current contents of user's paste buffer
1159: if (@currpaste) {
1160: foreach my $suffix (@currpaste) {
1161: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1162: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1163: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1164: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1165: ($url ne '')) {
1.597 raeburn 1166: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1167: }
1168: }
1169: }
1170:
1171: # Mark items for copying (skip any items already in user's paste buffer)
1172: my %addtoenv;
1.597 raeburn 1173:
1174: my @pathitems = split(/\&/,$env{'form.folderpath'});
1175: my @folderconf = split(/\:/,$pathitems[-1]);
1176: my $ispage = $folderconf[4];
1177:
1.538 raeburn 1178: foreach my $item (@possibles) {
1179: my ($orderidx,$cmd) = split(/:/,$item);
1180: next if ($orderidx =~ /\D/);
1181: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1182: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1183: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1184: my %denied = &action_restrictions($coursenum,$coursedom,
1185: &LONCAPA::map::qtescape($url),
1186: $env{'form.folderpath'},\%curr_groups);
1187: next if ($denied{'copy'});
1188: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1189: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1190: my ($suffix,$errortxt,$locknotfreed) =
1191: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1192: if ($suffix ne '') {
1193: push(@newpaste,$suffix);
1194: } else {
1195: if ($locknotfreed) {
1196: return $locknotfreed;
1197: }
1.538 raeburn 1198: }
1199: if (&is_supplemental_title($title)) {
1200: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1201: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1202: }
1.329 droeschl 1203:
1.538 raeburn 1204: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1205: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1206: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1207: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1208: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1209: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1210: my $prefix = $1;
1211: my $subdir =$2;
1212: if ($subdir eq '') {
1213: $subdir = $prefix;
1.492 raeburn 1214: }
1.538 raeburn 1215: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1216: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1217: \%hierarchy,\%titles,\%allmaps);
1218: if (ref($hierarchy{$url}) eq 'HASH') {
1219: my ($nested,$nestednames);
1220: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1221: $nested =~ s/\&$//;
1222: $nestednames =~ s/\Q___&&&___\E$//;
1223: if ($nested ne '') {
1224: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1225: }
1226: if ($nestednames ne '') {
1227: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1228: }
1.492 raeburn 1229: }
1230: }
1.591 raeburn 1231: if ($locknotfreed) {
1232: $output = $locknotfreed;
1233: last;
1234: }
1.492 raeburn 1235: }
1.538 raeburn 1236: if (@newpaste) {
1237: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1238: }
1.492 raeburn 1239: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1240: delete($env{'form.markcopy'});
1.591 raeburn 1241: return $output;
1.329 droeschl 1242: }
1243:
1.492 raeburn 1244: sub recurse_uploaded_maps {
1245: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1246: if (ref($hierarchy->{$url}) eq 'HASH') {
1247: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1248: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1249: my (@uploaded,@names,%shorter);
1250: for (my $i=0; $i<@maps; $i++) {
1251: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1252: if ($inner ne '') {
1253: push(@uploaded,$inner);
1254: push(@names,&escape($titles[$i]));
1255: $shorter{$maps[$i]} = $inner;
1256: }
1257: }
1258: $$nestref .= "$dir:".join(',',@uploaded).'&';
1259: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1260: foreach my $map (@maps) {
1261: if ($shorter{$map} ne '') {
1262: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1263: }
1264: }
1265: }
1266: return;
1267: }
1268:
1.329 droeschl 1269: sub print_paste_buffer {
1.492 raeburn 1270: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1271: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1272:
1.538 raeburn 1273: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1274: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1275: }
1276:
1.538 raeburn 1277: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1278: my ($pasteitems,@pasteable);
1.575 raeburn 1279: my $clipboardcount = 0;
1.488 raeburn 1280:
1.538 raeburn 1281: # Construct identifiers for current contents of user's paste buffer
1282: foreach my $suffix (@currpaste) {
1283: next if ($suffix =~ /\D/);
1284: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1285: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1286: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1287: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1288: ($url ne '')) {
1.575 raeburn 1289: $clipboardcount ++;
1.538 raeburn 1290: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1291: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1292: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1293: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1294: $is_external = 1;
1.625 ! raeburn 1295: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttool$}) {
1.598 raeburn 1296: $is_exttool = 1;
1.538 raeburn 1297: }
1298: if ($folder =~ /^supplemental/) {
1299: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1300: unless ($canpaste) {
1301: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1302: }
1303: } else {
1304: $canpaste = 1;
1305: }
1306: if ($canpaste) {
1307: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1308: my $srcdom = $1;
1309: my $srcnum = $2;
1310: my $rem = $3;
1311: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1312: $othercourse = 1;
1313: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1314: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1315: } else {
1316: $canpaste = 0;
1317: $nopaste = &mt('Paste from another course unavailable.');
1318: }
1319: }
1320: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1321: my $prefix = $1;
1322: $parent = $2;
1323: if ($folder !~ /^\Q$prefix\E/) {
1324: $areachange = 1;
1325: }
1326: $is_uploaded_map = 1;
1.492 raeburn 1327: }
1.597 raeburn 1328: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1329: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1330: if ($cid ne $env{'request.course.id'}) {
1331: my ($srcdom,$srcnum) = split(/_/,$cid);
1332: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1333: $othercrs = '<br />'.&mt('(from another course)');
1334: } else {
1335: $canpaste = 0;
1336: $nopaste = &mt('Paste from another course unavailable.');
1337: }
1338: }
1.492 raeburn 1339: }
1.596 raeburn 1340: if ($canpaste) {
1341: push(@pasteable,$suffix);
1342: }
1.538 raeburn 1343: }
1344: my $buffer;
1.598 raeburn 1345: if (($is_external) || ($is_exttool)) {
1.538 raeburn 1346: $buffer = &mt('External Resource').': '.
1347: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1348: &LONCAPA::map::qtescape($url).')';
1349: } else {
1350: my $icon = &Apache::loncommon::icon($extension);
1351: if ($extension eq 'sequence' &&
1352: $url =~ m{/default_\d+\.sequence$}x) {
1353: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1354: $icon .= '/navmap.folder.closed.gif';
1355: }
1.589 raeburn 1356: my $title = $env{'docs.markedcopy_title_'.$suffix};
1357: if ($title eq '') {
1358: ($title) = ($url =~ m{/([^/]+)$});
1359: }
1.538 raeburn 1360: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1361: ': '.
1362: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1363: &LONCAPA::map::qtescape($title));
1.538 raeburn 1364: }
1365: $pasteitems .= '<div class="LC_left_float">';
1366: my ($options,$onclick);
1367: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1368: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1369: if (($is_uploaded_map) ||
1370: ($url =~ /(bulletinboard|smppg)$/) ||
1371: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1372: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1373: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1374: }
1375: }
1376: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1377: if ($nopaste) {
1378: $pasteitems .= $nopaste;
1379: } else {
1380: if ($othercrs) {
1381: $pasteitems .= $othercrs;
1382: }
1383: if ($options) {
1384: $pasteitems .= $options;
1.492 raeburn 1385: }
1386: }
1.538 raeburn 1387: $pasteitems .= '</div>';
1388: }
1389: }
1390: if ($pasteitems eq '') {
1391: &Apache::lonnet::delenv('docs.markedcopies');
1392: }
1393: my ($pasteform,$form_start,$buttons,$form_end);
1394: if ($pasteitems) {
1395: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1396: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1397: if (@pasteable) {
1.575 raeburn 1398: my $value = &mt('Paste to current folder');
1399: if ($container eq 'page') {
1400: $value = &mt('Paste to current page');
1401: }
1402: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1403: }
1404: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1405: if ($clipboardcount > 1) {
1406: $buttons .=
1407: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1408: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1409: (' 'x2).
1410: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1411: (' 'x2);
1.492 raeburn 1412: }
1.575 raeburn 1413: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1414: '</form>';
1.538 raeburn 1415: } else {
1416: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1417: }
1.538 raeburn 1418: $r->print($form_start
1419: .'<fieldset>'
1420: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1421: .$pasteitems
1422: .'</fieldset>'
1423: .$form_end);
1424: }
1425:
1426: sub paste_options {
1427: my ($suffix,$is_uploaded_map,$parent) = @_;
1428: my ($copytext,$movetext);
1429: if ($is_uploaded_map) {
1430: $copytext = &mt('Copy to new folder');
1431: $movetext = &mt('Move old');
1432: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1433: $copytext = &mt('Copy to new board');
1434: $movetext = &mt('Move (not posts)');
1435: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1436: $copytext = &mt('Copy to new page');
1437: $movetext = &mt('Move');
1.533 raeburn 1438: } else {
1.538 raeburn 1439: $copytext = &mt('Copy to new file');
1440: $movetext = &mt('Move');
1441: }
1442: my $output = '<br />'.
1443: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1444: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1445: '<label>'.
1446: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1447: $copytext.'</label></span>'.(' 'x2).' '.
1448: '<span class="LC_nobreak"><label>'.
1449: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1450: $movetext.'</label></span>';
1451: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1452: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1453: '</legend><table border="0">';
1454: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1455: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1456: my $lastdir = $parent;
1457: my %depths = (
1458: $lastdir => 0,
1459: );
1460: my (%display,%deps);
1461: for (my $i=0; $i<@pastemaps; $i++) {
1462: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1463: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1464: my @subfolders = split(/,/,$subfolderstr);
1465: $deps{$lastdir} = \@subfolders;
1466: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1467: my $depth = $depths{$lastdir} + 1;
1468: my $offset = int($depth * 4);
1469: my $indent = (' ' x $offset);
1470: for (my $j=0; $j<@subfolders; $j++) {
1471: $depths{$subfolders[$j]} = $depth;
1472: $display{$subfolders[$j]} =
1473: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1474: '<td><label>'.
1475: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1476: '<label>'.
1477: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1478: &mt('Move old').'</label>'.
1479: '</td></tr>';
1480: }
1.492 raeburn 1481: }
1.538 raeburn 1482: &recurse_print(\$output,$parent,\%deps,\%display);
1483: $output .= '</table></fieldset>';
1.329 droeschl 1484: }
1.538 raeburn 1485: $output .= '</div>';
1486: return $output;
1.488 raeburn 1487: }
1488:
1.492 raeburn 1489: sub recurse_print {
1.538 raeburn 1490: my ($outputref,$dir,$deps,$display) = @_;
1491: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1492: if (ref($deps->{$dir}) eq 'ARRAY') {
1493: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1494: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1495: }
1496: }
1497: }
1498:
1.488 raeburn 1499: sub supp_pasteable {
1500: my ($url) = @_;
1501: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1502: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1503: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1504: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1505: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.625 ! raeburn 1506: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttool$})) {
1.488 raeburn 1507: return 1;
1508: }
1509: return;
1.329 droeschl 1510: }
1511:
1.492 raeburn 1512: sub paste_popup_js {
1.594 damieng 1513: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1514: show => 'Show Options',
1515: hide => 'Hide Options',
1.594 damieng 1516: );
1517: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1518: none => 'No items selected from clipboard.',
1.492 raeburn 1519: );
1.594 damieng 1520: &html_escape(\%html_js_lt);
1521: &js_escape(\%html_js_lt);
1522: &js_escape(\%js_lt);
1.492 raeburn 1523: return <<"END";
1524:
1.538 raeburn 1525: function showPasteOptions(suffix) {
1526: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1527: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1528: return;
1529: }
1530:
1.538 raeburn 1531: function hidePasteOptions(suffix) {
1532: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1533: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1534: return;
1535: }
1536:
1537: function showOptions(caller,suffix) {
1538: if (document.getElementById('pasteoptionstext_'+suffix)) {
1539: if (caller.checked) {
1.594 damieng 1540: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1541: } else {
1542: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1543: }
1544: if (document.getElementById('pasteoptions_'+suffix)) {
1545: document.getElementById('pasteoptions_'+suffix).style.display='none';
1546: }
1547: }
1.492 raeburn 1548: return;
1549: }
1550:
1.541 raeburn 1551: function validateClipboard() {
1552: var numchk = 0;
1553: if (document.pasteform.pasting.length > 1) {
1554: for (var i=0; i<document.pasteform.pasting.length; i++) {
1555: if (document.pasteform.pasting[i].checked) {
1556: numchk ++;
1557: }
1558: }
1559: } else {
1560: if (document.pasteform.pasting.type == 'checkbox') {
1561: if (document.pasteform.pasting.checked) {
1562: numchk ++;
1563: }
1564: }
1565: }
1566: if (numchk > 0) {
1567: return true;
1568: } else {
1.594 damieng 1569: alert("$js_lt{'none'}");
1.541 raeburn 1570: return false;
1571: }
1572: }
1573:
1.575 raeburn 1574: function checkClipboard() {
1575: if (document.pasteform.pasting.length > 1) {
1576: for (var i=0; i<document.pasteform.pasting.length; i++) {
1577: document.pasteform.pasting[i].checked = true;
1578: }
1579: }
1580: return;
1581: }
1582:
1583: function uncheckClipboard() {
1584: if (document.pasteform.pasting.length >1) {
1585: for (var i=0; i<document.pasteform.pasting.length; i++) {
1586: document.pasteform.pasting[i].checked = false;
1587: }
1588: }
1589: return;
1590: }
1591:
1.492 raeburn 1592: END
1593:
1594: }
1595:
1.329 droeschl 1596: sub do_paste_from_buffer {
1.492 raeburn 1597: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1598:
1.538 raeburn 1599: # Array of items in paste buffer
1600: my (@currpaste,%pastebuffer,%allerrors);
1601: @currpaste = split(/,/,$env{'docs.markedcopies'});
1602:
1.492 raeburn 1603: # Early out if paste buffer is empty
1.538 raeburn 1604: if (@currpaste == 0) {
1.492 raeburn 1605: return ();
1.538 raeburn 1606: }
1607: map { $pastebuffer{$_} = 1; } @currpaste;
1608:
1609: # Array of items selected items to paste
1610: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1611:
1612: # Early out if nothing selected to paste
1613: if (@reqpaste == 0) {
1614: return();
1615: }
1616: my @topaste;
1617: foreach my $suffix (@reqpaste) {
1618: next if ($suffix =~ /\D/);
1619: next unless (exists($pastebuffer{$suffix}));
1620: push(@topaste,$suffix);
1621: }
1622:
1623: # Early out if nothing available to paste
1624: if (@topaste == 0) {
1625: return();
1.329 droeschl 1626: }
1627:
1.538 raeburn 1628: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.597 raeburn 1629: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1630:
1631: foreach my $suffix (@topaste) {
1632: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1633: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1634: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1635: # Supplemental content may only include certain types of content
1636: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1637: if ($folder =~ /^supplemental/) {
1638: unless (&supp_pasteable($url)) {
1639: $notinsupp{$suffix} = 1;
1640: next;
1641: }
1.492 raeburn 1642: }
1.538 raeburn 1643: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1644: my $srcd = $1;
1645: my $srcn = $2;
1.492 raeburn 1646: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1647: # check for mdc privilege in the course from which the resource was pasted
1648: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1649: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1650: $notincrs{$suffix} = 1;
1651: next;
1652: }
1.491 raeburn 1653: }
1.538 raeburn 1654: $srcdom{$suffix} = $srcd;
1655: $srcnum{$suffix} = $srcn;
1.597 raeburn 1656: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1657: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1658: my ($srcd,$srcn) = split(/_/,$cid);
1659: # When paste buffer was populated using an active role in a different course
1660: # check for mdc privilege in the course from which the resource was pasted
1661: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1662: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1663: $notincrs{$suffix} = 1;
1664: next;
1665: }
1666: }
1667: $srcdom{$suffix} = $srcd;
1668: $srcnum{$suffix} = $srcn;
1.491 raeburn 1669: }
1.597 raeburn 1670: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1671: push(@dopaste,$suffix);
1672: if ($url=~/\.(page|sequence)$/) {
1673: $is_map{$suffix} = 1;
1674: }
1675:
1676: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1677: my $oldprefix = $1;
1.492 raeburn 1678: # When pasting content from Main Content to Supplemental Content and vice versa
1679: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1680: # a folder/page or a document).
1.538 raeburn 1681: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1682: $prefixchg{$suffix} = 'docstosupp';
1683: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1684: $prefixchg{$suffix} = 'supptodocs';
1685: }
1.491 raeburn 1686:
1.492 raeburn 1687: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1688: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1689: my @nested;
1690: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1691: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1692: my @deps = map { /\d+:([\d,]+$)/ } @items;
1693: foreach my $dep (@deps) {
1694: if ($dep =~ /,/) {
1695: push(@nested,split(/,/,$dep));
1696: } else {
1697: push(@nested,$dep);
1698: }
1.492 raeburn 1699: }
1.538 raeburn 1700: foreach my $item (@nested) {
1701: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1702: push(@{$marktomove{$suffix}},$type.'_'.$item);
1703: }
1.492 raeburn 1704: }
1705: }
1.488 raeburn 1706: }
1707: }
1708:
1.538 raeburn 1709: # Early out if nothing available to paste
1710: if (@dopaste == 0) {
1711: return ();
1712: }
1713:
1714: # Populate message hash and hashes used for main content <=> supplemental content
1715: # changes
1716:
1717: %msgs = &Apache::lonlocal::texthash (
1718: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1719: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1720: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1721: );
1722:
1723: %before = (
1724: docstosupp => {
1725: map => 'default',
1726: doc => 'docs',
1727: },
1728: supptodocs => {
1729: map => 'supplemental',
1730: doc => 'supplemental',
1731: },
1732: );
1733:
1734: %after = (
1735: docstosupp => {
1736: map => 'supplemental',
1737: doc => 'supplemental'
1738: },
1739: supptodocs => {
1740: map => 'default',
1741: doc => 'docs',
1742: },
1743: );
1744:
1745: # Retrieve information about all course maps in main content area
1746:
1747: my $allmaps = {};
1748: if ($folder =~ /^default/) {
1749: $allmaps =
1750: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1751: $env{"course.$env{'request.course.id'}.home"},
1752: $env{'request.course.id'});
1753: }
1754:
1755: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1756:
1757: # Loop over the items to paste
1758: foreach my $suffix (@dopaste) {
1.329 droeschl 1759: # Maps need to be copied first
1.538 raeburn 1760: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1761: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1762: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1763: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1764: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1765: }
1766: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1767: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1768: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1769: my $oldurl = $url;
1770: if ($is_map{$suffix}) {
1.491 raeburn 1771: # If pasting a map, check if map contains other maps
1.538 raeburn 1772: my (%hierarchy,%titles);
1773: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1774: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1775: if ($url=~ m{^/uploaded/}) {
1776: my $newurl;
1777: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1778: ($newurl,my $error) =
1779: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1780: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1781: \$title,$allmaps,\%newurls);
1782: if ($error) {
1783: $allerrors{$suffix} = $error;
1784: next;
1785: }
1786: if ($newurl ne '') {
1787: if ($newurl ne $url) {
1788: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1789: $newsubdir{$url} = $1;
1790: }
1791: $mapchanges{$url} = 1;
1.492 raeburn 1792: }
1.538 raeburn 1793: }
1794: }
1795: if (($srcdom{$suffix} ne $coursedom) ||
1796: ($srcnum{$suffix} ne $coursenum) ||
1797: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1798: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1799: $coursedom,$coursenum,$srcdom{$suffix},
1800: $srcnum{$suffix},$allmaps,\%rewrites,
1801: \%retitles,\%copies,\%dbcopies,
1802: \%zombies,\%params,\%mapmoves,
1803: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1804: \%newurls,\%resdatacopy)) {
1.538 raeburn 1805: $mapmoves{$url} = 1;
1806: }
1807: $url = $newurl;
1808: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1809: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1810: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1811: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1812: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1813: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1814: }
1815: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1816: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1817: push(@toclear,$suffix);
1818: # if pasting published map (main content area only) check map not already in course
1819: if ($folder =~ /^default/) {
1820: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1821: $duplicate{$suffix} = 1;
1822: next;
1.492 raeburn 1823: }
1.491 raeburn 1824: }
1825: }
1.538 raeburn 1826: }
1827: if ($url=~ m{/(bulletinboard|smppg)$}) {
1828: my $prefix = $1;
1.596 raeburn 1829: my $fromothercrs;
1.538 raeburn 1830: #need to copy the db contents to a new one, unless this is a move.
1831: my %info = (
1832: src => $url,
1833: cdom => $coursedom,
1834: cnum => $coursenum,
1.596 raeburn 1835: );
1836: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1837: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1838: $fromothercrs = 1;
1839: $info{'cdom'} = $srcdom{$suffix};
1840: $info{'cnum'} = $srcnum{$suffix};
1841: }
1842: }
1843: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.538 raeburn 1844: my (%lockerr,$msg);
1845: my ($newurl,$result,$errtext) =
1846: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1847: if ($result eq 'ok') {
1848: $url = $newurl;
1849: $title=&mt('Copy of').' '.$title;
1850: } else {
1851: if ($prefix eq 'smppg') {
1852: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1853: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1854: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.538 raeburn 1855: }
1856: $results{$suffix} = $result;
1857: $msgerrs{$suffix} = $msg;
1858: $lockerrs{$suffix} = $lockerr{$prefix};
1859: next;
1860: }
1861: if ($lockerr{$prefix}) {
1862: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1863: }
1.489 raeburn 1864: }
1865: }
1.538 raeburn 1866: $title = &LONCAPA::map::qtunescape($title);
1867: my $ext='false';
1868: if ($url=~m{^http(|s)://}) { $ext='true'; }
1869: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1870: if ($folder !~ /^supplemental/) {
1871: (undef,undef,$title) =
1872: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1873: }
1874: } else {
1875: if ($folder=~/^supplemental/) {
1876: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1877: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1878: }
1.533 raeburn 1879: }
1.491 raeburn 1880:
1881: # For uploaded files (excluding pages/sequences) path in copied file is changed
1882: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1883: # courses.
1884:
1.538 raeburn 1885: unless ($is_map{$suffix}) {
1886: my $newidx;
1.492 raeburn 1887: # Now insert the URL at the bottom
1.538 raeburn 1888: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1889: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1890: my $relpath = $1;
1891: if ($relpath ne '') {
1892: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1893: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1894: my $newprefix = $newloc;
1895: if ($newloc eq 'default') {
1896: $newprefix = 'docs';
1897: }
1898: if ($newdocsdir eq '') {
1899: $newdocsdir = 'default';
1900: }
1901: if (($prefixchg{$suffix}) ||
1902: ($srcdom{$suffix} ne $coursedom) ||
1903: ($srcnum{$suffix} ne $coursenum) ||
1904: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1905: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1906: $url =
1907: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1908: &Apache::lonnet::getfile($oldurl));
1909: if ($url eq '/adm/notfound.html') {
1910: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1911: next;
1912: } else {
1913: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1914: $newsubpath =~ s{/+$}{/};
1915: $docmoves{$oldurl} = $newsubpath;
1916: }
1.491 raeburn 1917: }
1918: }
1.597 raeburn 1919: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1920: my $template = $1;
1921: if ($newidx) {
1922: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1923: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1924: }
1.491 raeburn 1925: }
1.538 raeburn 1926: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1927: ':'.$ext.':normal:res';
1928: push(@LONCAPA::map::order,$newidx);
1929: # Store the result
1930: my ($errtext,$fatal) =
1931: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1932: if ($fatal) {
1933: $save_err .= $errtext;
1934: $allresult = 'fail';
1935: }
1.488 raeburn 1936: }
1.538 raeburn 1937:
1.597 raeburn 1938: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1939: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1940: unless ($allresult eq 'fail') {
1941: my %updated = (
1942: rewrites => \%rewrites,
1943: zombies => \%zombies,
1944: removefrommap => \%removefrommap,
1945: removeparam => \%removeparam,
1946: dbcopies => \%dbcopies,
1.597 raeburn 1947: resdatacopy => \%resdatacopy,
1.538 raeburn 1948: retitles => \%retitles,
1949: );
1950: my %info = (
1951: newsubdir => \%newsubdir,
1952: params => \%params,
1953: );
1954: if ($prefixchg{$suffix}) {
1955: $info{'before'} = $before{$prefixchg{$suffix}};
1956: $info{'after'} = $after{$prefixchg{$suffix}};
1957: }
1958: my %moves = (
1959: copies => \%copies,
1960: docmoves => \%docmoves,
1961: mapmoves => \%mapmoves,
1962: );
1963: (my $result,$msgs{$suffix},my $lockerror) =
1964: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1965: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1966: $url,'paste');
1967: $lockerrors .= $lockerror;
1968: if ($result eq 'ok') {
1969: if ($is_map{$suffix}) {
1970: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1971: $folder.'.'.$container);
1972: if ($fatal) {
1973: $allresult = 'failread';
1974: } else {
1975: if ($#LONCAPA::map::order<1) {
1976: my $idx=&LONCAPA::map::getresidx();
1977: if ($idx<=0) { $idx=1; }
1978: $LONCAPA::map::order[0]=$idx;
1979: $LONCAPA::map::resources[$idx]='';
1980: }
1981: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1982: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1983: ':'.$ext.':normal:res';
1984: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 1985:
1986: # Store the result
1.538 raeburn 1987: my ($errtext,$fatal) =
1988: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1989: if ($fatal) {
1990: $save_err .= $errtext;
1991: $allresult = 'failstore';
1992: }
1993: }
1994: }
1995: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1996: push(@toclear,$suffix);
1997: }
1998: }
1.492 raeburn 1999: }
2000: }
1.538 raeburn 2001: &clear_from_buffer(\@toclear,\@currpaste);
2002: my $msgsarray;
2003: foreach my $suffix (keys(%msgs)) {
2004: if (ref($msgs{$suffix}) eq 'ARRAY') {
2005: $msgsarray .= join(',',@{$msgs{$suffix}});
2006: }
2007: }
2008: return ($allresult,$save_err,$msgsarray,$lockerrors);
2009: }
1.533 raeburn 2010:
1.538 raeburn 2011: sub do_buffer_empty {
2012: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2013: if (@currpaste == 0) {
2014: return &mt('Clipboard is already empty');
2015: }
2016: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2017: if (@toclear == 0) {
2018: return &mt('Nothing selected to clear from clipboard');
2019: }
2020: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2021: if ($numdel) {
2022: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2023: } else {
2024: return &mt('Clipboard unchanged');
1.492 raeburn 2025: }
1.538 raeburn 2026: return;
2027: }
2028:
2029: sub clear_from_buffer {
2030: my ($toclear,$currpaste) = @_;
2031: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2032: my %pastebuffer;
2033: map { $pastebuffer{$_} = 1; } @{$currpaste};
2034: my $numdel = 0;
2035: foreach my $suffix (@{$toclear}) {
2036: next if ($suffix =~ /\D/);
2037: next unless (exists($pastebuffer{$suffix}));
2038: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2039: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2040: delete($pastebuffer{$suffix});
2041: $numdel ++;
2042: }
2043: }
2044: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2045: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2046: return $numdel;
1.492 raeburn 2047: }
2048:
2049: sub get_newmap_url {
2050: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2051: $titleref,$allmaps,$newurls) = @_;
2052: my $newurl;
2053: if ($url=~ m{^/uploaded/}) {
2054: $$titleref=&mt('Copy of').' '.$$titleref;
2055: }
2056: my $now = time;
2057: my $suffix=$$.int(rand(100)).$now;
2058: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2059: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2060: my $path = $1;
2061: my $prefix = $2;
2062: my $ancestor = $3;
2063: if (length($ancestor) > 10) {
2064: $ancestor = substr($ancestor,-10,10);
2065: }
2066: my $newid;
2067: if ($prefixchg) {
2068: if ($folder =~ /^supplemental/) {
2069: $prefix =~ s/^default/supplemental/;
2070: } else {
2071: $prefix =~ s/^supplemental/default/;
2072: }
2073: }
2074: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2075: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2076: } else {
2077: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2078: }
2079: my $counter = 0;
2080: my $is_unique = &uniqueness_check($newurl);
2081: if ($folder =~ /^default/) {
2082: if ($allmaps->{$newurl}) {
2083: $is_unique = 0;
2084: }
2085: }
2086: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2087: $counter ++;
2088: $suffix ++;
2089: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2090: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2091: } else {
2092: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2093: }
2094: $is_unique = &uniqueness_check($newurl);
2095: }
2096: if ($is_unique) {
2097: $newurls->{$newurl} = 1;
2098: } else {
2099: if ($url=~/\.page$/) {
2100: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2101: } else {
2102: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2103: }
2104: }
1.329 droeschl 2105: }
1.492 raeburn 2106: return ($newurl);
1.329 droeschl 2107: }
2108:
1.488 raeburn 2109: sub dbcopy {
1.533 raeburn 2110: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2111: my ($url,$result,$errtext);
2112: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2113: $url = $dbref->{'src'};
1.533 raeburn 2114: if ($url =~ m{/(smppg|bulletinboard)$}) {
2115: my $prefix = $1;
2116: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2117: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2118: my $db_name;
2119: my $marker = (split(m{/},$url))[4];
2120: $marker=~s/\D//g;
2121: if ($dbref->{'src'} =~ m{/smppg$}) {
2122: $db_name =
2123: &Apache::lonsimplepage::get_db_name($url,$marker,
2124: $dbref->{'cdom'},
2125: $dbref->{'cnum'});
2126: } else {
2127: $db_name = 'bulletinpage_'.$marker;
2128: }
2129: my ($suffix,$freedlock,$error) =
2130: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2131: $coursedom,$coursenum,
2132: 'concat');
2133: if (!$suffix) {
2134: if ($prefix eq 'smppg') {
2135: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2136: } else {
1.565 bisitz 2137: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2138: }
2139: if ($error) {
2140: $errtext .= '<br />'.$error;
2141: }
2142: } else {
2143: #need to copy the db contents to a new one.
2144: my %contents=&Apache::lonnet::dump($db_name,
2145: $dbref->{'cdom'},
2146: $dbref->{'cnum'});
2147: if (exists($contents{'uploaded.photourl'})) {
2148: my $photo = $contents{'uploaded.photourl'};
2149: my ($subdir,$fname) =
2150: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2151: my $newphoto;
1.533 raeburn 2152: if ($fname ne '') {
2153: my $content = &Apache::lonnet::getfile($photo);
2154: unless ($content eq '-1') {
2155: $env{'form.'.$suffix.'.photourl'} = $content;
2156: $newphoto =
2157: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2158: delete($env{'form.'.$suffix.'.photourl'});
2159: }
2160: }
2161: if ($newphoto =~ m{^/uploaded/}) {
2162: $contents{'uploaded.photourl'} = $newphoto;
2163: }
2164: }
2165: $db_name =~ s{_\d*$ }{_$suffix}x;
2166: $result=&Apache::lonnet::put($db_name,\%contents,
2167: $coursedom,$coursenum);
2168: if ($result eq 'ok') {
2169: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2170: }
2171: }
2172: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2173: $lockerrorsref->{$prefix} =
1.533 raeburn 2174: '<div class="LC_error">'.
2175: &mt('There was a problem removing a lockfile.');
2176: if ($prefix eq 'smppg') {
1.560 raeburn 2177: $lockerrorsref->{$prefix} .=
1.559 raeburn 2178: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.533 raeburn 2179: } else {
1.565 bisitz 2180: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2181: }
1.560 raeburn 2182: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2183: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2184: '</div>';
1.533 raeburn 2185: }
2186: }
2187: } elsif ($url =~ m{/syllabus$}) {
2188: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2189: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2190: if (($dbref->{'cdom'} ne $coursedom) ||
2191: ($dbref->{'cnum'} ne $coursenum)) {
2192: my %contents=&Apache::lonnet::dump('syllabus',
2193: $dbref->{'cdom'},
2194: $dbref->{'cnum'});
2195: $result=&Apache::lonnet::put('syllabus',\%contents,
2196: $coursedom,$coursenum);
2197: }
2198: }
1.488 raeburn 2199: }
2200: }
1.533 raeburn 2201: return ($url,$result,$errtext);
1.488 raeburn 2202: }
2203:
1.597 raeburn 2204: sub copy_templated_files {
2205: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2206: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2207: my $srccontainer = 'sequence';
2208: if ($srcwaspage) {
2209: $srccontainer = 'page';
2210: }
2211: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2212: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2213: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2214: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2215: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2216: $template.'.problem';
2217: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2218: if ($template eq 'simpleproblem') {
2219: $srcprefix .= '.0.';
2220: my $weightprefix = $newprefix;
2221: $newprefix .= '.0.';
2222: my @simpleprobqtypes = qw(radio option string essay numerical);
2223: my $qtype=$srcparms{$srcprefix.'questiontype'};
2224: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2225: my %newdata;
2226: foreach my $type (@simpleprobqtypes) {
2227: if ($type eq $qtype) {
2228: $newdata{"$weightprefix.$type.weight"}=1;
2229: } else {
2230: $newdata{"$weightprefix.$type.weight"}=0;
2231: }
2232: }
2233: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2234: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2235: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2236: if ($qtype eq 'numerical') {
2237: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2238: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2239: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2240: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2241: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2242: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2243: unless (defined($maxfoils)) { $maxfoils=10; }
2244: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2245: if ($maxfoils<=0) { $maxfoils=10; }
2246: my $randomize=$srcparms{$srcprefix.'randomize'};
2247: unless (defined($randomize)) { $randomize='yes'; }
2248: unless ($randomize eq 'no') { $randomize='yes'; }
2249: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2250: $newdata{$newprefix.'randomize'} = $randomize;
2251: if ($qtype eq 'option') {
2252: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2253: }
2254: for (my $i=1; $i<=10; $i++) {
2255: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2256: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2257: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2258: }
2259:
2260: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2261: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2262: unless (defined($maxfoils)) { $maxfoils=10; }
2263: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2264: if ($maxfoils<=0) { $maxfoils=10; }
2265: my $randomize=$srcparms{$srcprefix.'randomize'};
2266: unless (defined($randomize)) { $randomize='yes'; }
2267: unless ($randomize eq 'no') { $randomize='yes'; }
2268: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2269: $newdata{$newprefix.'randomize'} = $randomize;
2270: if ($qtype eq 'option') {
2271: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2272: }
2273: for (my $i=1; $i<=10; $i++) {
2274: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2275: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2276: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2277: }
2278: } elsif ($qtype eq 'string') {
2279: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2280: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2281: }
2282: if (keys(%newdata)) {
2283: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2284: $coursenum);
2285: if ($putres eq 'ok') {
2286: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2287: }
2288: }
2289: }
2290: }
2291: }
2292:
1.329 droeschl 2293: sub uniqueness_check {
2294: my ($newurl) = @_;
2295: my $unique = 1;
2296: foreach my $res (@LONCAPA::map::order) {
2297: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2298: $url=&LONCAPA::map::qtescape($url);
2299: if ($newurl eq $url) {
2300: $unique = 0;
1.344 bisitz 2301: last;
1.329 droeschl 2302: }
2303: }
2304: return $unique;
2305: }
2306:
1.488 raeburn 2307: sub contained_map_check {
1.492 raeburn 2308: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2309: $allmaps) = @_;
1.488 raeburn 2310: my $content = &Apache::lonnet::getfile($url);
2311: unless ($content eq '-1') {
2312: my $parser = HTML::TokeParser->new(\$content);
2313: $parser->attr_encoded(1);
2314: while (my $token = $parser->get_token) {
2315: next if ($token->[0] ne 'S');
2316: if ($token->[1] eq 'resource') {
2317: next if ($token->[2]->{'type'} eq 'zombie');
2318: my $ressrc = $token->[2]->{'src'};
2319: if ($folder =~ /^supplemental/) {
2320: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2321: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2322: next;
2323: }
2324: }
1.492 raeburn 2325: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2326: if ($1 eq 'uploaded') {
2327: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2328: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2329: } else {
1.492 raeburn 2330: if ($allmaps->{$ressrc}) {
1.529 raeburn 2331: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2332: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2333: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2334: } else {
2335: $addedmaps->{$ressrc} = [$url];
2336: }
1.488 raeburn 2337: }
1.492 raeburn 2338: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2339: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2340: }
1.492 raeburn 2341: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2342: if ($folder =~ /^supplemental/) {
1.492 raeburn 2343: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2344: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2345: } else {
2346: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2347: }
1.488 raeburn 2348: }
2349: }
2350: }
2351: }
2352: return;
2353: }
2354:
2355: sub url_paste_fixups {
1.533 raeburn 2356: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2357: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2358: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2359: my $checktitle;
2360: if (($prefixchg) &&
1.492 raeburn 2361: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2362: $checktitle = 1;
2363: }
1.492 raeburn 2364: my $skip;
2365: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2366: my $mapid = $1.$2;
2367: if ($tomove->{$mapid}) {
2368: $skip = 1;
2369: }
2370: }
1.491 raeburn 2371: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2372: return if ($file eq '-1');
2373: my $parser = HTML::TokeParser->new(\$file);
2374: $parser->attr_encoded(1);
1.491 raeburn 2375: my $changed = 0;
1.488 raeburn 2376: while (my $token = $parser->get_token) {
2377: next if ($token->[0] ne 'S');
2378: if ($token->[1] eq 'resource') {
2379: my $ressrc = $token->[2]->{'src'};
2380: next if ($ressrc eq '');
1.491 raeburn 2381: my $id = $token->[2]->{'id'};
1.492 raeburn 2382: my $title = $token->[2]->{'title'};
1.491 raeburn 2383: if ($checktitle) {
2384: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2385: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2386: }
2387: }
1.488 raeburn 2388: next if ($token->[2]->{'type'} eq 'external');
2389: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2390: next if ($skip);
1.532 raeburn 2391: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2392: $changed = 1;
2393: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2394: my $srcdom = $1;
2395: my $srcnum = $2;
1.488 raeburn 2396: my $rem = $3;
1.492 raeburn 2397: my $newurl;
2398: my $mapname;
2399: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2400: my $prefix = $1;
2401: $mapname = $prefix.$2;
2402: if ($tomove->{$mapname}) {
1.533 raeburn 2403: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2404: $srcdom,$srcnum,$allmaps,$rewrites,
2405: $retitles,$copies,$dbcopies,$zombies,
2406: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2407: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2408: next;
2409: } else {
2410: ($newurl,my $error) =
2411: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2412: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2413: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2414: $newsubdir->{$ressrc} = $1;
2415: }
2416: if ($error) {
2417: next;
2418: }
2419: }
2420: }
2421: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2422: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2423:
1.488 raeburn 2424: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2425: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2426: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2427: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2428: $cnum,$srcdom,$srcnum,$allmaps,
2429: $rewrites,$retitles,$copies,$dbcopies,
2430: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2431: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2432: $mapmoves->{$ressrc} = 1;
2433: }
2434: $changed = 1;
1.488 raeburn 2435: } else {
1.532 raeburn 2436: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2437: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2438: $changed = 1;
1.488 raeburn 2439: }
2440: }
1.533 raeburn 2441: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2442: next if ($skip);
1.492 raeburn 2443: my $srcdom = $1;
2444: my $srcnum = $2;
2445: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2446: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2447: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2448: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2449: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2450: $changed = 1;
2451: }
2452: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2453: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2454: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2455: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2456: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2457: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2458: $changed = 1;
1.488 raeburn 2459: }
1.597 raeburn 2460: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2461: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2462: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2463: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2464: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2465: }
1.488 raeburn 2466: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2467: next if ($skip);
2468: my $srcdom = $1;
2469: my $srcnum = $2;
2470: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2471: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2472: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2473: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2474: $changed = 1;
1.488 raeburn 2475: }
2476: }
2477: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2478: next if ($skip);
1.488 raeburn 2479: my $to = $token->[2]->{'to'};
2480: if ($to ne '') {
2481: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2482: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2483: } else {
2484: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2485: }
2486: }
2487: }
2488: }
1.491 raeburn 2489: return $changed;
1.488 raeburn 2490: }
2491:
2492: sub apply_fixups {
1.529 raeburn 2493: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2494: $oldurl,$url,$caller) = @_;
2495: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2496: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2497: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2498: if (ref($updated) eq 'HASH') {
2499: if (ref($updated->{'rewrites'}) eq 'HASH') {
2500: %rewrites = %{$updated->{'rewrites'}};
2501: }
2502: if (ref($updated->{'zombies'}) eq 'HASH') {
2503: %zombies = %{$updated->{'zombies'}};
2504: }
2505: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2506: %removefrommap = %{$updated->{'removefrommap'}};
2507: }
2508: if (ref($updated->{'removeparam'}) eq 'HASH') {
2509: %removeparam = %{$updated->{'removeparam'}};
2510: }
2511: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2512: %dbcopies = %{$updated->{'dbcopies'}};
2513: }
2514: if (ref($updated->{'retitles'}) eq 'HASH') {
2515: %retitles = %{$updated->{'retitles'}};
2516: }
1.597 raeburn 2517: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2518: %resdatacopy = %{$updated->{'resdatacopy'}};
2519: }
1.529 raeburn 2520: }
2521: if (ref($info) eq 'HASH') {
2522: if (ref($info->{'newsubdir'}) eq 'HASH') {
2523: %newsubdir = %{$info->{'newsubdir'}};
2524: }
2525: if (ref($info->{'params'}) eq 'HASH') {
2526: %params = %{$info->{'params'}};
2527: }
2528: if (ref($info->{'before'}) eq 'HASH') {
2529: %before = %{$info->{'before'}};
2530: }
2531: if (ref($info->{'after'}) eq 'HASH') {
2532: %after = %{$info->{'after'}};
2533: }
2534: }
2535: if (ref($moves) eq 'HASH') {
2536: if (ref($moves->{'copies'}) eq 'HASH') {
2537: %copies = %{$moves->{'copies'}};
2538: }
2539: if (ref($moves->{'docmoves'}) eq 'HASH') {
2540: %docmoves = %{$moves->{'docmoves'}};
2541: }
2542: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2543: %mapmoves = %{$moves->{'mapmoves'}};
2544: }
2545: }
2546: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2547: my @allcopies;
1.529 raeburn 2548: if (exists($copies{$key})) {
2549: if (ref($copies{$key}) eq 'HASH') {
2550: my %added;
2551: foreach my $innerkey (keys(%{$copies{$key}})) {
2552: if (($innerkey ne '') && (!$added{$innerkey})) {
2553: push(@allcopies,$innerkey);
2554: $added{$innerkey} = 1;
2555: }
1.491 raeburn 2556: }
1.529 raeburn 2557: undef(%added);
1.491 raeburn 2558: }
2559: }
2560: if ($key eq $oldurl) {
1.529 raeburn 2561: if ((exists($docmoves{$key}))) {
1.532 raeburn 2562: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2563: push(@allcopies,$oldurl);
2564: }
2565: }
2566: }
2567: if (@allcopies > 0) {
2568: foreach my $item (@allcopies) {
1.492 raeburn 2569: my ($relpath,$oldsubdir,$fname) =
2570: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2571: if ($fname ne '') {
2572: my $content = &Apache::lonnet::getfile($item);
2573: unless ($content eq '-1') {
2574: my $storefn;
1.529 raeburn 2575: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2576: $storefn = $docmoves{$key};
1.491 raeburn 2577: } else {
2578: $storefn = $relpath;
2579: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2580: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2581: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2582: }
1.529 raeburn 2583: if ($newsubdir{$key}) {
1.532 raeburn 2584: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2585: }
2586: }
2587: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2588: my $copyurl =
2589: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2590: $storefn.$fname,$content);
2591: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2592: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2593: return &mt('Paste failed: an error occurred copying the file.');
2594: } elsif (ref($errors) eq 'HASH') {
2595: $errors->{$item} = 1;
1.489 raeburn 2596: }
2597: }
1.488 raeburn 2598: }
2599: }
1.491 raeburn 2600: }
2601: }
2602: }
1.529 raeburn 2603: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2604: my $storefn=$key;
2605: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2606: if ($prefixchg && $before{'map'} && $after{'map'}) {
2607: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2608: }
1.529 raeburn 2609: if ($newsubdir{$key}) {
2610: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2611: }
1.491 raeburn 2612: my $mapcontent = &Apache::lonnet::getfile($key);
2613: if ($mapcontent eq '-1') {
2614: if (ref($errors) eq 'HASH') {
2615: $errors->{$key} = 1;
2616: }
2617: } else {
2618: my $newmap =
2619: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2620: $mapcontent);
2621: if ($newmap eq '/adm/notfound.html') {
2622: if (ref($errors) eq 'HASH') {
2623: $errors->{$key} = 1;
1.489 raeburn 2624: }
1.488 raeburn 2625: }
2626: }
2627: }
1.491 raeburn 2628: my %updates;
2629: if ($is_map) {
1.529 raeburn 2630: if (ref($updated) eq 'HASH') {
2631: foreach my $type (keys(%{$updated})) {
2632: if (ref($updated->{$type}) eq 'HASH') {
2633: foreach my $key (keys(%{$updated->{$type}})) {
2634: $updates{$key} = 1;
2635: }
2636: }
2637: }
1.491 raeburn 2638: }
2639: foreach my $key (keys(%updates)) {
1.492 raeburn 2640: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2641: if (ref($rewrites{$key}) eq 'HASH') {
2642: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2643: }
1.529 raeburn 2644: if (ref($retitles{$key}) eq 'HASH') {
2645: %toretitle = %{$retitles{$key}};
1.491 raeburn 2646: }
1.529 raeburn 2647: if (ref($removefrommap{$key}) eq 'HASH') {
2648: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2649: }
1.529 raeburn 2650: if (ref($removeparam{$key}) eq 'HASH') {
2651: %remparam = %{$removeparam{$key}};
1.492 raeburn 2652: }
1.529 raeburn 2653: if (ref($zombies{$key}) eq 'HASH') {
2654: %zombie = %{$zombies{$key}};
1.491 raeburn 2655: }
1.529 raeburn 2656: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2657: foreach my $idx (keys(%{$dbcopies{$key}})) {
2658: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2659: my ($newurl,$result,$errtext) =
2660: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2661: if ($result eq 'ok') {
2662: $newdb{$idx} = $newurl;
2663: } elsif (ref($errors) eq 'HASH') {
2664: $errors->{$key} = 1;
2665: }
2666: push(@msgs,$errtext);
2667: }
1.491 raeburn 2668: }
2669: }
1.597 raeburn 2670: if (ref($resdatacopy{$key}) eq 'HASH') {
2671: if ($newsubdir{$key}) {
2672:
2673: }
2674: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2675: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2676: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2677: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2678: my $template = $1;
2679: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2680: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2681: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2682: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2683: my ($newmapname) = ($key =~ m{/([^/]+)$});
2684: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2685: my $srcmapinfo = $srcfolder.':'.$idx;
2686: if ($srccontainer eq 'page') {
2687: $srcmapinfo .= ':1';
2688: }
2689: if ($newsubdir{$key}) {
2690: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2691: }
2692: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2693: $cnum,$template,$idx,$newmapname);
2694: }
2695: }
2696: }
2697: }
2698: }
1.529 raeburn 2699: if (ref($params{$key}) eq 'HASH') {
2700: %currparam = %{$params{$key}};
1.492 raeburn 2701: }
2702: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2703: if ($fatal) {
1.533 raeburn 2704: return ($errtext);
1.492 raeburn 2705: }
2706: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2707: if (defined($LONCAPA::map::zombies[$i])) {
2708: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2709: if ($zombie{$i} eq $src) {
1.492 raeburn 2710: undef($LONCAPA::map::zombies[$i]);
2711: }
2712: }
2713: }
1.529 raeburn 2714: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2715: my $idx = $LONCAPA::map::order[$i];
2716: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2717: my $changed;
1.529 raeburn 2718: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2719: if ((exists($toremove{$idx})) &&
2720: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2721: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2722: if (ref($currparam{$idx}) eq 'ARRAY') {
2723: foreach my $name (@{$currparam{$idx}}) {
2724: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2725: }
2726: }
2727: next;
2728: }
2729: my $origsrc = $src;
1.532 raeburn 2730: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2731: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2732: $changed = 1;
1.491 raeburn 2733: }
1.492 raeburn 2734: }
1.532 raeburn 2735: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2736: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2737: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2738: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2739: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2740: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2741: } else {
1.529 raeburn 2742: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2743: }
1.491 raeburn 2744: }
1.532 raeburn 2745: if ($origsrc =~ /\.(page|sequence)$/) {
2746: if ($newsubdir{$origsrc}) {
1.529 raeburn 2747: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2748: }
1.532 raeburn 2749: } elsif ($newsubdir{$key}) {
2750: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2751: }
2752: }
1.492 raeburn 2753: $changed = 1;
1.533 raeburn 2754: } elsif ($newdb{$idx} ne '') {
2755: $src = $newdb{$idx};
1.492 raeburn 2756: $changed = 1;
2757: }
2758: if ($changed) {
1.538 raeburn 2759: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2760: }
2761: }
2762: }
2763: foreach my $idx (keys(%remparam)) {
2764: if (ref($remparam{$idx}) eq 'ARRAY') {
2765: foreach my $name (@{$remparam{$idx}}) {
2766: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2767: }
2768: }
2769: }
1.533 raeburn 2770: if (values(%lockerrors) > 0) {
2771: $lockmsg = join('<br />',values(%lockerrors));
2772: }
1.491 raeburn 2773: my $storefn;
2774: if ($key eq $oldurl) {
2775: $storefn = $url;
2776: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2777: } else {
2778: $storefn = $key;
2779: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2780: if ($prefixchg && $before{'map'} && $after{'map'}) {
2781: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2782: }
1.529 raeburn 2783: if ($newsubdir{$key}) {
2784: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2785: }
1.491 raeburn 2786: }
1.492 raeburn 2787: my $report;
2788: if ($folder !~ /^supplemental/) {
2789: $report = 1;
2790: }
1.527 raeburn 2791: (my $outtext,$errtext) =
1.492 raeburn 2792: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2793: if ($errtext) {
1.529 raeburn 2794: if ($caller eq 'paste') {
1.533 raeburn 2795: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2796: }
1.491 raeburn 2797: }
2798: }
2799: }
1.533 raeburn 2800: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2801: }
2802:
2803: sub copy_dependencies {
2804: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2805: my $content;
2806: if (ref($contentref)) {
2807: $content = $$contentref;
2808: } else {
2809: $content = &Apache::lonnet::getfile($item);
2810: }
2811: unless ($content eq '-1') {
2812: my $mm = new File::MMagic;
2813: my $mimetype = $mm->checktype_contents($content);
2814: if ($mimetype eq 'text/html') {
2815: my (%allfiles,%codebase,$state);
2816: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2817: if ($res eq 'ok') {
2818: my ($numexisting,$numpathchanges,$existing);
2819: (undef,$numexisting,$numpathchanges,$existing) =
2820: &Apache::loncommon::ask_for_embedded_content(
2821: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2822: {'error_on_invalid_names' => 1,
2823: 'ignore_remote_references' => 1,
2824: 'docs_url' => $item,
2825: 'context' => 'paste'});
2826: if ($numexisting > 0) {
2827: if (ref($existing) eq 'HASH') {
2828: foreach my $dep (keys(%{$existing})) {
2829: my $depfile = $dep;
2830: unless ($depfile =~ m{^\Q$relpath\E}) {
2831: $depfile = $relpath.$dep;
2832: }
2833: my $depcontent = &Apache::lonnet::getfile($depfile);
2834: unless ($depcontent eq '-1') {
2835: my $storedep = $dep;
2836: $storedep =~ s{^\Q$relpath\E}{};
2837: my $dep_url =
2838: &Apache::lonclonecourse::writefile(
2839: $env{'request.course.id'},
2840: $storefn.$storedep,$depcontent);
2841: if ($dep_url eq '/adm/notfound.html') {
2842: if (ref($errors) eq 'HASH') {
2843: $errors->{$depfile} = 1;
2844: }
2845: } else {
2846: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2847: }
2848: }
2849: }
1.488 raeburn 2850: }
2851: }
2852: }
2853: }
2854: }
2855: return;
2856: }
2857:
1.329 droeschl 2858: my %parameter_type = ( 'randompick' => 'int_pos',
2859: 'hiddenresource' => 'string_yesno',
2860: 'encrypturl' => 'string_yesno',
2861: 'randomorder' => 'string_yesno',);
2862: my $valid_parameters_re = join('|',keys(%parameter_type));
2863: # set parameters
2864: sub update_parameter {
1.537 raeburn 2865: if ($env{'form.changeparms'} eq 'all') {
2866: my (@allidx,@allmapidx,%allchecked,%currchecked);
2867: %allchecked = (
2868: 'hiddenresource' => {},
2869: 'encrypturl' => {},
2870: 'randompick' => {},
2871: 'randomorder' => {},
2872: );
2873: foreach my $which (keys(%allchecked)) {
2874: $env{'form.all'.$which} =~ s/,$//;
2875: if ($which eq 'randompick') {
2876: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2877: my ($res,$value) = split(/:/,$item);
2878: if ($value =~ /^\d+$/) {
2879: $allchecked{$which}{$res} = $value;
2880: }
2881: }
2882: } else {
1.539 raeburn 2883: if ($env{'form.all'.$which}) {
2884: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2885: }
1.537 raeburn 2886: }
2887: }
2888: my $haschanges = 0;
2889: foreach my $res (@LONCAPA::map::order) {
2890: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2891: $name=&LONCAPA::map::qtescape($name);
2892: $url=&LONCAPA::map::qtescape($url);
2893: next unless ($name && $url);
2894: my $is_map;
2895: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2896: $is_map = 1;
2897: }
2898: foreach my $which (keys(%allchecked)) {
2899: if (($which eq 'randompick' || $which eq 'randomorder')) {
2900: next if (!$is_map);
2901: }
2902: my $oldvalue = 0;
2903: my $newvalue = 0;
2904: if ($allchecked{$which}{$res}) {
2905: $newvalue = $allchecked{$which}{$res};
2906: }
2907: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2908: if ($which eq 'randompick') {
2909: if ($current =~ /^(\d+)$/) {
2910: $oldvalue = $1;
2911: }
2912: } else {
2913: if ($current =~ /^yes$/i) {
2914: $oldvalue = 1;
2915: }
2916: }
2917: if ($oldvalue ne $newvalue) {
2918: $haschanges = 1;
2919: if ($newvalue) {
2920: my $storeval = 'yes';
2921: if ($which eq 'randompick') {
2922: $storeval = $newvalue;
2923: }
2924: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2925: $storeval,
2926: $parameter_type{$which});
2927: &remember_parms($res,$which,'set',$storeval);
2928: } elsif ($oldvalue) {
2929: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2930: &remember_parms($res,$which,'del');
2931: }
2932: }
2933: }
2934: }
2935: return $haschanges;
2936: } else {
1.588 raeburn 2937: my $haschanges = 0;
2938: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2939:
1.537 raeburn 2940: my $which = $env{'form.changeparms'};
2941: my $idx = $env{'form.setparms'};
1.588 raeburn 2942: my $oldvalue = 0;
2943: my $newvalue = 0;
2944: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2945: if ($which eq 'randompick') {
2946: if ($current =~ /^(\d+)$/) {
2947: $oldvalue = $1;
2948: }
2949: } elsif ($current =~ /^yes$/i) {
2950: $oldvalue = 1;
2951: }
1.537 raeburn 2952: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2953: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2954: : 1;
2955: }
2956: if ($oldvalue ne $newvalue) {
2957: $haschanges = 1;
2958: if ($newvalue) {
2959: my $storeval = 'yes';
2960: if ($which eq 'randompick') {
2961: $storeval = $newvalue;
2962: }
2963: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2964: $parameter_type{$which});
2965: &remember_parms($idx,$which,'set',$storeval);
2966: } else {
2967: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2968: &remember_parms($idx,$which,'del');
2969: }
1.537 raeburn 2970: }
1.588 raeburn 2971: return $haschanges;
1.329 droeschl 2972: }
2973: }
2974:
2975: sub handle_edit_cmd {
2976: my ($coursenum,$coursedom) =@_;
1.543 raeburn 2977: if ($env{'form.cmd'} eq '') {
2978: return 0;
2979: }
1.329 droeschl 2980: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2981:
2982: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2983: my ($title, $url, @rrest) = split(':', $ratstr);
2984:
1.538 raeburn 2985: if ($cmd eq 'remove') {
1.329 droeschl 2986: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2987: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2988: &Apache::lonnet::removeuploadedurl($url);
2989: } else {
2990: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2991: }
2992: splice(@LONCAPA::map::order, $idx, 1);
2993:
2994: } elsif ($cmd eq 'cut') {
2995: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2996: splice(@LONCAPA::map::order, $idx, 1);
2997:
1.344 bisitz 2998: } elsif ($cmd eq 'up'
1.329 droeschl 2999: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3000: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3001:
3002: } elsif ($cmd eq 'down'
3003: && defined($LONCAPA::map::order[$idx+1])) {
3004: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3005:
3006: } elsif ($cmd eq 'rename') {
3007: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3008: if ($comment=~/\S/) {
3009: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3010: $comment.':'.join(':', $url, @rrest);
3011: }
3012: # Devalidate title cache
3013: my $renamed_url=&LONCAPA::map::qtescape($url);
3014: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 3015:
1.329 droeschl 3016: } else {
3017: return 0;
3018: }
3019: return 1;
3020: }
3021:
3022: sub editor {
1.458 raeburn 3023: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3024: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3025: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3026: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3027: if ($allowed) {
1.519 raeburn 3028: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3029: $is_random_order,$container) =
1.510 raeburn 3030: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3031: $r->print($breadcrumbtrail);
1.519 raeburn 3032: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3033: $container = 'page';
3034: } else {
3035: $container = 'sequence';
1.510 raeburn 3036: }
1.484 raeburn 3037:
1.525 raeburn 3038: my $jumpto;
3039:
3040: unless ($supplementalflag) {
1.546 raeburn 3041: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3042: }
1.484 raeburn 3043:
3044: unless ($allowed) {
3045: $randompick = -1;
3046: }
3047:
1.615 raeburn 3048: my ($errtext,$fatal);
3049: if (($folder eq '') && (!$supplementalflag)) {
3050: if (@LONCAPA::map::order) {
3051: undef(@LONCAPA::map::order);
3052: undef(@LONCAPA::map::resources);
3053: undef(@LONCAPA::map::resparms);
3054: undef(@LONCAPA::map::zombies);
3055: }
3056: $folder = 'default';
3057: $container = 'sequence';
3058: } else {
3059: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3060: $folder.'.'.$container);
3061: return $errtext if ($fatal);
3062: }
1.329 droeschl 3063:
3064: if ($#LONCAPA::map::order<1) {
3065: my $idx=&LONCAPA::map::getresidx();
3066: if ($idx<=0) { $idx=1; }
3067: $LONCAPA::map::order[0]=$idx;
3068: $LONCAPA::map::resources[$idx]='';
3069: }
1.364 bisitz 3070:
1.329 droeschl 3071: # ------------------------------------------------------------ Process commands
3072:
3073: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3074: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3075: # set parameters and change order
3076: &snapshotbefore();
3077:
3078: if (&update_parameter()) {
1.588 raeburn 3079: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3080: return $errtext if ($fatal);
3081: }
3082:
3083: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3084: # change order
3085: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3086: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3087:
3088: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3089: return $errtext if ($fatal);
3090: }
1.364 bisitz 3091:
1.329 droeschl 3092: if ($env{'form.pastemarked'}) {
1.491 raeburn 3093: my %paste_errors;
1.533 raeburn 3094: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3095: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3096: \%paste_errors);
1.541 raeburn 3097: if (ref($pastemsgarray) eq 'ARRAY') {
3098: if (@{$pastemsgarray} > 0) {
3099: $r->print('<p class="LC_info">'.
3100: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3101: '</p>');
3102: }
1.541 raeburn 3103: }
3104: if ($lockerror) {
3105: $r->print('<p class="LC_error">'.
3106: $lockerror.
3107: '</p>');
3108: }
3109: if ($save_error ne '') {
3110: return $save_error;
3111: }
3112: if ($paste_res) {
3113: my %errortext = &Apache::lonlocal::texthash (
3114: fail => 'Storage of folder contents failed',
3115: failread => 'Reading folder contents failed',
3116: failstore => 'Storage of folder contents failed',
3117: );
3118: if ($errortext{$paste_res}) {
3119: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3120: }
1.329 droeschl 3121: }
1.491 raeburn 3122: if (keys(%paste_errors) > 0) {
1.538 raeburn 3123: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3124: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
3125: '<ul>'."\n");
3126: foreach my $key (sort(keys(%paste_errors))) {
3127: $r->print('<li>'.$key.'</li>'."\n");
3128: }
3129: $r->print('</ul></p>'."\n");
3130: }
1.538 raeburn 3131: } elsif ($env{'form.clearmarked'}) {
3132: my $output = &do_buffer_empty();
3133: if ($output) {
3134: $r->print('<p class="LC_info">'.$output.'</p>');
3135: }
3136: }
1.329 droeschl 3137:
3138: $r->print($upload_output);
3139:
1.538 raeburn 3140: # Rename, cut, copy or remove a single resource
1.602 raeburn 3141: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3142: my $contentchg;
1.592 raeburn 3143: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 3144: $contentchg = 1;
3145: }
3146: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3147: return $errtext if ($fatal);
3148: }
1.538 raeburn 3149:
3150: # Cut, copy and/or remove multiple resources
3151: if ($env{'form.multichange'}) {
3152: my %allchecked = (
3153: cut => {},
3154: remove => {},
3155: );
3156: my $needsupdate;
3157: foreach my $which (keys(%allchecked)) {
3158: $env{'form.multi'.$which} =~ s/,$//;
3159: if ($env{'form.multi'.$which}) {
3160: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3161: if (ref($allchecked{$which}) eq 'HASH') {
3162: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3163: }
3164: }
3165: }
3166: if ($needsupdate) {
3167: my $haschanges = 0;
3168: my %curr_groups = &Apache::longroup::coursegroups();
3169: my $total = scalar(@LONCAPA::map::order) - 1;
3170: for (my $i=$total; $i>=0; $i--) {
3171: my $res = $LONCAPA::map::order[$i];
3172: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3173: $name=&LONCAPA::map::qtescape($name);
3174: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3175: next unless $url;
1.538 raeburn 3176: my %denied =
3177: &action_restrictions($coursenum,$coursedom,$url,
3178: $env{'form.folderpath'},\%curr_groups);
3179: foreach my $which (keys(%allchecked)) {
3180: next if ($denied{$which});
3181: next unless ($allchecked{$which}{$res});
3182: if ($which eq 'remove') {
3183: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3184: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3185: &Apache::lonnet::removeuploadedurl($url);
3186: } else {
3187: &LONCAPA::map::makezombie($res);
3188: }
3189: splice(@LONCAPA::map::order,$i,1);
3190: $haschanges ++;
3191: } elsif ($which eq 'cut') {
3192: &LONCAPA::map::makezombie($res);
3193: splice(@LONCAPA::map::order,$i,1);
3194: $haschanges ++;
3195: }
3196: }
3197: }
3198: if ($haschanges) {
3199: ($errtext,$fatal) =
3200: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3201: return $errtext if ($fatal);
3202: }
3203: }
3204: }
3205:
1.329 droeschl 3206: # Group import/search
3207: if ($env{'form.importdetail'}) {
3208: my @imports;
3209: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3210: if (defined($item)) {
3211: my ($name,$url,$residx)=
1.533 raeburn 3212: map { &unescape($_); } split(/\=/,$item);
3213: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3214: my ($suffix,$errortxt,$locknotfreed) =
3215: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3216: if ($locknotfreed) {
3217: $r->print($locknotfreed);
3218: }
3219: if ($suffix) {
3220: $url =~ s/_new\./_$suffix./;
3221: } else {
3222: return $errortxt;
3223: }
1.533 raeburn 3224: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3225: my $type = $1;
3226: my ($suffix,$errortxt,$locknotfreed) =
3227: &new_timebased_suffix($coursedom,$coursenum,$type);
3228: if ($locknotfreed) {
3229: $r->print($locknotfreed);
3230: }
3231: if ($suffix) {
3232: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3233: } else {
3234: return $errortxt;
3235: }
1.598 raeburn 3236: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
3237: my ($suffix,$errortxt,$locknotfreed) =
3238: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3239: if ($locknotfreed) {
3240: $r->print($locknotfreed);
3241: }
3242: if ($suffix) {
3243: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3244: } else {
3245: return $errortxt;
3246: }
1.534 raeburn 3247: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3248: if ($supplementalflag) {
3249: next unless ($1 eq 'supplemental');
3250: if ($folder eq 'supplemental') {
3251: next unless ($2 eq 'default');
3252: } else {
3253: next unless ($folder eq 'supplemental_'.$2);
3254: }
3255: } else {
3256: next unless ($1 eq 'docs');
3257: if ($folder eq 'default') {
3258: next unless ($2 eq 'default');
3259: } else {
3260: next unless ($folder eq 'default_'.$2);
3261: }
3262: }
1.504 raeburn 3263: }
1.329 droeschl 3264: push(@imports, [$name, $url, $residx]);
3265: }
3266: }
1.530 raeburn 3267: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3268: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3269: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3270: return $errtext if ($fatal);
1.529 raeburn 3271: if ($fixuperrors) {
3272: $r->print($fixuperrors);
3273: }
1.329 droeschl 3274: }
3275: # Loading a complete map
3276: if ($env{'form.loadmap'}) {
3277: if ($env{'form.importmap'}=~/\w/) {
3278: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3279: my ($title,$url,$ext,$type)=split(/\:/,$res);
3280: my $idx=&LONCAPA::map::getresidx($url);
3281: $LONCAPA::map::resources[$idx]=$res;
3282: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3283: }
3284: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3285: $folder.'.'.$container,1);
1.329 droeschl 3286: return $errtext if ($fatal);
3287: } else {
3288: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3289:
1.329 droeschl 3290: }
3291: }
3292: &log_differences($plain);
3293: }
3294: # ---------------------------------------------------------------- End commands
3295: # ---------------------------------------------------------------- Print screen
3296: my $idx=0;
3297: my $shown=0;
3298: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3299: $r->print('<div class="LC_Box">'.
1.432 raeburn 3300: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3301: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3302: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3303: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3304: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3305: '</ol>');
1.381 bisitz 3306: if ($randompick>=0) {
3307: $r->print('<p class="LC_warning">'
3308: .&mt('Caution: this folder is set to randomly pick a subset'
3309: .' of resources. Adding or removing resources from this'
3310: .' folder will change the set of resources that the'
3311: .' students see, resulting in spurious or missing credit'
3312: .' for completed problems, not limited to ones you'
3313: .' modify. Do not modify the contents of this folder if'
3314: .' it is in active student use.')
3315: .'</p>'
3316: );
3317: }
3318: if ($is_random_order) {
3319: $r->print('<p class="LC_warning">'
3320: .&mt('Caution: this folder is set to randomly order its'
3321: .' contents. Adding or removing resources from this folder'
3322: .' will change the order of resources shown.')
3323: .'</p>'
3324: );
3325: }
3326: $r->print('</div>');
1.364 bisitz 3327: }
1.381 bisitz 3328:
1.538 raeburn 3329: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3330: %filters = (
1.543 raeburn 3331: canremove => [],
3332: cancut => [],
3333: cancopy => [],
3334: hiddenresource => [],
3335: encrypturl => [],
3336: randomorder => [],
3337: randompick => [],
1.538 raeburn 3338: );
3339: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3340: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3341: foreach my $res (@LONCAPA::map::order) {
3342: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3343: $name=&LONCAPA::map::qtescape($name);
3344: $url=&LONCAPA::map::qtescape($url);
3345: unless ($name) { $name=(split(/\//,$url))[-1]; }
3346: unless ($name) { $idx++; next; }
1.537 raeburn 3347: push(@allidx,$res);
3348: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3349: push(@allmapidx,$res);
3350: }
1.617 raeburn 3351:
1.381 bisitz 3352: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3353: $coursenum,$coursedom,$crstype,
1.538 raeburn 3354: $pathitem,$supplementalflag,$container,
1.620 raeburn 3355: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3356: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3357: $idx++;
3358: $shown++;
1.329 droeschl 3359: }
1.424 onken 3360: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3361:
1.538 raeburn 3362: my $need_save;
1.611 raeburn 3363: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3364: my $toolslink;
1.611 raeburn 3365: if ($allowed) {
1.544 raeburn 3366: $toolslink = '<table><tr><td>'
1.520 raeburn 3367: .&Apache::loncommon::help_open_menu('Navigation Screen',
3368: 'Navigation_Screen',undef,'RAT')
3369: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3370: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3371: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3372: .'id="LC_content_toolbar_edittoplevel" '
3373: .'class="LC_toolbarItem" '
3374: .'title="'.&mt('Supplemental Content Editor').'">'
3375: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3376: }
1.510 raeburn 3377: if ($shown) {
3378: if ($allowed) {
3379: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3380: .&Apache::loncommon::start_data_table(undef,'contentlist')
3381: .&Apache::loncommon::start_data_table_header_row()
3382: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3383: .'<th colspan="2">'.&mt('Actions').'</th>'
3384: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3385: if ($folder !~ /^supplemental/) {
3386: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3387: }
1.537 raeburn 3388: $to_show .= &Apache::loncommon::end_data_table_header_row();
3389: if ($folder !~ /^supplemental/) {
1.538 raeburn 3390: $lists{'canhide'} = join(',',@allidx);
3391: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3392: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3393: 'randomorder','randompick');
3394: foreach my $item (@possfilters) {
1.538 raeburn 3395: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3396: if (@{$filters{$item}} > 0) {
3397: $lists{$item} = join(',',@{$filters{$item}});
3398: }
1.538 raeburn 3399: }
3400: }
1.537 raeburn 3401: if (@allidx > 0) {
3402: my $path;
3403: if ($env{'form.folderpath'}) {
3404: $path =
3405: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3406: }
1.538 raeburn 3407: if (@allidx > 1) {
3408: $to_show .=
3409: &Apache::loncommon::continue_data_table_row().
3410: '<td colspan="2"> </td>'.
3411: '<td>'.
1.611 raeburn 3412: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3413: '</td>'.
3414: '<td> </td>'.
3415: '<td> </td>'.
3416: '<td colspan="4">'.
1.611 raeburn 3417: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3418: '</td>'.
3419: &Apache::loncommon::end_data_table_row();
3420: $need_save = 1;
3421: }
1.537 raeburn 3422: }
3423: }
3424: $to_show .= $output.' '
1.510 raeburn 3425: .&Apache::loncommon::end_data_table()
3426: .'<br style="line-height:2px;" />'
3427: .&Apache::loncommon::end_scrollbox();
3428: } else {
1.520 raeburn 3429: $to_show .= $toolslink
1.510 raeburn 3430: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3431: .$output.' '
3432: .&Apache::loncommon::end_data_table();
1.393 raeburn 3433: }
1.510 raeburn 3434: } else {
1.520 raeburn 3435: if (!$allowed) {
3436: $to_show .= $toolslink;
3437: }
1.615 raeburn 3438: my $noresmsg;
3439: if ($allowed && $hiddentop && !$supplementalflag) {
3440: $noresmsg = &mt('Main Content Hidden');
3441: } else {
3442: $noresmsg = &mt('Currently empty');
3443: }
1.510 raeburn 3444: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3445: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3446: .$noresmsg
1.510 raeburn 3447: .'</div>'
3448: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3449: }
3450: } else {
1.510 raeburn 3451: if ($shown) {
3452: $to_show = '<div>'
3453: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3454: .$output
3455: .&Apache::loncommon::end_data_table()
3456: .'</div>';
3457: } else {
3458: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3459: .&mt('Currently empty')
1.510 raeburn 3460: .'</div>'
3461: }
1.458 raeburn 3462: }
3463: my $tid = 1;
3464: if ($supplementalflag) {
3465: $tid = 2;
1.329 droeschl 3466: }
3467: if ($allowed) {
1.484 raeburn 3468: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3469: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3470: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3471: if ($canedit) {
3472: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3473: }
1.460 raeburn 3474: } else {
3475: $r->print($to_show);
1.329 droeschl 3476: }
3477: return;
3478: }
3479:
1.538 raeburn 3480: sub multiple_check_form {
1.611 raeburn 3481: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3482: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3483: my $disabled;
3484: unless ($canedit) {
3485: $disabled = 'disabled="disabled"';
3486: }
1.538 raeburn 3487: my $output =
3488: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3489: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3490: '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick('."'$caller','0'".');" checked="checked" />'.&mt('one').'</label>'.(' 'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick('."'$caller','1'".');" />'.&mt('multiple').'</label></span><span id="more'.$caller.'" class="LC_nobreak LC_docs_ext_edit"></span></form>'.
3491: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3492: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3493: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3494: if ($caller eq 'settings') {
3495: $output .=
3496: '<table><tr>'.
3497: '<td class="LC_docs_entry_parameter">'.
3498: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3499: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3500: '</label></span></td>'.
3501: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3502: '<span class="LC_nobreak"><label><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');"'.$disabled.' />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
1.538 raeburn 3503: '</span></td>'.
3504: '</tr>'."\n".
3505: '<tr>'.
3506: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3507: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')"'.$disabled.' />'.&mt('URL hidden').'</label></span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><label><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')"'.$disabled.' />'.&mt('Random Order').
1.538 raeburn 3508: '</label></span>'.
3509: '</td></tr></table>'."\n";
3510: } else {
3511: $output .=
3512: '<table><tr>'.
3513: '<td class="LC_docs_entry_parameter">'.
3514: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3515: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3516: '</label></span></td>'.
3517: '<td class="LC_docs_entry_parameter">'.
3518: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3519: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3520: '</label></span></td>'."\n".
3521: '<td class="LC_docs_entry_parameter">'.
3522: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3523: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3524: '</label></span></td>'.
3525: '</tr></table>'."\n";
3526: }
3527: $output .=
3528: '</fieldset>'.
3529: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3530: if ($caller eq 'settings') {
3531: $output .=
1.543 raeburn 3532: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3533: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3534: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3535: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3536: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3537: } elsif ($caller eq 'actions') {
3538: $output .=
3539: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3540: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3541: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3542: }
3543: $output .=
3544: '</form>'.
3545: '</div>';
3546: return $output;
3547: }
3548:
1.329 droeschl 3549: sub process_file_upload {
1.552 raeburn 3550: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3551: # upload a file, if present
1.552 raeburn 3552: my $filesize = length($env{'form.uploaddoc'});
3553: if (!$filesize) {
3554: $$upload_output = '<div class="LC_error">'.
3555: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3556: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3557: $filesize).'<br />'.
3558: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3559: '</div>';
3560: return;
3561: }
3562: my $quotatype = 'unofficial';
3563: if ($crstype eq 'Community') {
1.601 raeburn 3564: $quotatype = 'community';
3565: } elsif ($crstype eq 'Placement') {
3566: $quotatype = 'placement';
1.580 raeburn 3567: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3568: $quotatype = 'official';
1.573 raeburn 3569: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3570: $quotatype = 'textbook';
1.552 raeburn 3571: }
3572: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3573: $filesize = int($filesize/1000); #expressed in kb
3574: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3575: $env{'form.uploaddoc.filename'},$filesize,
3576: 'upload',$quotatype);
1.552 raeburn 3577: return if ($$upload_output);
3578: }
1.440 raeburn 3579: my ($parseaction,$showupload,$nextphase,$mimetype);
3580: if ($env{'form.parserflag'}) {
1.329 droeschl 3581: $parseaction = 'parse';
3582: }
3583: my $folder=$env{'form.folder'};
3584: if ($folder eq '') {
3585: $folder='default';
3586: }
3587: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3588: my $errtext='';
3589: my $fatal=0;
3590: my $container='sequence';
1.519 raeburn 3591: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3592: $container='page';
3593: }
3594: ($errtext,$fatal)=
1.534 raeburn 3595: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3596: if ($#LONCAPA::map::order<1) {
3597: $LONCAPA::map::order[0]=1;
3598: $LONCAPA::map::resources[1]='';
3599: }
3600: my $destination = 'docs/';
3601: if ($folder =~ /^supplemental/) {
3602: $destination = 'supplemental/';
3603: }
3604: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3605: $destination .= 'default/';
3606: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3607: $destination .= $2.'/';
3608: }
1.534 raeburn 3609: if ($fatal) {
3610: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'</div>';
3611: return;
3612: }
1.440 raeburn 3613: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3614: my $newidx=&LONCAPA::map::getresidx();
3615: $destination .= $newidx;
1.439 raeburn 3616: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3617: $parseaction,$allfiles,
1.440 raeburn 3618: $codebase,undef,undef,undef,undef,
3619: undef,undef,\$mimetype);
3620: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3621: my $stored = $1;
3622: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3623: $stored.'</span>').'</p>';
3624: } else {
3625: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3626:
1.457 raeburn 3627: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3628: return;
3629: }
1.329 droeschl 3630: my $ext='false';
3631: if ($url=~m{^http://}) { $ext='true'; }
3632: $url = &LONCAPA::map::qtunescape($url);
3633: my $comment=$env{'form.comment'};
3634: $comment = &LONCAPA::map::qtunescape($comment);
3635: if ($folder=~/^supplemental/) {
3636: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3637: $env{'user.domain'}.'___&&&___'.$comment;
3638: }
3639:
3640: $LONCAPA::map::resources[$newidx]=
3641: $comment.':'.$url.':'.$ext.':normal:res';
3642: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3643: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3644: $folder.'.'.$container,1);
1.329 droeschl 3645: if ($fatal) {
1.457 raeburn 3646: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3647: return;
1.329 droeschl 3648: } else {
1.440 raeburn 3649: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3650: $$upload_output = $showupload;
1.384 raeburn 3651: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3652: if ($total_embedded > 0) {
1.440 raeburn 3653: my $uploadphase = 'upload_embedded';
3654: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3655: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3656: my ($embedded,$num) =
3657: &Apache::loncommon::ask_for_embedded_content(
3658: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3659: if ($embedded) {
3660: if ($num) {
3661: $$upload_output .=
3662: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3663: $nextphase = $uploadphase;
3664: } else {
3665: $$upload_output .= $embedded;
3666: }
3667: } else {
3668: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3669: }
1.329 droeschl 3670: } else {
1.440 raeburn 3671: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3672: }
1.457 raeburn 3673: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3674: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3675: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3676: $nextphase = 'decompress_uploaded';
3677: my $position = scalar(@LONCAPA::map::order)-1;
3678: my $noextract = &return_to_editor();
3679: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3680: my %archiveitems = (
3681: folderpath => $env{'form.folderpath'},
3682: cmd => $nextphase,
3683: newidx => $newidx,
3684: position => $position,
3685: phase => $nextphase,
1.477 raeburn 3686: comment => $comment,
1.480 raeburn 3687: );
3688: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3689: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3690: $$upload_output = $showupload.
3691: &Apache::loncommon::decompress_form($mimetype,
3692: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3693: \%archiveitems,\@current);
1.329 droeschl 3694: }
3695: }
3696: }
1.440 raeburn 3697: return $nextphase;
1.329 droeschl 3698: }
3699:
1.480 raeburn 3700: sub get_dir_list {
3701: my ($url,$coursenum,$coursedom,$newidx) = @_;
3702: my ($destination,$dir_root) = &embedded_destination();
3703: my ($dirlistref,$listerror) =
3704: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3705: my @dir_lines;
3706: my $dirptr=16384;
3707: if (ref($dirlistref) eq 'ARRAY') {
3708: foreach my $dir_line (sort
3709: {
3710: my ($afile)=split('&',$a,2);
3711: my ($bfile)=split('&',$b,2);
3712: return (lc($afile) cmp lc($bfile));
3713: } (@{$dirlistref})) {
3714: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3715: $filename =~ s/\s+$//;
3716: next if ($filename =~ /^\.\.?$/);
3717: my $isdir = 0;
3718: if ($dirptr&$testdir) {
3719: $isdir = 1;
3720: }
3721: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3722: }
3723: }
3724: return @dir_lines;
3725: }
3726:
1.329 droeschl 3727: sub is_supplemental_title {
3728: my ($title) = @_;
3729: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3730: }
3731:
3732: # --------------------------------------------------------------- An entry line
3733:
3734: sub entryline {
1.501 raeburn 3735: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3736: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3737: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3738: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3739: if (&is_supplemental_title($title)) {
1.488 raeburn 3740: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3741: } else {
3742: $title=&HTML::Entities::encode($title,'"<>&\'');
3743: $renametitle=$title;
3744: $foldertitle=$title;
3745: }
3746:
1.611 raeburn 3747: my ($disabled,$readonly,$js_lt);
3748: unless ($canedit) {
3749: $disabled = 'disabled="disabled"';
3750: $readonly = 1;
3751: }
3752:
1.329 droeschl 3753: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3754:
1.329 droeschl 3755: $renametitle=~s/\\/\\\\/g;
3756: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3757: $renametitle=~s/"/%22/g;
1.581 raeburn 3758: $renametitle=~s/ /%20/g;
3759: $oldtitle = $renametitle;
1.576 raeburn 3760: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3761: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3762: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3763: # Edit commands
1.535 raeburn 3764: my ($esc_path, $path, $symb);
1.329 droeschl 3765: if ($env{'form.folderpath'}) {
3766: $esc_path=&escape($env{'form.folderpath'});
3767: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3768: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3769: }
1.505 raeburn 3770: my $isexternal;
1.510 raeburn 3771: if ($residx) {
1.501 raeburn 3772: my $currurl = $url;
3773: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3774: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3775: $isexternal = 1;
3776: }
1.510 raeburn 3777: if (!$supplementalflag) {
3778: my $path = 'uploaded/'.
3779: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3780: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3781: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3782: $residx,
3783: &Apache::lonnet::declutter($currurl));
3784: }
1.501 raeburn 3785: }
1.538 raeburn 3786: my ($renamelink,%lt,$ishash);
3787: if (ref($filtersref) eq 'HASH') {
3788: $ishash = 1;
3789: }
3790:
1.329 droeschl 3791: if ($allowed) {
1.538 raeburn 3792: $form_start = '
3793: <form action="/adm/coursedocs" method="post">
3794: ';
3795: $form_common=(<<END);
3796: <input type="hidden" name="folderpath" value="$path" />
3797: <input type="hidden" name="symb" value="$symb" />
3798: END
3799: $form_param=(<<END);
3800: <input type="hidden" name="setparms" value="$orderidx" />
3801: <input type="hidden" name="changeparms" value="0" />
3802: END
3803: $form_end = '</form>';
3804:
1.329 droeschl 3805: my $incindex=$index+1;
3806: my $selectbox='';
1.471 raeburn 3807: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3808: ((split(/\:/,
1.344 bisitz 3809: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3810: ne '') &&
1.329 droeschl 3811: ((split(/\:/,
1.344 bisitz 3812: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3813: ne '')) {
3814: $selectbox=
3815: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3816: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3817: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3818: if ($i==$incindex) {
1.358 bisitz 3819: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3820: } else {
3821: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3822: }
3823: }
3824: $selectbox.='</select>';
3825: }
1.501 raeburn 3826: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3827: 'up' => 'Move Up',
3828: 'dw' => 'Move Down',
3829: 'rm' => 'Remove',
3830: 'ct' => 'Cut',
3831: 'rn' => 'Rename',
1.501 raeburn 3832: 'cp' => 'Copy',
3833: 'ex' => 'External Resource',
1.598 raeburn 3834: 'et' => 'External Tool',
1.501 raeburn 3835: 'ed' => 'Edit',
3836: 'pr' => 'Preview',
3837: 'sv' => 'Save',
3838: 'ul' => 'URL',
1.611 raeburn 3839: 'ti' => 'Title',
1.618 raeburn 3840: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3841: );
1.538 raeburn 3842: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3843: $env{'form.folderpath'},
3844: $currgroups);
1.517 raeburn 3845: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3846: my $skip_confirm = 0;
1.603 raeburn 3847: my $confirm_removal = 0;
1.329 droeschl 3848: if ( $folder =~ /^supplemental/
3849: || ($url =~ m{( /smppg$
3850: |/syllabus$
3851: |/aboutme$
3852: |/navmaps$
3853: |/bulletinboard$
1.625 ! raeburn 3854: |/exttool$
1.505 raeburn 3855: |\.html$)}x)
3856: || $isexternal) {
1.329 droeschl 3857: $skip_confirm = 1;
3858: }
1.603 raeburn 3859: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3860: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3861: $confirm_removal = 1;
3862: }
1.329 droeschl 3863:
1.538 raeburn 3864: if ($denied{'copy'}) {
1.543 raeburn 3865: $copylink=(<<ENDCOPY)
1.507 raeburn 3866: <span style="visibility: hidden;">$lt{'cp'}</span>
3867: ENDCOPY
3868: } else {
1.538 raeburn 3869: my $formname = 'edit_copy_'.$orderidx;
3870: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3871: $copylink=(<<ENDCOPY);
1.538 raeburn 3872: <form name="$formname" method="post" action="/adm/coursedocs">
3873: $form_common
1.611 raeburn 3874: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.538 raeburn 3875: $form_end
1.329 droeschl 3876: ENDCOPY
1.538 raeburn 3877: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3878: push(@{$filtersref->{'cancopy'}},$orderidx);
3879: }
1.329 droeschl 3880: }
1.538 raeburn 3881: if ($denied{'cut'}) {
1.507 raeburn 3882: $cutlink=(<<ENDCUT);
3883: <span style="visibility: hidden;">$lt{'ct'}</span>
3884: ENDCUT
3885: } else {
1.538 raeburn 3886: my $formname = 'edit_cut_'.$orderidx;
3887: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3888: $cutlink=(<<ENDCUT);
1.538 raeburn 3889: <form name="$formname" method="post" action="/adm/coursedocs">
3890: $form_common
1.542 raeburn 3891: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3892: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.538 raeburn 3893: $form_end
1.329 droeschl 3894: ENDCUT
1.538 raeburn 3895: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3896: push(@{$filtersref->{'cancut'}},$orderidx);
3897: }
1.329 droeschl 3898: }
1.538 raeburn 3899: if ($denied{'remove'}) {
1.507 raeburn 3900: $removelink=(<<ENDREM);
3901: <span style="visibility: hidden;">$lt{'rm'}</a>
3902: ENDREM
3903: } else {
1.538 raeburn 3904: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3905: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3906: $removelink=(<<ENDREM);
1.538 raeburn 3907: <form name="$formname" method="post" action="/adm/coursedocs">
3908: $form_common
1.542 raeburn 3909: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3910: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 3911: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.538 raeburn 3912: $form_end
1.497 raeburn 3913: ENDREM
1.538 raeburn 3914: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3915: push(@{$filtersref->{'canremove'}},$orderidx);
3916: }
1.497 raeburn 3917: }
1.551 raeburn 3918: $renamelink=(<<ENDREN);
1.581 raeburn 3919: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3920: ENDREN
1.611 raeburn 3921: my ($uplink,$downlink);
3922: if ($canedit) {
3923: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3924: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3925: } else {
3926: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3927: $downlink = $uplink;
3928: }
1.329 droeschl 3929: $line.=(<<END);
3930: <td>
1.379 bisitz 3931: <div class="LC_docs_entry_move">
1.611 raeburn 3932: <a href="$uplink">
1.501 raeburn 3933: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3934: </a>
3935: </div>
3936: <div class="LC_docs_entry_move">
1.611 raeburn 3937: <a href="$downlink">
1.501 raeburn 3938: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3939: </a>
3940: </div>
1.329 droeschl 3941: </td>
3942: <td>
3943: $form_start
1.538 raeburn 3944: $form_param
1.478 raeburn 3945: $form_common
1.329 droeschl 3946: $selectbox
3947: $form_end
3948: </td>
1.540 raeburn 3949: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3950: $removelink
1.329 droeschl 3951: $cutlink
3952: $copylink
3953: </td>
3954: END
3955: }
3956: # Figure out what kind of a resource this is
3957: my ($extension)=($url=~/\.(\w+)$/);
3958: my $uploaded=($url=~/^\/*uploaded\//);
3959: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3960: my $isfolder;
3961: my $ispage;
3962: my $containerarg;
1.615 raeburn 3963: my $folderurl;
1.329 droeschl 3964: if ($uploaded) {
1.472 raeburn 3965: if (($extension eq 'sequence') || ($extension eq 'page')) {
3966: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3967: $containerarg = $1;
1.472 raeburn 3968: if ($extension eq 'sequence') {
3969: $icon=$iconpath.'navmap.folder.closed.gif';
3970: $isfolder=1;
3971: } else {
3972: $icon=$iconpath.'page.gif';
3973: $ispage=1;
3974: }
1.615 raeburn 3975: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3976: if ($allowed) {
3977: $url='/adm/coursedocs?';
3978: } else {
3979: $url='/adm/supplemental?';
3980: }
1.329 droeschl 3981: } else {
3982: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3983: }
3984: }
1.364 bisitz 3985:
1.621 raeburn 3986: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3987: my $orig_url = $url;
1.340 raeburn 3988: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 3989: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 3990: if (!$supplementalflag && $residx && $symb) {
3991: if ((!$isfolder) && (!$ispage)) {
3992: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3993: $url=&Apache::lonnet::clutter($url);
3994: if ($url=~/^\/*uploaded\//) {
3995: $url=~/\.(\w+)$/;
3996: my $embstyle=&Apache::loncommon::fileembstyle($1);
3997: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3998: $url='/adm/wrapper'.$url;
3999: } elsif ($embstyle eq 'ssi') {
4000: #do nothing with these
4001: } elsif ($url!~/\.(sequence|page)$/) {
4002: $url='/adm/coursedocs/showdoc'.$url;
4003: }
1.623 raeburn 4004: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4005: my $wrapped = $1;
4006: my $exturl = $2;
4007: if ($wrapped eq '') {
4008: $url='/adm/wrapper'.$url;
4009: }
4010: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4011: $nomodal = 1;
4012: }
1.625 ! raeburn 4013: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttool$}) {
1.598 raeburn 4014: $url='/adm/wrapper'.$url;
1.621 raeburn 4015: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4016: if (($ENV{'SERVER_PORT'} == 443) &&
4017: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4018: $url .= '?usehttp=1';
4019: $nomodal = 1;
4020: }
1.598 raeburn 4021: }
1.501 raeburn 4022: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4023: my $shownsymb = $symb;
4024: if ($isexternal) {
4025: if ($url =~ /^([^#]+)#([^#]+)$/) {
4026: $url = $1;
4027: $anchor = $2;
4028: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4029: $shownsymb = $1.&escape('#').$anchor;
4030: }
4031: }
4032: }
1.617 raeburn 4033: unless ($env{'request.role.adv'}) {
4034: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4035: $url = '';
4036: }
4037: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4038: $url = '';
4039: $hiddenres = 1;
4040: }
4041: }
4042: if ($url ne '') {
4043: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4044: }
1.615 raeburn 4045: } elsif (!$env{'request.role.adv'}) {
4046: my $checkencrypt;
4047: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4048: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4049: $checkencrypt = 1;
1.620 raeburn 4050: } elsif (ref($navmapref)) {
1.615 raeburn 4051: unless (ref($$navmapref)) {
4052: $$navmapref = Apache::lonnavmaps::navmap->new();
4053: }
4054: if (ref($$navmapref)) {
4055: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4056: $checkencrypt = 1;
4057: }
4058: }
4059: }
4060: if ($checkencrypt) {
4061: my $shownsymb = &Apache::lonenc::encrypted($symb);
4062: my $shownurl = &Apache::lonenc::encrypted($url);
4063: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4064: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4065: if ($env{'request.enc'} ne '') {
4066: delete($env{'request.enc'});
4067: }
4068: } else {
4069: $url='';
1.613 raeburn 4070: }
1.612 raeburn 4071: } else {
4072: $url='';
4073: }
1.501 raeburn 4074: } else {
4075: $url='';
4076: }
1.329 droeschl 4077: }
1.621 raeburn 4078: } elsif ($supplementalflag) {
1.610 raeburn 4079: if ($isexternal) {
4080: if ($url =~ /^([^#]+)#([^#]+)$/) {
4081: $url = $1;
4082: $anchor = $2;
1.623 raeburn 4083: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4084: if ($hostname ne '') {
4085: $url = 'http://'.$hostname.$url;
4086: }
4087: $nomodal = 1;
4088: }
1.610 raeburn 4089: }
1.621 raeburn 4090: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4091: if (($ENV{'SERVER_PORT'} == 443) &&
4092: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.622 raeburn 4093: if ($hostname ne '') {
4094: $url = 'http://'.$hostname.$url;
4095: }
1.621 raeburn 4096: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4097: $nomodal = 1;
4098: }
1.610 raeburn 4099: }
1.329 droeschl 4100: }
1.615 raeburn 4101: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4102: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4103: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4104: my $foldername=&escape($foldertitle);
4105: my $folderpath=$env{'form.folderpath'};
4106: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4107: if (!$allowed && $supplementalflag) {
1.519 raeburn 4108: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4109: $url.='folderpath='.&escape($folderpath);
4110: } else {
1.617 raeburn 4111: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4112: 'parameter_randompick'))[0];
4113: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4114: 'parameter_randomorder'))[0]=~/^yes$/i);
4115: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4116: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4117: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4118: 'parameter_encrypturl'))[0]=~/^yes$/i);
4119: unless ($hiddenmap) {
1.620 raeburn 4120: if (ref($navmapref)) {
4121: unless (ref($$navmapref)) {
4122: $$navmapref = Apache::lonnavmaps::navmap->new();
4123: }
4124: if (ref($$navmapref)) {
4125: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4126: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4127: unless (@resources) {
4128: $hiddenmap = 1;
4129: unless ($env{'request.role.adv'}) {
4130: $url = '';
4131: $hiddenfolder = 1;
4132: }
1.617 raeburn 4133: }
1.615 raeburn 4134: }
4135: }
4136: }
4137: }
1.617 raeburn 4138: unless ($encryptmap) {
1.620 raeburn 4139: if ((ref($navmapref)) && (ref($$navmapref))) {
4140: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4141: $encryptmap = 1;
4142: }
1.617 raeburn 4143: }
4144: }
4145:
4146: # Append randompick number, hidden, and encrypted with ":" to foldername,
4147: # so it gets transferred between levels
4148: $folderpath.=$containerarg.'&'.$foldername.
4149: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4150: unless ($url eq '') {
1.612 raeburn 4151: $url.='folderpath='.&escape($folderpath);
4152: }
1.510 raeburn 4153: my $rpckchk;
4154: if ($rpicknum) {
4155: $rpckchk = ' checked="checked"';
1.543 raeburn 4156: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4157: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4158: }
1.510 raeburn 4159: }
1.537 raeburn 4160: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4161: $rand_pick_text =
1.478 raeburn 4162: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4163: $form_param."\n".
1.478 raeburn 4164: $form_common."\n".
1.611 raeburn 4165: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.$disabled.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
1.510 raeburn 4166: if ($rpicknum ne '') {
4167: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4168: }
1.537 raeburn 4169: $rand_pick_text .= '</span></span>'.
4170: $form_end;
1.543 raeburn 4171: my $ro_set;
1.617 raeburn 4172: if ($randorder) {
1.543 raeburn 4173: $ro_set = 'checked="checked"';
4174: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4175: push(@{$filtersref->{'randomorder'}},$orderidx);
4176: }
4177: }
1.564 raeburn 4178: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4179: $rand_order_text =
1.537 raeburn 4180: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4181: $form_param."\n".
1.537 raeburn 4182: $form_common."\n".
1.611 raeburn 4183: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.$disabled.' /> '.&mt('Random Order').' </label></span>'.
1.537 raeburn 4184: $form_end;
1.510 raeburn 4185: }
1.509 raeburn 4186: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4187: my $isexttool;
1.625 ! raeburn 4188: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttool$}) {
1.598 raeburn 4189: $url='/adm/wrapper'.$url;
4190: $isexttool = 1;
4191: }
1.510 raeburn 4192: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4193: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4194: if ($title) {
4195: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4196: }
1.598 raeburn 4197: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4198: $url .= '&idx='.$orderidx;
4199: }
1.610 raeburn 4200: if ($anchor ne '') {
4201: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4202: }
1.329 droeschl 4203: }
1.519 raeburn 4204: my ($tdalign,$tdwidth);
1.501 raeburn 4205: if ($allowed) {
4206: my $fileloc =
4207: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4208: if ($isexternal) {
1.518 raeburn 4209: ($editlink,$extresform) =
1.611 raeburn 4210: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4211: undef,undef,undef,undef,undef,undef,
4212: undef,$disabled);
1.625 ! raeburn 4213: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttool$}) {
1.598 raeburn 4214: ($editlink,$extresform) =
4215: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4216: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4217: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4218: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4219: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4220: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4221: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4222: my $suppanchor;
4223: if ($supplementalflag) {
4224: $suppanchor = $anchor;
4225: }
1.501 raeburn 4226: my $jscall =
4227: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4228: $switchserver,
1.503 raeburn 4229: $forceedit,
1.511 raeburn 4230: undef,$symb,
4231: &escape($env{'form.folderpath'}),
1.622 raeburn 4232: $renametitle,$hostname,
4233: '','',1,$suppanchor);
1.501 raeburn 4234: if ($jscall) {
1.518 raeburn 4235: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4236: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4237: }
4238: }
4239: }
1.519 raeburn 4240: $tdalign = ' align="right" valign="top"';
4241: $tdwidth = ' width="80%"';
1.329 droeschl 4242: }
1.408 raeburn 4243: my $reinit;
4244: if ($crstype eq 'Community') {
4245: $reinit = &mt('(re-initialize community to access)');
4246: } else {
4247: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4248: }
4249: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.621 raeburn 4250: my $link;
1.472 raeburn 4251: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4252: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4253: } elsif ($url) {
1.610 raeburn 4254: if ($anchor ne '') {
4255: if ($supplementalflag) {
4256: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4257: } else {
4258: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4259: }
4260: }
1.622 raeburn 4261: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4262: $link = 'http://'.$hostname.$url;
4263: } else {
4264: $link = $url;
4265: }
4266: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.621 raeburn 4267: (($anchor ne '')?$anchor:''));
4268: if ($nomodal) {
4269: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4270: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4271: } else {
4272: $line.=&Apache::loncommon::modal_link($link,
4273: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4274: }
1.469 www 4275: } else {
4276: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4277: }
1.519 raeburn 4278: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4279: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4280: $line.='<a href="'.$url.'">'.$title.'</a>';
4281: } elsif ($url) {
1.621 raeburn 4282: if ($nomodal) {
4283: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4284: $title.'</a>';
4285: } else {
4286: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4287: }
1.617 raeburn 4288: } elsif (($hiddenfolder) || ($hiddenres)) {
1.615 raeburn 4289: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
1.469 www 4290: } else {
4291: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4292: }
1.518 raeburn 4293: $line.="$extresform</td>";
1.478 raeburn 4294: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4295: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4296: if (($allowed) && ($folder!~/^supplemental/)) {
4297: my %lt=&Apache::lonlocal::texthash(
4298: 'hd' => 'Hidden',
4299: 'ec' => 'URL hidden');
1.543 raeburn 4300: my ($enctext,$hidtext);
4301: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4302: $enctext = ' checked="checked"';
4303: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4304: push(@{$filtersref->{'encrypturl'}},$orderidx);
4305: }
4306: }
4307: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4308: $hidtext = ' checked="checked"';
4309: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4310: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4311: }
4312: }
1.537 raeburn 4313: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4314: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4315: $line.=(<<ENDPARMS);
4316: <td class="LC_docs_entry_parameter">
1.537 raeburn 4317: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4318: $form_param
1.478 raeburn 4319: $form_common
1.611 raeburn 4320: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4321: $form_end
1.458 raeburn 4322: <br />
1.537 raeburn 4323: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4324: $form_param
1.478 raeburn 4325: $form_common
1.611 raeburn 4326: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4327: $form_end
4328: </td>
1.478 raeburn 4329: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4330: $rand_order_text</td>
1.329 droeschl 4331: ENDPARMS
4332: }
1.379 bisitz 4333: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4334: return $line;
4335: }
4336:
1.538 raeburn 4337: sub action_restrictions {
4338: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4339: my %denied = (
4340: cut => 0,
4341: copy => 0,
4342: remove => 0,
4343: );
4344: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4345: # no copy for published maps
4346: $denied{'copy'} = 1;
1.597 raeburn 4347: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4348: unless ($1 eq 'simpleproblem') {
4349: $denied{'copy'} = 1;
4350: }
4351: $denied{'cut'} = 1;
1.538 raeburn 4352: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4353: if ($folderpath =~ /^default&[^\&]+$/) {
4354: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4355: $denied{'remove'} = 1;
4356: }
4357: $denied{'cut'} = 1;
4358: $denied{'copy'} = 1;
4359: }
4360: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4361: my $group = $1;
4362: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4363: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4364: $denied{'remove'} = 1;
4365: }
4366: }
4367: $denied{'cut'} = 1;
4368: $denied{'copy'} = 1;
4369: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4370: my $group = $1;
4371: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4372: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4373: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4374: if (keys(%groupsettings) > 0) {
4375: $denied{'remove'} = 1;
4376: }
4377: $denied{'cut'} = 1;
4378: $denied{'copy'} = 1;
4379: }
4380: }
4381: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4382: my $group = $1;
4383: if ($url =~ /group_boards_\Q$group\E/) {
4384: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4385: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4386: if (keys(%groupsettings) > 0) {
4387: if (ref($groupsettings{'functions'}) eq 'HASH') {
4388: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4389: $denied{'remove'} = 1;
4390: }
4391: }
4392: }
4393: $denied{'cut'} = 1;
4394: $denied{'copy'} = 1;
4395: }
4396: }
4397: }
4398: return %denied;
4399: }
4400:
1.533 raeburn 4401: sub new_timebased_suffix {
1.538 raeburn 4402: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4403: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4404: if ($type eq 'paste') {
4405: $prefix = $type;
4406: $namespace = 'courseeditor';
1.587 raeburn 4407: $idtype = 'addcode';
1.538 raeburn 4408: } elsif ($type eq 'map') {
1.533 raeburn 4409: $prefix = 'docs';
4410: if ($area eq 'supplemental') {
4411: $prefix = 'supp';
4412: }
4413: $prefix .= $container;
4414: $namespace = 'uploadedmaps';
4415: } else {
4416: $prefix = $type;
4417: $namespace = 'templated';
1.504 raeburn 4418: }
4419: my ($suffix,$freedlock,$error) =
1.587 raeburn 4420: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4421: if (!$suffix) {
1.538 raeburn 4422: if ($type eq 'paste') {
4423: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4424: } elsif ($type eq 'map') {
1.533 raeburn 4425: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4426: } elsif ($type eq 'smppg') {
4427: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4428: } else {
1.565 bisitz 4429: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4430: }
1.504 raeburn 4431: if ($error) {
4432: $errtext .= '<br />'.$error;
4433: }
4434: }
4435: if ($freedlock ne 'ok') {
1.533 raeburn 4436: $locknotfreed =
4437: '<div class="LC_error">'.
4438: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4439: if ($type eq 'paste') {
1.591 raeburn 4440: if ($freedlock eq 'nolock') {
4441: $locknotfreed =
4442: '<div class="LC_error">'.
4443: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4444:
1.593 droeschl 4445: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4446: } else {
4447: $locknotfreed .=
4448: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4449: }
1.538 raeburn 4450: } elsif ($type eq 'map') {
1.591 raeburn 4451: $locknotfreed .=
4452: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4453: } elsif ($type eq 'smppg') {
4454: $locknotfreed .=
4455: &mt('This will prevent creation of additional simple pages in this course.');
4456: } else {
4457: $locknotfreed .=
1.565 bisitz 4458: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4459: }
1.538 raeburn 4460: unless ($type eq 'paste') {
4461: $locknotfreed .=
1.560 raeburn 4462: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4463: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4464: }
4465: $locknotfreed .= '</div>';
1.504 raeburn 4466: }
4467: return ($suffix,$errtext,$locknotfreed);
4468: }
4469:
1.329 droeschl 4470: =pod
4471:
4472: =item tiehash()
4473:
4474: tie the hash
4475:
4476: =cut
4477:
4478: sub tiehash {
4479: my ($mode)=@_;
4480: $hashtied=0;
4481: if ($env{'request.course.fn'}) {
4482: if ($mode eq 'write') {
4483: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4484: &GDBM_WRCREAT(),0640)) {
4485: $hashtied=2;
4486: }
4487: } else {
4488: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4489: &GDBM_READER(),0640)) {
4490: $hashtied=1;
4491: }
4492: }
1.364 bisitz 4493: }
1.329 droeschl 4494: }
4495:
4496: sub untiehash {
4497: if ($hashtied) { untie %hash; }
4498: $hashtied=0;
4499: return OK;
4500: }
4501:
4502:
4503:
4504:
4505: sub checkonthis {
4506: my ($r,$url,$level,$title)=@_;
4507: $url=&unescape($url);
4508: $alreadyseen{$url}=1;
4509: $r->rflush();
4510: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4511: $r->print("\n<br />");
4512: if ($level==0) {
4513: $r->print("<br />");
4514: }
4515: for (my $i=0;$i<=$level*5;$i++) {
4516: $r->print(' ');
4517: }
4518: $r->print('<a href="'.$url.'" target="cat">'.
4519: ($title?$title:$url).'</a> ');
4520: if ($url=~/^\/res\//) {
4521: my $result=&Apache::lonnet::repcopy(
4522: &Apache::lonnet::filelocation('',$url));
4523: if ($result eq 'ok') {
4524: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4525: $r->rflush();
4526: &Apache::lonnet::countacc($url);
4527: $url=~/\.(\w+)$/;
4528: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4529: $r->print('<br />');
4530: $r->rflush();
4531: for (my $i=0;$i<=$level*5;$i++) {
4532: $r->print(' ');
4533: }
4534: $r->print('- '.&mt('Rendering:').' ');
4535: my ($errorcount,$warningcount)=split(/:/,
4536: &Apache::lonnet::ssi_body($url,
4537: ('grade_target'=>'web',
4538: 'return_only_error_and_warning_counts' => 1)));
4539: if (($errorcount) ||
4540: ($warningcount)) {
4541: if ($errorcount) {
1.369 bisitz 4542: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4543: &mt('[quant,_1,error]',$errorcount).'</span>');
4544: }
4545: if ($warningcount) {
4546: $r->print('<span class="LC_warning">'.
4547: &mt('[quant,_1,warning]',$warningcount).'</span>');
4548: }
4549: } else {
4550: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4551: }
4552: $r->rflush();
4553: }
4554: my $dependencies=
4555: &Apache::lonnet::metadata($url,'dependencies');
4556: foreach my $dep (split(/\,/,$dependencies)) {
4557: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4558: &checkonthis($r,$dep,$level+1);
4559: }
4560: }
4561: } elsif ($result eq 'unavailable') {
4562: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4563: } elsif ($result eq 'not_found') {
4564: unless ($url=~/\$/) {
1.521 bisitz 4565: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4566: } else {
1.366 bisitz 4567: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4568: }
4569: } else {
4570: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4571: }
4572: }
4573: }
4574: }
4575:
4576:
4577:
4578: =pod
4579:
4580: =item list_symbs()
4581:
1.485 raeburn 4582: List Content Identifiers
1.329 droeschl 4583:
4584: =cut
4585:
4586: sub list_symbs {
4587: my ($r) = @_;
4588:
1.408 raeburn 4589: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4590: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4591: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4592: $r->print(&startContentScreen('tools'));
1.329 droeschl 4593: my $navmap = Apache::lonnavmaps::navmap->new();
4594: if (!defined($navmap)) {
4595: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4596: '<div class="LC_error">'.
4597: &mt('Unable to retrieve information about course contents').
4598: '</div>');
1.408 raeburn 4599: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4600: } else {
1.484 raeburn 4601: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4602: &Apache::loncommon::start_data_table().
4603: &Apache::loncommon::start_data_table_header_row().
4604: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4605: &Apache::loncommon::end_data_table_header_row()."\n");
4606: my $count;
1.329 droeschl 4607: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4608: $r->print(&Apache::loncommon::start_data_table_row().
4609: '<td>'.$res->compTitle().'</td>'.
4610: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4611: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4612: $count ++;
4613: }
4614: if (!$count) {
4615: $r->print(&Apache::loncommon::start_data_table_row().
4616: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4617: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4618: }
1.484 raeburn 4619: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4620: }
1.521 bisitz 4621: $r->print(&endContentScreen());
1.329 droeschl 4622: }
4623:
4624:
4625: sub verifycontent {
4626: my ($r) = @_;
1.408 raeburn 4627: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4628: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4629: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4630: $r->print(&startContentScreen('tools'));
4631: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4632: $hashtied=0;
4633: undef %alreadyseen;
4634: %alreadyseen=();
4635: &tiehash();
1.484 raeburn 4636:
1.329 droeschl 4637: foreach my $key (keys(%hash)) {
4638: if ($hash{$key}=~/\.(page|sequence)$/) {
4639: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4640: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4641: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4642: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4643: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4644: }
4645: }
4646: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4647: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4648: }
4649: }
4650: &untiehash();
1.442 www 4651: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4652: $r->print(&endContentScreen());
1.329 droeschl 4653: }
4654:
4655:
4656: sub devalidateversioncache {
4657: my $src=shift;
4658: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4659: &Apache::lonnet::clutter($src));
4660: }
4661:
4662: sub checkversions {
1.611 raeburn 4663: my ($r,$canedit) = @_;
1.408 raeburn 4664: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4665: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4666: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4667: $r->print(&startContentScreen('tools'));
1.442 www 4668:
1.329 droeschl 4669: my $header='';
4670: my $startsel='';
4671: my $monthsel='';
4672: my $weeksel='';
4673: my $daysel='';
4674: my $allsel='';
4675: my %changes=();
4676: my $starttime=0;
4677: my $haschanged=0;
4678: my %setversions=&Apache::lonnet::dump('resourceversions',
4679: $env{'course.'.$env{'request.course.id'}.'.domain'},
4680: $env{'course.'.$env{'request.course.id'}.'.num'});
4681:
4682: $hashtied=0;
4683: &tiehash();
1.611 raeburn 4684: if ($canedit) {
4685: my %newsetversions=();
4686: if ($env{'form.setmostrecent'}) {
4687: $haschanged=1;
4688: foreach my $key (keys(%hash)) {
4689: if ($key=~/^ids\_(\/res\/.+)$/) {
4690: $newsetversions{$1}='mostrecent';
4691: &devalidateversioncache($1);
4692: }
4693: }
4694: } elsif ($env{'form.setcurrent'}) {
4695: $haschanged=1;
4696: foreach my $key (keys(%hash)) {
4697: if ($key=~/^ids\_(\/res\/.+)$/) {
4698: my $getvers=&Apache::lonnet::getversion($1);
4699: if ($getvers>0) {
4700: $newsetversions{$1}=$getvers;
4701: &devalidateversioncache($1);
4702: }
4703: }
1.329 droeschl 4704: }
1.611 raeburn 4705: } elsif ($env{'form.setversions'}) {
4706: $haschanged=1;
4707: foreach my $key (keys(%env)) {
4708: if ($key=~/^form\.set_version_(.+)$/) {
4709: my $src=$1;
4710: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4711: $newsetversions{$src}=$env{$key};
4712: &devalidateversioncache($src);
4713: }
4714: }
1.329 droeschl 4715: }
1.611 raeburn 4716: }
4717: if ($haschanged) {
4718: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4719: $env{'course.'.$env{'request.course.id'}.'.domain'},
4720: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4721: $r->print(&Apache::loncommon::confirmwrapper(
4722: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4723: } else {
4724: $r->print(&Apache::loncommon::confirmwrapper(
4725: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4726: }
1.611 raeburn 4727: &mark_hash_old();
4728: }
4729: &changewarning($r,'');
1.329 droeschl 4730: }
4731: if ($env{'form.timerange'} eq 'all') {
4732: # show all documents
1.549 raeburn 4733: $header=&mt('All content in '.$crstype);
1.521 bisitz 4734: $allsel=' selected="selected"';
1.329 droeschl 4735: foreach my $key (keys(%hash)) {
4736: if ($key=~/^ids\_(\/res\/.+)$/) {
4737: my $src=$1;
4738: $changes{$src}=1;
4739: }
4740: }
4741: } else {
4742: # show documents which changed
4743: %changes=&Apache::lonnet::dump
4744: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4745: $env{'course.'.$env{'request.course.id'}.'.num'});
4746: my $firstkey=(keys(%changes))[0];
4747: unless ($firstkey=~/^error\:/) {
4748: unless ($env{'form.timerange'}) {
4749: $env{'form.timerange'}=604800;
4750: }
4751: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4752: .&mt('seconds');
4753: if ($env{'form.timerange'}==-1) {
4754: $seltext='since start of course';
1.521 bisitz 4755: $startsel=' selected="selected"';
1.329 droeschl 4756: $env{'form.timerange'}=time;
4757: }
4758: $starttime=time-$env{'form.timerange'};
4759: if ($env{'form.timerange'}==2592000) {
4760: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4761: $monthsel=' selected="selected"';
1.329 droeschl 4762: } elsif ($env{'form.timerange'}==604800) {
4763: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4764: $weeksel=' selected="selected"';
1.329 droeschl 4765: } elsif ($env{'form.timerange'}==86400) {
4766: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4767: $daysel=' selected="selected"';
1.329 droeschl 4768: }
4769: $header=&mt('Content changed').' '.$seltext;
4770: } else {
4771: $header=&mt('No content modifications yet.');
4772: }
4773: }
4774: %setversions=&Apache::lonnet::dump('resourceversions',
4775: $env{'course.'.$env{'request.course.id'}.'.domain'},
4776: $env{'course.'.$env{'request.course.id'}.'.num'});
4777: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4778: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4779: 'lm' => 'Version changes since last Month',
4780: 'lw' => 'Version changes since last Week',
4781: 'sy' => 'Version changes since Yesterday',
4782: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4783: 'cd' => 'Change display',
1.329 droeschl 4784: 'sd' => 'Display',
4785: 'fi' => 'File',
4786: 'md' => 'Modification Date',
4787: 'mr' => 'Most recently published Version',
1.408 raeburn 4788: 've' => 'Version used in '.$crstype,
4789: 'vu' => 'Set Version to be used in '.$crstype,
4790: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4791: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4792: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4793: 'di' => 'Differences',
1.484 raeburn 4794: 'save' => 'Save changes',
4795: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4796: 'act' => 'Actions');
1.611 raeburn 4797: my ($disabled,$readonly);
4798: unless ($canedit) {
4799: $disabled = 'disabled="disabled"';
4800: $readonly = 1;
4801: }
1.329 droeschl 4802: $r->print(<<ENDHEADERS);
1.484 raeburn 4803: <h4 class="LC_info">$header</h4>
1.329 droeschl 4804: <form action="/adm/coursedocs" method="post">
4805: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4806: <div class="LC_left_float">
1.479 golterma 4807: <fieldset>
1.484 raeburn 4808: <legend>$lt{'cd'}</legend>
1.329 droeschl 4809: <select name="timerange">
1.521 bisitz 4810: <option value='all'$allsel>$lt{'al'}</option>
4811: <option value="-1"$startsel>$lt{'st'}</option>
4812: <option value="2592000"$monthsel>$lt{'lm'}</option>
4813: <option value="604800"$weeksel>$lt{'lw'}</option>
4814: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4815: </select>
4816: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4817: </fieldset>
4818: </div>
4819: <div class="LC_left_float">
4820: <fieldset>
4821: <legend>$lt{'act'}</legend>
1.611 raeburn 4822: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4823: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4824: </fieldset>
4825: </div>
4826: <br clear="all" />
4827: <hr />
4828: <h4>$lt{'vers'}</h4>
1.329 droeschl 4829: ENDHEADERS
1.479 golterma 4830: #number of columns for version history
1.571 raeburn 4831: my %changedbytime;
4832: foreach my $key (keys(%changes)) {
4833: #excludes not versionable problems from resource version history:
4834: next if ($key =~ /^\/res\/lib\/templates/);
4835: my $chg;
4836: if ($env{'form.timerange'} eq 'all') {
4837: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4838: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4839: } else {
4840: $chg = $changes{$key};
4841: next if ($chg < $starttime);
4842: }
4843: push(@{$changedbytime{$chg}},$key);
4844: }
4845: if (keys(%changedbytime) == 0) {
4846: &untiehash();
4847: $r->print(&mt('No content changes in imported content in specified time frame').
4848: &endContentScreen());
4849: return;
4850: }
1.479 golterma 4851: $r->print(
1.611 raeburn 4852: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4853: &Apache::loncommon::start_data_table().
4854: &Apache::loncommon::start_data_table_header_row().
4855: '<th>'.&mt('Resources').'</th>'.
4856: "<th>$lt{'mr'}</th>".
4857: "<th>$lt{'ve'}</th>".
4858: "<th>$lt{'vu'}</th>".
4859: '<th>'.&mt('History').'</th>'.
4860: &Apache::loncommon::end_data_table_header_row()
4861: );
1.571 raeburn 4862: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4863: foreach my $key (sort(@{$changedbytime{$chg}})) {
4864: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4865: my $currentversion=&Apache::lonnet::getversion($key);
4866: if ($currentversion<0) {
4867: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4868: }
4869: my $linkurl=&Apache::lonnet::clutter($key);
4870: $r->print(
4871: &Apache::loncommon::start_data_table_row().
4872: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4873: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4874: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4875: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4876: '<td align="right">'
4877: );
4878: # Used in course
4879: my $usedversion=$hash{'version_'.$linkurl};
4880: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4881: if ($usedversion != $currentversion) {
1.479 golterma 4882: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4883: } else {
1.479 golterma 4884: $r->print($usedversion);
4885: }
1.329 droeschl 4886: } else {
1.521 bisitz 4887: $r->print($currentversion);
1.329 droeschl 4888: }
1.571 raeburn 4889: $r->print('</td><td title="'.$lt{'vu'}.'">');
4890: # Set version
4891: $r->print(&Apache::loncommon::select_form(
4892: $setversions{$linkurl},
4893: 'set_version_'.$linkurl,
4894: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4895: '' => '',
4896: 'mostrecent' => &mt('most recent'),
1.611 raeburn 4897: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 4898: my $lastold=1;
4899: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4900: my $url=$root.'.'.$prevvers.'.'.$extension;
4901: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4902: $lastold=$prevvers;
4903: }
4904: }
4905: $r->print('</td>');
4906: # List all available versions
4907: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4908: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4909: my $url=$root.'.'.$prevvers.'.'.$extension;
4910: $r->print(
4911: '<span class="LC_nobreak">'
4912: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4913: .&mt('Version [_1]',$prevvers).'</a>'
4914: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4915: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4916: .')');
4917: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4918: $r->print(
4919: ' <a href="/adm/diff?filename='.
4920: &Apache::lonnet::clutter($root.'.'.$extension).
4921: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4922: '" target="diffs">'.&mt('Diffs').'</a>');
4923: }
4924: $r->print('</span><br />');
1.329 droeschl 4925: }
1.571 raeburn 4926: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4927: }
1.329 droeschl 4928: }
1.521 bisitz 4929: $r->print(
4930: &Apache::loncommon::end_data_table().
1.611 raeburn 4931: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4932: '</form>'
4933: );
1.329 droeschl 4934:
4935: &untiehash();
1.521 bisitz 4936: $r->print(&endContentScreen());
1.571 raeburn 4937: return;
1.329 droeschl 4938: }
4939:
4940: sub mark_hash_old {
4941: my $retie_hash=0;
4942: if ($hashtied) {
4943: $retie_hash=1;
4944: &untiehash();
4945: }
4946: &tiehash('write');
4947: $hash{'old'}=1;
4948: &untiehash();
4949: if ($retie_hash) { &tiehash(); }
4950: }
4951:
4952: sub is_hash_old {
4953: my $untie_hash=0;
4954: if (!$hashtied) {
4955: $untie_hash=1;
4956: &tiehash();
4957: }
4958: my $return=$hash{'old'};
4959: if ($untie_hash) { &untiehash(); }
4960: return $return;
4961: }
4962:
4963: sub changewarning {
4964: my ($r,$postexec,$message,$url)=@_;
4965: if (!&is_hash_old()) { return; }
4966: my $pathvar='folderpath';
4967: my $path=&escape($env{'form.folderpath'});
4968: if (!defined($url)) {
4969: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4970: }
4971: my $course_type = &Apache::loncommon::course_type();
4972: if (!defined($message)) {
4973: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4974: }
4975: $r->print("\n\n".
1.372 bisitz 4976: '<script type="text/javascript">'."\n".
4977: '// <![CDATA['."\n".
4978: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4979: '// ]]>'."\n".
1.369 bisitz 4980: '</script>'."\n".
1.375 tempelho 4981: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4982: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4983: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4984: &mt($message,' <input type="hidden" name="'.
4985: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4986: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4987: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4988: }
4989:
4990:
4991: sub init_breadcrumbs {
1.571 raeburn 4992: my ($form,$text,$help)=@_;
1.329 droeschl 4993: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4994: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4995: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4996: faq=>273,
4997: bug=>'Instructor Interface',
1.571 raeburn 4998: help => $help});
1.329 droeschl 4999: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5000: text=>$text,
5001: faq=>273,
5002: bug=>'Instructor Interface'});
5003: }
5004:
1.441 www 5005: # subroutine to list form elements
5006: sub create_list_elements {
5007: my @formarr = @_;
5008: my $list = '';
1.501 raeburn 5009: foreach my $button (@formarr){
5010: foreach my $picture (keys(%{$button})) {
5011: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5012: }
5013: }
5014: return $list;
5015: }
1.329 droeschl 5016:
1.441 www 5017: # subroutine to create ul from list elements
5018: sub create_form_ul {
5019: my $list = shift;
5020: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5021: return $ul;
5022: }
1.329 droeschl 5023:
1.442 www 5024: #
5025: # Start tabs
5026: #
5027:
5028: sub startContentScreen {
1.484 raeburn 5029: my ($mode) = @_;
5030: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5031: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5032: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5033: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5034: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5035: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5036: } else {
1.549 raeburn 5037: $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 5038: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5039: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5040: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5041: }
5042: $output .= "\n".'</ul>'."\n";
5043: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5044: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5045: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5046: return $output;
1.442 www 5047: }
5048:
5049: #
5050: # End tabs
5051: #
5052:
5053: sub endContentScreen {
1.484 raeburn 5054: return '</div></div></div>';
1.442 www 5055: }
1.329 droeschl 5056:
1.446 www 5057: sub supplemental_base {
1.548 raeburn 5058: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5059: }
5060:
1.329 droeschl 5061: sub handler {
5062: my $r = shift;
5063: &Apache::loncommon::content_type($r,'text/html');
5064: $r->send_http_header;
5065: return OK if $r->header_only;
1.484 raeburn 5066:
5067: # get course data
1.408 raeburn 5068: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5069: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5070: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5071:
1.606 raeburn 5072: # get docroot
5073: my $londocroot = $r->dir_config('lonDocRoot');
5074:
1.484 raeburn 5075: # graphics settings
5076: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5077:
1.443 www 5078: #
1.329 droeschl 5079: # --------------------------------------------- Initialize help topics for this
5080: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5081: 'Adding_External_Resource','Navigate_Content',
5082: 'Adding_Folders','Docs_Overview', 'Load_Map',
5083: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 5084: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.571 raeburn 5085: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
1.572 raeburn 5086: 'Dropbox','Simple_Problem') {
1.329 droeschl 5087: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5088: }
5089: # Composite help files
5090: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5091: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5092: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5093: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5094: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5095: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5096: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5097: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5098: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5099: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5100:
1.611 raeburn 5101: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5102: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5103: unless ($r->uri eq '/adm/supplemental') {
5104: # does this user have privileges to modify content.
1.611 raeburn 5105: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5106: $allowed = 1;
5107: $canedit = 1;
5108: $canview = 1;
5109: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5110: $allowed = 1;
5111: $canview = 1;
5112: }
5113: }
5114: unless ($canedit) {
5115: $disabled = ' disabled="disabled"';
1.472 raeburn 5116: }
1.582 raeburn 5117: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5118: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5119: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 5120: &verifycontent($r);
5121: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5122: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5123: &list_symbs($r);
5124: } elsif ($allowed && $env{'form.docslog'}) {
5125: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5126: my $folder = $env{'form.folder'};
5127: if ($folder eq '') {
5128: $folder='default';
5129: }
1.611 raeburn 5130: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5131: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5132: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5133: &checkversions($r,$canedit);
5134: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5135: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5136: &dumpcourse($r);
1.611 raeburn 5137: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5138: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5139: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5140: } else {
1.611 raeburn 5141: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5142: $noendpage = 1;
5143: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5144: if ($redirect) {
5145: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5146: my $container = 'sequence';
5147: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5148: $is_random_order,$container) =
5149: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5150: my (@folders)=split('&',$env{'form.folderpath'});
5151: $env{'form.foldername'}=&unescape(pop(@folders));
5152: my $folder=pop(@folders);
5153: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5154: $folder.'.'.$container);
5155: my $warning;
5156: if ($fatal) {
5157: if ($container eq 'page') {
5158: $warning = &mt('An error occurred retrieving the contents of the current page.');
5159: } else {
5160: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5161: }
5162: } else {
5163: my $url = $redirect;
5164: my $srcfile = $londocroot.$url;
5165: $url =~ s{^/priv/}{/res/};
5166: my $targetfile = $londocroot.$url;
5167: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5168: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5169: $env{'form.folder'} = $folder;
5170: &snapshotbefore();
5171: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5172: my $ext = 'false';
5173: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5174: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5175: ':'.$ext.':normal:res';
5176: push(@LONCAPA::map::order,$newidx);
5177: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5178: 'string_yesno');
5179: &remember_parms($newidx,'hiddenresource','set','yes');
5180: ($errtext,$fatal) =
5181: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5182: &log_differences($plain);
5183: &mark_hash_old();
5184: $r->internal_redirect($redirect);
5185: return OK;
5186: }
5187: }
5188: }
5189: }
1.445 www 5190: #
5191: # Done catching special calls
1.484 raeburn 5192: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5193: # Get the parameters that may be needed
5194: #
5195: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5196: ['folderpath',
5197: 'forcesupplement','forcestandard',
1.510 raeburn 5198: 'tools','symb','command','supppath']);
1.445 www 5199:
5200: # standard=1: this is a "new-style" course with an uploaded map as top level
5201: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5202:
5203: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5204:
1.484 raeburn 5205: # Decide whether this should display supplemental or main content or utilities
1.445 www 5206: # supplementalflag=1: show supplemental documents
5207: # supplementalflag=0: show standard documents
1.484 raeburn 5208: # toolsflag=1: show utilities
1.445 www 5209:
1.561 raeburn 5210: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5211: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5212: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5213: $supplementalflag=0;
5214: }
5215: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5216: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5217: unless ($allowed) { $supplementalflag=1; }
5218: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5219: my $toolsflag=0;
5220: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5221:
1.329 droeschl 5222: my $script='';
5223: my $showdoc=0;
1.457 raeburn 5224: my $addentries = {};
1.475 raeburn 5225: my $container;
1.329 droeschl 5226: my $containertag;
1.508 raeburn 5227: my $pathitem;
1.598 raeburn 5228: my %ltitools;
1.617 raeburn 5229: my $hiddentop;
1.615 raeburn 5230: my $navmap;
1.617 raeburn 5231: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5232:
1.464 www 5233: # Do we directly jump somewhere?
1.525 raeburn 5234: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5235: if ($env{'form.symb'} ne '') {
1.522 raeburn 5236: $env{'form.folderpath'}=
1.617 raeburn 5237: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5238: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5239: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5240: } elsif ($env{'form.supppath'} ne '') {
5241: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5242: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5243: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5244: }
1.472 raeburn 5245: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5246: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5247: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5248: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5249: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5250: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5251: } elsif ($env{'form.command'} eq 'contents') {
5252: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5253: } elsif ($env{'form.command'} eq 'home') {
5254: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5255: }
5256:
1.525 raeburn 5257:
1.445 www 5258: # Where do we store these for when we come back?
5259: my $stored_folderpath='docs_folderpath';
5260: if ($supplementalflag) {
5261: $stored_folderpath='docs_sup_folderpath';
5262: }
1.464 www 5263:
1.519 raeburn 5264: # No folderpath, and in edit mode, see if we have something stored
5265: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5266: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5267: {'folderpath' => 'scalar'});
1.615 raeburn 5268:
5269: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5270: if ($supplementalflag) {
5271: undef($env{'form.folderpath'}) if ($1 eq 'default');
5272: } else {
5273: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5274: }
5275: } else {
1.523 raeburn 5276: undef($env{'form.folderpath'});
5277: }
1.329 droeschl 5278: }
1.446 www 5279:
5280: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5281: if (!$allowed) {
1.446 www 5282: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5283: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5284: }
5285: }
1.446 www 5286: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5287: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5288: $env{'form.folderpath'} = &supplemental_base()
5289: .'&'.
1.329 droeschl 5290: $env{'form.folderpath'};
5291: }
1.615 raeburn 5292: # If allowed and user's role is not advanced check folderpath is not hidden
5293: if (($allowed) && (!$env{'request.role.adv'}) &&
5294: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5295: my $folderurl;
5296: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5297: my $folder = $pathitems[-2];
5298: if ($folder eq '') {
5299: undef($env{'form.folderpath'});
5300: } else {
5301: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5302: if ((split(/\:/,$pathitems[-1]))[4]) {
5303: $folderurl .= '.page';
5304: } else {
5305: $folderurl .= '.sequence';
5306: }
1.617 raeburn 5307: unless (ref($navmap)) {
5308: $navmap = Apache::lonnavmaps::navmap->new();
5309: }
1.615 raeburn 5310: if (ref($navmap)) {
5311: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5312: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5313: unless (@resources) {
5314: undef($env{'form.folderpath'});
5315: }
1.615 raeburn 5316: }
5317: }
5318: }
5319: }
5320:
5321:
1.446 www 5322: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5323: unless ($env{'form.folderpath'}) {
1.446 www 5324: if ($supplementalflag) {
5325: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5326: } elsif ($allowed) {
5327: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5328: }
1.472 raeburn 5329: }
1.446 www 5330:
1.445 www 5331: # Store this
1.484 raeburn 5332: unless ($toolsflag) {
1.615 raeburn 5333: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5334: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5335: {'folderpath' => 'scalar'});
1.510 raeburn 5336: }
1.519 raeburn 5337: my $folderpath;
1.484 raeburn 5338: if ($env{'form.folderpath'}) {
1.519 raeburn 5339: $folderpath = $env{'form.folderpath'};
5340: my (@folders)=split('&',$env{'form.folderpath'});
5341: $env{'form.foldername'}=&unescape(pop(@folders));
5342: if ($env{'form.foldername'} =~ /\:1$/) {
5343: $container = 'page';
5344: } else {
5345: $container = 'sequence';
5346: }
5347: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5348: } else {
1.519 raeburn 5349: if ($env{'form.folder'} eq '' ||
5350: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5351: if ($env{'form.folder'} eq 'supplemental') {
5352: $folderpath=&supplemental_base();
5353: } elsif (!$hiddentop) {
5354: $folderpath='default&'.
5355: &escape(&mt('Main Content').':::::');
5356: }
1.484 raeburn 5357: }
5358: }
1.519 raeburn 5359: $containertag = '<input type="hidden" name="folderpath" value="" />';
5360: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5361: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5362: $showdoc='/'.$1;
5363: }
5364: if ($showdoc) { # got called in sequence from course
5365: $allowed=0;
5366: } else {
1.611 raeburn 5367: if ($canedit) {
1.484 raeburn 5368: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5369: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5370: }
5371: }
1.329 droeschl 5372: }
5373:
1.344 bisitz 5374: # get personal data
1.329 droeschl 5375: my $uname=$env{'user.name'};
5376: my $udom=$env{'user.domain'};
5377: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5378:
5379: if ($allowed) {
1.484 raeburn 5380: if ($toolsflag) {
5381: $script .= &inject_data_js();
5382: my ($home,$other,%outhash)=&authorhosts();
5383: if (!$home && $other) {
5384: my @hosts;
5385: foreach my $aurole (keys(%outhash)) {
5386: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5387: push(@hosts,$outhash{$aurole});
5388: }
5389: }
5390: $script .= &dump_switchserver_js(@hosts);
5391: }
1.458 raeburn 5392: } else {
1.570 raeburn 5393: my $tid = 1;
1.484 raeburn 5394: my @tabids;
5395: if ($supplementalflag) {
5396: @tabids = ('002','ee2','ff2');
1.570 raeburn 5397: $tid = 2;
1.484 raeburn 5398: } else {
5399: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5400: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5401: unshift(@tabids,'001');
5402: push(@tabids,('dd1','ee1'));
5403: }
1.458 raeburn 5404: }
1.484 raeburn 5405: my $tabidstr = join("','",@tabids);
1.598 raeburn 5406: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5407: my $posslti = keys(%ltitools);
1.622 raeburn 5408: my $hostname = $r->hostname();
1.606 raeburn 5409: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5410: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5411: &history_tab_js().
5412: &inject_data_js().
1.570 raeburn 5413: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5414: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5415: $addentries = {
1.485 raeburn 5416: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5417: };
1.458 raeburn 5418: }
1.538 raeburn 5419: $script .= &paste_popup_js();
1.501 raeburn 5420: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5421: &mt('Switch server?');
5422:
5423:
1.329 droeschl 5424: }
5425: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5426: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5427: .'// <![CDATA['."\n"
5428: .$script."\n"
5429: .'// ]]>'."\n"
1.595 musolffc 5430: .'</script>'."\n"
5431: .'<script type="text/javascript"
5432: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5433:
5434: # Breadcrumbs
5435: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5436:
5437: if ($showdoc) {
5438: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5439: {'force_register' => $showdoc,}));
1.571 raeburn 5440: } elsif ($toolsflag) {
1.611 raeburn 5441: my ($breadtext,$breadtitle);
1.617 raeburn 5442: $breadtext = "$crstype Editor";
1.611 raeburn 5443: if ($canedit) {
5444: $breadtitle = 'Editing '.$crstype.' Contents';
5445: } else {
5446: $breadtext .= ' (View-only mode)';
5447: $breadtitle = 'Viewing '.$crstype.' Contents';
5448: }
1.571 raeburn 5449: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5450: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5451: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5452: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5453: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5454: $breadtitle)
1.571 raeburn 5455: );
1.510 raeburn 5456: } elsif ($r->uri eq '/adm/supplemental') {
5457: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5458: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5459: {'bread_crumbs' => $brcrum,}));
5460: } else {
1.611 raeburn 5461: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5462: $breadtext = "$crstype Editor";
1.611 raeburn 5463: if ($canedit) {
5464: $breadtitle = 'Editing '.$crstype.' Contents';
5465: $helpitem = 'Docs_Adding_Course_Doc';
5466: } else {
5467: $breadtext .= ' (View-only mode)';
5468: $breadtitle = 'Viewing '.$crstype.' Contents';
5469: $helpitem = 'Docs_Viewing_Course_Doc';
5470: }
1.392 raeburn 5471: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5472: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5473: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5474: {'add_entries' => $addentries}
5475: )
1.392 raeburn 5476: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5477: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5478: $breadtitle,
5479: $helpitem)
1.392 raeburn 5480: );
5481: }
1.364 bisitz 5482:
1.329 droeschl 5483: my %allfiles = ();
5484: my %codebase = ();
1.440 raeburn 5485: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5486: if ($canedit) {
1.329 droeschl 5487: if (($env{'form.uploaddoc.filename'}) &&
5488: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5489: my $context = $1;
5490: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5491: undef($hadchanges);
1.440 raeburn 5492: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5493: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5494: if ($hadchanges) {
5495: &mark_hash_old();
5496: }
1.440 raeburn 5497: $r->print($upload_output);
5498: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5499: # Process file upload - phase two - upload embedded objects
5500: $uploadphase = 'check_embedded';
5501: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5502: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5503: $env{'form.newidx'});
5504: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5505: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5506: my ($destination,$dir_root) = &embedded_destination();
5507: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5508: my $actionurl = '/adm/coursedocs';
5509: my ($result,$flag) =
5510: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5511: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5512: $actionurl);
5513: $r->print($result.&return_to_editor());
5514: } elsif ($env{'form.phase'} eq 'check_embedded') {
5515: # Process file upload - phase three - modify references in HTML file
5516: $uploadphase = 'modified_orightml';
5517: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5518: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5519: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5520: my $result =
5521: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5522: $docuname,$docudom,undef,
5523: $dir_root);
5524: $r->print($result.&return_to_editor());
1.476 raeburn 5525: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5526: $uploadphase = 'decompress_phase_one';
5527: $r->print(&decompression_phase_one().
5528: &return_to_editor());
5529: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5530: $uploadphase = 'decompress_phase_two';
5531: $r->print(&decompression_phase_two().
5532: &return_to_editor());
1.329 droeschl 5533: }
5534: }
5535:
1.484 raeburn 5536: if ($allowed && $toolsflag) {
5537: $r->print(&startContentScreen('tools'));
1.611 raeburn 5538: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5539: $r->print(&endContentScreen());
5540: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5541: # -----------------------------------------------------------------------------
5542: my %lt=&Apache::lonlocal::texthash(
5543: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5544: 'upfi' => 'Upload File',
1.553 raeburn 5545: 'upld' => 'Upload Content',
1.329 droeschl 5546: 'srch' => 'Search',
5547: 'impo' => 'Import',
1.487 raeburn 5548: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5549: 'impm' => 'Import from Assembled Map',
1.606 raeburn 5550: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5551: 'extr' => 'External Resource',
5552: 'extt' => 'External Tool',
1.329 droeschl 5553: 'selm' => 'Select Map',
5554: 'load' => 'Load Map',
5555: 'newf' => 'New Folder',
5556: 'newp' => 'New Composite Page',
5557: 'syll' => 'Syllabus',
1.425 raeburn 5558: 'navc' => 'Table of Contents',
1.343 biermanm 5559: 'sipa' => 'Simple Course Page',
1.329 droeschl 5560: 'sipr' => 'Simple Problem',
1.534 raeburn 5561: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5562: 'stpr' => 'Standard Problem',
5563: 'news' => 'New sub-directory',
5564: 'crpr' => 'Create Problem',
1.329 droeschl 5565: 'drbx' => 'Drop Box',
1.451 www 5566: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5567: 'bull' => 'Discussion Board',
1.347 weissno 5568: 'mypi' => 'My Personal Information Page',
1.353 weissno 5569: 'grpo' => 'Group Portfolio',
1.329 droeschl 5570: 'rost' => 'Course Roster',
1.528 raeburn 5571: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5572: 'imsf' => 'IMS Upload',
5573: 'imsl' => 'Upload IMS package',
1.501 raeburn 5574: 'cms' => 'Origin of IMS package',
5575: 'se' => 'Select',
1.329 droeschl 5576: 'file' => 'File',
5577: 'title' => 'Title',
1.606 raeburn 5578: 'addp' => 'Add Placeholder to course?',
5579: 'uste' => 'Use Template?',
5580: 'fnam' => 'File Name:',
5581: 'loca' => 'Location:',
5582: 'dire' => 'Directory:',
5583: 'cate' => 'Category:',
5584: 'tmpl' => 'Template:',
1.329 droeschl 5585: 'comment' => 'Comment',
1.403 raeburn 5586: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5587: 'bb5' => 'Blackboard 5',
5588: 'bb6' => 'Blackboard 6',
5589: 'angel5' => 'ANGEL 5.5',
5590: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5591: 'yes' => 'Yes',
5592: 'no' => 'No',
1.618 raeburn 5593: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5594: );
1.329 droeschl 5595: # -----------------------------------------------------------------------------
1.595 musolffc 5596:
5597: # Calculate free quota space for a user or course. A javascript function checks
5598: # file size to determine if upload should be allowed.
5599: my $quotatype = 'unofficial';
5600: if ($crstype eq 'Community') {
1.601 raeburn 5601: $quotatype = 'community';
5602: } elsif ($crstype eq 'Placement') {
5603: $quotatype = 'placement';
1.595 musolffc 5604: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5605: $quotatype = 'official';
5606: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5607: $quotatype = 'textbook';
5608: }
5609: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5610: 'course',$quotatype); # expressed in MB
5611: my $current_disk_usage = 0;
5612: foreach my $subdir ('docs','supplemental') {
5613: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5614: "userfiles/$subdir",1); # expressed in kB
5615: }
5616: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5617: my $usage = $current_disk_usage/1024; # in MB
5618: my $quota = $disk_quota;
5619: my $percent;
5620: if ($disk_quota == 0) {
5621: $percent = 100.0;
5622: } else {
1.619 raeburn 5623: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5624: }
5625: $usage = sprintf("%.2f",$usage);
5626: $quota = sprintf("%.2f",$quota);
5627: $percent = sprintf("%.0f",$percent);
5628: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5629: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5630:
1.329 droeschl 5631: my $fileupload=(<<FIUP);
1.605 raeburn 5632: $quotainfo
1.329 droeschl 5633: $lt{'file'}:<br />
1.611 raeburn 5634: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5635: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5636: FIUP
5637:
5638: my $checkbox=(<<CHBO);
5639: <!-- <label>$lt{'parse'}?
5640: <input type="checkbox" name="parserflag" />
5641: </label> -->
5642: <label>
1.611 raeburn 5643: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5644: </label>
5645: CHBO
1.501 raeburn 5646: my $imsfolder = $env{'form.folder'};
5647: if ($imsfolder eq '') {
5648: $imsfolder = 'default';
5649: }
5650: my $imspform=(<<IMSFORM);
5651: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5652: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5653: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5654: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5655: <legend>$lt{'imsf'}</legend>
5656: $fileupload
5657: <br />
5658: <p>
5659: $lt{'cms'}:
1.611 raeburn 5660: <select name="source" $disabled>
1.501 raeburn 5661: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5662: <option value="bb5">$lt{'bb5'}</option>
5663: <option value="bb6">$lt{'bb6'}</option>
5664: <option value="angel5">$lt{'angel5'}</option>
5665: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5666: </select>
5667: <input type="hidden" name="folder" value="$imsfolder" />
5668: </p>
5669: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5670: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5671: </fieldset>
5672: </form>
5673: IMSFORM
1.329 droeschl 5674:
5675: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5676: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5677: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5678: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5679: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5680: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5681: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5682: $fileupload
1.329 droeschl 5683: <br />
5684: $lt{'title'}:<br />
1.611 raeburn 5685: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5686: $pathitem
1.329 droeschl 5687: <input type="hidden" name="cmd" value="upload_default" />
5688: <br />
1.458 raeburn 5689: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5690: $checkbox
5691: </span>
1.501 raeburn 5692: <br clear="all" />
1.611 raeburn 5693: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5694: </fieldset>
5695: </form>
1.383 tempelho 5696: FUFORM
1.329 droeschl 5697:
1.611 raeburn 5698: my $mapimportjs;
5699: if ($canedit) {
5700: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5701: } else {
5702: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5703: }
1.502 raeburn 5704: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5705: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5706: $lt{'impm'}</a>$help{'Load_Map'}
5707: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5708: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5709: <legend>$lt{'impm'}</legend>
1.371 tempelho 5710: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5711: $lt{'copm'}<br />
5712: <span class="LC_nobreak">
5713: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5714: onfocus="this.blur();$mapimportjs" $disabled />
5715: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5716: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5717: </fieldset>
5718: </form>
5719:
1.383 tempelho 5720: SEDFFORM
1.606 raeburn 5721: my $importcrsresform;
1.608 raeburn 5722: my ($numdirs,$pickfile) =
5723: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5724: "resize_scrollbox('contentscroll','1','0');",
5725: undef,'res');
1.606 raeburn 5726: if ($pickfile) {
5727: $importcrsresform=(<<CRSFORM);
5728: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5729: $lt{'imcr'}</a>$help{'Course_Resources'}
5730: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5731: <fieldset id="importcrsresform" style="display: none;">
5732: <legend>$lt{'imcr'}</legend>
5733: <input type="hidden" name="active" value="bb" />
5734: $pickfile
5735: <p>
1.611 raeburn 5736: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5737: </p>
5738: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5739: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5740: </fieldset>
5741: </form>
5742: CRSFORM
5743: }
5744:
1.611 raeburn 5745: my $fromstoredjs;
5746: if ($canedit) {
5747: $fromstoredjs = 'open_StoredLinks_Import()';
5748: } else {
5749: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5750: }
5751:
1.502 raeburn 5752: my @importpubforma = (
1.508 raeburn 5753: { '<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 5754: { '<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 5755: { '<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 5756: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5757: );
5758: if ($pickfile) {
5759: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5760: }
1.502 raeburn 5761: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5762: my $extresourcesform =
5763: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5764: $help{'Adding_External_Resource'},
5765: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5766: my $exttoolform =
5767: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5768: $help{'Adding_External_Tool'},undef,
5769: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5770: \%ltitools,$disabled);
1.329 droeschl 5771: if ($allowed) {
1.492 raeburn 5772: my $folder = $env{'form.folder'};
5773: if ($folder eq '') {
5774: $folder='default';
5775: }
1.615 raeburn 5776: if ($canedit) {
5777: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5778: if ($output) {
5779: $r->print($output);
5780: }
1.538 raeburn 5781: }
1.337 ehlerst 5782: $r->print(<<HIDDENFORM);
5783: <form name="renameform" method="post" action="/adm/coursedocs">
5784: <input type="hidden" name="title" />
5785: <input type="hidden" name="cmd" />
5786: <input type="hidden" name="markcopy" />
5787: <input type="hidden" name="copyfolder" />
5788: $containertag
5789: </form>
1.484 raeburn 5790:
1.337 ehlerst 5791: HIDDENFORM
1.508 raeburn 5792: $r->print(&makesimpleeditform($pathitem)."\n".
5793: &makedocslogform($pathitem."\n".
1.484 raeburn 5794: '<input type="hidden" name="folder" value="'.
5795: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5796: }
1.442 www 5797:
5798: # Generate the tabs
1.510 raeburn 5799: my ($mode,$needs_end);
1.472 raeburn 5800: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5801: my @folders = split('&',$env{'form.folderpath'});
5802: unless (@folders > 2) {
5803: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5804: $needs_end = 1;
5805: }
1.472 raeburn 5806: } else {
1.484 raeburn 5807: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5808: $needs_end = 1;
1.472 raeburn 5809: }
1.443 www 5810:
1.442 www 5811: #
1.622 raeburn 5812: my $hostname = $r->hostname();
1.442 www 5813: my $savefolderpath;
5814:
1.395 raeburn 5815: if ($allowed) {
1.329 droeschl 5816: my $folder=$env{'form.folder'};
1.615 raeburn 5817: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5818: $folder='default';
1.356 tempelho 5819: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5820: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5821: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5822: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5823: }
5824: my $postexec='';
5825: if ($folder eq 'default') {
1.372 bisitz 5826: $r->print('<script type="text/javascript">'."\n"
5827: .'// <![CDATA['."\n"
5828: .'this.window.name="loncapaclient";'."\n"
5829: .'// ]]>'."\n"
5830: .'</script>'."\n"
1.369 bisitz 5831: );
1.329 droeschl 5832: } else {
5833: #$postexec='self.close();';
5834: }
1.504 raeburn 5835: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5836: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5837: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5838:
5839: my $newnavform=(<<NNFORM);
5840: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5841: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5842: $pathitem
1.329 droeschl 5843: <input type="hidden" name="importdetail"
5844: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 5845: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5846: $help{'Navigate_Content'}
5847: </form>
5848: NNFORM
5849: my $newsmppageform=(<<NSPFORM);
5850: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5851: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5852: $pathitem
1.329 droeschl 5853: <input type="hidden" name="importdetail" value="" />
1.423 onken 5854: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5855: $help{'Simple Page'}
1.329 droeschl 5856: </form>
5857: NSPFORM
5858:
5859: my $newsmpproblemform=(<<NSPROBFORM);
5860: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5861: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5862: $pathitem
1.329 droeschl 5863: <input type="hidden" name="importdetail" value="" />
1.423 onken 5864: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5865: $help{'Simple_Problem'}
1.329 droeschl 5866: </form>
5867:
5868: NSPROBFORM
5869:
5870: my $newdropboxform=(<<NDBFORM);
5871: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5872: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5873: $pathitem
1.329 droeschl 5874: <input type="hidden" name="importdetail" value="" />
1.423 onken 5875: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5876: $help{'Dropbox'}
1.344 bisitz 5877: </form>
1.329 droeschl 5878: NDBFORM
5879:
5880: my $newexuploadform=(<<NEXUFORM);
5881: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5882: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5883: $pathitem
1.329 droeschl 5884: <input type="hidden" name="importdetail" value="" />
1.423 onken 5885: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5886: $help{'Score_Upload_Form'}
5887: </form>
5888: NEXUFORM
5889:
5890: my $newbulform=(<<NBFORM);
5891: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5892: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5893: $pathitem
1.329 droeschl 5894: <input type="hidden" name="importdetail" value="" />
1.423 onken 5895: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5896: $help{'Bulletin Board'}
5897: </form>
5898: NBFORM
5899:
5900: my $newaboutmeform=(<<NAMFORM);
5901: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5902: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5903: $pathitem
1.329 droeschl 5904: <input type="hidden" name="importdetail"
5905: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 5906: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5907: $help{'My Personal Information Page'}
1.329 droeschl 5908: </form>
5909: NAMFORM
5910:
5911: my $newaboutsomeoneform=(<<NASOFORM);
5912: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5913: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5914: $pathitem
1.329 droeschl 5915: <input type="hidden" name="importdetail" value="" />
1.423 onken 5916: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5917: </form>
5918: NASOFORM
5919:
5920: my $newrosterform=(<<NROSTFORM);
5921: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5922: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5923: $pathitem
1.329 droeschl 5924: <input type="hidden" name="importdetail"
5925: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 5926: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 5927: $help{'Course_Roster'}
1.329 droeschl 5928: </form>
5929: NROSTFORM
5930:
1.534 raeburn 5931: my $newwebpage;
5932: if ($folder =~ /^default_?(\d*)$/) {
5933: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5934: if ($1) {
5935: $newwebpage .= $1;
5936: } else {
5937: $newwebpage .= 'default';
5938: }
5939: $newwebpage .= '/new.html';
5940: }
5941: my $newwebpageform =(<<NWEBFORM);
5942: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5943: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5944: $pathitem
5945: <input type="hidden" name="importdetail" value="$newwebpage" />
5946: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5947: $help{'Web_Page'}
1.534 raeburn 5948: </form>
5949: NWEBFORM
1.604 raeburn 5950:
1.606 raeburn 5951: my @ids=&Apache::lonnet::current_machine_ids();
5952: my %select_menus;
5953: my $numauthor = 0;
5954: my $numcrsdirs = 0;
5955: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5956: if ($env{'user.author'}) {
5957: $numauthor ++;
5958: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5959: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5960: my $is_home = 1;
5961: my %subdirs;
1.608 raeburn 5962: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5963: $select_menus{'author'}->{'default'} = '/';
5964: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5965: my @ordered = ('/');
5966: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5967: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5968: push(@ordered,$relpath);
5969: }
5970: $select_menus{'author'}->{'order'} = \@ordered;
5971: } else {
5972: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5973: $select_menus{'author'}->{'default'} = 'switch';
5974: $select_menus{'author'}->{'order'} = ['switch'];
5975: }
5976: }
5977: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5978: ['active'],['ca','aa']);
5979: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5980: my %by_roletype;
5981: if (keys(%roleshash)) {
5982: foreach my $entry (keys(%roleshash)) {
5983: my ($auname,$audom,$roletype) = split(/:/,$entry);
5984: my $key = $entry;
5985: $key =~ s/:/___/g;
5986: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5987: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5988: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5989: if (grep(/^\Q$rolehome\E$/,@ids)) {
5990: my $is_home = 1;
5991: my (%subdirs,@ordered);
5992: my $toppath="/priv/$audom/$auname";
1.608 raeburn 5993: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5994: $select_menus{$key}->{'default'} = '/';
5995: $select_menus{$key}->{'select2'}->{'/'} = '/';
5996: my @ordered = ('/');
5997: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5998: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
5999: push(@ordered,$relpath);
6000: }
6001: $select_menus{$key}->{'order'} = \@ordered;
6002: } else {
6003: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6004: $select_menus{$key}->{'default'} = 'switch';
6005: $select_menus{$key}->{'order'} = ['switch'];
6006: }
6007: $numauthor ++;
6008: }
6009: }
6010: my ($pickdir,$showtitle);;
6011: if ($numauthor) {
6012: my @order;
6013: my $defrole;
6014: if ($env{'user.author'}) {
6015: push(@order,'author');
6016: $defrole = 'author';
6017: }
6018: if (keys(%by_roletype)) {
6019: foreach my $possrole ('ca','aa') {
6020: if (ref($by_roletype{$possrole}) eq 'HASH') {
6021: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6022: unless ($defrole) {
6023: $defrole = $author;
6024: }
6025: push(@order,$author.'___'.$possrole);
6026: }
6027: }
6028: }
6029: }
6030: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6031: if (grep(/^\Q$crshome\E$/,@ids)) {
6032: my $is_home = 1;
6033: my %subdirs;
6034: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6035: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6036: $numcrsdirs = keys(%subdirs);
6037: $select_menus{'course'}->{'default'} = '/';
6038: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6039: my @ordered = ('/');
6040: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6041: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6042: push(@ordered,$relpath);
6043: }
6044: $select_menus{'course'}->{'order'} = \@ordered;
6045: } else {
6046: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6047: $select_menus{'course'}->{'default'} = 'switch';
6048: $select_menus{'course'}->{'order'} = ['switch'];
6049: }
6050: push(@order,'course');
6051: $pickdir = $lt{'loca'}.
6052: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6053: $defrole,'authorrole','authorpath',
6054: \%select_menus,\@order,'toggleCrsResTitle();',
6055: '','priv').'<br />';
6056: $showtitle = 'none';
6057: } else {
6058: my $is_home;
6059: $showtitle = 'inline';
6060: if (grep(/^\Q$crshome\E$/,@ids)) {
6061: $is_home = 1;
6062: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6063: my $toppath="/priv/$coursedom/$coursenum'}";
6064: my %subdirs;
1.608 raeburn 6065: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6066: $numcrsdirs = keys(%subdirs);
6067: if ($numcrsdirs) {
6068: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6069: '<option value="/">/</option>'."\n";
6070: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6071: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6072: }
6073: $pickdir .= '</select>';
6074: } else {
6075: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6076: }
6077: }
6078: }
6079:
6080: my %seltemplate_menus;
6081: my @files = &Apache::lonhomework::get_template_list('problem');
6082: my @noexamplelink = ('blank.problem','blank.library','script.library');
6083: my $currentcategory = '';
6084: my @ordered = ('');
6085: my %templatehelp;
6086: my $defcategory = '';
6087: my @catorder = ($defcategory);
6088: $seltemplate_menus{$defcategory}->{'order'} = [''];
6089: $seltemplate_menus{$defcategory}->{'text'} = '';
6090: foreach my $file (@files) {
6091: if (ref($file) eq 'ARRAY') {
6092: my ($path,$title,$category,$help) = @{$file};
6093: next if ($title !~ /\S/);
6094: if (&js_escape($category) ne $currentcategory) {
6095: $currentcategory = &js_escape($category);
6096: push(@catorder,&js_escape($currentcategory));
6097: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6098: $seltemplate_menus{$currentcategory}->{'default'} = '';
6099: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6100: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6101: }
6102: if ($path) {
6103: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6104: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6105: if ($help) {
6106: $templatehelp{$path} = $help;
6107: }
6108: }
6109: }
6110: }
6111:
6112: my $templates = $lt{'cate'}.' '.
6113: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6114: $defcategory,'tempcategory','template',
6115: \%seltemplate_menus,\@catorder,
6116: "resize_scrollbox('contentscroll','1','0');",
6117: "toggleExampleText();",'template').'<br />';
6118: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6119: '<span id="newresexample">'.&mt('Example').'<span></a>';
6120: my $crsresform=(<<RESFORM);
6121: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6122: $lt{'stpr'}</a>$help{'Course_Resource'}
6123: <form action="/adm/coursedocs" method="post" name="courseresform">
6124: <fieldset id="crsresform" style="display:none;">
6125: <legend>$lt{'stpr'}</legend>
6126: <input type="hidden" name="active" value="ee" />
6127: <p>
6128: $pickdir
6129: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6130: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6131:
1.611 raeburn 6132: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6133: </span><span id="newsubdir"></span>
6134: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6135: </p>
6136: $lt{'fnam'}
1.611 raeburn 6137: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6138: <p>
6139: <div id="newresource" style="display:$showtitle">
6140: $lt{'addp'}
1.611 raeburn 6141: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6142: $lt{'no'}</label>
1.611 raeburn 6143: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6144: $lt{'yes'}</label>
6145: <span id="newrestitle"></span>
1.611 raeburn 6146: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6147: </div>
6148: </p>
6149: <p>
6150: $lt{'uste'}
1.611 raeburn 6151: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6152: $lt{'no'}</label>
1.611 raeburn 6153: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6154: $lt{'yes'}</label>
6155: <div id="newrestemplate" style="display:none">
6156: $templates
6157: $templatepreview
6158: </div>
6159: </p>
6160: <span class="LC_nobreak">
6161: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6162: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6163: </span>
6164: </fieldset>
6165: </form>
6166:
6167: RESFORM
1.534 raeburn 6168:
1.342 ehlerst 6169: my $specialdocumentsform;
1.383 tempelho 6170: my @specialdocumentsforma;
1.451 www 6171: my $gradingform;
6172: my @gradingforma;
6173: my $communityform;
6174: my @communityforma;
1.351 ehlerst 6175: my $newfolderform;
1.390 tempelho 6176: my $newfolderb;
1.342 ehlerst 6177:
1.451 www 6178: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6179:
1.329 droeschl 6180: my $newpageform=(<<NPFORM);
6181: <form action="/adm/coursedocs" method="post" name="newpage">
6182: <input type="hidden" name="folderpath" value="$path" />
6183: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6184: <input type="hidden" name="active" value="ee" />
1.423 onken 6185: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6186: $help{'Adding_Pages'}
1.329 droeschl 6187: </form>
6188: NPFORM
1.390 tempelho 6189:
6190:
1.351 ehlerst 6191: $newfolderform=(<<NFFORM);
1.329 droeschl 6192: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6193: $pathitem
1.329 droeschl 6194: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6195: <input type="hidden" name="active" value="" />
1.422 onken 6196: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6197: </form>
6198: NFFORM
6199:
6200: my $newsylform=(<<NSYLFORM);
6201: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6202: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6203: $pathitem
1.329 droeschl 6204: <input type="hidden" name="importdetail"
6205: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6206: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6207: $help{'Syllabus'}
1.383 tempelho 6208:
1.329 droeschl 6209: </form>
6210: NSYLFORM
1.364 bisitz 6211:
1.329 droeschl 6212: my $newgroupfileform=(<<NGFFORM);
6213: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6214: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6215: $pathitem
1.329 droeschl 6216: <input type="hidden" name="importdetail"
6217: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6218: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6219: $help{'Group Portfolio'}
1.329 droeschl 6220: </form>
6221: NGFFORM
1.383 tempelho 6222: @specialdocumentsforma=(
1.421 onken 6223: {'<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 6224: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6225: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6226: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6227: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6228: );
6229: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6230:
1.434 raeburn 6231:
6232: my @importdoc = (
1.519 raeburn 6233: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6234: );
1.598 raeburn 6235: if (keys(%ltitools)) {
6236: push(@importdoc,
6237: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6238: );
6239: }
1.519 raeburn 6240: unless ($container eq 'page') {
6241: push(@importdoc,
6242: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6243: );
6244: }
6245: push(@importdoc,
1.558 raeburn 6246: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6247: );
1.501 raeburn 6248: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6249:
1.451 www 6250: @gradingforma=(
6251: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6252: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6253: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6254: {'<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 6255: );
6256: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6257:
6258: @communityforma=(
6259: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6260: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6261: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6262: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6263: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6264: );
6265: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6266:
1.330 tempelho 6267: my %orderhash = (
1.553 raeburn 6268: 'aa' => ['Upload',$fileuploadform],
6269: 'bb' => ['Import',$importpubform],
6270: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6271: );
1.519 raeburn 6272: unless ($container eq 'page') {
1.434 raeburn 6273: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6274: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6275: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6276: }
6277:
1.341 ehlerst 6278: $hadchanges=0;
1.484 raeburn 6279: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6280: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6281: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6282: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6283: undef($navmap);
1.443 www 6284: if ($error) {
6285: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6286: }
6287: if ($hadchanges) {
6288: &mark_hash_old();
6289: }
1.341 ehlerst 6290:
1.443 www 6291: &changewarning($r,'');
6292: }
1.458 raeburn 6293: }
1.442 www 6294:
1.443 www 6295: # Supplemental documents start here
6296:
1.329 droeschl 6297: my $folder=$env{'form.folder'};
1.443 www 6298: unless ($supplementalflag) {
1.329 droeschl 6299: $folder='supplemental';
6300: }
6301: if ($folder =~ /^supplemental$/ &&
6302: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6303: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6304: } elsif ($allowed) {
1.356 tempelho 6305: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6306: }
1.508 raeburn 6307: $pathitem = '<input type="hidden" name="folderpath" value="'.
6308: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6309: if ($allowed) {
6310: my $folderseq=
1.504 raeburn 6311: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6312:
6313: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6314: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6315: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6316: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6317: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6318: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6319: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6320: $fileupload
6321: <br />
6322: <br />
6323: <span class="LC_nobreak">
6324: $checkbox
6325: </span>
6326: <br /><br />
6327: $lt{'comment'}:<br />
1.383 tempelho 6328: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6329: <br />
1.508 raeburn 6330: $pathitem
1.329 droeschl 6331: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6332: <input type='submit' value="$lt{'upld'}" />
6333: </form>
1.329 droeschl 6334: SUPDOCFORM
6335:
6336: my $supnewfolderform=(<<SNFFORM);
6337: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6338: <input type="hidden" name="active" value="" />
1.508 raeburn 6339: $pathitem
1.329 droeschl 6340: <input type="hidden" name="importdetail" value="" />
1.423 onken 6341: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6342: $help{'Adding_Folders'}
1.329 droeschl 6343: </form>
6344: SNFFORM
1.383 tempelho 6345:
1.510 raeburn 6346: my $supextform =
6347: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6348: $help{'Adding_External_Resource'},
6349: undef,undef,undef,undef,undef,undef,
6350: $disabled);
1.329 droeschl 6351:
1.598 raeburn 6352: my $supexttoolform =
6353: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6354: $help{'Adding_External_Tool'},
6355: undef,undef,'tool',$coursedom,
1.611 raeburn 6356: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6357:
1.329 droeschl 6358: my $supnewsylform=(<<SNSFORM);
6359: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6360: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6361: $pathitem
1.329 droeschl 6362: <input type="hidden" name="importdetail"
6363: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6364: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6365: $help{'Syllabus'}
6366: </form>
6367: SNSFORM
6368:
6369: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6370: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6371: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6372: $pathitem
1.329 droeschl 6373: <input type="hidden" name="importdetail"
6374: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6375: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6376: $help{'My Personal Information Page'}
1.329 droeschl 6377: </form>
6378: SNAMFORM
6379:
1.534 raeburn 6380: my $supwebpage;
6381: if ($folder =~ /^supplemental_?(\d*)$/) {
6382: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6383: if ($1) {
6384: $supwebpage .= $1;
6385: } else {
6386: $supwebpage .= 'default';
6387: }
6388: $supwebpage .= '/new.html';
6389: }
6390: my $supwebpageform =(<<SWEBFORM);
6391: <form action="/adm/coursedocs" method="post" name="supwebpage">
6392: <input type="hidden" name="active" value="cc" />
6393: $pathitem
6394: <input type="hidden" name="importdetail" value="$supwebpage" />
6395: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6396: $help{'Web_Page'}
1.534 raeburn 6397: </form>
6398: SWEBFORM
6399:
1.333 muellerd 6400:
1.383 tempelho 6401: my @specialdocs = (
1.618 raeburn 6402: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6403: =>$supnewsylform},
1.611 raeburn 6404: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6405: =>$supnewaboutmeform},
1.534 raeburn 6406: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6407:
1.383 tempelho 6408: );
1.417 droeschl 6409: my @supimportdoc = (
1.515 raeburn 6410: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6411: =>$supextform});
6412: if (keys(%ltitools)) {
6413: push(@supimportdoc,
6414: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6415: =>$supexttoolform});
6416: }
6417: push(@supimportdoc,
6418: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6419: =>$supupdocform},
1.598 raeburn 6420: );
1.501 raeburn 6421:
6422: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6423: my %suporderhash = (
1.390 tempelho 6424: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6425: 'ee' => ['Upload',$supupdocform],
6426: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6427: );
1.443 www 6428: if ($supplementalflag) {
1.458 raeburn 6429: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6430: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6431: \%ltitools,$canedit,$hostname);
1.443 www 6432: if ($error) {
6433: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6434: } else {
6435: if ($suppchanges) {
6436: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6437: my @ids=&Apache::lonnet::current_machine_ids();
6438: foreach my $server (keys(%servers)) {
6439: next if (grep(/^\Q$server\E$/,@ids));
6440: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6441: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6442: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6443: }
6444: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6445: undef($suppchanges);
6446: }
6447: }
1.393 raeburn 6448: }
1.443 www 6449: } elsif ($supplementalflag) {
1.458 raeburn 6450: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6451: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6452: if ($error) {
6453: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6454: }
1.393 raeburn 6455: }
1.389 tempelho 6456:
1.510 raeburn 6457: if ($needs_end) {
6458: $r->print(&endContentScreen());
6459: }
1.383 tempelho 6460:
1.329 droeschl 6461: if ($allowed) {
6462: $r->print('
6463: <form method="post" name="extimport" action="/adm/coursedocs">
6464: <input type="hidden" name="title" />
6465: <input type="hidden" name="url" />
6466: <input type="hidden" name="useform" />
6467: <input type="hidden" name="residx" />
6468: </form>');
6469: }
1.484 raeburn 6470: } elsif ($showdoc) {
1.329 droeschl 6471: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6472: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6473: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6474: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6475: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6476: }
6477: }
1.606 raeburn 6478: unless ($noendpage) {
6479: $r->print(&Apache::loncommon::end_page());
6480: }
1.329 droeschl 6481: return OK;
1.364 bisitz 6482: }
1.329 droeschl 6483:
1.440 raeburn 6484: sub embedded_form_elems {
6485: my ($phase,$primaryurl,$newidx) = @_;
6486: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6487: return <<STATE;
6488: <input type="hidden" name="folderpath" value="$folderpath" />
6489: <input type="hidden" name="cmd" value="upload_embedded" />
6490: <input type="hidden" name="newidx" value="$newidx" />
6491: <input type="hidden" name="phase" value="$phase" />
6492: <input type="hidden" name="primaryurl" value="$primaryurl" />
6493: STATE
6494: }
6495:
6496: sub embedded_destination {
6497: my $folder=$env{'form.folder'};
6498: my $destination = 'docs/';
6499: if ($folder =~ /^supplemental/) {
6500: $destination = 'supplemental/';
6501: }
6502: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6503: $destination .= 'default/';
6504: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6505: $destination .= $2.'/';
6506: }
6507: $destination .= $env{'form.newidx'};
6508: my $dir_root = '/userfiles';
6509: return ($destination,$dir_root);
6510: }
6511:
6512: sub return_to_editor {
6513: my $actionurl = '/adm/coursedocs';
6514: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6515: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6516: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6517: '</a></p>';
6518: }
6519:
1.476 raeburn 6520: sub decompression_info {
6521: my ($destination,$dir_root) = &embedded_destination();
6522: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6523: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6524: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6525: my $container='sequence';
1.480 raeburn 6526: my ($pathitem,$hiddenelem);
1.583 raeburn 6527: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6528: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6529: $container='page';
6530: }
1.480 raeburn 6531: unshift(@hiddens,$pathitem);
6532: foreach my $item (@hiddens) {
6533: if ($env{'form.'.$item}) {
6534: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6535: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6536: }
1.477 raeburn 6537: }
1.476 raeburn 6538: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6539: $hiddenelem);
6540: }
6541:
6542: sub decompression_phase_one {
6543: my ($dir,$file,$warning,$error,$output);
6544: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6545: &decompression_info();
1.490 raeburn 6546: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6547: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6548: } else {
6549: my $file = $1;
1.481 raeburn 6550: $output =
6551: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6552: $destination,$dir_root,
6553: $hiddenelem);
6554: if ($env{'form.autoextract_camtasia'}) {
6555: $output .= &remove_archive($docudom,$docuname,$container);
6556: }
1.476 raeburn 6557: }
6558: if ($error) {
6559: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6560: $error.'</p>'."\n";
6561: }
6562: if ($warning) {
6563: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6564: }
6565: return $output;
6566: }
6567:
6568: sub decompression_phase_two {
6569: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6570: &decompression_info();
1.481 raeburn 6571: my $output;
1.480 raeburn 6572: if ($env{'form.archivedelete'}) {
1.481 raeburn 6573: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6574: }
6575: $output .=
1.481 raeburn 6576: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6577: $destination,$dir_root,$hiddenelem);
6578: return $output;
6579: }
6580:
1.480 raeburn 6581: sub remove_archive {
6582: my ($docudom,$docuname,$container) = @_;
6583: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6584: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6585: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6586: if ($fatal) {
6587: if ($container eq 'page') {
6588: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6589: } else {
6590: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6591: }
1.583 raeburn 6592: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6593: } else {
6594: my $currcmd = $env{'form.cmd'};
6595: my $position = $env{'form.position'};
1.583 raeburn 6596: my $archiveidx = $position;
1.563 raeburn 6597: if ($position > 0) {
1.583 raeburn 6598: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6599: $archiveidx = $position-1;
6600: }
6601: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6602: my ($title,$url,@rrest) =
1.583 raeburn 6603: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6604: if ($url eq $env{'form.archiveurl'}) {
6605: if (&handle_edit_cmd($docuname,$docudom)) {
6606: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6607: if ($fatal) {
6608: if ($container eq 'page') {
6609: $delwarning = &mt('An error occurred updating the contents of the current page.');
6610: } else {
6611: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6612: }
1.480 raeburn 6613: } else {
1.583 raeburn 6614: $delresult = &mt('Archive file removed.');
1.480 raeburn 6615: }
6616: }
1.583 raeburn 6617: } else {
6618: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6619: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6620: }
6621: }
6622: $env{'form.cmd'} = $currcmd;
6623: }
6624: if ($delwarning) {
6625: $output = '<p class="LC_warning">'.
6626: $delwarning.
6627: '</p>';
6628: }
6629: if ($delresult) {
6630: $output .= '<p class="LC_info">'.
6631: $delresult.
6632: '</p>';
6633: }
1.481 raeburn 6634: return $output;
1.480 raeburn 6635: }
6636:
1.484 raeburn 6637: sub generate_admin_menu {
1.611 raeburn 6638: my ($crstype,$canedit) = @_;
1.484 raeburn 6639: my $lc_crstype = lc($crstype);
6640: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6641: my %lt= ( # do not translate here
1.484 raeburn 6642: 'vc' => 'Verify Content',
6643: 'cv' => 'Check/Set Resource Versions',
6644: 'ls' => 'List Resource Identifiers',
6645: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6646: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6647: );
1.484 raeburn 6648: my ($candump,$dumpurl);
6649: if ($home + $other > 0) {
6650: $candump = 'F';
6651: if ($home) {
6652: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6653: } else {
6654: my @hosts;
6655: foreach my $aurole (keys(%outhash)) {
6656: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6657: push(@hosts,$outhash{$aurole});
1.538 raeburn 6658: }
1.484 raeburn 6659: }
6660: if (@hosts == 1) {
6661: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6662: '&role='.
6663: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6664: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6665: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6666: } else {
6667: $dumpurl = "javascript:choose_switchserver_window()";
6668: }
6669: }
6670: }
6671: my @menu=
6672: ({ categorytitle=>'Administration',
6673: items =>[
6674: { linktext => $lt{'vc'},
6675: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6676: permission => 'F',
1.571 raeburn 6677: help => 'Docs_Verify_Content',
1.484 raeburn 6678: icon => 'verify.png',
6679: linktitle => 'Verify contents can be retrieved/rendered',
6680: },
6681: { linktext => $lt{'cv'},
6682: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6683: permission => 'F',
1.571 raeburn 6684: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6685: icon => 'resversion.png',
6686: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6687: },
6688: { linktext => $lt{'ls'},
6689: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6690: permission => 'F',
6691: #help => '',
6692: icon => 'symbs.png',
6693: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6694: },
6695: ]
1.611 raeburn 6696: });
6697: if ($canedit) {
6698: push(@menu,
1.484 raeburn 6699: { categorytitle=>'Export',
6700: items =>[
6701: { linktext => $lt{'imse'},
6702: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6703: permission => 'F',
6704: help => 'Docs_Export_Course_Docs',
6705: icon => 'imsexport.png',
6706: linktitle => $lt{'imse'},
6707: },
6708: { linktext => $lt{'dcd'},
6709: url => $dumpurl,
6710: permission => $candump,
1.571 raeburn 6711: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6712: icon => 'dump.png',
6713: linktitle => $lt{'dcd'},
6714: },
6715: ]
6716: });
1.611 raeburn 6717: }
1.484 raeburn 6718: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6719: '<input type="hidden" id="dummy" />'."\n".
6720: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6721: '</form>';
1.329 droeschl 6722: }
6723:
6724: sub generate_edit_table {
1.538 raeburn 6725: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6726: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6727: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6728: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6729: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6730: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6731: $activetab = $env{'form.active'};
6732: }
1.611 raeburn 6733: unless ($canedit) {
6734: $disabled = ' disabled="disabled"';
6735: }
1.472 raeburn 6736: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6737: my $backtext = &mt('Exit Editor');
1.458 raeburn 6738: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6739: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6740: '<li class="goback">'.
1.546 raeburn 6741: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6742: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6743: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6744: '<li>'.
6745: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6746: &mt('Undo Delete').'</a></li>'."\n";
6747: if ($env{'form.docslog'}) {
6748: $form .= '<li class="active">';
6749: } else {
6750: $form .= '<li>';
6751: }
6752: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6753: &mt('History').'</a></li>'."\n";
6754: if ($env{'form.docslog'}) {
6755: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6756: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6757: }
1.458 raeburn 6758: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6759: if($name ne '00'){
1.371 tempelho 6760: if($activetab eq '' || $activetab ne $name){
6761: $active = '';
6762: }elsif($activetab eq $name){
6763: $active = 'class="active"';
6764: }
1.458 raeburn 6765: $form .= '<li style="float:right" '.$active
1.484 raeburn 6766: .' 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 6767: } else {
1.570 raeburn 6768: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6769:
6770: }
1.329 droeschl 6771: }
1.484 raeburn 6772: $form .= '</ul>'."\n";
6773: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6774:
6775: if ($to_show ne '') {
1.538 raeburn 6776: my $saveform;
6777: if ($need_save) {
6778: my $button = &mt('Make changes');
6779: my $path;
6780: if ($env{'form.folderpath'}) {
6781: $path =
6782: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6783: }
6784: $saveform = <<"END";
6785: <div id="multisave" style="display:none; clear:both;" >
6786: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6787: <input type="hidden" name="folderpath" value="$path" />
6788: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6789: <input type="hidden" name="allhiddenresource" value="" />
6790: <input type="hidden" name="allencrypturl" value="" />
6791: <input type="hidden" name="allrandompick" value="" />
6792: <input type="hidden" name="allrandomorder" value="" />
6793: <input type="hidden" name="changeparms" value="" />
6794: <input type="hidden" name="multiremove" value="" />
6795: <input type="hidden" name="multicut" value="" />
6796: <input type="hidden" name="multicopy" value="" />
6797: <input type="hidden" name="multichange" value="" />
6798: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 6799: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 6800: </form>
6801: </div>
6802: END
6803: }
6804: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6805: }
1.363 ehlerst 6806: foreach my $field (keys(%orderhash)){
1.390 tempelho 6807: if($field ne '00'){
1.422 onken 6808: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6809: $active = 'style="display: none;float:left"';
1.422 onken 6810: }elsif($activetab eq $field){
1.458 raeburn 6811: $active = 'style="display:block;float:left"';
1.422 onken 6812: }
6813: $form .= '<div id="'.$field.$tid.'"'
6814: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6815: .'</div>'."\n";
1.363 ehlerst 6816: }
6817: }
1.484 raeburn 6818: unless ($env{'form.docslog'}) {
6819: $form .= '</div></div>'."\n";
6820: }
1.329 droeschl 6821: return $form;
6822: }
6823:
6824: sub editing_js {
1.622 raeburn 6825: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
6826: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 6827: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6828: p_mnf => 'Name of New Folder',
6829: t_mnf => 'New Folder',
6830: p_mnp => 'Name of New Page',
6831: t_mnp => 'New Page',
1.451 www 6832: p_mxu => 'Title for the External Score',
1.349 biermanm 6833: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6834: p_msb => 'Title for the Problem',
6835: p_mdb => 'Title for the Drop Box',
1.336 schafran 6836: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 6837: p_mwp => 'Title for Web Page',
1.606 raeburn 6838: p_mnr => 'Title for the Resource',
1.348 weissno 6839: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6840: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6841: p_mab_alrt1 => 'Not a valid user:domain',
6842: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6843: p_chn => 'New Title',
6844: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 6845: p_rmr2a => 'Remove',
6846: p_rmr2b => '?',
6847: p_rmr3a => 'Remove those',
6848: p_rmr3b => 'items?',
6849: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6850: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6851: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6852: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 6853: p_ctr2a => 'Cut',
6854: p_ctr2b => '?',
6855: p_ctr3a => 'Cut those',
6856: p_ctr3b => 'items?',
1.478 raeburn 6857: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6858: imsfile => 'You must choose an IMS package for import',
6859: imscms => 'You must select which Course Management System was the source of the IMS package',
6860: invurl => 'Invalid URL',
6861: titbl => 'Title is blank',
1.538 raeburn 6862: more => '(More ...)',
6863: less => '(Less ...)',
1.543 raeburn 6864: noor => 'No actions selected or changes to settings specified.',
6865: noch => 'No changes to settings specified.',
6866: noac => 'No actions selected.',
1.606 raeburn 6867: nofi => 'No file selected',
6868: tinc => 'Title in course',
6869: sunm => 'Sub-directory name',
1.618 raeburn 6870: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6871: );
1.594 damieng 6872: &js_escape(\%js_lt);
1.433 raeburn 6873: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6874: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6875: my $main_container_page;
1.519 raeburn 6876: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6877: $main_container_page = 1;
1.434 raeburn 6878: }
1.617 raeburn 6879: my $backtourl;
6880: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6881: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6882:
1.530 raeburn 6883: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6884: my $caller = $1;
1.525 raeburn 6885: if ($caller =~ /^supplemental/) {
6886: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6887: } else {
6888: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6889: $res = &Apache::lonnet::clutter($res);
6890: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 6891: my ($url,$anchor);
6892: if ($res =~ /^([^#]+)#([^#]+)$/) {
6893: $url = $1;
6894: $anchor = $2;
6895: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6896: $caller = $1.&escape('#').$anchor;
6897: }
1.614 raeburn 6898: } else {
6899: $url = $res;
1.609 raeburn 6900: }
6901: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 6902: &HTML::Entities::encode($caller,'<>&"');
1.622 raeburn 6903: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6904: if (($ENV{'SERVER_PORT'} == 443) &&
6905: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6906: if ($hostname ne '') {
6907: $backtourl = 'http://'.$hostname.$backtourl;
6908: }
6909: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6910: }
1.623 raeburn 6911: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6912: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6913: $backtourl = 'http://'.$hostname.$backtourl;
6914: }
1.622 raeburn 6915: }
1.609 raeburn 6916: if ($anchor ne '') {
6917: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6918: }
1.590 raeburn 6919: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6920: } else {
6921: $backtourl = '/adm/navmaps';
1.525 raeburn 6922: }
6923: }
6924: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6925: $backtourl = '/adm/menu';
6926: } elsif ($supplementalflag) {
1.472 raeburn 6927: $backtourl = '/adm/supplemental';
1.525 raeburn 6928: } else {
6929: $backtourl = '/adm/navmaps';
1.472 raeburn 6930: }
6931:
1.600 raeburn 6932: my $fieldsets = "'ext','doc'";
6933: if ($posslti) {
6934: $fieldsets .= ",'tool'";
6935: }
1.519 raeburn 6936: unless ($main_container_page) {
6937: $fieldsets .=",'ims'";
6938: }
1.501 raeburn 6939: if ($supplementalflag) {
1.600 raeburn 6940: $fieldsets = "'suppext','suppdoc'";
6941: if ($posslti) {
6942: $fieldsets .= ",'supptool'";
6943: }
1.501 raeburn 6944: }
1.611 raeburn 6945:
6946: my $jsmakefunctions;
6947: if ($canedit) {
6948: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6949: function makenewfolder(targetform,folderseq) {
1.594 damieng 6950: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6951: if (foldername) {
6952: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6953: targetform.submit();
6954: }
6955: }
6956:
6957: function makenewpage(targetform,folderseq) {
1.594 damieng 6958: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6959: if (pagename) {
6960: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6961: targetform.submit();
6962: }
6963: }
6964:
6965: function makeexamupload() {
1.594 damieng 6966: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6967: if (title) {
1.329 droeschl 6968: this.document.forms.newexamupload.importdetail.value=
6969: escape(title)+'=/res/lib/templates/examupload.problem';
6970: this.document.forms.newexamupload.submit();
6971: }
6972: }
6973:
6974: function makesmppage() {
1.594 damieng 6975: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6976: if (title) {
1.329 droeschl 6977: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 6978: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6979: this.document.forms.newsmppg.submit();
6980: }
6981: }
6982:
1.534 raeburn 6983: function makewebpage(type) {
1.594 damieng 6984: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 6985: var formname;
6986: if (type == 'supp') {
6987: formname = this.document.forms.supwebpage;
6988: } else {
6989: formname = this.document.forms.newwebpage;
6990: }
6991: if (title) {
6992: var webpage = formname.importdetail.value;
6993: formname.importdetail.value = escape(title)+'='+webpage;
6994: formname.submit();
6995: }
6996: }
6997:
1.329 droeschl 6998: function makesmpproblem() {
1.594 damieng 6999: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7000: if (title) {
1.329 droeschl 7001: this.document.forms.newsmpproblem.importdetail.value=
7002: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7003: this.document.forms.newsmpproblem.submit();
7004: }
7005: }
7006:
7007: function makedropbox() {
1.594 damieng 7008: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7009: if (title) {
1.329 droeschl 7010: this.document.forms.newdropbox.importdetail.value=
7011: escape(title)+'=/res/lib/templates/DropBox.problem';
7012: this.document.forms.newdropbox.submit();
7013: }
7014: }
7015:
7016: function makebulboard() {
1.594 damieng 7017: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7018: if (title) {
7019: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7020: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7021: this.document.forms.newbul.submit();
7022: }
7023: }
7024:
7025: function makeabout() {
1.594 damieng 7026: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7027: if (user) {
7028: var comp=new Array();
7029: comp=user.split(':');
7030: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7031: if ((comp[0]) && (comp[1])) {
7032: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7033: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7034: this.document.forms.newaboutsomeone.submit();
7035: } else {
7036: alert("$js_lt{'p_mab_alrt1'}");
7037: }
7038: } else {
7039: alert("$js_lt{'p_mab_alrt2'}");
7040: }
7041: }
7042: }
7043:
7044: function makenew(targetform) {
7045: targetform.submit();
7046: }
7047:
7048: function changename(folderpath,index,oldtitle) {
7049: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7050: if (title) {
7051: this.document.forms.renameform.markcopy.value='';
7052: this.document.forms.renameform.title.value=title;
7053: this.document.forms.renameform.cmd.value='rename_'+index;
7054: this.document.forms.renameform.folderpath.value=folderpath;
7055: this.document.forms.renameform.submit();
7056: }
7057: }
7058:
7059: ENDNEWSCRIPT
7060: } else {
7061: $jsmakefunctions = <<ENDNEWSCRIPT;
7062:
7063: function makenewfolder() {
7064: alert("$js_lt{'edri'}");
7065: }
7066:
7067: function makenewpage() {
7068: alert("$js_lt{'edri'}");
7069: }
7070:
7071: function makeexamupload() {
7072: alert("$js_lt{'edri'}");
7073: }
7074:
7075: function makesmppage() {
7076: alert("$js_lt{'edri'}");
7077: }
7078:
7079: function makewebpage(type) {
7080: alert("$js_lt{'edri'}");
7081: }
7082:
7083: function makesmpproblem() {
7084: alert("$js_lt{'edri'}");
7085: }
7086:
7087: function makedropbox() {
7088: alert("$js_lt{'edri'}");
7089: }
7090:
7091: function makebulboard() {
7092: alert("$js_lt{'edri'}");
7093: }
7094:
7095: function makeabout() {
7096: alert("$js_lt{'edri'}");
7097: }
7098:
7099: function changename() {
7100: alert("$js_lt{'edri'}");
7101: }
7102:
7103: function makenew() {
7104: alert("$js_lt{'edri'}");
7105: }
7106:
7107: function groupimport() {
7108: alert("$js_lt{'edri'}");
1.335 ehlerst 7109: }
1.611 raeburn 7110:
7111: function groupsearch() {
7112: alert("$js_lt{'edri'}");
1.335 ehlerst 7113: }
1.611 raeburn 7114:
7115: function groupopen(url,recover) {
7116: var options="scrollbars=1,resizable=1,menubar=0";
7117: idxflag=1;
7118: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7119: idx.focus();
1.329 droeschl 7120: }
7121:
1.611 raeburn 7122: ENDNEWSCRIPT
7123:
7124: }
7125: return <<ENDSCRIPT;
7126:
7127: $jsmakefunctions
7128:
1.501 raeburn 7129: function toggleUpload(caller) {
7130: var blocks = Array($fieldsets);
7131: for (var i=0; i<blocks.length; i++) {
7132: var disp = 'none';
7133: if (caller == blocks[i]) {
7134: var curr = document.getElementById('upload'+caller+'form').style.display;
7135: if (curr == 'none') {
7136: disp='block';
7137: }
7138: }
7139: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7140: if ((caller == 'tool') || (caller == 'supptool')) {
7141: if (disp == 'block') {
7142: if (document.getElementById('LC_exttoolid')) {
7143: var toolselector = document.getElementById('LC_exttoolid');
7144: var suppflag = 0;
7145: if (caller == 'supptool') {
7146: suppflag = 1;
7147: }
7148: currForm = document.getElementById('new'+caller);
7149: updateExttool(toolselector,currForm,suppflag);
7150: }
7151: }
7152: }
1.501 raeburn 7153: }
1.502 raeburn 7154: resize_scrollbox('contentscroll','1','1');
7155: return;
7156: }
7157:
1.514 raeburn 7158: function toggleMap(caller) {
1.502 raeburn 7159: var disp = 'none';
1.510 raeburn 7160: if (document.getElementById('importmapform')) {
1.514 raeburn 7161: if (caller == 'map') {
7162: var curr = document.getElementById('importmapform').style.display;
7163: if (curr == 'none') {
7164: disp='block';
7165: }
1.510 raeburn 7166: }
7167: document.getElementById('importmapform').style.display=disp;
7168: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7169: }
1.501 raeburn 7170: return;
1.329 droeschl 7171: }
7172:
1.606 raeburn 7173: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7174: var disp = 'none';
7175: if (document.getElementById('crsresform')) {
7176: if (caller == 'res') {
7177: var curr = document.getElementById('crsresform').style.display;
7178: if (curr == 'none') {
7179: disp='block';
7180: numauthor = parseInt(numauthorrole);
7181: if (numauthor > 0) {
7182: document.courseresform.authorrole.selectedIndex = 0;
7183: select1priv_changed();
7184: document.courseresform.authorpath.selectedIndex = 0;
7185: document.courseresform.newresourceadd.selectedIndex = 0;
7186: toggleNewInCourse(document.courseresform);
7187: if (document.getElementById('newresource')) {
7188: document.getElementById('newresource').style.display = 'none';
7189: }
7190: } else {
7191: if (numcrsdirs) {
7192: document.courseresform.authorpath.selectedIndex = 0;
7193: }
7194: }
7195: if (document.courseresform.newresusetemp.length) {
7196: document.courseresform.newresusetemp[0].checked = true;
7197: toggleWithTemplate(document.courseresform);
7198: }
7199: document.courseresform.newresourcename.value = '';
7200: }
7201: }
7202: if (document.courseresform.newsubdir.length) {
7203: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7204: if (document.courseresform.newsubdir[j].value == 0) {
7205: document.courseresform.newsubdir[j].checked = true;
7206: }
7207: break;
7208: }
7209: if (document.getElementById('newsubdirname')) {
7210: document.getElementById('newsubdirname').type = "hidden";
7211: document.getElementById('newsubdirname').value = "";
7212: }
7213: if (document.getElementById('newsubdir')) {
7214: document.getElementById('newsubdir').innerHTML = "";
7215: }
7216: }
7217: document.getElementById('crsresform').style.display=disp;
7218: resize_scrollbox('contentscroll','1','0');
7219: }
7220: return;
7221: }
7222:
7223: function toggleNewsubdir(form) {
7224: if (form.newsubdir.length) {
7225: for (var j=0; j<form.newsubdir.length; j++) {
7226: if (form.newsubdir[j].checked) {
7227: if (document.getElementById('newsubdirname')) {
7228: if (form.newsubdir[j].value == '1') {
7229: document.getElementById('newsubdirname').type = "text";
7230: if (document.getElementById('newsubdir')) {
7231: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7232: }
7233: } else {
7234: document.getElementById('newsubdirname').type = "hidden";
7235: document.getElementById('newsubdirname').value = "";
7236: document.getElementById('newsubdir').innerHTML = "";
7237: }
7238: }
7239: break;
7240: }
7241: }
7242: }
7243: }
7244:
7245: function toggleCrsResTitle() {
7246: if (document.getElementById('newresource')) {
7247: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7248: document.getElementById('newresource').style.display = 'inline';
7249: document.courseresform.newresourceadd[0].checked = true;
7250: toggleNewInCourse(document.courseresform);
7251: } else {
7252: document.getElementById('newresource').style.display = 'none';
7253: }
7254: }
7255: }
7256:
7257: function toggleNewInCourse(form) {
7258: if (form.newresourceadd.length) {
7259: for (var i=0; i<form.newresourceadd.length; i++) {
7260: if (form.newresourceadd[i].checked) {
7261: if (document.getElementById('newresourcetitle')) {
7262: if (form.newresourceadd[i].value == '1') {
7263: document.getElementById('newresourcetitle').type = 'text';
7264: if (document.getElementById('newrestitle')) {
7265: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7266: }
7267: } else {
7268: document.getElementById('newresourcetitle').type = 'hidden';
7269: document.getElementById('newresourcetitle').value = '';
7270: if (document.getElementById('newrestitle')) {
7271: document.getElementById('newrestitle').innerHTML = '';
7272: }
7273: }
7274: }
7275: break;
7276: }
7277: }
7278: }
7279: }
7280:
7281: function toggleWithTemplate(form) {
7282: if (form.newresusetemp.length) {
7283: for (var i=0; i<form.newresusetemp.length; i++) {
7284: if (form.newresusetemp[i].checked) {
7285: if (document.getElementById('newrestemplate')) {
7286: if (form.newresusetemp[i].value == '1') {
7287: document.getElementById('newrestemplate').style.display = 'inline';
7288: toggleExampleText();
7289: } else {
7290: form.tempcategory.selectedIndex = 0;
7291: select1template_changed();
7292: document.getElementById('newrestemplate').style.display = 'none';
7293: }
7294: }
7295: }
7296: }
7297: }
7298: }
7299:
7300: function toggleExampleText() {
7301: if (document.getElementById('newresexample')) {
7302: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7303: if (url == '') {
7304: document.getElementById('newresexample').style.fontWeight = 'normal';
7305: } else {
7306: document.getElementById('newresexample').style.fontWeight = 'bold';
7307: }
7308: }
7309: }
7310:
7311: function getExample(width,height,scrolling,transparency) {
7312: var url;
7313: if (document.courseresform.newresusetemp.length) {
7314: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7315: if (document.courseresform.newresusetemp[i].checked) {
7316: if (document.courseresform.newresusetemp[i].value == '1') {
7317: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7318: if (url == '') {
7319: alert('Pick a category and template');
7320: } else {
7321: url = url.replace("$londocroot","");
7322: url += '?inhibitmenu=yes';
7323: }
7324: }
7325: break;
7326: }
7327: }
7328: }
7329: if (url != '') {
7330: openMyModal(url,width,height,scrolling,transparency,'');
7331: }
7332: }
7333:
7334: function toggleImportCrsres(caller,dircount) {
7335: var disp = 'none';
7336: if (document.getElementById('importcrsresform')) {
7337: if (caller == 'res') {
7338: var numdirs = parseInt(dircount);
7339: var curr = document.getElementById('importcrsresform').style.display;
7340: if (curr == 'none') {
7341: disp='block';
7342: if (numdirs > 1) {
7343: select1res_changed();
7344: }
7345: }
7346: }
7347: document.getElementById('importcrsresform').style.display=disp;
7348: resize_scrollbox('contentscroll','1','0');
7349: }
7350: return;
7351: }
7352:
1.501 raeburn 7353: function makeims(imsform) {
7354: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7355: alert("$js_lt{'imsfile'}");
1.501 raeburn 7356: return;
7357: }
7358: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7359: alert("$js_lt{'imscms'}");
1.501 raeburn 7360: return;
7361: }
7362: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7363: imsform.submit();
7364: }
7365:
1.478 raeburn 7366: function updatePick(targetform,index,caller) {
1.537 raeburn 7367: var pickitem;
7368: var picknumitem;
7369: var picknumtext;
7370: if (index == 'all') {
7371: pickitem = document.getElementById('randompickall');
7372: picknumitem = document.getElementById('rpicknumall');
7373: picknumtext = document.getElementById('rpicktextall');
7374: } else {
7375: pickitem = document.getElementById('randompick_'+index);
7376: picknumitem = document.getElementById('rpicknum_'+index);
7377: picknumtext = document.getElementById('randompicknum_'+index);
7378: }
1.478 raeburn 7379: if (pickitem.checked) {
1.594 damieng 7380: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7381: if (picknum == '' || picknum == null) {
7382: if (caller == 'check') {
7383: pickitem.checked=false;
1.537 raeburn 7384: if (index == 'all') {
7385: picknumtext.innerHTML = '';
7386: if (caller == 'link') {
7387: propagateState(targetform,'rpicknum');
7388: }
7389: } else {
1.538 raeburn 7390: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7391: }
1.478 raeburn 7392: }
7393: } else {
7394: picknum.toString();
7395: var regexdigit=/^\\d+\$/;
7396: if (regexdigit.test(picknum)) {
7397: picknumitem.value = picknum;
1.537 raeburn 7398: if (index == 'all') {
1.538 raeburn 7399: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7400: if (caller == 'link') {
7401: propagateState(targetform,'rpicknum');
7402: }
7403: } else {
7404: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7405: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7406: }
1.478 raeburn 7407: } else {
7408: if (caller == 'check') {
1.537 raeburn 7409: if (index == 'all') {
7410: picknumtext.innerHTML = '';
7411: if (caller == 'link') {
7412: propagateState(targetform,'rpicknum');
7413: }
7414: } else {
7415: pickitem.checked=false;
1.538 raeburn 7416: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7417: }
1.478 raeburn 7418: }
7419: return;
7420: }
7421: }
7422: } else {
1.537 raeburn 7423: picknumitem.value = '';
7424: picknumtext.innerHTML = '';
7425: if (index == 'all') {
7426: if (caller == 'link') {
7427: propagateState(targetform,'rpicknum');
7428: }
7429: } else {
1.538 raeburn 7430: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7431: }
7432: }
7433: }
7434:
7435: function propagateState(form,param) {
7436: if (document.getElementById(param+'all')) {
7437: var setcheck = 0;
7438: var rpick = 0;
7439: if (param == 'rpicknum') {
7440: if (document.getElementById('randompickall')) {
7441: if (document.getElementById('randompickall').checked) {
7442: if (document.getElementById('rpicknumall')) {
7443: rpick = document.getElementById('rpicknumall').value;
7444: }
7445: }
7446: }
7447: } else {
7448: if (document.getElementById(param+'all').checked) {
7449: setcheck = 1;
7450: }
7451: }
1.538 raeburn 7452: var allidxlist;
7453: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7454: if (document.getElementById('all'+param+'idx')) {
7455: allidxlist = document.getElementById('all'+param+'idx').value;
7456: }
7457: var actions = new Array ('remove','cut','copy');
7458: for (var i=0; i<actions.length; i++) {
7459: if (actions[i] != param) {
7460: if (document.getElementById(actions[i]+'all')) {
7461: document.getElementById(actions[i]+'all').checked = false;
7462: }
7463: }
7464: }
7465: }
1.537 raeburn 7466: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7467: allidxlist = form.allidx.value;
7468: }
7469: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7470: allidxlist = form.allmapidx.value;
7471: }
7472: if ((allidxlist != '') && (allidxlist != null)) {
7473: var allidxs = allidxlist.split(',');
7474: if (allidxs.length > 1) {
7475: for (var i=0; i<allidxs.length; i++) {
7476: if (document.getElementById(param+'_'+allidxs[i])) {
7477: if (param == 'rpicknum') {
7478: if (document.getElementById('randompick_'+allidxs[i])) {
7479: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7480: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7481: if (rpick > 0) {
7482: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7483: } else {
7484: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7485: }
7486: }
7487: }
7488: } else {
1.537 raeburn 7489: if (setcheck == 1) {
7490: document.getElementById(param+'_'+allidxs[i]).checked = true;
7491: } else {
7492: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7493: if (param == 'randompick') {
7494: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7495: }
1.537 raeburn 7496: }
7497: }
7498: }
7499: }
1.538 raeburn 7500: if (setcheck == 1) {
7501: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7502: var actions = new Array('copy','cut','remove');
7503: for (var i=0; i<actions.length; i++) {
7504: var otheractions;
7505: var otheridxs;
7506: if (actions[i] === param) {
7507: continue;
7508: } else {
7509: if (document.getElementById('all'+actions[i]+'idx')) {
7510: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7511: otheridxs = otheractions.split(',');
7512: if (otheridxs.length > 1) {
7513: for (var j=0; j<otheridxs.length; j++) {
7514: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7515: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7516: }
1.537 raeburn 7517: }
7518: }
7519: }
1.538 raeburn 7520: }
7521: }
7522: }
7523: }
7524: }
7525: }
7526: }
7527: return;
7528: }
7529:
1.603 raeburn 7530: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7531: var canedit = '$canedit';
7532: if (canedit == '') {
7533: alert("$js_lt{'edri'}");
7534: return;
7535: }
1.539 raeburn 7536: var dosettings;
7537: var doaction;
1.538 raeburn 7538: var control = document.togglemultsettings;
7539: if (context == 'actions') {
7540: control = document.togglemultactions;
1.539 raeburn 7541: doaction = 1;
7542: } else {
7543: dosettings = 1;
1.538 raeburn 7544: }
1.539 raeburn 7545: if (control) {
7546: if (control.showmultpick.length) {
7547: for (var i=0; i<control.showmultpick.length; i++) {
7548: if (control.showmultpick[i].checked) {
7549: if (control.showmultpick[i].value == 1) {
7550: if (context == 'settings') {
7551: dosettings = 0;
7552: } else {
7553: doaction = 0;
1.538 raeburn 7554: }
7555: }
7556: }
1.537 raeburn 7557: }
7558: }
1.539 raeburn 7559: }
7560: if (context == 'settings') {
7561: if (dosettings == 1) {
1.538 raeburn 7562: targetform.changeparms.value=param;
7563: targetform.submit();
7564: }
1.537 raeburn 7565: }
1.539 raeburn 7566: if (context == 'actions') {
7567: if (doaction == 1) {
7568: targetform.cmd.value=param+'_'+index;
7569: targetform.folderpath.value=folderpath;
7570: targetform.markcopy.value=idx+':'+param;
7571: targetform.copyfolder.value=folder+'.'+container;
7572: if (param == 'remove') {
1.603 raeburn 7573: var doremove = 0;
7574: if (skip_confirm) {
7575: if (confirm_removal) {
7576: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7577: doremove = 1;
7578: }
7579: } else {
7580: doremove = 1;
7581: }
7582: } else {
7583: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7584: doremove = 1;
7585: }
7586: }
7587: if (doremove) {
1.539 raeburn 7588: targetform.markcopy.value='';
7589: targetform.copyfolder.value='';
7590: targetform.submit();
7591: }
7592: }
7593: if (param == 'cut') {
1.594 damieng 7594: 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 7595: targetform.submit();
7596: return;
7597: }
7598: }
7599: if (param == 'copy') {
7600: targetform.submit();
7601: return;
7602: }
7603: targetform.markcopy.value='';
7604: targetform.copyfolder.value='';
7605: targetform.cmd.value='';
7606: targetform.folderpath.value='';
7607: return;
7608: } else {
7609: if (document.getElementById(param+'_'+idx)) {
7610: item = document.getElementById(param+'_'+idx);
7611: if (item.type == 'checkbox') {
7612: if (item.checked) {
7613: item.checked = false;
7614: } else {
7615: item.checked = true;
7616: singleCheck(item,idx,param);
7617: }
7618: }
7619: }
7620: }
7621: }
1.537 raeburn 7622: return;
7623: }
7624:
1.538 raeburn 7625: function singleCheck(caller,idx,action) {
7626: actions = new Array('cut','copy','remove');
7627: if (caller.checked) {
7628: for (var i=0; i<actions.length; i++) {
7629: if (actions[i] != action) {
7630: if (document.getElementById(actions[i]+'_'+idx)) {
7631: if (document.getElementById(actions[i]+'_'+idx).checked) {
7632: document.getElementById(actions[i]+'_'+idx).checked = false;
7633: }
1.537 raeburn 7634: }
7635: }
7636: }
1.478 raeburn 7637: }
1.537 raeburn 7638: return;
1.478 raeburn 7639: }
7640:
1.334 muellerd 7641: function unselectInactive(nav) {
1.335 ehlerst 7642: currentNav = document.getElementById(nav);
7643: currentLis = currentNav.getElementsByTagName('LI');
7644: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7645: if (currentLis[i].className == 'goback') {
7646: currentLis[i].className = 'goback';
7647: } else {
7648: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7649: currentLis[i].className = 'right';
1.472 raeburn 7650: } else {
1.374 tempelho 7651: currentLis[i].className = 'i';
1.472 raeburn 7652: }
7653: }
1.335 ehlerst 7654: }
1.332 tempelho 7655: }
7656:
1.334 muellerd 7657: function hideAll(current, nav, data) {
1.335 ehlerst 7658: unselectInactive(nav);
1.570 raeburn 7659: if (current) {
7660: if (current.className == 'right'){
7661: current.className = 'right active'
7662: } else {
7663: current.className = 'active';
7664: }
1.374 tempelho 7665: }
1.335 ehlerst 7666: currentData = document.getElementById(data);
7667: currentDivs = currentData.getElementsByTagName('DIV');
7668: for (i = 0; i < currentDivs.length; i++) {
7669: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7670: currentDivs[i].style.display = 'none';
1.330 tempelho 7671: }
7672: }
1.335 ehlerst 7673: }
1.330 tempelho 7674:
1.374 tempelho 7675: function openTabs(pageId) {
7676: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7677: if(tabnav.length > 2 ){
1.389 tempelho 7678: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7679: currentLis = currentNav.getElementsByTagName('LI');
7680: for(i = 0; i< currentLis.length; i++){
7681: if(currentLis[i].className == 'active') {
1.375 tempelho 7682: funcString = currentLis[i].onclick.toString();
7683: tab = funcString.split('"');
1.420 onken 7684: if(tab.length < 2) {
7685: tab = funcString.split("'");
7686: }
1.375 tempelho 7687: currentData = document.getElementById(tab[1]);
7688: currentData.style.display = 'block';
1.374 tempelho 7689: }
7690: }
7691: }
7692: }
7693:
1.334 muellerd 7694: function showPage(current, pageId, nav, data) {
1.570 raeburn 7695: currstate = current.className;
1.334 muellerd 7696: hideAll(current, nav, data);
1.375 tempelho 7697: openTabs(pageId);
1.334 muellerd 7698: unselectInactive(nav);
1.570 raeburn 7699: if ((currstate == 'active') || (currstate == 'right active')) {
7700: if (currstate == 'active') {
7701: current.className = '';
7702: } else {
7703: current.className = 'right';
7704: }
7705: activeTab = '';
7706: toggleUpload();
7707: toggleMap();
1.606 raeburn 7708: toggleCrsRes();
7709: toggleImportCrsres();
1.570 raeburn 7710: resize_scrollbox('contentscroll','1','0');
7711: return;
7712: } else {
7713: current.className = 'active';
7714: }
1.330 tempelho 7715: currentData = document.getElementById(pageId);
7716: currentData.style.display = 'block';
1.458 raeburn 7717: activeTab = pageId;
1.501 raeburn 7718: toggleUpload();
1.503 raeburn 7719: toggleMap();
1.606 raeburn 7720: toggleCrsRes();
7721: toggleImportCrsres();
1.433 raeburn 7722: if (nav == 'mainnav') {
7723: var storedpath = "$docs_folderpath";
1.434 raeburn 7724: var storedpage = "$main_container_page";
1.433 raeburn 7725: var reg = new RegExp("^supplemental");
7726: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7727: if (storedpage == 1) {
7728: document.simpleedit.folderpath.value = '';
7729: document.uploaddocument.folderpath.value = '';
7730: } else {
7731: if (reg.test(storedpath)) {
7732: document.simpleedit.folderpath.value = '$toplevelmain';
7733: document.uploaddocument.folderpath.value = '$toplevelmain';
7734: document.newext.folderpath.value = '$toplevelmain';
7735: } else {
7736: document.simpleedit.folderpath.value = storedpath;
7737: document.uploaddocument.folderpath.value = storedpath;
7738: document.newext.folderpath.value = storedpath;
7739: }
1.433 raeburn 7740: }
7741: } else {
1.434 raeburn 7742: if (reg.test(storedpath)) {
7743: document.simpleedit.folderpath.value = storedpath;
7744: document.supuploaddocument.folderpath.value = storedpath;
7745: document.supnewext.folderpath.value = storedpath;
7746: } else {
1.433 raeburn 7747: document.simpleedit.folderpath.value = '$toplevelsupp';
7748: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7749: document.supnewext.folderpath.value = '$toplevelsupp';
7750: }
7751: }
7752: }
1.485 raeburn 7753: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7754: return false;
7755: }
1.329 droeschl 7756:
1.472 raeburn 7757: function toContents(jumpto) {
7758: var newurl = '$backtourl';
1.525 raeburn 7759: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7760: newurl = newurl+'?postdata='+jumpto;
7761: }
7762: location.href=newurl;
7763: }
7764:
1.538 raeburn 7765: function togglePick(caller,value) {
7766: var disp = 'none';
7767: if (document.getElementById('multi'+caller)) {
7768: var curr = document.getElementById('multi'+caller).style.display;
7769: if (value == 1) {
7770: disp='block';
7771: }
7772: if (curr == disp) {
7773: return;
7774: }
7775: document.getElementById('multi'+caller).style.display=disp;
7776: if (value == 1) {
1.594 damieng 7777: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7778: } else {
7779: document.getElementById('more'+caller).innerHTML = '';
7780: }
7781: if (caller == 'actions') {
7782: setClass(value);
7783: setBoxes(value);
7784: }
7785: }
7786: var showButton = multiSettings();
7787: if (showButton != 1) {
7788: showButton = multiActions();
7789: }
7790: if (document.getElementById('multisave')) {
7791: if (showButton == 1) {
7792: document.getElementById('multisave').style.display='block';
7793: } else {
7794: document.getElementById('multisave').style.display='none';
7795: }
7796: }
7797: resize_scrollbox('contentscroll','1','1');
7798: return;
7799: }
7800:
7801: function toggleCheckUncheck(caller,more) {
7802: if (more == 1) {
1.594 damieng 7803: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 7804: document.getElementById('allfields'+caller).style.display='block';
7805: } else {
1.594 damieng 7806: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7807: document.getElementById('allfields'+caller).style.display='none';
7808: }
7809: resize_scrollbox('contentscroll','1','1');
7810: }
7811:
7812: function multiSettings() {
7813: var inuse = 0;
7814: var settingsform = document.togglemultsettings;
7815: if (settingsform.showmultpick.length > 1) {
7816: for (var i=0; i<settingsform.showmultpick.length; i++) {
7817: if (settingsform.showmultpick[i].checked) {
7818: if (settingsform.showmultpick[i].value == 1) {
7819: inuse = 1;
7820: }
7821: }
7822: }
7823: }
7824: return inuse;
7825: }
7826:
7827: function multiActions() {
7828: var inuse = 0;
7829: var actionsform = document.togglemultactions;
7830: if (actionsform.showmultpick.length > 1) {
7831: for (var i=0; i<actionsform.showmultpick.length; i++) {
7832: if (actionsform.showmultpick[i].checked) {
7833: if (actionsform.showmultpick[i].value == 1) {
7834: inuse = 1;
7835: }
7836: }
7837: }
7838: }
7839: return inuse;
7840: }
7841:
7842: function checkSubmits() {
7843: var numchanges = 0;
7844: var form = document.saveactions;
7845: var doactions = multiActions();
1.542 raeburn 7846: var cutwarnings = 0;
7847: var remwarnings = 0;
1.603 raeburn 7848: var removalinfo = 0;
1.538 raeburn 7849: if (doactions == 1) {
7850: var remidxlist = document.cumulativeactions.allremoveidx.value;
7851: if ((remidxlist != '') && (remidxlist != null)) {
7852: var remidxs = remidxlist.split(',');
7853: for (var i=0; i<remidxs.length; i++) {
7854: if (document.getElementById('remove_'+remidxs[i])) {
7855: if (document.getElementById('remove_'+remidxs[i]).checked) {
7856: form.multiremove.value += remidxs[i]+',';
7857: numchanges ++;
1.542 raeburn 7858: if (document.getElementById('skip_remove_'+remidxs[i])) {
7859: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7860: remwarnings ++;
7861: }
7862: }
1.603 raeburn 7863: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7864: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7865: removalinfo ++;
7866: }
7867: }
1.537 raeburn 7868: }
7869: }
1.538 raeburn 7870: }
7871: }
7872: var cutidxlist = document.cumulativeactions.allcutidx.value;
7873: if ((cutidxlist != '') && (cutidxlist != null)) {
7874: var cutidxs = cutidxlist.split(',');
7875: for (var i=0; i<cutidxs.length; i++) {
7876: if (document.getElementById('cut_'+cutidxs[i])) {
7877: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7878: form.multicut.value += cutidxs[i]+',';
7879: numchanges ++;
1.542 raeburn 7880: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7881: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7882: cutwarnings ++;
7883: }
7884: }
1.537 raeburn 7885: }
7886: }
7887: }
7888: }
1.538 raeburn 7889: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7890: if ((copyidxlist != '') && (copyidxlist != null)) {
7891: var copyidxs = copyidxlist.split(',');
7892: for (var i=0; i<copyidxs.length; i++) {
7893: if (document.getElementById('copy_'+copyidxs[i])) {
7894: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7895: form.multicopy.value += copyidxs[i]+',';
7896: numchanges ++;
7897: }
7898: }
7899: }
7900: }
7901: if (numchanges > 0) {
7902: form.multichange.value = numchanges;
7903: }
1.537 raeburn 7904: }
1.538 raeburn 7905: var dosettings = multiSettings();
1.543 raeburn 7906: var haschanges = 0;
1.538 raeburn 7907: if (dosettings == 1) {
7908: form.allencrypturl.value = '';
7909: form.allhiddenresource.value = '';
1.543 raeburn 7910: form.changeparms.value = 'all';
7911: var patt=new RegExp(",\$");
1.538 raeburn 7912: var allidxlist = document.cumulativesettings.allidx.value;
7913: if ((allidxlist != '') && (allidxlist != null)) {
7914: var allidxs = allidxlist.split(',');
7915: if (allidxs.length > 1) {
7916: for (var i=0; i<allidxs.length; i++) {
7917: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7918: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7919: form.allhiddenresource.value += allidxs[i]+',';
7920: }
7921: }
7922: if (document.getElementById('encrypturl_'+allidxs[i])) {
7923: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7924: form.allencrypturl.value += allidxs[i]+',';
7925: }
7926: }
7927: }
1.543 raeburn 7928: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7929: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 7930: }
1.538 raeburn 7931: }
7932: form.allrandompick.value = '';
7933: form.allrandomorder.value = '';
7934: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7935: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7936: var allmapidxs = allmapidxlist.split(',');
7937: for (var i=0; i<allmapidxs.length; i++) {
7938: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7939: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7940: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7941: if ((randompick.checked) && (rpicknum.value != '')) {
7942: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7943: }
7944: if (randorder.checked) {
7945: form.allrandomorder.value += allmapidxs[i]+',';
7946: }
1.537 raeburn 7947: }
1.543 raeburn 7948: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7949: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7950: }
7951: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7952: haschanges = 1;
7953: }
7954: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7955: haschanges = 1;
7956: }
7957: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7958: haschanges = 1;
7959: }
7960: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7961: haschanges = 1;
1.537 raeburn 7962: }
7963: }
1.543 raeburn 7964: if (doactions == 1) {
1.542 raeburn 7965: if (numchanges > 0) {
1.603 raeburn 7966: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 7967: if (remwarnings > 0) {
1.594 damieng 7968: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 7969: return false;
7970: }
7971: }
1.603 raeburn 7972: if (removalinfo > 0) {
7973: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7974: return false;
7975: }
7976: }
1.542 raeburn 7977: if (cutwarnings > 0) {
1.594 damieng 7978: 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 7979: return false;
7980: }
7981: }
7982: }
7983: form.submit();
7984: return true;
1.543 raeburn 7985: }
7986: }
7987: if (dosettings == 1) {
7988: if (haschanges == 1) {
1.542 raeburn 7989: form.submit();
7990: return true;
7991: }
1.543 raeburn 7992: }
7993: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 7994: alert("$js_lt{'noor'}");
1.543 raeburn 7995: } else {
7996: if (dosettings == 1) {
1.594 damieng 7997: alert("$js_lt{'noch'}");
1.543 raeburn 7998: } else {
1.594 damieng 7999: alert("$js_lt{'noac'}");
1.543 raeburn 8000: }
8001: }
1.538 raeburn 8002: return false;
8003: }
8004:
8005: function setClass(value) {
8006: var cutclass = 'LC_docs_cut';
8007: var copyclass = 'LC_docs_copy';
8008: var removeclass = 'LC_docs_remove';
8009: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8010: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8011: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8012: var links = document.getElementsByTagName('a');
8013: for (var i=0; i<links.length; i++) {
8014: var classes = links[i].className;
8015: if (cutreg.test(classes)) {
8016: links[i].className = cutclass;
8017: if (value == 1) {
8018: links[i].className += " LC_menubuttons_link";
8019: }
8020: } else {
8021: if (copyreg.test(classes)) {
8022: links[i].className = copyclass;
8023: if (value == 1) {
8024: links[i].className += " LC_menubuttons_link";
8025: }
8026: } else {
8027: if (removereg.test(classes)) {
8028: links[i].className = removeclass;
8029: if (value == 1) {
8030: links[i].className += " LC_menubuttons_link";
8031: }
8032: }
8033: }
8034: }
8035: }
8036: return;
1.537 raeburn 8037: }
8038:
1.538 raeburn 8039: function setBoxes(value) {
8040: var remidxlist = document.cumulativeactions.allremoveidx.value;
8041: if ((remidxlist != '') && (remidxlist != null)) {
8042: var remidxs = remidxlist.split(',');
8043: for (var i=0; i<remidxs.length; i++) {
8044: if (document.getElementById('remove_'+remidxs[i])) {
8045: var item = document.getElementById('remove_'+remidxs[i]);
8046: if (value == 1) {
8047: item.className = 'LC_docs_remove';
8048: } else {
8049: item.className = 'LC_hidden';
8050: }
8051: }
8052: }
8053: }
8054: var cutidxlist = document.cumulativeactions.allcutidx.value;
8055: if ((cutidxlist != '') && (cutidxlist != null)) {
8056: var cutidxs = cutidxlist.split(',');
8057: for (var i=0; i<cutidxs.length; i++) {
8058: if (document.getElementById('cut_'+cutidxs[i])) {
8059: var item = document.getElementById('cut_'+cutidxs[i]);
8060: if (value == 1) {
8061: item.className = 'LC_docs_cut';
8062: } else {
8063: item.className = 'LC_hidden';
8064: }
8065: }
1.537 raeburn 8066: }
8067: }
1.538 raeburn 8068: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8069: if ((copyidxlist != '') && (copyidxlist != null)) {
8070: var copyidxs = copyidxlist.split(',');
8071: for (var i=0; i<copyidxs.length; i++) {
8072: if (document.getElementById('copy_'+copyidxs[i])) {
8073: var item = document.getElementById('copy_'+copyidxs[i]);
8074: if (value == 1) {
8075: item.className = 'LC_docs_copy';
8076: } else {
8077: item.className = 'LC_hidden';
8078: }
8079: }
1.537 raeburn 8080: }
8081: }
8082: return;
8083: }
8084:
1.606 raeburn 8085: function validImportCrsRes() {
8086: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8087: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8088: if ((fname == '') || (fname == null)) {
8089: alert("$js_lt{'nofi'}");
8090: return false;
8091: }
8092: var url = '/res/$coursedom/$coursenum/';
8093: if (path && path != '/') {
8094: url += path+'/';
8095: }
8096: if (fname != '') {
8097: url += fname;
8098: }
8099: var title = document.crsresimportform.crsrestitle.value;
8100: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8101: return true;
8102: }
8103:
8104: function validateNewRes(caller) {
8105: if (caller == 'single') {
8106: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8107: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8108: var resname = document.courseresform.newresourcename.value;
8109: }
8110: }
8111:
1.611 raeburn 8112: ENDSCRIPT
1.329 droeschl 8113: }
1.457 raeburn 8114:
1.483 raeburn 8115: sub history_tab_js {
8116: return <<"ENDHIST";
8117: function toggleHistoryDisp(choice) {
8118: document.docslogform.docslog.value = choice;
8119: document.docslogform.submit();
8120: return;
8121: }
8122:
8123: ENDHIST
8124: }
8125:
1.484 raeburn 8126: sub inject_data_js {
8127: return <<ENDINJECT;
8128:
8129: function injectData(current, hiddenField, name, value) {
8130: currentElement = document.getElementById(hiddenField);
8131: currentElement.name = name;
8132: currentElement.value = value;
8133: current.submit();
8134: }
8135:
8136: ENDINJECT
8137: }
8138:
8139: sub dump_switchserver_js {
8140: my @hosts = @_;
1.594 damieng 8141: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8142: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8143: swit => 'Switch server?',
1.594 damieng 8144: );
8145: my %html_js_lt = &Apache::lonlocal::texthash(
8146: swit => 'Switch server?',
1.568 raeburn 8147: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8148: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8149: chos => 'Choose server',
8150: );
1.594 damieng 8151: &js_escape(\%js_lt);
8152: &html_escape(\%html_js_lt);
8153: &js_escape(\%html_js_lt);
1.484 raeburn 8154: my $role = $env{'request.role'};
8155: my $js = <<"ENDSWJS";
8156: <script type="text/javascript">
8157: function write_switchserver() {
8158: var server;
8159: if (document.setserver.posshosts.length > 0) {
8160: for (var i=0; i<document.setserver.posshosts.length; i++) {
8161: if (document.setserver.posshosts[i].checked) {
8162: server = document.setserver.posshosts[i].value;
8163: }
8164: }
8165: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8166: }
8167: window.close();
8168: }
8169: </script>
8170:
8171: ENDSWJS
8172:
8173: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8174: {'only_body' => 1,
8175: 'js_ready' => 1,});
8176: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8177:
8178: my $hostpicker;
8179: my $count = 0;
8180: foreach my $host (sort(@hosts)) {
8181: my $checked;
8182: if ($count == 0) {
8183: $checked = ' checked="checked"';
8184: }
8185: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8186: $host.'"'.$checked.' />'.$host.'</label> ';
8187: $count++;
8188: }
8189:
8190: return <<"ENDSWITCHJS";
8191:
8192: function dump_needs_switchserver(url) {
8193: if (url!='' && url!= null) {
1.594 damieng 8194: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8195: go(url);
8196: }
8197: }
8198: return;
8199: }
8200:
8201: function choose_switchserver_window() {
8202: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8203: newWindow.document.open();
8204: newWindow.document.writeln('$startpage');
1.594 damieng 8205: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8206: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8207: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8208: '<form name="setserver" method="post" action="" \\/>\\n'+
8209: '$hostpicker\\n'+
8210: '<br \\/><br \\/>\\n'+
1.594 damieng 8211: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8212: 'onclick="write_switchserver();" \\/>\\n'+
8213: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8214: newWindow.document.writeln('$endpage');
8215: newWindow.document.close();
8216: newWindow.focus();
8217: }
8218:
8219: ENDSWITCHJS
8220: }
8221:
8222: sub makedocslogform {
8223: my ($formelems,$docslog) = @_;
8224: return <<"LOGSFORM";
8225: <form action="/adm/coursedocs" method="post" name="docslogform">
8226: <input type="hidden" name="docslog" value="$docslog" />
8227: $formelems
8228: </form>
8229: LOGSFORM
8230: }
8231:
8232: sub makesimpleeditform {
8233: my ($formelems) = @_;
8234: return <<"SIMPFORM";
8235: <form name="simpleedit" method="post" action="/adm/coursedocs">
8236: <input type="hidden" name="importdetail" value="" />
8237: $formelems
8238: </form>
8239: SIMPFORM
8240: }
8241:
1.606 raeburn 8242: sub makenewproblem {
8243: my ($r,$coursedom,$coursenum) = @_;
8244: # Creating a new problem
8245: my ($redirect,$error);
8246: if ($env{'form.authorrole'}) {
8247: my ($newsubdir,$filename);
8248: if ($env{'form.newsubdir'}) {
8249: if ($env{'form.newsubdirname'} ne '') {
8250: $newsubdir = $env{'form.newsubdirname'};
8251: }
8252: }
8253: if ($env{'form.newresourcename'}) {
8254: $filename = $env{'form.newresourcename'};
8255: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8256: $filename =~ s/`//g;
8257: $filename =~ s{/\.\./}{_}g;
8258: $filename =~ s/\.+/./g;
8259: $filename =~ s{/+}{_}g;
8260: if ($filename ne '') {
8261: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8262: if (($ext) && ($ext ne '.problem')) {
8263: $filename = $name.'.problem';
8264: } elsif ($ext eq '') {
8265: $filename .= '.problem';
8266: }
8267: my $docroot = $r->dir_config('lonDocRoot');
8268: my @ids=&Apache::lonnet::current_machine_ids();
8269: if ($env{'form.authorrole'} eq 'author') {
8270: if ($env{'user.author'}) {
8271: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8272: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8273: my $path = $docroot.$url;
8274: my $subdir = $env{'form.authorpath'};
8275: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8276: }
8277: }
8278: } elsif ($env{'form.authorrole'} eq 'course') {
8279: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8280: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8281: my $url = "/priv/$coursedom/$coursenum";
8282: my $path=$docroot.$url;
8283: my $subdir = $env{'form.authorpath'};
8284: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8285: if ($redirect) {
8286: my $rightsfile = 'default.rights';
8287: my $sourcerights = "$path/$rightsfile";
8288: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8289: my $now = time;
8290: if (!-e $sourcerights) {
8291: my $cid = $coursedom.'_'.$coursenum;
8292: if (open(my $fh,">$sourcerights")) {
8293: print $fh <<END;
8294: <accessrule effect="deny" realm="" type="course" role="" />
8295: <accessrule effect="allow" realm="$cid" type="course" role="" />
8296: END
8297: close($fh);
8298: }
8299: }
8300: if (!-e "$sourcerights.meta") {
8301: if (open(my $fh,">$sourcerights.meta")) {
8302: my $author=$env{'environment.firstname'}.' '.
8303: $env{'environment.middlename'}.' '.
8304: $env{'environment.lastname'}.' '.
8305: $env{'environment.generation'};
8306: $author =~ s/\s+$//;
8307: print $fh <<"END";
8308:
8309: <abstract></abstract>
8310: <author>$author</author>
8311: <authorspace>$coursenum:$coursedom</authorspace>
8312: <copyright>private</copyright>
8313: <creationdate>$now</creationdate>
8314: <customdistributionfile></customdistributionfile>
8315: <dependencies></dependencies>
8316: <domain>$coursedom</domain>
8317: <highestgradelevel>0</highestgradelevel>
8318: <keywords></keywords>
8319: <language>notset </language>
8320: <lastrevisiondate>$now</lastrevisiondate>
8321: <lowestgradelevel>0</lowestgradelevel>
8322: <mime>rights</mime>
8323: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8324: <notes></notes>
8325: <obsolete></obsolete>
8326: <obsoletereplacement></obsoletereplacement>
8327: <owner>$coursenum:$coursedom</owner>
8328: <rule>deny:::course,allow:$cid::course</rule>
8329: <sourceavail></sourceavail>
8330: <standards></standards>
8331: <subject></subject>
8332: <title></title>
8333: END
8334: close($fh);
8335: }
8336: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8337: if (!-e "$docroot/res/$coursedom") {
8338: mkdir("$docroot/res/$coursedom",0755);
8339: }
8340: if (!-e "$docroot/res/$coursedom/$coursenum") {
8341: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8342: }
8343: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8344: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8345: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8346: }
8347: }
8348: }
8349: if ($env{'form.newresourceadd'}) {
8350: my $template = $env{'form.template'};
8351: my $source = $docroot.$redirect;
8352: my $target = $redirect;
8353: $target =~ s{^/priv/}{/res/};
8354: $target = $docroot.$target;
8355: if (!-e $source) {
8356: my $copyfrom;
8357: if ($template) {
8358: my %templates;
8359: my @files = &Apache::lonhomework::get_template_list('problem');
8360: foreach my $poss (@files) {
8361: if (ref($poss) eq 'ARRAY') {
8362: if ($template eq $poss->[0]) {
8363: $templates{$template} = 1;
8364: last;
8365: }
8366: }
8367: }
8368: if ($templates{$template}) {
8369: $copyfrom = $template;
8370: }
8371: }
8372: unless ($copyfrom) {
8373: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8374: }
8375: &File::Copy::copy($copyfrom,$source);
8376: }
8377: if (!-e "$source.meta") {
8378: my $cid = $coursedom.'_'.$coursenum;
8379: my $now = time;
8380: if (open(my $fh,">$source.meta")) {
8381: my $author=$env{'environment.firstname'}.' '.
8382: $env{'environment.middlename'}.' '.
8383: $env{'environment.lastname'}.' '.
8384: $env{'environment.generation'};
8385: $author =~ s/\s+$//;
8386: my $title = $env{'form.newresourcetitle'};
8387: $title =~ s/^\s+|\s+$//g;
8388: print $fh <<END;
8389:
8390: <abstract></abstract>
8391: <author>$author</author>
8392: <authorspace>$coursenum:$coursedom</authorspace>
8393: <copyright>custom</copyright>
8394: <creationdate>$now</creationdate>
8395: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8396: <dependencies></dependencies>
8397: <domain>$coursedom</domain>
8398: <highestgradelevel>0</highestgradelevel>
8399: <keywords></keywords>
8400: <language>notset </language>
8401: <lastrevisiondate>$now</lastrevisiondate>
8402: <lowestgradelevel>0</lowestgradelevel>
8403: <mime>problem</mime>
8404: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8405: <notes></notes>
8406: <obsolete></obsolete>
8407: <obsoletereplacement></obsoletereplacement>
8408: <owner>$coursenum:$coursedom</owner>
8409: <sourceavail></sourceavail>
8410: <standards></standards>
8411: <subject></subject>
8412: <title>$title</title>
8413: END
8414: close($fh);
8415: }
8416: }
8417: }
8418: }
8419: }
8420: } else {
8421: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8422: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8423: if (grep(/^\Q$rolehome\E$/,@ids)) {
8424: my $now = time;
8425: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8426: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8427: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8428: my $url = "/priv/$audom/$auname";
8429: my $path = $r->dir_config('lonDocRoot').$url;
8430: my $subdir = $env{'form.authorpath'};
8431: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8432: }
8433: }
8434: }
8435: }
8436: }
8437: }
8438: }
8439: return ($redirect,$error);
8440: }
8441:
8442: sub finishnewprob {
8443: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8444: unless (-d $path) {
8445: unless (mkdir($path,02770)) {
8446: return;
8447: }
8448: }
1.606 raeburn 8449: my $redirect;
8450: if ($subdir ne '/') {
8451: $subdir = &cleandir($subdir);
8452: if (($subdir ne '') && (-d "$path/$subdir")) {
8453: $path .= "/$subdir";
8454: $url .= "/$subdir";
8455: }
8456: }
8457: my $dest;
8458: if ($newsubdir ne '') {
8459: $newsubdir = &cleandir($newsubdir);
8460: }
8461: if ($newsubdir ne '') {
8462: if (-d "$path/$newsubdir") {
8463: $dest = "$path/$newsubdir/$filename";
8464: } else {
8465: my $dirok;
8466: unless (-e "$path/$newsubdir") {
8467: if (mkdir("$path/$newsubdir",02770)) {
8468: if (chmod(02770,"$path/$newsubdir")) {
8469: $dirok = 1;
8470: }
8471: }
8472: }
8473: if ($dirok) {
8474: $dest = "$path/$newsubdir/$filename";
8475: }
8476: }
8477: if (($dest ne '') && (!-e $dest)) {
8478: $redirect = "$url/$newsubdir/$filename";
8479: }
8480: } else {
8481: $dest = "$path/$filename";
8482: if (($dest ne '') && (!-e $dest)) {
8483: $redirect = "$url/$filename";
8484: }
8485: }
8486: return $redirect;
8487: }
8488:
8489: sub cleandir {
8490: my ($dir) = @_;
8491: $dir =~ s/^\s+//;
8492: $dir =~ s/\s+$//;
8493: $dir =~ s/\.+//g;
8494: $dir =~ s/[\#\?&%\":]//g;
8495: return $dir;
8496: }
8497:
1.329 droeschl 8498: 1;
8499: __END__
8500:
8501:
8502: =head1 NAME
8503:
8504: Apache::londocs.pm
8505:
8506: =head1 SYNOPSIS
8507:
8508: This is part of the LearningOnline Network with CAPA project
8509: described at http://www.lon-capa.org.
8510:
8511: =head1 SUBROUTINES
8512:
8513: =over
8514:
8515: =item %help=()
8516:
8517: Available help topics
8518:
8519: =item mapread()
8520:
1.344 bisitz 8521: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8522: @order and @resources, determines status
8523: sets @order - pointer to resources in right order
8524: sets @resources - array with the resources with correct idx
8525:
8526: =item authorhosts()
8527:
8528: Return hash with valid author names
8529:
8530: =item clean()
8531:
8532: =item dumpcourse()
8533:
8534: Actually dump course
8535:
8536: =item group_import()
8537:
8538: Imports the given (name, url) resources into the course
8539: coursenum, coursedom, and folder must precede the list
8540:
8541: =item breadcrumbs()
8542:
8543: =item log_docs()
8544:
8545: =item docs_change_log()
8546:
8547: =item update_paste_buffer()
8548:
8549: =item print_paste_buffer()
8550:
8551: =item do_paste_from_buffer()
8552:
1.538 raeburn 8553: =item do_buffer_empty()
8554:
8555: =item clear_from_buffer()
8556:
1.492 raeburn 8557: =item get_newmap_url()
8558:
8559: =item dbcopy()
8560:
8561: =item uniqueness_check()
8562:
8563: =item contained_map_check()
8564:
8565: =item url_paste_fixups()
8566:
8567: =item apply_fixups()
8568:
8569: =item copy_dependencies()
8570:
1.329 droeschl 8571: =item update_parameter()
8572:
8573: =item handle_edit_cmd()
8574:
8575: =item editor()
8576:
8577: =item process_file_upload()
8578:
8579: =item process_secondary_uploads()
8580:
8581: =item is_supplemental_title()
8582:
8583: =item entryline()
8584:
8585: =item tiehash()
8586:
8587: =item untiehash()
8588:
8589: =item checkonthis()
8590:
8591: check on this
8592:
8593: =item verifycontent()
8594:
8595: Verify Content
8596:
8597: =item devalidateversioncache() & checkversions()
8598:
8599: Check Versions
8600:
8601: =item mark_hash_old()
8602:
8603: =item is_hash_old()
8604:
8605: =item changewarning()
8606:
8607: =item init_breadcrumbs()
8608:
8609: Breadcrumbs for special functions
8610:
1.484 raeburn 8611: =item create_list_elements()
8612:
8613: =item create_form_ul()
8614:
8615: =item startContentScreen()
8616:
8617: =item endContentScreen()
8618:
8619: =item supplemental_base()
8620:
8621: =item embedded_form_elems()
8622:
8623: =item embedded_destination()
8624:
8625: =item return_to_editor()
8626:
8627: =item decompression_info()
8628:
8629: =item decompression_phase_one()
8630:
8631: =item decompression_phase_two()
8632:
8633: =item remove_archive()
8634:
8635: =item generate_admin_menu()
8636:
8637: =item generate_edit_table()
8638:
8639: =item editing_js()
8640:
8641: =item history_tab_js()
8642:
8643: =item inject_data_js()
8644:
8645: =item dump_switchserver_js()
8646:
1.485 raeburn 8647: =item resize_scrollbox_js()
1.484 raeburn 8648:
8649: =item makedocslogform()
8650:
1.485 raeburn 8651: =item makesimpleeditform()
8652:
1.329 droeschl 8653: =back
8654:
8655: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>