Annotation of loncom/interface/londocs.pm, revision 1.621
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.621 ! raeburn 4: # $Id: londocs.pm,v 1.620 2017/02/18 14:16:47 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.329 droeschl 48: use HTML::Entities;
1.488 raeburn 49: use HTML::TokeParser;
1.329 droeschl 50: use GDBM_File;
1.578 raeburn 51: use File::MMagic;
1.606 raeburn 52: use File::Copy;
1.329 droeschl 53: use Apache::lonlocal;
54: use Cwd;
55: use LONCAPA qw(:DEFAULT :match);
56:
57: my $iconpath;
58:
59: my %hash;
60:
61: my $hashtied;
62: my %alreadyseen=();
63:
64: my $hadchanges;
1.557 raeburn 65: my $suppchanges;
1.329 droeschl 66:
67:
68: my %help=();
69:
70:
71: sub mapread {
72: my ($coursenum,$coursedom,$map)=@_;
73: return
74: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
75: $map);
76: }
77:
78: sub storemap {
1.492 raeburn 79: my ($coursenum,$coursedom,$map,$contentchg)=@_;
80: my $report;
81: if (($contentchg) && ($map =~ /^default/)) {
82: $report = 1;
83: }
1.329 droeschl 84: my ($outtext,$errtext)=
85: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 86: $map,1,$report);
1.329 droeschl 87: if ($errtext) { return ($errtext,2); }
1.364 bisitz 88:
1.557 raeburn 89: if ($map =~ /^default/) {
90: $hadchanges=1;
91: } else {
92: $suppchanges=1;
93: }
1.329 droeschl 94: return ($errtext,0);
95: }
96:
97:
98:
99: sub authorhosts {
100: my %outhash=();
101: my $home=0;
102: my $other=0;
103: foreach my $key (keys(%env)) {
104: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
105: my $role=$1;
106: my $realm=$2;
107: my ($start,$end)=split(/\./,$env{$key});
108: if (($start) && ($start>time)) { next; }
109: if (($end) && (time>$end)) { next; }
110: my ($ca,$cd);
111: if ($1 eq 'au') {
112: $ca=$env{'user.name'};
113: $cd=$env{'user.domain'};
114: } else {
115: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
116: }
117: my $allowed=0;
118: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
119: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 120: foreach my $id (@ids) {
121: if ($id eq $myhome) {
122: $allowed=1;
123: last;
124: }
125: }
1.329 droeschl 126: if ($allowed) {
127: $home++;
1.484 raeburn 128: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 129: } else {
1.484 raeburn 130: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 131: $other++;
132: }
133: }
134: }
135: return ($home,$other,%outhash);
136: }
137:
138:
139: sub clean {
140: my ($title)=@_;
141: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 142: return $title;
1.329 droeschl 143: }
144:
1.617 raeburn 145: sub default_folderpath {
146: my ($coursenum,$coursedom,$navmapref) = @_;
147: return unless ($coursenum && $coursedom && ref($navmapref));
148: # Check if entire course is hidden and/or encrypted
149: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
150: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
151: unless (ref($$navmapref)) {
152: $$navmapref = Apache::lonnavmaps::navmap->new();
153: }
154: if (ref($$navmapref)) {
155: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
156: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
157: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
158: unless (@resources) {
159: $hiddenmap = 1;
160: unless ($env{'request.role.adv'}) {
161: $hiddentop = 1;
162: if ($env{'form.folder'}) {
163: undef($env{'form.folder'});
164: }
165: }
166: }
167: }
168: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
169: $encryptmap = 1;
170: }
171: }
172: unless ($hiddentop) {
173: $folderpath='default&'.&escape(&mt('Main Content')).
174: '::'.$hiddenmap.':'.$encryptmap.'::';
175: }
176: if (wantarray) {
177: return ($folderpath,$hiddentop);
178: } else {
179: return $folderpath;
180: }
181: }
1.329 droeschl 182:
183: sub dumpcourse {
184: my ($r) = @_;
1.408 raeburn 185: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 186: my ($starthash,$js);
187: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
188: $js = <<"ENDJS";
189: <script type="text/javascript">
190: // <![CDATA[
191:
192: function hide_searching() {
193: if (document.getElementById('searching')) {
194: document.getElementById('searching').style.display = 'none';
195: }
196: return;
197: }
198:
199: // ]]>
200: </script>
201: ENDJS
202: $starthash = {
203: add_entries => {'onload' => "hide_searching();"},
204: };
205: }
1.568 raeburn 206: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
207: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 208: $r->print(&startContentScreen('tools'));
1.329 droeschl 209: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 210: unless ($home) {
211: $r->print(&endContentScreen());
212: return '';
213: }
1.329 droeschl 214: my $origcrsid=$env{'request.course.id'};
215: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
216: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
217: # Do the dumping
1.484 raeburn 218: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
219: $r->print(&endContentScreen());
220: return '';
221: }
1.531 raeburn 222: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 223: $r->print('<h3>'.&mt('Copying Files').'</h3>');
224: my $title=$env{'form.authorfolder'};
225: $title=&clean($title);
1.567 raeburn 226: my ($navmap,$errormsg) =
227: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
228: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
229: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
230: my (%maps,%resources,%titles);
231: if (!ref($navmap)) {
232: $r->print($errormsg.
233: &endContentScreen());
234: return '';
235: } else {
236: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
237: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 238: }
1.567 raeburn 239: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
240: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
241: %newcontent,%has_simpleprobs);
242: foreach my $item (sort {$a <=> $b} (@todump)) {
243: my $name = $env{'form.namefor_'.$item};
244: if ($resources{$item}) {
245: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
246: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
247: $tocopy{$1} = $name;
248: $display{$item} = $1;
249: $lookup{$1} = $item;
250: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
251: $simpleproblems{$item} = {
252: symb => $resources{$item},
253: name => $name,
254: };
255: $display{$item} = 'simpleproblem_'.$name;
256: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
257: $has_simpleprobs{$1}{$id} = $item;
258: }
259: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
260: my $marker = $1;
261: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
262: $simplepages{$item} = {
263: res => $res,
264: title => $titles{$item},
265: db => $db_name,
266: marker => $marker,
267: symb => $resources{$item},
268: name => $name,
269: };
270: $display{$item} = '/'.$res;
271: }
272: } elsif ($maps{$item}) {
273: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
274: $tocopy{$1} = $name;
275: $display{$item} = $1;
276: $lookup{$1} = $item;
277: }
278: } else {
279: next;
280: }
281: }
1.329 droeschl 282: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
283: $crs=~s/\_/\//g;
1.567 raeburn 284: my $mm = new File::MMagic;
285: my $prefix = "/uploaded/$cdom/$cnum/";
286: %replacehash = %tocopy;
287: foreach my $item (sort(keys(%simpleproblems))) {
288: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
289: $newcontent{$display{$item}} = $content;
290: }
291: my $gateway = Apache::lonhtmlgateway->new('web');
292: foreach my $item (sort(keys(%simplepages))) {
293: if (ref($simplepages{$item}) eq 'HASH') {
294: my $pagetitle = $simplepages{$item}{'title'};
295: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
296: my %contents;
297: foreach my $field (keys(%fields)) {
298: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
299: my $name = $1;
300: my $msg = $fields{$field};
301: if ($name eq 'webreferences') {
302: if ($msg =~ m{^https?://}) {
303: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
304: }
305: } else {
306: $msg = &Encode::decode('utf8',$msg);
307: $msg = $gateway->process_outgoing_html($msg,1);
308: $contents{$name} = $msg;
309: }
310: } elsif ($field eq 'uploaded.photourl') {
311: my $marker = $simplepages{$item}{marker};
312: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
313: my $filepath = $1;
314: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
315: if ($fname ne '') {
316: $fname=~s/\.(\w+)$//;
317: my $ext=$1;
318: $fname = &clean($fname);
319: $fname.='.'.$ext;
320: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
321: $replacehash{$filepath} = $relpath.$fname;
322: $deps{$item}{$filepath} = 1;
323: }
324: }
325: }
326: }
327: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
328: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
329: my $content = '
330: <html>
331: <head>
332: <title>'.$pagetitle.'</title>
333: </head>
334: <body bgcolor="#ffffff">';
335: if ($contents{title}) {
336: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
337: }
338: if ($contents{image}) {
339: $content .= "\n".$contents{image};
340: }
341: if ($contents{content}) {
342: $content .= '
343: <div class="LC_Box">
1.577 bisitz 344: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 345: $contents{content}.'
346: </div>';
347: }
348: if ($contents{webreferences}) {
349: $content .= '
350: <div class="LC_Box">
1.577 bisitz 351: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 352: $contents{webreferences}.'
353: </div>';
354: }
355: $content .= '
356: </body>
357: </html>
358: ';
359: $newcontent{'/'.$simplepages{$item}{res}} = $content;
360: }
361: }
362: foreach my $item (keys(%tocopy)) {
363: unless ($item=~/\.(sequence|page)$/) {
364: my $currurlpath = $prefix.$item;
365: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
366: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
367: }
368: }
369: foreach my $num (sort {$a <=> $b} (@todump)) {
370: my $src = $display{$num};
371: next if ($src eq '');
372: my @needcopy = ();
373: if ($replacehash{$src}) {
374: push(@needcopy,$src);
375: if (ref($deps{$num}) eq 'HASH') {
376: foreach my $dep (sort(keys(%{$deps{$num}}))) {
377: if ($replacehash{$dep}) {
378: push(@needcopy,$dep);
379: }
380: }
381: }
382: } elsif ($src =~ /^simpleproblem_/) {
383: push(@needcopy,$src);
384: }
385: next if (@needcopy == 0);
386: my ($result,$depresult);
387: for (my $i=0; $i<@needcopy; $i++) {
388: my $item = $needcopy[$i];
389: my $newfilename;
390: if ($simpleproblems{$num}) {
391: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
392: } else {
393: $newfilename=$title.'/'.$replacehash{$item};
394: }
395: $newfilename=~s/\.(\w+)$//;
396: my $ext=$1;
397: $newfilename=&clean($newfilename);
398: $newfilename.='.'.$ext;
399: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
400: if ($newrelpath ne $replacehash{$item}) {
401: $replacehash{$item} = $newrelpath;
402: }
403: my @dirs=split(/\//,$newfilename);
404: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
405: my $makepath=$path;
406: my $fail;
407: my $origin;
408: for (my $i=0;$i<$#dirs;$i++) {
409: $makepath.='/'.$dirs[$i];
410: unless (-e $makepath) {
411: unless(mkdir($makepath,0755)) {
412: $fail = &mt('Directory creation failed.');
413: }
414: }
415: }
416: if ($i == 0) {
417: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
418: } else {
419: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
420: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
421: &mt('(dependency)').'</span>: ';
422: }
423: if (-e $path.'/'.$newfilename) {
424: $fail = &mt('Destination already exists -- not overwriting.');
425: } else {
426: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
427: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
428: ($item =~ /^simpleproblem_/)) {
429: print $fh $newcontent{$item};
430: } else {
431: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
432: if (-e $fileloc) {
433: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
434: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
435: (ref($has_simpleprobs{$item}) eq 'HASH')) {
436: my %changes = %{$has_simpleprobs{$item}};
437: my $content = &Apache::lonclonecourse::rewritefile(
438: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
439: (%replacehash,$crs => '')
440: );
441: my $updatedcontent = '';
442: my $parser = HTML::TokeParser->new(\$content);
443: $parser->attr_encoded(1);
444: while (my $token = $parser->get_token) {
445: if ($token->[0] eq 'S') {
446: if (($token->[1] eq 'resource') &&
447: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
448: ($changes{$token->[2]->{'id'}})) {
449: my $id = $token->[2]->{'id'};
450: $updatedcontent .= '<'.$token->[1];
451: foreach my $attrib (@{$token->[3]}) {
452: next unless ($attrib =~ /^(src|type|title|id)$/);
453: if ($attrib eq 'src') {
454: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
455: if ($file) {
456: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: } else {
461: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
462: }
463: }
464: $updatedcontent .= ' />'."\n";
465: } else {
466: $updatedcontent .= $token->[4]."\n";
467: }
468: } else {
469: $updatedcontent .= $token->[2];
470: }
471: }
472: print $fh $updatedcontent;
473: } else {
474: print $fh &Apache::lonclonecourse::rewritefile(
475: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
476: (%replacehash,$crs => '')
477: );
478: }
479: } else {
480: print $fh
481: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
482: }
483: } else {
484: $fail = &mt('Source does not exist.');
485: }
486: }
487: $fh->close();
488: } else {
489: $fail = &mt('Could not write to destination.');
490: }
491: }
492: my $text;
493: if ($fail) {
494: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
495: } else {
496: $text = '<span class="LC_success">'.&mt('ok').'</span>';
497: }
498: if ($i == 0) {
499: $result .= $text;
500: } else {
501: $depresult .= $text.'</li>';
502: }
503: }
504: $r->print($result);
505: if ($depresult) {
506: $r->print('<ul>'.$depresult.'</ul>');
507: }
508: }
509: } else {
510: my ($navmap,$errormsg) =
511: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
512: if (!ref($navmap)) {
513: $r->print($errormsg);
514: } else {
515: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
516: $r->rflush();
517: my ($preamble,$formname);
518: $formname = 'dumpdoc';
519: unless ($home==1) {
520: $preamble = '<div class="LC_left_float">'.
521: '<fieldset><legend>'.
522: &mt('Select the Authoring Space').
523: '</legend><select name="authorspace">';
1.329 droeschl 524: }
1.567 raeburn 525: my @orderspaces = ();
526: foreach my $key (sort(keys(%outhash))) {
527: if ($key=~/^home_(.+)$/) {
528: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
529: unshift(@orderspaces,$1);
530: } else {
531: push(@orderspaces,$1);
532: }
533: }
534: }
1.569 raeburn 535: if ($home>1) {
536: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
537: }
1.567 raeburn 538: foreach my $user (@orderspaces) {
1.329 droeschl 539: if ($home==1) {
1.567 raeburn 540: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 541: } else {
1.567 raeburn 542: $preamble .= '<option value="'.$user.'">'.$user.' - '.
543: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
544: }
1.329 droeschl 545: }
1.567 raeburn 546: unless ($home==1) {
547: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 548: }
1.567 raeburn 549: my $title=$origcrsdata{'description'};
550: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 551: $title=&clean($title);
1.567 raeburn 552: $preamble .= '<div class="LC_left_float">'.
553: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
554: '<input type="text" size="50" name="authorfolder" value="'.
555: $title.'" />'.
556: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
557: my %uploadedfiles;
558: &tiehash();
559: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
560: my ($ext)=($file=~/\.(\w+)$/);
561: # FIXME Check supplemental here
562: my $title=$hash{'title_'.$hash{
563: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
564: if (!$title) {
565: $title=$file;
566: } else {
567: $title=~s|/|_|g;
568: }
569: $title=~s/\.(\w+)$//;
570: $title=&clean($title);
571: $title.='.'.$ext;
572: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
573: $uploadedfiles{$file} = $title;
574: }
575: &untiehash();
576: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
577: undef,undef,$preamble,$home,\%uploadedfiles));
578: }
1.329 droeschl 579: }
1.484 raeburn 580: $r->print(&endContentScreen());
1.329 droeschl 581: }
582:
1.567 raeburn 583: sub recurse_html {
584: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
585: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
586: my (%allfiles,%codebase);
587: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
588: if (keys(%allfiles)) {
589: foreach my $dependency (keys(%allfiles)) {
590: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
591: my ($depurl,$relfile,$newcontainer);
592: if ($dependency =~ m{^/}) {
593: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
594: $relfile = $1;
595: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
596: $newcontainer = $1;
597: next if ($replacehash->{$newcontainer});
598: }
599: $depurl = $dependency;
600: } else {
601: next;
602: }
603: } else {
604: $relfile = $dependency;
605: $depurl = $currurlpath;
606: $depurl =~ s{[^/]+$}{};
607: $depurl .= $dependency;
608: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
609: }
610: next if ($relfile eq '');
611: my $newname = $replacehash->{$container};
612: $newname =~ s{[^/]+$}{};
613: $replacehash->{$newcontainer} = $newname.$relfile;
614: $deps->{$item}{$newcontainer} = 1;
615: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
616: my $depfile = &Apache::lonnet::filelocation('',$depurl);
617: my $type = $mm->checktype_filename($depfile);
618: if ($type eq 'text/html') {
619: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
620: }
621: }
622: }
623: }
624: return;
625: }
626:
1.329 droeschl 627: sub group_import {
1.598 raeburn 628: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 629: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
630: %removeparam,$importuploaded,$fixuperrors);
631: $allmaps = {};
1.329 droeschl 632: while (@files) {
633: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 634: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 635: && ($caller eq 'londocs')
636: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 637:
1.329 droeschl 638: my $errtext = '';
639: my $fatal = 0;
640: my $newmapstr = '<map>'."\n".
641: '<resource id="1" src="" type="start"></resource>'."\n".
642: '<link from="1" to="2" index="1"></link>'."\n".
643: '<resource id="2" src="" type="finish"></resource>'."\n".
644: '</map>';
645: $env{'form.output'}=$newmapstr;
646: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
647: 'output',$1.$2);
1.534 raeburn 648: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 649: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
650: $fatal = 2;
651: }
652: if ($fatal) {
653: return ($errtext,$fatal);
654: }
655: }
656: if ($url) {
1.598 raeburn 657: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) {
658: $url = $1;
659: my $marker = $2;
660: my $info = $3;
1.604 raeburn 661: my ($toolid,%toolhash,%toolsettings);
1.598 raeburn 662: my @toolinfo = split(/:/,$info);
663: if ($residx) {
1.604 raeburn 664: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 665: $toolid = $toolsettings{'id'};
666: } else {
1.604 raeburn 667: $toolid = shift(@toolinfo);
1.598 raeburn 668: }
669: $toolid =~ s/\D//g;
1.604 raeburn 670: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
671: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
672: $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'});
673: $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'});
1.598 raeburn 674: if (ref($ltitoolsref) eq 'HASH') {
1.604 raeburn 675: my @deleted;
1.598 raeburn 676: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
677: if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
678: $url =~ s/exttool$/exttools/;
679: }
680: $toolhash{'id'} = $toolid;
1.604 raeburn 681: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
682: if ($toolhash{'target'} eq 'window') {
683: foreach my $item ('width','height') {
684: $toolhash{$item} =~ s/^\s+//;
685: $toolhash{$item} =~ s/\s+$//;
686: }
687: }
688: } elsif ($residx) {
689: $toolhash{'target'} = $toolsettings{'target'};
690: if ($toolhash{'target'} eq 'window') {
691: $toolhash{'width'} = $toolsettings{'width'};
692: $toolhash{'height'} = $toolsettings{'height'};
693: }
694: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
695: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
696: if ($toolhash{'target'} eq 'window') {
697: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
698: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
699: }
700: }
1.598 raeburn 701: if ($toolhash{'target'} eq 'iframe') {
702: delete($toolhash{'width'});
703: delete($toolhash{'height'});
1.604 raeburn 704: if ($residx) {
705: if ($toolsettings{'width'}) {
706: push(@deleted,'width');
707: }
708: if ($toolsettings{'height'}) {
709: push(@deleted,'height');
710: }
711: }
712: }
713: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
714: foreach my $item ('label','title') {
715: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
716: $toolhash{'crs'.$item} =~ s/^\s+//;
717: $toolhash{'crs'.$item} =~ s/\s+$//;
718: if ($toolhash{'crs'.$item} eq '') {
719: delete($toolhash{'crs'.$item});
720: }
721: } else {
722: delete($toolhash{'crs'.$item});
723: }
724: if (($residx) && (exists($toolsettings{'crs'.$item}))) {
725: unless (exists($toolhash{'crs'.$item})) {
726: push(@deleted,'crs'.$item);
727: }
728: }
1.598 raeburn 729: }
730: }
731: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 732: if ($putres eq 'ok') {
733: if (@deleted) {
734: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
735: }
736: }
1.598 raeburn 737: }
738: }
739: }
1.529 raeburn 740: if (($caller eq 'londocs') &&
741: ($folder =~ /^default/)) {
1.534 raeburn 742: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 743: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
744: my $cid = $coursedom.'_'.$coursenum;
745: $allmaps =
746: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
747: $chome,$cid);
748: $donechk = 1;
749: }
750: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
751: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
752: \%addedmaps,\%hierarchy,\%titles,$allmaps);
753: $importuploaded = 1;
754: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
755: next if ($allmaps->{$url});
756: }
757: }
1.344 bisitz 758: if (!$residx
1.329 droeschl 759: || defined($LONCAPA::map::zombies[$residx])) {
760: $residx = &LONCAPA::map::getresidx($url,$residx);
761: push(@LONCAPA::map::order, $residx);
762: }
763: my $ext = 'false';
764: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
765: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 766: if ($name eq '') {
1.538 raeburn 767: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 768: }
769: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
770: my $filepath = $1;
771: my $fname = $name;
772: if ($fname =~ /^\W+$/) {
773: $fname = 'web';
774: } else {
775: $fname =~ s/\W/_/g;
776: }
1.599 damieng 777: if (length($fname) > 15) {
1.534 raeburn 778: $fname = substr($fname,0,14);
779: }
780: my $initialtext = &mt('Replace with your own content.');
781: my $newhtml = <<END;
1.545 raeburn 782: <html>
1.534 raeburn 783: <head>
784: <title>$name</title>
785: </head>
786: <body bgcolor="#ffffff">
787: $initialtext
788: </body>
789: </html>
790: END
791: $env{'form.output'}=$newhtml;
792: my $result =
793: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
794: 'output',
795: "$filepath/$residx/$fname.html");
796: if ($result =~ m{^/uploaded/}) {
797: $url = $result;
798: if ($filepath =~ /^supplemental/) {
799: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
800: $env{'user.domain'}.'___&&&___'.$name;
801: }
802: } else {
803: return (&mt('Failed to save new web page.'),1);
804: }
805: }
1.538 raeburn 806: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 807: $LONCAPA::map::resources[$residx] =
1.329 droeschl 808: join(':', ($name, $url, $ext, 'normal', 'res'));
809: }
810: }
1.529 raeburn 811: if ($importuploaded) {
812: my %import_errors;
813: my %updated = (
814: removefrommap => \%removefrommap,
815: removeparam => \%removeparam,
816: );
1.533 raeburn 817: my ($result,$msgsarray,$lockerror) =
818: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 819: if (keys(%import_errors) > 0) {
1.530 raeburn 820: $fixuperrors =
1.529 raeburn 821: '<p span class="LC_warning">'."\n".
822: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
823: '<ul>'."\n";
824: foreach my $key (sort(keys(%import_errors))) {
825: $fixuperrors .= '<li>'.$key.'</li>'."\n";
826: }
827: $fixuperrors .= '</ul></p>'."\n";
828: }
1.533 raeburn 829: if (ref($msgsarray) eq 'ARRAY') {
830: if (@{$msgsarray} > 0) {
831: $fixuperrors .= '<p class="LC_info">'.
832: join('<br />',@{$msgsarray}).
833: '</p>';
834: }
835: }
836: if ($lockerror) {
837: $fixuperrors .= '<p class="LC_error">'.
838: $lockerror.
839: '</p>';
840: }
1.529 raeburn 841: }
842: my ($errtext,$fatal) =
843: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 844: unless ($fatal) {
845: if ($folder =~ /^supplemental/) {
846: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 847: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
848: $folder.'.'.$container);
1.557 raeburn 849: }
850: }
1.529 raeburn 851: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 852: }
853:
854: sub log_docs {
1.494 raeburn 855: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 856: }
857:
858: {
859: my @oldresources=();
860: my @oldorder=();
861: my $parmidx;
862: my %parmaction=();
863: my %parmvalue=();
864: my $changedflag;
865:
866: sub snapshotbefore {
867: @oldresources=@LONCAPA::map::resources;
868: @oldorder=@LONCAPA::map::order;
869: $parmidx=undef;
870: %parmaction=();
871: %parmvalue=();
872: $changedflag=0;
873: }
874:
875: sub remember_parms {
876: my ($idx,$parameter,$action,$value)=@_;
877: $parmidx=$idx;
878: $parmaction{$parameter}=$action;
879: $parmvalue{$parameter}=$value;
880: $changedflag=1;
881: }
882:
883: sub log_differences {
884: my ($plain)=@_;
885: my %storehash=('folder' => $plain,
886: 'currentfolder' => $env{'form.folder'});
887: if ($parmidx) {
888: $storehash{'parameter_res'}=$oldresources[$parmidx];
889: foreach my $parm (keys(%parmaction)) {
890: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
891: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
892: }
893: }
894: my $maxidx=$#oldresources;
895: if ($#LONCAPA::map::resources>$#oldresources) {
896: $maxidx=$#LONCAPA::map::resources;
897: }
898: for (my $idx=0; $idx<=$maxidx; $idx++) {
899: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
900: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
901: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
902: $changedflag=1;
903: }
904: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
905: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
906: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
907: $changedflag=1;
908: }
909: }
910: $storehash{'maxidx'}=$maxidx;
911: if ($changedflag) { &log_docs(\%storehash); }
912: }
913: }
914:
915: sub docs_change_log {
1.611 raeburn 916: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 917: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 918: my $navmap;
1.483 raeburn 919: my $js = '<script type="text/javascript">'."\n".
920: '// <![CDATA['."\n".
921: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 922: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.617 raeburn 923: $coursedom,$coursenum,'','',$canedit,\$navmap)."\n".
1.483 raeburn 924: &history_tab_js()."\n".
1.484 raeburn 925: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 926: '// ]]>'."\n".
927: '</script>'."\n";
1.484 raeburn 928: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
929: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 930: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 931: my %orderhash;
932: my $container='sequence';
933: my $pathitem;
1.519 raeburn 934: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 935: $container='page';
936: }
1.519 raeburn 937: my $folderpath=$env{'form.folderpath'};
938: if ($folderpath eq '') {
1.617 raeburn 939: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 940: }
1.617 raeburn 941: undef($navmap);
1.519 raeburn 942: $pathitem = '<input type="hidden" name="folderpath" value="'.
943: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 944: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
945: my $jumpto = $readfile;
946: $jumpto =~ s{^/}{};
947: my $tid = 1;
1.489 raeburn 948: if ($supplementalflag) {
949: $tid = 2;
950: }
1.509 raeburn 951: my ($breadcrumbtrail) =
952: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 953: $r->print($breadcrumbtrail.
954: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
955: $readfile));
1.329 droeschl 956: my %docslog=&Apache::lonnet::dump('nohist_docslog',
957: $env{'course.'.$env{'request.course.id'}.'.domain'},
958: $env{'course.'.$env{'request.course.id'}.'.num'});
959:
960: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
961:
962: my %saveable_parameters = ('show' => 'scalar',);
963: &Apache::loncommon::store_course_settings('docs_log',
964: \%saveable_parameters);
965: &Apache::loncommon::restore_course_settings('docs_log',
966: \%saveable_parameters);
967: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 968: # FIXME: internationalization seems wrong here
1.329 droeschl 969: my %lt=('hiddenresource' => 'Resources hidden',
970: 'encrypturl' => 'URL hidden',
971: 'randompick' => 'Randomly pick',
972: 'randomorder' => 'Randomly ordered',
973: 'set' => 'set to',
974: 'del' => 'deleted');
1.484 raeburn 975: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
976: $pathitem."\n".
977: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
978: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
979: $r->print('<div class="LC_left_float">'.
980: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
981: &makedocslogform($filter,1).
982: '</fieldset></div><br clear="all" />');
1.329 droeschl 983: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
984: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
985: &mt('After').'</th>'.
986: &Apache::loncommon::end_data_table_header_row());
987: my $shown=0;
988: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
989: if ($env{'form.displayfilter'} eq 'currentfolder') {
990: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
991: }
992: my @changes=keys(%{$docslog{$id}{'logentry'}});
993: if ($env{'form.displayfilter'} eq 'containing') {
994: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
995: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
996: foreach my $key (@changes) {
997: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
998: }
1.344 bisitz 999: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1000: }
1001: my $count = 0;
1002: my $time =
1003: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1004: my $plainname =
1005: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1006: $docslog{$id}{'exe_udom'});
1007: my $about_me_link =
1008: &Apache::loncommon::aboutmewrapper($plainname,
1009: $docslog{$id}{'exe_uname'},
1010: $docslog{$id}{'exe_udom'});
1011: my $send_msg_link='';
1012: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1013: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1014: $send_msg_link ='<br />'.
1015: &Apache::loncommon::messagewrapper(&mt('Send message'),
1016: $docslog{$id}{'exe_uname'},
1017: $docslog{$id}{'exe_udom'});
1018: }
1019: $r->print(&Apache::loncommon::start_data_table_row());
1020: $r->print('<td>'.$time.'</td>
1021: <td>'.$about_me_link.
1022: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1023: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1024: $send_msg_link.'</td><td>'.
1025: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1026: my $is_supp = 0;
1027: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1028: $is_supp = 1;
1029: }
1.329 droeschl 1030: # Before
1031: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1032: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1033: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1034: if ($oldname ne $newname) {
1.488 raeburn 1035: my $shown = &LONCAPA::map::qtescape($oldname);
1036: if ($is_supp) {
1037: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1038: }
1039: $r->print($shown);
1.329 droeschl 1040: }
1041: }
1042: $r->print('<ul>');
1043: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1044: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1045: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1046: if ($is_supp) {
1047: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1048: }
1049: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1050: }
1051: }
1052: $r->print('</ul>');
1053: # After
1054: $r->print('</td><td>');
1055:
1056: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1057: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1058: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1059: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1060: my $shown = &LONCAPA::map::qtescape($newname);
1061: if ($is_supp) {
1062: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1063: }
1064: $r->print($shown);
1.329 droeschl 1065: }
1.364 bisitz 1066: }
1.329 droeschl 1067: $r->print('<ul>');
1068: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1069: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1070: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1071: if ($is_supp) {
1072: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1073: }
1074: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1075: }
1076: }
1077: $r->print('</ul>');
1078: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1079: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1080: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1081: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1082: # FIXME: internationalization seems wrong here
1.329 droeschl 1083: $r->print('<li>'.
1084: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1085: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1086: .'</li>');
1087: }
1088: }
1089: $r->print('</ul>');
1090: }
1091: # End
1092: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1093: $shown++;
1094: if (!($env{'form.show'} eq &mt('all')
1095: || $shown<=$env{'form.show'})) { last; }
1096: }
1.484 raeburn 1097: $r->print(&Apache::loncommon::end_data_table()."\n".
1098: &makesimpleeditform($pathitem)."\n".
1099: '</div></div>');
1100: $r->print(&endContentScreen());
1.329 droeschl 1101: }
1102:
1103: sub update_paste_buffer {
1.492 raeburn 1104: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1105: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1106: if ($env{'form.multiremove'}) {
1107: $env{'form.multiremove'} =~ s/,$//;
1108: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1109: }
1110: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1111: if ($env{'form.multicut'}) {
1112: $env{'form.multicut'} =~ s/,$//;
1113: foreach my $item (split(/,/,$env{'form.multicut'})) {
1114: unless ($removals{$item}) {
1115: $cuts{$item} = 1;
1116: push(@possibles,$item.':cut');
1117: }
1118: }
1119: }
1120: if ($env{'form.multicopy'}) {
1121: $env{'form.multicopy'} =~ s/,$//;
1122: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1123: unless ($removals{$item} || $cuts{$item}) {
1124: push(@possibles,$item.':copy');
1125: }
1126: }
1127: }
1128: } elsif ($env{'form.markcopy'}) {
1129: @possibles = split(/,/,$env{'form.markcopy'});
1130: }
1.329 droeschl 1131:
1.538 raeburn 1132: return if (@possibles == 0);
1.329 droeschl 1133: return if (!defined($env{'form.copyfolder'}));
1134:
1135: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1136: $env{'form.copyfolder'});
1.538 raeburn 1137: return if ($fatal);
1138:
1139: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1140:
1.538 raeburn 1141: # Retrieve current paste buffer suffixes.
1142: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1143: my (%pasteurls,@newpaste);
1144:
1145: # Construct identifiers for current contents of user's paste buffer
1146: if (@currpaste) {
1147: foreach my $suffix (@currpaste) {
1148: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1149: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1150: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1151: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1152: ($url ne '')) {
1.597 raeburn 1153: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1154: }
1155: }
1156: }
1157:
1158: # Mark items for copying (skip any items already in user's paste buffer)
1159: my %addtoenv;
1.597 raeburn 1160:
1161: my @pathitems = split(/\&/,$env{'form.folderpath'});
1162: my @folderconf = split(/\:/,$pathitems[-1]);
1163: my $ispage = $folderconf[4];
1164:
1.538 raeburn 1165: foreach my $item (@possibles) {
1166: my ($orderidx,$cmd) = split(/:/,$item);
1167: next if ($orderidx =~ /\D/);
1168: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1169: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1170: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1171: my %denied = &action_restrictions($coursenum,$coursedom,
1172: &LONCAPA::map::qtescape($url),
1173: $env{'form.folderpath'},\%curr_groups);
1174: next if ($denied{'copy'});
1175: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1176: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1177: my ($suffix,$errortxt,$locknotfreed) =
1178: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1179: if ($suffix ne '') {
1180: push(@newpaste,$suffix);
1181: } else {
1182: if ($locknotfreed) {
1183: return $locknotfreed;
1184: }
1.538 raeburn 1185: }
1186: if (&is_supplemental_title($title)) {
1187: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1188: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1189: }
1.329 droeschl 1190:
1.538 raeburn 1191: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1192: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1193: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1194: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1195: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1196: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1197: my $prefix = $1;
1198: my $subdir =$2;
1199: if ($subdir eq '') {
1200: $subdir = $prefix;
1.492 raeburn 1201: }
1.538 raeburn 1202: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1203: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1204: \%hierarchy,\%titles,\%allmaps);
1205: if (ref($hierarchy{$url}) eq 'HASH') {
1206: my ($nested,$nestednames);
1207: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1208: $nested =~ s/\&$//;
1209: $nestednames =~ s/\Q___&&&___\E$//;
1210: if ($nested ne '') {
1211: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1212: }
1213: if ($nestednames ne '') {
1214: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1215: }
1.492 raeburn 1216: }
1217: }
1.591 raeburn 1218: if ($locknotfreed) {
1219: $output = $locknotfreed;
1220: last;
1221: }
1.492 raeburn 1222: }
1.538 raeburn 1223: if (@newpaste) {
1224: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1225: }
1.492 raeburn 1226: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1227: delete($env{'form.markcopy'});
1.591 raeburn 1228: return $output;
1.329 droeschl 1229: }
1230:
1.492 raeburn 1231: sub recurse_uploaded_maps {
1232: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1233: if (ref($hierarchy->{$url}) eq 'HASH') {
1234: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1235: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1236: my (@uploaded,@names,%shorter);
1237: for (my $i=0; $i<@maps; $i++) {
1238: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1239: if ($inner ne '') {
1240: push(@uploaded,$inner);
1241: push(@names,&escape($titles[$i]));
1242: $shorter{$maps[$i]} = $inner;
1243: }
1244: }
1245: $$nestref .= "$dir:".join(',',@uploaded).'&';
1246: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1247: foreach my $map (@maps) {
1248: if ($shorter{$map} ne '') {
1249: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1250: }
1251: }
1252: }
1253: return;
1254: }
1255:
1.329 droeschl 1256: sub print_paste_buffer {
1.492 raeburn 1257: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1258: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1259:
1.538 raeburn 1260: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1261: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1262: }
1263:
1.538 raeburn 1264: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1265: my ($pasteitems,@pasteable);
1.575 raeburn 1266: my $clipboardcount = 0;
1.488 raeburn 1267:
1.538 raeburn 1268: # Construct identifiers for current contents of user's paste buffer
1269: foreach my $suffix (@currpaste) {
1270: next if ($suffix =~ /\D/);
1271: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1272: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1273: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1274: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1275: ($url ne '')) {
1.575 raeburn 1276: $clipboardcount ++;
1.538 raeburn 1277: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1278: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1279: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1280: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1281: $is_external = 1;
1.598 raeburn 1282: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
1283: $is_exttool = 1;
1.538 raeburn 1284: }
1285: if ($folder =~ /^supplemental/) {
1286: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1287: unless ($canpaste) {
1288: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1289: }
1290: } else {
1291: $canpaste = 1;
1292: }
1293: if ($canpaste) {
1294: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1295: my $srcdom = $1;
1296: my $srcnum = $2;
1297: my $rem = $3;
1298: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1299: $othercourse = 1;
1300: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1301: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1302: } else {
1303: $canpaste = 0;
1304: $nopaste = &mt('Paste from another course unavailable.');
1305: }
1306: }
1307: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1308: my $prefix = $1;
1309: $parent = $2;
1310: if ($folder !~ /^\Q$prefix\E/) {
1311: $areachange = 1;
1312: }
1313: $is_uploaded_map = 1;
1.492 raeburn 1314: }
1.597 raeburn 1315: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1316: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1317: if ($cid ne $env{'request.course.id'}) {
1318: my ($srcdom,$srcnum) = split(/_/,$cid);
1319: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1320: $othercrs = '<br />'.&mt('(from another course)');
1321: } else {
1322: $canpaste = 0;
1323: $nopaste = &mt('Paste from another course unavailable.');
1324: }
1325: }
1.492 raeburn 1326: }
1.596 raeburn 1327: if ($canpaste) {
1328: push(@pasteable,$suffix);
1329: }
1.538 raeburn 1330: }
1331: my $buffer;
1.598 raeburn 1332: if (($is_external) || ($is_exttool)) {
1.538 raeburn 1333: $buffer = &mt('External Resource').': '.
1334: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1335: &LONCAPA::map::qtescape($url).')';
1336: } else {
1337: my $icon = &Apache::loncommon::icon($extension);
1338: if ($extension eq 'sequence' &&
1339: $url =~ m{/default_\d+\.sequence$}x) {
1340: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1341: $icon .= '/navmap.folder.closed.gif';
1342: }
1.589 raeburn 1343: my $title = $env{'docs.markedcopy_title_'.$suffix};
1344: if ($title eq '') {
1345: ($title) = ($url =~ m{/([^/]+)$});
1346: }
1.538 raeburn 1347: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1348: ': '.
1349: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1350: &LONCAPA::map::qtescape($title));
1.538 raeburn 1351: }
1352: $pasteitems .= '<div class="LC_left_float">';
1353: my ($options,$onclick);
1354: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1355: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1356: if (($is_uploaded_map) ||
1357: ($url =~ /(bulletinboard|smppg)$/) ||
1358: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1359: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1360: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1361: }
1362: }
1363: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1364: if ($nopaste) {
1365: $pasteitems .= $nopaste;
1366: } else {
1367: if ($othercrs) {
1368: $pasteitems .= $othercrs;
1369: }
1370: if ($options) {
1371: $pasteitems .= $options;
1.492 raeburn 1372: }
1373: }
1.538 raeburn 1374: $pasteitems .= '</div>';
1375: }
1376: }
1377: if ($pasteitems eq '') {
1378: &Apache::lonnet::delenv('docs.markedcopies');
1379: }
1380: my ($pasteform,$form_start,$buttons,$form_end);
1381: if ($pasteitems) {
1382: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1383: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1384: if (@pasteable) {
1.575 raeburn 1385: my $value = &mt('Paste to current folder');
1386: if ($container eq 'page') {
1387: $value = &mt('Paste to current page');
1388: }
1389: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1390: }
1391: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1392: if ($clipboardcount > 1) {
1393: $buttons .=
1394: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1395: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1396: (' 'x2).
1397: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1398: (' 'x2);
1.492 raeburn 1399: }
1.575 raeburn 1400: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1401: '</form>';
1.538 raeburn 1402: } else {
1403: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1404: }
1.538 raeburn 1405: $r->print($form_start
1406: .'<fieldset>'
1407: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1408: .$pasteitems
1409: .'</fieldset>'
1410: .$form_end);
1411: }
1412:
1413: sub paste_options {
1414: my ($suffix,$is_uploaded_map,$parent) = @_;
1415: my ($copytext,$movetext);
1416: if ($is_uploaded_map) {
1417: $copytext = &mt('Copy to new folder');
1418: $movetext = &mt('Move old');
1419: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1420: $copytext = &mt('Copy to new board');
1421: $movetext = &mt('Move (not posts)');
1422: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1423: $copytext = &mt('Copy to new page');
1424: $movetext = &mt('Move');
1.533 raeburn 1425: } else {
1.538 raeburn 1426: $copytext = &mt('Copy to new file');
1427: $movetext = &mt('Move');
1428: }
1429: my $output = '<br />'.
1430: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1431: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1432: '<label>'.
1433: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1434: $copytext.'</label></span>'.(' 'x2).' '.
1435: '<span class="LC_nobreak"><label>'.
1436: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1437: $movetext.'</label></span>';
1438: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1439: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1440: '</legend><table border="0">';
1441: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1442: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1443: my $lastdir = $parent;
1444: my %depths = (
1445: $lastdir => 0,
1446: );
1447: my (%display,%deps);
1448: for (my $i=0; $i<@pastemaps; $i++) {
1449: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1450: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1451: my @subfolders = split(/,/,$subfolderstr);
1452: $deps{$lastdir} = \@subfolders;
1453: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1454: my $depth = $depths{$lastdir} + 1;
1455: my $offset = int($depth * 4);
1456: my $indent = (' ' x $offset);
1457: for (my $j=0; $j<@subfolders; $j++) {
1458: $depths{$subfolders[$j]} = $depth;
1459: $display{$subfolders[$j]} =
1460: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1461: '<td><label>'.
1462: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1463: '<label>'.
1464: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1465: &mt('Move old').'</label>'.
1466: '</td></tr>';
1467: }
1.492 raeburn 1468: }
1.538 raeburn 1469: &recurse_print(\$output,$parent,\%deps,\%display);
1470: $output .= '</table></fieldset>';
1.329 droeschl 1471: }
1.538 raeburn 1472: $output .= '</div>';
1473: return $output;
1.488 raeburn 1474: }
1475:
1.492 raeburn 1476: sub recurse_print {
1.538 raeburn 1477: my ($outputref,$dir,$deps,$display) = @_;
1478: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1479: if (ref($deps->{$dir}) eq 'ARRAY') {
1480: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1481: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1482: }
1483: }
1484: }
1485:
1.488 raeburn 1486: sub supp_pasteable {
1487: my ($url) = @_;
1488: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1489: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1490: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1491: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1492: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1493: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
1.488 raeburn 1494: return 1;
1495: }
1496: return;
1.329 droeschl 1497: }
1498:
1.492 raeburn 1499: sub paste_popup_js {
1.594 damieng 1500: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1501: show => 'Show Options',
1502: hide => 'Hide Options',
1.594 damieng 1503: );
1504: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1505: none => 'No items selected from clipboard.',
1.492 raeburn 1506: );
1.594 damieng 1507: &html_escape(\%html_js_lt);
1508: &js_escape(\%html_js_lt);
1509: &js_escape(\%js_lt);
1.492 raeburn 1510: return <<"END";
1511:
1.538 raeburn 1512: function showPasteOptions(suffix) {
1513: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1514: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1515: return;
1516: }
1517:
1.538 raeburn 1518: function hidePasteOptions(suffix) {
1519: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1520: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1521: return;
1522: }
1523:
1524: function showOptions(caller,suffix) {
1525: if (document.getElementById('pasteoptionstext_'+suffix)) {
1526: if (caller.checked) {
1.594 damieng 1527: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1528: } else {
1529: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1530: }
1531: if (document.getElementById('pasteoptions_'+suffix)) {
1532: document.getElementById('pasteoptions_'+suffix).style.display='none';
1533: }
1534: }
1.492 raeburn 1535: return;
1536: }
1537:
1.541 raeburn 1538: function validateClipboard() {
1539: var numchk = 0;
1540: if (document.pasteform.pasting.length > 1) {
1541: for (var i=0; i<document.pasteform.pasting.length; i++) {
1542: if (document.pasteform.pasting[i].checked) {
1543: numchk ++;
1544: }
1545: }
1546: } else {
1547: if (document.pasteform.pasting.type == 'checkbox') {
1548: if (document.pasteform.pasting.checked) {
1549: numchk ++;
1550: }
1551: }
1552: }
1553: if (numchk > 0) {
1554: return true;
1555: } else {
1.594 damieng 1556: alert("$js_lt{'none'}");
1.541 raeburn 1557: return false;
1558: }
1559: }
1560:
1.575 raeburn 1561: function checkClipboard() {
1562: if (document.pasteform.pasting.length > 1) {
1563: for (var i=0; i<document.pasteform.pasting.length; i++) {
1564: document.pasteform.pasting[i].checked = true;
1565: }
1566: }
1567: return;
1568: }
1569:
1570: function uncheckClipboard() {
1571: if (document.pasteform.pasting.length >1) {
1572: for (var i=0; i<document.pasteform.pasting.length; i++) {
1573: document.pasteform.pasting[i].checked = false;
1574: }
1575: }
1576: return;
1577: }
1578:
1.492 raeburn 1579: END
1580:
1581: }
1582:
1.329 droeschl 1583: sub do_paste_from_buffer {
1.492 raeburn 1584: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1585:
1.538 raeburn 1586: # Array of items in paste buffer
1587: my (@currpaste,%pastebuffer,%allerrors);
1588: @currpaste = split(/,/,$env{'docs.markedcopies'});
1589:
1.492 raeburn 1590: # Early out if paste buffer is empty
1.538 raeburn 1591: if (@currpaste == 0) {
1.492 raeburn 1592: return ();
1.538 raeburn 1593: }
1594: map { $pastebuffer{$_} = 1; } @currpaste;
1595:
1596: # Array of items selected items to paste
1597: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1598:
1599: # Early out if nothing selected to paste
1600: if (@reqpaste == 0) {
1601: return();
1602: }
1603: my @topaste;
1604: foreach my $suffix (@reqpaste) {
1605: next if ($suffix =~ /\D/);
1606: next unless (exists($pastebuffer{$suffix}));
1607: push(@topaste,$suffix);
1608: }
1609:
1610: # Early out if nothing available to paste
1611: if (@topaste == 0) {
1612: return();
1.329 droeschl 1613: }
1614:
1.538 raeburn 1615: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.597 raeburn 1616: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1617:
1618: foreach my $suffix (@topaste) {
1619: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1620: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1621: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1622: # Supplemental content may only include certain types of content
1623: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1624: if ($folder =~ /^supplemental/) {
1625: unless (&supp_pasteable($url)) {
1626: $notinsupp{$suffix} = 1;
1627: next;
1628: }
1.492 raeburn 1629: }
1.538 raeburn 1630: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1631: my $srcd = $1;
1632: my $srcn = $2;
1.492 raeburn 1633: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1634: # check for mdc privilege in the course from which the resource was pasted
1635: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1636: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1637: $notincrs{$suffix} = 1;
1638: next;
1639: }
1.491 raeburn 1640: }
1.538 raeburn 1641: $srcdom{$suffix} = $srcd;
1642: $srcnum{$suffix} = $srcn;
1.597 raeburn 1643: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1644: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1645: my ($srcd,$srcn) = split(/_/,$cid);
1646: # When paste buffer was populated using an active role in a different course
1647: # check for mdc privilege in the course from which the resource was pasted
1648: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1649: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1650: $notincrs{$suffix} = 1;
1651: next;
1652: }
1653: }
1654: $srcdom{$suffix} = $srcd;
1655: $srcnum{$suffix} = $srcn;
1.491 raeburn 1656: }
1.597 raeburn 1657: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1658: push(@dopaste,$suffix);
1659: if ($url=~/\.(page|sequence)$/) {
1660: $is_map{$suffix} = 1;
1661: }
1662:
1663: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1664: my $oldprefix = $1;
1.492 raeburn 1665: # When pasting content from Main Content to Supplemental Content and vice versa
1666: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1667: # a folder/page or a document).
1.538 raeburn 1668: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1669: $prefixchg{$suffix} = 'docstosupp';
1670: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1671: $prefixchg{$suffix} = 'supptodocs';
1672: }
1.491 raeburn 1673:
1.492 raeburn 1674: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1675: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1676: my @nested;
1677: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1678: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1679: my @deps = map { /\d+:([\d,]+$)/ } @items;
1680: foreach my $dep (@deps) {
1681: if ($dep =~ /,/) {
1682: push(@nested,split(/,/,$dep));
1683: } else {
1684: push(@nested,$dep);
1685: }
1.492 raeburn 1686: }
1.538 raeburn 1687: foreach my $item (@nested) {
1688: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1689: push(@{$marktomove{$suffix}},$type.'_'.$item);
1690: }
1.492 raeburn 1691: }
1692: }
1.488 raeburn 1693: }
1694: }
1695:
1.538 raeburn 1696: # Early out if nothing available to paste
1697: if (@dopaste == 0) {
1698: return ();
1699: }
1700:
1701: # Populate message hash and hashes used for main content <=> supplemental content
1702: # changes
1703:
1704: %msgs = &Apache::lonlocal::texthash (
1705: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1706: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1707: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1708: );
1709:
1710: %before = (
1711: docstosupp => {
1712: map => 'default',
1713: doc => 'docs',
1714: },
1715: supptodocs => {
1716: map => 'supplemental',
1717: doc => 'supplemental',
1718: },
1719: );
1720:
1721: %after = (
1722: docstosupp => {
1723: map => 'supplemental',
1724: doc => 'supplemental'
1725: },
1726: supptodocs => {
1727: map => 'default',
1728: doc => 'docs',
1729: },
1730: );
1731:
1732: # Retrieve information about all course maps in main content area
1733:
1734: my $allmaps = {};
1735: if ($folder =~ /^default/) {
1736: $allmaps =
1737: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1738: $env{"course.$env{'request.course.id'}.home"},
1739: $env{'request.course.id'});
1740: }
1741:
1742: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1743:
1744: # Loop over the items to paste
1745: foreach my $suffix (@dopaste) {
1.329 droeschl 1746: # Maps need to be copied first
1.538 raeburn 1747: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1748: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1749: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1750: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1751: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1752: }
1753: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1754: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1755: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1756: my $oldurl = $url;
1757: if ($is_map{$suffix}) {
1.491 raeburn 1758: # If pasting a map, check if map contains other maps
1.538 raeburn 1759: my (%hierarchy,%titles);
1760: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1761: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1762: if ($url=~ m{^/uploaded/}) {
1763: my $newurl;
1764: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1765: ($newurl,my $error) =
1766: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1767: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1768: \$title,$allmaps,\%newurls);
1769: if ($error) {
1770: $allerrors{$suffix} = $error;
1771: next;
1772: }
1773: if ($newurl ne '') {
1774: if ($newurl ne $url) {
1775: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1776: $newsubdir{$url} = $1;
1777: }
1778: $mapchanges{$url} = 1;
1.492 raeburn 1779: }
1.538 raeburn 1780: }
1781: }
1782: if (($srcdom{$suffix} ne $coursedom) ||
1783: ($srcnum{$suffix} ne $coursenum) ||
1784: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1785: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1786: $coursedom,$coursenum,$srcdom{$suffix},
1787: $srcnum{$suffix},$allmaps,\%rewrites,
1788: \%retitles,\%copies,\%dbcopies,
1789: \%zombies,\%params,\%mapmoves,
1790: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1791: \%newurls,\%resdatacopy)) {
1.538 raeburn 1792: $mapmoves{$url} = 1;
1793: }
1794: $url = $newurl;
1795: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1796: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1797: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1798: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1799: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1800: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1801: }
1802: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1803: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1804: push(@toclear,$suffix);
1805: # if pasting published map (main content area only) check map not already in course
1806: if ($folder =~ /^default/) {
1807: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1808: $duplicate{$suffix} = 1;
1809: next;
1.492 raeburn 1810: }
1.491 raeburn 1811: }
1812: }
1.538 raeburn 1813: }
1814: if ($url=~ m{/(bulletinboard|smppg)$}) {
1815: my $prefix = $1;
1.596 raeburn 1816: my $fromothercrs;
1.538 raeburn 1817: #need to copy the db contents to a new one, unless this is a move.
1818: my %info = (
1819: src => $url,
1820: cdom => $coursedom,
1821: cnum => $coursenum,
1.596 raeburn 1822: );
1823: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1824: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1825: $fromothercrs = 1;
1826: $info{'cdom'} = $srcdom{$suffix};
1827: $info{'cnum'} = $srcnum{$suffix};
1828: }
1829: }
1830: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.538 raeburn 1831: my (%lockerr,$msg);
1832: my ($newurl,$result,$errtext) =
1833: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1834: if ($result eq 'ok') {
1835: $url = $newurl;
1836: $title=&mt('Copy of').' '.$title;
1837: } else {
1838: if ($prefix eq 'smppg') {
1839: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1840: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1841: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.538 raeburn 1842: }
1843: $results{$suffix} = $result;
1844: $msgerrs{$suffix} = $msg;
1845: $lockerrs{$suffix} = $lockerr{$prefix};
1846: next;
1847: }
1848: if ($lockerr{$prefix}) {
1849: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1850: }
1.489 raeburn 1851: }
1852: }
1.538 raeburn 1853: $title = &LONCAPA::map::qtunescape($title);
1854: my $ext='false';
1855: if ($url=~m{^http(|s)://}) { $ext='true'; }
1856: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1857: if ($folder !~ /^supplemental/) {
1858: (undef,undef,$title) =
1859: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1860: }
1861: } else {
1862: if ($folder=~/^supplemental/) {
1863: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1864: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1865: }
1.533 raeburn 1866: }
1.491 raeburn 1867:
1868: # For uploaded files (excluding pages/sequences) path in copied file is changed
1869: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1870: # courses.
1871:
1.538 raeburn 1872: unless ($is_map{$suffix}) {
1873: my $newidx;
1.492 raeburn 1874: # Now insert the URL at the bottom
1.538 raeburn 1875: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1876: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1877: my $relpath = $1;
1878: if ($relpath ne '') {
1879: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1880: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1881: my $newprefix = $newloc;
1882: if ($newloc eq 'default') {
1883: $newprefix = 'docs';
1884: }
1885: if ($newdocsdir eq '') {
1886: $newdocsdir = 'default';
1887: }
1888: if (($prefixchg{$suffix}) ||
1889: ($srcdom{$suffix} ne $coursedom) ||
1890: ($srcnum{$suffix} ne $coursenum) ||
1891: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1892: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1893: $url =
1894: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1895: &Apache::lonnet::getfile($oldurl));
1896: if ($url eq '/adm/notfound.html') {
1897: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1898: next;
1899: } else {
1900: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1901: $newsubpath =~ s{/+$}{/};
1902: $docmoves{$oldurl} = $newsubpath;
1903: }
1.491 raeburn 1904: }
1905: }
1.597 raeburn 1906: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1907: my $template = $1;
1908: if ($newidx) {
1909: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1910: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1911: }
1.491 raeburn 1912: }
1.538 raeburn 1913: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1914: ':'.$ext.':normal:res';
1915: push(@LONCAPA::map::order,$newidx);
1916: # Store the result
1917: my ($errtext,$fatal) =
1918: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1919: if ($fatal) {
1920: $save_err .= $errtext;
1921: $allresult = 'fail';
1922: }
1.488 raeburn 1923: }
1.538 raeburn 1924:
1.597 raeburn 1925: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1926: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1927: unless ($allresult eq 'fail') {
1928: my %updated = (
1929: rewrites => \%rewrites,
1930: zombies => \%zombies,
1931: removefrommap => \%removefrommap,
1932: removeparam => \%removeparam,
1933: dbcopies => \%dbcopies,
1.597 raeburn 1934: resdatacopy => \%resdatacopy,
1.538 raeburn 1935: retitles => \%retitles,
1936: );
1937: my %info = (
1938: newsubdir => \%newsubdir,
1939: params => \%params,
1940: );
1941: if ($prefixchg{$suffix}) {
1942: $info{'before'} = $before{$prefixchg{$suffix}};
1943: $info{'after'} = $after{$prefixchg{$suffix}};
1944: }
1945: my %moves = (
1946: copies => \%copies,
1947: docmoves => \%docmoves,
1948: mapmoves => \%mapmoves,
1949: );
1950: (my $result,$msgs{$suffix},my $lockerror) =
1951: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1952: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1953: $url,'paste');
1954: $lockerrors .= $lockerror;
1955: if ($result eq 'ok') {
1956: if ($is_map{$suffix}) {
1957: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1958: $folder.'.'.$container);
1959: if ($fatal) {
1960: $allresult = 'failread';
1961: } else {
1962: if ($#LONCAPA::map::order<1) {
1963: my $idx=&LONCAPA::map::getresidx();
1964: if ($idx<=0) { $idx=1; }
1965: $LONCAPA::map::order[0]=$idx;
1966: $LONCAPA::map::resources[$idx]='';
1967: }
1968: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1969: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1970: ':'.$ext.':normal:res';
1971: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 1972:
1973: # Store the result
1.538 raeburn 1974: my ($errtext,$fatal) =
1975: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1976: if ($fatal) {
1977: $save_err .= $errtext;
1978: $allresult = 'failstore';
1979: }
1980: }
1981: }
1982: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1983: push(@toclear,$suffix);
1984: }
1985: }
1.492 raeburn 1986: }
1987: }
1.538 raeburn 1988: &clear_from_buffer(\@toclear,\@currpaste);
1989: my $msgsarray;
1990: foreach my $suffix (keys(%msgs)) {
1991: if (ref($msgs{$suffix}) eq 'ARRAY') {
1992: $msgsarray .= join(',',@{$msgs{$suffix}});
1993: }
1994: }
1995: return ($allresult,$save_err,$msgsarray,$lockerrors);
1996: }
1.533 raeburn 1997:
1.538 raeburn 1998: sub do_buffer_empty {
1999: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2000: if (@currpaste == 0) {
2001: return &mt('Clipboard is already empty');
2002: }
2003: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2004: if (@toclear == 0) {
2005: return &mt('Nothing selected to clear from clipboard');
2006: }
2007: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2008: if ($numdel) {
2009: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2010: } else {
2011: return &mt('Clipboard unchanged');
1.492 raeburn 2012: }
1.538 raeburn 2013: return;
2014: }
2015:
2016: sub clear_from_buffer {
2017: my ($toclear,$currpaste) = @_;
2018: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2019: my %pastebuffer;
2020: map { $pastebuffer{$_} = 1; } @{$currpaste};
2021: my $numdel = 0;
2022: foreach my $suffix (@{$toclear}) {
2023: next if ($suffix =~ /\D/);
2024: next unless (exists($pastebuffer{$suffix}));
2025: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2026: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2027: delete($pastebuffer{$suffix});
2028: $numdel ++;
2029: }
2030: }
2031: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2032: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2033: return $numdel;
1.492 raeburn 2034: }
2035:
2036: sub get_newmap_url {
2037: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2038: $titleref,$allmaps,$newurls) = @_;
2039: my $newurl;
2040: if ($url=~ m{^/uploaded/}) {
2041: $$titleref=&mt('Copy of').' '.$$titleref;
2042: }
2043: my $now = time;
2044: my $suffix=$$.int(rand(100)).$now;
2045: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2046: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2047: my $path = $1;
2048: my $prefix = $2;
2049: my $ancestor = $3;
2050: if (length($ancestor) > 10) {
2051: $ancestor = substr($ancestor,-10,10);
2052: }
2053: my $newid;
2054: if ($prefixchg) {
2055: if ($folder =~ /^supplemental/) {
2056: $prefix =~ s/^default/supplemental/;
2057: } else {
2058: $prefix =~ s/^supplemental/default/;
2059: }
2060: }
2061: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2062: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2063: } else {
2064: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2065: }
2066: my $counter = 0;
2067: my $is_unique = &uniqueness_check($newurl);
2068: if ($folder =~ /^default/) {
2069: if ($allmaps->{$newurl}) {
2070: $is_unique = 0;
2071: }
2072: }
2073: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2074: $counter ++;
2075: $suffix ++;
2076: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2077: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2078: } else {
2079: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2080: }
2081: $is_unique = &uniqueness_check($newurl);
2082: }
2083: if ($is_unique) {
2084: $newurls->{$newurl} = 1;
2085: } else {
2086: if ($url=~/\.page$/) {
2087: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2088: } else {
2089: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2090: }
2091: }
1.329 droeschl 2092: }
1.492 raeburn 2093: return ($newurl);
1.329 droeschl 2094: }
2095:
1.488 raeburn 2096: sub dbcopy {
1.533 raeburn 2097: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2098: my ($url,$result,$errtext);
2099: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2100: $url = $dbref->{'src'};
1.533 raeburn 2101: if ($url =~ m{/(smppg|bulletinboard)$}) {
2102: my $prefix = $1;
2103: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2104: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2105: my $db_name;
2106: my $marker = (split(m{/},$url))[4];
2107: $marker=~s/\D//g;
2108: if ($dbref->{'src'} =~ m{/smppg$}) {
2109: $db_name =
2110: &Apache::lonsimplepage::get_db_name($url,$marker,
2111: $dbref->{'cdom'},
2112: $dbref->{'cnum'});
2113: } else {
2114: $db_name = 'bulletinpage_'.$marker;
2115: }
2116: my ($suffix,$freedlock,$error) =
2117: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2118: $coursedom,$coursenum,
2119: 'concat');
2120: if (!$suffix) {
2121: if ($prefix eq 'smppg') {
2122: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2123: } else {
1.565 bisitz 2124: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2125: }
2126: if ($error) {
2127: $errtext .= '<br />'.$error;
2128: }
2129: } else {
2130: #need to copy the db contents to a new one.
2131: my %contents=&Apache::lonnet::dump($db_name,
2132: $dbref->{'cdom'},
2133: $dbref->{'cnum'});
2134: if (exists($contents{'uploaded.photourl'})) {
2135: my $photo = $contents{'uploaded.photourl'};
2136: my ($subdir,$fname) =
2137: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2138: my $newphoto;
1.533 raeburn 2139: if ($fname ne '') {
2140: my $content = &Apache::lonnet::getfile($photo);
2141: unless ($content eq '-1') {
2142: $env{'form.'.$suffix.'.photourl'} = $content;
2143: $newphoto =
2144: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2145: delete($env{'form.'.$suffix.'.photourl'});
2146: }
2147: }
2148: if ($newphoto =~ m{^/uploaded/}) {
2149: $contents{'uploaded.photourl'} = $newphoto;
2150: }
2151: }
2152: $db_name =~ s{_\d*$ }{_$suffix}x;
2153: $result=&Apache::lonnet::put($db_name,\%contents,
2154: $coursedom,$coursenum);
2155: if ($result eq 'ok') {
2156: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2157: }
2158: }
2159: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2160: $lockerrorsref->{$prefix} =
1.533 raeburn 2161: '<div class="LC_error">'.
2162: &mt('There was a problem removing a lockfile.');
2163: if ($prefix eq 'smppg') {
1.560 raeburn 2164: $lockerrorsref->{$prefix} .=
1.559 raeburn 2165: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.533 raeburn 2166: } else {
1.565 bisitz 2167: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2168: }
1.560 raeburn 2169: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2170: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2171: '</div>';
1.533 raeburn 2172: }
2173: }
2174: } elsif ($url =~ m{/syllabus$}) {
2175: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2176: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2177: if (($dbref->{'cdom'} ne $coursedom) ||
2178: ($dbref->{'cnum'} ne $coursenum)) {
2179: my %contents=&Apache::lonnet::dump('syllabus',
2180: $dbref->{'cdom'},
2181: $dbref->{'cnum'});
2182: $result=&Apache::lonnet::put('syllabus',\%contents,
2183: $coursedom,$coursenum);
2184: }
2185: }
1.488 raeburn 2186: }
2187: }
1.533 raeburn 2188: return ($url,$result,$errtext);
1.488 raeburn 2189: }
2190:
1.597 raeburn 2191: sub copy_templated_files {
2192: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2193: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2194: my $srccontainer = 'sequence';
2195: if ($srcwaspage) {
2196: $srccontainer = 'page';
2197: }
2198: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2199: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2200: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2201: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2202: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2203: $template.'.problem';
2204: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2205: if ($template eq 'simpleproblem') {
2206: $srcprefix .= '.0.';
2207: my $weightprefix = $newprefix;
2208: $newprefix .= '.0.';
2209: my @simpleprobqtypes = qw(radio option string essay numerical);
2210: my $qtype=$srcparms{$srcprefix.'questiontype'};
2211: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2212: my %newdata;
2213: foreach my $type (@simpleprobqtypes) {
2214: if ($type eq $qtype) {
2215: $newdata{"$weightprefix.$type.weight"}=1;
2216: } else {
2217: $newdata{"$weightprefix.$type.weight"}=0;
2218: }
2219: }
2220: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2221: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2222: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2223: if ($qtype eq 'numerical') {
2224: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2225: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2226: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2227: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2228: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2229: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2230: unless (defined($maxfoils)) { $maxfoils=10; }
2231: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2232: if ($maxfoils<=0) { $maxfoils=10; }
2233: my $randomize=$srcparms{$srcprefix.'randomize'};
2234: unless (defined($randomize)) { $randomize='yes'; }
2235: unless ($randomize eq 'no') { $randomize='yes'; }
2236: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2237: $newdata{$newprefix.'randomize'} = $randomize;
2238: if ($qtype eq 'option') {
2239: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2240: }
2241: for (my $i=1; $i<=10; $i++) {
2242: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2243: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2244: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2245: }
2246:
2247: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2248: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2249: unless (defined($maxfoils)) { $maxfoils=10; }
2250: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2251: if ($maxfoils<=0) { $maxfoils=10; }
2252: my $randomize=$srcparms{$srcprefix.'randomize'};
2253: unless (defined($randomize)) { $randomize='yes'; }
2254: unless ($randomize eq 'no') { $randomize='yes'; }
2255: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2256: $newdata{$newprefix.'randomize'} = $randomize;
2257: if ($qtype eq 'option') {
2258: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2259: }
2260: for (my $i=1; $i<=10; $i++) {
2261: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2262: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2263: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2264: }
2265: } elsif ($qtype eq 'string') {
2266: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2267: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2268: }
2269: if (keys(%newdata)) {
2270: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2271: $coursenum);
2272: if ($putres eq 'ok') {
2273: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2274: }
2275: }
2276: }
2277: }
2278: }
2279:
1.329 droeschl 2280: sub uniqueness_check {
2281: my ($newurl) = @_;
2282: my $unique = 1;
2283: foreach my $res (@LONCAPA::map::order) {
2284: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2285: $url=&LONCAPA::map::qtescape($url);
2286: if ($newurl eq $url) {
2287: $unique = 0;
1.344 bisitz 2288: last;
1.329 droeschl 2289: }
2290: }
2291: return $unique;
2292: }
2293:
1.488 raeburn 2294: sub contained_map_check {
1.492 raeburn 2295: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2296: $allmaps) = @_;
1.488 raeburn 2297: my $content = &Apache::lonnet::getfile($url);
2298: unless ($content eq '-1') {
2299: my $parser = HTML::TokeParser->new(\$content);
2300: $parser->attr_encoded(1);
2301: while (my $token = $parser->get_token) {
2302: next if ($token->[0] ne 'S');
2303: if ($token->[1] eq 'resource') {
2304: next if ($token->[2]->{'type'} eq 'zombie');
2305: my $ressrc = $token->[2]->{'src'};
2306: if ($folder =~ /^supplemental/) {
2307: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2308: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2309: next;
2310: }
2311: }
1.492 raeburn 2312: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2313: if ($1 eq 'uploaded') {
2314: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2315: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2316: } else {
1.492 raeburn 2317: if ($allmaps->{$ressrc}) {
1.529 raeburn 2318: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2319: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2320: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2321: } else {
2322: $addedmaps->{$ressrc} = [$url];
2323: }
1.488 raeburn 2324: }
1.492 raeburn 2325: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2326: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2327: }
1.492 raeburn 2328: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2329: if ($folder =~ /^supplemental/) {
1.492 raeburn 2330: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2331: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2332: } else {
2333: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2334: }
1.488 raeburn 2335: }
2336: }
2337: }
2338: }
2339: return;
2340: }
2341:
2342: sub url_paste_fixups {
1.533 raeburn 2343: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2344: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2345: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2346: my $checktitle;
2347: if (($prefixchg) &&
1.492 raeburn 2348: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2349: $checktitle = 1;
2350: }
1.492 raeburn 2351: my $skip;
2352: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2353: my $mapid = $1.$2;
2354: if ($tomove->{$mapid}) {
2355: $skip = 1;
2356: }
2357: }
1.491 raeburn 2358: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2359: return if ($file eq '-1');
2360: my $parser = HTML::TokeParser->new(\$file);
2361: $parser->attr_encoded(1);
1.491 raeburn 2362: my $changed = 0;
1.488 raeburn 2363: while (my $token = $parser->get_token) {
2364: next if ($token->[0] ne 'S');
2365: if ($token->[1] eq 'resource') {
2366: my $ressrc = $token->[2]->{'src'};
2367: next if ($ressrc eq '');
1.491 raeburn 2368: my $id = $token->[2]->{'id'};
1.492 raeburn 2369: my $title = $token->[2]->{'title'};
1.491 raeburn 2370: if ($checktitle) {
2371: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2372: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2373: }
2374: }
1.488 raeburn 2375: next if ($token->[2]->{'type'} eq 'external');
2376: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2377: next if ($skip);
1.532 raeburn 2378: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2379: $changed = 1;
2380: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2381: my $srcdom = $1;
2382: my $srcnum = $2;
1.488 raeburn 2383: my $rem = $3;
1.492 raeburn 2384: my $newurl;
2385: my $mapname;
2386: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2387: my $prefix = $1;
2388: $mapname = $prefix.$2;
2389: if ($tomove->{$mapname}) {
1.533 raeburn 2390: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2391: $srcdom,$srcnum,$allmaps,$rewrites,
2392: $retitles,$copies,$dbcopies,$zombies,
2393: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2394: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2395: next;
2396: } else {
2397: ($newurl,my $error) =
2398: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2399: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2400: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2401: $newsubdir->{$ressrc} = $1;
2402: }
2403: if ($error) {
2404: next;
2405: }
2406: }
2407: }
2408: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2409: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2410:
1.488 raeburn 2411: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2412: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2413: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2414: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2415: $cnum,$srcdom,$srcnum,$allmaps,
2416: $rewrites,$retitles,$copies,$dbcopies,
2417: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2418: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2419: $mapmoves->{$ressrc} = 1;
2420: }
2421: $changed = 1;
1.488 raeburn 2422: } else {
1.532 raeburn 2423: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2424: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2425: $changed = 1;
1.488 raeburn 2426: }
2427: }
1.533 raeburn 2428: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2429: next if ($skip);
1.492 raeburn 2430: my $srcdom = $1;
2431: my $srcnum = $2;
2432: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2433: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2434: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2435: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2436: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2437: $changed = 1;
2438: }
2439: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2440: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2441: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2442: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2443: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2444: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2445: $changed = 1;
1.488 raeburn 2446: }
1.597 raeburn 2447: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2448: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2449: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2450: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2451: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2452: }
1.488 raeburn 2453: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2454: next if ($skip);
2455: my $srcdom = $1;
2456: my $srcnum = $2;
2457: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2458: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2459: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2460: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2461: $changed = 1;
1.488 raeburn 2462: }
2463: }
2464: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2465: next if ($skip);
1.488 raeburn 2466: my $to = $token->[2]->{'to'};
2467: if ($to ne '') {
2468: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2469: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2470: } else {
2471: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2472: }
2473: }
2474: }
2475: }
1.491 raeburn 2476: return $changed;
1.488 raeburn 2477: }
2478:
2479: sub apply_fixups {
1.529 raeburn 2480: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2481: $oldurl,$url,$caller) = @_;
2482: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2483: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2484: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2485: if (ref($updated) eq 'HASH') {
2486: if (ref($updated->{'rewrites'}) eq 'HASH') {
2487: %rewrites = %{$updated->{'rewrites'}};
2488: }
2489: if (ref($updated->{'zombies'}) eq 'HASH') {
2490: %zombies = %{$updated->{'zombies'}};
2491: }
2492: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2493: %removefrommap = %{$updated->{'removefrommap'}};
2494: }
2495: if (ref($updated->{'removeparam'}) eq 'HASH') {
2496: %removeparam = %{$updated->{'removeparam'}};
2497: }
2498: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2499: %dbcopies = %{$updated->{'dbcopies'}};
2500: }
2501: if (ref($updated->{'retitles'}) eq 'HASH') {
2502: %retitles = %{$updated->{'retitles'}};
2503: }
1.597 raeburn 2504: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2505: %resdatacopy = %{$updated->{'resdatacopy'}};
2506: }
1.529 raeburn 2507: }
2508: if (ref($info) eq 'HASH') {
2509: if (ref($info->{'newsubdir'}) eq 'HASH') {
2510: %newsubdir = %{$info->{'newsubdir'}};
2511: }
2512: if (ref($info->{'params'}) eq 'HASH') {
2513: %params = %{$info->{'params'}};
2514: }
2515: if (ref($info->{'before'}) eq 'HASH') {
2516: %before = %{$info->{'before'}};
2517: }
2518: if (ref($info->{'after'}) eq 'HASH') {
2519: %after = %{$info->{'after'}};
2520: }
2521: }
2522: if (ref($moves) eq 'HASH') {
2523: if (ref($moves->{'copies'}) eq 'HASH') {
2524: %copies = %{$moves->{'copies'}};
2525: }
2526: if (ref($moves->{'docmoves'}) eq 'HASH') {
2527: %docmoves = %{$moves->{'docmoves'}};
2528: }
2529: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2530: %mapmoves = %{$moves->{'mapmoves'}};
2531: }
2532: }
2533: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2534: my @allcopies;
1.529 raeburn 2535: if (exists($copies{$key})) {
2536: if (ref($copies{$key}) eq 'HASH') {
2537: my %added;
2538: foreach my $innerkey (keys(%{$copies{$key}})) {
2539: if (($innerkey ne '') && (!$added{$innerkey})) {
2540: push(@allcopies,$innerkey);
2541: $added{$innerkey} = 1;
2542: }
1.491 raeburn 2543: }
1.529 raeburn 2544: undef(%added);
1.491 raeburn 2545: }
2546: }
2547: if ($key eq $oldurl) {
1.529 raeburn 2548: if ((exists($docmoves{$key}))) {
1.532 raeburn 2549: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2550: push(@allcopies,$oldurl);
2551: }
2552: }
2553: }
2554: if (@allcopies > 0) {
2555: foreach my $item (@allcopies) {
1.492 raeburn 2556: my ($relpath,$oldsubdir,$fname) =
2557: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2558: if ($fname ne '') {
2559: my $content = &Apache::lonnet::getfile($item);
2560: unless ($content eq '-1') {
2561: my $storefn;
1.529 raeburn 2562: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2563: $storefn = $docmoves{$key};
1.491 raeburn 2564: } else {
2565: $storefn = $relpath;
2566: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2567: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2568: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2569: }
1.529 raeburn 2570: if ($newsubdir{$key}) {
1.532 raeburn 2571: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2572: }
2573: }
2574: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2575: my $copyurl =
2576: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2577: $storefn.$fname,$content);
2578: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2579: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2580: return &mt('Paste failed: an error occurred copying the file.');
2581: } elsif (ref($errors) eq 'HASH') {
2582: $errors->{$item} = 1;
1.489 raeburn 2583: }
2584: }
1.488 raeburn 2585: }
2586: }
1.491 raeburn 2587: }
2588: }
2589: }
1.529 raeburn 2590: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2591: my $storefn=$key;
2592: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2593: if ($prefixchg && $before{'map'} && $after{'map'}) {
2594: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2595: }
1.529 raeburn 2596: if ($newsubdir{$key}) {
2597: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2598: }
1.491 raeburn 2599: my $mapcontent = &Apache::lonnet::getfile($key);
2600: if ($mapcontent eq '-1') {
2601: if (ref($errors) eq 'HASH') {
2602: $errors->{$key} = 1;
2603: }
2604: } else {
2605: my $newmap =
2606: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2607: $mapcontent);
2608: if ($newmap eq '/adm/notfound.html') {
2609: if (ref($errors) eq 'HASH') {
2610: $errors->{$key} = 1;
1.489 raeburn 2611: }
1.488 raeburn 2612: }
2613: }
2614: }
1.491 raeburn 2615: my %updates;
2616: if ($is_map) {
1.529 raeburn 2617: if (ref($updated) eq 'HASH') {
2618: foreach my $type (keys(%{$updated})) {
2619: if (ref($updated->{$type}) eq 'HASH') {
2620: foreach my $key (keys(%{$updated->{$type}})) {
2621: $updates{$key} = 1;
2622: }
2623: }
2624: }
1.491 raeburn 2625: }
2626: foreach my $key (keys(%updates)) {
1.492 raeburn 2627: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2628: if (ref($rewrites{$key}) eq 'HASH') {
2629: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2630: }
1.529 raeburn 2631: if (ref($retitles{$key}) eq 'HASH') {
2632: %toretitle = %{$retitles{$key}};
1.491 raeburn 2633: }
1.529 raeburn 2634: if (ref($removefrommap{$key}) eq 'HASH') {
2635: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2636: }
1.529 raeburn 2637: if (ref($removeparam{$key}) eq 'HASH') {
2638: %remparam = %{$removeparam{$key}};
1.492 raeburn 2639: }
1.529 raeburn 2640: if (ref($zombies{$key}) eq 'HASH') {
2641: %zombie = %{$zombies{$key}};
1.491 raeburn 2642: }
1.529 raeburn 2643: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2644: foreach my $idx (keys(%{$dbcopies{$key}})) {
2645: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2646: my ($newurl,$result,$errtext) =
2647: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2648: if ($result eq 'ok') {
2649: $newdb{$idx} = $newurl;
2650: } elsif (ref($errors) eq 'HASH') {
2651: $errors->{$key} = 1;
2652: }
2653: push(@msgs,$errtext);
2654: }
1.491 raeburn 2655: }
2656: }
1.597 raeburn 2657: if (ref($resdatacopy{$key}) eq 'HASH') {
2658: if ($newsubdir{$key}) {
2659:
2660: }
2661: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2662: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2663: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2664: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2665: my $template = $1;
2666: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2667: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2668: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2669: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2670: my ($newmapname) = ($key =~ m{/([^/]+)$});
2671: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2672: my $srcmapinfo = $srcfolder.':'.$idx;
2673: if ($srccontainer eq 'page') {
2674: $srcmapinfo .= ':1';
2675: }
2676: if ($newsubdir{$key}) {
2677: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2678: }
2679: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2680: $cnum,$template,$idx,$newmapname);
2681: }
2682: }
2683: }
2684: }
2685: }
1.529 raeburn 2686: if (ref($params{$key}) eq 'HASH') {
2687: %currparam = %{$params{$key}};
1.492 raeburn 2688: }
2689: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2690: if ($fatal) {
1.533 raeburn 2691: return ($errtext);
1.492 raeburn 2692: }
2693: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2694: if (defined($LONCAPA::map::zombies[$i])) {
2695: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2696: if ($zombie{$i} eq $src) {
1.492 raeburn 2697: undef($LONCAPA::map::zombies[$i]);
2698: }
2699: }
2700: }
1.529 raeburn 2701: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2702: my $idx = $LONCAPA::map::order[$i];
2703: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2704: my $changed;
1.529 raeburn 2705: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2706: if ((exists($toremove{$idx})) &&
2707: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2708: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2709: if (ref($currparam{$idx}) eq 'ARRAY') {
2710: foreach my $name (@{$currparam{$idx}}) {
2711: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2712: }
2713: }
2714: next;
2715: }
2716: my $origsrc = $src;
1.532 raeburn 2717: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2718: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2719: $changed = 1;
1.491 raeburn 2720: }
1.492 raeburn 2721: }
1.532 raeburn 2722: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2723: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2724: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2725: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2726: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2727: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2728: } else {
1.529 raeburn 2729: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2730: }
1.491 raeburn 2731: }
1.532 raeburn 2732: if ($origsrc =~ /\.(page|sequence)$/) {
2733: if ($newsubdir{$origsrc}) {
1.529 raeburn 2734: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2735: }
1.532 raeburn 2736: } elsif ($newsubdir{$key}) {
2737: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2738: }
2739: }
1.492 raeburn 2740: $changed = 1;
1.533 raeburn 2741: } elsif ($newdb{$idx} ne '') {
2742: $src = $newdb{$idx};
1.492 raeburn 2743: $changed = 1;
2744: }
2745: if ($changed) {
1.538 raeburn 2746: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2747: }
2748: }
2749: }
2750: foreach my $idx (keys(%remparam)) {
2751: if (ref($remparam{$idx}) eq 'ARRAY') {
2752: foreach my $name (@{$remparam{$idx}}) {
2753: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2754: }
2755: }
2756: }
1.533 raeburn 2757: if (values(%lockerrors) > 0) {
2758: $lockmsg = join('<br />',values(%lockerrors));
2759: }
1.491 raeburn 2760: my $storefn;
2761: if ($key eq $oldurl) {
2762: $storefn = $url;
2763: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2764: } else {
2765: $storefn = $key;
2766: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2767: if ($prefixchg && $before{'map'} && $after{'map'}) {
2768: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2769: }
1.529 raeburn 2770: if ($newsubdir{$key}) {
2771: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2772: }
1.491 raeburn 2773: }
1.492 raeburn 2774: my $report;
2775: if ($folder !~ /^supplemental/) {
2776: $report = 1;
2777: }
1.527 raeburn 2778: (my $outtext,$errtext) =
1.492 raeburn 2779: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2780: if ($errtext) {
1.529 raeburn 2781: if ($caller eq 'paste') {
1.533 raeburn 2782: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2783: }
1.491 raeburn 2784: }
2785: }
2786: }
1.533 raeburn 2787: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2788: }
2789:
2790: sub copy_dependencies {
2791: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2792: my $content;
2793: if (ref($contentref)) {
2794: $content = $$contentref;
2795: } else {
2796: $content = &Apache::lonnet::getfile($item);
2797: }
2798: unless ($content eq '-1') {
2799: my $mm = new File::MMagic;
2800: my $mimetype = $mm->checktype_contents($content);
2801: if ($mimetype eq 'text/html') {
2802: my (%allfiles,%codebase,$state);
2803: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2804: if ($res eq 'ok') {
2805: my ($numexisting,$numpathchanges,$existing);
2806: (undef,$numexisting,$numpathchanges,$existing) =
2807: &Apache::loncommon::ask_for_embedded_content(
2808: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2809: {'error_on_invalid_names' => 1,
2810: 'ignore_remote_references' => 1,
2811: 'docs_url' => $item,
2812: 'context' => 'paste'});
2813: if ($numexisting > 0) {
2814: if (ref($existing) eq 'HASH') {
2815: foreach my $dep (keys(%{$existing})) {
2816: my $depfile = $dep;
2817: unless ($depfile =~ m{^\Q$relpath\E}) {
2818: $depfile = $relpath.$dep;
2819: }
2820: my $depcontent = &Apache::lonnet::getfile($depfile);
2821: unless ($depcontent eq '-1') {
2822: my $storedep = $dep;
2823: $storedep =~ s{^\Q$relpath\E}{};
2824: my $dep_url =
2825: &Apache::lonclonecourse::writefile(
2826: $env{'request.course.id'},
2827: $storefn.$storedep,$depcontent);
2828: if ($dep_url eq '/adm/notfound.html') {
2829: if (ref($errors) eq 'HASH') {
2830: $errors->{$depfile} = 1;
2831: }
2832: } else {
2833: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2834: }
2835: }
2836: }
1.488 raeburn 2837: }
2838: }
2839: }
2840: }
2841: }
2842: return;
2843: }
2844:
1.329 droeschl 2845: my %parameter_type = ( 'randompick' => 'int_pos',
2846: 'hiddenresource' => 'string_yesno',
2847: 'encrypturl' => 'string_yesno',
2848: 'randomorder' => 'string_yesno',);
2849: my $valid_parameters_re = join('|',keys(%parameter_type));
2850: # set parameters
2851: sub update_parameter {
1.537 raeburn 2852: if ($env{'form.changeparms'} eq 'all') {
2853: my (@allidx,@allmapidx,%allchecked,%currchecked);
2854: %allchecked = (
2855: 'hiddenresource' => {},
2856: 'encrypturl' => {},
2857: 'randompick' => {},
2858: 'randomorder' => {},
2859: );
2860: foreach my $which (keys(%allchecked)) {
2861: $env{'form.all'.$which} =~ s/,$//;
2862: if ($which eq 'randompick') {
2863: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2864: my ($res,$value) = split(/:/,$item);
2865: if ($value =~ /^\d+$/) {
2866: $allchecked{$which}{$res} = $value;
2867: }
2868: }
2869: } else {
1.539 raeburn 2870: if ($env{'form.all'.$which}) {
2871: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2872: }
1.537 raeburn 2873: }
2874: }
2875: my $haschanges = 0;
2876: foreach my $res (@LONCAPA::map::order) {
2877: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2878: $name=&LONCAPA::map::qtescape($name);
2879: $url=&LONCAPA::map::qtescape($url);
2880: next unless ($name && $url);
2881: my $is_map;
2882: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2883: $is_map = 1;
2884: }
2885: foreach my $which (keys(%allchecked)) {
2886: if (($which eq 'randompick' || $which eq 'randomorder')) {
2887: next if (!$is_map);
2888: }
2889: my $oldvalue = 0;
2890: my $newvalue = 0;
2891: if ($allchecked{$which}{$res}) {
2892: $newvalue = $allchecked{$which}{$res};
2893: }
2894: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2895: if ($which eq 'randompick') {
2896: if ($current =~ /^(\d+)$/) {
2897: $oldvalue = $1;
2898: }
2899: } else {
2900: if ($current =~ /^yes$/i) {
2901: $oldvalue = 1;
2902: }
2903: }
2904: if ($oldvalue ne $newvalue) {
2905: $haschanges = 1;
2906: if ($newvalue) {
2907: my $storeval = 'yes';
2908: if ($which eq 'randompick') {
2909: $storeval = $newvalue;
2910: }
2911: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2912: $storeval,
2913: $parameter_type{$which});
2914: &remember_parms($res,$which,'set',$storeval);
2915: } elsif ($oldvalue) {
2916: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2917: &remember_parms($res,$which,'del');
2918: }
2919: }
2920: }
2921: }
2922: return $haschanges;
2923: } else {
1.588 raeburn 2924: my $haschanges = 0;
2925: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2926:
1.537 raeburn 2927: my $which = $env{'form.changeparms'};
2928: my $idx = $env{'form.setparms'};
1.588 raeburn 2929: my $oldvalue = 0;
2930: my $newvalue = 0;
2931: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2932: if ($which eq 'randompick') {
2933: if ($current =~ /^(\d+)$/) {
2934: $oldvalue = $1;
2935: }
2936: } elsif ($current =~ /^yes$/i) {
2937: $oldvalue = 1;
2938: }
1.537 raeburn 2939: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2940: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2941: : 1;
2942: }
2943: if ($oldvalue ne $newvalue) {
2944: $haschanges = 1;
2945: if ($newvalue) {
2946: my $storeval = 'yes';
2947: if ($which eq 'randompick') {
2948: $storeval = $newvalue;
2949: }
2950: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2951: $parameter_type{$which});
2952: &remember_parms($idx,$which,'set',$storeval);
2953: } else {
2954: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2955: &remember_parms($idx,$which,'del');
2956: }
1.537 raeburn 2957: }
1.588 raeburn 2958: return $haschanges;
1.329 droeschl 2959: }
2960: }
2961:
2962: sub handle_edit_cmd {
2963: my ($coursenum,$coursedom) =@_;
1.543 raeburn 2964: if ($env{'form.cmd'} eq '') {
2965: return 0;
2966: }
1.329 droeschl 2967: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2968:
2969: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2970: my ($title, $url, @rrest) = split(':', $ratstr);
2971:
1.538 raeburn 2972: if ($cmd eq 'remove') {
1.329 droeschl 2973: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2974: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2975: &Apache::lonnet::removeuploadedurl($url);
2976: } else {
2977: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2978: }
2979: splice(@LONCAPA::map::order, $idx, 1);
2980:
2981: } elsif ($cmd eq 'cut') {
2982: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2983: splice(@LONCAPA::map::order, $idx, 1);
2984:
1.344 bisitz 2985: } elsif ($cmd eq 'up'
1.329 droeschl 2986: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2987: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2988:
2989: } elsif ($cmd eq 'down'
2990: && defined($LONCAPA::map::order[$idx+1])) {
2991: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2992:
2993: } elsif ($cmd eq 'rename') {
2994: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2995: if ($comment=~/\S/) {
2996: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2997: $comment.':'.join(':', $url, @rrest);
2998: }
2999: # Devalidate title cache
3000: my $renamed_url=&LONCAPA::map::qtescape($url);
3001: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 3002:
1.329 droeschl 3003: } else {
3004: return 0;
3005: }
3006: return 1;
3007: }
3008:
3009: sub editor {
1.458 raeburn 3010: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3011: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3012: $canedit,$navmapref,$hiddentop)=@_;
1.519 raeburn 3013: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3014: if ($allowed) {
1.519 raeburn 3015: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3016: $is_random_order,$container) =
1.510 raeburn 3017: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3018: $r->print($breadcrumbtrail);
1.519 raeburn 3019: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3020: $container = 'page';
3021: } else {
3022: $container = 'sequence';
1.510 raeburn 3023: }
1.484 raeburn 3024:
1.525 raeburn 3025: my $jumpto;
3026:
3027: unless ($supplementalflag) {
1.546 raeburn 3028: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3029: }
1.484 raeburn 3030:
3031: unless ($allowed) {
3032: $randompick = -1;
3033: }
3034:
1.615 raeburn 3035: my ($errtext,$fatal);
3036: if (($folder eq '') && (!$supplementalflag)) {
3037: if (@LONCAPA::map::order) {
3038: undef(@LONCAPA::map::order);
3039: undef(@LONCAPA::map::resources);
3040: undef(@LONCAPA::map::resparms);
3041: undef(@LONCAPA::map::zombies);
3042: }
3043: $folder = 'default';
3044: $container = 'sequence';
3045: } else {
3046: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3047: $folder.'.'.$container);
3048: return $errtext if ($fatal);
3049: }
1.329 droeschl 3050:
3051: if ($#LONCAPA::map::order<1) {
3052: my $idx=&LONCAPA::map::getresidx();
3053: if ($idx<=0) { $idx=1; }
3054: $LONCAPA::map::order[0]=$idx;
3055: $LONCAPA::map::resources[$idx]='';
3056: }
1.364 bisitz 3057:
1.329 droeschl 3058: # ------------------------------------------------------------ Process commands
3059:
3060: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3061: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3062: # set parameters and change order
3063: &snapshotbefore();
3064:
3065: if (&update_parameter()) {
1.588 raeburn 3066: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3067: return $errtext if ($fatal);
3068: }
3069:
3070: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3071: # change order
3072: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3073: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3074:
3075: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3076: return $errtext if ($fatal);
3077: }
1.364 bisitz 3078:
1.329 droeschl 3079: if ($env{'form.pastemarked'}) {
1.491 raeburn 3080: my %paste_errors;
1.533 raeburn 3081: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3082: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3083: \%paste_errors);
1.541 raeburn 3084: if (ref($pastemsgarray) eq 'ARRAY') {
3085: if (@{$pastemsgarray} > 0) {
3086: $r->print('<p class="LC_info">'.
3087: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3088: '</p>');
3089: }
1.541 raeburn 3090: }
3091: if ($lockerror) {
3092: $r->print('<p class="LC_error">'.
3093: $lockerror.
3094: '</p>');
3095: }
3096: if ($save_error ne '') {
3097: return $save_error;
3098: }
3099: if ($paste_res) {
3100: my %errortext = &Apache::lonlocal::texthash (
3101: fail => 'Storage of folder contents failed',
3102: failread => 'Reading folder contents failed',
3103: failstore => 'Storage of folder contents failed',
3104: );
3105: if ($errortext{$paste_res}) {
3106: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3107: }
1.329 droeschl 3108: }
1.491 raeburn 3109: if (keys(%paste_errors) > 0) {
1.538 raeburn 3110: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3111: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
3112: '<ul>'."\n");
3113: foreach my $key (sort(keys(%paste_errors))) {
3114: $r->print('<li>'.$key.'</li>'."\n");
3115: }
3116: $r->print('</ul></p>'."\n");
3117: }
1.538 raeburn 3118: } elsif ($env{'form.clearmarked'}) {
3119: my $output = &do_buffer_empty();
3120: if ($output) {
3121: $r->print('<p class="LC_info">'.$output.'</p>');
3122: }
3123: }
1.329 droeschl 3124:
3125: $r->print($upload_output);
3126:
1.538 raeburn 3127: # Rename, cut, copy or remove a single resource
1.602 raeburn 3128: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3129: my $contentchg;
1.592 raeburn 3130: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 3131: $contentchg = 1;
3132: }
3133: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3134: return $errtext if ($fatal);
3135: }
1.538 raeburn 3136:
3137: # Cut, copy and/or remove multiple resources
3138: if ($env{'form.multichange'}) {
3139: my %allchecked = (
3140: cut => {},
3141: remove => {},
3142: );
3143: my $needsupdate;
3144: foreach my $which (keys(%allchecked)) {
3145: $env{'form.multi'.$which} =~ s/,$//;
3146: if ($env{'form.multi'.$which}) {
3147: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3148: if (ref($allchecked{$which}) eq 'HASH') {
3149: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3150: }
3151: }
3152: }
3153: if ($needsupdate) {
3154: my $haschanges = 0;
3155: my %curr_groups = &Apache::longroup::coursegroups();
3156: my $total = scalar(@LONCAPA::map::order) - 1;
3157: for (my $i=$total; $i>=0; $i--) {
3158: my $res = $LONCAPA::map::order[$i];
3159: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3160: $name=&LONCAPA::map::qtescape($name);
3161: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3162: next unless $url;
1.538 raeburn 3163: my %denied =
3164: &action_restrictions($coursenum,$coursedom,$url,
3165: $env{'form.folderpath'},\%curr_groups);
3166: foreach my $which (keys(%allchecked)) {
3167: next if ($denied{$which});
3168: next unless ($allchecked{$which}{$res});
3169: if ($which eq 'remove') {
3170: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3171: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3172: &Apache::lonnet::removeuploadedurl($url);
3173: } else {
3174: &LONCAPA::map::makezombie($res);
3175: }
3176: splice(@LONCAPA::map::order,$i,1);
3177: $haschanges ++;
3178: } elsif ($which eq 'cut') {
3179: &LONCAPA::map::makezombie($res);
3180: splice(@LONCAPA::map::order,$i,1);
3181: $haschanges ++;
3182: }
3183: }
3184: }
3185: if ($haschanges) {
3186: ($errtext,$fatal) =
3187: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3188: return $errtext if ($fatal);
3189: }
3190: }
3191: }
3192:
1.329 droeschl 3193: # Group import/search
3194: if ($env{'form.importdetail'}) {
3195: my @imports;
3196: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3197: if (defined($item)) {
3198: my ($name,$url,$residx)=
1.533 raeburn 3199: map { &unescape($_); } split(/\=/,$item);
3200: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3201: my ($suffix,$errortxt,$locknotfreed) =
3202: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3203: if ($locknotfreed) {
3204: $r->print($locknotfreed);
3205: }
3206: if ($suffix) {
3207: $url =~ s/_new\./_$suffix./;
3208: } else {
3209: return $errortxt;
3210: }
1.533 raeburn 3211: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3212: my $type = $1;
3213: my ($suffix,$errortxt,$locknotfreed) =
3214: &new_timebased_suffix($coursedom,$coursenum,$type);
3215: if ($locknotfreed) {
3216: $r->print($locknotfreed);
3217: }
3218: if ($suffix) {
3219: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3220: } else {
3221: return $errortxt;
3222: }
1.598 raeburn 3223: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
3224: my ($suffix,$errortxt,$locknotfreed) =
3225: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3226: if ($locknotfreed) {
3227: $r->print($locknotfreed);
3228: }
3229: if ($suffix) {
3230: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3231: } else {
3232: return $errortxt;
3233: }
1.534 raeburn 3234: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3235: if ($supplementalflag) {
3236: next unless ($1 eq 'supplemental');
3237: if ($folder eq 'supplemental') {
3238: next unless ($2 eq 'default');
3239: } else {
3240: next unless ($folder eq 'supplemental_'.$2);
3241: }
3242: } else {
3243: next unless ($1 eq 'docs');
3244: if ($folder eq 'default') {
3245: next unless ($2 eq 'default');
3246: } else {
3247: next unless ($folder eq 'default_'.$2);
3248: }
3249: }
1.504 raeburn 3250: }
1.329 droeschl 3251: push(@imports, [$name, $url, $residx]);
3252: }
3253: }
1.530 raeburn 3254: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3255: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3256: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3257: return $errtext if ($fatal);
1.529 raeburn 3258: if ($fixuperrors) {
3259: $r->print($fixuperrors);
3260: }
1.329 droeschl 3261: }
3262: # Loading a complete map
3263: if ($env{'form.loadmap'}) {
3264: if ($env{'form.importmap'}=~/\w/) {
3265: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3266: my ($title,$url,$ext,$type)=split(/\:/,$res);
3267: my $idx=&LONCAPA::map::getresidx($url);
3268: $LONCAPA::map::resources[$idx]=$res;
3269: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3270: }
3271: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3272: $folder.'.'.$container,1);
1.329 droeschl 3273: return $errtext if ($fatal);
3274: } else {
3275: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3276:
1.329 droeschl 3277: }
3278: }
3279: &log_differences($plain);
3280: }
3281: # ---------------------------------------------------------------- End commands
3282: # ---------------------------------------------------------------- Print screen
3283: my $idx=0;
3284: my $shown=0;
3285: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3286: $r->print('<div class="LC_Box">'.
1.432 raeburn 3287: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3288: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3289: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3290: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3291: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3292: '</ol>');
1.381 bisitz 3293: if ($randompick>=0) {
3294: $r->print('<p class="LC_warning">'
3295: .&mt('Caution: this folder is set to randomly pick a subset'
3296: .' of resources. Adding or removing resources from this'
3297: .' folder will change the set of resources that the'
3298: .' students see, resulting in spurious or missing credit'
3299: .' for completed problems, not limited to ones you'
3300: .' modify. Do not modify the contents of this folder if'
3301: .' it is in active student use.')
3302: .'</p>'
3303: );
3304: }
3305: if ($is_random_order) {
3306: $r->print('<p class="LC_warning">'
3307: .&mt('Caution: this folder is set to randomly order its'
3308: .' contents. Adding or removing resources from this folder'
3309: .' will change the order of resources shown.')
3310: .'</p>'
3311: );
3312: }
3313: $r->print('</div>');
1.364 bisitz 3314: }
1.381 bisitz 3315:
1.538 raeburn 3316: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3317: %filters = (
1.543 raeburn 3318: canremove => [],
3319: cancut => [],
3320: cancopy => [],
3321: hiddenresource => [],
3322: encrypturl => [],
3323: randomorder => [],
3324: randompick => [],
1.538 raeburn 3325: );
3326: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3327: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3328: foreach my $res (@LONCAPA::map::order) {
3329: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3330: $name=&LONCAPA::map::qtescape($name);
3331: $url=&LONCAPA::map::qtescape($url);
3332: unless ($name) { $name=(split(/\//,$url))[-1]; }
3333: unless ($name) { $idx++; next; }
1.537 raeburn 3334: push(@allidx,$res);
3335: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3336: push(@allmapidx,$res);
3337: }
1.617 raeburn 3338:
1.381 bisitz 3339: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3340: $coursenum,$coursedom,$crstype,
1.538 raeburn 3341: $pathitem,$supplementalflag,$container,
1.620 raeburn 3342: \%filters,\%curr_groups,$ltitoolsref,$canedit,
3343: $isencrypted,$navmapref);
1.381 bisitz 3344: $idx++;
3345: $shown++;
1.329 droeschl 3346: }
1.424 onken 3347: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3348:
1.538 raeburn 3349: my $need_save;
1.611 raeburn 3350: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3351: my $toolslink;
1.611 raeburn 3352: if ($allowed) {
1.544 raeburn 3353: $toolslink = '<table><tr><td>'
1.520 raeburn 3354: .&Apache::loncommon::help_open_menu('Navigation Screen',
3355: 'Navigation_Screen',undef,'RAT')
3356: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3357: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3358: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3359: .'id="LC_content_toolbar_edittoplevel" '
3360: .'class="LC_toolbarItem" '
3361: .'title="'.&mt('Supplemental Content Editor').'">'
3362: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3363: }
1.510 raeburn 3364: if ($shown) {
3365: if ($allowed) {
3366: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3367: .&Apache::loncommon::start_data_table(undef,'contentlist')
3368: .&Apache::loncommon::start_data_table_header_row()
3369: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3370: .'<th colspan="2">'.&mt('Actions').'</th>'
3371: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3372: if ($folder !~ /^supplemental/) {
3373: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3374: }
1.537 raeburn 3375: $to_show .= &Apache::loncommon::end_data_table_header_row();
3376: if ($folder !~ /^supplemental/) {
1.538 raeburn 3377: $lists{'canhide'} = join(',',@allidx);
3378: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3379: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3380: 'randomorder','randompick');
3381: foreach my $item (@possfilters) {
1.538 raeburn 3382: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3383: if (@{$filters{$item}} > 0) {
3384: $lists{$item} = join(',',@{$filters{$item}});
3385: }
1.538 raeburn 3386: }
3387: }
1.537 raeburn 3388: if (@allidx > 0) {
3389: my $path;
3390: if ($env{'form.folderpath'}) {
3391: $path =
3392: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3393: }
1.538 raeburn 3394: if (@allidx > 1) {
3395: $to_show .=
3396: &Apache::loncommon::continue_data_table_row().
3397: '<td colspan="2"> </td>'.
3398: '<td>'.
1.611 raeburn 3399: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3400: '</td>'.
3401: '<td> </td>'.
3402: '<td> </td>'.
3403: '<td colspan="4">'.
1.611 raeburn 3404: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3405: '</td>'.
3406: &Apache::loncommon::end_data_table_row();
3407: $need_save = 1;
3408: }
1.537 raeburn 3409: }
3410: }
3411: $to_show .= $output.' '
1.510 raeburn 3412: .&Apache::loncommon::end_data_table()
3413: .'<br style="line-height:2px;" />'
3414: .&Apache::loncommon::end_scrollbox();
3415: } else {
1.520 raeburn 3416: $to_show .= $toolslink
1.510 raeburn 3417: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3418: .$output.' '
3419: .&Apache::loncommon::end_data_table();
1.393 raeburn 3420: }
1.510 raeburn 3421: } else {
1.520 raeburn 3422: if (!$allowed) {
3423: $to_show .= $toolslink;
3424: }
1.615 raeburn 3425: my $noresmsg;
3426: if ($allowed && $hiddentop && !$supplementalflag) {
3427: $noresmsg = &mt('Main Content Hidden');
3428: } else {
3429: $noresmsg = &mt('Currently empty');
3430: }
1.510 raeburn 3431: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3432: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3433: .$noresmsg
1.510 raeburn 3434: .'</div>'
3435: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3436: }
3437: } else {
1.510 raeburn 3438: if ($shown) {
3439: $to_show = '<div>'
3440: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3441: .$output
3442: .&Apache::loncommon::end_data_table()
3443: .'</div>';
3444: } else {
3445: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3446: .&mt('Currently empty')
1.510 raeburn 3447: .'</div>'
3448: }
1.458 raeburn 3449: }
3450: my $tid = 1;
3451: if ($supplementalflag) {
3452: $tid = 2;
1.329 droeschl 3453: }
3454: if ($allowed) {
1.484 raeburn 3455: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3456: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3457: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3458: if ($canedit) {
3459: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3460: }
1.460 raeburn 3461: } else {
3462: $r->print($to_show);
1.329 droeschl 3463: }
3464: return;
3465: }
3466:
1.538 raeburn 3467: sub multiple_check_form {
1.611 raeburn 3468: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3469: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3470: my $disabled;
3471: unless ($canedit) {
3472: $disabled = 'disabled="disabled"';
3473: }
1.538 raeburn 3474: my $output =
3475: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3476: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3477: '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick('."'$caller','0'".');" checked="checked" />'.&mt('one').'</label>'.(' 'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick('."'$caller','1'".');" />'.&mt('multiple').'</label></span><span id="more'.$caller.'" class="LC_nobreak LC_docs_ext_edit"></span></form>'.
3478: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3479: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3480: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3481: if ($caller eq 'settings') {
3482: $output .=
3483: '<table><tr>'.
3484: '<td class="LC_docs_entry_parameter">'.
3485: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3486: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3487: '</label></span></td>'.
3488: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3489: '<span class="LC_nobreak"><label><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');"'.$disabled.' />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
1.538 raeburn 3490: '</span></td>'.
3491: '</tr>'."\n".
3492: '<tr>'.
3493: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3494: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')"'.$disabled.' />'.&mt('URL hidden').'</label></span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><label><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')"'.$disabled.' />'.&mt('Random Order').
1.538 raeburn 3495: '</label></span>'.
3496: '</td></tr></table>'."\n";
3497: } else {
3498: $output .=
3499: '<table><tr>'.
3500: '<td class="LC_docs_entry_parameter">'.
3501: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3502: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3503: '</label></span></td>'.
3504: '<td class="LC_docs_entry_parameter">'.
3505: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3506: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3507: '</label></span></td>'."\n".
3508: '<td class="LC_docs_entry_parameter">'.
3509: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3510: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3511: '</label></span></td>'.
3512: '</tr></table>'."\n";
3513: }
3514: $output .=
3515: '</fieldset>'.
3516: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3517: if ($caller eq 'settings') {
3518: $output .=
1.543 raeburn 3519: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3520: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3521: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3522: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3523: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3524: } elsif ($caller eq 'actions') {
3525: $output .=
3526: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3527: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3528: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3529: }
3530: $output .=
3531: '</form>'.
3532: '</div>';
3533: return $output;
3534: }
3535:
1.329 droeschl 3536: sub process_file_upload {
1.552 raeburn 3537: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3538: # upload a file, if present
1.552 raeburn 3539: my $filesize = length($env{'form.uploaddoc'});
3540: if (!$filesize) {
3541: $$upload_output = '<div class="LC_error">'.
3542: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3543: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3544: $filesize).'<br />'.
3545: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3546: '</div>';
3547: return;
3548: }
3549: my $quotatype = 'unofficial';
3550: if ($crstype eq 'Community') {
1.601 raeburn 3551: $quotatype = 'community';
3552: } elsif ($crstype eq 'Placement') {
3553: $quotatype = 'placement';
1.580 raeburn 3554: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3555: $quotatype = 'official';
1.573 raeburn 3556: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3557: $quotatype = 'textbook';
1.552 raeburn 3558: }
3559: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3560: $filesize = int($filesize/1000); #expressed in kb
3561: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3562: $env{'form.uploaddoc.filename'},$filesize,
3563: 'upload',$quotatype);
1.552 raeburn 3564: return if ($$upload_output);
3565: }
1.440 raeburn 3566: my ($parseaction,$showupload,$nextphase,$mimetype);
3567: if ($env{'form.parserflag'}) {
1.329 droeschl 3568: $parseaction = 'parse';
3569: }
3570: my $folder=$env{'form.folder'};
3571: if ($folder eq '') {
3572: $folder='default';
3573: }
3574: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3575: my $errtext='';
3576: my $fatal=0;
3577: my $container='sequence';
1.519 raeburn 3578: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3579: $container='page';
3580: }
3581: ($errtext,$fatal)=
1.534 raeburn 3582: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3583: if ($#LONCAPA::map::order<1) {
3584: $LONCAPA::map::order[0]=1;
3585: $LONCAPA::map::resources[1]='';
3586: }
3587: my $destination = 'docs/';
3588: if ($folder =~ /^supplemental/) {
3589: $destination = 'supplemental/';
3590: }
3591: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3592: $destination .= 'default/';
3593: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3594: $destination .= $2.'/';
3595: }
1.534 raeburn 3596: if ($fatal) {
3597: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'</div>';
3598: return;
3599: }
1.440 raeburn 3600: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3601: my $newidx=&LONCAPA::map::getresidx();
3602: $destination .= $newidx;
1.439 raeburn 3603: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3604: $parseaction,$allfiles,
1.440 raeburn 3605: $codebase,undef,undef,undef,undef,
3606: undef,undef,\$mimetype);
3607: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3608: my $stored = $1;
3609: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3610: $stored.'</span>').'</p>';
3611: } else {
3612: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3613:
1.457 raeburn 3614: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3615: return;
3616: }
1.329 droeschl 3617: my $ext='false';
3618: if ($url=~m{^http://}) { $ext='true'; }
3619: $url = &LONCAPA::map::qtunescape($url);
3620: my $comment=$env{'form.comment'};
3621: $comment = &LONCAPA::map::qtunescape($comment);
3622: if ($folder=~/^supplemental/) {
3623: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3624: $env{'user.domain'}.'___&&&___'.$comment;
3625: }
3626:
3627: $LONCAPA::map::resources[$newidx]=
3628: $comment.':'.$url.':'.$ext.':normal:res';
3629: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3630: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3631: $folder.'.'.$container,1);
1.329 droeschl 3632: if ($fatal) {
1.457 raeburn 3633: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3634: return;
1.329 droeschl 3635: } else {
1.440 raeburn 3636: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3637: $$upload_output = $showupload;
1.384 raeburn 3638: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3639: if ($total_embedded > 0) {
1.440 raeburn 3640: my $uploadphase = 'upload_embedded';
3641: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3642: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3643: my ($embedded,$num) =
3644: &Apache::loncommon::ask_for_embedded_content(
3645: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3646: if ($embedded) {
3647: if ($num) {
3648: $$upload_output .=
3649: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3650: $nextphase = $uploadphase;
3651: } else {
3652: $$upload_output .= $embedded;
3653: }
3654: } else {
3655: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3656: }
1.329 droeschl 3657: } else {
1.440 raeburn 3658: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3659: }
1.457 raeburn 3660: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3661: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3662: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3663: $nextphase = 'decompress_uploaded';
3664: my $position = scalar(@LONCAPA::map::order)-1;
3665: my $noextract = &return_to_editor();
3666: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3667: my %archiveitems = (
3668: folderpath => $env{'form.folderpath'},
3669: cmd => $nextphase,
3670: newidx => $newidx,
3671: position => $position,
3672: phase => $nextphase,
1.477 raeburn 3673: comment => $comment,
1.480 raeburn 3674: );
3675: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3676: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3677: $$upload_output = $showupload.
3678: &Apache::loncommon::decompress_form($mimetype,
3679: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3680: \%archiveitems,\@current);
1.329 droeschl 3681: }
3682: }
3683: }
1.440 raeburn 3684: return $nextphase;
1.329 droeschl 3685: }
3686:
1.480 raeburn 3687: sub get_dir_list {
3688: my ($url,$coursenum,$coursedom,$newidx) = @_;
3689: my ($destination,$dir_root) = &embedded_destination();
3690: my ($dirlistref,$listerror) =
3691: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3692: my @dir_lines;
3693: my $dirptr=16384;
3694: if (ref($dirlistref) eq 'ARRAY') {
3695: foreach my $dir_line (sort
3696: {
3697: my ($afile)=split('&',$a,2);
3698: my ($bfile)=split('&',$b,2);
3699: return (lc($afile) cmp lc($bfile));
3700: } (@{$dirlistref})) {
3701: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3702: $filename =~ s/\s+$//;
3703: next if ($filename =~ /^\.\.?$/);
3704: my $isdir = 0;
3705: if ($dirptr&$testdir) {
3706: $isdir = 1;
3707: }
3708: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3709: }
3710: }
3711: return @dir_lines;
3712: }
3713:
1.329 droeschl 3714: sub is_supplemental_title {
3715: my ($title) = @_;
3716: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3717: }
3718:
3719: # --------------------------------------------------------------- An entry line
3720:
3721: sub entryline {
1.501 raeburn 3722: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3723: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.615 raeburn 3724: $ltitoolsref,$canedit,$isencrypted,$navmapref)=@_;
1.581 raeburn 3725: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3726: if (&is_supplemental_title($title)) {
1.488 raeburn 3727: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3728: } else {
3729: $title=&HTML::Entities::encode($title,'"<>&\'');
3730: $renametitle=$title;
3731: $foldertitle=$title;
3732: }
3733:
1.611 raeburn 3734: my ($disabled,$readonly,$js_lt);
3735: unless ($canedit) {
3736: $disabled = 'disabled="disabled"';
3737: $readonly = 1;
3738: }
3739:
1.329 droeschl 3740: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3741:
1.329 droeschl 3742: $renametitle=~s/\\/\\\\/g;
3743: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3744: $renametitle=~s/"/%22/g;
1.581 raeburn 3745: $renametitle=~s/ /%20/g;
3746: $oldtitle = $renametitle;
1.576 raeburn 3747: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3748: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3749: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3750: # Edit commands
1.535 raeburn 3751: my ($esc_path, $path, $symb);
1.329 droeschl 3752: if ($env{'form.folderpath'}) {
3753: $esc_path=&escape($env{'form.folderpath'});
3754: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3755: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3756: }
1.505 raeburn 3757: my $isexternal;
1.510 raeburn 3758: if ($residx) {
1.501 raeburn 3759: my $currurl = $url;
3760: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3761: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3762: $isexternal = 1;
3763: }
1.510 raeburn 3764: if (!$supplementalflag) {
3765: my $path = 'uploaded/'.
3766: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3767: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3768: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3769: $residx,
3770: &Apache::lonnet::declutter($currurl));
3771: }
1.501 raeburn 3772: }
1.538 raeburn 3773: my ($renamelink,%lt,$ishash);
3774: if (ref($filtersref) eq 'HASH') {
3775: $ishash = 1;
3776: }
3777:
1.329 droeschl 3778: if ($allowed) {
1.538 raeburn 3779: $form_start = '
3780: <form action="/adm/coursedocs" method="post">
3781: ';
3782: $form_common=(<<END);
3783: <input type="hidden" name="folderpath" value="$path" />
3784: <input type="hidden" name="symb" value="$symb" />
3785: END
3786: $form_param=(<<END);
3787: <input type="hidden" name="setparms" value="$orderidx" />
3788: <input type="hidden" name="changeparms" value="0" />
3789: END
3790: $form_end = '</form>';
3791:
1.329 droeschl 3792: my $incindex=$index+1;
3793: my $selectbox='';
1.471 raeburn 3794: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3795: ((split(/\:/,
1.344 bisitz 3796: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3797: ne '') &&
1.329 droeschl 3798: ((split(/\:/,
1.344 bisitz 3799: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3800: ne '')) {
3801: $selectbox=
3802: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3803: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3804: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3805: if ($i==$incindex) {
1.358 bisitz 3806: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3807: } else {
3808: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3809: }
3810: }
3811: $selectbox.='</select>';
3812: }
1.501 raeburn 3813: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3814: 'up' => 'Move Up',
3815: 'dw' => 'Move Down',
3816: 'rm' => 'Remove',
3817: 'ct' => 'Cut',
3818: 'rn' => 'Rename',
1.501 raeburn 3819: 'cp' => 'Copy',
3820: 'ex' => 'External Resource',
1.598 raeburn 3821: 'et' => 'External Tool',
1.501 raeburn 3822: 'ed' => 'Edit',
3823: 'pr' => 'Preview',
3824: 'sv' => 'Save',
3825: 'ul' => 'URL',
1.611 raeburn 3826: 'ti' => 'Title',
1.618 raeburn 3827: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3828: );
1.538 raeburn 3829: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3830: $env{'form.folderpath'},
3831: $currgroups);
1.517 raeburn 3832: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3833: my $skip_confirm = 0;
1.603 raeburn 3834: my $confirm_removal = 0;
1.329 droeschl 3835: if ( $folder =~ /^supplemental/
3836: || ($url =~ m{( /smppg$
3837: |/syllabus$
3838: |/aboutme$
3839: |/navmaps$
3840: |/bulletinboard$
1.598 raeburn 3841: |/exttools?$
1.505 raeburn 3842: |\.html$)}x)
3843: || $isexternal) {
1.329 droeschl 3844: $skip_confirm = 1;
3845: }
1.603 raeburn 3846: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3847: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3848: $confirm_removal = 1;
3849: }
1.329 droeschl 3850:
1.538 raeburn 3851: if ($denied{'copy'}) {
1.543 raeburn 3852: $copylink=(<<ENDCOPY)
1.507 raeburn 3853: <span style="visibility: hidden;">$lt{'cp'}</span>
3854: ENDCOPY
3855: } else {
1.538 raeburn 3856: my $formname = 'edit_copy_'.$orderidx;
3857: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3858: $copylink=(<<ENDCOPY);
1.538 raeburn 3859: <form name="$formname" method="post" action="/adm/coursedocs">
3860: $form_common
1.611 raeburn 3861: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.538 raeburn 3862: $form_end
1.329 droeschl 3863: ENDCOPY
1.538 raeburn 3864: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3865: push(@{$filtersref->{'cancopy'}},$orderidx);
3866: }
1.329 droeschl 3867: }
1.538 raeburn 3868: if ($denied{'cut'}) {
1.507 raeburn 3869: $cutlink=(<<ENDCUT);
3870: <span style="visibility: hidden;">$lt{'ct'}</span>
3871: ENDCUT
3872: } else {
1.538 raeburn 3873: my $formname = 'edit_cut_'.$orderidx;
3874: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3875: $cutlink=(<<ENDCUT);
1.538 raeburn 3876: <form name="$formname" method="post" action="/adm/coursedocs">
3877: $form_common
1.542 raeburn 3878: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3879: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.538 raeburn 3880: $form_end
1.329 droeschl 3881: ENDCUT
1.538 raeburn 3882: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3883: push(@{$filtersref->{'cancut'}},$orderidx);
3884: }
1.329 droeschl 3885: }
1.538 raeburn 3886: if ($denied{'remove'}) {
1.507 raeburn 3887: $removelink=(<<ENDREM);
3888: <span style="visibility: hidden;">$lt{'rm'}</a>
3889: ENDREM
3890: } else {
1.538 raeburn 3891: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3892: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3893: $removelink=(<<ENDREM);
1.538 raeburn 3894: <form name="$formname" method="post" action="/adm/coursedocs">
3895: $form_common
1.542 raeburn 3896: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3897: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 3898: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.538 raeburn 3899: $form_end
1.497 raeburn 3900: ENDREM
1.538 raeburn 3901: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3902: push(@{$filtersref->{'canremove'}},$orderidx);
3903: }
1.497 raeburn 3904: }
1.551 raeburn 3905: $renamelink=(<<ENDREN);
1.581 raeburn 3906: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3907: ENDREN
1.611 raeburn 3908: my ($uplink,$downlink);
3909: if ($canedit) {
3910: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3911: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3912: } else {
3913: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3914: $downlink = $uplink;
3915: }
1.329 droeschl 3916: $line.=(<<END);
3917: <td>
1.379 bisitz 3918: <div class="LC_docs_entry_move">
1.611 raeburn 3919: <a href="$uplink">
1.501 raeburn 3920: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3921: </a>
3922: </div>
3923: <div class="LC_docs_entry_move">
1.611 raeburn 3924: <a href="$downlink">
1.501 raeburn 3925: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3926: </a>
3927: </div>
1.329 droeschl 3928: </td>
3929: <td>
3930: $form_start
1.538 raeburn 3931: $form_param
1.478 raeburn 3932: $form_common
1.329 droeschl 3933: $selectbox
3934: $form_end
3935: </td>
1.540 raeburn 3936: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3937: $removelink
1.329 droeschl 3938: $cutlink
3939: $copylink
3940: </td>
3941: END
3942: }
3943: # Figure out what kind of a resource this is
3944: my ($extension)=($url=~/\.(\w+)$/);
3945: my $uploaded=($url=~/^\/*uploaded\//);
3946: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3947: my $isfolder;
3948: my $ispage;
3949: my $containerarg;
1.615 raeburn 3950: my $folderurl;
1.329 droeschl 3951: if ($uploaded) {
1.472 raeburn 3952: if (($extension eq 'sequence') || ($extension eq 'page')) {
3953: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3954: $containerarg = $1;
1.472 raeburn 3955: if ($extension eq 'sequence') {
3956: $icon=$iconpath.'navmap.folder.closed.gif';
3957: $isfolder=1;
3958: } else {
3959: $icon=$iconpath.'page.gif';
3960: $ispage=1;
3961: }
1.615 raeburn 3962: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3963: if ($allowed) {
3964: $url='/adm/coursedocs?';
3965: } else {
3966: $url='/adm/supplemental?';
3967: }
1.329 droeschl 3968: } else {
3969: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3970: }
3971: }
1.364 bisitz 3972:
1.621 ! raeburn 3973: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3974: my $orig_url = $url;
1.340 raeburn 3975: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 3976: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 3977: if (!$supplementalflag && $residx && $symb) {
3978: if ((!$isfolder) && (!$ispage)) {
3979: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3980: $url=&Apache::lonnet::clutter($url);
3981: if ($url=~/^\/*uploaded\//) {
3982: $url=~/\.(\w+)$/;
3983: my $embstyle=&Apache::loncommon::fileembstyle($1);
3984: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3985: $url='/adm/wrapper'.$url;
3986: } elsif ($embstyle eq 'ssi') {
3987: #do nothing with these
3988: } elsif ($url!~/\.(sequence|page)$/) {
3989: $url='/adm/coursedocs/showdoc'.$url;
3990: }
3991: } elsif ($url=~m|^/ext/|) {
3992: $url='/adm/wrapper'.$url;
1.598 raeburn 3993: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3994: $url='/adm/wrapper'.$url;
1.621 ! raeburn 3995: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
! 3996: if (($ENV{'SERVER_PORT'} == 443) &&
! 3997: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
! 3998: $url .= '?usehttp=1';
! 3999: $nomodal = 1;
! 4000: }
1.598 raeburn 4001: }
1.501 raeburn 4002: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4003: my $shownsymb = $symb;
4004: if ($isexternal) {
4005: if ($url =~ /^([^#]+)#([^#]+)$/) {
4006: $url = $1;
4007: $anchor = $2;
4008: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4009: $shownsymb = $1.&escape('#').$anchor;
4010: }
4011: }
4012: }
1.617 raeburn 4013: unless ($env{'request.role.adv'}) {
4014: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4015: $url = '';
4016: }
4017: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4018: $url = '';
4019: $hiddenres = 1;
4020: }
4021: }
4022: if ($url ne '') {
4023: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4024: }
1.615 raeburn 4025: } elsif (!$env{'request.role.adv'}) {
4026: my $checkencrypt;
4027: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4028: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4029: $checkencrypt = 1;
1.620 raeburn 4030: } elsif (ref($navmapref)) {
1.615 raeburn 4031: unless (ref($$navmapref)) {
4032: $$navmapref = Apache::lonnavmaps::navmap->new();
4033: }
4034: if (ref($$navmapref)) {
4035: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4036: $checkencrypt = 1;
4037: }
4038: }
4039: }
4040: if ($checkencrypt) {
4041: my $shownsymb = &Apache::lonenc::encrypted($symb);
4042: my $shownurl = &Apache::lonenc::encrypted($url);
4043: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
4044: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
4045: if ($env{'request.enc'} ne '') {
4046: delete($env{'request.enc'});
4047: }
4048: } else {
4049: $url='';
1.613 raeburn 4050: }
1.612 raeburn 4051: } else {
4052: $url='';
4053: }
1.501 raeburn 4054: } else {
4055: $url='';
4056: }
1.329 droeschl 4057: }
1.621 ! raeburn 4058: } elsif ($supplementalflag) {
1.610 raeburn 4059: if ($isexternal) {
4060: if ($url =~ /^([^#]+)#([^#]+)$/) {
4061: $url = $1;
4062: $anchor = $2;
4063: }
1.621 ! raeburn 4064: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
! 4065: if (($ENV{'SERVER_PORT'} == 443) &&
! 4066: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
! 4067: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
! 4068: $nomodal = 1;
! 4069: }
1.610 raeburn 4070: }
1.329 droeschl 4071: }
1.615 raeburn 4072: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4073: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4074: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4075: my $foldername=&escape($foldertitle);
4076: my $folderpath=$env{'form.folderpath'};
4077: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4078: if (!$allowed && $supplementalflag) {
1.519 raeburn 4079: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4080: $url.='folderpath='.&escape($folderpath);
4081: } else {
1.617 raeburn 4082: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4083: 'parameter_randompick'))[0];
4084: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4085: 'parameter_randomorder'))[0]=~/^yes$/i);
4086: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4087: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4088: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4089: 'parameter_encrypturl'))[0]=~/^yes$/i);
4090: unless ($hiddenmap) {
1.620 raeburn 4091: if (ref($navmapref)) {
4092: unless (ref($$navmapref)) {
4093: $$navmapref = Apache::lonnavmaps::navmap->new();
4094: }
4095: if (ref($$navmapref)) {
4096: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4097: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4098: unless (@resources) {
4099: $hiddenmap = 1;
4100: unless ($env{'request.role.adv'}) {
4101: $url = '';
4102: $hiddenfolder = 1;
4103: }
1.617 raeburn 4104: }
1.615 raeburn 4105: }
4106: }
4107: }
4108: }
1.617 raeburn 4109: unless ($encryptmap) {
1.620 raeburn 4110: if ((ref($navmapref)) && (ref($$navmapref))) {
4111: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4112: $encryptmap = 1;
4113: }
1.617 raeburn 4114: }
4115: }
4116:
4117: # Append randompick number, hidden, and encrypted with ":" to foldername,
4118: # so it gets transferred between levels
4119: $folderpath.=$containerarg.'&'.$foldername.
4120: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4121: unless ($url eq '') {
1.612 raeburn 4122: $url.='folderpath='.&escape($folderpath);
4123: }
1.510 raeburn 4124: my $rpckchk;
4125: if ($rpicknum) {
4126: $rpckchk = ' checked="checked"';
1.543 raeburn 4127: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4128: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4129: }
1.510 raeburn 4130: }
1.537 raeburn 4131: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4132: $rand_pick_text =
1.478 raeburn 4133: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4134: $form_param."\n".
1.478 raeburn 4135: $form_common."\n".
1.611 raeburn 4136: '<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 4137: if ($rpicknum ne '') {
4138: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4139: }
1.537 raeburn 4140: $rand_pick_text .= '</span></span>'.
4141: $form_end;
1.543 raeburn 4142: my $ro_set;
1.617 raeburn 4143: if ($randorder) {
1.543 raeburn 4144: $ro_set = 'checked="checked"';
4145: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4146: push(@{$filtersref->{'randomorder'}},$orderidx);
4147: }
4148: }
1.564 raeburn 4149: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4150: $rand_order_text =
1.537 raeburn 4151: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4152: $form_param."\n".
1.537 raeburn 4153: $form_common."\n".
1.611 raeburn 4154: '<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 4155: $form_end;
1.510 raeburn 4156: }
1.509 raeburn 4157: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4158: my $isexttool;
4159: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4160: $url='/adm/wrapper'.$url;
4161: $isexttool = 1;
4162: }
1.510 raeburn 4163: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4164: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4165: if ($title) {
4166: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4167: }
1.598 raeburn 4168: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4169: $url .= '&idx='.$orderidx;
4170: }
1.610 raeburn 4171: if ($anchor ne '') {
4172: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4173: }
1.329 droeschl 4174: }
1.519 raeburn 4175: my ($tdalign,$tdwidth);
1.501 raeburn 4176: if ($allowed) {
4177: my $fileloc =
4178: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4179: if ($isexternal) {
1.518 raeburn 4180: ($editlink,$extresform) =
1.611 raeburn 4181: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4182: undef,undef,undef,undef,undef,undef,
4183: undef,$disabled);
1.598 raeburn 4184: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4185: ($editlink,$extresform) =
4186: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4187: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4188: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4189: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4190: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4191: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4192: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4193: my $suppanchor;
4194: if ($supplementalflag) {
4195: $suppanchor = $anchor;
4196: }
1.501 raeburn 4197: my $jscall =
4198: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4199: $switchserver,
1.503 raeburn 4200: $forceedit,
1.511 raeburn 4201: undef,$symb,
4202: &escape($env{'form.folderpath'}),
1.610 raeburn 4203: $renametitle,'','',1,$suppanchor);
1.501 raeburn 4204: if ($jscall) {
1.518 raeburn 4205: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4206: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4207: }
4208: }
4209: }
1.519 raeburn 4210: $tdalign = ' align="right" valign="top"';
4211: $tdwidth = ' width="80%"';
1.329 droeschl 4212: }
1.408 raeburn 4213: my $reinit;
4214: if ($crstype eq 'Community') {
4215: $reinit = &mt('(re-initialize community to access)');
4216: } else {
4217: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4218: }
4219: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.621 ! raeburn 4220: my $link;
1.472 raeburn 4221: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4222: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4223: } elsif ($url) {
1.610 raeburn 4224: if ($anchor ne '') {
4225: if ($supplementalflag) {
4226: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4227: } else {
4228: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4229: }
4230: }
1.621 ! raeburn 4231: $link = &js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
! 4232: (($anchor ne '')?$anchor:''));
! 4233: if ($nomodal) {
! 4234: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
! 4235: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
! 4236: } else {
! 4237: $line.=&Apache::loncommon::modal_link($link,
! 4238: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
! 4239: }
1.469 www 4240: } else {
4241: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4242: }
1.519 raeburn 4243: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4244: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4245: $line.='<a href="'.$url.'">'.$title.'</a>';
4246: } elsif ($url) {
1.621 ! raeburn 4247: if ($nomodal) {
! 4248: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
! 4249: $title.'</a>';
! 4250: } else {
! 4251: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
! 4252: }
1.617 raeburn 4253: } elsif (($hiddenfolder) || ($hiddenres)) {
1.615 raeburn 4254: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
1.469 www 4255: } else {
4256: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4257: }
1.518 raeburn 4258: $line.="$extresform</td>";
1.478 raeburn 4259: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4260: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4261: if (($allowed) && ($folder!~/^supplemental/)) {
4262: my %lt=&Apache::lonlocal::texthash(
4263: 'hd' => 'Hidden',
4264: 'ec' => 'URL hidden');
1.543 raeburn 4265: my ($enctext,$hidtext);
4266: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4267: $enctext = ' checked="checked"';
4268: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4269: push(@{$filtersref->{'encrypturl'}},$orderidx);
4270: }
4271: }
4272: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4273: $hidtext = ' checked="checked"';
4274: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4275: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4276: }
4277: }
1.537 raeburn 4278: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4279: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4280: $line.=(<<ENDPARMS);
4281: <td class="LC_docs_entry_parameter">
1.537 raeburn 4282: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4283: $form_param
1.478 raeburn 4284: $form_common
1.611 raeburn 4285: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4286: $form_end
1.458 raeburn 4287: <br />
1.537 raeburn 4288: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4289: $form_param
1.478 raeburn 4290: $form_common
1.611 raeburn 4291: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4292: $form_end
4293: </td>
1.478 raeburn 4294: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4295: $rand_order_text</td>
1.329 droeschl 4296: ENDPARMS
4297: }
1.379 bisitz 4298: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4299: return $line;
4300: }
4301:
1.538 raeburn 4302: sub action_restrictions {
4303: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4304: my %denied = (
4305: cut => 0,
4306: copy => 0,
4307: remove => 0,
4308: );
4309: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4310: # no copy for published maps
4311: $denied{'copy'} = 1;
1.597 raeburn 4312: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4313: unless ($1 eq 'simpleproblem') {
4314: $denied{'copy'} = 1;
4315: }
4316: $denied{'cut'} = 1;
1.538 raeburn 4317: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4318: if ($folderpath =~ /^default&[^\&]+$/) {
4319: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4320: $denied{'remove'} = 1;
4321: }
4322: $denied{'cut'} = 1;
4323: $denied{'copy'} = 1;
4324: }
4325: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4326: my $group = $1;
4327: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4328: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4329: $denied{'remove'} = 1;
4330: }
4331: }
4332: $denied{'cut'} = 1;
4333: $denied{'copy'} = 1;
4334: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4335: my $group = $1;
4336: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4337: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4338: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4339: if (keys(%groupsettings) > 0) {
4340: $denied{'remove'} = 1;
4341: }
4342: $denied{'cut'} = 1;
4343: $denied{'copy'} = 1;
4344: }
4345: }
4346: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4347: my $group = $1;
4348: if ($url =~ /group_boards_\Q$group\E/) {
4349: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4350: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4351: if (keys(%groupsettings) > 0) {
4352: if (ref($groupsettings{'functions'}) eq 'HASH') {
4353: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4354: $denied{'remove'} = 1;
4355: }
4356: }
4357: }
4358: $denied{'cut'} = 1;
4359: $denied{'copy'} = 1;
4360: }
4361: }
4362: }
4363: return %denied;
4364: }
4365:
1.533 raeburn 4366: sub new_timebased_suffix {
1.538 raeburn 4367: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4368: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4369: if ($type eq 'paste') {
4370: $prefix = $type;
4371: $namespace = 'courseeditor';
1.587 raeburn 4372: $idtype = 'addcode';
1.538 raeburn 4373: } elsif ($type eq 'map') {
1.533 raeburn 4374: $prefix = 'docs';
4375: if ($area eq 'supplemental') {
4376: $prefix = 'supp';
4377: }
4378: $prefix .= $container;
4379: $namespace = 'uploadedmaps';
4380: } else {
4381: $prefix = $type;
4382: $namespace = 'templated';
1.504 raeburn 4383: }
4384: my ($suffix,$freedlock,$error) =
1.587 raeburn 4385: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4386: if (!$suffix) {
1.538 raeburn 4387: if ($type eq 'paste') {
4388: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4389: } elsif ($type eq 'map') {
1.533 raeburn 4390: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4391: } elsif ($type eq 'smppg') {
4392: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4393: } else {
1.565 bisitz 4394: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4395: }
1.504 raeburn 4396: if ($error) {
4397: $errtext .= '<br />'.$error;
4398: }
4399: }
4400: if ($freedlock ne 'ok') {
1.533 raeburn 4401: $locknotfreed =
4402: '<div class="LC_error">'.
4403: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4404: if ($type eq 'paste') {
1.591 raeburn 4405: if ($freedlock eq 'nolock') {
4406: $locknotfreed =
4407: '<div class="LC_error">'.
4408: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4409:
1.593 droeschl 4410: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4411: } else {
4412: $locknotfreed .=
4413: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4414: }
1.538 raeburn 4415: } elsif ($type eq 'map') {
1.591 raeburn 4416: $locknotfreed .=
4417: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4418: } elsif ($type eq 'smppg') {
4419: $locknotfreed .=
4420: &mt('This will prevent creation of additional simple pages in this course.');
4421: } else {
4422: $locknotfreed .=
1.565 bisitz 4423: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4424: }
1.538 raeburn 4425: unless ($type eq 'paste') {
4426: $locknotfreed .=
1.560 raeburn 4427: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4428: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4429: }
4430: $locknotfreed .= '</div>';
1.504 raeburn 4431: }
4432: return ($suffix,$errtext,$locknotfreed);
4433: }
4434:
1.329 droeschl 4435: =pod
4436:
4437: =item tiehash()
4438:
4439: tie the hash
4440:
4441: =cut
4442:
4443: sub tiehash {
4444: my ($mode)=@_;
4445: $hashtied=0;
4446: if ($env{'request.course.fn'}) {
4447: if ($mode eq 'write') {
4448: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4449: &GDBM_WRCREAT(),0640)) {
4450: $hashtied=2;
4451: }
4452: } else {
4453: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4454: &GDBM_READER(),0640)) {
4455: $hashtied=1;
4456: }
4457: }
1.364 bisitz 4458: }
1.329 droeschl 4459: }
4460:
4461: sub untiehash {
4462: if ($hashtied) { untie %hash; }
4463: $hashtied=0;
4464: return OK;
4465: }
4466:
4467:
4468:
4469:
4470: sub checkonthis {
4471: my ($r,$url,$level,$title)=@_;
4472: $url=&unescape($url);
4473: $alreadyseen{$url}=1;
4474: $r->rflush();
4475: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4476: $r->print("\n<br />");
4477: if ($level==0) {
4478: $r->print("<br />");
4479: }
4480: for (my $i=0;$i<=$level*5;$i++) {
4481: $r->print(' ');
4482: }
4483: $r->print('<a href="'.$url.'" target="cat">'.
4484: ($title?$title:$url).'</a> ');
4485: if ($url=~/^\/res\//) {
4486: my $result=&Apache::lonnet::repcopy(
4487: &Apache::lonnet::filelocation('',$url));
4488: if ($result eq 'ok') {
4489: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4490: $r->rflush();
4491: &Apache::lonnet::countacc($url);
4492: $url=~/\.(\w+)$/;
4493: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4494: $r->print('<br />');
4495: $r->rflush();
4496: for (my $i=0;$i<=$level*5;$i++) {
4497: $r->print(' ');
4498: }
4499: $r->print('- '.&mt('Rendering:').' ');
4500: my ($errorcount,$warningcount)=split(/:/,
4501: &Apache::lonnet::ssi_body($url,
4502: ('grade_target'=>'web',
4503: 'return_only_error_and_warning_counts' => 1)));
4504: if (($errorcount) ||
4505: ($warningcount)) {
4506: if ($errorcount) {
1.369 bisitz 4507: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4508: &mt('[quant,_1,error]',$errorcount).'</span>');
4509: }
4510: if ($warningcount) {
4511: $r->print('<span class="LC_warning">'.
4512: &mt('[quant,_1,warning]',$warningcount).'</span>');
4513: }
4514: } else {
4515: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4516: }
4517: $r->rflush();
4518: }
4519: my $dependencies=
4520: &Apache::lonnet::metadata($url,'dependencies');
4521: foreach my $dep (split(/\,/,$dependencies)) {
4522: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4523: &checkonthis($r,$dep,$level+1);
4524: }
4525: }
4526: } elsif ($result eq 'unavailable') {
4527: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4528: } elsif ($result eq 'not_found') {
4529: unless ($url=~/\$/) {
1.521 bisitz 4530: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4531: } else {
1.366 bisitz 4532: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4533: }
4534: } else {
4535: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4536: }
4537: }
4538: }
4539: }
4540:
4541:
4542:
4543: =pod
4544:
4545: =item list_symbs()
4546:
1.485 raeburn 4547: List Content Identifiers
1.329 droeschl 4548:
4549: =cut
4550:
4551: sub list_symbs {
4552: my ($r) = @_;
4553:
1.408 raeburn 4554: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4555: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4556: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4557: $r->print(&startContentScreen('tools'));
1.329 droeschl 4558: my $navmap = Apache::lonnavmaps::navmap->new();
4559: if (!defined($navmap)) {
4560: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4561: '<div class="LC_error">'.
4562: &mt('Unable to retrieve information about course contents').
4563: '</div>');
1.408 raeburn 4564: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4565: } else {
1.484 raeburn 4566: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4567: &Apache::loncommon::start_data_table().
4568: &Apache::loncommon::start_data_table_header_row().
4569: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4570: &Apache::loncommon::end_data_table_header_row()."\n");
4571: my $count;
1.329 droeschl 4572: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4573: $r->print(&Apache::loncommon::start_data_table_row().
4574: '<td>'.$res->compTitle().'</td>'.
4575: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4576: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4577: $count ++;
4578: }
4579: if (!$count) {
4580: $r->print(&Apache::loncommon::start_data_table_row().
4581: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4582: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4583: }
1.484 raeburn 4584: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4585: }
1.521 bisitz 4586: $r->print(&endContentScreen());
1.329 droeschl 4587: }
4588:
4589:
4590: sub verifycontent {
4591: my ($r) = @_;
1.408 raeburn 4592: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4593: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4594: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4595: $r->print(&startContentScreen('tools'));
4596: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4597: $hashtied=0;
4598: undef %alreadyseen;
4599: %alreadyseen=();
4600: &tiehash();
1.484 raeburn 4601:
1.329 droeschl 4602: foreach my $key (keys(%hash)) {
4603: if ($hash{$key}=~/\.(page|sequence)$/) {
4604: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4605: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4606: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4607: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4608: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4609: }
4610: }
4611: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4612: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4613: }
4614: }
4615: &untiehash();
1.442 www 4616: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4617: $r->print(&endContentScreen());
1.329 droeschl 4618: }
4619:
4620:
4621: sub devalidateversioncache {
4622: my $src=shift;
4623: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4624: &Apache::lonnet::clutter($src));
4625: }
4626:
4627: sub checkversions {
1.611 raeburn 4628: my ($r,$canedit) = @_;
1.408 raeburn 4629: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4630: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4631: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4632: $r->print(&startContentScreen('tools'));
1.442 www 4633:
1.329 droeschl 4634: my $header='';
4635: my $startsel='';
4636: my $monthsel='';
4637: my $weeksel='';
4638: my $daysel='';
4639: my $allsel='';
4640: my %changes=();
4641: my $starttime=0;
4642: my $haschanged=0;
4643: my %setversions=&Apache::lonnet::dump('resourceversions',
4644: $env{'course.'.$env{'request.course.id'}.'.domain'},
4645: $env{'course.'.$env{'request.course.id'}.'.num'});
4646:
4647: $hashtied=0;
4648: &tiehash();
1.611 raeburn 4649: if ($canedit) {
4650: my %newsetversions=();
4651: if ($env{'form.setmostrecent'}) {
4652: $haschanged=1;
4653: foreach my $key (keys(%hash)) {
4654: if ($key=~/^ids\_(\/res\/.+)$/) {
4655: $newsetversions{$1}='mostrecent';
4656: &devalidateversioncache($1);
4657: }
4658: }
4659: } elsif ($env{'form.setcurrent'}) {
4660: $haschanged=1;
4661: foreach my $key (keys(%hash)) {
4662: if ($key=~/^ids\_(\/res\/.+)$/) {
4663: my $getvers=&Apache::lonnet::getversion($1);
4664: if ($getvers>0) {
4665: $newsetversions{$1}=$getvers;
4666: &devalidateversioncache($1);
4667: }
4668: }
1.329 droeschl 4669: }
1.611 raeburn 4670: } elsif ($env{'form.setversions'}) {
4671: $haschanged=1;
4672: foreach my $key (keys(%env)) {
4673: if ($key=~/^form\.set_version_(.+)$/) {
4674: my $src=$1;
4675: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4676: $newsetversions{$src}=$env{$key};
4677: &devalidateversioncache($src);
4678: }
4679: }
1.329 droeschl 4680: }
1.611 raeburn 4681: }
4682: if ($haschanged) {
4683: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4684: $env{'course.'.$env{'request.course.id'}.'.domain'},
4685: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4686: $r->print(&Apache::loncommon::confirmwrapper(
4687: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4688: } else {
4689: $r->print(&Apache::loncommon::confirmwrapper(
4690: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4691: }
1.611 raeburn 4692: &mark_hash_old();
4693: }
4694: &changewarning($r,'');
1.329 droeschl 4695: }
4696: if ($env{'form.timerange'} eq 'all') {
4697: # show all documents
1.549 raeburn 4698: $header=&mt('All content in '.$crstype);
1.521 bisitz 4699: $allsel=' selected="selected"';
1.329 droeschl 4700: foreach my $key (keys(%hash)) {
4701: if ($key=~/^ids\_(\/res\/.+)$/) {
4702: my $src=$1;
4703: $changes{$src}=1;
4704: }
4705: }
4706: } else {
4707: # show documents which changed
4708: %changes=&Apache::lonnet::dump
4709: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4710: $env{'course.'.$env{'request.course.id'}.'.num'});
4711: my $firstkey=(keys(%changes))[0];
4712: unless ($firstkey=~/^error\:/) {
4713: unless ($env{'form.timerange'}) {
4714: $env{'form.timerange'}=604800;
4715: }
4716: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4717: .&mt('seconds');
4718: if ($env{'form.timerange'}==-1) {
4719: $seltext='since start of course';
1.521 bisitz 4720: $startsel=' selected="selected"';
1.329 droeschl 4721: $env{'form.timerange'}=time;
4722: }
4723: $starttime=time-$env{'form.timerange'};
4724: if ($env{'form.timerange'}==2592000) {
4725: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4726: $monthsel=' selected="selected"';
1.329 droeschl 4727: } elsif ($env{'form.timerange'}==604800) {
4728: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4729: $weeksel=' selected="selected"';
1.329 droeschl 4730: } elsif ($env{'form.timerange'}==86400) {
4731: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4732: $daysel=' selected="selected"';
1.329 droeschl 4733: }
4734: $header=&mt('Content changed').' '.$seltext;
4735: } else {
4736: $header=&mt('No content modifications yet.');
4737: }
4738: }
4739: %setversions=&Apache::lonnet::dump('resourceversions',
4740: $env{'course.'.$env{'request.course.id'}.'.domain'},
4741: $env{'course.'.$env{'request.course.id'}.'.num'});
4742: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4743: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4744: 'lm' => 'Version changes since last Month',
4745: 'lw' => 'Version changes since last Week',
4746: 'sy' => 'Version changes since Yesterday',
4747: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4748: 'cd' => 'Change display',
1.329 droeschl 4749: 'sd' => 'Display',
4750: 'fi' => 'File',
4751: 'md' => 'Modification Date',
4752: 'mr' => 'Most recently published Version',
1.408 raeburn 4753: 've' => 'Version used in '.$crstype,
4754: 'vu' => 'Set Version to be used in '.$crstype,
4755: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4756: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4757: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4758: 'di' => 'Differences',
1.484 raeburn 4759: 'save' => 'Save changes',
4760: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4761: 'act' => 'Actions');
1.611 raeburn 4762: my ($disabled,$readonly);
4763: unless ($canedit) {
4764: $disabled = 'disabled="disabled"';
4765: $readonly = 1;
4766: }
1.329 droeschl 4767: $r->print(<<ENDHEADERS);
1.484 raeburn 4768: <h4 class="LC_info">$header</h4>
1.329 droeschl 4769: <form action="/adm/coursedocs" method="post">
4770: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4771: <div class="LC_left_float">
1.479 golterma 4772: <fieldset>
1.484 raeburn 4773: <legend>$lt{'cd'}</legend>
1.329 droeschl 4774: <select name="timerange">
1.521 bisitz 4775: <option value='all'$allsel>$lt{'al'}</option>
4776: <option value="-1"$startsel>$lt{'st'}</option>
4777: <option value="2592000"$monthsel>$lt{'lm'}</option>
4778: <option value="604800"$weeksel>$lt{'lw'}</option>
4779: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4780: </select>
4781: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4782: </fieldset>
4783: </div>
4784: <div class="LC_left_float">
4785: <fieldset>
4786: <legend>$lt{'act'}</legend>
1.611 raeburn 4787: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4788: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4789: </fieldset>
4790: </div>
4791: <br clear="all" />
4792: <hr />
4793: <h4>$lt{'vers'}</h4>
1.329 droeschl 4794: ENDHEADERS
1.479 golterma 4795: #number of columns for version history
1.571 raeburn 4796: my %changedbytime;
4797: foreach my $key (keys(%changes)) {
4798: #excludes not versionable problems from resource version history:
4799: next if ($key =~ /^\/res\/lib\/templates/);
4800: my $chg;
4801: if ($env{'form.timerange'} eq 'all') {
4802: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4803: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4804: } else {
4805: $chg = $changes{$key};
4806: next if ($chg < $starttime);
4807: }
4808: push(@{$changedbytime{$chg}},$key);
4809: }
4810: if (keys(%changedbytime) == 0) {
4811: &untiehash();
4812: $r->print(&mt('No content changes in imported content in specified time frame').
4813: &endContentScreen());
4814: return;
4815: }
1.479 golterma 4816: $r->print(
1.611 raeburn 4817: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4818: &Apache::loncommon::start_data_table().
4819: &Apache::loncommon::start_data_table_header_row().
4820: '<th>'.&mt('Resources').'</th>'.
4821: "<th>$lt{'mr'}</th>".
4822: "<th>$lt{'ve'}</th>".
4823: "<th>$lt{'vu'}</th>".
4824: '<th>'.&mt('History').'</th>'.
4825: &Apache::loncommon::end_data_table_header_row()
4826: );
1.571 raeburn 4827: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4828: foreach my $key (sort(@{$changedbytime{$chg}})) {
4829: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4830: my $currentversion=&Apache::lonnet::getversion($key);
4831: if ($currentversion<0) {
4832: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4833: }
4834: my $linkurl=&Apache::lonnet::clutter($key);
4835: $r->print(
4836: &Apache::loncommon::start_data_table_row().
4837: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4838: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4839: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4840: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4841: '<td align="right">'
4842: );
4843: # Used in course
4844: my $usedversion=$hash{'version_'.$linkurl};
4845: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4846: if ($usedversion != $currentversion) {
1.479 golterma 4847: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4848: } else {
1.479 golterma 4849: $r->print($usedversion);
4850: }
1.329 droeschl 4851: } else {
1.521 bisitz 4852: $r->print($currentversion);
1.329 droeschl 4853: }
1.571 raeburn 4854: $r->print('</td><td title="'.$lt{'vu'}.'">');
4855: # Set version
4856: $r->print(&Apache::loncommon::select_form(
4857: $setversions{$linkurl},
4858: 'set_version_'.$linkurl,
4859: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4860: '' => '',
4861: 'mostrecent' => &mt('most recent'),
1.611 raeburn 4862: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 4863: my $lastold=1;
4864: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4865: my $url=$root.'.'.$prevvers.'.'.$extension;
4866: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4867: $lastold=$prevvers;
4868: }
4869: }
4870: $r->print('</td>');
4871: # List all available versions
4872: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4873: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4874: my $url=$root.'.'.$prevvers.'.'.$extension;
4875: $r->print(
4876: '<span class="LC_nobreak">'
4877: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4878: .&mt('Version [_1]',$prevvers).'</a>'
4879: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4880: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4881: .')');
4882: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4883: $r->print(
4884: ' <a href="/adm/diff?filename='.
4885: &Apache::lonnet::clutter($root.'.'.$extension).
4886: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4887: '" target="diffs">'.&mt('Diffs').'</a>');
4888: }
4889: $r->print('</span><br />');
1.329 droeschl 4890: }
1.571 raeburn 4891: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4892: }
1.329 droeschl 4893: }
1.521 bisitz 4894: $r->print(
4895: &Apache::loncommon::end_data_table().
1.611 raeburn 4896: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4897: '</form>'
4898: );
1.329 droeschl 4899:
4900: &untiehash();
1.521 bisitz 4901: $r->print(&endContentScreen());
1.571 raeburn 4902: return;
1.329 droeschl 4903: }
4904:
4905: sub mark_hash_old {
4906: my $retie_hash=0;
4907: if ($hashtied) {
4908: $retie_hash=1;
4909: &untiehash();
4910: }
4911: &tiehash('write');
4912: $hash{'old'}=1;
4913: &untiehash();
4914: if ($retie_hash) { &tiehash(); }
4915: }
4916:
4917: sub is_hash_old {
4918: my $untie_hash=0;
4919: if (!$hashtied) {
4920: $untie_hash=1;
4921: &tiehash();
4922: }
4923: my $return=$hash{'old'};
4924: if ($untie_hash) { &untiehash(); }
4925: return $return;
4926: }
4927:
4928: sub changewarning {
4929: my ($r,$postexec,$message,$url)=@_;
4930: if (!&is_hash_old()) { return; }
4931: my $pathvar='folderpath';
4932: my $path=&escape($env{'form.folderpath'});
4933: if (!defined($url)) {
4934: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4935: }
4936: my $course_type = &Apache::loncommon::course_type();
4937: if (!defined($message)) {
4938: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4939: }
4940: $r->print("\n\n".
1.372 bisitz 4941: '<script type="text/javascript">'."\n".
4942: '// <![CDATA['."\n".
4943: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4944: '// ]]>'."\n".
1.369 bisitz 4945: '</script>'."\n".
1.375 tempelho 4946: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4947: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4948: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4949: &mt($message,' <input type="hidden" name="'.
4950: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4951: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4952: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4953: }
4954:
4955:
4956: sub init_breadcrumbs {
1.571 raeburn 4957: my ($form,$text,$help)=@_;
1.329 droeschl 4958: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4959: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4960: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4961: faq=>273,
4962: bug=>'Instructor Interface',
1.571 raeburn 4963: help => $help});
1.329 droeschl 4964: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4965: text=>$text,
4966: faq=>273,
4967: bug=>'Instructor Interface'});
4968: }
4969:
1.441 www 4970: # subroutine to list form elements
4971: sub create_list_elements {
4972: my @formarr = @_;
4973: my $list = '';
1.501 raeburn 4974: foreach my $button (@formarr){
4975: foreach my $picture (keys(%{$button})) {
4976: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4977: }
4978: }
4979: return $list;
4980: }
1.329 droeschl 4981:
1.441 www 4982: # subroutine to create ul from list elements
4983: sub create_form_ul {
4984: my $list = shift;
4985: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4986: return $ul;
4987: }
1.329 droeschl 4988:
1.442 www 4989: #
4990: # Start tabs
4991: #
4992:
4993: sub startContentScreen {
1.484 raeburn 4994: my ($mode) = @_;
4995: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4996: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4997: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4998: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4999: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5000: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5001: } else {
1.549 raeburn 5002: $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 5003: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5004: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5005: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5006: }
5007: $output .= "\n".'</ul>'."\n";
5008: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5009: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5010: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5011: return $output;
1.442 www 5012: }
5013:
5014: #
5015: # End tabs
5016: #
5017:
5018: sub endContentScreen {
1.484 raeburn 5019: return '</div></div></div>';
1.442 www 5020: }
1.329 droeschl 5021:
1.446 www 5022: sub supplemental_base {
1.548 raeburn 5023: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5024: }
5025:
1.329 droeschl 5026: sub handler {
5027: my $r = shift;
5028: &Apache::loncommon::content_type($r,'text/html');
5029: $r->send_http_header;
5030: return OK if $r->header_only;
1.484 raeburn 5031:
5032: # get course data
1.408 raeburn 5033: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5034: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5035: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5036:
1.606 raeburn 5037: # get docroot
5038: my $londocroot = $r->dir_config('lonDocRoot');
5039:
1.484 raeburn 5040: # graphics settings
5041: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5042:
1.443 www 5043: #
1.329 droeschl 5044: # --------------------------------------------- Initialize help topics for this
5045: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5046: 'Adding_External_Resource','Navigate_Content',
5047: 'Adding_Folders','Docs_Overview', 'Load_Map',
5048: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 5049: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.571 raeburn 5050: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
1.572 raeburn 5051: 'Dropbox','Simple_Problem') {
1.329 droeschl 5052: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5053: }
5054: # Composite help files
5055: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5056: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5057: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5058: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5059: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5060: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5061: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5062: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5063: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5064: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5065:
1.611 raeburn 5066: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5067: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5068: unless ($r->uri eq '/adm/supplemental') {
5069: # does this user have privileges to modify content.
1.611 raeburn 5070: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5071: $allowed = 1;
5072: $canedit = 1;
5073: $canview = 1;
5074: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5075: $allowed = 1;
5076: $canview = 1;
5077: }
5078: }
5079: unless ($canedit) {
5080: $disabled = ' disabled="disabled"';
1.472 raeburn 5081: }
1.582 raeburn 5082: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5083: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5084: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 5085: &verifycontent($r);
5086: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5087: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5088: &list_symbs($r);
5089: } elsif ($allowed && $env{'form.docslog'}) {
5090: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5091: my $folder = $env{'form.folder'};
5092: if ($folder eq '') {
5093: $folder='default';
5094: }
1.611 raeburn 5095: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5096: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5097: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5098: &checkversions($r,$canedit);
5099: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5100: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5101: &dumpcourse($r);
1.611 raeburn 5102: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5103: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5104: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5105: } else {
1.611 raeburn 5106: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5107: $noendpage = 1;
5108: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5109: if ($redirect) {
5110: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5111: my $container = 'sequence';
5112: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5113: $is_random_order,$container) =
5114: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5115: my (@folders)=split('&',$env{'form.folderpath'});
5116: $env{'form.foldername'}=&unescape(pop(@folders));
5117: my $folder=pop(@folders);
5118: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5119: $folder.'.'.$container);
5120: my $warning;
5121: if ($fatal) {
5122: if ($container eq 'page') {
5123: $warning = &mt('An error occurred retrieving the contents of the current page.');
5124: } else {
5125: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5126: }
5127: } else {
5128: my $url = $redirect;
5129: my $srcfile = $londocroot.$url;
5130: $url =~ s{^/priv/}{/res/};
5131: my $targetfile = $londocroot.$url;
5132: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5133: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5134: $env{'form.folder'} = $folder;
5135: &snapshotbefore();
5136: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5137: my $ext = 'false';
5138: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5139: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5140: ':'.$ext.':normal:res';
5141: push(@LONCAPA::map::order,$newidx);
5142: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5143: 'string_yesno');
5144: &remember_parms($newidx,'hiddenresource','set','yes');
5145: ($errtext,$fatal) =
5146: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5147: &log_differences($plain);
5148: &mark_hash_old();
5149: $r->internal_redirect($redirect);
5150: return OK;
5151: }
5152: }
5153: }
5154: }
1.445 www 5155: #
5156: # Done catching special calls
1.484 raeburn 5157: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5158: # Get the parameters that may be needed
5159: #
5160: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5161: ['folderpath',
5162: 'forcesupplement','forcestandard',
1.510 raeburn 5163: 'tools','symb','command','supppath']);
1.445 www 5164:
5165: # standard=1: this is a "new-style" course with an uploaded map as top level
5166: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5167:
5168: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5169:
1.484 raeburn 5170: # Decide whether this should display supplemental or main content or utilities
1.445 www 5171: # supplementalflag=1: show supplemental documents
5172: # supplementalflag=0: show standard documents
1.484 raeburn 5173: # toolsflag=1: show utilities
1.445 www 5174:
1.561 raeburn 5175: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5176: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5177: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5178: $supplementalflag=0;
5179: }
5180: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5181: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5182: unless ($allowed) { $supplementalflag=1; }
5183: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5184: my $toolsflag=0;
5185: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5186:
1.329 droeschl 5187: my $script='';
5188: my $showdoc=0;
1.457 raeburn 5189: my $addentries = {};
1.475 raeburn 5190: my $container;
1.329 droeschl 5191: my $containertag;
1.508 raeburn 5192: my $pathitem;
1.598 raeburn 5193: my %ltitools;
1.617 raeburn 5194: my $hiddentop;
1.615 raeburn 5195: my $navmap;
1.617 raeburn 5196: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5197:
1.464 www 5198: # Do we directly jump somewhere?
1.525 raeburn 5199: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5200: if ($env{'form.symb'} ne '') {
1.522 raeburn 5201: $env{'form.folderpath'}=
1.617 raeburn 5202: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5203: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5204: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5205: } elsif ($env{'form.supppath'} ne '') {
5206: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5207: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5208: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5209: }
1.472 raeburn 5210: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5211: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5212: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5213: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5214: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5215: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5216: } elsif ($env{'form.command'} eq 'contents') {
5217: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5218: } elsif ($env{'form.command'} eq 'home') {
5219: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5220: }
5221:
1.525 raeburn 5222:
1.445 www 5223: # Where do we store these for when we come back?
5224: my $stored_folderpath='docs_folderpath';
5225: if ($supplementalflag) {
5226: $stored_folderpath='docs_sup_folderpath';
5227: }
1.464 www 5228:
1.519 raeburn 5229: # No folderpath, and in edit mode, see if we have something stored
5230: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5231: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5232: {'folderpath' => 'scalar'});
1.615 raeburn 5233:
5234: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5235: if ($supplementalflag) {
5236: undef($env{'form.folderpath'}) if ($1 eq 'default');
5237: } else {
5238: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5239: }
5240: } else {
1.523 raeburn 5241: undef($env{'form.folderpath'});
5242: }
1.329 droeschl 5243: }
1.446 www 5244:
5245: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5246: if (!$allowed) {
1.446 www 5247: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5248: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5249: }
5250: }
1.446 www 5251: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5252: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5253: $env{'form.folderpath'} = &supplemental_base()
5254: .'&'.
1.329 droeschl 5255: $env{'form.folderpath'};
5256: }
1.615 raeburn 5257: # If allowed and user's role is not advanced check folderpath is not hidden
5258: if (($allowed) && (!$env{'request.role.adv'}) &&
5259: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5260: my $folderurl;
5261: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5262: my $folder = $pathitems[-2];
5263: if ($folder eq '') {
5264: undef($env{'form.folderpath'});
5265: } else {
5266: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5267: if ((split(/\:/,$pathitems[-1]))[4]) {
5268: $folderurl .= '.page';
5269: } else {
5270: $folderurl .= '.sequence';
5271: }
1.617 raeburn 5272: unless (ref($navmap)) {
5273: $navmap = Apache::lonnavmaps::navmap->new();
5274: }
1.615 raeburn 5275: if (ref($navmap)) {
5276: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5277: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5278: unless (@resources) {
5279: undef($env{'form.folderpath'});
5280: }
1.615 raeburn 5281: }
5282: }
5283: }
5284: }
5285:
5286:
1.446 www 5287: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5288: unless ($env{'form.folderpath'}) {
1.446 www 5289: if ($supplementalflag) {
5290: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5291: } elsif ($allowed) {
5292: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5293: }
1.472 raeburn 5294: }
1.446 www 5295:
1.445 www 5296: # Store this
1.484 raeburn 5297: unless ($toolsflag) {
1.615 raeburn 5298: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5299: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5300: {'folderpath' => 'scalar'});
1.510 raeburn 5301: }
1.519 raeburn 5302: my $folderpath;
1.484 raeburn 5303: if ($env{'form.folderpath'}) {
1.519 raeburn 5304: $folderpath = $env{'form.folderpath'};
5305: my (@folders)=split('&',$env{'form.folderpath'});
5306: $env{'form.foldername'}=&unescape(pop(@folders));
5307: if ($env{'form.foldername'} =~ /\:1$/) {
5308: $container = 'page';
5309: } else {
5310: $container = 'sequence';
5311: }
5312: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5313: } else {
1.519 raeburn 5314: if ($env{'form.folder'} eq '' ||
5315: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5316: if ($env{'form.folder'} eq 'supplemental') {
5317: $folderpath=&supplemental_base();
5318: } elsif (!$hiddentop) {
5319: $folderpath='default&'.
5320: &escape(&mt('Main Content').':::::');
5321: }
1.484 raeburn 5322: }
5323: }
1.519 raeburn 5324: $containertag = '<input type="hidden" name="folderpath" value="" />';
5325: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5326: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5327: $showdoc='/'.$1;
5328: }
5329: if ($showdoc) { # got called in sequence from course
5330: $allowed=0;
5331: } else {
1.611 raeburn 5332: if ($canedit) {
1.484 raeburn 5333: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5334: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5335: }
5336: }
1.329 droeschl 5337: }
5338:
1.344 bisitz 5339: # get personal data
1.329 droeschl 5340: my $uname=$env{'user.name'};
5341: my $udom=$env{'user.domain'};
5342: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5343:
5344: if ($allowed) {
1.484 raeburn 5345: if ($toolsflag) {
5346: $script .= &inject_data_js();
5347: my ($home,$other,%outhash)=&authorhosts();
5348: if (!$home && $other) {
5349: my @hosts;
5350: foreach my $aurole (keys(%outhash)) {
5351: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5352: push(@hosts,$outhash{$aurole});
5353: }
5354: }
5355: $script .= &dump_switchserver_js(@hosts);
5356: }
1.458 raeburn 5357: } else {
1.570 raeburn 5358: my $tid = 1;
1.484 raeburn 5359: my @tabids;
5360: if ($supplementalflag) {
5361: @tabids = ('002','ee2','ff2');
1.570 raeburn 5362: $tid = 2;
1.484 raeburn 5363: } else {
5364: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5365: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5366: unshift(@tabids,'001');
5367: push(@tabids,('dd1','ee1'));
5368: }
1.458 raeburn 5369: }
1.484 raeburn 5370: my $tabidstr = join("','",@tabids);
1.598 raeburn 5371: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5372: my $posslti = keys(%ltitools);
1.606 raeburn 5373: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.617 raeburn 5374: $londocroot,$canedit,\$navmap).
1.484 raeburn 5375: &history_tab_js().
5376: &inject_data_js().
1.570 raeburn 5377: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5378: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5379: $addentries = {
1.485 raeburn 5380: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5381: };
1.458 raeburn 5382: }
1.538 raeburn 5383: $script .= &paste_popup_js();
1.501 raeburn 5384: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5385: &mt('Switch server?');
5386:
5387:
1.329 droeschl 5388: }
5389: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5390: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5391: .'// <![CDATA['."\n"
5392: .$script."\n"
5393: .'// ]]>'."\n"
1.595 musolffc 5394: .'</script>'."\n"
5395: .'<script type="text/javascript"
5396: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5397:
5398: # Breadcrumbs
5399: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5400:
5401: if ($showdoc) {
5402: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5403: {'force_register' => $showdoc,}));
1.571 raeburn 5404: } elsif ($toolsflag) {
1.611 raeburn 5405: my ($breadtext,$breadtitle);
1.617 raeburn 5406: $breadtext = "$crstype Editor";
1.611 raeburn 5407: if ($canedit) {
5408: $breadtitle = 'Editing '.$crstype.' Contents';
5409: } else {
5410: $breadtext .= ' (View-only mode)';
5411: $breadtitle = 'Viewing '.$crstype.' Contents';
5412: }
1.571 raeburn 5413: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5414: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5415: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5416: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5417: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5418: $breadtitle)
1.571 raeburn 5419: );
1.510 raeburn 5420: } elsif ($r->uri eq '/adm/supplemental') {
5421: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5422: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5423: {'bread_crumbs' => $brcrum,}));
5424: } else {
1.611 raeburn 5425: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5426: $breadtext = "$crstype Editor";
1.611 raeburn 5427: if ($canedit) {
5428: $breadtitle = 'Editing '.$crstype.' Contents';
5429: $helpitem = 'Docs_Adding_Course_Doc';
5430: } else {
5431: $breadtext .= ' (View-only mode)';
5432: $breadtitle = 'Viewing '.$crstype.' Contents';
5433: $helpitem = 'Docs_Viewing_Course_Doc';
5434: }
1.392 raeburn 5435: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5436: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5437: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5438: {'add_entries' => $addentries}
5439: )
1.392 raeburn 5440: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5441: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5442: $breadtitle,
5443: $helpitem)
1.392 raeburn 5444: );
5445: }
1.364 bisitz 5446:
1.329 droeschl 5447: my %allfiles = ();
5448: my %codebase = ();
1.440 raeburn 5449: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5450: if ($canedit) {
1.329 droeschl 5451: if (($env{'form.uploaddoc.filename'}) &&
5452: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5453: my $context = $1;
5454: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5455: undef($hadchanges);
1.440 raeburn 5456: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5457: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5458: if ($hadchanges) {
5459: &mark_hash_old();
5460: }
1.440 raeburn 5461: $r->print($upload_output);
5462: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5463: # Process file upload - phase two - upload embedded objects
5464: $uploadphase = 'check_embedded';
5465: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5466: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5467: $env{'form.newidx'});
5468: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5469: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5470: my ($destination,$dir_root) = &embedded_destination();
5471: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5472: my $actionurl = '/adm/coursedocs';
5473: my ($result,$flag) =
5474: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5475: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5476: $actionurl);
5477: $r->print($result.&return_to_editor());
5478: } elsif ($env{'form.phase'} eq 'check_embedded') {
5479: # Process file upload - phase three - modify references in HTML file
5480: $uploadphase = 'modified_orightml';
5481: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5482: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5483: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5484: my $result =
5485: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5486: $docuname,$docudom,undef,
5487: $dir_root);
5488: $r->print($result.&return_to_editor());
1.476 raeburn 5489: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5490: $uploadphase = 'decompress_phase_one';
5491: $r->print(&decompression_phase_one().
5492: &return_to_editor());
5493: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5494: $uploadphase = 'decompress_phase_two';
5495: $r->print(&decompression_phase_two().
5496: &return_to_editor());
1.329 droeschl 5497: }
5498: }
5499:
1.484 raeburn 5500: if ($allowed && $toolsflag) {
5501: $r->print(&startContentScreen('tools'));
1.611 raeburn 5502: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5503: $r->print(&endContentScreen());
5504: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5505: # -----------------------------------------------------------------------------
5506: my %lt=&Apache::lonlocal::texthash(
5507: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5508: 'upfi' => 'Upload File',
1.553 raeburn 5509: 'upld' => 'Upload Content',
1.329 droeschl 5510: 'srch' => 'Search',
5511: 'impo' => 'Import',
1.487 raeburn 5512: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5513: 'impm' => 'Import from Assembled Map',
1.606 raeburn 5514: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5515: 'extr' => 'External Resource',
5516: 'extt' => 'External Tool',
1.329 droeschl 5517: 'selm' => 'Select Map',
5518: 'load' => 'Load Map',
5519: 'newf' => 'New Folder',
5520: 'newp' => 'New Composite Page',
5521: 'syll' => 'Syllabus',
1.425 raeburn 5522: 'navc' => 'Table of Contents',
1.343 biermanm 5523: 'sipa' => 'Simple Course Page',
1.329 droeschl 5524: 'sipr' => 'Simple Problem',
1.534 raeburn 5525: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5526: 'stpr' => 'Standard Problem',
5527: 'news' => 'New sub-directory',
5528: 'crpr' => 'Create Problem',
1.329 droeschl 5529: 'drbx' => 'Drop Box',
1.451 www 5530: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5531: 'bull' => 'Discussion Board',
1.347 weissno 5532: 'mypi' => 'My Personal Information Page',
1.353 weissno 5533: 'grpo' => 'Group Portfolio',
1.329 droeschl 5534: 'rost' => 'Course Roster',
1.528 raeburn 5535: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5536: 'imsf' => 'IMS Upload',
5537: 'imsl' => 'Upload IMS package',
1.501 raeburn 5538: 'cms' => 'Origin of IMS package',
5539: 'se' => 'Select',
1.329 droeschl 5540: 'file' => 'File',
5541: 'title' => 'Title',
1.606 raeburn 5542: 'addp' => 'Add Placeholder to course?',
5543: 'uste' => 'Use Template?',
5544: 'fnam' => 'File Name:',
5545: 'loca' => 'Location:',
5546: 'dire' => 'Directory:',
5547: 'cate' => 'Category:',
5548: 'tmpl' => 'Template:',
1.329 droeschl 5549: 'comment' => 'Comment',
1.403 raeburn 5550: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5551: 'bb5' => 'Blackboard 5',
5552: 'bb6' => 'Blackboard 6',
5553: 'angel5' => 'ANGEL 5.5',
5554: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5555: 'yes' => 'Yes',
5556: 'no' => 'No',
1.618 raeburn 5557: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5558: );
1.329 droeschl 5559: # -----------------------------------------------------------------------------
1.595 musolffc 5560:
5561: # Calculate free quota space for a user or course. A javascript function checks
5562: # file size to determine if upload should be allowed.
5563: my $quotatype = 'unofficial';
5564: if ($crstype eq 'Community') {
1.601 raeburn 5565: $quotatype = 'community';
5566: } elsif ($crstype eq 'Placement') {
5567: $quotatype = 'placement';
1.595 musolffc 5568: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5569: $quotatype = 'official';
5570: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5571: $quotatype = 'textbook';
5572: }
5573: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5574: 'course',$quotatype); # expressed in MB
5575: my $current_disk_usage = 0;
5576: foreach my $subdir ('docs','supplemental') {
5577: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5578: "userfiles/$subdir",1); # expressed in kB
5579: }
5580: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5581: my $usage = $current_disk_usage/1024; # in MB
5582: my $quota = $disk_quota;
5583: my $percent;
5584: if ($disk_quota == 0) {
5585: $percent = 100.0;
5586: } else {
1.619 raeburn 5587: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5588: }
5589: $usage = sprintf("%.2f",$usage);
5590: $quota = sprintf("%.2f",$quota);
5591: $percent = sprintf("%.0f",$percent);
5592: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5593: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5594:
1.329 droeschl 5595: my $fileupload=(<<FIUP);
1.605 raeburn 5596: $quotainfo
1.329 droeschl 5597: $lt{'file'}:<br />
1.611 raeburn 5598: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5599: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5600: FIUP
5601:
5602: my $checkbox=(<<CHBO);
5603: <!-- <label>$lt{'parse'}?
5604: <input type="checkbox" name="parserflag" />
5605: </label> -->
5606: <label>
1.611 raeburn 5607: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5608: </label>
5609: CHBO
1.501 raeburn 5610: my $imsfolder = $env{'form.folder'};
5611: if ($imsfolder eq '') {
5612: $imsfolder = 'default';
5613: }
5614: my $imspform=(<<IMSFORM);
5615: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5616: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5617: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5618: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5619: <legend>$lt{'imsf'}</legend>
5620: $fileupload
5621: <br />
5622: <p>
5623: $lt{'cms'}:
1.611 raeburn 5624: <select name="source" $disabled>
1.501 raeburn 5625: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5626: <option value="bb5">$lt{'bb5'}</option>
5627: <option value="bb6">$lt{'bb6'}</option>
5628: <option value="angel5">$lt{'angel5'}</option>
5629: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5630: </select>
5631: <input type="hidden" name="folder" value="$imsfolder" />
5632: </p>
5633: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5634: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5635: </fieldset>
5636: </form>
5637: IMSFORM
1.329 droeschl 5638:
5639: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5640: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5641: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5642: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5643: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5644: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5645: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5646: $fileupload
1.329 droeschl 5647: <br />
5648: $lt{'title'}:<br />
1.611 raeburn 5649: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5650: $pathitem
1.329 droeschl 5651: <input type="hidden" name="cmd" value="upload_default" />
5652: <br />
1.458 raeburn 5653: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5654: $checkbox
5655: </span>
1.501 raeburn 5656: <br clear="all" />
1.611 raeburn 5657: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5658: </fieldset>
5659: </form>
1.383 tempelho 5660: FUFORM
1.329 droeschl 5661:
1.611 raeburn 5662: my $mapimportjs;
5663: if ($canedit) {
5664: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5665: } else {
5666: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5667: }
1.502 raeburn 5668: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5669: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5670: $lt{'impm'}</a>$help{'Load_Map'}
5671: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5672: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5673: <legend>$lt{'impm'}</legend>
1.371 tempelho 5674: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5675: $lt{'copm'}<br />
5676: <span class="LC_nobreak">
5677: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5678: onfocus="this.blur();$mapimportjs" $disabled />
5679: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5680: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5681: </fieldset>
5682: </form>
5683:
1.383 tempelho 5684: SEDFFORM
1.606 raeburn 5685: my $importcrsresform;
1.608 raeburn 5686: my ($numdirs,$pickfile) =
5687: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5688: "resize_scrollbox('contentscroll','1','0');",
5689: undef,'res');
1.606 raeburn 5690: if ($pickfile) {
5691: $importcrsresform=(<<CRSFORM);
5692: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5693: $lt{'imcr'}</a>$help{'Course_Resources'}
5694: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5695: <fieldset id="importcrsresform" style="display: none;">
5696: <legend>$lt{'imcr'}</legend>
5697: <input type="hidden" name="active" value="bb" />
5698: $pickfile
5699: <p>
1.611 raeburn 5700: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5701: </p>
5702: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5703: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5704: </fieldset>
5705: </form>
5706: CRSFORM
5707: }
5708:
1.611 raeburn 5709: my $fromstoredjs;
5710: if ($canedit) {
5711: $fromstoredjs = 'open_StoredLinks_Import()';
5712: } else {
5713: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5714: }
5715:
1.502 raeburn 5716: my @importpubforma = (
1.508 raeburn 5717: { '<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 5718: { '<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 5719: { '<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 5720: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5721: );
5722: if ($pickfile) {
5723: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5724: }
1.502 raeburn 5725: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5726: my $extresourcesform =
5727: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5728: $help{'Adding_External_Resource'},
5729: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5730: my $exttoolform =
5731: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5732: $help{'Adding_External_Tool'},undef,
5733: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5734: \%ltitools,$disabled);
1.329 droeschl 5735: if ($allowed) {
1.492 raeburn 5736: my $folder = $env{'form.folder'};
5737: if ($folder eq '') {
5738: $folder='default';
5739: }
1.615 raeburn 5740: if ($canedit) {
5741: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5742: if ($output) {
5743: $r->print($output);
5744: }
1.538 raeburn 5745: }
1.337 ehlerst 5746: $r->print(<<HIDDENFORM);
5747: <form name="renameform" method="post" action="/adm/coursedocs">
5748: <input type="hidden" name="title" />
5749: <input type="hidden" name="cmd" />
5750: <input type="hidden" name="markcopy" />
5751: <input type="hidden" name="copyfolder" />
5752: $containertag
5753: </form>
1.484 raeburn 5754:
1.337 ehlerst 5755: HIDDENFORM
1.508 raeburn 5756: $r->print(&makesimpleeditform($pathitem)."\n".
5757: &makedocslogform($pathitem."\n".
1.484 raeburn 5758: '<input type="hidden" name="folder" value="'.
5759: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5760: }
1.442 www 5761:
5762: # Generate the tabs
1.510 raeburn 5763: my ($mode,$needs_end);
1.472 raeburn 5764: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5765: my @folders = split('&',$env{'form.folderpath'});
5766: unless (@folders > 2) {
5767: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5768: $needs_end = 1;
5769: }
1.472 raeburn 5770: } else {
1.484 raeburn 5771: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5772: $needs_end = 1;
1.472 raeburn 5773: }
1.443 www 5774:
1.442 www 5775: #
5776:
5777: my $savefolderpath;
5778:
1.395 raeburn 5779: if ($allowed) {
1.329 droeschl 5780: my $folder=$env{'form.folder'};
1.615 raeburn 5781: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5782: $folder='default';
1.356 tempelho 5783: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5784: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5785: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5786: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5787: }
5788: my $postexec='';
5789: if ($folder eq 'default') {
1.372 bisitz 5790: $r->print('<script type="text/javascript">'."\n"
5791: .'// <![CDATA['."\n"
5792: .'this.window.name="loncapaclient";'."\n"
5793: .'// ]]>'."\n"
5794: .'</script>'."\n"
1.369 bisitz 5795: );
1.329 droeschl 5796: } else {
5797: #$postexec='self.close();';
5798: }
1.504 raeburn 5799: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5800: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5801: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5802:
5803: my $newnavform=(<<NNFORM);
5804: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5805: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5806: $pathitem
1.329 droeschl 5807: <input type="hidden" name="importdetail"
5808: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 5809: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5810: $help{'Navigate_Content'}
5811: </form>
5812: NNFORM
5813: my $newsmppageform=(<<NSPFORM);
5814: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5815: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5816: $pathitem
1.329 droeschl 5817: <input type="hidden" name="importdetail" value="" />
1.423 onken 5818: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5819: $help{'Simple Page'}
1.329 droeschl 5820: </form>
5821: NSPFORM
5822:
5823: my $newsmpproblemform=(<<NSPROBFORM);
5824: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5825: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5826: $pathitem
1.329 droeschl 5827: <input type="hidden" name="importdetail" value="" />
1.423 onken 5828: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5829: $help{'Simple_Problem'}
1.329 droeschl 5830: </form>
5831:
5832: NSPROBFORM
5833:
5834: my $newdropboxform=(<<NDBFORM);
5835: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5836: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5837: $pathitem
1.329 droeschl 5838: <input type="hidden" name="importdetail" value="" />
1.423 onken 5839: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5840: $help{'Dropbox'}
1.344 bisitz 5841: </form>
1.329 droeschl 5842: NDBFORM
5843:
5844: my $newexuploadform=(<<NEXUFORM);
5845: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5846: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5847: $pathitem
1.329 droeschl 5848: <input type="hidden" name="importdetail" value="" />
1.423 onken 5849: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5850: $help{'Score_Upload_Form'}
5851: </form>
5852: NEXUFORM
5853:
5854: my $newbulform=(<<NBFORM);
5855: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5856: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5857: $pathitem
1.329 droeschl 5858: <input type="hidden" name="importdetail" value="" />
1.423 onken 5859: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5860: $help{'Bulletin Board'}
5861: </form>
5862: NBFORM
5863:
5864: my $newaboutmeform=(<<NAMFORM);
5865: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5866: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5867: $pathitem
1.329 droeschl 5868: <input type="hidden" name="importdetail"
5869: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 5870: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5871: $help{'My Personal Information Page'}
1.329 droeschl 5872: </form>
5873: NAMFORM
5874:
5875: my $newaboutsomeoneform=(<<NASOFORM);
5876: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5877: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5878: $pathitem
1.329 droeschl 5879: <input type="hidden" name="importdetail" value="" />
1.423 onken 5880: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5881: </form>
5882: NASOFORM
5883:
5884: my $newrosterform=(<<NROSTFORM);
5885: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5886: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5887: $pathitem
1.329 droeschl 5888: <input type="hidden" name="importdetail"
5889: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 5890: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 5891: $help{'Course_Roster'}
1.329 droeschl 5892: </form>
5893: NROSTFORM
5894:
1.534 raeburn 5895: my $newwebpage;
5896: if ($folder =~ /^default_?(\d*)$/) {
5897: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5898: if ($1) {
5899: $newwebpage .= $1;
5900: } else {
5901: $newwebpage .= 'default';
5902: }
5903: $newwebpage .= '/new.html';
5904: }
5905: my $newwebpageform =(<<NWEBFORM);
5906: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5907: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5908: $pathitem
5909: <input type="hidden" name="importdetail" value="$newwebpage" />
5910: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5911: $help{'Web_Page'}
1.534 raeburn 5912: </form>
5913: NWEBFORM
1.604 raeburn 5914:
1.606 raeburn 5915: my @ids=&Apache::lonnet::current_machine_ids();
5916: my %select_menus;
5917: my $numauthor = 0;
5918: my $numcrsdirs = 0;
5919: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5920: if ($env{'user.author'}) {
5921: $numauthor ++;
5922: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5923: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5924: my $is_home = 1;
5925: my %subdirs;
1.608 raeburn 5926: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5927: $select_menus{'author'}->{'default'} = '/';
5928: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5929: my @ordered = ('/');
5930: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5931: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5932: push(@ordered,$relpath);
5933: }
5934: $select_menus{'author'}->{'order'} = \@ordered;
5935: } else {
5936: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5937: $select_menus{'author'}->{'default'} = 'switch';
5938: $select_menus{'author'}->{'order'} = ['switch'];
5939: }
5940: }
5941: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5942: ['active'],['ca','aa']);
5943: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5944: my %by_roletype;
5945: if (keys(%roleshash)) {
5946: foreach my $entry (keys(%roleshash)) {
5947: my ($auname,$audom,$roletype) = split(/:/,$entry);
5948: my $key = $entry;
5949: $key =~ s/:/___/g;
5950: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5951: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5952: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5953: if (grep(/^\Q$rolehome\E$/,@ids)) {
5954: my $is_home = 1;
5955: my (%subdirs,@ordered);
5956: my $toppath="/priv/$audom/$auname";
1.608 raeburn 5957: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5958: $select_menus{$key}->{'default'} = '/';
5959: $select_menus{$key}->{'select2'}->{'/'} = '/';
5960: my @ordered = ('/');
5961: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5962: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
5963: push(@ordered,$relpath);
5964: }
5965: $select_menus{$key}->{'order'} = \@ordered;
5966: } else {
5967: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
5968: $select_menus{$key}->{'default'} = 'switch';
5969: $select_menus{$key}->{'order'} = ['switch'];
5970: }
5971: $numauthor ++;
5972: }
5973: }
5974: my ($pickdir,$showtitle);;
5975: if ($numauthor) {
5976: my @order;
5977: my $defrole;
5978: if ($env{'user.author'}) {
5979: push(@order,'author');
5980: $defrole = 'author';
5981: }
5982: if (keys(%by_roletype)) {
5983: foreach my $possrole ('ca','aa') {
5984: if (ref($by_roletype{$possrole}) eq 'HASH') {
5985: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
5986: unless ($defrole) {
5987: $defrole = $author;
5988: }
5989: push(@order,$author.'___'.$possrole);
5990: }
5991: }
5992: }
5993: }
5994: $select_menus{'course'}->{'text'} = &mt('Course Resource');
5995: if (grep(/^\Q$crshome\E$/,@ids)) {
5996: my $is_home = 1;
5997: my %subdirs;
5998: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 5999: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6000: $numcrsdirs = keys(%subdirs);
6001: $select_menus{'course'}->{'default'} = '/';
6002: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6003: my @ordered = ('/');
6004: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6005: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6006: push(@ordered,$relpath);
6007: }
6008: $select_menus{'course'}->{'order'} = \@ordered;
6009: } else {
6010: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6011: $select_menus{'course'}->{'default'} = 'switch';
6012: $select_menus{'course'}->{'order'} = ['switch'];
6013: }
6014: push(@order,'course');
6015: $pickdir = $lt{'loca'}.
6016: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6017: $defrole,'authorrole','authorpath',
6018: \%select_menus,\@order,'toggleCrsResTitle();',
6019: '','priv').'<br />';
6020: $showtitle = 'none';
6021: } else {
6022: my $is_home;
6023: $showtitle = 'inline';
6024: if (grep(/^\Q$crshome\E$/,@ids)) {
6025: $is_home = 1;
6026: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6027: my $toppath="/priv/$coursedom/$coursenum'}";
6028: my %subdirs;
1.608 raeburn 6029: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6030: $numcrsdirs = keys(%subdirs);
6031: if ($numcrsdirs) {
6032: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6033: '<option value="/">/</option>'."\n";
6034: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6035: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6036: }
6037: $pickdir .= '</select>';
6038: } else {
6039: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6040: }
6041: }
6042: }
6043:
6044: my %seltemplate_menus;
6045: my @files = &Apache::lonhomework::get_template_list('problem');
6046: my @noexamplelink = ('blank.problem','blank.library','script.library');
6047: my $currentcategory = '';
6048: my @ordered = ('');
6049: my %templatehelp;
6050: my $defcategory = '';
6051: my @catorder = ($defcategory);
6052: $seltemplate_menus{$defcategory}->{'order'} = [''];
6053: $seltemplate_menus{$defcategory}->{'text'} = '';
6054: foreach my $file (@files) {
6055: if (ref($file) eq 'ARRAY') {
6056: my ($path,$title,$category,$help) = @{$file};
6057: next if ($title !~ /\S/);
6058: if (&js_escape($category) ne $currentcategory) {
6059: $currentcategory = &js_escape($category);
6060: push(@catorder,&js_escape($currentcategory));
6061: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6062: $seltemplate_menus{$currentcategory}->{'default'} = '';
6063: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6064: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6065: }
6066: if ($path) {
6067: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6068: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6069: if ($help) {
6070: $templatehelp{$path} = $help;
6071: }
6072: }
6073: }
6074: }
6075:
6076: my $templates = $lt{'cate'}.' '.
6077: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6078: $defcategory,'tempcategory','template',
6079: \%seltemplate_menus,\@catorder,
6080: "resize_scrollbox('contentscroll','1','0');",
6081: "toggleExampleText();",'template').'<br />';
6082: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6083: '<span id="newresexample">'.&mt('Example').'<span></a>';
6084: my $crsresform=(<<RESFORM);
6085: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6086: $lt{'stpr'}</a>$help{'Course_Resource'}
6087: <form action="/adm/coursedocs" method="post" name="courseresform">
6088: <fieldset id="crsresform" style="display:none;">
6089: <legend>$lt{'stpr'}</legend>
6090: <input type="hidden" name="active" value="ee" />
6091: <p>
6092: $pickdir
6093: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6094: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6095:
1.611 raeburn 6096: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6097: </span><span id="newsubdir"></span>
6098: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6099: </p>
6100: $lt{'fnam'}
1.611 raeburn 6101: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6102: <p>
6103: <div id="newresource" style="display:$showtitle">
6104: $lt{'addp'}
1.611 raeburn 6105: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6106: $lt{'no'}</label>
1.611 raeburn 6107: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6108: $lt{'yes'}</label>
6109: <span id="newrestitle"></span>
1.611 raeburn 6110: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6111: </div>
6112: </p>
6113: <p>
6114: $lt{'uste'}
1.611 raeburn 6115: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6116: $lt{'no'}</label>
1.611 raeburn 6117: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6118: $lt{'yes'}</label>
6119: <div id="newrestemplate" style="display:none">
6120: $templates
6121: $templatepreview
6122: </div>
6123: </p>
6124: <span class="LC_nobreak">
6125: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6126: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6127: </span>
6128: </fieldset>
6129: </form>
6130:
6131: RESFORM
1.534 raeburn 6132:
1.342 ehlerst 6133: my $specialdocumentsform;
1.383 tempelho 6134: my @specialdocumentsforma;
1.451 www 6135: my $gradingform;
6136: my @gradingforma;
6137: my $communityform;
6138: my @communityforma;
1.351 ehlerst 6139: my $newfolderform;
1.390 tempelho 6140: my $newfolderb;
1.342 ehlerst 6141:
1.451 www 6142: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6143:
1.329 droeschl 6144: my $newpageform=(<<NPFORM);
6145: <form action="/adm/coursedocs" method="post" name="newpage">
6146: <input type="hidden" name="folderpath" value="$path" />
6147: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6148: <input type="hidden" name="active" value="ee" />
1.423 onken 6149: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6150: $help{'Adding_Pages'}
1.329 droeschl 6151: </form>
6152: NPFORM
1.390 tempelho 6153:
6154:
1.351 ehlerst 6155: $newfolderform=(<<NFFORM);
1.329 droeschl 6156: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6157: $pathitem
1.329 droeschl 6158: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6159: <input type="hidden" name="active" value="" />
1.422 onken 6160: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6161: </form>
6162: NFFORM
6163:
6164: my $newsylform=(<<NSYLFORM);
6165: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6166: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6167: $pathitem
1.329 droeschl 6168: <input type="hidden" name="importdetail"
6169: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6170: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6171: $help{'Syllabus'}
1.383 tempelho 6172:
1.329 droeschl 6173: </form>
6174: NSYLFORM
1.364 bisitz 6175:
1.329 droeschl 6176: my $newgroupfileform=(<<NGFFORM);
6177: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6178: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6179: $pathitem
1.329 droeschl 6180: <input type="hidden" name="importdetail"
6181: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6182: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6183: $help{'Group Portfolio'}
1.329 droeschl 6184: </form>
6185: NGFFORM
1.383 tempelho 6186: @specialdocumentsforma=(
1.421 onken 6187: {'<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 6188: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6189: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6190: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6191: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6192: );
6193: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6194:
1.434 raeburn 6195:
6196: my @importdoc = (
1.519 raeburn 6197: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6198: );
1.598 raeburn 6199: if (keys(%ltitools)) {
6200: push(@importdoc,
6201: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6202: );
6203: }
1.519 raeburn 6204: unless ($container eq 'page') {
6205: push(@importdoc,
6206: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6207: );
6208: }
6209: push(@importdoc,
1.558 raeburn 6210: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6211: );
1.501 raeburn 6212: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6213:
1.451 www 6214: @gradingforma=(
6215: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6216: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6217: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6218: {'<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 6219: );
6220: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6221:
6222: @communityforma=(
6223: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6224: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6225: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6226: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6227: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6228: );
6229: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6230:
1.330 tempelho 6231: my %orderhash = (
1.553 raeburn 6232: 'aa' => ['Upload',$fileuploadform],
6233: 'bb' => ['Import',$importpubform],
6234: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6235: );
1.519 raeburn 6236: unless ($container eq 'page') {
1.434 raeburn 6237: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6238: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6239: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6240: }
6241:
1.341 ehlerst 6242: $hadchanges=0;
1.484 raeburn 6243: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6244: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6245: $supplementalflag,\%orderhash,$iconpath,$pathitem,
6246: \%ltitools,$canedit,\$navmap,$hiddentop);
1.617 raeburn 6247: undef($navmap);
1.443 www 6248: if ($error) {
6249: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6250: }
6251: if ($hadchanges) {
6252: &mark_hash_old();
6253: }
1.341 ehlerst 6254:
1.443 www 6255: &changewarning($r,'');
6256: }
1.458 raeburn 6257: }
1.442 www 6258:
1.443 www 6259: # Supplemental documents start here
6260:
1.329 droeschl 6261: my $folder=$env{'form.folder'};
1.443 www 6262: unless ($supplementalflag) {
1.329 droeschl 6263: $folder='supplemental';
6264: }
6265: if ($folder =~ /^supplemental$/ &&
6266: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6267: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6268: } elsif ($allowed) {
1.356 tempelho 6269: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6270: }
1.508 raeburn 6271: $pathitem = '<input type="hidden" name="folderpath" value="'.
6272: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6273: if ($allowed) {
6274: my $folderseq=
1.504 raeburn 6275: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6276:
6277: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6278: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6279: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6280: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6281: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6282: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6283: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6284: $fileupload
6285: <br />
6286: <br />
6287: <span class="LC_nobreak">
6288: $checkbox
6289: </span>
6290: <br /><br />
6291: $lt{'comment'}:<br />
1.383 tempelho 6292: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6293: <br />
1.508 raeburn 6294: $pathitem
1.329 droeschl 6295: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6296: <input type='submit' value="$lt{'upld'}" />
6297: </form>
1.329 droeschl 6298: SUPDOCFORM
6299:
6300: my $supnewfolderform=(<<SNFFORM);
6301: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6302: <input type="hidden" name="active" value="" />
1.508 raeburn 6303: $pathitem
1.329 droeschl 6304: <input type="hidden" name="importdetail" value="" />
1.423 onken 6305: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6306: $help{'Adding_Folders'}
1.329 droeschl 6307: </form>
6308: SNFFORM
1.383 tempelho 6309:
1.510 raeburn 6310: my $supextform =
6311: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6312: $help{'Adding_External_Resource'},
6313: undef,undef,undef,undef,undef,undef,
6314: $disabled);
1.329 droeschl 6315:
1.598 raeburn 6316: my $supexttoolform =
6317: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6318: $help{'Adding_External_Tool'},
6319: undef,undef,'tool',$coursedom,
1.611 raeburn 6320: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6321:
1.329 droeschl 6322: my $supnewsylform=(<<SNSFORM);
6323: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6324: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6325: $pathitem
1.329 droeschl 6326: <input type="hidden" name="importdetail"
6327: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6328: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6329: $help{'Syllabus'}
6330: </form>
6331: SNSFORM
6332:
6333: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6334: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6335: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6336: $pathitem
1.329 droeschl 6337: <input type="hidden" name="importdetail"
6338: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6339: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6340: $help{'My Personal Information Page'}
1.329 droeschl 6341: </form>
6342: SNAMFORM
6343:
1.534 raeburn 6344: my $supwebpage;
6345: if ($folder =~ /^supplemental_?(\d*)$/) {
6346: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6347: if ($1) {
6348: $supwebpage .= $1;
6349: } else {
6350: $supwebpage .= 'default';
6351: }
6352: $supwebpage .= '/new.html';
6353: }
6354: my $supwebpageform =(<<SWEBFORM);
6355: <form action="/adm/coursedocs" method="post" name="supwebpage">
6356: <input type="hidden" name="active" value="cc" />
6357: $pathitem
6358: <input type="hidden" name="importdetail" value="$supwebpage" />
6359: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6360: $help{'Web_Page'}
1.534 raeburn 6361: </form>
6362: SWEBFORM
6363:
1.333 muellerd 6364:
1.383 tempelho 6365: my @specialdocs = (
1.618 raeburn 6366: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6367: =>$supnewsylform},
1.611 raeburn 6368: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6369: =>$supnewaboutmeform},
1.534 raeburn 6370: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6371:
1.383 tempelho 6372: );
1.417 droeschl 6373: my @supimportdoc = (
1.515 raeburn 6374: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6375: =>$supextform});
6376: if (keys(%ltitools)) {
6377: push(@supimportdoc,
6378: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6379: =>$supexttoolform});
6380: }
6381: push(@supimportdoc,
6382: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6383: =>$supupdocform},
1.598 raeburn 6384: );
1.501 raeburn 6385:
6386: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6387: my %suporderhash = (
1.390 tempelho 6388: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6389: 'ee' => ['Upload',$supupdocform],
6390: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6391: );
1.443 www 6392: if ($supplementalflag) {
1.458 raeburn 6393: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6394: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.617 raeburn 6395: \%ltitools,$canedit);
1.443 www 6396: if ($error) {
6397: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6398: } else {
6399: if ($suppchanges) {
6400: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6401: my @ids=&Apache::lonnet::current_machine_ids();
6402: foreach my $server (keys(%servers)) {
6403: next if (grep(/^\Q$server\E$/,@ids));
6404: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6405: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6406: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6407: }
6408: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6409: undef($suppchanges);
6410: }
6411: }
1.393 raeburn 6412: }
1.443 www 6413: } elsif ($supplementalflag) {
1.458 raeburn 6414: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6415: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 6416: if ($error) {
6417: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6418: }
1.393 raeburn 6419: }
1.389 tempelho 6420:
1.510 raeburn 6421: if ($needs_end) {
6422: $r->print(&endContentScreen());
6423: }
1.383 tempelho 6424:
1.329 droeschl 6425: if ($allowed) {
6426: $r->print('
6427: <form method="post" name="extimport" action="/adm/coursedocs">
6428: <input type="hidden" name="title" />
6429: <input type="hidden" name="url" />
6430: <input type="hidden" name="useform" />
6431: <input type="hidden" name="residx" />
6432: </form>');
6433: }
1.484 raeburn 6434: } elsif ($showdoc) {
1.329 droeschl 6435: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6436: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6437: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6438: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6439: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6440: }
6441: }
1.606 raeburn 6442: unless ($noendpage) {
6443: $r->print(&Apache::loncommon::end_page());
6444: }
1.329 droeschl 6445: return OK;
1.364 bisitz 6446: }
1.329 droeschl 6447:
1.440 raeburn 6448: sub embedded_form_elems {
6449: my ($phase,$primaryurl,$newidx) = @_;
6450: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6451: return <<STATE;
6452: <input type="hidden" name="folderpath" value="$folderpath" />
6453: <input type="hidden" name="cmd" value="upload_embedded" />
6454: <input type="hidden" name="newidx" value="$newidx" />
6455: <input type="hidden" name="phase" value="$phase" />
6456: <input type="hidden" name="primaryurl" value="$primaryurl" />
6457: STATE
6458: }
6459:
6460: sub embedded_destination {
6461: my $folder=$env{'form.folder'};
6462: my $destination = 'docs/';
6463: if ($folder =~ /^supplemental/) {
6464: $destination = 'supplemental/';
6465: }
6466: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6467: $destination .= 'default/';
6468: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6469: $destination .= $2.'/';
6470: }
6471: $destination .= $env{'form.newidx'};
6472: my $dir_root = '/userfiles';
6473: return ($destination,$dir_root);
6474: }
6475:
6476: sub return_to_editor {
6477: my $actionurl = '/adm/coursedocs';
6478: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6479: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6480: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6481: '</a></p>';
6482: }
6483:
1.476 raeburn 6484: sub decompression_info {
6485: my ($destination,$dir_root) = &embedded_destination();
6486: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6487: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6488: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6489: my $container='sequence';
1.480 raeburn 6490: my ($pathitem,$hiddenelem);
1.583 raeburn 6491: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6492: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6493: $container='page';
6494: }
1.480 raeburn 6495: unshift(@hiddens,$pathitem);
6496: foreach my $item (@hiddens) {
6497: if ($env{'form.'.$item}) {
6498: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6499: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6500: }
1.477 raeburn 6501: }
1.476 raeburn 6502: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6503: $hiddenelem);
6504: }
6505:
6506: sub decompression_phase_one {
6507: my ($dir,$file,$warning,$error,$output);
6508: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6509: &decompression_info();
1.490 raeburn 6510: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6511: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6512: } else {
6513: my $file = $1;
1.481 raeburn 6514: $output =
6515: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6516: $destination,$dir_root,
6517: $hiddenelem);
6518: if ($env{'form.autoextract_camtasia'}) {
6519: $output .= &remove_archive($docudom,$docuname,$container);
6520: }
1.476 raeburn 6521: }
6522: if ($error) {
6523: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6524: $error.'</p>'."\n";
6525: }
6526: if ($warning) {
6527: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6528: }
6529: return $output;
6530: }
6531:
6532: sub decompression_phase_two {
6533: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6534: &decompression_info();
1.481 raeburn 6535: my $output;
1.480 raeburn 6536: if ($env{'form.archivedelete'}) {
1.481 raeburn 6537: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6538: }
6539: $output .=
1.481 raeburn 6540: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6541: $destination,$dir_root,$hiddenelem);
6542: return $output;
6543: }
6544:
1.480 raeburn 6545: sub remove_archive {
6546: my ($docudom,$docuname,$container) = @_;
6547: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6548: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6549: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6550: if ($fatal) {
6551: if ($container eq 'page') {
6552: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6553: } else {
6554: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6555: }
1.583 raeburn 6556: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6557: } else {
6558: my $currcmd = $env{'form.cmd'};
6559: my $position = $env{'form.position'};
1.583 raeburn 6560: my $archiveidx = $position;
1.563 raeburn 6561: if ($position > 0) {
1.583 raeburn 6562: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6563: $archiveidx = $position-1;
6564: }
6565: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6566: my ($title,$url,@rrest) =
1.583 raeburn 6567: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6568: if ($url eq $env{'form.archiveurl'}) {
6569: if (&handle_edit_cmd($docuname,$docudom)) {
6570: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6571: if ($fatal) {
6572: if ($container eq 'page') {
6573: $delwarning = &mt('An error occurred updating the contents of the current page.');
6574: } else {
6575: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6576: }
1.480 raeburn 6577: } else {
1.583 raeburn 6578: $delresult = &mt('Archive file removed.');
1.480 raeburn 6579: }
6580: }
1.583 raeburn 6581: } else {
6582: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6583: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6584: }
6585: }
6586: $env{'form.cmd'} = $currcmd;
6587: }
6588: if ($delwarning) {
6589: $output = '<p class="LC_warning">'.
6590: $delwarning.
6591: '</p>';
6592: }
6593: if ($delresult) {
6594: $output .= '<p class="LC_info">'.
6595: $delresult.
6596: '</p>';
6597: }
1.481 raeburn 6598: return $output;
1.480 raeburn 6599: }
6600:
1.484 raeburn 6601: sub generate_admin_menu {
1.611 raeburn 6602: my ($crstype,$canedit) = @_;
1.484 raeburn 6603: my $lc_crstype = lc($crstype);
6604: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6605: my %lt= ( # do not translate here
1.484 raeburn 6606: 'vc' => 'Verify Content',
6607: 'cv' => 'Check/Set Resource Versions',
6608: 'ls' => 'List Resource Identifiers',
6609: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6610: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6611: );
1.484 raeburn 6612: my ($candump,$dumpurl);
6613: if ($home + $other > 0) {
6614: $candump = 'F';
6615: if ($home) {
6616: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6617: } else {
6618: my @hosts;
6619: foreach my $aurole (keys(%outhash)) {
6620: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6621: push(@hosts,$outhash{$aurole});
1.538 raeburn 6622: }
1.484 raeburn 6623: }
6624: if (@hosts == 1) {
6625: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6626: '&role='.
6627: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6628: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6629: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6630: } else {
6631: $dumpurl = "javascript:choose_switchserver_window()";
6632: }
6633: }
6634: }
6635: my @menu=
6636: ({ categorytitle=>'Administration',
6637: items =>[
6638: { linktext => $lt{'vc'},
6639: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6640: permission => 'F',
1.571 raeburn 6641: help => 'Docs_Verify_Content',
1.484 raeburn 6642: icon => 'verify.png',
6643: linktitle => 'Verify contents can be retrieved/rendered',
6644: },
6645: { linktext => $lt{'cv'},
6646: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6647: permission => 'F',
1.571 raeburn 6648: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6649: icon => 'resversion.png',
6650: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6651: },
6652: { linktext => $lt{'ls'},
6653: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6654: permission => 'F',
6655: #help => '',
6656: icon => 'symbs.png',
6657: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6658: },
6659: ]
1.611 raeburn 6660: });
6661: if ($canedit) {
6662: push(@menu,
1.484 raeburn 6663: { categorytitle=>'Export',
6664: items =>[
6665: { linktext => $lt{'imse'},
6666: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6667: permission => 'F',
6668: help => 'Docs_Export_Course_Docs',
6669: icon => 'imsexport.png',
6670: linktitle => $lt{'imse'},
6671: },
6672: { linktext => $lt{'dcd'},
6673: url => $dumpurl,
6674: permission => $candump,
1.571 raeburn 6675: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6676: icon => 'dump.png',
6677: linktitle => $lt{'dcd'},
6678: },
6679: ]
6680: });
1.611 raeburn 6681: }
1.484 raeburn 6682: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6683: '<input type="hidden" id="dummy" />'."\n".
6684: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6685: '</form>';
1.329 droeschl 6686: }
6687:
6688: sub generate_edit_table {
1.538 raeburn 6689: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6690: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6691: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6692: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6693: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6694: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6695: $activetab = $env{'form.active'};
6696: }
1.611 raeburn 6697: unless ($canedit) {
6698: $disabled = ' disabled="disabled"';
6699: }
1.472 raeburn 6700: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6701: my $backtext = &mt('Exit Editor');
1.458 raeburn 6702: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6703: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6704: '<li class="goback">'.
1.546 raeburn 6705: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6706: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6707: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6708: '<li>'.
6709: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6710: &mt('Undo Delete').'</a></li>'."\n";
6711: if ($env{'form.docslog'}) {
6712: $form .= '<li class="active">';
6713: } else {
6714: $form .= '<li>';
6715: }
6716: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6717: &mt('History').'</a></li>'."\n";
6718: if ($env{'form.docslog'}) {
6719: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6720: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6721: }
1.458 raeburn 6722: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6723: if($name ne '00'){
1.371 tempelho 6724: if($activetab eq '' || $activetab ne $name){
6725: $active = '';
6726: }elsif($activetab eq $name){
6727: $active = 'class="active"';
6728: }
1.458 raeburn 6729: $form .= '<li style="float:right" '.$active
1.484 raeburn 6730: .' 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 6731: } else {
1.570 raeburn 6732: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6733:
6734: }
1.329 droeschl 6735: }
1.484 raeburn 6736: $form .= '</ul>'."\n";
6737: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6738:
6739: if ($to_show ne '') {
1.538 raeburn 6740: my $saveform;
6741: if ($need_save) {
6742: my $button = &mt('Make changes');
6743: my $path;
6744: if ($env{'form.folderpath'}) {
6745: $path =
6746: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6747: }
6748: $saveform = <<"END";
6749: <div id="multisave" style="display:none; clear:both;" >
6750: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6751: <input type="hidden" name="folderpath" value="$path" />
6752: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6753: <input type="hidden" name="allhiddenresource" value="" />
6754: <input type="hidden" name="allencrypturl" value="" />
6755: <input type="hidden" name="allrandompick" value="" />
6756: <input type="hidden" name="allrandomorder" value="" />
6757: <input type="hidden" name="changeparms" value="" />
6758: <input type="hidden" name="multiremove" value="" />
6759: <input type="hidden" name="multicut" value="" />
6760: <input type="hidden" name="multicopy" value="" />
6761: <input type="hidden" name="multichange" value="" />
6762: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 6763: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 6764: </form>
6765: </div>
6766: END
6767: }
6768: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6769: }
1.363 ehlerst 6770: foreach my $field (keys(%orderhash)){
1.390 tempelho 6771: if($field ne '00'){
1.422 onken 6772: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6773: $active = 'style="display: none;float:left"';
1.422 onken 6774: }elsif($activetab eq $field){
1.458 raeburn 6775: $active = 'style="display:block;float:left"';
1.422 onken 6776: }
6777: $form .= '<div id="'.$field.$tid.'"'
6778: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6779: .'</div>'."\n";
1.363 ehlerst 6780: }
6781: }
1.484 raeburn 6782: unless ($env{'form.docslog'}) {
6783: $form .= '</div></div>'."\n";
6784: }
1.329 droeschl 6785: return $form;
6786: }
6787:
6788: sub editing_js {
1.617 raeburn 6789: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot,$canedit,$navmapref) = @_;
1.594 damieng 6790: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6791: p_mnf => 'Name of New Folder',
6792: t_mnf => 'New Folder',
6793: p_mnp => 'Name of New Page',
6794: t_mnp => 'New Page',
1.451 www 6795: p_mxu => 'Title for the External Score',
1.349 biermanm 6796: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6797: p_msb => 'Title for the Problem',
6798: p_mdb => 'Title for the Drop Box',
1.336 schafran 6799: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 6800: p_mwp => 'Title for Web Page',
1.606 raeburn 6801: p_mnr => 'Title for the Resource',
1.348 weissno 6802: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6803: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6804: p_mab_alrt1 => 'Not a valid user:domain',
6805: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6806: p_chn => 'New Title',
6807: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 6808: p_rmr2a => 'Remove',
6809: p_rmr2b => '?',
6810: p_rmr3a => 'Remove those',
6811: p_rmr3b => 'items?',
6812: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6813: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6814: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6815: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 6816: p_ctr2a => 'Cut',
6817: p_ctr2b => '?',
6818: p_ctr3a => 'Cut those',
6819: p_ctr3b => 'items?',
1.478 raeburn 6820: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6821: imsfile => 'You must choose an IMS package for import',
6822: imscms => 'You must select which Course Management System was the source of the IMS package',
6823: invurl => 'Invalid URL',
6824: titbl => 'Title is blank',
1.538 raeburn 6825: more => '(More ...)',
6826: less => '(Less ...)',
1.543 raeburn 6827: noor => 'No actions selected or changes to settings specified.',
6828: noch => 'No changes to settings specified.',
6829: noac => 'No actions selected.',
1.606 raeburn 6830: nofi => 'No file selected',
6831: tinc => 'Title in course',
6832: sunm => 'Sub-directory name',
1.618 raeburn 6833: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6834: );
1.594 damieng 6835: &js_escape(\%js_lt);
1.433 raeburn 6836: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6837: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6838: my $main_container_page;
1.519 raeburn 6839: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6840: $main_container_page = 1;
1.434 raeburn 6841: }
1.617 raeburn 6842: my $backtourl;
6843: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6844: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6845:
1.530 raeburn 6846: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6847: my $caller = $1;
1.525 raeburn 6848: if ($caller =~ /^supplemental/) {
6849: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6850: } else {
6851: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6852: $res = &Apache::lonnet::clutter($res);
6853: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 6854: my ($url,$anchor);
6855: if ($res =~ /^([^#]+)#([^#]+)$/) {
6856: $url = $1;
6857: $anchor = $2;
6858: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6859: $caller = $1.&escape('#').$anchor;
6860: }
1.614 raeburn 6861: } else {
6862: $url = $res;
1.609 raeburn 6863: }
6864: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 6865: &HTML::Entities::encode($caller,'<>&"');
1.609 raeburn 6866: if ($anchor ne '') {
6867: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6868: }
1.590 raeburn 6869: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6870: } else {
6871: $backtourl = '/adm/navmaps';
1.525 raeburn 6872: }
6873: }
6874: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6875: $backtourl = '/adm/menu';
6876: } elsif ($supplementalflag) {
1.472 raeburn 6877: $backtourl = '/adm/supplemental';
1.525 raeburn 6878: } else {
6879: $backtourl = '/adm/navmaps';
1.472 raeburn 6880: }
6881:
1.600 raeburn 6882: my $fieldsets = "'ext','doc'";
6883: if ($posslti) {
6884: $fieldsets .= ",'tool'";
6885: }
1.519 raeburn 6886: unless ($main_container_page) {
6887: $fieldsets .=",'ims'";
6888: }
1.501 raeburn 6889: if ($supplementalflag) {
1.600 raeburn 6890: $fieldsets = "'suppext','suppdoc'";
6891: if ($posslti) {
6892: $fieldsets .= ",'supptool'";
6893: }
1.501 raeburn 6894: }
1.611 raeburn 6895:
6896: my $jsmakefunctions;
6897: if ($canedit) {
6898: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6899: function makenewfolder(targetform,folderseq) {
1.594 damieng 6900: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6901: if (foldername) {
6902: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6903: targetform.submit();
6904: }
6905: }
6906:
6907: function makenewpage(targetform,folderseq) {
1.594 damieng 6908: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6909: if (pagename) {
6910: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6911: targetform.submit();
6912: }
6913: }
6914:
6915: function makeexamupload() {
1.594 damieng 6916: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6917: if (title) {
1.329 droeschl 6918: this.document.forms.newexamupload.importdetail.value=
6919: escape(title)+'=/res/lib/templates/examupload.problem';
6920: this.document.forms.newexamupload.submit();
6921: }
6922: }
6923:
6924: function makesmppage() {
1.594 damieng 6925: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6926: if (title) {
1.329 droeschl 6927: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 6928: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6929: this.document.forms.newsmppg.submit();
6930: }
6931: }
6932:
1.534 raeburn 6933: function makewebpage(type) {
1.594 damieng 6934: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 6935: var formname;
6936: if (type == 'supp') {
6937: formname = this.document.forms.supwebpage;
6938: } else {
6939: formname = this.document.forms.newwebpage;
6940: }
6941: if (title) {
6942: var webpage = formname.importdetail.value;
6943: formname.importdetail.value = escape(title)+'='+webpage;
6944: formname.submit();
6945: }
6946: }
6947:
1.329 droeschl 6948: function makesmpproblem() {
1.594 damieng 6949: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6950: if (title) {
1.329 droeschl 6951: this.document.forms.newsmpproblem.importdetail.value=
6952: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6953: this.document.forms.newsmpproblem.submit();
6954: }
6955: }
6956:
6957: function makedropbox() {
1.594 damieng 6958: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6959: if (title) {
1.329 droeschl 6960: this.document.forms.newdropbox.importdetail.value=
6961: escape(title)+'=/res/lib/templates/DropBox.problem';
6962: this.document.forms.newdropbox.submit();
6963: }
6964: }
6965:
6966: function makebulboard() {
1.594 damieng 6967: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6968: if (title) {
6969: this.document.forms.newbul.importdetail.value=
1.533 raeburn 6970: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6971: this.document.forms.newbul.submit();
6972: }
6973: }
6974:
6975: function makeabout() {
1.594 damieng 6976: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6977: if (user) {
6978: var comp=new Array();
6979: comp=user.split(':');
6980: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6981: if ((comp[0]) && (comp[1])) {
6982: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 6983: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 6984: this.document.forms.newaboutsomeone.submit();
6985: } else {
6986: alert("$js_lt{'p_mab_alrt1'}");
6987: }
6988: } else {
6989: alert("$js_lt{'p_mab_alrt2'}");
6990: }
6991: }
6992: }
6993:
6994: function makenew(targetform) {
6995: targetform.submit();
6996: }
6997:
6998: function changename(folderpath,index,oldtitle) {
6999: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7000: if (title) {
7001: this.document.forms.renameform.markcopy.value='';
7002: this.document.forms.renameform.title.value=title;
7003: this.document.forms.renameform.cmd.value='rename_'+index;
7004: this.document.forms.renameform.folderpath.value=folderpath;
7005: this.document.forms.renameform.submit();
7006: }
7007: }
7008:
7009: ENDNEWSCRIPT
7010: } else {
7011: $jsmakefunctions = <<ENDNEWSCRIPT;
7012:
7013: function makenewfolder() {
7014: alert("$js_lt{'edri'}");
7015: }
7016:
7017: function makenewpage() {
7018: alert("$js_lt{'edri'}");
7019: }
7020:
7021: function makeexamupload() {
7022: alert("$js_lt{'edri'}");
7023: }
7024:
7025: function makesmppage() {
7026: alert("$js_lt{'edri'}");
7027: }
7028:
7029: function makewebpage(type) {
7030: alert("$js_lt{'edri'}");
7031: }
7032:
7033: function makesmpproblem() {
7034: alert("$js_lt{'edri'}");
7035: }
7036:
7037: function makedropbox() {
7038: alert("$js_lt{'edri'}");
7039: }
7040:
7041: function makebulboard() {
7042: alert("$js_lt{'edri'}");
7043: }
7044:
7045: function makeabout() {
7046: alert("$js_lt{'edri'}");
7047: }
7048:
7049: function changename() {
7050: alert("$js_lt{'edri'}");
7051: }
7052:
7053: function makenew() {
7054: alert("$js_lt{'edri'}");
7055: }
7056:
7057: function groupimport() {
7058: alert("$js_lt{'edri'}");
1.335 ehlerst 7059: }
1.611 raeburn 7060:
7061: function groupsearch() {
7062: alert("$js_lt{'edri'}");
1.335 ehlerst 7063: }
1.611 raeburn 7064:
7065: function groupopen(url,recover) {
7066: var options="scrollbars=1,resizable=1,menubar=0";
7067: idxflag=1;
7068: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7069: idx.focus();
1.329 droeschl 7070: }
7071:
1.611 raeburn 7072: ENDNEWSCRIPT
7073:
7074: }
7075: return <<ENDSCRIPT;
7076:
7077: $jsmakefunctions
7078:
1.501 raeburn 7079: function toggleUpload(caller) {
7080: var blocks = Array($fieldsets);
7081: for (var i=0; i<blocks.length; i++) {
7082: var disp = 'none';
7083: if (caller == blocks[i]) {
7084: var curr = document.getElementById('upload'+caller+'form').style.display;
7085: if (curr == 'none') {
7086: disp='block';
7087: }
7088: }
7089: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7090: if ((caller == 'tool') || (caller == 'supptool')) {
7091: if (disp == 'block') {
7092: if (document.getElementById('LC_exttoolid')) {
7093: var toolselector = document.getElementById('LC_exttoolid');
7094: var suppflag = 0;
7095: if (caller == 'supptool') {
7096: suppflag = 1;
7097: }
7098: currForm = document.getElementById('new'+caller);
7099: updateExttool(toolselector,currForm,suppflag);
7100: }
7101: }
7102: }
1.501 raeburn 7103: }
1.502 raeburn 7104: resize_scrollbox('contentscroll','1','1');
7105: return;
7106: }
7107:
1.514 raeburn 7108: function toggleMap(caller) {
1.502 raeburn 7109: var disp = 'none';
1.510 raeburn 7110: if (document.getElementById('importmapform')) {
1.514 raeburn 7111: if (caller == 'map') {
7112: var curr = document.getElementById('importmapform').style.display;
7113: if (curr == 'none') {
7114: disp='block';
7115: }
1.510 raeburn 7116: }
7117: document.getElementById('importmapform').style.display=disp;
7118: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7119: }
1.501 raeburn 7120: return;
1.329 droeschl 7121: }
7122:
1.606 raeburn 7123: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7124: var disp = 'none';
7125: if (document.getElementById('crsresform')) {
7126: if (caller == 'res') {
7127: var curr = document.getElementById('crsresform').style.display;
7128: if (curr == 'none') {
7129: disp='block';
7130: numauthor = parseInt(numauthorrole);
7131: if (numauthor > 0) {
7132: document.courseresform.authorrole.selectedIndex = 0;
7133: select1priv_changed();
7134: document.courseresform.authorpath.selectedIndex = 0;
7135: document.courseresform.newresourceadd.selectedIndex = 0;
7136: toggleNewInCourse(document.courseresform);
7137: if (document.getElementById('newresource')) {
7138: document.getElementById('newresource').style.display = 'none';
7139: }
7140: } else {
7141: if (numcrsdirs) {
7142: document.courseresform.authorpath.selectedIndex = 0;
7143: }
7144: }
7145: if (document.courseresform.newresusetemp.length) {
7146: document.courseresform.newresusetemp[0].checked = true;
7147: toggleWithTemplate(document.courseresform);
7148: }
7149: document.courseresform.newresourcename.value = '';
7150: }
7151: }
7152: if (document.courseresform.newsubdir.length) {
7153: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7154: if (document.courseresform.newsubdir[j].value == 0) {
7155: document.courseresform.newsubdir[j].checked = true;
7156: }
7157: break;
7158: }
7159: if (document.getElementById('newsubdirname')) {
7160: document.getElementById('newsubdirname').type = "hidden";
7161: document.getElementById('newsubdirname').value = "";
7162: }
7163: if (document.getElementById('newsubdir')) {
7164: document.getElementById('newsubdir').innerHTML = "";
7165: }
7166: }
7167: document.getElementById('crsresform').style.display=disp;
7168: resize_scrollbox('contentscroll','1','0');
7169: }
7170: return;
7171: }
7172:
7173: function toggleNewsubdir(form) {
7174: if (form.newsubdir.length) {
7175: for (var j=0; j<form.newsubdir.length; j++) {
7176: if (form.newsubdir[j].checked) {
7177: if (document.getElementById('newsubdirname')) {
7178: if (form.newsubdir[j].value == '1') {
7179: document.getElementById('newsubdirname').type = "text";
7180: if (document.getElementById('newsubdir')) {
7181: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7182: }
7183: } else {
7184: document.getElementById('newsubdirname').type = "hidden";
7185: document.getElementById('newsubdirname').value = "";
7186: document.getElementById('newsubdir').innerHTML = "";
7187: }
7188: }
7189: break;
7190: }
7191: }
7192: }
7193: }
7194:
7195: function toggleCrsResTitle() {
7196: if (document.getElementById('newresource')) {
7197: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7198: document.getElementById('newresource').style.display = 'inline';
7199: document.courseresform.newresourceadd[0].checked = true;
7200: toggleNewInCourse(document.courseresform);
7201: } else {
7202: document.getElementById('newresource').style.display = 'none';
7203: }
7204: }
7205: }
7206:
7207: function toggleNewInCourse(form) {
7208: if (form.newresourceadd.length) {
7209: for (var i=0; i<form.newresourceadd.length; i++) {
7210: if (form.newresourceadd[i].checked) {
7211: if (document.getElementById('newresourcetitle')) {
7212: if (form.newresourceadd[i].value == '1') {
7213: document.getElementById('newresourcetitle').type = 'text';
7214: if (document.getElementById('newrestitle')) {
7215: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7216: }
7217: } else {
7218: document.getElementById('newresourcetitle').type = 'hidden';
7219: document.getElementById('newresourcetitle').value = '';
7220: if (document.getElementById('newrestitle')) {
7221: document.getElementById('newrestitle').innerHTML = '';
7222: }
7223: }
7224: }
7225: break;
7226: }
7227: }
7228: }
7229: }
7230:
7231: function toggleWithTemplate(form) {
7232: if (form.newresusetemp.length) {
7233: for (var i=0; i<form.newresusetemp.length; i++) {
7234: if (form.newresusetemp[i].checked) {
7235: if (document.getElementById('newrestemplate')) {
7236: if (form.newresusetemp[i].value == '1') {
7237: document.getElementById('newrestemplate').style.display = 'inline';
7238: toggleExampleText();
7239: } else {
7240: form.tempcategory.selectedIndex = 0;
7241: select1template_changed();
7242: document.getElementById('newrestemplate').style.display = 'none';
7243: }
7244: }
7245: }
7246: }
7247: }
7248: }
7249:
7250: function toggleExampleText() {
7251: if (document.getElementById('newresexample')) {
7252: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7253: if (url == '') {
7254: document.getElementById('newresexample').style.fontWeight = 'normal';
7255: } else {
7256: document.getElementById('newresexample').style.fontWeight = 'bold';
7257: }
7258: }
7259: }
7260:
7261: function getExample(width,height,scrolling,transparency) {
7262: var url;
7263: if (document.courseresform.newresusetemp.length) {
7264: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7265: if (document.courseresform.newresusetemp[i].checked) {
7266: if (document.courseresform.newresusetemp[i].value == '1') {
7267: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7268: if (url == '') {
7269: alert('Pick a category and template');
7270: } else {
7271: url = url.replace("$londocroot","");
7272: url += '?inhibitmenu=yes';
7273: }
7274: }
7275: break;
7276: }
7277: }
7278: }
7279: if (url != '') {
7280: openMyModal(url,width,height,scrolling,transparency,'');
7281: }
7282: }
7283:
7284: function toggleImportCrsres(caller,dircount) {
7285: var disp = 'none';
7286: if (document.getElementById('importcrsresform')) {
7287: if (caller == 'res') {
7288: var numdirs = parseInt(dircount);
7289: var curr = document.getElementById('importcrsresform').style.display;
7290: if (curr == 'none') {
7291: disp='block';
7292: if (numdirs > 1) {
7293: select1res_changed();
7294: }
7295: }
7296: }
7297: document.getElementById('importcrsresform').style.display=disp;
7298: resize_scrollbox('contentscroll','1','0');
7299: }
7300: return;
7301: }
7302:
1.501 raeburn 7303: function makeims(imsform) {
7304: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7305: alert("$js_lt{'imsfile'}");
1.501 raeburn 7306: return;
7307: }
7308: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7309: alert("$js_lt{'imscms'}");
1.501 raeburn 7310: return;
7311: }
7312: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7313: imsform.submit();
7314: }
7315:
1.478 raeburn 7316: function updatePick(targetform,index,caller) {
1.537 raeburn 7317: var pickitem;
7318: var picknumitem;
7319: var picknumtext;
7320: if (index == 'all') {
7321: pickitem = document.getElementById('randompickall');
7322: picknumitem = document.getElementById('rpicknumall');
7323: picknumtext = document.getElementById('rpicktextall');
7324: } else {
7325: pickitem = document.getElementById('randompick_'+index);
7326: picknumitem = document.getElementById('rpicknum_'+index);
7327: picknumtext = document.getElementById('randompicknum_'+index);
7328: }
1.478 raeburn 7329: if (pickitem.checked) {
1.594 damieng 7330: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7331: if (picknum == '' || picknum == null) {
7332: if (caller == 'check') {
7333: pickitem.checked=false;
1.537 raeburn 7334: if (index == 'all') {
7335: picknumtext.innerHTML = '';
7336: if (caller == 'link') {
7337: propagateState(targetform,'rpicknum');
7338: }
7339: } else {
1.538 raeburn 7340: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7341: }
1.478 raeburn 7342: }
7343: } else {
7344: picknum.toString();
7345: var regexdigit=/^\\d+\$/;
7346: if (regexdigit.test(picknum)) {
7347: picknumitem.value = picknum;
1.537 raeburn 7348: if (index == 'all') {
1.538 raeburn 7349: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7350: if (caller == 'link') {
7351: propagateState(targetform,'rpicknum');
7352: }
7353: } else {
7354: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7355: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7356: }
1.478 raeburn 7357: } else {
7358: if (caller == 'check') {
1.537 raeburn 7359: if (index == 'all') {
7360: picknumtext.innerHTML = '';
7361: if (caller == 'link') {
7362: propagateState(targetform,'rpicknum');
7363: }
7364: } else {
7365: pickitem.checked=false;
1.538 raeburn 7366: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7367: }
1.478 raeburn 7368: }
7369: return;
7370: }
7371: }
7372: } else {
1.537 raeburn 7373: picknumitem.value = '';
7374: picknumtext.innerHTML = '';
7375: if (index == 'all') {
7376: if (caller == 'link') {
7377: propagateState(targetform,'rpicknum');
7378: }
7379: } else {
1.538 raeburn 7380: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7381: }
7382: }
7383: }
7384:
7385: function propagateState(form,param) {
7386: if (document.getElementById(param+'all')) {
7387: var setcheck = 0;
7388: var rpick = 0;
7389: if (param == 'rpicknum') {
7390: if (document.getElementById('randompickall')) {
7391: if (document.getElementById('randompickall').checked) {
7392: if (document.getElementById('rpicknumall')) {
7393: rpick = document.getElementById('rpicknumall').value;
7394: }
7395: }
7396: }
7397: } else {
7398: if (document.getElementById(param+'all').checked) {
7399: setcheck = 1;
7400: }
7401: }
1.538 raeburn 7402: var allidxlist;
7403: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7404: if (document.getElementById('all'+param+'idx')) {
7405: allidxlist = document.getElementById('all'+param+'idx').value;
7406: }
7407: var actions = new Array ('remove','cut','copy');
7408: for (var i=0; i<actions.length; i++) {
7409: if (actions[i] != param) {
7410: if (document.getElementById(actions[i]+'all')) {
7411: document.getElementById(actions[i]+'all').checked = false;
7412: }
7413: }
7414: }
7415: }
1.537 raeburn 7416: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7417: allidxlist = form.allidx.value;
7418: }
7419: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7420: allidxlist = form.allmapidx.value;
7421: }
7422: if ((allidxlist != '') && (allidxlist != null)) {
7423: var allidxs = allidxlist.split(',');
7424: if (allidxs.length > 1) {
7425: for (var i=0; i<allidxs.length; i++) {
7426: if (document.getElementById(param+'_'+allidxs[i])) {
7427: if (param == 'rpicknum') {
7428: if (document.getElementById('randompick_'+allidxs[i])) {
7429: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7430: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7431: if (rpick > 0) {
7432: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7433: } else {
7434: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7435: }
7436: }
7437: }
7438: } else {
1.537 raeburn 7439: if (setcheck == 1) {
7440: document.getElementById(param+'_'+allidxs[i]).checked = true;
7441: } else {
7442: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7443: if (param == 'randompick') {
7444: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7445: }
1.537 raeburn 7446: }
7447: }
7448: }
7449: }
1.538 raeburn 7450: if (setcheck == 1) {
7451: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7452: var actions = new Array('copy','cut','remove');
7453: for (var i=0; i<actions.length; i++) {
7454: var otheractions;
7455: var otheridxs;
7456: if (actions[i] === param) {
7457: continue;
7458: } else {
7459: if (document.getElementById('all'+actions[i]+'idx')) {
7460: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7461: otheridxs = otheractions.split(',');
7462: if (otheridxs.length > 1) {
7463: for (var j=0; j<otheridxs.length; j++) {
7464: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7465: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7466: }
1.537 raeburn 7467: }
7468: }
7469: }
1.538 raeburn 7470: }
7471: }
7472: }
7473: }
7474: }
7475: }
7476: }
7477: return;
7478: }
7479:
1.603 raeburn 7480: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7481: var canedit = '$canedit';
7482: if (canedit == '') {
7483: alert("$js_lt{'edri'}");
7484: return;
7485: }
1.539 raeburn 7486: var dosettings;
7487: var doaction;
1.538 raeburn 7488: var control = document.togglemultsettings;
7489: if (context == 'actions') {
7490: control = document.togglemultactions;
1.539 raeburn 7491: doaction = 1;
7492: } else {
7493: dosettings = 1;
1.538 raeburn 7494: }
1.539 raeburn 7495: if (control) {
7496: if (control.showmultpick.length) {
7497: for (var i=0; i<control.showmultpick.length; i++) {
7498: if (control.showmultpick[i].checked) {
7499: if (control.showmultpick[i].value == 1) {
7500: if (context == 'settings') {
7501: dosettings = 0;
7502: } else {
7503: doaction = 0;
1.538 raeburn 7504: }
7505: }
7506: }
1.537 raeburn 7507: }
7508: }
1.539 raeburn 7509: }
7510: if (context == 'settings') {
7511: if (dosettings == 1) {
1.538 raeburn 7512: targetform.changeparms.value=param;
7513: targetform.submit();
7514: }
1.537 raeburn 7515: }
1.539 raeburn 7516: if (context == 'actions') {
7517: if (doaction == 1) {
7518: targetform.cmd.value=param+'_'+index;
7519: targetform.folderpath.value=folderpath;
7520: targetform.markcopy.value=idx+':'+param;
7521: targetform.copyfolder.value=folder+'.'+container;
7522: if (param == 'remove') {
1.603 raeburn 7523: var doremove = 0;
7524: if (skip_confirm) {
7525: if (confirm_removal) {
7526: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7527: doremove = 1;
7528: }
7529: } else {
7530: doremove = 1;
7531: }
7532: } else {
7533: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7534: doremove = 1;
7535: }
7536: }
7537: if (doremove) {
1.539 raeburn 7538: targetform.markcopy.value='';
7539: targetform.copyfolder.value='';
7540: targetform.submit();
7541: }
7542: }
7543: if (param == 'cut') {
1.594 damieng 7544: 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 7545: targetform.submit();
7546: return;
7547: }
7548: }
7549: if (param == 'copy') {
7550: targetform.submit();
7551: return;
7552: }
7553: targetform.markcopy.value='';
7554: targetform.copyfolder.value='';
7555: targetform.cmd.value='';
7556: targetform.folderpath.value='';
7557: return;
7558: } else {
7559: if (document.getElementById(param+'_'+idx)) {
7560: item = document.getElementById(param+'_'+idx);
7561: if (item.type == 'checkbox') {
7562: if (item.checked) {
7563: item.checked = false;
7564: } else {
7565: item.checked = true;
7566: singleCheck(item,idx,param);
7567: }
7568: }
7569: }
7570: }
7571: }
1.537 raeburn 7572: return;
7573: }
7574:
1.538 raeburn 7575: function singleCheck(caller,idx,action) {
7576: actions = new Array('cut','copy','remove');
7577: if (caller.checked) {
7578: for (var i=0; i<actions.length; i++) {
7579: if (actions[i] != action) {
7580: if (document.getElementById(actions[i]+'_'+idx)) {
7581: if (document.getElementById(actions[i]+'_'+idx).checked) {
7582: document.getElementById(actions[i]+'_'+idx).checked = false;
7583: }
1.537 raeburn 7584: }
7585: }
7586: }
1.478 raeburn 7587: }
1.537 raeburn 7588: return;
1.478 raeburn 7589: }
7590:
1.334 muellerd 7591: function unselectInactive(nav) {
1.335 ehlerst 7592: currentNav = document.getElementById(nav);
7593: currentLis = currentNav.getElementsByTagName('LI');
7594: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7595: if (currentLis[i].className == 'goback') {
7596: currentLis[i].className = 'goback';
7597: } else {
7598: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7599: currentLis[i].className = 'right';
1.472 raeburn 7600: } else {
1.374 tempelho 7601: currentLis[i].className = 'i';
1.472 raeburn 7602: }
7603: }
1.335 ehlerst 7604: }
1.332 tempelho 7605: }
7606:
1.334 muellerd 7607: function hideAll(current, nav, data) {
1.335 ehlerst 7608: unselectInactive(nav);
1.570 raeburn 7609: if (current) {
7610: if (current.className == 'right'){
7611: current.className = 'right active'
7612: } else {
7613: current.className = 'active';
7614: }
1.374 tempelho 7615: }
1.335 ehlerst 7616: currentData = document.getElementById(data);
7617: currentDivs = currentData.getElementsByTagName('DIV');
7618: for (i = 0; i < currentDivs.length; i++) {
7619: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7620: currentDivs[i].style.display = 'none';
1.330 tempelho 7621: }
7622: }
1.335 ehlerst 7623: }
1.330 tempelho 7624:
1.374 tempelho 7625: function openTabs(pageId) {
7626: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7627: if(tabnav.length > 2 ){
1.389 tempelho 7628: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7629: currentLis = currentNav.getElementsByTagName('LI');
7630: for(i = 0; i< currentLis.length; i++){
7631: if(currentLis[i].className == 'active') {
1.375 tempelho 7632: funcString = currentLis[i].onclick.toString();
7633: tab = funcString.split('"');
1.420 onken 7634: if(tab.length < 2) {
7635: tab = funcString.split("'");
7636: }
1.375 tempelho 7637: currentData = document.getElementById(tab[1]);
7638: currentData.style.display = 'block';
1.374 tempelho 7639: }
7640: }
7641: }
7642: }
7643:
1.334 muellerd 7644: function showPage(current, pageId, nav, data) {
1.570 raeburn 7645: currstate = current.className;
1.334 muellerd 7646: hideAll(current, nav, data);
1.375 tempelho 7647: openTabs(pageId);
1.334 muellerd 7648: unselectInactive(nav);
1.570 raeburn 7649: if ((currstate == 'active') || (currstate == 'right active')) {
7650: if (currstate == 'active') {
7651: current.className = '';
7652: } else {
7653: current.className = 'right';
7654: }
7655: activeTab = '';
7656: toggleUpload();
7657: toggleMap();
1.606 raeburn 7658: toggleCrsRes();
7659: toggleImportCrsres();
1.570 raeburn 7660: resize_scrollbox('contentscroll','1','0');
7661: return;
7662: } else {
7663: current.className = 'active';
7664: }
1.330 tempelho 7665: currentData = document.getElementById(pageId);
7666: currentData.style.display = 'block';
1.458 raeburn 7667: activeTab = pageId;
1.501 raeburn 7668: toggleUpload();
1.503 raeburn 7669: toggleMap();
1.606 raeburn 7670: toggleCrsRes();
7671: toggleImportCrsres();
1.433 raeburn 7672: if (nav == 'mainnav') {
7673: var storedpath = "$docs_folderpath";
1.434 raeburn 7674: var storedpage = "$main_container_page";
1.433 raeburn 7675: var reg = new RegExp("^supplemental");
7676: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7677: if (storedpage == 1) {
7678: document.simpleedit.folderpath.value = '';
7679: document.uploaddocument.folderpath.value = '';
7680: } else {
7681: if (reg.test(storedpath)) {
7682: document.simpleedit.folderpath.value = '$toplevelmain';
7683: document.uploaddocument.folderpath.value = '$toplevelmain';
7684: document.newext.folderpath.value = '$toplevelmain';
7685: } else {
7686: document.simpleedit.folderpath.value = storedpath;
7687: document.uploaddocument.folderpath.value = storedpath;
7688: document.newext.folderpath.value = storedpath;
7689: }
1.433 raeburn 7690: }
7691: } else {
1.434 raeburn 7692: if (reg.test(storedpath)) {
7693: document.simpleedit.folderpath.value = storedpath;
7694: document.supuploaddocument.folderpath.value = storedpath;
7695: document.supnewext.folderpath.value = storedpath;
7696: } else {
1.433 raeburn 7697: document.simpleedit.folderpath.value = '$toplevelsupp';
7698: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7699: document.supnewext.folderpath.value = '$toplevelsupp';
7700: }
7701: }
7702: }
1.485 raeburn 7703: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7704: return false;
7705: }
1.329 droeschl 7706:
1.472 raeburn 7707: function toContents(jumpto) {
7708: var newurl = '$backtourl';
1.525 raeburn 7709: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7710: newurl = newurl+'?postdata='+jumpto;
7711: }
7712: location.href=newurl;
7713: }
7714:
1.538 raeburn 7715: function togglePick(caller,value) {
7716: var disp = 'none';
7717: if (document.getElementById('multi'+caller)) {
7718: var curr = document.getElementById('multi'+caller).style.display;
7719: if (value == 1) {
7720: disp='block';
7721: }
7722: if (curr == disp) {
7723: return;
7724: }
7725: document.getElementById('multi'+caller).style.display=disp;
7726: if (value == 1) {
1.594 damieng 7727: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7728: } else {
7729: document.getElementById('more'+caller).innerHTML = '';
7730: }
7731: if (caller == 'actions') {
7732: setClass(value);
7733: setBoxes(value);
7734: }
7735: }
7736: var showButton = multiSettings();
7737: if (showButton != 1) {
7738: showButton = multiActions();
7739: }
7740: if (document.getElementById('multisave')) {
7741: if (showButton == 1) {
7742: document.getElementById('multisave').style.display='block';
7743: } else {
7744: document.getElementById('multisave').style.display='none';
7745: }
7746: }
7747: resize_scrollbox('contentscroll','1','1');
7748: return;
7749: }
7750:
7751: function toggleCheckUncheck(caller,more) {
7752: if (more == 1) {
1.594 damieng 7753: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 7754: document.getElementById('allfields'+caller).style.display='block';
7755: } else {
1.594 damieng 7756: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7757: document.getElementById('allfields'+caller).style.display='none';
7758: }
7759: resize_scrollbox('contentscroll','1','1');
7760: }
7761:
7762: function multiSettings() {
7763: var inuse = 0;
7764: var settingsform = document.togglemultsettings;
7765: if (settingsform.showmultpick.length > 1) {
7766: for (var i=0; i<settingsform.showmultpick.length; i++) {
7767: if (settingsform.showmultpick[i].checked) {
7768: if (settingsform.showmultpick[i].value == 1) {
7769: inuse = 1;
7770: }
7771: }
7772: }
7773: }
7774: return inuse;
7775: }
7776:
7777: function multiActions() {
7778: var inuse = 0;
7779: var actionsform = document.togglemultactions;
7780: if (actionsform.showmultpick.length > 1) {
7781: for (var i=0; i<actionsform.showmultpick.length; i++) {
7782: if (actionsform.showmultpick[i].checked) {
7783: if (actionsform.showmultpick[i].value == 1) {
7784: inuse = 1;
7785: }
7786: }
7787: }
7788: }
7789: return inuse;
7790: }
7791:
7792: function checkSubmits() {
7793: var numchanges = 0;
7794: var form = document.saveactions;
7795: var doactions = multiActions();
1.542 raeburn 7796: var cutwarnings = 0;
7797: var remwarnings = 0;
1.603 raeburn 7798: var removalinfo = 0;
1.538 raeburn 7799: if (doactions == 1) {
7800: var remidxlist = document.cumulativeactions.allremoveidx.value;
7801: if ((remidxlist != '') && (remidxlist != null)) {
7802: var remidxs = remidxlist.split(',');
7803: for (var i=0; i<remidxs.length; i++) {
7804: if (document.getElementById('remove_'+remidxs[i])) {
7805: if (document.getElementById('remove_'+remidxs[i]).checked) {
7806: form.multiremove.value += remidxs[i]+',';
7807: numchanges ++;
1.542 raeburn 7808: if (document.getElementById('skip_remove_'+remidxs[i])) {
7809: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7810: remwarnings ++;
7811: }
7812: }
1.603 raeburn 7813: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7814: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7815: removalinfo ++;
7816: }
7817: }
1.537 raeburn 7818: }
7819: }
1.538 raeburn 7820: }
7821: }
7822: var cutidxlist = document.cumulativeactions.allcutidx.value;
7823: if ((cutidxlist != '') && (cutidxlist != null)) {
7824: var cutidxs = cutidxlist.split(',');
7825: for (var i=0; i<cutidxs.length; i++) {
7826: if (document.getElementById('cut_'+cutidxs[i])) {
7827: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7828: form.multicut.value += cutidxs[i]+',';
7829: numchanges ++;
1.542 raeburn 7830: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7831: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7832: cutwarnings ++;
7833: }
7834: }
1.537 raeburn 7835: }
7836: }
7837: }
7838: }
1.538 raeburn 7839: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7840: if ((copyidxlist != '') && (copyidxlist != null)) {
7841: var copyidxs = copyidxlist.split(',');
7842: for (var i=0; i<copyidxs.length; i++) {
7843: if (document.getElementById('copy_'+copyidxs[i])) {
7844: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7845: form.multicopy.value += copyidxs[i]+',';
7846: numchanges ++;
7847: }
7848: }
7849: }
7850: }
7851: if (numchanges > 0) {
7852: form.multichange.value = numchanges;
7853: }
1.537 raeburn 7854: }
1.538 raeburn 7855: var dosettings = multiSettings();
1.543 raeburn 7856: var haschanges = 0;
1.538 raeburn 7857: if (dosettings == 1) {
7858: form.allencrypturl.value = '';
7859: form.allhiddenresource.value = '';
1.543 raeburn 7860: form.changeparms.value = 'all';
7861: var patt=new RegExp(",\$");
1.538 raeburn 7862: var allidxlist = document.cumulativesettings.allidx.value;
7863: if ((allidxlist != '') && (allidxlist != null)) {
7864: var allidxs = allidxlist.split(',');
7865: if (allidxs.length > 1) {
7866: for (var i=0; i<allidxs.length; i++) {
7867: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7868: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7869: form.allhiddenresource.value += allidxs[i]+',';
7870: }
7871: }
7872: if (document.getElementById('encrypturl_'+allidxs[i])) {
7873: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7874: form.allencrypturl.value += allidxs[i]+',';
7875: }
7876: }
7877: }
1.543 raeburn 7878: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7879: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 7880: }
1.538 raeburn 7881: }
7882: form.allrandompick.value = '';
7883: form.allrandomorder.value = '';
7884: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7885: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7886: var allmapidxs = allmapidxlist.split(',');
7887: for (var i=0; i<allmapidxs.length; i++) {
7888: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7889: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7890: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7891: if ((randompick.checked) && (rpicknum.value != '')) {
7892: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7893: }
7894: if (randorder.checked) {
7895: form.allrandomorder.value += allmapidxs[i]+',';
7896: }
1.537 raeburn 7897: }
1.543 raeburn 7898: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7899: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7900: }
7901: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7902: haschanges = 1;
7903: }
7904: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7905: haschanges = 1;
7906: }
7907: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7908: haschanges = 1;
7909: }
7910: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7911: haschanges = 1;
1.537 raeburn 7912: }
7913: }
1.543 raeburn 7914: if (doactions == 1) {
1.542 raeburn 7915: if (numchanges > 0) {
1.603 raeburn 7916: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 7917: if (remwarnings > 0) {
1.594 damieng 7918: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 7919: return false;
7920: }
7921: }
1.603 raeburn 7922: if (removalinfo > 0) {
7923: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7924: return false;
7925: }
7926: }
1.542 raeburn 7927: if (cutwarnings > 0) {
1.594 damieng 7928: 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 7929: return false;
7930: }
7931: }
7932: }
7933: form.submit();
7934: return true;
1.543 raeburn 7935: }
7936: }
7937: if (dosettings == 1) {
7938: if (haschanges == 1) {
1.542 raeburn 7939: form.submit();
7940: return true;
7941: }
1.543 raeburn 7942: }
7943: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 7944: alert("$js_lt{'noor'}");
1.543 raeburn 7945: } else {
7946: if (dosettings == 1) {
1.594 damieng 7947: alert("$js_lt{'noch'}");
1.543 raeburn 7948: } else {
1.594 damieng 7949: alert("$js_lt{'noac'}");
1.543 raeburn 7950: }
7951: }
1.538 raeburn 7952: return false;
7953: }
7954:
7955: function setClass(value) {
7956: var cutclass = 'LC_docs_cut';
7957: var copyclass = 'LC_docs_copy';
7958: var removeclass = 'LC_docs_remove';
7959: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7960: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7961: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7962: var links = document.getElementsByTagName('a');
7963: for (var i=0; i<links.length; i++) {
7964: var classes = links[i].className;
7965: if (cutreg.test(classes)) {
7966: links[i].className = cutclass;
7967: if (value == 1) {
7968: links[i].className += " LC_menubuttons_link";
7969: }
7970: } else {
7971: if (copyreg.test(classes)) {
7972: links[i].className = copyclass;
7973: if (value == 1) {
7974: links[i].className += " LC_menubuttons_link";
7975: }
7976: } else {
7977: if (removereg.test(classes)) {
7978: links[i].className = removeclass;
7979: if (value == 1) {
7980: links[i].className += " LC_menubuttons_link";
7981: }
7982: }
7983: }
7984: }
7985: }
7986: return;
1.537 raeburn 7987: }
7988:
1.538 raeburn 7989: function setBoxes(value) {
7990: var remidxlist = document.cumulativeactions.allremoveidx.value;
7991: if ((remidxlist != '') && (remidxlist != null)) {
7992: var remidxs = remidxlist.split(',');
7993: for (var i=0; i<remidxs.length; i++) {
7994: if (document.getElementById('remove_'+remidxs[i])) {
7995: var item = document.getElementById('remove_'+remidxs[i]);
7996: if (value == 1) {
7997: item.className = 'LC_docs_remove';
7998: } else {
7999: item.className = 'LC_hidden';
8000: }
8001: }
8002: }
8003: }
8004: var cutidxlist = document.cumulativeactions.allcutidx.value;
8005: if ((cutidxlist != '') && (cutidxlist != null)) {
8006: var cutidxs = cutidxlist.split(',');
8007: for (var i=0; i<cutidxs.length; i++) {
8008: if (document.getElementById('cut_'+cutidxs[i])) {
8009: var item = document.getElementById('cut_'+cutidxs[i]);
8010: if (value == 1) {
8011: item.className = 'LC_docs_cut';
8012: } else {
8013: item.className = 'LC_hidden';
8014: }
8015: }
1.537 raeburn 8016: }
8017: }
1.538 raeburn 8018: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8019: if ((copyidxlist != '') && (copyidxlist != null)) {
8020: var copyidxs = copyidxlist.split(',');
8021: for (var i=0; i<copyidxs.length; i++) {
8022: if (document.getElementById('copy_'+copyidxs[i])) {
8023: var item = document.getElementById('copy_'+copyidxs[i]);
8024: if (value == 1) {
8025: item.className = 'LC_docs_copy';
8026: } else {
8027: item.className = 'LC_hidden';
8028: }
8029: }
1.537 raeburn 8030: }
8031: }
8032: return;
8033: }
8034:
1.606 raeburn 8035: function validImportCrsRes() {
8036: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8037: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8038: if ((fname == '') || (fname == null)) {
8039: alert("$js_lt{'nofi'}");
8040: return false;
8041: }
8042: var url = '/res/$coursedom/$coursenum/';
8043: if (path && path != '/') {
8044: url += path+'/';
8045: }
8046: if (fname != '') {
8047: url += fname;
8048: }
8049: var title = document.crsresimportform.crsrestitle.value;
8050: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8051: return true;
8052: }
8053:
8054: function validateNewRes(caller) {
8055: if (caller == 'single') {
8056: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8057: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8058: var resname = document.courseresform.newresourcename.value;
8059: }
8060: }
8061:
1.611 raeburn 8062: ENDSCRIPT
1.329 droeschl 8063: }
1.457 raeburn 8064:
1.483 raeburn 8065: sub history_tab_js {
8066: return <<"ENDHIST";
8067: function toggleHistoryDisp(choice) {
8068: document.docslogform.docslog.value = choice;
8069: document.docslogform.submit();
8070: return;
8071: }
8072:
8073: ENDHIST
8074: }
8075:
1.484 raeburn 8076: sub inject_data_js {
8077: return <<ENDINJECT;
8078:
8079: function injectData(current, hiddenField, name, value) {
8080: currentElement = document.getElementById(hiddenField);
8081: currentElement.name = name;
8082: currentElement.value = value;
8083: current.submit();
8084: }
8085:
8086: ENDINJECT
8087: }
8088:
8089: sub dump_switchserver_js {
8090: my @hosts = @_;
1.594 damieng 8091: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8092: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8093: swit => 'Switch server?',
1.594 damieng 8094: );
8095: my %html_js_lt = &Apache::lonlocal::texthash(
8096: swit => 'Switch server?',
1.568 raeburn 8097: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8098: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8099: chos => 'Choose server',
8100: );
1.594 damieng 8101: &js_escape(\%js_lt);
8102: &html_escape(\%html_js_lt);
8103: &js_escape(\%html_js_lt);
1.484 raeburn 8104: my $role = $env{'request.role'};
8105: my $js = <<"ENDSWJS";
8106: <script type="text/javascript">
8107: function write_switchserver() {
8108: var server;
8109: if (document.setserver.posshosts.length > 0) {
8110: for (var i=0; i<document.setserver.posshosts.length; i++) {
8111: if (document.setserver.posshosts[i].checked) {
8112: server = document.setserver.posshosts[i].value;
8113: }
8114: }
8115: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8116: }
8117: window.close();
8118: }
8119: </script>
8120:
8121: ENDSWJS
8122:
8123: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8124: {'only_body' => 1,
8125: 'js_ready' => 1,});
8126: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8127:
8128: my $hostpicker;
8129: my $count = 0;
8130: foreach my $host (sort(@hosts)) {
8131: my $checked;
8132: if ($count == 0) {
8133: $checked = ' checked="checked"';
8134: }
8135: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8136: $host.'"'.$checked.' />'.$host.'</label> ';
8137: $count++;
8138: }
8139:
8140: return <<"ENDSWITCHJS";
8141:
8142: function dump_needs_switchserver(url) {
8143: if (url!='' && url!= null) {
1.594 damieng 8144: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8145: go(url);
8146: }
8147: }
8148: return;
8149: }
8150:
8151: function choose_switchserver_window() {
8152: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8153: newWindow.document.open();
8154: newWindow.document.writeln('$startpage');
1.594 damieng 8155: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8156: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8157: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8158: '<form name="setserver" method="post" action="" \\/>\\n'+
8159: '$hostpicker\\n'+
8160: '<br \\/><br \\/>\\n'+
1.594 damieng 8161: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8162: 'onclick="write_switchserver();" \\/>\\n'+
8163: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8164: newWindow.document.writeln('$endpage');
8165: newWindow.document.close();
8166: newWindow.focus();
8167: }
8168:
8169: ENDSWITCHJS
8170: }
8171:
8172: sub makedocslogform {
8173: my ($formelems,$docslog) = @_;
8174: return <<"LOGSFORM";
8175: <form action="/adm/coursedocs" method="post" name="docslogform">
8176: <input type="hidden" name="docslog" value="$docslog" />
8177: $formelems
8178: </form>
8179: LOGSFORM
8180: }
8181:
8182: sub makesimpleeditform {
8183: my ($formelems) = @_;
8184: return <<"SIMPFORM";
8185: <form name="simpleedit" method="post" action="/adm/coursedocs">
8186: <input type="hidden" name="importdetail" value="" />
8187: $formelems
8188: </form>
8189: SIMPFORM
8190: }
8191:
1.606 raeburn 8192: sub makenewproblem {
8193: my ($r,$coursedom,$coursenum) = @_;
8194: # Creating a new problem
8195: my ($redirect,$error);
8196: if ($env{'form.authorrole'}) {
8197: my ($newsubdir,$filename);
8198: if ($env{'form.newsubdir'}) {
8199: if ($env{'form.newsubdirname'} ne '') {
8200: $newsubdir = $env{'form.newsubdirname'};
8201: }
8202: }
8203: if ($env{'form.newresourcename'}) {
8204: $filename = $env{'form.newresourcename'};
8205: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8206: $filename =~ s/`//g;
8207: $filename =~ s{/\.\./}{_}g;
8208: $filename =~ s/\.+/./g;
8209: $filename =~ s{/+}{_}g;
8210: if ($filename ne '') {
8211: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8212: if (($ext) && ($ext ne '.problem')) {
8213: $filename = $name.'.problem';
8214: } elsif ($ext eq '') {
8215: $filename .= '.problem';
8216: }
8217: my $docroot = $r->dir_config('lonDocRoot');
8218: my @ids=&Apache::lonnet::current_machine_ids();
8219: if ($env{'form.authorrole'} eq 'author') {
8220: if ($env{'user.author'}) {
8221: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8222: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8223: my $path = $docroot.$url;
8224: my $subdir = $env{'form.authorpath'};
8225: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8226: }
8227: }
8228: } elsif ($env{'form.authorrole'} eq 'course') {
8229: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8230: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8231: my $url = "/priv/$coursedom/$coursenum";
8232: my $path=$docroot.$url;
8233: my $subdir = $env{'form.authorpath'};
8234: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8235: if ($redirect) {
8236: my $rightsfile = 'default.rights';
8237: my $sourcerights = "$path/$rightsfile";
8238: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8239: my $now = time;
8240: if (!-e $sourcerights) {
8241: my $cid = $coursedom.'_'.$coursenum;
8242: if (open(my $fh,">$sourcerights")) {
8243: print $fh <<END;
8244: <accessrule effect="deny" realm="" type="course" role="" />
8245: <accessrule effect="allow" realm="$cid" type="course" role="" />
8246: END
8247: close($fh);
8248: }
8249: }
8250: if (!-e "$sourcerights.meta") {
8251: if (open(my $fh,">$sourcerights.meta")) {
8252: my $author=$env{'environment.firstname'}.' '.
8253: $env{'environment.middlename'}.' '.
8254: $env{'environment.lastname'}.' '.
8255: $env{'environment.generation'};
8256: $author =~ s/\s+$//;
8257: print $fh <<"END";
8258:
8259: <abstract></abstract>
8260: <author>$author</author>
8261: <authorspace>$coursenum:$coursedom</authorspace>
8262: <copyright>private</copyright>
8263: <creationdate>$now</creationdate>
8264: <customdistributionfile></customdistributionfile>
8265: <dependencies></dependencies>
8266: <domain>$coursedom</domain>
8267: <highestgradelevel>0</highestgradelevel>
8268: <keywords></keywords>
8269: <language>notset </language>
8270: <lastrevisiondate>$now</lastrevisiondate>
8271: <lowestgradelevel>0</lowestgradelevel>
8272: <mime>rights</mime>
8273: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8274: <notes></notes>
8275: <obsolete></obsolete>
8276: <obsoletereplacement></obsoletereplacement>
8277: <owner>$coursenum:$coursedom</owner>
8278: <rule>deny:::course,allow:$cid::course</rule>
8279: <sourceavail></sourceavail>
8280: <standards></standards>
8281: <subject></subject>
8282: <title></title>
8283: END
8284: close($fh);
8285: }
8286: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8287: if (!-e "$docroot/res/$coursedom") {
8288: mkdir("$docroot/res/$coursedom",0755);
8289: }
8290: if (!-e "$docroot/res/$coursedom/$coursenum") {
8291: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8292: }
8293: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8294: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8295: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8296: }
8297: }
8298: }
8299: if ($env{'form.newresourceadd'}) {
8300: my $template = $env{'form.template'};
8301: my $source = $docroot.$redirect;
8302: my $target = $redirect;
8303: $target =~ s{^/priv/}{/res/};
8304: $target = $docroot.$target;
8305: if (!-e $source) {
8306: my $copyfrom;
8307: if ($template) {
8308: my %templates;
8309: my @files = &Apache::lonhomework::get_template_list('problem');
8310: foreach my $poss (@files) {
8311: if (ref($poss) eq 'ARRAY') {
8312: if ($template eq $poss->[0]) {
8313: $templates{$template} = 1;
8314: last;
8315: }
8316: }
8317: }
8318: if ($templates{$template}) {
8319: $copyfrom = $template;
8320: }
8321: }
8322: unless ($copyfrom) {
8323: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8324: }
8325: &File::Copy::copy($copyfrom,$source);
8326: }
8327: if (!-e "$source.meta") {
8328: my $cid = $coursedom.'_'.$coursenum;
8329: my $now = time;
8330: if (open(my $fh,">$source.meta")) {
8331: my $author=$env{'environment.firstname'}.' '.
8332: $env{'environment.middlename'}.' '.
8333: $env{'environment.lastname'}.' '.
8334: $env{'environment.generation'};
8335: $author =~ s/\s+$//;
8336: my $title = $env{'form.newresourcetitle'};
8337: $title =~ s/^\s+|\s+$//g;
8338: print $fh <<END;
8339:
8340: <abstract></abstract>
8341: <author>$author</author>
8342: <authorspace>$coursenum:$coursedom</authorspace>
8343: <copyright>custom</copyright>
8344: <creationdate>$now</creationdate>
8345: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8346: <dependencies></dependencies>
8347: <domain>$coursedom</domain>
8348: <highestgradelevel>0</highestgradelevel>
8349: <keywords></keywords>
8350: <language>notset </language>
8351: <lastrevisiondate>$now</lastrevisiondate>
8352: <lowestgradelevel>0</lowestgradelevel>
8353: <mime>problem</mime>
8354: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8355: <notes></notes>
8356: <obsolete></obsolete>
8357: <obsoletereplacement></obsoletereplacement>
8358: <owner>$coursenum:$coursedom</owner>
8359: <sourceavail></sourceavail>
8360: <standards></standards>
8361: <subject></subject>
8362: <title>$title</title>
8363: END
8364: close($fh);
8365: }
8366: }
8367: }
8368: }
8369: }
8370: } else {
8371: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8372: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8373: if (grep(/^\Q$rolehome\E$/,@ids)) {
8374: my $now = time;
8375: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8376: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8377: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8378: my $url = "/priv/$audom/$auname";
8379: my $path = $r->dir_config('lonDocRoot').$url;
8380: my $subdir = $env{'form.authorpath'};
8381: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8382: }
8383: }
8384: }
8385: }
8386: }
8387: }
8388: }
8389: return ($redirect,$error);
8390: }
8391:
8392: sub finishnewprob {
8393: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8394: unless (-d $path) {
8395: unless (mkdir($path,02770)) {
8396: return;
8397: }
8398: }
1.606 raeburn 8399: my $redirect;
8400: if ($subdir ne '/') {
8401: $subdir = &cleandir($subdir);
8402: if (($subdir ne '') && (-d "$path/$subdir")) {
8403: $path .= "/$subdir";
8404: $url .= "/$subdir";
8405: }
8406: }
8407: my $dest;
8408: if ($newsubdir ne '') {
8409: $newsubdir = &cleandir($newsubdir);
8410: }
8411: if ($newsubdir ne '') {
8412: if (-d "$path/$newsubdir") {
8413: $dest = "$path/$newsubdir/$filename";
8414: } else {
8415: my $dirok;
8416: unless (-e "$path/$newsubdir") {
8417: if (mkdir("$path/$newsubdir",02770)) {
8418: if (chmod(02770,"$path/$newsubdir")) {
8419: $dirok = 1;
8420: }
8421: }
8422: }
8423: if ($dirok) {
8424: $dest = "$path/$newsubdir/$filename";
8425: }
8426: }
8427: if (($dest ne '') && (!-e $dest)) {
8428: $redirect = "$url/$newsubdir/$filename";
8429: }
8430: } else {
8431: $dest = "$path/$filename";
8432: if (($dest ne '') && (!-e $dest)) {
8433: $redirect = "$url/$filename";
8434: }
8435: }
8436: return $redirect;
8437: }
8438:
8439: sub cleandir {
8440: my ($dir) = @_;
8441: $dir =~ s/^\s+//;
8442: $dir =~ s/\s+$//;
8443: $dir =~ s/\.+//g;
8444: $dir =~ s/[\#\?&%\":]//g;
8445: return $dir;
8446: }
8447:
1.329 droeschl 8448: 1;
8449: __END__
8450:
8451:
8452: =head1 NAME
8453:
8454: Apache::londocs.pm
8455:
8456: =head1 SYNOPSIS
8457:
8458: This is part of the LearningOnline Network with CAPA project
8459: described at http://www.lon-capa.org.
8460:
8461: =head1 SUBROUTINES
8462:
8463: =over
8464:
8465: =item %help=()
8466:
8467: Available help topics
8468:
8469: =item mapread()
8470:
1.344 bisitz 8471: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8472: @order and @resources, determines status
8473: sets @order - pointer to resources in right order
8474: sets @resources - array with the resources with correct idx
8475:
8476: =item authorhosts()
8477:
8478: Return hash with valid author names
8479:
8480: =item clean()
8481:
8482: =item dumpcourse()
8483:
8484: Actually dump course
8485:
8486: =item group_import()
8487:
8488: Imports the given (name, url) resources into the course
8489: coursenum, coursedom, and folder must precede the list
8490:
8491: =item breadcrumbs()
8492:
8493: =item log_docs()
8494:
8495: =item docs_change_log()
8496:
8497: =item update_paste_buffer()
8498:
8499: =item print_paste_buffer()
8500:
8501: =item do_paste_from_buffer()
8502:
1.538 raeburn 8503: =item do_buffer_empty()
8504:
8505: =item clear_from_buffer()
8506:
1.492 raeburn 8507: =item get_newmap_url()
8508:
8509: =item dbcopy()
8510:
8511: =item uniqueness_check()
8512:
8513: =item contained_map_check()
8514:
8515: =item url_paste_fixups()
8516:
8517: =item apply_fixups()
8518:
8519: =item copy_dependencies()
8520:
1.329 droeschl 8521: =item update_parameter()
8522:
8523: =item handle_edit_cmd()
8524:
8525: =item editor()
8526:
8527: =item process_file_upload()
8528:
8529: =item process_secondary_uploads()
8530:
8531: =item is_supplemental_title()
8532:
8533: =item entryline()
8534:
8535: =item tiehash()
8536:
8537: =item untiehash()
8538:
8539: =item checkonthis()
8540:
8541: check on this
8542:
8543: =item verifycontent()
8544:
8545: Verify Content
8546:
8547: =item devalidateversioncache() & checkversions()
8548:
8549: Check Versions
8550:
8551: =item mark_hash_old()
8552:
8553: =item is_hash_old()
8554:
8555: =item changewarning()
8556:
8557: =item init_breadcrumbs()
8558:
8559: Breadcrumbs for special functions
8560:
1.484 raeburn 8561: =item create_list_elements()
8562:
8563: =item create_form_ul()
8564:
8565: =item startContentScreen()
8566:
8567: =item endContentScreen()
8568:
8569: =item supplemental_base()
8570:
8571: =item embedded_form_elems()
8572:
8573: =item embedded_destination()
8574:
8575: =item return_to_editor()
8576:
8577: =item decompression_info()
8578:
8579: =item decompression_phase_one()
8580:
8581: =item decompression_phase_two()
8582:
8583: =item remove_archive()
8584:
8585: =item generate_admin_menu()
8586:
8587: =item generate_edit_table()
8588:
8589: =item editing_js()
8590:
8591: =item history_tab_js()
8592:
8593: =item inject_data_js()
8594:
8595: =item dump_switchserver_js()
8596:
1.485 raeburn 8597: =item resize_scrollbox_js()
1.484 raeburn 8598:
8599: =item makedocslogform()
8600:
1.485 raeburn 8601: =item makesimpleeditform()
8602:
1.329 droeschl 8603: =back
8604:
8605: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>