Annotation of loncom/interface/londocs.pm, revision 1.622
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.622 ! raeburn 4: # $Id: londocs.pm,v 1.621 2017/02/18 23:39:15 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.329 droeschl 48: use HTML::Entities;
1.488 raeburn 49: use HTML::TokeParser;
1.329 droeschl 50: use GDBM_File;
1.578 raeburn 51: use File::MMagic;
1.606 raeburn 52: use File::Copy;
1.329 droeschl 53: use Apache::lonlocal;
54: use Cwd;
55: use LONCAPA qw(:DEFAULT :match);
56:
57: my $iconpath;
58:
59: my %hash;
60:
61: my $hashtied;
62: my %alreadyseen=();
63:
64: my $hadchanges;
1.557 raeburn 65: my $suppchanges;
1.329 droeschl 66:
67:
68: my %help=();
69:
70:
71: sub mapread {
72: my ($coursenum,$coursedom,$map)=@_;
73: return
74: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
75: $map);
76: }
77:
78: sub storemap {
1.492 raeburn 79: my ($coursenum,$coursedom,$map,$contentchg)=@_;
80: my $report;
81: if (($contentchg) && ($map =~ /^default/)) {
82: $report = 1;
83: }
1.329 droeschl 84: my ($outtext,$errtext)=
85: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 86: $map,1,$report);
1.329 droeschl 87: if ($errtext) { return ($errtext,2); }
1.364 bisitz 88:
1.557 raeburn 89: if ($map =~ /^default/) {
90: $hadchanges=1;
91: } else {
92: $suppchanges=1;
93: }
1.329 droeschl 94: return ($errtext,0);
95: }
96:
97:
98:
99: sub authorhosts {
100: my %outhash=();
101: my $home=0;
102: my $other=0;
103: foreach my $key (keys(%env)) {
104: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
105: my $role=$1;
106: my $realm=$2;
107: my ($start,$end)=split(/\./,$env{$key});
108: if (($start) && ($start>time)) { next; }
109: if (($end) && (time>$end)) { next; }
110: my ($ca,$cd);
111: if ($1 eq 'au') {
112: $ca=$env{'user.name'};
113: $cd=$env{'user.domain'};
114: } else {
115: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
116: }
117: my $allowed=0;
118: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
119: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 120: foreach my $id (@ids) {
121: if ($id eq $myhome) {
122: $allowed=1;
123: last;
124: }
125: }
1.329 droeschl 126: if ($allowed) {
127: $home++;
1.484 raeburn 128: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 129: } else {
1.484 raeburn 130: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 131: $other++;
132: }
133: }
134: }
135: return ($home,$other,%outhash);
136: }
137:
138:
139: sub clean {
140: my ($title)=@_;
141: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 142: return $title;
1.329 droeschl 143: }
144:
1.617 raeburn 145: sub default_folderpath {
146: my ($coursenum,$coursedom,$navmapref) = @_;
147: return unless ($coursenum && $coursedom && ref($navmapref));
148: # Check if entire course is hidden and/or encrypted
149: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
150: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
151: unless (ref($$navmapref)) {
152: $$navmapref = Apache::lonnavmaps::navmap->new();
153: }
154: if (ref($$navmapref)) {
155: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
156: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
157: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
158: unless (@resources) {
159: $hiddenmap = 1;
160: unless ($env{'request.role.adv'}) {
161: $hiddentop = 1;
162: if ($env{'form.folder'}) {
163: undef($env{'form.folder'});
164: }
165: }
166: }
167: }
168: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
169: $encryptmap = 1;
170: }
171: }
172: unless ($hiddentop) {
173: $folderpath='default&'.&escape(&mt('Main Content')).
174: '::'.$hiddenmap.':'.$encryptmap.'::';
175: }
176: if (wantarray) {
177: return ($folderpath,$hiddentop);
178: } else {
179: return $folderpath;
180: }
181: }
1.329 droeschl 182:
183: sub dumpcourse {
184: my ($r) = @_;
1.408 raeburn 185: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 186: my ($starthash,$js);
187: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
188: $js = <<"ENDJS";
189: <script type="text/javascript">
190: // <![CDATA[
191:
192: function hide_searching() {
193: if (document.getElementById('searching')) {
194: document.getElementById('searching').style.display = 'none';
195: }
196: return;
197: }
198:
199: // ]]>
200: </script>
201: ENDJS
202: $starthash = {
203: add_entries => {'onload' => "hide_searching();"},
204: };
205: }
1.568 raeburn 206: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
207: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 208: $r->print(&startContentScreen('tools'));
1.329 droeschl 209: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 210: unless ($home) {
211: $r->print(&endContentScreen());
212: return '';
213: }
1.329 droeschl 214: my $origcrsid=$env{'request.course.id'};
215: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
216: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
217: # Do the dumping
1.484 raeburn 218: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
219: $r->print(&endContentScreen());
220: return '';
221: }
1.531 raeburn 222: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 223: $r->print('<h3>'.&mt('Copying Files').'</h3>');
224: my $title=$env{'form.authorfolder'};
225: $title=&clean($title);
1.567 raeburn 226: my ($navmap,$errormsg) =
227: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
228: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
229: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
230: my (%maps,%resources,%titles);
231: if (!ref($navmap)) {
232: $r->print($errormsg.
233: &endContentScreen());
234: return '';
235: } else {
236: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
237: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 238: }
1.567 raeburn 239: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
240: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
241: %newcontent,%has_simpleprobs);
242: foreach my $item (sort {$a <=> $b} (@todump)) {
243: my $name = $env{'form.namefor_'.$item};
244: if ($resources{$item}) {
245: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
246: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
247: $tocopy{$1} = $name;
248: $display{$item} = $1;
249: $lookup{$1} = $item;
250: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
251: $simpleproblems{$item} = {
252: symb => $resources{$item},
253: name => $name,
254: };
255: $display{$item} = 'simpleproblem_'.$name;
256: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
257: $has_simpleprobs{$1}{$id} = $item;
258: }
259: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
260: my $marker = $1;
261: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
262: $simplepages{$item} = {
263: res => $res,
264: title => $titles{$item},
265: db => $db_name,
266: marker => $marker,
267: symb => $resources{$item},
268: name => $name,
269: };
270: $display{$item} = '/'.$res;
271: }
272: } elsif ($maps{$item}) {
273: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
274: $tocopy{$1} = $name;
275: $display{$item} = $1;
276: $lookup{$1} = $item;
277: }
278: } else {
279: next;
280: }
281: }
1.329 droeschl 282: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
283: $crs=~s/\_/\//g;
1.567 raeburn 284: my $mm = new File::MMagic;
285: my $prefix = "/uploaded/$cdom/$cnum/";
286: %replacehash = %tocopy;
287: foreach my $item (sort(keys(%simpleproblems))) {
288: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
289: $newcontent{$display{$item}} = $content;
290: }
291: my $gateway = Apache::lonhtmlgateway->new('web');
292: foreach my $item (sort(keys(%simplepages))) {
293: if (ref($simplepages{$item}) eq 'HASH') {
294: my $pagetitle = $simplepages{$item}{'title'};
295: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
296: my %contents;
297: foreach my $field (keys(%fields)) {
298: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
299: my $name = $1;
300: my $msg = $fields{$field};
301: if ($name eq 'webreferences') {
302: if ($msg =~ m{^https?://}) {
303: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
304: }
305: } else {
306: $msg = &Encode::decode('utf8',$msg);
307: $msg = $gateway->process_outgoing_html($msg,1);
308: $contents{$name} = $msg;
309: }
310: } elsif ($field eq 'uploaded.photourl') {
311: my $marker = $simplepages{$item}{marker};
312: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
313: my $filepath = $1;
314: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
315: if ($fname ne '') {
316: $fname=~s/\.(\w+)$//;
317: my $ext=$1;
318: $fname = &clean($fname);
319: $fname.='.'.$ext;
320: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
321: $replacehash{$filepath} = $relpath.$fname;
322: $deps{$item}{$filepath} = 1;
323: }
324: }
325: }
326: }
327: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
328: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
329: my $content = '
330: <html>
331: <head>
332: <title>'.$pagetitle.'</title>
333: </head>
334: <body bgcolor="#ffffff">';
335: if ($contents{title}) {
336: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
337: }
338: if ($contents{image}) {
339: $content .= "\n".$contents{image};
340: }
341: if ($contents{content}) {
342: $content .= '
343: <div class="LC_Box">
1.577 bisitz 344: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 345: $contents{content}.'
346: </div>';
347: }
348: if ($contents{webreferences}) {
349: $content .= '
350: <div class="LC_Box">
1.577 bisitz 351: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 352: $contents{webreferences}.'
353: </div>';
354: }
355: $content .= '
356: </body>
357: </html>
358: ';
359: $newcontent{'/'.$simplepages{$item}{res}} = $content;
360: }
361: }
362: foreach my $item (keys(%tocopy)) {
363: unless ($item=~/\.(sequence|page)$/) {
364: my $currurlpath = $prefix.$item;
365: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
366: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
367: }
368: }
369: foreach my $num (sort {$a <=> $b} (@todump)) {
370: my $src = $display{$num};
371: next if ($src eq '');
372: my @needcopy = ();
373: if ($replacehash{$src}) {
374: push(@needcopy,$src);
375: if (ref($deps{$num}) eq 'HASH') {
376: foreach my $dep (sort(keys(%{$deps{$num}}))) {
377: if ($replacehash{$dep}) {
378: push(@needcopy,$dep);
379: }
380: }
381: }
382: } elsif ($src =~ /^simpleproblem_/) {
383: push(@needcopy,$src);
384: }
385: next if (@needcopy == 0);
386: my ($result,$depresult);
387: for (my $i=0; $i<@needcopy; $i++) {
388: my $item = $needcopy[$i];
389: my $newfilename;
390: if ($simpleproblems{$num}) {
391: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
392: } else {
393: $newfilename=$title.'/'.$replacehash{$item};
394: }
395: $newfilename=~s/\.(\w+)$//;
396: my $ext=$1;
397: $newfilename=&clean($newfilename);
398: $newfilename.='.'.$ext;
399: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
400: if ($newrelpath ne $replacehash{$item}) {
401: $replacehash{$item} = $newrelpath;
402: }
403: my @dirs=split(/\//,$newfilename);
404: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
405: my $makepath=$path;
406: my $fail;
407: my $origin;
408: for (my $i=0;$i<$#dirs;$i++) {
409: $makepath.='/'.$dirs[$i];
410: unless (-e $makepath) {
411: unless(mkdir($makepath,0755)) {
412: $fail = &mt('Directory creation failed.');
413: }
414: }
415: }
416: if ($i == 0) {
417: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
418: } else {
419: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
420: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
421: &mt('(dependency)').'</span>: ';
422: }
423: if (-e $path.'/'.$newfilename) {
424: $fail = &mt('Destination already exists -- not overwriting.');
425: } else {
426: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
427: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
428: ($item =~ /^simpleproblem_/)) {
429: print $fh $newcontent{$item};
430: } else {
431: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
432: if (-e $fileloc) {
433: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
434: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
435: (ref($has_simpleprobs{$item}) eq 'HASH')) {
436: my %changes = %{$has_simpleprobs{$item}};
437: my $content = &Apache::lonclonecourse::rewritefile(
438: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
439: (%replacehash,$crs => '')
440: );
441: my $updatedcontent = '';
442: my $parser = HTML::TokeParser->new(\$content);
443: $parser->attr_encoded(1);
444: while (my $token = $parser->get_token) {
445: if ($token->[0] eq 'S') {
446: if (($token->[1] eq 'resource') &&
447: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
448: ($changes{$token->[2]->{'id'}})) {
449: my $id = $token->[2]->{'id'};
450: $updatedcontent .= '<'.$token->[1];
451: foreach my $attrib (@{$token->[3]}) {
452: next unless ($attrib =~ /^(src|type|title|id)$/);
453: if ($attrib eq 'src') {
454: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
455: if ($file) {
456: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: } else {
461: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
462: }
463: }
464: $updatedcontent .= ' />'."\n";
465: } else {
466: $updatedcontent .= $token->[4]."\n";
467: }
468: } else {
469: $updatedcontent .= $token->[2];
470: }
471: }
472: print $fh $updatedcontent;
473: } else {
474: print $fh &Apache::lonclonecourse::rewritefile(
475: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
476: (%replacehash,$crs => '')
477: );
478: }
479: } else {
480: print $fh
481: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
482: }
483: } else {
484: $fail = &mt('Source does not exist.');
485: }
486: }
487: $fh->close();
488: } else {
489: $fail = &mt('Could not write to destination.');
490: }
491: }
492: my $text;
493: if ($fail) {
494: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
495: } else {
496: $text = '<span class="LC_success">'.&mt('ok').'</span>';
497: }
498: if ($i == 0) {
499: $result .= $text;
500: } else {
501: $depresult .= $text.'</li>';
502: }
503: }
504: $r->print($result);
505: if ($depresult) {
506: $r->print('<ul>'.$depresult.'</ul>');
507: }
508: }
509: } else {
510: my ($navmap,$errormsg) =
511: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
512: if (!ref($navmap)) {
513: $r->print($errormsg);
514: } else {
515: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
516: $r->rflush();
517: my ($preamble,$formname);
518: $formname = 'dumpdoc';
519: unless ($home==1) {
520: $preamble = '<div class="LC_left_float">'.
521: '<fieldset><legend>'.
522: &mt('Select the Authoring Space').
523: '</legend><select name="authorspace">';
1.329 droeschl 524: }
1.567 raeburn 525: my @orderspaces = ();
526: foreach my $key (sort(keys(%outhash))) {
527: if ($key=~/^home_(.+)$/) {
528: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
529: unshift(@orderspaces,$1);
530: } else {
531: push(@orderspaces,$1);
532: }
533: }
534: }
1.569 raeburn 535: if ($home>1) {
536: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
537: }
1.567 raeburn 538: foreach my $user (@orderspaces) {
1.329 droeschl 539: if ($home==1) {
1.567 raeburn 540: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 541: } else {
1.567 raeburn 542: $preamble .= '<option value="'.$user.'">'.$user.' - '.
543: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
544: }
1.329 droeschl 545: }
1.567 raeburn 546: unless ($home==1) {
547: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 548: }
1.567 raeburn 549: my $title=$origcrsdata{'description'};
550: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 551: $title=&clean($title);
1.567 raeburn 552: $preamble .= '<div class="LC_left_float">'.
553: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
554: '<input type="text" size="50" name="authorfolder" value="'.
555: $title.'" />'.
556: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
557: my %uploadedfiles;
558: &tiehash();
559: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
560: my ($ext)=($file=~/\.(\w+)$/);
561: # FIXME Check supplemental here
562: my $title=$hash{'title_'.$hash{
563: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
564: if (!$title) {
565: $title=$file;
566: } else {
567: $title=~s|/|_|g;
568: }
569: $title=~s/\.(\w+)$//;
570: $title=&clean($title);
571: $title.='.'.$ext;
572: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
573: $uploadedfiles{$file} = $title;
574: }
575: &untiehash();
576: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
577: undef,undef,$preamble,$home,\%uploadedfiles));
578: }
1.329 droeschl 579: }
1.484 raeburn 580: $r->print(&endContentScreen());
1.329 droeschl 581: }
582:
1.567 raeburn 583: sub recurse_html {
584: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
585: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
586: my (%allfiles,%codebase);
587: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
588: if (keys(%allfiles)) {
589: foreach my $dependency (keys(%allfiles)) {
590: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
591: my ($depurl,$relfile,$newcontainer);
592: if ($dependency =~ m{^/}) {
593: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
594: $relfile = $1;
595: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
596: $newcontainer = $1;
597: next if ($replacehash->{$newcontainer});
598: }
599: $depurl = $dependency;
600: } else {
601: next;
602: }
603: } else {
604: $relfile = $dependency;
605: $depurl = $currurlpath;
606: $depurl =~ s{[^/]+$}{};
607: $depurl .= $dependency;
608: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
609: }
610: next if ($relfile eq '');
611: my $newname = $replacehash->{$container};
612: $newname =~ s{[^/]+$}{};
613: $replacehash->{$newcontainer} = $newname.$relfile;
614: $deps->{$item}{$newcontainer} = 1;
615: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
616: my $depfile = &Apache::lonnet::filelocation('',$depurl);
617: my $type = $mm->checktype_filename($depfile);
618: if ($type eq 'text/html') {
619: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
620: }
621: }
622: }
623: }
624: return;
625: }
626:
1.329 droeschl 627: sub group_import {
1.598 raeburn 628: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 629: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
630: %removeparam,$importuploaded,$fixuperrors);
631: $allmaps = {};
1.329 droeschl 632: while (@files) {
633: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 634: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 635: && ($caller eq 'londocs')
636: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 637:
1.329 droeschl 638: my $errtext = '';
639: my $fatal = 0;
640: my $newmapstr = '<map>'."\n".
641: '<resource id="1" src="" type="start"></resource>'."\n".
642: '<link from="1" to="2" index="1"></link>'."\n".
643: '<resource id="2" src="" type="finish"></resource>'."\n".
644: '</map>';
645: $env{'form.output'}=$newmapstr;
646: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
647: 'output',$1.$2);
1.534 raeburn 648: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 649: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
650: $fatal = 2;
651: }
652: if ($fatal) {
653: return ($errtext,$fatal);
654: }
655: }
656: if ($url) {
1.598 raeburn 657: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) {
658: $url = $1;
659: my $marker = $2;
660: my $info = $3;
1.604 raeburn 661: my ($toolid,%toolhash,%toolsettings);
1.598 raeburn 662: my @toolinfo = split(/:/,$info);
663: if ($residx) {
1.604 raeburn 664: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 665: $toolid = $toolsettings{'id'};
666: } else {
1.604 raeburn 667: $toolid = shift(@toolinfo);
1.598 raeburn 668: }
669: $toolid =~ s/\D//g;
1.604 raeburn 670: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
671: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
672: $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'});
673: $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'});
1.598 raeburn 674: if (ref($ltitoolsref) eq 'HASH') {
1.604 raeburn 675: my @deleted;
1.598 raeburn 676: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
677: if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
678: $url =~ s/exttool$/exttools/;
679: }
680: $toolhash{'id'} = $toolid;
1.604 raeburn 681: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
682: if ($toolhash{'target'} eq 'window') {
683: foreach my $item ('width','height') {
684: $toolhash{$item} =~ s/^\s+//;
685: $toolhash{$item} =~ s/\s+$//;
686: }
687: }
688: } elsif ($residx) {
689: $toolhash{'target'} = $toolsettings{'target'};
690: if ($toolhash{'target'} eq 'window') {
691: $toolhash{'width'} = $toolsettings{'width'};
692: $toolhash{'height'} = $toolsettings{'height'};
693: }
694: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
695: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
696: if ($toolhash{'target'} eq 'window') {
697: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
698: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
699: }
700: }
1.598 raeburn 701: if ($toolhash{'target'} eq 'iframe') {
702: delete($toolhash{'width'});
703: delete($toolhash{'height'});
1.604 raeburn 704: if ($residx) {
705: if ($toolsettings{'width'}) {
706: push(@deleted,'width');
707: }
708: if ($toolsettings{'height'}) {
709: push(@deleted,'height');
710: }
711: }
712: }
713: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
714: foreach my $item ('label','title') {
715: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
716: $toolhash{'crs'.$item} =~ s/^\s+//;
717: $toolhash{'crs'.$item} =~ s/\s+$//;
718: if ($toolhash{'crs'.$item} eq '') {
719: delete($toolhash{'crs'.$item});
720: }
721: } else {
722: delete($toolhash{'crs'.$item});
723: }
724: if (($residx) && (exists($toolsettings{'crs'.$item}))) {
725: unless (exists($toolhash{'crs'.$item})) {
726: push(@deleted,'crs'.$item);
727: }
728: }
1.598 raeburn 729: }
730: }
731: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 732: if ($putres eq 'ok') {
733: if (@deleted) {
734: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
735: }
736: }
1.598 raeburn 737: }
738: }
739: }
1.529 raeburn 740: if (($caller eq 'londocs') &&
741: ($folder =~ /^default/)) {
1.534 raeburn 742: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 743: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
744: my $cid = $coursedom.'_'.$coursenum;
745: $allmaps =
746: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
747: $chome,$cid);
748: $donechk = 1;
749: }
750: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
751: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
752: \%addedmaps,\%hierarchy,\%titles,$allmaps);
753: $importuploaded = 1;
754: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
755: next if ($allmaps->{$url});
756: }
757: }
1.344 bisitz 758: if (!$residx
1.329 droeschl 759: || defined($LONCAPA::map::zombies[$residx])) {
760: $residx = &LONCAPA::map::getresidx($url,$residx);
761: push(@LONCAPA::map::order, $residx);
762: }
763: my $ext = 'false';
764: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
765: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 766: if ($name eq '') {
1.538 raeburn 767: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 768: }
769: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
770: my $filepath = $1;
771: my $fname = $name;
772: if ($fname =~ /^\W+$/) {
773: $fname = 'web';
774: } else {
775: $fname =~ s/\W/_/g;
776: }
1.599 damieng 777: if (length($fname) > 15) {
1.534 raeburn 778: $fname = substr($fname,0,14);
779: }
780: my $initialtext = &mt('Replace with your own content.');
781: my $newhtml = <<END;
1.545 raeburn 782: <html>
1.534 raeburn 783: <head>
784: <title>$name</title>
785: </head>
786: <body bgcolor="#ffffff">
787: $initialtext
788: </body>
789: </html>
790: END
791: $env{'form.output'}=$newhtml;
792: my $result =
793: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
794: 'output',
795: "$filepath/$residx/$fname.html");
796: if ($result =~ m{^/uploaded/}) {
797: $url = $result;
798: if ($filepath =~ /^supplemental/) {
799: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
800: $env{'user.domain'}.'___&&&___'.$name;
801: }
802: } else {
803: return (&mt('Failed to save new web page.'),1);
804: }
805: }
1.538 raeburn 806: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 807: $LONCAPA::map::resources[$residx] =
1.329 droeschl 808: join(':', ($name, $url, $ext, 'normal', 'res'));
809: }
810: }
1.529 raeburn 811: if ($importuploaded) {
812: my %import_errors;
813: my %updated = (
814: removefrommap => \%removefrommap,
815: removeparam => \%removeparam,
816: );
1.533 raeburn 817: my ($result,$msgsarray,$lockerror) =
818: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 819: if (keys(%import_errors) > 0) {
1.530 raeburn 820: $fixuperrors =
1.529 raeburn 821: '<p span class="LC_warning">'."\n".
822: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
823: '<ul>'."\n";
824: foreach my $key (sort(keys(%import_errors))) {
825: $fixuperrors .= '<li>'.$key.'</li>'."\n";
826: }
827: $fixuperrors .= '</ul></p>'."\n";
828: }
1.533 raeburn 829: if (ref($msgsarray) eq 'ARRAY') {
830: if (@{$msgsarray} > 0) {
831: $fixuperrors .= '<p class="LC_info">'.
832: join('<br />',@{$msgsarray}).
833: '</p>';
834: }
835: }
836: if ($lockerror) {
837: $fixuperrors .= '<p class="LC_error">'.
838: $lockerror.
839: '</p>';
840: }
1.529 raeburn 841: }
842: my ($errtext,$fatal) =
843: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 844: unless ($fatal) {
845: if ($folder =~ /^supplemental/) {
846: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 847: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
848: $folder.'.'.$container);
1.557 raeburn 849: }
850: }
1.529 raeburn 851: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 852: }
853:
854: sub log_docs {
1.494 raeburn 855: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 856: }
857:
858: {
859: my @oldresources=();
860: my @oldorder=();
861: my $parmidx;
862: my %parmaction=();
863: my %parmvalue=();
864: my $changedflag;
865:
866: sub snapshotbefore {
867: @oldresources=@LONCAPA::map::resources;
868: @oldorder=@LONCAPA::map::order;
869: $parmidx=undef;
870: %parmaction=();
871: %parmvalue=();
872: $changedflag=0;
873: }
874:
875: sub remember_parms {
876: my ($idx,$parameter,$action,$value)=@_;
877: $parmidx=$idx;
878: $parmaction{$parameter}=$action;
879: $parmvalue{$parameter}=$value;
880: $changedflag=1;
881: }
882:
883: sub log_differences {
884: my ($plain)=@_;
885: my %storehash=('folder' => $plain,
886: 'currentfolder' => $env{'form.folder'});
887: if ($parmidx) {
888: $storehash{'parameter_res'}=$oldresources[$parmidx];
889: foreach my $parm (keys(%parmaction)) {
890: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
891: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
892: }
893: }
894: my $maxidx=$#oldresources;
895: if ($#LONCAPA::map::resources>$#oldresources) {
896: $maxidx=$#LONCAPA::map::resources;
897: }
898: for (my $idx=0; $idx<=$maxidx; $idx++) {
899: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
900: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
901: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
902: $changedflag=1;
903: }
904: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
905: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
906: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
907: $changedflag=1;
908: }
909: }
910: $storehash{'maxidx'}=$maxidx;
911: if ($changedflag) { &log_docs(\%storehash); }
912: }
913: }
914:
915: sub docs_change_log {
1.611 raeburn 916: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 917: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 918: my $navmap;
1.483 raeburn 919: my $js = '<script type="text/javascript">'."\n".
920: '// <![CDATA['."\n".
921: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 922: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 ! raeburn 923: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 924: &history_tab_js()."\n".
1.484 raeburn 925: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 926: '// ]]>'."\n".
927: '</script>'."\n";
1.484 raeburn 928: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
929: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 930: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 931: my %orderhash;
932: my $container='sequence';
933: my $pathitem;
1.519 raeburn 934: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 935: $container='page';
936: }
1.519 raeburn 937: my $folderpath=$env{'form.folderpath'};
938: if ($folderpath eq '') {
1.617 raeburn 939: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 940: }
1.617 raeburn 941: undef($navmap);
1.519 raeburn 942: $pathitem = '<input type="hidden" name="folderpath" value="'.
943: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 944: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
945: my $jumpto = $readfile;
946: $jumpto =~ s{^/}{};
947: my $tid = 1;
1.489 raeburn 948: if ($supplementalflag) {
949: $tid = 2;
950: }
1.509 raeburn 951: my ($breadcrumbtrail) =
952: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 953: $r->print($breadcrumbtrail.
954: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
955: $readfile));
1.329 droeschl 956: my %docslog=&Apache::lonnet::dump('nohist_docslog',
957: $env{'course.'.$env{'request.course.id'}.'.domain'},
958: $env{'course.'.$env{'request.course.id'}.'.num'});
959:
960: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
961:
962: my %saveable_parameters = ('show' => 'scalar',);
963: &Apache::loncommon::store_course_settings('docs_log',
964: \%saveable_parameters);
965: &Apache::loncommon::restore_course_settings('docs_log',
966: \%saveable_parameters);
967: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 968: # FIXME: internationalization seems wrong here
1.329 droeschl 969: my %lt=('hiddenresource' => 'Resources hidden',
970: 'encrypturl' => 'URL hidden',
971: 'randompick' => 'Randomly pick',
972: 'randomorder' => 'Randomly ordered',
973: 'set' => 'set to',
974: 'del' => 'deleted');
1.484 raeburn 975: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
976: $pathitem."\n".
977: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
978: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
979: $r->print('<div class="LC_left_float">'.
980: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
981: &makedocslogform($filter,1).
982: '</fieldset></div><br clear="all" />');
1.329 droeschl 983: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
984: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
985: &mt('After').'</th>'.
986: &Apache::loncommon::end_data_table_header_row());
987: my $shown=0;
988: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
989: if ($env{'form.displayfilter'} eq 'currentfolder') {
990: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
991: }
992: my @changes=keys(%{$docslog{$id}{'logentry'}});
993: if ($env{'form.displayfilter'} eq 'containing') {
994: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
995: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
996: foreach my $key (@changes) {
997: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
998: }
1.344 bisitz 999: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1000: }
1001: my $count = 0;
1002: my $time =
1003: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1004: my $plainname =
1005: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1006: $docslog{$id}{'exe_udom'});
1007: my $about_me_link =
1008: &Apache::loncommon::aboutmewrapper($plainname,
1009: $docslog{$id}{'exe_uname'},
1010: $docslog{$id}{'exe_udom'});
1011: my $send_msg_link='';
1012: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1013: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1014: $send_msg_link ='<br />'.
1015: &Apache::loncommon::messagewrapper(&mt('Send message'),
1016: $docslog{$id}{'exe_uname'},
1017: $docslog{$id}{'exe_udom'});
1018: }
1019: $r->print(&Apache::loncommon::start_data_table_row());
1020: $r->print('<td>'.$time.'</td>
1021: <td>'.$about_me_link.
1022: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1023: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1024: $send_msg_link.'</td><td>'.
1025: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1026: my $is_supp = 0;
1027: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1028: $is_supp = 1;
1029: }
1.329 droeschl 1030: # Before
1031: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1032: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1033: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1034: if ($oldname ne $newname) {
1.488 raeburn 1035: my $shown = &LONCAPA::map::qtescape($oldname);
1036: if ($is_supp) {
1037: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1038: }
1039: $r->print($shown);
1.329 droeschl 1040: }
1041: }
1042: $r->print('<ul>');
1043: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1044: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1045: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1046: if ($is_supp) {
1047: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1048: }
1049: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1050: }
1051: }
1052: $r->print('</ul>');
1053: # After
1054: $r->print('</td><td>');
1055:
1056: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1057: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1058: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1059: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1060: my $shown = &LONCAPA::map::qtescape($newname);
1061: if ($is_supp) {
1062: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1063: }
1064: $r->print($shown);
1.329 droeschl 1065: }
1.364 bisitz 1066: }
1.329 droeschl 1067: $r->print('<ul>');
1068: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1069: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1070: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1071: if ($is_supp) {
1072: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1073: }
1074: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1075: }
1076: }
1077: $r->print('</ul>');
1078: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1079: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1080: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1081: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1082: # FIXME: internationalization seems wrong here
1.329 droeschl 1083: $r->print('<li>'.
1084: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1085: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1086: .'</li>');
1087: }
1088: }
1089: $r->print('</ul>');
1090: }
1091: # End
1092: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1093: $shown++;
1094: if (!($env{'form.show'} eq &mt('all')
1095: || $shown<=$env{'form.show'})) { last; }
1096: }
1.484 raeburn 1097: $r->print(&Apache::loncommon::end_data_table()."\n".
1098: &makesimpleeditform($pathitem)."\n".
1099: '</div></div>');
1100: $r->print(&endContentScreen());
1.329 droeschl 1101: }
1102:
1103: sub update_paste_buffer {
1.492 raeburn 1104: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1105: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1106: if ($env{'form.multiremove'}) {
1107: $env{'form.multiremove'} =~ s/,$//;
1108: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1109: }
1110: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1111: if ($env{'form.multicut'}) {
1112: $env{'form.multicut'} =~ s/,$//;
1113: foreach my $item (split(/,/,$env{'form.multicut'})) {
1114: unless ($removals{$item}) {
1115: $cuts{$item} = 1;
1116: push(@possibles,$item.':cut');
1117: }
1118: }
1119: }
1120: if ($env{'form.multicopy'}) {
1121: $env{'form.multicopy'} =~ s/,$//;
1122: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1123: unless ($removals{$item} || $cuts{$item}) {
1124: push(@possibles,$item.':copy');
1125: }
1126: }
1127: }
1128: } elsif ($env{'form.markcopy'}) {
1129: @possibles = split(/,/,$env{'form.markcopy'});
1130: }
1.329 droeschl 1131:
1.538 raeburn 1132: return if (@possibles == 0);
1.329 droeschl 1133: return if (!defined($env{'form.copyfolder'}));
1134:
1135: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1136: $env{'form.copyfolder'});
1.538 raeburn 1137: return if ($fatal);
1138:
1139: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1140:
1.538 raeburn 1141: # Retrieve current paste buffer suffixes.
1142: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1143: my (%pasteurls,@newpaste);
1144:
1145: # Construct identifiers for current contents of user's paste buffer
1146: if (@currpaste) {
1147: foreach my $suffix (@currpaste) {
1148: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1149: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1150: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1151: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1152: ($url ne '')) {
1.597 raeburn 1153: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1154: }
1155: }
1156: }
1157:
1158: # Mark items for copying (skip any items already in user's paste buffer)
1159: my %addtoenv;
1.597 raeburn 1160:
1161: my @pathitems = split(/\&/,$env{'form.folderpath'});
1162: my @folderconf = split(/\:/,$pathitems[-1]);
1163: my $ispage = $folderconf[4];
1164:
1.538 raeburn 1165: foreach my $item (@possibles) {
1166: my ($orderidx,$cmd) = split(/:/,$item);
1167: next if ($orderidx =~ /\D/);
1168: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1169: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1170: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1171: my %denied = &action_restrictions($coursenum,$coursedom,
1172: &LONCAPA::map::qtescape($url),
1173: $env{'form.folderpath'},\%curr_groups);
1174: next if ($denied{'copy'});
1175: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1176: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1177: my ($suffix,$errortxt,$locknotfreed) =
1178: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1179: if ($suffix ne '') {
1180: push(@newpaste,$suffix);
1181: } else {
1182: if ($locknotfreed) {
1183: return $locknotfreed;
1184: }
1.538 raeburn 1185: }
1186: if (&is_supplemental_title($title)) {
1187: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1188: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1189: }
1.329 droeschl 1190:
1.538 raeburn 1191: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1192: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1193: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1194: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1195: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1196: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1197: my $prefix = $1;
1198: my $subdir =$2;
1199: if ($subdir eq '') {
1200: $subdir = $prefix;
1.492 raeburn 1201: }
1.538 raeburn 1202: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1203: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1204: \%hierarchy,\%titles,\%allmaps);
1205: if (ref($hierarchy{$url}) eq 'HASH') {
1206: my ($nested,$nestednames);
1207: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1208: $nested =~ s/\&$//;
1209: $nestednames =~ s/\Q___&&&___\E$//;
1210: if ($nested ne '') {
1211: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1212: }
1213: if ($nestednames ne '') {
1214: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1215: }
1.492 raeburn 1216: }
1217: }
1.591 raeburn 1218: if ($locknotfreed) {
1219: $output = $locknotfreed;
1220: last;
1221: }
1.492 raeburn 1222: }
1.538 raeburn 1223: if (@newpaste) {
1224: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1225: }
1.492 raeburn 1226: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1227: delete($env{'form.markcopy'});
1.591 raeburn 1228: return $output;
1.329 droeschl 1229: }
1230:
1.492 raeburn 1231: sub recurse_uploaded_maps {
1232: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1233: if (ref($hierarchy->{$url}) eq 'HASH') {
1234: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1235: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1236: my (@uploaded,@names,%shorter);
1237: for (my $i=0; $i<@maps; $i++) {
1238: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1239: if ($inner ne '') {
1240: push(@uploaded,$inner);
1241: push(@names,&escape($titles[$i]));
1242: $shorter{$maps[$i]} = $inner;
1243: }
1244: }
1245: $$nestref .= "$dir:".join(',',@uploaded).'&';
1246: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1247: foreach my $map (@maps) {
1248: if ($shorter{$map} ne '') {
1249: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1250: }
1251: }
1252: }
1253: return;
1254: }
1255:
1.329 droeschl 1256: sub print_paste_buffer {
1.492 raeburn 1257: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1258: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1259:
1.538 raeburn 1260: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1261: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1262: }
1263:
1.538 raeburn 1264: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1265: my ($pasteitems,@pasteable);
1.575 raeburn 1266: my $clipboardcount = 0;
1.488 raeburn 1267:
1.538 raeburn 1268: # Construct identifiers for current contents of user's paste buffer
1269: foreach my $suffix (@currpaste) {
1270: next if ($suffix =~ /\D/);
1271: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1272: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1273: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1274: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1275: ($url ne '')) {
1.575 raeburn 1276: $clipboardcount ++;
1.538 raeburn 1277: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1278: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1279: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1280: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1281: $is_external = 1;
1.598 raeburn 1282: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
1283: $is_exttool = 1;
1.538 raeburn 1284: }
1285: if ($folder =~ /^supplemental/) {
1286: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1287: unless ($canpaste) {
1288: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1289: }
1290: } else {
1291: $canpaste = 1;
1292: }
1293: if ($canpaste) {
1294: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1295: my $srcdom = $1;
1296: my $srcnum = $2;
1297: my $rem = $3;
1298: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1299: $othercourse = 1;
1300: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1301: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1302: } else {
1303: $canpaste = 0;
1304: $nopaste = &mt('Paste from another course unavailable.');
1305: }
1306: }
1307: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1308: my $prefix = $1;
1309: $parent = $2;
1310: if ($folder !~ /^\Q$prefix\E/) {
1311: $areachange = 1;
1312: }
1313: $is_uploaded_map = 1;
1.492 raeburn 1314: }
1.597 raeburn 1315: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1316: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1317: if ($cid ne $env{'request.course.id'}) {
1318: my ($srcdom,$srcnum) = split(/_/,$cid);
1319: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1320: $othercrs = '<br />'.&mt('(from another course)');
1321: } else {
1322: $canpaste = 0;
1323: $nopaste = &mt('Paste from another course unavailable.');
1324: }
1325: }
1.492 raeburn 1326: }
1.596 raeburn 1327: if ($canpaste) {
1328: push(@pasteable,$suffix);
1329: }
1.538 raeburn 1330: }
1331: my $buffer;
1.598 raeburn 1332: if (($is_external) || ($is_exttool)) {
1.538 raeburn 1333: $buffer = &mt('External Resource').': '.
1334: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1335: &LONCAPA::map::qtescape($url).')';
1336: } else {
1337: my $icon = &Apache::loncommon::icon($extension);
1338: if ($extension eq 'sequence' &&
1339: $url =~ m{/default_\d+\.sequence$}x) {
1340: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1341: $icon .= '/navmap.folder.closed.gif';
1342: }
1.589 raeburn 1343: my $title = $env{'docs.markedcopy_title_'.$suffix};
1344: if ($title eq '') {
1345: ($title) = ($url =~ m{/([^/]+)$});
1346: }
1.538 raeburn 1347: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1348: ': '.
1349: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1350: &LONCAPA::map::qtescape($title));
1.538 raeburn 1351: }
1352: $pasteitems .= '<div class="LC_left_float">';
1353: my ($options,$onclick);
1354: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1355: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1356: if (($is_uploaded_map) ||
1357: ($url =~ /(bulletinboard|smppg)$/) ||
1358: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1359: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1360: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1361: }
1362: }
1363: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1364: if ($nopaste) {
1365: $pasteitems .= $nopaste;
1366: } else {
1367: if ($othercrs) {
1368: $pasteitems .= $othercrs;
1369: }
1370: if ($options) {
1371: $pasteitems .= $options;
1.492 raeburn 1372: }
1373: }
1.538 raeburn 1374: $pasteitems .= '</div>';
1375: }
1376: }
1377: if ($pasteitems eq '') {
1378: &Apache::lonnet::delenv('docs.markedcopies');
1379: }
1380: my ($pasteform,$form_start,$buttons,$form_end);
1381: if ($pasteitems) {
1382: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1383: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1384: if (@pasteable) {
1.575 raeburn 1385: my $value = &mt('Paste to current folder');
1386: if ($container eq 'page') {
1387: $value = &mt('Paste to current page');
1388: }
1389: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1390: }
1391: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1392: if ($clipboardcount > 1) {
1393: $buttons .=
1394: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1395: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1396: (' 'x2).
1397: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1398: (' 'x2);
1.492 raeburn 1399: }
1.575 raeburn 1400: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1401: '</form>';
1.538 raeburn 1402: } else {
1403: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1404: }
1.538 raeburn 1405: $r->print($form_start
1406: .'<fieldset>'
1407: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1408: .$pasteitems
1409: .'</fieldset>'
1410: .$form_end);
1411: }
1412:
1413: sub paste_options {
1414: my ($suffix,$is_uploaded_map,$parent) = @_;
1415: my ($copytext,$movetext);
1416: if ($is_uploaded_map) {
1417: $copytext = &mt('Copy to new folder');
1418: $movetext = &mt('Move old');
1419: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1420: $copytext = &mt('Copy to new board');
1421: $movetext = &mt('Move (not posts)');
1422: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1423: $copytext = &mt('Copy to new page');
1424: $movetext = &mt('Move');
1.533 raeburn 1425: } else {
1.538 raeburn 1426: $copytext = &mt('Copy to new file');
1427: $movetext = &mt('Move');
1428: }
1429: my $output = '<br />'.
1430: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1431: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1432: '<label>'.
1433: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1434: $copytext.'</label></span>'.(' 'x2).' '.
1435: '<span class="LC_nobreak"><label>'.
1436: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1437: $movetext.'</label></span>';
1438: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1439: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1440: '</legend><table border="0">';
1441: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1442: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1443: my $lastdir = $parent;
1444: my %depths = (
1445: $lastdir => 0,
1446: );
1447: my (%display,%deps);
1448: for (my $i=0; $i<@pastemaps; $i++) {
1449: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1450: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1451: my @subfolders = split(/,/,$subfolderstr);
1452: $deps{$lastdir} = \@subfolders;
1453: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1454: my $depth = $depths{$lastdir} + 1;
1455: my $offset = int($depth * 4);
1456: my $indent = (' ' x $offset);
1457: for (my $j=0; $j<@subfolders; $j++) {
1458: $depths{$subfolders[$j]} = $depth;
1459: $display{$subfolders[$j]} =
1460: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1461: '<td><label>'.
1462: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1463: '<label>'.
1464: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1465: &mt('Move old').'</label>'.
1466: '</td></tr>';
1467: }
1.492 raeburn 1468: }
1.538 raeburn 1469: &recurse_print(\$output,$parent,\%deps,\%display);
1470: $output .= '</table></fieldset>';
1.329 droeschl 1471: }
1.538 raeburn 1472: $output .= '</div>';
1473: return $output;
1.488 raeburn 1474: }
1475:
1.492 raeburn 1476: sub recurse_print {
1.538 raeburn 1477: my ($outputref,$dir,$deps,$display) = @_;
1478: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1479: if (ref($deps->{$dir}) eq 'ARRAY') {
1480: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1481: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1482: }
1483: }
1484: }
1485:
1.488 raeburn 1486: sub supp_pasteable {
1487: my ($url) = @_;
1488: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1489: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1490: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1491: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1492: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1493: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
1.488 raeburn 1494: return 1;
1495: }
1496: return;
1.329 droeschl 1497: }
1498:
1.492 raeburn 1499: sub paste_popup_js {
1.594 damieng 1500: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1501: show => 'Show Options',
1502: hide => 'Hide Options',
1.594 damieng 1503: );
1504: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1505: none => 'No items selected from clipboard.',
1.492 raeburn 1506: );
1.594 damieng 1507: &html_escape(\%html_js_lt);
1508: &js_escape(\%html_js_lt);
1509: &js_escape(\%js_lt);
1.492 raeburn 1510: return <<"END";
1511:
1.538 raeburn 1512: function showPasteOptions(suffix) {
1513: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1514: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1515: return;
1516: }
1517:
1.538 raeburn 1518: function hidePasteOptions(suffix) {
1519: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1520: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1521: return;
1522: }
1523:
1524: function showOptions(caller,suffix) {
1525: if (document.getElementById('pasteoptionstext_'+suffix)) {
1526: if (caller.checked) {
1.594 damieng 1527: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1528: } else {
1529: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1530: }
1531: if (document.getElementById('pasteoptions_'+suffix)) {
1532: document.getElementById('pasteoptions_'+suffix).style.display='none';
1533: }
1534: }
1.492 raeburn 1535: return;
1536: }
1537:
1.541 raeburn 1538: function validateClipboard() {
1539: var numchk = 0;
1540: if (document.pasteform.pasting.length > 1) {
1541: for (var i=0; i<document.pasteform.pasting.length; i++) {
1542: if (document.pasteform.pasting[i].checked) {
1543: numchk ++;
1544: }
1545: }
1546: } else {
1547: if (document.pasteform.pasting.type == 'checkbox') {
1548: if (document.pasteform.pasting.checked) {
1549: numchk ++;
1550: }
1551: }
1552: }
1553: if (numchk > 0) {
1554: return true;
1555: } else {
1.594 damieng 1556: alert("$js_lt{'none'}");
1.541 raeburn 1557: return false;
1558: }
1559: }
1560:
1.575 raeburn 1561: function checkClipboard() {
1562: if (document.pasteform.pasting.length > 1) {
1563: for (var i=0; i<document.pasteform.pasting.length; i++) {
1564: document.pasteform.pasting[i].checked = true;
1565: }
1566: }
1567: return;
1568: }
1569:
1570: function uncheckClipboard() {
1571: if (document.pasteform.pasting.length >1) {
1572: for (var i=0; i<document.pasteform.pasting.length; i++) {
1573: document.pasteform.pasting[i].checked = false;
1574: }
1575: }
1576: return;
1577: }
1578:
1.492 raeburn 1579: END
1580:
1581: }
1582:
1.329 droeschl 1583: sub do_paste_from_buffer {
1.492 raeburn 1584: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1585:
1.538 raeburn 1586: # Array of items in paste buffer
1587: my (@currpaste,%pastebuffer,%allerrors);
1588: @currpaste = split(/,/,$env{'docs.markedcopies'});
1589:
1.492 raeburn 1590: # Early out if paste buffer is empty
1.538 raeburn 1591: if (@currpaste == 0) {
1.492 raeburn 1592: return ();
1.538 raeburn 1593: }
1594: map { $pastebuffer{$_} = 1; } @currpaste;
1595:
1596: # Array of items selected items to paste
1597: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1598:
1599: # Early out if nothing selected to paste
1600: if (@reqpaste == 0) {
1601: return();
1602: }
1603: my @topaste;
1604: foreach my $suffix (@reqpaste) {
1605: next if ($suffix =~ /\D/);
1606: next unless (exists($pastebuffer{$suffix}));
1607: push(@topaste,$suffix);
1608: }
1609:
1610: # Early out if nothing available to paste
1611: if (@topaste == 0) {
1612: return();
1.329 droeschl 1613: }
1614:
1.538 raeburn 1615: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.597 raeburn 1616: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1617:
1618: foreach my $suffix (@topaste) {
1619: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1620: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1621: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1622: # Supplemental content may only include certain types of content
1623: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1624: if ($folder =~ /^supplemental/) {
1625: unless (&supp_pasteable($url)) {
1626: $notinsupp{$suffix} = 1;
1627: next;
1628: }
1.492 raeburn 1629: }
1.538 raeburn 1630: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1631: my $srcd = $1;
1632: my $srcn = $2;
1.492 raeburn 1633: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1634: # check for mdc privilege in the course from which the resource was pasted
1635: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1636: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1637: $notincrs{$suffix} = 1;
1638: next;
1639: }
1.491 raeburn 1640: }
1.538 raeburn 1641: $srcdom{$suffix} = $srcd;
1642: $srcnum{$suffix} = $srcn;
1.597 raeburn 1643: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1644: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1645: my ($srcd,$srcn) = split(/_/,$cid);
1646: # When paste buffer was populated using an active role in a different course
1647: # check for mdc privilege in the course from which the resource was pasted
1648: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1649: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1650: $notincrs{$suffix} = 1;
1651: next;
1652: }
1653: }
1654: $srcdom{$suffix} = $srcd;
1655: $srcnum{$suffix} = $srcn;
1.491 raeburn 1656: }
1.597 raeburn 1657: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1658: push(@dopaste,$suffix);
1659: if ($url=~/\.(page|sequence)$/) {
1660: $is_map{$suffix} = 1;
1661: }
1662:
1663: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1664: my $oldprefix = $1;
1.492 raeburn 1665: # When pasting content from Main Content to Supplemental Content and vice versa
1666: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1667: # a folder/page or a document).
1.538 raeburn 1668: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1669: $prefixchg{$suffix} = 'docstosupp';
1670: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1671: $prefixchg{$suffix} = 'supptodocs';
1672: }
1.491 raeburn 1673:
1.492 raeburn 1674: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1675: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1676: my @nested;
1677: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1678: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1679: my @deps = map { /\d+:([\d,]+$)/ } @items;
1680: foreach my $dep (@deps) {
1681: if ($dep =~ /,/) {
1682: push(@nested,split(/,/,$dep));
1683: } else {
1684: push(@nested,$dep);
1685: }
1.492 raeburn 1686: }
1.538 raeburn 1687: foreach my $item (@nested) {
1688: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1689: push(@{$marktomove{$suffix}},$type.'_'.$item);
1690: }
1.492 raeburn 1691: }
1692: }
1.488 raeburn 1693: }
1694: }
1695:
1.538 raeburn 1696: # Early out if nothing available to paste
1697: if (@dopaste == 0) {
1698: return ();
1699: }
1700:
1701: # Populate message hash and hashes used for main content <=> supplemental content
1702: # changes
1703:
1704: %msgs = &Apache::lonlocal::texthash (
1705: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1706: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1707: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1708: );
1709:
1710: %before = (
1711: docstosupp => {
1712: map => 'default',
1713: doc => 'docs',
1714: },
1715: supptodocs => {
1716: map => 'supplemental',
1717: doc => 'supplemental',
1718: },
1719: );
1720:
1721: %after = (
1722: docstosupp => {
1723: map => 'supplemental',
1724: doc => 'supplemental'
1725: },
1726: supptodocs => {
1727: map => 'default',
1728: doc => 'docs',
1729: },
1730: );
1731:
1732: # Retrieve information about all course maps in main content area
1733:
1734: my $allmaps = {};
1735: if ($folder =~ /^default/) {
1736: $allmaps =
1737: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1738: $env{"course.$env{'request.course.id'}.home"},
1739: $env{'request.course.id'});
1740: }
1741:
1742: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1743:
1744: # Loop over the items to paste
1745: foreach my $suffix (@dopaste) {
1.329 droeschl 1746: # Maps need to be copied first
1.538 raeburn 1747: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1748: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1749: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1750: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1751: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1752: }
1753: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1754: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1755: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1756: my $oldurl = $url;
1757: if ($is_map{$suffix}) {
1.491 raeburn 1758: # If pasting a map, check if map contains other maps
1.538 raeburn 1759: my (%hierarchy,%titles);
1760: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1761: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1762: if ($url=~ m{^/uploaded/}) {
1763: my $newurl;
1764: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1765: ($newurl,my $error) =
1766: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1767: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1768: \$title,$allmaps,\%newurls);
1769: if ($error) {
1770: $allerrors{$suffix} = $error;
1771: next;
1772: }
1773: if ($newurl ne '') {
1774: if ($newurl ne $url) {
1775: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1776: $newsubdir{$url} = $1;
1777: }
1778: $mapchanges{$url} = 1;
1.492 raeburn 1779: }
1.538 raeburn 1780: }
1781: }
1782: if (($srcdom{$suffix} ne $coursedom) ||
1783: ($srcnum{$suffix} ne $coursenum) ||
1784: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1785: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1786: $coursedom,$coursenum,$srcdom{$suffix},
1787: $srcnum{$suffix},$allmaps,\%rewrites,
1788: \%retitles,\%copies,\%dbcopies,
1789: \%zombies,\%params,\%mapmoves,
1790: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1791: \%newurls,\%resdatacopy)) {
1.538 raeburn 1792: $mapmoves{$url} = 1;
1793: }
1794: $url = $newurl;
1795: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1796: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1797: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1798: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1799: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1800: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1801: }
1802: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1803: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1804: push(@toclear,$suffix);
1805: # if pasting published map (main content area only) check map not already in course
1806: if ($folder =~ /^default/) {
1807: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1808: $duplicate{$suffix} = 1;
1809: next;
1.492 raeburn 1810: }
1.491 raeburn 1811: }
1812: }
1.538 raeburn 1813: }
1814: if ($url=~ m{/(bulletinboard|smppg)$}) {
1815: my $prefix = $1;
1.596 raeburn 1816: my $fromothercrs;
1.538 raeburn 1817: #need to copy the db contents to a new one, unless this is a move.
1818: my %info = (
1819: src => $url,
1820: cdom => $coursedom,
1821: cnum => $coursenum,
1.596 raeburn 1822: );
1823: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1824: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1825: $fromothercrs = 1;
1826: $info{'cdom'} = $srcdom{$suffix};
1827: $info{'cnum'} = $srcnum{$suffix};
1828: }
1829: }
1830: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.538 raeburn 1831: my (%lockerr,$msg);
1832: my ($newurl,$result,$errtext) =
1833: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1834: if ($result eq 'ok') {
1835: $url = $newurl;
1836: $title=&mt('Copy of').' '.$title;
1837: } else {
1838: if ($prefix eq 'smppg') {
1839: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1840: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1841: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.538 raeburn 1842: }
1843: $results{$suffix} = $result;
1844: $msgerrs{$suffix} = $msg;
1845: $lockerrs{$suffix} = $lockerr{$prefix};
1846: next;
1847: }
1848: if ($lockerr{$prefix}) {
1849: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1850: }
1.489 raeburn 1851: }
1852: }
1.538 raeburn 1853: $title = &LONCAPA::map::qtunescape($title);
1854: my $ext='false';
1855: if ($url=~m{^http(|s)://}) { $ext='true'; }
1856: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1857: if ($folder !~ /^supplemental/) {
1858: (undef,undef,$title) =
1859: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1860: }
1861: } else {
1862: if ($folder=~/^supplemental/) {
1863: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1864: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1865: }
1.533 raeburn 1866: }
1.491 raeburn 1867:
1868: # For uploaded files (excluding pages/sequences) path in copied file is changed
1869: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1870: # courses.
1871:
1.538 raeburn 1872: unless ($is_map{$suffix}) {
1873: my $newidx;
1.492 raeburn 1874: # Now insert the URL at the bottom
1.538 raeburn 1875: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1876: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1877: my $relpath = $1;
1878: if ($relpath ne '') {
1879: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1880: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1881: my $newprefix = $newloc;
1882: if ($newloc eq 'default') {
1883: $newprefix = 'docs';
1884: }
1885: if ($newdocsdir eq '') {
1886: $newdocsdir = 'default';
1887: }
1888: if (($prefixchg{$suffix}) ||
1889: ($srcdom{$suffix} ne $coursedom) ||
1890: ($srcnum{$suffix} ne $coursenum) ||
1891: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1892: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1893: $url =
1894: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1895: &Apache::lonnet::getfile($oldurl));
1896: if ($url eq '/adm/notfound.html') {
1897: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1898: next;
1899: } else {
1900: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1901: $newsubpath =~ s{/+$}{/};
1902: $docmoves{$oldurl} = $newsubpath;
1903: }
1.491 raeburn 1904: }
1905: }
1.597 raeburn 1906: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1907: my $template = $1;
1908: if ($newidx) {
1909: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1910: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1911: }
1.491 raeburn 1912: }
1.538 raeburn 1913: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1914: ':'.$ext.':normal:res';
1915: push(@LONCAPA::map::order,$newidx);
1916: # Store the result
1917: my ($errtext,$fatal) =
1918: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1919: if ($fatal) {
1920: $save_err .= $errtext;
1921: $allresult = 'fail';
1922: }
1.488 raeburn 1923: }
1.538 raeburn 1924:
1.597 raeburn 1925: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1926: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1927: unless ($allresult eq 'fail') {
1928: my %updated = (
1929: rewrites => \%rewrites,
1930: zombies => \%zombies,
1931: removefrommap => \%removefrommap,
1932: removeparam => \%removeparam,
1933: dbcopies => \%dbcopies,
1.597 raeburn 1934: resdatacopy => \%resdatacopy,
1.538 raeburn 1935: retitles => \%retitles,
1936: );
1937: my %info = (
1938: newsubdir => \%newsubdir,
1939: params => \%params,
1940: );
1941: if ($prefixchg{$suffix}) {
1942: $info{'before'} = $before{$prefixchg{$suffix}};
1943: $info{'after'} = $after{$prefixchg{$suffix}};
1944: }
1945: my %moves = (
1946: copies => \%copies,
1947: docmoves => \%docmoves,
1948: mapmoves => \%mapmoves,
1949: );
1950: (my $result,$msgs{$suffix},my $lockerror) =
1951: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1952: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1953: $url,'paste');
1954: $lockerrors .= $lockerror;
1955: if ($result eq 'ok') {
1956: if ($is_map{$suffix}) {
1957: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1958: $folder.'.'.$container);
1959: if ($fatal) {
1960: $allresult = 'failread';
1961: } else {
1962: if ($#LONCAPA::map::order<1) {
1963: my $idx=&LONCAPA::map::getresidx();
1964: if ($idx<=0) { $idx=1; }
1965: $LONCAPA::map::order[0]=$idx;
1966: $LONCAPA::map::resources[$idx]='';
1967: }
1968: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1969: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1970: ':'.$ext.':normal:res';
1971: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 1972:
1973: # Store the result
1.538 raeburn 1974: my ($errtext,$fatal) =
1975: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1976: if ($fatal) {
1977: $save_err .= $errtext;
1978: $allresult = 'failstore';
1979: }
1980: }
1981: }
1982: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1983: push(@toclear,$suffix);
1984: }
1985: }
1.492 raeburn 1986: }
1987: }
1.538 raeburn 1988: &clear_from_buffer(\@toclear,\@currpaste);
1989: my $msgsarray;
1990: foreach my $suffix (keys(%msgs)) {
1991: if (ref($msgs{$suffix}) eq 'ARRAY') {
1992: $msgsarray .= join(',',@{$msgs{$suffix}});
1993: }
1994: }
1995: return ($allresult,$save_err,$msgsarray,$lockerrors);
1996: }
1.533 raeburn 1997:
1.538 raeburn 1998: sub do_buffer_empty {
1999: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2000: if (@currpaste == 0) {
2001: return &mt('Clipboard is already empty');
2002: }
2003: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2004: if (@toclear == 0) {
2005: return &mt('Nothing selected to clear from clipboard');
2006: }
2007: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2008: if ($numdel) {
2009: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2010: } else {
2011: return &mt('Clipboard unchanged');
1.492 raeburn 2012: }
1.538 raeburn 2013: return;
2014: }
2015:
2016: sub clear_from_buffer {
2017: my ($toclear,$currpaste) = @_;
2018: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2019: my %pastebuffer;
2020: map { $pastebuffer{$_} = 1; } @{$currpaste};
2021: my $numdel = 0;
2022: foreach my $suffix (@{$toclear}) {
2023: next if ($suffix =~ /\D/);
2024: next unless (exists($pastebuffer{$suffix}));
2025: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2026: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2027: delete($pastebuffer{$suffix});
2028: $numdel ++;
2029: }
2030: }
2031: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2032: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2033: return $numdel;
1.492 raeburn 2034: }
2035:
2036: sub get_newmap_url {
2037: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2038: $titleref,$allmaps,$newurls) = @_;
2039: my $newurl;
2040: if ($url=~ m{^/uploaded/}) {
2041: $$titleref=&mt('Copy of').' '.$$titleref;
2042: }
2043: my $now = time;
2044: my $suffix=$$.int(rand(100)).$now;
2045: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2046: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2047: my $path = $1;
2048: my $prefix = $2;
2049: my $ancestor = $3;
2050: if (length($ancestor) > 10) {
2051: $ancestor = substr($ancestor,-10,10);
2052: }
2053: my $newid;
2054: if ($prefixchg) {
2055: if ($folder =~ /^supplemental/) {
2056: $prefix =~ s/^default/supplemental/;
2057: } else {
2058: $prefix =~ s/^supplemental/default/;
2059: }
2060: }
2061: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2062: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2063: } else {
2064: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2065: }
2066: my $counter = 0;
2067: my $is_unique = &uniqueness_check($newurl);
2068: if ($folder =~ /^default/) {
2069: if ($allmaps->{$newurl}) {
2070: $is_unique = 0;
2071: }
2072: }
2073: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2074: $counter ++;
2075: $suffix ++;
2076: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2077: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2078: } else {
2079: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2080: }
2081: $is_unique = &uniqueness_check($newurl);
2082: }
2083: if ($is_unique) {
2084: $newurls->{$newurl} = 1;
2085: } else {
2086: if ($url=~/\.page$/) {
2087: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2088: } else {
2089: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2090: }
2091: }
1.329 droeschl 2092: }
1.492 raeburn 2093: return ($newurl);
1.329 droeschl 2094: }
2095:
1.488 raeburn 2096: sub dbcopy {
1.533 raeburn 2097: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2098: my ($url,$result,$errtext);
2099: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2100: $url = $dbref->{'src'};
1.533 raeburn 2101: if ($url =~ m{/(smppg|bulletinboard)$}) {
2102: my $prefix = $1;
2103: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2104: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2105: my $db_name;
2106: my $marker = (split(m{/},$url))[4];
2107: $marker=~s/\D//g;
2108: if ($dbref->{'src'} =~ m{/smppg$}) {
2109: $db_name =
2110: &Apache::lonsimplepage::get_db_name($url,$marker,
2111: $dbref->{'cdom'},
2112: $dbref->{'cnum'});
2113: } else {
2114: $db_name = 'bulletinpage_'.$marker;
2115: }
2116: my ($suffix,$freedlock,$error) =
2117: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2118: $coursedom,$coursenum,
2119: 'concat');
2120: if (!$suffix) {
2121: if ($prefix eq 'smppg') {
2122: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2123: } else {
1.565 bisitz 2124: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2125: }
2126: if ($error) {
2127: $errtext .= '<br />'.$error;
2128: }
2129: } else {
2130: #need to copy the db contents to a new one.
2131: my %contents=&Apache::lonnet::dump($db_name,
2132: $dbref->{'cdom'},
2133: $dbref->{'cnum'});
2134: if (exists($contents{'uploaded.photourl'})) {
2135: my $photo = $contents{'uploaded.photourl'};
2136: my ($subdir,$fname) =
2137: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2138: my $newphoto;
1.533 raeburn 2139: if ($fname ne '') {
2140: my $content = &Apache::lonnet::getfile($photo);
2141: unless ($content eq '-1') {
2142: $env{'form.'.$suffix.'.photourl'} = $content;
2143: $newphoto =
2144: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2145: delete($env{'form.'.$suffix.'.photourl'});
2146: }
2147: }
2148: if ($newphoto =~ m{^/uploaded/}) {
2149: $contents{'uploaded.photourl'} = $newphoto;
2150: }
2151: }
2152: $db_name =~ s{_\d*$ }{_$suffix}x;
2153: $result=&Apache::lonnet::put($db_name,\%contents,
2154: $coursedom,$coursenum);
2155: if ($result eq 'ok') {
2156: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2157: }
2158: }
2159: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2160: $lockerrorsref->{$prefix} =
1.533 raeburn 2161: '<div class="LC_error">'.
2162: &mt('There was a problem removing a lockfile.');
2163: if ($prefix eq 'smppg') {
1.560 raeburn 2164: $lockerrorsref->{$prefix} .=
1.559 raeburn 2165: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.533 raeburn 2166: } else {
1.565 bisitz 2167: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2168: }
1.560 raeburn 2169: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2170: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2171: '</div>';
1.533 raeburn 2172: }
2173: }
2174: } elsif ($url =~ m{/syllabus$}) {
2175: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2176: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2177: if (($dbref->{'cdom'} ne $coursedom) ||
2178: ($dbref->{'cnum'} ne $coursenum)) {
2179: my %contents=&Apache::lonnet::dump('syllabus',
2180: $dbref->{'cdom'},
2181: $dbref->{'cnum'});
2182: $result=&Apache::lonnet::put('syllabus',\%contents,
2183: $coursedom,$coursenum);
2184: }
2185: }
1.488 raeburn 2186: }
2187: }
1.533 raeburn 2188: return ($url,$result,$errtext);
1.488 raeburn 2189: }
2190:
1.597 raeburn 2191: sub copy_templated_files {
2192: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2193: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2194: my $srccontainer = 'sequence';
2195: if ($srcwaspage) {
2196: $srccontainer = 'page';
2197: }
2198: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2199: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2200: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2201: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2202: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2203: $template.'.problem';
2204: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2205: if ($template eq 'simpleproblem') {
2206: $srcprefix .= '.0.';
2207: my $weightprefix = $newprefix;
2208: $newprefix .= '.0.';
2209: my @simpleprobqtypes = qw(radio option string essay numerical);
2210: my $qtype=$srcparms{$srcprefix.'questiontype'};
2211: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2212: my %newdata;
2213: foreach my $type (@simpleprobqtypes) {
2214: if ($type eq $qtype) {
2215: $newdata{"$weightprefix.$type.weight"}=1;
2216: } else {
2217: $newdata{"$weightprefix.$type.weight"}=0;
2218: }
2219: }
2220: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2221: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2222: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2223: if ($qtype eq 'numerical') {
2224: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2225: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2226: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2227: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2228: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2229: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2230: unless (defined($maxfoils)) { $maxfoils=10; }
2231: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2232: if ($maxfoils<=0) { $maxfoils=10; }
2233: my $randomize=$srcparms{$srcprefix.'randomize'};
2234: unless (defined($randomize)) { $randomize='yes'; }
2235: unless ($randomize eq 'no') { $randomize='yes'; }
2236: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2237: $newdata{$newprefix.'randomize'} = $randomize;
2238: if ($qtype eq 'option') {
2239: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2240: }
2241: for (my $i=1; $i<=10; $i++) {
2242: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2243: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2244: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2245: }
2246:
2247: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2248: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2249: unless (defined($maxfoils)) { $maxfoils=10; }
2250: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2251: if ($maxfoils<=0) { $maxfoils=10; }
2252: my $randomize=$srcparms{$srcprefix.'randomize'};
2253: unless (defined($randomize)) { $randomize='yes'; }
2254: unless ($randomize eq 'no') { $randomize='yes'; }
2255: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2256: $newdata{$newprefix.'randomize'} = $randomize;
2257: if ($qtype eq 'option') {
2258: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2259: }
2260: for (my $i=1; $i<=10; $i++) {
2261: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2262: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2263: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2264: }
2265: } elsif ($qtype eq 'string') {
2266: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2267: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2268: }
2269: if (keys(%newdata)) {
2270: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2271: $coursenum);
2272: if ($putres eq 'ok') {
2273: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2274: }
2275: }
2276: }
2277: }
2278: }
2279:
1.329 droeschl 2280: sub uniqueness_check {
2281: my ($newurl) = @_;
2282: my $unique = 1;
2283: foreach my $res (@LONCAPA::map::order) {
2284: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2285: $url=&LONCAPA::map::qtescape($url);
2286: if ($newurl eq $url) {
2287: $unique = 0;
1.344 bisitz 2288: last;
1.329 droeschl 2289: }
2290: }
2291: return $unique;
2292: }
2293:
1.488 raeburn 2294: sub contained_map_check {
1.492 raeburn 2295: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2296: $allmaps) = @_;
1.488 raeburn 2297: my $content = &Apache::lonnet::getfile($url);
2298: unless ($content eq '-1') {
2299: my $parser = HTML::TokeParser->new(\$content);
2300: $parser->attr_encoded(1);
2301: while (my $token = $parser->get_token) {
2302: next if ($token->[0] ne 'S');
2303: if ($token->[1] eq 'resource') {
2304: next if ($token->[2]->{'type'} eq 'zombie');
2305: my $ressrc = $token->[2]->{'src'};
2306: if ($folder =~ /^supplemental/) {
2307: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2308: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2309: next;
2310: }
2311: }
1.492 raeburn 2312: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2313: if ($1 eq 'uploaded') {
2314: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2315: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2316: } else {
1.492 raeburn 2317: if ($allmaps->{$ressrc}) {
1.529 raeburn 2318: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2319: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2320: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2321: } else {
2322: $addedmaps->{$ressrc} = [$url];
2323: }
1.488 raeburn 2324: }
1.492 raeburn 2325: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2326: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2327: }
1.492 raeburn 2328: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2329: if ($folder =~ /^supplemental/) {
1.492 raeburn 2330: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2331: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2332: } else {
2333: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2334: }
1.488 raeburn 2335: }
2336: }
2337: }
2338: }
2339: return;
2340: }
2341:
2342: sub url_paste_fixups {
1.533 raeburn 2343: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2344: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2345: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2346: my $checktitle;
2347: if (($prefixchg) &&
1.492 raeburn 2348: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2349: $checktitle = 1;
2350: }
1.492 raeburn 2351: my $skip;
2352: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2353: my $mapid = $1.$2;
2354: if ($tomove->{$mapid}) {
2355: $skip = 1;
2356: }
2357: }
1.491 raeburn 2358: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2359: return if ($file eq '-1');
2360: my $parser = HTML::TokeParser->new(\$file);
2361: $parser->attr_encoded(1);
1.491 raeburn 2362: my $changed = 0;
1.488 raeburn 2363: while (my $token = $parser->get_token) {
2364: next if ($token->[0] ne 'S');
2365: if ($token->[1] eq 'resource') {
2366: my $ressrc = $token->[2]->{'src'};
2367: next if ($ressrc eq '');
1.491 raeburn 2368: my $id = $token->[2]->{'id'};
1.492 raeburn 2369: my $title = $token->[2]->{'title'};
1.491 raeburn 2370: if ($checktitle) {
2371: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2372: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2373: }
2374: }
1.488 raeburn 2375: next if ($token->[2]->{'type'} eq 'external');
2376: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2377: next if ($skip);
1.532 raeburn 2378: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2379: $changed = 1;
2380: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2381: my $srcdom = $1;
2382: my $srcnum = $2;
1.488 raeburn 2383: my $rem = $3;
1.492 raeburn 2384: my $newurl;
2385: my $mapname;
2386: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2387: my $prefix = $1;
2388: $mapname = $prefix.$2;
2389: if ($tomove->{$mapname}) {
1.533 raeburn 2390: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2391: $srcdom,$srcnum,$allmaps,$rewrites,
2392: $retitles,$copies,$dbcopies,$zombies,
2393: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2394: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2395: next;
2396: } else {
2397: ($newurl,my $error) =
2398: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2399: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2400: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2401: $newsubdir->{$ressrc} = $1;
2402: }
2403: if ($error) {
2404: next;
2405: }
2406: }
2407: }
2408: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2409: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2410:
1.488 raeburn 2411: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2412: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2413: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2414: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2415: $cnum,$srcdom,$srcnum,$allmaps,
2416: $rewrites,$retitles,$copies,$dbcopies,
2417: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2418: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2419: $mapmoves->{$ressrc} = 1;
2420: }
2421: $changed = 1;
1.488 raeburn 2422: } else {
1.532 raeburn 2423: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2424: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2425: $changed = 1;
1.488 raeburn 2426: }
2427: }
1.533 raeburn 2428: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2429: next if ($skip);
1.492 raeburn 2430: my $srcdom = $1;
2431: my $srcnum = $2;
2432: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2433: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2434: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2435: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2436: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2437: $changed = 1;
2438: }
2439: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2440: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2441: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2442: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2443: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2444: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2445: $changed = 1;
1.488 raeburn 2446: }
1.597 raeburn 2447: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2448: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2449: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2450: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2451: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2452: }
1.488 raeburn 2453: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2454: next if ($skip);
2455: my $srcdom = $1;
2456: my $srcnum = $2;
2457: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2458: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2459: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2460: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2461: $changed = 1;
1.488 raeburn 2462: }
2463: }
2464: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2465: next if ($skip);
1.488 raeburn 2466: my $to = $token->[2]->{'to'};
2467: if ($to ne '') {
2468: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2469: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2470: } else {
2471: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2472: }
2473: }
2474: }
2475: }
1.491 raeburn 2476: return $changed;
1.488 raeburn 2477: }
2478:
2479: sub apply_fixups {
1.529 raeburn 2480: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2481: $oldurl,$url,$caller) = @_;
2482: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2483: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2484: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2485: if (ref($updated) eq 'HASH') {
2486: if (ref($updated->{'rewrites'}) eq 'HASH') {
2487: %rewrites = %{$updated->{'rewrites'}};
2488: }
2489: if (ref($updated->{'zombies'}) eq 'HASH') {
2490: %zombies = %{$updated->{'zombies'}};
2491: }
2492: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2493: %removefrommap = %{$updated->{'removefrommap'}};
2494: }
2495: if (ref($updated->{'removeparam'}) eq 'HASH') {
2496: %removeparam = %{$updated->{'removeparam'}};
2497: }
2498: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2499: %dbcopies = %{$updated->{'dbcopies'}};
2500: }
2501: if (ref($updated->{'retitles'}) eq 'HASH') {
2502: %retitles = %{$updated->{'retitles'}};
2503: }
1.597 raeburn 2504: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2505: %resdatacopy = %{$updated->{'resdatacopy'}};
2506: }
1.529 raeburn 2507: }
2508: if (ref($info) eq 'HASH') {
2509: if (ref($info->{'newsubdir'}) eq 'HASH') {
2510: %newsubdir = %{$info->{'newsubdir'}};
2511: }
2512: if (ref($info->{'params'}) eq 'HASH') {
2513: %params = %{$info->{'params'}};
2514: }
2515: if (ref($info->{'before'}) eq 'HASH') {
2516: %before = %{$info->{'before'}};
2517: }
2518: if (ref($info->{'after'}) eq 'HASH') {
2519: %after = %{$info->{'after'}};
2520: }
2521: }
2522: if (ref($moves) eq 'HASH') {
2523: if (ref($moves->{'copies'}) eq 'HASH') {
2524: %copies = %{$moves->{'copies'}};
2525: }
2526: if (ref($moves->{'docmoves'}) eq 'HASH') {
2527: %docmoves = %{$moves->{'docmoves'}};
2528: }
2529: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2530: %mapmoves = %{$moves->{'mapmoves'}};
2531: }
2532: }
2533: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2534: my @allcopies;
1.529 raeburn 2535: if (exists($copies{$key})) {
2536: if (ref($copies{$key}) eq 'HASH') {
2537: my %added;
2538: foreach my $innerkey (keys(%{$copies{$key}})) {
2539: if (($innerkey ne '') && (!$added{$innerkey})) {
2540: push(@allcopies,$innerkey);
2541: $added{$innerkey} = 1;
2542: }
1.491 raeburn 2543: }
1.529 raeburn 2544: undef(%added);
1.491 raeburn 2545: }
2546: }
2547: if ($key eq $oldurl) {
1.529 raeburn 2548: if ((exists($docmoves{$key}))) {
1.532 raeburn 2549: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2550: push(@allcopies,$oldurl);
2551: }
2552: }
2553: }
2554: if (@allcopies > 0) {
2555: foreach my $item (@allcopies) {
1.492 raeburn 2556: my ($relpath,$oldsubdir,$fname) =
2557: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2558: if ($fname ne '') {
2559: my $content = &Apache::lonnet::getfile($item);
2560: unless ($content eq '-1') {
2561: my $storefn;
1.529 raeburn 2562: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2563: $storefn = $docmoves{$key};
1.491 raeburn 2564: } else {
2565: $storefn = $relpath;
2566: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2567: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2568: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2569: }
1.529 raeburn 2570: if ($newsubdir{$key}) {
1.532 raeburn 2571: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2572: }
2573: }
2574: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2575: my $copyurl =
2576: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2577: $storefn.$fname,$content);
2578: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2579: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2580: return &mt('Paste failed: an error occurred copying the file.');
2581: } elsif (ref($errors) eq 'HASH') {
2582: $errors->{$item} = 1;
1.489 raeburn 2583: }
2584: }
1.488 raeburn 2585: }
2586: }
1.491 raeburn 2587: }
2588: }
2589: }
1.529 raeburn 2590: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2591: my $storefn=$key;
2592: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2593: if ($prefixchg && $before{'map'} && $after{'map'}) {
2594: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2595: }
1.529 raeburn 2596: if ($newsubdir{$key}) {
2597: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2598: }
1.491 raeburn 2599: my $mapcontent = &Apache::lonnet::getfile($key);
2600: if ($mapcontent eq '-1') {
2601: if (ref($errors) eq 'HASH') {
2602: $errors->{$key} = 1;
2603: }
2604: } else {
2605: my $newmap =
2606: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2607: $mapcontent);
2608: if ($newmap eq '/adm/notfound.html') {
2609: if (ref($errors) eq 'HASH') {
2610: $errors->{$key} = 1;
1.489 raeburn 2611: }
1.488 raeburn 2612: }
2613: }
2614: }
1.491 raeburn 2615: my %updates;
2616: if ($is_map) {
1.529 raeburn 2617: if (ref($updated) eq 'HASH') {
2618: foreach my $type (keys(%{$updated})) {
2619: if (ref($updated->{$type}) eq 'HASH') {
2620: foreach my $key (keys(%{$updated->{$type}})) {
2621: $updates{$key} = 1;
2622: }
2623: }
2624: }
1.491 raeburn 2625: }
2626: foreach my $key (keys(%updates)) {
1.492 raeburn 2627: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2628: if (ref($rewrites{$key}) eq 'HASH') {
2629: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2630: }
1.529 raeburn 2631: if (ref($retitles{$key}) eq 'HASH') {
2632: %toretitle = %{$retitles{$key}};
1.491 raeburn 2633: }
1.529 raeburn 2634: if (ref($removefrommap{$key}) eq 'HASH') {
2635: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2636: }
1.529 raeburn 2637: if (ref($removeparam{$key}) eq 'HASH') {
2638: %remparam = %{$removeparam{$key}};
1.492 raeburn 2639: }
1.529 raeburn 2640: if (ref($zombies{$key}) eq 'HASH') {
2641: %zombie = %{$zombies{$key}};
1.491 raeburn 2642: }
1.529 raeburn 2643: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2644: foreach my $idx (keys(%{$dbcopies{$key}})) {
2645: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2646: my ($newurl,$result,$errtext) =
2647: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2648: if ($result eq 'ok') {
2649: $newdb{$idx} = $newurl;
2650: } elsif (ref($errors) eq 'HASH') {
2651: $errors->{$key} = 1;
2652: }
2653: push(@msgs,$errtext);
2654: }
1.491 raeburn 2655: }
2656: }
1.597 raeburn 2657: if (ref($resdatacopy{$key}) eq 'HASH') {
2658: if ($newsubdir{$key}) {
2659:
2660: }
2661: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2662: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2663: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2664: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2665: my $template = $1;
2666: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2667: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2668: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2669: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2670: my ($newmapname) = ($key =~ m{/([^/]+)$});
2671: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2672: my $srcmapinfo = $srcfolder.':'.$idx;
2673: if ($srccontainer eq 'page') {
2674: $srcmapinfo .= ':1';
2675: }
2676: if ($newsubdir{$key}) {
2677: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2678: }
2679: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2680: $cnum,$template,$idx,$newmapname);
2681: }
2682: }
2683: }
2684: }
2685: }
1.529 raeburn 2686: if (ref($params{$key}) eq 'HASH') {
2687: %currparam = %{$params{$key}};
1.492 raeburn 2688: }
2689: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2690: if ($fatal) {
1.533 raeburn 2691: return ($errtext);
1.492 raeburn 2692: }
2693: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2694: if (defined($LONCAPA::map::zombies[$i])) {
2695: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2696: if ($zombie{$i} eq $src) {
1.492 raeburn 2697: undef($LONCAPA::map::zombies[$i]);
2698: }
2699: }
2700: }
1.529 raeburn 2701: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2702: my $idx = $LONCAPA::map::order[$i];
2703: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2704: my $changed;
1.529 raeburn 2705: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2706: if ((exists($toremove{$idx})) &&
2707: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2708: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2709: if (ref($currparam{$idx}) eq 'ARRAY') {
2710: foreach my $name (@{$currparam{$idx}}) {
2711: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2712: }
2713: }
2714: next;
2715: }
2716: my $origsrc = $src;
1.532 raeburn 2717: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2718: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2719: $changed = 1;
1.491 raeburn 2720: }
1.492 raeburn 2721: }
1.532 raeburn 2722: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2723: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2724: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2725: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2726: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2727: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2728: } else {
1.529 raeburn 2729: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2730: }
1.491 raeburn 2731: }
1.532 raeburn 2732: if ($origsrc =~ /\.(page|sequence)$/) {
2733: if ($newsubdir{$origsrc}) {
1.529 raeburn 2734: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2735: }
1.532 raeburn 2736: } elsif ($newsubdir{$key}) {
2737: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2738: }
2739: }
1.492 raeburn 2740: $changed = 1;
1.533 raeburn 2741: } elsif ($newdb{$idx} ne '') {
2742: $src = $newdb{$idx};
1.492 raeburn 2743: $changed = 1;
2744: }
2745: if ($changed) {
1.538 raeburn 2746: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2747: }
2748: }
2749: }
2750: foreach my $idx (keys(%remparam)) {
2751: if (ref($remparam{$idx}) eq 'ARRAY') {
2752: foreach my $name (@{$remparam{$idx}}) {
2753: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2754: }
2755: }
2756: }
1.533 raeburn 2757: if (values(%lockerrors) > 0) {
2758: $lockmsg = join('<br />',values(%lockerrors));
2759: }
1.491 raeburn 2760: my $storefn;
2761: if ($key eq $oldurl) {
2762: $storefn = $url;
2763: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2764: } else {
2765: $storefn = $key;
2766: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2767: if ($prefixchg && $before{'map'} && $after{'map'}) {
2768: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2769: }
1.529 raeburn 2770: if ($newsubdir{$key}) {
2771: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2772: }
1.491 raeburn 2773: }
1.492 raeburn 2774: my $report;
2775: if ($folder !~ /^supplemental/) {
2776: $report = 1;
2777: }
1.527 raeburn 2778: (my $outtext,$errtext) =
1.492 raeburn 2779: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2780: if ($errtext) {
1.529 raeburn 2781: if ($caller eq 'paste') {
1.533 raeburn 2782: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2783: }
1.491 raeburn 2784: }
2785: }
2786: }
1.533 raeburn 2787: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2788: }
2789:
2790: sub copy_dependencies {
2791: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2792: my $content;
2793: if (ref($contentref)) {
2794: $content = $$contentref;
2795: } else {
2796: $content = &Apache::lonnet::getfile($item);
2797: }
2798: unless ($content eq '-1') {
2799: my $mm = new File::MMagic;
2800: my $mimetype = $mm->checktype_contents($content);
2801: if ($mimetype eq 'text/html') {
2802: my (%allfiles,%codebase,$state);
2803: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2804: if ($res eq 'ok') {
2805: my ($numexisting,$numpathchanges,$existing);
2806: (undef,$numexisting,$numpathchanges,$existing) =
2807: &Apache::loncommon::ask_for_embedded_content(
2808: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2809: {'error_on_invalid_names' => 1,
2810: 'ignore_remote_references' => 1,
2811: 'docs_url' => $item,
2812: 'context' => 'paste'});
2813: if ($numexisting > 0) {
2814: if (ref($existing) eq 'HASH') {
2815: foreach my $dep (keys(%{$existing})) {
2816: my $depfile = $dep;
2817: unless ($depfile =~ m{^\Q$relpath\E}) {
2818: $depfile = $relpath.$dep;
2819: }
2820: my $depcontent = &Apache::lonnet::getfile($depfile);
2821: unless ($depcontent eq '-1') {
2822: my $storedep = $dep;
2823: $storedep =~ s{^\Q$relpath\E}{};
2824: my $dep_url =
2825: &Apache::lonclonecourse::writefile(
2826: $env{'request.course.id'},
2827: $storefn.$storedep,$depcontent);
2828: if ($dep_url eq '/adm/notfound.html') {
2829: if (ref($errors) eq 'HASH') {
2830: $errors->{$depfile} = 1;
2831: }
2832: } else {
2833: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2834: }
2835: }
2836: }
1.488 raeburn 2837: }
2838: }
2839: }
2840: }
2841: }
2842: return;
2843: }
2844:
1.329 droeschl 2845: my %parameter_type = ( 'randompick' => 'int_pos',
2846: 'hiddenresource' => 'string_yesno',
2847: 'encrypturl' => 'string_yesno',
2848: 'randomorder' => 'string_yesno',);
2849: my $valid_parameters_re = join('|',keys(%parameter_type));
2850: # set parameters
2851: sub update_parameter {
1.537 raeburn 2852: if ($env{'form.changeparms'} eq 'all') {
2853: my (@allidx,@allmapidx,%allchecked,%currchecked);
2854: %allchecked = (
2855: 'hiddenresource' => {},
2856: 'encrypturl' => {},
2857: 'randompick' => {},
2858: 'randomorder' => {},
2859: );
2860: foreach my $which (keys(%allchecked)) {
2861: $env{'form.all'.$which} =~ s/,$//;
2862: if ($which eq 'randompick') {
2863: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2864: my ($res,$value) = split(/:/,$item);
2865: if ($value =~ /^\d+$/) {
2866: $allchecked{$which}{$res} = $value;
2867: }
2868: }
2869: } else {
1.539 raeburn 2870: if ($env{'form.all'.$which}) {
2871: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2872: }
1.537 raeburn 2873: }
2874: }
2875: my $haschanges = 0;
2876: foreach my $res (@LONCAPA::map::order) {
2877: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2878: $name=&LONCAPA::map::qtescape($name);
2879: $url=&LONCAPA::map::qtescape($url);
2880: next unless ($name && $url);
2881: my $is_map;
2882: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2883: $is_map = 1;
2884: }
2885: foreach my $which (keys(%allchecked)) {
2886: if (($which eq 'randompick' || $which eq 'randomorder')) {
2887: next if (!$is_map);
2888: }
2889: my $oldvalue = 0;
2890: my $newvalue = 0;
2891: if ($allchecked{$which}{$res}) {
2892: $newvalue = $allchecked{$which}{$res};
2893: }
2894: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2895: if ($which eq 'randompick') {
2896: if ($current =~ /^(\d+)$/) {
2897: $oldvalue = $1;
2898: }
2899: } else {
2900: if ($current =~ /^yes$/i) {
2901: $oldvalue = 1;
2902: }
2903: }
2904: if ($oldvalue ne $newvalue) {
2905: $haschanges = 1;
2906: if ($newvalue) {
2907: my $storeval = 'yes';
2908: if ($which eq 'randompick') {
2909: $storeval = $newvalue;
2910: }
2911: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2912: $storeval,
2913: $parameter_type{$which});
2914: &remember_parms($res,$which,'set',$storeval);
2915: } elsif ($oldvalue) {
2916: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2917: &remember_parms($res,$which,'del');
2918: }
2919: }
2920: }
2921: }
2922: return $haschanges;
2923: } else {
1.588 raeburn 2924: my $haschanges = 0;
2925: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2926:
1.537 raeburn 2927: my $which = $env{'form.changeparms'};
2928: my $idx = $env{'form.setparms'};
1.588 raeburn 2929: my $oldvalue = 0;
2930: my $newvalue = 0;
2931: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2932: if ($which eq 'randompick') {
2933: if ($current =~ /^(\d+)$/) {
2934: $oldvalue = $1;
2935: }
2936: } elsif ($current =~ /^yes$/i) {
2937: $oldvalue = 1;
2938: }
1.537 raeburn 2939: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2940: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2941: : 1;
2942: }
2943: if ($oldvalue ne $newvalue) {
2944: $haschanges = 1;
2945: if ($newvalue) {
2946: my $storeval = 'yes';
2947: if ($which eq 'randompick') {
2948: $storeval = $newvalue;
2949: }
2950: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2951: $parameter_type{$which});
2952: &remember_parms($idx,$which,'set',$storeval);
2953: } else {
2954: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2955: &remember_parms($idx,$which,'del');
2956: }
1.537 raeburn 2957: }
1.588 raeburn 2958: return $haschanges;
1.329 droeschl 2959: }
2960: }
2961:
2962: sub handle_edit_cmd {
2963: my ($coursenum,$coursedom) =@_;
1.543 raeburn 2964: if ($env{'form.cmd'} eq '') {
2965: return 0;
2966: }
1.329 droeschl 2967: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2968:
2969: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2970: my ($title, $url, @rrest) = split(':', $ratstr);
2971:
1.538 raeburn 2972: if ($cmd eq 'remove') {
1.329 droeschl 2973: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2974: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2975: &Apache::lonnet::removeuploadedurl($url);
2976: } else {
2977: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2978: }
2979: splice(@LONCAPA::map::order, $idx, 1);
2980:
2981: } elsif ($cmd eq 'cut') {
2982: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2983: splice(@LONCAPA::map::order, $idx, 1);
2984:
1.344 bisitz 2985: } elsif ($cmd eq 'up'
1.329 droeschl 2986: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2987: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2988:
2989: } elsif ($cmd eq 'down'
2990: && defined($LONCAPA::map::order[$idx+1])) {
2991: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2992:
2993: } elsif ($cmd eq 'rename') {
2994: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2995: if ($comment=~/\S/) {
2996: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2997: $comment.':'.join(':', $url, @rrest);
2998: }
2999: # Devalidate title cache
3000: my $renamed_url=&LONCAPA::map::qtescape($url);
3001: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 3002:
1.329 droeschl 3003: } else {
3004: return 0;
3005: }
3006: return 1;
3007: }
3008:
3009: sub editor {
1.458 raeburn 3010: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3011: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 ! raeburn 3012: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3013: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3014: if ($allowed) {
1.519 raeburn 3015: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3016: $is_random_order,$container) =
1.510 raeburn 3017: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3018: $r->print($breadcrumbtrail);
1.519 raeburn 3019: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3020: $container = 'page';
3021: } else {
3022: $container = 'sequence';
1.510 raeburn 3023: }
1.484 raeburn 3024:
1.525 raeburn 3025: my $jumpto;
3026:
3027: unless ($supplementalflag) {
1.546 raeburn 3028: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3029: }
1.484 raeburn 3030:
3031: unless ($allowed) {
3032: $randompick = -1;
3033: }
3034:
1.615 raeburn 3035: my ($errtext,$fatal);
3036: if (($folder eq '') && (!$supplementalflag)) {
3037: if (@LONCAPA::map::order) {
3038: undef(@LONCAPA::map::order);
3039: undef(@LONCAPA::map::resources);
3040: undef(@LONCAPA::map::resparms);
3041: undef(@LONCAPA::map::zombies);
3042: }
3043: $folder = 'default';
3044: $container = 'sequence';
3045: } else {
3046: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3047: $folder.'.'.$container);
3048: return $errtext if ($fatal);
3049: }
1.329 droeschl 3050:
3051: if ($#LONCAPA::map::order<1) {
3052: my $idx=&LONCAPA::map::getresidx();
3053: if ($idx<=0) { $idx=1; }
3054: $LONCAPA::map::order[0]=$idx;
3055: $LONCAPA::map::resources[$idx]='';
3056: }
1.364 bisitz 3057:
1.329 droeschl 3058: # ------------------------------------------------------------ Process commands
3059:
3060: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3061: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3062: # set parameters and change order
3063: &snapshotbefore();
3064:
3065: if (&update_parameter()) {
1.588 raeburn 3066: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3067: return $errtext if ($fatal);
3068: }
3069:
3070: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3071: # change order
3072: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3073: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3074:
3075: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3076: return $errtext if ($fatal);
3077: }
1.364 bisitz 3078:
1.329 droeschl 3079: if ($env{'form.pastemarked'}) {
1.491 raeburn 3080: my %paste_errors;
1.533 raeburn 3081: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3082: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3083: \%paste_errors);
1.541 raeburn 3084: if (ref($pastemsgarray) eq 'ARRAY') {
3085: if (@{$pastemsgarray} > 0) {
3086: $r->print('<p class="LC_info">'.
3087: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3088: '</p>');
3089: }
1.541 raeburn 3090: }
3091: if ($lockerror) {
3092: $r->print('<p class="LC_error">'.
3093: $lockerror.
3094: '</p>');
3095: }
3096: if ($save_error ne '') {
3097: return $save_error;
3098: }
3099: if ($paste_res) {
3100: my %errortext = &Apache::lonlocal::texthash (
3101: fail => 'Storage of folder contents failed',
3102: failread => 'Reading folder contents failed',
3103: failstore => 'Storage of folder contents failed',
3104: );
3105: if ($errortext{$paste_res}) {
3106: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3107: }
1.329 droeschl 3108: }
1.491 raeburn 3109: if (keys(%paste_errors) > 0) {
1.538 raeburn 3110: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3111: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
3112: '<ul>'."\n");
3113: foreach my $key (sort(keys(%paste_errors))) {
3114: $r->print('<li>'.$key.'</li>'."\n");
3115: }
3116: $r->print('</ul></p>'."\n");
3117: }
1.538 raeburn 3118: } elsif ($env{'form.clearmarked'}) {
3119: my $output = &do_buffer_empty();
3120: if ($output) {
3121: $r->print('<p class="LC_info">'.$output.'</p>');
3122: }
3123: }
1.329 droeschl 3124:
3125: $r->print($upload_output);
3126:
1.538 raeburn 3127: # Rename, cut, copy or remove a single resource
1.602 raeburn 3128: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3129: my $contentchg;
1.592 raeburn 3130: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 3131: $contentchg = 1;
3132: }
3133: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3134: return $errtext if ($fatal);
3135: }
1.538 raeburn 3136:
3137: # Cut, copy and/or remove multiple resources
3138: if ($env{'form.multichange'}) {
3139: my %allchecked = (
3140: cut => {},
3141: remove => {},
3142: );
3143: my $needsupdate;
3144: foreach my $which (keys(%allchecked)) {
3145: $env{'form.multi'.$which} =~ s/,$//;
3146: if ($env{'form.multi'.$which}) {
3147: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3148: if (ref($allchecked{$which}) eq 'HASH') {
3149: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3150: }
3151: }
3152: }
3153: if ($needsupdate) {
3154: my $haschanges = 0;
3155: my %curr_groups = &Apache::longroup::coursegroups();
3156: my $total = scalar(@LONCAPA::map::order) - 1;
3157: for (my $i=$total; $i>=0; $i--) {
3158: my $res = $LONCAPA::map::order[$i];
3159: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3160: $name=&LONCAPA::map::qtescape($name);
3161: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3162: next unless $url;
1.538 raeburn 3163: my %denied =
3164: &action_restrictions($coursenum,$coursedom,$url,
3165: $env{'form.folderpath'},\%curr_groups);
3166: foreach my $which (keys(%allchecked)) {
3167: next if ($denied{$which});
3168: next unless ($allchecked{$which}{$res});
3169: if ($which eq 'remove') {
3170: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3171: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3172: &Apache::lonnet::removeuploadedurl($url);
3173: } else {
3174: &LONCAPA::map::makezombie($res);
3175: }
3176: splice(@LONCAPA::map::order,$i,1);
3177: $haschanges ++;
3178: } elsif ($which eq 'cut') {
3179: &LONCAPA::map::makezombie($res);
3180: splice(@LONCAPA::map::order,$i,1);
3181: $haschanges ++;
3182: }
3183: }
3184: }
3185: if ($haschanges) {
3186: ($errtext,$fatal) =
3187: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3188: return $errtext if ($fatal);
3189: }
3190: }
3191: }
3192:
1.329 droeschl 3193: # Group import/search
3194: if ($env{'form.importdetail'}) {
3195: my @imports;
3196: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3197: if (defined($item)) {
3198: my ($name,$url,$residx)=
1.533 raeburn 3199: map { &unescape($_); } split(/\=/,$item);
3200: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3201: my ($suffix,$errortxt,$locknotfreed) =
3202: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3203: if ($locknotfreed) {
3204: $r->print($locknotfreed);
3205: }
3206: if ($suffix) {
3207: $url =~ s/_new\./_$suffix./;
3208: } else {
3209: return $errortxt;
3210: }
1.533 raeburn 3211: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3212: my $type = $1;
3213: my ($suffix,$errortxt,$locknotfreed) =
3214: &new_timebased_suffix($coursedom,$coursenum,$type);
3215: if ($locknotfreed) {
3216: $r->print($locknotfreed);
3217: }
3218: if ($suffix) {
3219: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3220: } else {
3221: return $errortxt;
3222: }
1.598 raeburn 3223: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
3224: my ($suffix,$errortxt,$locknotfreed) =
3225: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3226: if ($locknotfreed) {
3227: $r->print($locknotfreed);
3228: }
3229: if ($suffix) {
3230: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3231: } else {
3232: return $errortxt;
3233: }
1.534 raeburn 3234: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3235: if ($supplementalflag) {
3236: next unless ($1 eq 'supplemental');
3237: if ($folder eq 'supplemental') {
3238: next unless ($2 eq 'default');
3239: } else {
3240: next unless ($folder eq 'supplemental_'.$2);
3241: }
3242: } else {
3243: next unless ($1 eq 'docs');
3244: if ($folder eq 'default') {
3245: next unless ($2 eq 'default');
3246: } else {
3247: next unless ($folder eq 'default_'.$2);
3248: }
3249: }
1.504 raeburn 3250: }
1.329 droeschl 3251: push(@imports, [$name, $url, $residx]);
3252: }
3253: }
1.530 raeburn 3254: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3255: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3256: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3257: return $errtext if ($fatal);
1.529 raeburn 3258: if ($fixuperrors) {
3259: $r->print($fixuperrors);
3260: }
1.329 droeschl 3261: }
3262: # Loading a complete map
3263: if ($env{'form.loadmap'}) {
3264: if ($env{'form.importmap'}=~/\w/) {
3265: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3266: my ($title,$url,$ext,$type)=split(/\:/,$res);
3267: my $idx=&LONCAPA::map::getresidx($url);
3268: $LONCAPA::map::resources[$idx]=$res;
3269: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3270: }
3271: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3272: $folder.'.'.$container,1);
1.329 droeschl 3273: return $errtext if ($fatal);
3274: } else {
3275: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3276:
1.329 droeschl 3277: }
3278: }
3279: &log_differences($plain);
3280: }
3281: # ---------------------------------------------------------------- End commands
3282: # ---------------------------------------------------------------- Print screen
3283: my $idx=0;
3284: my $shown=0;
3285: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3286: $r->print('<div class="LC_Box">'.
1.432 raeburn 3287: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3288: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3289: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3290: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3291: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3292: '</ol>');
1.381 bisitz 3293: if ($randompick>=0) {
3294: $r->print('<p class="LC_warning">'
3295: .&mt('Caution: this folder is set to randomly pick a subset'
3296: .' of resources. Adding or removing resources from this'
3297: .' folder will change the set of resources that the'
3298: .' students see, resulting in spurious or missing credit'
3299: .' for completed problems, not limited to ones you'
3300: .' modify. Do not modify the contents of this folder if'
3301: .' it is in active student use.')
3302: .'</p>'
3303: );
3304: }
3305: if ($is_random_order) {
3306: $r->print('<p class="LC_warning">'
3307: .&mt('Caution: this folder is set to randomly order its'
3308: .' contents. Adding or removing resources from this folder'
3309: .' will change the order of resources shown.')
3310: .'</p>'
3311: );
3312: }
3313: $r->print('</div>');
1.364 bisitz 3314: }
1.381 bisitz 3315:
1.538 raeburn 3316: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3317: %filters = (
1.543 raeburn 3318: canremove => [],
3319: cancut => [],
3320: cancopy => [],
3321: hiddenresource => [],
3322: encrypturl => [],
3323: randomorder => [],
3324: randompick => [],
1.538 raeburn 3325: );
3326: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3327: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3328: foreach my $res (@LONCAPA::map::order) {
3329: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3330: $name=&LONCAPA::map::qtescape($name);
3331: $url=&LONCAPA::map::qtescape($url);
3332: unless ($name) { $name=(split(/\//,$url))[-1]; }
3333: unless ($name) { $idx++; next; }
1.537 raeburn 3334: push(@allidx,$res);
3335: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3336: push(@allmapidx,$res);
3337: }
1.617 raeburn 3338:
1.381 bisitz 3339: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3340: $coursenum,$coursedom,$crstype,
1.538 raeburn 3341: $pathitem,$supplementalflag,$container,
1.620 raeburn 3342: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 ! raeburn 3343: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3344: $idx++;
3345: $shown++;
1.329 droeschl 3346: }
1.424 onken 3347: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3348:
1.538 raeburn 3349: my $need_save;
1.611 raeburn 3350: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3351: my $toolslink;
1.611 raeburn 3352: if ($allowed) {
1.544 raeburn 3353: $toolslink = '<table><tr><td>'
1.520 raeburn 3354: .&Apache::loncommon::help_open_menu('Navigation Screen',
3355: 'Navigation_Screen',undef,'RAT')
3356: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3357: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3358: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3359: .'id="LC_content_toolbar_edittoplevel" '
3360: .'class="LC_toolbarItem" '
3361: .'title="'.&mt('Supplemental Content Editor').'">'
3362: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3363: }
1.510 raeburn 3364: if ($shown) {
3365: if ($allowed) {
3366: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3367: .&Apache::loncommon::start_data_table(undef,'contentlist')
3368: .&Apache::loncommon::start_data_table_header_row()
3369: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3370: .'<th colspan="2">'.&mt('Actions').'</th>'
3371: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3372: if ($folder !~ /^supplemental/) {
3373: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3374: }
1.537 raeburn 3375: $to_show .= &Apache::loncommon::end_data_table_header_row();
3376: if ($folder !~ /^supplemental/) {
1.538 raeburn 3377: $lists{'canhide'} = join(',',@allidx);
3378: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3379: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3380: 'randomorder','randompick');
3381: foreach my $item (@possfilters) {
1.538 raeburn 3382: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3383: if (@{$filters{$item}} > 0) {
3384: $lists{$item} = join(',',@{$filters{$item}});
3385: }
1.538 raeburn 3386: }
3387: }
1.537 raeburn 3388: if (@allidx > 0) {
3389: my $path;
3390: if ($env{'form.folderpath'}) {
3391: $path =
3392: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3393: }
1.538 raeburn 3394: if (@allidx > 1) {
3395: $to_show .=
3396: &Apache::loncommon::continue_data_table_row().
3397: '<td colspan="2"> </td>'.
3398: '<td>'.
1.611 raeburn 3399: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3400: '</td>'.
3401: '<td> </td>'.
3402: '<td> </td>'.
3403: '<td colspan="4">'.
1.611 raeburn 3404: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3405: '</td>'.
3406: &Apache::loncommon::end_data_table_row();
3407: $need_save = 1;
3408: }
1.537 raeburn 3409: }
3410: }
3411: $to_show .= $output.' '
1.510 raeburn 3412: .&Apache::loncommon::end_data_table()
3413: .'<br style="line-height:2px;" />'
3414: .&Apache::loncommon::end_scrollbox();
3415: } else {
1.520 raeburn 3416: $to_show .= $toolslink
1.510 raeburn 3417: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3418: .$output.' '
3419: .&Apache::loncommon::end_data_table();
1.393 raeburn 3420: }
1.510 raeburn 3421: } else {
1.520 raeburn 3422: if (!$allowed) {
3423: $to_show .= $toolslink;
3424: }
1.615 raeburn 3425: my $noresmsg;
3426: if ($allowed && $hiddentop && !$supplementalflag) {
3427: $noresmsg = &mt('Main Content Hidden');
3428: } else {
3429: $noresmsg = &mt('Currently empty');
3430: }
1.510 raeburn 3431: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3432: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3433: .$noresmsg
1.510 raeburn 3434: .'</div>'
3435: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3436: }
3437: } else {
1.510 raeburn 3438: if ($shown) {
3439: $to_show = '<div>'
3440: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3441: .$output
3442: .&Apache::loncommon::end_data_table()
3443: .'</div>';
3444: } else {
3445: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3446: .&mt('Currently empty')
1.510 raeburn 3447: .'</div>'
3448: }
1.458 raeburn 3449: }
3450: my $tid = 1;
3451: if ($supplementalflag) {
3452: $tid = 2;
1.329 droeschl 3453: }
3454: if ($allowed) {
1.484 raeburn 3455: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3456: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3457: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3458: if ($canedit) {
3459: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3460: }
1.460 raeburn 3461: } else {
3462: $r->print($to_show);
1.329 droeschl 3463: }
3464: return;
3465: }
3466:
1.538 raeburn 3467: sub multiple_check_form {
1.611 raeburn 3468: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3469: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3470: my $disabled;
3471: unless ($canedit) {
3472: $disabled = 'disabled="disabled"';
3473: }
1.538 raeburn 3474: my $output =
3475: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3476: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3477: '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick('."'$caller','0'".');" checked="checked" />'.&mt('one').'</label>'.(' 'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick('."'$caller','1'".');" />'.&mt('multiple').'</label></span><span id="more'.$caller.'" class="LC_nobreak LC_docs_ext_edit"></span></form>'.
3478: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3479: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3480: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3481: if ($caller eq 'settings') {
3482: $output .=
3483: '<table><tr>'.
3484: '<td class="LC_docs_entry_parameter">'.
3485: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3486: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3487: '</label></span></td>'.
3488: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3489: '<span class="LC_nobreak"><label><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');"'.$disabled.' />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
1.538 raeburn 3490: '</span></td>'.
3491: '</tr>'."\n".
3492: '<tr>'.
3493: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3494: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')"'.$disabled.' />'.&mt('URL hidden').'</label></span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><label><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')"'.$disabled.' />'.&mt('Random Order').
1.538 raeburn 3495: '</label></span>'.
3496: '</td></tr></table>'."\n";
3497: } else {
3498: $output .=
3499: '<table><tr>'.
3500: '<td class="LC_docs_entry_parameter">'.
3501: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3502: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3503: '</label></span></td>'.
3504: '<td class="LC_docs_entry_parameter">'.
3505: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3506: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3507: '</label></span></td>'."\n".
3508: '<td class="LC_docs_entry_parameter">'.
3509: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3510: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3511: '</label></span></td>'.
3512: '</tr></table>'."\n";
3513: }
3514: $output .=
3515: '</fieldset>'.
3516: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3517: if ($caller eq 'settings') {
3518: $output .=
1.543 raeburn 3519: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3520: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3521: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3522: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3523: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3524: } elsif ($caller eq 'actions') {
3525: $output .=
3526: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3527: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3528: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3529: }
3530: $output .=
3531: '</form>'.
3532: '</div>';
3533: return $output;
3534: }
3535:
1.329 droeschl 3536: sub process_file_upload {
1.552 raeburn 3537: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3538: # upload a file, if present
1.552 raeburn 3539: my $filesize = length($env{'form.uploaddoc'});
3540: if (!$filesize) {
3541: $$upload_output = '<div class="LC_error">'.
3542: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3543: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3544: $filesize).'<br />'.
3545: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3546: '</div>';
3547: return;
3548: }
3549: my $quotatype = 'unofficial';
3550: if ($crstype eq 'Community') {
1.601 raeburn 3551: $quotatype = 'community';
3552: } elsif ($crstype eq 'Placement') {
3553: $quotatype = 'placement';
1.580 raeburn 3554: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3555: $quotatype = 'official';
1.573 raeburn 3556: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3557: $quotatype = 'textbook';
1.552 raeburn 3558: }
3559: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3560: $filesize = int($filesize/1000); #expressed in kb
3561: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3562: $env{'form.uploaddoc.filename'},$filesize,
3563: 'upload',$quotatype);
1.552 raeburn 3564: return if ($$upload_output);
3565: }
1.440 raeburn 3566: my ($parseaction,$showupload,$nextphase,$mimetype);
3567: if ($env{'form.parserflag'}) {
1.329 droeschl 3568: $parseaction = 'parse';
3569: }
3570: my $folder=$env{'form.folder'};
3571: if ($folder eq '') {
3572: $folder='default';
3573: }
3574: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3575: my $errtext='';
3576: my $fatal=0;
3577: my $container='sequence';
1.519 raeburn 3578: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3579: $container='page';
3580: }
3581: ($errtext,$fatal)=
1.534 raeburn 3582: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3583: if ($#LONCAPA::map::order<1) {
3584: $LONCAPA::map::order[0]=1;
3585: $LONCAPA::map::resources[1]='';
3586: }
3587: my $destination = 'docs/';
3588: if ($folder =~ /^supplemental/) {
3589: $destination = 'supplemental/';
3590: }
3591: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3592: $destination .= 'default/';
3593: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3594: $destination .= $2.'/';
3595: }
1.534 raeburn 3596: if ($fatal) {
3597: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'</div>';
3598: return;
3599: }
1.440 raeburn 3600: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3601: my $newidx=&LONCAPA::map::getresidx();
3602: $destination .= $newidx;
1.439 raeburn 3603: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3604: $parseaction,$allfiles,
1.440 raeburn 3605: $codebase,undef,undef,undef,undef,
3606: undef,undef,\$mimetype);
3607: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3608: my $stored = $1;
3609: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3610: $stored.'</span>').'</p>';
3611: } else {
3612: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3613:
1.457 raeburn 3614: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3615: return;
3616: }
1.329 droeschl 3617: my $ext='false';
3618: if ($url=~m{^http://}) { $ext='true'; }
3619: $url = &LONCAPA::map::qtunescape($url);
3620: my $comment=$env{'form.comment'};
3621: $comment = &LONCAPA::map::qtunescape($comment);
3622: if ($folder=~/^supplemental/) {
3623: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3624: $env{'user.domain'}.'___&&&___'.$comment;
3625: }
3626:
3627: $LONCAPA::map::resources[$newidx]=
3628: $comment.':'.$url.':'.$ext.':normal:res';
3629: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3630: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3631: $folder.'.'.$container,1);
1.329 droeschl 3632: if ($fatal) {
1.457 raeburn 3633: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3634: return;
1.329 droeschl 3635: } else {
1.440 raeburn 3636: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3637: $$upload_output = $showupload;
1.384 raeburn 3638: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3639: if ($total_embedded > 0) {
1.440 raeburn 3640: my $uploadphase = 'upload_embedded';
3641: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3642: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3643: my ($embedded,$num) =
3644: &Apache::loncommon::ask_for_embedded_content(
3645: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3646: if ($embedded) {
3647: if ($num) {
3648: $$upload_output .=
3649: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3650: $nextphase = $uploadphase;
3651: } else {
3652: $$upload_output .= $embedded;
3653: }
3654: } else {
3655: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3656: }
1.329 droeschl 3657: } else {
1.440 raeburn 3658: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3659: }
1.457 raeburn 3660: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3661: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3662: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3663: $nextphase = 'decompress_uploaded';
3664: my $position = scalar(@LONCAPA::map::order)-1;
3665: my $noextract = &return_to_editor();
3666: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3667: my %archiveitems = (
3668: folderpath => $env{'form.folderpath'},
3669: cmd => $nextphase,
3670: newidx => $newidx,
3671: position => $position,
3672: phase => $nextphase,
1.477 raeburn 3673: comment => $comment,
1.480 raeburn 3674: );
3675: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3676: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3677: $$upload_output = $showupload.
3678: &Apache::loncommon::decompress_form($mimetype,
3679: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3680: \%archiveitems,\@current);
1.329 droeschl 3681: }
3682: }
3683: }
1.440 raeburn 3684: return $nextphase;
1.329 droeschl 3685: }
3686:
1.480 raeburn 3687: sub get_dir_list {
3688: my ($url,$coursenum,$coursedom,$newidx) = @_;
3689: my ($destination,$dir_root) = &embedded_destination();
3690: my ($dirlistref,$listerror) =
3691: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3692: my @dir_lines;
3693: my $dirptr=16384;
3694: if (ref($dirlistref) eq 'ARRAY') {
3695: foreach my $dir_line (sort
3696: {
3697: my ($afile)=split('&',$a,2);
3698: my ($bfile)=split('&',$b,2);
3699: return (lc($afile) cmp lc($bfile));
3700: } (@{$dirlistref})) {
3701: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3702: $filename =~ s/\s+$//;
3703: next if ($filename =~ /^\.\.?$/);
3704: my $isdir = 0;
3705: if ($dirptr&$testdir) {
3706: $isdir = 1;
3707: }
3708: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3709: }
3710: }
3711: return @dir_lines;
3712: }
3713:
1.329 droeschl 3714: sub is_supplemental_title {
3715: my ($title) = @_;
3716: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3717: }
3718:
3719: # --------------------------------------------------------------- An entry line
3720:
3721: sub entryline {
1.501 raeburn 3722: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3723: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 ! raeburn 3724: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3725: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3726: if (&is_supplemental_title($title)) {
1.488 raeburn 3727: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3728: } else {
3729: $title=&HTML::Entities::encode($title,'"<>&\'');
3730: $renametitle=$title;
3731: $foldertitle=$title;
3732: }
3733:
1.611 raeburn 3734: my ($disabled,$readonly,$js_lt);
3735: unless ($canedit) {
3736: $disabled = 'disabled="disabled"';
3737: $readonly = 1;
3738: }
3739:
1.329 droeschl 3740: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3741:
1.329 droeschl 3742: $renametitle=~s/\\/\\\\/g;
3743: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3744: $renametitle=~s/"/%22/g;
1.581 raeburn 3745: $renametitle=~s/ /%20/g;
3746: $oldtitle = $renametitle;
1.576 raeburn 3747: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3748: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3749: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3750: # Edit commands
1.535 raeburn 3751: my ($esc_path, $path, $symb);
1.329 droeschl 3752: if ($env{'form.folderpath'}) {
3753: $esc_path=&escape($env{'form.folderpath'});
3754: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3755: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3756: }
1.505 raeburn 3757: my $isexternal;
1.510 raeburn 3758: if ($residx) {
1.501 raeburn 3759: my $currurl = $url;
3760: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3761: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3762: $isexternal = 1;
3763: }
1.510 raeburn 3764: if (!$supplementalflag) {
3765: my $path = 'uploaded/'.
3766: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3767: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3768: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3769: $residx,
3770: &Apache::lonnet::declutter($currurl));
3771: }
1.501 raeburn 3772: }
1.538 raeburn 3773: my ($renamelink,%lt,$ishash);
3774: if (ref($filtersref) eq 'HASH') {
3775: $ishash = 1;
3776: }
3777:
1.329 droeschl 3778: if ($allowed) {
1.538 raeburn 3779: $form_start = '
3780: <form action="/adm/coursedocs" method="post">
3781: ';
3782: $form_common=(<<END);
3783: <input type="hidden" name="folderpath" value="$path" />
3784: <input type="hidden" name="symb" value="$symb" />
3785: END
3786: $form_param=(<<END);
3787: <input type="hidden" name="setparms" value="$orderidx" />
3788: <input type="hidden" name="changeparms" value="0" />
3789: END
3790: $form_end = '</form>';
3791:
1.329 droeschl 3792: my $incindex=$index+1;
3793: my $selectbox='';
1.471 raeburn 3794: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3795: ((split(/\:/,
1.344 bisitz 3796: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3797: ne '') &&
1.329 droeschl 3798: ((split(/\:/,
1.344 bisitz 3799: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3800: ne '')) {
3801: $selectbox=
3802: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3803: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3804: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3805: if ($i==$incindex) {
1.358 bisitz 3806: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3807: } else {
3808: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3809: }
3810: }
3811: $selectbox.='</select>';
3812: }
1.501 raeburn 3813: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3814: 'up' => 'Move Up',
3815: 'dw' => 'Move Down',
3816: 'rm' => 'Remove',
3817: 'ct' => 'Cut',
3818: 'rn' => 'Rename',
1.501 raeburn 3819: 'cp' => 'Copy',
3820: 'ex' => 'External Resource',
1.598 raeburn 3821: 'et' => 'External Tool',
1.501 raeburn 3822: 'ed' => 'Edit',
3823: 'pr' => 'Preview',
3824: 'sv' => 'Save',
3825: 'ul' => 'URL',
1.611 raeburn 3826: 'ti' => 'Title',
1.618 raeburn 3827: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3828: );
1.538 raeburn 3829: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3830: $env{'form.folderpath'},
3831: $currgroups);
1.517 raeburn 3832: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3833: my $skip_confirm = 0;
1.603 raeburn 3834: my $confirm_removal = 0;
1.329 droeschl 3835: if ( $folder =~ /^supplemental/
3836: || ($url =~ m{( /smppg$
3837: |/syllabus$
3838: |/aboutme$
3839: |/navmaps$
3840: |/bulletinboard$
1.598 raeburn 3841: |/exttools?$
1.505 raeburn 3842: |\.html$)}x)
3843: || $isexternal) {
1.329 droeschl 3844: $skip_confirm = 1;
3845: }
1.603 raeburn 3846: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3847: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3848: $confirm_removal = 1;
3849: }
1.329 droeschl 3850:
1.538 raeburn 3851: if ($denied{'copy'}) {
1.543 raeburn 3852: $copylink=(<<ENDCOPY)
1.507 raeburn 3853: <span style="visibility: hidden;">$lt{'cp'}</span>
3854: ENDCOPY
3855: } else {
1.538 raeburn 3856: my $formname = 'edit_copy_'.$orderidx;
3857: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3858: $copylink=(<<ENDCOPY);
1.538 raeburn 3859: <form name="$formname" method="post" action="/adm/coursedocs">
3860: $form_common
1.611 raeburn 3861: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.538 raeburn 3862: $form_end
1.329 droeschl 3863: ENDCOPY
1.538 raeburn 3864: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3865: push(@{$filtersref->{'cancopy'}},$orderidx);
3866: }
1.329 droeschl 3867: }
1.538 raeburn 3868: if ($denied{'cut'}) {
1.507 raeburn 3869: $cutlink=(<<ENDCUT);
3870: <span style="visibility: hidden;">$lt{'ct'}</span>
3871: ENDCUT
3872: } else {
1.538 raeburn 3873: my $formname = 'edit_cut_'.$orderidx;
3874: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3875: $cutlink=(<<ENDCUT);
1.538 raeburn 3876: <form name="$formname" method="post" action="/adm/coursedocs">
3877: $form_common
1.542 raeburn 3878: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3879: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.538 raeburn 3880: $form_end
1.329 droeschl 3881: ENDCUT
1.538 raeburn 3882: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3883: push(@{$filtersref->{'cancut'}},$orderidx);
3884: }
1.329 droeschl 3885: }
1.538 raeburn 3886: if ($denied{'remove'}) {
1.507 raeburn 3887: $removelink=(<<ENDREM);
3888: <span style="visibility: hidden;">$lt{'rm'}</a>
3889: ENDREM
3890: } else {
1.538 raeburn 3891: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3892: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3893: $removelink=(<<ENDREM);
1.538 raeburn 3894: <form name="$formname" method="post" action="/adm/coursedocs">
3895: $form_common
1.542 raeburn 3896: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3897: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 3898: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.538 raeburn 3899: $form_end
1.497 raeburn 3900: ENDREM
1.538 raeburn 3901: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3902: push(@{$filtersref->{'canremove'}},$orderidx);
3903: }
1.497 raeburn 3904: }
1.551 raeburn 3905: $renamelink=(<<ENDREN);
1.581 raeburn 3906: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3907: ENDREN
1.611 raeburn 3908: my ($uplink,$downlink);
3909: if ($canedit) {
3910: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3911: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3912: } else {
3913: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3914: $downlink = $uplink;
3915: }
1.329 droeschl 3916: $line.=(<<END);
3917: <td>
1.379 bisitz 3918: <div class="LC_docs_entry_move">
1.611 raeburn 3919: <a href="$uplink">
1.501 raeburn 3920: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3921: </a>
3922: </div>
3923: <div class="LC_docs_entry_move">
1.611 raeburn 3924: <a href="$downlink">
1.501 raeburn 3925: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3926: </a>
3927: </div>
1.329 droeschl 3928: </td>
3929: <td>
3930: $form_start
1.538 raeburn 3931: $form_param
1.478 raeburn 3932: $form_common
1.329 droeschl 3933: $selectbox
3934: $form_end
3935: </td>
1.540 raeburn 3936: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3937: $removelink
1.329 droeschl 3938: $cutlink
3939: $copylink
3940: </td>
3941: END
3942: }
3943: # Figure out what kind of a resource this is
3944: my ($extension)=($url=~/\.(\w+)$/);
3945: my $uploaded=($url=~/^\/*uploaded\//);
3946: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3947: my $isfolder;
3948: my $ispage;
3949: my $containerarg;
1.615 raeburn 3950: my $folderurl;
1.329 droeschl 3951: if ($uploaded) {
1.472 raeburn 3952: if (($extension eq 'sequence') || ($extension eq 'page')) {
3953: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3954: $containerarg = $1;
1.472 raeburn 3955: if ($extension eq 'sequence') {
3956: $icon=$iconpath.'navmap.folder.closed.gif';
3957: $isfolder=1;
3958: } else {
3959: $icon=$iconpath.'page.gif';
3960: $ispage=1;
3961: }
1.615 raeburn 3962: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3963: if ($allowed) {
3964: $url='/adm/coursedocs?';
3965: } else {
3966: $url='/adm/supplemental?';
3967: }
1.329 droeschl 3968: } else {
3969: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3970: }
3971: }
1.364 bisitz 3972:
1.621 raeburn 3973: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3974: my $orig_url = $url;
1.340 raeburn 3975: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 3976: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 3977: if (!$supplementalflag && $residx && $symb) {
3978: if ((!$isfolder) && (!$ispage)) {
3979: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3980: $url=&Apache::lonnet::clutter($url);
3981: if ($url=~/^\/*uploaded\//) {
3982: $url=~/\.(\w+)$/;
3983: my $embstyle=&Apache::loncommon::fileembstyle($1);
3984: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3985: $url='/adm/wrapper'.$url;
3986: } elsif ($embstyle eq 'ssi') {
3987: #do nothing with these
3988: } elsif ($url!~/\.(sequence|page)$/) {
3989: $url='/adm/coursedocs/showdoc'.$url;
3990: }
3991: } elsif ($url=~m|^/ext/|) {
3992: $url='/adm/wrapper'.$url;
1.598 raeburn 3993: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3994: $url='/adm/wrapper'.$url;
1.621 raeburn 3995: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3996: if (($ENV{'SERVER_PORT'} == 443) &&
3997: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
3998: $url .= '?usehttp=1';
3999: $nomodal = 1;
4000: }
1.598 raeburn 4001: }
1.501 raeburn 4002: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4003: my $shownsymb = $symb;
4004: if ($isexternal) {
4005: if ($url =~ /^([^#]+)#([^#]+)$/) {
4006: $url = $1;
4007: $anchor = $2;
4008: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4009: $shownsymb = $1.&escape('#').$anchor;
4010: }
4011: }
4012: }
1.617 raeburn 4013: unless ($env{'request.role.adv'}) {
4014: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4015: $url = '';
4016: }
4017: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4018: $url = '';
4019: $hiddenres = 1;
4020: }
4021: }
4022: if ($url ne '') {
4023: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4024: }
1.615 raeburn 4025: } elsif (!$env{'request.role.adv'}) {
4026: my $checkencrypt;
4027: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4028: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4029: $checkencrypt = 1;
1.620 raeburn 4030: } elsif (ref($navmapref)) {
1.615 raeburn 4031: unless (ref($$navmapref)) {
4032: $$navmapref = Apache::lonnavmaps::navmap->new();
4033: }
4034: if (ref($$navmapref)) {
4035: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4036: $checkencrypt = 1;
4037: }
4038: }
4039: }
4040: if ($checkencrypt) {
4041: my $shownsymb = &Apache::lonenc::encrypted($symb);
4042: my $shownurl = &Apache::lonenc::encrypted($url);
4043: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4044: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4045: if ($env{'request.enc'} ne '') {
4046: delete($env{'request.enc'});
4047: }
4048: } else {
4049: $url='';
1.613 raeburn 4050: }
1.612 raeburn 4051: } else {
4052: $url='';
4053: }
1.501 raeburn 4054: } else {
4055: $url='';
4056: }
1.329 droeschl 4057: }
1.621 raeburn 4058: } elsif ($supplementalflag) {
1.610 raeburn 4059: if ($isexternal) {
4060: if ($url =~ /^([^#]+)#([^#]+)$/) {
4061: $url = $1;
4062: $anchor = $2;
4063: }
1.621 raeburn 4064: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4065: if (($ENV{'SERVER_PORT'} == 443) &&
4066: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.622 ! raeburn 4067: if ($hostname ne '') {
! 4068: $url = 'http://'.$hostname.$url;
! 4069: }
1.621 raeburn 4070: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4071: $nomodal = 1;
4072: }
1.610 raeburn 4073: }
1.329 droeschl 4074: }
1.615 raeburn 4075: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4076: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4077: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4078: my $foldername=&escape($foldertitle);
4079: my $folderpath=$env{'form.folderpath'};
4080: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4081: if (!$allowed && $supplementalflag) {
1.519 raeburn 4082: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4083: $url.='folderpath='.&escape($folderpath);
4084: } else {
1.617 raeburn 4085: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4086: 'parameter_randompick'))[0];
4087: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4088: 'parameter_randomorder'))[0]=~/^yes$/i);
4089: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4090: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4091: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4092: 'parameter_encrypturl'))[0]=~/^yes$/i);
4093: unless ($hiddenmap) {
1.620 raeburn 4094: if (ref($navmapref)) {
4095: unless (ref($$navmapref)) {
4096: $$navmapref = Apache::lonnavmaps::navmap->new();
4097: }
4098: if (ref($$navmapref)) {
4099: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4100: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4101: unless (@resources) {
4102: $hiddenmap = 1;
4103: unless ($env{'request.role.adv'}) {
4104: $url = '';
4105: $hiddenfolder = 1;
4106: }
1.617 raeburn 4107: }
1.615 raeburn 4108: }
4109: }
4110: }
4111: }
1.617 raeburn 4112: unless ($encryptmap) {
1.620 raeburn 4113: if ((ref($navmapref)) && (ref($$navmapref))) {
4114: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4115: $encryptmap = 1;
4116: }
1.617 raeburn 4117: }
4118: }
4119:
4120: # Append randompick number, hidden, and encrypted with ":" to foldername,
4121: # so it gets transferred between levels
4122: $folderpath.=$containerarg.'&'.$foldername.
4123: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4124: unless ($url eq '') {
1.612 raeburn 4125: $url.='folderpath='.&escape($folderpath);
4126: }
1.510 raeburn 4127: my $rpckchk;
4128: if ($rpicknum) {
4129: $rpckchk = ' checked="checked"';
1.543 raeburn 4130: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4131: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4132: }
1.510 raeburn 4133: }
1.537 raeburn 4134: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4135: $rand_pick_text =
1.478 raeburn 4136: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4137: $form_param."\n".
1.478 raeburn 4138: $form_common."\n".
1.611 raeburn 4139: '<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 4140: if ($rpicknum ne '') {
4141: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4142: }
1.537 raeburn 4143: $rand_pick_text .= '</span></span>'.
4144: $form_end;
1.543 raeburn 4145: my $ro_set;
1.617 raeburn 4146: if ($randorder) {
1.543 raeburn 4147: $ro_set = 'checked="checked"';
4148: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4149: push(@{$filtersref->{'randomorder'}},$orderidx);
4150: }
4151: }
1.564 raeburn 4152: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4153: $rand_order_text =
1.537 raeburn 4154: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4155: $form_param."\n".
1.537 raeburn 4156: $form_common."\n".
1.611 raeburn 4157: '<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 4158: $form_end;
1.510 raeburn 4159: }
1.509 raeburn 4160: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4161: my $isexttool;
4162: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4163: $url='/adm/wrapper'.$url;
4164: $isexttool = 1;
4165: }
1.510 raeburn 4166: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4167: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4168: if ($title) {
4169: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4170: }
1.598 raeburn 4171: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4172: $url .= '&idx='.$orderidx;
4173: }
1.610 raeburn 4174: if ($anchor ne '') {
4175: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4176: }
1.329 droeschl 4177: }
1.519 raeburn 4178: my ($tdalign,$tdwidth);
1.501 raeburn 4179: if ($allowed) {
4180: my $fileloc =
4181: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4182: if ($isexternal) {
1.518 raeburn 4183: ($editlink,$extresform) =
1.611 raeburn 4184: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4185: undef,undef,undef,undef,undef,undef,
4186: undef,$disabled);
1.598 raeburn 4187: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4188: ($editlink,$extresform) =
4189: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4190: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4191: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4192: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4193: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4194: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4195: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4196: my $suppanchor;
4197: if ($supplementalflag) {
4198: $suppanchor = $anchor;
4199: }
1.501 raeburn 4200: my $jscall =
4201: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4202: $switchserver,
1.503 raeburn 4203: $forceedit,
1.511 raeburn 4204: undef,$symb,
4205: &escape($env{'form.folderpath'}),
1.622 ! raeburn 4206: $renametitle,$hostname,
! 4207: '','',1,$suppanchor);
1.501 raeburn 4208: if ($jscall) {
1.518 raeburn 4209: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4210: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4211: }
4212: }
4213: }
1.519 raeburn 4214: $tdalign = ' align="right" valign="top"';
4215: $tdwidth = ' width="80%"';
1.329 droeschl 4216: }
1.408 raeburn 4217: my $reinit;
4218: if ($crstype eq 'Community') {
4219: $reinit = &mt('(re-initialize community to access)');
4220: } else {
4221: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4222: }
4223: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.621 raeburn 4224: my $link;
1.472 raeburn 4225: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4226: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4227: } elsif ($url) {
1.610 raeburn 4228: if ($anchor ne '') {
4229: if ($supplementalflag) {
4230: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4231: } else {
4232: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4233: }
4234: }
1.622 ! raeburn 4235: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
! 4236: $link = 'http://'.$hostname.$url;
! 4237: } else {
! 4238: $link = $url;
! 4239: }
! 4240: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.621 raeburn 4241: (($anchor ne '')?$anchor:''));
4242: if ($nomodal) {
4243: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4244: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4245: } else {
4246: $line.=&Apache::loncommon::modal_link($link,
4247: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4248: }
1.469 www 4249: } else {
4250: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4251: }
1.519 raeburn 4252: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4253: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4254: $line.='<a href="'.$url.'">'.$title.'</a>';
4255: } elsif ($url) {
1.621 raeburn 4256: if ($nomodal) {
4257: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4258: $title.'</a>';
4259: } else {
4260: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4261: }
1.617 raeburn 4262: } elsif (($hiddenfolder) || ($hiddenres)) {
1.615 raeburn 4263: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
1.469 www 4264: } else {
4265: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4266: }
1.518 raeburn 4267: $line.="$extresform</td>";
1.478 raeburn 4268: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4269: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4270: if (($allowed) && ($folder!~/^supplemental/)) {
4271: my %lt=&Apache::lonlocal::texthash(
4272: 'hd' => 'Hidden',
4273: 'ec' => 'URL hidden');
1.543 raeburn 4274: my ($enctext,$hidtext);
4275: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4276: $enctext = ' checked="checked"';
4277: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4278: push(@{$filtersref->{'encrypturl'}},$orderidx);
4279: }
4280: }
4281: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4282: $hidtext = ' checked="checked"';
4283: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4284: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4285: }
4286: }
1.537 raeburn 4287: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4288: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4289: $line.=(<<ENDPARMS);
4290: <td class="LC_docs_entry_parameter">
1.537 raeburn 4291: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4292: $form_param
1.478 raeburn 4293: $form_common
1.611 raeburn 4294: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4295: $form_end
1.458 raeburn 4296: <br />
1.537 raeburn 4297: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4298: $form_param
1.478 raeburn 4299: $form_common
1.611 raeburn 4300: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4301: $form_end
4302: </td>
1.478 raeburn 4303: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4304: $rand_order_text</td>
1.329 droeschl 4305: ENDPARMS
4306: }
1.379 bisitz 4307: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4308: return $line;
4309: }
4310:
1.538 raeburn 4311: sub action_restrictions {
4312: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4313: my %denied = (
4314: cut => 0,
4315: copy => 0,
4316: remove => 0,
4317: );
4318: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4319: # no copy for published maps
4320: $denied{'copy'} = 1;
1.597 raeburn 4321: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4322: unless ($1 eq 'simpleproblem') {
4323: $denied{'copy'} = 1;
4324: }
4325: $denied{'cut'} = 1;
1.538 raeburn 4326: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4327: if ($folderpath =~ /^default&[^\&]+$/) {
4328: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4329: $denied{'remove'} = 1;
4330: }
4331: $denied{'cut'} = 1;
4332: $denied{'copy'} = 1;
4333: }
4334: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4335: my $group = $1;
4336: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4337: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4338: $denied{'remove'} = 1;
4339: }
4340: }
4341: $denied{'cut'} = 1;
4342: $denied{'copy'} = 1;
4343: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4344: my $group = $1;
4345: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4346: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4347: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4348: if (keys(%groupsettings) > 0) {
4349: $denied{'remove'} = 1;
4350: }
4351: $denied{'cut'} = 1;
4352: $denied{'copy'} = 1;
4353: }
4354: }
4355: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4356: my $group = $1;
4357: if ($url =~ /group_boards_\Q$group\E/) {
4358: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4359: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4360: if (keys(%groupsettings) > 0) {
4361: if (ref($groupsettings{'functions'}) eq 'HASH') {
4362: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4363: $denied{'remove'} = 1;
4364: }
4365: }
4366: }
4367: $denied{'cut'} = 1;
4368: $denied{'copy'} = 1;
4369: }
4370: }
4371: }
4372: return %denied;
4373: }
4374:
1.533 raeburn 4375: sub new_timebased_suffix {
1.538 raeburn 4376: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4377: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4378: if ($type eq 'paste') {
4379: $prefix = $type;
4380: $namespace = 'courseeditor';
1.587 raeburn 4381: $idtype = 'addcode';
1.538 raeburn 4382: } elsif ($type eq 'map') {
1.533 raeburn 4383: $prefix = 'docs';
4384: if ($area eq 'supplemental') {
4385: $prefix = 'supp';
4386: }
4387: $prefix .= $container;
4388: $namespace = 'uploadedmaps';
4389: } else {
4390: $prefix = $type;
4391: $namespace = 'templated';
1.504 raeburn 4392: }
4393: my ($suffix,$freedlock,$error) =
1.587 raeburn 4394: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4395: if (!$suffix) {
1.538 raeburn 4396: if ($type eq 'paste') {
4397: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4398: } elsif ($type eq 'map') {
1.533 raeburn 4399: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4400: } elsif ($type eq 'smppg') {
4401: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4402: } else {
1.565 bisitz 4403: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4404: }
1.504 raeburn 4405: if ($error) {
4406: $errtext .= '<br />'.$error;
4407: }
4408: }
4409: if ($freedlock ne 'ok') {
1.533 raeburn 4410: $locknotfreed =
4411: '<div class="LC_error">'.
4412: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4413: if ($type eq 'paste') {
1.591 raeburn 4414: if ($freedlock eq 'nolock') {
4415: $locknotfreed =
4416: '<div class="LC_error">'.
4417: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4418:
1.593 droeschl 4419: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4420: } else {
4421: $locknotfreed .=
4422: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4423: }
1.538 raeburn 4424: } elsif ($type eq 'map') {
1.591 raeburn 4425: $locknotfreed .=
4426: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4427: } elsif ($type eq 'smppg') {
4428: $locknotfreed .=
4429: &mt('This will prevent creation of additional simple pages in this course.');
4430: } else {
4431: $locknotfreed .=
1.565 bisitz 4432: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4433: }
1.538 raeburn 4434: unless ($type eq 'paste') {
4435: $locknotfreed .=
1.560 raeburn 4436: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4437: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4438: }
4439: $locknotfreed .= '</div>';
1.504 raeburn 4440: }
4441: return ($suffix,$errtext,$locknotfreed);
4442: }
4443:
1.329 droeschl 4444: =pod
4445:
4446: =item tiehash()
4447:
4448: tie the hash
4449:
4450: =cut
4451:
4452: sub tiehash {
4453: my ($mode)=@_;
4454: $hashtied=0;
4455: if ($env{'request.course.fn'}) {
4456: if ($mode eq 'write') {
4457: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4458: &GDBM_WRCREAT(),0640)) {
4459: $hashtied=2;
4460: }
4461: } else {
4462: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4463: &GDBM_READER(),0640)) {
4464: $hashtied=1;
4465: }
4466: }
1.364 bisitz 4467: }
1.329 droeschl 4468: }
4469:
4470: sub untiehash {
4471: if ($hashtied) { untie %hash; }
4472: $hashtied=0;
4473: return OK;
4474: }
4475:
4476:
4477:
4478:
4479: sub checkonthis {
4480: my ($r,$url,$level,$title)=@_;
4481: $url=&unescape($url);
4482: $alreadyseen{$url}=1;
4483: $r->rflush();
4484: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4485: $r->print("\n<br />");
4486: if ($level==0) {
4487: $r->print("<br />");
4488: }
4489: for (my $i=0;$i<=$level*5;$i++) {
4490: $r->print(' ');
4491: }
4492: $r->print('<a href="'.$url.'" target="cat">'.
4493: ($title?$title:$url).'</a> ');
4494: if ($url=~/^\/res\//) {
4495: my $result=&Apache::lonnet::repcopy(
4496: &Apache::lonnet::filelocation('',$url));
4497: if ($result eq 'ok') {
4498: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4499: $r->rflush();
4500: &Apache::lonnet::countacc($url);
4501: $url=~/\.(\w+)$/;
4502: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4503: $r->print('<br />');
4504: $r->rflush();
4505: for (my $i=0;$i<=$level*5;$i++) {
4506: $r->print(' ');
4507: }
4508: $r->print('- '.&mt('Rendering:').' ');
4509: my ($errorcount,$warningcount)=split(/:/,
4510: &Apache::lonnet::ssi_body($url,
4511: ('grade_target'=>'web',
4512: 'return_only_error_and_warning_counts' => 1)));
4513: if (($errorcount) ||
4514: ($warningcount)) {
4515: if ($errorcount) {
1.369 bisitz 4516: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4517: &mt('[quant,_1,error]',$errorcount).'</span>');
4518: }
4519: if ($warningcount) {
4520: $r->print('<span class="LC_warning">'.
4521: &mt('[quant,_1,warning]',$warningcount).'</span>');
4522: }
4523: } else {
4524: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4525: }
4526: $r->rflush();
4527: }
4528: my $dependencies=
4529: &Apache::lonnet::metadata($url,'dependencies');
4530: foreach my $dep (split(/\,/,$dependencies)) {
4531: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4532: &checkonthis($r,$dep,$level+1);
4533: }
4534: }
4535: } elsif ($result eq 'unavailable') {
4536: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4537: } elsif ($result eq 'not_found') {
4538: unless ($url=~/\$/) {
1.521 bisitz 4539: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4540: } else {
1.366 bisitz 4541: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4542: }
4543: } else {
4544: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4545: }
4546: }
4547: }
4548: }
4549:
4550:
4551:
4552: =pod
4553:
4554: =item list_symbs()
4555:
1.485 raeburn 4556: List Content Identifiers
1.329 droeschl 4557:
4558: =cut
4559:
4560: sub list_symbs {
4561: my ($r) = @_;
4562:
1.408 raeburn 4563: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4564: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4565: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4566: $r->print(&startContentScreen('tools'));
1.329 droeschl 4567: my $navmap = Apache::lonnavmaps::navmap->new();
4568: if (!defined($navmap)) {
4569: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4570: '<div class="LC_error">'.
4571: &mt('Unable to retrieve information about course contents').
4572: '</div>');
1.408 raeburn 4573: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4574: } else {
1.484 raeburn 4575: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4576: &Apache::loncommon::start_data_table().
4577: &Apache::loncommon::start_data_table_header_row().
4578: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4579: &Apache::loncommon::end_data_table_header_row()."\n");
4580: my $count;
1.329 droeschl 4581: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4582: $r->print(&Apache::loncommon::start_data_table_row().
4583: '<td>'.$res->compTitle().'</td>'.
4584: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4585: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4586: $count ++;
4587: }
4588: if (!$count) {
4589: $r->print(&Apache::loncommon::start_data_table_row().
4590: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4591: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4592: }
1.484 raeburn 4593: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4594: }
1.521 bisitz 4595: $r->print(&endContentScreen());
1.329 droeschl 4596: }
4597:
4598:
4599: sub verifycontent {
4600: my ($r) = @_;
1.408 raeburn 4601: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4602: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4603: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4604: $r->print(&startContentScreen('tools'));
4605: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4606: $hashtied=0;
4607: undef %alreadyseen;
4608: %alreadyseen=();
4609: &tiehash();
1.484 raeburn 4610:
1.329 droeschl 4611: foreach my $key (keys(%hash)) {
4612: if ($hash{$key}=~/\.(page|sequence)$/) {
4613: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4614: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4615: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4616: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4617: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4618: }
4619: }
4620: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4621: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4622: }
4623: }
4624: &untiehash();
1.442 www 4625: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4626: $r->print(&endContentScreen());
1.329 droeschl 4627: }
4628:
4629:
4630: sub devalidateversioncache {
4631: my $src=shift;
4632: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4633: &Apache::lonnet::clutter($src));
4634: }
4635:
4636: sub checkversions {
1.611 raeburn 4637: my ($r,$canedit) = @_;
1.408 raeburn 4638: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4639: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4640: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4641: $r->print(&startContentScreen('tools'));
1.442 www 4642:
1.329 droeschl 4643: my $header='';
4644: my $startsel='';
4645: my $monthsel='';
4646: my $weeksel='';
4647: my $daysel='';
4648: my $allsel='';
4649: my %changes=();
4650: my $starttime=0;
4651: my $haschanged=0;
4652: my %setversions=&Apache::lonnet::dump('resourceversions',
4653: $env{'course.'.$env{'request.course.id'}.'.domain'},
4654: $env{'course.'.$env{'request.course.id'}.'.num'});
4655:
4656: $hashtied=0;
4657: &tiehash();
1.611 raeburn 4658: if ($canedit) {
4659: my %newsetversions=();
4660: if ($env{'form.setmostrecent'}) {
4661: $haschanged=1;
4662: foreach my $key (keys(%hash)) {
4663: if ($key=~/^ids\_(\/res\/.+)$/) {
4664: $newsetversions{$1}='mostrecent';
4665: &devalidateversioncache($1);
4666: }
4667: }
4668: } elsif ($env{'form.setcurrent'}) {
4669: $haschanged=1;
4670: foreach my $key (keys(%hash)) {
4671: if ($key=~/^ids\_(\/res\/.+)$/) {
4672: my $getvers=&Apache::lonnet::getversion($1);
4673: if ($getvers>0) {
4674: $newsetversions{$1}=$getvers;
4675: &devalidateversioncache($1);
4676: }
4677: }
1.329 droeschl 4678: }
1.611 raeburn 4679: } elsif ($env{'form.setversions'}) {
4680: $haschanged=1;
4681: foreach my $key (keys(%env)) {
4682: if ($key=~/^form\.set_version_(.+)$/) {
4683: my $src=$1;
4684: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4685: $newsetversions{$src}=$env{$key};
4686: &devalidateversioncache($src);
4687: }
4688: }
1.329 droeschl 4689: }
1.611 raeburn 4690: }
4691: if ($haschanged) {
4692: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4693: $env{'course.'.$env{'request.course.id'}.'.domain'},
4694: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4695: $r->print(&Apache::loncommon::confirmwrapper(
4696: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4697: } else {
4698: $r->print(&Apache::loncommon::confirmwrapper(
4699: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4700: }
1.611 raeburn 4701: &mark_hash_old();
4702: }
4703: &changewarning($r,'');
1.329 droeschl 4704: }
4705: if ($env{'form.timerange'} eq 'all') {
4706: # show all documents
1.549 raeburn 4707: $header=&mt('All content in '.$crstype);
1.521 bisitz 4708: $allsel=' selected="selected"';
1.329 droeschl 4709: foreach my $key (keys(%hash)) {
4710: if ($key=~/^ids\_(\/res\/.+)$/) {
4711: my $src=$1;
4712: $changes{$src}=1;
4713: }
4714: }
4715: } else {
4716: # show documents which changed
4717: %changes=&Apache::lonnet::dump
4718: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4719: $env{'course.'.$env{'request.course.id'}.'.num'});
4720: my $firstkey=(keys(%changes))[0];
4721: unless ($firstkey=~/^error\:/) {
4722: unless ($env{'form.timerange'}) {
4723: $env{'form.timerange'}=604800;
4724: }
4725: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4726: .&mt('seconds');
4727: if ($env{'form.timerange'}==-1) {
4728: $seltext='since start of course';
1.521 bisitz 4729: $startsel=' selected="selected"';
1.329 droeschl 4730: $env{'form.timerange'}=time;
4731: }
4732: $starttime=time-$env{'form.timerange'};
4733: if ($env{'form.timerange'}==2592000) {
4734: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4735: $monthsel=' selected="selected"';
1.329 droeschl 4736: } elsif ($env{'form.timerange'}==604800) {
4737: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4738: $weeksel=' selected="selected"';
1.329 droeschl 4739: } elsif ($env{'form.timerange'}==86400) {
4740: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4741: $daysel=' selected="selected"';
1.329 droeschl 4742: }
4743: $header=&mt('Content changed').' '.$seltext;
4744: } else {
4745: $header=&mt('No content modifications yet.');
4746: }
4747: }
4748: %setversions=&Apache::lonnet::dump('resourceversions',
4749: $env{'course.'.$env{'request.course.id'}.'.domain'},
4750: $env{'course.'.$env{'request.course.id'}.'.num'});
4751: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4752: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4753: 'lm' => 'Version changes since last Month',
4754: 'lw' => 'Version changes since last Week',
4755: 'sy' => 'Version changes since Yesterday',
4756: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4757: 'cd' => 'Change display',
1.329 droeschl 4758: 'sd' => 'Display',
4759: 'fi' => 'File',
4760: 'md' => 'Modification Date',
4761: 'mr' => 'Most recently published Version',
1.408 raeburn 4762: 've' => 'Version used in '.$crstype,
4763: 'vu' => 'Set Version to be used in '.$crstype,
4764: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4765: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4766: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4767: 'di' => 'Differences',
1.484 raeburn 4768: 'save' => 'Save changes',
4769: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4770: 'act' => 'Actions');
1.611 raeburn 4771: my ($disabled,$readonly);
4772: unless ($canedit) {
4773: $disabled = 'disabled="disabled"';
4774: $readonly = 1;
4775: }
1.329 droeschl 4776: $r->print(<<ENDHEADERS);
1.484 raeburn 4777: <h4 class="LC_info">$header</h4>
1.329 droeschl 4778: <form action="/adm/coursedocs" method="post">
4779: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4780: <div class="LC_left_float">
1.479 golterma 4781: <fieldset>
1.484 raeburn 4782: <legend>$lt{'cd'}</legend>
1.329 droeschl 4783: <select name="timerange">
1.521 bisitz 4784: <option value='all'$allsel>$lt{'al'}</option>
4785: <option value="-1"$startsel>$lt{'st'}</option>
4786: <option value="2592000"$monthsel>$lt{'lm'}</option>
4787: <option value="604800"$weeksel>$lt{'lw'}</option>
4788: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4789: </select>
4790: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4791: </fieldset>
4792: </div>
4793: <div class="LC_left_float">
4794: <fieldset>
4795: <legend>$lt{'act'}</legend>
1.611 raeburn 4796: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4797: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4798: </fieldset>
4799: </div>
4800: <br clear="all" />
4801: <hr />
4802: <h4>$lt{'vers'}</h4>
1.329 droeschl 4803: ENDHEADERS
1.479 golterma 4804: #number of columns for version history
1.571 raeburn 4805: my %changedbytime;
4806: foreach my $key (keys(%changes)) {
4807: #excludes not versionable problems from resource version history:
4808: next if ($key =~ /^\/res\/lib\/templates/);
4809: my $chg;
4810: if ($env{'form.timerange'} eq 'all') {
4811: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4812: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4813: } else {
4814: $chg = $changes{$key};
4815: next if ($chg < $starttime);
4816: }
4817: push(@{$changedbytime{$chg}},$key);
4818: }
4819: if (keys(%changedbytime) == 0) {
4820: &untiehash();
4821: $r->print(&mt('No content changes in imported content in specified time frame').
4822: &endContentScreen());
4823: return;
4824: }
1.479 golterma 4825: $r->print(
1.611 raeburn 4826: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4827: &Apache::loncommon::start_data_table().
4828: &Apache::loncommon::start_data_table_header_row().
4829: '<th>'.&mt('Resources').'</th>'.
4830: "<th>$lt{'mr'}</th>".
4831: "<th>$lt{'ve'}</th>".
4832: "<th>$lt{'vu'}</th>".
4833: '<th>'.&mt('History').'</th>'.
4834: &Apache::loncommon::end_data_table_header_row()
4835: );
1.571 raeburn 4836: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4837: foreach my $key (sort(@{$changedbytime{$chg}})) {
4838: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4839: my $currentversion=&Apache::lonnet::getversion($key);
4840: if ($currentversion<0) {
4841: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4842: }
4843: my $linkurl=&Apache::lonnet::clutter($key);
4844: $r->print(
4845: &Apache::loncommon::start_data_table_row().
4846: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4847: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4848: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4849: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4850: '<td align="right">'
4851: );
4852: # Used in course
4853: my $usedversion=$hash{'version_'.$linkurl};
4854: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4855: if ($usedversion != $currentversion) {
1.479 golterma 4856: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4857: } else {
1.479 golterma 4858: $r->print($usedversion);
4859: }
1.329 droeschl 4860: } else {
1.521 bisitz 4861: $r->print($currentversion);
1.329 droeschl 4862: }
1.571 raeburn 4863: $r->print('</td><td title="'.$lt{'vu'}.'">');
4864: # Set version
4865: $r->print(&Apache::loncommon::select_form(
4866: $setversions{$linkurl},
4867: 'set_version_'.$linkurl,
4868: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4869: '' => '',
4870: 'mostrecent' => &mt('most recent'),
1.611 raeburn 4871: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 4872: my $lastold=1;
4873: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4874: my $url=$root.'.'.$prevvers.'.'.$extension;
4875: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4876: $lastold=$prevvers;
4877: }
4878: }
4879: $r->print('</td>');
4880: # List all available versions
4881: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4882: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4883: my $url=$root.'.'.$prevvers.'.'.$extension;
4884: $r->print(
4885: '<span class="LC_nobreak">'
4886: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4887: .&mt('Version [_1]',$prevvers).'</a>'
4888: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4889: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4890: .')');
4891: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4892: $r->print(
4893: ' <a href="/adm/diff?filename='.
4894: &Apache::lonnet::clutter($root.'.'.$extension).
4895: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4896: '" target="diffs">'.&mt('Diffs').'</a>');
4897: }
4898: $r->print('</span><br />');
1.329 droeschl 4899: }
1.571 raeburn 4900: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4901: }
1.329 droeschl 4902: }
1.521 bisitz 4903: $r->print(
4904: &Apache::loncommon::end_data_table().
1.611 raeburn 4905: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4906: '</form>'
4907: );
1.329 droeschl 4908:
4909: &untiehash();
1.521 bisitz 4910: $r->print(&endContentScreen());
1.571 raeburn 4911: return;
1.329 droeschl 4912: }
4913:
4914: sub mark_hash_old {
4915: my $retie_hash=0;
4916: if ($hashtied) {
4917: $retie_hash=1;
4918: &untiehash();
4919: }
4920: &tiehash('write');
4921: $hash{'old'}=1;
4922: &untiehash();
4923: if ($retie_hash) { &tiehash(); }
4924: }
4925:
4926: sub is_hash_old {
4927: my $untie_hash=0;
4928: if (!$hashtied) {
4929: $untie_hash=1;
4930: &tiehash();
4931: }
4932: my $return=$hash{'old'};
4933: if ($untie_hash) { &untiehash(); }
4934: return $return;
4935: }
4936:
4937: sub changewarning {
4938: my ($r,$postexec,$message,$url)=@_;
4939: if (!&is_hash_old()) { return; }
4940: my $pathvar='folderpath';
4941: my $path=&escape($env{'form.folderpath'});
4942: if (!defined($url)) {
4943: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4944: }
4945: my $course_type = &Apache::loncommon::course_type();
4946: if (!defined($message)) {
4947: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4948: }
4949: $r->print("\n\n".
1.372 bisitz 4950: '<script type="text/javascript">'."\n".
4951: '// <![CDATA['."\n".
4952: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4953: '// ]]>'."\n".
1.369 bisitz 4954: '</script>'."\n".
1.375 tempelho 4955: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4956: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4957: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4958: &mt($message,' <input type="hidden" name="'.
4959: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4960: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4961: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4962: }
4963:
4964:
4965: sub init_breadcrumbs {
1.571 raeburn 4966: my ($form,$text,$help)=@_;
1.329 droeschl 4967: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4968: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4969: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4970: faq=>273,
4971: bug=>'Instructor Interface',
1.571 raeburn 4972: help => $help});
1.329 droeschl 4973: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4974: text=>$text,
4975: faq=>273,
4976: bug=>'Instructor Interface'});
4977: }
4978:
1.441 www 4979: # subroutine to list form elements
4980: sub create_list_elements {
4981: my @formarr = @_;
4982: my $list = '';
1.501 raeburn 4983: foreach my $button (@formarr){
4984: foreach my $picture (keys(%{$button})) {
4985: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4986: }
4987: }
4988: return $list;
4989: }
1.329 droeschl 4990:
1.441 www 4991: # subroutine to create ul from list elements
4992: sub create_form_ul {
4993: my $list = shift;
4994: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4995: return $ul;
4996: }
1.329 droeschl 4997:
1.442 www 4998: #
4999: # Start tabs
5000: #
5001:
5002: sub startContentScreen {
1.484 raeburn 5003: my ($mode) = @_;
5004: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5005: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5006: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5007: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5008: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5009: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5010: } else {
1.549 raeburn 5011: $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 5012: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5013: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5014: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5015: }
5016: $output .= "\n".'</ul>'."\n";
5017: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5018: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5019: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5020: return $output;
1.442 www 5021: }
5022:
5023: #
5024: # End tabs
5025: #
5026:
5027: sub endContentScreen {
1.484 raeburn 5028: return '</div></div></div>';
1.442 www 5029: }
1.329 droeschl 5030:
1.446 www 5031: sub supplemental_base {
1.548 raeburn 5032: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5033: }
5034:
1.329 droeschl 5035: sub handler {
5036: my $r = shift;
5037: &Apache::loncommon::content_type($r,'text/html');
5038: $r->send_http_header;
5039: return OK if $r->header_only;
1.484 raeburn 5040:
5041: # get course data
1.408 raeburn 5042: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5043: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5044: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5045:
1.606 raeburn 5046: # get docroot
5047: my $londocroot = $r->dir_config('lonDocRoot');
5048:
1.484 raeburn 5049: # graphics settings
5050: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5051:
1.443 www 5052: #
1.329 droeschl 5053: # --------------------------------------------- Initialize help topics for this
5054: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5055: 'Adding_External_Resource','Navigate_Content',
5056: 'Adding_Folders','Docs_Overview', 'Load_Map',
5057: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 5058: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.571 raeburn 5059: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
1.572 raeburn 5060: 'Dropbox','Simple_Problem') {
1.329 droeschl 5061: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5062: }
5063: # Composite help files
5064: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5065: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5066: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5067: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5068: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5069: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5070: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5071: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5072: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5073: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5074:
1.611 raeburn 5075: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5076: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5077: unless ($r->uri eq '/adm/supplemental') {
5078: # does this user have privileges to modify content.
1.611 raeburn 5079: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5080: $allowed = 1;
5081: $canedit = 1;
5082: $canview = 1;
5083: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5084: $allowed = 1;
5085: $canview = 1;
5086: }
5087: }
5088: unless ($canedit) {
5089: $disabled = ' disabled="disabled"';
1.472 raeburn 5090: }
1.582 raeburn 5091: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5092: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5093: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 5094: &verifycontent($r);
5095: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5096: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5097: &list_symbs($r);
5098: } elsif ($allowed && $env{'form.docslog'}) {
5099: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5100: my $folder = $env{'form.folder'};
5101: if ($folder eq '') {
5102: $folder='default';
5103: }
1.611 raeburn 5104: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5105: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5106: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5107: &checkversions($r,$canedit);
5108: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5109: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5110: &dumpcourse($r);
1.611 raeburn 5111: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5112: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5113: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5114: } else {
1.611 raeburn 5115: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5116: $noendpage = 1;
5117: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5118: if ($redirect) {
5119: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5120: my $container = 'sequence';
5121: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5122: $is_random_order,$container) =
5123: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5124: my (@folders)=split('&',$env{'form.folderpath'});
5125: $env{'form.foldername'}=&unescape(pop(@folders));
5126: my $folder=pop(@folders);
5127: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5128: $folder.'.'.$container);
5129: my $warning;
5130: if ($fatal) {
5131: if ($container eq 'page') {
5132: $warning = &mt('An error occurred retrieving the contents of the current page.');
5133: } else {
5134: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5135: }
5136: } else {
5137: my $url = $redirect;
5138: my $srcfile = $londocroot.$url;
5139: $url =~ s{^/priv/}{/res/};
5140: my $targetfile = $londocroot.$url;
5141: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5142: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5143: $env{'form.folder'} = $folder;
5144: &snapshotbefore();
5145: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5146: my $ext = 'false';
5147: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5148: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5149: ':'.$ext.':normal:res';
5150: push(@LONCAPA::map::order,$newidx);
5151: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5152: 'string_yesno');
5153: &remember_parms($newidx,'hiddenresource','set','yes');
5154: ($errtext,$fatal) =
5155: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5156: &log_differences($plain);
5157: &mark_hash_old();
5158: $r->internal_redirect($redirect);
5159: return OK;
5160: }
5161: }
5162: }
5163: }
1.445 www 5164: #
5165: # Done catching special calls
1.484 raeburn 5166: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5167: # Get the parameters that may be needed
5168: #
5169: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5170: ['folderpath',
5171: 'forcesupplement','forcestandard',
1.510 raeburn 5172: 'tools','symb','command','supppath']);
1.445 www 5173:
5174: # standard=1: this is a "new-style" course with an uploaded map as top level
5175: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5176:
5177: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5178:
1.484 raeburn 5179: # Decide whether this should display supplemental or main content or utilities
1.445 www 5180: # supplementalflag=1: show supplemental documents
5181: # supplementalflag=0: show standard documents
1.484 raeburn 5182: # toolsflag=1: show utilities
1.445 www 5183:
1.561 raeburn 5184: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5185: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5186: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5187: $supplementalflag=0;
5188: }
5189: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5190: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5191: unless ($allowed) { $supplementalflag=1; }
5192: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5193: my $toolsflag=0;
5194: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5195:
1.329 droeschl 5196: my $script='';
5197: my $showdoc=0;
1.457 raeburn 5198: my $addentries = {};
1.475 raeburn 5199: my $container;
1.329 droeschl 5200: my $containertag;
1.508 raeburn 5201: my $pathitem;
1.598 raeburn 5202: my %ltitools;
1.617 raeburn 5203: my $hiddentop;
1.615 raeburn 5204: my $navmap;
1.617 raeburn 5205: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5206:
1.464 www 5207: # Do we directly jump somewhere?
1.525 raeburn 5208: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5209: if ($env{'form.symb'} ne '') {
1.522 raeburn 5210: $env{'form.folderpath'}=
1.617 raeburn 5211: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5212: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5213: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5214: } elsif ($env{'form.supppath'} ne '') {
5215: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5216: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5217: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5218: }
1.472 raeburn 5219: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5220: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5221: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5222: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5223: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5224: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5225: } elsif ($env{'form.command'} eq 'contents') {
5226: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5227: } elsif ($env{'form.command'} eq 'home') {
5228: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5229: }
5230:
1.525 raeburn 5231:
1.445 www 5232: # Where do we store these for when we come back?
5233: my $stored_folderpath='docs_folderpath';
5234: if ($supplementalflag) {
5235: $stored_folderpath='docs_sup_folderpath';
5236: }
1.464 www 5237:
1.519 raeburn 5238: # No folderpath, and in edit mode, see if we have something stored
5239: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5240: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5241: {'folderpath' => 'scalar'});
1.615 raeburn 5242:
5243: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5244: if ($supplementalflag) {
5245: undef($env{'form.folderpath'}) if ($1 eq 'default');
5246: } else {
5247: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5248: }
5249: } else {
1.523 raeburn 5250: undef($env{'form.folderpath'});
5251: }
1.329 droeschl 5252: }
1.446 www 5253:
5254: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5255: if (!$allowed) {
1.446 www 5256: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5257: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5258: }
5259: }
1.446 www 5260: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5261: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5262: $env{'form.folderpath'} = &supplemental_base()
5263: .'&'.
1.329 droeschl 5264: $env{'form.folderpath'};
5265: }
1.615 raeburn 5266: # If allowed and user's role is not advanced check folderpath is not hidden
5267: if (($allowed) && (!$env{'request.role.adv'}) &&
5268: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5269: my $folderurl;
5270: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5271: my $folder = $pathitems[-2];
5272: if ($folder eq '') {
5273: undef($env{'form.folderpath'});
5274: } else {
5275: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5276: if ((split(/\:/,$pathitems[-1]))[4]) {
5277: $folderurl .= '.page';
5278: } else {
5279: $folderurl .= '.sequence';
5280: }
1.617 raeburn 5281: unless (ref($navmap)) {
5282: $navmap = Apache::lonnavmaps::navmap->new();
5283: }
1.615 raeburn 5284: if (ref($navmap)) {
5285: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5286: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5287: unless (@resources) {
5288: undef($env{'form.folderpath'});
5289: }
1.615 raeburn 5290: }
5291: }
5292: }
5293: }
5294:
5295:
1.446 www 5296: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5297: unless ($env{'form.folderpath'}) {
1.446 www 5298: if ($supplementalflag) {
5299: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5300: } elsif ($allowed) {
5301: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5302: }
1.472 raeburn 5303: }
1.446 www 5304:
1.445 www 5305: # Store this
1.484 raeburn 5306: unless ($toolsflag) {
1.615 raeburn 5307: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5308: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5309: {'folderpath' => 'scalar'});
1.510 raeburn 5310: }
1.519 raeburn 5311: my $folderpath;
1.484 raeburn 5312: if ($env{'form.folderpath'}) {
1.519 raeburn 5313: $folderpath = $env{'form.folderpath'};
5314: my (@folders)=split('&',$env{'form.folderpath'});
5315: $env{'form.foldername'}=&unescape(pop(@folders));
5316: if ($env{'form.foldername'} =~ /\:1$/) {
5317: $container = 'page';
5318: } else {
5319: $container = 'sequence';
5320: }
5321: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5322: } else {
1.519 raeburn 5323: if ($env{'form.folder'} eq '' ||
5324: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5325: if ($env{'form.folder'} eq 'supplemental') {
5326: $folderpath=&supplemental_base();
5327: } elsif (!$hiddentop) {
5328: $folderpath='default&'.
5329: &escape(&mt('Main Content').':::::');
5330: }
1.484 raeburn 5331: }
5332: }
1.519 raeburn 5333: $containertag = '<input type="hidden" name="folderpath" value="" />';
5334: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5335: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5336: $showdoc='/'.$1;
5337: }
5338: if ($showdoc) { # got called in sequence from course
5339: $allowed=0;
5340: } else {
1.611 raeburn 5341: if ($canedit) {
1.484 raeburn 5342: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5343: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5344: }
5345: }
1.329 droeschl 5346: }
5347:
1.344 bisitz 5348: # get personal data
1.329 droeschl 5349: my $uname=$env{'user.name'};
5350: my $udom=$env{'user.domain'};
5351: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5352:
5353: if ($allowed) {
1.484 raeburn 5354: if ($toolsflag) {
5355: $script .= &inject_data_js();
5356: my ($home,$other,%outhash)=&authorhosts();
5357: if (!$home && $other) {
5358: my @hosts;
5359: foreach my $aurole (keys(%outhash)) {
5360: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5361: push(@hosts,$outhash{$aurole});
5362: }
5363: }
5364: $script .= &dump_switchserver_js(@hosts);
5365: }
1.458 raeburn 5366: } else {
1.570 raeburn 5367: my $tid = 1;
1.484 raeburn 5368: my @tabids;
5369: if ($supplementalflag) {
5370: @tabids = ('002','ee2','ff2');
1.570 raeburn 5371: $tid = 2;
1.484 raeburn 5372: } else {
5373: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5374: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5375: unshift(@tabids,'001');
5376: push(@tabids,('dd1','ee1'));
5377: }
1.458 raeburn 5378: }
1.484 raeburn 5379: my $tabidstr = join("','",@tabids);
1.598 raeburn 5380: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5381: my $posslti = keys(%ltitools);
1.622 ! raeburn 5382: my $hostname = $r->hostname();
1.606 raeburn 5383: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 ! raeburn 5384: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5385: &history_tab_js().
5386: &inject_data_js().
1.570 raeburn 5387: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5388: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5389: $addentries = {
1.485 raeburn 5390: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5391: };
1.458 raeburn 5392: }
1.538 raeburn 5393: $script .= &paste_popup_js();
1.501 raeburn 5394: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5395: &mt('Switch server?');
5396:
5397:
1.329 droeschl 5398: }
5399: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5400: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5401: .'// <![CDATA['."\n"
5402: .$script."\n"
5403: .'// ]]>'."\n"
1.595 musolffc 5404: .'</script>'."\n"
5405: .'<script type="text/javascript"
5406: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5407:
5408: # Breadcrumbs
5409: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5410:
5411: if ($showdoc) {
5412: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5413: {'force_register' => $showdoc,}));
1.571 raeburn 5414: } elsif ($toolsflag) {
1.611 raeburn 5415: my ($breadtext,$breadtitle);
1.617 raeburn 5416: $breadtext = "$crstype Editor";
1.611 raeburn 5417: if ($canedit) {
5418: $breadtitle = 'Editing '.$crstype.' Contents';
5419: } else {
5420: $breadtext .= ' (View-only mode)';
5421: $breadtitle = 'Viewing '.$crstype.' Contents';
5422: }
1.571 raeburn 5423: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5424: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5425: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5426: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5427: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5428: $breadtitle)
1.571 raeburn 5429: );
1.510 raeburn 5430: } elsif ($r->uri eq '/adm/supplemental') {
5431: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5432: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5433: {'bread_crumbs' => $brcrum,}));
5434: } else {
1.611 raeburn 5435: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5436: $breadtext = "$crstype Editor";
1.611 raeburn 5437: if ($canedit) {
5438: $breadtitle = 'Editing '.$crstype.' Contents';
5439: $helpitem = 'Docs_Adding_Course_Doc';
5440: } else {
5441: $breadtext .= ' (View-only mode)';
5442: $breadtitle = 'Viewing '.$crstype.' Contents';
5443: $helpitem = 'Docs_Viewing_Course_Doc';
5444: }
1.392 raeburn 5445: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5446: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5447: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5448: {'add_entries' => $addentries}
5449: )
1.392 raeburn 5450: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5451: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5452: $breadtitle,
5453: $helpitem)
1.392 raeburn 5454: );
5455: }
1.364 bisitz 5456:
1.329 droeschl 5457: my %allfiles = ();
5458: my %codebase = ();
1.440 raeburn 5459: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5460: if ($canedit) {
1.329 droeschl 5461: if (($env{'form.uploaddoc.filename'}) &&
5462: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5463: my $context = $1;
5464: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5465: undef($hadchanges);
1.440 raeburn 5466: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5467: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5468: if ($hadchanges) {
5469: &mark_hash_old();
5470: }
1.440 raeburn 5471: $r->print($upload_output);
5472: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5473: # Process file upload - phase two - upload embedded objects
5474: $uploadphase = 'check_embedded';
5475: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5476: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5477: $env{'form.newidx'});
5478: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5479: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5480: my ($destination,$dir_root) = &embedded_destination();
5481: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5482: my $actionurl = '/adm/coursedocs';
5483: my ($result,$flag) =
5484: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5485: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5486: $actionurl);
5487: $r->print($result.&return_to_editor());
5488: } elsif ($env{'form.phase'} eq 'check_embedded') {
5489: # Process file upload - phase three - modify references in HTML file
5490: $uploadphase = 'modified_orightml';
5491: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5492: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5493: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5494: my $result =
5495: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5496: $docuname,$docudom,undef,
5497: $dir_root);
5498: $r->print($result.&return_to_editor());
1.476 raeburn 5499: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5500: $uploadphase = 'decompress_phase_one';
5501: $r->print(&decompression_phase_one().
5502: &return_to_editor());
5503: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5504: $uploadphase = 'decompress_phase_two';
5505: $r->print(&decompression_phase_two().
5506: &return_to_editor());
1.329 droeschl 5507: }
5508: }
5509:
1.484 raeburn 5510: if ($allowed && $toolsflag) {
5511: $r->print(&startContentScreen('tools'));
1.611 raeburn 5512: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5513: $r->print(&endContentScreen());
5514: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5515: # -----------------------------------------------------------------------------
5516: my %lt=&Apache::lonlocal::texthash(
5517: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5518: 'upfi' => 'Upload File',
1.553 raeburn 5519: 'upld' => 'Upload Content',
1.329 droeschl 5520: 'srch' => 'Search',
5521: 'impo' => 'Import',
1.487 raeburn 5522: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5523: 'impm' => 'Import from Assembled Map',
1.606 raeburn 5524: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5525: 'extr' => 'External Resource',
5526: 'extt' => 'External Tool',
1.329 droeschl 5527: 'selm' => 'Select Map',
5528: 'load' => 'Load Map',
5529: 'newf' => 'New Folder',
5530: 'newp' => 'New Composite Page',
5531: 'syll' => 'Syllabus',
1.425 raeburn 5532: 'navc' => 'Table of Contents',
1.343 biermanm 5533: 'sipa' => 'Simple Course Page',
1.329 droeschl 5534: 'sipr' => 'Simple Problem',
1.534 raeburn 5535: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5536: 'stpr' => 'Standard Problem',
5537: 'news' => 'New sub-directory',
5538: 'crpr' => 'Create Problem',
1.329 droeschl 5539: 'drbx' => 'Drop Box',
1.451 www 5540: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5541: 'bull' => 'Discussion Board',
1.347 weissno 5542: 'mypi' => 'My Personal Information Page',
1.353 weissno 5543: 'grpo' => 'Group Portfolio',
1.329 droeschl 5544: 'rost' => 'Course Roster',
1.528 raeburn 5545: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5546: 'imsf' => 'IMS Upload',
5547: 'imsl' => 'Upload IMS package',
1.501 raeburn 5548: 'cms' => 'Origin of IMS package',
5549: 'se' => 'Select',
1.329 droeschl 5550: 'file' => 'File',
5551: 'title' => 'Title',
1.606 raeburn 5552: 'addp' => 'Add Placeholder to course?',
5553: 'uste' => 'Use Template?',
5554: 'fnam' => 'File Name:',
5555: 'loca' => 'Location:',
5556: 'dire' => 'Directory:',
5557: 'cate' => 'Category:',
5558: 'tmpl' => 'Template:',
1.329 droeschl 5559: 'comment' => 'Comment',
1.403 raeburn 5560: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5561: 'bb5' => 'Blackboard 5',
5562: 'bb6' => 'Blackboard 6',
5563: 'angel5' => 'ANGEL 5.5',
5564: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5565: 'yes' => 'Yes',
5566: 'no' => 'No',
1.618 raeburn 5567: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5568: );
1.329 droeschl 5569: # -----------------------------------------------------------------------------
1.595 musolffc 5570:
5571: # Calculate free quota space for a user or course. A javascript function checks
5572: # file size to determine if upload should be allowed.
5573: my $quotatype = 'unofficial';
5574: if ($crstype eq 'Community') {
1.601 raeburn 5575: $quotatype = 'community';
5576: } elsif ($crstype eq 'Placement') {
5577: $quotatype = 'placement';
1.595 musolffc 5578: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5579: $quotatype = 'official';
5580: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5581: $quotatype = 'textbook';
5582: }
5583: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5584: 'course',$quotatype); # expressed in MB
5585: my $current_disk_usage = 0;
5586: foreach my $subdir ('docs','supplemental') {
5587: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5588: "userfiles/$subdir",1); # expressed in kB
5589: }
5590: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5591: my $usage = $current_disk_usage/1024; # in MB
5592: my $quota = $disk_quota;
5593: my $percent;
5594: if ($disk_quota == 0) {
5595: $percent = 100.0;
5596: } else {
1.619 raeburn 5597: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5598: }
5599: $usage = sprintf("%.2f",$usage);
5600: $quota = sprintf("%.2f",$quota);
5601: $percent = sprintf("%.0f",$percent);
5602: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5603: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5604:
1.329 droeschl 5605: my $fileupload=(<<FIUP);
1.605 raeburn 5606: $quotainfo
1.329 droeschl 5607: $lt{'file'}:<br />
1.611 raeburn 5608: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5609: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5610: FIUP
5611:
5612: my $checkbox=(<<CHBO);
5613: <!-- <label>$lt{'parse'}?
5614: <input type="checkbox" name="parserflag" />
5615: </label> -->
5616: <label>
1.611 raeburn 5617: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5618: </label>
5619: CHBO
1.501 raeburn 5620: my $imsfolder = $env{'form.folder'};
5621: if ($imsfolder eq '') {
5622: $imsfolder = 'default';
5623: }
5624: my $imspform=(<<IMSFORM);
5625: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5626: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5627: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5628: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5629: <legend>$lt{'imsf'}</legend>
5630: $fileupload
5631: <br />
5632: <p>
5633: $lt{'cms'}:
1.611 raeburn 5634: <select name="source" $disabled>
1.501 raeburn 5635: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5636: <option value="bb5">$lt{'bb5'}</option>
5637: <option value="bb6">$lt{'bb6'}</option>
5638: <option value="angel5">$lt{'angel5'}</option>
5639: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5640: </select>
5641: <input type="hidden" name="folder" value="$imsfolder" />
5642: </p>
5643: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5644: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5645: </fieldset>
5646: </form>
5647: IMSFORM
1.329 droeschl 5648:
5649: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5650: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5651: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5652: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5653: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5654: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5655: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5656: $fileupload
1.329 droeschl 5657: <br />
5658: $lt{'title'}:<br />
1.611 raeburn 5659: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5660: $pathitem
1.329 droeschl 5661: <input type="hidden" name="cmd" value="upload_default" />
5662: <br />
1.458 raeburn 5663: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5664: $checkbox
5665: </span>
1.501 raeburn 5666: <br clear="all" />
1.611 raeburn 5667: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5668: </fieldset>
5669: </form>
1.383 tempelho 5670: FUFORM
1.329 droeschl 5671:
1.611 raeburn 5672: my $mapimportjs;
5673: if ($canedit) {
5674: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5675: } else {
5676: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5677: }
1.502 raeburn 5678: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5679: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5680: $lt{'impm'}</a>$help{'Load_Map'}
5681: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5682: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5683: <legend>$lt{'impm'}</legend>
1.371 tempelho 5684: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5685: $lt{'copm'}<br />
5686: <span class="LC_nobreak">
5687: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5688: onfocus="this.blur();$mapimportjs" $disabled />
5689: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5690: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5691: </fieldset>
5692: </form>
5693:
1.383 tempelho 5694: SEDFFORM
1.606 raeburn 5695: my $importcrsresform;
1.608 raeburn 5696: my ($numdirs,$pickfile) =
5697: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5698: "resize_scrollbox('contentscroll','1','0');",
5699: undef,'res');
1.606 raeburn 5700: if ($pickfile) {
5701: $importcrsresform=(<<CRSFORM);
5702: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5703: $lt{'imcr'}</a>$help{'Course_Resources'}
5704: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5705: <fieldset id="importcrsresform" style="display: none;">
5706: <legend>$lt{'imcr'}</legend>
5707: <input type="hidden" name="active" value="bb" />
5708: $pickfile
5709: <p>
1.611 raeburn 5710: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5711: </p>
5712: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5713: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5714: </fieldset>
5715: </form>
5716: CRSFORM
5717: }
5718:
1.611 raeburn 5719: my $fromstoredjs;
5720: if ($canedit) {
5721: $fromstoredjs = 'open_StoredLinks_Import()';
5722: } else {
5723: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5724: }
5725:
1.502 raeburn 5726: my @importpubforma = (
1.508 raeburn 5727: { '<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 5728: { '<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 5729: { '<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 5730: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5731: );
5732: if ($pickfile) {
5733: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5734: }
1.502 raeburn 5735: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5736: my $extresourcesform =
5737: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5738: $help{'Adding_External_Resource'},
5739: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5740: my $exttoolform =
5741: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5742: $help{'Adding_External_Tool'},undef,
5743: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5744: \%ltitools,$disabled);
1.329 droeschl 5745: if ($allowed) {
1.492 raeburn 5746: my $folder = $env{'form.folder'};
5747: if ($folder eq '') {
5748: $folder='default';
5749: }
1.615 raeburn 5750: if ($canedit) {
5751: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5752: if ($output) {
5753: $r->print($output);
5754: }
1.538 raeburn 5755: }
1.337 ehlerst 5756: $r->print(<<HIDDENFORM);
5757: <form name="renameform" method="post" action="/adm/coursedocs">
5758: <input type="hidden" name="title" />
5759: <input type="hidden" name="cmd" />
5760: <input type="hidden" name="markcopy" />
5761: <input type="hidden" name="copyfolder" />
5762: $containertag
5763: </form>
1.484 raeburn 5764:
1.337 ehlerst 5765: HIDDENFORM
1.508 raeburn 5766: $r->print(&makesimpleeditform($pathitem)."\n".
5767: &makedocslogform($pathitem."\n".
1.484 raeburn 5768: '<input type="hidden" name="folder" value="'.
5769: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5770: }
1.442 www 5771:
5772: # Generate the tabs
1.510 raeburn 5773: my ($mode,$needs_end);
1.472 raeburn 5774: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5775: my @folders = split('&',$env{'form.folderpath'});
5776: unless (@folders > 2) {
5777: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5778: $needs_end = 1;
5779: }
1.472 raeburn 5780: } else {
1.484 raeburn 5781: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5782: $needs_end = 1;
1.472 raeburn 5783: }
1.443 www 5784:
1.442 www 5785: #
1.622 ! raeburn 5786: my $hostname = $r->hostname();
1.442 www 5787: my $savefolderpath;
5788:
1.395 raeburn 5789: if ($allowed) {
1.329 droeschl 5790: my $folder=$env{'form.folder'};
1.615 raeburn 5791: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5792: $folder='default';
1.356 tempelho 5793: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5794: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5795: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5796: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5797: }
5798: my $postexec='';
5799: if ($folder eq 'default') {
1.372 bisitz 5800: $r->print('<script type="text/javascript">'."\n"
5801: .'// <![CDATA['."\n"
5802: .'this.window.name="loncapaclient";'."\n"
5803: .'// ]]>'."\n"
5804: .'</script>'."\n"
1.369 bisitz 5805: );
1.329 droeschl 5806: } else {
5807: #$postexec='self.close();';
5808: }
1.504 raeburn 5809: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5810: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5811: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5812:
5813: my $newnavform=(<<NNFORM);
5814: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5815: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5816: $pathitem
1.329 droeschl 5817: <input type="hidden" name="importdetail"
5818: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 5819: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5820: $help{'Navigate_Content'}
5821: </form>
5822: NNFORM
5823: my $newsmppageform=(<<NSPFORM);
5824: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5825: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5826: $pathitem
1.329 droeschl 5827: <input type="hidden" name="importdetail" value="" />
1.423 onken 5828: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5829: $help{'Simple Page'}
1.329 droeschl 5830: </form>
5831: NSPFORM
5832:
5833: my $newsmpproblemform=(<<NSPROBFORM);
5834: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5835: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5836: $pathitem
1.329 droeschl 5837: <input type="hidden" name="importdetail" value="" />
1.423 onken 5838: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5839: $help{'Simple_Problem'}
1.329 droeschl 5840: </form>
5841:
5842: NSPROBFORM
5843:
5844: my $newdropboxform=(<<NDBFORM);
5845: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5846: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5847: $pathitem
1.329 droeschl 5848: <input type="hidden" name="importdetail" value="" />
1.423 onken 5849: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5850: $help{'Dropbox'}
1.344 bisitz 5851: </form>
1.329 droeschl 5852: NDBFORM
5853:
5854: my $newexuploadform=(<<NEXUFORM);
5855: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5856: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5857: $pathitem
1.329 droeschl 5858: <input type="hidden" name="importdetail" value="" />
1.423 onken 5859: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5860: $help{'Score_Upload_Form'}
5861: </form>
5862: NEXUFORM
5863:
5864: my $newbulform=(<<NBFORM);
5865: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5866: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5867: $pathitem
1.329 droeschl 5868: <input type="hidden" name="importdetail" value="" />
1.423 onken 5869: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5870: $help{'Bulletin Board'}
5871: </form>
5872: NBFORM
5873:
5874: my $newaboutmeform=(<<NAMFORM);
5875: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5876: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5877: $pathitem
1.329 droeschl 5878: <input type="hidden" name="importdetail"
5879: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 5880: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5881: $help{'My Personal Information Page'}
1.329 droeschl 5882: </form>
5883: NAMFORM
5884:
5885: my $newaboutsomeoneform=(<<NASOFORM);
5886: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5887: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5888: $pathitem
1.329 droeschl 5889: <input type="hidden" name="importdetail" value="" />
1.423 onken 5890: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5891: </form>
5892: NASOFORM
5893:
5894: my $newrosterform=(<<NROSTFORM);
5895: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5896: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5897: $pathitem
1.329 droeschl 5898: <input type="hidden" name="importdetail"
5899: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 5900: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 5901: $help{'Course_Roster'}
1.329 droeschl 5902: </form>
5903: NROSTFORM
5904:
1.534 raeburn 5905: my $newwebpage;
5906: if ($folder =~ /^default_?(\d*)$/) {
5907: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5908: if ($1) {
5909: $newwebpage .= $1;
5910: } else {
5911: $newwebpage .= 'default';
5912: }
5913: $newwebpage .= '/new.html';
5914: }
5915: my $newwebpageform =(<<NWEBFORM);
5916: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5917: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5918: $pathitem
5919: <input type="hidden" name="importdetail" value="$newwebpage" />
5920: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5921: $help{'Web_Page'}
1.534 raeburn 5922: </form>
5923: NWEBFORM
1.604 raeburn 5924:
1.606 raeburn 5925: my @ids=&Apache::lonnet::current_machine_ids();
5926: my %select_menus;
5927: my $numauthor = 0;
5928: my $numcrsdirs = 0;
5929: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5930: if ($env{'user.author'}) {
5931: $numauthor ++;
5932: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5933: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5934: my $is_home = 1;
5935: my %subdirs;
1.608 raeburn 5936: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5937: $select_menus{'author'}->{'default'} = '/';
5938: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5939: my @ordered = ('/');
5940: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5941: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5942: push(@ordered,$relpath);
5943: }
5944: $select_menus{'author'}->{'order'} = \@ordered;
5945: } else {
5946: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5947: $select_menus{'author'}->{'default'} = 'switch';
5948: $select_menus{'author'}->{'order'} = ['switch'];
5949: }
5950: }
5951: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5952: ['active'],['ca','aa']);
5953: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5954: my %by_roletype;
5955: if (keys(%roleshash)) {
5956: foreach my $entry (keys(%roleshash)) {
5957: my ($auname,$audom,$roletype) = split(/:/,$entry);
5958: my $key = $entry;
5959: $key =~ s/:/___/g;
5960: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5961: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5962: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5963: if (grep(/^\Q$rolehome\E$/,@ids)) {
5964: my $is_home = 1;
5965: my (%subdirs,@ordered);
5966: my $toppath="/priv/$audom/$auname";
1.608 raeburn 5967: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5968: $select_menus{$key}->{'default'} = '/';
5969: $select_menus{$key}->{'select2'}->{'/'} = '/';
5970: my @ordered = ('/');
5971: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5972: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
5973: push(@ordered,$relpath);
5974: }
5975: $select_menus{$key}->{'order'} = \@ordered;
5976: } else {
5977: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
5978: $select_menus{$key}->{'default'} = 'switch';
5979: $select_menus{$key}->{'order'} = ['switch'];
5980: }
5981: $numauthor ++;
5982: }
5983: }
5984: my ($pickdir,$showtitle);;
5985: if ($numauthor) {
5986: my @order;
5987: my $defrole;
5988: if ($env{'user.author'}) {
5989: push(@order,'author');
5990: $defrole = 'author';
5991: }
5992: if (keys(%by_roletype)) {
5993: foreach my $possrole ('ca','aa') {
5994: if (ref($by_roletype{$possrole}) eq 'HASH') {
5995: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
5996: unless ($defrole) {
5997: $defrole = $author;
5998: }
5999: push(@order,$author.'___'.$possrole);
6000: }
6001: }
6002: }
6003: }
6004: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6005: if (grep(/^\Q$crshome\E$/,@ids)) {
6006: my $is_home = 1;
6007: my %subdirs;
6008: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6009: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6010: $numcrsdirs = keys(%subdirs);
6011: $select_menus{'course'}->{'default'} = '/';
6012: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6013: my @ordered = ('/');
6014: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6015: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6016: push(@ordered,$relpath);
6017: }
6018: $select_menus{'course'}->{'order'} = \@ordered;
6019: } else {
6020: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6021: $select_menus{'course'}->{'default'} = 'switch';
6022: $select_menus{'course'}->{'order'} = ['switch'];
6023: }
6024: push(@order,'course');
6025: $pickdir = $lt{'loca'}.
6026: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6027: $defrole,'authorrole','authorpath',
6028: \%select_menus,\@order,'toggleCrsResTitle();',
6029: '','priv').'<br />';
6030: $showtitle = 'none';
6031: } else {
6032: my $is_home;
6033: $showtitle = 'inline';
6034: if (grep(/^\Q$crshome\E$/,@ids)) {
6035: $is_home = 1;
6036: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6037: my $toppath="/priv/$coursedom/$coursenum'}";
6038: my %subdirs;
1.608 raeburn 6039: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6040: $numcrsdirs = keys(%subdirs);
6041: if ($numcrsdirs) {
6042: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6043: '<option value="/">/</option>'."\n";
6044: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6045: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6046: }
6047: $pickdir .= '</select>';
6048: } else {
6049: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6050: }
6051: }
6052: }
6053:
6054: my %seltemplate_menus;
6055: my @files = &Apache::lonhomework::get_template_list('problem');
6056: my @noexamplelink = ('blank.problem','blank.library','script.library');
6057: my $currentcategory = '';
6058: my @ordered = ('');
6059: my %templatehelp;
6060: my $defcategory = '';
6061: my @catorder = ($defcategory);
6062: $seltemplate_menus{$defcategory}->{'order'} = [''];
6063: $seltemplate_menus{$defcategory}->{'text'} = '';
6064: foreach my $file (@files) {
6065: if (ref($file) eq 'ARRAY') {
6066: my ($path,$title,$category,$help) = @{$file};
6067: next if ($title !~ /\S/);
6068: if (&js_escape($category) ne $currentcategory) {
6069: $currentcategory = &js_escape($category);
6070: push(@catorder,&js_escape($currentcategory));
6071: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6072: $seltemplate_menus{$currentcategory}->{'default'} = '';
6073: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6074: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6075: }
6076: if ($path) {
6077: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6078: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6079: if ($help) {
6080: $templatehelp{$path} = $help;
6081: }
6082: }
6083: }
6084: }
6085:
6086: my $templates = $lt{'cate'}.' '.
6087: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6088: $defcategory,'tempcategory','template',
6089: \%seltemplate_menus,\@catorder,
6090: "resize_scrollbox('contentscroll','1','0');",
6091: "toggleExampleText();",'template').'<br />';
6092: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6093: '<span id="newresexample">'.&mt('Example').'<span></a>';
6094: my $crsresform=(<<RESFORM);
6095: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6096: $lt{'stpr'}</a>$help{'Course_Resource'}
6097: <form action="/adm/coursedocs" method="post" name="courseresform">
6098: <fieldset id="crsresform" style="display:none;">
6099: <legend>$lt{'stpr'}</legend>
6100: <input type="hidden" name="active" value="ee" />
6101: <p>
6102: $pickdir
6103: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6104: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6105:
1.611 raeburn 6106: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6107: </span><span id="newsubdir"></span>
6108: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6109: </p>
6110: $lt{'fnam'}
1.611 raeburn 6111: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6112: <p>
6113: <div id="newresource" style="display:$showtitle">
6114: $lt{'addp'}
1.611 raeburn 6115: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6116: $lt{'no'}</label>
1.611 raeburn 6117: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6118: $lt{'yes'}</label>
6119: <span id="newrestitle"></span>
1.611 raeburn 6120: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6121: </div>
6122: </p>
6123: <p>
6124: $lt{'uste'}
1.611 raeburn 6125: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6126: $lt{'no'}</label>
1.611 raeburn 6127: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6128: $lt{'yes'}</label>
6129: <div id="newrestemplate" style="display:none">
6130: $templates
6131: $templatepreview
6132: </div>
6133: </p>
6134: <span class="LC_nobreak">
6135: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6136: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6137: </span>
6138: </fieldset>
6139: </form>
6140:
6141: RESFORM
1.534 raeburn 6142:
1.342 ehlerst 6143: my $specialdocumentsform;
1.383 tempelho 6144: my @specialdocumentsforma;
1.451 www 6145: my $gradingform;
6146: my @gradingforma;
6147: my $communityform;
6148: my @communityforma;
1.351 ehlerst 6149: my $newfolderform;
1.390 tempelho 6150: my $newfolderb;
1.342 ehlerst 6151:
1.451 www 6152: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6153:
1.329 droeschl 6154: my $newpageform=(<<NPFORM);
6155: <form action="/adm/coursedocs" method="post" name="newpage">
6156: <input type="hidden" name="folderpath" value="$path" />
6157: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6158: <input type="hidden" name="active" value="ee" />
1.423 onken 6159: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6160: $help{'Adding_Pages'}
1.329 droeschl 6161: </form>
6162: NPFORM
1.390 tempelho 6163:
6164:
1.351 ehlerst 6165: $newfolderform=(<<NFFORM);
1.329 droeschl 6166: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6167: $pathitem
1.329 droeschl 6168: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6169: <input type="hidden" name="active" value="" />
1.422 onken 6170: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6171: </form>
6172: NFFORM
6173:
6174: my $newsylform=(<<NSYLFORM);
6175: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6176: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6177: $pathitem
1.329 droeschl 6178: <input type="hidden" name="importdetail"
6179: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6180: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6181: $help{'Syllabus'}
1.383 tempelho 6182:
1.329 droeschl 6183: </form>
6184: NSYLFORM
1.364 bisitz 6185:
1.329 droeschl 6186: my $newgroupfileform=(<<NGFFORM);
6187: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6188: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6189: $pathitem
1.329 droeschl 6190: <input type="hidden" name="importdetail"
6191: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6192: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6193: $help{'Group Portfolio'}
1.329 droeschl 6194: </form>
6195: NGFFORM
1.383 tempelho 6196: @specialdocumentsforma=(
1.421 onken 6197: {'<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 6198: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6199: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6200: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6201: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6202: );
6203: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6204:
1.434 raeburn 6205:
6206: my @importdoc = (
1.519 raeburn 6207: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6208: );
1.598 raeburn 6209: if (keys(%ltitools)) {
6210: push(@importdoc,
6211: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6212: );
6213: }
1.519 raeburn 6214: unless ($container eq 'page') {
6215: push(@importdoc,
6216: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6217: );
6218: }
6219: push(@importdoc,
1.558 raeburn 6220: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6221: );
1.501 raeburn 6222: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6223:
1.451 www 6224: @gradingforma=(
6225: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6226: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6227: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6228: {'<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 6229: );
6230: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6231:
6232: @communityforma=(
6233: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6234: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6235: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6236: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6237: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6238: );
6239: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6240:
1.330 tempelho 6241: my %orderhash = (
1.553 raeburn 6242: 'aa' => ['Upload',$fileuploadform],
6243: 'bb' => ['Import',$importpubform],
6244: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6245: );
1.519 raeburn 6246: unless ($container eq 'page') {
1.434 raeburn 6247: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6248: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6249: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6250: }
6251:
1.341 ehlerst 6252: $hadchanges=0;
1.484 raeburn 6253: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6254: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6255: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 ! raeburn 6256: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6257: undef($navmap);
1.443 www 6258: if ($error) {
6259: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6260: }
6261: if ($hadchanges) {
6262: &mark_hash_old();
6263: }
1.341 ehlerst 6264:
1.443 www 6265: &changewarning($r,'');
6266: }
1.458 raeburn 6267: }
1.442 www 6268:
1.443 www 6269: # Supplemental documents start here
6270:
1.329 droeschl 6271: my $folder=$env{'form.folder'};
1.443 www 6272: unless ($supplementalflag) {
1.329 droeschl 6273: $folder='supplemental';
6274: }
6275: if ($folder =~ /^supplemental$/ &&
6276: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6277: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6278: } elsif ($allowed) {
1.356 tempelho 6279: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6280: }
1.508 raeburn 6281: $pathitem = '<input type="hidden" name="folderpath" value="'.
6282: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6283: if ($allowed) {
6284: my $folderseq=
1.504 raeburn 6285: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6286:
6287: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6288: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6289: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6290: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6291: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6292: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6293: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6294: $fileupload
6295: <br />
6296: <br />
6297: <span class="LC_nobreak">
6298: $checkbox
6299: </span>
6300: <br /><br />
6301: $lt{'comment'}:<br />
1.383 tempelho 6302: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6303: <br />
1.508 raeburn 6304: $pathitem
1.329 droeschl 6305: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6306: <input type='submit' value="$lt{'upld'}" />
6307: </form>
1.329 droeschl 6308: SUPDOCFORM
6309:
6310: my $supnewfolderform=(<<SNFFORM);
6311: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6312: <input type="hidden" name="active" value="" />
1.508 raeburn 6313: $pathitem
1.329 droeschl 6314: <input type="hidden" name="importdetail" value="" />
1.423 onken 6315: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6316: $help{'Adding_Folders'}
1.329 droeschl 6317: </form>
6318: SNFFORM
1.383 tempelho 6319:
1.510 raeburn 6320: my $supextform =
6321: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6322: $help{'Adding_External_Resource'},
6323: undef,undef,undef,undef,undef,undef,
6324: $disabled);
1.329 droeschl 6325:
1.598 raeburn 6326: my $supexttoolform =
6327: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6328: $help{'Adding_External_Tool'},
6329: undef,undef,'tool',$coursedom,
1.611 raeburn 6330: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6331:
1.329 droeschl 6332: my $supnewsylform=(<<SNSFORM);
6333: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6334: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6335: $pathitem
1.329 droeschl 6336: <input type="hidden" name="importdetail"
6337: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6338: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6339: $help{'Syllabus'}
6340: </form>
6341: SNSFORM
6342:
6343: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6344: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6345: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6346: $pathitem
1.329 droeschl 6347: <input type="hidden" name="importdetail"
6348: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6349: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6350: $help{'My Personal Information Page'}
1.329 droeschl 6351: </form>
6352: SNAMFORM
6353:
1.534 raeburn 6354: my $supwebpage;
6355: if ($folder =~ /^supplemental_?(\d*)$/) {
6356: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6357: if ($1) {
6358: $supwebpage .= $1;
6359: } else {
6360: $supwebpage .= 'default';
6361: }
6362: $supwebpage .= '/new.html';
6363: }
6364: my $supwebpageform =(<<SWEBFORM);
6365: <form action="/adm/coursedocs" method="post" name="supwebpage">
6366: <input type="hidden" name="active" value="cc" />
6367: $pathitem
6368: <input type="hidden" name="importdetail" value="$supwebpage" />
6369: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6370: $help{'Web_Page'}
1.534 raeburn 6371: </form>
6372: SWEBFORM
6373:
1.333 muellerd 6374:
1.383 tempelho 6375: my @specialdocs = (
1.618 raeburn 6376: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6377: =>$supnewsylform},
1.611 raeburn 6378: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6379: =>$supnewaboutmeform},
1.534 raeburn 6380: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6381:
1.383 tempelho 6382: );
1.417 droeschl 6383: my @supimportdoc = (
1.515 raeburn 6384: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6385: =>$supextform});
6386: if (keys(%ltitools)) {
6387: push(@supimportdoc,
6388: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6389: =>$supexttoolform});
6390: }
6391: push(@supimportdoc,
6392: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6393: =>$supupdocform},
1.598 raeburn 6394: );
1.501 raeburn 6395:
6396: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6397: my %suporderhash = (
1.390 tempelho 6398: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6399: 'ee' => ['Upload',$supupdocform],
6400: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6401: );
1.443 www 6402: if ($supplementalflag) {
1.458 raeburn 6403: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6404: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 ! raeburn 6405: \%ltitools,$canedit,$hostname);
1.443 www 6406: if ($error) {
6407: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6408: } else {
6409: if ($suppchanges) {
6410: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6411: my @ids=&Apache::lonnet::current_machine_ids();
6412: foreach my $server (keys(%servers)) {
6413: next if (grep(/^\Q$server\E$/,@ids));
6414: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6415: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6416: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6417: }
6418: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6419: undef($suppchanges);
6420: }
6421: }
1.393 raeburn 6422: }
1.443 www 6423: } elsif ($supplementalflag) {
1.458 raeburn 6424: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 ! raeburn 6425: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6426: if ($error) {
6427: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6428: }
1.393 raeburn 6429: }
1.389 tempelho 6430:
1.510 raeburn 6431: if ($needs_end) {
6432: $r->print(&endContentScreen());
6433: }
1.383 tempelho 6434:
1.329 droeschl 6435: if ($allowed) {
6436: $r->print('
6437: <form method="post" name="extimport" action="/adm/coursedocs">
6438: <input type="hidden" name="title" />
6439: <input type="hidden" name="url" />
6440: <input type="hidden" name="useform" />
6441: <input type="hidden" name="residx" />
6442: </form>');
6443: }
1.484 raeburn 6444: } elsif ($showdoc) {
1.329 droeschl 6445: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6446: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6447: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6448: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6449: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6450: }
6451: }
1.606 raeburn 6452: unless ($noendpage) {
6453: $r->print(&Apache::loncommon::end_page());
6454: }
1.329 droeschl 6455: return OK;
1.364 bisitz 6456: }
1.329 droeschl 6457:
1.440 raeburn 6458: sub embedded_form_elems {
6459: my ($phase,$primaryurl,$newidx) = @_;
6460: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6461: return <<STATE;
6462: <input type="hidden" name="folderpath" value="$folderpath" />
6463: <input type="hidden" name="cmd" value="upload_embedded" />
6464: <input type="hidden" name="newidx" value="$newidx" />
6465: <input type="hidden" name="phase" value="$phase" />
6466: <input type="hidden" name="primaryurl" value="$primaryurl" />
6467: STATE
6468: }
6469:
6470: sub embedded_destination {
6471: my $folder=$env{'form.folder'};
6472: my $destination = 'docs/';
6473: if ($folder =~ /^supplemental/) {
6474: $destination = 'supplemental/';
6475: }
6476: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6477: $destination .= 'default/';
6478: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6479: $destination .= $2.'/';
6480: }
6481: $destination .= $env{'form.newidx'};
6482: my $dir_root = '/userfiles';
6483: return ($destination,$dir_root);
6484: }
6485:
6486: sub return_to_editor {
6487: my $actionurl = '/adm/coursedocs';
6488: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6489: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6490: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6491: '</a></p>';
6492: }
6493:
1.476 raeburn 6494: sub decompression_info {
6495: my ($destination,$dir_root) = &embedded_destination();
6496: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6497: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6498: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6499: my $container='sequence';
1.480 raeburn 6500: my ($pathitem,$hiddenelem);
1.583 raeburn 6501: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6502: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6503: $container='page';
6504: }
1.480 raeburn 6505: unshift(@hiddens,$pathitem);
6506: foreach my $item (@hiddens) {
6507: if ($env{'form.'.$item}) {
6508: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6509: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6510: }
1.477 raeburn 6511: }
1.476 raeburn 6512: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6513: $hiddenelem);
6514: }
6515:
6516: sub decompression_phase_one {
6517: my ($dir,$file,$warning,$error,$output);
6518: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6519: &decompression_info();
1.490 raeburn 6520: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6521: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6522: } else {
6523: my $file = $1;
1.481 raeburn 6524: $output =
6525: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6526: $destination,$dir_root,
6527: $hiddenelem);
6528: if ($env{'form.autoextract_camtasia'}) {
6529: $output .= &remove_archive($docudom,$docuname,$container);
6530: }
1.476 raeburn 6531: }
6532: if ($error) {
6533: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6534: $error.'</p>'."\n";
6535: }
6536: if ($warning) {
6537: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6538: }
6539: return $output;
6540: }
6541:
6542: sub decompression_phase_two {
6543: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6544: &decompression_info();
1.481 raeburn 6545: my $output;
1.480 raeburn 6546: if ($env{'form.archivedelete'}) {
1.481 raeburn 6547: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6548: }
6549: $output .=
1.481 raeburn 6550: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6551: $destination,$dir_root,$hiddenelem);
6552: return $output;
6553: }
6554:
1.480 raeburn 6555: sub remove_archive {
6556: my ($docudom,$docuname,$container) = @_;
6557: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6558: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6559: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6560: if ($fatal) {
6561: if ($container eq 'page') {
6562: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6563: } else {
6564: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6565: }
1.583 raeburn 6566: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6567: } else {
6568: my $currcmd = $env{'form.cmd'};
6569: my $position = $env{'form.position'};
1.583 raeburn 6570: my $archiveidx = $position;
1.563 raeburn 6571: if ($position > 0) {
1.583 raeburn 6572: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6573: $archiveidx = $position-1;
6574: }
6575: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6576: my ($title,$url,@rrest) =
1.583 raeburn 6577: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6578: if ($url eq $env{'form.archiveurl'}) {
6579: if (&handle_edit_cmd($docuname,$docudom)) {
6580: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6581: if ($fatal) {
6582: if ($container eq 'page') {
6583: $delwarning = &mt('An error occurred updating the contents of the current page.');
6584: } else {
6585: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6586: }
1.480 raeburn 6587: } else {
1.583 raeburn 6588: $delresult = &mt('Archive file removed.');
1.480 raeburn 6589: }
6590: }
1.583 raeburn 6591: } else {
6592: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6593: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6594: }
6595: }
6596: $env{'form.cmd'} = $currcmd;
6597: }
6598: if ($delwarning) {
6599: $output = '<p class="LC_warning">'.
6600: $delwarning.
6601: '</p>';
6602: }
6603: if ($delresult) {
6604: $output .= '<p class="LC_info">'.
6605: $delresult.
6606: '</p>';
6607: }
1.481 raeburn 6608: return $output;
1.480 raeburn 6609: }
6610:
1.484 raeburn 6611: sub generate_admin_menu {
1.611 raeburn 6612: my ($crstype,$canedit) = @_;
1.484 raeburn 6613: my $lc_crstype = lc($crstype);
6614: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6615: my %lt= ( # do not translate here
1.484 raeburn 6616: 'vc' => 'Verify Content',
6617: 'cv' => 'Check/Set Resource Versions',
6618: 'ls' => 'List Resource Identifiers',
6619: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6620: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6621: );
1.484 raeburn 6622: my ($candump,$dumpurl);
6623: if ($home + $other > 0) {
6624: $candump = 'F';
6625: if ($home) {
6626: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6627: } else {
6628: my @hosts;
6629: foreach my $aurole (keys(%outhash)) {
6630: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6631: push(@hosts,$outhash{$aurole});
1.538 raeburn 6632: }
1.484 raeburn 6633: }
6634: if (@hosts == 1) {
6635: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6636: '&role='.
6637: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6638: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6639: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6640: } else {
6641: $dumpurl = "javascript:choose_switchserver_window()";
6642: }
6643: }
6644: }
6645: my @menu=
6646: ({ categorytitle=>'Administration',
6647: items =>[
6648: { linktext => $lt{'vc'},
6649: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6650: permission => 'F',
1.571 raeburn 6651: help => 'Docs_Verify_Content',
1.484 raeburn 6652: icon => 'verify.png',
6653: linktitle => 'Verify contents can be retrieved/rendered',
6654: },
6655: { linktext => $lt{'cv'},
6656: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6657: permission => 'F',
1.571 raeburn 6658: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6659: icon => 'resversion.png',
6660: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6661: },
6662: { linktext => $lt{'ls'},
6663: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6664: permission => 'F',
6665: #help => '',
6666: icon => 'symbs.png',
6667: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6668: },
6669: ]
1.611 raeburn 6670: });
6671: if ($canedit) {
6672: push(@menu,
1.484 raeburn 6673: { categorytitle=>'Export',
6674: items =>[
6675: { linktext => $lt{'imse'},
6676: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6677: permission => 'F',
6678: help => 'Docs_Export_Course_Docs',
6679: icon => 'imsexport.png',
6680: linktitle => $lt{'imse'},
6681: },
6682: { linktext => $lt{'dcd'},
6683: url => $dumpurl,
6684: permission => $candump,
1.571 raeburn 6685: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6686: icon => 'dump.png',
6687: linktitle => $lt{'dcd'},
6688: },
6689: ]
6690: });
1.611 raeburn 6691: }
1.484 raeburn 6692: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6693: '<input type="hidden" id="dummy" />'."\n".
6694: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6695: '</form>';
1.329 droeschl 6696: }
6697:
6698: sub generate_edit_table {
1.538 raeburn 6699: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6700: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6701: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6702: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6703: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6704: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6705: $activetab = $env{'form.active'};
6706: }
1.611 raeburn 6707: unless ($canedit) {
6708: $disabled = ' disabled="disabled"';
6709: }
1.472 raeburn 6710: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6711: my $backtext = &mt('Exit Editor');
1.458 raeburn 6712: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6713: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6714: '<li class="goback">'.
1.546 raeburn 6715: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6716: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6717: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6718: '<li>'.
6719: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6720: &mt('Undo Delete').'</a></li>'."\n";
6721: if ($env{'form.docslog'}) {
6722: $form .= '<li class="active">';
6723: } else {
6724: $form .= '<li>';
6725: }
6726: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6727: &mt('History').'</a></li>'."\n";
6728: if ($env{'form.docslog'}) {
6729: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6730: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6731: }
1.458 raeburn 6732: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6733: if($name ne '00'){
1.371 tempelho 6734: if($activetab eq '' || $activetab ne $name){
6735: $active = '';
6736: }elsif($activetab eq $name){
6737: $active = 'class="active"';
6738: }
1.458 raeburn 6739: $form .= '<li style="float:right" '.$active
1.484 raeburn 6740: .' 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 6741: } else {
1.570 raeburn 6742: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6743:
6744: }
1.329 droeschl 6745: }
1.484 raeburn 6746: $form .= '</ul>'."\n";
6747: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6748:
6749: if ($to_show ne '') {
1.538 raeburn 6750: my $saveform;
6751: if ($need_save) {
6752: my $button = &mt('Make changes');
6753: my $path;
6754: if ($env{'form.folderpath'}) {
6755: $path =
6756: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6757: }
6758: $saveform = <<"END";
6759: <div id="multisave" style="display:none; clear:both;" >
6760: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6761: <input type="hidden" name="folderpath" value="$path" />
6762: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6763: <input type="hidden" name="allhiddenresource" value="" />
6764: <input type="hidden" name="allencrypturl" value="" />
6765: <input type="hidden" name="allrandompick" value="" />
6766: <input type="hidden" name="allrandomorder" value="" />
6767: <input type="hidden" name="changeparms" value="" />
6768: <input type="hidden" name="multiremove" value="" />
6769: <input type="hidden" name="multicut" value="" />
6770: <input type="hidden" name="multicopy" value="" />
6771: <input type="hidden" name="multichange" value="" />
6772: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 6773: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 6774: </form>
6775: </div>
6776: END
6777: }
6778: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6779: }
1.363 ehlerst 6780: foreach my $field (keys(%orderhash)){
1.390 tempelho 6781: if($field ne '00'){
1.422 onken 6782: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6783: $active = 'style="display: none;float:left"';
1.422 onken 6784: }elsif($activetab eq $field){
1.458 raeburn 6785: $active = 'style="display:block;float:left"';
1.422 onken 6786: }
6787: $form .= '<div id="'.$field.$tid.'"'
6788: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6789: .'</div>'."\n";
1.363 ehlerst 6790: }
6791: }
1.484 raeburn 6792: unless ($env{'form.docslog'}) {
6793: $form .= '</div></div>'."\n";
6794: }
1.329 droeschl 6795: return $form;
6796: }
6797:
6798: sub editing_js {
1.622 ! raeburn 6799: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
! 6800: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 6801: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6802: p_mnf => 'Name of New Folder',
6803: t_mnf => 'New Folder',
6804: p_mnp => 'Name of New Page',
6805: t_mnp => 'New Page',
1.451 www 6806: p_mxu => 'Title for the External Score',
1.349 biermanm 6807: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6808: p_msb => 'Title for the Problem',
6809: p_mdb => 'Title for the Drop Box',
1.336 schafran 6810: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 6811: p_mwp => 'Title for Web Page',
1.606 raeburn 6812: p_mnr => 'Title for the Resource',
1.348 weissno 6813: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6814: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6815: p_mab_alrt1 => 'Not a valid user:domain',
6816: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6817: p_chn => 'New Title',
6818: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 6819: p_rmr2a => 'Remove',
6820: p_rmr2b => '?',
6821: p_rmr3a => 'Remove those',
6822: p_rmr3b => 'items?',
6823: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6824: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6825: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6826: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 6827: p_ctr2a => 'Cut',
6828: p_ctr2b => '?',
6829: p_ctr3a => 'Cut those',
6830: p_ctr3b => 'items?',
1.478 raeburn 6831: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6832: imsfile => 'You must choose an IMS package for import',
6833: imscms => 'You must select which Course Management System was the source of the IMS package',
6834: invurl => 'Invalid URL',
6835: titbl => 'Title is blank',
1.538 raeburn 6836: more => '(More ...)',
6837: less => '(Less ...)',
1.543 raeburn 6838: noor => 'No actions selected or changes to settings specified.',
6839: noch => 'No changes to settings specified.',
6840: noac => 'No actions selected.',
1.606 raeburn 6841: nofi => 'No file selected',
6842: tinc => 'Title in course',
6843: sunm => 'Sub-directory name',
1.618 raeburn 6844: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6845: );
1.594 damieng 6846: &js_escape(\%js_lt);
1.433 raeburn 6847: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6848: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6849: my $main_container_page;
1.519 raeburn 6850: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6851: $main_container_page = 1;
1.434 raeburn 6852: }
1.617 raeburn 6853: my $backtourl;
6854: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6855: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6856:
1.530 raeburn 6857: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6858: my $caller = $1;
1.525 raeburn 6859: if ($caller =~ /^supplemental/) {
6860: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6861: } else {
6862: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6863: $res = &Apache::lonnet::clutter($res);
6864: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 6865: my ($url,$anchor);
6866: if ($res =~ /^([^#]+)#([^#]+)$/) {
6867: $url = $1;
6868: $anchor = $2;
6869: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6870: $caller = $1.&escape('#').$anchor;
6871: }
1.614 raeburn 6872: } else {
6873: $url = $res;
1.609 raeburn 6874: }
6875: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 6876: &HTML::Entities::encode($caller,'<>&"');
1.622 ! raeburn 6877: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
! 6878: if (($ENV{'SERVER_PORT'} == 443) &&
! 6879: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
! 6880: if ($hostname ne '') {
! 6881: $backtourl = 'http://'.$hostname.$backtourl;
! 6882: }
! 6883: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
! 6884: }
! 6885: }
1.609 raeburn 6886: if ($anchor ne '') {
6887: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6888: }
1.590 raeburn 6889: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6890: } else {
6891: $backtourl = '/adm/navmaps';
1.525 raeburn 6892: }
6893: }
6894: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6895: $backtourl = '/adm/menu';
6896: } elsif ($supplementalflag) {
1.472 raeburn 6897: $backtourl = '/adm/supplemental';
1.525 raeburn 6898: } else {
6899: $backtourl = '/adm/navmaps';
1.472 raeburn 6900: }
6901:
1.600 raeburn 6902: my $fieldsets = "'ext','doc'";
6903: if ($posslti) {
6904: $fieldsets .= ",'tool'";
6905: }
1.519 raeburn 6906: unless ($main_container_page) {
6907: $fieldsets .=",'ims'";
6908: }
1.501 raeburn 6909: if ($supplementalflag) {
1.600 raeburn 6910: $fieldsets = "'suppext','suppdoc'";
6911: if ($posslti) {
6912: $fieldsets .= ",'supptool'";
6913: }
1.501 raeburn 6914: }
1.611 raeburn 6915:
6916: my $jsmakefunctions;
6917: if ($canedit) {
6918: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6919: function makenewfolder(targetform,folderseq) {
1.594 damieng 6920: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6921: if (foldername) {
6922: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6923: targetform.submit();
6924: }
6925: }
6926:
6927: function makenewpage(targetform,folderseq) {
1.594 damieng 6928: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6929: if (pagename) {
6930: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6931: targetform.submit();
6932: }
6933: }
6934:
6935: function makeexamupload() {
1.594 damieng 6936: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6937: if (title) {
1.329 droeschl 6938: this.document.forms.newexamupload.importdetail.value=
6939: escape(title)+'=/res/lib/templates/examupload.problem';
6940: this.document.forms.newexamupload.submit();
6941: }
6942: }
6943:
6944: function makesmppage() {
1.594 damieng 6945: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6946: if (title) {
1.329 droeschl 6947: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 6948: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6949: this.document.forms.newsmppg.submit();
6950: }
6951: }
6952:
1.534 raeburn 6953: function makewebpage(type) {
1.594 damieng 6954: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 6955: var formname;
6956: if (type == 'supp') {
6957: formname = this.document.forms.supwebpage;
6958: } else {
6959: formname = this.document.forms.newwebpage;
6960: }
6961: if (title) {
6962: var webpage = formname.importdetail.value;
6963: formname.importdetail.value = escape(title)+'='+webpage;
6964: formname.submit();
6965: }
6966: }
6967:
1.329 droeschl 6968: function makesmpproblem() {
1.594 damieng 6969: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6970: if (title) {
1.329 droeschl 6971: this.document.forms.newsmpproblem.importdetail.value=
6972: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6973: this.document.forms.newsmpproblem.submit();
6974: }
6975: }
6976:
6977: function makedropbox() {
1.594 damieng 6978: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6979: if (title) {
1.329 droeschl 6980: this.document.forms.newdropbox.importdetail.value=
6981: escape(title)+'=/res/lib/templates/DropBox.problem';
6982: this.document.forms.newdropbox.submit();
6983: }
6984: }
6985:
6986: function makebulboard() {
1.594 damieng 6987: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6988: if (title) {
6989: this.document.forms.newbul.importdetail.value=
1.533 raeburn 6990: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6991: this.document.forms.newbul.submit();
6992: }
6993: }
6994:
6995: function makeabout() {
1.594 damieng 6996: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6997: if (user) {
6998: var comp=new Array();
6999: comp=user.split(':');
7000: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7001: if ((comp[0]) && (comp[1])) {
7002: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7003: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7004: this.document.forms.newaboutsomeone.submit();
7005: } else {
7006: alert("$js_lt{'p_mab_alrt1'}");
7007: }
7008: } else {
7009: alert("$js_lt{'p_mab_alrt2'}");
7010: }
7011: }
7012: }
7013:
7014: function makenew(targetform) {
7015: targetform.submit();
7016: }
7017:
7018: function changename(folderpath,index,oldtitle) {
7019: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7020: if (title) {
7021: this.document.forms.renameform.markcopy.value='';
7022: this.document.forms.renameform.title.value=title;
7023: this.document.forms.renameform.cmd.value='rename_'+index;
7024: this.document.forms.renameform.folderpath.value=folderpath;
7025: this.document.forms.renameform.submit();
7026: }
7027: }
7028:
7029: ENDNEWSCRIPT
7030: } else {
7031: $jsmakefunctions = <<ENDNEWSCRIPT;
7032:
7033: function makenewfolder() {
7034: alert("$js_lt{'edri'}");
7035: }
7036:
7037: function makenewpage() {
7038: alert("$js_lt{'edri'}");
7039: }
7040:
7041: function makeexamupload() {
7042: alert("$js_lt{'edri'}");
7043: }
7044:
7045: function makesmppage() {
7046: alert("$js_lt{'edri'}");
7047: }
7048:
7049: function makewebpage(type) {
7050: alert("$js_lt{'edri'}");
7051: }
7052:
7053: function makesmpproblem() {
7054: alert("$js_lt{'edri'}");
7055: }
7056:
7057: function makedropbox() {
7058: alert("$js_lt{'edri'}");
7059: }
7060:
7061: function makebulboard() {
7062: alert("$js_lt{'edri'}");
7063: }
7064:
7065: function makeabout() {
7066: alert("$js_lt{'edri'}");
7067: }
7068:
7069: function changename() {
7070: alert("$js_lt{'edri'}");
7071: }
7072:
7073: function makenew() {
7074: alert("$js_lt{'edri'}");
7075: }
7076:
7077: function groupimport() {
7078: alert("$js_lt{'edri'}");
1.335 ehlerst 7079: }
1.611 raeburn 7080:
7081: function groupsearch() {
7082: alert("$js_lt{'edri'}");
1.335 ehlerst 7083: }
1.611 raeburn 7084:
7085: function groupopen(url,recover) {
7086: var options="scrollbars=1,resizable=1,menubar=0";
7087: idxflag=1;
7088: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7089: idx.focus();
1.329 droeschl 7090: }
7091:
1.611 raeburn 7092: ENDNEWSCRIPT
7093:
7094: }
7095: return <<ENDSCRIPT;
7096:
7097: $jsmakefunctions
7098:
1.501 raeburn 7099: function toggleUpload(caller) {
7100: var blocks = Array($fieldsets);
7101: for (var i=0; i<blocks.length; i++) {
7102: var disp = 'none';
7103: if (caller == blocks[i]) {
7104: var curr = document.getElementById('upload'+caller+'form').style.display;
7105: if (curr == 'none') {
7106: disp='block';
7107: }
7108: }
7109: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7110: if ((caller == 'tool') || (caller == 'supptool')) {
7111: if (disp == 'block') {
7112: if (document.getElementById('LC_exttoolid')) {
7113: var toolselector = document.getElementById('LC_exttoolid');
7114: var suppflag = 0;
7115: if (caller == 'supptool') {
7116: suppflag = 1;
7117: }
7118: currForm = document.getElementById('new'+caller);
7119: updateExttool(toolselector,currForm,suppflag);
7120: }
7121: }
7122: }
1.501 raeburn 7123: }
1.502 raeburn 7124: resize_scrollbox('contentscroll','1','1');
7125: return;
7126: }
7127:
1.514 raeburn 7128: function toggleMap(caller) {
1.502 raeburn 7129: var disp = 'none';
1.510 raeburn 7130: if (document.getElementById('importmapform')) {
1.514 raeburn 7131: if (caller == 'map') {
7132: var curr = document.getElementById('importmapform').style.display;
7133: if (curr == 'none') {
7134: disp='block';
7135: }
1.510 raeburn 7136: }
7137: document.getElementById('importmapform').style.display=disp;
7138: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7139: }
1.501 raeburn 7140: return;
1.329 droeschl 7141: }
7142:
1.606 raeburn 7143: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7144: var disp = 'none';
7145: if (document.getElementById('crsresform')) {
7146: if (caller == 'res') {
7147: var curr = document.getElementById('crsresform').style.display;
7148: if (curr == 'none') {
7149: disp='block';
7150: numauthor = parseInt(numauthorrole);
7151: if (numauthor > 0) {
7152: document.courseresform.authorrole.selectedIndex = 0;
7153: select1priv_changed();
7154: document.courseresform.authorpath.selectedIndex = 0;
7155: document.courseresform.newresourceadd.selectedIndex = 0;
7156: toggleNewInCourse(document.courseresform);
7157: if (document.getElementById('newresource')) {
7158: document.getElementById('newresource').style.display = 'none';
7159: }
7160: } else {
7161: if (numcrsdirs) {
7162: document.courseresform.authorpath.selectedIndex = 0;
7163: }
7164: }
7165: if (document.courseresform.newresusetemp.length) {
7166: document.courseresform.newresusetemp[0].checked = true;
7167: toggleWithTemplate(document.courseresform);
7168: }
7169: document.courseresform.newresourcename.value = '';
7170: }
7171: }
7172: if (document.courseresform.newsubdir.length) {
7173: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7174: if (document.courseresform.newsubdir[j].value == 0) {
7175: document.courseresform.newsubdir[j].checked = true;
7176: }
7177: break;
7178: }
7179: if (document.getElementById('newsubdirname')) {
7180: document.getElementById('newsubdirname').type = "hidden";
7181: document.getElementById('newsubdirname').value = "";
7182: }
7183: if (document.getElementById('newsubdir')) {
7184: document.getElementById('newsubdir').innerHTML = "";
7185: }
7186: }
7187: document.getElementById('crsresform').style.display=disp;
7188: resize_scrollbox('contentscroll','1','0');
7189: }
7190: return;
7191: }
7192:
7193: function toggleNewsubdir(form) {
7194: if (form.newsubdir.length) {
7195: for (var j=0; j<form.newsubdir.length; j++) {
7196: if (form.newsubdir[j].checked) {
7197: if (document.getElementById('newsubdirname')) {
7198: if (form.newsubdir[j].value == '1') {
7199: document.getElementById('newsubdirname').type = "text";
7200: if (document.getElementById('newsubdir')) {
7201: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7202: }
7203: } else {
7204: document.getElementById('newsubdirname').type = "hidden";
7205: document.getElementById('newsubdirname').value = "";
7206: document.getElementById('newsubdir').innerHTML = "";
7207: }
7208: }
7209: break;
7210: }
7211: }
7212: }
7213: }
7214:
7215: function toggleCrsResTitle() {
7216: if (document.getElementById('newresource')) {
7217: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7218: document.getElementById('newresource').style.display = 'inline';
7219: document.courseresform.newresourceadd[0].checked = true;
7220: toggleNewInCourse(document.courseresform);
7221: } else {
7222: document.getElementById('newresource').style.display = 'none';
7223: }
7224: }
7225: }
7226:
7227: function toggleNewInCourse(form) {
7228: if (form.newresourceadd.length) {
7229: for (var i=0; i<form.newresourceadd.length; i++) {
7230: if (form.newresourceadd[i].checked) {
7231: if (document.getElementById('newresourcetitle')) {
7232: if (form.newresourceadd[i].value == '1') {
7233: document.getElementById('newresourcetitle').type = 'text';
7234: if (document.getElementById('newrestitle')) {
7235: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7236: }
7237: } else {
7238: document.getElementById('newresourcetitle').type = 'hidden';
7239: document.getElementById('newresourcetitle').value = '';
7240: if (document.getElementById('newrestitle')) {
7241: document.getElementById('newrestitle').innerHTML = '';
7242: }
7243: }
7244: }
7245: break;
7246: }
7247: }
7248: }
7249: }
7250:
7251: function toggleWithTemplate(form) {
7252: if (form.newresusetemp.length) {
7253: for (var i=0; i<form.newresusetemp.length; i++) {
7254: if (form.newresusetemp[i].checked) {
7255: if (document.getElementById('newrestemplate')) {
7256: if (form.newresusetemp[i].value == '1') {
7257: document.getElementById('newrestemplate').style.display = 'inline';
7258: toggleExampleText();
7259: } else {
7260: form.tempcategory.selectedIndex = 0;
7261: select1template_changed();
7262: document.getElementById('newrestemplate').style.display = 'none';
7263: }
7264: }
7265: }
7266: }
7267: }
7268: }
7269:
7270: function toggleExampleText() {
7271: if (document.getElementById('newresexample')) {
7272: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7273: if (url == '') {
7274: document.getElementById('newresexample').style.fontWeight = 'normal';
7275: } else {
7276: document.getElementById('newresexample').style.fontWeight = 'bold';
7277: }
7278: }
7279: }
7280:
7281: function getExample(width,height,scrolling,transparency) {
7282: var url;
7283: if (document.courseresform.newresusetemp.length) {
7284: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7285: if (document.courseresform.newresusetemp[i].checked) {
7286: if (document.courseresform.newresusetemp[i].value == '1') {
7287: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7288: if (url == '') {
7289: alert('Pick a category and template');
7290: } else {
7291: url = url.replace("$londocroot","");
7292: url += '?inhibitmenu=yes';
7293: }
7294: }
7295: break;
7296: }
7297: }
7298: }
7299: if (url != '') {
7300: openMyModal(url,width,height,scrolling,transparency,'');
7301: }
7302: }
7303:
7304: function toggleImportCrsres(caller,dircount) {
7305: var disp = 'none';
7306: if (document.getElementById('importcrsresform')) {
7307: if (caller == 'res') {
7308: var numdirs = parseInt(dircount);
7309: var curr = document.getElementById('importcrsresform').style.display;
7310: if (curr == 'none') {
7311: disp='block';
7312: if (numdirs > 1) {
7313: select1res_changed();
7314: }
7315: }
7316: }
7317: document.getElementById('importcrsresform').style.display=disp;
7318: resize_scrollbox('contentscroll','1','0');
7319: }
7320: return;
7321: }
7322:
1.501 raeburn 7323: function makeims(imsform) {
7324: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7325: alert("$js_lt{'imsfile'}");
1.501 raeburn 7326: return;
7327: }
7328: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7329: alert("$js_lt{'imscms'}");
1.501 raeburn 7330: return;
7331: }
7332: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7333: imsform.submit();
7334: }
7335:
1.478 raeburn 7336: function updatePick(targetform,index,caller) {
1.537 raeburn 7337: var pickitem;
7338: var picknumitem;
7339: var picknumtext;
7340: if (index == 'all') {
7341: pickitem = document.getElementById('randompickall');
7342: picknumitem = document.getElementById('rpicknumall');
7343: picknumtext = document.getElementById('rpicktextall');
7344: } else {
7345: pickitem = document.getElementById('randompick_'+index);
7346: picknumitem = document.getElementById('rpicknum_'+index);
7347: picknumtext = document.getElementById('randompicknum_'+index);
7348: }
1.478 raeburn 7349: if (pickitem.checked) {
1.594 damieng 7350: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7351: if (picknum == '' || picknum == null) {
7352: if (caller == 'check') {
7353: pickitem.checked=false;
1.537 raeburn 7354: if (index == 'all') {
7355: picknumtext.innerHTML = '';
7356: if (caller == 'link') {
7357: propagateState(targetform,'rpicknum');
7358: }
7359: } else {
1.538 raeburn 7360: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7361: }
1.478 raeburn 7362: }
7363: } else {
7364: picknum.toString();
7365: var regexdigit=/^\\d+\$/;
7366: if (regexdigit.test(picknum)) {
7367: picknumitem.value = picknum;
1.537 raeburn 7368: if (index == 'all') {
1.538 raeburn 7369: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7370: if (caller == 'link') {
7371: propagateState(targetform,'rpicknum');
7372: }
7373: } else {
7374: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7375: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7376: }
1.478 raeburn 7377: } else {
7378: if (caller == 'check') {
1.537 raeburn 7379: if (index == 'all') {
7380: picknumtext.innerHTML = '';
7381: if (caller == 'link') {
7382: propagateState(targetform,'rpicknum');
7383: }
7384: } else {
7385: pickitem.checked=false;
1.538 raeburn 7386: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7387: }
1.478 raeburn 7388: }
7389: return;
7390: }
7391: }
7392: } else {
1.537 raeburn 7393: picknumitem.value = '';
7394: picknumtext.innerHTML = '';
7395: if (index == 'all') {
7396: if (caller == 'link') {
7397: propagateState(targetform,'rpicknum');
7398: }
7399: } else {
1.538 raeburn 7400: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7401: }
7402: }
7403: }
7404:
7405: function propagateState(form,param) {
7406: if (document.getElementById(param+'all')) {
7407: var setcheck = 0;
7408: var rpick = 0;
7409: if (param == 'rpicknum') {
7410: if (document.getElementById('randompickall')) {
7411: if (document.getElementById('randompickall').checked) {
7412: if (document.getElementById('rpicknumall')) {
7413: rpick = document.getElementById('rpicknumall').value;
7414: }
7415: }
7416: }
7417: } else {
7418: if (document.getElementById(param+'all').checked) {
7419: setcheck = 1;
7420: }
7421: }
1.538 raeburn 7422: var allidxlist;
7423: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7424: if (document.getElementById('all'+param+'idx')) {
7425: allidxlist = document.getElementById('all'+param+'idx').value;
7426: }
7427: var actions = new Array ('remove','cut','copy');
7428: for (var i=0; i<actions.length; i++) {
7429: if (actions[i] != param) {
7430: if (document.getElementById(actions[i]+'all')) {
7431: document.getElementById(actions[i]+'all').checked = false;
7432: }
7433: }
7434: }
7435: }
1.537 raeburn 7436: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7437: allidxlist = form.allidx.value;
7438: }
7439: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7440: allidxlist = form.allmapidx.value;
7441: }
7442: if ((allidxlist != '') && (allidxlist != null)) {
7443: var allidxs = allidxlist.split(',');
7444: if (allidxs.length > 1) {
7445: for (var i=0; i<allidxs.length; i++) {
7446: if (document.getElementById(param+'_'+allidxs[i])) {
7447: if (param == 'rpicknum') {
7448: if (document.getElementById('randompick_'+allidxs[i])) {
7449: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7450: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7451: if (rpick > 0) {
7452: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7453: } else {
7454: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7455: }
7456: }
7457: }
7458: } else {
1.537 raeburn 7459: if (setcheck == 1) {
7460: document.getElementById(param+'_'+allidxs[i]).checked = true;
7461: } else {
7462: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7463: if (param == 'randompick') {
7464: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7465: }
1.537 raeburn 7466: }
7467: }
7468: }
7469: }
1.538 raeburn 7470: if (setcheck == 1) {
7471: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7472: var actions = new Array('copy','cut','remove');
7473: for (var i=0; i<actions.length; i++) {
7474: var otheractions;
7475: var otheridxs;
7476: if (actions[i] === param) {
7477: continue;
7478: } else {
7479: if (document.getElementById('all'+actions[i]+'idx')) {
7480: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7481: otheridxs = otheractions.split(',');
7482: if (otheridxs.length > 1) {
7483: for (var j=0; j<otheridxs.length; j++) {
7484: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7485: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7486: }
1.537 raeburn 7487: }
7488: }
7489: }
1.538 raeburn 7490: }
7491: }
7492: }
7493: }
7494: }
7495: }
7496: }
7497: return;
7498: }
7499:
1.603 raeburn 7500: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7501: var canedit = '$canedit';
7502: if (canedit == '') {
7503: alert("$js_lt{'edri'}");
7504: return;
7505: }
1.539 raeburn 7506: var dosettings;
7507: var doaction;
1.538 raeburn 7508: var control = document.togglemultsettings;
7509: if (context == 'actions') {
7510: control = document.togglemultactions;
1.539 raeburn 7511: doaction = 1;
7512: } else {
7513: dosettings = 1;
1.538 raeburn 7514: }
1.539 raeburn 7515: if (control) {
7516: if (control.showmultpick.length) {
7517: for (var i=0; i<control.showmultpick.length; i++) {
7518: if (control.showmultpick[i].checked) {
7519: if (control.showmultpick[i].value == 1) {
7520: if (context == 'settings') {
7521: dosettings = 0;
7522: } else {
7523: doaction = 0;
1.538 raeburn 7524: }
7525: }
7526: }
1.537 raeburn 7527: }
7528: }
1.539 raeburn 7529: }
7530: if (context == 'settings') {
7531: if (dosettings == 1) {
1.538 raeburn 7532: targetform.changeparms.value=param;
7533: targetform.submit();
7534: }
1.537 raeburn 7535: }
1.539 raeburn 7536: if (context == 'actions') {
7537: if (doaction == 1) {
7538: targetform.cmd.value=param+'_'+index;
7539: targetform.folderpath.value=folderpath;
7540: targetform.markcopy.value=idx+':'+param;
7541: targetform.copyfolder.value=folder+'.'+container;
7542: if (param == 'remove') {
1.603 raeburn 7543: var doremove = 0;
7544: if (skip_confirm) {
7545: if (confirm_removal) {
7546: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7547: doremove = 1;
7548: }
7549: } else {
7550: doremove = 1;
7551: }
7552: } else {
7553: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7554: doremove = 1;
7555: }
7556: }
7557: if (doremove) {
1.539 raeburn 7558: targetform.markcopy.value='';
7559: targetform.copyfolder.value='';
7560: targetform.submit();
7561: }
7562: }
7563: if (param == 'cut') {
1.594 damieng 7564: 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 7565: targetform.submit();
7566: return;
7567: }
7568: }
7569: if (param == 'copy') {
7570: targetform.submit();
7571: return;
7572: }
7573: targetform.markcopy.value='';
7574: targetform.copyfolder.value='';
7575: targetform.cmd.value='';
7576: targetform.folderpath.value='';
7577: return;
7578: } else {
7579: if (document.getElementById(param+'_'+idx)) {
7580: item = document.getElementById(param+'_'+idx);
7581: if (item.type == 'checkbox') {
7582: if (item.checked) {
7583: item.checked = false;
7584: } else {
7585: item.checked = true;
7586: singleCheck(item,idx,param);
7587: }
7588: }
7589: }
7590: }
7591: }
1.537 raeburn 7592: return;
7593: }
7594:
1.538 raeburn 7595: function singleCheck(caller,idx,action) {
7596: actions = new Array('cut','copy','remove');
7597: if (caller.checked) {
7598: for (var i=0; i<actions.length; i++) {
7599: if (actions[i] != action) {
7600: if (document.getElementById(actions[i]+'_'+idx)) {
7601: if (document.getElementById(actions[i]+'_'+idx).checked) {
7602: document.getElementById(actions[i]+'_'+idx).checked = false;
7603: }
1.537 raeburn 7604: }
7605: }
7606: }
1.478 raeburn 7607: }
1.537 raeburn 7608: return;
1.478 raeburn 7609: }
7610:
1.334 muellerd 7611: function unselectInactive(nav) {
1.335 ehlerst 7612: currentNav = document.getElementById(nav);
7613: currentLis = currentNav.getElementsByTagName('LI');
7614: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7615: if (currentLis[i].className == 'goback') {
7616: currentLis[i].className = 'goback';
7617: } else {
7618: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7619: currentLis[i].className = 'right';
1.472 raeburn 7620: } else {
1.374 tempelho 7621: currentLis[i].className = 'i';
1.472 raeburn 7622: }
7623: }
1.335 ehlerst 7624: }
1.332 tempelho 7625: }
7626:
1.334 muellerd 7627: function hideAll(current, nav, data) {
1.335 ehlerst 7628: unselectInactive(nav);
1.570 raeburn 7629: if (current) {
7630: if (current.className == 'right'){
7631: current.className = 'right active'
7632: } else {
7633: current.className = 'active';
7634: }
1.374 tempelho 7635: }
1.335 ehlerst 7636: currentData = document.getElementById(data);
7637: currentDivs = currentData.getElementsByTagName('DIV');
7638: for (i = 0; i < currentDivs.length; i++) {
7639: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7640: currentDivs[i].style.display = 'none';
1.330 tempelho 7641: }
7642: }
1.335 ehlerst 7643: }
1.330 tempelho 7644:
1.374 tempelho 7645: function openTabs(pageId) {
7646: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7647: if(tabnav.length > 2 ){
1.389 tempelho 7648: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7649: currentLis = currentNav.getElementsByTagName('LI');
7650: for(i = 0; i< currentLis.length; i++){
7651: if(currentLis[i].className == 'active') {
1.375 tempelho 7652: funcString = currentLis[i].onclick.toString();
7653: tab = funcString.split('"');
1.420 onken 7654: if(tab.length < 2) {
7655: tab = funcString.split("'");
7656: }
1.375 tempelho 7657: currentData = document.getElementById(tab[1]);
7658: currentData.style.display = 'block';
1.374 tempelho 7659: }
7660: }
7661: }
7662: }
7663:
1.334 muellerd 7664: function showPage(current, pageId, nav, data) {
1.570 raeburn 7665: currstate = current.className;
1.334 muellerd 7666: hideAll(current, nav, data);
1.375 tempelho 7667: openTabs(pageId);
1.334 muellerd 7668: unselectInactive(nav);
1.570 raeburn 7669: if ((currstate == 'active') || (currstate == 'right active')) {
7670: if (currstate == 'active') {
7671: current.className = '';
7672: } else {
7673: current.className = 'right';
7674: }
7675: activeTab = '';
7676: toggleUpload();
7677: toggleMap();
1.606 raeburn 7678: toggleCrsRes();
7679: toggleImportCrsres();
1.570 raeburn 7680: resize_scrollbox('contentscroll','1','0');
7681: return;
7682: } else {
7683: current.className = 'active';
7684: }
1.330 tempelho 7685: currentData = document.getElementById(pageId);
7686: currentData.style.display = 'block';
1.458 raeburn 7687: activeTab = pageId;
1.501 raeburn 7688: toggleUpload();
1.503 raeburn 7689: toggleMap();
1.606 raeburn 7690: toggleCrsRes();
7691: toggleImportCrsres();
1.433 raeburn 7692: if (nav == 'mainnav') {
7693: var storedpath = "$docs_folderpath";
1.434 raeburn 7694: var storedpage = "$main_container_page";
1.433 raeburn 7695: var reg = new RegExp("^supplemental");
7696: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7697: if (storedpage == 1) {
7698: document.simpleedit.folderpath.value = '';
7699: document.uploaddocument.folderpath.value = '';
7700: } else {
7701: if (reg.test(storedpath)) {
7702: document.simpleedit.folderpath.value = '$toplevelmain';
7703: document.uploaddocument.folderpath.value = '$toplevelmain';
7704: document.newext.folderpath.value = '$toplevelmain';
7705: } else {
7706: document.simpleedit.folderpath.value = storedpath;
7707: document.uploaddocument.folderpath.value = storedpath;
7708: document.newext.folderpath.value = storedpath;
7709: }
1.433 raeburn 7710: }
7711: } else {
1.434 raeburn 7712: if (reg.test(storedpath)) {
7713: document.simpleedit.folderpath.value = storedpath;
7714: document.supuploaddocument.folderpath.value = storedpath;
7715: document.supnewext.folderpath.value = storedpath;
7716: } else {
1.433 raeburn 7717: document.simpleedit.folderpath.value = '$toplevelsupp';
7718: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7719: document.supnewext.folderpath.value = '$toplevelsupp';
7720: }
7721: }
7722: }
1.485 raeburn 7723: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7724: return false;
7725: }
1.329 droeschl 7726:
1.472 raeburn 7727: function toContents(jumpto) {
7728: var newurl = '$backtourl';
1.525 raeburn 7729: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7730: newurl = newurl+'?postdata='+jumpto;
7731: }
7732: location.href=newurl;
7733: }
7734:
1.538 raeburn 7735: function togglePick(caller,value) {
7736: var disp = 'none';
7737: if (document.getElementById('multi'+caller)) {
7738: var curr = document.getElementById('multi'+caller).style.display;
7739: if (value == 1) {
7740: disp='block';
7741: }
7742: if (curr == disp) {
7743: return;
7744: }
7745: document.getElementById('multi'+caller).style.display=disp;
7746: if (value == 1) {
1.594 damieng 7747: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7748: } else {
7749: document.getElementById('more'+caller).innerHTML = '';
7750: }
7751: if (caller == 'actions') {
7752: setClass(value);
7753: setBoxes(value);
7754: }
7755: }
7756: var showButton = multiSettings();
7757: if (showButton != 1) {
7758: showButton = multiActions();
7759: }
7760: if (document.getElementById('multisave')) {
7761: if (showButton == 1) {
7762: document.getElementById('multisave').style.display='block';
7763: } else {
7764: document.getElementById('multisave').style.display='none';
7765: }
7766: }
7767: resize_scrollbox('contentscroll','1','1');
7768: return;
7769: }
7770:
7771: function toggleCheckUncheck(caller,more) {
7772: if (more == 1) {
1.594 damieng 7773: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 7774: document.getElementById('allfields'+caller).style.display='block';
7775: } else {
1.594 damieng 7776: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7777: document.getElementById('allfields'+caller).style.display='none';
7778: }
7779: resize_scrollbox('contentscroll','1','1');
7780: }
7781:
7782: function multiSettings() {
7783: var inuse = 0;
7784: var settingsform = document.togglemultsettings;
7785: if (settingsform.showmultpick.length > 1) {
7786: for (var i=0; i<settingsform.showmultpick.length; i++) {
7787: if (settingsform.showmultpick[i].checked) {
7788: if (settingsform.showmultpick[i].value == 1) {
7789: inuse = 1;
7790: }
7791: }
7792: }
7793: }
7794: return inuse;
7795: }
7796:
7797: function multiActions() {
7798: var inuse = 0;
7799: var actionsform = document.togglemultactions;
7800: if (actionsform.showmultpick.length > 1) {
7801: for (var i=0; i<actionsform.showmultpick.length; i++) {
7802: if (actionsform.showmultpick[i].checked) {
7803: if (actionsform.showmultpick[i].value == 1) {
7804: inuse = 1;
7805: }
7806: }
7807: }
7808: }
7809: return inuse;
7810: }
7811:
7812: function checkSubmits() {
7813: var numchanges = 0;
7814: var form = document.saveactions;
7815: var doactions = multiActions();
1.542 raeburn 7816: var cutwarnings = 0;
7817: var remwarnings = 0;
1.603 raeburn 7818: var removalinfo = 0;
1.538 raeburn 7819: if (doactions == 1) {
7820: var remidxlist = document.cumulativeactions.allremoveidx.value;
7821: if ((remidxlist != '') && (remidxlist != null)) {
7822: var remidxs = remidxlist.split(',');
7823: for (var i=0; i<remidxs.length; i++) {
7824: if (document.getElementById('remove_'+remidxs[i])) {
7825: if (document.getElementById('remove_'+remidxs[i]).checked) {
7826: form.multiremove.value += remidxs[i]+',';
7827: numchanges ++;
1.542 raeburn 7828: if (document.getElementById('skip_remove_'+remidxs[i])) {
7829: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7830: remwarnings ++;
7831: }
7832: }
1.603 raeburn 7833: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7834: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7835: removalinfo ++;
7836: }
7837: }
1.537 raeburn 7838: }
7839: }
1.538 raeburn 7840: }
7841: }
7842: var cutidxlist = document.cumulativeactions.allcutidx.value;
7843: if ((cutidxlist != '') && (cutidxlist != null)) {
7844: var cutidxs = cutidxlist.split(',');
7845: for (var i=0; i<cutidxs.length; i++) {
7846: if (document.getElementById('cut_'+cutidxs[i])) {
7847: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7848: form.multicut.value += cutidxs[i]+',';
7849: numchanges ++;
1.542 raeburn 7850: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7851: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7852: cutwarnings ++;
7853: }
7854: }
1.537 raeburn 7855: }
7856: }
7857: }
7858: }
1.538 raeburn 7859: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7860: if ((copyidxlist != '') && (copyidxlist != null)) {
7861: var copyidxs = copyidxlist.split(',');
7862: for (var i=0; i<copyidxs.length; i++) {
7863: if (document.getElementById('copy_'+copyidxs[i])) {
7864: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7865: form.multicopy.value += copyidxs[i]+',';
7866: numchanges ++;
7867: }
7868: }
7869: }
7870: }
7871: if (numchanges > 0) {
7872: form.multichange.value = numchanges;
7873: }
1.537 raeburn 7874: }
1.538 raeburn 7875: var dosettings = multiSettings();
1.543 raeburn 7876: var haschanges = 0;
1.538 raeburn 7877: if (dosettings == 1) {
7878: form.allencrypturl.value = '';
7879: form.allhiddenresource.value = '';
1.543 raeburn 7880: form.changeparms.value = 'all';
7881: var patt=new RegExp(",\$");
1.538 raeburn 7882: var allidxlist = document.cumulativesettings.allidx.value;
7883: if ((allidxlist != '') && (allidxlist != null)) {
7884: var allidxs = allidxlist.split(',');
7885: if (allidxs.length > 1) {
7886: for (var i=0; i<allidxs.length; i++) {
7887: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7888: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7889: form.allhiddenresource.value += allidxs[i]+',';
7890: }
7891: }
7892: if (document.getElementById('encrypturl_'+allidxs[i])) {
7893: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7894: form.allencrypturl.value += allidxs[i]+',';
7895: }
7896: }
7897: }
1.543 raeburn 7898: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7899: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 7900: }
1.538 raeburn 7901: }
7902: form.allrandompick.value = '';
7903: form.allrandomorder.value = '';
7904: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7905: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7906: var allmapidxs = allmapidxlist.split(',');
7907: for (var i=0; i<allmapidxs.length; i++) {
7908: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7909: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7910: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7911: if ((randompick.checked) && (rpicknum.value != '')) {
7912: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7913: }
7914: if (randorder.checked) {
7915: form.allrandomorder.value += allmapidxs[i]+',';
7916: }
1.537 raeburn 7917: }
1.543 raeburn 7918: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7919: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7920: }
7921: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7922: haschanges = 1;
7923: }
7924: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7925: haschanges = 1;
7926: }
7927: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7928: haschanges = 1;
7929: }
7930: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7931: haschanges = 1;
1.537 raeburn 7932: }
7933: }
1.543 raeburn 7934: if (doactions == 1) {
1.542 raeburn 7935: if (numchanges > 0) {
1.603 raeburn 7936: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 7937: if (remwarnings > 0) {
1.594 damieng 7938: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 7939: return false;
7940: }
7941: }
1.603 raeburn 7942: if (removalinfo > 0) {
7943: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7944: return false;
7945: }
7946: }
1.542 raeburn 7947: if (cutwarnings > 0) {
1.594 damieng 7948: 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 7949: return false;
7950: }
7951: }
7952: }
7953: form.submit();
7954: return true;
1.543 raeburn 7955: }
7956: }
7957: if (dosettings == 1) {
7958: if (haschanges == 1) {
1.542 raeburn 7959: form.submit();
7960: return true;
7961: }
1.543 raeburn 7962: }
7963: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 7964: alert("$js_lt{'noor'}");
1.543 raeburn 7965: } else {
7966: if (dosettings == 1) {
1.594 damieng 7967: alert("$js_lt{'noch'}");
1.543 raeburn 7968: } else {
1.594 damieng 7969: alert("$js_lt{'noac'}");
1.543 raeburn 7970: }
7971: }
1.538 raeburn 7972: return false;
7973: }
7974:
7975: function setClass(value) {
7976: var cutclass = 'LC_docs_cut';
7977: var copyclass = 'LC_docs_copy';
7978: var removeclass = 'LC_docs_remove';
7979: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7980: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7981: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7982: var links = document.getElementsByTagName('a');
7983: for (var i=0; i<links.length; i++) {
7984: var classes = links[i].className;
7985: if (cutreg.test(classes)) {
7986: links[i].className = cutclass;
7987: if (value == 1) {
7988: links[i].className += " LC_menubuttons_link";
7989: }
7990: } else {
7991: if (copyreg.test(classes)) {
7992: links[i].className = copyclass;
7993: if (value == 1) {
7994: links[i].className += " LC_menubuttons_link";
7995: }
7996: } else {
7997: if (removereg.test(classes)) {
7998: links[i].className = removeclass;
7999: if (value == 1) {
8000: links[i].className += " LC_menubuttons_link";
8001: }
8002: }
8003: }
8004: }
8005: }
8006: return;
1.537 raeburn 8007: }
8008:
1.538 raeburn 8009: function setBoxes(value) {
8010: var remidxlist = document.cumulativeactions.allremoveidx.value;
8011: if ((remidxlist != '') && (remidxlist != null)) {
8012: var remidxs = remidxlist.split(',');
8013: for (var i=0; i<remidxs.length; i++) {
8014: if (document.getElementById('remove_'+remidxs[i])) {
8015: var item = document.getElementById('remove_'+remidxs[i]);
8016: if (value == 1) {
8017: item.className = 'LC_docs_remove';
8018: } else {
8019: item.className = 'LC_hidden';
8020: }
8021: }
8022: }
8023: }
8024: var cutidxlist = document.cumulativeactions.allcutidx.value;
8025: if ((cutidxlist != '') && (cutidxlist != null)) {
8026: var cutidxs = cutidxlist.split(',');
8027: for (var i=0; i<cutidxs.length; i++) {
8028: if (document.getElementById('cut_'+cutidxs[i])) {
8029: var item = document.getElementById('cut_'+cutidxs[i]);
8030: if (value == 1) {
8031: item.className = 'LC_docs_cut';
8032: } else {
8033: item.className = 'LC_hidden';
8034: }
8035: }
1.537 raeburn 8036: }
8037: }
1.538 raeburn 8038: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8039: if ((copyidxlist != '') && (copyidxlist != null)) {
8040: var copyidxs = copyidxlist.split(',');
8041: for (var i=0; i<copyidxs.length; i++) {
8042: if (document.getElementById('copy_'+copyidxs[i])) {
8043: var item = document.getElementById('copy_'+copyidxs[i]);
8044: if (value == 1) {
8045: item.className = 'LC_docs_copy';
8046: } else {
8047: item.className = 'LC_hidden';
8048: }
8049: }
1.537 raeburn 8050: }
8051: }
8052: return;
8053: }
8054:
1.606 raeburn 8055: function validImportCrsRes() {
8056: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8057: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8058: if ((fname == '') || (fname == null)) {
8059: alert("$js_lt{'nofi'}");
8060: return false;
8061: }
8062: var url = '/res/$coursedom/$coursenum/';
8063: if (path && path != '/') {
8064: url += path+'/';
8065: }
8066: if (fname != '') {
8067: url += fname;
8068: }
8069: var title = document.crsresimportform.crsrestitle.value;
8070: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8071: return true;
8072: }
8073:
8074: function validateNewRes(caller) {
8075: if (caller == 'single') {
8076: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8077: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8078: var resname = document.courseresform.newresourcename.value;
8079: }
8080: }
8081:
1.611 raeburn 8082: ENDSCRIPT
1.329 droeschl 8083: }
1.457 raeburn 8084:
1.483 raeburn 8085: sub history_tab_js {
8086: return <<"ENDHIST";
8087: function toggleHistoryDisp(choice) {
8088: document.docslogform.docslog.value = choice;
8089: document.docslogform.submit();
8090: return;
8091: }
8092:
8093: ENDHIST
8094: }
8095:
1.484 raeburn 8096: sub inject_data_js {
8097: return <<ENDINJECT;
8098:
8099: function injectData(current, hiddenField, name, value) {
8100: currentElement = document.getElementById(hiddenField);
8101: currentElement.name = name;
8102: currentElement.value = value;
8103: current.submit();
8104: }
8105:
8106: ENDINJECT
8107: }
8108:
8109: sub dump_switchserver_js {
8110: my @hosts = @_;
1.594 damieng 8111: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8112: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8113: swit => 'Switch server?',
1.594 damieng 8114: );
8115: my %html_js_lt = &Apache::lonlocal::texthash(
8116: swit => 'Switch server?',
1.568 raeburn 8117: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8118: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8119: chos => 'Choose server',
8120: );
1.594 damieng 8121: &js_escape(\%js_lt);
8122: &html_escape(\%html_js_lt);
8123: &js_escape(\%html_js_lt);
1.484 raeburn 8124: my $role = $env{'request.role'};
8125: my $js = <<"ENDSWJS";
8126: <script type="text/javascript">
8127: function write_switchserver() {
8128: var server;
8129: if (document.setserver.posshosts.length > 0) {
8130: for (var i=0; i<document.setserver.posshosts.length; i++) {
8131: if (document.setserver.posshosts[i].checked) {
8132: server = document.setserver.posshosts[i].value;
8133: }
8134: }
8135: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8136: }
8137: window.close();
8138: }
8139: </script>
8140:
8141: ENDSWJS
8142:
8143: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8144: {'only_body' => 1,
8145: 'js_ready' => 1,});
8146: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8147:
8148: my $hostpicker;
8149: my $count = 0;
8150: foreach my $host (sort(@hosts)) {
8151: my $checked;
8152: if ($count == 0) {
8153: $checked = ' checked="checked"';
8154: }
8155: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8156: $host.'"'.$checked.' />'.$host.'</label> ';
8157: $count++;
8158: }
8159:
8160: return <<"ENDSWITCHJS";
8161:
8162: function dump_needs_switchserver(url) {
8163: if (url!='' && url!= null) {
1.594 damieng 8164: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8165: go(url);
8166: }
8167: }
8168: return;
8169: }
8170:
8171: function choose_switchserver_window() {
8172: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8173: newWindow.document.open();
8174: newWindow.document.writeln('$startpage');
1.594 damieng 8175: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8176: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8177: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8178: '<form name="setserver" method="post" action="" \\/>\\n'+
8179: '$hostpicker\\n'+
8180: '<br \\/><br \\/>\\n'+
1.594 damieng 8181: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8182: 'onclick="write_switchserver();" \\/>\\n'+
8183: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8184: newWindow.document.writeln('$endpage');
8185: newWindow.document.close();
8186: newWindow.focus();
8187: }
8188:
8189: ENDSWITCHJS
8190: }
8191:
8192: sub makedocslogform {
8193: my ($formelems,$docslog) = @_;
8194: return <<"LOGSFORM";
8195: <form action="/adm/coursedocs" method="post" name="docslogform">
8196: <input type="hidden" name="docslog" value="$docslog" />
8197: $formelems
8198: </form>
8199: LOGSFORM
8200: }
8201:
8202: sub makesimpleeditform {
8203: my ($formelems) = @_;
8204: return <<"SIMPFORM";
8205: <form name="simpleedit" method="post" action="/adm/coursedocs">
8206: <input type="hidden" name="importdetail" value="" />
8207: $formelems
8208: </form>
8209: SIMPFORM
8210: }
8211:
1.606 raeburn 8212: sub makenewproblem {
8213: my ($r,$coursedom,$coursenum) = @_;
8214: # Creating a new problem
8215: my ($redirect,$error);
8216: if ($env{'form.authorrole'}) {
8217: my ($newsubdir,$filename);
8218: if ($env{'form.newsubdir'}) {
8219: if ($env{'form.newsubdirname'} ne '') {
8220: $newsubdir = $env{'form.newsubdirname'};
8221: }
8222: }
8223: if ($env{'form.newresourcename'}) {
8224: $filename = $env{'form.newresourcename'};
8225: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8226: $filename =~ s/`//g;
8227: $filename =~ s{/\.\./}{_}g;
8228: $filename =~ s/\.+/./g;
8229: $filename =~ s{/+}{_}g;
8230: if ($filename ne '') {
8231: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8232: if (($ext) && ($ext ne '.problem')) {
8233: $filename = $name.'.problem';
8234: } elsif ($ext eq '') {
8235: $filename .= '.problem';
8236: }
8237: my $docroot = $r->dir_config('lonDocRoot');
8238: my @ids=&Apache::lonnet::current_machine_ids();
8239: if ($env{'form.authorrole'} eq 'author') {
8240: if ($env{'user.author'}) {
8241: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8242: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8243: my $path = $docroot.$url;
8244: my $subdir = $env{'form.authorpath'};
8245: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8246: }
8247: }
8248: } elsif ($env{'form.authorrole'} eq 'course') {
8249: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8250: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8251: my $url = "/priv/$coursedom/$coursenum";
8252: my $path=$docroot.$url;
8253: my $subdir = $env{'form.authorpath'};
8254: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8255: if ($redirect) {
8256: my $rightsfile = 'default.rights';
8257: my $sourcerights = "$path/$rightsfile";
8258: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8259: my $now = time;
8260: if (!-e $sourcerights) {
8261: my $cid = $coursedom.'_'.$coursenum;
8262: if (open(my $fh,">$sourcerights")) {
8263: print $fh <<END;
8264: <accessrule effect="deny" realm="" type="course" role="" />
8265: <accessrule effect="allow" realm="$cid" type="course" role="" />
8266: END
8267: close($fh);
8268: }
8269: }
8270: if (!-e "$sourcerights.meta") {
8271: if (open(my $fh,">$sourcerights.meta")) {
8272: my $author=$env{'environment.firstname'}.' '.
8273: $env{'environment.middlename'}.' '.
8274: $env{'environment.lastname'}.' '.
8275: $env{'environment.generation'};
8276: $author =~ s/\s+$//;
8277: print $fh <<"END";
8278:
8279: <abstract></abstract>
8280: <author>$author</author>
8281: <authorspace>$coursenum:$coursedom</authorspace>
8282: <copyright>private</copyright>
8283: <creationdate>$now</creationdate>
8284: <customdistributionfile></customdistributionfile>
8285: <dependencies></dependencies>
8286: <domain>$coursedom</domain>
8287: <highestgradelevel>0</highestgradelevel>
8288: <keywords></keywords>
8289: <language>notset </language>
8290: <lastrevisiondate>$now</lastrevisiondate>
8291: <lowestgradelevel>0</lowestgradelevel>
8292: <mime>rights</mime>
8293: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8294: <notes></notes>
8295: <obsolete></obsolete>
8296: <obsoletereplacement></obsoletereplacement>
8297: <owner>$coursenum:$coursedom</owner>
8298: <rule>deny:::course,allow:$cid::course</rule>
8299: <sourceavail></sourceavail>
8300: <standards></standards>
8301: <subject></subject>
8302: <title></title>
8303: END
8304: close($fh);
8305: }
8306: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8307: if (!-e "$docroot/res/$coursedom") {
8308: mkdir("$docroot/res/$coursedom",0755);
8309: }
8310: if (!-e "$docroot/res/$coursedom/$coursenum") {
8311: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8312: }
8313: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8314: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8315: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8316: }
8317: }
8318: }
8319: if ($env{'form.newresourceadd'}) {
8320: my $template = $env{'form.template'};
8321: my $source = $docroot.$redirect;
8322: my $target = $redirect;
8323: $target =~ s{^/priv/}{/res/};
8324: $target = $docroot.$target;
8325: if (!-e $source) {
8326: my $copyfrom;
8327: if ($template) {
8328: my %templates;
8329: my @files = &Apache::lonhomework::get_template_list('problem');
8330: foreach my $poss (@files) {
8331: if (ref($poss) eq 'ARRAY') {
8332: if ($template eq $poss->[0]) {
8333: $templates{$template} = 1;
8334: last;
8335: }
8336: }
8337: }
8338: if ($templates{$template}) {
8339: $copyfrom = $template;
8340: }
8341: }
8342: unless ($copyfrom) {
8343: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8344: }
8345: &File::Copy::copy($copyfrom,$source);
8346: }
8347: if (!-e "$source.meta") {
8348: my $cid = $coursedom.'_'.$coursenum;
8349: my $now = time;
8350: if (open(my $fh,">$source.meta")) {
8351: my $author=$env{'environment.firstname'}.' '.
8352: $env{'environment.middlename'}.' '.
8353: $env{'environment.lastname'}.' '.
8354: $env{'environment.generation'};
8355: $author =~ s/\s+$//;
8356: my $title = $env{'form.newresourcetitle'};
8357: $title =~ s/^\s+|\s+$//g;
8358: print $fh <<END;
8359:
8360: <abstract></abstract>
8361: <author>$author</author>
8362: <authorspace>$coursenum:$coursedom</authorspace>
8363: <copyright>custom</copyright>
8364: <creationdate>$now</creationdate>
8365: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8366: <dependencies></dependencies>
8367: <domain>$coursedom</domain>
8368: <highestgradelevel>0</highestgradelevel>
8369: <keywords></keywords>
8370: <language>notset </language>
8371: <lastrevisiondate>$now</lastrevisiondate>
8372: <lowestgradelevel>0</lowestgradelevel>
8373: <mime>problem</mime>
8374: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8375: <notes></notes>
8376: <obsolete></obsolete>
8377: <obsoletereplacement></obsoletereplacement>
8378: <owner>$coursenum:$coursedom</owner>
8379: <sourceavail></sourceavail>
8380: <standards></standards>
8381: <subject></subject>
8382: <title>$title</title>
8383: END
8384: close($fh);
8385: }
8386: }
8387: }
8388: }
8389: }
8390: } else {
8391: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8392: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8393: if (grep(/^\Q$rolehome\E$/,@ids)) {
8394: my $now = time;
8395: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8396: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8397: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8398: my $url = "/priv/$audom/$auname";
8399: my $path = $r->dir_config('lonDocRoot').$url;
8400: my $subdir = $env{'form.authorpath'};
8401: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8402: }
8403: }
8404: }
8405: }
8406: }
8407: }
8408: }
8409: return ($redirect,$error);
8410: }
8411:
8412: sub finishnewprob {
8413: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8414: unless (-d $path) {
8415: unless (mkdir($path,02770)) {
8416: return;
8417: }
8418: }
1.606 raeburn 8419: my $redirect;
8420: if ($subdir ne '/') {
8421: $subdir = &cleandir($subdir);
8422: if (($subdir ne '') && (-d "$path/$subdir")) {
8423: $path .= "/$subdir";
8424: $url .= "/$subdir";
8425: }
8426: }
8427: my $dest;
8428: if ($newsubdir ne '') {
8429: $newsubdir = &cleandir($newsubdir);
8430: }
8431: if ($newsubdir ne '') {
8432: if (-d "$path/$newsubdir") {
8433: $dest = "$path/$newsubdir/$filename";
8434: } else {
8435: my $dirok;
8436: unless (-e "$path/$newsubdir") {
8437: if (mkdir("$path/$newsubdir",02770)) {
8438: if (chmod(02770,"$path/$newsubdir")) {
8439: $dirok = 1;
8440: }
8441: }
8442: }
8443: if ($dirok) {
8444: $dest = "$path/$newsubdir/$filename";
8445: }
8446: }
8447: if (($dest ne '') && (!-e $dest)) {
8448: $redirect = "$url/$newsubdir/$filename";
8449: }
8450: } else {
8451: $dest = "$path/$filename";
8452: if (($dest ne '') && (!-e $dest)) {
8453: $redirect = "$url/$filename";
8454: }
8455: }
8456: return $redirect;
8457: }
8458:
8459: sub cleandir {
8460: my ($dir) = @_;
8461: $dir =~ s/^\s+//;
8462: $dir =~ s/\s+$//;
8463: $dir =~ s/\.+//g;
8464: $dir =~ s/[\#\?&%\":]//g;
8465: return $dir;
8466: }
8467:
1.329 droeschl 8468: 1;
8469: __END__
8470:
8471:
8472: =head1 NAME
8473:
8474: Apache::londocs.pm
8475:
8476: =head1 SYNOPSIS
8477:
8478: This is part of the LearningOnline Network with CAPA project
8479: described at http://www.lon-capa.org.
8480:
8481: =head1 SUBROUTINES
8482:
8483: =over
8484:
8485: =item %help=()
8486:
8487: Available help topics
8488:
8489: =item mapread()
8490:
1.344 bisitz 8491: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8492: @order and @resources, determines status
8493: sets @order - pointer to resources in right order
8494: sets @resources - array with the resources with correct idx
8495:
8496: =item authorhosts()
8497:
8498: Return hash with valid author names
8499:
8500: =item clean()
8501:
8502: =item dumpcourse()
8503:
8504: Actually dump course
8505:
8506: =item group_import()
8507:
8508: Imports the given (name, url) resources into the course
8509: coursenum, coursedom, and folder must precede the list
8510:
8511: =item breadcrumbs()
8512:
8513: =item log_docs()
8514:
8515: =item docs_change_log()
8516:
8517: =item update_paste_buffer()
8518:
8519: =item print_paste_buffer()
8520:
8521: =item do_paste_from_buffer()
8522:
1.538 raeburn 8523: =item do_buffer_empty()
8524:
8525: =item clear_from_buffer()
8526:
1.492 raeburn 8527: =item get_newmap_url()
8528:
8529: =item dbcopy()
8530:
8531: =item uniqueness_check()
8532:
8533: =item contained_map_check()
8534:
8535: =item url_paste_fixups()
8536:
8537: =item apply_fixups()
8538:
8539: =item copy_dependencies()
8540:
1.329 droeschl 8541: =item update_parameter()
8542:
8543: =item handle_edit_cmd()
8544:
8545: =item editor()
8546:
8547: =item process_file_upload()
8548:
8549: =item process_secondary_uploads()
8550:
8551: =item is_supplemental_title()
8552:
8553: =item entryline()
8554:
8555: =item tiehash()
8556:
8557: =item untiehash()
8558:
8559: =item checkonthis()
8560:
8561: check on this
8562:
8563: =item verifycontent()
8564:
8565: Verify Content
8566:
8567: =item devalidateversioncache() & checkversions()
8568:
8569: Check Versions
8570:
8571: =item mark_hash_old()
8572:
8573: =item is_hash_old()
8574:
8575: =item changewarning()
8576:
8577: =item init_breadcrumbs()
8578:
8579: Breadcrumbs for special functions
8580:
1.484 raeburn 8581: =item create_list_elements()
8582:
8583: =item create_form_ul()
8584:
8585: =item startContentScreen()
8586:
8587: =item endContentScreen()
8588:
8589: =item supplemental_base()
8590:
8591: =item embedded_form_elems()
8592:
8593: =item embedded_destination()
8594:
8595: =item return_to_editor()
8596:
8597: =item decompression_info()
8598:
8599: =item decompression_phase_one()
8600:
8601: =item decompression_phase_two()
8602:
8603: =item remove_archive()
8604:
8605: =item generate_admin_menu()
8606:
8607: =item generate_edit_table()
8608:
8609: =item editing_js()
8610:
8611: =item history_tab_js()
8612:
8613: =item inject_data_js()
8614:
8615: =item dump_switchserver_js()
8616:
1.485 raeburn 8617: =item resize_scrollbox_js()
1.484 raeburn 8618:
8619: =item makedocslogform()
8620:
1.485 raeburn 8621: =item makesimpleeditform()
8622:
1.329 droeschl 8623: =back
8624:
8625: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>