Annotation of loncom/interface/londocs.pm, revision 1.613
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.613 ! raeburn 4: # $Id: londocs.pm,v 1.612 2016/11/23 01:28:50 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:
145:
146:
147: sub dumpcourse {
148: my ($r) = @_;
1.408 raeburn 149: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 150: my ($starthash,$js);
151: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
152: $js = <<"ENDJS";
153: <script type="text/javascript">
154: // <![CDATA[
155:
156: function hide_searching() {
157: if (document.getElementById('searching')) {
158: document.getElementById('searching').style.display = 'none';
159: }
160: return;
161: }
162:
163: // ]]>
164: </script>
165: ENDJS
166: $starthash = {
167: add_entries => {'onload' => "hide_searching();"},
168: };
169: }
1.568 raeburn 170: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
171: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 172: $r->print(&startContentScreen('tools'));
1.329 droeschl 173: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 174: unless ($home) {
175: $r->print(&endContentScreen());
176: return '';
177: }
1.329 droeschl 178: my $origcrsid=$env{'request.course.id'};
179: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
180: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
181: # Do the dumping
1.484 raeburn 182: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
183: $r->print(&endContentScreen());
184: return '';
185: }
1.531 raeburn 186: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 187: $r->print('<h3>'.&mt('Copying Files').'</h3>');
188: my $title=$env{'form.authorfolder'};
189: $title=&clean($title);
1.567 raeburn 190: my ($navmap,$errormsg) =
191: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
192: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
193: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
194: my (%maps,%resources,%titles);
195: if (!ref($navmap)) {
196: $r->print($errormsg.
197: &endContentScreen());
198: return '';
199: } else {
200: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
201: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 202: }
1.567 raeburn 203: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
204: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
205: %newcontent,%has_simpleprobs);
206: foreach my $item (sort {$a <=> $b} (@todump)) {
207: my $name = $env{'form.namefor_'.$item};
208: if ($resources{$item}) {
209: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
210: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
211: $tocopy{$1} = $name;
212: $display{$item} = $1;
213: $lookup{$1} = $item;
214: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
215: $simpleproblems{$item} = {
216: symb => $resources{$item},
217: name => $name,
218: };
219: $display{$item} = 'simpleproblem_'.$name;
220: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
221: $has_simpleprobs{$1}{$id} = $item;
222: }
223: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
224: my $marker = $1;
225: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
226: $simplepages{$item} = {
227: res => $res,
228: title => $titles{$item},
229: db => $db_name,
230: marker => $marker,
231: symb => $resources{$item},
232: name => $name,
233: };
234: $display{$item} = '/'.$res;
235: }
236: } elsif ($maps{$item}) {
237: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
238: $tocopy{$1} = $name;
239: $display{$item} = $1;
240: $lookup{$1} = $item;
241: }
242: } else {
243: next;
244: }
245: }
1.329 droeschl 246: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
247: $crs=~s/\_/\//g;
1.567 raeburn 248: my $mm = new File::MMagic;
249: my $prefix = "/uploaded/$cdom/$cnum/";
250: %replacehash = %tocopy;
251: foreach my $item (sort(keys(%simpleproblems))) {
252: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
253: $newcontent{$display{$item}} = $content;
254: }
255: my $gateway = Apache::lonhtmlgateway->new('web');
256: foreach my $item (sort(keys(%simplepages))) {
257: if (ref($simplepages{$item}) eq 'HASH') {
258: my $pagetitle = $simplepages{$item}{'title'};
259: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
260: my %contents;
261: foreach my $field (keys(%fields)) {
262: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
263: my $name = $1;
264: my $msg = $fields{$field};
265: if ($name eq 'webreferences') {
266: if ($msg =~ m{^https?://}) {
267: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
268: }
269: } else {
270: $msg = &Encode::decode('utf8',$msg);
271: $msg = $gateway->process_outgoing_html($msg,1);
272: $contents{$name} = $msg;
273: }
274: } elsif ($field eq 'uploaded.photourl') {
275: my $marker = $simplepages{$item}{marker};
276: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
277: my $filepath = $1;
278: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
279: if ($fname ne '') {
280: $fname=~s/\.(\w+)$//;
281: my $ext=$1;
282: $fname = &clean($fname);
283: $fname.='.'.$ext;
284: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
285: $replacehash{$filepath} = $relpath.$fname;
286: $deps{$item}{$filepath} = 1;
287: }
288: }
289: }
290: }
291: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
292: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
293: my $content = '
294: <html>
295: <head>
296: <title>'.$pagetitle.'</title>
297: </head>
298: <body bgcolor="#ffffff">';
299: if ($contents{title}) {
300: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
301: }
302: if ($contents{image}) {
303: $content .= "\n".$contents{image};
304: }
305: if ($contents{content}) {
306: $content .= '
307: <div class="LC_Box">
1.577 bisitz 308: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 309: $contents{content}.'
310: </div>';
311: }
312: if ($contents{webreferences}) {
313: $content .= '
314: <div class="LC_Box">
1.577 bisitz 315: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 316: $contents{webreferences}.'
317: </div>';
318: }
319: $content .= '
320: </body>
321: </html>
322: ';
323: $newcontent{'/'.$simplepages{$item}{res}} = $content;
324: }
325: }
326: foreach my $item (keys(%tocopy)) {
327: unless ($item=~/\.(sequence|page)$/) {
328: my $currurlpath = $prefix.$item;
329: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
330: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
331: }
332: }
333: foreach my $num (sort {$a <=> $b} (@todump)) {
334: my $src = $display{$num};
335: next if ($src eq '');
336: my @needcopy = ();
337: if ($replacehash{$src}) {
338: push(@needcopy,$src);
339: if (ref($deps{$num}) eq 'HASH') {
340: foreach my $dep (sort(keys(%{$deps{$num}}))) {
341: if ($replacehash{$dep}) {
342: push(@needcopy,$dep);
343: }
344: }
345: }
346: } elsif ($src =~ /^simpleproblem_/) {
347: push(@needcopy,$src);
348: }
349: next if (@needcopy == 0);
350: my ($result,$depresult);
351: for (my $i=0; $i<@needcopy; $i++) {
352: my $item = $needcopy[$i];
353: my $newfilename;
354: if ($simpleproblems{$num}) {
355: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
356: } else {
357: $newfilename=$title.'/'.$replacehash{$item};
358: }
359: $newfilename=~s/\.(\w+)$//;
360: my $ext=$1;
361: $newfilename=&clean($newfilename);
362: $newfilename.='.'.$ext;
363: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
364: if ($newrelpath ne $replacehash{$item}) {
365: $replacehash{$item} = $newrelpath;
366: }
367: my @dirs=split(/\//,$newfilename);
368: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
369: my $makepath=$path;
370: my $fail;
371: my $origin;
372: for (my $i=0;$i<$#dirs;$i++) {
373: $makepath.='/'.$dirs[$i];
374: unless (-e $makepath) {
375: unless(mkdir($makepath,0755)) {
376: $fail = &mt('Directory creation failed.');
377: }
378: }
379: }
380: if ($i == 0) {
381: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
382: } else {
383: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
384: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
385: &mt('(dependency)').'</span>: ';
386: }
387: if (-e $path.'/'.$newfilename) {
388: $fail = &mt('Destination already exists -- not overwriting.');
389: } else {
390: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
391: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
392: ($item =~ /^simpleproblem_/)) {
393: print $fh $newcontent{$item};
394: } else {
395: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
396: if (-e $fileloc) {
397: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
398: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
399: (ref($has_simpleprobs{$item}) eq 'HASH')) {
400: my %changes = %{$has_simpleprobs{$item}};
401: my $content = &Apache::lonclonecourse::rewritefile(
402: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
403: (%replacehash,$crs => '')
404: );
405: my $updatedcontent = '';
406: my $parser = HTML::TokeParser->new(\$content);
407: $parser->attr_encoded(1);
408: while (my $token = $parser->get_token) {
409: if ($token->[0] eq 'S') {
410: if (($token->[1] eq 'resource') &&
411: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
412: ($changes{$token->[2]->{'id'}})) {
413: my $id = $token->[2]->{'id'};
414: $updatedcontent .= '<'.$token->[1];
415: foreach my $attrib (@{$token->[3]}) {
416: next unless ($attrib =~ /^(src|type|title|id)$/);
417: if ($attrib eq 'src') {
418: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
419: if ($file) {
420: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
421: } else {
422: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
423: }
424: } else {
425: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
426: }
427: }
428: $updatedcontent .= ' />'."\n";
429: } else {
430: $updatedcontent .= $token->[4]."\n";
431: }
432: } else {
433: $updatedcontent .= $token->[2];
434: }
435: }
436: print $fh $updatedcontent;
437: } else {
438: print $fh &Apache::lonclonecourse::rewritefile(
439: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
440: (%replacehash,$crs => '')
441: );
442: }
443: } else {
444: print $fh
445: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
446: }
447: } else {
448: $fail = &mt('Source does not exist.');
449: }
450: }
451: $fh->close();
452: } else {
453: $fail = &mt('Could not write to destination.');
454: }
455: }
456: my $text;
457: if ($fail) {
458: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
459: } else {
460: $text = '<span class="LC_success">'.&mt('ok').'</span>';
461: }
462: if ($i == 0) {
463: $result .= $text;
464: } else {
465: $depresult .= $text.'</li>';
466: }
467: }
468: $r->print($result);
469: if ($depresult) {
470: $r->print('<ul>'.$depresult.'</ul>');
471: }
472: }
473: } else {
474: my ($navmap,$errormsg) =
475: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
476: if (!ref($navmap)) {
477: $r->print($errormsg);
478: } else {
479: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
480: $r->rflush();
481: my ($preamble,$formname);
482: $formname = 'dumpdoc';
483: unless ($home==1) {
484: $preamble = '<div class="LC_left_float">'.
485: '<fieldset><legend>'.
486: &mt('Select the Authoring Space').
487: '</legend><select name="authorspace">';
1.329 droeschl 488: }
1.567 raeburn 489: my @orderspaces = ();
490: foreach my $key (sort(keys(%outhash))) {
491: if ($key=~/^home_(.+)$/) {
492: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
493: unshift(@orderspaces,$1);
494: } else {
495: push(@orderspaces,$1);
496: }
497: }
498: }
1.569 raeburn 499: if ($home>1) {
500: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
501: }
1.567 raeburn 502: foreach my $user (@orderspaces) {
1.329 droeschl 503: if ($home==1) {
1.567 raeburn 504: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 505: } else {
1.567 raeburn 506: $preamble .= '<option value="'.$user.'">'.$user.' - '.
507: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
508: }
1.329 droeschl 509: }
1.567 raeburn 510: unless ($home==1) {
511: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 512: }
1.567 raeburn 513: my $title=$origcrsdata{'description'};
514: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 515: $title=&clean($title);
1.567 raeburn 516: $preamble .= '<div class="LC_left_float">'.
517: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
518: '<input type="text" size="50" name="authorfolder" value="'.
519: $title.'" />'.
520: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
521: my %uploadedfiles;
522: &tiehash();
523: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
524: my ($ext)=($file=~/\.(\w+)$/);
525: # FIXME Check supplemental here
526: my $title=$hash{'title_'.$hash{
527: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
528: if (!$title) {
529: $title=$file;
530: } else {
531: $title=~s|/|_|g;
532: }
533: $title=~s/\.(\w+)$//;
534: $title=&clean($title);
535: $title.='.'.$ext;
536: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
537: $uploadedfiles{$file} = $title;
538: }
539: &untiehash();
540: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
541: undef,undef,$preamble,$home,\%uploadedfiles));
542: }
1.329 droeschl 543: }
1.484 raeburn 544: $r->print(&endContentScreen());
1.329 droeschl 545: }
546:
1.567 raeburn 547: sub recurse_html {
548: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
549: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
550: my (%allfiles,%codebase);
551: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
552: if (keys(%allfiles)) {
553: foreach my $dependency (keys(%allfiles)) {
554: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
555: my ($depurl,$relfile,$newcontainer);
556: if ($dependency =~ m{^/}) {
557: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
558: $relfile = $1;
559: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
560: $newcontainer = $1;
561: next if ($replacehash->{$newcontainer});
562: }
563: $depurl = $dependency;
564: } else {
565: next;
566: }
567: } else {
568: $relfile = $dependency;
569: $depurl = $currurlpath;
570: $depurl =~ s{[^/]+$}{};
571: $depurl .= $dependency;
572: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
573: }
574: next if ($relfile eq '');
575: my $newname = $replacehash->{$container};
576: $newname =~ s{[^/]+$}{};
577: $replacehash->{$newcontainer} = $newname.$relfile;
578: $deps->{$item}{$newcontainer} = 1;
579: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
580: my $depfile = &Apache::lonnet::filelocation('',$depurl);
581: my $type = $mm->checktype_filename($depfile);
582: if ($type eq 'text/html') {
583: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
584: }
585: }
586: }
587: }
588: return;
589: }
590:
1.329 droeschl 591: sub group_import {
1.598 raeburn 592: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 593: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
594: %removeparam,$importuploaded,$fixuperrors);
595: $allmaps = {};
1.329 droeschl 596: while (@files) {
597: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 598: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 599: && ($caller eq 'londocs')
600: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 601:
1.329 droeschl 602: my $errtext = '';
603: my $fatal = 0;
604: my $newmapstr = '<map>'."\n".
605: '<resource id="1" src="" type="start"></resource>'."\n".
606: '<link from="1" to="2" index="1"></link>'."\n".
607: '<resource id="2" src="" type="finish"></resource>'."\n".
608: '</map>';
609: $env{'form.output'}=$newmapstr;
610: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
611: 'output',$1.$2);
1.534 raeburn 612: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 613: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
614: $fatal = 2;
615: }
616: if ($fatal) {
617: return ($errtext,$fatal);
618: }
619: }
620: if ($url) {
1.598 raeburn 621: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) {
622: $url = $1;
623: my $marker = $2;
624: my $info = $3;
1.604 raeburn 625: my ($toolid,%toolhash,%toolsettings);
1.598 raeburn 626: my @toolinfo = split(/:/,$info);
627: if ($residx) {
1.604 raeburn 628: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 629: $toolid = $toolsettings{'id'};
630: } else {
1.604 raeburn 631: $toolid = shift(@toolinfo);
1.598 raeburn 632: }
633: $toolid =~ s/\D//g;
1.604 raeburn 634: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
635: $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;
636: $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'});
637: $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'});
1.598 raeburn 638: if (ref($ltitoolsref) eq 'HASH') {
1.604 raeburn 639: my @deleted;
1.598 raeburn 640: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
641: if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) {
642: $url =~ s/exttool$/exttools/;
643: }
644: $toolhash{'id'} = $toolid;
1.604 raeburn 645: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) {
646: if ($toolhash{'target'} eq 'window') {
647: foreach my $item ('width','height') {
648: $toolhash{$item} =~ s/^\s+//;
649: $toolhash{$item} =~ s/\s+$//;
650: }
651: }
652: } elsif ($residx) {
653: $toolhash{'target'} = $toolsettings{'target'};
654: if ($toolhash{'target'} eq 'window') {
655: $toolhash{'width'} = $toolsettings{'width'};
656: $toolhash{'height'} = $toolsettings{'height'};
657: }
658: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
659: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
660: if ($toolhash{'target'} eq 'window') {
661: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
662: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
663: }
664: }
1.598 raeburn 665: if ($toolhash{'target'} eq 'iframe') {
666: delete($toolhash{'width'});
667: delete($toolhash{'height'});
1.604 raeburn 668: if ($residx) {
669: if ($toolsettings{'width'}) {
670: push(@deleted,'width');
671: }
672: if ($toolsettings{'height'}) {
673: push(@deleted,'height');
674: }
675: }
676: }
677: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
678: foreach my $item ('label','title') {
679: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
680: $toolhash{'crs'.$item} =~ s/^\s+//;
681: $toolhash{'crs'.$item} =~ s/\s+$//;
682: if ($toolhash{'crs'.$item} eq '') {
683: delete($toolhash{'crs'.$item});
684: }
685: } else {
686: delete($toolhash{'crs'.$item});
687: }
688: if (($residx) && (exists($toolsettings{'crs'.$item}))) {
689: unless (exists($toolhash{'crs'.$item})) {
690: push(@deleted,'crs'.$item);
691: }
692: }
1.598 raeburn 693: }
694: }
695: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 696: if ($putres eq 'ok') {
697: if (@deleted) {
698: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
699: }
700: }
1.598 raeburn 701: }
702: }
703: }
1.529 raeburn 704: if (($caller eq 'londocs') &&
705: ($folder =~ /^default/)) {
1.534 raeburn 706: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 707: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
708: my $cid = $coursedom.'_'.$coursenum;
709: $allmaps =
710: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
711: $chome,$cid);
712: $donechk = 1;
713: }
714: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
715: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
716: \%addedmaps,\%hierarchy,\%titles,$allmaps);
717: $importuploaded = 1;
718: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
719: next if ($allmaps->{$url});
720: }
721: }
1.344 bisitz 722: if (!$residx
1.329 droeschl 723: || defined($LONCAPA::map::zombies[$residx])) {
724: $residx = &LONCAPA::map::getresidx($url,$residx);
725: push(@LONCAPA::map::order, $residx);
726: }
727: my $ext = 'false';
728: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
729: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 730: if ($name eq '') {
1.538 raeburn 731: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 732: }
733: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
734: my $filepath = $1;
735: my $fname = $name;
736: if ($fname =~ /^\W+$/) {
737: $fname = 'web';
738: } else {
739: $fname =~ s/\W/_/g;
740: }
1.599 damieng 741: if (length($fname) > 15) {
1.534 raeburn 742: $fname = substr($fname,0,14);
743: }
744: my $initialtext = &mt('Replace with your own content.');
745: my $newhtml = <<END;
1.545 raeburn 746: <html>
1.534 raeburn 747: <head>
748: <title>$name</title>
749: </head>
750: <body bgcolor="#ffffff">
751: $initialtext
752: </body>
753: </html>
754: END
755: $env{'form.output'}=$newhtml;
756: my $result =
757: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
758: 'output',
759: "$filepath/$residx/$fname.html");
760: if ($result =~ m{^/uploaded/}) {
761: $url = $result;
762: if ($filepath =~ /^supplemental/) {
763: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
764: $env{'user.domain'}.'___&&&___'.$name;
765: }
766: } else {
767: return (&mt('Failed to save new web page.'),1);
768: }
769: }
1.538 raeburn 770: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 771: $LONCAPA::map::resources[$residx] =
1.329 droeschl 772: join(':', ($name, $url, $ext, 'normal', 'res'));
773: }
774: }
1.529 raeburn 775: if ($importuploaded) {
776: my %import_errors;
777: my %updated = (
778: removefrommap => \%removefrommap,
779: removeparam => \%removeparam,
780: );
1.533 raeburn 781: my ($result,$msgsarray,$lockerror) =
782: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 783: if (keys(%import_errors) > 0) {
1.530 raeburn 784: $fixuperrors =
1.529 raeburn 785: '<p span class="LC_warning">'."\n".
786: &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".
787: '<ul>'."\n";
788: foreach my $key (sort(keys(%import_errors))) {
789: $fixuperrors .= '<li>'.$key.'</li>'."\n";
790: }
791: $fixuperrors .= '</ul></p>'."\n";
792: }
1.533 raeburn 793: if (ref($msgsarray) eq 'ARRAY') {
794: if (@{$msgsarray} > 0) {
795: $fixuperrors .= '<p class="LC_info">'.
796: join('<br />',@{$msgsarray}).
797: '</p>';
798: }
799: }
800: if ($lockerror) {
801: $fixuperrors .= '<p class="LC_error">'.
802: $lockerror.
803: '</p>';
804: }
1.529 raeburn 805: }
806: my ($errtext,$fatal) =
807: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 808: unless ($fatal) {
809: if ($folder =~ /^supplemental/) {
810: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 811: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
812: $folder.'.'.$container);
1.557 raeburn 813: }
814: }
1.529 raeburn 815: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 816: }
817:
818: sub log_docs {
1.494 raeburn 819: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 820: }
821:
822: {
823: my @oldresources=();
824: my @oldorder=();
825: my $parmidx;
826: my %parmaction=();
827: my %parmvalue=();
828: my $changedflag;
829:
830: sub snapshotbefore {
831: @oldresources=@LONCAPA::map::resources;
832: @oldorder=@LONCAPA::map::order;
833: $parmidx=undef;
834: %parmaction=();
835: %parmvalue=();
836: $changedflag=0;
837: }
838:
839: sub remember_parms {
840: my ($idx,$parameter,$action,$value)=@_;
841: $parmidx=$idx;
842: $parmaction{$parameter}=$action;
843: $parmvalue{$parameter}=$value;
844: $changedflag=1;
845: }
846:
847: sub log_differences {
848: my ($plain)=@_;
849: my %storehash=('folder' => $plain,
850: 'currentfolder' => $env{'form.folder'});
851: if ($parmidx) {
852: $storehash{'parameter_res'}=$oldresources[$parmidx];
853: foreach my $parm (keys(%parmaction)) {
854: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
855: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
856: }
857: }
858: my $maxidx=$#oldresources;
859: if ($#LONCAPA::map::resources>$#oldresources) {
860: $maxidx=$#LONCAPA::map::resources;
861: }
862: for (my $idx=0; $idx<=$maxidx; $idx++) {
863: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
864: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
865: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
866: $changedflag=1;
867: }
868: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
869: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
870: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
871: $changedflag=1;
872: }
873: }
874: $storehash{'maxidx'}=$maxidx;
875: if ($changedflag) { &log_docs(\%storehash); }
876: }
877: }
878:
879: sub docs_change_log {
1.611 raeburn 880: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 881: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.483 raeburn 882: my $js = '<script type="text/javascript">'."\n".
883: '// <![CDATA['."\n".
884: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 885: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.611 raeburn 886: $coursedom,$coursenum,'','',$canedit)."\n".
1.483 raeburn 887: &history_tab_js()."\n".
1.484 raeburn 888: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 889: '// ]]>'."\n".
890: '</script>'."\n";
1.484 raeburn 891: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
892: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 893: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 894: my %orderhash;
895: my $container='sequence';
896: my $pathitem;
1.519 raeburn 897: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 898: $container='page';
899: }
1.519 raeburn 900: my $folderpath=$env{'form.folderpath'};
901: if ($folderpath eq '') {
1.548 raeburn 902: $folderpath = 'default&'.&escape(&mt('Main Content').':::::');
1.519 raeburn 903: }
904: $pathitem = '<input type="hidden" name="folderpath" value="'.
905: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 906: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
907: my $jumpto = $readfile;
908: $jumpto =~ s{^/}{};
909: my $tid = 1;
1.489 raeburn 910: if ($supplementalflag) {
911: $tid = 2;
912: }
1.509 raeburn 913: my ($breadcrumbtrail) =
914: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 915: $r->print($breadcrumbtrail.
916: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
917: $readfile));
1.329 droeschl 918: my %docslog=&Apache::lonnet::dump('nohist_docslog',
919: $env{'course.'.$env{'request.course.id'}.'.domain'},
920: $env{'course.'.$env{'request.course.id'}.'.num'});
921:
922: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
923:
924: my %saveable_parameters = ('show' => 'scalar',);
925: &Apache::loncommon::store_course_settings('docs_log',
926: \%saveable_parameters);
927: &Apache::loncommon::restore_course_settings('docs_log',
928: \%saveable_parameters);
929: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 930: # FIXME: internationalization seems wrong here
1.329 droeschl 931: my %lt=('hiddenresource' => 'Resources hidden',
932: 'encrypturl' => 'URL hidden',
933: 'randompick' => 'Randomly pick',
934: 'randomorder' => 'Randomly ordered',
935: 'set' => 'set to',
936: 'del' => 'deleted');
1.484 raeburn 937: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
938: $pathitem."\n".
939: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
940: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
941: $r->print('<div class="LC_left_float">'.
942: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
943: &makedocslogform($filter,1).
944: '</fieldset></div><br clear="all" />');
1.329 droeschl 945: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
946: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
947: &mt('After').'</th>'.
948: &Apache::loncommon::end_data_table_header_row());
949: my $shown=0;
950: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
951: if ($env{'form.displayfilter'} eq 'currentfolder') {
952: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
953: }
954: my @changes=keys(%{$docslog{$id}{'logentry'}});
955: if ($env{'form.displayfilter'} eq 'containing') {
956: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
957: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
958: foreach my $key (@changes) {
959: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
960: }
1.344 bisitz 961: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 962: }
963: my $count = 0;
964: my $time =
965: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
966: my $plainname =
967: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
968: $docslog{$id}{'exe_udom'});
969: my $about_me_link =
970: &Apache::loncommon::aboutmewrapper($plainname,
971: $docslog{$id}{'exe_uname'},
972: $docslog{$id}{'exe_udom'});
973: my $send_msg_link='';
974: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
975: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
976: $send_msg_link ='<br />'.
977: &Apache::loncommon::messagewrapper(&mt('Send message'),
978: $docslog{$id}{'exe_uname'},
979: $docslog{$id}{'exe_udom'});
980: }
981: $r->print(&Apache::loncommon::start_data_table_row());
982: $r->print('<td>'.$time.'</td>
983: <td>'.$about_me_link.
984: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
985: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
986: $send_msg_link.'</td><td>'.
987: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 988: my $is_supp = 0;
989: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
990: $is_supp = 1;
991: }
1.329 droeschl 992: # Before
993: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
994: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
995: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
996: if ($oldname ne $newname) {
1.488 raeburn 997: my $shown = &LONCAPA::map::qtescape($oldname);
998: if ($is_supp) {
999: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1000: }
1001: $r->print($shown);
1.329 droeschl 1002: }
1003: }
1004: $r->print('<ul>');
1005: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1006: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1007: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1008: if ($is_supp) {
1009: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1010: }
1011: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1012: }
1013: }
1014: $r->print('</ul>');
1015: # After
1016: $r->print('</td><td>');
1017:
1018: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1019: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1020: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1021: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1022: my $shown = &LONCAPA::map::qtescape($newname);
1023: if ($is_supp) {
1024: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1025: }
1026: $r->print($shown);
1.329 droeschl 1027: }
1.364 bisitz 1028: }
1.329 droeschl 1029: $r->print('<ul>');
1030: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1031: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1032: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1033: if ($is_supp) {
1034: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1035: }
1036: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1037: }
1038: }
1039: $r->print('</ul>');
1040: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1041: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1042: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1043: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1044: # FIXME: internationalization seems wrong here
1.329 droeschl 1045: $r->print('<li>'.
1046: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1047: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1048: .'</li>');
1049: }
1050: }
1051: $r->print('</ul>');
1052: }
1053: # End
1054: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1055: $shown++;
1056: if (!($env{'form.show'} eq &mt('all')
1057: || $shown<=$env{'form.show'})) { last; }
1058: }
1.484 raeburn 1059: $r->print(&Apache::loncommon::end_data_table()."\n".
1060: &makesimpleeditform($pathitem)."\n".
1061: '</div></div>');
1062: $r->print(&endContentScreen());
1.329 droeschl 1063: }
1064:
1065: sub update_paste_buffer {
1.492 raeburn 1066: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1067: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1068: if ($env{'form.multiremove'}) {
1069: $env{'form.multiremove'} =~ s/,$//;
1070: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1071: }
1072: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1073: if ($env{'form.multicut'}) {
1074: $env{'form.multicut'} =~ s/,$//;
1075: foreach my $item (split(/,/,$env{'form.multicut'})) {
1076: unless ($removals{$item}) {
1077: $cuts{$item} = 1;
1078: push(@possibles,$item.':cut');
1079: }
1080: }
1081: }
1082: if ($env{'form.multicopy'}) {
1083: $env{'form.multicopy'} =~ s/,$//;
1084: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1085: unless ($removals{$item} || $cuts{$item}) {
1086: push(@possibles,$item.':copy');
1087: }
1088: }
1089: }
1090: } elsif ($env{'form.markcopy'}) {
1091: @possibles = split(/,/,$env{'form.markcopy'});
1092: }
1.329 droeschl 1093:
1.538 raeburn 1094: return if (@possibles == 0);
1.329 droeschl 1095: return if (!defined($env{'form.copyfolder'}));
1096:
1097: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1098: $env{'form.copyfolder'});
1.538 raeburn 1099: return if ($fatal);
1100:
1101: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1102:
1.538 raeburn 1103: # Retrieve current paste buffer suffixes.
1104: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1105: my (%pasteurls,@newpaste);
1106:
1107: # Construct identifiers for current contents of user's paste buffer
1108: if (@currpaste) {
1109: foreach my $suffix (@currpaste) {
1110: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1111: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1112: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1113: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1114: ($url ne '')) {
1.597 raeburn 1115: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1116: }
1117: }
1118: }
1119:
1120: # Mark items for copying (skip any items already in user's paste buffer)
1121: my %addtoenv;
1.597 raeburn 1122:
1123: my @pathitems = split(/\&/,$env{'form.folderpath'});
1124: my @folderconf = split(/\:/,$pathitems[-1]);
1125: my $ispage = $folderconf[4];
1126:
1.538 raeburn 1127: foreach my $item (@possibles) {
1128: my ($orderidx,$cmd) = split(/:/,$item);
1129: next if ($orderidx =~ /\D/);
1130: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1131: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1132: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1133: my %denied = &action_restrictions($coursenum,$coursedom,
1134: &LONCAPA::map::qtescape($url),
1135: $env{'form.folderpath'},\%curr_groups);
1136: next if ($denied{'copy'});
1137: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1138: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1139: my ($suffix,$errortxt,$locknotfreed) =
1140: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1141: if ($suffix ne '') {
1142: push(@newpaste,$suffix);
1143: } else {
1144: if ($locknotfreed) {
1145: return $locknotfreed;
1146: }
1.538 raeburn 1147: }
1148: if (&is_supplemental_title($title)) {
1149: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1150: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1151: }
1.329 droeschl 1152:
1.538 raeburn 1153: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1154: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1155: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1156: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1157: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1158: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1159: my $prefix = $1;
1160: my $subdir =$2;
1161: if ($subdir eq '') {
1162: $subdir = $prefix;
1.492 raeburn 1163: }
1.538 raeburn 1164: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1165: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1166: \%hierarchy,\%titles,\%allmaps);
1167: if (ref($hierarchy{$url}) eq 'HASH') {
1168: my ($nested,$nestednames);
1169: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1170: $nested =~ s/\&$//;
1171: $nestednames =~ s/\Q___&&&___\E$//;
1172: if ($nested ne '') {
1173: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1174: }
1175: if ($nestednames ne '') {
1176: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1177: }
1.492 raeburn 1178: }
1179: }
1.591 raeburn 1180: if ($locknotfreed) {
1181: $output = $locknotfreed;
1182: last;
1183: }
1.492 raeburn 1184: }
1.538 raeburn 1185: if (@newpaste) {
1186: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1187: }
1.492 raeburn 1188: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1189: delete($env{'form.markcopy'});
1.591 raeburn 1190: return $output;
1.329 droeschl 1191: }
1192:
1.492 raeburn 1193: sub recurse_uploaded_maps {
1194: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1195: if (ref($hierarchy->{$url}) eq 'HASH') {
1196: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1197: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1198: my (@uploaded,@names,%shorter);
1199: for (my $i=0; $i<@maps; $i++) {
1200: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1201: if ($inner ne '') {
1202: push(@uploaded,$inner);
1203: push(@names,&escape($titles[$i]));
1204: $shorter{$maps[$i]} = $inner;
1205: }
1206: }
1207: $$nestref .= "$dir:".join(',',@uploaded).'&';
1208: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1209: foreach my $map (@maps) {
1210: if ($shorter{$map} ne '') {
1211: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1212: }
1213: }
1214: }
1215: return;
1216: }
1217:
1.329 droeschl 1218: sub print_paste_buffer {
1.492 raeburn 1219: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1220: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1221:
1.538 raeburn 1222: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1223: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1224: }
1225:
1.538 raeburn 1226: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1227: my ($pasteitems,@pasteable);
1.575 raeburn 1228: my $clipboardcount = 0;
1.488 raeburn 1229:
1.538 raeburn 1230: # Construct identifiers for current contents of user's paste buffer
1231: foreach my $suffix (@currpaste) {
1232: next if ($suffix =~ /\D/);
1233: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1234: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1235: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1236: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1237: ($url ne '')) {
1.575 raeburn 1238: $clipboardcount ++;
1.538 raeburn 1239: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1240: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1241: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1242: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1243: $is_external = 1;
1.598 raeburn 1244: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) {
1245: $is_exttool = 1;
1.538 raeburn 1246: }
1247: if ($folder =~ /^supplemental/) {
1248: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1249: unless ($canpaste) {
1250: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1251: }
1252: } else {
1253: $canpaste = 1;
1254: }
1255: if ($canpaste) {
1256: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1257: my $srcdom = $1;
1258: my $srcnum = $2;
1259: my $rem = $3;
1260: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1261: $othercourse = 1;
1262: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1263: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1264: } else {
1265: $canpaste = 0;
1266: $nopaste = &mt('Paste from another course unavailable.');
1267: }
1268: }
1269: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1270: my $prefix = $1;
1271: $parent = $2;
1272: if ($folder !~ /^\Q$prefix\E/) {
1273: $areachange = 1;
1274: }
1275: $is_uploaded_map = 1;
1.492 raeburn 1276: }
1.597 raeburn 1277: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1278: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1279: if ($cid ne $env{'request.course.id'}) {
1280: my ($srcdom,$srcnum) = split(/_/,$cid);
1281: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1282: $othercrs = '<br />'.&mt('(from another course)');
1283: } else {
1284: $canpaste = 0;
1285: $nopaste = &mt('Paste from another course unavailable.');
1286: }
1287: }
1.492 raeburn 1288: }
1.596 raeburn 1289: if ($canpaste) {
1290: push(@pasteable,$suffix);
1291: }
1.538 raeburn 1292: }
1293: my $buffer;
1.598 raeburn 1294: if (($is_external) || ($is_exttool)) {
1.538 raeburn 1295: $buffer = &mt('External Resource').': '.
1296: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1297: &LONCAPA::map::qtescape($url).')';
1298: } else {
1299: my $icon = &Apache::loncommon::icon($extension);
1300: if ($extension eq 'sequence' &&
1301: $url =~ m{/default_\d+\.sequence$}x) {
1302: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1303: $icon .= '/navmap.folder.closed.gif';
1304: }
1.589 raeburn 1305: my $title = $env{'docs.markedcopy_title_'.$suffix};
1306: if ($title eq '') {
1307: ($title) = ($url =~ m{/([^/]+)$});
1308: }
1.538 raeburn 1309: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1310: ': '.
1311: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1312: &LONCAPA::map::qtescape($title));
1.538 raeburn 1313: }
1314: $pasteitems .= '<div class="LC_left_float">';
1315: my ($options,$onclick);
1316: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1317: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1318: if (($is_uploaded_map) ||
1319: ($url =~ /(bulletinboard|smppg)$/) ||
1320: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1321: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1322: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1323: }
1324: }
1325: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1326: if ($nopaste) {
1327: $pasteitems .= $nopaste;
1328: } else {
1329: if ($othercrs) {
1330: $pasteitems .= $othercrs;
1331: }
1332: if ($options) {
1333: $pasteitems .= $options;
1.492 raeburn 1334: }
1335: }
1.538 raeburn 1336: $pasteitems .= '</div>';
1337: }
1338: }
1339: if ($pasteitems eq '') {
1340: &Apache::lonnet::delenv('docs.markedcopies');
1341: }
1342: my ($pasteform,$form_start,$buttons,$form_end);
1343: if ($pasteitems) {
1344: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1345: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1346: if (@pasteable) {
1.575 raeburn 1347: my $value = &mt('Paste to current folder');
1348: if ($container eq 'page') {
1349: $value = &mt('Paste to current page');
1350: }
1351: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1352: }
1353: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1354: if ($clipboardcount > 1) {
1355: $buttons .=
1356: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1357: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1358: (' 'x2).
1359: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1360: (' 'x2);
1.492 raeburn 1361: }
1.575 raeburn 1362: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1363: '</form>';
1.538 raeburn 1364: } else {
1365: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1366: }
1.538 raeburn 1367: $r->print($form_start
1368: .'<fieldset>'
1369: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1370: .$pasteitems
1371: .'</fieldset>'
1372: .$form_end);
1373: }
1374:
1375: sub paste_options {
1376: my ($suffix,$is_uploaded_map,$parent) = @_;
1377: my ($copytext,$movetext);
1378: if ($is_uploaded_map) {
1379: $copytext = &mt('Copy to new folder');
1380: $movetext = &mt('Move old');
1381: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1382: $copytext = &mt('Copy to new board');
1383: $movetext = &mt('Move (not posts)');
1384: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1385: $copytext = &mt('Copy to new page');
1386: $movetext = &mt('Move');
1.533 raeburn 1387: } else {
1.538 raeburn 1388: $copytext = &mt('Copy to new file');
1389: $movetext = &mt('Move');
1390: }
1391: my $output = '<br />'.
1392: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1393: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1394: '<label>'.
1395: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1396: $copytext.'</label></span>'.(' 'x2).' '.
1397: '<span class="LC_nobreak"><label>'.
1398: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1399: $movetext.'</label></span>';
1400: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1401: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1402: '</legend><table border="0">';
1403: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1404: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1405: my $lastdir = $parent;
1406: my %depths = (
1407: $lastdir => 0,
1408: );
1409: my (%display,%deps);
1410: for (my $i=0; $i<@pastemaps; $i++) {
1411: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1412: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1413: my @subfolders = split(/,/,$subfolderstr);
1414: $deps{$lastdir} = \@subfolders;
1415: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1416: my $depth = $depths{$lastdir} + 1;
1417: my $offset = int($depth * 4);
1418: my $indent = (' ' x $offset);
1419: for (my $j=0; $j<@subfolders; $j++) {
1420: $depths{$subfolders[$j]} = $depth;
1421: $display{$subfolders[$j]} =
1422: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1423: '<td><label>'.
1424: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1425: '<label>'.
1426: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1427: &mt('Move old').'</label>'.
1428: '</td></tr>';
1429: }
1.492 raeburn 1430: }
1.538 raeburn 1431: &recurse_print(\$output,$parent,\%deps,\%display);
1432: $output .= '</table></fieldset>';
1.329 droeschl 1433: }
1.538 raeburn 1434: $output .= '</div>';
1435: return $output;
1.488 raeburn 1436: }
1437:
1.492 raeburn 1438: sub recurse_print {
1.538 raeburn 1439: my ($outputref,$dir,$deps,$display) = @_;
1440: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1441: if (ref($deps->{$dir}) eq 'ARRAY') {
1442: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1443: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1444: }
1445: }
1446: }
1447:
1.488 raeburn 1448: sub supp_pasteable {
1449: my ($url) = @_;
1450: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1451: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1452: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1453: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1454: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1455: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) {
1.488 raeburn 1456: return 1;
1457: }
1458: return;
1.329 droeschl 1459: }
1460:
1.492 raeburn 1461: sub paste_popup_js {
1.594 damieng 1462: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1463: show => 'Show Options',
1464: hide => 'Hide Options',
1.594 damieng 1465: );
1466: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1467: none => 'No items selected from clipboard.',
1.492 raeburn 1468: );
1.594 damieng 1469: &html_escape(\%html_js_lt);
1470: &js_escape(\%html_js_lt);
1471: &js_escape(\%js_lt);
1.492 raeburn 1472: return <<"END";
1473:
1.538 raeburn 1474: function showPasteOptions(suffix) {
1475: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1476: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1477: return;
1478: }
1479:
1.538 raeburn 1480: function hidePasteOptions(suffix) {
1481: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1482: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1483: return;
1484: }
1485:
1486: function showOptions(caller,suffix) {
1487: if (document.getElementById('pasteoptionstext_'+suffix)) {
1488: if (caller.checked) {
1.594 damieng 1489: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1490: } else {
1491: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1492: }
1493: if (document.getElementById('pasteoptions_'+suffix)) {
1494: document.getElementById('pasteoptions_'+suffix).style.display='none';
1495: }
1496: }
1.492 raeburn 1497: return;
1498: }
1499:
1.541 raeburn 1500: function validateClipboard() {
1501: var numchk = 0;
1502: if (document.pasteform.pasting.length > 1) {
1503: for (var i=0; i<document.pasteform.pasting.length; i++) {
1504: if (document.pasteform.pasting[i].checked) {
1505: numchk ++;
1506: }
1507: }
1508: } else {
1509: if (document.pasteform.pasting.type == 'checkbox') {
1510: if (document.pasteform.pasting.checked) {
1511: numchk ++;
1512: }
1513: }
1514: }
1515: if (numchk > 0) {
1516: return true;
1517: } else {
1.594 damieng 1518: alert("$js_lt{'none'}");
1.541 raeburn 1519: return false;
1520: }
1521: }
1522:
1.575 raeburn 1523: function checkClipboard() {
1524: if (document.pasteform.pasting.length > 1) {
1525: for (var i=0; i<document.pasteform.pasting.length; i++) {
1526: document.pasteform.pasting[i].checked = true;
1527: }
1528: }
1529: return;
1530: }
1531:
1532: function uncheckClipboard() {
1533: if (document.pasteform.pasting.length >1) {
1534: for (var i=0; i<document.pasteform.pasting.length; i++) {
1535: document.pasteform.pasting[i].checked = false;
1536: }
1537: }
1538: return;
1539: }
1540:
1.492 raeburn 1541: END
1542:
1543: }
1544:
1.329 droeschl 1545: sub do_paste_from_buffer {
1.492 raeburn 1546: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1547:
1.538 raeburn 1548: # Array of items in paste buffer
1549: my (@currpaste,%pastebuffer,%allerrors);
1550: @currpaste = split(/,/,$env{'docs.markedcopies'});
1551:
1.492 raeburn 1552: # Early out if paste buffer is empty
1.538 raeburn 1553: if (@currpaste == 0) {
1.492 raeburn 1554: return ();
1.538 raeburn 1555: }
1556: map { $pastebuffer{$_} = 1; } @currpaste;
1557:
1558: # Array of items selected items to paste
1559: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1560:
1561: # Early out if nothing selected to paste
1562: if (@reqpaste == 0) {
1563: return();
1564: }
1565: my @topaste;
1566: foreach my $suffix (@reqpaste) {
1567: next if ($suffix =~ /\D/);
1568: next unless (exists($pastebuffer{$suffix}));
1569: push(@topaste,$suffix);
1570: }
1571:
1572: # Early out if nothing available to paste
1573: if (@topaste == 0) {
1574: return();
1.329 droeschl 1575: }
1576:
1.538 raeburn 1577: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.597 raeburn 1578: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1579:
1580: foreach my $suffix (@topaste) {
1581: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1582: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1583: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1584: # Supplemental content may only include certain types of content
1585: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1586: if ($folder =~ /^supplemental/) {
1587: unless (&supp_pasteable($url)) {
1588: $notinsupp{$suffix} = 1;
1589: next;
1590: }
1.492 raeburn 1591: }
1.538 raeburn 1592: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1593: my $srcd = $1;
1594: my $srcn = $2;
1.492 raeburn 1595: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1596: # check for mdc privilege in the course from which the resource was pasted
1597: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1598: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1599: $notincrs{$suffix} = 1;
1600: next;
1601: }
1.491 raeburn 1602: }
1.538 raeburn 1603: $srcdom{$suffix} = $srcd;
1604: $srcnum{$suffix} = $srcn;
1.597 raeburn 1605: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1606: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.596 raeburn 1607: my ($srcd,$srcn) = split(/_/,$cid);
1608: # When paste buffer was populated using an active role in a different course
1609: # check for mdc privilege in the course from which the resource was pasted
1610: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1611: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1612: $notincrs{$suffix} = 1;
1613: next;
1614: }
1615: }
1616: $srcdom{$suffix} = $srcd;
1617: $srcnum{$suffix} = $srcn;
1.491 raeburn 1618: }
1.597 raeburn 1619: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1620: push(@dopaste,$suffix);
1621: if ($url=~/\.(page|sequence)$/) {
1622: $is_map{$suffix} = 1;
1623: }
1624:
1625: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1626: my $oldprefix = $1;
1.492 raeburn 1627: # When pasting content from Main Content to Supplemental Content and vice versa
1628: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1629: # a folder/page or a document).
1.538 raeburn 1630: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1631: $prefixchg{$suffix} = 'docstosupp';
1632: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1633: $prefixchg{$suffix} = 'supptodocs';
1634: }
1.491 raeburn 1635:
1.492 raeburn 1636: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1637: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1638: my @nested;
1639: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1640: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1641: my @deps = map { /\d+:([\d,]+$)/ } @items;
1642: foreach my $dep (@deps) {
1643: if ($dep =~ /,/) {
1644: push(@nested,split(/,/,$dep));
1645: } else {
1646: push(@nested,$dep);
1647: }
1.492 raeburn 1648: }
1.538 raeburn 1649: foreach my $item (@nested) {
1650: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1651: push(@{$marktomove{$suffix}},$type.'_'.$item);
1652: }
1.492 raeburn 1653: }
1654: }
1.488 raeburn 1655: }
1656: }
1657:
1.538 raeburn 1658: # Early out if nothing available to paste
1659: if (@dopaste == 0) {
1660: return ();
1661: }
1662:
1663: # Populate message hash and hashes used for main content <=> supplemental content
1664: # changes
1665:
1666: %msgs = &Apache::lonlocal::texthash (
1667: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1668: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1669: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1670: );
1671:
1672: %before = (
1673: docstosupp => {
1674: map => 'default',
1675: doc => 'docs',
1676: },
1677: supptodocs => {
1678: map => 'supplemental',
1679: doc => 'supplemental',
1680: },
1681: );
1682:
1683: %after = (
1684: docstosupp => {
1685: map => 'supplemental',
1686: doc => 'supplemental'
1687: },
1688: supptodocs => {
1689: map => 'default',
1690: doc => 'docs',
1691: },
1692: );
1693:
1694: # Retrieve information about all course maps in main content area
1695:
1696: my $allmaps = {};
1697: if ($folder =~ /^default/) {
1698: $allmaps =
1699: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1700: $env{"course.$env{'request.course.id'}.home"},
1701: $env{'request.course.id'});
1702: }
1703:
1704: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1705:
1706: # Loop over the items to paste
1707: foreach my $suffix (@dopaste) {
1.329 droeschl 1708: # Maps need to be copied first
1.538 raeburn 1709: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1710: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1711: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1712: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1713: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1714: }
1715: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1716: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1717: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1718: my $oldurl = $url;
1719: if ($is_map{$suffix}) {
1.491 raeburn 1720: # If pasting a map, check if map contains other maps
1.538 raeburn 1721: my (%hierarchy,%titles);
1722: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1723: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1724: if ($url=~ m{^/uploaded/}) {
1725: my $newurl;
1726: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1727: ($newurl,my $error) =
1728: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1729: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1730: \$title,$allmaps,\%newurls);
1731: if ($error) {
1732: $allerrors{$suffix} = $error;
1733: next;
1734: }
1735: if ($newurl ne '') {
1736: if ($newurl ne $url) {
1737: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1738: $newsubdir{$url} = $1;
1739: }
1740: $mapchanges{$url} = 1;
1.492 raeburn 1741: }
1.538 raeburn 1742: }
1743: }
1744: if (($srcdom{$suffix} ne $coursedom) ||
1745: ($srcnum{$suffix} ne $coursenum) ||
1746: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1747: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1748: $coursedom,$coursenum,$srcdom{$suffix},
1749: $srcnum{$suffix},$allmaps,\%rewrites,
1750: \%retitles,\%copies,\%dbcopies,
1751: \%zombies,\%params,\%mapmoves,
1752: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1753: \%newurls,\%resdatacopy)) {
1.538 raeburn 1754: $mapmoves{$url} = 1;
1755: }
1756: $url = $newurl;
1757: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1758: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1759: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1760: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1761: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1762: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1763: }
1764: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1765: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1766: push(@toclear,$suffix);
1767: # if pasting published map (main content area only) check map not already in course
1768: if ($folder =~ /^default/) {
1769: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1770: $duplicate{$suffix} = 1;
1771: next;
1.492 raeburn 1772: }
1.491 raeburn 1773: }
1774: }
1.538 raeburn 1775: }
1776: if ($url=~ m{/(bulletinboard|smppg)$}) {
1777: my $prefix = $1;
1.596 raeburn 1778: my $fromothercrs;
1.538 raeburn 1779: #need to copy the db contents to a new one, unless this is a move.
1780: my %info = (
1781: src => $url,
1782: cdom => $coursedom,
1783: cnum => $coursenum,
1.596 raeburn 1784: );
1785: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1786: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1787: $fromothercrs = 1;
1788: $info{'cdom'} = $srcdom{$suffix};
1789: $info{'cnum'} = $srcnum{$suffix};
1790: }
1791: }
1792: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.538 raeburn 1793: my (%lockerr,$msg);
1794: my ($newurl,$result,$errtext) =
1795: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1796: if ($result eq 'ok') {
1797: $url = $newurl;
1798: $title=&mt('Copy of').' '.$title;
1799: } else {
1800: if ($prefix eq 'smppg') {
1801: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1802: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1803: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.538 raeburn 1804: }
1805: $results{$suffix} = $result;
1806: $msgerrs{$suffix} = $msg;
1807: $lockerrs{$suffix} = $lockerr{$prefix};
1808: next;
1809: }
1810: if ($lockerr{$prefix}) {
1811: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1812: }
1.489 raeburn 1813: }
1814: }
1.538 raeburn 1815: $title = &LONCAPA::map::qtunescape($title);
1816: my $ext='false';
1817: if ($url=~m{^http(|s)://}) { $ext='true'; }
1818: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1819: if ($folder !~ /^supplemental/) {
1820: (undef,undef,$title) =
1821: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1822: }
1823: } else {
1824: if ($folder=~/^supplemental/) {
1825: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1826: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1827: }
1.533 raeburn 1828: }
1.491 raeburn 1829:
1830: # For uploaded files (excluding pages/sequences) path in copied file is changed
1831: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1832: # courses.
1833:
1.538 raeburn 1834: unless ($is_map{$suffix}) {
1835: my $newidx;
1.492 raeburn 1836: # Now insert the URL at the bottom
1.538 raeburn 1837: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1838: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1839: my $relpath = $1;
1840: if ($relpath ne '') {
1841: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1842: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1843: my $newprefix = $newloc;
1844: if ($newloc eq 'default') {
1845: $newprefix = 'docs';
1846: }
1847: if ($newdocsdir eq '') {
1848: $newdocsdir = 'default';
1849: }
1850: if (($prefixchg{$suffix}) ||
1851: ($srcdom{$suffix} ne $coursedom) ||
1852: ($srcnum{$suffix} ne $coursenum) ||
1853: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1854: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1855: $url =
1856: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1857: &Apache::lonnet::getfile($oldurl));
1858: if ($url eq '/adm/notfound.html') {
1859: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1860: next;
1861: } else {
1862: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1863: $newsubpath =~ s{/+$}{/};
1864: $docmoves{$oldurl} = $newsubpath;
1865: }
1.491 raeburn 1866: }
1867: }
1.597 raeburn 1868: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1869: my $template = $1;
1870: if ($newidx) {
1871: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1872: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1873: }
1.491 raeburn 1874: }
1.538 raeburn 1875: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1876: ':'.$ext.':normal:res';
1877: push(@LONCAPA::map::order,$newidx);
1878: # Store the result
1879: my ($errtext,$fatal) =
1880: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1881: if ($fatal) {
1882: $save_err .= $errtext;
1883: $allresult = 'fail';
1884: }
1.488 raeburn 1885: }
1.538 raeburn 1886:
1.597 raeburn 1887: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1888: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1889: unless ($allresult eq 'fail') {
1890: my %updated = (
1891: rewrites => \%rewrites,
1892: zombies => \%zombies,
1893: removefrommap => \%removefrommap,
1894: removeparam => \%removeparam,
1895: dbcopies => \%dbcopies,
1.597 raeburn 1896: resdatacopy => \%resdatacopy,
1.538 raeburn 1897: retitles => \%retitles,
1898: );
1899: my %info = (
1900: newsubdir => \%newsubdir,
1901: params => \%params,
1902: );
1903: if ($prefixchg{$suffix}) {
1904: $info{'before'} = $before{$prefixchg{$suffix}};
1905: $info{'after'} = $after{$prefixchg{$suffix}};
1906: }
1907: my %moves = (
1908: copies => \%copies,
1909: docmoves => \%docmoves,
1910: mapmoves => \%mapmoves,
1911: );
1912: (my $result,$msgs{$suffix},my $lockerror) =
1913: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1914: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1915: $url,'paste');
1916: $lockerrors .= $lockerror;
1917: if ($result eq 'ok') {
1918: if ($is_map{$suffix}) {
1919: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1920: $folder.'.'.$container);
1921: if ($fatal) {
1922: $allresult = 'failread';
1923: } else {
1924: if ($#LONCAPA::map::order<1) {
1925: my $idx=&LONCAPA::map::getresidx();
1926: if ($idx<=0) { $idx=1; }
1927: $LONCAPA::map::order[0]=$idx;
1928: $LONCAPA::map::resources[$idx]='';
1929: }
1930: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1931: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1932: ':'.$ext.':normal:res';
1933: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 1934:
1935: # Store the result
1.538 raeburn 1936: my ($errtext,$fatal) =
1937: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1938: if ($fatal) {
1939: $save_err .= $errtext;
1940: $allresult = 'failstore';
1941: }
1942: }
1943: }
1944: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1945: push(@toclear,$suffix);
1946: }
1947: }
1.492 raeburn 1948: }
1949: }
1.538 raeburn 1950: &clear_from_buffer(\@toclear,\@currpaste);
1951: my $msgsarray;
1952: foreach my $suffix (keys(%msgs)) {
1953: if (ref($msgs{$suffix}) eq 'ARRAY') {
1954: $msgsarray .= join(',',@{$msgs{$suffix}});
1955: }
1956: }
1957: return ($allresult,$save_err,$msgsarray,$lockerrors);
1958: }
1.533 raeburn 1959:
1.538 raeburn 1960: sub do_buffer_empty {
1961: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1962: if (@currpaste == 0) {
1963: return &mt('Clipboard is already empty');
1964: }
1965: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1966: if (@toclear == 0) {
1967: return &mt('Nothing selected to clear from clipboard');
1968: }
1969: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1970: if ($numdel) {
1971: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1972: } else {
1973: return &mt('Clipboard unchanged');
1.492 raeburn 1974: }
1.538 raeburn 1975: return;
1976: }
1977:
1978: sub clear_from_buffer {
1979: my ($toclear,$currpaste) = @_;
1980: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1981: my %pastebuffer;
1982: map { $pastebuffer{$_} = 1; } @{$currpaste};
1983: my $numdel = 0;
1984: foreach my $suffix (@{$toclear}) {
1985: next if ($suffix =~ /\D/);
1986: next unless (exists($pastebuffer{$suffix}));
1987: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1988: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1989: delete($pastebuffer{$suffix});
1990: $numdel ++;
1991: }
1992: }
1993: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1994: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1995: return $numdel;
1.492 raeburn 1996: }
1997:
1998: sub get_newmap_url {
1999: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2000: $titleref,$allmaps,$newurls) = @_;
2001: my $newurl;
2002: if ($url=~ m{^/uploaded/}) {
2003: $$titleref=&mt('Copy of').' '.$$titleref;
2004: }
2005: my $now = time;
2006: my $suffix=$$.int(rand(100)).$now;
2007: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2008: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2009: my $path = $1;
2010: my $prefix = $2;
2011: my $ancestor = $3;
2012: if (length($ancestor) > 10) {
2013: $ancestor = substr($ancestor,-10,10);
2014: }
2015: my $newid;
2016: if ($prefixchg) {
2017: if ($folder =~ /^supplemental/) {
2018: $prefix =~ s/^default/supplemental/;
2019: } else {
2020: $prefix =~ s/^supplemental/default/;
2021: }
2022: }
2023: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2024: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2025: } else {
2026: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2027: }
2028: my $counter = 0;
2029: my $is_unique = &uniqueness_check($newurl);
2030: if ($folder =~ /^default/) {
2031: if ($allmaps->{$newurl}) {
2032: $is_unique = 0;
2033: }
2034: }
2035: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2036: $counter ++;
2037: $suffix ++;
2038: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2039: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2040: } else {
2041: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2042: }
2043: $is_unique = &uniqueness_check($newurl);
2044: }
2045: if ($is_unique) {
2046: $newurls->{$newurl} = 1;
2047: } else {
2048: if ($url=~/\.page$/) {
2049: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2050: } else {
2051: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2052: }
2053: }
1.329 droeschl 2054: }
1.492 raeburn 2055: return ($newurl);
1.329 droeschl 2056: }
2057:
1.488 raeburn 2058: sub dbcopy {
1.533 raeburn 2059: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2060: my ($url,$result,$errtext);
2061: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2062: $url = $dbref->{'src'};
1.533 raeburn 2063: if ($url =~ m{/(smppg|bulletinboard)$}) {
2064: my $prefix = $1;
2065: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2066: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2067: my $db_name;
2068: my $marker = (split(m{/},$url))[4];
2069: $marker=~s/\D//g;
2070: if ($dbref->{'src'} =~ m{/smppg$}) {
2071: $db_name =
2072: &Apache::lonsimplepage::get_db_name($url,$marker,
2073: $dbref->{'cdom'},
2074: $dbref->{'cnum'});
2075: } else {
2076: $db_name = 'bulletinpage_'.$marker;
2077: }
2078: my ($suffix,$freedlock,$error) =
2079: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2080: $coursedom,$coursenum,
2081: 'concat');
2082: if (!$suffix) {
2083: if ($prefix eq 'smppg') {
2084: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2085: } else {
1.565 bisitz 2086: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2087: }
2088: if ($error) {
2089: $errtext .= '<br />'.$error;
2090: }
2091: } else {
2092: #need to copy the db contents to a new one.
2093: my %contents=&Apache::lonnet::dump($db_name,
2094: $dbref->{'cdom'},
2095: $dbref->{'cnum'});
2096: if (exists($contents{'uploaded.photourl'})) {
2097: my $photo = $contents{'uploaded.photourl'};
2098: my ($subdir,$fname) =
2099: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2100: my $newphoto;
1.533 raeburn 2101: if ($fname ne '') {
2102: my $content = &Apache::lonnet::getfile($photo);
2103: unless ($content eq '-1') {
2104: $env{'form.'.$suffix.'.photourl'} = $content;
2105: $newphoto =
2106: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2107: delete($env{'form.'.$suffix.'.photourl'});
2108: }
2109: }
2110: if ($newphoto =~ m{^/uploaded/}) {
2111: $contents{'uploaded.photourl'} = $newphoto;
2112: }
2113: }
2114: $db_name =~ s{_\d*$ }{_$suffix}x;
2115: $result=&Apache::lonnet::put($db_name,\%contents,
2116: $coursedom,$coursenum);
2117: if ($result eq 'ok') {
2118: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2119: }
2120: }
2121: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2122: $lockerrorsref->{$prefix} =
1.533 raeburn 2123: '<div class="LC_error">'.
2124: &mt('There was a problem removing a lockfile.');
2125: if ($prefix eq 'smppg') {
1.560 raeburn 2126: $lockerrorsref->{$prefix} .=
1.559 raeburn 2127: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.533 raeburn 2128: } else {
1.565 bisitz 2129: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2130: }
1.560 raeburn 2131: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2132: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2133: '</div>';
1.533 raeburn 2134: }
2135: }
2136: } elsif ($url =~ m{/syllabus$}) {
2137: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2138: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2139: if (($dbref->{'cdom'} ne $coursedom) ||
2140: ($dbref->{'cnum'} ne $coursenum)) {
2141: my %contents=&Apache::lonnet::dump('syllabus',
2142: $dbref->{'cdom'},
2143: $dbref->{'cnum'});
2144: $result=&Apache::lonnet::put('syllabus',\%contents,
2145: $coursedom,$coursenum);
2146: }
2147: }
1.488 raeburn 2148: }
2149: }
1.533 raeburn 2150: return ($url,$result,$errtext);
1.488 raeburn 2151: }
2152:
1.597 raeburn 2153: sub copy_templated_files {
2154: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2155: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2156: my $srccontainer = 'sequence';
2157: if ($srcwaspage) {
2158: $srccontainer = 'page';
2159: }
2160: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2161: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2162: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2163: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2164: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2165: $template.'.problem';
2166: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2167: if ($template eq 'simpleproblem') {
2168: $srcprefix .= '.0.';
2169: my $weightprefix = $newprefix;
2170: $newprefix .= '.0.';
2171: my @simpleprobqtypes = qw(radio option string essay numerical);
2172: my $qtype=$srcparms{$srcprefix.'questiontype'};
2173: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2174: my %newdata;
2175: foreach my $type (@simpleprobqtypes) {
2176: if ($type eq $qtype) {
2177: $newdata{"$weightprefix.$type.weight"}=1;
2178: } else {
2179: $newdata{"$weightprefix.$type.weight"}=0;
2180: }
2181: }
2182: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2183: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2184: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2185: if ($qtype eq 'numerical') {
2186: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2187: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2188: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2189: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2190: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2191: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2192: unless (defined($maxfoils)) { $maxfoils=10; }
2193: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2194: if ($maxfoils<=0) { $maxfoils=10; }
2195: my $randomize=$srcparms{$srcprefix.'randomize'};
2196: unless (defined($randomize)) { $randomize='yes'; }
2197: unless ($randomize eq 'no') { $randomize='yes'; }
2198: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2199: $newdata{$newprefix.'randomize'} = $randomize;
2200: if ($qtype eq 'option') {
2201: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2202: }
2203: for (my $i=1; $i<=10; $i++) {
2204: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2205: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2206: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2207: }
2208:
2209: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2210: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2211: unless (defined($maxfoils)) { $maxfoils=10; }
2212: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2213: if ($maxfoils<=0) { $maxfoils=10; }
2214: my $randomize=$srcparms{$srcprefix.'randomize'};
2215: unless (defined($randomize)) { $randomize='yes'; }
2216: unless ($randomize eq 'no') { $randomize='yes'; }
2217: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2218: $newdata{$newprefix.'randomize'} = $randomize;
2219: if ($qtype eq 'option') {
2220: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2221: }
2222: for (my $i=1; $i<=10; $i++) {
2223: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2224: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2225: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2226: }
2227: } elsif ($qtype eq 'string') {
2228: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2229: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2230: }
2231: if (keys(%newdata)) {
2232: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2233: $coursenum);
2234: if ($putres eq 'ok') {
2235: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2236: }
2237: }
2238: }
2239: }
2240: }
2241:
1.329 droeschl 2242: sub uniqueness_check {
2243: my ($newurl) = @_;
2244: my $unique = 1;
2245: foreach my $res (@LONCAPA::map::order) {
2246: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2247: $url=&LONCAPA::map::qtescape($url);
2248: if ($newurl eq $url) {
2249: $unique = 0;
1.344 bisitz 2250: last;
1.329 droeschl 2251: }
2252: }
2253: return $unique;
2254: }
2255:
1.488 raeburn 2256: sub contained_map_check {
1.492 raeburn 2257: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2258: $allmaps) = @_;
1.488 raeburn 2259: my $content = &Apache::lonnet::getfile($url);
2260: unless ($content eq '-1') {
2261: my $parser = HTML::TokeParser->new(\$content);
2262: $parser->attr_encoded(1);
2263: while (my $token = $parser->get_token) {
2264: next if ($token->[0] ne 'S');
2265: if ($token->[1] eq 'resource') {
2266: next if ($token->[2]->{'type'} eq 'zombie');
2267: my $ressrc = $token->[2]->{'src'};
2268: if ($folder =~ /^supplemental/) {
2269: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2270: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2271: next;
2272: }
2273: }
1.492 raeburn 2274: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2275: if ($1 eq 'uploaded') {
2276: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2277: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2278: } else {
1.492 raeburn 2279: if ($allmaps->{$ressrc}) {
1.529 raeburn 2280: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2281: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2282: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2283: } else {
2284: $addedmaps->{$ressrc} = [$url];
2285: }
1.488 raeburn 2286: }
1.492 raeburn 2287: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2288: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2289: }
1.492 raeburn 2290: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2291: if ($folder =~ /^supplemental/) {
1.492 raeburn 2292: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2293: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2294: } else {
2295: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2296: }
1.488 raeburn 2297: }
2298: }
2299: }
2300: }
2301: return;
2302: }
2303:
2304: sub url_paste_fixups {
1.533 raeburn 2305: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2306: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2307: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2308: my $checktitle;
2309: if (($prefixchg) &&
1.492 raeburn 2310: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2311: $checktitle = 1;
2312: }
1.492 raeburn 2313: my $skip;
2314: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2315: my $mapid = $1.$2;
2316: if ($tomove->{$mapid}) {
2317: $skip = 1;
2318: }
2319: }
1.491 raeburn 2320: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2321: return if ($file eq '-1');
2322: my $parser = HTML::TokeParser->new(\$file);
2323: $parser->attr_encoded(1);
1.491 raeburn 2324: my $changed = 0;
1.488 raeburn 2325: while (my $token = $parser->get_token) {
2326: next if ($token->[0] ne 'S');
2327: if ($token->[1] eq 'resource') {
2328: my $ressrc = $token->[2]->{'src'};
2329: next if ($ressrc eq '');
1.491 raeburn 2330: my $id = $token->[2]->{'id'};
1.492 raeburn 2331: my $title = $token->[2]->{'title'};
1.491 raeburn 2332: if ($checktitle) {
2333: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2334: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2335: }
2336: }
1.488 raeburn 2337: next if ($token->[2]->{'type'} eq 'external');
2338: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2339: next if ($skip);
1.532 raeburn 2340: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2341: $changed = 1;
2342: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2343: my $srcdom = $1;
2344: my $srcnum = $2;
1.488 raeburn 2345: my $rem = $3;
1.492 raeburn 2346: my $newurl;
2347: my $mapname;
2348: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2349: my $prefix = $1;
2350: $mapname = $prefix.$2;
2351: if ($tomove->{$mapname}) {
1.533 raeburn 2352: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2353: $srcdom,$srcnum,$allmaps,$rewrites,
2354: $retitles,$copies,$dbcopies,$zombies,
2355: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2356: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2357: next;
2358: } else {
2359: ($newurl,my $error) =
2360: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2361: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2362: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2363: $newsubdir->{$ressrc} = $1;
2364: }
2365: if ($error) {
2366: next;
2367: }
2368: }
2369: }
2370: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2371: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2372:
1.488 raeburn 2373: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2374: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2375: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2376: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2377: $cnum,$srcdom,$srcnum,$allmaps,
2378: $rewrites,$retitles,$copies,$dbcopies,
2379: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2380: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2381: $mapmoves->{$ressrc} = 1;
2382: }
2383: $changed = 1;
1.488 raeburn 2384: } else {
1.532 raeburn 2385: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2386: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2387: $changed = 1;
1.488 raeburn 2388: }
2389: }
1.533 raeburn 2390: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2391: next if ($skip);
1.492 raeburn 2392: my $srcdom = $1;
2393: my $srcnum = $2;
2394: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2395: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2396: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2397: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2398: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2399: $changed = 1;
2400: }
2401: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2402: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2403: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2404: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2405: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2406: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2407: $changed = 1;
1.488 raeburn 2408: }
1.597 raeburn 2409: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2410: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2411: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2412: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2413: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2414: }
1.488 raeburn 2415: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2416: next if ($skip);
2417: my $srcdom = $1;
2418: my $srcnum = $2;
2419: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2420: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2421: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2422: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2423: $changed = 1;
1.488 raeburn 2424: }
2425: }
2426: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2427: next if ($skip);
1.488 raeburn 2428: my $to = $token->[2]->{'to'};
2429: if ($to ne '') {
2430: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2431: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2432: } else {
2433: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2434: }
2435: }
2436: }
2437: }
1.491 raeburn 2438: return $changed;
1.488 raeburn 2439: }
2440:
2441: sub apply_fixups {
1.529 raeburn 2442: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2443: $oldurl,$url,$caller) = @_;
2444: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2445: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2446: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2447: if (ref($updated) eq 'HASH') {
2448: if (ref($updated->{'rewrites'}) eq 'HASH') {
2449: %rewrites = %{$updated->{'rewrites'}};
2450: }
2451: if (ref($updated->{'zombies'}) eq 'HASH') {
2452: %zombies = %{$updated->{'zombies'}};
2453: }
2454: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2455: %removefrommap = %{$updated->{'removefrommap'}};
2456: }
2457: if (ref($updated->{'removeparam'}) eq 'HASH') {
2458: %removeparam = %{$updated->{'removeparam'}};
2459: }
2460: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2461: %dbcopies = %{$updated->{'dbcopies'}};
2462: }
2463: if (ref($updated->{'retitles'}) eq 'HASH') {
2464: %retitles = %{$updated->{'retitles'}};
2465: }
1.597 raeburn 2466: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2467: %resdatacopy = %{$updated->{'resdatacopy'}};
2468: }
1.529 raeburn 2469: }
2470: if (ref($info) eq 'HASH') {
2471: if (ref($info->{'newsubdir'}) eq 'HASH') {
2472: %newsubdir = %{$info->{'newsubdir'}};
2473: }
2474: if (ref($info->{'params'}) eq 'HASH') {
2475: %params = %{$info->{'params'}};
2476: }
2477: if (ref($info->{'before'}) eq 'HASH') {
2478: %before = %{$info->{'before'}};
2479: }
2480: if (ref($info->{'after'}) eq 'HASH') {
2481: %after = %{$info->{'after'}};
2482: }
2483: }
2484: if (ref($moves) eq 'HASH') {
2485: if (ref($moves->{'copies'}) eq 'HASH') {
2486: %copies = %{$moves->{'copies'}};
2487: }
2488: if (ref($moves->{'docmoves'}) eq 'HASH') {
2489: %docmoves = %{$moves->{'docmoves'}};
2490: }
2491: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2492: %mapmoves = %{$moves->{'mapmoves'}};
2493: }
2494: }
2495: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2496: my @allcopies;
1.529 raeburn 2497: if (exists($copies{$key})) {
2498: if (ref($copies{$key}) eq 'HASH') {
2499: my %added;
2500: foreach my $innerkey (keys(%{$copies{$key}})) {
2501: if (($innerkey ne '') && (!$added{$innerkey})) {
2502: push(@allcopies,$innerkey);
2503: $added{$innerkey} = 1;
2504: }
1.491 raeburn 2505: }
1.529 raeburn 2506: undef(%added);
1.491 raeburn 2507: }
2508: }
2509: if ($key eq $oldurl) {
1.529 raeburn 2510: if ((exists($docmoves{$key}))) {
1.532 raeburn 2511: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2512: push(@allcopies,$oldurl);
2513: }
2514: }
2515: }
2516: if (@allcopies > 0) {
2517: foreach my $item (@allcopies) {
1.492 raeburn 2518: my ($relpath,$oldsubdir,$fname) =
2519: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2520: if ($fname ne '') {
2521: my $content = &Apache::lonnet::getfile($item);
2522: unless ($content eq '-1') {
2523: my $storefn;
1.529 raeburn 2524: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2525: $storefn = $docmoves{$key};
1.491 raeburn 2526: } else {
2527: $storefn = $relpath;
2528: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2529: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2530: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2531: }
1.529 raeburn 2532: if ($newsubdir{$key}) {
1.532 raeburn 2533: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2534: }
2535: }
2536: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2537: my $copyurl =
2538: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2539: $storefn.$fname,$content);
2540: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2541: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2542: return &mt('Paste failed: an error occurred copying the file.');
2543: } elsif (ref($errors) eq 'HASH') {
2544: $errors->{$item} = 1;
1.489 raeburn 2545: }
2546: }
1.488 raeburn 2547: }
2548: }
1.491 raeburn 2549: }
2550: }
2551: }
1.529 raeburn 2552: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2553: my $storefn=$key;
2554: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2555: if ($prefixchg && $before{'map'} && $after{'map'}) {
2556: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2557: }
1.529 raeburn 2558: if ($newsubdir{$key}) {
2559: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2560: }
1.491 raeburn 2561: my $mapcontent = &Apache::lonnet::getfile($key);
2562: if ($mapcontent eq '-1') {
2563: if (ref($errors) eq 'HASH') {
2564: $errors->{$key} = 1;
2565: }
2566: } else {
2567: my $newmap =
2568: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2569: $mapcontent);
2570: if ($newmap eq '/adm/notfound.html') {
2571: if (ref($errors) eq 'HASH') {
2572: $errors->{$key} = 1;
1.489 raeburn 2573: }
1.488 raeburn 2574: }
2575: }
2576: }
1.491 raeburn 2577: my %updates;
2578: if ($is_map) {
1.529 raeburn 2579: if (ref($updated) eq 'HASH') {
2580: foreach my $type (keys(%{$updated})) {
2581: if (ref($updated->{$type}) eq 'HASH') {
2582: foreach my $key (keys(%{$updated->{$type}})) {
2583: $updates{$key} = 1;
2584: }
2585: }
2586: }
1.491 raeburn 2587: }
2588: foreach my $key (keys(%updates)) {
1.492 raeburn 2589: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2590: if (ref($rewrites{$key}) eq 'HASH') {
2591: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2592: }
1.529 raeburn 2593: if (ref($retitles{$key}) eq 'HASH') {
2594: %toretitle = %{$retitles{$key}};
1.491 raeburn 2595: }
1.529 raeburn 2596: if (ref($removefrommap{$key}) eq 'HASH') {
2597: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2598: }
1.529 raeburn 2599: if (ref($removeparam{$key}) eq 'HASH') {
2600: %remparam = %{$removeparam{$key}};
1.492 raeburn 2601: }
1.529 raeburn 2602: if (ref($zombies{$key}) eq 'HASH') {
2603: %zombie = %{$zombies{$key}};
1.491 raeburn 2604: }
1.529 raeburn 2605: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2606: foreach my $idx (keys(%{$dbcopies{$key}})) {
2607: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2608: my ($newurl,$result,$errtext) =
2609: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2610: if ($result eq 'ok') {
2611: $newdb{$idx} = $newurl;
2612: } elsif (ref($errors) eq 'HASH') {
2613: $errors->{$key} = 1;
2614: }
2615: push(@msgs,$errtext);
2616: }
1.491 raeburn 2617: }
2618: }
1.597 raeburn 2619: if (ref($resdatacopy{$key}) eq 'HASH') {
2620: if ($newsubdir{$key}) {
2621:
2622: }
2623: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2624: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2625: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2626: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2627: my $template = $1;
2628: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2629: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2630: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2631: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2632: my ($newmapname) = ($key =~ m{/([^/]+)$});
2633: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2634: my $srcmapinfo = $srcfolder.':'.$idx;
2635: if ($srccontainer eq 'page') {
2636: $srcmapinfo .= ':1';
2637: }
2638: if ($newsubdir{$key}) {
2639: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2640: }
2641: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2642: $cnum,$template,$idx,$newmapname);
2643: }
2644: }
2645: }
2646: }
2647: }
1.529 raeburn 2648: if (ref($params{$key}) eq 'HASH') {
2649: %currparam = %{$params{$key}};
1.492 raeburn 2650: }
2651: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2652: if ($fatal) {
1.533 raeburn 2653: return ($errtext);
1.492 raeburn 2654: }
2655: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2656: if (defined($LONCAPA::map::zombies[$i])) {
2657: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2658: if ($zombie{$i} eq $src) {
1.492 raeburn 2659: undef($LONCAPA::map::zombies[$i]);
2660: }
2661: }
2662: }
1.529 raeburn 2663: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2664: my $idx = $LONCAPA::map::order[$i];
2665: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2666: my $changed;
1.529 raeburn 2667: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2668: if ((exists($toremove{$idx})) &&
2669: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2670: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2671: if (ref($currparam{$idx}) eq 'ARRAY') {
2672: foreach my $name (@{$currparam{$idx}}) {
2673: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2674: }
2675: }
2676: next;
2677: }
2678: my $origsrc = $src;
1.532 raeburn 2679: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2680: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2681: $changed = 1;
1.491 raeburn 2682: }
1.492 raeburn 2683: }
1.532 raeburn 2684: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2685: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2686: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2687: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2688: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2689: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2690: } else {
1.529 raeburn 2691: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2692: }
1.491 raeburn 2693: }
1.532 raeburn 2694: if ($origsrc =~ /\.(page|sequence)$/) {
2695: if ($newsubdir{$origsrc}) {
1.529 raeburn 2696: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2697: }
1.532 raeburn 2698: } elsif ($newsubdir{$key}) {
2699: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2700: }
2701: }
1.492 raeburn 2702: $changed = 1;
1.533 raeburn 2703: } elsif ($newdb{$idx} ne '') {
2704: $src = $newdb{$idx};
1.492 raeburn 2705: $changed = 1;
2706: }
2707: if ($changed) {
1.538 raeburn 2708: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2709: }
2710: }
2711: }
2712: foreach my $idx (keys(%remparam)) {
2713: if (ref($remparam{$idx}) eq 'ARRAY') {
2714: foreach my $name (@{$remparam{$idx}}) {
2715: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2716: }
2717: }
2718: }
1.533 raeburn 2719: if (values(%lockerrors) > 0) {
2720: $lockmsg = join('<br />',values(%lockerrors));
2721: }
1.491 raeburn 2722: my $storefn;
2723: if ($key eq $oldurl) {
2724: $storefn = $url;
2725: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2726: } else {
2727: $storefn = $key;
2728: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2729: if ($prefixchg && $before{'map'} && $after{'map'}) {
2730: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2731: }
1.529 raeburn 2732: if ($newsubdir{$key}) {
2733: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2734: }
1.491 raeburn 2735: }
1.492 raeburn 2736: my $report;
2737: if ($folder !~ /^supplemental/) {
2738: $report = 1;
2739: }
1.527 raeburn 2740: (my $outtext,$errtext) =
1.492 raeburn 2741: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2742: if ($errtext) {
1.529 raeburn 2743: if ($caller eq 'paste') {
1.533 raeburn 2744: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2745: }
1.491 raeburn 2746: }
2747: }
2748: }
1.533 raeburn 2749: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2750: }
2751:
2752: sub copy_dependencies {
2753: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2754: my $content;
2755: if (ref($contentref)) {
2756: $content = $$contentref;
2757: } else {
2758: $content = &Apache::lonnet::getfile($item);
2759: }
2760: unless ($content eq '-1') {
2761: my $mm = new File::MMagic;
2762: my $mimetype = $mm->checktype_contents($content);
2763: if ($mimetype eq 'text/html') {
2764: my (%allfiles,%codebase,$state);
2765: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2766: if ($res eq 'ok') {
2767: my ($numexisting,$numpathchanges,$existing);
2768: (undef,$numexisting,$numpathchanges,$existing) =
2769: &Apache::loncommon::ask_for_embedded_content(
2770: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2771: {'error_on_invalid_names' => 1,
2772: 'ignore_remote_references' => 1,
2773: 'docs_url' => $item,
2774: 'context' => 'paste'});
2775: if ($numexisting > 0) {
2776: if (ref($existing) eq 'HASH') {
2777: foreach my $dep (keys(%{$existing})) {
2778: my $depfile = $dep;
2779: unless ($depfile =~ m{^\Q$relpath\E}) {
2780: $depfile = $relpath.$dep;
2781: }
2782: my $depcontent = &Apache::lonnet::getfile($depfile);
2783: unless ($depcontent eq '-1') {
2784: my $storedep = $dep;
2785: $storedep =~ s{^\Q$relpath\E}{};
2786: my $dep_url =
2787: &Apache::lonclonecourse::writefile(
2788: $env{'request.course.id'},
2789: $storefn.$storedep,$depcontent);
2790: if ($dep_url eq '/adm/notfound.html') {
2791: if (ref($errors) eq 'HASH') {
2792: $errors->{$depfile} = 1;
2793: }
2794: } else {
2795: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2796: }
2797: }
2798: }
1.488 raeburn 2799: }
2800: }
2801: }
2802: }
2803: }
2804: return;
2805: }
2806:
1.329 droeschl 2807: my %parameter_type = ( 'randompick' => 'int_pos',
2808: 'hiddenresource' => 'string_yesno',
2809: 'encrypturl' => 'string_yesno',
2810: 'randomorder' => 'string_yesno',);
2811: my $valid_parameters_re = join('|',keys(%parameter_type));
2812: # set parameters
2813: sub update_parameter {
1.537 raeburn 2814: if ($env{'form.changeparms'} eq 'all') {
2815: my (@allidx,@allmapidx,%allchecked,%currchecked);
2816: %allchecked = (
2817: 'hiddenresource' => {},
2818: 'encrypturl' => {},
2819: 'randompick' => {},
2820: 'randomorder' => {},
2821: );
2822: foreach my $which (keys(%allchecked)) {
2823: $env{'form.all'.$which} =~ s/,$//;
2824: if ($which eq 'randompick') {
2825: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2826: my ($res,$value) = split(/:/,$item);
2827: if ($value =~ /^\d+$/) {
2828: $allchecked{$which}{$res} = $value;
2829: }
2830: }
2831: } else {
1.539 raeburn 2832: if ($env{'form.all'.$which}) {
2833: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2834: }
1.537 raeburn 2835: }
2836: }
2837: my $haschanges = 0;
2838: foreach my $res (@LONCAPA::map::order) {
2839: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2840: $name=&LONCAPA::map::qtescape($name);
2841: $url=&LONCAPA::map::qtescape($url);
2842: next unless ($name && $url);
2843: my $is_map;
2844: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2845: $is_map = 1;
2846: }
2847: foreach my $which (keys(%allchecked)) {
2848: if (($which eq 'randompick' || $which eq 'randomorder')) {
2849: next if (!$is_map);
2850: }
2851: my $oldvalue = 0;
2852: my $newvalue = 0;
2853: if ($allchecked{$which}{$res}) {
2854: $newvalue = $allchecked{$which}{$res};
2855: }
2856: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2857: if ($which eq 'randompick') {
2858: if ($current =~ /^(\d+)$/) {
2859: $oldvalue = $1;
2860: }
2861: } else {
2862: if ($current =~ /^yes$/i) {
2863: $oldvalue = 1;
2864: }
2865: }
2866: if ($oldvalue ne $newvalue) {
2867: $haschanges = 1;
2868: if ($newvalue) {
2869: my $storeval = 'yes';
2870: if ($which eq 'randompick') {
2871: $storeval = $newvalue;
2872: }
2873: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2874: $storeval,
2875: $parameter_type{$which});
2876: &remember_parms($res,$which,'set',$storeval);
2877: } elsif ($oldvalue) {
2878: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2879: &remember_parms($res,$which,'del');
2880: }
2881: }
2882: }
2883: }
2884: return $haschanges;
2885: } else {
1.588 raeburn 2886: my $haschanges = 0;
2887: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2888:
1.537 raeburn 2889: my $which = $env{'form.changeparms'};
2890: my $idx = $env{'form.setparms'};
1.588 raeburn 2891: my $oldvalue = 0;
2892: my $newvalue = 0;
2893: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2894: if ($which eq 'randompick') {
2895: if ($current =~ /^(\d+)$/) {
2896: $oldvalue = $1;
2897: }
2898: } elsif ($current =~ /^yes$/i) {
2899: $oldvalue = 1;
2900: }
1.537 raeburn 2901: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 2902: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2903: : 1;
2904: }
2905: if ($oldvalue ne $newvalue) {
2906: $haschanges = 1;
2907: if ($newvalue) {
2908: my $storeval = 'yes';
2909: if ($which eq 'randompick') {
2910: $storeval = $newvalue;
2911: }
2912: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2913: $parameter_type{$which});
2914: &remember_parms($idx,$which,'set',$storeval);
2915: } else {
2916: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2917: &remember_parms($idx,$which,'del');
2918: }
1.537 raeburn 2919: }
1.588 raeburn 2920: return $haschanges;
1.329 droeschl 2921: }
2922: }
2923:
2924: sub handle_edit_cmd {
2925: my ($coursenum,$coursedom) =@_;
1.543 raeburn 2926: if ($env{'form.cmd'} eq '') {
2927: return 0;
2928: }
1.329 droeschl 2929: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2930:
2931: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2932: my ($title, $url, @rrest) = split(':', $ratstr);
2933:
1.538 raeburn 2934: if ($cmd eq 'remove') {
1.329 droeschl 2935: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2936: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2937: &Apache::lonnet::removeuploadedurl($url);
2938: } else {
2939: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2940: }
2941: splice(@LONCAPA::map::order, $idx, 1);
2942:
2943: } elsif ($cmd eq 'cut') {
2944: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2945: splice(@LONCAPA::map::order, $idx, 1);
2946:
1.344 bisitz 2947: } elsif ($cmd eq 'up'
1.329 droeschl 2948: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2949: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2950:
2951: } elsif ($cmd eq 'down'
2952: && defined($LONCAPA::map::order[$idx+1])) {
2953: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2954:
2955: } elsif ($cmd eq 'rename') {
2956: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2957: if ($comment=~/\S/) {
2958: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2959: $comment.':'.join(':', $url, @rrest);
2960: }
2961: # Devalidate title cache
2962: my $renamed_url=&LONCAPA::map::qtescape($url);
2963: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 2964:
1.329 droeschl 2965: } else {
2966: return 0;
2967: }
2968: return 1;
2969: }
2970:
2971: sub editor {
1.458 raeburn 2972: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.611 raeburn 2973: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,$canedit)=@_;
1.519 raeburn 2974: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 2975: if ($allowed) {
1.519 raeburn 2976: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2977: $is_random_order,$container) =
1.510 raeburn 2978: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2979: $r->print($breadcrumbtrail);
1.519 raeburn 2980: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2981: $container = 'page';
2982: } else {
2983: $container = 'sequence';
1.510 raeburn 2984: }
1.484 raeburn 2985:
1.525 raeburn 2986: my $jumpto;
2987:
2988: unless ($supplementalflag) {
1.546 raeburn 2989: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 2990: }
1.484 raeburn 2991:
2992: unless ($allowed) {
2993: $randompick = -1;
2994: }
2995:
1.329 droeschl 2996: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2997: $folder.'.'.$container);
2998: return $errtext if ($fatal);
2999:
3000: if ($#LONCAPA::map::order<1) {
3001: my $idx=&LONCAPA::map::getresidx();
3002: if ($idx<=0) { $idx=1; }
3003: $LONCAPA::map::order[0]=$idx;
3004: $LONCAPA::map::resources[$idx]='';
3005: }
1.364 bisitz 3006:
1.329 droeschl 3007: # ------------------------------------------------------------ Process commands
3008:
3009: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3010: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3011: # set parameters and change order
3012: &snapshotbefore();
3013:
3014: if (&update_parameter()) {
1.588 raeburn 3015: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3016: return $errtext if ($fatal);
3017: }
3018:
3019: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3020: # change order
3021: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3022: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3023:
3024: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3025: return $errtext if ($fatal);
3026: }
1.364 bisitz 3027:
1.329 droeschl 3028: if ($env{'form.pastemarked'}) {
1.491 raeburn 3029: my %paste_errors;
1.533 raeburn 3030: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3031: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3032: \%paste_errors);
1.541 raeburn 3033: if (ref($pastemsgarray) eq 'ARRAY') {
3034: if (@{$pastemsgarray} > 0) {
3035: $r->print('<p class="LC_info">'.
3036: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3037: '</p>');
3038: }
1.541 raeburn 3039: }
3040: if ($lockerror) {
3041: $r->print('<p class="LC_error">'.
3042: $lockerror.
3043: '</p>');
3044: }
3045: if ($save_error ne '') {
3046: return $save_error;
3047: }
3048: if ($paste_res) {
3049: my %errortext = &Apache::lonlocal::texthash (
3050: fail => 'Storage of folder contents failed',
3051: failread => 'Reading folder contents failed',
3052: failstore => 'Storage of folder contents failed',
3053: );
3054: if ($errortext{$paste_res}) {
3055: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3056: }
1.329 droeschl 3057: }
1.491 raeburn 3058: if (keys(%paste_errors) > 0) {
1.538 raeburn 3059: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3060: &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".
3061: '<ul>'."\n");
3062: foreach my $key (sort(keys(%paste_errors))) {
3063: $r->print('<li>'.$key.'</li>'."\n");
3064: }
3065: $r->print('</ul></p>'."\n");
3066: }
1.538 raeburn 3067: } elsif ($env{'form.clearmarked'}) {
3068: my $output = &do_buffer_empty();
3069: if ($output) {
3070: $r->print('<p class="LC_info">'.$output.'</p>');
3071: }
3072: }
1.329 droeschl 3073:
3074: $r->print($upload_output);
3075:
1.538 raeburn 3076: # Rename, cut, copy or remove a single resource
1.602 raeburn 3077: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3078: my $contentchg;
1.592 raeburn 3079: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.492 raeburn 3080: $contentchg = 1;
3081: }
3082: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3083: return $errtext if ($fatal);
3084: }
1.538 raeburn 3085:
3086: # Cut, copy and/or remove multiple resources
3087: if ($env{'form.multichange'}) {
3088: my %allchecked = (
3089: cut => {},
3090: remove => {},
3091: );
3092: my $needsupdate;
3093: foreach my $which (keys(%allchecked)) {
3094: $env{'form.multi'.$which} =~ s/,$//;
3095: if ($env{'form.multi'.$which}) {
3096: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3097: if (ref($allchecked{$which}) eq 'HASH') {
3098: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3099: }
3100: }
3101: }
3102: if ($needsupdate) {
3103: my $haschanges = 0;
3104: my %curr_groups = &Apache::longroup::coursegroups();
3105: my $total = scalar(@LONCAPA::map::order) - 1;
3106: for (my $i=$total; $i>=0; $i--) {
3107: my $res = $LONCAPA::map::order[$i];
3108: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3109: $name=&LONCAPA::map::qtescape($name);
3110: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3111: next unless $url;
1.538 raeburn 3112: my %denied =
3113: &action_restrictions($coursenum,$coursedom,$url,
3114: $env{'form.folderpath'},\%curr_groups);
3115: foreach my $which (keys(%allchecked)) {
3116: next if ($denied{$which});
3117: next unless ($allchecked{$which}{$res});
3118: if ($which eq 'remove') {
3119: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3120: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3121: &Apache::lonnet::removeuploadedurl($url);
3122: } else {
3123: &LONCAPA::map::makezombie($res);
3124: }
3125: splice(@LONCAPA::map::order,$i,1);
3126: $haschanges ++;
3127: } elsif ($which eq 'cut') {
3128: &LONCAPA::map::makezombie($res);
3129: splice(@LONCAPA::map::order,$i,1);
3130: $haschanges ++;
3131: }
3132: }
3133: }
3134: if ($haschanges) {
3135: ($errtext,$fatal) =
3136: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3137: return $errtext if ($fatal);
3138: }
3139: }
3140: }
3141:
1.329 droeschl 3142: # Group import/search
3143: if ($env{'form.importdetail'}) {
3144: my @imports;
3145: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3146: if (defined($item)) {
3147: my ($name,$url,$residx)=
1.533 raeburn 3148: map { &unescape($_); } split(/\=/,$item);
3149: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3150: my ($suffix,$errortxt,$locknotfreed) =
3151: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3152: if ($locknotfreed) {
3153: $r->print($locknotfreed);
3154: }
3155: if ($suffix) {
3156: $url =~ s/_new\./_$suffix./;
3157: } else {
3158: return $errortxt;
3159: }
1.533 raeburn 3160: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3161: my $type = $1;
3162: my ($suffix,$errortxt,$locknotfreed) =
3163: &new_timebased_suffix($coursedom,$coursenum,$type);
3164: if ($locknotfreed) {
3165: $r->print($locknotfreed);
3166: }
3167: if ($suffix) {
3168: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3169: } else {
3170: return $errortxt;
3171: }
1.598 raeburn 3172: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/exttool}) {
3173: my ($suffix,$errortxt,$locknotfreed) =
3174: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3175: if ($locknotfreed) {
3176: $r->print($locknotfreed);
3177: }
3178: if ($suffix) {
3179: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3180: } else {
3181: return $errortxt;
3182: }
1.534 raeburn 3183: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3184: if ($supplementalflag) {
3185: next unless ($1 eq 'supplemental');
3186: if ($folder eq 'supplemental') {
3187: next unless ($2 eq 'default');
3188: } else {
3189: next unless ($folder eq 'supplemental_'.$2);
3190: }
3191: } else {
3192: next unless ($1 eq 'docs');
3193: if ($folder eq 'default') {
3194: next unless ($2 eq 'default');
3195: } else {
3196: next unless ($folder eq 'default_'.$2);
3197: }
3198: }
1.504 raeburn 3199: }
1.329 droeschl 3200: push(@imports, [$name, $url, $residx]);
3201: }
3202: }
1.530 raeburn 3203: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3204: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3205: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3206: return $errtext if ($fatal);
1.529 raeburn 3207: if ($fixuperrors) {
3208: $r->print($fixuperrors);
3209: }
1.329 droeschl 3210: }
3211: # Loading a complete map
3212: if ($env{'form.loadmap'}) {
3213: if ($env{'form.importmap'}=~/\w/) {
3214: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3215: my ($title,$url,$ext,$type)=split(/\:/,$res);
3216: my $idx=&LONCAPA::map::getresidx($url);
3217: $LONCAPA::map::resources[$idx]=$res;
3218: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3219: }
3220: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3221: $folder.'.'.$container,1);
1.329 droeschl 3222: return $errtext if ($fatal);
3223: } else {
3224: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3225:
1.329 droeschl 3226: }
3227: }
3228: &log_differences($plain);
3229: }
3230: # ---------------------------------------------------------------- End commands
3231: # ---------------------------------------------------------------- Print screen
3232: my $idx=0;
3233: my $shown=0;
3234: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3235: $r->print('<div class="LC_Box">'.
1.432 raeburn 3236: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3237: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3238: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3239: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3240: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3241: '</ol>');
1.381 bisitz 3242: if ($randompick>=0) {
3243: $r->print('<p class="LC_warning">'
3244: .&mt('Caution: this folder is set to randomly pick a subset'
3245: .' of resources. Adding or removing resources from this'
3246: .' folder will change the set of resources that the'
3247: .' students see, resulting in spurious or missing credit'
3248: .' for completed problems, not limited to ones you'
3249: .' modify. Do not modify the contents of this folder if'
3250: .' it is in active student use.')
3251: .'</p>'
3252: );
3253: }
3254: if ($is_random_order) {
3255: $r->print('<p class="LC_warning">'
3256: .&mt('Caution: this folder is set to randomly order its'
3257: .' contents. Adding or removing resources from this folder'
3258: .' will change the order of resources shown.')
3259: .'</p>'
3260: );
3261: }
3262: $r->print('</div>');
1.364 bisitz 3263: }
1.381 bisitz 3264:
1.538 raeburn 3265: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3266: %filters = (
1.543 raeburn 3267: canremove => [],
3268: cancut => [],
3269: cancopy => [],
3270: hiddenresource => [],
3271: encrypturl => [],
3272: randomorder => [],
3273: randompick => [],
1.538 raeburn 3274: );
3275: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3276: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3277: foreach my $res (@LONCAPA::map::order) {
3278: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3279: $name=&LONCAPA::map::qtescape($name);
3280: $url=&LONCAPA::map::qtescape($url);
3281: unless ($name) { $name=(split(/\//,$url))[-1]; }
3282: unless ($name) { $idx++; next; }
1.537 raeburn 3283: push(@allidx,$res);
3284: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3285: push(@allmapidx,$res);
3286: }
1.381 bisitz 3287: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3288: $coursenum,$coursedom,$crstype,
1.538 raeburn 3289: $pathitem,$supplementalflag,$container,
1.612 raeburn 3290: \%filters,\%curr_groups,$ltitoolsref,$canedit,$isencrypted);
1.381 bisitz 3291: $idx++;
3292: $shown++;
1.329 droeschl 3293: }
1.424 onken 3294: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3295:
1.538 raeburn 3296: my $need_save;
1.611 raeburn 3297: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3298: my $toolslink;
1.611 raeburn 3299: if ($allowed) {
1.544 raeburn 3300: $toolslink = '<table><tr><td>'
1.520 raeburn 3301: .&Apache::loncommon::help_open_menu('Navigation Screen',
3302: 'Navigation_Screen',undef,'RAT')
3303: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3304: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3305: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3306: .'id="LC_content_toolbar_edittoplevel" '
3307: .'class="LC_toolbarItem" '
3308: .'title="'.&mt('Supplemental Content Editor').'">'
3309: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3310: }
1.510 raeburn 3311: if ($shown) {
3312: if ($allowed) {
3313: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3314: .&Apache::loncommon::start_data_table(undef,'contentlist')
3315: .&Apache::loncommon::start_data_table_header_row()
3316: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 3317: .'<th colspan="2">'.&mt('Actions').'</th>'
3318: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3319: if ($folder !~ /^supplemental/) {
3320: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3321: }
1.537 raeburn 3322: $to_show .= &Apache::loncommon::end_data_table_header_row();
3323: if ($folder !~ /^supplemental/) {
1.538 raeburn 3324: $lists{'canhide'} = join(',',@allidx);
3325: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3326: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3327: 'randomorder','randompick');
3328: foreach my $item (@possfilters) {
1.538 raeburn 3329: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3330: if (@{$filters{$item}} > 0) {
3331: $lists{$item} = join(',',@{$filters{$item}});
3332: }
1.538 raeburn 3333: }
3334: }
1.537 raeburn 3335: if (@allidx > 0) {
3336: my $path;
3337: if ($env{'form.folderpath'}) {
3338: $path =
3339: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3340: }
1.538 raeburn 3341: if (@allidx > 1) {
3342: $to_show .=
3343: &Apache::loncommon::continue_data_table_row().
3344: '<td colspan="2"> </td>'.
3345: '<td>'.
1.611 raeburn 3346: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3347: '</td>'.
3348: '<td> </td>'.
3349: '<td> </td>'.
3350: '<td colspan="4">'.
1.611 raeburn 3351: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3352: '</td>'.
3353: &Apache::loncommon::end_data_table_row();
3354: $need_save = 1;
3355: }
1.537 raeburn 3356: }
3357: }
3358: $to_show .= $output.' '
1.510 raeburn 3359: .&Apache::loncommon::end_data_table()
3360: .'<br style="line-height:2px;" />'
3361: .&Apache::loncommon::end_scrollbox();
3362: } else {
1.520 raeburn 3363: $to_show .= $toolslink
1.510 raeburn 3364: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3365: .$output.' '
3366: .&Apache::loncommon::end_data_table();
1.393 raeburn 3367: }
1.510 raeburn 3368: } else {
1.520 raeburn 3369: if (!$allowed) {
3370: $to_show .= $toolslink;
3371: }
1.510 raeburn 3372: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3373: .'<div class="LC_info" id="contentlist">'
1.550 raeburn 3374: .&mt('Currently empty')
1.510 raeburn 3375: .'</div>'
3376: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3377: }
3378: } else {
1.510 raeburn 3379: if ($shown) {
3380: $to_show = '<div>'
3381: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3382: .$output
3383: .&Apache::loncommon::end_data_table()
3384: .'</div>';
3385: } else {
3386: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3387: .&mt('Currently empty')
1.510 raeburn 3388: .'</div>'
3389: }
1.458 raeburn 3390: }
3391: my $tid = 1;
3392: if ($supplementalflag) {
3393: $tid = 2;
1.329 droeschl 3394: }
3395: if ($allowed) {
1.484 raeburn 3396: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3397: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3398: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3399: if ($canedit) {
3400: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3401: }
1.460 raeburn 3402: } else {
3403: $r->print($to_show);
1.329 droeschl 3404: }
3405: return;
3406: }
3407:
1.538 raeburn 3408: sub multiple_check_form {
1.611 raeburn 3409: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3410: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3411: my $disabled;
3412: unless ($canedit) {
3413: $disabled = 'disabled="disabled"';
3414: }
1.538 raeburn 3415: my $output =
3416: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3417: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3418: '<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>'.
3419: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3420: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3421: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3422: if ($caller eq 'settings') {
3423: $output .=
3424: '<table><tr>'.
3425: '<td class="LC_docs_entry_parameter">'.
3426: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3427: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3428: '</label></span></td>'.
3429: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3430: '<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 3431: '</span></td>'.
3432: '</tr>'."\n".
3433: '<tr>'.
3434: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3435: '<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 3436: '</label></span>'.
3437: '</td></tr></table>'."\n";
3438: } else {
3439: $output .=
3440: '<table><tr>'.
3441: '<td class="LC_docs_entry_parameter">'.
3442: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3443: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3444: '</label></span></td>'.
3445: '<td class="LC_docs_entry_parameter">'.
3446: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3447: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3448: '</label></span></td>'."\n".
3449: '<td class="LC_docs_entry_parameter">'.
3450: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3451: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3452: '</label></span></td>'.
3453: '</tr></table>'."\n";
3454: }
3455: $output .=
3456: '</fieldset>'.
3457: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3458: if ($caller eq 'settings') {
3459: $output .=
1.543 raeburn 3460: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3461: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3462: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3463: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3464: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3465: } elsif ($caller eq 'actions') {
3466: $output .=
3467: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3468: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3469: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3470: }
3471: $output .=
3472: '</form>'.
3473: '</div>';
3474: return $output;
3475: }
3476:
1.329 droeschl 3477: sub process_file_upload {
1.552 raeburn 3478: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3479: # upload a file, if present
1.552 raeburn 3480: my $filesize = length($env{'form.uploaddoc'});
3481: if (!$filesize) {
3482: $$upload_output = '<div class="LC_error">'.
3483: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3484: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3485: $filesize).'<br />'.
3486: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3487: '</div>';
3488: return;
3489: }
3490: my $quotatype = 'unofficial';
3491: if ($crstype eq 'Community') {
1.601 raeburn 3492: $quotatype = 'community';
3493: } elsif ($crstype eq 'Placement') {
3494: $quotatype = 'placement';
1.580 raeburn 3495: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3496: $quotatype = 'official';
1.573 raeburn 3497: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3498: $quotatype = 'textbook';
1.552 raeburn 3499: }
3500: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3501: $filesize = int($filesize/1000); #expressed in kb
3502: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3503: $env{'form.uploaddoc.filename'},$filesize,
3504: 'upload',$quotatype);
1.552 raeburn 3505: return if ($$upload_output);
3506: }
1.440 raeburn 3507: my ($parseaction,$showupload,$nextphase,$mimetype);
3508: if ($env{'form.parserflag'}) {
1.329 droeschl 3509: $parseaction = 'parse';
3510: }
3511: my $folder=$env{'form.folder'};
3512: if ($folder eq '') {
3513: $folder='default';
3514: }
3515: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3516: my $errtext='';
3517: my $fatal=0;
3518: my $container='sequence';
1.519 raeburn 3519: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3520: $container='page';
3521: }
3522: ($errtext,$fatal)=
1.534 raeburn 3523: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3524: if ($#LONCAPA::map::order<1) {
3525: $LONCAPA::map::order[0]=1;
3526: $LONCAPA::map::resources[1]='';
3527: }
3528: my $destination = 'docs/';
3529: if ($folder =~ /^supplemental/) {
3530: $destination = 'supplemental/';
3531: }
3532: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3533: $destination .= 'default/';
3534: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3535: $destination .= $2.'/';
3536: }
1.534 raeburn 3537: if ($fatal) {
3538: $$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>';
3539: return;
3540: }
1.440 raeburn 3541: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3542: my $newidx=&LONCAPA::map::getresidx();
3543: $destination .= $newidx;
1.439 raeburn 3544: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3545: $parseaction,$allfiles,
1.440 raeburn 3546: $codebase,undef,undef,undef,undef,
3547: undef,undef,\$mimetype);
3548: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3549: my $stored = $1;
3550: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3551: $stored.'</span>').'</p>';
3552: } else {
3553: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3554:
1.457 raeburn 3555: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3556: return;
3557: }
1.329 droeschl 3558: my $ext='false';
3559: if ($url=~m{^http://}) { $ext='true'; }
3560: $url = &LONCAPA::map::qtunescape($url);
3561: my $comment=$env{'form.comment'};
3562: $comment = &LONCAPA::map::qtunescape($comment);
3563: if ($folder=~/^supplemental/) {
3564: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3565: $env{'user.domain'}.'___&&&___'.$comment;
3566: }
3567:
3568: $LONCAPA::map::resources[$newidx]=
3569: $comment.':'.$url.':'.$ext.':normal:res';
3570: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3571: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3572: $folder.'.'.$container,1);
1.329 droeschl 3573: if ($fatal) {
1.457 raeburn 3574: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3575: return;
1.329 droeschl 3576: } else {
1.440 raeburn 3577: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3578: $$upload_output = $showupload;
1.384 raeburn 3579: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3580: if ($total_embedded > 0) {
1.440 raeburn 3581: my $uploadphase = 'upload_embedded';
3582: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3583: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3584: my ($embedded,$num) =
3585: &Apache::loncommon::ask_for_embedded_content(
3586: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3587: if ($embedded) {
3588: if ($num) {
3589: $$upload_output .=
3590: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3591: $nextphase = $uploadphase;
3592: } else {
3593: $$upload_output .= $embedded;
3594: }
3595: } else {
3596: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3597: }
1.329 droeschl 3598: } else {
1.440 raeburn 3599: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3600: }
1.457 raeburn 3601: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3602: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3603: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3604: $nextphase = 'decompress_uploaded';
3605: my $position = scalar(@LONCAPA::map::order)-1;
3606: my $noextract = &return_to_editor();
3607: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3608: my %archiveitems = (
3609: folderpath => $env{'form.folderpath'},
3610: cmd => $nextphase,
3611: newidx => $newidx,
3612: position => $position,
3613: phase => $nextphase,
1.477 raeburn 3614: comment => $comment,
1.480 raeburn 3615: );
3616: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3617: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3618: $$upload_output = $showupload.
3619: &Apache::loncommon::decompress_form($mimetype,
3620: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3621: \%archiveitems,\@current);
1.329 droeschl 3622: }
3623: }
3624: }
1.440 raeburn 3625: return $nextphase;
1.329 droeschl 3626: }
3627:
1.480 raeburn 3628: sub get_dir_list {
3629: my ($url,$coursenum,$coursedom,$newidx) = @_;
3630: my ($destination,$dir_root) = &embedded_destination();
3631: my ($dirlistref,$listerror) =
3632: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3633: my @dir_lines;
3634: my $dirptr=16384;
3635: if (ref($dirlistref) eq 'ARRAY') {
3636: foreach my $dir_line (sort
3637: {
3638: my ($afile)=split('&',$a,2);
3639: my ($bfile)=split('&',$b,2);
3640: return (lc($afile) cmp lc($bfile));
3641: } (@{$dirlistref})) {
3642: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3643: $filename =~ s/\s+$//;
3644: next if ($filename =~ /^\.\.?$/);
3645: my $isdir = 0;
3646: if ($dirptr&$testdir) {
3647: $isdir = 1;
3648: }
3649: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3650: }
3651: }
3652: return @dir_lines;
3653: }
3654:
1.329 droeschl 3655: sub is_supplemental_title {
3656: my ($title) = @_;
3657: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3658: }
3659:
3660: # --------------------------------------------------------------- An entry line
3661:
3662: sub entryline {
1.501 raeburn 3663: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3664: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.612 raeburn 3665: $ltitoolsref,$canedit,$isencrypted)=@_;
1.581 raeburn 3666: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3667: if (&is_supplemental_title($title)) {
1.488 raeburn 3668: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3669: } else {
3670: $title=&HTML::Entities::encode($title,'"<>&\'');
3671: $renametitle=$title;
3672: $foldertitle=$title;
3673: }
3674:
1.611 raeburn 3675: my ($disabled,$readonly,$js_lt);
3676: unless ($canedit) {
3677: $disabled = 'disabled="disabled"';
3678: $readonly = 1;
3679: }
3680:
1.329 droeschl 3681: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3682:
1.329 droeschl 3683: $renametitle=~s/\\/\\\\/g;
3684: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3685: $renametitle=~s/"/%22/g;
1.581 raeburn 3686: $renametitle=~s/ /%20/g;
3687: $oldtitle = $renametitle;
1.576 raeburn 3688: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3689: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3690: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3691: # Edit commands
1.535 raeburn 3692: my ($esc_path, $path, $symb);
1.329 droeschl 3693: if ($env{'form.folderpath'}) {
3694: $esc_path=&escape($env{'form.folderpath'});
3695: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3696: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3697: }
1.505 raeburn 3698: my $isexternal;
1.510 raeburn 3699: if ($residx) {
1.501 raeburn 3700: my $currurl = $url;
3701: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3702: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3703: $isexternal = 1;
3704: }
1.510 raeburn 3705: if (!$supplementalflag) {
3706: my $path = 'uploaded/'.
3707: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3708: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3709: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3710: $residx,
3711: &Apache::lonnet::declutter($currurl));
3712: }
1.501 raeburn 3713: }
1.538 raeburn 3714: my ($renamelink,%lt,$ishash);
3715: if (ref($filtersref) eq 'HASH') {
3716: $ishash = 1;
3717: }
3718:
1.329 droeschl 3719: if ($allowed) {
1.538 raeburn 3720: $form_start = '
3721: <form action="/adm/coursedocs" method="post">
3722: ';
3723: $form_common=(<<END);
3724: <input type="hidden" name="folderpath" value="$path" />
3725: <input type="hidden" name="symb" value="$symb" />
3726: END
3727: $form_param=(<<END);
3728: <input type="hidden" name="setparms" value="$orderidx" />
3729: <input type="hidden" name="changeparms" value="0" />
3730: END
3731: $form_end = '</form>';
3732:
1.329 droeschl 3733: my $incindex=$index+1;
3734: my $selectbox='';
1.471 raeburn 3735: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3736: ((split(/\:/,
1.344 bisitz 3737: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3738: ne '') &&
1.329 droeschl 3739: ((split(/\:/,
1.344 bisitz 3740: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3741: ne '')) {
3742: $selectbox=
3743: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3744: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3745: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3746: if ($i==$incindex) {
1.358 bisitz 3747: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3748: } else {
3749: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3750: }
3751: }
3752: $selectbox.='</select>';
3753: }
1.501 raeburn 3754: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3755: 'up' => 'Move Up',
3756: 'dw' => 'Move Down',
3757: 'rm' => 'Remove',
3758: 'ct' => 'Cut',
3759: 'rn' => 'Rename',
1.501 raeburn 3760: 'cp' => 'Copy',
3761: 'ex' => 'External Resource',
1.598 raeburn 3762: 'et' => 'External Tool',
1.501 raeburn 3763: 'ed' => 'Edit',
3764: 'pr' => 'Preview',
3765: 'sv' => 'Save',
3766: 'ul' => 'URL',
1.611 raeburn 3767: 'ti' => 'Title',
3768: 'er' => 'Editing rights unavailable for your current role',
1.501 raeburn 3769: );
1.538 raeburn 3770: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3771: $env{'form.folderpath'},
3772: $currgroups);
1.517 raeburn 3773: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3774: my $skip_confirm = 0;
1.603 raeburn 3775: my $confirm_removal = 0;
1.329 droeschl 3776: if ( $folder =~ /^supplemental/
3777: || ($url =~ m{( /smppg$
3778: |/syllabus$
3779: |/aboutme$
3780: |/navmaps$
3781: |/bulletinboard$
1.598 raeburn 3782: |/exttools?$
1.505 raeburn 3783: |\.html$)}x)
3784: || $isexternal) {
1.329 droeschl 3785: $skip_confirm = 1;
3786: }
1.603 raeburn 3787: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3788: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3789: $confirm_removal = 1;
3790: }
1.329 droeschl 3791:
1.538 raeburn 3792: if ($denied{'copy'}) {
1.543 raeburn 3793: $copylink=(<<ENDCOPY)
1.507 raeburn 3794: <span style="visibility: hidden;">$lt{'cp'}</span>
3795: ENDCOPY
3796: } else {
1.538 raeburn 3797: my $formname = 'edit_copy_'.$orderidx;
3798: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3799: $copylink=(<<ENDCOPY);
1.538 raeburn 3800: <form name="$formname" method="post" action="/adm/coursedocs">
3801: $form_common
1.611 raeburn 3802: <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 3803: $form_end
1.329 droeschl 3804: ENDCOPY
1.538 raeburn 3805: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3806: push(@{$filtersref->{'cancopy'}},$orderidx);
3807: }
1.329 droeschl 3808: }
1.538 raeburn 3809: if ($denied{'cut'}) {
1.507 raeburn 3810: $cutlink=(<<ENDCUT);
3811: <span style="visibility: hidden;">$lt{'ct'}</span>
3812: ENDCUT
3813: } else {
1.538 raeburn 3814: my $formname = 'edit_cut_'.$orderidx;
3815: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3816: $cutlink=(<<ENDCUT);
1.538 raeburn 3817: <form name="$formname" method="post" action="/adm/coursedocs">
3818: $form_common
1.542 raeburn 3819: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3820: <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 3821: $form_end
1.329 droeschl 3822: ENDCUT
1.538 raeburn 3823: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3824: push(@{$filtersref->{'cancut'}},$orderidx);
3825: }
1.329 droeschl 3826: }
1.538 raeburn 3827: if ($denied{'remove'}) {
1.507 raeburn 3828: $removelink=(<<ENDREM);
3829: <span style="visibility: hidden;">$lt{'rm'}</a>
3830: ENDREM
3831: } else {
1.538 raeburn 3832: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3833: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3834: $removelink=(<<ENDREM);
1.538 raeburn 3835: <form name="$formname" method="post" action="/adm/coursedocs">
3836: $form_common
1.542 raeburn 3837: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3838: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 3839: <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 3840: $form_end
1.497 raeburn 3841: ENDREM
1.538 raeburn 3842: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3843: push(@{$filtersref->{'canremove'}},$orderidx);
3844: }
1.497 raeburn 3845: }
1.551 raeburn 3846: $renamelink=(<<ENDREN);
1.581 raeburn 3847: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3848: ENDREN
1.611 raeburn 3849: my ($uplink,$downlink);
3850: if ($canedit) {
3851: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3852: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3853: } else {
3854: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3855: $downlink = $uplink;
3856: }
1.329 droeschl 3857: $line.=(<<END);
3858: <td>
1.379 bisitz 3859: <div class="LC_docs_entry_move">
1.611 raeburn 3860: <a href="$uplink">
1.501 raeburn 3861: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3862: </a>
3863: </div>
3864: <div class="LC_docs_entry_move">
1.611 raeburn 3865: <a href="$downlink">
1.501 raeburn 3866: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3867: </a>
3868: </div>
1.329 droeschl 3869: </td>
3870: <td>
3871: $form_start
1.538 raeburn 3872: $form_param
1.478 raeburn 3873: $form_common
1.329 droeschl 3874: $selectbox
3875: $form_end
3876: </td>
1.540 raeburn 3877: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3878: $removelink
1.329 droeschl 3879: $cutlink
3880: $copylink
3881: </td>
3882: END
3883: }
3884: # Figure out what kind of a resource this is
3885: my ($extension)=($url=~/\.(\w+)$/);
3886: my $uploaded=($url=~/^\/*uploaded\//);
3887: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3888: my $isfolder;
3889: my $ispage;
3890: my $containerarg;
1.329 droeschl 3891: if ($uploaded) {
1.472 raeburn 3892: if (($extension eq 'sequence') || ($extension eq 'page')) {
3893: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3894: $containerarg = $1;
1.472 raeburn 3895: if ($extension eq 'sequence') {
3896: $icon=$iconpath.'navmap.folder.closed.gif';
3897: $isfolder=1;
3898: } else {
3899: $icon=$iconpath.'page.gif';
3900: $ispage=1;
3901: }
3902: if ($allowed) {
3903: $url='/adm/coursedocs?';
3904: } else {
3905: $url='/adm/supplemental?';
3906: }
1.329 droeschl 3907: } else {
3908: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3909: }
3910: }
1.364 bisitz 3911:
1.609 raeburn 3912: my ($editlink,$extresform,$anchor);
1.329 droeschl 3913: my $orig_url = $url;
1.340 raeburn 3914: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 3915: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 3916: if (!$supplementalflag && $residx && $symb) {
3917: if ((!$isfolder) && (!$ispage)) {
3918: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3919: $url=&Apache::lonnet::clutter($url);
3920: if ($url=~/^\/*uploaded\//) {
3921: $url=~/\.(\w+)$/;
3922: my $embstyle=&Apache::loncommon::fileembstyle($1);
3923: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3924: $url='/adm/wrapper'.$url;
3925: } elsif ($embstyle eq 'ssi') {
3926: #do nothing with these
3927: } elsif ($url!~/\.(sequence|page)$/) {
3928: $url='/adm/coursedocs/showdoc'.$url;
3929: }
3930: } elsif ($url=~m|^/ext/|) {
3931: $url='/adm/wrapper'.$url;
1.598 raeburn 3932: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
3933: $url='/adm/wrapper'.$url;
3934: }
1.501 raeburn 3935: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 3936: my $shownsymb = $symb;
3937: if ($isexternal) {
3938: if ($url =~ /^([^#]+)#([^#]+)$/) {
3939: $url = $1;
3940: $anchor = $2;
3941: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
3942: $shownsymb = $1.&escape('#').$anchor;
3943: }
3944: }
3945: }
3946: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
1.612 raeburn 3947: } elsif ((!$env{'request.role.adv'}) &&
3948: (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3949: $isencrypted)) {
3950: my $shownsymb = &Apache::lonenc::encrypted($symb);
3951: my $shownurl = &Apache::lonenc::encrypted($url);
3952: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
3953: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
1.613 ! raeburn 3954: if ($env{'request.enc'} ne '') {
! 3955: delete($env{'request.enc'});
! 3956: }
1.612 raeburn 3957: } else {
3958: $url='';
3959: }
1.501 raeburn 3960: } else {
3961: $url='';
3962: }
1.329 droeschl 3963: }
1.610 raeburn 3964: } elsif ($supplementalflag) {
3965: if ($isexternal) {
3966: if ($url =~ /^([^#]+)#([^#]+)$/) {
3967: $url = $1;
3968: $anchor = $2;
3969: }
3970: }
1.329 droeschl 3971: }
1.478 raeburn 3972: my ($rand_pick_text,$rand_order_text);
1.519 raeburn 3973: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3974: my $foldername=&escape($foldertitle);
3975: my $folderpath=$env{'form.folderpath'};
3976: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 3977: if (!$allowed && $supplementalflag) {
1.519 raeburn 3978: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 3979: $url.='folderpath='.&escape($folderpath);
3980: } else {
1.344 bisitz 3981: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 3982: # so it gets transferred between levels
1.519 raeburn 3983: $folderpath.=$containerarg.'&'.$foldername.
1.510 raeburn 3984: ':'.(&LONCAPA::map::getparameter($orderidx,
1.329 droeschl 3985: 'parameter_randompick'))[0]
3986: .':'.((&LONCAPA::map::getparameter($orderidx,
3987: 'parameter_hiddenresource'))[0]=~/^yes$/i)
3988: .':'.((&LONCAPA::map::getparameter($orderidx,
3989: 'parameter_encrypturl'))[0]=~/^yes$/i)
3990: .':'.((&LONCAPA::map::getparameter($orderidx,
1.519 raeburn 3991: 'parameter_randomorder'))[0]=~/^yes$/i)
3992: .':'.$ispage;
1.612 raeburn 3993: if ($env{'request.role.adv'} ||
3994: (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]!~/^yes$/i) {
3995: $url.='folderpath='.&escape($folderpath);
3996: } else {
3997: $url = '';
3998: }
1.510 raeburn 3999: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4000: 'parameter_randompick'))[0];
4001: my $rpckchk;
4002: if ($rpicknum) {
4003: $rpckchk = ' checked="checked"';
1.543 raeburn 4004: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4005: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4006: }
1.510 raeburn 4007: }
1.537 raeburn 4008: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4009: $rand_pick_text =
1.478 raeburn 4010: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4011: $form_param."\n".
1.478 raeburn 4012: $form_common."\n".
1.611 raeburn 4013: '<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 4014: if ($rpicknum ne '') {
4015: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4016: }
1.537 raeburn 4017: $rand_pick_text .= '</span></span>'.
4018: $form_end;
1.543 raeburn 4019: my $ro_set;
4020: if ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i) {
4021: $ro_set = 'checked="checked"';
4022: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4023: push(@{$filtersref->{'randomorder'}},$orderidx);
4024: }
4025: }
1.564 raeburn 4026: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4027: $rand_order_text =
1.537 raeburn 4028: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4029: $form_param."\n".
1.537 raeburn 4030: $form_common."\n".
1.611 raeburn 4031: '<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 4032: $form_end;
1.510 raeburn 4033: }
1.509 raeburn 4034: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4035: my $isexttool;
4036: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4037: $url='/adm/wrapper'.$url;
4038: $isexttool = 1;
4039: }
1.510 raeburn 4040: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4041: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4042: if ($title) {
4043: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4044: }
1.598 raeburn 4045: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4046: $url .= '&idx='.$orderidx;
4047: }
1.610 raeburn 4048: if ($anchor ne '') {
4049: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4050: }
1.329 droeschl 4051: }
1.519 raeburn 4052: my ($tdalign,$tdwidth);
1.501 raeburn 4053: if ($allowed) {
4054: my $fileloc =
4055: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4056: if ($isexternal) {
1.518 raeburn 4057: ($editlink,$extresform) =
1.611 raeburn 4058: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4059: undef,undef,undef,undef,undef,undef,
4060: undef,$disabled);
1.598 raeburn 4061: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) {
4062: ($editlink,$extresform) =
4063: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4064: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4065: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4066: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4067: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4068: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4069: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4070: my $suppanchor;
4071: if ($supplementalflag) {
4072: $suppanchor = $anchor;
4073: }
1.501 raeburn 4074: my $jscall =
4075: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4076: $switchserver,
1.503 raeburn 4077: $forceedit,
1.511 raeburn 4078: undef,$symb,
4079: &escape($env{'form.folderpath'}),
1.610 raeburn 4080: $renametitle,'','',1,$suppanchor);
1.501 raeburn 4081: if ($jscall) {
1.518 raeburn 4082: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4083: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4084: }
4085: }
4086: }
1.519 raeburn 4087: $tdalign = ' align="right" valign="top"';
4088: $tdwidth = ' width="80%"';
1.329 droeschl 4089: }
1.408 raeburn 4090: my $reinit;
4091: if ($crstype eq 'Community') {
4092: $reinit = &mt('(re-initialize community to access)');
4093: } else {
4094: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4095: }
4096: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.472 raeburn 4097: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4098: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4099: } elsif ($url) {
1.610 raeburn 4100: if ($anchor ne '') {
4101: if ($supplementalflag) {
4102: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4103: } else {
4104: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4105: }
4106: }
1.609 raeburn 4107: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.610 raeburn 4108: (($anchor ne '')?$anchor:''),
1.470 raeburn 4109: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 4110: } else {
4111: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4112: }
1.519 raeburn 4113: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4114: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4115: $line.='<a href="'.$url.'">'.$title.'</a>';
4116: } elsif ($url) {
1.609 raeburn 4117: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.610 raeburn 4118: (($anchor ne '')?$anchor:''),
1.470 raeburn 4119: $title,600,500);
1.469 www 4120: } else {
4121: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4122: }
1.518 raeburn 4123: $line.="$extresform</td>";
1.478 raeburn 4124: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4125: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4126: if (($allowed) && ($folder!~/^supplemental/)) {
4127: my %lt=&Apache::lonlocal::texthash(
4128: 'hd' => 'Hidden',
4129: 'ec' => 'URL hidden');
1.543 raeburn 4130: my ($enctext,$hidtext);
4131: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4132: $enctext = ' checked="checked"';
4133: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4134: push(@{$filtersref->{'encrypturl'}},$orderidx);
4135: }
4136: }
4137: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4138: $hidtext = ' checked="checked"';
4139: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4140: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4141: }
4142: }
1.537 raeburn 4143: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4144: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4145: $line.=(<<ENDPARMS);
4146: <td class="LC_docs_entry_parameter">
1.537 raeburn 4147: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4148: $form_param
1.478 raeburn 4149: $form_common
1.611 raeburn 4150: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4151: $form_end
1.458 raeburn 4152: <br />
1.537 raeburn 4153: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4154: $form_param
1.478 raeburn 4155: $form_common
1.611 raeburn 4156: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4157: $form_end
4158: </td>
1.478 raeburn 4159: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4160: $rand_order_text</td>
1.329 droeschl 4161: ENDPARMS
4162: }
1.379 bisitz 4163: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4164: return $line;
4165: }
4166:
1.538 raeburn 4167: sub action_restrictions {
4168: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4169: my %denied = (
4170: cut => 0,
4171: copy => 0,
4172: remove => 0,
4173: );
4174: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4175: # no copy for published maps
4176: $denied{'copy'} = 1;
1.597 raeburn 4177: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4178: unless ($1 eq 'simpleproblem') {
4179: $denied{'copy'} = 1;
4180: }
4181: $denied{'cut'} = 1;
1.538 raeburn 4182: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4183: if ($folderpath =~ /^default&[^\&]+$/) {
4184: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4185: $denied{'remove'} = 1;
4186: }
4187: $denied{'cut'} = 1;
4188: $denied{'copy'} = 1;
4189: }
4190: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4191: my $group = $1;
4192: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4193: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4194: $denied{'remove'} = 1;
4195: }
4196: }
4197: $denied{'cut'} = 1;
4198: $denied{'copy'} = 1;
4199: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4200: my $group = $1;
4201: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4202: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4203: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4204: if (keys(%groupsettings) > 0) {
4205: $denied{'remove'} = 1;
4206: }
4207: $denied{'cut'} = 1;
4208: $denied{'copy'} = 1;
4209: }
4210: }
4211: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4212: my $group = $1;
4213: if ($url =~ /group_boards_\Q$group\E/) {
4214: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4215: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4216: if (keys(%groupsettings) > 0) {
4217: if (ref($groupsettings{'functions'}) eq 'HASH') {
4218: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4219: $denied{'remove'} = 1;
4220: }
4221: }
4222: }
4223: $denied{'cut'} = 1;
4224: $denied{'copy'} = 1;
4225: }
4226: }
4227: }
4228: return %denied;
4229: }
4230:
1.533 raeburn 4231: sub new_timebased_suffix {
1.538 raeburn 4232: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4233: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4234: if ($type eq 'paste') {
4235: $prefix = $type;
4236: $namespace = 'courseeditor';
1.587 raeburn 4237: $idtype = 'addcode';
1.538 raeburn 4238: } elsif ($type eq 'map') {
1.533 raeburn 4239: $prefix = 'docs';
4240: if ($area eq 'supplemental') {
4241: $prefix = 'supp';
4242: }
4243: $prefix .= $container;
4244: $namespace = 'uploadedmaps';
4245: } else {
4246: $prefix = $type;
4247: $namespace = 'templated';
1.504 raeburn 4248: }
4249: my ($suffix,$freedlock,$error) =
1.587 raeburn 4250: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4251: if (!$suffix) {
1.538 raeburn 4252: if ($type eq 'paste') {
4253: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4254: } elsif ($type eq 'map') {
1.533 raeburn 4255: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4256: } elsif ($type eq 'smppg') {
4257: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4258: } else {
1.565 bisitz 4259: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4260: }
1.504 raeburn 4261: if ($error) {
4262: $errtext .= '<br />'.$error;
4263: }
4264: }
4265: if ($freedlock ne 'ok') {
1.533 raeburn 4266: $locknotfreed =
4267: '<div class="LC_error">'.
4268: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4269: if ($type eq 'paste') {
1.591 raeburn 4270: if ($freedlock eq 'nolock') {
4271: $locknotfreed =
4272: '<div class="LC_error">'.
4273: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4274:
1.593 droeschl 4275: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4276: } else {
4277: $locknotfreed .=
4278: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4279: }
1.538 raeburn 4280: } elsif ($type eq 'map') {
1.591 raeburn 4281: $locknotfreed .=
4282: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4283: } elsif ($type eq 'smppg') {
4284: $locknotfreed .=
4285: &mt('This will prevent creation of additional simple pages in this course.');
4286: } else {
4287: $locknotfreed .=
1.565 bisitz 4288: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4289: }
1.538 raeburn 4290: unless ($type eq 'paste') {
4291: $locknotfreed .=
1.560 raeburn 4292: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4293: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4294: }
4295: $locknotfreed .= '</div>';
1.504 raeburn 4296: }
4297: return ($suffix,$errtext,$locknotfreed);
4298: }
4299:
1.329 droeschl 4300: =pod
4301:
4302: =item tiehash()
4303:
4304: tie the hash
4305:
4306: =cut
4307:
4308: sub tiehash {
4309: my ($mode)=@_;
4310: $hashtied=0;
4311: if ($env{'request.course.fn'}) {
4312: if ($mode eq 'write') {
4313: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4314: &GDBM_WRCREAT(),0640)) {
4315: $hashtied=2;
4316: }
4317: } else {
4318: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4319: &GDBM_READER(),0640)) {
4320: $hashtied=1;
4321: }
4322: }
1.364 bisitz 4323: }
1.329 droeschl 4324: }
4325:
4326: sub untiehash {
4327: if ($hashtied) { untie %hash; }
4328: $hashtied=0;
4329: return OK;
4330: }
4331:
4332:
4333:
4334:
4335: sub checkonthis {
4336: my ($r,$url,$level,$title)=@_;
4337: $url=&unescape($url);
4338: $alreadyseen{$url}=1;
4339: $r->rflush();
4340: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4341: $r->print("\n<br />");
4342: if ($level==0) {
4343: $r->print("<br />");
4344: }
4345: for (my $i=0;$i<=$level*5;$i++) {
4346: $r->print(' ');
4347: }
4348: $r->print('<a href="'.$url.'" target="cat">'.
4349: ($title?$title:$url).'</a> ');
4350: if ($url=~/^\/res\//) {
4351: my $result=&Apache::lonnet::repcopy(
4352: &Apache::lonnet::filelocation('',$url));
4353: if ($result eq 'ok') {
4354: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4355: $r->rflush();
4356: &Apache::lonnet::countacc($url);
4357: $url=~/\.(\w+)$/;
4358: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4359: $r->print('<br />');
4360: $r->rflush();
4361: for (my $i=0;$i<=$level*5;$i++) {
4362: $r->print(' ');
4363: }
4364: $r->print('- '.&mt('Rendering:').' ');
4365: my ($errorcount,$warningcount)=split(/:/,
4366: &Apache::lonnet::ssi_body($url,
4367: ('grade_target'=>'web',
4368: 'return_only_error_and_warning_counts' => 1)));
4369: if (($errorcount) ||
4370: ($warningcount)) {
4371: if ($errorcount) {
1.369 bisitz 4372: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4373: &mt('[quant,_1,error]',$errorcount).'</span>');
4374: }
4375: if ($warningcount) {
4376: $r->print('<span class="LC_warning">'.
4377: &mt('[quant,_1,warning]',$warningcount).'</span>');
4378: }
4379: } else {
4380: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4381: }
4382: $r->rflush();
4383: }
4384: my $dependencies=
4385: &Apache::lonnet::metadata($url,'dependencies');
4386: foreach my $dep (split(/\,/,$dependencies)) {
4387: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4388: &checkonthis($r,$dep,$level+1);
4389: }
4390: }
4391: } elsif ($result eq 'unavailable') {
4392: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4393: } elsif ($result eq 'not_found') {
4394: unless ($url=~/\$/) {
1.521 bisitz 4395: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4396: } else {
1.366 bisitz 4397: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4398: }
4399: } else {
4400: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4401: }
4402: }
4403: }
4404: }
4405:
4406:
4407:
4408: =pod
4409:
4410: =item list_symbs()
4411:
1.485 raeburn 4412: List Content Identifiers
1.329 droeschl 4413:
4414: =cut
4415:
4416: sub list_symbs {
4417: my ($r) = @_;
4418:
1.408 raeburn 4419: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4420: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4421: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4422: $r->print(&startContentScreen('tools'));
1.329 droeschl 4423: my $navmap = Apache::lonnavmaps::navmap->new();
4424: if (!defined($navmap)) {
4425: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4426: '<div class="LC_error">'.
4427: &mt('Unable to retrieve information about course contents').
4428: '</div>');
1.408 raeburn 4429: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4430: } else {
1.484 raeburn 4431: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4432: &Apache::loncommon::start_data_table().
4433: &Apache::loncommon::start_data_table_header_row().
4434: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4435: &Apache::loncommon::end_data_table_header_row()."\n");
4436: my $count;
1.329 droeschl 4437: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4438: $r->print(&Apache::loncommon::start_data_table_row().
4439: '<td>'.$res->compTitle().'</td>'.
4440: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4441: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4442: $count ++;
4443: }
4444: if (!$count) {
4445: $r->print(&Apache::loncommon::start_data_table_row().
4446: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4447: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4448: }
1.484 raeburn 4449: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4450: }
1.521 bisitz 4451: $r->print(&endContentScreen());
1.329 droeschl 4452: }
4453:
4454:
4455: sub verifycontent {
4456: my ($r) = @_;
1.408 raeburn 4457: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4458: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4459: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4460: $r->print(&startContentScreen('tools'));
4461: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4462: $hashtied=0;
4463: undef %alreadyseen;
4464: %alreadyseen=();
4465: &tiehash();
1.484 raeburn 4466:
1.329 droeschl 4467: foreach my $key (keys(%hash)) {
4468: if ($hash{$key}=~/\.(page|sequence)$/) {
4469: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4470: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4471: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4472: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4473: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4474: }
4475: }
4476: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4477: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4478: }
4479: }
4480: &untiehash();
1.442 www 4481: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4482: $r->print(&endContentScreen());
1.329 droeschl 4483: }
4484:
4485:
4486: sub devalidateversioncache {
4487: my $src=shift;
4488: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4489: &Apache::lonnet::clutter($src));
4490: }
4491:
4492: sub checkversions {
1.611 raeburn 4493: my ($r,$canedit) = @_;
1.408 raeburn 4494: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4495: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4496: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4497: $r->print(&startContentScreen('tools'));
1.442 www 4498:
1.329 droeschl 4499: my $header='';
4500: my $startsel='';
4501: my $monthsel='';
4502: my $weeksel='';
4503: my $daysel='';
4504: my $allsel='';
4505: my %changes=();
4506: my $starttime=0;
4507: my $haschanged=0;
4508: my %setversions=&Apache::lonnet::dump('resourceversions',
4509: $env{'course.'.$env{'request.course.id'}.'.domain'},
4510: $env{'course.'.$env{'request.course.id'}.'.num'});
4511:
4512: $hashtied=0;
4513: &tiehash();
1.611 raeburn 4514: if ($canedit) {
4515: my %newsetversions=();
4516: if ($env{'form.setmostrecent'}) {
4517: $haschanged=1;
4518: foreach my $key (keys(%hash)) {
4519: if ($key=~/^ids\_(\/res\/.+)$/) {
4520: $newsetversions{$1}='mostrecent';
4521: &devalidateversioncache($1);
4522: }
4523: }
4524: } elsif ($env{'form.setcurrent'}) {
4525: $haschanged=1;
4526: foreach my $key (keys(%hash)) {
4527: if ($key=~/^ids\_(\/res\/.+)$/) {
4528: my $getvers=&Apache::lonnet::getversion($1);
4529: if ($getvers>0) {
4530: $newsetversions{$1}=$getvers;
4531: &devalidateversioncache($1);
4532: }
4533: }
1.329 droeschl 4534: }
1.611 raeburn 4535: } elsif ($env{'form.setversions'}) {
4536: $haschanged=1;
4537: foreach my $key (keys(%env)) {
4538: if ($key=~/^form\.set_version_(.+)$/) {
4539: my $src=$1;
4540: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4541: $newsetversions{$src}=$env{$key};
4542: &devalidateversioncache($src);
4543: }
4544: }
1.329 droeschl 4545: }
1.611 raeburn 4546: }
4547: if ($haschanged) {
4548: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4549: $env{'course.'.$env{'request.course.id'}.'.domain'},
4550: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4551: $r->print(&Apache::loncommon::confirmwrapper(
4552: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4553: } else {
4554: $r->print(&Apache::loncommon::confirmwrapper(
4555: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4556: }
1.611 raeburn 4557: &mark_hash_old();
4558: }
4559: &changewarning($r,'');
1.329 droeschl 4560: }
4561: if ($env{'form.timerange'} eq 'all') {
4562: # show all documents
1.549 raeburn 4563: $header=&mt('All content in '.$crstype);
1.521 bisitz 4564: $allsel=' selected="selected"';
1.329 droeschl 4565: foreach my $key (keys(%hash)) {
4566: if ($key=~/^ids\_(\/res\/.+)$/) {
4567: my $src=$1;
4568: $changes{$src}=1;
4569: }
4570: }
4571: } else {
4572: # show documents which changed
4573: %changes=&Apache::lonnet::dump
4574: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4575: $env{'course.'.$env{'request.course.id'}.'.num'});
4576: my $firstkey=(keys(%changes))[0];
4577: unless ($firstkey=~/^error\:/) {
4578: unless ($env{'form.timerange'}) {
4579: $env{'form.timerange'}=604800;
4580: }
4581: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4582: .&mt('seconds');
4583: if ($env{'form.timerange'}==-1) {
4584: $seltext='since start of course';
1.521 bisitz 4585: $startsel=' selected="selected"';
1.329 droeschl 4586: $env{'form.timerange'}=time;
4587: }
4588: $starttime=time-$env{'form.timerange'};
4589: if ($env{'form.timerange'}==2592000) {
4590: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4591: $monthsel=' selected="selected"';
1.329 droeschl 4592: } elsif ($env{'form.timerange'}==604800) {
4593: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4594: $weeksel=' selected="selected"';
1.329 droeschl 4595: } elsif ($env{'form.timerange'}==86400) {
4596: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4597: $daysel=' selected="selected"';
1.329 droeschl 4598: }
4599: $header=&mt('Content changed').' '.$seltext;
4600: } else {
4601: $header=&mt('No content modifications yet.');
4602: }
4603: }
4604: %setversions=&Apache::lonnet::dump('resourceversions',
4605: $env{'course.'.$env{'request.course.id'}.'.domain'},
4606: $env{'course.'.$env{'request.course.id'}.'.num'});
4607: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4608: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4609: 'lm' => 'Version changes since last Month',
4610: 'lw' => 'Version changes since last Week',
4611: 'sy' => 'Version changes since Yesterday',
4612: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4613: 'cd' => 'Change display',
1.329 droeschl 4614: 'sd' => 'Display',
4615: 'fi' => 'File',
4616: 'md' => 'Modification Date',
4617: 'mr' => 'Most recently published Version',
1.408 raeburn 4618: 've' => 'Version used in '.$crstype,
4619: 'vu' => 'Set Version to be used in '.$crstype,
4620: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4621: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4622: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4623: 'di' => 'Differences',
1.484 raeburn 4624: 'save' => 'Save changes',
4625: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4626: 'act' => 'Actions');
1.611 raeburn 4627: my ($disabled,$readonly);
4628: unless ($canedit) {
4629: $disabled = 'disabled="disabled"';
4630: $readonly = 1;
4631: }
1.329 droeschl 4632: $r->print(<<ENDHEADERS);
1.484 raeburn 4633: <h4 class="LC_info">$header</h4>
1.329 droeschl 4634: <form action="/adm/coursedocs" method="post">
4635: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4636: <div class="LC_left_float">
1.479 golterma 4637: <fieldset>
1.484 raeburn 4638: <legend>$lt{'cd'}</legend>
1.329 droeschl 4639: <select name="timerange">
1.521 bisitz 4640: <option value='all'$allsel>$lt{'al'}</option>
4641: <option value="-1"$startsel>$lt{'st'}</option>
4642: <option value="2592000"$monthsel>$lt{'lm'}</option>
4643: <option value="604800"$weeksel>$lt{'lw'}</option>
4644: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4645: </select>
4646: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4647: </fieldset>
4648: </div>
4649: <div class="LC_left_float">
4650: <fieldset>
4651: <legend>$lt{'act'}</legend>
1.611 raeburn 4652: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4653: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4654: </fieldset>
4655: </div>
4656: <br clear="all" />
4657: <hr />
4658: <h4>$lt{'vers'}</h4>
1.329 droeschl 4659: ENDHEADERS
1.479 golterma 4660: #number of columns for version history
1.571 raeburn 4661: my %changedbytime;
4662: foreach my $key (keys(%changes)) {
4663: #excludes not versionable problems from resource version history:
4664: next if ($key =~ /^\/res\/lib\/templates/);
4665: my $chg;
4666: if ($env{'form.timerange'} eq 'all') {
4667: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4668: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4669: } else {
4670: $chg = $changes{$key};
4671: next if ($chg < $starttime);
4672: }
4673: push(@{$changedbytime{$chg}},$key);
4674: }
4675: if (keys(%changedbytime) == 0) {
4676: &untiehash();
4677: $r->print(&mt('No content changes in imported content in specified time frame').
4678: &endContentScreen());
4679: return;
4680: }
1.479 golterma 4681: $r->print(
1.611 raeburn 4682: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4683: &Apache::loncommon::start_data_table().
4684: &Apache::loncommon::start_data_table_header_row().
4685: '<th>'.&mt('Resources').'</th>'.
4686: "<th>$lt{'mr'}</th>".
4687: "<th>$lt{'ve'}</th>".
4688: "<th>$lt{'vu'}</th>".
4689: '<th>'.&mt('History').'</th>'.
4690: &Apache::loncommon::end_data_table_header_row()
4691: );
1.571 raeburn 4692: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4693: foreach my $key (sort(@{$changedbytime{$chg}})) {
4694: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4695: my $currentversion=&Apache::lonnet::getversion($key);
4696: if ($currentversion<0) {
4697: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4698: }
4699: my $linkurl=&Apache::lonnet::clutter($key);
4700: $r->print(
4701: &Apache::loncommon::start_data_table_row().
4702: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4703: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4704: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4705: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4706: '<td align="right">'
4707: );
4708: # Used in course
4709: my $usedversion=$hash{'version_'.$linkurl};
4710: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 4711: if ($usedversion != $currentversion) {
1.479 golterma 4712: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4713: } else {
1.479 golterma 4714: $r->print($usedversion);
4715: }
1.329 droeschl 4716: } else {
1.521 bisitz 4717: $r->print($currentversion);
1.329 droeschl 4718: }
1.571 raeburn 4719: $r->print('</td><td title="'.$lt{'vu'}.'">');
4720: # Set version
4721: $r->print(&Apache::loncommon::select_form(
4722: $setversions{$linkurl},
4723: 'set_version_'.$linkurl,
4724: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4725: '' => '',
4726: 'mostrecent' => &mt('most recent'),
1.611 raeburn 4727: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 4728: my $lastold=1;
4729: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4730: my $url=$root.'.'.$prevvers.'.'.$extension;
4731: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4732: $lastold=$prevvers;
4733: }
4734: }
4735: $r->print('</td>');
4736: # List all available versions
4737: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4738: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4739: my $url=$root.'.'.$prevvers.'.'.$extension;
4740: $r->print(
4741: '<span class="LC_nobreak">'
4742: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4743: .&mt('Version [_1]',$prevvers).'</a>'
4744: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 4745: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 4746: .')');
4747: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4748: $r->print(
4749: ' <a href="/adm/diff?filename='.
4750: &Apache::lonnet::clutter($root.'.'.$extension).
4751: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4752: '" target="diffs">'.&mt('Diffs').'</a>');
4753: }
4754: $r->print('</span><br />');
1.329 droeschl 4755: }
1.571 raeburn 4756: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 4757: }
1.329 droeschl 4758: }
1.521 bisitz 4759: $r->print(
4760: &Apache::loncommon::end_data_table().
1.611 raeburn 4761: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4762: '</form>'
4763: );
1.329 droeschl 4764:
4765: &untiehash();
1.521 bisitz 4766: $r->print(&endContentScreen());
1.571 raeburn 4767: return;
1.329 droeschl 4768: }
4769:
4770: sub mark_hash_old {
4771: my $retie_hash=0;
4772: if ($hashtied) {
4773: $retie_hash=1;
4774: &untiehash();
4775: }
4776: &tiehash('write');
4777: $hash{'old'}=1;
4778: &untiehash();
4779: if ($retie_hash) { &tiehash(); }
4780: }
4781:
4782: sub is_hash_old {
4783: my $untie_hash=0;
4784: if (!$hashtied) {
4785: $untie_hash=1;
4786: &tiehash();
4787: }
4788: my $return=$hash{'old'};
4789: if ($untie_hash) { &untiehash(); }
4790: return $return;
4791: }
4792:
4793: sub changewarning {
4794: my ($r,$postexec,$message,$url)=@_;
4795: if (!&is_hash_old()) { return; }
4796: my $pathvar='folderpath';
4797: my $path=&escape($env{'form.folderpath'});
4798: if (!defined($url)) {
4799: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4800: }
4801: my $course_type = &Apache::loncommon::course_type();
4802: if (!defined($message)) {
4803: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4804: }
4805: $r->print("\n\n".
1.372 bisitz 4806: '<script type="text/javascript">'."\n".
4807: '// <![CDATA['."\n".
4808: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4809: '// ]]>'."\n".
1.369 bisitz 4810: '</script>'."\n".
1.375 tempelho 4811: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4812: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4813: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4814: &mt($message,' <input type="hidden" name="'.
4815: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4816: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4817: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4818: }
4819:
4820:
4821: sub init_breadcrumbs {
1.571 raeburn 4822: my ($form,$text,$help)=@_;
1.329 droeschl 4823: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4824: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4825: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4826: faq=>273,
4827: bug=>'Instructor Interface',
1.571 raeburn 4828: help => $help});
1.329 droeschl 4829: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4830: text=>$text,
4831: faq=>273,
4832: bug=>'Instructor Interface'});
4833: }
4834:
1.441 www 4835: # subroutine to list form elements
4836: sub create_list_elements {
4837: my @formarr = @_;
4838: my $list = '';
1.501 raeburn 4839: foreach my $button (@formarr){
4840: foreach my $picture (keys(%{$button})) {
4841: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4842: }
4843: }
4844: return $list;
4845: }
1.329 droeschl 4846:
1.441 www 4847: # subroutine to create ul from list elements
4848: sub create_form_ul {
4849: my $list = shift;
4850: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4851: return $ul;
4852: }
1.329 droeschl 4853:
1.442 www 4854: #
4855: # Start tabs
4856: #
4857:
4858: sub startContentScreen {
1.484 raeburn 4859: my ($mode) = @_;
4860: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4861: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4862: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4863: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4864: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
4865: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4866: } else {
1.549 raeburn 4867: $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 4868: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4869: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4870: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4871: }
4872: $output .= "\n".'</ul>'."\n";
4873: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4874: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4875: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4876: return $output;
1.442 www 4877: }
4878:
4879: #
4880: # End tabs
4881: #
4882:
4883: sub endContentScreen {
1.484 raeburn 4884: return '</div></div></div>';
1.442 www 4885: }
1.329 droeschl 4886:
1.446 www 4887: sub supplemental_base {
1.548 raeburn 4888: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4889: }
4890:
1.329 droeschl 4891: sub handler {
4892: my $r = shift;
4893: &Apache::loncommon::content_type($r,'text/html');
4894: $r->send_http_header;
4895: return OK if $r->header_only;
1.484 raeburn 4896:
4897: # get course data
1.408 raeburn 4898: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4899: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4900: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4901:
1.606 raeburn 4902: # get docroot
4903: my $londocroot = $r->dir_config('lonDocRoot');
4904:
1.484 raeburn 4905: # graphics settings
4906: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4907:
1.443 www 4908: #
1.329 droeschl 4909: # --------------------------------------------- Initialize help topics for this
4910: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4911: 'Adding_External_Resource','Navigate_Content',
4912: 'Adding_Folders','Docs_Overview', 'Load_Map',
4913: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 4914: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.571 raeburn 4915: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
1.572 raeburn 4916: 'Dropbox','Simple_Problem') {
1.329 droeschl 4917: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4918: }
4919: # Composite help files
4920: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4921: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4922: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4923: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4924: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4925: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4926: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4927: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4928: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4929: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 4930:
1.611 raeburn 4931: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 4932: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4933: unless ($r->uri eq '/adm/supplemental') {
4934: # does this user have privileges to modify content.
1.611 raeburn 4935: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
4936: $allowed = 1;
4937: $canedit = 1;
4938: $canview = 1;
4939: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
4940: $allowed = 1;
4941: $canview = 1;
4942: }
4943: }
4944: unless ($canedit) {
4945: $disabled = ' disabled="disabled"';
1.472 raeburn 4946: }
1.582 raeburn 4947: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
4948: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 4949: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 4950: &verifycontent($r);
4951: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4952: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4953: &list_symbs($r);
4954: } elsif ($allowed && $env{'form.docslog'}) {
4955: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4956: my $folder = $env{'form.folder'};
4957: if ($folder eq '') {
4958: $folder='default';
4959: }
1.611 raeburn 4960: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 4961: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 4962: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 4963: &checkversions($r,$canedit);
4964: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 4965: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4966: &dumpcourse($r);
1.611 raeburn 4967: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 4968: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4969: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4970: } else {
1.611 raeburn 4971: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 4972: $noendpage = 1;
4973: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
4974: if ($redirect) {
4975: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
4976: my $container = 'sequence';
4977: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
4978: $is_random_order,$container) =
4979: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
4980: my (@folders)=split('&',$env{'form.folderpath'});
4981: $env{'form.foldername'}=&unescape(pop(@folders));
4982: my $folder=pop(@folders);
4983: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
4984: $folder.'.'.$container);
4985: my $warning;
4986: if ($fatal) {
4987: if ($container eq 'page') {
4988: $warning = &mt('An error occurred retrieving the contents of the current page.');
4989: } else {
4990: $warning = &mt('An error occurred retrieving the contents of the current folder.');
4991: }
4992: } else {
4993: my $url = $redirect;
4994: my $srcfile = $londocroot.$url;
4995: $url =~ s{^/priv/}{/res/};
4996: my $targetfile = $londocroot.$url;
4997: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
4998: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
4999: $env{'form.folder'} = $folder;
5000: &snapshotbefore();
5001: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5002: my $ext = 'false';
5003: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5004: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5005: ':'.$ext.':normal:res';
5006: push(@LONCAPA::map::order,$newidx);
5007: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5008: 'string_yesno');
5009: &remember_parms($newidx,'hiddenresource','set','yes');
5010: ($errtext,$fatal) =
5011: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5012: &log_differences($plain);
5013: &mark_hash_old();
5014: $r->internal_redirect($redirect);
5015: return OK;
5016: }
5017: }
5018: }
5019: }
1.445 www 5020: #
5021: # Done catching special calls
1.484 raeburn 5022: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5023: # Get the parameters that may be needed
5024: #
5025: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5026: ['folderpath',
5027: 'forcesupplement','forcestandard',
1.510 raeburn 5028: 'tools','symb','command','supppath']);
1.445 www 5029:
5030: # standard=1: this is a "new-style" course with an uploaded map as top level
5031: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5032:
5033: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5034:
1.484 raeburn 5035: # Decide whether this should display supplemental or main content or utilities
1.445 www 5036: # supplementalflag=1: show supplemental documents
5037: # supplementalflag=0: show standard documents
1.484 raeburn 5038: # toolsflag=1: show utilities
1.445 www 5039:
1.561 raeburn 5040: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5041: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5042: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5043: $supplementalflag=0;
5044: }
5045: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5046: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5047: unless ($allowed) { $supplementalflag=1; }
5048: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5049: my $toolsflag=0;
5050: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5051:
1.329 droeschl 5052: my $script='';
5053: my $showdoc=0;
1.457 raeburn 5054: my $addentries = {};
1.475 raeburn 5055: my $container;
1.329 droeschl 5056: my $containertag;
1.508 raeburn 5057: my $pathitem;
1.598 raeburn 5058: my %ltitools;
1.329 droeschl 5059:
1.464 www 5060: # Do we directly jump somewhere?
1.466 www 5061:
1.525 raeburn 5062: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5063: if ($env{'form.symb'} ne '') {
1.522 raeburn 5064: $env{'form.folderpath'}=
5065: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
1.530 raeburn 5066: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5067: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5068: } elsif ($env{'form.supppath'} ne '') {
5069: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5070: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5071: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5072: }
1.472 raeburn 5073: } elsif ($env{'form.command'} eq 'editdocs') {
1.525 raeburn 5074: $env{'form.folderpath'} = 'default&'.
1.548 raeburn 5075: &escape(&mt('Main Content').':::::');
1.525 raeburn 5076: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5077: } elsif ($env{'form.command'} eq 'editsupp') {
1.525 raeburn 5078: $env{'form.folderpath'} = 'supplemental&'.
1.538 raeburn 5079: &escape('Supplemental Content');
1.525 raeburn 5080: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5081: } elsif ($env{'form.command'} eq 'contents') {
5082: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5083: } elsif ($env{'form.command'} eq 'home') {
5084: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5085: }
5086:
1.525 raeburn 5087:
1.445 www 5088: # Where do we store these for when we come back?
5089: my $stored_folderpath='docs_folderpath';
5090: if ($supplementalflag) {
5091: $stored_folderpath='docs_sup_folderpath';
5092: }
1.464 www 5093:
1.519 raeburn 5094: # No folderpath, and in edit mode, see if we have something stored
5095: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5096: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5097: {'folderpath' => 'scalar'});
1.523 raeburn 5098: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5099: undef($env{'form.folderpath'});
5100: }
1.329 droeschl 5101: }
1.446 www 5102:
5103: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5104: if (!$allowed) {
1.446 www 5105: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5106: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5107: }
5108: }
1.446 www 5109: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5110: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5111: $env{'form.folderpath'} = &supplemental_base()
5112: .'&'.
1.329 droeschl 5113: $env{'form.folderpath'};
5114: }
1.446 www 5115: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5116: unless ($env{'form.folderpath'}) {
1.446 www 5117: if ($supplementalflag) {
5118: $env{'form.folderpath'}=&supplemental_base();
5119: } else {
1.548 raeburn 5120: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
1.538 raeburn 5121: ':::::');
1.446 www 5122: }
1.472 raeburn 5123: }
1.446 www 5124:
1.445 www 5125: # Store this
1.484 raeburn 5126: unless ($toolsflag) {
1.510 raeburn 5127: if ($allowed) {
5128: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5129: {'folderpath' => 'scalar'});
1.510 raeburn 5130: }
1.519 raeburn 5131: my $folderpath;
1.484 raeburn 5132: if ($env{'form.folderpath'}) {
1.519 raeburn 5133: $folderpath = $env{'form.folderpath'};
5134: my (@folders)=split('&',$env{'form.folderpath'});
5135: $env{'form.foldername'}=&unescape(pop(@folders));
5136: if ($env{'form.foldername'} =~ /\:1$/) {
5137: $container = 'page';
5138: } else {
5139: $container = 'sequence';
5140: }
5141: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5142: } else {
1.519 raeburn 5143: if ($env{'form.folder'} eq '' ||
5144: $env{'form.folder'} eq 'supplemental') {
5145: $folderpath='default&'.
1.548 raeburn 5146: &escape(&mt('Main Content').':::::');
1.484 raeburn 5147: }
5148: }
1.519 raeburn 5149: $containertag = '<input type="hidden" name="folderpath" value="" />';
5150: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5151: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5152: $showdoc='/'.$1;
5153: }
5154: if ($showdoc) { # got called in sequence from course
5155: $allowed=0;
5156: } else {
1.611 raeburn 5157: if ($canedit) {
1.484 raeburn 5158: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5159: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5160: }
5161: }
1.329 droeschl 5162: }
5163:
1.344 bisitz 5164: # get personal data
1.329 droeschl 5165: my $uname=$env{'user.name'};
5166: my $udom=$env{'user.domain'};
5167: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5168:
5169: if ($allowed) {
1.484 raeburn 5170: if ($toolsflag) {
5171: $script .= &inject_data_js();
5172: my ($home,$other,%outhash)=&authorhosts();
5173: if (!$home && $other) {
5174: my @hosts;
5175: foreach my $aurole (keys(%outhash)) {
5176: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5177: push(@hosts,$outhash{$aurole});
5178: }
5179: }
5180: $script .= &dump_switchserver_js(@hosts);
5181: }
1.458 raeburn 5182: } else {
1.570 raeburn 5183: my $tid = 1;
1.484 raeburn 5184: my @tabids;
5185: if ($supplementalflag) {
5186: @tabids = ('002','ee2','ff2');
1.570 raeburn 5187: $tid = 2;
1.484 raeburn 5188: } else {
5189: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5190: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5191: unshift(@tabids,'001');
5192: push(@tabids,('dd1','ee1'));
5193: }
1.458 raeburn 5194: }
1.484 raeburn 5195: my $tabidstr = join("','",@tabids);
1.598 raeburn 5196: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5197: my $posslti = keys(%ltitools);
1.606 raeburn 5198: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.611 raeburn 5199: $londocroot,$canedit).
1.484 raeburn 5200: &history_tab_js().
5201: &inject_data_js().
1.570 raeburn 5202: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5203: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5204: $addentries = {
1.485 raeburn 5205: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5206: };
1.458 raeburn 5207: }
1.538 raeburn 5208: $script .= &paste_popup_js();
1.501 raeburn 5209: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5210: &mt('Switch server?');
5211:
5212:
1.329 droeschl 5213: }
5214: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5215: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5216: .'// <![CDATA['."\n"
5217: .$script."\n"
5218: .'// ]]>'."\n"
1.595 musolffc 5219: .'</script>'."\n"
5220: .'<script type="text/javascript"
5221: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5222:
5223: # Breadcrumbs
5224: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5225:
5226: if ($showdoc) {
5227: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5228: {'force_register' => $showdoc,}));
1.571 raeburn 5229: } elsif ($toolsflag) {
1.611 raeburn 5230: my ($breadtext,$breadtitle);
5231: $breadtext = "$crstype Contents";
5232: if ($canedit) {
5233: $breadtitle = 'Editing '.$crstype.' Contents';
5234: } else {
5235: $breadtext .= ' (View-only mode)';
5236: $breadtitle = 'Viewing '.$crstype.' Contents';
5237: }
1.571 raeburn 5238: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5239: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5240: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5241: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5242: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5243: $breadtitle)
1.571 raeburn 5244: );
1.510 raeburn 5245: } elsif ($r->uri eq '/adm/supplemental') {
5246: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5247: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5248: {'bread_crumbs' => $brcrum,}));
5249: } else {
1.611 raeburn 5250: my ($breadtext,$breadtitle,$helpitem);
5251: $breadtext = "$crstype Contents";
5252: if ($canedit) {
5253: $breadtitle = 'Editing '.$crstype.' Contents';
5254: $helpitem = 'Docs_Adding_Course_Doc';
5255: } else {
5256: $breadtext .= ' (View-only mode)';
5257: $breadtitle = 'Viewing '.$crstype.' Contents';
5258: $helpitem = 'Docs_Viewing_Course_Doc';
5259: }
1.392 raeburn 5260: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5261: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5262: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5263: {'add_entries' => $addentries}
5264: )
1.392 raeburn 5265: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5266: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5267: $breadtitle,
5268: $helpitem)
1.392 raeburn 5269: );
5270: }
1.364 bisitz 5271:
1.329 droeschl 5272: my %allfiles = ();
5273: my %codebase = ();
1.440 raeburn 5274: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5275: if ($canedit) {
1.329 droeschl 5276: if (($env{'form.uploaddoc.filename'}) &&
5277: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5278: my $context = $1;
5279: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5280: undef($hadchanges);
1.440 raeburn 5281: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5282: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5283: if ($hadchanges) {
5284: &mark_hash_old();
5285: }
1.440 raeburn 5286: $r->print($upload_output);
5287: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5288: # Process file upload - phase two - upload embedded objects
5289: $uploadphase = 'check_embedded';
5290: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5291: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5292: $env{'form.newidx'});
5293: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5294: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5295: my ($destination,$dir_root) = &embedded_destination();
5296: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5297: my $actionurl = '/adm/coursedocs';
5298: my ($result,$flag) =
5299: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5300: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5301: $actionurl);
5302: $r->print($result.&return_to_editor());
5303: } elsif ($env{'form.phase'} eq 'check_embedded') {
5304: # Process file upload - phase three - modify references in HTML file
5305: $uploadphase = 'modified_orightml';
5306: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5307: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5308: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5309: my $result =
5310: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5311: $docuname,$docudom,undef,
5312: $dir_root);
5313: $r->print($result.&return_to_editor());
1.476 raeburn 5314: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5315: $uploadphase = 'decompress_phase_one';
5316: $r->print(&decompression_phase_one().
5317: &return_to_editor());
5318: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5319: $uploadphase = 'decompress_phase_two';
5320: $r->print(&decompression_phase_two().
5321: &return_to_editor());
1.329 droeschl 5322: }
5323: }
5324:
1.484 raeburn 5325: if ($allowed && $toolsflag) {
5326: $r->print(&startContentScreen('tools'));
1.611 raeburn 5327: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5328: $r->print(&endContentScreen());
5329: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5330: # -----------------------------------------------------------------------------
5331: my %lt=&Apache::lonlocal::texthash(
5332: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5333: 'upfi' => 'Upload File',
1.553 raeburn 5334: 'upld' => 'Upload Content',
1.329 droeschl 5335: 'srch' => 'Search',
5336: 'impo' => 'Import',
1.487 raeburn 5337: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5338: 'impm' => 'Import from Assembled Map',
1.606 raeburn 5339: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5340: 'extr' => 'External Resource',
5341: 'extt' => 'External Tool',
1.329 droeschl 5342: 'selm' => 'Select Map',
5343: 'load' => 'Load Map',
5344: 'newf' => 'New Folder',
5345: 'newp' => 'New Composite Page',
5346: 'syll' => 'Syllabus',
1.425 raeburn 5347: 'navc' => 'Table of Contents',
1.343 biermanm 5348: 'sipa' => 'Simple Course Page',
1.329 droeschl 5349: 'sipr' => 'Simple Problem',
1.534 raeburn 5350: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5351: 'stpr' => 'Standard Problem',
5352: 'news' => 'New sub-directory',
5353: 'crpr' => 'Create Problem',
1.329 droeschl 5354: 'drbx' => 'Drop Box',
1.451 www 5355: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5356: 'bull' => 'Discussion Board',
1.347 weissno 5357: 'mypi' => 'My Personal Information Page',
1.353 weissno 5358: 'grpo' => 'Group Portfolio',
1.329 droeschl 5359: 'rost' => 'Course Roster',
1.528 raeburn 5360: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5361: 'imsf' => 'IMS Upload',
5362: 'imsl' => 'Upload IMS package',
1.501 raeburn 5363: 'cms' => 'Origin of IMS package',
5364: 'se' => 'Select',
1.329 droeschl 5365: 'file' => 'File',
5366: 'title' => 'Title',
1.606 raeburn 5367: 'addp' => 'Add Placeholder to course?',
5368: 'uste' => 'Use Template?',
5369: 'fnam' => 'File Name:',
5370: 'loca' => 'Location:',
5371: 'dire' => 'Directory:',
5372: 'cate' => 'Category:',
5373: 'tmpl' => 'Template:',
1.329 droeschl 5374: 'comment' => 'Comment',
1.403 raeburn 5375: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5376: 'bb5' => 'Blackboard 5',
5377: 'bb6' => 'Blackboard 6',
5378: 'angel5' => 'ANGEL 5.5',
5379: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5380: 'yes' => 'Yes',
5381: 'no' => 'No',
1.611 raeburn 5382: 'er' => 'Editing rights unavailable for your current role',
1.577 bisitz 5383: );
1.329 droeschl 5384: # -----------------------------------------------------------------------------
1.595 musolffc 5385:
5386: # Calculate free quota space for a user or course. A javascript function checks
5387: # file size to determine if upload should be allowed.
5388: my $quotatype = 'unofficial';
5389: if ($crstype eq 'Community') {
1.601 raeburn 5390: $quotatype = 'community';
5391: } elsif ($crstype eq 'Placement') {
5392: $quotatype = 'placement';
1.595 musolffc 5393: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5394: $quotatype = 'official';
5395: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5396: $quotatype = 'textbook';
5397: }
5398: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5399: 'course',$quotatype); # expressed in MB
5400: my $current_disk_usage = 0;
5401: foreach my $subdir ('docs','supplemental') {
5402: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5403: "userfiles/$subdir",1); # expressed in kB
5404: }
5405: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5406: my $usage = $current_disk_usage/1024; # in MB
5407: my $quota = $disk_quota;
5408: my $percent;
5409: if ($disk_quota == 0) {
5410: $percent = 100.0;
5411: } else {
5412: $percent = 100*($current_disk_usage/$disk_quota);
5413: }
5414: $usage = sprintf("%.2f",$usage);
5415: $quota = sprintf("%.2f",$quota);
5416: $percent = sprintf("%.0f",$percent);
5417: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5418: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5419:
1.329 droeschl 5420: my $fileupload=(<<FIUP);
1.605 raeburn 5421: $quotainfo
1.329 droeschl 5422: $lt{'file'}:<br />
1.611 raeburn 5423: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5424: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5425: FIUP
5426:
5427: my $checkbox=(<<CHBO);
5428: <!-- <label>$lt{'parse'}?
5429: <input type="checkbox" name="parserflag" />
5430: </label> -->
5431: <label>
1.611 raeburn 5432: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5433: </label>
5434: CHBO
1.501 raeburn 5435: my $imsfolder = $env{'form.folder'};
5436: if ($imsfolder eq '') {
5437: $imsfolder = 'default';
5438: }
5439: my $imspform=(<<IMSFORM);
5440: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5441: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5442: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5443: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5444: <legend>$lt{'imsf'}</legend>
5445: $fileupload
5446: <br />
5447: <p>
5448: $lt{'cms'}:
1.611 raeburn 5449: <select name="source" $disabled>
1.501 raeburn 5450: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5451: <option value="bb5">$lt{'bb5'}</option>
5452: <option value="bb6">$lt{'bb6'}</option>
5453: <option value="angel5">$lt{'angel5'}</option>
5454: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5455: </select>
5456: <input type="hidden" name="folder" value="$imsfolder" />
5457: </p>
5458: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5459: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5460: </fieldset>
5461: </form>
5462: IMSFORM
1.329 droeschl 5463:
5464: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5465: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5466: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5467: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5468: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5469: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5470: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5471: $fileupload
1.329 droeschl 5472: <br />
5473: $lt{'title'}:<br />
1.611 raeburn 5474: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5475: $pathitem
1.329 droeschl 5476: <input type="hidden" name="cmd" value="upload_default" />
5477: <br />
1.458 raeburn 5478: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5479: $checkbox
5480: </span>
1.501 raeburn 5481: <br clear="all" />
1.611 raeburn 5482: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5483: </fieldset>
5484: </form>
1.383 tempelho 5485: FUFORM
1.329 droeschl 5486:
1.611 raeburn 5487: my $mapimportjs;
5488: if ($canedit) {
5489: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5490: } else {
5491: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5492: }
1.502 raeburn 5493: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5494: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5495: $lt{'impm'}</a>$help{'Load_Map'}
5496: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5497: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5498: <legend>$lt{'impm'}</legend>
1.371 tempelho 5499: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5500: $lt{'copm'}<br />
5501: <span class="LC_nobreak">
5502: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5503: onfocus="this.blur();$mapimportjs" $disabled />
5504: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5505: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5506: </fieldset>
5507: </form>
5508:
1.383 tempelho 5509: SEDFFORM
1.606 raeburn 5510: my $importcrsresform;
1.608 raeburn 5511: my ($numdirs,$pickfile) =
5512: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5513: "resize_scrollbox('contentscroll','1','0');",
5514: undef,'res');
1.606 raeburn 5515: if ($pickfile) {
5516: $importcrsresform=(<<CRSFORM);
5517: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5518: $lt{'imcr'}</a>$help{'Course_Resources'}
5519: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5520: <fieldset id="importcrsresform" style="display: none;">
5521: <legend>$lt{'imcr'}</legend>
5522: <input type="hidden" name="active" value="bb" />
5523: $pickfile
5524: <p>
1.611 raeburn 5525: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5526: </p>
5527: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5528: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5529: </fieldset>
5530: </form>
5531: CRSFORM
5532: }
5533:
1.611 raeburn 5534: my $fromstoredjs;
5535: if ($canedit) {
5536: $fromstoredjs = 'open_StoredLinks_Import()';
5537: } else {
5538: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5539: }
5540:
1.502 raeburn 5541: my @importpubforma = (
1.508 raeburn 5542: { '<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 5543: { '<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 5544: { '<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 5545: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5546: );
5547: if ($pickfile) {
5548: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5549: }
1.502 raeburn 5550: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5551: my $extresourcesform =
5552: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5553: $help{'Adding_External_Resource'},
5554: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5555: my $exttoolform =
5556: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5557: $help{'Adding_External_Tool'},undef,
5558: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5559: \%ltitools,$disabled);
1.329 droeschl 5560: if ($allowed) {
1.492 raeburn 5561: my $folder = $env{'form.folder'};
5562: if ($folder eq '') {
5563: $folder='default';
5564: }
1.538 raeburn 5565: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5566: if ($output) {
5567: $r->print($output);
5568: }
1.337 ehlerst 5569: $r->print(<<HIDDENFORM);
5570: <form name="renameform" method="post" action="/adm/coursedocs">
5571: <input type="hidden" name="title" />
5572: <input type="hidden" name="cmd" />
5573: <input type="hidden" name="markcopy" />
5574: <input type="hidden" name="copyfolder" />
5575: $containertag
5576: </form>
1.484 raeburn 5577:
1.337 ehlerst 5578: HIDDENFORM
1.508 raeburn 5579: $r->print(&makesimpleeditform($pathitem)."\n".
5580: &makedocslogform($pathitem."\n".
1.484 raeburn 5581: '<input type="hidden" name="folder" value="'.
5582: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5583: }
1.442 www 5584:
5585: # Generate the tabs
1.510 raeburn 5586: my ($mode,$needs_end);
1.472 raeburn 5587: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 5588: my @folders = split('&',$env{'form.folderpath'});
5589: unless (@folders > 2) {
5590: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5591: $needs_end = 1;
5592: }
1.472 raeburn 5593: } else {
1.484 raeburn 5594: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 5595: $needs_end = 1;
1.472 raeburn 5596: }
1.443 www 5597:
1.442 www 5598: #
5599:
5600: my $savefolderpath;
5601:
1.395 raeburn 5602: if ($allowed) {
1.329 droeschl 5603: my $folder=$env{'form.folder'};
1.443 www 5604: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 5605: $folder='default';
1.356 tempelho 5606: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 5607: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 5608: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5609: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5610: }
5611: my $postexec='';
5612: if ($folder eq 'default') {
1.372 bisitz 5613: $r->print('<script type="text/javascript">'."\n"
5614: .'// <![CDATA['."\n"
5615: .'this.window.name="loncapaclient";'."\n"
5616: .'// ]]>'."\n"
5617: .'</script>'."\n"
1.369 bisitz 5618: );
1.329 droeschl 5619: } else {
5620: #$postexec='self.close();';
5621: }
1.504 raeburn 5622: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5623: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5624: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5625:
5626: my $newnavform=(<<NNFORM);
5627: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 5628: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5629: $pathitem
1.329 droeschl 5630: <input type="hidden" name="importdetail"
5631: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 5632: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5633: $help{'Navigate_Content'}
5634: </form>
5635: NNFORM
5636: my $newsmppageform=(<<NSPFORM);
5637: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 5638: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5639: $pathitem
1.329 droeschl 5640: <input type="hidden" name="importdetail" value="" />
1.423 onken 5641: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5642: $help{'Simple Page'}
1.329 droeschl 5643: </form>
5644: NSPFORM
5645:
5646: my $newsmpproblemform=(<<NSPROBFORM);
5647: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5648: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5649: $pathitem
1.329 droeschl 5650: <input type="hidden" name="importdetail" value="" />
1.423 onken 5651: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 5652: $help{'Simple_Problem'}
1.329 droeschl 5653: </form>
5654:
5655: NSPROBFORM
5656:
5657: my $newdropboxform=(<<NDBFORM);
5658: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5659: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5660: $pathitem
1.329 droeschl 5661: <input type="hidden" name="importdetail" value="" />
1.423 onken 5662: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 5663: $help{'Dropbox'}
1.344 bisitz 5664: </form>
1.329 droeschl 5665: NDBFORM
5666:
5667: my $newexuploadform=(<<NEXUFORM);
5668: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5669: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5670: $pathitem
1.329 droeschl 5671: <input type="hidden" name="importdetail" value="" />
1.423 onken 5672: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5673: $help{'Score_Upload_Form'}
5674: </form>
5675: NEXUFORM
5676:
5677: my $newbulform=(<<NBFORM);
5678: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 5679: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5680: $pathitem
1.329 droeschl 5681: <input type="hidden" name="importdetail" value="" />
1.423 onken 5682: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5683: $help{'Bulletin Board'}
5684: </form>
5685: NBFORM
5686:
5687: my $newaboutmeform=(<<NAMFORM);
5688: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 5689: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5690: $pathitem
1.329 droeschl 5691: <input type="hidden" name="importdetail"
5692: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 5693: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5694: $help{'My Personal Information Page'}
1.329 droeschl 5695: </form>
5696: NAMFORM
5697:
5698: my $newaboutsomeoneform=(<<NASOFORM);
5699: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 5700: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5701: $pathitem
1.329 droeschl 5702: <input type="hidden" name="importdetail" value="" />
1.423 onken 5703: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5704: </form>
5705: NASOFORM
5706:
5707: my $newrosterform=(<<NROSTFORM);
5708: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 5709: <input type="hidden" name="active" value="dd" />
1.508 raeburn 5710: $pathitem
1.329 droeschl 5711: <input type="hidden" name="importdetail"
5712: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 5713: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 5714: $help{'Course_Roster'}
1.329 droeschl 5715: </form>
5716: NROSTFORM
5717:
1.534 raeburn 5718: my $newwebpage;
5719: if ($folder =~ /^default_?(\d*)$/) {
5720: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5721: if ($1) {
5722: $newwebpage .= $1;
5723: } else {
5724: $newwebpage .= 'default';
5725: }
5726: $newwebpage .= '/new.html';
5727: }
5728: my $newwebpageform =(<<NWEBFORM);
5729: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 5730: <input type="hidden" name="active" value="ee" />
1.534 raeburn 5731: $pathitem
5732: <input type="hidden" name="importdetail" value="$newwebpage" />
5733: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5734: $help{'Web_Page'}
1.534 raeburn 5735: </form>
5736: NWEBFORM
1.604 raeburn 5737:
1.606 raeburn 5738: my @ids=&Apache::lonnet::current_machine_ids();
5739: my %select_menus;
5740: my $numauthor = 0;
5741: my $numcrsdirs = 0;
5742: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
5743: if ($env{'user.author'}) {
5744: $numauthor ++;
5745: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
5746: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
5747: my $is_home = 1;
5748: my %subdirs;
1.608 raeburn 5749: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5750: $select_menus{'author'}->{'default'} = '/';
5751: $select_menus{'author'}->{'select2'}->{'/'} = '/';
5752: my @ordered = ('/');
5753: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5754: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
5755: push(@ordered,$relpath);
5756: }
5757: $select_menus{'author'}->{'order'} = \@ordered;
5758: } else {
5759: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
5760: $select_menus{'author'}->{'default'} = 'switch';
5761: $select_menus{'author'}->{'order'} = ['switch'];
5762: }
5763: }
5764: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
5765: ['active'],['ca','aa']);
5766: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
5767: my %by_roletype;
5768: if (keys(%roleshash)) {
5769: foreach my $entry (keys(%roleshash)) {
5770: my ($auname,$audom,$roletype) = split(/:/,$entry);
5771: my $key = $entry;
5772: $key =~ s/:/___/g;
5773: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
5774: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
5775: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
5776: if (grep(/^\Q$rolehome\E$/,@ids)) {
5777: my $is_home = 1;
5778: my (%subdirs,@ordered);
5779: my $toppath="/priv/$audom/$auname";
1.608 raeburn 5780: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5781: $select_menus{$key}->{'default'} = '/';
5782: $select_menus{$key}->{'select2'}->{'/'} = '/';
5783: my @ordered = ('/');
5784: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5785: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
5786: push(@ordered,$relpath);
5787: }
5788: $select_menus{$key}->{'order'} = \@ordered;
5789: } else {
5790: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
5791: $select_menus{$key}->{'default'} = 'switch';
5792: $select_menus{$key}->{'order'} = ['switch'];
5793: }
5794: $numauthor ++;
5795: }
5796: }
5797: my ($pickdir,$showtitle);;
5798: if ($numauthor) {
5799: my @order;
5800: my $defrole;
5801: if ($env{'user.author'}) {
5802: push(@order,'author');
5803: $defrole = 'author';
5804: }
5805: if (keys(%by_roletype)) {
5806: foreach my $possrole ('ca','aa') {
5807: if (ref($by_roletype{$possrole}) eq 'HASH') {
5808: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
5809: unless ($defrole) {
5810: $defrole = $author;
5811: }
5812: push(@order,$author.'___'.$possrole);
5813: }
5814: }
5815: }
5816: }
5817: $select_menus{'course'}->{'text'} = &mt('Course Resource');
5818: if (grep(/^\Q$crshome\E$/,@ids)) {
5819: my $is_home = 1;
5820: my %subdirs;
5821: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 5822: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5823: $numcrsdirs = keys(%subdirs);
5824: $select_menus{'course'}->{'default'} = '/';
5825: $select_menus{'course'}->{'select2'}->{'/'} = '/';
5826: my @ordered = ('/');
5827: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
5828: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
5829: push(@ordered,$relpath);
5830: }
5831: $select_menus{'course'}->{'order'} = \@ordered;
5832: } else {
5833: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
5834: $select_menus{'course'}->{'default'} = 'switch';
5835: $select_menus{'course'}->{'order'} = ['switch'];
5836: }
5837: push(@order,'course');
5838: $pickdir = $lt{'loca'}.
5839: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
5840: $defrole,'authorrole','authorpath',
5841: \%select_menus,\@order,'toggleCrsResTitle();',
5842: '','priv').'<br />';
5843: $showtitle = 'none';
5844: } else {
5845: my $is_home;
5846: $showtitle = 'inline';
5847: if (grep(/^\Q$crshome\E$/,@ids)) {
5848: $is_home = 1;
5849: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
5850: my $toppath="/priv/$coursedom/$coursenum'}";
5851: my %subdirs;
1.608 raeburn 5852: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 5853: $numcrsdirs = keys(%subdirs);
5854: if ($numcrsdirs) {
5855: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
5856: '<option value="/">/</option>'."\n";
5857: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 5858: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 5859: }
5860: $pickdir .= '</select>';
5861: } else {
5862: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
5863: }
5864: }
5865: }
5866:
5867: my %seltemplate_menus;
5868: my @files = &Apache::lonhomework::get_template_list('problem');
5869: my @noexamplelink = ('blank.problem','blank.library','script.library');
5870: my $currentcategory = '';
5871: my @ordered = ('');
5872: my %templatehelp;
5873: my $defcategory = '';
5874: my @catorder = ($defcategory);
5875: $seltemplate_menus{$defcategory}->{'order'} = [''];
5876: $seltemplate_menus{$defcategory}->{'text'} = '';
5877: foreach my $file (@files) {
5878: if (ref($file) eq 'ARRAY') {
5879: my ($path,$title,$category,$help) = @{$file};
5880: next if ($title !~ /\S/);
5881: if (&js_escape($category) ne $currentcategory) {
5882: $currentcategory = &js_escape($category);
5883: push(@catorder,&js_escape($currentcategory));
5884: $seltemplate_menus{$currentcategory}->{'text'} = $category;
5885: $seltemplate_menus{$currentcategory}->{'default'} = '';
5886: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
5887: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
5888: }
5889: if ($path) {
5890: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
5891: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
5892: if ($help) {
5893: $templatehelp{$path} = $help;
5894: }
5895: }
5896: }
5897: }
5898:
5899: my $templates = $lt{'cate'}.' '.
5900: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
5901: $defcategory,'tempcategory','template',
5902: \%seltemplate_menus,\@catorder,
5903: "resize_scrollbox('contentscroll','1','0');",
5904: "toggleExampleText();",'template').'<br />';
5905: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
5906: '<span id="newresexample">'.&mt('Example').'<span></a>';
5907: my $crsresform=(<<RESFORM);
5908: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
5909: $lt{'stpr'}</a>$help{'Course_Resource'}
5910: <form action="/adm/coursedocs" method="post" name="courseresform">
5911: <fieldset id="crsresform" style="display:none;">
5912: <legend>$lt{'stpr'}</legend>
5913: <input type="hidden" name="active" value="ee" />
5914: <p>
5915: $pickdir
5916: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 5917: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 5918:
1.611 raeburn 5919: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 5920: </span><span id="newsubdir"></span>
5921: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
5922: </p>
5923: $lt{'fnam'}
1.611 raeburn 5924: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 5925: <p>
5926: <div id="newresource" style="display:$showtitle">
5927: $lt{'addp'}
1.611 raeburn 5928: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 5929: $lt{'no'}</label>
1.611 raeburn 5930: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 5931: $lt{'yes'}</label>
5932: <span id="newrestitle"></span>
1.611 raeburn 5933: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 5934: </div>
5935: </p>
5936: <p>
5937: $lt{'uste'}
1.611 raeburn 5938: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 5939: $lt{'no'}</label>
1.611 raeburn 5940: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 5941: $lt{'yes'}</label>
5942: <div id="newrestemplate" style="display:none">
5943: $templates
5944: $templatepreview
5945: </div>
5946: </p>
5947: <span class="LC_nobreak">
5948: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 5949: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 5950: </span>
5951: </fieldset>
5952: </form>
5953:
5954: RESFORM
1.534 raeburn 5955:
1.342 ehlerst 5956: my $specialdocumentsform;
1.383 tempelho 5957: my @specialdocumentsforma;
1.451 www 5958: my $gradingform;
5959: my @gradingforma;
5960: my $communityform;
5961: my @communityforma;
1.351 ehlerst 5962: my $newfolderform;
1.390 tempelho 5963: my $newfolderb;
1.342 ehlerst 5964:
1.451 www 5965: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5966:
1.329 droeschl 5967: my $newpageform=(<<NPFORM);
5968: <form action="/adm/coursedocs" method="post" name="newpage">
5969: <input type="hidden" name="folderpath" value="$path" />
5970: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 5971: <input type="hidden" name="active" value="ee" />
1.423 onken 5972: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5973: $help{'Adding_Pages'}
1.329 droeschl 5974: </form>
5975: NPFORM
1.390 tempelho 5976:
5977:
1.351 ehlerst 5978: $newfolderform=(<<NFFORM);
1.329 droeschl 5979: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 5980: $pathitem
1.329 droeschl 5981: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 5982: <input type="hidden" name="active" value="" />
1.422 onken 5983: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5984: </form>
5985: NFFORM
5986:
5987: my $newsylform=(<<NSYLFORM);
5988: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 5989: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5990: $pathitem
1.329 droeschl 5991: <input type="hidden" name="importdetail"
5992: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 5993: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5994: $help{'Syllabus'}
1.383 tempelho 5995:
1.329 droeschl 5996: </form>
5997: NSYLFORM
1.364 bisitz 5998:
1.329 droeschl 5999: my $newgroupfileform=(<<NGFFORM);
6000: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6001: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6002: $pathitem
1.329 droeschl 6003: <input type="hidden" name="importdetail"
6004: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6005: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6006: $help{'Group Portfolio'}
1.329 droeschl 6007: </form>
6008: NGFFORM
1.383 tempelho 6009: @specialdocumentsforma=(
1.421 onken 6010: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.611 raeburn 6011: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="makenew(document.newsyl);" />'=>$newsylform},
6012: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6013: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6014: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6015: );
6016: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6017:
1.434 raeburn 6018:
6019: my @importdoc = (
1.519 raeburn 6020: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6021: );
1.598 raeburn 6022: if (keys(%ltitools)) {
6023: push(@importdoc,
6024: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
6025: );
6026: }
1.519 raeburn 6027: unless ($container eq 'page') {
6028: push(@importdoc,
6029: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6030: );
6031: }
6032: push(@importdoc,
1.558 raeburn 6033: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6034: );
1.501 raeburn 6035: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6036:
1.451 www 6037: @gradingforma=(
6038: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6039: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6040: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6041: {'<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 6042: );
6043: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6044:
6045: @communityforma=(
6046: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6047: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6048: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6049: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6050: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6051: );
6052: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6053:
1.330 tempelho 6054: my %orderhash = (
1.553 raeburn 6055: 'aa' => ['Upload',$fileuploadform],
6056: 'bb' => ['Import',$importpubform],
6057: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6058: );
1.519 raeburn 6059: unless ($container eq 'page') {
1.434 raeburn 6060: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6061: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6062: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6063: }
6064:
1.341 ehlerst 6065: $hadchanges=0;
1.484 raeburn 6066: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6067: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.611 raeburn 6068: $supplementalflag,\%orderhash,$iconpath,$pathitem,\%ltitools,$canedit);
1.443 www 6069: if ($error) {
6070: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6071: }
6072: if ($hadchanges) {
6073: &mark_hash_old();
6074: }
1.341 ehlerst 6075:
1.443 www 6076: &changewarning($r,'');
6077: }
1.458 raeburn 6078: }
1.442 www 6079:
1.443 www 6080: # Supplemental documents start here
6081:
1.329 droeschl 6082: my $folder=$env{'form.folder'};
1.443 www 6083: unless ($supplementalflag) {
1.329 droeschl 6084: $folder='supplemental';
6085: }
6086: if ($folder =~ /^supplemental$/ &&
6087: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6088: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6089: } elsif ($allowed) {
1.356 tempelho 6090: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6091: }
1.508 raeburn 6092: $pathitem = '<input type="hidden" name="folderpath" value="'.
6093: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6094: if ($allowed) {
6095: my $folderseq=
1.504 raeburn 6096: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6097:
6098: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6099: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6100: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6101: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6102: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6103: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6104: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6105: $fileupload
6106: <br />
6107: <br />
6108: <span class="LC_nobreak">
6109: $checkbox
6110: </span>
6111: <br /><br />
6112: $lt{'comment'}:<br />
1.383 tempelho 6113: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6114: <br />
1.508 raeburn 6115: $pathitem
1.329 droeschl 6116: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6117: <input type='submit' value="$lt{'upld'}" />
6118: </form>
1.329 droeschl 6119: SUPDOCFORM
6120:
6121: my $supnewfolderform=(<<SNFFORM);
6122: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6123: <input type="hidden" name="active" value="" />
1.508 raeburn 6124: $pathitem
1.329 droeschl 6125: <input type="hidden" name="importdetail" value="" />
1.423 onken 6126: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6127: $help{'Adding_Folders'}
1.329 droeschl 6128: </form>
6129: SNFFORM
1.383 tempelho 6130:
1.510 raeburn 6131: my $supextform =
6132: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6133: $help{'Adding_External_Resource'},
6134: undef,undef,undef,undef,undef,undef,
6135: $disabled);
1.329 droeschl 6136:
1.598 raeburn 6137: my $supexttoolform =
6138: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6139: $help{'Adding_External_Tool'},
6140: undef,undef,'tool',$coursedom,
1.611 raeburn 6141: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6142:
1.329 droeschl 6143: my $supnewsylform=(<<SNSFORM);
6144: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6145: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6146: $pathitem
1.329 droeschl 6147: <input type="hidden" name="importdetail"
6148: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6149: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6150: $help{'Syllabus'}
6151: </form>
6152: SNSFORM
6153:
6154: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6155: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6156: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6157: $pathitem
1.329 droeschl 6158: <input type="hidden" name="importdetail"
6159: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6160: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6161: $help{'My Personal Information Page'}
1.329 droeschl 6162: </form>
6163: SNAMFORM
6164:
1.534 raeburn 6165: my $supwebpage;
6166: if ($folder =~ /^supplemental_?(\d*)$/) {
6167: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6168: if ($1) {
6169: $supwebpage .= $1;
6170: } else {
6171: $supwebpage .= 'default';
6172: }
6173: $supwebpage .= '/new.html';
6174: }
6175: my $supwebpageform =(<<SWEBFORM);
6176: <form action="/adm/coursedocs" method="post" name="supwebpage">
6177: <input type="hidden" name="active" value="cc" />
6178: $pathitem
6179: <input type="hidden" name="importdetail" value="$supwebpage" />
6180: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6181: $help{'Web_Page'}
1.534 raeburn 6182: </form>
6183: SWEBFORM
6184:
1.333 muellerd 6185:
1.383 tempelho 6186: my @specialdocs = (
1.611 raeburn 6187: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="makenew(document.supnewsyl);" />'
1.417 droeschl 6188: =>$supnewsylform},
1.611 raeburn 6189: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6190: =>$supnewaboutmeform},
1.534 raeburn 6191: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6192:
1.383 tempelho 6193: );
1.417 droeschl 6194: my @supimportdoc = (
1.515 raeburn 6195: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6196: =>$supextform});
6197: if (keys(%ltitools)) {
6198: push(@supimportdoc,
6199: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
6200: =>$supexttoolform});
6201: }
6202: push(@supimportdoc,
6203: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6204: =>$supupdocform},
1.598 raeburn 6205: );
1.501 raeburn 6206:
6207: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6208: my %suporderhash = (
1.390 tempelho 6209: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6210: 'ee' => ['Upload',$supupdocform],
6211: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6212: );
1.443 www 6213: if ($supplementalflag) {
1.458 raeburn 6214: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.611 raeburn 6215: $supplementalflag,\%suporderhash,$iconpath,$pathitem,\%ltitools,$canedit);
1.443 www 6216: if ($error) {
6217: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6218: } else {
6219: if ($suppchanges) {
6220: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6221: my @ids=&Apache::lonnet::current_machine_ids();
6222: foreach my $server (keys(%servers)) {
6223: next if (grep(/^\Q$server\E$/,@ids));
6224: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6225: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6226: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6227: }
6228: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6229: undef($suppchanges);
6230: }
6231: }
1.393 raeburn 6232: }
1.443 www 6233: } elsif ($supplementalflag) {
1.458 raeburn 6234: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.611 raeburn 6235: $supplementalflag,'',$iconpath,$pathitem,$canedit);
1.393 raeburn 6236: if ($error) {
6237: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6238: }
1.393 raeburn 6239: }
1.389 tempelho 6240:
1.510 raeburn 6241: if ($needs_end) {
6242: $r->print(&endContentScreen());
6243: }
1.383 tempelho 6244:
1.329 droeschl 6245: if ($allowed) {
6246: $r->print('
6247: <form method="post" name="extimport" action="/adm/coursedocs">
6248: <input type="hidden" name="title" />
6249: <input type="hidden" name="url" />
6250: <input type="hidden" name="useform" />
6251: <input type="hidden" name="residx" />
6252: </form>');
6253: }
1.484 raeburn 6254: } elsif ($showdoc) {
1.329 droeschl 6255: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6256: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6257: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6258: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6259: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6260: }
6261: }
1.606 raeburn 6262: unless ($noendpage) {
6263: $r->print(&Apache::loncommon::end_page());
6264: }
1.329 droeschl 6265: return OK;
1.364 bisitz 6266: }
1.329 droeschl 6267:
1.440 raeburn 6268: sub embedded_form_elems {
6269: my ($phase,$primaryurl,$newidx) = @_;
6270: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6271: return <<STATE;
6272: <input type="hidden" name="folderpath" value="$folderpath" />
6273: <input type="hidden" name="cmd" value="upload_embedded" />
6274: <input type="hidden" name="newidx" value="$newidx" />
6275: <input type="hidden" name="phase" value="$phase" />
6276: <input type="hidden" name="primaryurl" value="$primaryurl" />
6277: STATE
6278: }
6279:
6280: sub embedded_destination {
6281: my $folder=$env{'form.folder'};
6282: my $destination = 'docs/';
6283: if ($folder =~ /^supplemental/) {
6284: $destination = 'supplemental/';
6285: }
6286: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6287: $destination .= 'default/';
6288: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6289: $destination .= $2.'/';
6290: }
6291: $destination .= $env{'form.newidx'};
6292: my $dir_root = '/userfiles';
6293: return ($destination,$dir_root);
6294: }
6295:
6296: sub return_to_editor {
6297: my $actionurl = '/adm/coursedocs';
6298: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6299: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6300: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6301: '</a></p>';
6302: }
6303:
1.476 raeburn 6304: sub decompression_info {
6305: my ($destination,$dir_root) = &embedded_destination();
6306: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6307: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6308: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6309: my $container='sequence';
1.480 raeburn 6310: my ($pathitem,$hiddenelem);
1.583 raeburn 6311: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6312: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6313: $container='page';
6314: }
1.480 raeburn 6315: unshift(@hiddens,$pathitem);
6316: foreach my $item (@hiddens) {
6317: if ($env{'form.'.$item}) {
6318: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6319: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6320: }
1.477 raeburn 6321: }
1.476 raeburn 6322: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6323: $hiddenelem);
6324: }
6325:
6326: sub decompression_phase_one {
6327: my ($dir,$file,$warning,$error,$output);
6328: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6329: &decompression_info();
1.490 raeburn 6330: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6331: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6332: } else {
6333: my $file = $1;
1.481 raeburn 6334: $output =
6335: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6336: $destination,$dir_root,
6337: $hiddenelem);
6338: if ($env{'form.autoextract_camtasia'}) {
6339: $output .= &remove_archive($docudom,$docuname,$container);
6340: }
1.476 raeburn 6341: }
6342: if ($error) {
6343: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6344: $error.'</p>'."\n";
6345: }
6346: if ($warning) {
6347: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6348: }
6349: return $output;
6350: }
6351:
6352: sub decompression_phase_two {
6353: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6354: &decompression_info();
1.481 raeburn 6355: my $output;
1.480 raeburn 6356: if ($env{'form.archivedelete'}) {
1.481 raeburn 6357: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6358: }
6359: $output .=
1.481 raeburn 6360: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6361: $destination,$dir_root,$hiddenelem);
6362: return $output;
6363: }
6364:
1.480 raeburn 6365: sub remove_archive {
6366: my ($docudom,$docuname,$container) = @_;
6367: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6368: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6369: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6370: if ($fatal) {
6371: if ($container eq 'page') {
6372: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6373: } else {
6374: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6375: }
1.583 raeburn 6376: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6377: } else {
6378: my $currcmd = $env{'form.cmd'};
6379: my $position = $env{'form.position'};
1.583 raeburn 6380: my $archiveidx = $position;
1.563 raeburn 6381: if ($position > 0) {
1.583 raeburn 6382: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6383: $archiveidx = $position-1;
6384: }
6385: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6386: my ($title,$url,@rrest) =
1.583 raeburn 6387: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6388: if ($url eq $env{'form.archiveurl'}) {
6389: if (&handle_edit_cmd($docuname,$docudom)) {
6390: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6391: if ($fatal) {
6392: if ($container eq 'page') {
6393: $delwarning = &mt('An error occurred updating the contents of the current page.');
6394: } else {
6395: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6396: }
1.480 raeburn 6397: } else {
1.583 raeburn 6398: $delresult = &mt('Archive file removed.');
1.480 raeburn 6399: }
6400: }
1.583 raeburn 6401: } else {
6402: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6403: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6404: }
6405: }
6406: $env{'form.cmd'} = $currcmd;
6407: }
6408: if ($delwarning) {
6409: $output = '<p class="LC_warning">'.
6410: $delwarning.
6411: '</p>';
6412: }
6413: if ($delresult) {
6414: $output .= '<p class="LC_info">'.
6415: $delresult.
6416: '</p>';
6417: }
1.481 raeburn 6418: return $output;
1.480 raeburn 6419: }
6420:
1.484 raeburn 6421: sub generate_admin_menu {
1.611 raeburn 6422: my ($crstype,$canedit) = @_;
1.484 raeburn 6423: my $lc_crstype = lc($crstype);
6424: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6425: my %lt= ( # do not translate here
1.484 raeburn 6426: 'vc' => 'Verify Content',
6427: 'cv' => 'Check/Set Resource Versions',
6428: 'ls' => 'List Resource Identifiers',
6429: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6430: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6431: );
1.484 raeburn 6432: my ($candump,$dumpurl);
6433: if ($home + $other > 0) {
6434: $candump = 'F';
6435: if ($home) {
6436: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6437: } else {
6438: my @hosts;
6439: foreach my $aurole (keys(%outhash)) {
6440: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6441: push(@hosts,$outhash{$aurole});
1.538 raeburn 6442: }
1.484 raeburn 6443: }
6444: if (@hosts == 1) {
6445: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6446: '&role='.
6447: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6448: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6449: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6450: } else {
6451: $dumpurl = "javascript:choose_switchserver_window()";
6452: }
6453: }
6454: }
6455: my @menu=
6456: ({ categorytitle=>'Administration',
6457: items =>[
6458: { linktext => $lt{'vc'},
6459: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6460: permission => 'F',
1.571 raeburn 6461: help => 'Docs_Verify_Content',
1.484 raeburn 6462: icon => 'verify.png',
6463: linktitle => 'Verify contents can be retrieved/rendered',
6464: },
6465: { linktext => $lt{'cv'},
6466: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6467: permission => 'F',
1.571 raeburn 6468: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6469: icon => 'resversion.png',
6470: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6471: },
6472: { linktext => $lt{'ls'},
6473: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6474: permission => 'F',
6475: #help => '',
6476: icon => 'symbs.png',
6477: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6478: },
6479: ]
1.611 raeburn 6480: });
6481: if ($canedit) {
6482: push(@menu,
1.484 raeburn 6483: { categorytitle=>'Export',
6484: items =>[
6485: { linktext => $lt{'imse'},
6486: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6487: permission => 'F',
6488: help => 'Docs_Export_Course_Docs',
6489: icon => 'imsexport.png',
6490: linktitle => $lt{'imse'},
6491: },
6492: { linktext => $lt{'dcd'},
6493: url => $dumpurl,
6494: permission => $candump,
1.571 raeburn 6495: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6496: icon => 'dump.png',
6497: linktitle => $lt{'dcd'},
6498: },
6499: ]
6500: });
1.611 raeburn 6501: }
1.484 raeburn 6502: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6503: '<input type="hidden" id="dummy" />'."\n".
6504: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6505: '</form>';
1.329 droeschl 6506: }
6507:
6508: sub generate_edit_table {
1.538 raeburn 6509: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6510: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6511: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6512: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6513: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6514: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6515: $activetab = $env{'form.active'};
6516: }
1.611 raeburn 6517: unless ($canedit) {
6518: $disabled = ' disabled="disabled"';
6519: }
1.472 raeburn 6520: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6521: my $backtext = &mt('Exit Editor');
1.458 raeburn 6522: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6523: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6524: '<li class="goback">'.
1.546 raeburn 6525: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6526: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6527: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6528: '<li>'.
6529: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6530: &mt('Undo Delete').'</a></li>'."\n";
6531: if ($env{'form.docslog'}) {
6532: $form .= '<li class="active">';
6533: } else {
6534: $form .= '<li>';
6535: }
6536: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6537: &mt('History').'</a></li>'."\n";
6538: if ($env{'form.docslog'}) {
6539: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6540: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6541: }
1.458 raeburn 6542: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6543: if($name ne '00'){
1.371 tempelho 6544: if($activetab eq '' || $activetab ne $name){
6545: $active = '';
6546: }elsif($activetab eq $name){
6547: $active = 'class="active"';
6548: }
1.458 raeburn 6549: $form .= '<li style="float:right" '.$active
1.484 raeburn 6550: .' 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 6551: } else {
1.570 raeburn 6552: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6553:
6554: }
1.329 droeschl 6555: }
1.484 raeburn 6556: $form .= '</ul>'."\n";
6557: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6558:
6559: if ($to_show ne '') {
1.538 raeburn 6560: my $saveform;
6561: if ($need_save) {
6562: my $button = &mt('Make changes');
6563: my $path;
6564: if ($env{'form.folderpath'}) {
6565: $path =
6566: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6567: }
6568: $saveform = <<"END";
6569: <div id="multisave" style="display:none; clear:both;" >
6570: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6571: <input type="hidden" name="folderpath" value="$path" />
6572: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6573: <input type="hidden" name="allhiddenresource" value="" />
6574: <input type="hidden" name="allencrypturl" value="" />
6575: <input type="hidden" name="allrandompick" value="" />
6576: <input type="hidden" name="allrandomorder" value="" />
6577: <input type="hidden" name="changeparms" value="" />
6578: <input type="hidden" name="multiremove" value="" />
6579: <input type="hidden" name="multicut" value="" />
6580: <input type="hidden" name="multicopy" value="" />
6581: <input type="hidden" name="multichange" value="" />
6582: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 6583: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 6584: </form>
6585: </div>
6586: END
6587: }
6588: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6589: }
1.363 ehlerst 6590: foreach my $field (keys(%orderhash)){
1.390 tempelho 6591: if($field ne '00'){
1.422 onken 6592: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6593: $active = 'style="display: none;float:left"';
1.422 onken 6594: }elsif($activetab eq $field){
1.458 raeburn 6595: $active = 'style="display:block;float:left"';
1.422 onken 6596: }
6597: $form .= '<div id="'.$field.$tid.'"'
6598: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6599: .'</div>'."\n";
1.363 ehlerst 6600: }
6601: }
1.484 raeburn 6602: unless ($env{'form.docslog'}) {
6603: $form .= '</div></div>'."\n";
6604: }
1.329 droeschl 6605: return $form;
6606: }
6607:
6608: sub editing_js {
1.611 raeburn 6609: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot,$canedit) = @_;
1.594 damieng 6610: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6611: p_mnf => 'Name of New Folder',
6612: t_mnf => 'New Folder',
6613: p_mnp => 'Name of New Page',
6614: t_mnp => 'New Page',
1.451 www 6615: p_mxu => 'Title for the External Score',
1.349 biermanm 6616: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6617: p_msb => 'Title for the Problem',
6618: p_mdb => 'Title for the Drop Box',
1.336 schafran 6619: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 6620: p_mwp => 'Title for Web Page',
1.606 raeburn 6621: p_mnr => 'Title for the Resource',
1.348 weissno 6622: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6623: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6624: p_mab_alrt1 => 'Not a valid user:domain',
6625: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6626: p_chn => 'New Title',
6627: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 6628: p_rmr2a => 'Remove',
6629: p_rmr2b => '?',
6630: p_rmr3a => 'Remove those',
6631: p_rmr3b => 'items?',
6632: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6633: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6634: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6635: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 6636: p_ctr2a => 'Cut',
6637: p_ctr2b => '?',
6638: p_ctr3a => 'Cut those',
6639: p_ctr3b => 'items?',
1.478 raeburn 6640: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 6641: imsfile => 'You must choose an IMS package for import',
6642: imscms => 'You must select which Course Management System was the source of the IMS package',
6643: invurl => 'Invalid URL',
6644: titbl => 'Title is blank',
1.538 raeburn 6645: more => '(More ...)',
6646: less => '(Less ...)',
1.543 raeburn 6647: noor => 'No actions selected or changes to settings specified.',
6648: noch => 'No changes to settings specified.',
6649: noac => 'No actions selected.',
1.606 raeburn 6650: nofi => 'No file selected',
6651: tinc => 'Title in course',
6652: sunm => 'Sub-directory name',
1.611 raeburn 6653: edri => 'Editing rights unavailable for your current role',
1.329 droeschl 6654: );
1.594 damieng 6655: &js_escape(\%js_lt);
1.433 raeburn 6656: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6657: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6658: my $main_container_page;
1.519 raeburn 6659: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6660: $main_container_page = 1;
1.434 raeburn 6661: }
1.538 raeburn 6662: my $toplevelmain =
1.548 raeburn 6663: &escape(&mt('Main Content').':::::');
1.446 www 6664: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6665:
1.525 raeburn 6666: my $backtourl;
1.530 raeburn 6667: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6668: my $caller = $1;
1.525 raeburn 6669: if ($caller =~ /^supplemental/) {
6670: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6671: } else {
6672: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6673: $res = &Apache::lonnet::clutter($res);
6674: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 6675: my ($url,$anchor);
6676: if ($res =~ /^([^#]+)#([^#]+)$/) {
6677: $url = $1;
6678: $anchor = $2;
6679: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6680: $caller = $1.&escape('#').$anchor;
6681: }
6682: }
6683: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.525 raeburn 6684: &HTML::Entities::encode($caller,'<>&"');
1.609 raeburn 6685: if ($anchor ne '') {
6686: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6687: }
1.590 raeburn 6688: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 6689: } else {
6690: $backtourl = '/adm/navmaps';
1.525 raeburn 6691: }
6692: }
6693: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6694: $backtourl = '/adm/menu';
6695: } elsif ($supplementalflag) {
1.472 raeburn 6696: $backtourl = '/adm/supplemental';
1.525 raeburn 6697: } else {
6698: $backtourl = '/adm/navmaps';
1.472 raeburn 6699: }
6700:
1.600 raeburn 6701: my $fieldsets = "'ext','doc'";
6702: if ($posslti) {
6703: $fieldsets .= ",'tool'";
6704: }
1.519 raeburn 6705: unless ($main_container_page) {
6706: $fieldsets .=",'ims'";
6707: }
1.501 raeburn 6708: if ($supplementalflag) {
1.600 raeburn 6709: $fieldsets = "'suppext','suppdoc'";
6710: if ($posslti) {
6711: $fieldsets .= ",'supptool'";
6712: }
1.501 raeburn 6713: }
1.611 raeburn 6714:
6715: my $jsmakefunctions;
6716: if ($canedit) {
6717: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6718: function makenewfolder(targetform,folderseq) {
1.594 damieng 6719: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6720: if (foldername) {
6721: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6722: targetform.submit();
6723: }
6724: }
6725:
6726: function makenewpage(targetform,folderseq) {
1.594 damieng 6727: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6728: if (pagename) {
6729: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6730: targetform.submit();
6731: }
6732: }
6733:
6734: function makeexamupload() {
1.594 damieng 6735: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6736: if (title) {
1.329 droeschl 6737: this.document.forms.newexamupload.importdetail.value=
6738: escape(title)+'=/res/lib/templates/examupload.problem';
6739: this.document.forms.newexamupload.submit();
6740: }
6741: }
6742:
6743: function makesmppage() {
1.594 damieng 6744: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6745: if (title) {
1.329 droeschl 6746: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 6747: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6748: this.document.forms.newsmppg.submit();
6749: }
6750: }
6751:
1.534 raeburn 6752: function makewebpage(type) {
1.594 damieng 6753: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 6754: var formname;
6755: if (type == 'supp') {
6756: formname = this.document.forms.supwebpage;
6757: } else {
6758: formname = this.document.forms.newwebpage;
6759: }
6760: if (title) {
6761: var webpage = formname.importdetail.value;
6762: formname.importdetail.value = escape(title)+'='+webpage;
6763: formname.submit();
6764: }
6765: }
6766:
1.329 droeschl 6767: function makesmpproblem() {
1.594 damieng 6768: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6769: if (title) {
1.329 droeschl 6770: this.document.forms.newsmpproblem.importdetail.value=
6771: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6772: this.document.forms.newsmpproblem.submit();
6773: }
6774: }
6775:
6776: function makedropbox() {
1.594 damieng 6777: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6778: if (title) {
1.329 droeschl 6779: this.document.forms.newdropbox.importdetail.value=
6780: escape(title)+'=/res/lib/templates/DropBox.problem';
6781: this.document.forms.newdropbox.submit();
6782: }
6783: }
6784:
6785: function makebulboard() {
1.594 damieng 6786: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6787: if (title) {
6788: this.document.forms.newbul.importdetail.value=
1.533 raeburn 6789: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6790: this.document.forms.newbul.submit();
6791: }
6792: }
6793:
6794: function makeabout() {
1.594 damieng 6795: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6796: if (user) {
6797: var comp=new Array();
6798: comp=user.split(':');
6799: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6800: if ((comp[0]) && (comp[1])) {
6801: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 6802: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 6803: this.document.forms.newaboutsomeone.submit();
6804: } else {
6805: alert("$js_lt{'p_mab_alrt1'}");
6806: }
6807: } else {
6808: alert("$js_lt{'p_mab_alrt2'}");
6809: }
6810: }
6811: }
6812:
6813: function makenew(targetform) {
6814: targetform.submit();
6815: }
6816:
6817: function changename(folderpath,index,oldtitle) {
6818: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6819: if (title) {
6820: this.document.forms.renameform.markcopy.value='';
6821: this.document.forms.renameform.title.value=title;
6822: this.document.forms.renameform.cmd.value='rename_'+index;
6823: this.document.forms.renameform.folderpath.value=folderpath;
6824: this.document.forms.renameform.submit();
6825: }
6826: }
6827:
6828: ENDNEWSCRIPT
6829: } else {
6830: $jsmakefunctions = <<ENDNEWSCRIPT;
6831:
6832: function makenewfolder() {
6833: alert("$js_lt{'edri'}");
6834: }
6835:
6836: function makenewpage() {
6837: alert("$js_lt{'edri'}");
6838: }
6839:
6840: function makeexamupload() {
6841: alert("$js_lt{'edri'}");
6842: }
6843:
6844: function makesmppage() {
6845: alert("$js_lt{'edri'}");
6846: }
6847:
6848: function makewebpage(type) {
6849: alert("$js_lt{'edri'}");
6850: }
6851:
6852: function makesmpproblem() {
6853: alert("$js_lt{'edri'}");
6854: }
6855:
6856: function makedropbox() {
6857: alert("$js_lt{'edri'}");
6858: }
6859:
6860: function makebulboard() {
6861: alert("$js_lt{'edri'}");
6862: }
6863:
6864: function makeabout() {
6865: alert("$js_lt{'edri'}");
6866: }
6867:
6868: function changename() {
6869: alert("$js_lt{'edri'}");
6870: }
6871:
6872: function makenew() {
6873: alert("$js_lt{'edri'}");
6874: }
6875:
6876: function groupimport() {
6877: alert("$js_lt{'edri'}");
1.335 ehlerst 6878: }
1.611 raeburn 6879:
6880: function groupsearch() {
6881: alert("$js_lt{'edri'}");
1.335 ehlerst 6882: }
1.611 raeburn 6883:
6884: function groupopen(url,recover) {
6885: var options="scrollbars=1,resizable=1,menubar=0";
6886: idxflag=1;
6887: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6888: idx.focus();
1.329 droeschl 6889: }
6890:
1.611 raeburn 6891: ENDNEWSCRIPT
6892:
6893: }
6894: return <<ENDSCRIPT;
6895:
6896: $jsmakefunctions
6897:
1.501 raeburn 6898: function toggleUpload(caller) {
6899: var blocks = Array($fieldsets);
6900: for (var i=0; i<blocks.length; i++) {
6901: var disp = 'none';
6902: if (caller == blocks[i]) {
6903: var curr = document.getElementById('upload'+caller+'form').style.display;
6904: if (curr == 'none') {
6905: disp='block';
6906: }
6907: }
6908: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 6909: if ((caller == 'tool') || (caller == 'supptool')) {
6910: if (disp == 'block') {
6911: if (document.getElementById('LC_exttoolid')) {
6912: var toolselector = document.getElementById('LC_exttoolid');
6913: var suppflag = 0;
6914: if (caller == 'supptool') {
6915: suppflag = 1;
6916: }
6917: currForm = document.getElementById('new'+caller);
6918: updateExttool(toolselector,currForm,suppflag);
6919: }
6920: }
6921: }
1.501 raeburn 6922: }
1.502 raeburn 6923: resize_scrollbox('contentscroll','1','1');
6924: return;
6925: }
6926:
1.514 raeburn 6927: function toggleMap(caller) {
1.502 raeburn 6928: var disp = 'none';
1.510 raeburn 6929: if (document.getElementById('importmapform')) {
1.514 raeburn 6930: if (caller == 'map') {
6931: var curr = document.getElementById('importmapform').style.display;
6932: if (curr == 'none') {
6933: disp='block';
6934: }
1.510 raeburn 6935: }
6936: document.getElementById('importmapform').style.display=disp;
6937: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 6938: }
1.501 raeburn 6939: return;
1.329 droeschl 6940: }
6941:
1.606 raeburn 6942: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
6943: var disp = 'none';
6944: if (document.getElementById('crsresform')) {
6945: if (caller == 'res') {
6946: var curr = document.getElementById('crsresform').style.display;
6947: if (curr == 'none') {
6948: disp='block';
6949: numauthor = parseInt(numauthorrole);
6950: if (numauthor > 0) {
6951: document.courseresform.authorrole.selectedIndex = 0;
6952: select1priv_changed();
6953: document.courseresform.authorpath.selectedIndex = 0;
6954: document.courseresform.newresourceadd.selectedIndex = 0;
6955: toggleNewInCourse(document.courseresform);
6956: if (document.getElementById('newresource')) {
6957: document.getElementById('newresource').style.display = 'none';
6958: }
6959: } else {
6960: if (numcrsdirs) {
6961: document.courseresform.authorpath.selectedIndex = 0;
6962: }
6963: }
6964: if (document.courseresform.newresusetemp.length) {
6965: document.courseresform.newresusetemp[0].checked = true;
6966: toggleWithTemplate(document.courseresform);
6967: }
6968: document.courseresform.newresourcename.value = '';
6969: }
6970: }
6971: if (document.courseresform.newsubdir.length) {
6972: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
6973: if (document.courseresform.newsubdir[j].value == 0) {
6974: document.courseresform.newsubdir[j].checked = true;
6975: }
6976: break;
6977: }
6978: if (document.getElementById('newsubdirname')) {
6979: document.getElementById('newsubdirname').type = "hidden";
6980: document.getElementById('newsubdirname').value = "";
6981: }
6982: if (document.getElementById('newsubdir')) {
6983: document.getElementById('newsubdir').innerHTML = "";
6984: }
6985: }
6986: document.getElementById('crsresform').style.display=disp;
6987: resize_scrollbox('contentscroll','1','0');
6988: }
6989: return;
6990: }
6991:
6992: function toggleNewsubdir(form) {
6993: if (form.newsubdir.length) {
6994: for (var j=0; j<form.newsubdir.length; j++) {
6995: if (form.newsubdir[j].checked) {
6996: if (document.getElementById('newsubdirname')) {
6997: if (form.newsubdir[j].value == '1') {
6998: document.getElementById('newsubdirname').type = "text";
6999: if (document.getElementById('newsubdir')) {
7000: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7001: }
7002: } else {
7003: document.getElementById('newsubdirname').type = "hidden";
7004: document.getElementById('newsubdirname').value = "";
7005: document.getElementById('newsubdir').innerHTML = "";
7006: }
7007: }
7008: break;
7009: }
7010: }
7011: }
7012: }
7013:
7014: function toggleCrsResTitle() {
7015: if (document.getElementById('newresource')) {
7016: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7017: document.getElementById('newresource').style.display = 'inline';
7018: document.courseresform.newresourceadd[0].checked = true;
7019: toggleNewInCourse(document.courseresform);
7020: } else {
7021: document.getElementById('newresource').style.display = 'none';
7022: }
7023: }
7024: }
7025:
7026: function toggleNewInCourse(form) {
7027: if (form.newresourceadd.length) {
7028: for (var i=0; i<form.newresourceadd.length; i++) {
7029: if (form.newresourceadd[i].checked) {
7030: if (document.getElementById('newresourcetitle')) {
7031: if (form.newresourceadd[i].value == '1') {
7032: document.getElementById('newresourcetitle').type = 'text';
7033: if (document.getElementById('newrestitle')) {
7034: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7035: }
7036: } else {
7037: document.getElementById('newresourcetitle').type = 'hidden';
7038: document.getElementById('newresourcetitle').value = '';
7039: if (document.getElementById('newrestitle')) {
7040: document.getElementById('newrestitle').innerHTML = '';
7041: }
7042: }
7043: }
7044: break;
7045: }
7046: }
7047: }
7048: }
7049:
7050: function toggleWithTemplate(form) {
7051: if (form.newresusetemp.length) {
7052: for (var i=0; i<form.newresusetemp.length; i++) {
7053: if (form.newresusetemp[i].checked) {
7054: if (document.getElementById('newrestemplate')) {
7055: if (form.newresusetemp[i].value == '1') {
7056: document.getElementById('newrestemplate').style.display = 'inline';
7057: toggleExampleText();
7058: } else {
7059: form.tempcategory.selectedIndex = 0;
7060: select1template_changed();
7061: document.getElementById('newrestemplate').style.display = 'none';
7062: }
7063: }
7064: }
7065: }
7066: }
7067: }
7068:
7069: function toggleExampleText() {
7070: if (document.getElementById('newresexample')) {
7071: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7072: if (url == '') {
7073: document.getElementById('newresexample').style.fontWeight = 'normal';
7074: } else {
7075: document.getElementById('newresexample').style.fontWeight = 'bold';
7076: }
7077: }
7078: }
7079:
7080: function getExample(width,height,scrolling,transparency) {
7081: var url;
7082: if (document.courseresform.newresusetemp.length) {
7083: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7084: if (document.courseresform.newresusetemp[i].checked) {
7085: if (document.courseresform.newresusetemp[i].value == '1') {
7086: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7087: if (url == '') {
7088: alert('Pick a category and template');
7089: } else {
7090: url = url.replace("$londocroot","");
7091: url += '?inhibitmenu=yes';
7092: }
7093: }
7094: break;
7095: }
7096: }
7097: }
7098: if (url != '') {
7099: openMyModal(url,width,height,scrolling,transparency,'');
7100: }
7101: }
7102:
7103: function toggleImportCrsres(caller,dircount) {
7104: var disp = 'none';
7105: if (document.getElementById('importcrsresform')) {
7106: if (caller == 'res') {
7107: var numdirs = parseInt(dircount);
7108: var curr = document.getElementById('importcrsresform').style.display;
7109: if (curr == 'none') {
7110: disp='block';
7111: if (numdirs > 1) {
7112: select1res_changed();
7113: }
7114: }
7115: }
7116: document.getElementById('importcrsresform').style.display=disp;
7117: resize_scrollbox('contentscroll','1','0');
7118: }
7119: return;
7120: }
7121:
1.501 raeburn 7122: function makeims(imsform) {
7123: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7124: alert("$js_lt{'imsfile'}");
1.501 raeburn 7125: return;
7126: }
7127: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7128: alert("$js_lt{'imscms'}");
1.501 raeburn 7129: return;
7130: }
7131: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7132: imsform.submit();
7133: }
7134:
1.478 raeburn 7135: function updatePick(targetform,index,caller) {
1.537 raeburn 7136: var pickitem;
7137: var picknumitem;
7138: var picknumtext;
7139: if (index == 'all') {
7140: pickitem = document.getElementById('randompickall');
7141: picknumitem = document.getElementById('rpicknumall');
7142: picknumtext = document.getElementById('rpicktextall');
7143: } else {
7144: pickitem = document.getElementById('randompick_'+index);
7145: picknumitem = document.getElementById('rpicknum_'+index);
7146: picknumtext = document.getElementById('randompicknum_'+index);
7147: }
1.478 raeburn 7148: if (pickitem.checked) {
1.594 damieng 7149: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7150: if (picknum == '' || picknum == null) {
7151: if (caller == 'check') {
7152: pickitem.checked=false;
1.537 raeburn 7153: if (index == 'all') {
7154: picknumtext.innerHTML = '';
7155: if (caller == 'link') {
7156: propagateState(targetform,'rpicknum');
7157: }
7158: } else {
1.538 raeburn 7159: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7160: }
1.478 raeburn 7161: }
7162: } else {
7163: picknum.toString();
7164: var regexdigit=/^\\d+\$/;
7165: if (regexdigit.test(picknum)) {
7166: picknumitem.value = picknum;
1.537 raeburn 7167: if (index == 'all') {
1.538 raeburn 7168: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7169: if (caller == 'link') {
7170: propagateState(targetform,'rpicknum');
7171: }
7172: } else {
7173: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7174: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7175: }
1.478 raeburn 7176: } else {
7177: if (caller == 'check') {
1.537 raeburn 7178: if (index == 'all') {
7179: picknumtext.innerHTML = '';
7180: if (caller == 'link') {
7181: propagateState(targetform,'rpicknum');
7182: }
7183: } else {
7184: pickitem.checked=false;
1.538 raeburn 7185: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7186: }
1.478 raeburn 7187: }
7188: return;
7189: }
7190: }
7191: } else {
1.537 raeburn 7192: picknumitem.value = '';
7193: picknumtext.innerHTML = '';
7194: if (index == 'all') {
7195: if (caller == 'link') {
7196: propagateState(targetform,'rpicknum');
7197: }
7198: } else {
1.538 raeburn 7199: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7200: }
7201: }
7202: }
7203:
7204: function propagateState(form,param) {
7205: if (document.getElementById(param+'all')) {
7206: var setcheck = 0;
7207: var rpick = 0;
7208: if (param == 'rpicknum') {
7209: if (document.getElementById('randompickall')) {
7210: if (document.getElementById('randompickall').checked) {
7211: if (document.getElementById('rpicknumall')) {
7212: rpick = document.getElementById('rpicknumall').value;
7213: }
7214: }
7215: }
7216: } else {
7217: if (document.getElementById(param+'all').checked) {
7218: setcheck = 1;
7219: }
7220: }
1.538 raeburn 7221: var allidxlist;
7222: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7223: if (document.getElementById('all'+param+'idx')) {
7224: allidxlist = document.getElementById('all'+param+'idx').value;
7225: }
7226: var actions = new Array ('remove','cut','copy');
7227: for (var i=0; i<actions.length; i++) {
7228: if (actions[i] != param) {
7229: if (document.getElementById(actions[i]+'all')) {
7230: document.getElementById(actions[i]+'all').checked = false;
7231: }
7232: }
7233: }
7234: }
1.537 raeburn 7235: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7236: allidxlist = form.allidx.value;
7237: }
7238: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7239: allidxlist = form.allmapidx.value;
7240: }
7241: if ((allidxlist != '') && (allidxlist != null)) {
7242: var allidxs = allidxlist.split(',');
7243: if (allidxs.length > 1) {
7244: for (var i=0; i<allidxs.length; i++) {
7245: if (document.getElementById(param+'_'+allidxs[i])) {
7246: if (param == 'rpicknum') {
7247: if (document.getElementById('randompick_'+allidxs[i])) {
7248: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7249: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7250: if (rpick > 0) {
7251: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7252: } else {
7253: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7254: }
7255: }
7256: }
7257: } else {
1.537 raeburn 7258: if (setcheck == 1) {
7259: document.getElementById(param+'_'+allidxs[i]).checked = true;
7260: } else {
7261: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7262: if (param == 'randompick') {
7263: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7264: }
1.537 raeburn 7265: }
7266: }
7267: }
7268: }
1.538 raeburn 7269: if (setcheck == 1) {
7270: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7271: var actions = new Array('copy','cut','remove');
7272: for (var i=0; i<actions.length; i++) {
7273: var otheractions;
7274: var otheridxs;
7275: if (actions[i] === param) {
7276: continue;
7277: } else {
7278: if (document.getElementById('all'+actions[i]+'idx')) {
7279: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7280: otheridxs = otheractions.split(',');
7281: if (otheridxs.length > 1) {
7282: for (var j=0; j<otheridxs.length; j++) {
7283: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7284: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7285: }
1.537 raeburn 7286: }
7287: }
7288: }
1.538 raeburn 7289: }
7290: }
7291: }
7292: }
7293: }
7294: }
7295: }
7296: return;
7297: }
7298:
1.603 raeburn 7299: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7300: var canedit = '$canedit';
7301: if (canedit == '') {
7302: alert("$js_lt{'edri'}");
7303: return;
7304: }
1.539 raeburn 7305: var dosettings;
7306: var doaction;
1.538 raeburn 7307: var control = document.togglemultsettings;
7308: if (context == 'actions') {
7309: control = document.togglemultactions;
1.539 raeburn 7310: doaction = 1;
7311: } else {
7312: dosettings = 1;
1.538 raeburn 7313: }
1.539 raeburn 7314: if (control) {
7315: if (control.showmultpick.length) {
7316: for (var i=0; i<control.showmultpick.length; i++) {
7317: if (control.showmultpick[i].checked) {
7318: if (control.showmultpick[i].value == 1) {
7319: if (context == 'settings') {
7320: dosettings = 0;
7321: } else {
7322: doaction = 0;
1.538 raeburn 7323: }
7324: }
7325: }
1.537 raeburn 7326: }
7327: }
1.539 raeburn 7328: }
7329: if (context == 'settings') {
7330: if (dosettings == 1) {
1.538 raeburn 7331: targetform.changeparms.value=param;
7332: targetform.submit();
7333: }
1.537 raeburn 7334: }
1.539 raeburn 7335: if (context == 'actions') {
7336: if (doaction == 1) {
7337: targetform.cmd.value=param+'_'+index;
7338: targetform.folderpath.value=folderpath;
7339: targetform.markcopy.value=idx+':'+param;
7340: targetform.copyfolder.value=folder+'.'+container;
7341: if (param == 'remove') {
1.603 raeburn 7342: var doremove = 0;
7343: if (skip_confirm) {
7344: if (confirm_removal) {
7345: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7346: doremove = 1;
7347: }
7348: } else {
7349: doremove = 1;
7350: }
7351: } else {
7352: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7353: doremove = 1;
7354: }
7355: }
7356: if (doremove) {
1.539 raeburn 7357: targetform.markcopy.value='';
7358: targetform.copyfolder.value='';
7359: targetform.submit();
7360: }
7361: }
7362: if (param == 'cut') {
1.594 damieng 7363: 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 7364: targetform.submit();
7365: return;
7366: }
7367: }
7368: if (param == 'copy') {
7369: targetform.submit();
7370: return;
7371: }
7372: targetform.markcopy.value='';
7373: targetform.copyfolder.value='';
7374: targetform.cmd.value='';
7375: targetform.folderpath.value='';
7376: return;
7377: } else {
7378: if (document.getElementById(param+'_'+idx)) {
7379: item = document.getElementById(param+'_'+idx);
7380: if (item.type == 'checkbox') {
7381: if (item.checked) {
7382: item.checked = false;
7383: } else {
7384: item.checked = true;
7385: singleCheck(item,idx,param);
7386: }
7387: }
7388: }
7389: }
7390: }
1.537 raeburn 7391: return;
7392: }
7393:
1.538 raeburn 7394: function singleCheck(caller,idx,action) {
7395: actions = new Array('cut','copy','remove');
7396: if (caller.checked) {
7397: for (var i=0; i<actions.length; i++) {
7398: if (actions[i] != action) {
7399: if (document.getElementById(actions[i]+'_'+idx)) {
7400: if (document.getElementById(actions[i]+'_'+idx).checked) {
7401: document.getElementById(actions[i]+'_'+idx).checked = false;
7402: }
1.537 raeburn 7403: }
7404: }
7405: }
1.478 raeburn 7406: }
1.537 raeburn 7407: return;
1.478 raeburn 7408: }
7409:
1.334 muellerd 7410: function unselectInactive(nav) {
1.335 ehlerst 7411: currentNav = document.getElementById(nav);
7412: currentLis = currentNav.getElementsByTagName('LI');
7413: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7414: if (currentLis[i].className == 'goback') {
7415: currentLis[i].className = 'goback';
7416: } else {
7417: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7418: currentLis[i].className = 'right';
1.472 raeburn 7419: } else {
1.374 tempelho 7420: currentLis[i].className = 'i';
1.472 raeburn 7421: }
7422: }
1.335 ehlerst 7423: }
1.332 tempelho 7424: }
7425:
1.334 muellerd 7426: function hideAll(current, nav, data) {
1.335 ehlerst 7427: unselectInactive(nav);
1.570 raeburn 7428: if (current) {
7429: if (current.className == 'right'){
7430: current.className = 'right active'
7431: } else {
7432: current.className = 'active';
7433: }
1.374 tempelho 7434: }
1.335 ehlerst 7435: currentData = document.getElementById(data);
7436: currentDivs = currentData.getElementsByTagName('DIV');
7437: for (i = 0; i < currentDivs.length; i++) {
7438: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7439: currentDivs[i].style.display = 'none';
1.330 tempelho 7440: }
7441: }
1.335 ehlerst 7442: }
1.330 tempelho 7443:
1.374 tempelho 7444: function openTabs(pageId) {
7445: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7446: if(tabnav.length > 2 ){
1.389 tempelho 7447: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7448: currentLis = currentNav.getElementsByTagName('LI');
7449: for(i = 0; i< currentLis.length; i++){
7450: if(currentLis[i].className == 'active') {
1.375 tempelho 7451: funcString = currentLis[i].onclick.toString();
7452: tab = funcString.split('"');
1.420 onken 7453: if(tab.length < 2) {
7454: tab = funcString.split("'");
7455: }
1.375 tempelho 7456: currentData = document.getElementById(tab[1]);
7457: currentData.style.display = 'block';
1.374 tempelho 7458: }
7459: }
7460: }
7461: }
7462:
1.334 muellerd 7463: function showPage(current, pageId, nav, data) {
1.570 raeburn 7464: currstate = current.className;
1.334 muellerd 7465: hideAll(current, nav, data);
1.375 tempelho 7466: openTabs(pageId);
1.334 muellerd 7467: unselectInactive(nav);
1.570 raeburn 7468: if ((currstate == 'active') || (currstate == 'right active')) {
7469: if (currstate == 'active') {
7470: current.className = '';
7471: } else {
7472: current.className = 'right';
7473: }
7474: activeTab = '';
7475: toggleUpload();
7476: toggleMap();
1.606 raeburn 7477: toggleCrsRes();
7478: toggleImportCrsres();
1.570 raeburn 7479: resize_scrollbox('contentscroll','1','0');
7480: return;
7481: } else {
7482: current.className = 'active';
7483: }
1.330 tempelho 7484: currentData = document.getElementById(pageId);
7485: currentData.style.display = 'block';
1.458 raeburn 7486: activeTab = pageId;
1.501 raeburn 7487: toggleUpload();
1.503 raeburn 7488: toggleMap();
1.606 raeburn 7489: toggleCrsRes();
7490: toggleImportCrsres();
1.433 raeburn 7491: if (nav == 'mainnav') {
7492: var storedpath = "$docs_folderpath";
1.434 raeburn 7493: var storedpage = "$main_container_page";
1.433 raeburn 7494: var reg = new RegExp("^supplemental");
7495: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7496: if (storedpage == 1) {
7497: document.simpleedit.folderpath.value = '';
7498: document.uploaddocument.folderpath.value = '';
7499: } else {
7500: if (reg.test(storedpath)) {
7501: document.simpleedit.folderpath.value = '$toplevelmain';
7502: document.uploaddocument.folderpath.value = '$toplevelmain';
7503: document.newext.folderpath.value = '$toplevelmain';
7504: } else {
7505: document.simpleedit.folderpath.value = storedpath;
7506: document.uploaddocument.folderpath.value = storedpath;
7507: document.newext.folderpath.value = storedpath;
7508: }
1.433 raeburn 7509: }
7510: } else {
1.434 raeburn 7511: if (reg.test(storedpath)) {
7512: document.simpleedit.folderpath.value = storedpath;
7513: document.supuploaddocument.folderpath.value = storedpath;
7514: document.supnewext.folderpath.value = storedpath;
7515: } else {
1.433 raeburn 7516: document.simpleedit.folderpath.value = '$toplevelsupp';
7517: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7518: document.supnewext.folderpath.value = '$toplevelsupp';
7519: }
7520: }
7521: }
1.485 raeburn 7522: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7523: return false;
7524: }
1.329 droeschl 7525:
1.472 raeburn 7526: function toContents(jumpto) {
7527: var newurl = '$backtourl';
1.525 raeburn 7528: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7529: newurl = newurl+'?postdata='+jumpto;
7530: }
7531: location.href=newurl;
7532: }
7533:
1.538 raeburn 7534: function togglePick(caller,value) {
7535: var disp = 'none';
7536: if (document.getElementById('multi'+caller)) {
7537: var curr = document.getElementById('multi'+caller).style.display;
7538: if (value == 1) {
7539: disp='block';
7540: }
7541: if (curr == disp) {
7542: return;
7543: }
7544: document.getElementById('multi'+caller).style.display=disp;
7545: if (value == 1) {
1.594 damieng 7546: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7547: } else {
7548: document.getElementById('more'+caller).innerHTML = '';
7549: }
7550: if (caller == 'actions') {
7551: setClass(value);
7552: setBoxes(value);
7553: }
7554: }
7555: var showButton = multiSettings();
7556: if (showButton != 1) {
7557: showButton = multiActions();
7558: }
7559: if (document.getElementById('multisave')) {
7560: if (showButton == 1) {
7561: document.getElementById('multisave').style.display='block';
7562: } else {
7563: document.getElementById('multisave').style.display='none';
7564: }
7565: }
7566: resize_scrollbox('contentscroll','1','1');
7567: return;
7568: }
7569:
7570: function toggleCheckUncheck(caller,more) {
7571: if (more == 1) {
1.594 damieng 7572: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 7573: document.getElementById('allfields'+caller).style.display='block';
7574: } else {
1.594 damieng 7575: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 7576: document.getElementById('allfields'+caller).style.display='none';
7577: }
7578: resize_scrollbox('contentscroll','1','1');
7579: }
7580:
7581: function multiSettings() {
7582: var inuse = 0;
7583: var settingsform = document.togglemultsettings;
7584: if (settingsform.showmultpick.length > 1) {
7585: for (var i=0; i<settingsform.showmultpick.length; i++) {
7586: if (settingsform.showmultpick[i].checked) {
7587: if (settingsform.showmultpick[i].value == 1) {
7588: inuse = 1;
7589: }
7590: }
7591: }
7592: }
7593: return inuse;
7594: }
7595:
7596: function multiActions() {
7597: var inuse = 0;
7598: var actionsform = document.togglemultactions;
7599: if (actionsform.showmultpick.length > 1) {
7600: for (var i=0; i<actionsform.showmultpick.length; i++) {
7601: if (actionsform.showmultpick[i].checked) {
7602: if (actionsform.showmultpick[i].value == 1) {
7603: inuse = 1;
7604: }
7605: }
7606: }
7607: }
7608: return inuse;
7609: }
7610:
7611: function checkSubmits() {
7612: var numchanges = 0;
7613: var form = document.saveactions;
7614: var doactions = multiActions();
1.542 raeburn 7615: var cutwarnings = 0;
7616: var remwarnings = 0;
1.603 raeburn 7617: var removalinfo = 0;
1.538 raeburn 7618: if (doactions == 1) {
7619: var remidxlist = document.cumulativeactions.allremoveidx.value;
7620: if ((remidxlist != '') && (remidxlist != null)) {
7621: var remidxs = remidxlist.split(',');
7622: for (var i=0; i<remidxs.length; i++) {
7623: if (document.getElementById('remove_'+remidxs[i])) {
7624: if (document.getElementById('remove_'+remidxs[i]).checked) {
7625: form.multiremove.value += remidxs[i]+',';
7626: numchanges ++;
1.542 raeburn 7627: if (document.getElementById('skip_remove_'+remidxs[i])) {
7628: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7629: remwarnings ++;
7630: }
7631: }
1.603 raeburn 7632: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7633: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7634: removalinfo ++;
7635: }
7636: }
1.537 raeburn 7637: }
7638: }
1.538 raeburn 7639: }
7640: }
7641: var cutidxlist = document.cumulativeactions.allcutidx.value;
7642: if ((cutidxlist != '') && (cutidxlist != null)) {
7643: var cutidxs = cutidxlist.split(',');
7644: for (var i=0; i<cutidxs.length; i++) {
7645: if (document.getElementById('cut_'+cutidxs[i])) {
7646: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7647: form.multicut.value += cutidxs[i]+',';
7648: numchanges ++;
1.542 raeburn 7649: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7650: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7651: cutwarnings ++;
7652: }
7653: }
1.537 raeburn 7654: }
7655: }
7656: }
7657: }
1.538 raeburn 7658: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7659: if ((copyidxlist != '') && (copyidxlist != null)) {
7660: var copyidxs = copyidxlist.split(',');
7661: for (var i=0; i<copyidxs.length; i++) {
7662: if (document.getElementById('copy_'+copyidxs[i])) {
7663: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7664: form.multicopy.value += copyidxs[i]+',';
7665: numchanges ++;
7666: }
7667: }
7668: }
7669: }
7670: if (numchanges > 0) {
7671: form.multichange.value = numchanges;
7672: }
1.537 raeburn 7673: }
1.538 raeburn 7674: var dosettings = multiSettings();
1.543 raeburn 7675: var haschanges = 0;
1.538 raeburn 7676: if (dosettings == 1) {
7677: form.allencrypturl.value = '';
7678: form.allhiddenresource.value = '';
1.543 raeburn 7679: form.changeparms.value = 'all';
7680: var patt=new RegExp(",\$");
1.538 raeburn 7681: var allidxlist = document.cumulativesettings.allidx.value;
7682: if ((allidxlist != '') && (allidxlist != null)) {
7683: var allidxs = allidxlist.split(',');
7684: if (allidxs.length > 1) {
7685: for (var i=0; i<allidxs.length; i++) {
7686: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7687: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7688: form.allhiddenresource.value += allidxs[i]+',';
7689: }
7690: }
7691: if (document.getElementById('encrypturl_'+allidxs[i])) {
7692: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7693: form.allencrypturl.value += allidxs[i]+',';
7694: }
7695: }
7696: }
1.543 raeburn 7697: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7698: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 7699: }
1.538 raeburn 7700: }
7701: form.allrandompick.value = '';
7702: form.allrandomorder.value = '';
7703: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7704: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7705: var allmapidxs = allmapidxlist.split(',');
7706: for (var i=0; i<allmapidxs.length; i++) {
7707: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7708: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7709: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7710: if ((randompick.checked) && (rpicknum.value != '')) {
7711: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7712: }
7713: if (randorder.checked) {
7714: form.allrandomorder.value += allmapidxs[i]+',';
7715: }
1.537 raeburn 7716: }
1.543 raeburn 7717: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7718: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7719: }
7720: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7721: haschanges = 1;
7722: }
7723: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7724: haschanges = 1;
7725: }
7726: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7727: haschanges = 1;
7728: }
7729: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7730: haschanges = 1;
1.537 raeburn 7731: }
7732: }
1.543 raeburn 7733: if (doactions == 1) {
1.542 raeburn 7734: if (numchanges > 0) {
1.603 raeburn 7735: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 7736: if (remwarnings > 0) {
1.594 damieng 7737: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 7738: return false;
7739: }
7740: }
1.603 raeburn 7741: if (removalinfo > 0) {
7742: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7743: return false;
7744: }
7745: }
1.542 raeburn 7746: if (cutwarnings > 0) {
1.594 damieng 7747: 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 7748: return false;
7749: }
7750: }
7751: }
7752: form.submit();
7753: return true;
1.543 raeburn 7754: }
7755: }
7756: if (dosettings == 1) {
7757: if (haschanges == 1) {
1.542 raeburn 7758: form.submit();
7759: return true;
7760: }
1.543 raeburn 7761: }
7762: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 7763: alert("$js_lt{'noor'}");
1.543 raeburn 7764: } else {
7765: if (dosettings == 1) {
1.594 damieng 7766: alert("$js_lt{'noch'}");
1.543 raeburn 7767: } else {
1.594 damieng 7768: alert("$js_lt{'noac'}");
1.543 raeburn 7769: }
7770: }
1.538 raeburn 7771: return false;
7772: }
7773:
7774: function setClass(value) {
7775: var cutclass = 'LC_docs_cut';
7776: var copyclass = 'LC_docs_copy';
7777: var removeclass = 'LC_docs_remove';
7778: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7779: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7780: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7781: var links = document.getElementsByTagName('a');
7782: for (var i=0; i<links.length; i++) {
7783: var classes = links[i].className;
7784: if (cutreg.test(classes)) {
7785: links[i].className = cutclass;
7786: if (value == 1) {
7787: links[i].className += " LC_menubuttons_link";
7788: }
7789: } else {
7790: if (copyreg.test(classes)) {
7791: links[i].className = copyclass;
7792: if (value == 1) {
7793: links[i].className += " LC_menubuttons_link";
7794: }
7795: } else {
7796: if (removereg.test(classes)) {
7797: links[i].className = removeclass;
7798: if (value == 1) {
7799: links[i].className += " LC_menubuttons_link";
7800: }
7801: }
7802: }
7803: }
7804: }
7805: return;
1.537 raeburn 7806: }
7807:
1.538 raeburn 7808: function setBoxes(value) {
7809: var remidxlist = document.cumulativeactions.allremoveidx.value;
7810: if ((remidxlist != '') && (remidxlist != null)) {
7811: var remidxs = remidxlist.split(',');
7812: for (var i=0; i<remidxs.length; i++) {
7813: if (document.getElementById('remove_'+remidxs[i])) {
7814: var item = document.getElementById('remove_'+remidxs[i]);
7815: if (value == 1) {
7816: item.className = 'LC_docs_remove';
7817: } else {
7818: item.className = 'LC_hidden';
7819: }
7820: }
7821: }
7822: }
7823: var cutidxlist = document.cumulativeactions.allcutidx.value;
7824: if ((cutidxlist != '') && (cutidxlist != null)) {
7825: var cutidxs = cutidxlist.split(',');
7826: for (var i=0; i<cutidxs.length; i++) {
7827: if (document.getElementById('cut_'+cutidxs[i])) {
7828: var item = document.getElementById('cut_'+cutidxs[i]);
7829: if (value == 1) {
7830: item.className = 'LC_docs_cut';
7831: } else {
7832: item.className = 'LC_hidden';
7833: }
7834: }
1.537 raeburn 7835: }
7836: }
1.538 raeburn 7837: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7838: if ((copyidxlist != '') && (copyidxlist != null)) {
7839: var copyidxs = copyidxlist.split(',');
7840: for (var i=0; i<copyidxs.length; i++) {
7841: if (document.getElementById('copy_'+copyidxs[i])) {
7842: var item = document.getElementById('copy_'+copyidxs[i]);
7843: if (value == 1) {
7844: item.className = 'LC_docs_copy';
7845: } else {
7846: item.className = 'LC_hidden';
7847: }
7848: }
1.537 raeburn 7849: }
7850: }
7851: return;
7852: }
7853:
1.606 raeburn 7854: function validImportCrsRes() {
7855: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
7856: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
7857: if ((fname == '') || (fname == null)) {
7858: alert("$js_lt{'nofi'}");
7859: return false;
7860: }
7861: var url = '/res/$coursedom/$coursenum/';
7862: if (path && path != '/') {
7863: url += path+'/';
7864: }
7865: if (fname != '') {
7866: url += fname;
7867: }
7868: var title = document.crsresimportform.crsrestitle.value;
7869: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
7870: return true;
7871: }
7872:
7873: function validateNewRes(caller) {
7874: if (caller == 'single') {
7875: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
7876: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
7877: var resname = document.courseresform.newresourcename.value;
7878: }
7879: }
7880:
1.611 raeburn 7881: ENDSCRIPT
1.329 droeschl 7882: }
1.457 raeburn 7883:
1.483 raeburn 7884: sub history_tab_js {
7885: return <<"ENDHIST";
7886: function toggleHistoryDisp(choice) {
7887: document.docslogform.docslog.value = choice;
7888: document.docslogform.submit();
7889: return;
7890: }
7891:
7892: ENDHIST
7893: }
7894:
1.484 raeburn 7895: sub inject_data_js {
7896: return <<ENDINJECT;
7897:
7898: function injectData(current, hiddenField, name, value) {
7899: currentElement = document.getElementById(hiddenField);
7900: currentElement.name = name;
7901: currentElement.value = value;
7902: current.submit();
7903: }
7904:
7905: ENDINJECT
7906: }
7907:
7908: sub dump_switchserver_js {
7909: my @hosts = @_;
1.594 damieng 7910: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 7911: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7912: swit => 'Switch server?',
1.594 damieng 7913: );
7914: my %html_js_lt = &Apache::lonlocal::texthash(
7915: swit => 'Switch server?',
1.568 raeburn 7916: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7917: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7918: chos => 'Choose server',
7919: );
1.594 damieng 7920: &js_escape(\%js_lt);
7921: &html_escape(\%html_js_lt);
7922: &js_escape(\%html_js_lt);
1.484 raeburn 7923: my $role = $env{'request.role'};
7924: my $js = <<"ENDSWJS";
7925: <script type="text/javascript">
7926: function write_switchserver() {
7927: var server;
7928: if (document.setserver.posshosts.length > 0) {
7929: for (var i=0; i<document.setserver.posshosts.length; i++) {
7930: if (document.setserver.posshosts[i].checked) {
7931: server = document.setserver.posshosts[i].value;
7932: }
7933: }
7934: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7935: }
7936: window.close();
7937: }
7938: </script>
7939:
7940: ENDSWJS
7941:
7942: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7943: {'only_body' => 1,
7944: 'js_ready' => 1,});
7945: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7946:
7947: my $hostpicker;
7948: my $count = 0;
7949: foreach my $host (sort(@hosts)) {
7950: my $checked;
7951: if ($count == 0) {
7952: $checked = ' checked="checked"';
7953: }
7954: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7955: $host.'"'.$checked.' />'.$host.'</label> ';
7956: $count++;
7957: }
7958:
7959: return <<"ENDSWITCHJS";
7960:
7961: function dump_needs_switchserver(url) {
7962: if (url!='' && url!= null) {
1.594 damieng 7963: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7964: go(url);
7965: }
7966: }
7967: return;
7968: }
7969:
7970: function choose_switchserver_window() {
7971: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7972: newWindow.document.open();
7973: newWindow.document.writeln('$startpage');
1.594 damieng 7974: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7975: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7976: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7977: '<form name="setserver" method="post" action="" \\/>\\n'+
7978: '$hostpicker\\n'+
7979: '<br \\/><br \\/>\\n'+
1.594 damieng 7980: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7981: 'onclick="write_switchserver();" \\/>\\n'+
7982: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7983: newWindow.document.writeln('$endpage');
7984: newWindow.document.close();
7985: newWindow.focus();
7986: }
7987:
7988: ENDSWITCHJS
7989: }
7990:
7991: sub makedocslogform {
7992: my ($formelems,$docslog) = @_;
7993: return <<"LOGSFORM";
7994: <form action="/adm/coursedocs" method="post" name="docslogform">
7995: <input type="hidden" name="docslog" value="$docslog" />
7996: $formelems
7997: </form>
7998: LOGSFORM
7999: }
8000:
8001: sub makesimpleeditform {
8002: my ($formelems) = @_;
8003: return <<"SIMPFORM";
8004: <form name="simpleedit" method="post" action="/adm/coursedocs">
8005: <input type="hidden" name="importdetail" value="" />
8006: $formelems
8007: </form>
8008: SIMPFORM
8009: }
8010:
1.606 raeburn 8011: sub makenewproblem {
8012: my ($r,$coursedom,$coursenum) = @_;
8013: # Creating a new problem
8014: my ($redirect,$error);
8015: if ($env{'form.authorrole'}) {
8016: my ($newsubdir,$filename);
8017: if ($env{'form.newsubdir'}) {
8018: if ($env{'form.newsubdirname'} ne '') {
8019: $newsubdir = $env{'form.newsubdirname'};
8020: }
8021: }
8022: if ($env{'form.newresourcename'}) {
8023: $filename = $env{'form.newresourcename'};
8024: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8025: $filename =~ s/`//g;
8026: $filename =~ s{/\.\./}{_}g;
8027: $filename =~ s/\.+/./g;
8028: $filename =~ s{/+}{_}g;
8029: if ($filename ne '') {
8030: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8031: if (($ext) && ($ext ne '.problem')) {
8032: $filename = $name.'.problem';
8033: } elsif ($ext eq '') {
8034: $filename .= '.problem';
8035: }
8036: my $docroot = $r->dir_config('lonDocRoot');
8037: my @ids=&Apache::lonnet::current_machine_ids();
8038: if ($env{'form.authorrole'} eq 'author') {
8039: if ($env{'user.author'}) {
8040: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8041: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8042: my $path = $docroot.$url;
8043: my $subdir = $env{'form.authorpath'};
8044: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8045: }
8046: }
8047: } elsif ($env{'form.authorrole'} eq 'course') {
8048: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8049: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8050: my $url = "/priv/$coursedom/$coursenum";
8051: my $path=$docroot.$url;
8052: my $subdir = $env{'form.authorpath'};
8053: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8054: if ($redirect) {
8055: my $rightsfile = 'default.rights';
8056: my $sourcerights = "$path/$rightsfile";
8057: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8058: my $now = time;
8059: if (!-e $sourcerights) {
8060: my $cid = $coursedom.'_'.$coursenum;
8061: if (open(my $fh,">$sourcerights")) {
8062: print $fh <<END;
8063: <accessrule effect="deny" realm="" type="course" role="" />
8064: <accessrule effect="allow" realm="$cid" type="course" role="" />
8065: END
8066: close($fh);
8067: }
8068: }
8069: if (!-e "$sourcerights.meta") {
8070: if (open(my $fh,">$sourcerights.meta")) {
8071: my $author=$env{'environment.firstname'}.' '.
8072: $env{'environment.middlename'}.' '.
8073: $env{'environment.lastname'}.' '.
8074: $env{'environment.generation'};
8075: $author =~ s/\s+$//;
8076: print $fh <<"END";
8077:
8078: <abstract></abstract>
8079: <author>$author</author>
8080: <authorspace>$coursenum:$coursedom</authorspace>
8081: <copyright>private</copyright>
8082: <creationdate>$now</creationdate>
8083: <customdistributionfile></customdistributionfile>
8084: <dependencies></dependencies>
8085: <domain>$coursedom</domain>
8086: <highestgradelevel>0</highestgradelevel>
8087: <keywords></keywords>
8088: <language>notset </language>
8089: <lastrevisiondate>$now</lastrevisiondate>
8090: <lowestgradelevel>0</lowestgradelevel>
8091: <mime>rights</mime>
8092: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8093: <notes></notes>
8094: <obsolete></obsolete>
8095: <obsoletereplacement></obsoletereplacement>
8096: <owner>$coursenum:$coursedom</owner>
8097: <rule>deny:::course,allow:$cid::course</rule>
8098: <sourceavail></sourceavail>
8099: <standards></standards>
8100: <subject></subject>
8101: <title></title>
8102: END
8103: close($fh);
8104: }
8105: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8106: if (!-e "$docroot/res/$coursedom") {
8107: mkdir("$docroot/res/$coursedom",0755);
8108: }
8109: if (!-e "$docroot/res/$coursedom/$coursenum") {
8110: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8111: }
8112: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8113: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8114: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8115: }
8116: }
8117: }
8118: if ($env{'form.newresourceadd'}) {
8119: my $template = $env{'form.template'};
8120: my $source = $docroot.$redirect;
8121: my $target = $redirect;
8122: $target =~ s{^/priv/}{/res/};
8123: $target = $docroot.$target;
8124: if (!-e $source) {
8125: my $copyfrom;
8126: if ($template) {
8127: my %templates;
8128: my @files = &Apache::lonhomework::get_template_list('problem');
8129: foreach my $poss (@files) {
8130: if (ref($poss) eq 'ARRAY') {
8131: if ($template eq $poss->[0]) {
8132: $templates{$template} = 1;
8133: last;
8134: }
8135: }
8136: }
8137: if ($templates{$template}) {
8138: $copyfrom = $template;
8139: }
8140: }
8141: unless ($copyfrom) {
8142: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8143: }
8144: &File::Copy::copy($copyfrom,$source);
8145: }
8146: if (!-e "$source.meta") {
8147: my $cid = $coursedom.'_'.$coursenum;
8148: my $now = time;
8149: if (open(my $fh,">$source.meta")) {
8150: my $author=$env{'environment.firstname'}.' '.
8151: $env{'environment.middlename'}.' '.
8152: $env{'environment.lastname'}.' '.
8153: $env{'environment.generation'};
8154: $author =~ s/\s+$//;
8155: my $title = $env{'form.newresourcetitle'};
8156: $title =~ s/^\s+|\s+$//g;
8157: print $fh <<END;
8158:
8159: <abstract></abstract>
8160: <author>$author</author>
8161: <authorspace>$coursenum:$coursedom</authorspace>
8162: <copyright>custom</copyright>
8163: <creationdate>$now</creationdate>
8164: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8165: <dependencies></dependencies>
8166: <domain>$coursedom</domain>
8167: <highestgradelevel>0</highestgradelevel>
8168: <keywords></keywords>
8169: <language>notset </language>
8170: <lastrevisiondate>$now</lastrevisiondate>
8171: <lowestgradelevel>0</lowestgradelevel>
8172: <mime>problem</mime>
8173: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8174: <notes></notes>
8175: <obsolete></obsolete>
8176: <obsoletereplacement></obsoletereplacement>
8177: <owner>$coursenum:$coursedom</owner>
8178: <sourceavail></sourceavail>
8179: <standards></standards>
8180: <subject></subject>
8181: <title>$title</title>
8182: END
8183: close($fh);
8184: }
8185: }
8186: }
8187: }
8188: }
8189: } else {
8190: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8191: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8192: if (grep(/^\Q$rolehome\E$/,@ids)) {
8193: my $now = time;
8194: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8195: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8196: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8197: my $url = "/priv/$audom/$auname";
8198: my $path = $r->dir_config('lonDocRoot').$url;
8199: my $subdir = $env{'form.authorpath'};
8200: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8201: }
8202: }
8203: }
8204: }
8205: }
8206: }
8207: }
8208: return ($redirect,$error);
8209: }
8210:
8211: sub finishnewprob {
8212: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8213: unless (-d $path) {
8214: unless (mkdir($path,02770)) {
8215: return;
8216: }
8217: }
1.606 raeburn 8218: my $redirect;
8219: if ($subdir ne '/') {
8220: $subdir = &cleandir($subdir);
8221: if (($subdir ne '') && (-d "$path/$subdir")) {
8222: $path .= "/$subdir";
8223: $url .= "/$subdir";
8224: }
8225: }
8226: my $dest;
8227: if ($newsubdir ne '') {
8228: $newsubdir = &cleandir($newsubdir);
8229: }
8230: if ($newsubdir ne '') {
8231: if (-d "$path/$newsubdir") {
8232: $dest = "$path/$newsubdir/$filename";
8233: } else {
8234: my $dirok;
8235: unless (-e "$path/$newsubdir") {
8236: if (mkdir("$path/$newsubdir",02770)) {
8237: if (chmod(02770,"$path/$newsubdir")) {
8238: $dirok = 1;
8239: }
8240: }
8241: }
8242: if ($dirok) {
8243: $dest = "$path/$newsubdir/$filename";
8244: }
8245: }
8246: if (($dest ne '') && (!-e $dest)) {
8247: $redirect = "$url/$newsubdir/$filename";
8248: }
8249: } else {
8250: $dest = "$path/$filename";
8251: if (($dest ne '') && (!-e $dest)) {
8252: $redirect = "$url/$filename";
8253: }
8254: }
8255: return $redirect;
8256: }
8257:
8258: sub cleandir {
8259: my ($dir) = @_;
8260: $dir =~ s/^\s+//;
8261: $dir =~ s/\s+$//;
8262: $dir =~ s/\.+//g;
8263: $dir =~ s/[\#\?&%\":]//g;
8264: return $dir;
8265: }
8266:
1.329 droeschl 8267: 1;
8268: __END__
8269:
8270:
8271: =head1 NAME
8272:
8273: Apache::londocs.pm
8274:
8275: =head1 SYNOPSIS
8276:
8277: This is part of the LearningOnline Network with CAPA project
8278: described at http://www.lon-capa.org.
8279:
8280: =head1 SUBROUTINES
8281:
8282: =over
8283:
8284: =item %help=()
8285:
8286: Available help topics
8287:
8288: =item mapread()
8289:
1.344 bisitz 8290: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8291: @order and @resources, determines status
8292: sets @order - pointer to resources in right order
8293: sets @resources - array with the resources with correct idx
8294:
8295: =item authorhosts()
8296:
8297: Return hash with valid author names
8298:
8299: =item clean()
8300:
8301: =item dumpcourse()
8302:
8303: Actually dump course
8304:
8305: =item group_import()
8306:
8307: Imports the given (name, url) resources into the course
8308: coursenum, coursedom, and folder must precede the list
8309:
8310: =item breadcrumbs()
8311:
8312: =item log_docs()
8313:
8314: =item docs_change_log()
8315:
8316: =item update_paste_buffer()
8317:
8318: =item print_paste_buffer()
8319:
8320: =item do_paste_from_buffer()
8321:
1.538 raeburn 8322: =item do_buffer_empty()
8323:
8324: =item clear_from_buffer()
8325:
1.492 raeburn 8326: =item get_newmap_url()
8327:
8328: =item dbcopy()
8329:
8330: =item uniqueness_check()
8331:
8332: =item contained_map_check()
8333:
8334: =item url_paste_fixups()
8335:
8336: =item apply_fixups()
8337:
8338: =item copy_dependencies()
8339:
1.329 droeschl 8340: =item update_parameter()
8341:
8342: =item handle_edit_cmd()
8343:
8344: =item editor()
8345:
8346: =item process_file_upload()
8347:
8348: =item process_secondary_uploads()
8349:
8350: =item is_supplemental_title()
8351:
8352: =item entryline()
8353:
8354: =item tiehash()
8355:
8356: =item untiehash()
8357:
8358: =item checkonthis()
8359:
8360: check on this
8361:
8362: =item verifycontent()
8363:
8364: Verify Content
8365:
8366: =item devalidateversioncache() & checkversions()
8367:
8368: Check Versions
8369:
8370: =item mark_hash_old()
8371:
8372: =item is_hash_old()
8373:
8374: =item changewarning()
8375:
8376: =item init_breadcrumbs()
8377:
8378: Breadcrumbs for special functions
8379:
1.484 raeburn 8380: =item create_list_elements()
8381:
8382: =item create_form_ul()
8383:
8384: =item startContentScreen()
8385:
8386: =item endContentScreen()
8387:
8388: =item supplemental_base()
8389:
8390: =item embedded_form_elems()
8391:
8392: =item embedded_destination()
8393:
8394: =item return_to_editor()
8395:
8396: =item decompression_info()
8397:
8398: =item decompression_phase_one()
8399:
8400: =item decompression_phase_two()
8401:
8402: =item remove_archive()
8403:
8404: =item generate_admin_menu()
8405:
8406: =item generate_edit_table()
8407:
8408: =item editing_js()
8409:
8410: =item history_tab_js()
8411:
8412: =item inject_data_js()
8413:
8414: =item dump_switchserver_js()
8415:
1.485 raeburn 8416: =item resize_scrollbox_js()
1.484 raeburn 8417:
8418: =item makedocslogform()
8419:
1.485 raeburn 8420: =item makesimpleeditform()
8421:
1.329 droeschl 8422: =back
8423:
8424: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>