Annotation of loncom/interface/londocs.pm, revision 1.623
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.623 ! raeburn 4: # $Id: londocs.pm,v 1.622 2017/02/20 18:29:22 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: }
1.623 ! raeburn 3991: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
! 3992: my $wrapped = $1;
! 3993: my $exturl = $2;
! 3994: if ($wrapped eq '') {
! 3995: $url='/adm/wrapper'.$url;
! 3996: }
! 3997: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
! 3998: $nomodal = 1;
! 3999: }
1.598 raeburn 4000: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4001: $url='/adm/wrapper'.$url;
1.621 raeburn 4002: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4003: if (($ENV{'SERVER_PORT'} == 443) &&
4004: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4005: $url .= '?usehttp=1';
4006: $nomodal = 1;
4007: }
1.598 raeburn 4008: }
1.501 raeburn 4009: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4010: my $shownsymb = $symb;
4011: if ($isexternal) {
4012: if ($url =~ /^([^#]+)#([^#]+)$/) {
4013: $url = $1;
4014: $anchor = $2;
4015: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4016: $shownsymb = $1.&escape('#').$anchor;
4017: }
4018: }
4019: }
1.617 raeburn 4020: unless ($env{'request.role.adv'}) {
4021: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4022: $url = '';
4023: }
4024: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4025: $url = '';
4026: $hiddenres = 1;
4027: }
4028: }
4029: if ($url ne '') {
4030: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4031: }
1.615 raeburn 4032: } elsif (!$env{'request.role.adv'}) {
4033: my $checkencrypt;
4034: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4035: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4036: $checkencrypt = 1;
1.620 raeburn 4037: } elsif (ref($navmapref)) {
1.615 raeburn 4038: unless (ref($$navmapref)) {
4039: $$navmapref = Apache::lonnavmaps::navmap->new();
4040: }
4041: if (ref($$navmapref)) {
4042: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4043: $checkencrypt = 1;
4044: }
4045: }
4046: }
4047: if ($checkencrypt) {
4048: my $shownsymb = &Apache::lonenc::encrypted($symb);
4049: my $shownurl = &Apache::lonenc::encrypted($url);
4050: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4051: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4052: if ($env{'request.enc'} ne '') {
4053: delete($env{'request.enc'});
4054: }
4055: } else {
4056: $url='';
1.613 raeburn 4057: }
1.612 raeburn 4058: } else {
4059: $url='';
4060: }
1.501 raeburn 4061: } else {
4062: $url='';
4063: }
1.329 droeschl 4064: }
1.621 raeburn 4065: } elsif ($supplementalflag) {
1.610 raeburn 4066: if ($isexternal) {
4067: if ($url =~ /^([^#]+)#([^#]+)$/) {
4068: $url = $1;
4069: $anchor = $2;
1.623 ! raeburn 4070: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
! 4071: if ($hostname ne '') {
! 4072: $url = 'http://'.$hostname.$url;
! 4073: }
! 4074: $nomodal = 1;
! 4075: }
1.610 raeburn 4076: }
1.621 raeburn 4077: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4078: if (($ENV{'SERVER_PORT'} == 443) &&
4079: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.622 raeburn 4080: if ($hostname ne '') {
4081: $url = 'http://'.$hostname.$url;
4082: }
1.621 raeburn 4083: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4084: $nomodal = 1;
4085: }
1.610 raeburn 4086: }
1.329 droeschl 4087: }
1.615 raeburn 4088: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4089: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4090: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4091: my $foldername=&escape($foldertitle);
4092: my $folderpath=$env{'form.folderpath'};
4093: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4094: if (!$allowed && $supplementalflag) {
1.519 raeburn 4095: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4096: $url.='folderpath='.&escape($folderpath);
4097: } else {
1.617 raeburn 4098: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4099: 'parameter_randompick'))[0];
4100: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4101: 'parameter_randomorder'))[0]=~/^yes$/i);
4102: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4103: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4104: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4105: 'parameter_encrypturl'))[0]=~/^yes$/i);
4106: unless ($hiddenmap) {
1.620 raeburn 4107: if (ref($navmapref)) {
4108: unless (ref($$navmapref)) {
4109: $$navmapref = Apache::lonnavmaps::navmap->new();
4110: }
4111: if (ref($$navmapref)) {
4112: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4113: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4114: unless (@resources) {
4115: $hiddenmap = 1;
4116: unless ($env{'request.role.adv'}) {
4117: $url = '';
4118: $hiddenfolder = 1;
4119: }
1.617 raeburn 4120: }
1.615 raeburn 4121: }
4122: }
4123: }
4124: }
1.617 raeburn 4125: unless ($encryptmap) {
1.620 raeburn 4126: if ((ref($navmapref)) && (ref($$navmapref))) {
4127: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4128: $encryptmap = 1;
4129: }
1.617 raeburn 4130: }
4131: }
4132:
4133: # Append randompick number, hidden, and encrypted with ":" to foldername,
4134: # so it gets transferred between levels
4135: $folderpath.=$containerarg.'&'.$foldername.
4136: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4137: unless ($url eq '') {
1.612 raeburn 4138: $url.='folderpath='.&escape($folderpath);
4139: }
1.510 raeburn 4140: my $rpckchk;
4141: if ($rpicknum) {
4142: $rpckchk = ' checked="checked"';
1.543 raeburn 4143: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4144: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4145: }
1.510 raeburn 4146: }
1.537 raeburn 4147: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4148: $rand_pick_text =
1.478 raeburn 4149: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4150: $form_param."\n".
1.478 raeburn 4151: $form_common."\n".
1.611 raeburn 4152: '<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 4153: if ($rpicknum ne '') {
4154: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4155: }
1.537 raeburn 4156: $rand_pick_text .= '</span></span>'.
4157: $form_end;
1.543 raeburn 4158: my $ro_set;
1.617 raeburn 4159: if ($randorder) {
1.543 raeburn 4160: $ro_set = 'checked="checked"';
4161: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4162: push(@{$filtersref->{'randomorder'}},$orderidx);
4163: }
4164: }
1.564 raeburn 4165: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4166: $rand_order_text =
1.537 raeburn 4167: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4168: $form_param."\n".
1.537 raeburn 4169: $form_common."\n".
1.611 raeburn 4170: '<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 4171: $form_end;
1.510 raeburn 4172: }
1.509 raeburn 4173: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4174: my $isexttool;
4175: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4176: $url='/adm/wrapper'.$url;
4177: $isexttool = 1;
4178: }
1.510 raeburn 4179: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4180: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4181: if ($title) {
4182: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4183: }
1.598 raeburn 4184: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4185: $url .= '&idx='.$orderidx;
4186: }
1.610 raeburn 4187: if ($anchor ne '') {
4188: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4189: }
1.329 droeschl 4190: }
1.519 raeburn 4191: my ($tdalign,$tdwidth);
1.501 raeburn 4192: if ($allowed) {
4193: my $fileloc =
4194: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4195: if ($isexternal) {
1.518 raeburn 4196: ($editlink,$extresform) =
1.611 raeburn 4197: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4198: undef,undef,undef,undef,undef,undef,
4199: undef,$disabled);
1.598 raeburn 4200: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4201: ($editlink,$extresform) =
4202: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4203: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4204: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4205: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4206: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4207: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4208: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4209: my $suppanchor;
4210: if ($supplementalflag) {
4211: $suppanchor = $anchor;
4212: }
1.501 raeburn 4213: my $jscall =
4214: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4215: $switchserver,
1.503 raeburn 4216: $forceedit,
1.511 raeburn 4217: undef,$symb,
4218: &escape($env{'form.folderpath'}),
1.622 raeburn 4219: $renametitle,$hostname,
4220: '','',1,$suppanchor);
1.501 raeburn 4221: if ($jscall) {
1.518 raeburn 4222: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4223: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4224: }
4225: }
4226: }
1.519 raeburn 4227: $tdalign = ' align="right" valign="top"';
4228: $tdwidth = ' width="80%"';
1.329 droeschl 4229: }
1.408 raeburn 4230: my $reinit;
4231: if ($crstype eq 'Community') {
4232: $reinit = &mt('(re-initialize community to access)');
4233: } else {
4234: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4235: }
4236: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.621 raeburn 4237: my $link;
1.472 raeburn 4238: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4239: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4240: } elsif ($url) {
1.610 raeburn 4241: if ($anchor ne '') {
4242: if ($supplementalflag) {
4243: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4244: } else {
4245: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4246: }
4247: }
1.622 raeburn 4248: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4249: $link = 'http://'.$hostname.$url;
4250: } else {
4251: $link = $url;
4252: }
4253: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.621 raeburn 4254: (($anchor ne '')?$anchor:''));
4255: if ($nomodal) {
4256: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4257: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4258: } else {
4259: $line.=&Apache::loncommon::modal_link($link,
4260: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4261: }
1.469 www 4262: } else {
4263: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4264: }
1.519 raeburn 4265: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4266: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4267: $line.='<a href="'.$url.'">'.$title.'</a>';
4268: } elsif ($url) {
1.621 raeburn 4269: if ($nomodal) {
4270: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4271: $title.'</a>';
4272: } else {
4273: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4274: }
1.617 raeburn 4275: } elsif (($hiddenfolder) || ($hiddenres)) {
1.615 raeburn 4276: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
1.469 www 4277: } else {
4278: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4279: }
1.518 raeburn 4280: $line.="$extresform</td>";
1.478 raeburn 4281: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4282: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4283: if (($allowed) && ($folder!~/^supplemental/)) {
4284: my %lt=&Apache::lonlocal::texthash(
4285: 'hd' => 'Hidden',
4286: 'ec' => 'URL hidden');
1.543 raeburn 4287: my ($enctext,$hidtext);
4288: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4289: $enctext = ' checked="checked"';
4290: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4291: push(@{$filtersref->{'encrypturl'}},$orderidx);
4292: }
4293: }
4294: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4295: $hidtext = ' checked="checked"';
4296: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4297: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4298: }
4299: }
1.537 raeburn 4300: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4301: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4302: $line.=(<<ENDPARMS);
4303: <td class="LC_docs_entry_parameter">
1.537 raeburn 4304: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4305: $form_param
1.478 raeburn 4306: $form_common
1.611 raeburn 4307: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4308: $form_end
1.458 raeburn 4309: <br />
1.537 raeburn 4310: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4311: $form_param
1.478 raeburn 4312: $form_common
1.611 raeburn 4313: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4314: $form_end
4315: </td>
1.478 raeburn 4316: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4317: $rand_order_text</td>
1.329 droeschl 4318: ENDPARMS
4319: }
1.379 bisitz 4320: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4321: return $line;
4322: }
4323:
1.538 raeburn 4324: sub action_restrictions {
4325: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4326: my %denied = (
4327: cut => 0,
4328: copy => 0,
4329: remove => 0,
4330: );
4331: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4332: # no copy for published maps
4333: $denied{'copy'} = 1;
1.597 raeburn 4334: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4335: unless ($1 eq 'simpleproblem') {
4336: $denied{'copy'} = 1;
4337: }
4338: $denied{'cut'} = 1;
1.538 raeburn 4339: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4340: if ($folderpath =~ /^default&[^\&]+$/) {
4341: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4342: $denied{'remove'} = 1;
4343: }
4344: $denied{'cut'} = 1;
4345: $denied{'copy'} = 1;
4346: }
4347: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4348: my $group = $1;
4349: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4350: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4351: $denied{'remove'} = 1;
4352: }
4353: }
4354: $denied{'cut'} = 1;
4355: $denied{'copy'} = 1;
4356: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4357: my $group = $1;
4358: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4359: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4360: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4361: if (keys(%groupsettings) > 0) {
4362: $denied{'remove'} = 1;
4363: }
4364: $denied{'cut'} = 1;
4365: $denied{'copy'} = 1;
4366: }
4367: }
4368: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4369: my $group = $1;
4370: if ($url =~ /group_boards_\Q$group\E/) {
4371: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4372: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4373: if (keys(%groupsettings) > 0) {
4374: if (ref($groupsettings{'functions'}) eq 'HASH') {
4375: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4376: $denied{'remove'} = 1;
4377: }
4378: }
4379: }
4380: $denied{'cut'} = 1;
4381: $denied{'copy'} = 1;
4382: }
4383: }
4384: }
4385: return %denied;
4386: }
4387:
1.533 raeburn 4388: sub new_timebased_suffix {
1.538 raeburn 4389: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4390: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4391: if ($type eq 'paste') {
4392: $prefix = $type;
4393: $namespace = 'courseeditor';
1.587 raeburn 4394: $idtype = 'addcode';
1.538 raeburn 4395: } elsif ($type eq 'map') {
1.533 raeburn 4396: $prefix = 'docs';
4397: if ($area eq 'supplemental') {
4398: $prefix = 'supp';
4399: }
4400: $prefix .= $container;
4401: $namespace = 'uploadedmaps';
4402: } else {
4403: $prefix = $type;
4404: $namespace = 'templated';
1.504 raeburn 4405: }
4406: my ($suffix,$freedlock,$error) =
1.587 raeburn 4407: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4408: if (!$suffix) {
1.538 raeburn 4409: if ($type eq 'paste') {
4410: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4411: } elsif ($type eq 'map') {
1.533 raeburn 4412: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4413: } elsif ($type eq 'smppg') {
4414: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4415: } else {
1.565 bisitz 4416: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4417: }
1.504 raeburn 4418: if ($error) {
4419: $errtext .= '<br />'.$error;
4420: }
4421: }
4422: if ($freedlock ne 'ok') {
1.533 raeburn 4423: $locknotfreed =
4424: '<div class="LC_error">'.
4425: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4426: if ($type eq 'paste') {
1.591 raeburn 4427: if ($freedlock eq 'nolock') {
4428: $locknotfreed =
4429: '<div class="LC_error">'.
4430: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4431:
1.593 droeschl 4432: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4433: } else {
4434: $locknotfreed .=
4435: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4436: }
1.538 raeburn 4437: } elsif ($type eq 'map') {
1.591 raeburn 4438: $locknotfreed .=
4439: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4440: } elsif ($type eq 'smppg') {
4441: $locknotfreed .=
4442: &mt('This will prevent creation of additional simple pages in this course.');
4443: } else {
4444: $locknotfreed .=
1.565 bisitz 4445: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4446: }
1.538 raeburn 4447: unless ($type eq 'paste') {
4448: $locknotfreed .=
1.560 raeburn 4449: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4450: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4451: }
4452: $locknotfreed .= '</div>';
1.504 raeburn 4453: }
4454: return ($suffix,$errtext,$locknotfreed);
4455: }
4456:
1.329 droeschl 4457: =pod
4458:
4459: =item tiehash()
4460:
4461: tie the hash
4462:
4463: =cut
4464:
4465: sub tiehash {
4466: my ($mode)=@_;
4467: $hashtied=0;
4468: if ($env{'request.course.fn'}) {
4469: if ($mode eq 'write') {
4470: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4471: &GDBM_WRCREAT(),0640)) {
4472: $hashtied=2;
4473: }
4474: } else {
4475: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4476: &GDBM_READER(),0640)) {
4477: $hashtied=1;
4478: }
4479: }
1.364 bisitz 4480: }
1.329 droeschl 4481: }
4482:
4483: sub untiehash {
4484: if ($hashtied) { untie %hash; }
4485: $hashtied=0;
4486: return OK;
4487: }
4488:
4489:
4490:
4491:
4492: sub checkonthis {
4493: my ($r,$url,$level,$title)=@_;
4494: $url=&unescape($url);
4495: $alreadyseen{$url}=1;
4496: $r->rflush();
4497: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4498: $r->print("\n<br />");
4499: if ($level==0) {
4500: $r->print("<br />");
4501: }
4502: for (my $i=0;$i<=$level*5;$i++) {
4503: $r->print(' ');
4504: }
4505: $r->print('<a href="'.$url.'" target="cat">'.
4506: ($title?$title:$url).'</a> ');
4507: if ($url=~/^\/res\//) {
4508: my $result=&Apache::lonnet::repcopy(
4509: &Apache::lonnet::filelocation('',$url));
4510: if ($result eq 'ok') {
4511: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4512: $r->rflush();
4513: &Apache::lonnet::countacc($url);
4514: $url=~/\.(\w+)$/;
4515: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4516: $r->print('<br />');
4517: $r->rflush();
4518: for (my $i=0;$i<=$level*5;$i++) {
4519: $r->print(' ');
4520: }
4521: $r->print('- '.&mt('Rendering:').' ');
4522: my ($errorcount,$warningcount)=split(/:/,
4523: &Apache::lonnet::ssi_body($url,
4524: ('grade_target'=>'web',
4525: 'return_only_error_and_warning_counts' => 1)));
4526: if (($errorcount) ||
4527: ($warningcount)) {
4528: if ($errorcount) {
1.369 bisitz 4529: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4530: &mt('[quant,_1,error]',$errorcount).'</span>');
4531: }
4532: if ($warningcount) {
4533: $r->print('<span class="LC_warning">'.
4534: &mt('[quant,_1,warning]',$warningcount).'</span>');
4535: }
4536: } else {
4537: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4538: }
4539: $r->rflush();
4540: }
4541: my $dependencies=
4542: &Apache::lonnet::metadata($url,'dependencies');
4543: foreach my $dep (split(/\,/,$dependencies)) {
4544: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4545: &checkonthis($r,$dep,$level+1);
4546: }
4547: }
4548: } elsif ($result eq 'unavailable') {
4549: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4550: } elsif ($result eq 'not_found') {
4551: unless ($url=~/\$/) {
1.521 bisitz 4552: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4553: } else {
1.366 bisitz 4554: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4555: }
4556: } else {
4557: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4558: }
4559: }
4560: }
4561: }
4562:
4563:
4564:
4565: =pod
4566:
4567: =item list_symbs()
4568:
1.485 raeburn 4569: List Content Identifiers
1.329 droeschl 4570:
4571: =cut
4572:
4573: sub list_symbs {
4574: my ($r) = @_;
4575:
1.408 raeburn 4576: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4577: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4578: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4579: $r->print(&startContentScreen('tools'));
1.329 droeschl 4580: my $navmap = Apache::lonnavmaps::navmap->new();
4581: if (!defined($navmap)) {
4582: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4583: '<div class="LC_error">'.
4584: &mt('Unable to retrieve information about course contents').
4585: '</div>');
1.408 raeburn 4586: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4587: } else {
1.484 raeburn 4588: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4589: &Apache::loncommon::start_data_table().
4590: &Apache::loncommon::start_data_table_header_row().
4591: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4592: &Apache::loncommon::end_data_table_header_row()."\n");
4593: my $count;
1.329 droeschl 4594: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4595: $r->print(&Apache::loncommon::start_data_table_row().
4596: '<td>'.$res->compTitle().'</td>'.
4597: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4598: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4599: $count ++;
4600: }
4601: if (!$count) {
4602: $r->print(&Apache::loncommon::start_data_table_row().
4603: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4604: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4605: }
1.484 raeburn 4606: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4607: }
1.521 bisitz 4608: $r->print(&endContentScreen());
1.329 droeschl 4609: }
4610:
4611:
4612: sub verifycontent {
4613: my ($r) = @_;
1.408 raeburn 4614: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4615: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4616: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4617: $r->print(&startContentScreen('tools'));
4618: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4619: $hashtied=0;
4620: undef %alreadyseen;
4621: %alreadyseen=();
4622: &tiehash();
1.484 raeburn 4623:
1.329 droeschl 4624: foreach my $key (keys(%hash)) {
4625: if ($hash{$key}=~/\.(page|sequence)$/) {
4626: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4627: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4628: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4629: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4630: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4631: }
4632: }
4633: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4634: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4635: }
4636: }
4637: &untiehash();
1.442 www 4638: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4639: $r->print(&endContentScreen());
1.329 droeschl 4640: }
4641:
4642:
4643: sub devalidateversioncache {
4644: my $src=shift;
4645: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4646: &Apache::lonnet::clutter($src));
4647: }
4648:
4649: sub checkversions {
1.611 raeburn 4650: my ($r,$canedit) = @_;
1.408 raeburn 4651: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4652: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4653: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4654: $r->print(&startContentScreen('tools'));
1.442 www 4655:
1.329 droeschl 4656: my $header='';
4657: my $startsel='';
4658: my $monthsel='';
4659: my $weeksel='';
4660: my $daysel='';
4661: my $allsel='';
4662: my %changes=();
4663: my $starttime=0;
4664: my $haschanged=0;
4665: my %setversions=&Apache::lonnet::dump('resourceversions',
4666: $env{'course.'.$env{'request.course.id'}.'.domain'},
4667: $env{'course.'.$env{'request.course.id'}.'.num'});
4668:
4669: $hashtied=0;
4670: &tiehash();
1.611 raeburn 4671: if ($canedit) {
4672: my %newsetversions=();
4673: if ($env{'form.setmostrecent'}) {
4674: $haschanged=1;
4675: foreach my $key (keys(%hash)) {
4676: if ($key=~/^ids\_(\/res\/.+)$/) {
4677: $newsetversions{$1}='mostrecent';
4678: &devalidateversioncache($1);
4679: }
4680: }
4681: } elsif ($env{'form.setcurrent'}) {
4682: $haschanged=1;
4683: foreach my $key (keys(%hash)) {
4684: if ($key=~/^ids\_(\/res\/.+)$/) {
4685: my $getvers=&Apache::lonnet::getversion($1);
4686: if ($getvers>0) {
4687: $newsetversions{$1}=$getvers;
4688: &devalidateversioncache($1);
4689: }
4690: }
1.329 droeschl 4691: }
1.611 raeburn 4692: } elsif ($env{'form.setversions'}) {
4693: $haschanged=1;
4694: foreach my $key (keys(%env)) {
4695: if ($key=~/^form\.set_version_(.+)$/) {
4696: my $src=$1;
4697: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4698: $newsetversions{$src}=$env{$key};
4699: &devalidateversioncache($src);
4700: }
4701: }
1.329 droeschl 4702: }
1.611 raeburn 4703: }
4704: if ($haschanged) {
4705: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4706: $env{'course.'.$env{'request.course.id'}.'.domain'},
4707: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4708: $r->print(&Apache::loncommon::confirmwrapper(
4709: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4710: } else {
4711: $r->print(&Apache::loncommon::confirmwrapper(
4712: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4713: }
1.611 raeburn 4714: &mark_hash_old();
4715: }
4716: &changewarning($r,'');
1.329 droeschl 4717: }
4718: if ($env{'form.timerange'} eq 'all') {
4719: # show all documents
1.549 raeburn 4720: $header=&mt('All content in '.$crstype);
1.521 bisitz 4721: $allsel=' selected="selected"';
1.329 droeschl 4722: foreach my $key (keys(%hash)) {
4723: if ($key=~/^ids\_(\/res\/.+)$/) {
4724: my $src=$1;
4725: $changes{$src}=1;
4726: }
4727: }
4728: } else {
4729: # show documents which changed
4730: %changes=&Apache::lonnet::dump
4731: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4732: $env{'course.'.$env{'request.course.id'}.'.num'});
4733: my $firstkey=(keys(%changes))[0];
4734: unless ($firstkey=~/^error\:/) {
4735: unless ($env{'form.timerange'}) {
4736: $env{'form.timerange'}=604800;
4737: }
4738: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4739: .&mt('seconds');
4740: if ($env{'form.timerange'}==-1) {
4741: $seltext='since start of course';
1.521 bisitz 4742: $startsel=' selected="selected"';
1.329 droeschl 4743: $env{'form.timerange'}=time;
4744: }
4745: $starttime=time-$env{'form.timerange'};
4746: if ($env{'form.timerange'}==2592000) {
4747: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4748: $monthsel=' selected="selected"';
1.329 droeschl 4749: } elsif ($env{'form.timerange'}==604800) {
4750: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4751: $weeksel=' selected="selected"';
1.329 droeschl 4752: } elsif ($env{'form.timerange'}==86400) {
4753: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4754: $daysel=' selected="selected"';
1.329 droeschl 4755: }
4756: $header=&mt('Content changed').' '.$seltext;
4757: } else {
4758: $header=&mt('No content modifications yet.');
4759: }
4760: }
4761: %setversions=&Apache::lonnet::dump('resourceversions',
4762: $env{'course.'.$env{'request.course.id'}.'.domain'},
4763: $env{'course.'.$env{'request.course.id'}.'.num'});
4764: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4765: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4766: 'lm' => 'Version changes since last Month',
4767: 'lw' => 'Version changes since last Week',
4768: 'sy' => 'Version changes since Yesterday',
4769: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4770: 'cd' => 'Change display',
1.329 droeschl 4771: 'sd' => 'Display',
4772: 'fi' => 'File',
4773: 'md' => 'Modification Date',
4774: 'mr' => 'Most recently published Version',
1.408 raeburn 4775: 've' => 'Version used in '.$crstype,
4776: 'vu' => 'Set Version to be used in '.$crstype,
4777: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4778: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4779: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4780: 'di' => 'Differences',
1.484 raeburn 4781: 'save' => 'Save changes',
4782: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4783: 'act' => 'Actions');
1.611 raeburn 4784: my ($disabled,$readonly);
4785: unless ($canedit) {
4786: $disabled = 'disabled="disabled"';
4787: $readonly = 1;
4788: }
1.329 droeschl 4789: $r->print(<<ENDHEADERS);
1.484 raeburn 4790: <h4 class="LC_info">$header</h4>
1.329 droeschl 4791: <form action="/adm/coursedocs" method="post">
4792: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4793: <div class="LC_left_float">
1.479 golterma 4794: <fieldset>
1.484 raeburn 4795: <legend>$lt{'cd'}</legend>
1.329 droeschl 4796: <select name="timerange">
1.521 bisitz 4797: <option value='all'$allsel>$lt{'al'}</option>
4798: <option value="-1"$startsel>$lt{'st'}</option>
4799: <option value="2592000"$monthsel>$lt{'lm'}</option>
4800: <option value="604800"$weeksel>$lt{'lw'}</option>
4801: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4802: </select>
4803: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4804: </fieldset>
4805: </div>
4806: <div class="LC_left_float">
4807: <fieldset>
4808: <legend>$lt{'act'}</legend>
1.611 raeburn 4809: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4810: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4811: </fieldset>
4812: </div>
4813: <br clear="all" />
4814: <hr />
4815: <h4>$lt{'vers'}</h4>
1.329 droeschl 4816: ENDHEADERS
1.479 golterma 4817: #number of columns for version history
1.571 raeburn 4818: my %changedbytime;
4819: foreach my $key (keys(%changes)) {
4820: #excludes not versionable problems from resource version history:
4821: next if ($key =~ /^\/res\/lib\/templates/);
4822: my $chg;
4823: if ($env{'form.timerange'} eq 'all') {
4824: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4825: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4826: } else {
4827: $chg = $changes{$key};
4828: next if ($chg < $starttime);
4829: }
4830: push(@{$changedbytime{$chg}},$key);
4831: }
4832: if (keys(%changedbytime) == 0) {
4833: &untiehash();
4834: $r->print(&mt('No content changes in imported content in specified time frame').
4835: &endContentScreen());
4836: return;
4837: }
1.479 golterma 4838: $r->print(
1.611 raeburn 4839: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4840: &Apache::loncommon::start_data_table().
4841: &Apache::loncommon::start_data_table_header_row().
4842: '<th>'.&mt('Resources').'</th>'.
4843: "<th>$lt{'mr'}</th>".
4844: "<th>$lt{'ve'}</th>".
4845: "<th>$lt{'vu'}</th>".
4846: '<th>'.&mt('History').'</th>'.
4847: &Apache::loncommon::end_data_table_header_row()
4848: );
1.571 raeburn 4849: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4850: foreach my $key (sort(@{$changedbytime{$chg}})) {
4851: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4852: my $currentversion=&Apache::lonnet::getversion($key);
4853: if ($currentversion<0) {
4854: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4855: }
4856: my $linkurl=&Apache::lonnet::clutter($key);
4857: $r->print(
4858: &Apache::loncommon::start_data_table_row().
4859: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4860: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4861: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4862: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4863: '<td align="right">'
4864: );
4865: # Used in course
4866: my $usedversion=$hash{'version_'.$linkurl};
4867: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4868: if ($usedversion != $currentversion) {
1.479 golterma 4869: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4870: } else {
1.479 golterma 4871: $r->print($usedversion);
4872: }
1.329 droeschl 4873: } else {
1.521 bisitz 4874: $r->print($currentversion);
1.329 droeschl 4875: }
1.571 raeburn 4876: $r->print('</td><td title="'.$lt{'vu'}.'">');
4877: # Set version
4878: $r->print(&Apache::loncommon::select_form(
4879: $setversions{$linkurl},
4880: 'set_version_'.$linkurl,
4881: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4882: '' => '',
4883: 'mostrecent' => &mt('most recent'),
1.611 raeburn 4884: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 4885: my $lastold=1;
4886: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4887: my $url=$root.'.'.$prevvers.'.'.$extension;
4888: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4889: $lastold=$prevvers;
4890: }
4891: }
4892: $r->print('</td>');
4893: # List all available versions
4894: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4895: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4896: my $url=$root.'.'.$prevvers.'.'.$extension;
4897: $r->print(
4898: '<span class="LC_nobreak">'
4899: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4900: .&mt('Version [_1]',$prevvers).'</a>'
4901: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4902: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4903: .')');
4904: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4905: $r->print(
4906: ' <a href="/adm/diff?filename='.
4907: &Apache::lonnet::clutter($root.'.'.$extension).
4908: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4909: '" target="diffs">'.&mt('Diffs').'</a>');
4910: }
4911: $r->print('</span><br />');
1.329 droeschl 4912: }
1.571 raeburn 4913: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4914: }
1.329 droeschl 4915: }
1.521 bisitz 4916: $r->print(
4917: &Apache::loncommon::end_data_table().
1.611 raeburn 4918: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4919: '</form>'
4920: );
1.329 droeschl 4921:
4922: &untiehash();
1.521 bisitz 4923: $r->print(&endContentScreen());
1.571 raeburn 4924: return;
1.329 droeschl 4925: }
4926:
4927: sub mark_hash_old {
4928: my $retie_hash=0;
4929: if ($hashtied) {
4930: $retie_hash=1;
4931: &untiehash();
4932: }
4933: &tiehash('write');
4934: $hash{'old'}=1;
4935: &untiehash();
4936: if ($retie_hash) { &tiehash(); }
4937: }
4938:
4939: sub is_hash_old {
4940: my $untie_hash=0;
4941: if (!$hashtied) {
4942: $untie_hash=1;
4943: &tiehash();
4944: }
4945: my $return=$hash{'old'};
4946: if ($untie_hash) { &untiehash(); }
4947: return $return;
4948: }
4949:
4950: sub changewarning {
4951: my ($r,$postexec,$message,$url)=@_;
4952: if (!&is_hash_old()) { return; }
4953: my $pathvar='folderpath';
4954: my $path=&escape($env{'form.folderpath'});
4955: if (!defined($url)) {
4956: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4957: }
4958: my $course_type = &Apache::loncommon::course_type();
4959: if (!defined($message)) {
4960: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4961: }
4962: $r->print("\n\n".
1.372 bisitz 4963: '<script type="text/javascript">'."\n".
4964: '// <![CDATA['."\n".
4965: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4966: '// ]]>'."\n".
1.369 bisitz 4967: '</script>'."\n".
1.375 tempelho 4968: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4969: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4970: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4971: &mt($message,' <input type="hidden" name="'.
4972: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4973: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4974: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4975: }
4976:
4977:
4978: sub init_breadcrumbs {
1.571 raeburn 4979: my ($form,$text,$help)=@_;
1.329 droeschl 4980: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4981: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4982: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4983: faq=>273,
4984: bug=>'Instructor Interface',
1.571 raeburn 4985: help => $help});
1.329 droeschl 4986: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4987: text=>$text,
4988: faq=>273,
4989: bug=>'Instructor Interface'});
4990: }
4991:
1.441 www 4992: # subroutine to list form elements
4993: sub create_list_elements {
4994: my @formarr = @_;
4995: my $list = '';
1.501 raeburn 4996: foreach my $button (@formarr){
4997: foreach my $picture (keys(%{$button})) {
4998: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4999: }
5000: }
5001: return $list;
5002: }
1.329 droeschl 5003:
1.441 www 5004: # subroutine to create ul from list elements
5005: sub create_form_ul {
5006: my $list = shift;
5007: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5008: return $ul;
5009: }
1.329 droeschl 5010:
1.442 www 5011: #
5012: # Start tabs
5013: #
5014:
5015: sub startContentScreen {
1.484 raeburn 5016: my ($mode) = @_;
5017: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5018: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5019: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5020: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5021: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5022: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5023: } else {
1.549 raeburn 5024: $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 5025: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5026: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5027: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5028: }
5029: $output .= "\n".'</ul>'."\n";
5030: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5031: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5032: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5033: return $output;
1.442 www 5034: }
5035:
5036: #
5037: # End tabs
5038: #
5039:
5040: sub endContentScreen {
1.484 raeburn 5041: return '</div></div></div>';
1.442 www 5042: }
1.329 droeschl 5043:
1.446 www 5044: sub supplemental_base {
1.548 raeburn 5045: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5046: }
5047:
1.329 droeschl 5048: sub handler {
5049: my $r = shift;
5050: &Apache::loncommon::content_type($r,'text/html');
5051: $r->send_http_header;
5052: return OK if $r->header_only;
1.484 raeburn 5053:
5054: # get course data
1.408 raeburn 5055: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5056: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5057: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5058:
1.606 raeburn 5059: # get docroot
5060: my $londocroot = $r->dir_config('lonDocRoot');
5061:
1.484 raeburn 5062: # graphics settings
5063: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5064:
1.443 www 5065: #
1.329 droeschl 5066: # --------------------------------------------- Initialize help topics for this
5067: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5068: 'Adding_External_Resource','Navigate_Content',
5069: 'Adding_Folders','Docs_Overview', 'Load_Map',
5070: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 5071: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.571 raeburn 5072: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
1.572 raeburn 5073: 'Dropbox','Simple_Problem') {
1.329 droeschl 5074: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5075: }
5076: # Composite help files
5077: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5078: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5079: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5080: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5081: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5082: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5083: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5084: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5085: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5086: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5087:
1.611 raeburn 5088: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5089: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5090: unless ($r->uri eq '/adm/supplemental') {
5091: # does this user have privileges to modify content.
1.611 raeburn 5092: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5093: $allowed = 1;
5094: $canedit = 1;
5095: $canview = 1;
5096: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5097: $allowed = 1;
5098: $canview = 1;
5099: }
5100: }
5101: unless ($canedit) {
5102: $disabled = ' disabled="disabled"';
1.472 raeburn 5103: }
1.582 raeburn 5104: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5105: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5106: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 5107: &verifycontent($r);
5108: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5109: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5110: &list_symbs($r);
5111: } elsif ($allowed && $env{'form.docslog'}) {
5112: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5113: my $folder = $env{'form.folder'};
5114: if ($folder eq '') {
5115: $folder='default';
5116: }
1.611 raeburn 5117: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5118: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5119: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5120: &checkversions($r,$canedit);
5121: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5122: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5123: &dumpcourse($r);
1.611 raeburn 5124: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5125: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5126: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5127: } else {
1.611 raeburn 5128: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5129: $noendpage = 1;
5130: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5131: if ($redirect) {
5132: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5133: my $container = 'sequence';
5134: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5135: $is_random_order,$container) =
5136: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5137: my (@folders)=split('&',$env{'form.folderpath'});
5138: $env{'form.foldername'}=&unescape(pop(@folders));
5139: my $folder=pop(@folders);
5140: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5141: $folder.'.'.$container);
5142: my $warning;
5143: if ($fatal) {
5144: if ($container eq 'page') {
5145: $warning = &mt('An error occurred retrieving the contents of the current page.');
5146: } else {
5147: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5148: }
5149: } else {
5150: my $url = $redirect;
5151: my $srcfile = $londocroot.$url;
5152: $url =~ s{^/priv/}{/res/};
5153: my $targetfile = $londocroot.$url;
5154: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5155: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5156: $env{'form.folder'} = $folder;
5157: &snapshotbefore();
5158: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5159: my $ext = 'false';
5160: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5161: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5162: ':'.$ext.':normal:res';
5163: push(@LONCAPA::map::order,$newidx);
5164: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5165: 'string_yesno');
5166: &remember_parms($newidx,'hiddenresource','set','yes');
5167: ($errtext,$fatal) =
5168: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5169: &log_differences($plain);
5170: &mark_hash_old();
5171: $r->internal_redirect($redirect);
5172: return OK;
5173: }
5174: }
5175: }
5176: }
1.445 www 5177: #
5178: # Done catching special calls
1.484 raeburn 5179: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5180: # Get the parameters that may be needed
5181: #
5182: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5183: ['folderpath',
5184: 'forcesupplement','forcestandard',
1.510 raeburn 5185: 'tools','symb','command','supppath']);
1.445 www 5186:
5187: # standard=1: this is a "new-style" course with an uploaded map as top level
5188: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5189:
5190: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5191:
1.484 raeburn 5192: # Decide whether this should display supplemental or main content or utilities
1.445 www 5193: # supplementalflag=1: show supplemental documents
5194: # supplementalflag=0: show standard documents
1.484 raeburn 5195: # toolsflag=1: show utilities
1.445 www 5196:
1.561 raeburn 5197: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5198: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5199: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5200: $supplementalflag=0;
5201: }
5202: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5203: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5204: unless ($allowed) { $supplementalflag=1; }
5205: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5206: my $toolsflag=0;
5207: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5208:
1.329 droeschl 5209: my $script='';
5210: my $showdoc=0;
1.457 raeburn 5211: my $addentries = {};
1.475 raeburn 5212: my $container;
1.329 droeschl 5213: my $containertag;
1.508 raeburn 5214: my $pathitem;
1.598 raeburn 5215: my %ltitools;
1.617 raeburn 5216: my $hiddentop;
1.615 raeburn 5217: my $navmap;
1.617 raeburn 5218: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5219:
1.464 www 5220: # Do we directly jump somewhere?
1.525 raeburn 5221: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5222: if ($env{'form.symb'} ne '') {
1.522 raeburn 5223: $env{'form.folderpath'}=
1.617 raeburn 5224: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5225: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5226: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5227: } elsif ($env{'form.supppath'} ne '') {
5228: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5229: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5230: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5231: }
1.472 raeburn 5232: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5233: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5234: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5235: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5236: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5237: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5238: } elsif ($env{'form.command'} eq 'contents') {
5239: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5240: } elsif ($env{'form.command'} eq 'home') {
5241: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5242: }
5243:
1.525 raeburn 5244:
1.445 www 5245: # Where do we store these for when we come back?
5246: my $stored_folderpath='docs_folderpath';
5247: if ($supplementalflag) {
5248: $stored_folderpath='docs_sup_folderpath';
5249: }
1.464 www 5250:
1.519 raeburn 5251: # No folderpath, and in edit mode, see if we have something stored
5252: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5253: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5254: {'folderpath' => 'scalar'});
1.615 raeburn 5255:
5256: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5257: if ($supplementalflag) {
5258: undef($env{'form.folderpath'}) if ($1 eq 'default');
5259: } else {
5260: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5261: }
5262: } else {
1.523 raeburn 5263: undef($env{'form.folderpath'});
5264: }
1.329 droeschl 5265: }
1.446 www 5266:
5267: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5268: if (!$allowed) {
1.446 www 5269: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5270: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5271: }
5272: }
1.446 www 5273: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5274: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5275: $env{'form.folderpath'} = &supplemental_base()
5276: .'&'.
1.329 droeschl 5277: $env{'form.folderpath'};
5278: }
1.615 raeburn 5279: # If allowed and user's role is not advanced check folderpath is not hidden
5280: if (($allowed) && (!$env{'request.role.adv'}) &&
5281: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5282: my $folderurl;
5283: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5284: my $folder = $pathitems[-2];
5285: if ($folder eq '') {
5286: undef($env{'form.folderpath'});
5287: } else {
5288: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5289: if ((split(/\:/,$pathitems[-1]))[4]) {
5290: $folderurl .= '.page';
5291: } else {
5292: $folderurl .= '.sequence';
5293: }
1.617 raeburn 5294: unless (ref($navmap)) {
5295: $navmap = Apache::lonnavmaps::navmap->new();
5296: }
1.615 raeburn 5297: if (ref($navmap)) {
5298: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5299: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5300: unless (@resources) {
5301: undef($env{'form.folderpath'});
5302: }
1.615 raeburn 5303: }
5304: }
5305: }
5306: }
5307:
5308:
1.446 www 5309: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5310: unless ($env{'form.folderpath'}) {
1.446 www 5311: if ($supplementalflag) {
5312: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5313: } elsif ($allowed) {
5314: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5315: }
1.472 raeburn 5316: }
1.446 www 5317:
1.445 www 5318: # Store this
1.484 raeburn 5319: unless ($toolsflag) {
1.615 raeburn 5320: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5321: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5322: {'folderpath' => 'scalar'});
1.510 raeburn 5323: }
1.519 raeburn 5324: my $folderpath;
1.484 raeburn 5325: if ($env{'form.folderpath'}) {
1.519 raeburn 5326: $folderpath = $env{'form.folderpath'};
5327: my (@folders)=split('&',$env{'form.folderpath'});
5328: $env{'form.foldername'}=&unescape(pop(@folders));
5329: if ($env{'form.foldername'} =~ /\:1$/) {
5330: $container = 'page';
5331: } else {
5332: $container = 'sequence';
5333: }
5334: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5335: } else {
1.519 raeburn 5336: if ($env{'form.folder'} eq '' ||
5337: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5338: if ($env{'form.folder'} eq 'supplemental') {
5339: $folderpath=&supplemental_base();
5340: } elsif (!$hiddentop) {
5341: $folderpath='default&'.
5342: &escape(&mt('Main Content').':::::');
5343: }
1.484 raeburn 5344: }
5345: }
1.519 raeburn 5346: $containertag = '<input type="hidden" name="folderpath" value="" />';
5347: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5348: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5349: $showdoc='/'.$1;
5350: }
5351: if ($showdoc) { # got called in sequence from course
5352: $allowed=0;
5353: } else {
1.611 raeburn 5354: if ($canedit) {
1.484 raeburn 5355: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5356: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5357: }
5358: }
1.329 droeschl 5359: }
5360:
1.344 bisitz 5361: # get personal data
1.329 droeschl 5362: my $uname=$env{'user.name'};
5363: my $udom=$env{'user.domain'};
5364: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5365:
5366: if ($allowed) {
1.484 raeburn 5367: if ($toolsflag) {
5368: $script .= &inject_data_js();
5369: my ($home,$other,%outhash)=&authorhosts();
5370: if (!$home && $other) {
5371: my @hosts;
5372: foreach my $aurole (keys(%outhash)) {
5373: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5374: push(@hosts,$outhash{$aurole});
5375: }
5376: }
5377: $script .= &dump_switchserver_js(@hosts);
5378: }
1.458 raeburn 5379: } else {
1.570 raeburn 5380: my $tid = 1;
1.484 raeburn 5381: my @tabids;
5382: if ($supplementalflag) {
5383: @tabids = ('002','ee2','ff2');
1.570 raeburn 5384: $tid = 2;
1.484 raeburn 5385: } else {
5386: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5387: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5388: unshift(@tabids,'001');
5389: push(@tabids,('dd1','ee1'));
5390: }
1.458 raeburn 5391: }
1.484 raeburn 5392: my $tabidstr = join("','",@tabids);
1.598 raeburn 5393: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5394: my $posslti = keys(%ltitools);
1.622 raeburn 5395: my $hostname = $r->hostname();
1.606 raeburn 5396: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5397: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5398: &history_tab_js().
5399: &inject_data_js().
1.570 raeburn 5400: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5401: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5402: $addentries = {
1.485 raeburn 5403: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5404: };
1.458 raeburn 5405: }
1.538 raeburn 5406: $script .= &paste_popup_js();
1.501 raeburn 5407: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5408: &mt('Switch server?');
5409:
5410:
1.329 droeschl 5411: }
5412: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5413: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5414: .'// <![CDATA['."\n"
5415: .$script."\n"
5416: .'// ]]>'."\n"
1.595 musolffc 5417: .'</script>'."\n"
5418: .'<script type="text/javascript"
5419: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5420:
5421: # Breadcrumbs
5422: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5423:
5424: if ($showdoc) {
5425: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5426: {'force_register' => $showdoc,}));
1.571 raeburn 5427: } elsif ($toolsflag) {
1.611 raeburn 5428: my ($breadtext,$breadtitle);
1.617 raeburn 5429: $breadtext = "$crstype Editor";
1.611 raeburn 5430: if ($canedit) {
5431: $breadtitle = 'Editing '.$crstype.' Contents';
5432: } else {
5433: $breadtext .= ' (View-only mode)';
5434: $breadtitle = 'Viewing '.$crstype.' Contents';
5435: }
1.571 raeburn 5436: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5437: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5438: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5439: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5440: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5441: $breadtitle)
1.571 raeburn 5442: );
1.510 raeburn 5443: } elsif ($r->uri eq '/adm/supplemental') {
5444: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5445: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5446: {'bread_crumbs' => $brcrum,}));
5447: } else {
1.611 raeburn 5448: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5449: $breadtext = "$crstype Editor";
1.611 raeburn 5450: if ($canedit) {
5451: $breadtitle = 'Editing '.$crstype.' Contents';
5452: $helpitem = 'Docs_Adding_Course_Doc';
5453: } else {
5454: $breadtext .= ' (View-only mode)';
5455: $breadtitle = 'Viewing '.$crstype.' Contents';
5456: $helpitem = 'Docs_Viewing_Course_Doc';
5457: }
1.392 raeburn 5458: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5459: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5460: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5461: {'add_entries' => $addentries}
5462: )
1.392 raeburn 5463: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5464: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5465: $breadtitle,
5466: $helpitem)
1.392 raeburn 5467: );
5468: }
1.364 bisitz 5469:
1.329 droeschl 5470: my %allfiles = ();
5471: my %codebase = ();
1.440 raeburn 5472: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5473: if ($canedit) {
1.329 droeschl 5474: if (($env{'form.uploaddoc.filename'}) &&
5475: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5476: my $context = $1;
5477: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5478: undef($hadchanges);
1.440 raeburn 5479: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5480: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5481: if ($hadchanges) {
5482: &mark_hash_old();
5483: }
1.440 raeburn 5484: $r->print($upload_output);
5485: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5486: # Process file upload - phase two - upload embedded objects
5487: $uploadphase = 'check_embedded';
5488: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5489: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5490: $env{'form.newidx'});
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();
5494: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5495: my $actionurl = '/adm/coursedocs';
5496: my ($result,$flag) =
5497: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5498: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5499: $actionurl);
5500: $r->print($result.&return_to_editor());
5501: } elsif ($env{'form.phase'} eq 'check_embedded') {
5502: # Process file upload - phase three - modify references in HTML file
5503: $uploadphase = 'modified_orightml';
5504: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5505: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5506: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5507: my $result =
5508: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5509: $docuname,$docudom,undef,
5510: $dir_root);
5511: $r->print($result.&return_to_editor());
1.476 raeburn 5512: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5513: $uploadphase = 'decompress_phase_one';
5514: $r->print(&decompression_phase_one().
5515: &return_to_editor());
5516: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5517: $uploadphase = 'decompress_phase_two';
5518: $r->print(&decompression_phase_two().
5519: &return_to_editor());
1.329 droeschl 5520: }
5521: }
5522:
1.484 raeburn 5523: if ($allowed && $toolsflag) {
5524: $r->print(&startContentScreen('tools'));
1.611 raeburn 5525: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5526: $r->print(&endContentScreen());
5527: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5528: # -----------------------------------------------------------------------------
5529: my %lt=&Apache::lonlocal::texthash(
5530: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5531: 'upfi' => 'Upload File',
1.553 raeburn 5532: 'upld' => 'Upload Content',
1.329 droeschl 5533: 'srch' => 'Search',
5534: 'impo' => 'Import',
1.487 raeburn 5535: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5536: 'impm' => 'Import from Assembled Map',
1.606 raeburn 5537: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5538: 'extr' => 'External Resource',
5539: 'extt' => 'External Tool',
1.329 droeschl 5540: 'selm' => 'Select Map',
5541: 'load' => 'Load Map',
5542: 'newf' => 'New Folder',
5543: 'newp' => 'New Composite Page',
5544: 'syll' => 'Syllabus',
1.425 raeburn 5545: 'navc' => 'Table of Contents',
1.343 biermanm 5546: 'sipa' => 'Simple Course Page',
1.329 droeschl 5547: 'sipr' => 'Simple Problem',
1.534 raeburn 5548: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5549: 'stpr' => 'Standard Problem',
5550: 'news' => 'New sub-directory',
5551: 'crpr' => 'Create Problem',
1.329 droeschl 5552: 'drbx' => 'Drop Box',
1.451 www 5553: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5554: 'bull' => 'Discussion Board',
1.347 weissno 5555: 'mypi' => 'My Personal Information Page',
1.353 weissno 5556: 'grpo' => 'Group Portfolio',
1.329 droeschl 5557: 'rost' => 'Course Roster',
1.528 raeburn 5558: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5559: 'imsf' => 'IMS Upload',
5560: 'imsl' => 'Upload IMS package',
1.501 raeburn 5561: 'cms' => 'Origin of IMS package',
5562: 'se' => 'Select',
1.329 droeschl 5563: 'file' => 'File',
5564: 'title' => 'Title',
1.606 raeburn 5565: 'addp' => 'Add Placeholder to course?',
5566: 'uste' => 'Use Template?',
5567: 'fnam' => 'File Name:',
5568: 'loca' => 'Location:',
5569: 'dire' => 'Directory:',
5570: 'cate' => 'Category:',
5571: 'tmpl' => 'Template:',
1.329 droeschl 5572: 'comment' => 'Comment',
1.403 raeburn 5573: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5574: 'bb5' => 'Blackboard 5',
5575: 'bb6' => 'Blackboard 6',
5576: 'angel5' => 'ANGEL 5.5',
5577: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5578: 'yes' => 'Yes',
5579: 'no' => 'No',
1.618 raeburn 5580: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5581: );
1.329 droeschl 5582: # -----------------------------------------------------------------------------
1.595 musolffc 5583:
5584: # Calculate free quota space for a user or course. A javascript function checks
5585: # file size to determine if upload should be allowed.
5586: my $quotatype = 'unofficial';
5587: if ($crstype eq 'Community') {
1.601 raeburn 5588: $quotatype = 'community';
5589: } elsif ($crstype eq 'Placement') {
5590: $quotatype = 'placement';
1.595 musolffc 5591: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5592: $quotatype = 'official';
5593: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5594: $quotatype = 'textbook';
5595: }
5596: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5597: 'course',$quotatype); # expressed in MB
5598: my $current_disk_usage = 0;
5599: foreach my $subdir ('docs','supplemental') {
5600: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5601: "userfiles/$subdir",1); # expressed in kB
5602: }
5603: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5604: my $usage = $current_disk_usage/1024; # in MB
5605: my $quota = $disk_quota;
5606: my $percent;
5607: if ($disk_quota == 0) {
5608: $percent = 100.0;
5609: } else {
1.619 raeburn 5610: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5611: }
5612: $usage = sprintf("%.2f",$usage);
5613: $quota = sprintf("%.2f",$quota);
5614: $percent = sprintf("%.0f",$percent);
5615: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5616: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5617:
1.329 droeschl 5618: my $fileupload=(<<FIUP);
1.605 raeburn 5619: $quotainfo
1.329 droeschl 5620: $lt{'file'}:<br />
1.611 raeburn 5621: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5622: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5623: FIUP
5624:
5625: my $checkbox=(<<CHBO);
5626: <!-- <label>$lt{'parse'}?
5627: <input type="checkbox" name="parserflag" />
5628: </label> -->
5629: <label>
1.611 raeburn 5630: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5631: </label>
5632: CHBO
1.501 raeburn 5633: my $imsfolder = $env{'form.folder'};
5634: if ($imsfolder eq '') {
5635: $imsfolder = 'default';
5636: }
5637: my $imspform=(<<IMSFORM);
5638: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5639: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5640: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5641: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5642: <legend>$lt{'imsf'}</legend>
5643: $fileupload
5644: <br />
5645: <p>
5646: $lt{'cms'}:
1.611 raeburn 5647: <select name="source" $disabled>
1.501 raeburn 5648: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5649: <option value="bb5">$lt{'bb5'}</option>
5650: <option value="bb6">$lt{'bb6'}</option>
5651: <option value="angel5">$lt{'angel5'}</option>
5652: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5653: </select>
5654: <input type="hidden" name="folder" value="$imsfolder" />
5655: </p>
5656: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5657: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5658: </fieldset>
5659: </form>
5660: IMSFORM
1.329 droeschl 5661:
5662: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5663: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5664: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5665: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5666: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5667: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5668: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5669: $fileupload
1.329 droeschl 5670: <br />
5671: $lt{'title'}:<br />
1.611 raeburn 5672: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5673: $pathitem
1.329 droeschl 5674: <input type="hidden" name="cmd" value="upload_default" />
5675: <br />
1.458 raeburn 5676: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5677: $checkbox
5678: </span>
1.501 raeburn 5679: <br clear="all" />
1.611 raeburn 5680: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5681: </fieldset>
5682: </form>
1.383 tempelho 5683: FUFORM
1.329 droeschl 5684:
1.611 raeburn 5685: my $mapimportjs;
5686: if ($canedit) {
5687: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5688: } else {
5689: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5690: }
1.502 raeburn 5691: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5692: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5693: $lt{'impm'}</a>$help{'Load_Map'}
5694: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5695: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5696: <legend>$lt{'impm'}</legend>
1.371 tempelho 5697: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5698: $lt{'copm'}<br />
5699: <span class="LC_nobreak">
5700: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5701: onfocus="this.blur();$mapimportjs" $disabled />
5702: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5703: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5704: </fieldset>
5705: </form>
5706:
1.383 tempelho 5707: SEDFFORM
1.606 raeburn 5708: my $importcrsresform;
1.608 raeburn 5709: my ($numdirs,$pickfile) =
5710: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5711: "resize_scrollbox('contentscroll','1','0');",
5712: undef,'res');
1.606 raeburn 5713: if ($pickfile) {
5714: $importcrsresform=(<<CRSFORM);
5715: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5716: $lt{'imcr'}</a>$help{'Course_Resources'}
5717: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5718: <fieldset id="importcrsresform" style="display: none;">
5719: <legend>$lt{'imcr'}</legend>
5720: <input type="hidden" name="active" value="bb" />
5721: $pickfile
5722: <p>
1.611 raeburn 5723: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5724: </p>
5725: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5726: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5727: </fieldset>
5728: </form>
5729: CRSFORM
5730: }
5731:
1.611 raeburn 5732: my $fromstoredjs;
5733: if ($canedit) {
5734: $fromstoredjs = 'open_StoredLinks_Import()';
5735: } else {
5736: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5737: }
5738:
1.502 raeburn 5739: my @importpubforma = (
1.508 raeburn 5740: { '<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 5741: { '<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 5742: { '<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 5743: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5744: );
5745: if ($pickfile) {
5746: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5747: }
1.502 raeburn 5748: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5749: my $extresourcesform =
5750: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5751: $help{'Adding_External_Resource'},
5752: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5753: my $exttoolform =
5754: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5755: $help{'Adding_External_Tool'},undef,
5756: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5757: \%ltitools,$disabled);
1.329 droeschl 5758: if ($allowed) {
1.492 raeburn 5759: my $folder = $env{'form.folder'};
5760: if ($folder eq '') {
5761: $folder='default';
5762: }
1.615 raeburn 5763: if ($canedit) {
5764: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5765: if ($output) {
5766: $r->print($output);
5767: }
1.538 raeburn 5768: }
1.337 ehlerst 5769: $r->print(<<HIDDENFORM);
5770: <form name="renameform" method="post" action="/adm/coursedocs">
5771: <input type="hidden" name="title" />
5772: <input type="hidden" name="cmd" />
5773: <input type="hidden" name="markcopy" />
5774: <input type="hidden" name="copyfolder" />
5775: $containertag
5776: </form>
1.484 raeburn 5777:
1.337 ehlerst 5778: HIDDENFORM
1.508 raeburn 5779: $r->print(&makesimpleeditform($pathitem)."\n".
5780: &makedocslogform($pathitem."\n".
1.484 raeburn 5781: '<input type="hidden" name="folder" value="'.
5782: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5783: }
1.442 www 5784:
5785: # Generate the tabs
1.510 raeburn 5786: my ($mode,$needs_end);
1.472 raeburn 5787: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5788: my @folders = split('&',$env{'form.folderpath'});
5789: unless (@folders > 2) {
5790: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5791: $needs_end = 1;
5792: }
1.472 raeburn 5793: } else {
1.484 raeburn 5794: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5795: $needs_end = 1;
1.472 raeburn 5796: }
1.443 www 5797:
1.442 www 5798: #
1.622 raeburn 5799: my $hostname = $r->hostname();
1.442 www 5800: my $savefolderpath;
5801:
1.395 raeburn 5802: if ($allowed) {
1.329 droeschl 5803: my $folder=$env{'form.folder'};
1.615 raeburn 5804: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5805: $folder='default';
1.356 tempelho 5806: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5807: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5808: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5809: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5810: }
5811: my $postexec='';
5812: if ($folder eq 'default') {
1.372 bisitz 5813: $r->print('<script type="text/javascript">'."\n"
5814: .'// <![CDATA['."\n"
5815: .'this.window.name="loncapaclient";'."\n"
5816: .'// ]]>'."\n"
5817: .'</script>'."\n"
1.369 bisitz 5818: );
1.329 droeschl 5819: } else {
5820: #$postexec='self.close();';
5821: }
1.504 raeburn 5822: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5823: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5824: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5825:
5826: my $newnavform=(<<NNFORM);
5827: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5828: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5829: $pathitem
1.329 droeschl 5830: <input type="hidden" name="importdetail"
5831: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 5832: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5833: $help{'Navigate_Content'}
5834: </form>
5835: NNFORM
5836: my $newsmppageform=(<<NSPFORM);
5837: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5838: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5839: $pathitem
1.329 droeschl 5840: <input type="hidden" name="importdetail" value="" />
1.423 onken 5841: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5842: $help{'Simple Page'}
1.329 droeschl 5843: </form>
5844: NSPFORM
5845:
5846: my $newsmpproblemform=(<<NSPROBFORM);
5847: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5848: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5849: $pathitem
1.329 droeschl 5850: <input type="hidden" name="importdetail" value="" />
1.423 onken 5851: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5852: $help{'Simple_Problem'}
1.329 droeschl 5853: </form>
5854:
5855: NSPROBFORM
5856:
5857: my $newdropboxform=(<<NDBFORM);
5858: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5859: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5860: $pathitem
1.329 droeschl 5861: <input type="hidden" name="importdetail" value="" />
1.423 onken 5862: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5863: $help{'Dropbox'}
1.344 bisitz 5864: </form>
1.329 droeschl 5865: NDBFORM
5866:
5867: my $newexuploadform=(<<NEXUFORM);
5868: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5869: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5870: $pathitem
1.329 droeschl 5871: <input type="hidden" name="importdetail" value="" />
1.423 onken 5872: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5873: $help{'Score_Upload_Form'}
5874: </form>
5875: NEXUFORM
5876:
5877: my $newbulform=(<<NBFORM);
5878: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5879: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5880: $pathitem
1.329 droeschl 5881: <input type="hidden" name="importdetail" value="" />
1.423 onken 5882: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5883: $help{'Bulletin Board'}
5884: </form>
5885: NBFORM
5886:
5887: my $newaboutmeform=(<<NAMFORM);
5888: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5889: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5890: $pathitem
1.329 droeschl 5891: <input type="hidden" name="importdetail"
5892: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 5893: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5894: $help{'My Personal Information Page'}
1.329 droeschl 5895: </form>
5896: NAMFORM
5897:
5898: my $newaboutsomeoneform=(<<NASOFORM);
5899: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5900: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5901: $pathitem
1.329 droeschl 5902: <input type="hidden" name="importdetail" value="" />
1.423 onken 5903: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5904: </form>
5905: NASOFORM
5906:
5907: my $newrosterform=(<<NROSTFORM);
5908: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5909: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5910: $pathitem
1.329 droeschl 5911: <input type="hidden" name="importdetail"
5912: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 5913: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 5914: $help{'Course_Roster'}
1.329 droeschl 5915: </form>
5916: NROSTFORM
5917:
1.534 raeburn 5918: my $newwebpage;
5919: if ($folder =~ /^default_?(\d*)$/) {
5920: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5921: if ($1) {
5922: $newwebpage .= $1;
5923: } else {
5924: $newwebpage .= 'default';
5925: }
5926: $newwebpage .= '/new.html';
5927: }
5928: my $newwebpageform =(<<NWEBFORM);
5929: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5930: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5931: $pathitem
5932: <input type="hidden" name="importdetail" value="$newwebpage" />
5933: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5934: $help{'Web_Page'}
1.534 raeburn 5935: </form>
5936: NWEBFORM
1.604 raeburn 5937:
1.606 raeburn 5938: my @ids=&Apache::lonnet::current_machine_ids();
5939: my %select_menus;
5940: my $numauthor = 0;
5941: my $numcrsdirs = 0;
5942: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5943: if ($env{'user.author'}) {
5944: $numauthor ++;
5945: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5946: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5947: my $is_home = 1;
5948: my %subdirs;
1.608 raeburn 5949: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5950: $select_menus{'author'}->{'default'} = '/';
5951: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5952: my @ordered = ('/');
5953: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5954: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5955: push(@ordered,$relpath);
5956: }
5957: $select_menus{'author'}->{'order'} = \@ordered;
5958: } else {
5959: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5960: $select_menus{'author'}->{'default'} = 'switch';
5961: $select_menus{'author'}->{'order'} = ['switch'];
5962: }
5963: }
5964: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5965: ['active'],['ca','aa']);
5966: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5967: my %by_roletype;
5968: if (keys(%roleshash)) {
5969: foreach my $entry (keys(%roleshash)) {
5970: my ($auname,$audom,$roletype) = split(/:/,$entry);
5971: my $key = $entry;
5972: $key =~ s/:/___/g;
5973: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5974: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5975: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5976: if (grep(/^\Q$rolehome\E$/,@ids)) {
5977: my $is_home = 1;
5978: my (%subdirs,@ordered);
5979: my $toppath="/priv/$audom/$auname";
1.608 raeburn 5980: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5981: $select_menus{$key}->{'default'} = '/';
5982: $select_menus{$key}->{'select2'}->{'/'} = '/';
5983: my @ordered = ('/');
5984: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5985: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
5986: push(@ordered,$relpath);
5987: }
5988: $select_menus{$key}->{'order'} = \@ordered;
5989: } else {
5990: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
5991: $select_menus{$key}->{'default'} = 'switch';
5992: $select_menus{$key}->{'order'} = ['switch'];
5993: }
5994: $numauthor ++;
5995: }
5996: }
5997: my ($pickdir,$showtitle);;
5998: if ($numauthor) {
5999: my @order;
6000: my $defrole;
6001: if ($env{'user.author'}) {
6002: push(@order,'author');
6003: $defrole = 'author';
6004: }
6005: if (keys(%by_roletype)) {
6006: foreach my $possrole ('ca','aa') {
6007: if (ref($by_roletype{$possrole}) eq 'HASH') {
6008: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6009: unless ($defrole) {
6010: $defrole = $author;
6011: }
6012: push(@order,$author.'___'.$possrole);
6013: }
6014: }
6015: }
6016: }
6017: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6018: if (grep(/^\Q$crshome\E$/,@ids)) {
6019: my $is_home = 1;
6020: my %subdirs;
6021: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6022: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6023: $numcrsdirs = keys(%subdirs);
6024: $select_menus{'course'}->{'default'} = '/';
6025: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6026: my @ordered = ('/');
6027: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6028: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6029: push(@ordered,$relpath);
6030: }
6031: $select_menus{'course'}->{'order'} = \@ordered;
6032: } else {
6033: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6034: $select_menus{'course'}->{'default'} = 'switch';
6035: $select_menus{'course'}->{'order'} = ['switch'];
6036: }
6037: push(@order,'course');
6038: $pickdir = $lt{'loca'}.
6039: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6040: $defrole,'authorrole','authorpath',
6041: \%select_menus,\@order,'toggleCrsResTitle();',
6042: '','priv').'<br />';
6043: $showtitle = 'none';
6044: } else {
6045: my $is_home;
6046: $showtitle = 'inline';
6047: if (grep(/^\Q$crshome\E$/,@ids)) {
6048: $is_home = 1;
6049: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6050: my $toppath="/priv/$coursedom/$coursenum'}";
6051: my %subdirs;
1.608 raeburn 6052: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6053: $numcrsdirs = keys(%subdirs);
6054: if ($numcrsdirs) {
6055: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6056: '<option value="/">/</option>'."\n";
6057: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6058: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6059: }
6060: $pickdir .= '</select>';
6061: } else {
6062: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6063: }
6064: }
6065: }
6066:
6067: my %seltemplate_menus;
6068: my @files = &Apache::lonhomework::get_template_list('problem');
6069: my @noexamplelink = ('blank.problem','blank.library','script.library');
6070: my $currentcategory = '';
6071: my @ordered = ('');
6072: my %templatehelp;
6073: my $defcategory = '';
6074: my @catorder = ($defcategory);
6075: $seltemplate_menus{$defcategory}->{'order'} = [''];
6076: $seltemplate_menus{$defcategory}->{'text'} = '';
6077: foreach my $file (@files) {
6078: if (ref($file) eq 'ARRAY') {
6079: my ($path,$title,$category,$help) = @{$file};
6080: next if ($title !~ /\S/);
6081: if (&js_escape($category) ne $currentcategory) {
6082: $currentcategory = &js_escape($category);
6083: push(@catorder,&js_escape($currentcategory));
6084: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6085: $seltemplate_menus{$currentcategory}->{'default'} = '';
6086: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6087: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6088: }
6089: if ($path) {
6090: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6091: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6092: if ($help) {
6093: $templatehelp{$path} = $help;
6094: }
6095: }
6096: }
6097: }
6098:
6099: my $templates = $lt{'cate'}.' '.
6100: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6101: $defcategory,'tempcategory','template',
6102: \%seltemplate_menus,\@catorder,
6103: "resize_scrollbox('contentscroll','1','0');",
6104: "toggleExampleText();",'template').'<br />';
6105: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6106: '<span id="newresexample">'.&mt('Example').'<span></a>';
6107: my $crsresform=(<<RESFORM);
6108: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6109: $lt{'stpr'}</a>$help{'Course_Resource'}
6110: <form action="/adm/coursedocs" method="post" name="courseresform">
6111: <fieldset id="crsresform" style="display:none;">
6112: <legend>$lt{'stpr'}</legend>
6113: <input type="hidden" name="active" value="ee" />
6114: <p>
6115: $pickdir
6116: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6117: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6118:
1.611 raeburn 6119: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6120: </span><span id="newsubdir"></span>
6121: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6122: </p>
6123: $lt{'fnam'}
1.611 raeburn 6124: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6125: <p>
6126: <div id="newresource" style="display:$showtitle">
6127: $lt{'addp'}
1.611 raeburn 6128: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6129: $lt{'no'}</label>
1.611 raeburn 6130: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6131: $lt{'yes'}</label>
6132: <span id="newrestitle"></span>
1.611 raeburn 6133: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6134: </div>
6135: </p>
6136: <p>
6137: $lt{'uste'}
1.611 raeburn 6138: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6139: $lt{'no'}</label>
1.611 raeburn 6140: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6141: $lt{'yes'}</label>
6142: <div id="newrestemplate" style="display:none">
6143: $templates
6144: $templatepreview
6145: </div>
6146: </p>
6147: <span class="LC_nobreak">
6148: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6149: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6150: </span>
6151: </fieldset>
6152: </form>
6153:
6154: RESFORM
1.534 raeburn 6155:
1.342 ehlerst 6156: my $specialdocumentsform;
1.383 tempelho 6157: my @specialdocumentsforma;
1.451 www 6158: my $gradingform;
6159: my @gradingforma;
6160: my $communityform;
6161: my @communityforma;
1.351 ehlerst 6162: my $newfolderform;
1.390 tempelho 6163: my $newfolderb;
1.342 ehlerst 6164:
1.451 www 6165: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6166:
1.329 droeschl 6167: my $newpageform=(<<NPFORM);
6168: <form action="/adm/coursedocs" method="post" name="newpage">
6169: <input type="hidden" name="folderpath" value="$path" />
6170: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6171: <input type="hidden" name="active" value="ee" />
1.423 onken 6172: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6173: $help{'Adding_Pages'}
1.329 droeschl 6174: </form>
6175: NPFORM
1.390 tempelho 6176:
6177:
1.351 ehlerst 6178: $newfolderform=(<<NFFORM);
1.329 droeschl 6179: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6180: $pathitem
1.329 droeschl 6181: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6182: <input type="hidden" name="active" value="" />
1.422 onken 6183: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6184: </form>
6185: NFFORM
6186:
6187: my $newsylform=(<<NSYLFORM);
6188: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6189: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6190: $pathitem
1.329 droeschl 6191: <input type="hidden" name="importdetail"
6192: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6193: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6194: $help{'Syllabus'}
1.383 tempelho 6195:
1.329 droeschl 6196: </form>
6197: NSYLFORM
1.364 bisitz 6198:
1.329 droeschl 6199: my $newgroupfileform=(<<NGFFORM);
6200: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6201: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6202: $pathitem
1.329 droeschl 6203: <input type="hidden" name="importdetail"
6204: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6205: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6206: $help{'Group Portfolio'}
1.329 droeschl 6207: </form>
6208: NGFFORM
1.383 tempelho 6209: @specialdocumentsforma=(
1.421 onken 6210: {'<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 6211: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6212: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6213: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6214: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6215: );
6216: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6217:
1.434 raeburn 6218:
6219: my @importdoc = (
1.519 raeburn 6220: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6221: );
1.598 raeburn 6222: if (keys(%ltitools)) {
6223: push(@importdoc,
6224: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6225: );
6226: }
1.519 raeburn 6227: unless ($container eq 'page') {
6228: push(@importdoc,
6229: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6230: );
6231: }
6232: push(@importdoc,
1.558 raeburn 6233: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6234: );
1.501 raeburn 6235: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6236:
1.451 www 6237: @gradingforma=(
6238: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6239: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6240: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6241: {'<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 6242: );
6243: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6244:
6245: @communityforma=(
6246: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6247: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6248: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6249: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6250: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6251: );
6252: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6253:
1.330 tempelho 6254: my %orderhash = (
1.553 raeburn 6255: 'aa' => ['Upload',$fileuploadform],
6256: 'bb' => ['Import',$importpubform],
6257: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6258: );
1.519 raeburn 6259: unless ($container eq 'page') {
1.434 raeburn 6260: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6261: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6262: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6263: }
6264:
1.341 ehlerst 6265: $hadchanges=0;
1.484 raeburn 6266: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6267: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6268: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6269: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6270: undef($navmap);
1.443 www 6271: if ($error) {
6272: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6273: }
6274: if ($hadchanges) {
6275: &mark_hash_old();
6276: }
1.341 ehlerst 6277:
1.443 www 6278: &changewarning($r,'');
6279: }
1.458 raeburn 6280: }
1.442 www 6281:
1.443 www 6282: # Supplemental documents start here
6283:
1.329 droeschl 6284: my $folder=$env{'form.folder'};
1.443 www 6285: unless ($supplementalflag) {
1.329 droeschl 6286: $folder='supplemental';
6287: }
6288: if ($folder =~ /^supplemental$/ &&
6289: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6290: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6291: } elsif ($allowed) {
1.356 tempelho 6292: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6293: }
1.508 raeburn 6294: $pathitem = '<input type="hidden" name="folderpath" value="'.
6295: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6296: if ($allowed) {
6297: my $folderseq=
1.504 raeburn 6298: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6299:
6300: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6301: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6302: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6303: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6304: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6305: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6306: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6307: $fileupload
6308: <br />
6309: <br />
6310: <span class="LC_nobreak">
6311: $checkbox
6312: </span>
6313: <br /><br />
6314: $lt{'comment'}:<br />
1.383 tempelho 6315: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6316: <br />
1.508 raeburn 6317: $pathitem
1.329 droeschl 6318: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6319: <input type='submit' value="$lt{'upld'}" />
6320: </form>
1.329 droeschl 6321: SUPDOCFORM
6322:
6323: my $supnewfolderform=(<<SNFFORM);
6324: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6325: <input type="hidden" name="active" value="" />
1.508 raeburn 6326: $pathitem
1.329 droeschl 6327: <input type="hidden" name="importdetail" value="" />
1.423 onken 6328: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6329: $help{'Adding_Folders'}
1.329 droeschl 6330: </form>
6331: SNFFORM
1.383 tempelho 6332:
1.510 raeburn 6333: my $supextform =
6334: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6335: $help{'Adding_External_Resource'},
6336: undef,undef,undef,undef,undef,undef,
6337: $disabled);
1.329 droeschl 6338:
1.598 raeburn 6339: my $supexttoolform =
6340: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6341: $help{'Adding_External_Tool'},
6342: undef,undef,'tool',$coursedom,
1.611 raeburn 6343: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6344:
1.329 droeschl 6345: my $supnewsylform=(<<SNSFORM);
6346: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6347: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6348: $pathitem
1.329 droeschl 6349: <input type="hidden" name="importdetail"
6350: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6351: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6352: $help{'Syllabus'}
6353: </form>
6354: SNSFORM
6355:
6356: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6357: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6358: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6359: $pathitem
1.329 droeschl 6360: <input type="hidden" name="importdetail"
6361: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6362: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6363: $help{'My Personal Information Page'}
1.329 droeschl 6364: </form>
6365: SNAMFORM
6366:
1.534 raeburn 6367: my $supwebpage;
6368: if ($folder =~ /^supplemental_?(\d*)$/) {
6369: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6370: if ($1) {
6371: $supwebpage .= $1;
6372: } else {
6373: $supwebpage .= 'default';
6374: }
6375: $supwebpage .= '/new.html';
6376: }
6377: my $supwebpageform =(<<SWEBFORM);
6378: <form action="/adm/coursedocs" method="post" name="supwebpage">
6379: <input type="hidden" name="active" value="cc" />
6380: $pathitem
6381: <input type="hidden" name="importdetail" value="$supwebpage" />
6382: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6383: $help{'Web_Page'}
1.534 raeburn 6384: </form>
6385: SWEBFORM
6386:
1.333 muellerd 6387:
1.383 tempelho 6388: my @specialdocs = (
1.618 raeburn 6389: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6390: =>$supnewsylform},
1.611 raeburn 6391: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6392: =>$supnewaboutmeform},
1.534 raeburn 6393: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6394:
1.383 tempelho 6395: );
1.417 droeschl 6396: my @supimportdoc = (
1.515 raeburn 6397: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6398: =>$supextform});
6399: if (keys(%ltitools)) {
6400: push(@supimportdoc,
6401: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6402: =>$supexttoolform});
6403: }
6404: push(@supimportdoc,
6405: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6406: =>$supupdocform},
1.598 raeburn 6407: );
1.501 raeburn 6408:
6409: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6410: my %suporderhash = (
1.390 tempelho 6411: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6412: 'ee' => ['Upload',$supupdocform],
6413: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6414: );
1.443 www 6415: if ($supplementalflag) {
1.458 raeburn 6416: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6417: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6418: \%ltitools,$canedit,$hostname);
1.443 www 6419: if ($error) {
6420: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6421: } else {
6422: if ($suppchanges) {
6423: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6424: my @ids=&Apache::lonnet::current_machine_ids();
6425: foreach my $server (keys(%servers)) {
6426: next if (grep(/^\Q$server\E$/,@ids));
6427: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6428: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6429: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6430: }
6431: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6432: undef($suppchanges);
6433: }
6434: }
1.393 raeburn 6435: }
1.443 www 6436: } elsif ($supplementalflag) {
1.458 raeburn 6437: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6438: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6439: if ($error) {
6440: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6441: }
1.393 raeburn 6442: }
1.389 tempelho 6443:
1.510 raeburn 6444: if ($needs_end) {
6445: $r->print(&endContentScreen());
6446: }
1.383 tempelho 6447:
1.329 droeschl 6448: if ($allowed) {
6449: $r->print('
6450: <form method="post" name="extimport" action="/adm/coursedocs">
6451: <input type="hidden" name="title" />
6452: <input type="hidden" name="url" />
6453: <input type="hidden" name="useform" />
6454: <input type="hidden" name="residx" />
6455: </form>');
6456: }
1.484 raeburn 6457: } elsif ($showdoc) {
1.329 droeschl 6458: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6459: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6460: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6461: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6462: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6463: }
6464: }
1.606 raeburn 6465: unless ($noendpage) {
6466: $r->print(&Apache::loncommon::end_page());
6467: }
1.329 droeschl 6468: return OK;
1.364 bisitz 6469: }
1.329 droeschl 6470:
1.440 raeburn 6471: sub embedded_form_elems {
6472: my ($phase,$primaryurl,$newidx) = @_;
6473: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6474: return <<STATE;
6475: <input type="hidden" name="folderpath" value="$folderpath" />
6476: <input type="hidden" name="cmd" value="upload_embedded" />
6477: <input type="hidden" name="newidx" value="$newidx" />
6478: <input type="hidden" name="phase" value="$phase" />
6479: <input type="hidden" name="primaryurl" value="$primaryurl" />
6480: STATE
6481: }
6482:
6483: sub embedded_destination {
6484: my $folder=$env{'form.folder'};
6485: my $destination = 'docs/';
6486: if ($folder =~ /^supplemental/) {
6487: $destination = 'supplemental/';
6488: }
6489: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6490: $destination .= 'default/';
6491: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6492: $destination .= $2.'/';
6493: }
6494: $destination .= $env{'form.newidx'};
6495: my $dir_root = '/userfiles';
6496: return ($destination,$dir_root);
6497: }
6498:
6499: sub return_to_editor {
6500: my $actionurl = '/adm/coursedocs';
6501: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6502: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6503: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6504: '</a></p>';
6505: }
6506:
1.476 raeburn 6507: sub decompression_info {
6508: my ($destination,$dir_root) = &embedded_destination();
6509: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6510: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6511: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6512: my $container='sequence';
1.480 raeburn 6513: my ($pathitem,$hiddenelem);
1.583 raeburn 6514: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6515: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6516: $container='page';
6517: }
1.480 raeburn 6518: unshift(@hiddens,$pathitem);
6519: foreach my $item (@hiddens) {
6520: if ($env{'form.'.$item}) {
6521: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6522: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6523: }
1.477 raeburn 6524: }
1.476 raeburn 6525: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6526: $hiddenelem);
6527: }
6528:
6529: sub decompression_phase_one {
6530: my ($dir,$file,$warning,$error,$output);
6531: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6532: &decompression_info();
1.490 raeburn 6533: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6534: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6535: } else {
6536: my $file = $1;
1.481 raeburn 6537: $output =
6538: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6539: $destination,$dir_root,
6540: $hiddenelem);
6541: if ($env{'form.autoextract_camtasia'}) {
6542: $output .= &remove_archive($docudom,$docuname,$container);
6543: }
1.476 raeburn 6544: }
6545: if ($error) {
6546: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6547: $error.'</p>'."\n";
6548: }
6549: if ($warning) {
6550: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6551: }
6552: return $output;
6553: }
6554:
6555: sub decompression_phase_two {
6556: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6557: &decompression_info();
1.481 raeburn 6558: my $output;
1.480 raeburn 6559: if ($env{'form.archivedelete'}) {
1.481 raeburn 6560: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6561: }
6562: $output .=
1.481 raeburn 6563: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6564: $destination,$dir_root,$hiddenelem);
6565: return $output;
6566: }
6567:
1.480 raeburn 6568: sub remove_archive {
6569: my ($docudom,$docuname,$container) = @_;
6570: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6571: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6572: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6573: if ($fatal) {
6574: if ($container eq 'page') {
6575: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6576: } else {
6577: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6578: }
1.583 raeburn 6579: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6580: } else {
6581: my $currcmd = $env{'form.cmd'};
6582: my $position = $env{'form.position'};
1.583 raeburn 6583: my $archiveidx = $position;
1.563 raeburn 6584: if ($position > 0) {
1.583 raeburn 6585: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6586: $archiveidx = $position-1;
6587: }
6588: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6589: my ($title,$url,@rrest) =
1.583 raeburn 6590: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6591: if ($url eq $env{'form.archiveurl'}) {
6592: if (&handle_edit_cmd($docuname,$docudom)) {
6593: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6594: if ($fatal) {
6595: if ($container eq 'page') {
6596: $delwarning = &mt('An error occurred updating the contents of the current page.');
6597: } else {
6598: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6599: }
1.480 raeburn 6600: } else {
1.583 raeburn 6601: $delresult = &mt('Archive file removed.');
1.480 raeburn 6602: }
6603: }
1.583 raeburn 6604: } else {
6605: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6606: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6607: }
6608: }
6609: $env{'form.cmd'} = $currcmd;
6610: }
6611: if ($delwarning) {
6612: $output = '<p class="LC_warning">'.
6613: $delwarning.
6614: '</p>';
6615: }
6616: if ($delresult) {
6617: $output .= '<p class="LC_info">'.
6618: $delresult.
6619: '</p>';
6620: }
1.481 raeburn 6621: return $output;
1.480 raeburn 6622: }
6623:
1.484 raeburn 6624: sub generate_admin_menu {
1.611 raeburn 6625: my ($crstype,$canedit) = @_;
1.484 raeburn 6626: my $lc_crstype = lc($crstype);
6627: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6628: my %lt= ( # do not translate here
1.484 raeburn 6629: 'vc' => 'Verify Content',
6630: 'cv' => 'Check/Set Resource Versions',
6631: 'ls' => 'List Resource Identifiers',
6632: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6633: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6634: );
1.484 raeburn 6635: my ($candump,$dumpurl);
6636: if ($home + $other > 0) {
6637: $candump = 'F';
6638: if ($home) {
6639: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6640: } else {
6641: my @hosts;
6642: foreach my $aurole (keys(%outhash)) {
6643: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6644: push(@hosts,$outhash{$aurole});
1.538 raeburn 6645: }
1.484 raeburn 6646: }
6647: if (@hosts == 1) {
6648: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6649: '&role='.
6650: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6651: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6652: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6653: } else {
6654: $dumpurl = "javascript:choose_switchserver_window()";
6655: }
6656: }
6657: }
6658: my @menu=
6659: ({ categorytitle=>'Administration',
6660: items =>[
6661: { linktext => $lt{'vc'},
6662: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6663: permission => 'F',
1.571 raeburn 6664: help => 'Docs_Verify_Content',
1.484 raeburn 6665: icon => 'verify.png',
6666: linktitle => 'Verify contents can be retrieved/rendered',
6667: },
6668: { linktext => $lt{'cv'},
6669: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6670: permission => 'F',
1.571 raeburn 6671: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6672: icon => 'resversion.png',
6673: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6674: },
6675: { linktext => $lt{'ls'},
6676: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6677: permission => 'F',
6678: #help => '',
6679: icon => 'symbs.png',
6680: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6681: },
6682: ]
1.611 raeburn 6683: });
6684: if ($canedit) {
6685: push(@menu,
1.484 raeburn 6686: { categorytitle=>'Export',
6687: items =>[
6688: { linktext => $lt{'imse'},
6689: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6690: permission => 'F',
6691: help => 'Docs_Export_Course_Docs',
6692: icon => 'imsexport.png',
6693: linktitle => $lt{'imse'},
6694: },
6695: { linktext => $lt{'dcd'},
6696: url => $dumpurl,
6697: permission => $candump,
1.571 raeburn 6698: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6699: icon => 'dump.png',
6700: linktitle => $lt{'dcd'},
6701: },
6702: ]
6703: });
1.611 raeburn 6704: }
1.484 raeburn 6705: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6706: '<input type="hidden" id="dummy" />'."\n".
6707: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6708: '</form>';
1.329 droeschl 6709: }
6710:
6711: sub generate_edit_table {
1.538 raeburn 6712: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6713: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6714: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6715: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6716: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6717: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6718: $activetab = $env{'form.active'};
6719: }
1.611 raeburn 6720: unless ($canedit) {
6721: $disabled = ' disabled="disabled"';
6722: }
1.472 raeburn 6723: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6724: my $backtext = &mt('Exit Editor');
1.458 raeburn 6725: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6726: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6727: '<li class="goback">'.
1.546 raeburn 6728: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6729: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6730: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6731: '<li>'.
6732: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6733: &mt('Undo Delete').'</a></li>'."\n";
6734: if ($env{'form.docslog'}) {
6735: $form .= '<li class="active">';
6736: } else {
6737: $form .= '<li>';
6738: }
6739: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6740: &mt('History').'</a></li>'."\n";
6741: if ($env{'form.docslog'}) {
6742: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6743: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6744: }
1.458 raeburn 6745: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6746: if($name ne '00'){
1.371 tempelho 6747: if($activetab eq '' || $activetab ne $name){
6748: $active = '';
6749: }elsif($activetab eq $name){
6750: $active = 'class="active"';
6751: }
1.458 raeburn 6752: $form .= '<li style="float:right" '.$active
1.484 raeburn 6753: .' 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 6754: } else {
1.570 raeburn 6755: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6756:
6757: }
1.329 droeschl 6758: }
1.484 raeburn 6759: $form .= '</ul>'."\n";
6760: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6761:
6762: if ($to_show ne '') {
1.538 raeburn 6763: my $saveform;
6764: if ($need_save) {
6765: my $button = &mt('Make changes');
6766: my $path;
6767: if ($env{'form.folderpath'}) {
6768: $path =
6769: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6770: }
6771: $saveform = <<"END";
6772: <div id="multisave" style="display:none; clear:both;" >
6773: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6774: <input type="hidden" name="folderpath" value="$path" />
6775: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6776: <input type="hidden" name="allhiddenresource" value="" />
6777: <input type="hidden" name="allencrypturl" value="" />
6778: <input type="hidden" name="allrandompick" value="" />
6779: <input type="hidden" name="allrandomorder" value="" />
6780: <input type="hidden" name="changeparms" value="" />
6781: <input type="hidden" name="multiremove" value="" />
6782: <input type="hidden" name="multicut" value="" />
6783: <input type="hidden" name="multicopy" value="" />
6784: <input type="hidden" name="multichange" value="" />
6785: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 6786: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 6787: </form>
6788: </div>
6789: END
6790: }
6791: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6792: }
1.363 ehlerst 6793: foreach my $field (keys(%orderhash)){
1.390 tempelho 6794: if($field ne '00'){
1.422 onken 6795: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6796: $active = 'style="display: none;float:left"';
1.422 onken 6797: }elsif($activetab eq $field){
1.458 raeburn 6798: $active = 'style="display:block;float:left"';
1.422 onken 6799: }
6800: $form .= '<div id="'.$field.$tid.'"'
6801: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6802: .'</div>'."\n";
1.363 ehlerst 6803: }
6804: }
1.484 raeburn 6805: unless ($env{'form.docslog'}) {
6806: $form .= '</div></div>'."\n";
6807: }
1.329 droeschl 6808: return $form;
6809: }
6810:
6811: sub editing_js {
1.622 raeburn 6812: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
6813: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 6814: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6815: p_mnf => 'Name of New Folder',
6816: t_mnf => 'New Folder',
6817: p_mnp => 'Name of New Page',
6818: t_mnp => 'New Page',
1.451 www 6819: p_mxu => 'Title for the External Score',
1.349 biermanm 6820: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6821: p_msb => 'Title for the Problem',
6822: p_mdb => 'Title for the Drop Box',
1.336 schafran 6823: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 6824: p_mwp => 'Title for Web Page',
1.606 raeburn 6825: p_mnr => 'Title for the Resource',
1.348 weissno 6826: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6827: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6828: p_mab_alrt1 => 'Not a valid user:domain',
6829: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6830: p_chn => 'New Title',
6831: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 6832: p_rmr2a => 'Remove',
6833: p_rmr2b => '?',
6834: p_rmr3a => 'Remove those',
6835: p_rmr3b => 'items?',
6836: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6837: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6838: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6839: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 6840: p_ctr2a => 'Cut',
6841: p_ctr2b => '?',
6842: p_ctr3a => 'Cut those',
6843: p_ctr3b => 'items?',
1.478 raeburn 6844: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6845: imsfile => 'You must choose an IMS package for import',
6846: imscms => 'You must select which Course Management System was the source of the IMS package',
6847: invurl => 'Invalid URL',
6848: titbl => 'Title is blank',
1.538 raeburn 6849: more => '(More ...)',
6850: less => '(Less ...)',
1.543 raeburn 6851: noor => 'No actions selected or changes to settings specified.',
6852: noch => 'No changes to settings specified.',
6853: noac => 'No actions selected.',
1.606 raeburn 6854: nofi => 'No file selected',
6855: tinc => 'Title in course',
6856: sunm => 'Sub-directory name',
1.618 raeburn 6857: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6858: );
1.594 damieng 6859: &js_escape(\%js_lt);
1.433 raeburn 6860: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6861: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6862: my $main_container_page;
1.519 raeburn 6863: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6864: $main_container_page = 1;
1.434 raeburn 6865: }
1.617 raeburn 6866: my $backtourl;
6867: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6868: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6869:
1.530 raeburn 6870: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6871: my $caller = $1;
1.525 raeburn 6872: if ($caller =~ /^supplemental/) {
6873: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6874: } else {
6875: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6876: $res = &Apache::lonnet::clutter($res);
6877: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 6878: my ($url,$anchor);
6879: if ($res =~ /^([^#]+)#([^#]+)$/) {
6880: $url = $1;
6881: $anchor = $2;
6882: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6883: $caller = $1.&escape('#').$anchor;
6884: }
1.614 raeburn 6885: } else {
6886: $url = $res;
1.609 raeburn 6887: }
6888: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 6889: &HTML::Entities::encode($caller,'<>&"');
1.622 raeburn 6890: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6891: if (($ENV{'SERVER_PORT'} == 443) &&
6892: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6893: if ($hostname ne '') {
6894: $backtourl = 'http://'.$hostname.$backtourl;
6895: }
6896: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6897: }
1.623 ! raeburn 6898: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
! 6899: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
! 6900: $backtourl = 'http://'.$hostname.$backtourl;
! 6901: }
1.622 raeburn 6902: }
1.609 raeburn 6903: if ($anchor ne '') {
6904: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6905: }
1.590 raeburn 6906: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6907: } else {
6908: $backtourl = '/adm/navmaps';
1.525 raeburn 6909: }
6910: }
6911: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6912: $backtourl = '/adm/menu';
6913: } elsif ($supplementalflag) {
1.472 raeburn 6914: $backtourl = '/adm/supplemental';
1.525 raeburn 6915: } else {
6916: $backtourl = '/adm/navmaps';
1.472 raeburn 6917: }
6918:
1.600 raeburn 6919: my $fieldsets = "'ext','doc'";
6920: if ($posslti) {
6921: $fieldsets .= ",'tool'";
6922: }
1.519 raeburn 6923: unless ($main_container_page) {
6924: $fieldsets .=",'ims'";
6925: }
1.501 raeburn 6926: if ($supplementalflag) {
1.600 raeburn 6927: $fieldsets = "'suppext','suppdoc'";
6928: if ($posslti) {
6929: $fieldsets .= ",'supptool'";
6930: }
1.501 raeburn 6931: }
1.611 raeburn 6932:
6933: my $jsmakefunctions;
6934: if ($canedit) {
6935: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6936: function makenewfolder(targetform,folderseq) {
1.594 damieng 6937: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6938: if (foldername) {
6939: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6940: targetform.submit();
6941: }
6942: }
6943:
6944: function makenewpage(targetform,folderseq) {
1.594 damieng 6945: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6946: if (pagename) {
6947: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6948: targetform.submit();
6949: }
6950: }
6951:
6952: function makeexamupload() {
1.594 damieng 6953: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6954: if (title) {
1.329 droeschl 6955: this.document.forms.newexamupload.importdetail.value=
6956: escape(title)+'=/res/lib/templates/examupload.problem';
6957: this.document.forms.newexamupload.submit();
6958: }
6959: }
6960:
6961: function makesmppage() {
1.594 damieng 6962: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6963: if (title) {
1.329 droeschl 6964: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 6965: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6966: this.document.forms.newsmppg.submit();
6967: }
6968: }
6969:
1.534 raeburn 6970: function makewebpage(type) {
1.594 damieng 6971: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 6972: var formname;
6973: if (type == 'supp') {
6974: formname = this.document.forms.supwebpage;
6975: } else {
6976: formname = this.document.forms.newwebpage;
6977: }
6978: if (title) {
6979: var webpage = formname.importdetail.value;
6980: formname.importdetail.value = escape(title)+'='+webpage;
6981: formname.submit();
6982: }
6983: }
6984:
1.329 droeschl 6985: function makesmpproblem() {
1.594 damieng 6986: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6987: if (title) {
1.329 droeschl 6988: this.document.forms.newsmpproblem.importdetail.value=
6989: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6990: this.document.forms.newsmpproblem.submit();
6991: }
6992: }
6993:
6994: function makedropbox() {
1.594 damieng 6995: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6996: if (title) {
1.329 droeschl 6997: this.document.forms.newdropbox.importdetail.value=
6998: escape(title)+'=/res/lib/templates/DropBox.problem';
6999: this.document.forms.newdropbox.submit();
7000: }
7001: }
7002:
7003: function makebulboard() {
1.594 damieng 7004: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7005: if (title) {
7006: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7007: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7008: this.document.forms.newbul.submit();
7009: }
7010: }
7011:
7012: function makeabout() {
1.594 damieng 7013: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7014: if (user) {
7015: var comp=new Array();
7016: comp=user.split(':');
7017: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7018: if ((comp[0]) && (comp[1])) {
7019: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7020: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7021: this.document.forms.newaboutsomeone.submit();
7022: } else {
7023: alert("$js_lt{'p_mab_alrt1'}");
7024: }
7025: } else {
7026: alert("$js_lt{'p_mab_alrt2'}");
7027: }
7028: }
7029: }
7030:
7031: function makenew(targetform) {
7032: targetform.submit();
7033: }
7034:
7035: function changename(folderpath,index,oldtitle) {
7036: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7037: if (title) {
7038: this.document.forms.renameform.markcopy.value='';
7039: this.document.forms.renameform.title.value=title;
7040: this.document.forms.renameform.cmd.value='rename_'+index;
7041: this.document.forms.renameform.folderpath.value=folderpath;
7042: this.document.forms.renameform.submit();
7043: }
7044: }
7045:
7046: ENDNEWSCRIPT
7047: } else {
7048: $jsmakefunctions = <<ENDNEWSCRIPT;
7049:
7050: function makenewfolder() {
7051: alert("$js_lt{'edri'}");
7052: }
7053:
7054: function makenewpage() {
7055: alert("$js_lt{'edri'}");
7056: }
7057:
7058: function makeexamupload() {
7059: alert("$js_lt{'edri'}");
7060: }
7061:
7062: function makesmppage() {
7063: alert("$js_lt{'edri'}");
7064: }
7065:
7066: function makewebpage(type) {
7067: alert("$js_lt{'edri'}");
7068: }
7069:
7070: function makesmpproblem() {
7071: alert("$js_lt{'edri'}");
7072: }
7073:
7074: function makedropbox() {
7075: alert("$js_lt{'edri'}");
7076: }
7077:
7078: function makebulboard() {
7079: alert("$js_lt{'edri'}");
7080: }
7081:
7082: function makeabout() {
7083: alert("$js_lt{'edri'}");
7084: }
7085:
7086: function changename() {
7087: alert("$js_lt{'edri'}");
7088: }
7089:
7090: function makenew() {
7091: alert("$js_lt{'edri'}");
7092: }
7093:
7094: function groupimport() {
7095: alert("$js_lt{'edri'}");
1.335 ehlerst 7096: }
1.611 raeburn 7097:
7098: function groupsearch() {
7099: alert("$js_lt{'edri'}");
1.335 ehlerst 7100: }
1.611 raeburn 7101:
7102: function groupopen(url,recover) {
7103: var options="scrollbars=1,resizable=1,menubar=0";
7104: idxflag=1;
7105: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7106: idx.focus();
1.329 droeschl 7107: }
7108:
1.611 raeburn 7109: ENDNEWSCRIPT
7110:
7111: }
7112: return <<ENDSCRIPT;
7113:
7114: $jsmakefunctions
7115:
1.501 raeburn 7116: function toggleUpload(caller) {
7117: var blocks = Array($fieldsets);
7118: for (var i=0; i<blocks.length; i++) {
7119: var disp = 'none';
7120: if (caller == blocks[i]) {
7121: var curr = document.getElementById('upload'+caller+'form').style.display;
7122: if (curr == 'none') {
7123: disp='block';
7124: }
7125: }
7126: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7127: if ((caller == 'tool') || (caller == 'supptool')) {
7128: if (disp == 'block') {
7129: if (document.getElementById('LC_exttoolid')) {
7130: var toolselector = document.getElementById('LC_exttoolid');
7131: var suppflag = 0;
7132: if (caller == 'supptool') {
7133: suppflag = 1;
7134: }
7135: currForm = document.getElementById('new'+caller);
7136: updateExttool(toolselector,currForm,suppflag);
7137: }
7138: }
7139: }
1.501 raeburn 7140: }
1.502 raeburn 7141: resize_scrollbox('contentscroll','1','1');
7142: return;
7143: }
7144:
1.514 raeburn 7145: function toggleMap(caller) {
1.502 raeburn 7146: var disp = 'none';
1.510 raeburn 7147: if (document.getElementById('importmapform')) {
1.514 raeburn 7148: if (caller == 'map') {
7149: var curr = document.getElementById('importmapform').style.display;
7150: if (curr == 'none') {
7151: disp='block';
7152: }
1.510 raeburn 7153: }
7154: document.getElementById('importmapform').style.display=disp;
7155: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7156: }
1.501 raeburn 7157: return;
1.329 droeschl 7158: }
7159:
1.606 raeburn 7160: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7161: var disp = 'none';
7162: if (document.getElementById('crsresform')) {
7163: if (caller == 'res') {
7164: var curr = document.getElementById('crsresform').style.display;
7165: if (curr == 'none') {
7166: disp='block';
7167: numauthor = parseInt(numauthorrole);
7168: if (numauthor > 0) {
7169: document.courseresform.authorrole.selectedIndex = 0;
7170: select1priv_changed();
7171: document.courseresform.authorpath.selectedIndex = 0;
7172: document.courseresform.newresourceadd.selectedIndex = 0;
7173: toggleNewInCourse(document.courseresform);
7174: if (document.getElementById('newresource')) {
7175: document.getElementById('newresource').style.display = 'none';
7176: }
7177: } else {
7178: if (numcrsdirs) {
7179: document.courseresform.authorpath.selectedIndex = 0;
7180: }
7181: }
7182: if (document.courseresform.newresusetemp.length) {
7183: document.courseresform.newresusetemp[0].checked = true;
7184: toggleWithTemplate(document.courseresform);
7185: }
7186: document.courseresform.newresourcename.value = '';
7187: }
7188: }
7189: if (document.courseresform.newsubdir.length) {
7190: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7191: if (document.courseresform.newsubdir[j].value == 0) {
7192: document.courseresform.newsubdir[j].checked = true;
7193: }
7194: break;
7195: }
7196: if (document.getElementById('newsubdirname')) {
7197: document.getElementById('newsubdirname').type = "hidden";
7198: document.getElementById('newsubdirname').value = "";
7199: }
7200: if (document.getElementById('newsubdir')) {
7201: document.getElementById('newsubdir').innerHTML = "";
7202: }
7203: }
7204: document.getElementById('crsresform').style.display=disp;
7205: resize_scrollbox('contentscroll','1','0');
7206: }
7207: return;
7208: }
7209:
7210: function toggleNewsubdir(form) {
7211: if (form.newsubdir.length) {
7212: for (var j=0; j<form.newsubdir.length; j++) {
7213: if (form.newsubdir[j].checked) {
7214: if (document.getElementById('newsubdirname')) {
7215: if (form.newsubdir[j].value == '1') {
7216: document.getElementById('newsubdirname').type = "text";
7217: if (document.getElementById('newsubdir')) {
7218: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7219: }
7220: } else {
7221: document.getElementById('newsubdirname').type = "hidden";
7222: document.getElementById('newsubdirname').value = "";
7223: document.getElementById('newsubdir').innerHTML = "";
7224: }
7225: }
7226: break;
7227: }
7228: }
7229: }
7230: }
7231:
7232: function toggleCrsResTitle() {
7233: if (document.getElementById('newresource')) {
7234: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7235: document.getElementById('newresource').style.display = 'inline';
7236: document.courseresform.newresourceadd[0].checked = true;
7237: toggleNewInCourse(document.courseresform);
7238: } else {
7239: document.getElementById('newresource').style.display = 'none';
7240: }
7241: }
7242: }
7243:
7244: function toggleNewInCourse(form) {
7245: if (form.newresourceadd.length) {
7246: for (var i=0; i<form.newresourceadd.length; i++) {
7247: if (form.newresourceadd[i].checked) {
7248: if (document.getElementById('newresourcetitle')) {
7249: if (form.newresourceadd[i].value == '1') {
7250: document.getElementById('newresourcetitle').type = 'text';
7251: if (document.getElementById('newrestitle')) {
7252: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7253: }
7254: } else {
7255: document.getElementById('newresourcetitle').type = 'hidden';
7256: document.getElementById('newresourcetitle').value = '';
7257: if (document.getElementById('newrestitle')) {
7258: document.getElementById('newrestitle').innerHTML = '';
7259: }
7260: }
7261: }
7262: break;
7263: }
7264: }
7265: }
7266: }
7267:
7268: function toggleWithTemplate(form) {
7269: if (form.newresusetemp.length) {
7270: for (var i=0; i<form.newresusetemp.length; i++) {
7271: if (form.newresusetemp[i].checked) {
7272: if (document.getElementById('newrestemplate')) {
7273: if (form.newresusetemp[i].value == '1') {
7274: document.getElementById('newrestemplate').style.display = 'inline';
7275: toggleExampleText();
7276: } else {
7277: form.tempcategory.selectedIndex = 0;
7278: select1template_changed();
7279: document.getElementById('newrestemplate').style.display = 'none';
7280: }
7281: }
7282: }
7283: }
7284: }
7285: }
7286:
7287: function toggleExampleText() {
7288: if (document.getElementById('newresexample')) {
7289: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7290: if (url == '') {
7291: document.getElementById('newresexample').style.fontWeight = 'normal';
7292: } else {
7293: document.getElementById('newresexample').style.fontWeight = 'bold';
7294: }
7295: }
7296: }
7297:
7298: function getExample(width,height,scrolling,transparency) {
7299: var url;
7300: if (document.courseresform.newresusetemp.length) {
7301: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7302: if (document.courseresform.newresusetemp[i].checked) {
7303: if (document.courseresform.newresusetemp[i].value == '1') {
7304: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7305: if (url == '') {
7306: alert('Pick a category and template');
7307: } else {
7308: url = url.replace("$londocroot","");
7309: url += '?inhibitmenu=yes';
7310: }
7311: }
7312: break;
7313: }
7314: }
7315: }
7316: if (url != '') {
7317: openMyModal(url,width,height,scrolling,transparency,'');
7318: }
7319: }
7320:
7321: function toggleImportCrsres(caller,dircount) {
7322: var disp = 'none';
7323: if (document.getElementById('importcrsresform')) {
7324: if (caller == 'res') {
7325: var numdirs = parseInt(dircount);
7326: var curr = document.getElementById('importcrsresform').style.display;
7327: if (curr == 'none') {
7328: disp='block';
7329: if (numdirs > 1) {
7330: select1res_changed();
7331: }
7332: }
7333: }
7334: document.getElementById('importcrsresform').style.display=disp;
7335: resize_scrollbox('contentscroll','1','0');
7336: }
7337: return;
7338: }
7339:
1.501 raeburn 7340: function makeims(imsform) {
7341: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7342: alert("$js_lt{'imsfile'}");
1.501 raeburn 7343: return;
7344: }
7345: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7346: alert("$js_lt{'imscms'}");
1.501 raeburn 7347: return;
7348: }
7349: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7350: imsform.submit();
7351: }
7352:
1.478 raeburn 7353: function updatePick(targetform,index,caller) {
1.537 raeburn 7354: var pickitem;
7355: var picknumitem;
7356: var picknumtext;
7357: if (index == 'all') {
7358: pickitem = document.getElementById('randompickall');
7359: picknumitem = document.getElementById('rpicknumall');
7360: picknumtext = document.getElementById('rpicktextall');
7361: } else {
7362: pickitem = document.getElementById('randompick_'+index);
7363: picknumitem = document.getElementById('rpicknum_'+index);
7364: picknumtext = document.getElementById('randompicknum_'+index);
7365: }
1.478 raeburn 7366: if (pickitem.checked) {
1.594 damieng 7367: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7368: if (picknum == '' || picknum == null) {
7369: if (caller == 'check') {
7370: pickitem.checked=false;
1.537 raeburn 7371: if (index == 'all') {
7372: picknumtext.innerHTML = '';
7373: if (caller == 'link') {
7374: propagateState(targetform,'rpicknum');
7375: }
7376: } else {
1.538 raeburn 7377: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7378: }
1.478 raeburn 7379: }
7380: } else {
7381: picknum.toString();
7382: var regexdigit=/^\\d+\$/;
7383: if (regexdigit.test(picknum)) {
7384: picknumitem.value = picknum;
1.537 raeburn 7385: if (index == 'all') {
1.538 raeburn 7386: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7387: if (caller == 'link') {
7388: propagateState(targetform,'rpicknum');
7389: }
7390: } else {
7391: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7392: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7393: }
1.478 raeburn 7394: } else {
7395: if (caller == 'check') {
1.537 raeburn 7396: if (index == 'all') {
7397: picknumtext.innerHTML = '';
7398: if (caller == 'link') {
7399: propagateState(targetform,'rpicknum');
7400: }
7401: } else {
7402: pickitem.checked=false;
1.538 raeburn 7403: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7404: }
1.478 raeburn 7405: }
7406: return;
7407: }
7408: }
7409: } else {
1.537 raeburn 7410: picknumitem.value = '';
7411: picknumtext.innerHTML = '';
7412: if (index == 'all') {
7413: if (caller == 'link') {
7414: propagateState(targetform,'rpicknum');
7415: }
7416: } else {
1.538 raeburn 7417: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7418: }
7419: }
7420: }
7421:
7422: function propagateState(form,param) {
7423: if (document.getElementById(param+'all')) {
7424: var setcheck = 0;
7425: var rpick = 0;
7426: if (param == 'rpicknum') {
7427: if (document.getElementById('randompickall')) {
7428: if (document.getElementById('randompickall').checked) {
7429: if (document.getElementById('rpicknumall')) {
7430: rpick = document.getElementById('rpicknumall').value;
7431: }
7432: }
7433: }
7434: } else {
7435: if (document.getElementById(param+'all').checked) {
7436: setcheck = 1;
7437: }
7438: }
1.538 raeburn 7439: var allidxlist;
7440: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7441: if (document.getElementById('all'+param+'idx')) {
7442: allidxlist = document.getElementById('all'+param+'idx').value;
7443: }
7444: var actions = new Array ('remove','cut','copy');
7445: for (var i=0; i<actions.length; i++) {
7446: if (actions[i] != param) {
7447: if (document.getElementById(actions[i]+'all')) {
7448: document.getElementById(actions[i]+'all').checked = false;
7449: }
7450: }
7451: }
7452: }
1.537 raeburn 7453: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7454: allidxlist = form.allidx.value;
7455: }
7456: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7457: allidxlist = form.allmapidx.value;
7458: }
7459: if ((allidxlist != '') && (allidxlist != null)) {
7460: var allidxs = allidxlist.split(',');
7461: if (allidxs.length > 1) {
7462: for (var i=0; i<allidxs.length; i++) {
7463: if (document.getElementById(param+'_'+allidxs[i])) {
7464: if (param == 'rpicknum') {
7465: if (document.getElementById('randompick_'+allidxs[i])) {
7466: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7467: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7468: if (rpick > 0) {
7469: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7470: } else {
7471: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7472: }
7473: }
7474: }
7475: } else {
1.537 raeburn 7476: if (setcheck == 1) {
7477: document.getElementById(param+'_'+allidxs[i]).checked = true;
7478: } else {
7479: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7480: if (param == 'randompick') {
7481: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7482: }
1.537 raeburn 7483: }
7484: }
7485: }
7486: }
1.538 raeburn 7487: if (setcheck == 1) {
7488: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7489: var actions = new Array('copy','cut','remove');
7490: for (var i=0; i<actions.length; i++) {
7491: var otheractions;
7492: var otheridxs;
7493: if (actions[i] === param) {
7494: continue;
7495: } else {
7496: if (document.getElementById('all'+actions[i]+'idx')) {
7497: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7498: otheridxs = otheractions.split(',');
7499: if (otheridxs.length > 1) {
7500: for (var j=0; j<otheridxs.length; j++) {
7501: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7502: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7503: }
1.537 raeburn 7504: }
7505: }
7506: }
1.538 raeburn 7507: }
7508: }
7509: }
7510: }
7511: }
7512: }
7513: }
7514: return;
7515: }
7516:
1.603 raeburn 7517: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7518: var canedit = '$canedit';
7519: if (canedit == '') {
7520: alert("$js_lt{'edri'}");
7521: return;
7522: }
1.539 raeburn 7523: var dosettings;
7524: var doaction;
1.538 raeburn 7525: var control = document.togglemultsettings;
7526: if (context == 'actions') {
7527: control = document.togglemultactions;
1.539 raeburn 7528: doaction = 1;
7529: } else {
7530: dosettings = 1;
1.538 raeburn 7531: }
1.539 raeburn 7532: if (control) {
7533: if (control.showmultpick.length) {
7534: for (var i=0; i<control.showmultpick.length; i++) {
7535: if (control.showmultpick[i].checked) {
7536: if (control.showmultpick[i].value == 1) {
7537: if (context == 'settings') {
7538: dosettings = 0;
7539: } else {
7540: doaction = 0;
1.538 raeburn 7541: }
7542: }
7543: }
1.537 raeburn 7544: }
7545: }
1.539 raeburn 7546: }
7547: if (context == 'settings') {
7548: if (dosettings == 1) {
1.538 raeburn 7549: targetform.changeparms.value=param;
7550: targetform.submit();
7551: }
1.537 raeburn 7552: }
1.539 raeburn 7553: if (context == 'actions') {
7554: if (doaction == 1) {
7555: targetform.cmd.value=param+'_'+index;
7556: targetform.folderpath.value=folderpath;
7557: targetform.markcopy.value=idx+':'+param;
7558: targetform.copyfolder.value=folder+'.'+container;
7559: if (param == 'remove') {
1.603 raeburn 7560: var doremove = 0;
7561: if (skip_confirm) {
7562: if (confirm_removal) {
7563: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7564: doremove = 1;
7565: }
7566: } else {
7567: doremove = 1;
7568: }
7569: } else {
7570: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7571: doremove = 1;
7572: }
7573: }
7574: if (doremove) {
1.539 raeburn 7575: targetform.markcopy.value='';
7576: targetform.copyfolder.value='';
7577: targetform.submit();
7578: }
7579: }
7580: if (param == 'cut') {
1.594 damieng 7581: 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 7582: targetform.submit();
7583: return;
7584: }
7585: }
7586: if (param == 'copy') {
7587: targetform.submit();
7588: return;
7589: }
7590: targetform.markcopy.value='';
7591: targetform.copyfolder.value='';
7592: targetform.cmd.value='';
7593: targetform.folderpath.value='';
7594: return;
7595: } else {
7596: if (document.getElementById(param+'_'+idx)) {
7597: item = document.getElementById(param+'_'+idx);
7598: if (item.type == 'checkbox') {
7599: if (item.checked) {
7600: item.checked = false;
7601: } else {
7602: item.checked = true;
7603: singleCheck(item,idx,param);
7604: }
7605: }
7606: }
7607: }
7608: }
1.537 raeburn 7609: return;
7610: }
7611:
1.538 raeburn 7612: function singleCheck(caller,idx,action) {
7613: actions = new Array('cut','copy','remove');
7614: if (caller.checked) {
7615: for (var i=0; i<actions.length; i++) {
7616: if (actions[i] != action) {
7617: if (document.getElementById(actions[i]+'_'+idx)) {
7618: if (document.getElementById(actions[i]+'_'+idx).checked) {
7619: document.getElementById(actions[i]+'_'+idx).checked = false;
7620: }
1.537 raeburn 7621: }
7622: }
7623: }
1.478 raeburn 7624: }
1.537 raeburn 7625: return;
1.478 raeburn 7626: }
7627:
1.334 muellerd 7628: function unselectInactive(nav) {
1.335 ehlerst 7629: currentNav = document.getElementById(nav);
7630: currentLis = currentNav.getElementsByTagName('LI');
7631: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7632: if (currentLis[i].className == 'goback') {
7633: currentLis[i].className = 'goback';
7634: } else {
7635: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7636: currentLis[i].className = 'right';
1.472 raeburn 7637: } else {
1.374 tempelho 7638: currentLis[i].className = 'i';
1.472 raeburn 7639: }
7640: }
1.335 ehlerst 7641: }
1.332 tempelho 7642: }
7643:
1.334 muellerd 7644: function hideAll(current, nav, data) {
1.335 ehlerst 7645: unselectInactive(nav);
1.570 raeburn 7646: if (current) {
7647: if (current.className == 'right'){
7648: current.className = 'right active'
7649: } else {
7650: current.className = 'active';
7651: }
1.374 tempelho 7652: }
1.335 ehlerst 7653: currentData = document.getElementById(data);
7654: currentDivs = currentData.getElementsByTagName('DIV');
7655: for (i = 0; i < currentDivs.length; i++) {
7656: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7657: currentDivs[i].style.display = 'none';
1.330 tempelho 7658: }
7659: }
1.335 ehlerst 7660: }
1.330 tempelho 7661:
1.374 tempelho 7662: function openTabs(pageId) {
7663: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7664: if(tabnav.length > 2 ){
1.389 tempelho 7665: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7666: currentLis = currentNav.getElementsByTagName('LI');
7667: for(i = 0; i< currentLis.length; i++){
7668: if(currentLis[i].className == 'active') {
1.375 tempelho 7669: funcString = currentLis[i].onclick.toString();
7670: tab = funcString.split('"');
1.420 onken 7671: if(tab.length < 2) {
7672: tab = funcString.split("'");
7673: }
1.375 tempelho 7674: currentData = document.getElementById(tab[1]);
7675: currentData.style.display = 'block';
1.374 tempelho 7676: }
7677: }
7678: }
7679: }
7680:
1.334 muellerd 7681: function showPage(current, pageId, nav, data) {
1.570 raeburn 7682: currstate = current.className;
1.334 muellerd 7683: hideAll(current, nav, data);
1.375 tempelho 7684: openTabs(pageId);
1.334 muellerd 7685: unselectInactive(nav);
1.570 raeburn 7686: if ((currstate == 'active') || (currstate == 'right active')) {
7687: if (currstate == 'active') {
7688: current.className = '';
7689: } else {
7690: current.className = 'right';
7691: }
7692: activeTab = '';
7693: toggleUpload();
7694: toggleMap();
1.606 raeburn 7695: toggleCrsRes();
7696: toggleImportCrsres();
1.570 raeburn 7697: resize_scrollbox('contentscroll','1','0');
7698: return;
7699: } else {
7700: current.className = 'active';
7701: }
1.330 tempelho 7702: currentData = document.getElementById(pageId);
7703: currentData.style.display = 'block';
1.458 raeburn 7704: activeTab = pageId;
1.501 raeburn 7705: toggleUpload();
1.503 raeburn 7706: toggleMap();
1.606 raeburn 7707: toggleCrsRes();
7708: toggleImportCrsres();
1.433 raeburn 7709: if (nav == 'mainnav') {
7710: var storedpath = "$docs_folderpath";
1.434 raeburn 7711: var storedpage = "$main_container_page";
1.433 raeburn 7712: var reg = new RegExp("^supplemental");
7713: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7714: if (storedpage == 1) {
7715: document.simpleedit.folderpath.value = '';
7716: document.uploaddocument.folderpath.value = '';
7717: } else {
7718: if (reg.test(storedpath)) {
7719: document.simpleedit.folderpath.value = '$toplevelmain';
7720: document.uploaddocument.folderpath.value = '$toplevelmain';
7721: document.newext.folderpath.value = '$toplevelmain';
7722: } else {
7723: document.simpleedit.folderpath.value = storedpath;
7724: document.uploaddocument.folderpath.value = storedpath;
7725: document.newext.folderpath.value = storedpath;
7726: }
1.433 raeburn 7727: }
7728: } else {
1.434 raeburn 7729: if (reg.test(storedpath)) {
7730: document.simpleedit.folderpath.value = storedpath;
7731: document.supuploaddocument.folderpath.value = storedpath;
7732: document.supnewext.folderpath.value = storedpath;
7733: } else {
1.433 raeburn 7734: document.simpleedit.folderpath.value = '$toplevelsupp';
7735: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7736: document.supnewext.folderpath.value = '$toplevelsupp';
7737: }
7738: }
7739: }
1.485 raeburn 7740: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7741: return false;
7742: }
1.329 droeschl 7743:
1.472 raeburn 7744: function toContents(jumpto) {
7745: var newurl = '$backtourl';
1.525 raeburn 7746: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7747: newurl = newurl+'?postdata='+jumpto;
7748: }
7749: location.href=newurl;
7750: }
7751:
1.538 raeburn 7752: function togglePick(caller,value) {
7753: var disp = 'none';
7754: if (document.getElementById('multi'+caller)) {
7755: var curr = document.getElementById('multi'+caller).style.display;
7756: if (value == 1) {
7757: disp='block';
7758: }
7759: if (curr == disp) {
7760: return;
7761: }
7762: document.getElementById('multi'+caller).style.display=disp;
7763: if (value == 1) {
1.594 damieng 7764: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7765: } else {
7766: document.getElementById('more'+caller).innerHTML = '';
7767: }
7768: if (caller == 'actions') {
7769: setClass(value);
7770: setBoxes(value);
7771: }
7772: }
7773: var showButton = multiSettings();
7774: if (showButton != 1) {
7775: showButton = multiActions();
7776: }
7777: if (document.getElementById('multisave')) {
7778: if (showButton == 1) {
7779: document.getElementById('multisave').style.display='block';
7780: } else {
7781: document.getElementById('multisave').style.display='none';
7782: }
7783: }
7784: resize_scrollbox('contentscroll','1','1');
7785: return;
7786: }
7787:
7788: function toggleCheckUncheck(caller,more) {
7789: if (more == 1) {
1.594 damieng 7790: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 7791: document.getElementById('allfields'+caller).style.display='block';
7792: } else {
1.594 damieng 7793: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7794: document.getElementById('allfields'+caller).style.display='none';
7795: }
7796: resize_scrollbox('contentscroll','1','1');
7797: }
7798:
7799: function multiSettings() {
7800: var inuse = 0;
7801: var settingsform = document.togglemultsettings;
7802: if (settingsform.showmultpick.length > 1) {
7803: for (var i=0; i<settingsform.showmultpick.length; i++) {
7804: if (settingsform.showmultpick[i].checked) {
7805: if (settingsform.showmultpick[i].value == 1) {
7806: inuse = 1;
7807: }
7808: }
7809: }
7810: }
7811: return inuse;
7812: }
7813:
7814: function multiActions() {
7815: var inuse = 0;
7816: var actionsform = document.togglemultactions;
7817: if (actionsform.showmultpick.length > 1) {
7818: for (var i=0; i<actionsform.showmultpick.length; i++) {
7819: if (actionsform.showmultpick[i].checked) {
7820: if (actionsform.showmultpick[i].value == 1) {
7821: inuse = 1;
7822: }
7823: }
7824: }
7825: }
7826: return inuse;
7827: }
7828:
7829: function checkSubmits() {
7830: var numchanges = 0;
7831: var form = document.saveactions;
7832: var doactions = multiActions();
1.542 raeburn 7833: var cutwarnings = 0;
7834: var remwarnings = 0;
1.603 raeburn 7835: var removalinfo = 0;
1.538 raeburn 7836: if (doactions == 1) {
7837: var remidxlist = document.cumulativeactions.allremoveidx.value;
7838: if ((remidxlist != '') && (remidxlist != null)) {
7839: var remidxs = remidxlist.split(',');
7840: for (var i=0; i<remidxs.length; i++) {
7841: if (document.getElementById('remove_'+remidxs[i])) {
7842: if (document.getElementById('remove_'+remidxs[i]).checked) {
7843: form.multiremove.value += remidxs[i]+',';
7844: numchanges ++;
1.542 raeburn 7845: if (document.getElementById('skip_remove_'+remidxs[i])) {
7846: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7847: remwarnings ++;
7848: }
7849: }
1.603 raeburn 7850: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7851: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7852: removalinfo ++;
7853: }
7854: }
1.537 raeburn 7855: }
7856: }
1.538 raeburn 7857: }
7858: }
7859: var cutidxlist = document.cumulativeactions.allcutidx.value;
7860: if ((cutidxlist != '') && (cutidxlist != null)) {
7861: var cutidxs = cutidxlist.split(',');
7862: for (var i=0; i<cutidxs.length; i++) {
7863: if (document.getElementById('cut_'+cutidxs[i])) {
7864: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7865: form.multicut.value += cutidxs[i]+',';
7866: numchanges ++;
1.542 raeburn 7867: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7868: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7869: cutwarnings ++;
7870: }
7871: }
1.537 raeburn 7872: }
7873: }
7874: }
7875: }
1.538 raeburn 7876: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7877: if ((copyidxlist != '') && (copyidxlist != null)) {
7878: var copyidxs = copyidxlist.split(',');
7879: for (var i=0; i<copyidxs.length; i++) {
7880: if (document.getElementById('copy_'+copyidxs[i])) {
7881: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7882: form.multicopy.value += copyidxs[i]+',';
7883: numchanges ++;
7884: }
7885: }
7886: }
7887: }
7888: if (numchanges > 0) {
7889: form.multichange.value = numchanges;
7890: }
1.537 raeburn 7891: }
1.538 raeburn 7892: var dosettings = multiSettings();
1.543 raeburn 7893: var haschanges = 0;
1.538 raeburn 7894: if (dosettings == 1) {
7895: form.allencrypturl.value = '';
7896: form.allhiddenresource.value = '';
1.543 raeburn 7897: form.changeparms.value = 'all';
7898: var patt=new RegExp(",\$");
1.538 raeburn 7899: var allidxlist = document.cumulativesettings.allidx.value;
7900: if ((allidxlist != '') && (allidxlist != null)) {
7901: var allidxs = allidxlist.split(',');
7902: if (allidxs.length > 1) {
7903: for (var i=0; i<allidxs.length; i++) {
7904: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7905: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7906: form.allhiddenresource.value += allidxs[i]+',';
7907: }
7908: }
7909: if (document.getElementById('encrypturl_'+allidxs[i])) {
7910: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7911: form.allencrypturl.value += allidxs[i]+',';
7912: }
7913: }
7914: }
1.543 raeburn 7915: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7916: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 7917: }
1.538 raeburn 7918: }
7919: form.allrandompick.value = '';
7920: form.allrandomorder.value = '';
7921: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7922: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7923: var allmapidxs = allmapidxlist.split(',');
7924: for (var i=0; i<allmapidxs.length; i++) {
7925: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7926: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7927: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7928: if ((randompick.checked) && (rpicknum.value != '')) {
7929: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7930: }
7931: if (randorder.checked) {
7932: form.allrandomorder.value += allmapidxs[i]+',';
7933: }
1.537 raeburn 7934: }
1.543 raeburn 7935: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7936: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7937: }
7938: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7939: haschanges = 1;
7940: }
7941: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7942: haschanges = 1;
7943: }
7944: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7945: haschanges = 1;
7946: }
7947: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7948: haschanges = 1;
1.537 raeburn 7949: }
7950: }
1.543 raeburn 7951: if (doactions == 1) {
1.542 raeburn 7952: if (numchanges > 0) {
1.603 raeburn 7953: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 7954: if (remwarnings > 0) {
1.594 damieng 7955: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 7956: return false;
7957: }
7958: }
1.603 raeburn 7959: if (removalinfo > 0) {
7960: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7961: return false;
7962: }
7963: }
1.542 raeburn 7964: if (cutwarnings > 0) {
1.594 damieng 7965: 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 7966: return false;
7967: }
7968: }
7969: }
7970: form.submit();
7971: return true;
1.543 raeburn 7972: }
7973: }
7974: if (dosettings == 1) {
7975: if (haschanges == 1) {
1.542 raeburn 7976: form.submit();
7977: return true;
7978: }
1.543 raeburn 7979: }
7980: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 7981: alert("$js_lt{'noor'}");
1.543 raeburn 7982: } else {
7983: if (dosettings == 1) {
1.594 damieng 7984: alert("$js_lt{'noch'}");
1.543 raeburn 7985: } else {
1.594 damieng 7986: alert("$js_lt{'noac'}");
1.543 raeburn 7987: }
7988: }
1.538 raeburn 7989: return false;
7990: }
7991:
7992: function setClass(value) {
7993: var cutclass = 'LC_docs_cut';
7994: var copyclass = 'LC_docs_copy';
7995: var removeclass = 'LC_docs_remove';
7996: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7997: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7998: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7999: var links = document.getElementsByTagName('a');
8000: for (var i=0; i<links.length; i++) {
8001: var classes = links[i].className;
8002: if (cutreg.test(classes)) {
8003: links[i].className = cutclass;
8004: if (value == 1) {
8005: links[i].className += " LC_menubuttons_link";
8006: }
8007: } else {
8008: if (copyreg.test(classes)) {
8009: links[i].className = copyclass;
8010: if (value == 1) {
8011: links[i].className += " LC_menubuttons_link";
8012: }
8013: } else {
8014: if (removereg.test(classes)) {
8015: links[i].className = removeclass;
8016: if (value == 1) {
8017: links[i].className += " LC_menubuttons_link";
8018: }
8019: }
8020: }
8021: }
8022: }
8023: return;
1.537 raeburn 8024: }
8025:
1.538 raeburn 8026: function setBoxes(value) {
8027: var remidxlist = document.cumulativeactions.allremoveidx.value;
8028: if ((remidxlist != '') && (remidxlist != null)) {
8029: var remidxs = remidxlist.split(',');
8030: for (var i=0; i<remidxs.length; i++) {
8031: if (document.getElementById('remove_'+remidxs[i])) {
8032: var item = document.getElementById('remove_'+remidxs[i]);
8033: if (value == 1) {
8034: item.className = 'LC_docs_remove';
8035: } else {
8036: item.className = 'LC_hidden';
8037: }
8038: }
8039: }
8040: }
8041: var cutidxlist = document.cumulativeactions.allcutidx.value;
8042: if ((cutidxlist != '') && (cutidxlist != null)) {
8043: var cutidxs = cutidxlist.split(',');
8044: for (var i=0; i<cutidxs.length; i++) {
8045: if (document.getElementById('cut_'+cutidxs[i])) {
8046: var item = document.getElementById('cut_'+cutidxs[i]);
8047: if (value == 1) {
8048: item.className = 'LC_docs_cut';
8049: } else {
8050: item.className = 'LC_hidden';
8051: }
8052: }
1.537 raeburn 8053: }
8054: }
1.538 raeburn 8055: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8056: if ((copyidxlist != '') && (copyidxlist != null)) {
8057: var copyidxs = copyidxlist.split(',');
8058: for (var i=0; i<copyidxs.length; i++) {
8059: if (document.getElementById('copy_'+copyidxs[i])) {
8060: var item = document.getElementById('copy_'+copyidxs[i]);
8061: if (value == 1) {
8062: item.className = 'LC_docs_copy';
8063: } else {
8064: item.className = 'LC_hidden';
8065: }
8066: }
1.537 raeburn 8067: }
8068: }
8069: return;
8070: }
8071:
1.606 raeburn 8072: function validImportCrsRes() {
8073: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8074: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8075: if ((fname == '') || (fname == null)) {
8076: alert("$js_lt{'nofi'}");
8077: return false;
8078: }
8079: var url = '/res/$coursedom/$coursenum/';
8080: if (path && path != '/') {
8081: url += path+'/';
8082: }
8083: if (fname != '') {
8084: url += fname;
8085: }
8086: var title = document.crsresimportform.crsrestitle.value;
8087: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8088: return true;
8089: }
8090:
8091: function validateNewRes(caller) {
8092: if (caller == 'single') {
8093: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8094: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8095: var resname = document.courseresform.newresourcename.value;
8096: }
8097: }
8098:
1.611 raeburn 8099: ENDSCRIPT
1.329 droeschl 8100: }
1.457 raeburn 8101:
1.483 raeburn 8102: sub history_tab_js {
8103: return <<"ENDHIST";
8104: function toggleHistoryDisp(choice) {
8105: document.docslogform.docslog.value = choice;
8106: document.docslogform.submit();
8107: return;
8108: }
8109:
8110: ENDHIST
8111: }
8112:
1.484 raeburn 8113: sub inject_data_js {
8114: return <<ENDINJECT;
8115:
8116: function injectData(current, hiddenField, name, value) {
8117: currentElement = document.getElementById(hiddenField);
8118: currentElement.name = name;
8119: currentElement.value = value;
8120: current.submit();
8121: }
8122:
8123: ENDINJECT
8124: }
8125:
8126: sub dump_switchserver_js {
8127: my @hosts = @_;
1.594 damieng 8128: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8129: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8130: swit => 'Switch server?',
1.594 damieng 8131: );
8132: my %html_js_lt = &Apache::lonlocal::texthash(
8133: swit => 'Switch server?',
1.568 raeburn 8134: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8135: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8136: chos => 'Choose server',
8137: );
1.594 damieng 8138: &js_escape(\%js_lt);
8139: &html_escape(\%html_js_lt);
8140: &js_escape(\%html_js_lt);
1.484 raeburn 8141: my $role = $env{'request.role'};
8142: my $js = <<"ENDSWJS";
8143: <script type="text/javascript">
8144: function write_switchserver() {
8145: var server;
8146: if (document.setserver.posshosts.length > 0) {
8147: for (var i=0; i<document.setserver.posshosts.length; i++) {
8148: if (document.setserver.posshosts[i].checked) {
8149: server = document.setserver.posshosts[i].value;
8150: }
8151: }
8152: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8153: }
8154: window.close();
8155: }
8156: </script>
8157:
8158: ENDSWJS
8159:
8160: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8161: {'only_body' => 1,
8162: 'js_ready' => 1,});
8163: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8164:
8165: my $hostpicker;
8166: my $count = 0;
8167: foreach my $host (sort(@hosts)) {
8168: my $checked;
8169: if ($count == 0) {
8170: $checked = ' checked="checked"';
8171: }
8172: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8173: $host.'"'.$checked.' />'.$host.'</label> ';
8174: $count++;
8175: }
8176:
8177: return <<"ENDSWITCHJS";
8178:
8179: function dump_needs_switchserver(url) {
8180: if (url!='' && url!= null) {
1.594 damieng 8181: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8182: go(url);
8183: }
8184: }
8185: return;
8186: }
8187:
8188: function choose_switchserver_window() {
8189: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8190: newWindow.document.open();
8191: newWindow.document.writeln('$startpage');
1.594 damieng 8192: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8193: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8194: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8195: '<form name="setserver" method="post" action="" \\/>\\n'+
8196: '$hostpicker\\n'+
8197: '<br \\/><br \\/>\\n'+
1.594 damieng 8198: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8199: 'onclick="write_switchserver();" \\/>\\n'+
8200: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8201: newWindow.document.writeln('$endpage');
8202: newWindow.document.close();
8203: newWindow.focus();
8204: }
8205:
8206: ENDSWITCHJS
8207: }
8208:
8209: sub makedocslogform {
8210: my ($formelems,$docslog) = @_;
8211: return <<"LOGSFORM";
8212: <form action="/adm/coursedocs" method="post" name="docslogform">
8213: <input type="hidden" name="docslog" value="$docslog" />
8214: $formelems
8215: </form>
8216: LOGSFORM
8217: }
8218:
8219: sub makesimpleeditform {
8220: my ($formelems) = @_;
8221: return <<"SIMPFORM";
8222: <form name="simpleedit" method="post" action="/adm/coursedocs">
8223: <input type="hidden" name="importdetail" value="" />
8224: $formelems
8225: </form>
8226: SIMPFORM
8227: }
8228:
1.606 raeburn 8229: sub makenewproblem {
8230: my ($r,$coursedom,$coursenum) = @_;
8231: # Creating a new problem
8232: my ($redirect,$error);
8233: if ($env{'form.authorrole'}) {
8234: my ($newsubdir,$filename);
8235: if ($env{'form.newsubdir'}) {
8236: if ($env{'form.newsubdirname'} ne '') {
8237: $newsubdir = $env{'form.newsubdirname'};
8238: }
8239: }
8240: if ($env{'form.newresourcename'}) {
8241: $filename = $env{'form.newresourcename'};
8242: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8243: $filename =~ s/`//g;
8244: $filename =~ s{/\.\./}{_}g;
8245: $filename =~ s/\.+/./g;
8246: $filename =~ s{/+}{_}g;
8247: if ($filename ne '') {
8248: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8249: if (($ext) && ($ext ne '.problem')) {
8250: $filename = $name.'.problem';
8251: } elsif ($ext eq '') {
8252: $filename .= '.problem';
8253: }
8254: my $docroot = $r->dir_config('lonDocRoot');
8255: my @ids=&Apache::lonnet::current_machine_ids();
8256: if ($env{'form.authorrole'} eq 'author') {
8257: if ($env{'user.author'}) {
8258: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8259: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8260: my $path = $docroot.$url;
8261: my $subdir = $env{'form.authorpath'};
8262: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8263: }
8264: }
8265: } elsif ($env{'form.authorrole'} eq 'course') {
8266: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8267: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8268: my $url = "/priv/$coursedom/$coursenum";
8269: my $path=$docroot.$url;
8270: my $subdir = $env{'form.authorpath'};
8271: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8272: if ($redirect) {
8273: my $rightsfile = 'default.rights';
8274: my $sourcerights = "$path/$rightsfile";
8275: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8276: my $now = time;
8277: if (!-e $sourcerights) {
8278: my $cid = $coursedom.'_'.$coursenum;
8279: if (open(my $fh,">$sourcerights")) {
8280: print $fh <<END;
8281: <accessrule effect="deny" realm="" type="course" role="" />
8282: <accessrule effect="allow" realm="$cid" type="course" role="" />
8283: END
8284: close($fh);
8285: }
8286: }
8287: if (!-e "$sourcerights.meta") {
8288: if (open(my $fh,">$sourcerights.meta")) {
8289: my $author=$env{'environment.firstname'}.' '.
8290: $env{'environment.middlename'}.' '.
8291: $env{'environment.lastname'}.' '.
8292: $env{'environment.generation'};
8293: $author =~ s/\s+$//;
8294: print $fh <<"END";
8295:
8296: <abstract></abstract>
8297: <author>$author</author>
8298: <authorspace>$coursenum:$coursedom</authorspace>
8299: <copyright>private</copyright>
8300: <creationdate>$now</creationdate>
8301: <customdistributionfile></customdistributionfile>
8302: <dependencies></dependencies>
8303: <domain>$coursedom</domain>
8304: <highestgradelevel>0</highestgradelevel>
8305: <keywords></keywords>
8306: <language>notset </language>
8307: <lastrevisiondate>$now</lastrevisiondate>
8308: <lowestgradelevel>0</lowestgradelevel>
8309: <mime>rights</mime>
8310: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8311: <notes></notes>
8312: <obsolete></obsolete>
8313: <obsoletereplacement></obsoletereplacement>
8314: <owner>$coursenum:$coursedom</owner>
8315: <rule>deny:::course,allow:$cid::course</rule>
8316: <sourceavail></sourceavail>
8317: <standards></standards>
8318: <subject></subject>
8319: <title></title>
8320: END
8321: close($fh);
8322: }
8323: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8324: if (!-e "$docroot/res/$coursedom") {
8325: mkdir("$docroot/res/$coursedom",0755);
8326: }
8327: if (!-e "$docroot/res/$coursedom/$coursenum") {
8328: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8329: }
8330: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8331: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8332: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8333: }
8334: }
8335: }
8336: if ($env{'form.newresourceadd'}) {
8337: my $template = $env{'form.template'};
8338: my $source = $docroot.$redirect;
8339: my $target = $redirect;
8340: $target =~ s{^/priv/}{/res/};
8341: $target = $docroot.$target;
8342: if (!-e $source) {
8343: my $copyfrom;
8344: if ($template) {
8345: my %templates;
8346: my @files = &Apache::lonhomework::get_template_list('problem');
8347: foreach my $poss (@files) {
8348: if (ref($poss) eq 'ARRAY') {
8349: if ($template eq $poss->[0]) {
8350: $templates{$template} = 1;
8351: last;
8352: }
8353: }
8354: }
8355: if ($templates{$template}) {
8356: $copyfrom = $template;
8357: }
8358: }
8359: unless ($copyfrom) {
8360: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8361: }
8362: &File::Copy::copy($copyfrom,$source);
8363: }
8364: if (!-e "$source.meta") {
8365: my $cid = $coursedom.'_'.$coursenum;
8366: my $now = time;
8367: if (open(my $fh,">$source.meta")) {
8368: my $author=$env{'environment.firstname'}.' '.
8369: $env{'environment.middlename'}.' '.
8370: $env{'environment.lastname'}.' '.
8371: $env{'environment.generation'};
8372: $author =~ s/\s+$//;
8373: my $title = $env{'form.newresourcetitle'};
8374: $title =~ s/^\s+|\s+$//g;
8375: print $fh <<END;
8376:
8377: <abstract></abstract>
8378: <author>$author</author>
8379: <authorspace>$coursenum:$coursedom</authorspace>
8380: <copyright>custom</copyright>
8381: <creationdate>$now</creationdate>
8382: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8383: <dependencies></dependencies>
8384: <domain>$coursedom</domain>
8385: <highestgradelevel>0</highestgradelevel>
8386: <keywords></keywords>
8387: <language>notset </language>
8388: <lastrevisiondate>$now</lastrevisiondate>
8389: <lowestgradelevel>0</lowestgradelevel>
8390: <mime>problem</mime>
8391: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8392: <notes></notes>
8393: <obsolete></obsolete>
8394: <obsoletereplacement></obsoletereplacement>
8395: <owner>$coursenum:$coursedom</owner>
8396: <sourceavail></sourceavail>
8397: <standards></standards>
8398: <subject></subject>
8399: <title>$title</title>
8400: END
8401: close($fh);
8402: }
8403: }
8404: }
8405: }
8406: }
8407: } else {
8408: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8409: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8410: if (grep(/^\Q$rolehome\E$/,@ids)) {
8411: my $now = time;
8412: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8413: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8414: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8415: my $url = "/priv/$audom/$auname";
8416: my $path = $r->dir_config('lonDocRoot').$url;
8417: my $subdir = $env{'form.authorpath'};
8418: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8419: }
8420: }
8421: }
8422: }
8423: }
8424: }
8425: }
8426: return ($redirect,$error);
8427: }
8428:
8429: sub finishnewprob {
8430: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8431: unless (-d $path) {
8432: unless (mkdir($path,02770)) {
8433: return;
8434: }
8435: }
1.606 raeburn 8436: my $redirect;
8437: if ($subdir ne '/') {
8438: $subdir = &cleandir($subdir);
8439: if (($subdir ne '') && (-d "$path/$subdir")) {
8440: $path .= "/$subdir";
8441: $url .= "/$subdir";
8442: }
8443: }
8444: my $dest;
8445: if ($newsubdir ne '') {
8446: $newsubdir = &cleandir($newsubdir);
8447: }
8448: if ($newsubdir ne '') {
8449: if (-d "$path/$newsubdir") {
8450: $dest = "$path/$newsubdir/$filename";
8451: } else {
8452: my $dirok;
8453: unless (-e "$path/$newsubdir") {
8454: if (mkdir("$path/$newsubdir",02770)) {
8455: if (chmod(02770,"$path/$newsubdir")) {
8456: $dirok = 1;
8457: }
8458: }
8459: }
8460: if ($dirok) {
8461: $dest = "$path/$newsubdir/$filename";
8462: }
8463: }
8464: if (($dest ne '') && (!-e $dest)) {
8465: $redirect = "$url/$newsubdir/$filename";
8466: }
8467: } else {
8468: $dest = "$path/$filename";
8469: if (($dest ne '') && (!-e $dest)) {
8470: $redirect = "$url/$filename";
8471: }
8472: }
8473: return $redirect;
8474: }
8475:
8476: sub cleandir {
8477: my ($dir) = @_;
8478: $dir =~ s/^\s+//;
8479: $dir =~ s/\s+$//;
8480: $dir =~ s/\.+//g;
8481: $dir =~ s/[\#\?&%\":]//g;
8482: return $dir;
8483: }
8484:
1.329 droeschl 8485: 1;
8486: __END__
8487:
8488:
8489: =head1 NAME
8490:
8491: Apache::londocs.pm
8492:
8493: =head1 SYNOPSIS
8494:
8495: This is part of the LearningOnline Network with CAPA project
8496: described at http://www.lon-capa.org.
8497:
8498: =head1 SUBROUTINES
8499:
8500: =over
8501:
8502: =item %help=()
8503:
8504: Available help topics
8505:
8506: =item mapread()
8507:
1.344 bisitz 8508: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8509: @order and @resources, determines status
8510: sets @order - pointer to resources in right order
8511: sets @resources - array with the resources with correct idx
8512:
8513: =item authorhosts()
8514:
8515: Return hash with valid author names
8516:
8517: =item clean()
8518:
8519: =item dumpcourse()
8520:
8521: Actually dump course
8522:
8523: =item group_import()
8524:
8525: Imports the given (name, url) resources into the course
8526: coursenum, coursedom, and folder must precede the list
8527:
8528: =item breadcrumbs()
8529:
8530: =item log_docs()
8531:
8532: =item docs_change_log()
8533:
8534: =item update_paste_buffer()
8535:
8536: =item print_paste_buffer()
8537:
8538: =item do_paste_from_buffer()
8539:
1.538 raeburn 8540: =item do_buffer_empty()
8541:
8542: =item clear_from_buffer()
8543:
1.492 raeburn 8544: =item get_newmap_url()
8545:
8546: =item dbcopy()
8547:
8548: =item uniqueness_check()
8549:
8550: =item contained_map_check()
8551:
8552: =item url_paste_fixups()
8553:
8554: =item apply_fixups()
8555:
8556: =item copy_dependencies()
8557:
1.329 droeschl 8558: =item update_parameter()
8559:
8560: =item handle_edit_cmd()
8561:
8562: =item editor()
8563:
8564: =item process_file_upload()
8565:
8566: =item process_secondary_uploads()
8567:
8568: =item is_supplemental_title()
8569:
8570: =item entryline()
8571:
8572: =item tiehash()
8573:
8574: =item untiehash()
8575:
8576: =item checkonthis()
8577:
8578: check on this
8579:
8580: =item verifycontent()
8581:
8582: Verify Content
8583:
8584: =item devalidateversioncache() & checkversions()
8585:
8586: Check Versions
8587:
8588: =item mark_hash_old()
8589:
8590: =item is_hash_old()
8591:
8592: =item changewarning()
8593:
8594: =item init_breadcrumbs()
8595:
8596: Breadcrumbs for special functions
8597:
1.484 raeburn 8598: =item create_list_elements()
8599:
8600: =item create_form_ul()
8601:
8602: =item startContentScreen()
8603:
8604: =item endContentScreen()
8605:
8606: =item supplemental_base()
8607:
8608: =item embedded_form_elems()
8609:
8610: =item embedded_destination()
8611:
8612: =item return_to_editor()
8613:
8614: =item decompression_info()
8615:
8616: =item decompression_phase_one()
8617:
8618: =item decompression_phase_two()
8619:
8620: =item remove_archive()
8621:
8622: =item generate_admin_menu()
8623:
8624: =item generate_edit_table()
8625:
8626: =item editing_js()
8627:
8628: =item history_tab_js()
8629:
8630: =item inject_data_js()
8631:
8632: =item dump_switchserver_js()
8633:
1.485 raeburn 8634: =item resize_scrollbox_js()
1.484 raeburn 8635:
8636: =item makedocslogform()
8637:
1.485 raeburn 8638: =item makesimpleeditform()
8639:
1.329 droeschl 8640: =back
8641:
8642: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>