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