Annotation of loncom/interface/londocs.pm, revision 1.648
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.648 ! raeburn 4: # $Id: londocs.pm,v 1.647 2017/12/29 15:11:18 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.645 raeburn 48: use Apache::lonparmset();
1.329 droeschl 49: use HTML::Entities;
1.488 raeburn 50: use HTML::TokeParser;
1.329 droeschl 51: use GDBM_File;
1.578 raeburn 52: use File::MMagic;
1.606 raeburn 53: use File::Copy;
1.329 droeschl 54: use Apache::lonlocal;
55: use Cwd;
1.643 raeburn 56: use UUID::Tiny ':std';
1.329 droeschl 57: use LONCAPA qw(:DEFAULT :match);
58:
59: my $iconpath;
60:
61: my %hash;
62:
63: my $hashtied;
64: my %alreadyseen=();
65:
66: my $hadchanges;
1.557 raeburn 67: my $suppchanges;
1.329 droeschl 68:
69:
70: my %help=();
71:
72:
73: sub mapread {
74: my ($coursenum,$coursedom,$map)=@_;
75: return
76: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
77: $map);
78: }
79:
80: sub storemap {
1.492 raeburn 81: my ($coursenum,$coursedom,$map,$contentchg)=@_;
82: my $report;
83: if (($contentchg) && ($map =~ /^default/)) {
84: $report = 1;
85: }
1.329 droeschl 86: my ($outtext,$errtext)=
87: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 88: $map,1,$report);
1.329 droeschl 89: if ($errtext) { return ($errtext,2); }
1.364 bisitz 90:
1.557 raeburn 91: if ($map =~ /^default/) {
92: $hadchanges=1;
93: } else {
94: $suppchanges=1;
95: }
1.329 droeschl 96: return ($errtext,0);
97: }
98:
99:
100:
101: sub authorhosts {
102: my %outhash=();
103: my $home=0;
104: my $other=0;
105: foreach my $key (keys(%env)) {
106: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
107: my $role=$1;
108: my $realm=$2;
109: my ($start,$end)=split(/\./,$env{$key});
110: if (($start) && ($start>time)) { next; }
111: if (($end) && (time>$end)) { next; }
112: my ($ca,$cd);
113: if ($1 eq 'au') {
114: $ca=$env{'user.name'};
115: $cd=$env{'user.domain'};
116: } else {
117: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
118: }
119: my $allowed=0;
120: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
121: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 122: foreach my $id (@ids) {
123: if ($id eq $myhome) {
124: $allowed=1;
125: last;
126: }
127: }
1.329 droeschl 128: if ($allowed) {
129: $home++;
1.484 raeburn 130: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 131: } else {
1.484 raeburn 132: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 133: $other++;
134: }
135: }
136: }
137: return ($home,$other,%outhash);
138: }
139:
140:
141: sub clean {
142: my ($title)=@_;
143: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 144: return $title;
1.329 droeschl 145: }
146:
1.617 raeburn 147: sub default_folderpath {
148: my ($coursenum,$coursedom,$navmapref) = @_;
149: return unless ($coursenum && $coursedom && ref($navmapref));
150: # Check if entire course is hidden and/or encrypted
151: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
152: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
153: unless (ref($$navmapref)) {
154: $$navmapref = Apache::lonnavmaps::navmap->new();
155: }
156: if (ref($$navmapref)) {
157: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
158: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
159: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
160: unless (@resources) {
161: $hiddenmap = 1;
162: unless ($env{'request.role.adv'}) {
163: $hiddentop = 1;
164: if ($env{'form.folder'}) {
165: undef($env{'form.folder'});
166: }
167: }
168: }
169: }
170: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
171: $encryptmap = 1;
172: }
173: }
174: unless ($hiddentop) {
175: $folderpath='default&'.&escape(&mt('Main Content')).
176: '::'.$hiddenmap.':'.$encryptmap.'::';
177: }
178: if (wantarray) {
179: return ($folderpath,$hiddentop);
180: } else {
181: return $folderpath;
182: }
183: }
1.329 droeschl 184:
185: sub dumpcourse {
186: my ($r) = @_;
1.408 raeburn 187: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 188: my ($starthash,$js);
189: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
190: $js = <<"ENDJS";
191: <script type="text/javascript">
192: // <![CDATA[
193:
194: function hide_searching() {
195: if (document.getElementById('searching')) {
196: document.getElementById('searching').style.display = 'none';
197: }
198: return;
199: }
200:
201: // ]]>
202: </script>
203: ENDJS
204: $starthash = {
205: add_entries => {'onload' => "hide_searching();"},
206: };
207: }
1.568 raeburn 208: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
209: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 210: $r->print(&startContentScreen('tools'));
1.329 droeschl 211: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 212: unless ($home) {
213: $r->print(&endContentScreen());
214: return '';
215: }
1.329 droeschl 216: my $origcrsid=$env{'request.course.id'};
217: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
218: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
219: # Do the dumping
1.484 raeburn 220: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
221: $r->print(&endContentScreen());
222: return '';
223: }
1.531 raeburn 224: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 225: $r->print('<h3>'.&mt('Copying Files').'</h3>');
226: my $title=$env{'form.authorfolder'};
227: $title=&clean($title);
1.567 raeburn 228: my ($navmap,$errormsg) =
229: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
230: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
231: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
232: my (%maps,%resources,%titles);
233: if (!ref($navmap)) {
234: $r->print($errormsg.
235: &endContentScreen());
236: return '';
237: } else {
238: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
239: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 240: }
1.567 raeburn 241: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
242: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
243: %newcontent,%has_simpleprobs);
244: foreach my $item (sort {$a <=> $b} (@todump)) {
245: my $name = $env{'form.namefor_'.$item};
246: if ($resources{$item}) {
247: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
248: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
249: $tocopy{$1} = $name;
250: $display{$item} = $1;
251: $lookup{$1} = $item;
252: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
253: $simpleproblems{$item} = {
254: symb => $resources{$item},
255: name => $name,
256: };
257: $display{$item} = 'simpleproblem_'.$name;
258: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
259: $has_simpleprobs{$1}{$id} = $item;
260: }
261: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
262: my $marker = $1;
263: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
264: $simplepages{$item} = {
265: res => $res,
266: title => $titles{$item},
267: db => $db_name,
268: marker => $marker,
269: symb => $resources{$item},
270: name => $name,
271: };
272: $display{$item} = '/'.$res;
273: }
274: } elsif ($maps{$item}) {
275: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
276: $tocopy{$1} = $name;
277: $display{$item} = $1;
278: $lookup{$1} = $item;
279: }
280: } else {
281: next;
282: }
283: }
1.329 droeschl 284: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
285: $crs=~s/\_/\//g;
1.567 raeburn 286: my $mm = new File::MMagic;
287: my $prefix = "/uploaded/$cdom/$cnum/";
288: %replacehash = %tocopy;
289: foreach my $item (sort(keys(%simpleproblems))) {
290: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
291: $newcontent{$display{$item}} = $content;
292: }
293: my $gateway = Apache::lonhtmlgateway->new('web');
294: foreach my $item (sort(keys(%simplepages))) {
295: if (ref($simplepages{$item}) eq 'HASH') {
296: my $pagetitle = $simplepages{$item}{'title'};
297: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
298: my %contents;
299: foreach my $field (keys(%fields)) {
300: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
301: my $name = $1;
302: my $msg = $fields{$field};
303: if ($name eq 'webreferences') {
304: if ($msg =~ m{^https?://}) {
305: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
306: }
307: } else {
308: $msg = &Encode::decode('utf8',$msg);
309: $msg = $gateway->process_outgoing_html($msg,1);
310: $contents{$name} = $msg;
311: }
312: } elsif ($field eq 'uploaded.photourl') {
313: my $marker = $simplepages{$item}{marker};
314: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
315: my $filepath = $1;
316: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
317: if ($fname ne '') {
318: $fname=~s/\.(\w+)$//;
319: my $ext=$1;
320: $fname = &clean($fname);
321: $fname.='.'.$ext;
322: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
323: $replacehash{$filepath} = $relpath.$fname;
324: $deps{$item}{$filepath} = 1;
325: }
326: }
327: }
328: }
329: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
330: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
331: my $content = '
332: <html>
333: <head>
334: <title>'.$pagetitle.'</title>
335: </head>
336: <body bgcolor="#ffffff">';
337: if ($contents{title}) {
338: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
339: }
340: if ($contents{image}) {
341: $content .= "\n".$contents{image};
342: }
343: if ($contents{content}) {
344: $content .= '
345: <div class="LC_Box">
1.577 bisitz 346: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 347: $contents{content}.'
348: </div>';
349: }
350: if ($contents{webreferences}) {
351: $content .= '
352: <div class="LC_Box">
1.577 bisitz 353: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 354: $contents{webreferences}.'
355: </div>';
356: }
357: $content .= '
358: </body>
359: </html>
360: ';
361: $newcontent{'/'.$simplepages{$item}{res}} = $content;
362: }
363: }
364: foreach my $item (keys(%tocopy)) {
365: unless ($item=~/\.(sequence|page)$/) {
366: my $currurlpath = $prefix.$item;
367: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
368: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
369: }
370: }
371: foreach my $num (sort {$a <=> $b} (@todump)) {
372: my $src = $display{$num};
373: next if ($src eq '');
374: my @needcopy = ();
375: if ($replacehash{$src}) {
376: push(@needcopy,$src);
377: if (ref($deps{$num}) eq 'HASH') {
378: foreach my $dep (sort(keys(%{$deps{$num}}))) {
379: if ($replacehash{$dep}) {
380: push(@needcopy,$dep);
381: }
382: }
383: }
384: } elsif ($src =~ /^simpleproblem_/) {
385: push(@needcopy,$src);
386: }
387: next if (@needcopy == 0);
388: my ($result,$depresult);
389: for (my $i=0; $i<@needcopy; $i++) {
390: my $item = $needcopy[$i];
391: my $newfilename;
392: if ($simpleproblems{$num}) {
393: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
394: } else {
395: $newfilename=$title.'/'.$replacehash{$item};
396: }
397: $newfilename=~s/\.(\w+)$//;
398: my $ext=$1;
399: $newfilename=&clean($newfilename);
400: $newfilename.='.'.$ext;
401: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
402: if ($newrelpath ne $replacehash{$item}) {
403: $replacehash{$item} = $newrelpath;
404: }
405: my @dirs=split(/\//,$newfilename);
406: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
407: my $makepath=$path;
408: my $fail;
409: my $origin;
410: for (my $i=0;$i<$#dirs;$i++) {
411: $makepath.='/'.$dirs[$i];
412: unless (-e $makepath) {
413: unless(mkdir($makepath,0755)) {
414: $fail = &mt('Directory creation failed.');
415: }
416: }
417: }
418: if ($i == 0) {
419: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
420: } else {
421: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
422: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
423: &mt('(dependency)').'</span>: ';
424: }
425: if (-e $path.'/'.$newfilename) {
426: $fail = &mt('Destination already exists -- not overwriting.');
427: } else {
428: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
429: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
430: ($item =~ /^simpleproblem_/)) {
431: print $fh $newcontent{$item};
432: } else {
433: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
434: if (-e $fileloc) {
435: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
436: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
437: (ref($has_simpleprobs{$item}) eq 'HASH')) {
438: my %changes = %{$has_simpleprobs{$item}};
439: my $content = &Apache::lonclonecourse::rewritefile(
440: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
441: (%replacehash,$crs => '')
442: );
443: my $updatedcontent = '';
444: my $parser = HTML::TokeParser->new(\$content);
445: $parser->attr_encoded(1);
446: while (my $token = $parser->get_token) {
447: if ($token->[0] eq 'S') {
448: if (($token->[1] eq 'resource') &&
449: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
450: ($changes{$token->[2]->{'id'}})) {
451: my $id = $token->[2]->{'id'};
452: $updatedcontent .= '<'.$token->[1];
453: foreach my $attrib (@{$token->[3]}) {
454: next unless ($attrib =~ /^(src|type|title|id)$/);
455: if ($attrib eq 'src') {
456: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
457: if ($file) {
458: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
459: } else {
460: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
461: }
462: } else {
463: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
464: }
465: }
466: $updatedcontent .= ' />'."\n";
467: } else {
468: $updatedcontent .= $token->[4]."\n";
469: }
470: } else {
471: $updatedcontent .= $token->[2];
472: }
473: }
474: print $fh $updatedcontent;
475: } else {
476: print $fh &Apache::lonclonecourse::rewritefile(
477: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
478: (%replacehash,$crs => '')
479: );
480: }
481: } else {
482: print $fh
483: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
484: }
485: } else {
486: $fail = &mt('Source does not exist.');
487: }
488: }
489: $fh->close();
490: } else {
491: $fail = &mt('Could not write to destination.');
492: }
493: }
494: my $text;
495: if ($fail) {
496: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
497: } else {
498: $text = '<span class="LC_success">'.&mt('ok').'</span>';
499: }
500: if ($i == 0) {
501: $result .= $text;
502: } else {
503: $depresult .= $text.'</li>';
504: }
505: }
506: $r->print($result);
507: if ($depresult) {
508: $r->print('<ul>'.$depresult.'</ul>');
509: }
510: }
511: } else {
512: my ($navmap,$errormsg) =
513: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
514: if (!ref($navmap)) {
515: $r->print($errormsg);
516: } else {
517: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
518: $r->rflush();
519: my ($preamble,$formname);
520: $formname = 'dumpdoc';
521: unless ($home==1) {
522: $preamble = '<div class="LC_left_float">'.
523: '<fieldset><legend>'.
524: &mt('Select the Authoring Space').
525: '</legend><select name="authorspace">';
1.329 droeschl 526: }
1.567 raeburn 527: my @orderspaces = ();
528: foreach my $key (sort(keys(%outhash))) {
529: if ($key=~/^home_(.+)$/) {
530: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
531: unshift(@orderspaces,$1);
532: } else {
533: push(@orderspaces,$1);
534: }
535: }
536: }
1.569 raeburn 537: if ($home>1) {
538: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
539: }
1.567 raeburn 540: foreach my $user (@orderspaces) {
1.329 droeschl 541: if ($home==1) {
1.567 raeburn 542: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 543: } else {
1.567 raeburn 544: $preamble .= '<option value="'.$user.'">'.$user.' - '.
545: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
546: }
1.329 droeschl 547: }
1.567 raeburn 548: unless ($home==1) {
549: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 550: }
1.567 raeburn 551: my $title=$origcrsdata{'description'};
552: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 553: $title=&clean($title);
1.567 raeburn 554: $preamble .= '<div class="LC_left_float">'.
555: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
556: '<input type="text" size="50" name="authorfolder" value="'.
557: $title.'" />'.
558: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
559: my %uploadedfiles;
560: &tiehash();
561: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
562: my ($ext)=($file=~/\.(\w+)$/);
563: # FIXME Check supplemental here
564: my $title=$hash{'title_'.$hash{
565: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
566: if (!$title) {
567: $title=$file;
568: } else {
569: $title=~s|/|_|g;
570: }
571: $title=~s/\.(\w+)$//;
572: $title=&clean($title);
573: $title.='.'.$ext;
574: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
575: $uploadedfiles{$file} = $title;
576: }
577: &untiehash();
578: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
579: undef,undef,$preamble,$home,\%uploadedfiles));
580: }
1.329 droeschl 581: }
1.484 raeburn 582: $r->print(&endContentScreen());
1.329 droeschl 583: }
584:
1.567 raeburn 585: sub recurse_html {
586: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
587: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
588: my (%allfiles,%codebase);
589: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
590: if (keys(%allfiles)) {
591: foreach my $dependency (keys(%allfiles)) {
592: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
593: my ($depurl,$relfile,$newcontainer);
594: if ($dependency =~ m{^/}) {
595: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
596: $relfile = $1;
597: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
598: $newcontainer = $1;
599: next if ($replacehash->{$newcontainer});
600: }
601: $depurl = $dependency;
602: } else {
603: next;
604: }
605: } else {
606: $relfile = $dependency;
607: $depurl = $currurlpath;
1.630 raeburn 608: $depurl =~ s{[^/]+$}{};
1.567 raeburn 609: $depurl .= $dependency;
1.630 raeburn 610: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 611: }
612: next if ($relfile eq '');
613: my $newname = $replacehash->{$container};
614: $newname =~ s{[^/]+$}{};
615: $replacehash->{$newcontainer} = $newname.$relfile;
616: $deps->{$item}{$newcontainer} = 1;
617: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
618: my $depfile = &Apache::lonnet::filelocation('',$depurl);
619: my $type = $mm->checktype_filename($depfile);
620: if ($type eq 'text/html') {
621: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
622: }
623: }
624: }
625: }
626: return;
627: }
628:
1.329 droeschl 629: sub group_import {
1.598 raeburn 630: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 631: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
632: %removeparam,$importuploaded,$fixuperrors);
633: $allmaps = {};
1.329 droeschl 634: while (@files) {
635: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 636: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 637: && ($caller eq 'londocs')
638: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 639:
1.329 droeschl 640: my $errtext = '';
641: my $fatal = 0;
642: my $newmapstr = '<map>'."\n".
643: '<resource id="1" src="" type="start"></resource>'."\n".
644: '<link from="1" to="2" index="1"></link>'."\n".
645: '<resource id="2" src="" type="finish"></resource>'."\n".
646: '</map>';
647: $env{'form.output'}=$newmapstr;
648: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
649: 'output',$1.$2);
1.534 raeburn 650: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 651: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
652: $fatal = 2;
653: }
654: if ($fatal) {
655: return ($errtext,$fatal);
656: }
657: }
658: if ($url) {
1.626 raeburn 659: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 660: $url = $1;
661: my $marker = $2;
662: my $info = $3;
1.604 raeburn 663: my ($toolid,%toolhash,%toolsettings);
1.642 raeburn 664: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 665: my @toolinfo = split(/:/,$info);
666: if ($residx) {
1.604 raeburn 667: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 668: $toolid = $toolsettings{'id'};
669: } else {
1.604 raeburn 670: $toolid = shift(@toolinfo);
1.598 raeburn 671: }
672: $toolid =~ s/\D//g;
1.604 raeburn 673: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 674: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
675: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 676: foreach my $item (@extras) {
677: $toolhash{$item} = &unescape($toolhash{$item});
678: }
1.645 raeburn 679: if ($folder =~ /^supplemental/) {
1.648 ! raeburn 680: delete($toolhash{'gradable'});
! 681: } else {
! 682: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 683: }
1.598 raeburn 684: if (ref($ltitoolsref) eq 'HASH') {
685: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
1.643 raeburn 686: my @deleted;
1.598 raeburn 687: $toolhash{'id'} = $toolid;
1.628 raeburn 688: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
689: ($toolhash{'target'} eq 'window')) {
1.604 raeburn 690: if ($toolhash{'target'} eq 'window') {
691: foreach my $item ('width','height') {
692: $toolhash{$item} =~ s/^\s+//;
693: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 694: if ($toolhash{$item} =~ /\D/) {
695: delete($toolhash{$item});
696: if ($residx) {
697: if ($toolsettings{$item}) {
698: push(@deleted,$item);
699: }
700: }
701: }
1.604 raeburn 702: }
703: }
704: } elsif ($residx) {
705: $toolhash{'target'} = $toolsettings{'target'};
706: if ($toolhash{'target'} eq 'window') {
1.630 raeburn 707: foreach my $item ('width','height') {
1.624 raeburn 708: $toolhash{$item} = $toolsettings{$item};
709: }
1.604 raeburn 710: }
711: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
712: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
713: if ($toolhash{'target'} eq 'window') {
714: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
715: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
716: }
717: }
1.598 raeburn 718: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 719: foreach my $item ('width','height','linktext','explanation') {
720: delete($toolhash{$item});
721: if ($residx) {
722: if ($toolsettings{$item}) {
723: push(@deleted,$item);
724: }
1.604 raeburn 725: }
726: }
1.628 raeburn 727: } elsif ($toolhash{'target'} eq 'tab') {
728: foreach my $item ('width','height') {
729: delete($toolhash{$item});
730: if ($residx) {
731: if ($toolsettings{$item}) {
732: push(@deleted,$item);
733: }
734: }
735: }
1.604 raeburn 736: }
737: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 738: foreach my $item ('label','title','linktext','explanation') {
739: my $crsitem;
740: if (($item eq 'label') || ($item eq 'title')) {
741: $crsitem = 'crs'.$item;
742: } else {
743: $crsitem = $item;
744: }
1.604 raeburn 745: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 746: $toolhash{$crsitem} =~ s/^\s+//;
747: $toolhash{$crsitem} =~ s/\s+$//;
748: if ($toolhash{$crsitem} eq '') {
749: delete($toolhash{$crsitem});
1.604 raeburn 750: }
751: } else {
1.624 raeburn 752: delete($toolhash{$crsitem});
1.604 raeburn 753: }
1.624 raeburn 754: if (($residx) && (exists($toolsettings{$crsitem}))) {
755: unless (exists($toolhash{$crsitem})) {
756: push(@deleted,$crsitem);
1.604 raeburn 757: }
758: }
1.598 raeburn 759: }
760: }
1.643 raeburn 761: if ($toolhash{'passback'}) {
762: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
763: $toolhash{'gradesecret'} = $gradesecret;
764: $toolhash{'gradesecretdate'} = time;
765: }
766: if ($toolhash{'roster'}) {
767: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
768: $toolhash{'rostersecret'} = $rostersecret;
769: $toolhash{'rostersecretdate'} = time;
770: }
1.645 raeburn 771: my $changegradable;
772: if (($residx) && ($folder =~ /^default/)) {
1.648 ! raeburn 773: if ($toolsettings{'gradable'}) {
! 774: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 775: push(@deleted,'gradable');
776: $changegradable = 1;
777: }
1.648 ! raeburn 778: } elsif ($toolhash{'gradable'}) {
! 779: $changegradable = 1;
! 780: }
! 781: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 782: $changegradable = 1;
1.648 ! raeburn 783: if ($toolsettings{'gradable'}) {
! 784: $toolhash{'gradable'} = 1;
! 785: }
1.645 raeburn 786: }
787: }
1.598 raeburn 788: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 789: if ($putres eq 'ok') {
790: if (@deleted) {
791: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.645 raeburn 792: }
793: if (($changegradable) && ($folder =~ /^default/)) {
794: my $val;
795: if ($toolhash{'gradable'}) {
796: $val = 'yes';
797: } else {
798: $val = 'no';
799: }
800: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
801: 'string_yesno');
802: &remember_parms($residx,'gradable','set',$val);
803: }
804: } else {
805: return (&mt('Failed to save update to external tool.'),1);
1.604 raeburn 806: }
1.598 raeburn 807: }
808: }
809: }
1.529 raeburn 810: if (($caller eq 'londocs') &&
811: ($folder =~ /^default/)) {
1.534 raeburn 812: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 813: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
814: my $cid = $coursedom.'_'.$coursenum;
815: $allmaps =
816: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
817: $chome,$cid);
818: $donechk = 1;
819: }
820: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 821: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
822: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 823: $importuploaded = 1;
824: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
825: next if ($allmaps->{$url});
826: }
827: }
1.344 bisitz 828: if (!$residx
1.329 droeschl 829: || defined($LONCAPA::map::zombies[$residx])) {
830: $residx = &LONCAPA::map::getresidx($url,$residx);
831: push(@LONCAPA::map::order, $residx);
832: }
833: my $ext = 'false';
834: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
835: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 836: if ($name eq '') {
1.538 raeburn 837: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 838: }
839: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
840: my $filepath = $1;
841: my $fname = $name;
842: if ($fname =~ /^\W+$/) {
843: $fname = 'web';
844: } else {
845: $fname =~ s/\W/_/g;
846: }
1.599 damieng 847: if (length($fname) > 15) {
1.534 raeburn 848: $fname = substr($fname,0,14);
849: }
850: my $initialtext = &mt('Replace with your own content.');
851: my $newhtml = <<END;
1.545 raeburn 852: <html>
1.534 raeburn 853: <head>
854: <title>$name</title>
855: </head>
856: <body bgcolor="#ffffff">
857: $initialtext
858: </body>
859: </html>
860: END
861: $env{'form.output'}=$newhtml;
1.630 raeburn 862: my $result =
1.534 raeburn 863: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
864: 'output',
865: "$filepath/$residx/$fname.html");
866: if ($result =~ m{^/uploaded/}) {
867: $url = $result;
868: if ($filepath =~ /^supplemental/) {
869: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
870: $env{'user.domain'}.'___&&&___'.$name;
871: }
872: } else {
873: return (&mt('Failed to save new web page.'),1);
874: }
875: }
1.538 raeburn 876: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 877: $LONCAPA::map::resources[$residx] =
1.329 droeschl 878: join(':', ($name, $url, $ext, 'normal', 'res'));
879: }
880: }
1.529 raeburn 881: if ($importuploaded) {
882: my %import_errors;
883: my %updated = (
884: removefrommap => \%removefrommap,
885: removeparam => \%removeparam,
886: );
1.533 raeburn 887: my ($result,$msgsarray,$lockerror) =
888: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 889: if (keys(%import_errors) > 0) {
1.530 raeburn 890: $fixuperrors =
1.529 raeburn 891: '<p span class="LC_warning">'."\n".
892: &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".
893: '<ul>'."\n";
894: foreach my $key (sort(keys(%import_errors))) {
895: $fixuperrors .= '<li>'.$key.'</li>'."\n";
896: }
897: $fixuperrors .= '</ul></p>'."\n";
898: }
1.533 raeburn 899: if (ref($msgsarray) eq 'ARRAY') {
900: if (@{$msgsarray} > 0) {
901: $fixuperrors .= '<p class="LC_info">'.
902: join('<br />',@{$msgsarray}).
903: '</p>';
904: }
905: }
906: if ($lockerror) {
907: $fixuperrors .= '<p class="LC_error">'.
908: $lockerror.
909: '</p>';
910: }
1.529 raeburn 911: }
912: my ($errtext,$fatal) =
913: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 914: unless ($fatal) {
915: if ($folder =~ /^supplemental/) {
916: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 917: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
918: $folder.'.'.$container);
1.557 raeburn 919: }
920: }
1.529 raeburn 921: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 922: }
923:
924: sub log_docs {
1.494 raeburn 925: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 926: }
927:
928: {
929: my @oldresources=();
930: my @oldorder=();
931: my $parmidx;
932: my %parmaction=();
933: my %parmvalue=();
934: my $changedflag;
935:
936: sub snapshotbefore {
937: @oldresources=@LONCAPA::map::resources;
938: @oldorder=@LONCAPA::map::order;
939: $parmidx=undef;
940: %parmaction=();
941: %parmvalue=();
942: $changedflag=0;
943: }
944:
945: sub remember_parms {
946: my ($idx,$parameter,$action,$value)=@_;
947: $parmidx=$idx;
948: $parmaction{$parameter}=$action;
949: $parmvalue{$parameter}=$value;
950: $changedflag=1;
951: }
952:
953: sub log_differences {
954: my ($plain)=@_;
955: my %storehash=('folder' => $plain,
956: 'currentfolder' => $env{'form.folder'});
957: if ($parmidx) {
958: $storehash{'parameter_res'}=$oldresources[$parmidx];
959: foreach my $parm (keys(%parmaction)) {
960: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
961: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
962: }
963: }
964: my $maxidx=$#oldresources;
965: if ($#LONCAPA::map::resources>$#oldresources) {
966: $maxidx=$#LONCAPA::map::resources;
967: }
968: for (my $idx=0; $idx<=$maxidx; $idx++) {
969: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
970: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
971: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
972: $changedflag=1;
973: }
974: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
975: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
976: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
977: $changedflag=1;
978: }
979: }
980: $storehash{'maxidx'}=$maxidx;
981: if ($changedflag) { &log_docs(\%storehash); }
982: }
983: }
984:
985: sub docs_change_log {
1.611 raeburn 986: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 987: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 988: my $navmap;
1.483 raeburn 989: my $js = '<script type="text/javascript">'."\n".
990: '// <![CDATA['."\n".
991: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 992: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 993: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 994: &history_tab_js()."\n".
1.484 raeburn 995: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 996: '// ]]>'."\n".
997: '</script>'."\n";
1.484 raeburn 998: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
999: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1000: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1001: my %orderhash;
1002: my $container='sequence';
1003: my $pathitem;
1.519 raeburn 1004: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1005: $container='page';
1006: }
1.519 raeburn 1007: my $folderpath=$env{'form.folderpath'};
1008: if ($folderpath eq '') {
1.617 raeburn 1009: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1010: }
1.617 raeburn 1011: undef($navmap);
1.519 raeburn 1012: $pathitem = '<input type="hidden" name="folderpath" value="'.
1013: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1014: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1015: my $jumpto = $readfile;
1016: $jumpto =~ s{^/}{};
1017: my $tid = 1;
1.489 raeburn 1018: if ($supplementalflag) {
1019: $tid = 2;
1020: }
1.630 raeburn 1021: my ($breadcrumbtrail) =
1.509 raeburn 1022: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1023: $r->print($breadcrumbtrail.
1024: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1025: $readfile));
1.329 droeschl 1026: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1027: $env{'course.'.$env{'request.course.id'}.'.domain'},
1028: $env{'course.'.$env{'request.course.id'}.'.num'});
1029:
1030: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1031:
1032: my %saveable_parameters = ('show' => 'scalar',);
1033: &Apache::loncommon::store_course_settings('docs_log',
1034: \%saveable_parameters);
1035: &Apache::loncommon::restore_course_settings('docs_log',
1036: \%saveable_parameters);
1037: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1038: # FIXME: internationalization seems wrong here
1.329 droeschl 1039: my %lt=('hiddenresource' => 'Resources hidden',
1040: 'encrypturl' => 'URL hidden',
1041: 'randompick' => 'Randomly pick',
1042: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1043: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1044: 'set' => 'set to',
1045: 'del' => 'deleted');
1.484 raeburn 1046: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1047: $pathitem."\n".
1048: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1049: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1050: $r->print('<div class="LC_left_float">'.
1051: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1052: &makedocslogform($filter,1).
1053: '</fieldset></div><br clear="all" />');
1.329 droeschl 1054: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1055: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1056: &mt('After').'</th>'.
1057: &Apache::loncommon::end_data_table_header_row());
1058: my $shown=0;
1059: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1060: if ($env{'form.displayfilter'} eq 'currentfolder') {
1061: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1062: }
1063: my @changes=keys(%{$docslog{$id}{'logentry'}});
1064: if ($env{'form.displayfilter'} eq 'containing') {
1065: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1066: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1067: foreach my $key (@changes) {
1068: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1069: }
1.344 bisitz 1070: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1071: }
1072: my $count = 0;
1073: my $time =
1074: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1075: my $plainname =
1076: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1077: $docslog{$id}{'exe_udom'});
1078: my $about_me_link =
1079: &Apache::loncommon::aboutmewrapper($plainname,
1080: $docslog{$id}{'exe_uname'},
1081: $docslog{$id}{'exe_udom'});
1082: my $send_msg_link='';
1083: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1084: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1085: $send_msg_link ='<br />'.
1086: &Apache::loncommon::messagewrapper(&mt('Send message'),
1087: $docslog{$id}{'exe_uname'},
1088: $docslog{$id}{'exe_udom'});
1089: }
1090: $r->print(&Apache::loncommon::start_data_table_row());
1091: $r->print('<td>'.$time.'</td>
1092: <td>'.$about_me_link.
1093: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1094: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1095: $send_msg_link.'</td><td>'.
1096: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1097: my $is_supp = 0;
1098: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1099: $is_supp = 1;
1100: }
1.329 droeschl 1101: # Before
1102: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1103: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1104: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1105: if ($oldname ne $newname) {
1.488 raeburn 1106: my $shown = &LONCAPA::map::qtescape($oldname);
1107: if ($is_supp) {
1108: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1109: }
1110: $r->print($shown);
1.329 droeschl 1111: }
1112: }
1113: $r->print('<ul>');
1114: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1115: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1116: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1117: if ($is_supp) {
1118: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1119: }
1120: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1121: }
1122: }
1123: $r->print('</ul>');
1124: # After
1125: $r->print('</td><td>');
1126:
1127: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1128: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1129: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1130: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1131: my $shown = &LONCAPA::map::qtescape($newname);
1132: if ($is_supp) {
1133: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1134: }
1135: $r->print($shown);
1.329 droeschl 1136: }
1.364 bisitz 1137: }
1.329 droeschl 1138: $r->print('<ul>');
1139: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1140: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1141: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1142: if ($is_supp) {
1143: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1144: }
1145: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1146: }
1147: }
1148: $r->print('</ul>');
1149: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1150: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1.645 raeburn 1151: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1152: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1153: # FIXME: internationalization seems wrong here
1.329 droeschl 1154: $r->print('<li>'.
1155: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1156: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1157: .'</li>');
1158: }
1159: }
1160: $r->print('</ul>');
1161: }
1162: # End
1163: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1164: $shown++;
1165: if (!($env{'form.show'} eq &mt('all')
1166: || $shown<=$env{'form.show'})) { last; }
1167: }
1.484 raeburn 1168: $r->print(&Apache::loncommon::end_data_table()."\n".
1169: &makesimpleeditform($pathitem)."\n".
1170: '</div></div>');
1171: $r->print(&endContentScreen());
1.329 droeschl 1172: }
1173:
1174: sub update_paste_buffer {
1.492 raeburn 1175: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1176: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1177: if ($env{'form.multiremove'}) {
1178: $env{'form.multiremove'} =~ s/,$//;
1179: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1180: }
1181: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1182: if ($env{'form.multicut'}) {
1183: $env{'form.multicut'} =~ s/,$//;
1184: foreach my $item (split(/,/,$env{'form.multicut'})) {
1185: unless ($removals{$item}) {
1186: $cuts{$item} = 1;
1187: push(@possibles,$item.':cut');
1188: }
1189: }
1190: }
1191: if ($env{'form.multicopy'}) {
1192: $env{'form.multicopy'} =~ s/,$//;
1193: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1194: unless ($removals{$item} || $cuts{$item}) {
1195: push(@possibles,$item.':copy');
1196: }
1197: }
1198: }
1199: } elsif ($env{'form.markcopy'}) {
1200: @possibles = split(/,/,$env{'form.markcopy'});
1201: }
1.329 droeschl 1202:
1.538 raeburn 1203: return if (@possibles == 0);
1.329 droeschl 1204: return if (!defined($env{'form.copyfolder'}));
1205:
1206: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1207: $env{'form.copyfolder'});
1.538 raeburn 1208: return if ($fatal);
1209:
1210: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1211:
1.538 raeburn 1212: # Retrieve current paste buffer suffixes.
1213: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1214: my (%pasteurls,@newpaste);
1215:
1216: # Construct identifiers for current contents of user's paste buffer
1217: if (@currpaste) {
1218: foreach my $suffix (@currpaste) {
1219: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1220: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.630 raeburn 1221: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1222: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1223: ($url ne '')) {
1.597 raeburn 1224: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1225: }
1226: }
1227: }
1228:
1229: # Mark items for copying (skip any items already in user's paste buffer)
1230: my %addtoenv;
1.597 raeburn 1231:
1232: my @pathitems = split(/\&/,$env{'form.folderpath'});
1233: my @folderconf = split(/\:/,$pathitems[-1]);
1234: my $ispage = $folderconf[4];
1235:
1.538 raeburn 1236: foreach my $item (@possibles) {
1237: my ($orderidx,$cmd) = split(/:/,$item);
1238: next if ($orderidx =~ /\D/);
1239: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1240: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1241: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1242: my %denied = &action_restrictions($coursenum,$coursedom,
1243: &LONCAPA::map::qtescape($url),
1244: $env{'form.folderpath'},\%curr_groups);
1245: next if ($denied{'copy'});
1246: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1247: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1248: my ($suffix,$errortxt,$locknotfreed) =
1249: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1250: if ($suffix ne '') {
1251: push(@newpaste,$suffix);
1252: } else {
1253: if ($locknotfreed) {
1254: return $locknotfreed;
1255: }
1.538 raeburn 1256: }
1257: if (&is_supplemental_title($title)) {
1258: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1259: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1260: }
1.329 droeschl 1261:
1.538 raeburn 1262: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1263: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1264: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1265: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1266: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1267: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1268: my $prefix = $1;
1269: my $subdir =$2;
1270: if ($subdir eq '') {
1271: $subdir = $prefix;
1.492 raeburn 1272: }
1.538 raeburn 1273: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1274: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1275: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1276: if (ref($hierarchy{$url}) eq 'HASH') {
1277: my ($nested,$nestednames);
1278: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1279: $nested =~ s/\&$//;
1280: $nestednames =~ s/\Q___&&&___\E$//;
1281: if ($nested ne '') {
1282: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1283: }
1284: if ($nestednames ne '') {
1285: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1286: }
1.492 raeburn 1287: }
1288: }
1.591 raeburn 1289: if ($locknotfreed) {
1290: $output = $locknotfreed;
1291: last;
1292: }
1.492 raeburn 1293: }
1.538 raeburn 1294: if (@newpaste) {
1295: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1296: }
1.492 raeburn 1297: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1298: delete($env{'form.markcopy'});
1.591 raeburn 1299: return $output;
1.329 droeschl 1300: }
1301:
1.492 raeburn 1302: sub recurse_uploaded_maps {
1303: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1304: if (ref($hierarchy->{$url}) eq 'HASH') {
1305: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1306: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1307: my (@uploaded,@names,%shorter);
1308: for (my $i=0; $i<@maps; $i++) {
1309: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1310: if ($inner ne '') {
1311: push(@uploaded,$inner);
1312: push(@names,&escape($titles[$i]));
1313: $shorter{$maps[$i]} = $inner;
1314: }
1315: }
1316: $$nestref .= "$dir:".join(',',@uploaded).'&';
1317: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1318: foreach my $map (@maps) {
1319: if ($shorter{$map} ne '') {
1320: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1321: }
1322: }
1323: }
1324: return;
1325: }
1326:
1.329 droeschl 1327: sub print_paste_buffer {
1.492 raeburn 1328: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1329: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1330:
1.538 raeburn 1331: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1332: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1333: }
1334:
1.538 raeburn 1335: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1336: my ($pasteitems,@pasteable);
1.575 raeburn 1337: my $clipboardcount = 0;
1.488 raeburn 1338:
1.538 raeburn 1339: # Construct identifiers for current contents of user's paste buffer
1340: foreach my $suffix (@currpaste) {
1341: next if ($suffix =~ /\D/);
1342: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1343: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1344: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1345: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1346: ($url ne '')) {
1.575 raeburn 1347: $clipboardcount ++;
1.538 raeburn 1348: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1349: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1350: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1351: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1352: $is_external = 1;
1.626 raeburn 1353: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1354: $is_exttool = 1;
1.538 raeburn 1355: }
1356: if ($folder =~ /^supplemental/) {
1357: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1358: unless ($canpaste) {
1359: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1360: }
1361: } else {
1362: $canpaste = 1;
1363: }
1364: if ($canpaste) {
1365: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1366: my $srcdom = $1;
1367: my $srcnum = $2;
1368: my $rem = $3;
1369: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1370: $othercourse = 1;
1371: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1372: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1373: } else {
1374: $canpaste = 0;
1375: $nopaste = &mt('Paste from another course unavailable.');
1376: }
1377: }
1378: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1379: my $prefix = $1;
1380: $parent = $2;
1381: if ($folder !~ /^\Q$prefix\E/) {
1382: $areachange = 1;
1383: }
1384: $is_uploaded_map = 1;
1.492 raeburn 1385: }
1.597 raeburn 1386: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1387: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1388: if ($cid ne $env{'request.course.id'}) {
1389: my ($srcdom,$srcnum) = split(/_/,$cid);
1390: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1391: if (($is_exttool) && ($srcdom ne $coursedom)) {
1392: $canpaste = 0;
1393: $nopaste = &mt('Paste from another domain unavailable.');
1394: } else {
1395: $othercrs = '<br />'.&mt('(from another course)');
1396: }
1.596 raeburn 1397: } else {
1398: $canpaste = 0;
1399: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1400: }
1.596 raeburn 1401: }
1.492 raeburn 1402: }
1.596 raeburn 1403: if ($canpaste) {
1404: push(@pasteable,$suffix);
1.629 raeburn 1405: }
1.538 raeburn 1406: }
1407: my $buffer;
1.627 raeburn 1408: if ($is_external) {
1.538 raeburn 1409: $buffer = &mt('External Resource').': '.
1410: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1411: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1412: } elsif ($is_exttool) {
1413: $buffer = &mt('External Tool').': '.
1414: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1415: } else {
1416: my $icon = &Apache::loncommon::icon($extension);
1417: if ($extension eq 'sequence' &&
1418: $url =~ m{/default_\d+\.sequence$}x) {
1419: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1420: $icon .= '/navmap.folder.closed.gif';
1421: }
1.589 raeburn 1422: my $title = $env{'docs.markedcopy_title_'.$suffix};
1423: if ($title eq '') {
1424: ($title) = ($url =~ m{/([^/]+)$});
1425: }
1.538 raeburn 1426: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1427: ': '.
1428: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1429: &LONCAPA::map::qtescape($title));
1.538 raeburn 1430: }
1431: $pasteitems .= '<div class="LC_left_float">';
1432: my ($options,$onclick);
1433: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1434: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1435: if (($is_uploaded_map) ||
1436: ($url =~ /(bulletinboard|smppg)$/) ||
1437: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1438: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1439: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1440: }
1441: }
1442: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1443: if ($nopaste) {
1444: $pasteitems .= $nopaste;
1445: } else {
1446: if ($othercrs) {
1447: $pasteitems .= $othercrs;
1448: }
1449: if ($options) {
1450: $pasteitems .= $options;
1.492 raeburn 1451: }
1452: }
1.538 raeburn 1453: $pasteitems .= '</div>';
1454: }
1455: }
1456: if ($pasteitems eq '') {
1457: &Apache::lonnet::delenv('docs.markedcopies');
1458: }
1459: my ($pasteform,$form_start,$buttons,$form_end);
1460: if ($pasteitems) {
1461: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1462: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1463: if (@pasteable) {
1.575 raeburn 1464: my $value = &mt('Paste to current folder');
1465: if ($container eq 'page') {
1466: $value = &mt('Paste to current page');
1467: }
1468: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1469: }
1470: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1471: if ($clipboardcount > 1) {
1472: $buttons .=
1473: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1474: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1475: (' 'x2).
1476: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1477: (' 'x2);
1.492 raeburn 1478: }
1.575 raeburn 1479: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1480: '</form>';
1.538 raeburn 1481: } else {
1482: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1483: }
1.538 raeburn 1484: $r->print($form_start
1485: .'<fieldset>'
1486: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1487: .$pasteitems
1488: .'</fieldset>'
1489: .$form_end);
1490: }
1491:
1492: sub paste_options {
1493: my ($suffix,$is_uploaded_map,$parent) = @_;
1494: my ($copytext,$movetext);
1495: if ($is_uploaded_map) {
1496: $copytext = &mt('Copy to new folder');
1497: $movetext = &mt('Move old');
1498: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1499: $copytext = &mt('Copy to new board');
1500: $movetext = &mt('Move (not posts)');
1501: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1502: $copytext = &mt('Copy to new page');
1503: $movetext = &mt('Move');
1.533 raeburn 1504: } else {
1.538 raeburn 1505: $copytext = &mt('Copy to new file');
1506: $movetext = &mt('Move');
1507: }
1508: my $output = '<br />'.
1509: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1510: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1511: '<label>'.
1512: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1513: $copytext.'</label></span>'.(' 'x2).' '.
1514: '<span class="LC_nobreak"><label>'.
1515: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1516: $movetext.'</label></span>';
1517: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1518: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1519: '</legend><table border="0">';
1520: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1521: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1522: my $lastdir = $parent;
1523: my %depths = (
1524: $lastdir => 0,
1525: );
1526: my (%display,%deps);
1527: for (my $i=0; $i<@pastemaps; $i++) {
1528: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1529: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1530: my @subfolders = split(/,/,$subfolderstr);
1531: $deps{$lastdir} = \@subfolders;
1532: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1533: my $depth = $depths{$lastdir} + 1;
1534: my $offset = int($depth * 4);
1535: my $indent = (' ' x $offset);
1536: for (my $j=0; $j<@subfolders; $j++) {
1537: $depths{$subfolders[$j]} = $depth;
1538: $display{$subfolders[$j]} =
1539: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1540: '<td><label>'.
1541: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1542: '<label>'.
1543: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1544: &mt('Move old').'</label>'.
1545: '</td></tr>';
1546: }
1.492 raeburn 1547: }
1.538 raeburn 1548: &recurse_print(\$output,$parent,\%deps,\%display);
1549: $output .= '</table></fieldset>';
1.329 droeschl 1550: }
1.538 raeburn 1551: $output .= '</div>';
1552: return $output;
1.488 raeburn 1553: }
1554:
1.492 raeburn 1555: sub recurse_print {
1.538 raeburn 1556: my ($outputref,$dir,$deps,$display) = @_;
1557: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1558: if (ref($deps->{$dir}) eq 'ARRAY') {
1559: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1560: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1561: }
1562: }
1563: }
1564:
1.488 raeburn 1565: sub supp_pasteable {
1566: my ($url) = @_;
1567: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1568: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1569: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1570: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1571: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1572: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1573: return 1;
1574: }
1575: return;
1.329 droeschl 1576: }
1577:
1.492 raeburn 1578: sub paste_popup_js {
1.594 damieng 1579: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1580: show => 'Show Options',
1581: hide => 'Hide Options',
1.594 damieng 1582: );
1583: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1584: none => 'No items selected from clipboard.',
1.492 raeburn 1585: );
1.594 damieng 1586: &html_escape(\%html_js_lt);
1587: &js_escape(\%html_js_lt);
1588: &js_escape(\%js_lt);
1.492 raeburn 1589: return <<"END";
1590:
1.538 raeburn 1591: function showPasteOptions(suffix) {
1592: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1593: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1594: return;
1595: }
1596:
1.538 raeburn 1597: function hidePasteOptions(suffix) {
1598: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1599: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1600: return;
1601: }
1602:
1603: function showOptions(caller,suffix) {
1604: if (document.getElementById('pasteoptionstext_'+suffix)) {
1605: if (caller.checked) {
1.594 damieng 1606: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1607: } else {
1608: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1609: }
1610: if (document.getElementById('pasteoptions_'+suffix)) {
1611: document.getElementById('pasteoptions_'+suffix).style.display='none';
1612: }
1613: }
1.492 raeburn 1614: return;
1615: }
1616:
1.541 raeburn 1617: function validateClipboard() {
1618: var numchk = 0;
1619: if (document.pasteform.pasting.length > 1) {
1620: for (var i=0; i<document.pasteform.pasting.length; i++) {
1621: if (document.pasteform.pasting[i].checked) {
1622: numchk ++;
1623: }
1624: }
1625: } else {
1626: if (document.pasteform.pasting.type == 'checkbox') {
1627: if (document.pasteform.pasting.checked) {
1628: numchk ++;
1629: }
1630: }
1631: }
1632: if (numchk > 0) {
1633: return true;
1634: } else {
1.594 damieng 1635: alert("$js_lt{'none'}");
1.541 raeburn 1636: return false;
1637: }
1638: }
1639:
1.575 raeburn 1640: function checkClipboard() {
1641: if (document.pasteform.pasting.length > 1) {
1642: for (var i=0; i<document.pasteform.pasting.length; i++) {
1643: document.pasteform.pasting[i].checked = true;
1644: }
1645: }
1646: return;
1647: }
1648:
1649: function uncheckClipboard() {
1650: if (document.pasteform.pasting.length >1) {
1651: for (var i=0; i<document.pasteform.pasting.length; i++) {
1652: document.pasteform.pasting[i].checked = false;
1653: }
1654: }
1655: return;
1656: }
1657:
1.492 raeburn 1658: END
1659:
1660: }
1661:
1.329 droeschl 1662: sub do_paste_from_buffer {
1.492 raeburn 1663: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1664:
1.538 raeburn 1665: # Array of items in paste buffer
1666: my (@currpaste,%pastebuffer,%allerrors);
1667: @currpaste = split(/,/,$env{'docs.markedcopies'});
1668:
1.492 raeburn 1669: # Early out if paste buffer is empty
1.538 raeburn 1670: if (@currpaste == 0) {
1.492 raeburn 1671: return ();
1.538 raeburn 1672: }
1673: map { $pastebuffer{$_} = 1; } @currpaste;
1674:
1675: # Array of items selected items to paste
1676: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1677:
1678: # Early out if nothing selected to paste
1679: if (@reqpaste == 0) {
1680: return();
1681: }
1682: my @topaste;
1683: foreach my $suffix (@reqpaste) {
1684: next if ($suffix =~ /\D/);
1685: next unless (exists($pastebuffer{$suffix}));
1686: push(@topaste,$suffix);
1687: }
1688:
1689: # Early out if nothing available to paste
1690: if (@topaste == 0) {
1691: return();
1.329 droeschl 1692: }
1693:
1.627 raeburn 1694: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1695: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1696:
1697: foreach my $suffix (@topaste) {
1698: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1699: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1700: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1701: # Supplemental content may only include certain types of content
1702: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1703: if ($folder =~ /^supplemental/) {
1704: unless (&supp_pasteable($url)) {
1705: $notinsupp{$suffix} = 1;
1706: next;
1707: }
1.492 raeburn 1708: }
1.538 raeburn 1709: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1710: my $srcd = $1;
1711: my $srcn = $2;
1.492 raeburn 1712: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1713: # check for mdc privilege in the course from which the resource was pasted
1714: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1715: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1716: $notincrs{$suffix} = 1;
1717: next;
1718: }
1.491 raeburn 1719: }
1.538 raeburn 1720: $srcdom{$suffix} = $srcd;
1721: $srcnum{$suffix} = $srcn;
1.597 raeburn 1722: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1723: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1724: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1725: my ($srcd,$srcn) = split(/_/,$cid);
1726: # When paste buffer was populated using an active role in a different course
1727: # check for mdc privilege in the course from which the resource was pasted
1728: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1729: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1730: $notincrs{$suffix} = 1;
1731: next;
1732: }
1733: }
1.632 raeburn 1734: # When buffer was populated using an active role in a different course
1735: # disallow pasting of External Tool if course is in a different domain.
1736: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1737: $notindom{$suffix} = 1;
1738: next;
1739: }
1.596 raeburn 1740: $srcdom{$suffix} = $srcd;
1741: $srcnum{$suffix} = $srcn;
1.491 raeburn 1742: }
1.597 raeburn 1743: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1744: push(@dopaste,$suffix);
1745: if ($url=~/\.(page|sequence)$/) {
1746: $is_map{$suffix} = 1;
1747: }
1748: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1749: my $oldprefix = $1;
1.492 raeburn 1750: # When pasting content from Main Content to Supplemental Content and vice versa
1751: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1752: # a folder/page or a document).
1.538 raeburn 1753: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1754: $prefixchg{$suffix} = 'docstosupp';
1755: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1756: $prefixchg{$suffix} = 'supptodocs';
1757: }
1.491 raeburn 1758:
1.492 raeburn 1759: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1760: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1761: my @nested;
1762: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1763: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1764: my @deps = map { /\d+:([\d,]+$)/ } @items;
1765: foreach my $dep (@deps) {
1766: if ($dep =~ /,/) {
1767: push(@nested,split(/,/,$dep));
1768: } else {
1769: push(@nested,$dep);
1770: }
1.492 raeburn 1771: }
1.538 raeburn 1772: foreach my $item (@nested) {
1773: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1774: push(@{$marktomove{$suffix}},$type.'_'.$item);
1775: }
1.492 raeburn 1776: }
1777: }
1.488 raeburn 1778: }
1779: }
1780:
1.538 raeburn 1781: # Early out if nothing available to paste
1782: if (@dopaste == 0) {
1783: return ();
1784: }
1785:
1786: # Populate message hash and hashes used for main content <=> supplemental content
1787: # changes
1788:
1789: %msgs = &Apache::lonlocal::texthash (
1790: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1791: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.627 raeburn 1792: notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.538 raeburn 1793: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1794: );
1795:
1796: %before = (
1797: docstosupp => {
1798: map => 'default',
1799: doc => 'docs',
1800: },
1801: supptodocs => {
1802: map => 'supplemental',
1803: doc => 'supplemental',
1804: },
1805: );
1806:
1807: %after = (
1808: docstosupp => {
1809: map => 'supplemental',
1810: doc => 'supplemental'
1811: },
1812: supptodocs => {
1813: map => 'default',
1814: doc => 'docs',
1815: },
1816: );
1817:
1818: # Retrieve information about all course maps in main content area
1819:
1820: my $allmaps = {};
1821: if ($folder =~ /^default/) {
1822: $allmaps =
1823: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1824: $env{"course.$env{'request.course.id'}.home"},
1825: $env{'request.course.id'});
1826: }
1827:
1828: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1829:
1830: # Loop over the items to paste
1831: foreach my $suffix (@dopaste) {
1.329 droeschl 1832: # Maps need to be copied first
1.538 raeburn 1833: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1834: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1835: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1836: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1837: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1838: }
1839: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1840: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1841: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1842: my $oldurl = $url;
1843: if ($is_map{$suffix}) {
1.491 raeburn 1844: # If pasting a map, check if map contains other maps
1.538 raeburn 1845: my (%hierarchy,%titles);
1.627 raeburn 1846: &contained_map_check($url,$folder,$coursenum,$coursedom,
1847: \%removefrommap,\%removeparam,\%addedmaps,
1848: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1849: if ($url=~ m{^/uploaded/}) {
1850: my $newurl;
1851: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1852: ($newurl,my $error) =
1853: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1854: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1855: \$title,$allmaps,\%newurls);
1856: if ($error) {
1857: $allerrors{$suffix} = $error;
1858: next;
1859: }
1860: if ($newurl ne '') {
1861: if ($newurl ne $url) {
1862: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1863: $newsubdir{$url} = $1;
1864: }
1865: $mapchanges{$url} = 1;
1.492 raeburn 1866: }
1.538 raeburn 1867: }
1868: }
1869: if (($srcdom{$suffix} ne $coursedom) ||
1870: ($srcnum{$suffix} ne $coursenum) ||
1871: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1872: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1873: $coursedom,$coursenum,$srcdom{$suffix},
1874: $srcnum{$suffix},$allmaps,\%rewrites,
1875: \%retitles,\%copies,\%dbcopies,
1876: \%zombies,\%params,\%mapmoves,
1877: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1878: \%newurls,\%resdatacopy)) {
1.538 raeburn 1879: $mapmoves{$url} = 1;
1880: }
1881: $url = $newurl;
1882: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1883: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1884: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1885: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1886: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1887: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1888: }
1889: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1890: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1891: push(@toclear,$suffix);
1892: # if pasting published map (main content area only) check map not already in course
1893: if ($folder =~ /^default/) {
1894: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1895: $duplicate{$suffix} = 1;
1896: next;
1.492 raeburn 1897: }
1.491 raeburn 1898: }
1899: }
1.538 raeburn 1900: }
1.627 raeburn 1901: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1902: my $prefix = $1;
1.648 ! raeburn 1903: my $fromothercrs;
1.538 raeburn 1904: #need to copy the db contents to a new one, unless this is a move.
1905: my %info = (
1906: src => $url,
1907: cdom => $coursedom,
1908: cnum => $coursenum,
1.596 raeburn 1909: );
1910: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1911: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1912: $fromothercrs = 1;
1913: $info{'cdom'} = $srcdom{$suffix};
1914: $info{'cnum'} = $srcnum{$suffix};
1915: }
1916: }
1917: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 1918: my (%lockerr,$msg);
1.538 raeburn 1919: my ($newurl,$result,$errtext) =
1920: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1921: if ($result eq 'ok') {
1922: $url = $newurl;
1923: $title=&mt('Copy of').' '.$title;
1924: } else {
1925: if ($prefix eq 'smppg') {
1926: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1927: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1928: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 1929: } elsif ($prefix eq 'ext.tool') {
1930: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 1931: }
1932: $results{$suffix} = $result;
1933: $msgerrs{$suffix} = $msg;
1934: $lockerrs{$suffix} = $lockerr{$prefix};
1935: next;
1936: }
1937: if ($lockerr{$prefix}) {
1938: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1939: }
1.489 raeburn 1940: }
1941: }
1.538 raeburn 1942: $title = &LONCAPA::map::qtunescape($title);
1943: my $ext='false';
1944: if ($url=~m{^http(|s)://}) { $ext='true'; }
1945: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1946: if ($folder !~ /^supplemental/) {
1947: (undef,undef,$title) =
1948: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1949: }
1950: } else {
1951: if ($folder=~/^supplemental/) {
1952: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1953: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1954: }
1.533 raeburn 1955: }
1.491 raeburn 1956:
1957: # For uploaded files (excluding pages/sequences) path in copied file is changed
1958: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1959: # courses.
1960:
1.538 raeburn 1961: unless ($is_map{$suffix}) {
1962: my $newidx;
1.492 raeburn 1963: # Now insert the URL at the bottom
1.538 raeburn 1964: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1965: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1966: my $relpath = $1;
1967: if ($relpath ne '') {
1968: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1969: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1970: my $newprefix = $newloc;
1971: if ($newloc eq 'default') {
1972: $newprefix = 'docs';
1973: }
1974: if ($newdocsdir eq '') {
1975: $newdocsdir = 'default';
1976: }
1.630 raeburn 1977: if (($prefixchg{$suffix}) ||
1978: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 1979: ($srcnum{$suffix} ne $coursenum) ||
1980: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1981: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1982: $url =
1983: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1984: &Apache::lonnet::getfile($oldurl));
1985: if ($url eq '/adm/notfound.html') {
1986: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1987: next;
1988: } else {
1989: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1990: $newsubpath =~ s{/+$}{/};
1991: $docmoves{$oldurl} = $newsubpath;
1992: }
1.491 raeburn 1993: }
1994: }
1.597 raeburn 1995: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1996: my $template = $1;
1997: if ($newidx) {
1998: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1999: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2000: }
1.491 raeburn 2001: }
1.538 raeburn 2002: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2003: ':'.$ext.':normal:res';
2004: push(@LONCAPA::map::order,$newidx);
2005: # Store the result
2006: my ($errtext,$fatal) =
2007: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2008: if ($fatal) {
2009: $save_err .= $errtext;
2010: $allresult = 'fail';
2011: }
1.488 raeburn 2012: }
1.538 raeburn 2013:
1.597 raeburn 2014: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2015: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2016: unless ($allresult eq 'fail') {
2017: my %updated = (
2018: rewrites => \%rewrites,
2019: zombies => \%zombies,
2020: removefrommap => \%removefrommap,
2021: removeparam => \%removeparam,
2022: dbcopies => \%dbcopies,
1.597 raeburn 2023: resdatacopy => \%resdatacopy,
1.538 raeburn 2024: retitles => \%retitles,
2025: );
2026: my %info = (
2027: newsubdir => \%newsubdir,
2028: params => \%params,
2029: );
2030: if ($prefixchg{$suffix}) {
2031: $info{'before'} = $before{$prefixchg{$suffix}};
2032: $info{'after'} = $after{$prefixchg{$suffix}};
2033: }
2034: my %moves = (
2035: copies => \%copies,
2036: docmoves => \%docmoves,
2037: mapmoves => \%mapmoves,
2038: );
2039: (my $result,$msgs{$suffix},my $lockerror) =
2040: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2041: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2042: $url,'paste');
2043: $lockerrors .= $lockerror;
2044: if ($result eq 'ok') {
2045: if ($is_map{$suffix}) {
2046: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2047: $folder.'.'.$container);
2048: if ($fatal) {
2049: $allresult = 'failread';
2050: } else {
2051: if ($#LONCAPA::map::order<1) {
2052: my $idx=&LONCAPA::map::getresidx();
2053: if ($idx<=0) { $idx=1; }
2054: $LONCAPA::map::order[0]=$idx;
2055: $LONCAPA::map::resources[$idx]='';
2056: }
2057: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2058: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2059: ':'.$ext.':normal:res';
2060: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2061:
2062: # Store the result
1.538 raeburn 2063: my ($errtext,$fatal) =
2064: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2065: if ($fatal) {
2066: $save_err .= $errtext;
2067: $allresult = 'failstore';
2068: }
2069: }
2070: }
2071: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2072: push(@toclear,$suffix);
2073: }
2074: }
1.492 raeburn 2075: }
2076: }
1.538 raeburn 2077: &clear_from_buffer(\@toclear,\@currpaste);
2078: my $msgsarray;
2079: foreach my $suffix (keys(%msgs)) {
2080: if (ref($msgs{$suffix}) eq 'ARRAY') {
2081: $msgsarray .= join(',',@{$msgs{$suffix}});
2082: }
2083: }
2084: return ($allresult,$save_err,$msgsarray,$lockerrors);
2085: }
1.533 raeburn 2086:
1.538 raeburn 2087: sub do_buffer_empty {
2088: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2089: if (@currpaste == 0) {
2090: return &mt('Clipboard is already empty');
2091: }
2092: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2093: if (@toclear == 0) {
2094: return &mt('Nothing selected to clear from clipboard');
2095: }
2096: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2097: if ($numdel) {
2098: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2099: } else {
2100: return &mt('Clipboard unchanged');
1.492 raeburn 2101: }
1.538 raeburn 2102: return;
2103: }
2104:
2105: sub clear_from_buffer {
2106: my ($toclear,$currpaste) = @_;
2107: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2108: my %pastebuffer;
2109: map { $pastebuffer{$_} = 1; } @{$currpaste};
2110: my $numdel = 0;
2111: foreach my $suffix (@{$toclear}) {
2112: next if ($suffix =~ /\D/);
2113: next unless (exists($pastebuffer{$suffix}));
2114: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2115: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2116: delete($pastebuffer{$suffix});
2117: $numdel ++;
2118: }
2119: }
2120: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2121: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2122: return $numdel;
1.492 raeburn 2123: }
2124:
2125: sub get_newmap_url {
2126: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2127: $titleref,$allmaps,$newurls) = @_;
2128: my $newurl;
2129: if ($url=~ m{^/uploaded/}) {
2130: $$titleref=&mt('Copy of').' '.$$titleref;
2131: }
2132: my $now = time;
2133: my $suffix=$$.int(rand(100)).$now;
2134: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2135: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2136: my $path = $1;
2137: my $prefix = $2;
2138: my $ancestor = $3;
2139: if (length($ancestor) > 10) {
2140: $ancestor = substr($ancestor,-10,10);
2141: }
2142: my $newid;
2143: if ($prefixchg) {
2144: if ($folder =~ /^supplemental/) {
2145: $prefix =~ s/^default/supplemental/;
2146: } else {
2147: $prefix =~ s/^supplemental/default/;
2148: }
2149: }
2150: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2151: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2152: } else {
2153: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2154: }
2155: my $counter = 0;
2156: my $is_unique = &uniqueness_check($newurl);
2157: if ($folder =~ /^default/) {
2158: if ($allmaps->{$newurl}) {
2159: $is_unique = 0;
2160: }
2161: }
2162: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2163: $counter ++;
2164: $suffix ++;
2165: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2166: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2167: } else {
2168: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2169: }
2170: $is_unique = &uniqueness_check($newurl);
2171: }
2172: if ($is_unique) {
2173: $newurls->{$newurl} = 1;
2174: } else {
2175: if ($url=~/\.page$/) {
2176: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2177: } else {
2178: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2179: }
2180: }
1.329 droeschl 2181: }
1.492 raeburn 2182: return ($newurl);
1.329 droeschl 2183: }
2184:
1.488 raeburn 2185: sub dbcopy {
1.533 raeburn 2186: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2187: my ($url,$result,$errtext);
2188: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2189: $url = $dbref->{'src'};
1.627 raeburn 2190: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2191: my $prefix = $1;
1.627 raeburn 2192: if ($prefix eq 'ext.tool') {
2193: $prefix = 'exttool';
2194: }
1.533 raeburn 2195: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2196: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2197: my $db_name;
2198: my $marker = (split(m{/},$url))[4];
2199: $marker=~s/\D//g;
2200: if ($dbref->{'src'} =~ m{/smppg$}) {
2201: $db_name =
2202: &Apache::lonsimplepage::get_db_name($url,$marker,
2203: $dbref->{'cdom'},
2204: $dbref->{'cnum'});
1.627 raeburn 2205: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2206: $db_name = 'exttool_'.$marker;
1.533 raeburn 2207: } else {
2208: $db_name = 'bulletinpage_'.$marker;
2209: }
2210: my ($suffix,$freedlock,$error) =
2211: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2212: $coursedom,$coursenum,
2213: 'concat');
2214: if (!$suffix) {
2215: if ($prefix eq 'smppg') {
2216: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2217: } elsif ($prefix eq 'exttool') {
2218: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2219: } else {
1.565 bisitz 2220: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2221: }
2222: if ($error) {
2223: $errtext .= '<br />'.$error;
2224: }
2225: } else {
2226: #need to copy the db contents to a new one.
2227: my %contents=&Apache::lonnet::dump($db_name,
2228: $dbref->{'cdom'},
2229: $dbref->{'cnum'});
2230: if (exists($contents{'uploaded.photourl'})) {
2231: my $photo = $contents{'uploaded.photourl'};
2232: my ($subdir,$fname) =
2233: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2234: my $newphoto;
1.533 raeburn 2235: if ($fname ne '') {
2236: my $content = &Apache::lonnet::getfile($photo);
2237: unless ($content eq '-1') {
2238: $env{'form.'.$suffix.'.photourl'} = $content;
2239: $newphoto =
2240: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2241: delete($env{'form.'.$suffix.'.photourl'});
2242: }
2243: }
2244: if ($newphoto =~ m{^/uploaded/}) {
2245: $contents{'uploaded.photourl'} = $newphoto;
2246: }
2247: }
2248: $db_name =~ s{_\d*$ }{_$suffix}x;
2249: $result=&Apache::lonnet::put($db_name,\%contents,
2250: $coursedom,$coursenum);
2251: if ($result eq 'ok') {
1.627 raeburn 2252: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2253: }
2254: }
2255: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2256: $lockerrorsref->{$prefix} =
1.533 raeburn 2257: '<div class="LC_error">'.
2258: &mt('There was a problem removing a lockfile.');
2259: if ($prefix eq 'smppg') {
1.560 raeburn 2260: $lockerrorsref->{$prefix} .=
1.559 raeburn 2261: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2262: } elsif ($prefix eq 'exttool') {
2263: $lockerrorsref->{$prefix} .=
2264: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2265: } else {
1.565 bisitz 2266: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2267: }
1.560 raeburn 2268: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2269: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2270: '</div>';
1.533 raeburn 2271: }
2272: }
2273: } elsif ($url =~ m{/syllabus$}) {
2274: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2275: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2276: if (($dbref->{'cdom'} ne $coursedom) ||
2277: ($dbref->{'cnum'} ne $coursenum)) {
2278: my %contents=&Apache::lonnet::dump('syllabus',
2279: $dbref->{'cdom'},
2280: $dbref->{'cnum'});
2281: $result=&Apache::lonnet::put('syllabus',\%contents,
2282: $coursedom,$coursenum);
2283: }
2284: }
1.488 raeburn 2285: }
2286: }
1.533 raeburn 2287: return ($url,$result,$errtext);
1.488 raeburn 2288: }
2289:
1.597 raeburn 2290: sub copy_templated_files {
2291: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2292: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2293: my $srccontainer = 'sequence';
2294: if ($srcwaspage) {
2295: $srccontainer = 'page';
2296: }
2297: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2298: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2299: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2300: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2301: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2302: $template.'.problem';
2303: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2304: if ($template eq 'simpleproblem') {
2305: $srcprefix .= '.0.';
2306: my $weightprefix = $newprefix;
2307: $newprefix .= '.0.';
2308: my @simpleprobqtypes = qw(radio option string essay numerical);
2309: my $qtype=$srcparms{$srcprefix.'questiontype'};
2310: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2311: my %newdata;
2312: foreach my $type (@simpleprobqtypes) {
2313: if ($type eq $qtype) {
2314: $newdata{"$weightprefix.$type.weight"}=1;
2315: } else {
2316: $newdata{"$weightprefix.$type.weight"}=0;
2317: }
2318: }
2319: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2320: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2321: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2322: if ($qtype eq 'numerical') {
2323: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2324: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2325: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2326: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2327: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2328: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2329: unless (defined($maxfoils)) { $maxfoils=10; }
2330: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2331: if ($maxfoils<=0) { $maxfoils=10; }
2332: my $randomize=$srcparms{$srcprefix.'randomize'};
2333: unless (defined($randomize)) { $randomize='yes'; }
2334: unless ($randomize eq 'no') { $randomize='yes'; }
2335: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2336: $newdata{$newprefix.'randomize'} = $randomize;
2337: if ($qtype eq 'option') {
2338: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2339: }
2340: for (my $i=1; $i<=10; $i++) {
2341: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2342: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2343: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2344: }
2345:
2346: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2347: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2348: unless (defined($maxfoils)) { $maxfoils=10; }
2349: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2350: if ($maxfoils<=0) { $maxfoils=10; }
2351: my $randomize=$srcparms{$srcprefix.'randomize'};
2352: unless (defined($randomize)) { $randomize='yes'; }
2353: unless ($randomize eq 'no') { $randomize='yes'; }
2354: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2355: $newdata{$newprefix.'randomize'} = $randomize;
2356: if ($qtype eq 'option') {
2357: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2358: }
2359: for (my $i=1; $i<=10; $i++) {
2360: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2361: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2362: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2363: }
2364: } elsif ($qtype eq 'string') {
2365: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2366: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2367: }
2368: if (keys(%newdata)) {
2369: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2370: $coursenum);
2371: if ($putres eq 'ok') {
2372: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2373: }
2374: }
2375: }
2376: }
2377: }
2378:
1.329 droeschl 2379: sub uniqueness_check {
2380: my ($newurl) = @_;
2381: my $unique = 1;
2382: foreach my $res (@LONCAPA::map::order) {
2383: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2384: $url=&LONCAPA::map::qtescape($url);
2385: if ($newurl eq $url) {
2386: $unique = 0;
1.344 bisitz 2387: last;
1.329 droeschl 2388: }
2389: }
2390: return $unique;
2391: }
2392:
1.488 raeburn 2393: sub contained_map_check {
1.627 raeburn 2394: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2395: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2396: my $content = &Apache::lonnet::getfile($url);
2397: unless ($content eq '-1') {
2398: my $parser = HTML::TokeParser->new(\$content);
2399: $parser->attr_encoded(1);
2400: while (my $token = $parser->get_token) {
2401: next if ($token->[0] ne 'S');
2402: if ($token->[1] eq 'resource') {
2403: next if ($token->[2]->{'type'} eq 'zombie');
2404: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2405: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2406: my $srcdom = $1;
2407: unless ($srcdom eq $coursedom) {
2408: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2409: next;
2410: }
2411: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2412: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2413: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2414: next;
2415: }
2416: }
1.492 raeburn 2417: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2418: if ($1 eq 'uploaded') {
2419: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2420: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2421: } else {
1.492 raeburn 2422: if ($allmaps->{$ressrc}) {
1.529 raeburn 2423: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2424: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2425: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2426: } else {
2427: $addedmaps->{$ressrc} = [$url];
2428: }
1.488 raeburn 2429: }
1.627 raeburn 2430: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2431: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2432: }
1.492 raeburn 2433: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2434: if ($folder =~ /^supplemental/) {
1.492 raeburn 2435: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2436: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2437: } else {
2438: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2439: }
1.488 raeburn 2440: }
2441: }
2442: }
2443: }
2444: return;
2445: }
2446:
2447: sub url_paste_fixups {
1.533 raeburn 2448: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2449: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2450: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2451: my $checktitle;
2452: if (($prefixchg) &&
1.492 raeburn 2453: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2454: $checktitle = 1;
2455: }
1.492 raeburn 2456: my $skip;
2457: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2458: my $mapid = $1.$2;
2459: if ($tomove->{$mapid}) {
2460: $skip = 1;
2461: }
2462: }
1.491 raeburn 2463: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2464: return if ($file eq '-1');
2465: my $parser = HTML::TokeParser->new(\$file);
2466: $parser->attr_encoded(1);
1.491 raeburn 2467: my $changed = 0;
1.488 raeburn 2468: while (my $token = $parser->get_token) {
2469: next if ($token->[0] ne 'S');
2470: if ($token->[1] eq 'resource') {
2471: my $ressrc = $token->[2]->{'src'};
2472: next if ($ressrc eq '');
1.491 raeburn 2473: my $id = $token->[2]->{'id'};
1.492 raeburn 2474: my $title = $token->[2]->{'title'};
1.491 raeburn 2475: if ($checktitle) {
2476: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2477: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2478: }
2479: }
1.488 raeburn 2480: next if ($token->[2]->{'type'} eq 'external');
2481: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2482: next if ($skip);
1.532 raeburn 2483: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2484: $changed = 1;
2485: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2486: my $srcdom = $1;
2487: my $srcnum = $2;
1.488 raeburn 2488: my $rem = $3;
1.492 raeburn 2489: my $newurl;
2490: my $mapname;
2491: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2492: my $prefix = $1;
2493: $mapname = $prefix.$2;
2494: if ($tomove->{$mapname}) {
1.533 raeburn 2495: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2496: $srcdom,$srcnum,$allmaps,$rewrites,
2497: $retitles,$copies,$dbcopies,$zombies,
2498: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2499: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2500: next;
2501: } else {
2502: ($newurl,my $error) =
2503: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2504: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2505: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2506: $newsubdir->{$ressrc} = $1;
2507: }
2508: if ($error) {
2509: next;
2510: }
2511: }
2512: }
2513: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2514: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2515:
1.488 raeburn 2516: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2517: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2518: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2519: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2520: $cnum,$srcdom,$srcnum,$allmaps,
2521: $rewrites,$retitles,$copies,$dbcopies,
2522: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2523: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2524: $mapmoves->{$ressrc} = 1;
2525: }
2526: $changed = 1;
1.488 raeburn 2527: } else {
1.532 raeburn 2528: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2529: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2530: $changed = 1;
1.488 raeburn 2531: }
2532: }
1.533 raeburn 2533: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2534: next if ($skip);
1.492 raeburn 2535: my $srcdom = $1;
2536: my $srcnum = $2;
2537: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2538: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2539: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2540: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2541: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2542: $changed = 1;
2543: }
2544: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2545: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2546: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2547: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2548: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2549: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2550: $changed = 1;
1.488 raeburn 2551: }
1.597 raeburn 2552: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2553: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2554: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2555: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2556: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2557: }
1.488 raeburn 2558: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2559: next if ($skip);
2560: my $srcdom = $1;
2561: my $srcnum = $2;
2562: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2563: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2564: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2565: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2566: $changed = 1;
1.488 raeburn 2567: }
2568: }
2569: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2570: next if ($skip);
1.488 raeburn 2571: my $to = $token->[2]->{'to'};
2572: if ($to ne '') {
2573: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2574: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2575: } else {
2576: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2577: }
2578: }
2579: }
2580: }
1.491 raeburn 2581: return $changed;
1.488 raeburn 2582: }
2583:
2584: sub apply_fixups {
1.529 raeburn 2585: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2586: $oldurl,$url,$caller) = @_;
2587: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2588: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2589: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2590: if (ref($updated) eq 'HASH') {
2591: if (ref($updated->{'rewrites'}) eq 'HASH') {
2592: %rewrites = %{$updated->{'rewrites'}};
2593: }
2594: if (ref($updated->{'zombies'}) eq 'HASH') {
2595: %zombies = %{$updated->{'zombies'}};
2596: }
2597: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2598: %removefrommap = %{$updated->{'removefrommap'}};
2599: }
2600: if (ref($updated->{'removeparam'}) eq 'HASH') {
2601: %removeparam = %{$updated->{'removeparam'}};
2602: }
2603: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2604: %dbcopies = %{$updated->{'dbcopies'}};
2605: }
2606: if (ref($updated->{'retitles'}) eq 'HASH') {
2607: %retitles = %{$updated->{'retitles'}};
2608: }
1.597 raeburn 2609: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2610: %resdatacopy = %{$updated->{'resdatacopy'}};
2611: }
1.529 raeburn 2612: }
2613: if (ref($info) eq 'HASH') {
2614: if (ref($info->{'newsubdir'}) eq 'HASH') {
2615: %newsubdir = %{$info->{'newsubdir'}};
2616: }
2617: if (ref($info->{'params'}) eq 'HASH') {
2618: %params = %{$info->{'params'}};
2619: }
2620: if (ref($info->{'before'}) eq 'HASH') {
2621: %before = %{$info->{'before'}};
2622: }
2623: if (ref($info->{'after'}) eq 'HASH') {
2624: %after = %{$info->{'after'}};
2625: }
2626: }
2627: if (ref($moves) eq 'HASH') {
2628: if (ref($moves->{'copies'}) eq 'HASH') {
2629: %copies = %{$moves->{'copies'}};
2630: }
2631: if (ref($moves->{'docmoves'}) eq 'HASH') {
2632: %docmoves = %{$moves->{'docmoves'}};
2633: }
2634: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2635: %mapmoves = %{$moves->{'mapmoves'}};
2636: }
2637: }
2638: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2639: my @allcopies;
1.529 raeburn 2640: if (exists($copies{$key})) {
2641: if (ref($copies{$key}) eq 'HASH') {
2642: my %added;
2643: foreach my $innerkey (keys(%{$copies{$key}})) {
2644: if (($innerkey ne '') && (!$added{$innerkey})) {
2645: push(@allcopies,$innerkey);
2646: $added{$innerkey} = 1;
2647: }
1.491 raeburn 2648: }
1.529 raeburn 2649: undef(%added);
1.491 raeburn 2650: }
2651: }
2652: if ($key eq $oldurl) {
1.529 raeburn 2653: if ((exists($docmoves{$key}))) {
1.532 raeburn 2654: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2655: push(@allcopies,$oldurl);
2656: }
2657: }
2658: }
2659: if (@allcopies > 0) {
2660: foreach my $item (@allcopies) {
1.492 raeburn 2661: my ($relpath,$oldsubdir,$fname) =
2662: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2663: if ($fname ne '') {
2664: my $content = &Apache::lonnet::getfile($item);
2665: unless ($content eq '-1') {
2666: my $storefn;
1.529 raeburn 2667: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2668: $storefn = $docmoves{$key};
1.491 raeburn 2669: } else {
2670: $storefn = $relpath;
2671: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2672: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2673: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2674: }
1.529 raeburn 2675: if ($newsubdir{$key}) {
1.532 raeburn 2676: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2677: }
2678: }
2679: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2680: my $copyurl =
2681: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2682: $storefn.$fname,$content);
2683: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2684: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2685: return &mt('Paste failed: an error occurred copying the file.');
2686: } elsif (ref($errors) eq 'HASH') {
2687: $errors->{$item} = 1;
1.489 raeburn 2688: }
2689: }
1.488 raeburn 2690: }
2691: }
1.491 raeburn 2692: }
2693: }
2694: }
1.529 raeburn 2695: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2696: my $storefn=$key;
2697: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2698: if ($prefixchg && $before{'map'} && $after{'map'}) {
2699: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2700: }
1.529 raeburn 2701: if ($newsubdir{$key}) {
2702: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2703: }
1.491 raeburn 2704: my $mapcontent = &Apache::lonnet::getfile($key);
2705: if ($mapcontent eq '-1') {
2706: if (ref($errors) eq 'HASH') {
2707: $errors->{$key} = 1;
2708: }
2709: } else {
2710: my $newmap =
2711: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2712: $mapcontent);
2713: if ($newmap eq '/adm/notfound.html') {
2714: if (ref($errors) eq 'HASH') {
2715: $errors->{$key} = 1;
1.489 raeburn 2716: }
1.488 raeburn 2717: }
2718: }
2719: }
1.491 raeburn 2720: my %updates;
2721: if ($is_map) {
1.529 raeburn 2722: if (ref($updated) eq 'HASH') {
2723: foreach my $type (keys(%{$updated})) {
2724: if (ref($updated->{$type}) eq 'HASH') {
2725: foreach my $key (keys(%{$updated->{$type}})) {
2726: $updates{$key} = 1;
2727: }
2728: }
2729: }
1.491 raeburn 2730: }
2731: foreach my $key (keys(%updates)) {
1.492 raeburn 2732: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2733: if (ref($rewrites{$key}) eq 'HASH') {
2734: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2735: }
1.529 raeburn 2736: if (ref($retitles{$key}) eq 'HASH') {
2737: %toretitle = %{$retitles{$key}};
1.491 raeburn 2738: }
1.529 raeburn 2739: if (ref($removefrommap{$key}) eq 'HASH') {
2740: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2741: }
1.529 raeburn 2742: if (ref($removeparam{$key}) eq 'HASH') {
2743: %remparam = %{$removeparam{$key}};
1.492 raeburn 2744: }
1.529 raeburn 2745: if (ref($zombies{$key}) eq 'HASH') {
2746: %zombie = %{$zombies{$key}};
1.491 raeburn 2747: }
1.529 raeburn 2748: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2749: foreach my $idx (keys(%{$dbcopies{$key}})) {
2750: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2751: my ($newurl,$result,$errtext) =
2752: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2753: if ($result eq 'ok') {
2754: $newdb{$idx} = $newurl;
2755: } elsif (ref($errors) eq 'HASH') {
2756: $errors->{$key} = 1;
2757: }
2758: push(@msgs,$errtext);
2759: }
1.491 raeburn 2760: }
2761: }
1.597 raeburn 2762: if (ref($resdatacopy{$key}) eq 'HASH') {
2763: if ($newsubdir{$key}) {
2764:
2765: }
2766: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2767: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2768: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2769: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2770: my $template = $1;
2771: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2772: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2773: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2774: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2775: my ($newmapname) = ($key =~ m{/([^/]+)$});
2776: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2777: my $srcmapinfo = $srcfolder.':'.$idx;
2778: if ($srccontainer eq 'page') {
2779: $srcmapinfo .= ':1';
2780: }
2781: if ($newsubdir{$key}) {
2782: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2783: }
2784: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2785: $cnum,$template,$idx,$newmapname);
2786: }
2787: }
2788: }
2789: }
2790: }
1.529 raeburn 2791: if (ref($params{$key}) eq 'HASH') {
2792: %currparam = %{$params{$key}};
1.492 raeburn 2793: }
2794: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2795: if ($fatal) {
1.533 raeburn 2796: return ($errtext);
1.492 raeburn 2797: }
2798: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2799: if (defined($LONCAPA::map::zombies[$i])) {
2800: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2801: if ($zombie{$i} eq $src) {
1.492 raeburn 2802: undef($LONCAPA::map::zombies[$i]);
2803: }
2804: }
2805: }
1.646 raeburn 2806: my $total = scalar(@LONCAPA::map::order) - 1;
2807: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2808: my $idx = $LONCAPA::map::order[$i];
2809: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2810: my $changed;
1.529 raeburn 2811: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2812: if ((exists($toremove{$idx})) &&
2813: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2814: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2815: if (ref($currparam{$idx}) eq 'ARRAY') {
2816: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2817: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2818: }
2819: }
2820: next;
2821: }
2822: my $origsrc = $src;
1.532 raeburn 2823: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2824: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2825: $changed = 1;
1.491 raeburn 2826: }
1.492 raeburn 2827: }
1.532 raeburn 2828: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2829: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2830: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2831: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2832: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2833: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2834: } else {
1.529 raeburn 2835: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2836: }
1.491 raeburn 2837: }
1.532 raeburn 2838: if ($origsrc =~ /\.(page|sequence)$/) {
2839: if ($newsubdir{$origsrc}) {
1.529 raeburn 2840: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2841: }
1.532 raeburn 2842: } elsif ($newsubdir{$key}) {
2843: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2844: }
2845: }
1.492 raeburn 2846: $changed = 1;
1.533 raeburn 2847: } elsif ($newdb{$idx} ne '') {
2848: $src = $newdb{$idx};
1.492 raeburn 2849: $changed = 1;
2850: }
2851: if ($changed) {
1.538 raeburn 2852: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2853: }
2854: }
2855: }
2856: foreach my $idx (keys(%remparam)) {
2857: if (ref($remparam{$idx}) eq 'ARRAY') {
2858: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 2859: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 2860: }
2861: }
2862: }
1.533 raeburn 2863: if (values(%lockerrors) > 0) {
2864: $lockmsg = join('<br />',values(%lockerrors));
2865: }
1.491 raeburn 2866: my $storefn;
2867: if ($key eq $oldurl) {
2868: $storefn = $url;
2869: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2870: } else {
2871: $storefn = $key;
2872: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2873: if ($prefixchg && $before{'map'} && $after{'map'}) {
2874: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2875: }
1.529 raeburn 2876: if ($newsubdir{$key}) {
2877: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2878: }
1.491 raeburn 2879: }
1.492 raeburn 2880: my $report;
2881: if ($folder !~ /^supplemental/) {
2882: $report = 1;
2883: }
1.527 raeburn 2884: (my $outtext,$errtext) =
1.492 raeburn 2885: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2886: if ($errtext) {
1.529 raeburn 2887: if ($caller eq 'paste') {
1.533 raeburn 2888: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2889: }
1.491 raeburn 2890: }
2891: }
2892: }
1.533 raeburn 2893: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2894: }
2895:
2896: sub copy_dependencies {
2897: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2898: my $content;
2899: if (ref($contentref)) {
2900: $content = $$contentref;
2901: } else {
2902: $content = &Apache::lonnet::getfile($item);
2903: }
2904: unless ($content eq '-1') {
2905: my $mm = new File::MMagic;
2906: my $mimetype = $mm->checktype_contents($content);
2907: if ($mimetype eq 'text/html') {
2908: my (%allfiles,%codebase,$state);
2909: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2910: if ($res eq 'ok') {
2911: my ($numexisting,$numpathchanges,$existing);
2912: (undef,$numexisting,$numpathchanges,$existing) =
2913: &Apache::loncommon::ask_for_embedded_content(
2914: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2915: {'error_on_invalid_names' => 1,
2916: 'ignore_remote_references' => 1,
2917: 'docs_url' => $item,
2918: 'context' => 'paste'});
2919: if ($numexisting > 0) {
2920: if (ref($existing) eq 'HASH') {
2921: foreach my $dep (keys(%{$existing})) {
2922: my $depfile = $dep;
2923: unless ($depfile =~ m{^\Q$relpath\E}) {
2924: $depfile = $relpath.$dep;
2925: }
2926: my $depcontent = &Apache::lonnet::getfile($depfile);
2927: unless ($depcontent eq '-1') {
2928: my $storedep = $dep;
2929: $storedep =~ s{^\Q$relpath\E}{};
2930: my $dep_url =
2931: &Apache::lonclonecourse::writefile(
2932: $env{'request.course.id'},
2933: $storefn.$storedep,$depcontent);
2934: if ($dep_url eq '/adm/notfound.html') {
2935: if (ref($errors) eq 'HASH') {
2936: $errors->{$depfile} = 1;
2937: }
2938: } else {
2939: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2940: }
2941: }
2942: }
1.488 raeburn 2943: }
2944: }
2945: }
2946: }
2947: }
2948: return;
2949: }
2950:
1.329 droeschl 2951: my %parameter_type = ( 'randompick' => 'int_pos',
2952: 'hiddenresource' => 'string_yesno',
2953: 'encrypturl' => 'string_yesno',
2954: 'randomorder' => 'string_yesno',);
2955: my $valid_parameters_re = join('|',keys(%parameter_type));
2956: # set parameters
2957: sub update_parameter {
1.537 raeburn 2958: if ($env{'form.changeparms'} eq 'all') {
2959: my (@allidx,@allmapidx,%allchecked,%currchecked);
2960: %allchecked = (
2961: 'hiddenresource' => {},
2962: 'encrypturl' => {},
2963: 'randompick' => {},
2964: 'randomorder' => {},
2965: );
2966: foreach my $which (keys(%allchecked)) {
1.630 raeburn 2967: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 2968: if ($which eq 'randompick') {
2969: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2970: my ($res,$value) = split(/:/,$item);
2971: if ($value =~ /^\d+$/) {
2972: $allchecked{$which}{$res} = $value;
2973: }
2974: }
2975: } else {
1.539 raeburn 2976: if ($env{'form.all'.$which}) {
2977: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2978: }
1.537 raeburn 2979: }
2980: }
2981: my $haschanges = 0;
2982: foreach my $res (@LONCAPA::map::order) {
2983: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2984: $name=&LONCAPA::map::qtescape($name);
2985: $url=&LONCAPA::map::qtescape($url);
2986: next unless ($name && $url);
2987: my $is_map;
2988: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2989: $is_map = 1;
2990: }
2991: foreach my $which (keys(%allchecked)) {
2992: if (($which eq 'randompick' || $which eq 'randomorder')) {
2993: next if (!$is_map);
2994: }
2995: my $oldvalue = 0;
2996: my $newvalue = 0;
2997: if ($allchecked{$which}{$res}) {
2998: $newvalue = $allchecked{$which}{$res};
2999: }
3000: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3001: if ($which eq 'randompick') {
3002: if ($current =~ /^(\d+)$/) {
3003: $oldvalue = $1;
3004: }
3005: } else {
3006: if ($current =~ /^yes$/i) {
3007: $oldvalue = 1;
3008: }
3009: }
3010: if ($oldvalue ne $newvalue) {
3011: $haschanges = 1;
3012: if ($newvalue) {
3013: my $storeval = 'yes';
3014: if ($which eq 'randompick') {
3015: $storeval = $newvalue;
3016: }
3017: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3018: $storeval,
3019: $parameter_type{$which});
3020: &remember_parms($res,$which,'set',$storeval);
3021: } elsif ($oldvalue) {
3022: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3023: &remember_parms($res,$which,'del');
3024: }
3025: }
3026: }
3027: }
3028: return $haschanges;
3029: } else {
1.588 raeburn 3030: my $haschanges = 0;
3031: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3032:
1.537 raeburn 3033: my $which = $env{'form.changeparms'};
3034: my $idx = $env{'form.setparms'};
1.588 raeburn 3035: my $oldvalue = 0;
3036: my $newvalue = 0;
3037: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3038: if ($which eq 'randompick') {
3039: if ($current =~ /^(\d+)$/) {
3040: $oldvalue = $1;
3041: }
3042: } elsif ($current =~ /^yes$/i) {
3043: $oldvalue = 1;
3044: }
1.537 raeburn 3045: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3046: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3047: : 1;
3048: }
3049: if ($oldvalue ne $newvalue) {
3050: $haschanges = 1;
3051: if ($newvalue) {
3052: my $storeval = 'yes';
3053: if ($which eq 'randompick') {
3054: $storeval = $newvalue;
3055: }
3056: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3057: $parameter_type{$which});
3058: &remember_parms($idx,$which,'set',$storeval);
3059: } else {
3060: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3061: &remember_parms($idx,$which,'del');
3062: }
1.537 raeburn 3063: }
1.588 raeburn 3064: return $haschanges;
1.329 droeschl 3065: }
3066: }
3067:
3068: sub handle_edit_cmd {
3069: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3070: my $haschanges = 0;
1.543 raeburn 3071: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3072: return $haschanges;
1.543 raeburn 3073: }
1.329 droeschl 3074: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3075:
3076: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3077: my ($title, $url, @rrest) = split(':', $ratstr);
3078:
1.538 raeburn 3079: if ($cmd eq 'remove') {
1.329 droeschl 3080: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3081: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3082: &Apache::lonnet::removeuploadedurl($url);
3083: } else {
3084: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3085: }
3086: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3087: $haschanges = 1;
1.329 droeschl 3088: } elsif ($cmd eq 'cut') {
3089: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3090: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3091: $haschanges = 1;
1.344 bisitz 3092: } elsif ($cmd eq 'up'
1.329 droeschl 3093: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3094: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3095: $haschanges = 1;
1.329 droeschl 3096: } elsif ($cmd eq 'down'
3097: && defined($LONCAPA::map::order[$idx+1])) {
3098: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3099: $haschanges = 1;
1.329 droeschl 3100: } elsif ($cmd eq 'rename') {
3101: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3102: if ($comment=~/\S/) {
3103: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3104: $comment.':'.join(':', $url, @rrest);
3105: }
3106: # Devalidate title cache
3107: my $renamed_url=&LONCAPA::map::qtescape($url);
3108: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3109: $haschanges = 1;
3110: } elsif ($cmd eq 'setalias') {
3111: my $newvalue = $env{'form.alias'};
3112: if ($newvalue ne '') {
3113: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3114: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3115: 'string');
3116: &remember_parms($idx,'mapalias','set',$newvalue);
3117: $haschanges = 1;
3118: }
3119: }
3120: } elsif ($cmd eq 'delalias') {
3121: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3122: if ($current ne '') {
3123: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3124: &remember_parms($idx,'mapalias','del');
3125: $haschanges = 1;
3126: }
1.329 droeschl 3127: }
1.633 raeburn 3128: return $haschanges;
1.329 droeschl 3129: }
3130:
3131: sub editor {
1.458 raeburn 3132: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3133: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3134: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3135: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3136: if ($allowed) {
1.519 raeburn 3137: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3138: $is_random_order,$container) =
1.510 raeburn 3139: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3140: $r->print($breadcrumbtrail);
1.519 raeburn 3141: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3142: $container = 'page';
3143: } else {
3144: $container = 'sequence';
1.510 raeburn 3145: }
1.484 raeburn 3146:
1.525 raeburn 3147: my $jumpto;
3148:
3149: unless ($supplementalflag) {
1.546 raeburn 3150: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3151: }
1.484 raeburn 3152:
3153: unless ($allowed) {
3154: $randompick = -1;
3155: }
3156:
1.615 raeburn 3157: my ($errtext,$fatal);
3158: if (($folder eq '') && (!$supplementalflag)) {
3159: if (@LONCAPA::map::order) {
3160: undef(@LONCAPA::map::order);
3161: undef(@LONCAPA::map::resources);
3162: undef(@LONCAPA::map::resparms);
3163: undef(@LONCAPA::map::zombies);
3164: }
3165: $folder = 'default';
3166: $container = 'sequence';
3167: } else {
3168: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3169: $folder.'.'.$container);
3170: return $errtext if ($fatal);
3171: }
1.329 droeschl 3172:
3173: if ($#LONCAPA::map::order<1) {
3174: my $idx=&LONCAPA::map::getresidx();
3175: if ($idx<=0) { $idx=1; }
3176: $LONCAPA::map::order[0]=$idx;
3177: $LONCAPA::map::resources[$idx]='';
3178: }
1.364 bisitz 3179:
1.329 droeschl 3180: # ------------------------------------------------------------ Process commands
3181:
3182: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3183: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3184: # set parameters and change order
3185: &snapshotbefore();
3186:
3187: if (&update_parameter()) {
1.588 raeburn 3188: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3189: return $errtext if ($fatal);
3190: }
3191:
3192: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3193: # change order
3194: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3195: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3196:
3197: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3198: return $errtext if ($fatal);
3199: }
1.364 bisitz 3200:
1.329 droeschl 3201: if ($env{'form.pastemarked'}) {
1.491 raeburn 3202: my %paste_errors;
1.533 raeburn 3203: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3204: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3205: \%paste_errors);
1.541 raeburn 3206: if (ref($pastemsgarray) eq 'ARRAY') {
3207: if (@{$pastemsgarray} > 0) {
3208: $r->print('<p class="LC_info">'.
3209: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3210: '</p>');
3211: }
1.541 raeburn 3212: }
3213: if ($lockerror) {
3214: $r->print('<p class="LC_error">'.
3215: $lockerror.
3216: '</p>');
3217: }
3218: if ($save_error ne '') {
3219: return $save_error;
3220: }
3221: if ($paste_res) {
3222: my %errortext = &Apache::lonlocal::texthash (
3223: fail => 'Storage of folder contents failed',
3224: failread => 'Reading folder contents failed',
3225: failstore => 'Storage of folder contents failed',
3226: );
3227: if ($errortext{$paste_res}) {
3228: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3229: }
1.329 droeschl 3230: }
1.491 raeburn 3231: if (keys(%paste_errors) > 0) {
1.538 raeburn 3232: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3233: &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".
3234: '<ul>'."\n");
3235: foreach my $key (sort(keys(%paste_errors))) {
3236: $r->print('<li>'.$key.'</li>'."\n");
3237: }
3238: $r->print('</ul></p>'."\n");
3239: }
1.538 raeburn 3240: } elsif ($env{'form.clearmarked'}) {
3241: my $output = &do_buffer_empty();
3242: if ($output) {
3243: $r->print('<p class="LC_info">'.$output.'</p>');
3244: }
3245: }
1.329 droeschl 3246:
3247: $r->print($upload_output);
3248:
1.538 raeburn 3249: # Rename, cut, copy or remove a single resource
1.602 raeburn 3250: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3251: my $contentchg;
1.633 raeburn 3252: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3253: $contentchg = 1;
3254: }
3255: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3256: return $errtext if ($fatal);
3257: }
1.538 raeburn 3258:
3259: # Cut, copy and/or remove multiple resources
3260: if ($env{'form.multichange'}) {
3261: my %allchecked = (
3262: cut => {},
3263: remove => {},
3264: );
3265: my $needsupdate;
3266: foreach my $which (keys(%allchecked)) {
3267: $env{'form.multi'.$which} =~ s/,$//;
3268: if ($env{'form.multi'.$which}) {
3269: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3270: if (ref($allchecked{$which}) eq 'HASH') {
3271: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3272: }
3273: }
3274: }
3275: if ($needsupdate) {
3276: my $haschanges = 0;
3277: my %curr_groups = &Apache::longroup::coursegroups();
3278: my $total = scalar(@LONCAPA::map::order) - 1;
3279: for (my $i=$total; $i>=0; $i--) {
3280: my $res = $LONCAPA::map::order[$i];
3281: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3282: $name=&LONCAPA::map::qtescape($name);
3283: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3284: next unless $url;
1.538 raeburn 3285: my %denied =
3286: &action_restrictions($coursenum,$coursedom,$url,
3287: $env{'form.folderpath'},\%curr_groups);
3288: foreach my $which (keys(%allchecked)) {
3289: next if ($denied{$which});
3290: next unless ($allchecked{$which}{$res});
3291: if ($which eq 'remove') {
3292: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3293: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3294: &Apache::lonnet::removeuploadedurl($url);
3295: } else {
3296: &LONCAPA::map::makezombie($res);
3297: }
3298: splice(@LONCAPA::map::order,$i,1);
3299: $haschanges ++;
3300: } elsif ($which eq 'cut') {
3301: &LONCAPA::map::makezombie($res);
3302: splice(@LONCAPA::map::order,$i,1);
3303: $haschanges ++;
3304: }
3305: }
3306: }
3307: if ($haschanges) {
3308: ($errtext,$fatal) =
3309: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3310: return $errtext if ($fatal);
3311: }
3312: }
3313: }
3314:
1.329 droeschl 3315: # Group import/search
3316: if ($env{'form.importdetail'}) {
3317: my @imports;
3318: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3319: if (defined($item)) {
3320: my ($name,$url,$residx)=
1.533 raeburn 3321: map { &unescape($_); } split(/\=/,$item);
3322: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3323: my ($suffix,$errortxt,$locknotfreed) =
3324: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3325: if ($locknotfreed) {
3326: $r->print($locknotfreed);
3327: }
3328: if ($suffix) {
3329: $url =~ s/_new\./_$suffix./;
3330: } else {
3331: return $errortxt;
3332: }
1.533 raeburn 3333: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3334: my $type = $1;
3335: my ($suffix,$errortxt,$locknotfreed) =
3336: &new_timebased_suffix($coursedom,$coursenum,$type);
3337: if ($locknotfreed) {
3338: $r->print($locknotfreed);
3339: }
3340: if ($suffix) {
3341: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3342: } else {
3343: return $errortxt;
3344: }
1.626 raeburn 3345: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3346: my ($suffix,$errortxt,$locknotfreed) =
3347: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3348: if ($locknotfreed) {
3349: $r->print($locknotfreed);
3350: }
3351: if ($suffix) {
3352: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3353: } else {
3354: return $errortxt;
3355: }
1.534 raeburn 3356: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3357: if ($supplementalflag) {
3358: next unless ($1 eq 'supplemental');
3359: if ($folder eq 'supplemental') {
3360: next unless ($2 eq 'default');
3361: } else {
3362: next unless ($folder eq 'supplemental_'.$2);
3363: }
3364: } else {
3365: next unless ($1 eq 'docs');
3366: if ($folder eq 'default') {
3367: next unless ($2 eq 'default');
3368: } else {
3369: next unless ($folder eq 'default_'.$2);
3370: }
3371: }
1.504 raeburn 3372: }
1.329 droeschl 3373: push(@imports, [$name, $url, $residx]);
3374: }
3375: }
1.530 raeburn 3376: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3377: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3378: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3379: return $errtext if ($fatal);
1.529 raeburn 3380: if ($fixuperrors) {
3381: $r->print($fixuperrors);
3382: }
1.329 droeschl 3383: }
3384: # Loading a complete map
3385: if ($env{'form.loadmap'}) {
3386: if ($env{'form.importmap'}=~/\w/) {
3387: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3388: my ($title,$url,$ext,$type)=split(/\:/,$res);
3389: my $idx=&LONCAPA::map::getresidx($url);
3390: $LONCAPA::map::resources[$idx]=$res;
3391: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3392: }
3393: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3394: $folder.'.'.$container,1);
1.329 droeschl 3395: return $errtext if ($fatal);
3396: } else {
3397: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3398:
1.329 droeschl 3399: }
3400: }
3401: &log_differences($plain);
3402: }
3403: # ---------------------------------------------------------------- End commands
3404: # ---------------------------------------------------------------- Print screen
3405: my $idx=0;
3406: my $shown=0;
3407: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3408: $r->print('<div class="LC_Box">'.
1.432 raeburn 3409: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3410: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3411: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3412: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3413: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3414: '</ol>');
1.381 bisitz 3415: if ($randompick>=0) {
3416: $r->print('<p class="LC_warning">'
3417: .&mt('Caution: this folder is set to randomly pick a subset'
3418: .' of resources. Adding or removing resources from this'
3419: .' folder will change the set of resources that the'
3420: .' students see, resulting in spurious or missing credit'
3421: .' for completed problems, not limited to ones you'
3422: .' modify. Do not modify the contents of this folder if'
3423: .' it is in active student use.')
3424: .'</p>'
3425: );
3426: }
3427: if ($is_random_order) {
3428: $r->print('<p class="LC_warning">'
3429: .&mt('Caution: this folder is set to randomly order its'
3430: .' contents. Adding or removing resources from this folder'
3431: .' will change the order of resources shown.')
3432: .'</p>'
3433: );
3434: }
3435: $r->print('</div>');
1.364 bisitz 3436: }
1.381 bisitz 3437:
1.538 raeburn 3438: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3439: %filters = (
1.543 raeburn 3440: canremove => [],
3441: cancut => [],
3442: cancopy => [],
3443: hiddenresource => [],
3444: encrypturl => [],
3445: randomorder => [],
3446: randompick => [],
1.538 raeburn 3447: );
3448: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3449: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3450: foreach my $res (@LONCAPA::map::order) {
3451: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3452: $name=&LONCAPA::map::qtescape($name);
3453: $url=&LONCAPA::map::qtescape($url);
3454: unless ($name) { $name=(split(/\//,$url))[-1]; }
3455: unless ($name) { $idx++; next; }
1.537 raeburn 3456: push(@allidx,$res);
3457: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3458: push(@allmapidx,$res);
3459: }
1.617 raeburn 3460:
1.381 bisitz 3461: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3462: $coursenum,$coursedom,$crstype,
1.538 raeburn 3463: $pathitem,$supplementalflag,$container,
1.620 raeburn 3464: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3465: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3466: $idx++;
3467: $shown++;
1.329 droeschl 3468: }
1.424 onken 3469: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3470:
1.538 raeburn 3471: my $need_save;
1.611 raeburn 3472: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3473: my $toolslink;
1.611 raeburn 3474: if ($allowed) {
1.544 raeburn 3475: $toolslink = '<table><tr><td>'
1.520 raeburn 3476: .&Apache::loncommon::help_open_menu('Navigation Screen',
3477: 'Navigation_Screen',undef,'RAT')
3478: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3479: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3480: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3481: .'id="LC_content_toolbar_edittoplevel" '
3482: .'class="LC_toolbarItem" '
3483: .'title="'.&mt('Supplemental Content Editor').'">'
3484: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3485: }
1.510 raeburn 3486: if ($shown) {
3487: if ($allowed) {
3488: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3489: .&Apache::loncommon::start_data_table(undef,'contentlist')
3490: .&Apache::loncommon::start_data_table_header_row()
3491: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3492: .'<th colspan="3">'.&mt('Actions').'</th>'
1.538 raeburn 3493: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3494: if ($folder !~ /^supplemental/) {
1.633 raeburn 3495: $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
1.510 raeburn 3496: }
1.537 raeburn 3497: $to_show .= &Apache::loncommon::end_data_table_header_row();
3498: if ($folder !~ /^supplemental/) {
1.538 raeburn 3499: $lists{'canhide'} = join(',',@allidx);
3500: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3501: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3502: 'randomorder','randompick');
3503: foreach my $item (@possfilters) {
1.538 raeburn 3504: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3505: if (@{$filters{$item}} > 0) {
3506: $lists{$item} = join(',',@{$filters{$item}});
3507: }
1.538 raeburn 3508: }
3509: }
1.537 raeburn 3510: if (@allidx > 0) {
3511: my $path;
3512: if ($env{'form.folderpath'}) {
1.630 raeburn 3513: $path =
1.537 raeburn 3514: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3515: }
1.538 raeburn 3516: if (@allidx > 1) {
1.630 raeburn 3517: $to_show .=
1.538 raeburn 3518: &Apache::loncommon::continue_data_table_row().
3519: '<td colspan="2"> </td>'.
3520: '<td>'.
1.611 raeburn 3521: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3522: '</td>'.
1.633 raeburn 3523: '<td colspan="3"> </td>'.
3524: '<td colspan="2">'.
1.611 raeburn 3525: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3526: '</td>'.
3527: &Apache::loncommon::end_data_table_row();
3528: $need_save = 1;
3529: }
1.537 raeburn 3530: }
3531: }
3532: $to_show .= $output.' '
1.510 raeburn 3533: .&Apache::loncommon::end_data_table()
3534: .'<br style="line-height:2px;" />'
3535: .&Apache::loncommon::end_scrollbox();
3536: } else {
1.520 raeburn 3537: $to_show .= $toolslink
1.510 raeburn 3538: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3539: .$output.' '
3540: .&Apache::loncommon::end_data_table();
1.393 raeburn 3541: }
1.510 raeburn 3542: } else {
1.520 raeburn 3543: if (!$allowed) {
3544: $to_show .= $toolslink;
3545: }
1.615 raeburn 3546: my $noresmsg;
3547: if ($allowed && $hiddentop && !$supplementalflag) {
3548: $noresmsg = &mt('Main Content Hidden');
3549: } else {
3550: $noresmsg = &mt('Currently empty');
3551: }
1.510 raeburn 3552: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3553: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3554: .$noresmsg
1.510 raeburn 3555: .'</div>'
3556: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3557: }
3558: } else {
1.510 raeburn 3559: if ($shown) {
3560: $to_show = '<div>'
3561: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3562: .$output
3563: .&Apache::loncommon::end_data_table()
3564: .'</div>';
3565: } else {
3566: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3567: .&mt('Currently empty')
1.510 raeburn 3568: .'</div>'
3569: }
1.458 raeburn 3570: }
3571: my $tid = 1;
3572: if ($supplementalflag) {
3573: $tid = 2;
1.329 droeschl 3574: }
3575: if ($allowed) {
1.484 raeburn 3576: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3577: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3578: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3579: if ($canedit) {
3580: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3581: }
1.460 raeburn 3582: } else {
3583: $r->print($to_show);
1.329 droeschl 3584: }
3585: return;
3586: }
3587:
1.538 raeburn 3588: sub multiple_check_form {
1.611 raeburn 3589: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3590: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3591: my $disabled;
3592: unless ($canedit) {
3593: $disabled = 'disabled="disabled"';
3594: }
1.538 raeburn 3595: my $output =
3596: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3597: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3598: '<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>'.
3599: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3600: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3601: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3602: if ($caller eq 'settings') {
3603: $output .=
3604: '<table><tr>'.
3605: '<td class="LC_docs_entry_parameter">'.
3606: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3607: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3608: '</label></span></td>'.
3609: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3610: '<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 3611: '</span></td>'.
3612: '</tr>'."\n".
3613: '<tr>'.
3614: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3615: '<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 3616: '</label></span>'.
3617: '</td></tr></table>'."\n";
3618: } else {
3619: $output .=
3620: '<table><tr>'.
3621: '<td class="LC_docs_entry_parameter">'.
3622: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3623: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3624: '</label></span></td>'.
3625: '<td class="LC_docs_entry_parameter">'.
3626: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3627: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3628: '</label></span></td>'."\n".
3629: '<td class="LC_docs_entry_parameter">'.
3630: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3631: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3632: '</label></span></td>'.
3633: '</tr></table>'."\n";
3634: }
3635: $output .=
3636: '</fieldset>'.
3637: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3638: if ($caller eq 'settings') {
3639: $output .=
1.543 raeburn 3640: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3641: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3642: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3643: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3644: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3645: } elsif ($caller eq 'actions') {
3646: $output .=
3647: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3648: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3649: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3650: }
3651: $output .=
3652: '</form>'.
3653: '</div>';
3654: return $output;
3655: }
3656:
1.329 droeschl 3657: sub process_file_upload {
1.552 raeburn 3658: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3659: # upload a file, if present
1.552 raeburn 3660: my $filesize = length($env{'form.uploaddoc'});
3661: if (!$filesize) {
3662: $$upload_output = '<div class="LC_error">'.
3663: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3664: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3665: $filesize).'<br />'.
3666: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3667: '</div>';
3668: return;
3669: }
3670: my $quotatype = 'unofficial';
3671: if ($crstype eq 'Community') {
1.601 raeburn 3672: $quotatype = 'community';
3673: } elsif ($crstype eq 'Placement') {
3674: $quotatype = 'placement';
1.580 raeburn 3675: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3676: $quotatype = 'official';
1.573 raeburn 3677: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3678: $quotatype = 'textbook';
1.552 raeburn 3679: }
3680: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3681: $filesize = int($filesize/1000); #expressed in kb
3682: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3683: $env{'form.uploaddoc.filename'},$filesize,
3684: 'upload',$quotatype);
1.552 raeburn 3685: return if ($$upload_output);
3686: }
1.440 raeburn 3687: my ($parseaction,$showupload,$nextphase,$mimetype);
3688: if ($env{'form.parserflag'}) {
1.329 droeschl 3689: $parseaction = 'parse';
3690: }
3691: my $folder=$env{'form.folder'};
3692: if ($folder eq '') {
3693: $folder='default';
3694: }
3695: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3696: my $errtext='';
3697: my $fatal=0;
3698: my $container='sequence';
1.519 raeburn 3699: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3700: $container='page';
3701: }
3702: ($errtext,$fatal)=
1.534 raeburn 3703: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3704: if ($#LONCAPA::map::order<1) {
3705: $LONCAPA::map::order[0]=1;
3706: $LONCAPA::map::resources[1]='';
3707: }
3708: my $destination = 'docs/';
3709: if ($folder =~ /^supplemental/) {
3710: $destination = 'supplemental/';
3711: }
3712: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3713: $destination .= 'default/';
3714: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3715: $destination .= $2.'/';
3716: }
1.534 raeburn 3717: if ($fatal) {
3718: $$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>';
3719: return;
3720: }
1.440 raeburn 3721: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3722: my $newidx=&LONCAPA::map::getresidx();
3723: $destination .= $newidx;
1.439 raeburn 3724: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3725: $parseaction,$allfiles,
1.440 raeburn 3726: $codebase,undef,undef,undef,undef,
3727: undef,undef,\$mimetype);
3728: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3729: my $stored = $1;
3730: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3731: $stored.'</span>').'</p>';
3732: } else {
3733: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3734:
1.457 raeburn 3735: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3736: return;
3737: }
1.329 droeschl 3738: my $ext='false';
3739: if ($url=~m{^http://}) { $ext='true'; }
3740: $url = &LONCAPA::map::qtunescape($url);
3741: my $comment=$env{'form.comment'};
3742: $comment = &LONCAPA::map::qtunescape($comment);
3743: if ($folder=~/^supplemental/) {
3744: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3745: $env{'user.domain'}.'___&&&___'.$comment;
3746: }
3747:
3748: $LONCAPA::map::resources[$newidx]=
3749: $comment.':'.$url.':'.$ext.':normal:res';
3750: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3751: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3752: $folder.'.'.$container,1);
1.329 droeschl 3753: if ($fatal) {
1.457 raeburn 3754: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3755: return;
1.329 droeschl 3756: } else {
1.440 raeburn 3757: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3758: $$upload_output = $showupload;
1.384 raeburn 3759: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3760: if ($total_embedded > 0) {
1.440 raeburn 3761: my $uploadphase = 'upload_embedded';
3762: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3763: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3764: my ($embedded,$num) =
1.440 raeburn 3765: &Apache::loncommon::ask_for_embedded_content(
3766: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3767: if ($embedded) {
3768: if ($num) {
3769: $$upload_output .=
3770: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3771: $nextphase = $uploadphase;
3772: } else {
3773: $$upload_output .= $embedded;
3774: }
3775: } else {
3776: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3777: }
1.329 droeschl 3778: } else {
1.440 raeburn 3779: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3780: }
1.457 raeburn 3781: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3782: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3783: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3784: $nextphase = 'decompress_uploaded';
3785: my $position = scalar(@LONCAPA::map::order)-1;
3786: my $noextract = &return_to_editor();
3787: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3788: my %archiveitems = (
3789: folderpath => $env{'form.folderpath'},
3790: cmd => $nextphase,
3791: newidx => $newidx,
3792: position => $position,
3793: phase => $nextphase,
1.477 raeburn 3794: comment => $comment,
1.480 raeburn 3795: );
3796: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3797: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3798: $$upload_output = $showupload.
3799: &Apache::loncommon::decompress_form($mimetype,
3800: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3801: \%archiveitems,\@current);
1.329 droeschl 3802: }
3803: }
3804: }
1.440 raeburn 3805: return $nextphase;
1.329 droeschl 3806: }
3807:
1.480 raeburn 3808: sub get_dir_list {
3809: my ($url,$coursenum,$coursedom,$newidx) = @_;
3810: my ($destination,$dir_root) = &embedded_destination();
3811: my ($dirlistref,$listerror) =
3812: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3813: my @dir_lines;
3814: my $dirptr=16384;
3815: if (ref($dirlistref) eq 'ARRAY') {
3816: foreach my $dir_line (sort
3817: {
3818: my ($afile)=split('&',$a,2);
3819: my ($bfile)=split('&',$b,2);
3820: return (lc($afile) cmp lc($bfile));
3821: } (@{$dirlistref})) {
3822: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3823: $filename =~ s/\s+$//;
3824: next if ($filename =~ /^\.\.?$/);
3825: my $isdir = 0;
3826: if ($dirptr&$testdir) {
3827: $isdir = 1;
3828: }
3829: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3830: }
3831: }
3832: return @dir_lines;
3833: }
3834:
1.329 droeschl 3835: sub is_supplemental_title {
3836: my ($title) = @_;
3837: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3838: }
3839:
3840: # --------------------------------------------------------------- An entry line
3841:
3842: sub entryline {
1.501 raeburn 3843: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3844: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3845: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3846: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3847: if (&is_supplemental_title($title)) {
1.488 raeburn 3848: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3849: } else {
3850: $title=&HTML::Entities::encode($title,'"<>&\'');
3851: $renametitle=$title;
3852: $foldertitle=$title;
3853: }
3854:
1.611 raeburn 3855: my ($disabled,$readonly,$js_lt);
3856: unless ($canedit) {
3857: $disabled = 'disabled="disabled"';
3858: $readonly = 1;
3859: }
3860:
1.329 droeschl 3861: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3862:
1.329 droeschl 3863: $renametitle=~s/\\/\\\\/g;
3864: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3865: $renametitle=~s/"/%22/g;
1.581 raeburn 3866: $renametitle=~s/ /%20/g;
3867: $oldtitle = $renametitle;
1.576 raeburn 3868: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3869: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3870: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3871: # Edit commands
1.633 raeburn 3872: my ($esc_path, $path, $symb, $curralias);
1.329 droeschl 3873: if ($env{'form.folderpath'}) {
3874: $esc_path=&escape($env{'form.folderpath'});
3875: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3876: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3877: }
1.505 raeburn 3878: my $isexternal;
1.510 raeburn 3879: if ($residx) {
1.501 raeburn 3880: my $currurl = $url;
3881: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3882: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3883: $isexternal = 1;
3884: }
1.510 raeburn 3885: if (!$supplementalflag) {
3886: my $path = 'uploaded/'.
3887: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3888: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3889: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3890: $residx,
3891: &Apache::lonnet::declutter($currurl));
3892: }
1.501 raeburn 3893: }
1.538 raeburn 3894: my ($renamelink,%lt,$ishash);
3895: if (ref($filtersref) eq 'HASH') {
3896: $ishash = 1;
3897: }
3898:
1.329 droeschl 3899: if ($allowed) {
1.538 raeburn 3900: $form_start = '
3901: <form action="/adm/coursedocs" method="post">
3902: ';
3903: $form_common=(<<END);
3904: <input type="hidden" name="folderpath" value="$path" />
3905: <input type="hidden" name="symb" value="$symb" />
3906: END
3907: $form_param=(<<END);
3908: <input type="hidden" name="setparms" value="$orderidx" />
3909: <input type="hidden" name="changeparms" value="0" />
3910: END
3911: $form_end = '</form>';
3912:
1.329 droeschl 3913: my $incindex=$index+1;
3914: my $selectbox='';
1.471 raeburn 3915: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3916: ((split(/\:/,
1.344 bisitz 3917: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3918: ne '') &&
1.329 droeschl 3919: ((split(/\:/,
1.344 bisitz 3920: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3921: ne '')) {
3922: $selectbox=
3923: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3924: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3925: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3926: if ($i==$incindex) {
1.358 bisitz 3927: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3928: } else {
3929: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3930: }
3931: }
3932: $selectbox.='</select>';
3933: }
1.501 raeburn 3934: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3935: 'up' => 'Move Up',
3936: 'dw' => 'Move Down',
3937: 'rm' => 'Remove',
3938: 'ct' => 'Cut',
3939: 'rn' => 'Rename',
1.501 raeburn 3940: 'cp' => 'Copy',
1.633 raeburn 3941: 'da' => 'Unset alias',
3942: 'sa' => 'Set alias',
1.501 raeburn 3943: 'ex' => 'External Resource',
1.598 raeburn 3944: 'et' => 'External Tool',
1.501 raeburn 3945: 'ed' => 'Edit',
3946: 'pr' => 'Preview',
3947: 'sv' => 'Save',
3948: 'ul' => 'URL',
1.611 raeburn 3949: 'ti' => 'Title',
1.618 raeburn 3950: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3951: );
1.538 raeburn 3952: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3953: $env{'form.folderpath'},
3954: $currgroups);
1.517 raeburn 3955: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3956: my $skip_confirm = 0;
1.603 raeburn 3957: my $confirm_removal = 0;
1.329 droeschl 3958: if ( $folder =~ /^supplemental/
3959: || ($url =~ m{( /smppg$
3960: |/syllabus$
3961: |/aboutme$
3962: |/navmaps$
3963: |/bulletinboard$
1.626 raeburn 3964: |/ext\.tool$
1.505 raeburn 3965: |\.html$)}x)
3966: || $isexternal) {
1.329 droeschl 3967: $skip_confirm = 1;
3968: }
1.603 raeburn 3969: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3970: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3971: $confirm_removal = 1;
3972: }
1.633 raeburn 3973: if ($url =~ /$LONCAPA::assess_re/) {
3974: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
3975: }
1.329 droeschl 3976:
1.538 raeburn 3977: if ($denied{'copy'}) {
1.543 raeburn 3978: $copylink=(<<ENDCOPY)
1.507 raeburn 3979: <span style="visibility: hidden;">$lt{'cp'}</span>
3980: ENDCOPY
3981: } else {
1.538 raeburn 3982: my $formname = 'edit_copy_'.$orderidx;
3983: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3984: $copylink=(<<ENDCOPY);
1.538 raeburn 3985: <form name="$formname" method="post" action="/adm/coursedocs">
3986: $form_common
1.611 raeburn 3987: <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 3988: $form_end
1.329 droeschl 3989: ENDCOPY
1.538 raeburn 3990: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3991: push(@{$filtersref->{'cancopy'}},$orderidx);
3992: }
1.329 droeschl 3993: }
1.538 raeburn 3994: if ($denied{'cut'}) {
1.507 raeburn 3995: $cutlink=(<<ENDCUT);
3996: <span style="visibility: hidden;">$lt{'ct'}</span>
3997: ENDCUT
3998: } else {
1.538 raeburn 3999: my $formname = 'edit_cut_'.$orderidx;
4000: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4001: $cutlink=(<<ENDCUT);
1.538 raeburn 4002: <form name="$formname" method="post" action="/adm/coursedocs">
4003: $form_common
1.542 raeburn 4004: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4005: <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 4006: $form_end
1.329 droeschl 4007: ENDCUT
1.538 raeburn 4008: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4009: push(@{$filtersref->{'cancut'}},$orderidx);
4010: }
1.329 droeschl 4011: }
1.538 raeburn 4012: if ($denied{'remove'}) {
1.507 raeburn 4013: $removelink=(<<ENDREM);
4014: <span style="visibility: hidden;">$lt{'rm'}</a>
4015: ENDREM
4016: } else {
1.538 raeburn 4017: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4018: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4019: $removelink=(<<ENDREM);
1.538 raeburn 4020: <form name="$formname" method="post" action="/adm/coursedocs">
4021: $form_common
1.542 raeburn 4022: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4023: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4024: <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 4025: $form_end
1.497 raeburn 4026: ENDREM
1.538 raeburn 4027: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4028: push(@{$filtersref->{'canremove'}},$orderidx);
4029: }
1.497 raeburn 4030: }
1.551 raeburn 4031: $renamelink=(<<ENDREN);
1.581 raeburn 4032: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4033: ENDREN
1.611 raeburn 4034: my ($uplink,$downlink);
4035: if ($canedit) {
4036: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4037: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4038: } else {
4039: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4040: $downlink = $uplink;
4041: }
1.329 droeschl 4042: $line.=(<<END);
4043: <td>
1.379 bisitz 4044: <div class="LC_docs_entry_move">
1.611 raeburn 4045: <a href="$uplink">
1.501 raeburn 4046: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4047: </a>
4048: </div>
4049: <div class="LC_docs_entry_move">
1.611 raeburn 4050: <a href="$downlink">
1.501 raeburn 4051: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4052: </a>
4053: </div>
1.329 droeschl 4054: </td>
4055: <td>
4056: $form_start
1.538 raeburn 4057: $form_param
1.478 raeburn 4058: $form_common
1.329 droeschl 4059: $selectbox
4060: $form_end
4061: </td>
1.540 raeburn 4062: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4063: $removelink
1.329 droeschl 4064: $cutlink
4065: $copylink
4066: </td>
4067: END
4068: }
4069: # Figure out what kind of a resource this is
4070: my ($extension)=($url=~/\.(\w+)$/);
4071: my $uploaded=($url=~/^\/*uploaded\//);
4072: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4073: my $isfolder;
4074: my $ispage;
4075: my $containerarg;
1.615 raeburn 4076: my $folderurl;
1.329 droeschl 4077: if ($uploaded) {
1.472 raeburn 4078: if (($extension eq 'sequence') || ($extension eq 'page')) {
4079: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4080: $containerarg = $1;
1.472 raeburn 4081: if ($extension eq 'sequence') {
4082: $icon=$iconpath.'navmap.folder.closed.gif';
4083: $isfolder=1;
4084: } else {
4085: $icon=$iconpath.'page.gif';
4086: $ispage=1;
4087: }
1.615 raeburn 4088: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4089: if ($allowed) {
4090: $url='/adm/coursedocs?';
4091: } else {
4092: $url='/adm/supplemental?';
4093: }
1.329 droeschl 4094: } else {
4095: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4096: }
4097: }
1.364 bisitz 4098:
1.621 raeburn 4099: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4100: my $orig_url = $url;
1.340 raeburn 4101: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 4102: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 4103: if (!$supplementalflag && $residx && $symb) {
4104: if ((!$isfolder) && (!$ispage)) {
4105: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4106: $url=&Apache::lonnet::clutter($url);
4107: if ($url=~/^\/*uploaded\//) {
4108: $url=~/\.(\w+)$/;
4109: my $embstyle=&Apache::loncommon::fileembstyle($1);
4110: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4111: $url='/adm/wrapper'.$url;
4112: } elsif ($embstyle eq 'ssi') {
4113: #do nothing with these
4114: } elsif ($url!~/\.(sequence|page)$/) {
4115: $url='/adm/coursedocs/showdoc'.$url;
4116: }
1.623 raeburn 4117: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4118: my $wrapped = $1;
4119: my $exturl = $2;
4120: if ($wrapped eq '') {
4121: $url='/adm/wrapper'.$url;
4122: }
4123: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4124: $nomodal = 1;
4125: }
1.626 raeburn 4126: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4127: $url='/adm/wrapper'.$url;
1.621 raeburn 4128: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4129: if (($ENV{'SERVER_PORT'} == 443) &&
4130: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4131: $url .= '?usehttp=1';
4132: $nomodal = 1;
4133: }
1.598 raeburn 4134: }
1.501 raeburn 4135: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4136: my $shownsymb = $symb;
4137: if ($isexternal) {
4138: if ($url =~ /^([^#]+)#([^#]+)$/) {
4139: $url = $1;
4140: $anchor = $2;
4141: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4142: $shownsymb = $1.&escape('#').$anchor;
4143: }
4144: }
4145: }
1.617 raeburn 4146: unless ($env{'request.role.adv'}) {
4147: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4148: $url = '';
4149: }
4150: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4151: $url = '';
4152: $hiddenres = 1;
4153: }
4154: }
4155: if ($url ne '') {
1.641 raeburn 4156: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.617 raeburn 4157: }
1.615 raeburn 4158: } elsif (!$env{'request.role.adv'}) {
4159: my $checkencrypt;
4160: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4161: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4162: $checkencrypt = 1;
1.620 raeburn 4163: } elsif (ref($navmapref)) {
1.615 raeburn 4164: unless (ref($$navmapref)) {
4165: $$navmapref = Apache::lonnavmaps::navmap->new();
4166: }
4167: if (ref($$navmapref)) {
4168: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4169: $checkencrypt = 1;
4170: }
4171: }
4172: }
4173: if ($checkencrypt) {
4174: my $shownsymb = &Apache::lonenc::encrypted($symb);
4175: my $shownurl = &Apache::lonenc::encrypted($url);
4176: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.641 raeburn 4177: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.615 raeburn 4178: if ($env{'request.enc'} ne '') {
4179: delete($env{'request.enc'});
4180: }
4181: } else {
4182: $url='';
1.613 raeburn 4183: }
1.612 raeburn 4184: } else {
4185: $url='';
4186: }
1.501 raeburn 4187: } else {
4188: $url='';
4189: }
1.329 droeschl 4190: }
1.621 raeburn 4191: } elsif ($supplementalflag) {
1.610 raeburn 4192: if ($isexternal) {
4193: if ($url =~ /^([^#]+)#([^#]+)$/) {
4194: $url = $1;
4195: $anchor = $2;
1.623 raeburn 4196: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4197: if ($hostname ne '') {
4198: $url = 'http://'.$hostname.$url;
4199: }
4200: $nomodal = 1;
4201: }
1.610 raeburn 4202: }
1.621 raeburn 4203: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4204: if (($ENV{'SERVER_PORT'} == 443) &&
4205: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.622 raeburn 4206: if ($hostname ne '') {
4207: $url = 'http://'.$hostname.$url;
4208: }
1.621 raeburn 4209: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4210: $nomodal = 1;
4211: }
1.610 raeburn 4212: }
1.329 droeschl 4213: }
1.615 raeburn 4214: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4215: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4216: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4217: my $foldername=&escape($foldertitle);
4218: my $folderpath=$env{'form.folderpath'};
4219: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4220: if (!$allowed && $supplementalflag) {
1.519 raeburn 4221: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4222: $url.='folderpath='.&escape($folderpath);
4223: } else {
1.617 raeburn 4224: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4225: 'parameter_randompick'))[0];
4226: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4227: 'parameter_randomorder'))[0]=~/^yes$/i);
4228: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4229: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4230: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4231: 'parameter_encrypturl'))[0]=~/^yes$/i);
4232: unless ($hiddenmap) {
1.620 raeburn 4233: if (ref($navmapref)) {
4234: unless (ref($$navmapref)) {
4235: $$navmapref = Apache::lonnavmaps::navmap->new();
4236: }
4237: if (ref($$navmapref)) {
4238: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4239: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4240: unless (@resources) {
4241: $hiddenmap = 1;
4242: unless ($env{'request.role.adv'}) {
4243: $url = '';
4244: $hiddenfolder = 1;
4245: }
1.617 raeburn 4246: }
1.615 raeburn 4247: }
4248: }
4249: }
4250: }
1.617 raeburn 4251: unless ($encryptmap) {
1.620 raeburn 4252: if ((ref($navmapref)) && (ref($$navmapref))) {
4253: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4254: $encryptmap = 1;
4255: }
1.617 raeburn 4256: }
4257: }
1.630 raeburn 4258:
1.617 raeburn 4259: # Append randompick number, hidden, and encrypted with ":" to foldername,
4260: # so it gets transferred between levels
4261: $folderpath.=$containerarg.'&'.$foldername.
4262: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4263: unless ($url eq '') {
1.612 raeburn 4264: $url.='folderpath='.&escape($folderpath);
4265: }
1.510 raeburn 4266: my $rpckchk;
4267: if ($rpicknum) {
4268: $rpckchk = ' checked="checked"';
1.543 raeburn 4269: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4270: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4271: }
1.510 raeburn 4272: }
1.537 raeburn 4273: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4274: $rand_pick_text =
1.478 raeburn 4275: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4276: $form_param."\n".
1.478 raeburn 4277: $form_common."\n".
1.611 raeburn 4278: '<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 4279: if ($rpicknum ne '') {
4280: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4281: }
1.537 raeburn 4282: $rand_pick_text .= '</span></span>'.
4283: $form_end;
1.543 raeburn 4284: my $ro_set;
1.617 raeburn 4285: if ($randorder) {
1.543 raeburn 4286: $ro_set = 'checked="checked"';
4287: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4288: push(@{$filtersref->{'randomorder'}},$orderidx);
4289: }
4290: }
1.564 raeburn 4291: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4292: $rand_order_text =
1.537 raeburn 4293: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4294: $form_param."\n".
1.537 raeburn 4295: $form_common."\n".
1.611 raeburn 4296: '<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 4297: $form_end;
1.510 raeburn 4298: }
1.509 raeburn 4299: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4300: my $isexttool;
1.626 raeburn 4301: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4302: $url='/adm/wrapper'.$url;
4303: $isexttool = 1;
4304: }
1.510 raeburn 4305: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4306: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4307: if ($title) {
4308: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4309: }
1.598 raeburn 4310: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4311: $url .= '&idx='.$orderidx;
4312: }
1.610 raeburn 4313: if ($anchor ne '') {
4314: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4315: }
1.329 droeschl 4316: }
1.519 raeburn 4317: my ($tdalign,$tdwidth);
1.501 raeburn 4318: if ($allowed) {
1.630 raeburn 4319: my $fileloc =
1.501 raeburn 4320: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4321: if ($isexternal) {
1.630 raeburn 4322: ($editlink,$extresform) =
1.611 raeburn 4323: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4324: undef,undef,undef,undef,undef,undef,
4325: undef,$disabled);
1.626 raeburn 4326: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4327: ($editlink,$extresform) =
4328: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4329: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4330: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4331: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4332: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4333: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4334: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4335: my $suppanchor;
4336: if ($supplementalflag) {
4337: $suppanchor = $anchor;
4338: }
1.630 raeburn 4339: my $jscall =
1.501 raeburn 4340: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4341: $switchserver,
1.503 raeburn 4342: $forceedit,
1.511 raeburn 4343: undef,$symb,
4344: &escape($env{'form.folderpath'}),
1.622 raeburn 4345: $renametitle,$hostname,
4346: '','',1,$suppanchor);
1.501 raeburn 4347: if ($jscall) {
1.518 raeburn 4348: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4349: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4350: }
4351: }
4352: }
1.519 raeburn 4353: $tdalign = ' align="right" valign="top"';
4354: $tdwidth = ' width="80%"';
1.329 droeschl 4355: }
1.408 raeburn 4356: my $reinit;
4357: if ($crstype eq 'Community') {
4358: $reinit = &mt('(re-initialize community to access)');
4359: } else {
4360: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4361: }
4362: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.633 raeburn 4363: if ($url =~ /$LONCAPA::assess_re/) {
4364: $line.= '<br />';
4365: if ($curralias ne '') {
4366: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4367: $lt{'da'}.'</a></span>';
4368: } else {
4369: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4370: $lt{'sa'}.'</a></span>';
4371: }
4372: }
4373: $line.='</td><td>';
1.621 raeburn 4374: my $link;
1.472 raeburn 4375: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4376: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4377: } elsif ($url) {
1.610 raeburn 4378: if ($anchor ne '') {
4379: if ($supplementalflag) {
4380: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4381: } else {
4382: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4383: }
4384: }
1.622 raeburn 4385: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4386: $link = 'http://'.$hostname.$url;
4387: } else {
4388: $link = $url;
4389: }
4390: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.621 raeburn 4391: (($anchor ne '')?$anchor:''));
4392: if ($nomodal) {
4393: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4394: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4395: } else {
4396: $line.=&Apache::loncommon::modal_link($link,
4397: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4398: }
1.469 www 4399: } else {
4400: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4401: }
1.519 raeburn 4402: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4403: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4404: $line.='<a href="'.$url.'">'.$title.'</a>';
4405: } elsif ($url) {
1.621 raeburn 4406: if ($nomodal) {
4407: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4408: $title.'</a>';
4409: } else {
4410: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4411: }
1.617 raeburn 4412: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4413: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4414: } else {
4415: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4416: }
1.633 raeburn 4417: if (($allowed) && ($curralias ne '')) {
4418: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4419: } else {
4420: $line .= $extresform;
4421: }
4422: $line .= '</td>';
1.478 raeburn 4423: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4424: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4425: if (($allowed) && ($folder!~/^supplemental/)) {
4426: my %lt=&Apache::lonlocal::texthash(
4427: 'hd' => 'Hidden',
4428: 'ec' => 'URL hidden');
1.543 raeburn 4429: my ($enctext,$hidtext);
4430: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4431: $enctext = ' checked="checked"';
4432: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4433: push(@{$filtersref->{'encrypturl'}},$orderidx);
4434: }
4435: }
4436: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4437: $hidtext = ' checked="checked"';
4438: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4439: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4440: }
4441: }
1.537 raeburn 4442: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4443: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4444: $line.=(<<ENDPARMS);
4445: <td class="LC_docs_entry_parameter">
1.537 raeburn 4446: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4447: $form_param
1.478 raeburn 4448: $form_common
1.611 raeburn 4449: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4450: $form_end
1.458 raeburn 4451: <br />
1.537 raeburn 4452: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4453: $form_param
1.478 raeburn 4454: $form_common
1.611 raeburn 4455: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4456: $form_end
4457: </td>
1.478 raeburn 4458: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4459: $rand_order_text</td>
1.329 droeschl 4460: ENDPARMS
4461: }
1.379 bisitz 4462: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4463: return $line;
4464: }
4465:
1.538 raeburn 4466: sub action_restrictions {
4467: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4468: my %denied = (
4469: cut => 0,
4470: copy => 0,
4471: remove => 0,
4472: );
4473: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4474: # no copy for published maps
4475: $denied{'copy'} = 1;
1.597 raeburn 4476: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4477: unless ($1 eq 'simpleproblem') {
4478: $denied{'copy'} = 1;
4479: }
4480: $denied{'cut'} = 1;
1.538 raeburn 4481: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4482: if ($folderpath =~ /^default&[^\&]+$/) {
4483: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4484: $denied{'remove'} = 1;
4485: }
4486: $denied{'cut'} = 1;
4487: $denied{'copy'} = 1;
4488: }
4489: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4490: my $group = $1;
4491: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4492: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4493: $denied{'remove'} = 1;
4494: }
4495: }
4496: $denied{'cut'} = 1;
4497: $denied{'copy'} = 1;
4498: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4499: my $group = $1;
4500: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4501: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4502: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4503: if (keys(%groupsettings) > 0) {
4504: $denied{'remove'} = 1;
4505: }
4506: $denied{'cut'} = 1;
4507: $denied{'copy'} = 1;
4508: }
4509: }
4510: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4511: my $group = $1;
4512: if ($url =~ /group_boards_\Q$group\E/) {
4513: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4514: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4515: if (keys(%groupsettings) > 0) {
4516: if (ref($groupsettings{'functions'}) eq 'HASH') {
4517: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4518: $denied{'remove'} = 1;
4519: }
4520: }
4521: }
4522: $denied{'cut'} = 1;
4523: $denied{'copy'} = 1;
4524: }
4525: }
4526: }
4527: return %denied;
4528: }
4529:
1.533 raeburn 4530: sub new_timebased_suffix {
1.538 raeburn 4531: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4532: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4533: if ($type eq 'paste') {
4534: $prefix = $type;
4535: $namespace = 'courseeditor';
1.587 raeburn 4536: $idtype = 'addcode';
1.538 raeburn 4537: } elsif ($type eq 'map') {
1.533 raeburn 4538: $prefix = 'docs';
4539: if ($area eq 'supplemental') {
4540: $prefix = 'supp';
4541: }
4542: $prefix .= $container;
4543: $namespace = 'uploadedmaps';
4544: } else {
4545: $prefix = $type;
4546: $namespace = 'templated';
1.504 raeburn 4547: }
4548: my ($suffix,$freedlock,$error) =
1.587 raeburn 4549: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4550: if (!$suffix) {
1.538 raeburn 4551: if ($type eq 'paste') {
4552: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4553: } elsif ($type eq 'map') {
1.533 raeburn 4554: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4555: } elsif ($type eq 'smppg') {
4556: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4557: } elsif ($type eq 'exttool') {
4558: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4559: } else {
1.565 bisitz 4560: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4561: }
1.504 raeburn 4562: if ($error) {
4563: $errtext .= '<br />'.$error;
4564: }
4565: }
4566: if ($freedlock ne 'ok') {
1.630 raeburn 4567: $locknotfreed =
1.533 raeburn 4568: '<div class="LC_error">'.
4569: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4570: if ($type eq 'paste') {
1.591 raeburn 4571: if ($freedlock eq 'nolock') {
4572: $locknotfreed =
4573: '<div class="LC_error">'.
4574: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4575:
1.593 droeschl 4576: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4577: } else {
4578: $locknotfreed .=
4579: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4580: }
1.538 raeburn 4581: } elsif ($type eq 'map') {
1.591 raeburn 4582: $locknotfreed .=
4583: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4584: } elsif ($type eq 'smppg') {
4585: $locknotfreed .=
4586: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4587: } elsif ($type eq 'exttool') {
4588: $locknotfreed .=
4589: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4590: } else {
4591: $locknotfreed .=
1.565 bisitz 4592: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4593: }
1.538 raeburn 4594: unless ($type eq 'paste') {
4595: $locknotfreed .=
1.560 raeburn 4596: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4597: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4598: }
4599: $locknotfreed .= '</div>';
1.504 raeburn 4600: }
4601: return ($suffix,$errtext,$locknotfreed);
4602: }
4603:
1.329 droeschl 4604: =pod
4605:
4606: =item tiehash()
4607:
4608: tie the hash
4609:
4610: =cut
4611:
4612: sub tiehash {
4613: my ($mode)=@_;
4614: $hashtied=0;
4615: if ($env{'request.course.fn'}) {
4616: if ($mode eq 'write') {
4617: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4618: &GDBM_WRCREAT(),0640)) {
4619: $hashtied=2;
4620: }
4621: } else {
4622: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4623: &GDBM_READER(),0640)) {
4624: $hashtied=1;
4625: }
4626: }
1.364 bisitz 4627: }
1.329 droeschl 4628: }
4629:
4630: sub untiehash {
4631: if ($hashtied) { untie %hash; }
4632: $hashtied=0;
4633: return OK;
4634: }
4635:
4636:
4637:
4638:
4639: sub checkonthis {
1.637 raeburn 4640: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4641: $url=&unescape($url);
4642: $alreadyseen{$url}=1;
4643: $r->rflush();
4644: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4645: $r->print("\n<br />");
4646: if ($level==0) {
4647: $r->print("<br />");
4648: }
4649: for (my $i=0;$i<=$level*5;$i++) {
4650: $r->print(' ');
4651: }
4652: $r->print('<a href="'.$url.'" target="cat">'.
4653: ($title?$title:$url).'</a> ');
4654: if ($url=~/^\/res\//) {
1.637 raeburn 4655: my $updated;
4656: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4657: ($url !~ /\.\d+\.\w+$/)) {
4658: $updated = &Apache::lonnet::remove_stale_resfile($url);
4659: }
1.329 droeschl 4660: my $result=&Apache::lonnet::repcopy(
4661: &Apache::lonnet::filelocation('',$url));
4662: if ($result eq 'ok') {
4663: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4664: if ($updated) {
4665: $r->print('<br />');
4666: for (my $i=0;$i<=$level*5;$i++) {
4667: $r->print(' ');
4668: }
4669: $r->print('- '.&mt('Outdated copy removed'));
4670: }
1.329 droeschl 4671: $r->rflush();
4672: &Apache::lonnet::countacc($url);
4673: $url=~/\.(\w+)$/;
4674: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4675: $r->print('<br />');
4676: $r->rflush();
4677: for (my $i=0;$i<=$level*5;$i++) {
4678: $r->print(' ');
4679: }
4680: $r->print('- '.&mt('Rendering:').' ');
4681: my ($errorcount,$warningcount)=split(/:/,
4682: &Apache::lonnet::ssi_body($url,
4683: ('grade_target'=>'web',
4684: 'return_only_error_and_warning_counts' => 1)));
4685: if (($errorcount) ||
4686: ($warningcount)) {
4687: if ($errorcount) {
1.369 bisitz 4688: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4689: &mt('[quant,_1,error]',$errorcount).'</span>');
4690: }
4691: if ($warningcount) {
4692: $r->print('<span class="LC_warning">'.
4693: &mt('[quant,_1,warning]',$warningcount).'</span>');
4694: }
4695: } else {
4696: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4697: }
4698: $r->rflush();
4699: }
4700: my $dependencies=
4701: &Apache::lonnet::metadata($url,'dependencies');
4702: foreach my $dep (split(/\,/,$dependencies)) {
4703: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4704: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4705: }
4706: }
4707: } elsif ($result eq 'unavailable') {
4708: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4709: } elsif ($result eq 'not_found') {
4710: unless ($url=~/\$/) {
1.521 bisitz 4711: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4712: } else {
1.366 bisitz 4713: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4714: }
4715: } else {
4716: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4717: }
1.637 raeburn 4718: if (($updated) && ($result ne 'ok')) {
4719: $r->print('<br />'.&mt('Outdated copy removed'));
4720: }
1.329 droeschl 4721: }
4722: }
4723: }
4724:
4725:
4726:
4727: =pod
4728:
4729: =item list_symbs()
4730:
1.485 raeburn 4731: List Content Identifiers
1.329 droeschl 4732:
4733: =cut
4734:
4735: sub list_symbs {
4736: my ($r) = @_;
4737:
1.408 raeburn 4738: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4739: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4740: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4741: $r->print(&startContentScreen('tools'));
1.329 droeschl 4742: my $navmap = Apache::lonnavmaps::navmap->new();
4743: if (!defined($navmap)) {
4744: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4745: '<div class="LC_error">'.
4746: &mt('Unable to retrieve information about course contents').
4747: '</div>');
1.408 raeburn 4748: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4749: } else {
1.484 raeburn 4750: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4751: &Apache::loncommon::start_data_table().
4752: &Apache::loncommon::start_data_table_header_row().
4753: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4754: &Apache::loncommon::end_data_table_header_row()."\n");
4755: my $count;
1.329 droeschl 4756: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4757: $r->print(&Apache::loncommon::start_data_table_row().
4758: '<td>'.$res->compTitle().'</td>'.
4759: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4760: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4761: $count ++;
4762: }
4763: if (!$count) {
4764: $r->print(&Apache::loncommon::start_data_table_row().
4765: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4766: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4767: }
1.484 raeburn 4768: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4769: }
1.521 bisitz 4770: $r->print(&endContentScreen());
1.329 droeschl 4771: }
4772:
1.637 raeburn 4773: sub contentverifyform {
4774: my ($r) = @_;
4775: my $crstype = &Apache::loncommon::course_type();
4776: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4777: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4778: $r->print(&startContentScreen('tools'));
4779: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4780: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4781: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4782: ' <span class="LC_nobreak">'.
4783: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4784: &mt('No').'</label>'.(' 'x2).
4785: '<label><input type="radio" name="checkstale" value="1" />'.
4786: &mt('Yes').'</label></span></p><p>'.
4787: '<input type="submit" value="'.&mt('Verify content').' "/>'.
4788: '<input type="hidden" value="1" name="tools" />'.
4789: '<input type="hidden" value="1" name="verify" /></p></form>');
4790: $r->print(&endContentScreen());
4791: return;
4792: }
1.329 droeschl 4793:
4794: sub verifycontent {
1.637 raeburn 4795: my ($r,$checkstale) = @_;
1.408 raeburn 4796: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4797: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4798: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4799: $r->print(&startContentScreen('tools'));
4800: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4801: $hashtied=0;
4802: undef %alreadyseen;
4803: %alreadyseen=();
4804: &tiehash();
1.484 raeburn 4805:
1.329 droeschl 4806: foreach my $key (keys(%hash)) {
4807: if ($hash{$key}=~/\.(page|sequence)$/) {
4808: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4809: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4810: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4811: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4812: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4813: }
4814: }
4815: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 4816: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4817: }
4818: }
4819: &untiehash();
1.442 www 4820: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4821: $r->print(&endContentScreen());
1.329 droeschl 4822: }
4823:
4824: sub devalidateversioncache {
4825: my $src=shift;
4826: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4827: &Apache::lonnet::clutter($src));
4828: }
4829:
4830: sub checkversions {
1.611 raeburn 4831: my ($r,$canedit) = @_;
1.408 raeburn 4832: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4833: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4834: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4835: $r->print(&startContentScreen('tools'));
1.442 www 4836:
1.329 droeschl 4837: my $header='';
4838: my $startsel='';
4839: my $monthsel='';
4840: my $weeksel='';
4841: my $daysel='';
4842: my $allsel='';
4843: my %changes=();
4844: my $starttime=0;
4845: my $haschanged=0;
4846: my %setversions=&Apache::lonnet::dump('resourceversions',
4847: $env{'course.'.$env{'request.course.id'}.'.domain'},
4848: $env{'course.'.$env{'request.course.id'}.'.num'});
4849:
4850: $hashtied=0;
4851: &tiehash();
1.611 raeburn 4852: if ($canedit) {
4853: my %newsetversions=();
4854: if ($env{'form.setmostrecent'}) {
4855: $haschanged=1;
4856: foreach my $key (keys(%hash)) {
4857: if ($key=~/^ids\_(\/res\/.+)$/) {
4858: $newsetversions{$1}='mostrecent';
4859: &devalidateversioncache($1);
4860: }
4861: }
4862: } elsif ($env{'form.setcurrent'}) {
4863: $haschanged=1;
4864: foreach my $key (keys(%hash)) {
4865: if ($key=~/^ids\_(\/res\/.+)$/) {
4866: my $getvers=&Apache::lonnet::getversion($1);
4867: if ($getvers>0) {
4868: $newsetversions{$1}=$getvers;
4869: &devalidateversioncache($1);
4870: }
4871: }
1.329 droeschl 4872: }
1.611 raeburn 4873: } elsif ($env{'form.setversions'}) {
4874: $haschanged=1;
4875: foreach my $key (keys(%env)) {
4876: if ($key=~/^form\.set_version_(.+)$/) {
4877: my $src=$1;
4878: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4879: $newsetversions{$src}=$env{$key};
4880: &devalidateversioncache($src);
4881: }
4882: }
1.329 droeschl 4883: }
1.611 raeburn 4884: }
4885: if ($haschanged) {
4886: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4887: $env{'course.'.$env{'request.course.id'}.'.domain'},
4888: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4889: $r->print(&Apache::loncommon::confirmwrapper(
4890: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4891: } else {
4892: $r->print(&Apache::loncommon::confirmwrapper(
4893: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4894: }
1.611 raeburn 4895: &mark_hash_old();
4896: }
4897: &changewarning($r,'');
1.329 droeschl 4898: }
4899: if ($env{'form.timerange'} eq 'all') {
4900: # show all documents
1.549 raeburn 4901: $header=&mt('All content in '.$crstype);
1.521 bisitz 4902: $allsel=' selected="selected"';
1.329 droeschl 4903: foreach my $key (keys(%hash)) {
4904: if ($key=~/^ids\_(\/res\/.+)$/) {
4905: my $src=$1;
4906: $changes{$src}=1;
4907: }
4908: }
4909: } else {
4910: # show documents which changed
4911: %changes=&Apache::lonnet::dump
4912: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4913: $env{'course.'.$env{'request.course.id'}.'.num'});
4914: my $firstkey=(keys(%changes))[0];
4915: unless ($firstkey=~/^error\:/) {
4916: unless ($env{'form.timerange'}) {
4917: $env{'form.timerange'}=604800;
4918: }
4919: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4920: .&mt('seconds');
4921: if ($env{'form.timerange'}==-1) {
4922: $seltext='since start of course';
1.521 bisitz 4923: $startsel=' selected="selected"';
1.329 droeschl 4924: $env{'form.timerange'}=time;
4925: }
4926: $starttime=time-$env{'form.timerange'};
4927: if ($env{'form.timerange'}==2592000) {
4928: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4929: $monthsel=' selected="selected"';
1.329 droeschl 4930: } elsif ($env{'form.timerange'}==604800) {
4931: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4932: $weeksel=' selected="selected"';
1.329 droeschl 4933: } elsif ($env{'form.timerange'}==86400) {
4934: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4935: $daysel=' selected="selected"';
1.329 droeschl 4936: }
4937: $header=&mt('Content changed').' '.$seltext;
4938: } else {
4939: $header=&mt('No content modifications yet.');
4940: }
4941: }
4942: %setversions=&Apache::lonnet::dump('resourceversions',
4943: $env{'course.'.$env{'request.course.id'}.'.domain'},
4944: $env{'course.'.$env{'request.course.id'}.'.num'});
4945: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4946: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4947: 'lm' => 'Version changes since last Month',
4948: 'lw' => 'Version changes since last Week',
4949: 'sy' => 'Version changes since Yesterday',
4950: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4951: 'cd' => 'Change display',
1.329 droeschl 4952: 'sd' => 'Display',
4953: 'fi' => 'File',
4954: 'md' => 'Modification Date',
4955: 'mr' => 'Most recently published Version',
1.408 raeburn 4956: 've' => 'Version used in '.$crstype,
4957: 'vu' => 'Set Version to be used in '.$crstype,
4958: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4959: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4960: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4961: 'di' => 'Differences',
1.484 raeburn 4962: 'save' => 'Save changes',
4963: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4964: 'act' => 'Actions');
1.611 raeburn 4965: my ($disabled,$readonly);
4966: unless ($canedit) {
4967: $disabled = 'disabled="disabled"';
4968: $readonly = 1;
4969: }
1.329 droeschl 4970: $r->print(<<ENDHEADERS);
1.484 raeburn 4971: <h4 class="LC_info">$header</h4>
1.329 droeschl 4972: <form action="/adm/coursedocs" method="post">
4973: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4974: <div class="LC_left_float">
1.479 golterma 4975: <fieldset>
1.484 raeburn 4976: <legend>$lt{'cd'}</legend>
1.329 droeschl 4977: <select name="timerange">
1.521 bisitz 4978: <option value='all'$allsel>$lt{'al'}</option>
4979: <option value="-1"$startsel>$lt{'st'}</option>
4980: <option value="2592000"$monthsel>$lt{'lm'}</option>
4981: <option value="604800"$weeksel>$lt{'lw'}</option>
4982: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4983: </select>
4984: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4985: </fieldset>
4986: </div>
4987: <div class="LC_left_float">
4988: <fieldset>
4989: <legend>$lt{'act'}</legend>
1.611 raeburn 4990: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4991: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4992: </fieldset>
4993: </div>
4994: <br clear="all" />
4995: <hr />
4996: <h4>$lt{'vers'}</h4>
1.329 droeschl 4997: ENDHEADERS
1.479 golterma 4998: #number of columns for version history
1.571 raeburn 4999: my %changedbytime;
5000: foreach my $key (keys(%changes)) {
5001: #excludes not versionable problems from resource version history:
5002: next if ($key =~ /^\/res\/lib\/templates/);
5003: my $chg;
5004: if ($env{'form.timerange'} eq 'all') {
5005: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5006: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5007: } else {
5008: $chg = $changes{$key};
5009: next if ($chg < $starttime);
5010: }
5011: push(@{$changedbytime{$chg}},$key);
5012: }
5013: if (keys(%changedbytime) == 0) {
5014: &untiehash();
5015: $r->print(&mt('No content changes in imported content in specified time frame').
5016: &endContentScreen());
5017: return;
5018: }
1.479 golterma 5019: $r->print(
1.611 raeburn 5020: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5021: &Apache::loncommon::start_data_table().
5022: &Apache::loncommon::start_data_table_header_row().
5023: '<th>'.&mt('Resources').'</th>'.
5024: "<th>$lt{'mr'}</th>".
5025: "<th>$lt{'ve'}</th>".
5026: "<th>$lt{'vu'}</th>".
5027: '<th>'.&mt('History').'</th>'.
5028: &Apache::loncommon::end_data_table_header_row()
5029: );
1.571 raeburn 5030: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5031: foreach my $key (sort(@{$changedbytime{$chg}})) {
5032: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5033: my $currentversion=&Apache::lonnet::getversion($key);
5034: if ($currentversion<0) {
5035: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5036: }
5037: my $linkurl=&Apache::lonnet::clutter($key);
5038: $r->print(
5039: &Apache::loncommon::start_data_table_row().
5040: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5041: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5042: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5043: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5044: '<td align="right">'
5045: );
5046: # Used in course
5047: my $usedversion=$hash{'version_'.$linkurl};
5048: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5049: if ($usedversion != $currentversion) {
1.479 golterma 5050: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5051: } else {
1.479 golterma 5052: $r->print($usedversion);
5053: }
1.329 droeschl 5054: } else {
1.521 bisitz 5055: $r->print($currentversion);
1.329 droeschl 5056: }
1.571 raeburn 5057: $r->print('</td><td title="'.$lt{'vu'}.'">');
5058: # Set version
5059: $r->print(&Apache::loncommon::select_form(
5060: $setversions{$linkurl},
5061: 'set_version_'.$linkurl,
5062: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5063: '' => '',
5064: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5065: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5066: my $lastold=1;
5067: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5068: my $url=$root.'.'.$prevvers.'.'.$extension;
5069: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5070: $lastold=$prevvers;
5071: }
5072: }
5073: $r->print('</td>');
5074: # List all available versions
5075: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5076: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5077: my $url=$root.'.'.$prevvers.'.'.$extension;
5078: $r->print(
5079: '<span class="LC_nobreak">'
5080: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5081: .&mt('Version [_1]',$prevvers).'</a>'
5082: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5083: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5084: .')');
5085: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5086: $r->print(
5087: ' <a href="/adm/diff?filename='.
5088: &Apache::lonnet::clutter($root.'.'.$extension).
5089: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5090: '" target="diffs">'.&mt('Diffs').'</a>');
5091: }
5092: $r->print('</span><br />');
1.329 droeschl 5093: }
1.571 raeburn 5094: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5095: }
1.329 droeschl 5096: }
1.521 bisitz 5097: $r->print(
5098: &Apache::loncommon::end_data_table().
1.611 raeburn 5099: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5100: '</form>'
5101: );
1.329 droeschl 5102:
5103: &untiehash();
1.521 bisitz 5104: $r->print(&endContentScreen());
1.571 raeburn 5105: return;
1.329 droeschl 5106: }
5107:
5108: sub mark_hash_old {
5109: my $retie_hash=0;
5110: if ($hashtied) {
5111: $retie_hash=1;
5112: &untiehash();
5113: }
5114: &tiehash('write');
5115: $hash{'old'}=1;
5116: &untiehash();
5117: if ($retie_hash) { &tiehash(); }
5118: }
5119:
5120: sub is_hash_old {
5121: my $untie_hash=0;
5122: if (!$hashtied) {
5123: $untie_hash=1;
5124: &tiehash();
5125: }
5126: my $return=$hash{'old'};
5127: if ($untie_hash) { &untiehash(); }
5128: return $return;
5129: }
5130:
5131: sub changewarning {
5132: my ($r,$postexec,$message,$url)=@_;
5133: if (!&is_hash_old()) { return; }
5134: my $pathvar='folderpath';
5135: my $path=&escape($env{'form.folderpath'});
5136: if (!defined($url)) {
5137: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5138: }
5139: my $course_type = &Apache::loncommon::course_type();
5140: if (!defined($message)) {
5141: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5142: }
5143: $r->print("\n\n".
1.372 bisitz 5144: '<script type="text/javascript">'."\n".
5145: '// <![CDATA['."\n".
5146: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5147: '// ]]>'."\n".
1.369 bisitz 5148: '</script>'."\n".
1.375 tempelho 5149: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5150: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5151: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5152: &mt($message,' <input type="hidden" name="'.
5153: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5154: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5155: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5156: }
5157:
5158:
5159: sub init_breadcrumbs {
1.571 raeburn 5160: my ($form,$text,$help)=@_;
1.329 droeschl 5161: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5162: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5163: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5164: faq=>273,
5165: bug=>'Instructor Interface',
1.571 raeburn 5166: help => $help});
1.329 droeschl 5167: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5168: text=>$text,
5169: faq=>273,
5170: bug=>'Instructor Interface'});
5171: }
5172:
1.441 www 5173: # subroutine to list form elements
5174: sub create_list_elements {
5175: my @formarr = @_;
5176: my $list = '';
1.501 raeburn 5177: foreach my $button (@formarr){
5178: foreach my $picture (keys(%{$button})) {
5179: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5180: }
5181: }
5182: return $list;
5183: }
1.329 droeschl 5184:
1.441 www 5185: # subroutine to create ul from list elements
5186: sub create_form_ul {
5187: my $list = shift;
5188: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5189: return $ul;
5190: }
1.329 droeschl 5191:
1.442 www 5192: #
5193: # Start tabs
5194: #
5195:
5196: sub startContentScreen {
1.484 raeburn 5197: my ($mode) = @_;
5198: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5199: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5200: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5201: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5202: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5203: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5204: } else {
1.549 raeburn 5205: $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 5206: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5207: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5208: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5209: }
5210: $output .= "\n".'</ul>'."\n";
5211: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5212: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5213: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5214: return $output;
1.442 www 5215: }
5216:
5217: #
5218: # End tabs
5219: #
5220:
5221: sub endContentScreen {
1.484 raeburn 5222: return '</div></div></div>';
1.442 www 5223: }
1.329 droeschl 5224:
1.446 www 5225: sub supplemental_base {
1.548 raeburn 5226: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5227: }
5228:
1.329 droeschl 5229: sub handler {
5230: my $r = shift;
5231: &Apache::loncommon::content_type($r,'text/html');
5232: $r->send_http_header;
5233: return OK if $r->header_only;
1.484 raeburn 5234:
5235: # get course data
1.408 raeburn 5236: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5237: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5238: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5239:
1.606 raeburn 5240: # get docroot
5241: my $londocroot = $r->dir_config('lonDocRoot');
5242:
1.484 raeburn 5243: # graphics settings
5244: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5245:
1.443 www 5246: #
1.329 droeschl 5247: # --------------------------------------------- Initialize help topics for this
5248: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5249: 'Adding_External_Resource','Adding_External_Tool',
5250: 'Navigate_Content','Adding_Folders','Docs_Overview',
5251: 'Load_Map','Supplemental','Score_Upload_Form',
5252: 'Adding_Pages','Importing_LON-CAPA_Resource',
5253: 'Importing_IMS_Course','Uploading_From_Harddrive',
5254: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5255: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5256: }
5257: # Composite help files
5258: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5259: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5260: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5261: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5262: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5263: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5264: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5265: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5266: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5267: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5268:
1.611 raeburn 5269: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5270: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5271: unless ($r->uri eq '/adm/supplemental') {
5272: # does this user have privileges to modify content.
1.611 raeburn 5273: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5274: $allowed = 1;
5275: $canedit = 1;
5276: $canview = 1;
5277: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5278: $allowed = 1;
5279: $canview = 1;
5280: }
5281: }
5282: unless ($canedit) {
5283: $disabled = ' disabled="disabled"';
1.472 raeburn 5284: }
1.582 raeburn 5285: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5286: if ($env{'form.inhibitmenu'}) {
5287: unless ($env{'form.inhibitmenu'} eq 'yes') {
5288: delete($env{'form.inhibitmenu'});
5289: }
5290: }
5291:
1.582 raeburn 5292: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5293: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5294: if (!$canedit) {
5295: &verifycontent($r);
5296: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5297: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5298: text=>'Results',
5299: faq=>273,
5300: bug=>'Instructor Interface'});
5301: &verifycontent($r,$env{'form.checkstale'});
5302: } else {
5303: &contentverifyform($r);
5304: }
1.329 droeschl 5305: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5306: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5307: &list_symbs($r);
5308: } elsif ($allowed && $env{'form.docslog'}) {
5309: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5310: my $folder = $env{'form.folder'};
5311: if ($folder eq '') {
5312: $folder='default';
5313: }
1.611 raeburn 5314: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5315: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5316: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5317: &checkversions($r,$canedit);
5318: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5319: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5320: &dumpcourse($r);
1.611 raeburn 5321: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5322: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5323: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5324: } else {
1.611 raeburn 5325: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5326: $noendpage = 1;
5327: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5328: if ($redirect) {
5329: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5330: my $container = 'sequence';
5331: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5332: $is_random_order,$container) =
5333: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5334: my (@folders)=split('&',$env{'form.folderpath'});
5335: $env{'form.foldername'}=&unescape(pop(@folders));
5336: my $folder=pop(@folders);
5337: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5338: $folder.'.'.$container);
5339: my $warning;
5340: if ($fatal) {
5341: if ($container eq 'page') {
5342: $warning = &mt('An error occurred retrieving the contents of the current page.');
5343: } else {
5344: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5345: }
5346: } else {
5347: my $url = $redirect;
5348: my $srcfile = $londocroot.$url;
5349: $url =~ s{^/priv/}{/res/};
5350: my $targetfile = $londocroot.$url;
5351: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5352: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5353: $env{'form.folder'} = $folder;
5354: &snapshotbefore();
5355: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5356: my $ext = 'false';
5357: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5358: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5359: ':'.$ext.':normal:res';
5360: push(@LONCAPA::map::order,$newidx);
5361: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5362: 'string_yesno');
5363: &remember_parms($newidx,'hiddenresource','set','yes');
5364: ($errtext,$fatal) =
5365: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5366: &log_differences($plain);
5367: &mark_hash_old();
5368: $r->internal_redirect($redirect);
5369: return OK;
5370: }
5371: }
5372: }
5373: }
1.445 www 5374: #
5375: # Done catching special calls
1.484 raeburn 5376: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5377: # Get the parameters that may be needed
5378: #
5379: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5380: ['folderpath',
5381: 'forcesupplement','forcestandard',
1.510 raeburn 5382: 'tools','symb','command','supppath']);
1.445 www 5383:
1.635 raeburn 5384: foreach my $item ('forcesupplement','forcestandard','tools') {
5385: next if ($env{'form.'.$item} eq '');
5386: unless ($env{'form.'.$item} eq '1') {
5387: delete($env{'form.'.$item});
5388: }
5389: }
5390:
5391: if ($env{'form.command'}) {
5392: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5393: delete($env{'form.command'});
5394: }
5395: }
5396:
5397: if ($env{'form.symb'}) {
5398: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5399: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5400: delete($env{'form.symb'});
5401: }
5402: }
5403:
1.445 www 5404: # standard=1: this is a "new-style" course with an uploaded map as top level
5405: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5406:
5407: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5408:
1.484 raeburn 5409: # Decide whether this should display supplemental or main content or utilities
1.445 www 5410: # supplementalflag=1: show supplemental documents
5411: # supplementalflag=0: show standard documents
1.484 raeburn 5412: # toolsflag=1: show utilities
1.445 www 5413:
1.561 raeburn 5414: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5415: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5416: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5417: $supplementalflag=0;
5418: }
5419: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5420: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5421: unless ($allowed) { $supplementalflag=1; }
5422: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5423: my $toolsflag=0;
5424: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5425:
1.635 raeburn 5426: if ($env{'form.folderpath'} ne '') {
5427: my @items = split(/\&/,$env{'form.folderpath'});
5428: my $badpath;
5429: for (my $i=0; $i<@items; $i++) {
5430: my $odd = $i%2;
5431: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5432: $badpath = 1;
5433: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5434: $badpath = 1;
5435: }
5436: last if ($badpath);
5437: }
5438: if ($badpath) {
5439: delete($env{'form.folderpath'});
5440: }
5441: }
5442:
5443: if ($env{'form.supppath'} ne '') {
5444: my @items = split(/\&/,$env{'form.supppath'});
5445: my $badpath;
5446: for (my $i=0; $i<@items; $i++) {
5447: my $odd = $i%2;
5448: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5449: $badpath = 1;
5450: }
5451: last if ($badpath);
5452: }
5453: if ($badpath) {
5454: delete($env{'form.supppath'});
5455: }
5456: }
5457:
1.329 droeschl 5458: my $script='';
5459: my $showdoc=0;
1.457 raeburn 5460: my $addentries = {};
1.475 raeburn 5461: my $container;
1.329 droeschl 5462: my $containertag;
1.508 raeburn 5463: my $pathitem;
1.598 raeburn 5464: my %ltitools;
1.617 raeburn 5465: my $hiddentop;
1.615 raeburn 5466: my $navmap;
1.617 raeburn 5467: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5468:
1.464 www 5469: # Do we directly jump somewhere?
1.525 raeburn 5470: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5471: if ($env{'form.symb'} ne '') {
1.522 raeburn 5472: $env{'form.folderpath'}=
1.617 raeburn 5473: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5474: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5475: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5476: } elsif ($env{'form.supppath'} ne '') {
5477: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5478: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5479: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5480: }
1.472 raeburn 5481: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5482: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5483: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5484: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5485: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5486: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5487: } elsif ($env{'form.command'} eq 'contents') {
5488: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5489: } elsif ($env{'form.command'} eq 'home') {
5490: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5491: }
5492:
1.525 raeburn 5493:
1.445 www 5494: # Where do we store these for when we come back?
5495: my $stored_folderpath='docs_folderpath';
5496: if ($supplementalflag) {
5497: $stored_folderpath='docs_sup_folderpath';
5498: }
1.464 www 5499:
1.519 raeburn 5500: # No folderpath, and in edit mode, see if we have something stored
5501: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5502: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5503: {'folderpath' => 'scalar'});
1.615 raeburn 5504:
5505: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5506: if ($supplementalflag) {
5507: undef($env{'form.folderpath'}) if ($1 eq 'default');
5508: } else {
5509: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5510: }
5511: } else {
1.523 raeburn 5512: undef($env{'form.folderpath'});
5513: }
1.329 droeschl 5514: }
1.446 www 5515:
5516: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5517: if (!$allowed) {
1.446 www 5518: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5519: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5520: }
5521: }
1.446 www 5522: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5523: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5524: $env{'form.folderpath'} = &supplemental_base()
5525: .'&'.
1.329 droeschl 5526: $env{'form.folderpath'};
5527: }
1.615 raeburn 5528: # If allowed and user's role is not advanced check folderpath is not hidden
5529: if (($allowed) && (!$env{'request.role.adv'}) &&
5530: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5531: my $folderurl;
5532: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5533: my $folder = $pathitems[-2];
5534: if ($folder eq '') {
5535: undef($env{'form.folderpath'});
5536: } else {
5537: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5538: if ((split(/\:/,$pathitems[-1]))[4]) {
5539: $folderurl .= '.page';
5540: } else {
5541: $folderurl .= '.sequence';
5542: }
1.617 raeburn 5543: unless (ref($navmap)) {
5544: $navmap = Apache::lonnavmaps::navmap->new();
5545: }
1.615 raeburn 5546: if (ref($navmap)) {
5547: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5548: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5549: unless (@resources) {
5550: undef($env{'form.folderpath'});
5551: }
1.615 raeburn 5552: }
5553: }
5554: }
5555: }
5556:
5557:
1.446 www 5558: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5559: unless ($env{'form.folderpath'}) {
1.446 www 5560: if ($supplementalflag) {
5561: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5562: } elsif ($allowed) {
5563: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5564: }
1.472 raeburn 5565: }
1.446 www 5566:
1.445 www 5567: # Store this
1.484 raeburn 5568: unless ($toolsflag) {
1.615 raeburn 5569: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5570: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5571: {'folderpath' => 'scalar'});
1.510 raeburn 5572: }
1.519 raeburn 5573: my $folderpath;
1.484 raeburn 5574: if ($env{'form.folderpath'}) {
1.519 raeburn 5575: $folderpath = $env{'form.folderpath'};
5576: my (@folders)=split('&',$env{'form.folderpath'});
5577: $env{'form.foldername'}=&unescape(pop(@folders));
5578: if ($env{'form.foldername'} =~ /\:1$/) {
5579: $container = 'page';
5580: } else {
5581: $container = 'sequence';
5582: }
5583: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5584: } else {
1.519 raeburn 5585: if ($env{'form.folder'} eq '' ||
5586: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5587: if ($env{'form.folder'} eq 'supplemental') {
5588: $folderpath=&supplemental_base();
5589: } elsif (!$hiddentop) {
5590: $folderpath='default&'.
5591: &escape(&mt('Main Content').':::::');
5592: }
1.484 raeburn 5593: }
5594: }
1.519 raeburn 5595: $containertag = '<input type="hidden" name="folderpath" value="" />';
5596: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5597: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5598: $showdoc='/'.$1;
5599: }
5600: if ($showdoc) { # got called in sequence from course
5601: $allowed=0;
5602: } else {
1.611 raeburn 5603: if ($canedit) {
1.484 raeburn 5604: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5605: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5606: }
5607: }
1.329 droeschl 5608: }
5609:
1.344 bisitz 5610: # get personal data
1.329 droeschl 5611: my $uname=$env{'user.name'};
5612: my $udom=$env{'user.domain'};
5613: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5614:
5615: if ($allowed) {
1.484 raeburn 5616: if ($toolsflag) {
5617: $script .= &inject_data_js();
5618: my ($home,$other,%outhash)=&authorhosts();
5619: if (!$home && $other) {
5620: my @hosts;
5621: foreach my $aurole (keys(%outhash)) {
5622: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5623: push(@hosts,$outhash{$aurole});
5624: }
5625: }
5626: $script .= &dump_switchserver_js(@hosts);
5627: }
1.458 raeburn 5628: } else {
1.570 raeburn 5629: my $tid = 1;
1.484 raeburn 5630: my @tabids;
5631: if ($supplementalflag) {
5632: @tabids = ('002','ee2','ff2');
1.570 raeburn 5633: $tid = 2;
1.484 raeburn 5634: } else {
5635: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5636: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5637: unshift(@tabids,'001');
5638: push(@tabids,('dd1','ee1'));
5639: }
1.458 raeburn 5640: }
1.484 raeburn 5641: my $tabidstr = join("','",@tabids);
1.644 raeburn 5642: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600 raeburn 5643: my $posslti = keys(%ltitools);
1.622 raeburn 5644: my $hostname = $r->hostname();
1.606 raeburn 5645: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5646: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5647: &history_tab_js().
5648: &inject_data_js().
1.570 raeburn 5649: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5650: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5651: $addentries = {
1.485 raeburn 5652: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5653: };
1.458 raeburn 5654: }
1.538 raeburn 5655: $script .= &paste_popup_js();
1.501 raeburn 5656: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5657: &mt('Switch server?');
5658:
5659:
1.329 droeschl 5660: }
5661: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5662: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5663: .'// <![CDATA['."\n"
5664: .$script."\n"
5665: .'// ]]>'."\n"
1.595 musolffc 5666: .'</script>'."\n"
5667: .'<script type="text/javascript"
5668: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5669:
5670: # Breadcrumbs
5671: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5672:
5673: if ($showdoc) {
5674: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5675: {'force_register' => $showdoc,}));
1.571 raeburn 5676: } elsif ($toolsflag) {
1.611 raeburn 5677: my ($breadtext,$breadtitle);
1.617 raeburn 5678: $breadtext = "$crstype Editor";
1.611 raeburn 5679: if ($canedit) {
5680: $breadtitle = 'Editing '.$crstype.' Contents';
5681: } else {
5682: $breadtext .= ' (View-only mode)';
5683: $breadtitle = 'Viewing '.$crstype.' Contents';
5684: }
1.571 raeburn 5685: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5686: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5687: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5688: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5689: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5690: $breadtitle)
1.571 raeburn 5691: );
1.510 raeburn 5692: } elsif ($r->uri eq '/adm/supplemental') {
5693: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5694: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5695: {'bread_crumbs' => $brcrum,}));
5696: } else {
1.611 raeburn 5697: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5698: $breadtext = "$crstype Editor";
1.611 raeburn 5699: if ($canedit) {
5700: $breadtitle = 'Editing '.$crstype.' Contents';
5701: $helpitem = 'Docs_Adding_Course_Doc';
5702: } else {
5703: $breadtext .= ' (View-only mode)';
5704: $breadtitle = 'Viewing '.$crstype.' Contents';
5705: $helpitem = 'Docs_Viewing_Course_Doc';
5706: }
1.392 raeburn 5707: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5708: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5709: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5710: {'add_entries' => $addentries}
5711: )
1.392 raeburn 5712: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5713: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5714: $breadtitle,
5715: $helpitem)
1.392 raeburn 5716: );
5717: }
1.364 bisitz 5718:
1.329 droeschl 5719: my %allfiles = ();
5720: my %codebase = ();
1.440 raeburn 5721: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5722: if ($canedit) {
1.329 droeschl 5723: if (($env{'form.uploaddoc.filename'}) &&
5724: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5725: my $context = $1;
5726: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5727: undef($hadchanges);
1.440 raeburn 5728: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5729: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 5730: undef($navmap);
1.329 droeschl 5731: if ($hadchanges) {
5732: &mark_hash_old();
5733: }
1.440 raeburn 5734: $r->print($upload_output);
5735: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5736: # Process file upload - phase two - upload embedded objects
5737: $uploadphase = 'check_embedded';
5738: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5739: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5740: $env{'form.newidx'});
5741: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5742: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5743: my ($destination,$dir_root) = &embedded_destination();
5744: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5745: my $actionurl = '/adm/coursedocs';
1.630 raeburn 5746: my ($result,$flag) =
1.440 raeburn 5747: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5748: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5749: $actionurl);
5750: $r->print($result.&return_to_editor());
5751: } elsif ($env{'form.phase'} eq 'check_embedded') {
5752: # Process file upload - phase three - modify references in HTML file
5753: $uploadphase = 'modified_orightml';
5754: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5755: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5756: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 5757: my $result =
1.482 raeburn 5758: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5759: $docuname,$docudom,undef,
5760: $dir_root);
1.630 raeburn 5761: $r->print($result.&return_to_editor());
1.476 raeburn 5762: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5763: $uploadphase = 'decompress_phase_one';
5764: $r->print(&decompression_phase_one().
5765: &return_to_editor());
5766: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5767: $uploadphase = 'decompress_phase_two';
5768: $r->print(&decompression_phase_two().
5769: &return_to_editor());
1.329 droeschl 5770: }
5771: }
5772:
1.484 raeburn 5773: if ($allowed && $toolsflag) {
5774: $r->print(&startContentScreen('tools'));
1.611 raeburn 5775: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5776: $r->print(&endContentScreen());
5777: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5778: # -----------------------------------------------------------------------------
5779: my %lt=&Apache::lonlocal::texthash(
5780: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5781: 'upfi' => 'Upload File',
1.553 raeburn 5782: 'upld' => 'Upload Content',
1.329 droeschl 5783: 'srch' => 'Search',
5784: 'impo' => 'Import',
1.487 raeburn 5785: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5786: 'impm' => 'Import from Assembled Map',
1.630 raeburn 5787: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5788: 'extr' => 'External Resource',
5789: 'extt' => 'External Tool',
1.329 droeschl 5790: 'selm' => 'Select Map',
5791: 'load' => 'Load Map',
5792: 'newf' => 'New Folder',
5793: 'newp' => 'New Composite Page',
5794: 'syll' => 'Syllabus',
1.425 raeburn 5795: 'navc' => 'Table of Contents',
1.343 biermanm 5796: 'sipa' => 'Simple Course Page',
1.329 droeschl 5797: 'sipr' => 'Simple Problem',
1.630 raeburn 5798: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5799: 'stpr' => 'Standard Problem',
5800: 'news' => 'New sub-directory',
5801: 'crpr' => 'Create Problem',
1.329 droeschl 5802: 'drbx' => 'Drop Box',
1.451 www 5803: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5804: 'bull' => 'Discussion Board',
1.347 weissno 5805: 'mypi' => 'My Personal Information Page',
1.353 weissno 5806: 'grpo' => 'Group Portfolio',
1.329 droeschl 5807: 'rost' => 'Course Roster',
1.528 raeburn 5808: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5809: 'imsf' => 'IMS Upload',
5810: 'imsl' => 'Upload IMS package',
1.501 raeburn 5811: 'cms' => 'Origin of IMS package',
5812: 'se' => 'Select',
1.329 droeschl 5813: 'file' => 'File',
5814: 'title' => 'Title',
1.606 raeburn 5815: 'addp' => 'Add Placeholder to course?',
5816: 'uste' => 'Use Template?',
5817: 'fnam' => 'File Name:',
5818: 'loca' => 'Location:',
5819: 'dire' => 'Directory:',
5820: 'cate' => 'Category:',
5821: 'tmpl' => 'Template:',
1.329 droeschl 5822: 'comment' => 'Comment',
1.403 raeburn 5823: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5824: 'bb5' => 'Blackboard 5',
5825: 'bb6' => 'Blackboard 6',
5826: 'angel5' => 'ANGEL 5.5',
5827: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5828: 'yes' => 'Yes',
5829: 'no' => 'No',
1.618 raeburn 5830: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5831: );
1.329 droeschl 5832: # -----------------------------------------------------------------------------
1.595 musolffc 5833:
5834: # Calculate free quota space for a user or course. A javascript function checks
5835: # file size to determine if upload should be allowed.
5836: my $quotatype = 'unofficial';
5837: if ($crstype eq 'Community') {
1.601 raeburn 5838: $quotatype = 'community';
5839: } elsif ($crstype eq 'Placement') {
5840: $quotatype = 'placement';
1.595 musolffc 5841: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5842: $quotatype = 'official';
5843: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5844: $quotatype = 'textbook';
5845: }
5846: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5847: 'course',$quotatype); # expressed in MB
5848: my $current_disk_usage = 0;
5849: foreach my $subdir ('docs','supplemental') {
5850: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5851: "userfiles/$subdir",1); # expressed in kB
5852: }
5853: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5854: my $usage = $current_disk_usage/1024; # in MB
5855: my $quota = $disk_quota;
5856: my $percent;
5857: if ($disk_quota == 0) {
5858: $percent = 100.0;
5859: } else {
1.619 raeburn 5860: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5861: }
5862: $usage = sprintf("%.2f",$usage);
5863: $quota = sprintf("%.2f",$quota);
5864: $percent = sprintf("%.0f",$percent);
5865: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5866: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5867:
1.329 droeschl 5868: my $fileupload=(<<FIUP);
1.605 raeburn 5869: $quotainfo
1.329 droeschl 5870: $lt{'file'}:<br />
1.611 raeburn 5871: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5872: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5873: FIUP
5874:
5875: my $checkbox=(<<CHBO);
5876: <!-- <label>$lt{'parse'}?
5877: <input type="checkbox" name="parserflag" />
5878: </label> -->
5879: <label>
1.611 raeburn 5880: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5881: </label>
5882: CHBO
1.501 raeburn 5883: my $imsfolder = $env{'form.folder'};
5884: if ($imsfolder eq '') {
5885: $imsfolder = 'default';
5886: }
5887: my $imspform=(<<IMSFORM);
5888: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5889: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5890: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5891: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5892: <legend>$lt{'imsf'}</legend>
5893: $fileupload
5894: <br />
5895: <p>
5896: $lt{'cms'}:
1.611 raeburn 5897: <select name="source" $disabled>
1.501 raeburn 5898: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5899: <option value="bb5">$lt{'bb5'}</option>
5900: <option value="bb6">$lt{'bb6'}</option>
5901: <option value="angel5">$lt{'angel5'}</option>
5902: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5903: </select>
5904: <input type="hidden" name="folder" value="$imsfolder" />
5905: </p>
5906: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5907: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5908: </fieldset>
5909: </form>
5910: IMSFORM
1.329 droeschl 5911:
5912: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5913: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5914: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5915: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5916: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5917: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5918: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5919: $fileupload
1.329 droeschl 5920: <br />
5921: $lt{'title'}:<br />
1.611 raeburn 5922: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5923: $pathitem
1.329 droeschl 5924: <input type="hidden" name="cmd" value="upload_default" />
5925: <br />
1.458 raeburn 5926: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5927: $checkbox
5928: </span>
1.501 raeburn 5929: <br clear="all" />
1.611 raeburn 5930: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5931: </fieldset>
5932: </form>
1.383 tempelho 5933: FUFORM
1.329 droeschl 5934:
1.611 raeburn 5935: my $mapimportjs;
5936: if ($canedit) {
5937: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5938: } else {
5939: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5940: }
1.502 raeburn 5941: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5942: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5943: $lt{'impm'}</a>$help{'Load_Map'}
5944: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5945: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5946: <legend>$lt{'impm'}</legend>
1.371 tempelho 5947: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5948: $lt{'copm'}<br />
5949: <span class="LC_nobreak">
5950: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5951: onfocus="this.blur();$mapimportjs" $disabled />
5952: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5953: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5954: </fieldset>
5955: </form>
5956:
1.383 tempelho 5957: SEDFFORM
1.606 raeburn 5958: my $importcrsresform;
1.608 raeburn 5959: my ($numdirs,$pickfile) =
5960: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5961: "resize_scrollbox('contentscroll','1','0');",
5962: undef,'res');
1.606 raeburn 5963: if ($pickfile) {
5964: $importcrsresform=(<<CRSFORM);
5965: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5966: $lt{'imcr'}</a>$help{'Course_Resources'}
5967: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5968: <fieldset id="importcrsresform" style="display: none;">
5969: <legend>$lt{'imcr'}</legend>
5970: <input type="hidden" name="active" value="bb" />
5971: $pickfile
5972: <p>
1.611 raeburn 5973: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5974: </p>
5975: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5976: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5977: </fieldset>
5978: </form>
5979: CRSFORM
5980: }
5981:
1.611 raeburn 5982: my $fromstoredjs;
5983: if ($canedit) {
5984: $fromstoredjs = 'open_StoredLinks_Import()';
5985: } else {
5986: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5987: }
5988:
1.502 raeburn 5989: my @importpubforma = (
1.508 raeburn 5990: { '<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 5991: { '<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 5992: { '<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 5993: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5994: );
5995: if ($pickfile) {
5996: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5997: }
1.502 raeburn 5998: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5999: my $extresourcesform =
6000: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6001: $help{'Adding_External_Resource'},
6002: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6003: my $exttoolform =
6004: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6005: $help{'Adding_External_Tool'},undef,
6006: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6007: \%ltitools,$disabled);
1.329 droeschl 6008: if ($allowed) {
1.492 raeburn 6009: my $folder = $env{'form.folder'};
6010: if ($folder eq '') {
6011: $folder='default';
6012: }
1.615 raeburn 6013: if ($canedit) {
6014: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6015: if ($output) {
6016: $r->print($output);
6017: }
1.538 raeburn 6018: }
1.337 ehlerst 6019: $r->print(<<HIDDENFORM);
6020: <form name="renameform" method="post" action="/adm/coursedocs">
6021: <input type="hidden" name="title" />
6022: <input type="hidden" name="cmd" />
6023: <input type="hidden" name="markcopy" />
6024: <input type="hidden" name="copyfolder" />
6025: $containertag
6026: </form>
1.633 raeburn 6027: <form name="aliasform" method="post" action="/adm/coursedocs">
6028: <input type="hidden" name="alias" />
6029: <input type="hidden" name="cmd" />
6030: $containertag
6031: </form>
1.484 raeburn 6032:
1.337 ehlerst 6033: HIDDENFORM
1.508 raeburn 6034: $r->print(&makesimpleeditform($pathitem)."\n".
6035: &makedocslogform($pathitem."\n".
1.484 raeburn 6036: '<input type="hidden" name="folder" value="'.
6037: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6038: }
1.442 www 6039:
6040: # Generate the tabs
1.510 raeburn 6041: my ($mode,$needs_end);
1.472 raeburn 6042: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6043: my @folders = split('&',$env{'form.folderpath'});
6044: unless (@folders > 2) {
6045: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6046: $needs_end = 1;
6047: }
1.472 raeburn 6048: } else {
1.484 raeburn 6049: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6050: $needs_end = 1;
1.472 raeburn 6051: }
1.443 www 6052:
1.442 www 6053: #
1.622 raeburn 6054: my $hostname = $r->hostname();
1.442 www 6055: my $savefolderpath;
6056:
1.395 raeburn 6057: if ($allowed) {
1.329 droeschl 6058: my $folder=$env{'form.folder'};
1.615 raeburn 6059: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6060: $folder='default';
1.356 tempelho 6061: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6062: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6063: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6064: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6065: }
6066: my $postexec='';
6067: if ($folder eq 'default') {
1.372 bisitz 6068: $r->print('<script type="text/javascript">'."\n"
6069: .'// <![CDATA['."\n"
6070: .'this.window.name="loncapaclient";'."\n"
6071: .'// ]]>'."\n"
6072: .'</script>'."\n"
1.369 bisitz 6073: );
1.329 droeschl 6074: } else {
6075: #$postexec='self.close();';
6076: }
1.504 raeburn 6077: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6078: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6079: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6080:
6081: my $newnavform=(<<NNFORM);
6082: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 6083: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6084: $pathitem
1.329 droeschl 6085: <input type="hidden" name="importdetail"
6086: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6087: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6088: $help{'Navigate_Content'}
6089: </form>
6090: NNFORM
6091: my $newsmppageform=(<<NSPFORM);
6092: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 6093: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6094: $pathitem
1.329 droeschl 6095: <input type="hidden" name="importdetail" value="" />
1.423 onken 6096: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6097: $help{'Simple Page'}
1.329 droeschl 6098: </form>
6099: NSPFORM
6100:
6101: my $newsmpproblemform=(<<NSPROBFORM);
6102: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6103: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6104: $pathitem
1.329 droeschl 6105: <input type="hidden" name="importdetail" value="" />
1.423 onken 6106: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6107: $help{'Simple_Problem'}
1.329 droeschl 6108: </form>
6109:
6110: NSPROBFORM
6111:
6112: my $newdropboxform=(<<NDBFORM);
6113: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6114: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6115: $pathitem
1.329 droeschl 6116: <input type="hidden" name="importdetail" value="" />
1.423 onken 6117: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6118: $help{'Dropbox'}
1.344 bisitz 6119: </form>
1.329 droeschl 6120: NDBFORM
6121:
6122: my $newexuploadform=(<<NEXUFORM);
6123: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6124: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6125: $pathitem
1.329 droeschl 6126: <input type="hidden" name="importdetail" value="" />
1.423 onken 6127: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6128: $help{'Score_Upload_Form'}
6129: </form>
6130: NEXUFORM
6131:
6132: my $newbulform=(<<NBFORM);
6133: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 6134: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6135: $pathitem
1.329 droeschl 6136: <input type="hidden" name="importdetail" value="" />
1.423 onken 6137: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6138: $help{'Bulletin Board'}
6139: </form>
6140: NBFORM
6141:
6142: my $newaboutmeform=(<<NAMFORM);
6143: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 6144: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6145: $pathitem
1.329 droeschl 6146: <input type="hidden" name="importdetail"
6147: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6148: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6149: $help{'My Personal Information Page'}
1.329 droeschl 6150: </form>
6151: NAMFORM
6152:
6153: my $newaboutsomeoneform=(<<NASOFORM);
6154: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 6155: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6156: $pathitem
1.329 droeschl 6157: <input type="hidden" name="importdetail" value="" />
1.423 onken 6158: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6159: </form>
6160: NASOFORM
6161:
6162: my $newrosterform=(<<NROSTFORM);
6163: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 6164: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6165: $pathitem
1.329 droeschl 6166: <input type="hidden" name="importdetail"
6167: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6168: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6169: $help{'Course_Roster'}
1.329 droeschl 6170: </form>
6171: NROSTFORM
6172:
1.534 raeburn 6173: my $newwebpage;
6174: if ($folder =~ /^default_?(\d*)$/) {
6175: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6176: if ($1) {
6177: $newwebpage .= $1;
6178: } else {
6179: $newwebpage .= 'default';
6180: }
6181: $newwebpage .= '/new.html';
6182: }
6183: my $newwebpageform =(<<NWEBFORM);
6184: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 6185: <input type="hidden" name="active" value="ee" />
1.534 raeburn 6186: $pathitem
6187: <input type="hidden" name="importdetail" value="$newwebpage" />
6188: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6189: $help{'Web_Page'}
1.534 raeburn 6190: </form>
6191: NWEBFORM
1.604 raeburn 6192:
1.606 raeburn 6193: my @ids=&Apache::lonnet::current_machine_ids();
6194: my %select_menus;
6195: my $numauthor = 0;
6196: my $numcrsdirs = 0;
6197: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6198: if ($env{'user.author'}) {
6199: $numauthor ++;
6200: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6201: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6202: my $is_home = 1;
6203: my %subdirs;
1.608 raeburn 6204: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6205: $select_menus{'author'}->{'default'} = '/';
6206: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6207: my @ordered = ('/');
6208: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6209: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6210: push(@ordered,$relpath);
6211: }
6212: $select_menus{'author'}->{'order'} = \@ordered;
6213: } else {
6214: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6215: $select_menus{'author'}->{'default'} = 'switch';
6216: $select_menus{'author'}->{'order'} = ['switch'];
6217: }
6218: }
6219: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6220: ['active'],['ca','aa']);
6221: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6222: my %by_roletype;
6223: if (keys(%roleshash)) {
6224: foreach my $entry (keys(%roleshash)) {
6225: my ($auname,$audom,$roletype) = split(/:/,$entry);
6226: my $key = $entry;
6227: $key =~ s/:/___/g;
6228: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6229: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6230: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6231: if (grep(/^\Q$rolehome\E$/,@ids)) {
6232: my $is_home = 1;
6233: my (%subdirs,@ordered);
6234: my $toppath="/priv/$audom/$auname";
1.608 raeburn 6235: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6236: $select_menus{$key}->{'default'} = '/';
6237: $select_menus{$key}->{'select2'}->{'/'} = '/';
6238: my @ordered = ('/');
6239: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6240: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6241: push(@ordered,$relpath);
6242: }
6243: $select_menus{$key}->{'order'} = \@ordered;
6244: } else {
6245: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6246: $select_menus{$key}->{'default'} = 'switch';
6247: $select_menus{$key}->{'order'} = ['switch'];
6248: }
6249: $numauthor ++;
6250: }
6251: }
1.631 raeburn 6252: my ($pickdir,$showtitle);
1.606 raeburn 6253: if ($numauthor) {
6254: my @order;
6255: my $defrole;
6256: if ($env{'user.author'}) {
6257: push(@order,'author');
6258: $defrole = 'author';
6259: }
6260: if (keys(%by_roletype)) {
6261: foreach my $possrole ('ca','aa') {
6262: if (ref($by_roletype{$possrole}) eq 'HASH') {
6263: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6264: unless ($defrole) {
6265: $defrole = $author;
6266: }
6267: push(@order,$author.'___'.$possrole);
6268: }
6269: }
6270: }
6271: }
6272: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6273: if (grep(/^\Q$crshome\E$/,@ids)) {
6274: my $is_home = 1;
6275: my %subdirs;
6276: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6277: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6278: $numcrsdirs = keys(%subdirs);
6279: $select_menus{'course'}->{'default'} = '/';
6280: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6281: my @ordered = ('/');
6282: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6283: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6284: push(@ordered,$relpath);
6285: }
6286: $select_menus{'course'}->{'order'} = \@ordered;
6287: } else {
6288: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6289: $select_menus{'course'}->{'default'} = 'switch';
6290: $select_menus{'course'}->{'order'} = ['switch'];
6291: }
6292: push(@order,'course');
6293: $pickdir = $lt{'loca'}.
6294: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6295: $defrole,'authorrole','authorpath',
6296: \%select_menus,\@order,'toggleCrsResTitle();',
6297: '','priv').'<br />';
6298: $showtitle = 'none';
6299: } else {
6300: my $is_home;
6301: $showtitle = 'inline';
6302: if (grep(/^\Q$crshome\E$/,@ids)) {
6303: $is_home = 1;
6304: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6305: my $toppath="/priv/$coursedom/$coursenum'}";
6306: my %subdirs;
1.608 raeburn 6307: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6308: $numcrsdirs = keys(%subdirs);
6309: if ($numcrsdirs) {
6310: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6311: '<option value="/">/</option>'."\n";
6312: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6313: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6314: }
6315: $pickdir .= '</select>';
6316: } else {
6317: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6318: }
6319: }
6320: }
6321:
6322: my %seltemplate_menus;
6323: my @files = &Apache::lonhomework::get_template_list('problem');
6324: my @noexamplelink = ('blank.problem','blank.library','script.library');
6325: my $currentcategory = '';
6326: my @ordered = ('');
6327: my %templatehelp;
6328: my $defcategory = '';
6329: my @catorder = ($defcategory);
6330: $seltemplate_menus{$defcategory}->{'order'} = [''];
6331: $seltemplate_menus{$defcategory}->{'text'} = '';
6332: foreach my $file (@files) {
6333: if (ref($file) eq 'ARRAY') {
6334: my ($path,$title,$category,$help) = @{$file};
6335: next if ($title !~ /\S/);
6336: if (&js_escape($category) ne $currentcategory) {
6337: $currentcategory = &js_escape($category);
6338: push(@catorder,&js_escape($currentcategory));
6339: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6340: $seltemplate_menus{$currentcategory}->{'default'} = '';
6341: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6342: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6343: }
6344: if ($path) {
6345: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6346: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6347: if ($help) {
6348: $templatehelp{$path} = $help;
6349: }
6350: }
6351: }
6352: }
6353:
6354: my $templates = $lt{'cate'}.' '.
6355: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6356: $defcategory,'tempcategory','template',
6357: \%seltemplate_menus,\@catorder,
6358: "resize_scrollbox('contentscroll','1','0');",
6359: "toggleExampleText();",'template').'<br />';
6360: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6361: '<span id="newresexample">'.&mt('Example').'<span></a>';
6362: my $crsresform=(<<RESFORM);
6363: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6364: $lt{'stpr'}</a>$help{'Course_Resource'}
6365: <form action="/adm/coursedocs" method="post" name="courseresform">
6366: <fieldset id="crsresform" style="display:none;">
6367: <legend>$lt{'stpr'}</legend>
6368: <input type="hidden" name="active" value="ee" />
6369: <p>
6370: $pickdir
6371: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6372: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6373:
1.611 raeburn 6374: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6375: </span><span id="newsubdir"></span>
6376: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6377: </p>
6378: $lt{'fnam'}
1.611 raeburn 6379: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6380: <p>
6381: <div id="newresource" style="display:$showtitle">
6382: $lt{'addp'}
1.611 raeburn 6383: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6384: $lt{'no'}</label>
1.611 raeburn 6385: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6386: $lt{'yes'}</label>
6387: <span id="newrestitle"></span>
1.611 raeburn 6388: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6389: </div>
6390: </p>
6391: <p>
6392: $lt{'uste'}
1.611 raeburn 6393: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6394: $lt{'no'}</label>
1.611 raeburn 6395: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6396: $lt{'yes'}</label>
6397: <div id="newrestemplate" style="display:none">
6398: $templates
6399: $templatepreview
6400: </div>
6401: </p>
6402: <span class="LC_nobreak">
6403: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6404: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6405: </span>
6406: </fieldset>
6407: </form>
6408:
6409: RESFORM
1.534 raeburn 6410:
1.342 ehlerst 6411: my $specialdocumentsform;
1.383 tempelho 6412: my @specialdocumentsforma;
1.451 www 6413: my $gradingform;
6414: my @gradingforma;
6415: my $communityform;
6416: my @communityforma;
1.351 ehlerst 6417: my $newfolderform;
1.390 tempelho 6418: my $newfolderb;
1.342 ehlerst 6419:
1.451 www 6420: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6421:
1.329 droeschl 6422: my $newpageform=(<<NPFORM);
6423: <form action="/adm/coursedocs" method="post" name="newpage">
6424: <input type="hidden" name="folderpath" value="$path" />
6425: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6426: <input type="hidden" name="active" value="ee" />
1.423 onken 6427: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6428: $help{'Adding_Pages'}
1.329 droeschl 6429: </form>
6430: NPFORM
1.390 tempelho 6431:
6432:
1.351 ehlerst 6433: $newfolderform=(<<NFFORM);
1.329 droeschl 6434: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6435: $pathitem
1.329 droeschl 6436: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6437: <input type="hidden" name="active" value="" />
1.422 onken 6438: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6439: </form>
6440: NFFORM
6441:
6442: my $newsylform=(<<NSYLFORM);
6443: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6444: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6445: $pathitem
1.329 droeschl 6446: <input type="hidden" name="importdetail"
6447: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6448: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6449: $help{'Syllabus'}
1.383 tempelho 6450:
1.329 droeschl 6451: </form>
6452: NSYLFORM
1.364 bisitz 6453:
1.329 droeschl 6454: my $newgroupfileform=(<<NGFFORM);
6455: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6456: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6457: $pathitem
1.329 droeschl 6458: <input type="hidden" name="importdetail"
6459: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6460: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6461: $help{'Group Portfolio'}
1.329 droeschl 6462: </form>
6463: NGFFORM
1.383 tempelho 6464: @specialdocumentsforma=(
1.421 onken 6465: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.618 raeburn 6466: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6467: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6468: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6469: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6470: );
6471: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6472:
1.434 raeburn 6473:
6474: my @importdoc = (
1.519 raeburn 6475: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6476: );
1.598 raeburn 6477: if (keys(%ltitools)) {
6478: push(@importdoc,
1.627 raeburn 6479: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
1.598 raeburn 6480: );
6481: }
1.519 raeburn 6482: unless ($container eq 'page') {
6483: push(@importdoc,
6484: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6485: );
6486: }
6487: push(@importdoc,
1.558 raeburn 6488: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6489: );
1.501 raeburn 6490: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6491:
1.451 www 6492: @gradingforma=(
6493: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6494: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6495: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6496: {'<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 6497: );
6498: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6499:
6500: @communityforma=(
6501: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6502: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6503: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6504: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6505: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6506: );
6507: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6508:
1.330 tempelho 6509: my %orderhash = (
1.553 raeburn 6510: 'aa' => ['Upload',$fileuploadform],
6511: 'bb' => ['Import',$importpubform],
6512: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6513: );
1.519 raeburn 6514: unless ($container eq 'page') {
1.434 raeburn 6515: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6516: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6517: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6518: }
6519:
1.341 ehlerst 6520: $hadchanges=0;
1.484 raeburn 6521: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6522: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6523: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6524: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6525: undef($navmap);
1.443 www 6526: if ($error) {
6527: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6528: }
1.639 raeburn 6529: if ($hadchanges) {
6530: unless (&is_hash_old()) {
1.638 raeburn 6531: &mark_hash_old();
6532: }
6533: }
1.341 ehlerst 6534:
1.443 www 6535: &changewarning($r,'');
6536: }
1.458 raeburn 6537: }
1.442 www 6538:
1.443 www 6539: # Supplemental documents start here
6540:
1.329 droeschl 6541: my $folder=$env{'form.folder'};
1.443 www 6542: unless ($supplementalflag) {
1.329 droeschl 6543: $folder='supplemental';
6544: }
6545: if ($folder =~ /^supplemental$/ &&
6546: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6547: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6548: } elsif ($allowed) {
1.356 tempelho 6549: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6550: }
1.508 raeburn 6551: $pathitem = '<input type="hidden" name="folderpath" value="'.
6552: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6553: if ($allowed) {
6554: my $folderseq=
1.504 raeburn 6555: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6556:
6557: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6558: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6559: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6560: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6561: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6562: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6563: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6564: $fileupload
6565: <br />
6566: <br />
6567: <span class="LC_nobreak">
6568: $checkbox
6569: </span>
6570: <br /><br />
6571: $lt{'comment'}:<br />
1.383 tempelho 6572: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6573: <br />
1.508 raeburn 6574: $pathitem
1.329 droeschl 6575: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6576: <input type='submit' value="$lt{'upld'}" />
6577: </form>
1.329 droeschl 6578: SUPDOCFORM
6579:
6580: my $supnewfolderform=(<<SNFFORM);
6581: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6582: <input type="hidden" name="active" value="" />
1.508 raeburn 6583: $pathitem
1.329 droeschl 6584: <input type="hidden" name="importdetail" value="" />
1.423 onken 6585: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6586: $help{'Adding_Folders'}
1.329 droeschl 6587: </form>
6588: SNFFORM
1.383 tempelho 6589:
1.510 raeburn 6590: my $supextform =
6591: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6592: $help{'Adding_External_Resource'},
6593: undef,undef,undef,undef,undef,undef,
6594: $disabled);
1.329 droeschl 6595:
1.598 raeburn 6596: my $supexttoolform =
6597: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6598: $help{'Adding_External_Tool'},
6599: undef,undef,'tool',$coursedom,
1.611 raeburn 6600: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6601:
1.329 droeschl 6602: my $supnewsylform=(<<SNSFORM);
6603: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6604: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6605: $pathitem
1.329 droeschl 6606: <input type="hidden" name="importdetail"
6607: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6608: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6609: $help{'Syllabus'}
6610: </form>
6611: SNSFORM
6612:
6613: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6614: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6615: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6616: $pathitem
1.329 droeschl 6617: <input type="hidden" name="importdetail"
6618: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6619: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6620: $help{'My Personal Information Page'}
1.329 droeschl 6621: </form>
6622: SNAMFORM
6623:
1.534 raeburn 6624: my $supwebpage;
6625: if ($folder =~ /^supplemental_?(\d*)$/) {
6626: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6627: if ($1) {
6628: $supwebpage .= $1;
6629: } else {
6630: $supwebpage .= 'default';
6631: }
6632: $supwebpage .= '/new.html';
6633: }
6634: my $supwebpageform =(<<SWEBFORM);
6635: <form action="/adm/coursedocs" method="post" name="supwebpage">
6636: <input type="hidden" name="active" value="cc" />
6637: $pathitem
6638: <input type="hidden" name="importdetail" value="$supwebpage" />
6639: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6640: $help{'Web_Page'}
1.534 raeburn 6641: </form>
6642: SWEBFORM
6643:
1.333 muellerd 6644:
1.383 tempelho 6645: my @specialdocs = (
1.618 raeburn 6646: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6647: =>$supnewsylform},
1.611 raeburn 6648: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6649: =>$supnewaboutmeform},
1.534 raeburn 6650: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6651:
1.383 tempelho 6652: );
1.417 droeschl 6653: my @supimportdoc = (
1.515 raeburn 6654: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6655: =>$supextform});
6656: if (keys(%ltitools)) {
6657: push(@supimportdoc,
1.627 raeburn 6658: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
1.598 raeburn 6659: =>$supexttoolform});
6660: }
6661: push(@supimportdoc,
6662: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6663: =>$supupdocform},
1.598 raeburn 6664: );
1.501 raeburn 6665:
6666: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6667: my %suporderhash = (
1.390 tempelho 6668: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6669: 'ee' => ['Upload',$supupdocform],
6670: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6671: );
1.443 www 6672: if ($supplementalflag) {
1.458 raeburn 6673: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6674: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6675: \%ltitools,$canedit,$hostname);
1.443 www 6676: if ($error) {
6677: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6678: } else {
6679: if ($suppchanges) {
6680: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6681: my @ids=&Apache::lonnet::current_machine_ids();
6682: foreach my $server (keys(%servers)) {
6683: next if (grep(/^\Q$server\E$/,@ids));
6684: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6685: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6686: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6687: }
6688: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6689: undef($suppchanges);
1.630 raeburn 6690: }
6691: }
1.393 raeburn 6692: }
1.443 www 6693: } elsif ($supplementalflag) {
1.458 raeburn 6694: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6695: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6696: if ($error) {
6697: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6698: }
1.393 raeburn 6699: }
1.389 tempelho 6700:
1.510 raeburn 6701: if ($needs_end) {
6702: $r->print(&endContentScreen());
6703: }
1.383 tempelho 6704:
1.329 droeschl 6705: if ($allowed) {
6706: $r->print('
6707: <form method="post" name="extimport" action="/adm/coursedocs">
6708: <input type="hidden" name="title" />
6709: <input type="hidden" name="url" />
6710: <input type="hidden" name="useform" />
6711: <input type="hidden" name="residx" />
6712: </form>');
6713: }
1.484 raeburn 6714: } elsif ($showdoc) {
1.329 droeschl 6715: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6716: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6717: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6718: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6719: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6720: }
6721: }
1.630 raeburn 6722: unless ($noendpage) {
1.606 raeburn 6723: $r->print(&Apache::loncommon::end_page());
6724: }
1.329 droeschl 6725: return OK;
1.364 bisitz 6726: }
1.329 droeschl 6727:
1.440 raeburn 6728: sub embedded_form_elems {
6729: my ($phase,$primaryurl,$newidx) = @_;
6730: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 6731: $newidx =~s /\D+//g;
1.440 raeburn 6732: return <<STATE;
6733: <input type="hidden" name="folderpath" value="$folderpath" />
6734: <input type="hidden" name="cmd" value="upload_embedded" />
6735: <input type="hidden" name="newidx" value="$newidx" />
6736: <input type="hidden" name="phase" value="$phase" />
6737: <input type="hidden" name="primaryurl" value="$primaryurl" />
6738: STATE
6739: }
6740:
6741: sub embedded_destination {
6742: my $folder=$env{'form.folder'};
6743: my $destination = 'docs/';
6744: if ($folder =~ /^supplemental/) {
6745: $destination = 'supplemental/';
6746: }
6747: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6748: $destination .= 'default/';
6749: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6750: $destination .= $2.'/';
6751: }
1.634 raeburn 6752: my $newidx = $env{'form.newidx'};
6753: $newidx =~s /\D+//g;
6754: if ($newidx) {
6755: $destination .= $newidx;
6756: }
1.440 raeburn 6757: my $dir_root = '/userfiles';
6758: return ($destination,$dir_root);
6759: }
6760:
6761: sub return_to_editor {
6762: my $actionurl = '/adm/coursedocs';
6763: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6764: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6765: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6766: '</a></p>';
6767: }
6768:
1.476 raeburn 6769: sub decompression_info {
6770: my ($destination,$dir_root) = &embedded_destination();
6771: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6772: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6773: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6774: my $container='sequence';
1.480 raeburn 6775: my ($pathitem,$hiddenelem);
1.583 raeburn 6776: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6777: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6778: $container='page';
6779: }
1.480 raeburn 6780: unshift(@hiddens,$pathitem);
6781: foreach my $item (@hiddens) {
1.634 raeburn 6782: if ($item eq 'newidx') {
6783: next if ($env{'form.'.$item} =~ /\D/);
6784: }
1.480 raeburn 6785: if ($env{'form.'.$item}) {
6786: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6787: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6788: }
1.477 raeburn 6789: }
1.476 raeburn 6790: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6791: $hiddenelem);
6792: }
6793:
6794: sub decompression_phase_one {
6795: my ($dir,$file,$warning,$error,$output);
6796: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6797: &decompression_info();
1.490 raeburn 6798: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6799: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6800: } else {
6801: my $file = $1;
1.630 raeburn 6802: $output =
1.481 raeburn 6803: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6804: $destination,$dir_root,
6805: $hiddenelem);
6806: if ($env{'form.autoextract_camtasia'}) {
6807: $output .= &remove_archive($docudom,$docuname,$container);
6808: }
1.476 raeburn 6809: }
6810: if ($error) {
6811: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6812: $error.'</p>'."\n";
6813: }
6814: if ($warning) {
6815: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6816: }
6817: return $output;
6818: }
6819:
6820: sub decompression_phase_two {
6821: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6822: &decompression_info();
1.481 raeburn 6823: my $output;
1.480 raeburn 6824: if ($env{'form.archivedelete'}) {
1.481 raeburn 6825: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6826: }
6827: $output .=
1.481 raeburn 6828: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6829: $destination,$dir_root,$hiddenelem);
6830: return $output;
6831: }
6832:
1.480 raeburn 6833: sub remove_archive {
6834: my ($docudom,$docuname,$container) = @_;
6835: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6836: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6837: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6838: if ($fatal) {
6839: if ($container eq 'page') {
6840: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6841: } else {
6842: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6843: }
1.583 raeburn 6844: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6845: } else {
6846: my $currcmd = $env{'form.cmd'};
6847: my $position = $env{'form.position'};
1.583 raeburn 6848: my $archiveidx = $position;
1.563 raeburn 6849: if ($position > 0) {
1.583 raeburn 6850: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6851: $archiveidx = $position-1;
6852: }
6853: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6854: my ($title,$url,@rrest) =
1.583 raeburn 6855: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6856: if ($url eq $env{'form.archiveurl'}) {
6857: if (&handle_edit_cmd($docuname,$docudom)) {
6858: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6859: if ($fatal) {
6860: if ($container eq 'page') {
6861: $delwarning = &mt('An error occurred updating the contents of the current page.');
6862: } else {
6863: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6864: }
1.480 raeburn 6865: } else {
1.583 raeburn 6866: $delresult = &mt('Archive file removed.');
1.480 raeburn 6867: }
6868: }
1.583 raeburn 6869: } else {
6870: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6871: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6872: }
6873: }
6874: $env{'form.cmd'} = $currcmd;
6875: }
6876: if ($delwarning) {
6877: $output = '<p class="LC_warning">'.
6878: $delwarning.
6879: '</p>';
6880: }
6881: if ($delresult) {
6882: $output .= '<p class="LC_info">'.
6883: $delresult.
6884: '</p>';
6885: }
1.481 raeburn 6886: return $output;
1.480 raeburn 6887: }
6888:
1.484 raeburn 6889: sub generate_admin_menu {
1.611 raeburn 6890: my ($crstype,$canedit) = @_;
1.484 raeburn 6891: my $lc_crstype = lc($crstype);
6892: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6893: my %lt= ( # do not translate here
1.484 raeburn 6894: 'vc' => 'Verify Content',
6895: 'cv' => 'Check/Set Resource Versions',
6896: 'ls' => 'List Resource Identifiers',
6897: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6898: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6899: );
1.484 raeburn 6900: my ($candump,$dumpurl);
6901: if ($home + $other > 0) {
6902: $candump = 'F';
6903: if ($home) {
6904: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6905: } else {
6906: my @hosts;
6907: foreach my $aurole (keys(%outhash)) {
6908: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6909: push(@hosts,$outhash{$aurole});
1.538 raeburn 6910: }
1.484 raeburn 6911: }
6912: if (@hosts == 1) {
6913: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6914: '&role='.
6915: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6916: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6917: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6918: } else {
6919: $dumpurl = "javascript:choose_switchserver_window()";
6920: }
6921: }
6922: }
6923: my @menu=
6924: ({ categorytitle=>'Administration',
6925: items =>[
6926: { linktext => $lt{'vc'},
6927: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6928: permission => 'F',
1.571 raeburn 6929: help => 'Docs_Verify_Content',
1.484 raeburn 6930: icon => 'verify.png',
6931: linktitle => 'Verify contents can be retrieved/rendered',
6932: },
6933: { linktext => $lt{'cv'},
6934: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6935: permission => 'F',
1.571 raeburn 6936: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6937: icon => 'resversion.png',
6938: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6939: },
6940: { linktext => $lt{'ls'},
6941: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6942: permission => 'F',
6943: #help => '',
6944: icon => 'symbs.png',
6945: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6946: },
6947: ]
1.611 raeburn 6948: });
6949: if ($canedit) {
6950: push(@menu,
1.484 raeburn 6951: { categorytitle=>'Export',
6952: items =>[
6953: { linktext => $lt{'imse'},
6954: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6955: permission => 'F',
6956: help => 'Docs_Export_Course_Docs',
6957: icon => 'imsexport.png',
6958: linktitle => $lt{'imse'},
6959: },
6960: { linktext => $lt{'dcd'},
6961: url => $dumpurl,
6962: permission => $candump,
1.571 raeburn 6963: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6964: icon => 'dump.png',
6965: linktitle => $lt{'dcd'},
6966: },
6967: ]
6968: });
1.611 raeburn 6969: }
1.484 raeburn 6970: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6971: '<input type="hidden" id="dummy" />'."\n".
6972: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6973: '</form>';
1.329 droeschl 6974: }
6975:
6976: sub generate_edit_table {
1.538 raeburn 6977: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6978: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6979: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6980: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6981: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6982: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6983: $activetab = $env{'form.active'};
6984: }
1.611 raeburn 6985: unless ($canedit) {
6986: $disabled = ' disabled="disabled"';
6987: }
1.472 raeburn 6988: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6989: my $backtext = &mt('Exit Editor');
1.458 raeburn 6990: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6991: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6992: '<li class="goback">'.
1.546 raeburn 6993: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6994: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6995: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6996: '<li>'.
6997: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6998: &mt('Undo Delete').'</a></li>'."\n";
6999: if ($env{'form.docslog'}) {
7000: $form .= '<li class="active">';
7001: } else {
7002: $form .= '<li>';
7003: }
7004: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7005: &mt('History').'</a></li>'."\n";
7006: if ($env{'form.docslog'}) {
7007: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7008: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7009: }
1.458 raeburn 7010: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7011: if($name ne '00'){
1.371 tempelho 7012: if($activetab eq '' || $activetab ne $name){
7013: $active = '';
7014: }elsif($activetab eq $name){
7015: $active = 'class="active"';
7016: }
1.458 raeburn 7017: $form .= '<li style="float:right" '.$active
1.484 raeburn 7018: .' 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 7019: } else {
1.570 raeburn 7020: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7021:
7022: }
1.329 droeschl 7023: }
1.484 raeburn 7024: $form .= '</ul>'."\n";
7025: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7026:
7027: if ($to_show ne '') {
1.538 raeburn 7028: my $saveform;
7029: if ($need_save) {
7030: my $button = &mt('Make changes');
7031: my $path;
7032: if ($env{'form.folderpath'}) {
7033: $path =
7034: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7035: }
7036: $saveform = <<"END";
7037: <div id="multisave" style="display:none; clear:both;" >
7038: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7039: <input type="hidden" name="folderpath" value="$path" />
7040: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7041: <input type="hidden" name="allhiddenresource" value="" />
7042: <input type="hidden" name="allencrypturl" value="" />
7043: <input type="hidden" name="allrandompick" value="" />
7044: <input type="hidden" name="allrandomorder" value="" />
7045: <input type="hidden" name="changeparms" value="" />
7046: <input type="hidden" name="multiremove" value="" />
7047: <input type="hidden" name="multicut" value="" />
7048: <input type="hidden" name="multicopy" value="" />
7049: <input type="hidden" name="multichange" value="" />
7050: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7051: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7052: </form>
7053: </div>
7054: END
7055: }
7056: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7057: }
1.363 ehlerst 7058: foreach my $field (keys(%orderhash)){
1.390 tempelho 7059: if($field ne '00'){
1.422 onken 7060: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7061: $active = 'style="display: none;float:left"';
1.422 onken 7062: }elsif($activetab eq $field){
1.458 raeburn 7063: $active = 'style="display:block;float:left"';
1.422 onken 7064: }
7065: $form .= '<div id="'.$field.$tid.'"'
7066: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7067: .'</div>'."\n";
1.363 ehlerst 7068: }
7069: }
1.484 raeburn 7070: unless ($env{'form.docslog'}) {
7071: $form .= '</div></div>'."\n";
7072: }
1.329 droeschl 7073: return $form;
7074: }
7075:
7076: sub editing_js {
1.622 raeburn 7077: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7078: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7079: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7080: p_mnf => 'Name of New Folder',
7081: t_mnf => 'New Folder',
7082: p_mnp => 'Name of New Page',
7083: t_mnp => 'New Page',
1.451 www 7084: p_mxu => 'Title for the External Score',
1.349 biermanm 7085: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7086: p_msb => 'Title for the Problem',
7087: p_mdb => 'Title for the Drop Box',
1.336 schafran 7088: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7089: p_mwp => 'Title for Web Page',
1.606 raeburn 7090: p_mnr => 'Title for the Resource',
1.348 weissno 7091: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7092: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7093: p_mab_alrt1 => 'Not a valid user:domain',
7094: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7095: p_chn => 'New Title',
7096: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7097: p_rmr2a => 'Remove',
7098: p_rmr2b => '?',
7099: p_rmr3a => 'Remove those',
7100: p_rmr3b => 'items?',
7101: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7102: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7103: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7104: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7105: p_ctr2a => 'Cut',
7106: p_ctr2b => '?',
7107: p_ctr3a => 'Cut those',
7108: p_ctr3b => 'items?',
1.633 raeburn 7109: setal => 'Enter a (unique) alias',
7110: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7111: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7112: imsfile => 'You must choose an IMS package for import',
7113: imscms => 'You must select which Course Management System was the source of the IMS package',
7114: invurl => 'Invalid URL',
7115: titbl => 'Title is blank',
1.538 raeburn 7116: more => '(More ...)',
7117: less => '(Less ...)',
1.543 raeburn 7118: noor => 'No actions selected or changes to settings specified.',
7119: noch => 'No changes to settings specified.',
7120: noac => 'No actions selected.',
1.606 raeburn 7121: nofi => 'No file selected',
7122: tinc => 'Title in course',
7123: sunm => 'Sub-directory name',
1.618 raeburn 7124: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7125: );
1.594 damieng 7126: &js_escape(\%js_lt);
1.433 raeburn 7127: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7128: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7129: my $main_container_page;
1.519 raeburn 7130: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7131: $main_container_page = 1;
1.434 raeburn 7132: }
1.617 raeburn 7133: my $backtourl;
7134: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7135: my $toplevelsupp = &supplemental_base();
1.433 raeburn 7136:
1.530 raeburn 7137: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7138: my $caller = $1;
1.525 raeburn 7139: if ($caller =~ /^supplemental/) {
7140: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7141: } else {
7142: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7143: $res = &Apache::lonnet::clutter($res);
7144: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7145: my ($url,$anchor);
7146: if ($res =~ /^([^#]+)#([^#]+)$/) {
7147: $url = $1;
7148: $anchor = $2;
7149: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7150: $caller = $1.&escape('#').$anchor;
7151: }
1.614 raeburn 7152: } else {
7153: $url = $res;
1.609 raeburn 7154: }
1.640 raeburn 7155: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7156: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7157: $backtourl .= '?navmap=1';
7158: } else {
7159: $backtourl .= '?symb='.
7160: &HTML::Entities::encode($caller,'<>&"');
7161: }
1.622 raeburn 7162: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7163: if (($ENV{'SERVER_PORT'} == 443) &&
7164: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
7165: if ($hostname ne '') {
7166: $backtourl = 'http://'.$hostname.$backtourl;
7167: }
1.627 raeburn 7168: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7169: }
1.623 raeburn 7170: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7171: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
7172: $backtourl = 'http://'.$hostname.$backtourl;
7173: }
1.622 raeburn 7174: }
1.609 raeburn 7175: if ($anchor ne '') {
7176: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7177: }
1.590 raeburn 7178: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7179: } else {
7180: $backtourl = '/adm/navmaps';
1.525 raeburn 7181: }
7182: }
7183: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7184: $backtourl = '/adm/menu';
7185: } elsif ($supplementalflag) {
1.472 raeburn 7186: $backtourl = '/adm/supplemental';
1.525 raeburn 7187: } else {
7188: $backtourl = '/adm/navmaps';
1.472 raeburn 7189: }
7190:
1.600 raeburn 7191: my $fieldsets = "'ext','doc'";
7192: if ($posslti) {
7193: $fieldsets .= ",'tool'";
7194: }
1.519 raeburn 7195: unless ($main_container_page) {
7196: $fieldsets .=",'ims'";
7197: }
1.501 raeburn 7198: if ($supplementalflag) {
1.600 raeburn 7199: $fieldsets = "'suppext','suppdoc'";
7200: if ($posslti) {
7201: $fieldsets .= ",'supptool'";
7202: }
1.501 raeburn 7203: }
1.611 raeburn 7204:
7205: my $jsmakefunctions;
7206: if ($canedit) {
7207: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7208: function makenewfolder(targetform,folderseq) {
1.594 damieng 7209: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7210: if (foldername) {
7211: targetform.importdetail.value=escape(foldername)+"="+folderseq;
7212: targetform.submit();
7213: }
7214: }
7215:
7216: function makenewpage(targetform,folderseq) {
1.594 damieng 7217: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7218: if (pagename) {
7219: targetform.importdetail.value=escape(pagename)+"="+folderseq;
7220: targetform.submit();
7221: }
7222: }
7223:
7224: function makeexamupload() {
1.594 damieng 7225: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7226: if (title) {
1.329 droeschl 7227: this.document.forms.newexamupload.importdetail.value=
7228: escape(title)+'=/res/lib/templates/examupload.problem';
7229: this.document.forms.newexamupload.submit();
7230: }
7231: }
7232:
7233: function makesmppage() {
1.594 damieng 7234: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7235: if (title) {
1.329 droeschl 7236: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 7237: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7238: this.document.forms.newsmppg.submit();
7239: }
7240: }
7241:
1.534 raeburn 7242: function makewebpage(type) {
1.594 damieng 7243: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7244: var formname;
7245: if (type == 'supp') {
7246: formname = this.document.forms.supwebpage;
7247: } else {
7248: formname = this.document.forms.newwebpage;
7249: }
7250: if (title) {
7251: var webpage = formname.importdetail.value;
7252: formname.importdetail.value = escape(title)+'='+webpage;
7253: formname.submit();
7254: }
7255: }
7256:
1.329 droeschl 7257: function makesmpproblem() {
1.594 damieng 7258: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7259: if (title) {
1.329 droeschl 7260: this.document.forms.newsmpproblem.importdetail.value=
7261: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7262: this.document.forms.newsmpproblem.submit();
7263: }
7264: }
7265:
7266: function makedropbox() {
1.594 damieng 7267: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7268: if (title) {
1.329 droeschl 7269: this.document.forms.newdropbox.importdetail.value=
7270: escape(title)+'=/res/lib/templates/DropBox.problem';
7271: this.document.forms.newdropbox.submit();
7272: }
7273: }
7274:
7275: function makebulboard() {
1.594 damieng 7276: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7277: if (title) {
7278: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7279: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7280: this.document.forms.newbul.submit();
7281: }
7282: }
7283:
7284: function makeabout() {
1.594 damieng 7285: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7286: if (user) {
7287: var comp=new Array();
7288: comp=user.split(':');
7289: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7290: if ((comp[0]) && (comp[1])) {
7291: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7292: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7293: this.document.forms.newaboutsomeone.submit();
7294: } else {
7295: alert("$js_lt{'p_mab_alrt1'}");
7296: }
7297: } else {
7298: alert("$js_lt{'p_mab_alrt2'}");
7299: }
7300: }
7301: }
7302:
7303: function makenew(targetform) {
7304: targetform.submit();
7305: }
7306:
7307: function changename(folderpath,index,oldtitle) {
7308: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7309: if (title) {
7310: this.document.forms.renameform.markcopy.value='';
7311: this.document.forms.renameform.title.value=title;
7312: this.document.forms.renameform.cmd.value='rename_'+index;
7313: this.document.forms.renameform.folderpath.value=folderpath;
7314: this.document.forms.renameform.submit();
7315: }
7316: }
7317:
1.633 raeburn 7318: function setalias(folderpath,index) {
7319: var alias = prompt('$js_lt{"setal"}');
7320: if ((alias != null) && (alias != '')) {
7321: this.document.forms.aliasform.alias.value=alias;
7322: this.document.forms.aliasform.cmd.value='setalias_'+index;
7323: this.document.forms.aliasform.folderpath.value=folderpath;
7324: this.document.forms.aliasform.submit();
7325: }
7326: }
7327:
7328: function delalias(folderpath,index) {
7329: if (confirm('$js_lt{"delal"}')) {
7330: this.document.forms.aliasform.cmd.value='delalias_'+index;
7331: this.document.forms.aliasform.folderpath.value=folderpath;
7332: this.document.forms.aliasform.submit();
7333: }
7334: }
7335:
1.611 raeburn 7336: ENDNEWSCRIPT
7337: } else {
7338: $jsmakefunctions = <<ENDNEWSCRIPT;
7339:
7340: function makenewfolder() {
7341: alert("$js_lt{'edri'}");
7342: }
7343:
7344: function makenewpage() {
7345: alert("$js_lt{'edri'}");
7346: }
7347:
7348: function makeexamupload() {
7349: alert("$js_lt{'edri'}");
7350: }
7351:
7352: function makesmppage() {
7353: alert("$js_lt{'edri'}");
7354: }
7355:
7356: function makewebpage(type) {
7357: alert("$js_lt{'edri'}");
7358: }
7359:
7360: function makesmpproblem() {
7361: alert("$js_lt{'edri'}");
7362: }
7363:
7364: function makedropbox() {
7365: alert("$js_lt{'edri'}");
7366: }
7367:
7368: function makebulboard() {
7369: alert("$js_lt{'edri'}");
7370: }
7371:
7372: function makeabout() {
7373: alert("$js_lt{'edri'}");
7374: }
7375:
7376: function changename() {
7377: alert("$js_lt{'edri'}");
7378: }
7379:
1.633 raeburn 7380: function setalias() {
7381: alert("$js_lt{'edri'}");
7382: }
7383:
7384: function delalias() {
7385: alert("$js_lt{'edri'}");
7386: }
7387:
1.611 raeburn 7388: function makenew() {
7389: alert("$js_lt{'edri'}");
7390: }
7391:
7392: function groupimport() {
7393: alert("$js_lt{'edri'}");
1.335 ehlerst 7394: }
1.611 raeburn 7395:
7396: function groupsearch() {
7397: alert("$js_lt{'edri'}");
1.335 ehlerst 7398: }
1.611 raeburn 7399:
7400: function groupopen(url,recover) {
7401: var options="scrollbars=1,resizable=1,menubar=0";
7402: idxflag=1;
7403: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7404: idx.focus();
1.329 droeschl 7405: }
7406:
1.611 raeburn 7407: ENDNEWSCRIPT
7408:
7409: }
7410: return <<ENDSCRIPT;
7411:
7412: $jsmakefunctions
7413:
1.501 raeburn 7414: function toggleUpload(caller) {
7415: var blocks = Array($fieldsets);
7416: for (var i=0; i<blocks.length; i++) {
7417: var disp = 'none';
7418: if (caller == blocks[i]) {
7419: var curr = document.getElementById('upload'+caller+'form').style.display;
7420: if (curr == 'none') {
7421: disp='block';
7422: }
7423: }
7424: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7425: if ((caller == 'tool') || (caller == 'supptool')) {
7426: if (disp == 'block') {
7427: if (document.getElementById('LC_exttoolid')) {
7428: var toolselector = document.getElementById('LC_exttoolid');
7429: var suppflag = 0;
7430: if (caller == 'supptool') {
7431: suppflag = 1;
7432: }
7433: currForm = document.getElementById('new'+caller);
7434: updateExttool(toolselector,currForm,suppflag);
7435: }
7436: }
7437: }
1.501 raeburn 7438: }
1.502 raeburn 7439: resize_scrollbox('contentscroll','1','1');
7440: return;
7441: }
7442:
1.514 raeburn 7443: function toggleMap(caller) {
1.502 raeburn 7444: var disp = 'none';
1.510 raeburn 7445: if (document.getElementById('importmapform')) {
1.514 raeburn 7446: if (caller == 'map') {
7447: var curr = document.getElementById('importmapform').style.display;
7448: if (curr == 'none') {
7449: disp='block';
7450: }
1.510 raeburn 7451: }
7452: document.getElementById('importmapform').style.display=disp;
7453: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7454: }
1.501 raeburn 7455: return;
1.329 droeschl 7456: }
7457:
1.606 raeburn 7458: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7459: var disp = 'none';
7460: if (document.getElementById('crsresform')) {
7461: if (caller == 'res') {
7462: var curr = document.getElementById('crsresform').style.display;
7463: if (curr == 'none') {
7464: disp='block';
7465: numauthor = parseInt(numauthorrole);
7466: if (numauthor > 0) {
7467: document.courseresform.authorrole.selectedIndex = 0;
7468: select1priv_changed();
7469: document.courseresform.authorpath.selectedIndex = 0;
7470: document.courseresform.newresourceadd.selectedIndex = 0;
7471: toggleNewInCourse(document.courseresform);
7472: if (document.getElementById('newresource')) {
7473: document.getElementById('newresource').style.display = 'none';
7474: }
7475: } else {
7476: if (numcrsdirs) {
7477: document.courseresform.authorpath.selectedIndex = 0;
7478: }
7479: }
7480: if (document.courseresform.newresusetemp.length) {
7481: document.courseresform.newresusetemp[0].checked = true;
7482: toggleWithTemplate(document.courseresform);
7483: }
7484: document.courseresform.newresourcename.value = '';
7485: }
7486: }
7487: if (document.courseresform.newsubdir.length) {
7488: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7489: if (document.courseresform.newsubdir[j].value == 0) {
7490: document.courseresform.newsubdir[j].checked = true;
7491: }
7492: break;
7493: }
7494: if (document.getElementById('newsubdirname')) {
7495: document.getElementById('newsubdirname').type = "hidden";
7496: document.getElementById('newsubdirname').value = "";
7497: }
7498: if (document.getElementById('newsubdir')) {
7499: document.getElementById('newsubdir').innerHTML = "";
7500: }
7501: }
7502: document.getElementById('crsresform').style.display=disp;
7503: resize_scrollbox('contentscroll','1','0');
7504: }
7505: return;
7506: }
7507:
7508: function toggleNewsubdir(form) {
7509: if (form.newsubdir.length) {
7510: for (var j=0; j<form.newsubdir.length; j++) {
7511: if (form.newsubdir[j].checked) {
7512: if (document.getElementById('newsubdirname')) {
7513: if (form.newsubdir[j].value == '1') {
7514: document.getElementById('newsubdirname').type = "text";
7515: if (document.getElementById('newsubdir')) {
7516: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7517: }
7518: } else {
7519: document.getElementById('newsubdirname').type = "hidden";
7520: document.getElementById('newsubdirname').value = "";
7521: document.getElementById('newsubdir').innerHTML = "";
7522: }
7523: }
7524: break;
7525: }
7526: }
7527: }
7528: }
7529:
7530: function toggleCrsResTitle() {
7531: if (document.getElementById('newresource')) {
7532: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7533: document.getElementById('newresource').style.display = 'inline';
7534: document.courseresform.newresourceadd[0].checked = true;
7535: toggleNewInCourse(document.courseresform);
7536: } else {
7537: document.getElementById('newresource').style.display = 'none';
7538: }
7539: }
7540: }
7541:
7542: function toggleNewInCourse(form) {
7543: if (form.newresourceadd.length) {
7544: for (var i=0; i<form.newresourceadd.length; i++) {
7545: if (form.newresourceadd[i].checked) {
7546: if (document.getElementById('newresourcetitle')) {
7547: if (form.newresourceadd[i].value == '1') {
7548: document.getElementById('newresourcetitle').type = 'text';
7549: if (document.getElementById('newrestitle')) {
7550: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7551: }
7552: } else {
7553: document.getElementById('newresourcetitle').type = 'hidden';
7554: document.getElementById('newresourcetitle').value = '';
7555: if (document.getElementById('newrestitle')) {
7556: document.getElementById('newrestitle').innerHTML = '';
7557: }
7558: }
7559: }
7560: break;
7561: }
7562: }
7563: }
7564: }
7565:
7566: function toggleWithTemplate(form) {
7567: if (form.newresusetemp.length) {
7568: for (var i=0; i<form.newresusetemp.length; i++) {
7569: if (form.newresusetemp[i].checked) {
7570: if (document.getElementById('newrestemplate')) {
7571: if (form.newresusetemp[i].value == '1') {
7572: document.getElementById('newrestemplate').style.display = 'inline';
7573: toggleExampleText();
7574: } else {
7575: form.tempcategory.selectedIndex = 0;
7576: select1template_changed();
7577: document.getElementById('newrestemplate').style.display = 'none';
7578: }
7579: }
7580: }
7581: }
7582: }
7583: }
7584:
7585: function toggleExampleText() {
7586: if (document.getElementById('newresexample')) {
7587: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7588: if (url == '') {
7589: document.getElementById('newresexample').style.fontWeight = 'normal';
7590: } else {
7591: document.getElementById('newresexample').style.fontWeight = 'bold';
7592: }
7593: }
7594: }
7595:
7596: function getExample(width,height,scrolling,transparency) {
7597: var url;
7598: if (document.courseresform.newresusetemp.length) {
7599: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7600: if (document.courseresform.newresusetemp[i].checked) {
7601: if (document.courseresform.newresusetemp[i].value == '1') {
7602: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7603: if (url == '') {
7604: alert('Pick a category and template');
7605: } else {
7606: url = url.replace("$londocroot","");
7607: url += '?inhibitmenu=yes';
7608: }
7609: }
7610: break;
7611: }
7612: }
7613: }
7614: if (url != '') {
7615: openMyModal(url,width,height,scrolling,transparency,'');
7616: }
7617: }
7618:
7619: function toggleImportCrsres(caller,dircount) {
7620: var disp = 'none';
7621: if (document.getElementById('importcrsresform')) {
7622: if (caller == 'res') {
7623: var numdirs = parseInt(dircount);
7624: var curr = document.getElementById('importcrsresform').style.display;
7625: if (curr == 'none') {
7626: disp='block';
7627: if (numdirs > 1) {
7628: select1res_changed();
7629: }
7630: }
7631: }
7632: document.getElementById('importcrsresform').style.display=disp;
7633: resize_scrollbox('contentscroll','1','0');
7634: }
7635: return;
7636: }
7637:
1.501 raeburn 7638: function makeims(imsform) {
7639: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7640: alert("$js_lt{'imsfile'}");
1.501 raeburn 7641: return;
7642: }
7643: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7644: alert("$js_lt{'imscms'}");
1.501 raeburn 7645: return;
7646: }
7647: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7648: imsform.submit();
7649: }
7650:
1.478 raeburn 7651: function updatePick(targetform,index,caller) {
1.537 raeburn 7652: var pickitem;
7653: var picknumitem;
7654: var picknumtext;
7655: if (index == 'all') {
7656: pickitem = document.getElementById('randompickall');
7657: picknumitem = document.getElementById('rpicknumall');
7658: picknumtext = document.getElementById('rpicktextall');
7659: } else {
7660: pickitem = document.getElementById('randompick_'+index);
7661: picknumitem = document.getElementById('rpicknum_'+index);
7662: picknumtext = document.getElementById('randompicknum_'+index);
7663: }
1.478 raeburn 7664: if (pickitem.checked) {
1.594 damieng 7665: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7666: if (picknum == '' || picknum == null) {
7667: if (caller == 'check') {
7668: pickitem.checked=false;
1.537 raeburn 7669: if (index == 'all') {
7670: picknumtext.innerHTML = '';
7671: if (caller == 'link') {
7672: propagateState(targetform,'rpicknum');
7673: }
7674: } else {
1.538 raeburn 7675: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7676: }
1.478 raeburn 7677: }
7678: } else {
7679: picknum.toString();
7680: var regexdigit=/^\\d+\$/;
7681: if (regexdigit.test(picknum)) {
7682: picknumitem.value = picknum;
1.537 raeburn 7683: if (index == 'all') {
1.538 raeburn 7684: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7685: if (caller == 'link') {
7686: propagateState(targetform,'rpicknum');
7687: }
7688: } else {
7689: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7690: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7691: }
1.478 raeburn 7692: } else {
7693: if (caller == 'check') {
1.537 raeburn 7694: if (index == 'all') {
7695: picknumtext.innerHTML = '';
7696: if (caller == 'link') {
7697: propagateState(targetform,'rpicknum');
7698: }
7699: } else {
7700: pickitem.checked=false;
1.538 raeburn 7701: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7702: }
1.478 raeburn 7703: }
7704: return;
7705: }
7706: }
7707: } else {
1.537 raeburn 7708: picknumitem.value = '';
7709: picknumtext.innerHTML = '';
7710: if (index == 'all') {
7711: if (caller == 'link') {
7712: propagateState(targetform,'rpicknum');
7713: }
7714: } else {
1.538 raeburn 7715: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7716: }
7717: }
7718: }
7719:
7720: function propagateState(form,param) {
7721: if (document.getElementById(param+'all')) {
7722: var setcheck = 0;
7723: var rpick = 0;
7724: if (param == 'rpicknum') {
7725: if (document.getElementById('randompickall')) {
7726: if (document.getElementById('randompickall').checked) {
7727: if (document.getElementById('rpicknumall')) {
7728: rpick = document.getElementById('rpicknumall').value;
7729: }
7730: }
7731: }
7732: } else {
7733: if (document.getElementById(param+'all').checked) {
7734: setcheck = 1;
7735: }
7736: }
1.538 raeburn 7737: var allidxlist;
7738: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7739: if (document.getElementById('all'+param+'idx')) {
7740: allidxlist = document.getElementById('all'+param+'idx').value;
7741: }
7742: var actions = new Array ('remove','cut','copy');
7743: for (var i=0; i<actions.length; i++) {
7744: if (actions[i] != param) {
7745: if (document.getElementById(actions[i]+'all')) {
7746: document.getElementById(actions[i]+'all').checked = false;
7747: }
7748: }
7749: }
7750: }
1.537 raeburn 7751: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7752: allidxlist = form.allidx.value;
7753: }
7754: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7755: allidxlist = form.allmapidx.value;
7756: }
7757: if ((allidxlist != '') && (allidxlist != null)) {
7758: var allidxs = allidxlist.split(',');
7759: if (allidxs.length > 1) {
7760: for (var i=0; i<allidxs.length; i++) {
7761: if (document.getElementById(param+'_'+allidxs[i])) {
7762: if (param == 'rpicknum') {
7763: if (document.getElementById('randompick_'+allidxs[i])) {
7764: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7765: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7766: if (rpick > 0) {
7767: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7768: } else {
7769: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7770: }
7771: }
7772: }
7773: } else {
1.537 raeburn 7774: if (setcheck == 1) {
7775: document.getElementById(param+'_'+allidxs[i]).checked = true;
7776: } else {
7777: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7778: if (param == 'randompick') {
7779: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7780: }
1.537 raeburn 7781: }
7782: }
7783: }
7784: }
1.538 raeburn 7785: if (setcheck == 1) {
7786: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7787: var actions = new Array('copy','cut','remove');
7788: for (var i=0; i<actions.length; i++) {
7789: var otheractions;
7790: var otheridxs;
7791: if (actions[i] === param) {
7792: continue;
7793: } else {
7794: if (document.getElementById('all'+actions[i]+'idx')) {
7795: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7796: otheridxs = otheractions.split(',');
7797: if (otheridxs.length > 1) {
7798: for (var j=0; j<otheridxs.length; j++) {
7799: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7800: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7801: }
1.537 raeburn 7802: }
7803: }
7804: }
1.538 raeburn 7805: }
7806: }
7807: }
7808: }
7809: }
7810: }
7811: }
7812: return;
7813: }
7814:
1.603 raeburn 7815: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7816: var canedit = '$canedit';
7817: if (canedit == '') {
7818: alert("$js_lt{'edri'}");
7819: return;
7820: }
1.539 raeburn 7821: var dosettings;
7822: var doaction;
1.538 raeburn 7823: var control = document.togglemultsettings;
7824: if (context == 'actions') {
7825: control = document.togglemultactions;
1.539 raeburn 7826: doaction = 1;
7827: } else {
7828: dosettings = 1;
1.538 raeburn 7829: }
1.539 raeburn 7830: if (control) {
7831: if (control.showmultpick.length) {
7832: for (var i=0; i<control.showmultpick.length; i++) {
7833: if (control.showmultpick[i].checked) {
7834: if (control.showmultpick[i].value == 1) {
7835: if (context == 'settings') {
7836: dosettings = 0;
7837: } else {
7838: doaction = 0;
1.538 raeburn 7839: }
7840: }
7841: }
1.537 raeburn 7842: }
7843: }
1.539 raeburn 7844: }
7845: if (context == 'settings') {
7846: if (dosettings == 1) {
1.538 raeburn 7847: targetform.changeparms.value=param;
7848: targetform.submit();
7849: }
1.537 raeburn 7850: }
1.539 raeburn 7851: if (context == 'actions') {
7852: if (doaction == 1) {
7853: targetform.cmd.value=param+'_'+index;
7854: targetform.folderpath.value=folderpath;
7855: targetform.markcopy.value=idx+':'+param;
7856: targetform.copyfolder.value=folder+'.'+container;
7857: if (param == 'remove') {
1.603 raeburn 7858: var doremove = 0;
7859: if (skip_confirm) {
7860: if (confirm_removal) {
7861: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7862: doremove = 1;
7863: }
7864: } else {
7865: doremove = 1;
7866: }
7867: } else {
7868: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7869: doremove = 1;
7870: }
7871: }
7872: if (doremove) {
1.539 raeburn 7873: targetform.markcopy.value='';
7874: targetform.copyfolder.value='';
7875: targetform.submit();
7876: }
7877: }
7878: if (param == 'cut') {
1.594 damieng 7879: 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 7880: targetform.submit();
7881: return;
7882: }
7883: }
7884: if (param == 'copy') {
7885: targetform.submit();
7886: return;
7887: }
7888: targetform.markcopy.value='';
7889: targetform.copyfolder.value='';
7890: targetform.cmd.value='';
7891: targetform.folderpath.value='';
7892: return;
7893: } else {
7894: if (document.getElementById(param+'_'+idx)) {
7895: item = document.getElementById(param+'_'+idx);
7896: if (item.type == 'checkbox') {
7897: if (item.checked) {
7898: item.checked = false;
7899: } else {
7900: item.checked = true;
7901: singleCheck(item,idx,param);
7902: }
7903: }
7904: }
7905: }
7906: }
1.537 raeburn 7907: return;
7908: }
7909:
1.538 raeburn 7910: function singleCheck(caller,idx,action) {
7911: actions = new Array('cut','copy','remove');
7912: if (caller.checked) {
7913: for (var i=0; i<actions.length; i++) {
7914: if (actions[i] != action) {
7915: if (document.getElementById(actions[i]+'_'+idx)) {
7916: if (document.getElementById(actions[i]+'_'+idx).checked) {
7917: document.getElementById(actions[i]+'_'+idx).checked = false;
7918: }
1.537 raeburn 7919: }
7920: }
7921: }
1.478 raeburn 7922: }
1.537 raeburn 7923: return;
1.478 raeburn 7924: }
7925:
1.334 muellerd 7926: function unselectInactive(nav) {
1.335 ehlerst 7927: currentNav = document.getElementById(nav);
7928: currentLis = currentNav.getElementsByTagName('LI');
7929: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7930: if (currentLis[i].className == 'goback') {
7931: currentLis[i].className = 'goback';
7932: } else {
7933: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7934: currentLis[i].className = 'right';
1.472 raeburn 7935: } else {
1.374 tempelho 7936: currentLis[i].className = 'i';
1.472 raeburn 7937: }
7938: }
1.335 ehlerst 7939: }
1.332 tempelho 7940: }
7941:
1.334 muellerd 7942: function hideAll(current, nav, data) {
1.335 ehlerst 7943: unselectInactive(nav);
1.570 raeburn 7944: if (current) {
7945: if (current.className == 'right'){
7946: current.className = 'right active'
7947: } else {
7948: current.className = 'active';
7949: }
1.374 tempelho 7950: }
1.335 ehlerst 7951: currentData = document.getElementById(data);
7952: currentDivs = currentData.getElementsByTagName('DIV');
7953: for (i = 0; i < currentDivs.length; i++) {
7954: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7955: currentDivs[i].style.display = 'none';
1.330 tempelho 7956: }
7957: }
1.335 ehlerst 7958: }
1.330 tempelho 7959:
1.374 tempelho 7960: function openTabs(pageId) {
7961: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7962: if(tabnav.length > 2 ){
1.389 tempelho 7963: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7964: currentLis = currentNav.getElementsByTagName('LI');
7965: for(i = 0; i< currentLis.length; i++){
7966: if(currentLis[i].className == 'active') {
1.375 tempelho 7967: funcString = currentLis[i].onclick.toString();
7968: tab = funcString.split('"');
1.420 onken 7969: if(tab.length < 2) {
7970: tab = funcString.split("'");
7971: }
1.375 tempelho 7972: currentData = document.getElementById(tab[1]);
7973: currentData.style.display = 'block';
1.374 tempelho 7974: }
7975: }
7976: }
7977: }
7978:
1.334 muellerd 7979: function showPage(current, pageId, nav, data) {
1.570 raeburn 7980: currstate = current.className;
1.334 muellerd 7981: hideAll(current, nav, data);
1.375 tempelho 7982: openTabs(pageId);
1.334 muellerd 7983: unselectInactive(nav);
1.570 raeburn 7984: if ((currstate == 'active') || (currstate == 'right active')) {
7985: if (currstate == 'active') {
7986: current.className = '';
7987: } else {
7988: current.className = 'right';
7989: }
7990: activeTab = '';
7991: toggleUpload();
7992: toggleMap();
1.606 raeburn 7993: toggleCrsRes();
7994: toggleImportCrsres();
1.570 raeburn 7995: resize_scrollbox('contentscroll','1','0');
7996: return;
7997: } else {
7998: current.className = 'active';
7999: }
1.330 tempelho 8000: currentData = document.getElementById(pageId);
8001: currentData.style.display = 'block';
1.458 raeburn 8002: activeTab = pageId;
1.501 raeburn 8003: toggleUpload();
1.503 raeburn 8004: toggleMap();
1.606 raeburn 8005: toggleCrsRes();
8006: toggleImportCrsres();
1.433 raeburn 8007: if (nav == 'mainnav') {
8008: var storedpath = "$docs_folderpath";
1.434 raeburn 8009: var storedpage = "$main_container_page";
1.433 raeburn 8010: var reg = new RegExp("^supplemental");
8011: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8012: if (storedpage == 1) {
8013: document.simpleedit.folderpath.value = '';
8014: document.uploaddocument.folderpath.value = '';
8015: } else {
8016: if (reg.test(storedpath)) {
8017: document.simpleedit.folderpath.value = '$toplevelmain';
8018: document.uploaddocument.folderpath.value = '$toplevelmain';
8019: document.newext.folderpath.value = '$toplevelmain';
8020: } else {
8021: document.simpleedit.folderpath.value = storedpath;
8022: document.uploaddocument.folderpath.value = storedpath;
8023: document.newext.folderpath.value = storedpath;
8024: }
1.433 raeburn 8025: }
8026: } else {
1.434 raeburn 8027: if (reg.test(storedpath)) {
8028: document.simpleedit.folderpath.value = storedpath;
8029: document.supuploaddocument.folderpath.value = storedpath;
8030: document.supnewext.folderpath.value = storedpath;
8031: } else {
1.433 raeburn 8032: document.simpleedit.folderpath.value = '$toplevelsupp';
8033: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8034: document.supnewext.folderpath.value = '$toplevelsupp';
8035: }
8036: }
8037: }
1.485 raeburn 8038: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8039: return false;
8040: }
1.329 droeschl 8041:
1.472 raeburn 8042: function toContents(jumpto) {
8043: var newurl = '$backtourl';
1.525 raeburn 8044: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8045: newurl = newurl+'?postdata='+jumpto;
8046: }
8047: location.href=newurl;
8048: }
8049:
1.538 raeburn 8050: function togglePick(caller,value) {
8051: var disp = 'none';
8052: if (document.getElementById('multi'+caller)) {
8053: var curr = document.getElementById('multi'+caller).style.display;
8054: if (value == 1) {
8055: disp='block';
8056: }
8057: if (curr == disp) {
8058: return;
8059: }
8060: document.getElementById('multi'+caller).style.display=disp;
8061: if (value == 1) {
1.594 damieng 8062: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8063: } else {
8064: document.getElementById('more'+caller).innerHTML = '';
8065: }
8066: if (caller == 'actions') {
8067: setClass(value);
8068: setBoxes(value);
8069: }
8070: }
8071: var showButton = multiSettings();
8072: if (showButton != 1) {
8073: showButton = multiActions();
8074: }
8075: if (document.getElementById('multisave')) {
8076: if (showButton == 1) {
8077: document.getElementById('multisave').style.display='block';
8078: } else {
8079: document.getElementById('multisave').style.display='none';
8080: }
8081: }
8082: resize_scrollbox('contentscroll','1','1');
8083: return;
8084: }
8085:
8086: function toggleCheckUncheck(caller,more) {
8087: if (more == 1) {
1.594 damieng 8088: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8089: document.getElementById('allfields'+caller).style.display='block';
8090: } else {
1.594 damieng 8091: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8092: document.getElementById('allfields'+caller).style.display='none';
8093: }
8094: resize_scrollbox('contentscroll','1','1');
8095: }
8096:
8097: function multiSettings() {
8098: var inuse = 0;
8099: var settingsform = document.togglemultsettings;
8100: if (settingsform.showmultpick.length > 1) {
8101: for (var i=0; i<settingsform.showmultpick.length; i++) {
8102: if (settingsform.showmultpick[i].checked) {
8103: if (settingsform.showmultpick[i].value == 1) {
8104: inuse = 1;
8105: }
8106: }
8107: }
8108: }
8109: return inuse;
8110: }
8111:
8112: function multiActions() {
8113: var inuse = 0;
8114: var actionsform = document.togglemultactions;
8115: if (actionsform.showmultpick.length > 1) {
8116: for (var i=0; i<actionsform.showmultpick.length; i++) {
8117: if (actionsform.showmultpick[i].checked) {
8118: if (actionsform.showmultpick[i].value == 1) {
8119: inuse = 1;
8120: }
8121: }
8122: }
8123: }
8124: return inuse;
8125: }
8126:
8127: function checkSubmits() {
8128: var numchanges = 0;
8129: var form = document.saveactions;
8130: var doactions = multiActions();
1.542 raeburn 8131: var cutwarnings = 0;
8132: var remwarnings = 0;
1.603 raeburn 8133: var removalinfo = 0;
1.538 raeburn 8134: if (doactions == 1) {
8135: var remidxlist = document.cumulativeactions.allremoveidx.value;
8136: if ((remidxlist != '') && (remidxlist != null)) {
8137: var remidxs = remidxlist.split(',');
8138: for (var i=0; i<remidxs.length; i++) {
8139: if (document.getElementById('remove_'+remidxs[i])) {
8140: if (document.getElementById('remove_'+remidxs[i]).checked) {
8141: form.multiremove.value += remidxs[i]+',';
8142: numchanges ++;
1.542 raeburn 8143: if (document.getElementById('skip_remove_'+remidxs[i])) {
8144: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8145: remwarnings ++;
8146: }
8147: }
1.603 raeburn 8148: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8149: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8150: removalinfo ++;
8151: }
8152: }
1.537 raeburn 8153: }
8154: }
1.538 raeburn 8155: }
8156: }
8157: var cutidxlist = document.cumulativeactions.allcutidx.value;
8158: if ((cutidxlist != '') && (cutidxlist != null)) {
8159: var cutidxs = cutidxlist.split(',');
8160: for (var i=0; i<cutidxs.length; i++) {
8161: if (document.getElementById('cut_'+cutidxs[i])) {
8162: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8163: form.multicut.value += cutidxs[i]+',';
8164: numchanges ++;
1.542 raeburn 8165: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8166: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8167: cutwarnings ++;
8168: }
8169: }
1.537 raeburn 8170: }
8171: }
8172: }
8173: }
1.538 raeburn 8174: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8175: if ((copyidxlist != '') && (copyidxlist != null)) {
8176: var copyidxs = copyidxlist.split(',');
8177: for (var i=0; i<copyidxs.length; i++) {
8178: if (document.getElementById('copy_'+copyidxs[i])) {
8179: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8180: form.multicopy.value += copyidxs[i]+',';
8181: numchanges ++;
8182: }
8183: }
8184: }
8185: }
8186: if (numchanges > 0) {
8187: form.multichange.value = numchanges;
8188: }
1.537 raeburn 8189: }
1.538 raeburn 8190: var dosettings = multiSettings();
1.543 raeburn 8191: var haschanges = 0;
1.538 raeburn 8192: if (dosettings == 1) {
8193: form.allencrypturl.value = '';
8194: form.allhiddenresource.value = '';
1.543 raeburn 8195: form.changeparms.value = 'all';
8196: var patt=new RegExp(",\$");
1.538 raeburn 8197: var allidxlist = document.cumulativesettings.allidx.value;
8198: if ((allidxlist != '') && (allidxlist != null)) {
8199: var allidxs = allidxlist.split(',');
8200: if (allidxs.length > 1) {
8201: for (var i=0; i<allidxs.length; i++) {
8202: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8203: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8204: form.allhiddenresource.value += allidxs[i]+',';
8205: }
8206: }
8207: if (document.getElementById('encrypturl_'+allidxs[i])) {
8208: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8209: form.allencrypturl.value += allidxs[i]+',';
8210: }
8211: }
8212: }
1.543 raeburn 8213: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8214: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8215: }
1.538 raeburn 8216: }
8217: form.allrandompick.value = '';
8218: form.allrandomorder.value = '';
8219: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8220: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8221: var allmapidxs = allmapidxlist.split(',');
8222: for (var i=0; i<allmapidxs.length; i++) {
8223: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8224: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8225: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8226: if ((randompick.checked) && (rpicknum.value != '')) {
8227: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8228: }
8229: if (randorder.checked) {
8230: form.allrandomorder.value += allmapidxs[i]+',';
8231: }
1.537 raeburn 8232: }
1.543 raeburn 8233: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8234: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8235: }
8236: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8237: haschanges = 1;
8238: }
8239: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8240: haschanges = 1;
8241: }
8242: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8243: haschanges = 1;
8244: }
8245: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8246: haschanges = 1;
1.537 raeburn 8247: }
8248: }
1.543 raeburn 8249: if (doactions == 1) {
1.542 raeburn 8250: if (numchanges > 0) {
1.603 raeburn 8251: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8252: if (remwarnings > 0) {
1.594 damieng 8253: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8254: return false;
8255: }
8256: }
1.603 raeburn 8257: if (removalinfo > 0) {
8258: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8259: return false;
8260: }
8261: }
1.542 raeburn 8262: if (cutwarnings > 0) {
1.594 damieng 8263: 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 8264: return false;
8265: }
8266: }
8267: }
8268: form.submit();
8269: return true;
1.543 raeburn 8270: }
8271: }
8272: if (dosettings == 1) {
8273: if (haschanges == 1) {
1.542 raeburn 8274: form.submit();
8275: return true;
8276: }
1.543 raeburn 8277: }
8278: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8279: alert("$js_lt{'noor'}");
1.543 raeburn 8280: } else {
8281: if (dosettings == 1) {
1.594 damieng 8282: alert("$js_lt{'noch'}");
1.543 raeburn 8283: } else {
1.594 damieng 8284: alert("$js_lt{'noac'}");
1.543 raeburn 8285: }
8286: }
1.538 raeburn 8287: return false;
8288: }
8289:
8290: function setClass(value) {
8291: var cutclass = 'LC_docs_cut';
8292: var copyclass = 'LC_docs_copy';
8293: var removeclass = 'LC_docs_remove';
8294: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8295: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8296: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8297: var links = document.getElementsByTagName('a');
8298: for (var i=0; i<links.length; i++) {
8299: var classes = links[i].className;
8300: if (cutreg.test(classes)) {
8301: links[i].className = cutclass;
8302: if (value == 1) {
8303: links[i].className += " LC_menubuttons_link";
8304: }
8305: } else {
8306: if (copyreg.test(classes)) {
8307: links[i].className = copyclass;
8308: if (value == 1) {
8309: links[i].className += " LC_menubuttons_link";
8310: }
8311: } else {
8312: if (removereg.test(classes)) {
8313: links[i].className = removeclass;
8314: if (value == 1) {
8315: links[i].className += " LC_menubuttons_link";
8316: }
8317: }
8318: }
8319: }
8320: }
8321: return;
1.537 raeburn 8322: }
8323:
1.538 raeburn 8324: function setBoxes(value) {
8325: var remidxlist = document.cumulativeactions.allremoveidx.value;
8326: if ((remidxlist != '') && (remidxlist != null)) {
8327: var remidxs = remidxlist.split(',');
8328: for (var i=0; i<remidxs.length; i++) {
8329: if (document.getElementById('remove_'+remidxs[i])) {
8330: var item = document.getElementById('remove_'+remidxs[i]);
8331: if (value == 1) {
8332: item.className = 'LC_docs_remove';
8333: } else {
8334: item.className = 'LC_hidden';
8335: }
8336: }
8337: }
8338: }
8339: var cutidxlist = document.cumulativeactions.allcutidx.value;
8340: if ((cutidxlist != '') && (cutidxlist != null)) {
8341: var cutidxs = cutidxlist.split(',');
8342: for (var i=0; i<cutidxs.length; i++) {
8343: if (document.getElementById('cut_'+cutidxs[i])) {
8344: var item = document.getElementById('cut_'+cutidxs[i]);
8345: if (value == 1) {
8346: item.className = 'LC_docs_cut';
8347: } else {
8348: item.className = 'LC_hidden';
8349: }
8350: }
1.537 raeburn 8351: }
8352: }
1.538 raeburn 8353: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8354: if ((copyidxlist != '') && (copyidxlist != null)) {
8355: var copyidxs = copyidxlist.split(',');
8356: for (var i=0; i<copyidxs.length; i++) {
8357: if (document.getElementById('copy_'+copyidxs[i])) {
8358: var item = document.getElementById('copy_'+copyidxs[i]);
8359: if (value == 1) {
8360: item.className = 'LC_docs_copy';
8361: } else {
8362: item.className = 'LC_hidden';
8363: }
8364: }
1.537 raeburn 8365: }
8366: }
8367: return;
8368: }
8369:
1.606 raeburn 8370: function validImportCrsRes() {
8371: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8372: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8373: if ((fname == '') || (fname == null)) {
8374: alert("$js_lt{'nofi'}");
8375: return false;
8376: }
8377: var url = '/res/$coursedom/$coursenum/';
8378: if (path && path != '/') {
8379: url += path+'/';
8380: }
8381: if (fname != '') {
8382: url += fname;
8383: }
8384: var title = document.crsresimportform.crsrestitle.value;
8385: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8386: return true;
8387: }
8388:
8389: function validateNewRes(caller) {
8390: if (caller == 'single') {
8391: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8392: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8393: var resname = document.courseresform.newresourcename.value;
8394: }
8395: }
8396:
1.611 raeburn 8397: ENDSCRIPT
1.329 droeschl 8398: }
1.457 raeburn 8399:
1.483 raeburn 8400: sub history_tab_js {
8401: return <<"ENDHIST";
8402: function toggleHistoryDisp(choice) {
8403: document.docslogform.docslog.value = choice;
8404: document.docslogform.submit();
8405: return;
8406: }
8407:
8408: ENDHIST
8409: }
8410:
1.484 raeburn 8411: sub inject_data_js {
8412: return <<ENDINJECT;
8413:
8414: function injectData(current, hiddenField, name, value) {
8415: currentElement = document.getElementById(hiddenField);
8416: currentElement.name = name;
8417: currentElement.value = value;
8418: current.submit();
8419: }
8420:
8421: ENDINJECT
8422: }
8423:
8424: sub dump_switchserver_js {
8425: my @hosts = @_;
1.594 damieng 8426: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8427: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8428: swit => 'Switch server?',
1.594 damieng 8429: );
8430: my %html_js_lt = &Apache::lonlocal::texthash(
8431: swit => 'Switch server?',
1.568 raeburn 8432: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8433: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8434: chos => 'Choose server',
8435: );
1.594 damieng 8436: &js_escape(\%js_lt);
8437: &html_escape(\%html_js_lt);
8438: &js_escape(\%html_js_lt);
1.484 raeburn 8439: my $role = $env{'request.role'};
8440: my $js = <<"ENDSWJS";
8441: <script type="text/javascript">
8442: function write_switchserver() {
8443: var server;
8444: if (document.setserver.posshosts.length > 0) {
8445: for (var i=0; i<document.setserver.posshosts.length; i++) {
8446: if (document.setserver.posshosts[i].checked) {
8447: server = document.setserver.posshosts[i].value;
8448: }
8449: }
8450: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8451: }
8452: window.close();
8453: }
8454: </script>
8455:
8456: ENDSWJS
8457:
8458: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8459: {'only_body' => 1,
8460: 'js_ready' => 1,});
8461: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8462:
8463: my $hostpicker;
8464: my $count = 0;
8465: foreach my $host (sort(@hosts)) {
8466: my $checked;
8467: if ($count == 0) {
8468: $checked = ' checked="checked"';
8469: }
8470: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8471: $host.'"'.$checked.' />'.$host.'</label> ';
8472: $count++;
8473: }
8474:
8475: return <<"ENDSWITCHJS";
8476:
8477: function dump_needs_switchserver(url) {
8478: if (url!='' && url!= null) {
1.594 damieng 8479: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8480: go(url);
8481: }
8482: }
8483: return;
8484: }
8485:
8486: function choose_switchserver_window() {
8487: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8488: newWindow.document.open();
8489: newWindow.document.writeln('$startpage');
1.594 damieng 8490: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8491: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8492: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8493: '<form name="setserver" method="post" action="" \\/>\\n'+
8494: '$hostpicker\\n'+
8495: '<br \\/><br \\/>\\n'+
1.594 damieng 8496: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8497: 'onclick="write_switchserver();" \\/>\\n'+
8498: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8499: newWindow.document.writeln('$endpage');
8500: newWindow.document.close();
8501: newWindow.focus();
8502: }
8503:
8504: ENDSWITCHJS
8505: }
8506:
8507: sub makedocslogform {
8508: my ($formelems,$docslog) = @_;
8509: return <<"LOGSFORM";
8510: <form action="/adm/coursedocs" method="post" name="docslogform">
8511: <input type="hidden" name="docslog" value="$docslog" />
8512: $formelems
8513: </form>
8514: LOGSFORM
8515: }
8516:
8517: sub makesimpleeditform {
8518: my ($formelems) = @_;
8519: return <<"SIMPFORM";
8520: <form name="simpleedit" method="post" action="/adm/coursedocs">
8521: <input type="hidden" name="importdetail" value="" />
8522: $formelems
8523: </form>
8524: SIMPFORM
8525: }
8526:
1.606 raeburn 8527: sub makenewproblem {
8528: my ($r,$coursedom,$coursenum) = @_;
8529: # Creating a new problem
8530: my ($redirect,$error);
8531: if ($env{'form.authorrole'}) {
8532: my ($newsubdir,$filename);
8533: if ($env{'form.newsubdir'}) {
8534: if ($env{'form.newsubdirname'} ne '') {
8535: $newsubdir = $env{'form.newsubdirname'};
8536: }
8537: }
8538: if ($env{'form.newresourcename'}) {
8539: $filename = $env{'form.newresourcename'};
8540: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8541: $filename =~ s/`//g;
8542: $filename =~ s{/\.\./}{_}g;
8543: $filename =~ s/\.+/./g;
8544: $filename =~ s{/+}{_}g;
8545: if ($filename ne '') {
8546: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8547: if (($ext) && ($ext ne '.problem')) {
8548: $filename = $name.'.problem';
8549: } elsif ($ext eq '') {
8550: $filename .= '.problem';
8551: }
8552: my $docroot = $r->dir_config('lonDocRoot');
8553: my @ids=&Apache::lonnet::current_machine_ids();
8554: if ($env{'form.authorrole'} eq 'author') {
8555: if ($env{'user.author'}) {
8556: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8557: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8558: my $path = $docroot.$url;
8559: my $subdir = $env{'form.authorpath'};
8560: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8561: }
8562: }
8563: } elsif ($env{'form.authorrole'} eq 'course') {
8564: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8565: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8566: my $url = "/priv/$coursedom/$coursenum";
8567: my $path=$docroot.$url;
8568: my $subdir = $env{'form.authorpath'};
8569: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8570: if ($redirect) {
8571: my $rightsfile = 'default.rights';
8572: my $sourcerights = "$path/$rightsfile";
8573: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8574: my $now = time;
8575: if (!-e $sourcerights) {
8576: my $cid = $coursedom.'_'.$coursenum;
8577: if (open(my $fh,">$sourcerights")) {
8578: print $fh <<END;
8579: <accessrule effect="deny" realm="" type="course" role="" />
8580: <accessrule effect="allow" realm="$cid" type="course" role="" />
8581: END
8582: close($fh);
8583: }
8584: }
8585: if (!-e "$sourcerights.meta") {
8586: if (open(my $fh,">$sourcerights.meta")) {
8587: my $author=$env{'environment.firstname'}.' '.
8588: $env{'environment.middlename'}.' '.
8589: $env{'environment.lastname'}.' '.
8590: $env{'environment.generation'};
8591: $author =~ s/\s+$//;
8592: print $fh <<"END";
8593:
8594: <abstract></abstract>
8595: <author>$author</author>
8596: <authorspace>$coursenum:$coursedom</authorspace>
8597: <copyright>private</copyright>
8598: <creationdate>$now</creationdate>
8599: <customdistributionfile></customdistributionfile>
8600: <dependencies></dependencies>
8601: <domain>$coursedom</domain>
8602: <highestgradelevel>0</highestgradelevel>
8603: <keywords></keywords>
8604: <language>notset </language>
8605: <lastrevisiondate>$now</lastrevisiondate>
8606: <lowestgradelevel>0</lowestgradelevel>
8607: <mime>rights</mime>
8608: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8609: <notes></notes>
8610: <obsolete></obsolete>
8611: <obsoletereplacement></obsoletereplacement>
8612: <owner>$coursenum:$coursedom</owner>
8613: <rule>deny:::course,allow:$cid::course</rule>
8614: <sourceavail></sourceavail>
8615: <standards></standards>
8616: <subject></subject>
8617: <title></title>
8618: END
8619: close($fh);
8620: }
8621: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8622: if (!-e "$docroot/res/$coursedom") {
8623: mkdir("$docroot/res/$coursedom",0755);
8624: }
8625: if (!-e "$docroot/res/$coursedom/$coursenum") {
8626: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8627: }
8628: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8629: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8630: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8631: }
8632: }
8633: }
8634: if ($env{'form.newresourceadd'}) {
8635: my $template = $env{'form.template'};
8636: my $source = $docroot.$redirect;
8637: my $target = $redirect;
8638: $target =~ s{^/priv/}{/res/};
8639: $target = $docroot.$target;
8640: if (!-e $source) {
8641: my $copyfrom;
8642: if ($template) {
8643: my %templates;
8644: my @files = &Apache::lonhomework::get_template_list('problem');
8645: foreach my $poss (@files) {
8646: if (ref($poss) eq 'ARRAY') {
8647: if ($template eq $poss->[0]) {
8648: $templates{$template} = 1;
8649: last;
8650: }
8651: }
8652: }
8653: if ($templates{$template}) {
8654: $copyfrom = $template;
8655: }
8656: }
8657: unless ($copyfrom) {
8658: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8659: }
8660: &File::Copy::copy($copyfrom,$source);
8661: }
8662: if (!-e "$source.meta") {
8663: my $cid = $coursedom.'_'.$coursenum;
8664: my $now = time;
8665: if (open(my $fh,">$source.meta")) {
8666: my $author=$env{'environment.firstname'}.' '.
8667: $env{'environment.middlename'}.' '.
8668: $env{'environment.lastname'}.' '.
8669: $env{'environment.generation'};
8670: $author =~ s/\s+$//;
8671: my $title = $env{'form.newresourcetitle'};
8672: $title =~ s/^\s+|\s+$//g;
8673: print $fh <<END;
8674:
8675: <abstract></abstract>
8676: <author>$author</author>
8677: <authorspace>$coursenum:$coursedom</authorspace>
8678: <copyright>custom</copyright>
8679: <creationdate>$now</creationdate>
8680: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8681: <dependencies></dependencies>
8682: <domain>$coursedom</domain>
8683: <highestgradelevel>0</highestgradelevel>
8684: <keywords></keywords>
8685: <language>notset </language>
8686: <lastrevisiondate>$now</lastrevisiondate>
8687: <lowestgradelevel>0</lowestgradelevel>
8688: <mime>problem</mime>
8689: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8690: <notes></notes>
8691: <obsolete></obsolete>
8692: <obsoletereplacement></obsoletereplacement>
8693: <owner>$coursenum:$coursedom</owner>
8694: <sourceavail></sourceavail>
8695: <standards></standards>
8696: <subject></subject>
8697: <title>$title</title>
8698: END
8699: close($fh);
8700: }
8701: }
8702: }
8703: }
8704: }
8705: } else {
8706: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8707: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8708: if (grep(/^\Q$rolehome\E$/,@ids)) {
8709: my $now = time;
8710: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8711: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8712: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8713: my $url = "/priv/$audom/$auname";
8714: my $path = $r->dir_config('lonDocRoot').$url;
8715: my $subdir = $env{'form.authorpath'};
8716: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8717: }
8718: }
8719: }
8720: }
8721: }
8722: }
8723: }
8724: return ($redirect,$error);
8725: }
8726:
8727: sub finishnewprob {
8728: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8729: unless (-d $path) {
8730: unless (mkdir($path,02770)) {
8731: return;
8732: }
8733: }
1.606 raeburn 8734: my $redirect;
8735: if ($subdir ne '/') {
8736: $subdir = &cleandir($subdir);
8737: if (($subdir ne '') && (-d "$path/$subdir")) {
8738: $path .= "/$subdir";
8739: $url .= "/$subdir";
8740: }
8741: }
8742: my $dest;
8743: if ($newsubdir ne '') {
8744: $newsubdir = &cleandir($newsubdir);
8745: }
8746: if ($newsubdir ne '') {
8747: if (-d "$path/$newsubdir") {
8748: $dest = "$path/$newsubdir/$filename";
8749: } else {
8750: my $dirok;
8751: unless (-e "$path/$newsubdir") {
8752: if (mkdir("$path/$newsubdir",02770)) {
8753: if (chmod(02770,"$path/$newsubdir")) {
8754: $dirok = 1;
8755: }
8756: }
8757: }
8758: if ($dirok) {
8759: $dest = "$path/$newsubdir/$filename";
8760: }
8761: }
8762: if (($dest ne '') && (!-e $dest)) {
8763: $redirect = "$url/$newsubdir/$filename";
8764: }
8765: } else {
8766: $dest = "$path/$filename";
8767: if (($dest ne '') && (!-e $dest)) {
8768: $redirect = "$url/$filename";
8769: }
8770: }
8771: return $redirect;
8772: }
8773:
8774: sub cleandir {
8775: my ($dir) = @_;
8776: $dir =~ s/^\s+//;
8777: $dir =~ s/\s+$//;
8778: $dir =~ s/\.+//g;
8779: $dir =~ s/[\#\?&%\":]//g;
8780: return $dir;
8781: }
8782:
1.329 droeschl 8783: 1;
8784: __END__
8785:
8786:
8787: =head1 NAME
8788:
8789: Apache::londocs.pm
8790:
8791: =head1 SYNOPSIS
8792:
8793: This is part of the LearningOnline Network with CAPA project
8794: described at http://www.lon-capa.org.
8795:
8796: =head1 SUBROUTINES
8797:
8798: =over
8799:
8800: =item %help=()
8801:
8802: Available help topics
8803:
8804: =item mapread()
8805:
1.344 bisitz 8806: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8807: @order and @resources, determines status
8808: sets @order - pointer to resources in right order
8809: sets @resources - array with the resources with correct idx
8810:
8811: =item authorhosts()
8812:
8813: Return hash with valid author names
8814:
8815: =item clean()
8816:
8817: =item dumpcourse()
8818:
8819: Actually dump course
8820:
8821: =item group_import()
8822:
8823: Imports the given (name, url) resources into the course
8824: coursenum, coursedom, and folder must precede the list
8825:
8826: =item breadcrumbs()
8827:
8828: =item log_docs()
8829:
8830: =item docs_change_log()
8831:
8832: =item update_paste_buffer()
8833:
8834: =item print_paste_buffer()
8835:
8836: =item do_paste_from_buffer()
8837:
1.538 raeburn 8838: =item do_buffer_empty()
8839:
8840: =item clear_from_buffer()
8841:
1.492 raeburn 8842: =item get_newmap_url()
8843:
8844: =item dbcopy()
8845:
8846: =item uniqueness_check()
8847:
8848: =item contained_map_check()
8849:
8850: =item url_paste_fixups()
8851:
8852: =item apply_fixups()
8853:
8854: =item copy_dependencies()
8855:
1.329 droeschl 8856: =item update_parameter()
8857:
8858: =item handle_edit_cmd()
8859:
8860: =item editor()
8861:
8862: =item process_file_upload()
8863:
8864: =item process_secondary_uploads()
8865:
8866: =item is_supplemental_title()
8867:
8868: =item entryline()
8869:
8870: =item tiehash()
8871:
8872: =item untiehash()
8873:
8874: =item checkonthis()
8875:
8876: check on this
8877:
8878: =item verifycontent()
8879:
8880: Verify Content
8881:
1.636 raeburn 8882: =item devalidateversioncache()
8883:
8884: =item checkversions()
1.329 droeschl 8885:
8886: Check Versions
8887:
8888: =item mark_hash_old()
8889:
8890: =item is_hash_old()
8891:
8892: =item changewarning()
8893:
8894: =item init_breadcrumbs()
8895:
8896: Breadcrumbs for special functions
8897:
1.484 raeburn 8898: =item create_list_elements()
8899:
8900: =item create_form_ul()
8901:
8902: =item startContentScreen()
8903:
8904: =item endContentScreen()
8905:
8906: =item supplemental_base()
8907:
8908: =item embedded_form_elems()
8909:
8910: =item embedded_destination()
8911:
8912: =item return_to_editor()
8913:
8914: =item decompression_info()
8915:
8916: =item decompression_phase_one()
8917:
8918: =item decompression_phase_two()
8919:
8920: =item remove_archive()
8921:
8922: =item generate_admin_menu()
8923:
8924: =item generate_edit_table()
8925:
8926: =item editing_js()
8927:
8928: =item history_tab_js()
8929:
8930: =item inject_data_js()
8931:
8932: =item dump_switchserver_js()
8933:
1.485 raeburn 8934: =item resize_scrollbox_js()
1.484 raeburn 8935:
8936: =item makedocslogform()
8937:
1.485 raeburn 8938: =item makesimpleeditform()
8939:
1.329 droeschl 8940: =back
8941:
8942: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>