Annotation of loncom/interface/londocs.pm, revision 1.646
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.646 ! raeburn 4: # $Id: londocs.pm,v 1.645 2017/12/18 22:56:45 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/) {
680: delete($toolhash{'gradable'});
681: }
1.598 raeburn 682: if (ref($ltitoolsref) eq 'HASH') {
683: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
1.643 raeburn 684: my @deleted;
1.598 raeburn 685: $toolhash{'id'} = $toolid;
1.628 raeburn 686: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
687: ($toolhash{'target'} eq 'window')) {
1.604 raeburn 688: if ($toolhash{'target'} eq 'window') {
689: foreach my $item ('width','height') {
690: $toolhash{$item} =~ s/^\s+//;
691: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 692: if ($toolhash{$item} =~ /\D/) {
693: delete($toolhash{$item});
694: if ($residx) {
695: if ($toolsettings{$item}) {
696: push(@deleted,$item);
697: }
698: }
699: }
1.604 raeburn 700: }
701: }
702: } elsif ($residx) {
703: $toolhash{'target'} = $toolsettings{'target'};
704: if ($toolhash{'target'} eq 'window') {
1.630 raeburn 705: foreach my $item ('width','height') {
1.624 raeburn 706: $toolhash{$item} = $toolsettings{$item};
707: }
1.604 raeburn 708: }
709: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
710: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
711: if ($toolhash{'target'} eq 'window') {
712: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
713: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
714: }
715: }
1.598 raeburn 716: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 717: foreach my $item ('width','height','linktext','explanation') {
718: delete($toolhash{$item});
719: if ($residx) {
720: if ($toolsettings{$item}) {
721: push(@deleted,$item);
722: }
1.604 raeburn 723: }
724: }
1.628 raeburn 725: } elsif ($toolhash{'target'} eq 'tab') {
726: foreach my $item ('width','height') {
727: delete($toolhash{$item});
728: if ($residx) {
729: if ($toolsettings{$item}) {
730: push(@deleted,$item);
731: }
732: }
733: }
1.604 raeburn 734: }
735: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 736: foreach my $item ('label','title','linktext','explanation') {
737: my $crsitem;
738: if (($item eq 'label') || ($item eq 'title')) {
739: $crsitem = 'crs'.$item;
740: } else {
741: $crsitem = $item;
742: }
1.604 raeburn 743: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 744: $toolhash{$crsitem} =~ s/^\s+//;
745: $toolhash{$crsitem} =~ s/\s+$//;
746: if ($toolhash{$crsitem} eq '') {
747: delete($toolhash{$crsitem});
1.604 raeburn 748: }
749: } else {
1.624 raeburn 750: delete($toolhash{$crsitem});
1.604 raeburn 751: }
1.624 raeburn 752: if (($residx) && (exists($toolsettings{$crsitem}))) {
753: unless (exists($toolhash{$crsitem})) {
754: push(@deleted,$crsitem);
1.604 raeburn 755: }
756: }
1.598 raeburn 757: }
758: }
1.643 raeburn 759: if ($toolhash{'passback'}) {
760: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
761: $toolhash{'gradesecret'} = $gradesecret;
762: $toolhash{'gradesecretdate'} = time;
763: }
764: if ($toolhash{'roster'}) {
765: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
766: $toolhash{'rostersecret'} = $rostersecret;
767: $toolhash{'rostersecretdate'} = time;
768: }
1.645 raeburn 769: my $changegradable;
770: if (($residx) && ($folder =~ /^default/)) {
771: if (exists($toolsettings{'gradable'})) {
772: if (!exists($toolhash{'gradable'})) {
773: push(@deleted,'gradable');
774: $changegradable = 1;
775: }
776: } elsif (exists($toolhash{'gradable'})) {
777: $changegradable = 1;
778: }
779: }
1.598 raeburn 780: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 781: if ($putres eq 'ok') {
782: if (@deleted) {
783: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.645 raeburn 784: }
785: if (($changegradable) && ($folder =~ /^default/)) {
786: my $val;
787: if ($toolhash{'gradable'}) {
788: $val = 'yes';
789: } else {
790: $val = 'no';
791: }
792: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
793: 'string_yesno');
794: &remember_parms($residx,'gradable','set',$val);
795: }
796: } else {
797: return (&mt('Failed to save update to external tool.'),1);
1.604 raeburn 798: }
1.598 raeburn 799: }
800: }
801: }
1.529 raeburn 802: if (($caller eq 'londocs') &&
803: ($folder =~ /^default/)) {
1.534 raeburn 804: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 805: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
806: my $cid = $coursedom.'_'.$coursenum;
807: $allmaps =
808: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
809: $chome,$cid);
810: $donechk = 1;
811: }
812: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 813: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
814: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 815: $importuploaded = 1;
816: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
817: next if ($allmaps->{$url});
818: }
819: }
1.344 bisitz 820: if (!$residx
1.329 droeschl 821: || defined($LONCAPA::map::zombies[$residx])) {
822: $residx = &LONCAPA::map::getresidx($url,$residx);
823: push(@LONCAPA::map::order, $residx);
824: }
825: my $ext = 'false';
826: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
827: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 828: if ($name eq '') {
1.538 raeburn 829: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 830: }
831: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
832: my $filepath = $1;
833: my $fname = $name;
834: if ($fname =~ /^\W+$/) {
835: $fname = 'web';
836: } else {
837: $fname =~ s/\W/_/g;
838: }
1.599 damieng 839: if (length($fname) > 15) {
1.534 raeburn 840: $fname = substr($fname,0,14);
841: }
842: my $initialtext = &mt('Replace with your own content.');
843: my $newhtml = <<END;
1.545 raeburn 844: <html>
1.534 raeburn 845: <head>
846: <title>$name</title>
847: </head>
848: <body bgcolor="#ffffff">
849: $initialtext
850: </body>
851: </html>
852: END
853: $env{'form.output'}=$newhtml;
1.630 raeburn 854: my $result =
1.534 raeburn 855: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
856: 'output',
857: "$filepath/$residx/$fname.html");
858: if ($result =~ m{^/uploaded/}) {
859: $url = $result;
860: if ($filepath =~ /^supplemental/) {
861: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
862: $env{'user.domain'}.'___&&&___'.$name;
863: }
864: } else {
865: return (&mt('Failed to save new web page.'),1);
866: }
867: }
1.538 raeburn 868: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 869: $LONCAPA::map::resources[$residx] =
1.329 droeschl 870: join(':', ($name, $url, $ext, 'normal', 'res'));
871: }
872: }
1.529 raeburn 873: if ($importuploaded) {
874: my %import_errors;
875: my %updated = (
876: removefrommap => \%removefrommap,
877: removeparam => \%removeparam,
878: );
1.533 raeburn 879: my ($result,$msgsarray,$lockerror) =
880: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 881: if (keys(%import_errors) > 0) {
1.530 raeburn 882: $fixuperrors =
1.529 raeburn 883: '<p span class="LC_warning">'."\n".
884: &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".
885: '<ul>'."\n";
886: foreach my $key (sort(keys(%import_errors))) {
887: $fixuperrors .= '<li>'.$key.'</li>'."\n";
888: }
889: $fixuperrors .= '</ul></p>'."\n";
890: }
1.533 raeburn 891: if (ref($msgsarray) eq 'ARRAY') {
892: if (@{$msgsarray} > 0) {
893: $fixuperrors .= '<p class="LC_info">'.
894: join('<br />',@{$msgsarray}).
895: '</p>';
896: }
897: }
898: if ($lockerror) {
899: $fixuperrors .= '<p class="LC_error">'.
900: $lockerror.
901: '</p>';
902: }
1.529 raeburn 903: }
904: my ($errtext,$fatal) =
905: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 906: unless ($fatal) {
907: if ($folder =~ /^supplemental/) {
908: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 909: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
910: $folder.'.'.$container);
1.557 raeburn 911: }
912: }
1.529 raeburn 913: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 914: }
915:
916: sub log_docs {
1.494 raeburn 917: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 918: }
919:
920: {
921: my @oldresources=();
922: my @oldorder=();
923: my $parmidx;
924: my %parmaction=();
925: my %parmvalue=();
926: my $changedflag;
927:
928: sub snapshotbefore {
929: @oldresources=@LONCAPA::map::resources;
930: @oldorder=@LONCAPA::map::order;
931: $parmidx=undef;
932: %parmaction=();
933: %parmvalue=();
934: $changedflag=0;
935: }
936:
937: sub remember_parms {
938: my ($idx,$parameter,$action,$value)=@_;
939: $parmidx=$idx;
940: $parmaction{$parameter}=$action;
941: $parmvalue{$parameter}=$value;
942: $changedflag=1;
943: }
944:
945: sub log_differences {
946: my ($plain)=@_;
947: my %storehash=('folder' => $plain,
948: 'currentfolder' => $env{'form.folder'});
949: if ($parmidx) {
950: $storehash{'parameter_res'}=$oldresources[$parmidx];
951: foreach my $parm (keys(%parmaction)) {
952: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
953: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
954: }
955: }
956: my $maxidx=$#oldresources;
957: if ($#LONCAPA::map::resources>$#oldresources) {
958: $maxidx=$#LONCAPA::map::resources;
959: }
960: for (my $idx=0; $idx<=$maxidx; $idx++) {
961: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
962: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
963: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
964: $changedflag=1;
965: }
966: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
967: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
968: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
969: $changedflag=1;
970: }
971: }
972: $storehash{'maxidx'}=$maxidx;
973: if ($changedflag) { &log_docs(\%storehash); }
974: }
975: }
976:
977: sub docs_change_log {
1.611 raeburn 978: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 979: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 980: my $navmap;
1.483 raeburn 981: my $js = '<script type="text/javascript">'."\n".
982: '// <![CDATA['."\n".
983: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 984: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 985: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 986: &history_tab_js()."\n".
1.484 raeburn 987: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 988: '// ]]>'."\n".
989: '</script>'."\n";
1.484 raeburn 990: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
991: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 992: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 993: my %orderhash;
994: my $container='sequence';
995: my $pathitem;
1.519 raeburn 996: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 997: $container='page';
998: }
1.519 raeburn 999: my $folderpath=$env{'form.folderpath'};
1000: if ($folderpath eq '') {
1.617 raeburn 1001: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1002: }
1.617 raeburn 1003: undef($navmap);
1.519 raeburn 1004: $pathitem = '<input type="hidden" name="folderpath" value="'.
1005: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1006: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1007: my $jumpto = $readfile;
1008: $jumpto =~ s{^/}{};
1009: my $tid = 1;
1.489 raeburn 1010: if ($supplementalflag) {
1011: $tid = 2;
1012: }
1.630 raeburn 1013: my ($breadcrumbtrail) =
1.509 raeburn 1014: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1015: $r->print($breadcrumbtrail.
1016: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1017: $readfile));
1.329 droeschl 1018: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1019: $env{'course.'.$env{'request.course.id'}.'.domain'},
1020: $env{'course.'.$env{'request.course.id'}.'.num'});
1021:
1022: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1023:
1024: my %saveable_parameters = ('show' => 'scalar',);
1025: &Apache::loncommon::store_course_settings('docs_log',
1026: \%saveable_parameters);
1027: &Apache::loncommon::restore_course_settings('docs_log',
1028: \%saveable_parameters);
1029: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1030: # FIXME: internationalization seems wrong here
1.329 droeschl 1031: my %lt=('hiddenresource' => 'Resources hidden',
1032: 'encrypturl' => 'URL hidden',
1033: 'randompick' => 'Randomly pick',
1034: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1035: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1036: 'set' => 'set to',
1037: 'del' => 'deleted');
1.484 raeburn 1038: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1039: $pathitem."\n".
1040: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1041: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1042: $r->print('<div class="LC_left_float">'.
1043: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1044: &makedocslogform($filter,1).
1045: '</fieldset></div><br clear="all" />');
1.329 droeschl 1046: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1047: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1048: &mt('After').'</th>'.
1049: &Apache::loncommon::end_data_table_header_row());
1050: my $shown=0;
1051: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1052: if ($env{'form.displayfilter'} eq 'currentfolder') {
1053: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1054: }
1055: my @changes=keys(%{$docslog{$id}{'logentry'}});
1056: if ($env{'form.displayfilter'} eq 'containing') {
1057: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1058: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1059: foreach my $key (@changes) {
1060: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1061: }
1.344 bisitz 1062: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1063: }
1064: my $count = 0;
1065: my $time =
1066: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1067: my $plainname =
1068: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1069: $docslog{$id}{'exe_udom'});
1070: my $about_me_link =
1071: &Apache::loncommon::aboutmewrapper($plainname,
1072: $docslog{$id}{'exe_uname'},
1073: $docslog{$id}{'exe_udom'});
1074: my $send_msg_link='';
1075: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1076: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1077: $send_msg_link ='<br />'.
1078: &Apache::loncommon::messagewrapper(&mt('Send message'),
1079: $docslog{$id}{'exe_uname'},
1080: $docslog{$id}{'exe_udom'});
1081: }
1082: $r->print(&Apache::loncommon::start_data_table_row());
1083: $r->print('<td>'.$time.'</td>
1084: <td>'.$about_me_link.
1085: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1086: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1087: $send_msg_link.'</td><td>'.
1088: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1089: my $is_supp = 0;
1090: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1091: $is_supp = 1;
1092: }
1.329 droeschl 1093: # Before
1094: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1095: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1096: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1097: if ($oldname ne $newname) {
1.488 raeburn 1098: my $shown = &LONCAPA::map::qtescape($oldname);
1099: if ($is_supp) {
1100: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1101: }
1102: $r->print($shown);
1.329 droeschl 1103: }
1104: }
1105: $r->print('<ul>');
1106: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1107: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1108: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1109: if ($is_supp) {
1110: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1111: }
1112: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1113: }
1114: }
1115: $r->print('</ul>');
1116: # After
1117: $r->print('</td><td>');
1118:
1119: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1120: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1121: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1122: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1123: my $shown = &LONCAPA::map::qtescape($newname);
1124: if ($is_supp) {
1125: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1126: }
1127: $r->print($shown);
1.329 droeschl 1128: }
1.364 bisitz 1129: }
1.329 droeschl 1130: $r->print('<ul>');
1131: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1132: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1133: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1134: if ($is_supp) {
1135: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1136: }
1137: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1138: }
1139: }
1140: $r->print('</ul>');
1141: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1142: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1.645 raeburn 1143: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1144: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1145: # FIXME: internationalization seems wrong here
1.329 droeschl 1146: $r->print('<li>'.
1147: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1148: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1149: .'</li>');
1150: }
1151: }
1152: $r->print('</ul>');
1153: }
1154: # End
1155: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1156: $shown++;
1157: if (!($env{'form.show'} eq &mt('all')
1158: || $shown<=$env{'form.show'})) { last; }
1159: }
1.484 raeburn 1160: $r->print(&Apache::loncommon::end_data_table()."\n".
1161: &makesimpleeditform($pathitem)."\n".
1162: '</div></div>');
1163: $r->print(&endContentScreen());
1.329 droeschl 1164: }
1165:
1166: sub update_paste_buffer {
1.492 raeburn 1167: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1168: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1169: if ($env{'form.multiremove'}) {
1170: $env{'form.multiremove'} =~ s/,$//;
1171: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1172: }
1173: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1174: if ($env{'form.multicut'}) {
1175: $env{'form.multicut'} =~ s/,$//;
1176: foreach my $item (split(/,/,$env{'form.multicut'})) {
1177: unless ($removals{$item}) {
1178: $cuts{$item} = 1;
1179: push(@possibles,$item.':cut');
1180: }
1181: }
1182: }
1183: if ($env{'form.multicopy'}) {
1184: $env{'form.multicopy'} =~ s/,$//;
1185: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1186: unless ($removals{$item} || $cuts{$item}) {
1187: push(@possibles,$item.':copy');
1188: }
1189: }
1190: }
1191: } elsif ($env{'form.markcopy'}) {
1192: @possibles = split(/,/,$env{'form.markcopy'});
1193: }
1.329 droeschl 1194:
1.538 raeburn 1195: return if (@possibles == 0);
1.329 droeschl 1196: return if (!defined($env{'form.copyfolder'}));
1197:
1198: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1199: $env{'form.copyfolder'});
1.538 raeburn 1200: return if ($fatal);
1201:
1202: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1203:
1.538 raeburn 1204: # Retrieve current paste buffer suffixes.
1205: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1206: my (%pasteurls,@newpaste);
1207:
1208: # Construct identifiers for current contents of user's paste buffer
1209: if (@currpaste) {
1210: foreach my $suffix (@currpaste) {
1211: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1212: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.630 raeburn 1213: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1214: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1215: ($url ne '')) {
1.597 raeburn 1216: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1217: }
1218: }
1219: }
1220:
1221: # Mark items for copying (skip any items already in user's paste buffer)
1222: my %addtoenv;
1.597 raeburn 1223:
1224: my @pathitems = split(/\&/,$env{'form.folderpath'});
1225: my @folderconf = split(/\:/,$pathitems[-1]);
1226: my $ispage = $folderconf[4];
1227:
1.538 raeburn 1228: foreach my $item (@possibles) {
1229: my ($orderidx,$cmd) = split(/:/,$item);
1230: next if ($orderidx =~ /\D/);
1231: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1232: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1233: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1234: my %denied = &action_restrictions($coursenum,$coursedom,
1235: &LONCAPA::map::qtescape($url),
1236: $env{'form.folderpath'},\%curr_groups);
1237: next if ($denied{'copy'});
1238: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1239: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1240: my ($suffix,$errortxt,$locknotfreed) =
1241: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1242: if ($suffix ne '') {
1243: push(@newpaste,$suffix);
1244: } else {
1245: if ($locknotfreed) {
1246: return $locknotfreed;
1247: }
1.538 raeburn 1248: }
1249: if (&is_supplemental_title($title)) {
1250: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1251: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1252: }
1.329 droeschl 1253:
1.538 raeburn 1254: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1255: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1256: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1257: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1258: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1259: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1260: my $prefix = $1;
1261: my $subdir =$2;
1262: if ($subdir eq '') {
1263: $subdir = $prefix;
1.492 raeburn 1264: }
1.538 raeburn 1265: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1266: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1267: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1268: if (ref($hierarchy{$url}) eq 'HASH') {
1269: my ($nested,$nestednames);
1270: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1271: $nested =~ s/\&$//;
1272: $nestednames =~ s/\Q___&&&___\E$//;
1273: if ($nested ne '') {
1274: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1275: }
1276: if ($nestednames ne '') {
1277: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1278: }
1.492 raeburn 1279: }
1280: }
1.591 raeburn 1281: if ($locknotfreed) {
1282: $output = $locknotfreed;
1283: last;
1284: }
1.492 raeburn 1285: }
1.538 raeburn 1286: if (@newpaste) {
1287: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1288: }
1.492 raeburn 1289: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1290: delete($env{'form.markcopy'});
1.591 raeburn 1291: return $output;
1.329 droeschl 1292: }
1293:
1.492 raeburn 1294: sub recurse_uploaded_maps {
1295: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1296: if (ref($hierarchy->{$url}) eq 'HASH') {
1297: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1298: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1299: my (@uploaded,@names,%shorter);
1300: for (my $i=0; $i<@maps; $i++) {
1301: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1302: if ($inner ne '') {
1303: push(@uploaded,$inner);
1304: push(@names,&escape($titles[$i]));
1305: $shorter{$maps[$i]} = $inner;
1306: }
1307: }
1308: $$nestref .= "$dir:".join(',',@uploaded).'&';
1309: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1310: foreach my $map (@maps) {
1311: if ($shorter{$map} ne '') {
1312: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1313: }
1314: }
1315: }
1316: return;
1317: }
1318:
1.329 droeschl 1319: sub print_paste_buffer {
1.492 raeburn 1320: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1321: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1322:
1.538 raeburn 1323: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1324: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1325: }
1326:
1.538 raeburn 1327: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1328: my ($pasteitems,@pasteable);
1.575 raeburn 1329: my $clipboardcount = 0;
1.488 raeburn 1330:
1.538 raeburn 1331: # Construct identifiers for current contents of user's paste buffer
1332: foreach my $suffix (@currpaste) {
1333: next if ($suffix =~ /\D/);
1334: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1335: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1336: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1337: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1338: ($url ne '')) {
1.575 raeburn 1339: $clipboardcount ++;
1.538 raeburn 1340: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1341: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1342: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1343: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1344: $is_external = 1;
1.626 raeburn 1345: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1346: $is_exttool = 1;
1.538 raeburn 1347: }
1348: if ($folder =~ /^supplemental/) {
1349: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1350: unless ($canpaste) {
1351: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1352: }
1353: } else {
1354: $canpaste = 1;
1355: }
1356: if ($canpaste) {
1357: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1358: my $srcdom = $1;
1359: my $srcnum = $2;
1360: my $rem = $3;
1361: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1362: $othercourse = 1;
1363: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1364: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1365: } else {
1366: $canpaste = 0;
1367: $nopaste = &mt('Paste from another course unavailable.');
1368: }
1369: }
1370: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1371: my $prefix = $1;
1372: $parent = $2;
1373: if ($folder !~ /^\Q$prefix\E/) {
1374: $areachange = 1;
1375: }
1376: $is_uploaded_map = 1;
1.492 raeburn 1377: }
1.597 raeburn 1378: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1379: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1380: if ($cid ne $env{'request.course.id'}) {
1381: my ($srcdom,$srcnum) = split(/_/,$cid);
1382: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1383: if (($is_exttool) && ($srcdom ne $coursedom)) {
1384: $canpaste = 0;
1385: $nopaste = &mt('Paste from another domain unavailable.');
1386: } else {
1387: $othercrs = '<br />'.&mt('(from another course)');
1388: }
1.596 raeburn 1389: } else {
1390: $canpaste = 0;
1391: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1392: }
1.596 raeburn 1393: }
1.492 raeburn 1394: }
1.596 raeburn 1395: if ($canpaste) {
1396: push(@pasteable,$suffix);
1.629 raeburn 1397: }
1.538 raeburn 1398: }
1399: my $buffer;
1.627 raeburn 1400: if ($is_external) {
1.538 raeburn 1401: $buffer = &mt('External Resource').': '.
1402: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1403: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1404: } elsif ($is_exttool) {
1405: $buffer = &mt('External Tool').': '.
1406: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1407: } else {
1408: my $icon = &Apache::loncommon::icon($extension);
1409: if ($extension eq 'sequence' &&
1410: $url =~ m{/default_\d+\.sequence$}x) {
1411: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1412: $icon .= '/navmap.folder.closed.gif';
1413: }
1.589 raeburn 1414: my $title = $env{'docs.markedcopy_title_'.$suffix};
1415: if ($title eq '') {
1416: ($title) = ($url =~ m{/([^/]+)$});
1417: }
1.538 raeburn 1418: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1419: ': '.
1420: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1421: &LONCAPA::map::qtescape($title));
1.538 raeburn 1422: }
1423: $pasteitems .= '<div class="LC_left_float">';
1424: my ($options,$onclick);
1425: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1426: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1427: if (($is_uploaded_map) ||
1428: ($url =~ /(bulletinboard|smppg)$/) ||
1429: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1430: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1431: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1432: }
1433: }
1434: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1435: if ($nopaste) {
1436: $pasteitems .= $nopaste;
1437: } else {
1438: if ($othercrs) {
1439: $pasteitems .= $othercrs;
1440: }
1441: if ($options) {
1442: $pasteitems .= $options;
1.492 raeburn 1443: }
1444: }
1.538 raeburn 1445: $pasteitems .= '</div>';
1446: }
1447: }
1448: if ($pasteitems eq '') {
1449: &Apache::lonnet::delenv('docs.markedcopies');
1450: }
1451: my ($pasteform,$form_start,$buttons,$form_end);
1452: if ($pasteitems) {
1453: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1454: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1455: if (@pasteable) {
1.575 raeburn 1456: my $value = &mt('Paste to current folder');
1457: if ($container eq 'page') {
1458: $value = &mt('Paste to current page');
1459: }
1460: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1461: }
1462: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1463: if ($clipboardcount > 1) {
1464: $buttons .=
1465: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1466: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1467: (' 'x2).
1468: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1469: (' 'x2);
1.492 raeburn 1470: }
1.575 raeburn 1471: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1472: '</form>';
1.538 raeburn 1473: } else {
1474: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1475: }
1.538 raeburn 1476: $r->print($form_start
1477: .'<fieldset>'
1478: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1479: .$pasteitems
1480: .'</fieldset>'
1481: .$form_end);
1482: }
1483:
1484: sub paste_options {
1485: my ($suffix,$is_uploaded_map,$parent) = @_;
1486: my ($copytext,$movetext);
1487: if ($is_uploaded_map) {
1488: $copytext = &mt('Copy to new folder');
1489: $movetext = &mt('Move old');
1490: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1491: $copytext = &mt('Copy to new board');
1492: $movetext = &mt('Move (not posts)');
1493: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1494: $copytext = &mt('Copy to new page');
1495: $movetext = &mt('Move');
1.533 raeburn 1496: } else {
1.538 raeburn 1497: $copytext = &mt('Copy to new file');
1498: $movetext = &mt('Move');
1499: }
1500: my $output = '<br />'.
1501: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1502: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1503: '<label>'.
1504: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1505: $copytext.'</label></span>'.(' 'x2).' '.
1506: '<span class="LC_nobreak"><label>'.
1507: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1508: $movetext.'</label></span>';
1509: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1510: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1511: '</legend><table border="0">';
1512: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1513: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1514: my $lastdir = $parent;
1515: my %depths = (
1516: $lastdir => 0,
1517: );
1518: my (%display,%deps);
1519: for (my $i=0; $i<@pastemaps; $i++) {
1520: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1521: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1522: my @subfolders = split(/,/,$subfolderstr);
1523: $deps{$lastdir} = \@subfolders;
1524: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1525: my $depth = $depths{$lastdir} + 1;
1526: my $offset = int($depth * 4);
1527: my $indent = (' ' x $offset);
1528: for (my $j=0; $j<@subfolders; $j++) {
1529: $depths{$subfolders[$j]} = $depth;
1530: $display{$subfolders[$j]} =
1531: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1532: '<td><label>'.
1533: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1534: '<label>'.
1535: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1536: &mt('Move old').'</label>'.
1537: '</td></tr>';
1538: }
1.492 raeburn 1539: }
1.538 raeburn 1540: &recurse_print(\$output,$parent,\%deps,\%display);
1541: $output .= '</table></fieldset>';
1.329 droeschl 1542: }
1.538 raeburn 1543: $output .= '</div>';
1544: return $output;
1.488 raeburn 1545: }
1546:
1.492 raeburn 1547: sub recurse_print {
1.538 raeburn 1548: my ($outputref,$dir,$deps,$display) = @_;
1549: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1550: if (ref($deps->{$dir}) eq 'ARRAY') {
1551: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1552: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1553: }
1554: }
1555: }
1556:
1.488 raeburn 1557: sub supp_pasteable {
1558: my ($url) = @_;
1559: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1560: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1561: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1562: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1563: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1564: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1565: return 1;
1566: }
1567: return;
1.329 droeschl 1568: }
1569:
1.492 raeburn 1570: sub paste_popup_js {
1.594 damieng 1571: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1572: show => 'Show Options',
1573: hide => 'Hide Options',
1.594 damieng 1574: );
1575: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1576: none => 'No items selected from clipboard.',
1.492 raeburn 1577: );
1.594 damieng 1578: &html_escape(\%html_js_lt);
1579: &js_escape(\%html_js_lt);
1580: &js_escape(\%js_lt);
1.492 raeburn 1581: return <<"END";
1582:
1.538 raeburn 1583: function showPasteOptions(suffix) {
1584: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1585: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1586: return;
1587: }
1588:
1.538 raeburn 1589: function hidePasteOptions(suffix) {
1590: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1591: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1592: return;
1593: }
1594:
1595: function showOptions(caller,suffix) {
1596: if (document.getElementById('pasteoptionstext_'+suffix)) {
1597: if (caller.checked) {
1.594 damieng 1598: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1599: } else {
1600: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1601: }
1602: if (document.getElementById('pasteoptions_'+suffix)) {
1603: document.getElementById('pasteoptions_'+suffix).style.display='none';
1604: }
1605: }
1.492 raeburn 1606: return;
1607: }
1608:
1.541 raeburn 1609: function validateClipboard() {
1610: var numchk = 0;
1611: if (document.pasteform.pasting.length > 1) {
1612: for (var i=0; i<document.pasteform.pasting.length; i++) {
1613: if (document.pasteform.pasting[i].checked) {
1614: numchk ++;
1615: }
1616: }
1617: } else {
1618: if (document.pasteform.pasting.type == 'checkbox') {
1619: if (document.pasteform.pasting.checked) {
1620: numchk ++;
1621: }
1622: }
1623: }
1624: if (numchk > 0) {
1625: return true;
1626: } else {
1.594 damieng 1627: alert("$js_lt{'none'}");
1.541 raeburn 1628: return false;
1629: }
1630: }
1631:
1.575 raeburn 1632: function checkClipboard() {
1633: if (document.pasteform.pasting.length > 1) {
1634: for (var i=0; i<document.pasteform.pasting.length; i++) {
1635: document.pasteform.pasting[i].checked = true;
1636: }
1637: }
1638: return;
1639: }
1640:
1641: function uncheckClipboard() {
1642: if (document.pasteform.pasting.length >1) {
1643: for (var i=0; i<document.pasteform.pasting.length; i++) {
1644: document.pasteform.pasting[i].checked = false;
1645: }
1646: }
1647: return;
1648: }
1649:
1.492 raeburn 1650: END
1651:
1652: }
1653:
1.329 droeschl 1654: sub do_paste_from_buffer {
1.492 raeburn 1655: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1656:
1.538 raeburn 1657: # Array of items in paste buffer
1658: my (@currpaste,%pastebuffer,%allerrors);
1659: @currpaste = split(/,/,$env{'docs.markedcopies'});
1660:
1.492 raeburn 1661: # Early out if paste buffer is empty
1.538 raeburn 1662: if (@currpaste == 0) {
1.492 raeburn 1663: return ();
1.538 raeburn 1664: }
1665: map { $pastebuffer{$_} = 1; } @currpaste;
1666:
1667: # Array of items selected items to paste
1668: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1669:
1670: # Early out if nothing selected to paste
1671: if (@reqpaste == 0) {
1672: return();
1673: }
1674: my @topaste;
1675: foreach my $suffix (@reqpaste) {
1676: next if ($suffix =~ /\D/);
1677: next unless (exists($pastebuffer{$suffix}));
1678: push(@topaste,$suffix);
1679: }
1680:
1681: # Early out if nothing available to paste
1682: if (@topaste == 0) {
1683: return();
1.329 droeschl 1684: }
1685:
1.627 raeburn 1686: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1687: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1688:
1689: foreach my $suffix (@topaste) {
1690: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1691: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1692: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1693: # Supplemental content may only include certain types of content
1694: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1695: if ($folder =~ /^supplemental/) {
1696: unless (&supp_pasteable($url)) {
1697: $notinsupp{$suffix} = 1;
1698: next;
1699: }
1.492 raeburn 1700: }
1.538 raeburn 1701: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1702: my $srcd = $1;
1703: my $srcn = $2;
1.492 raeburn 1704: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1705: # check for mdc privilege in the course from which the resource was pasted
1706: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1707: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1708: $notincrs{$suffix} = 1;
1709: next;
1710: }
1.491 raeburn 1711: }
1.538 raeburn 1712: $srcdom{$suffix} = $srcd;
1713: $srcnum{$suffix} = $srcn;
1.597 raeburn 1714: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1715: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1716: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1717: my ($srcd,$srcn) = split(/_/,$cid);
1718: # When paste buffer was populated using an active role in a different course
1719: # check for mdc privilege in the course from which the resource was pasted
1720: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1721: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1722: $notincrs{$suffix} = 1;
1723: next;
1724: }
1725: }
1.632 raeburn 1726: # When buffer was populated using an active role in a different course
1727: # disallow pasting of External Tool if course is in a different domain.
1728: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1729: $notindom{$suffix} = 1;
1730: next;
1731: }
1.596 raeburn 1732: $srcdom{$suffix} = $srcd;
1733: $srcnum{$suffix} = $srcn;
1.491 raeburn 1734: }
1.597 raeburn 1735: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1736: push(@dopaste,$suffix);
1737: if ($url=~/\.(page|sequence)$/) {
1738: $is_map{$suffix} = 1;
1739: }
1740: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1741: my $oldprefix = $1;
1.492 raeburn 1742: # When pasting content from Main Content to Supplemental Content and vice versa
1743: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1744: # a folder/page or a document).
1.538 raeburn 1745: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1746: $prefixchg{$suffix} = 'docstosupp';
1747: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1748: $prefixchg{$suffix} = 'supptodocs';
1749: }
1.491 raeburn 1750:
1.492 raeburn 1751: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1752: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1753: my @nested;
1754: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1755: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1756: my @deps = map { /\d+:([\d,]+$)/ } @items;
1757: foreach my $dep (@deps) {
1758: if ($dep =~ /,/) {
1759: push(@nested,split(/,/,$dep));
1760: } else {
1761: push(@nested,$dep);
1762: }
1.492 raeburn 1763: }
1.538 raeburn 1764: foreach my $item (@nested) {
1765: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1766: push(@{$marktomove{$suffix}},$type.'_'.$item);
1767: }
1.492 raeburn 1768: }
1769: }
1.488 raeburn 1770: }
1771: }
1772:
1.538 raeburn 1773: # Early out if nothing available to paste
1774: if (@dopaste == 0) {
1775: return ();
1776: }
1777:
1778: # Populate message hash and hashes used for main content <=> supplemental content
1779: # changes
1780:
1781: %msgs = &Apache::lonlocal::texthash (
1782: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1783: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.627 raeburn 1784: notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.538 raeburn 1785: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1786: );
1787:
1788: %before = (
1789: docstosupp => {
1790: map => 'default',
1791: doc => 'docs',
1792: },
1793: supptodocs => {
1794: map => 'supplemental',
1795: doc => 'supplemental',
1796: },
1797: );
1798:
1799: %after = (
1800: docstosupp => {
1801: map => 'supplemental',
1802: doc => 'supplemental'
1803: },
1804: supptodocs => {
1805: map => 'default',
1806: doc => 'docs',
1807: },
1808: );
1809:
1810: # Retrieve information about all course maps in main content area
1811:
1812: my $allmaps = {};
1813: if ($folder =~ /^default/) {
1814: $allmaps =
1815: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1816: $env{"course.$env{'request.course.id'}.home"},
1817: $env{'request.course.id'});
1818: }
1819:
1820: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1821:
1822: # Loop over the items to paste
1823: foreach my $suffix (@dopaste) {
1.329 droeschl 1824: # Maps need to be copied first
1.538 raeburn 1825: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1826: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1827: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1828: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1829: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1830: }
1831: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1832: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1833: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1834: my $oldurl = $url;
1835: if ($is_map{$suffix}) {
1.491 raeburn 1836: # If pasting a map, check if map contains other maps
1.538 raeburn 1837: my (%hierarchy,%titles);
1.627 raeburn 1838: &contained_map_check($url,$folder,$coursenum,$coursedom,
1839: \%removefrommap,\%removeparam,\%addedmaps,
1840: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1841: if ($url=~ m{^/uploaded/}) {
1842: my $newurl;
1843: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1844: ($newurl,my $error) =
1845: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1846: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1847: \$title,$allmaps,\%newurls);
1848: if ($error) {
1849: $allerrors{$suffix} = $error;
1850: next;
1851: }
1852: if ($newurl ne '') {
1853: if ($newurl ne $url) {
1854: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1855: $newsubdir{$url} = $1;
1856: }
1857: $mapchanges{$url} = 1;
1.492 raeburn 1858: }
1.538 raeburn 1859: }
1860: }
1861: if (($srcdom{$suffix} ne $coursedom) ||
1862: ($srcnum{$suffix} ne $coursenum) ||
1863: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1864: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1865: $coursedom,$coursenum,$srcdom{$suffix},
1866: $srcnum{$suffix},$allmaps,\%rewrites,
1867: \%retitles,\%copies,\%dbcopies,
1868: \%zombies,\%params,\%mapmoves,
1869: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1870: \%newurls,\%resdatacopy)) {
1.538 raeburn 1871: $mapmoves{$url} = 1;
1872: }
1873: $url = $newurl;
1874: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1875: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1876: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1877: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1878: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1879: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1880: }
1881: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1882: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1883: push(@toclear,$suffix);
1884: # if pasting published map (main content area only) check map not already in course
1885: if ($folder =~ /^default/) {
1886: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1887: $duplicate{$suffix} = 1;
1888: next;
1.492 raeburn 1889: }
1.491 raeburn 1890: }
1891: }
1.538 raeburn 1892: }
1.627 raeburn 1893: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1894: my $prefix = $1;
1.596 raeburn 1895: my $fromothercrs;
1.538 raeburn 1896: #need to copy the db contents to a new one, unless this is a move.
1897: my %info = (
1898: src => $url,
1899: cdom => $coursedom,
1900: cnum => $coursenum,
1.596 raeburn 1901: );
1902: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1903: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1904: $fromothercrs = 1;
1905: $info{'cdom'} = $srcdom{$suffix};
1906: $info{'cnum'} = $srcnum{$suffix};
1907: }
1908: }
1909: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 1910: my (%lockerr,$msg);
1.538 raeburn 1911: my ($newurl,$result,$errtext) =
1912: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1913: if ($result eq 'ok') {
1914: $url = $newurl;
1915: $title=&mt('Copy of').' '.$title;
1916: } else {
1917: if ($prefix eq 'smppg') {
1918: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1919: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1920: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 1921: } elsif ($prefix eq 'ext.tool') {
1922: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 1923: }
1924: $results{$suffix} = $result;
1925: $msgerrs{$suffix} = $msg;
1926: $lockerrs{$suffix} = $lockerr{$prefix};
1927: next;
1928: }
1929: if ($lockerr{$prefix}) {
1930: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1931: }
1.489 raeburn 1932: }
1933: }
1.538 raeburn 1934: $title = &LONCAPA::map::qtunescape($title);
1935: my $ext='false';
1936: if ($url=~m{^http(|s)://}) { $ext='true'; }
1937: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1938: if ($folder !~ /^supplemental/) {
1939: (undef,undef,$title) =
1940: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1941: }
1942: } else {
1943: if ($folder=~/^supplemental/) {
1944: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1945: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1946: }
1.533 raeburn 1947: }
1.491 raeburn 1948:
1949: # For uploaded files (excluding pages/sequences) path in copied file is changed
1950: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1951: # courses.
1952:
1.538 raeburn 1953: unless ($is_map{$suffix}) {
1954: my $newidx;
1.492 raeburn 1955: # Now insert the URL at the bottom
1.538 raeburn 1956: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1957: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1958: my $relpath = $1;
1959: if ($relpath ne '') {
1960: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1961: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1962: my $newprefix = $newloc;
1963: if ($newloc eq 'default') {
1964: $newprefix = 'docs';
1965: }
1966: if ($newdocsdir eq '') {
1967: $newdocsdir = 'default';
1968: }
1.630 raeburn 1969: if (($prefixchg{$suffix}) ||
1970: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 1971: ($srcnum{$suffix} ne $coursenum) ||
1972: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1973: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1974: $url =
1975: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1976: &Apache::lonnet::getfile($oldurl));
1977: if ($url eq '/adm/notfound.html') {
1978: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1979: next;
1980: } else {
1981: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1982: $newsubpath =~ s{/+$}{/};
1983: $docmoves{$oldurl} = $newsubpath;
1984: }
1.491 raeburn 1985: }
1986: }
1.597 raeburn 1987: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1988: my $template = $1;
1989: if ($newidx) {
1990: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1991: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1992: }
1.491 raeburn 1993: }
1.538 raeburn 1994: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1995: ':'.$ext.':normal:res';
1996: push(@LONCAPA::map::order,$newidx);
1997: # Store the result
1998: my ($errtext,$fatal) =
1999: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2000: if ($fatal) {
2001: $save_err .= $errtext;
2002: $allresult = 'fail';
2003: }
1.488 raeburn 2004: }
1.538 raeburn 2005:
1.597 raeburn 2006: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2007: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2008: unless ($allresult eq 'fail') {
2009: my %updated = (
2010: rewrites => \%rewrites,
2011: zombies => \%zombies,
2012: removefrommap => \%removefrommap,
2013: removeparam => \%removeparam,
2014: dbcopies => \%dbcopies,
1.597 raeburn 2015: resdatacopy => \%resdatacopy,
1.538 raeburn 2016: retitles => \%retitles,
2017: );
2018: my %info = (
2019: newsubdir => \%newsubdir,
2020: params => \%params,
2021: );
2022: if ($prefixchg{$suffix}) {
2023: $info{'before'} = $before{$prefixchg{$suffix}};
2024: $info{'after'} = $after{$prefixchg{$suffix}};
2025: }
2026: my %moves = (
2027: copies => \%copies,
2028: docmoves => \%docmoves,
2029: mapmoves => \%mapmoves,
2030: );
2031: (my $result,$msgs{$suffix},my $lockerror) =
2032: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2033: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2034: $url,'paste');
2035: $lockerrors .= $lockerror;
2036: if ($result eq 'ok') {
2037: if ($is_map{$suffix}) {
2038: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2039: $folder.'.'.$container);
2040: if ($fatal) {
2041: $allresult = 'failread';
2042: } else {
2043: if ($#LONCAPA::map::order<1) {
2044: my $idx=&LONCAPA::map::getresidx();
2045: if ($idx<=0) { $idx=1; }
2046: $LONCAPA::map::order[0]=$idx;
2047: $LONCAPA::map::resources[$idx]='';
2048: }
2049: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2050: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2051: ':'.$ext.':normal:res';
2052: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2053:
2054: # Store the result
1.538 raeburn 2055: my ($errtext,$fatal) =
2056: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2057: if ($fatal) {
2058: $save_err .= $errtext;
2059: $allresult = 'failstore';
2060: }
2061: }
2062: }
2063: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2064: push(@toclear,$suffix);
2065: }
2066: }
1.492 raeburn 2067: }
2068: }
1.538 raeburn 2069: &clear_from_buffer(\@toclear,\@currpaste);
2070: my $msgsarray;
2071: foreach my $suffix (keys(%msgs)) {
2072: if (ref($msgs{$suffix}) eq 'ARRAY') {
2073: $msgsarray .= join(',',@{$msgs{$suffix}});
2074: }
2075: }
2076: return ($allresult,$save_err,$msgsarray,$lockerrors);
2077: }
1.533 raeburn 2078:
1.538 raeburn 2079: sub do_buffer_empty {
2080: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2081: if (@currpaste == 0) {
2082: return &mt('Clipboard is already empty');
2083: }
2084: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2085: if (@toclear == 0) {
2086: return &mt('Nothing selected to clear from clipboard');
2087: }
2088: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2089: if ($numdel) {
2090: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2091: } else {
2092: return &mt('Clipboard unchanged');
1.492 raeburn 2093: }
1.538 raeburn 2094: return;
2095: }
2096:
2097: sub clear_from_buffer {
2098: my ($toclear,$currpaste) = @_;
2099: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2100: my %pastebuffer;
2101: map { $pastebuffer{$_} = 1; } @{$currpaste};
2102: my $numdel = 0;
2103: foreach my $suffix (@{$toclear}) {
2104: next if ($suffix =~ /\D/);
2105: next unless (exists($pastebuffer{$suffix}));
2106: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2107: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2108: delete($pastebuffer{$suffix});
2109: $numdel ++;
2110: }
2111: }
2112: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2113: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2114: return $numdel;
1.492 raeburn 2115: }
2116:
2117: sub get_newmap_url {
2118: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2119: $titleref,$allmaps,$newurls) = @_;
2120: my $newurl;
2121: if ($url=~ m{^/uploaded/}) {
2122: $$titleref=&mt('Copy of').' '.$$titleref;
2123: }
2124: my $now = time;
2125: my $suffix=$$.int(rand(100)).$now;
2126: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2127: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2128: my $path = $1;
2129: my $prefix = $2;
2130: my $ancestor = $3;
2131: if (length($ancestor) > 10) {
2132: $ancestor = substr($ancestor,-10,10);
2133: }
2134: my $newid;
2135: if ($prefixchg) {
2136: if ($folder =~ /^supplemental/) {
2137: $prefix =~ s/^default/supplemental/;
2138: } else {
2139: $prefix =~ s/^supplemental/default/;
2140: }
2141: }
2142: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2143: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2144: } else {
2145: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2146: }
2147: my $counter = 0;
2148: my $is_unique = &uniqueness_check($newurl);
2149: if ($folder =~ /^default/) {
2150: if ($allmaps->{$newurl}) {
2151: $is_unique = 0;
2152: }
2153: }
2154: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2155: $counter ++;
2156: $suffix ++;
2157: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2158: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2159: } else {
2160: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2161: }
2162: $is_unique = &uniqueness_check($newurl);
2163: }
2164: if ($is_unique) {
2165: $newurls->{$newurl} = 1;
2166: } else {
2167: if ($url=~/\.page$/) {
2168: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2169: } else {
2170: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2171: }
2172: }
1.329 droeschl 2173: }
1.492 raeburn 2174: return ($newurl);
1.329 droeschl 2175: }
2176:
1.488 raeburn 2177: sub dbcopy {
1.533 raeburn 2178: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2179: my ($url,$result,$errtext);
2180: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2181: $url = $dbref->{'src'};
1.627 raeburn 2182: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2183: my $prefix = $1;
1.627 raeburn 2184: if ($prefix eq 'ext.tool') {
2185: $prefix = 'exttool';
2186: }
1.533 raeburn 2187: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2188: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2189: my $db_name;
2190: my $marker = (split(m{/},$url))[4];
2191: $marker=~s/\D//g;
2192: if ($dbref->{'src'} =~ m{/smppg$}) {
2193: $db_name =
2194: &Apache::lonsimplepage::get_db_name($url,$marker,
2195: $dbref->{'cdom'},
2196: $dbref->{'cnum'});
1.627 raeburn 2197: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2198: $db_name = 'exttool_'.$marker;
1.533 raeburn 2199: } else {
2200: $db_name = 'bulletinpage_'.$marker;
2201: }
2202: my ($suffix,$freedlock,$error) =
2203: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2204: $coursedom,$coursenum,
2205: 'concat');
2206: if (!$suffix) {
2207: if ($prefix eq 'smppg') {
2208: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2209: } elsif ($prefix eq 'exttool') {
2210: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2211: } else {
1.565 bisitz 2212: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2213: }
2214: if ($error) {
2215: $errtext .= '<br />'.$error;
2216: }
2217: } else {
2218: #need to copy the db contents to a new one.
2219: my %contents=&Apache::lonnet::dump($db_name,
2220: $dbref->{'cdom'},
2221: $dbref->{'cnum'});
2222: if (exists($contents{'uploaded.photourl'})) {
2223: my $photo = $contents{'uploaded.photourl'};
2224: my ($subdir,$fname) =
2225: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2226: my $newphoto;
1.533 raeburn 2227: if ($fname ne '') {
2228: my $content = &Apache::lonnet::getfile($photo);
2229: unless ($content eq '-1') {
2230: $env{'form.'.$suffix.'.photourl'} = $content;
2231: $newphoto =
2232: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2233: delete($env{'form.'.$suffix.'.photourl'});
2234: }
2235: }
2236: if ($newphoto =~ m{^/uploaded/}) {
2237: $contents{'uploaded.photourl'} = $newphoto;
2238: }
2239: }
2240: $db_name =~ s{_\d*$ }{_$suffix}x;
2241: $result=&Apache::lonnet::put($db_name,\%contents,
2242: $coursedom,$coursenum);
2243: if ($result eq 'ok') {
1.627 raeburn 2244: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2245: }
2246: }
2247: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2248: $lockerrorsref->{$prefix} =
1.533 raeburn 2249: '<div class="LC_error">'.
2250: &mt('There was a problem removing a lockfile.');
2251: if ($prefix eq 'smppg') {
1.560 raeburn 2252: $lockerrorsref->{$prefix} .=
1.559 raeburn 2253: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2254: } elsif ($prefix eq 'exttool') {
2255: $lockerrorsref->{$prefix} .=
2256: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2257: } else {
1.565 bisitz 2258: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2259: }
1.560 raeburn 2260: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2261: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2262: '</div>';
1.533 raeburn 2263: }
2264: }
2265: } elsif ($url =~ m{/syllabus$}) {
2266: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2267: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2268: if (($dbref->{'cdom'} ne $coursedom) ||
2269: ($dbref->{'cnum'} ne $coursenum)) {
2270: my %contents=&Apache::lonnet::dump('syllabus',
2271: $dbref->{'cdom'},
2272: $dbref->{'cnum'});
2273: $result=&Apache::lonnet::put('syllabus',\%contents,
2274: $coursedom,$coursenum);
2275: }
2276: }
1.488 raeburn 2277: }
2278: }
1.533 raeburn 2279: return ($url,$result,$errtext);
1.488 raeburn 2280: }
2281:
1.597 raeburn 2282: sub copy_templated_files {
2283: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2284: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2285: my $srccontainer = 'sequence';
2286: if ($srcwaspage) {
2287: $srccontainer = 'page';
2288: }
2289: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2290: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2291: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2292: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2293: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2294: $template.'.problem';
2295: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2296: if ($template eq 'simpleproblem') {
2297: $srcprefix .= '.0.';
2298: my $weightprefix = $newprefix;
2299: $newprefix .= '.0.';
2300: my @simpleprobqtypes = qw(radio option string essay numerical);
2301: my $qtype=$srcparms{$srcprefix.'questiontype'};
2302: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2303: my %newdata;
2304: foreach my $type (@simpleprobqtypes) {
2305: if ($type eq $qtype) {
2306: $newdata{"$weightprefix.$type.weight"}=1;
2307: } else {
2308: $newdata{"$weightprefix.$type.weight"}=0;
2309: }
2310: }
2311: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2312: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2313: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2314: if ($qtype eq 'numerical') {
2315: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2316: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2317: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2318: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2319: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2320: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2321: unless (defined($maxfoils)) { $maxfoils=10; }
2322: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2323: if ($maxfoils<=0) { $maxfoils=10; }
2324: my $randomize=$srcparms{$srcprefix.'randomize'};
2325: unless (defined($randomize)) { $randomize='yes'; }
2326: unless ($randomize eq 'no') { $randomize='yes'; }
2327: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2328: $newdata{$newprefix.'randomize'} = $randomize;
2329: if ($qtype eq 'option') {
2330: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2331: }
2332: for (my $i=1; $i<=10; $i++) {
2333: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2334: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2335: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2336: }
2337:
2338: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2339: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2340: unless (defined($maxfoils)) { $maxfoils=10; }
2341: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2342: if ($maxfoils<=0) { $maxfoils=10; }
2343: my $randomize=$srcparms{$srcprefix.'randomize'};
2344: unless (defined($randomize)) { $randomize='yes'; }
2345: unless ($randomize eq 'no') { $randomize='yes'; }
2346: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2347: $newdata{$newprefix.'randomize'} = $randomize;
2348: if ($qtype eq 'option') {
2349: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2350: }
2351: for (my $i=1; $i<=10; $i++) {
2352: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2353: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2354: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2355: }
2356: } elsif ($qtype eq 'string') {
2357: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2358: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2359: }
2360: if (keys(%newdata)) {
2361: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2362: $coursenum);
2363: if ($putres eq 'ok') {
2364: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2365: }
2366: }
2367: }
2368: }
2369: }
2370:
1.329 droeschl 2371: sub uniqueness_check {
2372: my ($newurl) = @_;
2373: my $unique = 1;
2374: foreach my $res (@LONCAPA::map::order) {
2375: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2376: $url=&LONCAPA::map::qtescape($url);
2377: if ($newurl eq $url) {
2378: $unique = 0;
1.344 bisitz 2379: last;
1.329 droeschl 2380: }
2381: }
2382: return $unique;
2383: }
2384:
1.488 raeburn 2385: sub contained_map_check {
1.627 raeburn 2386: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2387: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2388: my $content = &Apache::lonnet::getfile($url);
2389: unless ($content eq '-1') {
2390: my $parser = HTML::TokeParser->new(\$content);
2391: $parser->attr_encoded(1);
2392: while (my $token = $parser->get_token) {
2393: next if ($token->[0] ne 'S');
2394: if ($token->[1] eq 'resource') {
2395: next if ($token->[2]->{'type'} eq 'zombie');
2396: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2397: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2398: my $srcdom = $1;
2399: unless ($srcdom eq $coursedom) {
2400: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2401: next;
2402: }
2403: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2404: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2405: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2406: next;
2407: }
2408: }
1.492 raeburn 2409: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2410: if ($1 eq 'uploaded') {
2411: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2412: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2413: } else {
1.492 raeburn 2414: if ($allmaps->{$ressrc}) {
1.529 raeburn 2415: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2416: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2417: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2418: } else {
2419: $addedmaps->{$ressrc} = [$url];
2420: }
1.488 raeburn 2421: }
1.627 raeburn 2422: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2423: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2424: }
1.492 raeburn 2425: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2426: if ($folder =~ /^supplemental/) {
1.492 raeburn 2427: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2428: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2429: } else {
2430: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2431: }
1.488 raeburn 2432: }
2433: }
2434: }
2435: }
2436: return;
2437: }
2438:
2439: sub url_paste_fixups {
1.533 raeburn 2440: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2441: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2442: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2443: my $checktitle;
2444: if (($prefixchg) &&
1.492 raeburn 2445: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2446: $checktitle = 1;
2447: }
1.492 raeburn 2448: my $skip;
2449: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2450: my $mapid = $1.$2;
2451: if ($tomove->{$mapid}) {
2452: $skip = 1;
2453: }
2454: }
1.491 raeburn 2455: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2456: return if ($file eq '-1');
2457: my $parser = HTML::TokeParser->new(\$file);
2458: $parser->attr_encoded(1);
1.491 raeburn 2459: my $changed = 0;
1.488 raeburn 2460: while (my $token = $parser->get_token) {
2461: next if ($token->[0] ne 'S');
2462: if ($token->[1] eq 'resource') {
2463: my $ressrc = $token->[2]->{'src'};
2464: next if ($ressrc eq '');
1.491 raeburn 2465: my $id = $token->[2]->{'id'};
1.492 raeburn 2466: my $title = $token->[2]->{'title'};
1.491 raeburn 2467: if ($checktitle) {
2468: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2469: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2470: }
2471: }
1.488 raeburn 2472: next if ($token->[2]->{'type'} eq 'external');
2473: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2474: next if ($skip);
1.532 raeburn 2475: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2476: $changed = 1;
2477: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2478: my $srcdom = $1;
2479: my $srcnum = $2;
1.488 raeburn 2480: my $rem = $3;
1.492 raeburn 2481: my $newurl;
2482: my $mapname;
2483: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2484: my $prefix = $1;
2485: $mapname = $prefix.$2;
2486: if ($tomove->{$mapname}) {
1.533 raeburn 2487: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2488: $srcdom,$srcnum,$allmaps,$rewrites,
2489: $retitles,$copies,$dbcopies,$zombies,
2490: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2491: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2492: next;
2493: } else {
2494: ($newurl,my $error) =
2495: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2496: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2497: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2498: $newsubdir->{$ressrc} = $1;
2499: }
2500: if ($error) {
2501: next;
2502: }
2503: }
2504: }
2505: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2506: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2507:
1.488 raeburn 2508: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2509: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2510: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2511: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2512: $cnum,$srcdom,$srcnum,$allmaps,
2513: $rewrites,$retitles,$copies,$dbcopies,
2514: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2515: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2516: $mapmoves->{$ressrc} = 1;
2517: }
2518: $changed = 1;
1.488 raeburn 2519: } else {
1.532 raeburn 2520: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2521: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2522: $changed = 1;
1.488 raeburn 2523: }
2524: }
1.533 raeburn 2525: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2526: next if ($skip);
1.492 raeburn 2527: my $srcdom = $1;
2528: my $srcnum = $2;
2529: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2530: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2531: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2532: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2533: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2534: $changed = 1;
2535: }
2536: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2537: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2538: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2539: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2540: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2541: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2542: $changed = 1;
1.488 raeburn 2543: }
1.597 raeburn 2544: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2545: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2546: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2547: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2548: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2549: }
1.488 raeburn 2550: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2551: next if ($skip);
2552: my $srcdom = $1;
2553: my $srcnum = $2;
2554: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2555: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2556: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2557: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2558: $changed = 1;
1.488 raeburn 2559: }
2560: }
2561: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2562: next if ($skip);
1.488 raeburn 2563: my $to = $token->[2]->{'to'};
2564: if ($to ne '') {
2565: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2566: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2567: } else {
2568: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2569: }
2570: }
2571: }
2572: }
1.491 raeburn 2573: return $changed;
1.488 raeburn 2574: }
2575:
2576: sub apply_fixups {
1.529 raeburn 2577: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2578: $oldurl,$url,$caller) = @_;
2579: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2580: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2581: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2582: if (ref($updated) eq 'HASH') {
2583: if (ref($updated->{'rewrites'}) eq 'HASH') {
2584: %rewrites = %{$updated->{'rewrites'}};
2585: }
2586: if (ref($updated->{'zombies'}) eq 'HASH') {
2587: %zombies = %{$updated->{'zombies'}};
2588: }
2589: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2590: %removefrommap = %{$updated->{'removefrommap'}};
2591: }
2592: if (ref($updated->{'removeparam'}) eq 'HASH') {
2593: %removeparam = %{$updated->{'removeparam'}};
2594: }
2595: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2596: %dbcopies = %{$updated->{'dbcopies'}};
2597: }
2598: if (ref($updated->{'retitles'}) eq 'HASH') {
2599: %retitles = %{$updated->{'retitles'}};
2600: }
1.597 raeburn 2601: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2602: %resdatacopy = %{$updated->{'resdatacopy'}};
2603: }
1.529 raeburn 2604: }
2605: if (ref($info) eq 'HASH') {
2606: if (ref($info->{'newsubdir'}) eq 'HASH') {
2607: %newsubdir = %{$info->{'newsubdir'}};
2608: }
2609: if (ref($info->{'params'}) eq 'HASH') {
2610: %params = %{$info->{'params'}};
2611: }
2612: if (ref($info->{'before'}) eq 'HASH') {
2613: %before = %{$info->{'before'}};
2614: }
2615: if (ref($info->{'after'}) eq 'HASH') {
2616: %after = %{$info->{'after'}};
2617: }
2618: }
2619: if (ref($moves) eq 'HASH') {
2620: if (ref($moves->{'copies'}) eq 'HASH') {
2621: %copies = %{$moves->{'copies'}};
2622: }
2623: if (ref($moves->{'docmoves'}) eq 'HASH') {
2624: %docmoves = %{$moves->{'docmoves'}};
2625: }
2626: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2627: %mapmoves = %{$moves->{'mapmoves'}};
2628: }
2629: }
2630: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2631: my @allcopies;
1.529 raeburn 2632: if (exists($copies{$key})) {
2633: if (ref($copies{$key}) eq 'HASH') {
2634: my %added;
2635: foreach my $innerkey (keys(%{$copies{$key}})) {
2636: if (($innerkey ne '') && (!$added{$innerkey})) {
2637: push(@allcopies,$innerkey);
2638: $added{$innerkey} = 1;
2639: }
1.491 raeburn 2640: }
1.529 raeburn 2641: undef(%added);
1.491 raeburn 2642: }
2643: }
2644: if ($key eq $oldurl) {
1.529 raeburn 2645: if ((exists($docmoves{$key}))) {
1.532 raeburn 2646: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2647: push(@allcopies,$oldurl);
2648: }
2649: }
2650: }
2651: if (@allcopies > 0) {
2652: foreach my $item (@allcopies) {
1.492 raeburn 2653: my ($relpath,$oldsubdir,$fname) =
2654: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2655: if ($fname ne '') {
2656: my $content = &Apache::lonnet::getfile($item);
2657: unless ($content eq '-1') {
2658: my $storefn;
1.529 raeburn 2659: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2660: $storefn = $docmoves{$key};
1.491 raeburn 2661: } else {
2662: $storefn = $relpath;
2663: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2664: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2665: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2666: }
1.529 raeburn 2667: if ($newsubdir{$key}) {
1.532 raeburn 2668: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2669: }
2670: }
2671: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2672: my $copyurl =
2673: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2674: $storefn.$fname,$content);
2675: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2676: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2677: return &mt('Paste failed: an error occurred copying the file.');
2678: } elsif (ref($errors) eq 'HASH') {
2679: $errors->{$item} = 1;
1.489 raeburn 2680: }
2681: }
1.488 raeburn 2682: }
2683: }
1.491 raeburn 2684: }
2685: }
2686: }
1.529 raeburn 2687: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2688: my $storefn=$key;
2689: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2690: if ($prefixchg && $before{'map'} && $after{'map'}) {
2691: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2692: }
1.529 raeburn 2693: if ($newsubdir{$key}) {
2694: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2695: }
1.491 raeburn 2696: my $mapcontent = &Apache::lonnet::getfile($key);
2697: if ($mapcontent eq '-1') {
2698: if (ref($errors) eq 'HASH') {
2699: $errors->{$key} = 1;
2700: }
2701: } else {
2702: my $newmap =
2703: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2704: $mapcontent);
2705: if ($newmap eq '/adm/notfound.html') {
2706: if (ref($errors) eq 'HASH') {
2707: $errors->{$key} = 1;
1.489 raeburn 2708: }
1.488 raeburn 2709: }
2710: }
2711: }
1.491 raeburn 2712: my %updates;
2713: if ($is_map) {
1.529 raeburn 2714: if (ref($updated) eq 'HASH') {
2715: foreach my $type (keys(%{$updated})) {
2716: if (ref($updated->{$type}) eq 'HASH') {
2717: foreach my $key (keys(%{$updated->{$type}})) {
2718: $updates{$key} = 1;
2719: }
2720: }
2721: }
1.491 raeburn 2722: }
2723: foreach my $key (keys(%updates)) {
1.492 raeburn 2724: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2725: if (ref($rewrites{$key}) eq 'HASH') {
2726: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2727: }
1.529 raeburn 2728: if (ref($retitles{$key}) eq 'HASH') {
2729: %toretitle = %{$retitles{$key}};
1.491 raeburn 2730: }
1.529 raeburn 2731: if (ref($removefrommap{$key}) eq 'HASH') {
2732: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2733: }
1.529 raeburn 2734: if (ref($removeparam{$key}) eq 'HASH') {
2735: %remparam = %{$removeparam{$key}};
1.492 raeburn 2736: }
1.529 raeburn 2737: if (ref($zombies{$key}) eq 'HASH') {
2738: %zombie = %{$zombies{$key}};
1.491 raeburn 2739: }
1.529 raeburn 2740: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2741: foreach my $idx (keys(%{$dbcopies{$key}})) {
2742: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2743: my ($newurl,$result,$errtext) =
2744: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2745: if ($result eq 'ok') {
2746: $newdb{$idx} = $newurl;
2747: } elsif (ref($errors) eq 'HASH') {
2748: $errors->{$key} = 1;
2749: }
2750: push(@msgs,$errtext);
2751: }
1.491 raeburn 2752: }
2753: }
1.597 raeburn 2754: if (ref($resdatacopy{$key}) eq 'HASH') {
2755: if ($newsubdir{$key}) {
2756:
2757: }
2758: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2759: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2760: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2761: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2762: my $template = $1;
2763: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2764: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2765: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2766: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2767: my ($newmapname) = ($key =~ m{/([^/]+)$});
2768: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2769: my $srcmapinfo = $srcfolder.':'.$idx;
2770: if ($srccontainer eq 'page') {
2771: $srcmapinfo .= ':1';
2772: }
2773: if ($newsubdir{$key}) {
2774: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2775: }
2776: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2777: $cnum,$template,$idx,$newmapname);
2778: }
2779: }
2780: }
2781: }
2782: }
1.529 raeburn 2783: if (ref($params{$key}) eq 'HASH') {
2784: %currparam = %{$params{$key}};
1.492 raeburn 2785: }
2786: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2787: if ($fatal) {
1.533 raeburn 2788: return ($errtext);
1.492 raeburn 2789: }
2790: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2791: if (defined($LONCAPA::map::zombies[$i])) {
2792: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2793: if ($zombie{$i} eq $src) {
1.492 raeburn 2794: undef($LONCAPA::map::zombies[$i]);
2795: }
2796: }
2797: }
1.646 ! raeburn 2798: my $total = scalar(@LONCAPA::map::order) - 1;
! 2799: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2800: my $idx = $LONCAPA::map::order[$i];
2801: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2802: my $changed;
1.529 raeburn 2803: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2804: if ((exists($toremove{$idx})) &&
2805: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2806: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2807: if (ref($currparam{$idx}) eq 'ARRAY') {
2808: foreach my $name (@{$currparam{$idx}}) {
2809: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2810: }
2811: }
2812: next;
2813: }
2814: my $origsrc = $src;
1.532 raeburn 2815: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2816: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2817: $changed = 1;
1.491 raeburn 2818: }
1.492 raeburn 2819: }
1.532 raeburn 2820: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2821: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2822: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2823: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2824: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2825: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2826: } else {
1.529 raeburn 2827: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2828: }
1.491 raeburn 2829: }
1.532 raeburn 2830: if ($origsrc =~ /\.(page|sequence)$/) {
2831: if ($newsubdir{$origsrc}) {
1.529 raeburn 2832: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2833: }
1.532 raeburn 2834: } elsif ($newsubdir{$key}) {
2835: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2836: }
2837: }
1.492 raeburn 2838: $changed = 1;
1.533 raeburn 2839: } elsif ($newdb{$idx} ne '') {
2840: $src = $newdb{$idx};
1.492 raeburn 2841: $changed = 1;
2842: }
2843: if ($changed) {
1.538 raeburn 2844: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2845: }
2846: }
2847: }
2848: foreach my $idx (keys(%remparam)) {
2849: if (ref($remparam{$idx}) eq 'ARRAY') {
2850: foreach my $name (@{$remparam{$idx}}) {
2851: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2852: }
2853: }
2854: }
1.533 raeburn 2855: if (values(%lockerrors) > 0) {
2856: $lockmsg = join('<br />',values(%lockerrors));
2857: }
1.491 raeburn 2858: my $storefn;
2859: if ($key eq $oldurl) {
2860: $storefn = $url;
2861: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2862: } else {
2863: $storefn = $key;
2864: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2865: if ($prefixchg && $before{'map'} && $after{'map'}) {
2866: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2867: }
1.529 raeburn 2868: if ($newsubdir{$key}) {
2869: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2870: }
1.491 raeburn 2871: }
1.492 raeburn 2872: my $report;
2873: if ($folder !~ /^supplemental/) {
2874: $report = 1;
2875: }
1.527 raeburn 2876: (my $outtext,$errtext) =
1.492 raeburn 2877: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2878: if ($errtext) {
1.529 raeburn 2879: if ($caller eq 'paste') {
1.533 raeburn 2880: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2881: }
1.491 raeburn 2882: }
2883: }
2884: }
1.533 raeburn 2885: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2886: }
2887:
2888: sub copy_dependencies {
2889: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2890: my $content;
2891: if (ref($contentref)) {
2892: $content = $$contentref;
2893: } else {
2894: $content = &Apache::lonnet::getfile($item);
2895: }
2896: unless ($content eq '-1') {
2897: my $mm = new File::MMagic;
2898: my $mimetype = $mm->checktype_contents($content);
2899: if ($mimetype eq 'text/html') {
2900: my (%allfiles,%codebase,$state);
2901: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2902: if ($res eq 'ok') {
2903: my ($numexisting,$numpathchanges,$existing);
2904: (undef,$numexisting,$numpathchanges,$existing) =
2905: &Apache::loncommon::ask_for_embedded_content(
2906: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2907: {'error_on_invalid_names' => 1,
2908: 'ignore_remote_references' => 1,
2909: 'docs_url' => $item,
2910: 'context' => 'paste'});
2911: if ($numexisting > 0) {
2912: if (ref($existing) eq 'HASH') {
2913: foreach my $dep (keys(%{$existing})) {
2914: my $depfile = $dep;
2915: unless ($depfile =~ m{^\Q$relpath\E}) {
2916: $depfile = $relpath.$dep;
2917: }
2918: my $depcontent = &Apache::lonnet::getfile($depfile);
2919: unless ($depcontent eq '-1') {
2920: my $storedep = $dep;
2921: $storedep =~ s{^\Q$relpath\E}{};
2922: my $dep_url =
2923: &Apache::lonclonecourse::writefile(
2924: $env{'request.course.id'},
2925: $storefn.$storedep,$depcontent);
2926: if ($dep_url eq '/adm/notfound.html') {
2927: if (ref($errors) eq 'HASH') {
2928: $errors->{$depfile} = 1;
2929: }
2930: } else {
2931: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2932: }
2933: }
2934: }
1.488 raeburn 2935: }
2936: }
2937: }
2938: }
2939: }
2940: return;
2941: }
2942:
1.329 droeschl 2943: my %parameter_type = ( 'randompick' => 'int_pos',
2944: 'hiddenresource' => 'string_yesno',
2945: 'encrypturl' => 'string_yesno',
2946: 'randomorder' => 'string_yesno',);
2947: my $valid_parameters_re = join('|',keys(%parameter_type));
2948: # set parameters
2949: sub update_parameter {
1.537 raeburn 2950: if ($env{'form.changeparms'} eq 'all') {
2951: my (@allidx,@allmapidx,%allchecked,%currchecked);
2952: %allchecked = (
2953: 'hiddenresource' => {},
2954: 'encrypturl' => {},
2955: 'randompick' => {},
2956: 'randomorder' => {},
2957: );
2958: foreach my $which (keys(%allchecked)) {
1.630 raeburn 2959: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 2960: if ($which eq 'randompick') {
2961: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2962: my ($res,$value) = split(/:/,$item);
2963: if ($value =~ /^\d+$/) {
2964: $allchecked{$which}{$res} = $value;
2965: }
2966: }
2967: } else {
1.539 raeburn 2968: if ($env{'form.all'.$which}) {
2969: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2970: }
1.537 raeburn 2971: }
2972: }
2973: my $haschanges = 0;
2974: foreach my $res (@LONCAPA::map::order) {
2975: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2976: $name=&LONCAPA::map::qtescape($name);
2977: $url=&LONCAPA::map::qtescape($url);
2978: next unless ($name && $url);
2979: my $is_map;
2980: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2981: $is_map = 1;
2982: }
2983: foreach my $which (keys(%allchecked)) {
2984: if (($which eq 'randompick' || $which eq 'randomorder')) {
2985: next if (!$is_map);
2986: }
2987: my $oldvalue = 0;
2988: my $newvalue = 0;
2989: if ($allchecked{$which}{$res}) {
2990: $newvalue = $allchecked{$which}{$res};
2991: }
2992: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2993: if ($which eq 'randompick') {
2994: if ($current =~ /^(\d+)$/) {
2995: $oldvalue = $1;
2996: }
2997: } else {
2998: if ($current =~ /^yes$/i) {
2999: $oldvalue = 1;
3000: }
3001: }
3002: if ($oldvalue ne $newvalue) {
3003: $haschanges = 1;
3004: if ($newvalue) {
3005: my $storeval = 'yes';
3006: if ($which eq 'randompick') {
3007: $storeval = $newvalue;
3008: }
3009: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3010: $storeval,
3011: $parameter_type{$which});
3012: &remember_parms($res,$which,'set',$storeval);
3013: } elsif ($oldvalue) {
3014: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3015: &remember_parms($res,$which,'del');
3016: }
3017: }
3018: }
3019: }
3020: return $haschanges;
3021: } else {
1.588 raeburn 3022: my $haschanges = 0;
3023: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3024:
1.537 raeburn 3025: my $which = $env{'form.changeparms'};
3026: my $idx = $env{'form.setparms'};
1.588 raeburn 3027: my $oldvalue = 0;
3028: my $newvalue = 0;
3029: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3030: if ($which eq 'randompick') {
3031: if ($current =~ /^(\d+)$/) {
3032: $oldvalue = $1;
3033: }
3034: } elsif ($current =~ /^yes$/i) {
3035: $oldvalue = 1;
3036: }
1.537 raeburn 3037: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3038: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3039: : 1;
3040: }
3041: if ($oldvalue ne $newvalue) {
3042: $haschanges = 1;
3043: if ($newvalue) {
3044: my $storeval = 'yes';
3045: if ($which eq 'randompick') {
3046: $storeval = $newvalue;
3047: }
3048: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3049: $parameter_type{$which});
3050: &remember_parms($idx,$which,'set',$storeval);
3051: } else {
3052: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3053: &remember_parms($idx,$which,'del');
3054: }
1.537 raeburn 3055: }
1.588 raeburn 3056: return $haschanges;
1.329 droeschl 3057: }
3058: }
3059:
3060: sub handle_edit_cmd {
3061: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3062: my $haschanges = 0;
1.543 raeburn 3063: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3064: return $haschanges;
1.543 raeburn 3065: }
1.329 droeschl 3066: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3067:
3068: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3069: my ($title, $url, @rrest) = split(':', $ratstr);
3070:
1.538 raeburn 3071: if ($cmd eq 'remove') {
1.329 droeschl 3072: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3073: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3074: &Apache::lonnet::removeuploadedurl($url);
3075: } else {
3076: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3077: }
3078: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3079: $haschanges = 1;
1.329 droeschl 3080: } elsif ($cmd eq 'cut') {
3081: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3082: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3083: $haschanges = 1;
1.344 bisitz 3084: } elsif ($cmd eq 'up'
1.329 droeschl 3085: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3086: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3087: $haschanges = 1;
1.329 droeschl 3088: } elsif ($cmd eq 'down'
3089: && defined($LONCAPA::map::order[$idx+1])) {
3090: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3091: $haschanges = 1;
1.329 droeschl 3092: } elsif ($cmd eq 'rename') {
3093: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3094: if ($comment=~/\S/) {
3095: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3096: $comment.':'.join(':', $url, @rrest);
3097: }
3098: # Devalidate title cache
3099: my $renamed_url=&LONCAPA::map::qtescape($url);
3100: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3101: $haschanges = 1;
3102: } elsif ($cmd eq 'setalias') {
3103: my $newvalue = $env{'form.alias'};
3104: if ($newvalue ne '') {
3105: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3106: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3107: 'string');
3108: &remember_parms($idx,'mapalias','set',$newvalue);
3109: $haschanges = 1;
3110: }
3111: }
3112: } elsif ($cmd eq 'delalias') {
3113: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3114: if ($current ne '') {
3115: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3116: &remember_parms($idx,'mapalias','del');
3117: $haschanges = 1;
3118: }
1.329 droeschl 3119: }
1.633 raeburn 3120: return $haschanges;
1.329 droeschl 3121: }
3122:
3123: sub editor {
1.458 raeburn 3124: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3125: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3126: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3127: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3128: if ($allowed) {
1.519 raeburn 3129: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3130: $is_random_order,$container) =
1.510 raeburn 3131: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3132: $r->print($breadcrumbtrail);
1.519 raeburn 3133: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3134: $container = 'page';
3135: } else {
3136: $container = 'sequence';
1.510 raeburn 3137: }
1.484 raeburn 3138:
1.525 raeburn 3139: my $jumpto;
3140:
3141: unless ($supplementalflag) {
1.546 raeburn 3142: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3143: }
1.484 raeburn 3144:
3145: unless ($allowed) {
3146: $randompick = -1;
3147: }
3148:
1.615 raeburn 3149: my ($errtext,$fatal);
3150: if (($folder eq '') && (!$supplementalflag)) {
3151: if (@LONCAPA::map::order) {
3152: undef(@LONCAPA::map::order);
3153: undef(@LONCAPA::map::resources);
3154: undef(@LONCAPA::map::resparms);
3155: undef(@LONCAPA::map::zombies);
3156: }
3157: $folder = 'default';
3158: $container = 'sequence';
3159: } else {
3160: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3161: $folder.'.'.$container);
3162: return $errtext if ($fatal);
3163: }
1.329 droeschl 3164:
3165: if ($#LONCAPA::map::order<1) {
3166: my $idx=&LONCAPA::map::getresidx();
3167: if ($idx<=0) { $idx=1; }
3168: $LONCAPA::map::order[0]=$idx;
3169: $LONCAPA::map::resources[$idx]='';
3170: }
1.364 bisitz 3171:
1.329 droeschl 3172: # ------------------------------------------------------------ Process commands
3173:
3174: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3175: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3176: # set parameters and change order
3177: &snapshotbefore();
3178:
3179: if (&update_parameter()) {
1.588 raeburn 3180: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3181: return $errtext if ($fatal);
3182: }
3183:
3184: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3185: # change order
3186: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3187: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3188:
3189: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3190: return $errtext if ($fatal);
3191: }
1.364 bisitz 3192:
1.329 droeschl 3193: if ($env{'form.pastemarked'}) {
1.491 raeburn 3194: my %paste_errors;
1.533 raeburn 3195: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3196: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3197: \%paste_errors);
1.541 raeburn 3198: if (ref($pastemsgarray) eq 'ARRAY') {
3199: if (@{$pastemsgarray} > 0) {
3200: $r->print('<p class="LC_info">'.
3201: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3202: '</p>');
3203: }
1.541 raeburn 3204: }
3205: if ($lockerror) {
3206: $r->print('<p class="LC_error">'.
3207: $lockerror.
3208: '</p>');
3209: }
3210: if ($save_error ne '') {
3211: return $save_error;
3212: }
3213: if ($paste_res) {
3214: my %errortext = &Apache::lonlocal::texthash (
3215: fail => 'Storage of folder contents failed',
3216: failread => 'Reading folder contents failed',
3217: failstore => 'Storage of folder contents failed',
3218: );
3219: if ($errortext{$paste_res}) {
3220: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3221: }
1.329 droeschl 3222: }
1.491 raeburn 3223: if (keys(%paste_errors) > 0) {
1.538 raeburn 3224: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3225: &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".
3226: '<ul>'."\n");
3227: foreach my $key (sort(keys(%paste_errors))) {
3228: $r->print('<li>'.$key.'</li>'."\n");
3229: }
3230: $r->print('</ul></p>'."\n");
3231: }
1.538 raeburn 3232: } elsif ($env{'form.clearmarked'}) {
3233: my $output = &do_buffer_empty();
3234: if ($output) {
3235: $r->print('<p class="LC_info">'.$output.'</p>');
3236: }
3237: }
1.329 droeschl 3238:
3239: $r->print($upload_output);
3240:
1.538 raeburn 3241: # Rename, cut, copy or remove a single resource
1.602 raeburn 3242: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3243: my $contentchg;
1.633 raeburn 3244: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3245: $contentchg = 1;
3246: }
3247: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3248: return $errtext if ($fatal);
3249: }
1.538 raeburn 3250:
3251: # Cut, copy and/or remove multiple resources
3252: if ($env{'form.multichange'}) {
3253: my %allchecked = (
3254: cut => {},
3255: remove => {},
3256: );
3257: my $needsupdate;
3258: foreach my $which (keys(%allchecked)) {
3259: $env{'form.multi'.$which} =~ s/,$//;
3260: if ($env{'form.multi'.$which}) {
3261: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3262: if (ref($allchecked{$which}) eq 'HASH') {
3263: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3264: }
3265: }
3266: }
3267: if ($needsupdate) {
3268: my $haschanges = 0;
3269: my %curr_groups = &Apache::longroup::coursegroups();
3270: my $total = scalar(@LONCAPA::map::order) - 1;
3271: for (my $i=$total; $i>=0; $i--) {
3272: my $res = $LONCAPA::map::order[$i];
3273: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3274: $name=&LONCAPA::map::qtescape($name);
3275: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3276: next unless $url;
1.538 raeburn 3277: my %denied =
3278: &action_restrictions($coursenum,$coursedom,$url,
3279: $env{'form.folderpath'},\%curr_groups);
3280: foreach my $which (keys(%allchecked)) {
3281: next if ($denied{$which});
3282: next unless ($allchecked{$which}{$res});
3283: if ($which eq 'remove') {
3284: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3285: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3286: &Apache::lonnet::removeuploadedurl($url);
3287: } else {
3288: &LONCAPA::map::makezombie($res);
3289: }
3290: splice(@LONCAPA::map::order,$i,1);
3291: $haschanges ++;
3292: } elsif ($which eq 'cut') {
3293: &LONCAPA::map::makezombie($res);
3294: splice(@LONCAPA::map::order,$i,1);
3295: $haschanges ++;
3296: }
3297: }
3298: }
3299: if ($haschanges) {
3300: ($errtext,$fatal) =
3301: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3302: return $errtext if ($fatal);
3303: }
3304: }
3305: }
3306:
1.329 droeschl 3307: # Group import/search
3308: if ($env{'form.importdetail'}) {
3309: my @imports;
3310: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3311: if (defined($item)) {
3312: my ($name,$url,$residx)=
1.533 raeburn 3313: map { &unescape($_); } split(/\=/,$item);
3314: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3315: my ($suffix,$errortxt,$locknotfreed) =
3316: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3317: if ($locknotfreed) {
3318: $r->print($locknotfreed);
3319: }
3320: if ($suffix) {
3321: $url =~ s/_new\./_$suffix./;
3322: } else {
3323: return $errortxt;
3324: }
1.533 raeburn 3325: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3326: my $type = $1;
3327: my ($suffix,$errortxt,$locknotfreed) =
3328: &new_timebased_suffix($coursedom,$coursenum,$type);
3329: if ($locknotfreed) {
3330: $r->print($locknotfreed);
3331: }
3332: if ($suffix) {
3333: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3334: } else {
3335: return $errortxt;
3336: }
1.626 raeburn 3337: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3338: my ($suffix,$errortxt,$locknotfreed) =
3339: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3340: if ($locknotfreed) {
3341: $r->print($locknotfreed);
3342: }
3343: if ($suffix) {
3344: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3345: } else {
3346: return $errortxt;
3347: }
1.534 raeburn 3348: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3349: if ($supplementalflag) {
3350: next unless ($1 eq 'supplemental');
3351: if ($folder eq 'supplemental') {
3352: next unless ($2 eq 'default');
3353: } else {
3354: next unless ($folder eq 'supplemental_'.$2);
3355: }
3356: } else {
3357: next unless ($1 eq 'docs');
3358: if ($folder eq 'default') {
3359: next unless ($2 eq 'default');
3360: } else {
3361: next unless ($folder eq 'default_'.$2);
3362: }
3363: }
1.504 raeburn 3364: }
1.329 droeschl 3365: push(@imports, [$name, $url, $residx]);
3366: }
3367: }
1.530 raeburn 3368: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3369: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3370: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3371: return $errtext if ($fatal);
1.529 raeburn 3372: if ($fixuperrors) {
3373: $r->print($fixuperrors);
3374: }
1.329 droeschl 3375: }
3376: # Loading a complete map
3377: if ($env{'form.loadmap'}) {
3378: if ($env{'form.importmap'}=~/\w/) {
3379: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3380: my ($title,$url,$ext,$type)=split(/\:/,$res);
3381: my $idx=&LONCAPA::map::getresidx($url);
3382: $LONCAPA::map::resources[$idx]=$res;
3383: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3384: }
3385: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3386: $folder.'.'.$container,1);
1.329 droeschl 3387: return $errtext if ($fatal);
3388: } else {
3389: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3390:
1.329 droeschl 3391: }
3392: }
3393: &log_differences($plain);
3394: }
3395: # ---------------------------------------------------------------- End commands
3396: # ---------------------------------------------------------------- Print screen
3397: my $idx=0;
3398: my $shown=0;
3399: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3400: $r->print('<div class="LC_Box">'.
1.432 raeburn 3401: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3402: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3403: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3404: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3405: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3406: '</ol>');
1.381 bisitz 3407: if ($randompick>=0) {
3408: $r->print('<p class="LC_warning">'
3409: .&mt('Caution: this folder is set to randomly pick a subset'
3410: .' of resources. Adding or removing resources from this'
3411: .' folder will change the set of resources that the'
3412: .' students see, resulting in spurious or missing credit'
3413: .' for completed problems, not limited to ones you'
3414: .' modify. Do not modify the contents of this folder if'
3415: .' it is in active student use.')
3416: .'</p>'
3417: );
3418: }
3419: if ($is_random_order) {
3420: $r->print('<p class="LC_warning">'
3421: .&mt('Caution: this folder is set to randomly order its'
3422: .' contents. Adding or removing resources from this folder'
3423: .' will change the order of resources shown.')
3424: .'</p>'
3425: );
3426: }
3427: $r->print('</div>');
1.364 bisitz 3428: }
1.381 bisitz 3429:
1.538 raeburn 3430: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3431: %filters = (
1.543 raeburn 3432: canremove => [],
3433: cancut => [],
3434: cancopy => [],
3435: hiddenresource => [],
3436: encrypturl => [],
3437: randomorder => [],
3438: randompick => [],
1.538 raeburn 3439: );
3440: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3441: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3442: foreach my $res (@LONCAPA::map::order) {
3443: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3444: $name=&LONCAPA::map::qtescape($name);
3445: $url=&LONCAPA::map::qtescape($url);
3446: unless ($name) { $name=(split(/\//,$url))[-1]; }
3447: unless ($name) { $idx++; next; }
1.537 raeburn 3448: push(@allidx,$res);
3449: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3450: push(@allmapidx,$res);
3451: }
1.617 raeburn 3452:
1.381 bisitz 3453: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3454: $coursenum,$coursedom,$crstype,
1.538 raeburn 3455: $pathitem,$supplementalflag,$container,
1.620 raeburn 3456: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3457: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3458: $idx++;
3459: $shown++;
1.329 droeschl 3460: }
1.424 onken 3461: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3462:
1.538 raeburn 3463: my $need_save;
1.611 raeburn 3464: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3465: my $toolslink;
1.611 raeburn 3466: if ($allowed) {
1.544 raeburn 3467: $toolslink = '<table><tr><td>'
1.520 raeburn 3468: .&Apache::loncommon::help_open_menu('Navigation Screen',
3469: 'Navigation_Screen',undef,'RAT')
3470: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3471: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3472: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3473: .'id="LC_content_toolbar_edittoplevel" '
3474: .'class="LC_toolbarItem" '
3475: .'title="'.&mt('Supplemental Content Editor').'">'
3476: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3477: }
1.510 raeburn 3478: if ($shown) {
3479: if ($allowed) {
3480: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3481: .&Apache::loncommon::start_data_table(undef,'contentlist')
3482: .&Apache::loncommon::start_data_table_header_row()
3483: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3484: .'<th colspan="3">'.&mt('Actions').'</th>'
1.538 raeburn 3485: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3486: if ($folder !~ /^supplemental/) {
1.633 raeburn 3487: $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
1.510 raeburn 3488: }
1.537 raeburn 3489: $to_show .= &Apache::loncommon::end_data_table_header_row();
3490: if ($folder !~ /^supplemental/) {
1.538 raeburn 3491: $lists{'canhide'} = join(',',@allidx);
3492: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3493: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3494: 'randomorder','randompick');
3495: foreach my $item (@possfilters) {
1.538 raeburn 3496: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3497: if (@{$filters{$item}} > 0) {
3498: $lists{$item} = join(',',@{$filters{$item}});
3499: }
1.538 raeburn 3500: }
3501: }
1.537 raeburn 3502: if (@allidx > 0) {
3503: my $path;
3504: if ($env{'form.folderpath'}) {
1.630 raeburn 3505: $path =
1.537 raeburn 3506: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3507: }
1.538 raeburn 3508: if (@allidx > 1) {
1.630 raeburn 3509: $to_show .=
1.538 raeburn 3510: &Apache::loncommon::continue_data_table_row().
3511: '<td colspan="2"> </td>'.
3512: '<td>'.
1.611 raeburn 3513: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3514: '</td>'.
1.633 raeburn 3515: '<td colspan="3"> </td>'.
3516: '<td colspan="2">'.
1.611 raeburn 3517: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3518: '</td>'.
3519: &Apache::loncommon::end_data_table_row();
3520: $need_save = 1;
3521: }
1.537 raeburn 3522: }
3523: }
3524: $to_show .= $output.' '
1.510 raeburn 3525: .&Apache::loncommon::end_data_table()
3526: .'<br style="line-height:2px;" />'
3527: .&Apache::loncommon::end_scrollbox();
3528: } else {
1.520 raeburn 3529: $to_show .= $toolslink
1.510 raeburn 3530: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3531: .$output.' '
3532: .&Apache::loncommon::end_data_table();
1.393 raeburn 3533: }
1.510 raeburn 3534: } else {
1.520 raeburn 3535: if (!$allowed) {
3536: $to_show .= $toolslink;
3537: }
1.615 raeburn 3538: my $noresmsg;
3539: if ($allowed && $hiddentop && !$supplementalflag) {
3540: $noresmsg = &mt('Main Content Hidden');
3541: } else {
3542: $noresmsg = &mt('Currently empty');
3543: }
1.510 raeburn 3544: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3545: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3546: .$noresmsg
1.510 raeburn 3547: .'</div>'
3548: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3549: }
3550: } else {
1.510 raeburn 3551: if ($shown) {
3552: $to_show = '<div>'
3553: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3554: .$output
3555: .&Apache::loncommon::end_data_table()
3556: .'</div>';
3557: } else {
3558: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3559: .&mt('Currently empty')
1.510 raeburn 3560: .'</div>'
3561: }
1.458 raeburn 3562: }
3563: my $tid = 1;
3564: if ($supplementalflag) {
3565: $tid = 2;
1.329 droeschl 3566: }
3567: if ($allowed) {
1.484 raeburn 3568: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3569: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3570: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3571: if ($canedit) {
3572: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3573: }
1.460 raeburn 3574: } else {
3575: $r->print($to_show);
1.329 droeschl 3576: }
3577: return;
3578: }
3579:
1.538 raeburn 3580: sub multiple_check_form {
1.611 raeburn 3581: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3582: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3583: my $disabled;
3584: unless ($canedit) {
3585: $disabled = 'disabled="disabled"';
3586: }
1.538 raeburn 3587: my $output =
3588: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3589: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3590: '<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>'.
3591: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3592: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3593: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3594: if ($caller eq 'settings') {
3595: $output .=
3596: '<table><tr>'.
3597: '<td class="LC_docs_entry_parameter">'.
3598: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3599: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3600: '</label></span></td>'.
3601: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3602: '<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 3603: '</span></td>'.
3604: '</tr>'."\n".
3605: '<tr>'.
3606: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3607: '<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 3608: '</label></span>'.
3609: '</td></tr></table>'."\n";
3610: } else {
3611: $output .=
3612: '<table><tr>'.
3613: '<td class="LC_docs_entry_parameter">'.
3614: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3615: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3616: '</label></span></td>'.
3617: '<td class="LC_docs_entry_parameter">'.
3618: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3619: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3620: '</label></span></td>'."\n".
3621: '<td class="LC_docs_entry_parameter">'.
3622: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3623: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3624: '</label></span></td>'.
3625: '</tr></table>'."\n";
3626: }
3627: $output .=
3628: '</fieldset>'.
3629: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3630: if ($caller eq 'settings') {
3631: $output .=
1.543 raeburn 3632: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3633: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3634: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3635: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3636: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3637: } elsif ($caller eq 'actions') {
3638: $output .=
3639: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3640: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3641: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3642: }
3643: $output .=
3644: '</form>'.
3645: '</div>';
3646: return $output;
3647: }
3648:
1.329 droeschl 3649: sub process_file_upload {
1.552 raeburn 3650: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3651: # upload a file, if present
1.552 raeburn 3652: my $filesize = length($env{'form.uploaddoc'});
3653: if (!$filesize) {
3654: $$upload_output = '<div class="LC_error">'.
3655: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3656: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3657: $filesize).'<br />'.
3658: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3659: '</div>';
3660: return;
3661: }
3662: my $quotatype = 'unofficial';
3663: if ($crstype eq 'Community') {
1.601 raeburn 3664: $quotatype = 'community';
3665: } elsif ($crstype eq 'Placement') {
3666: $quotatype = 'placement';
1.580 raeburn 3667: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3668: $quotatype = 'official';
1.573 raeburn 3669: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3670: $quotatype = 'textbook';
1.552 raeburn 3671: }
3672: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3673: $filesize = int($filesize/1000); #expressed in kb
3674: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3675: $env{'form.uploaddoc.filename'},$filesize,
3676: 'upload',$quotatype);
1.552 raeburn 3677: return if ($$upload_output);
3678: }
1.440 raeburn 3679: my ($parseaction,$showupload,$nextphase,$mimetype);
3680: if ($env{'form.parserflag'}) {
1.329 droeschl 3681: $parseaction = 'parse';
3682: }
3683: my $folder=$env{'form.folder'};
3684: if ($folder eq '') {
3685: $folder='default';
3686: }
3687: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3688: my $errtext='';
3689: my $fatal=0;
3690: my $container='sequence';
1.519 raeburn 3691: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3692: $container='page';
3693: }
3694: ($errtext,$fatal)=
1.534 raeburn 3695: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3696: if ($#LONCAPA::map::order<1) {
3697: $LONCAPA::map::order[0]=1;
3698: $LONCAPA::map::resources[1]='';
3699: }
3700: my $destination = 'docs/';
3701: if ($folder =~ /^supplemental/) {
3702: $destination = 'supplemental/';
3703: }
3704: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3705: $destination .= 'default/';
3706: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3707: $destination .= $2.'/';
3708: }
1.534 raeburn 3709: if ($fatal) {
3710: $$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>';
3711: return;
3712: }
1.440 raeburn 3713: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3714: my $newidx=&LONCAPA::map::getresidx();
3715: $destination .= $newidx;
1.439 raeburn 3716: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3717: $parseaction,$allfiles,
1.440 raeburn 3718: $codebase,undef,undef,undef,undef,
3719: undef,undef,\$mimetype);
3720: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3721: my $stored = $1;
3722: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3723: $stored.'</span>').'</p>';
3724: } else {
3725: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3726:
1.457 raeburn 3727: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3728: return;
3729: }
1.329 droeschl 3730: my $ext='false';
3731: if ($url=~m{^http://}) { $ext='true'; }
3732: $url = &LONCAPA::map::qtunescape($url);
3733: my $comment=$env{'form.comment'};
3734: $comment = &LONCAPA::map::qtunescape($comment);
3735: if ($folder=~/^supplemental/) {
3736: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3737: $env{'user.domain'}.'___&&&___'.$comment;
3738: }
3739:
3740: $LONCAPA::map::resources[$newidx]=
3741: $comment.':'.$url.':'.$ext.':normal:res';
3742: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3743: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3744: $folder.'.'.$container,1);
1.329 droeschl 3745: if ($fatal) {
1.457 raeburn 3746: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3747: return;
1.329 droeschl 3748: } else {
1.440 raeburn 3749: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3750: $$upload_output = $showupload;
1.384 raeburn 3751: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3752: if ($total_embedded > 0) {
1.440 raeburn 3753: my $uploadphase = 'upload_embedded';
3754: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3755: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3756: my ($embedded,$num) =
1.440 raeburn 3757: &Apache::loncommon::ask_for_embedded_content(
3758: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3759: if ($embedded) {
3760: if ($num) {
3761: $$upload_output .=
3762: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3763: $nextphase = $uploadphase;
3764: } else {
3765: $$upload_output .= $embedded;
3766: }
3767: } else {
3768: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3769: }
1.329 droeschl 3770: } else {
1.440 raeburn 3771: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3772: }
1.457 raeburn 3773: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3774: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3775: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3776: $nextphase = 'decompress_uploaded';
3777: my $position = scalar(@LONCAPA::map::order)-1;
3778: my $noextract = &return_to_editor();
3779: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3780: my %archiveitems = (
3781: folderpath => $env{'form.folderpath'},
3782: cmd => $nextphase,
3783: newidx => $newidx,
3784: position => $position,
3785: phase => $nextphase,
1.477 raeburn 3786: comment => $comment,
1.480 raeburn 3787: );
3788: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3789: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3790: $$upload_output = $showupload.
3791: &Apache::loncommon::decompress_form($mimetype,
3792: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3793: \%archiveitems,\@current);
1.329 droeschl 3794: }
3795: }
3796: }
1.440 raeburn 3797: return $nextphase;
1.329 droeschl 3798: }
3799:
1.480 raeburn 3800: sub get_dir_list {
3801: my ($url,$coursenum,$coursedom,$newidx) = @_;
3802: my ($destination,$dir_root) = &embedded_destination();
3803: my ($dirlistref,$listerror) =
3804: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3805: my @dir_lines;
3806: my $dirptr=16384;
3807: if (ref($dirlistref) eq 'ARRAY') {
3808: foreach my $dir_line (sort
3809: {
3810: my ($afile)=split('&',$a,2);
3811: my ($bfile)=split('&',$b,2);
3812: return (lc($afile) cmp lc($bfile));
3813: } (@{$dirlistref})) {
3814: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3815: $filename =~ s/\s+$//;
3816: next if ($filename =~ /^\.\.?$/);
3817: my $isdir = 0;
3818: if ($dirptr&$testdir) {
3819: $isdir = 1;
3820: }
3821: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3822: }
3823: }
3824: return @dir_lines;
3825: }
3826:
1.329 droeschl 3827: sub is_supplemental_title {
3828: my ($title) = @_;
3829: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3830: }
3831:
3832: # --------------------------------------------------------------- An entry line
3833:
3834: sub entryline {
1.501 raeburn 3835: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3836: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3837: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3838: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3839: if (&is_supplemental_title($title)) {
1.488 raeburn 3840: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3841: } else {
3842: $title=&HTML::Entities::encode($title,'"<>&\'');
3843: $renametitle=$title;
3844: $foldertitle=$title;
3845: }
3846:
1.611 raeburn 3847: my ($disabled,$readonly,$js_lt);
3848: unless ($canedit) {
3849: $disabled = 'disabled="disabled"';
3850: $readonly = 1;
3851: }
3852:
1.329 droeschl 3853: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3854:
1.329 droeschl 3855: $renametitle=~s/\\/\\\\/g;
3856: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3857: $renametitle=~s/"/%22/g;
1.581 raeburn 3858: $renametitle=~s/ /%20/g;
3859: $oldtitle = $renametitle;
1.576 raeburn 3860: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3861: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3862: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3863: # Edit commands
1.633 raeburn 3864: my ($esc_path, $path, $symb, $curralias);
1.329 droeschl 3865: if ($env{'form.folderpath'}) {
3866: $esc_path=&escape($env{'form.folderpath'});
3867: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3868: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3869: }
1.505 raeburn 3870: my $isexternal;
1.510 raeburn 3871: if ($residx) {
1.501 raeburn 3872: my $currurl = $url;
3873: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3874: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3875: $isexternal = 1;
3876: }
1.510 raeburn 3877: if (!$supplementalflag) {
3878: my $path = 'uploaded/'.
3879: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3880: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3881: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3882: $residx,
3883: &Apache::lonnet::declutter($currurl));
3884: }
1.501 raeburn 3885: }
1.538 raeburn 3886: my ($renamelink,%lt,$ishash);
3887: if (ref($filtersref) eq 'HASH') {
3888: $ishash = 1;
3889: }
3890:
1.329 droeschl 3891: if ($allowed) {
1.538 raeburn 3892: $form_start = '
3893: <form action="/adm/coursedocs" method="post">
3894: ';
3895: $form_common=(<<END);
3896: <input type="hidden" name="folderpath" value="$path" />
3897: <input type="hidden" name="symb" value="$symb" />
3898: END
3899: $form_param=(<<END);
3900: <input type="hidden" name="setparms" value="$orderidx" />
3901: <input type="hidden" name="changeparms" value="0" />
3902: END
3903: $form_end = '</form>';
3904:
1.329 droeschl 3905: my $incindex=$index+1;
3906: my $selectbox='';
1.471 raeburn 3907: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3908: ((split(/\:/,
1.344 bisitz 3909: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3910: ne '') &&
1.329 droeschl 3911: ((split(/\:/,
1.344 bisitz 3912: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3913: ne '')) {
3914: $selectbox=
3915: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3916: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3917: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3918: if ($i==$incindex) {
1.358 bisitz 3919: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3920: } else {
3921: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3922: }
3923: }
3924: $selectbox.='</select>';
3925: }
1.501 raeburn 3926: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3927: 'up' => 'Move Up',
3928: 'dw' => 'Move Down',
3929: 'rm' => 'Remove',
3930: 'ct' => 'Cut',
3931: 'rn' => 'Rename',
1.501 raeburn 3932: 'cp' => 'Copy',
1.633 raeburn 3933: 'da' => 'Unset alias',
3934: 'sa' => 'Set alias',
1.501 raeburn 3935: 'ex' => 'External Resource',
1.598 raeburn 3936: 'et' => 'External Tool',
1.501 raeburn 3937: 'ed' => 'Edit',
3938: 'pr' => 'Preview',
3939: 'sv' => 'Save',
3940: 'ul' => 'URL',
1.611 raeburn 3941: 'ti' => 'Title',
1.618 raeburn 3942: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3943: );
1.538 raeburn 3944: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3945: $env{'form.folderpath'},
3946: $currgroups);
1.517 raeburn 3947: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3948: my $skip_confirm = 0;
1.603 raeburn 3949: my $confirm_removal = 0;
1.329 droeschl 3950: if ( $folder =~ /^supplemental/
3951: || ($url =~ m{( /smppg$
3952: |/syllabus$
3953: |/aboutme$
3954: |/navmaps$
3955: |/bulletinboard$
1.626 raeburn 3956: |/ext\.tool$
1.505 raeburn 3957: |\.html$)}x)
3958: || $isexternal) {
1.329 droeschl 3959: $skip_confirm = 1;
3960: }
1.603 raeburn 3961: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3962: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3963: $confirm_removal = 1;
3964: }
1.633 raeburn 3965: if ($url =~ /$LONCAPA::assess_re/) {
3966: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
3967: }
1.329 droeschl 3968:
1.538 raeburn 3969: if ($denied{'copy'}) {
1.543 raeburn 3970: $copylink=(<<ENDCOPY)
1.507 raeburn 3971: <span style="visibility: hidden;">$lt{'cp'}</span>
3972: ENDCOPY
3973: } else {
1.538 raeburn 3974: my $formname = 'edit_copy_'.$orderidx;
3975: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3976: $copylink=(<<ENDCOPY);
1.538 raeburn 3977: <form name="$formname" method="post" action="/adm/coursedocs">
3978: $form_common
1.611 raeburn 3979: <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 3980: $form_end
1.329 droeschl 3981: ENDCOPY
1.538 raeburn 3982: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3983: push(@{$filtersref->{'cancopy'}},$orderidx);
3984: }
1.329 droeschl 3985: }
1.538 raeburn 3986: if ($denied{'cut'}) {
1.507 raeburn 3987: $cutlink=(<<ENDCUT);
3988: <span style="visibility: hidden;">$lt{'ct'}</span>
3989: ENDCUT
3990: } else {
1.538 raeburn 3991: my $formname = 'edit_cut_'.$orderidx;
3992: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3993: $cutlink=(<<ENDCUT);
1.538 raeburn 3994: <form name="$formname" method="post" action="/adm/coursedocs">
3995: $form_common
1.542 raeburn 3996: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3997: <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 3998: $form_end
1.329 droeschl 3999: ENDCUT
1.538 raeburn 4000: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4001: push(@{$filtersref->{'cancut'}},$orderidx);
4002: }
1.329 droeschl 4003: }
1.538 raeburn 4004: if ($denied{'remove'}) {
1.507 raeburn 4005: $removelink=(<<ENDREM);
4006: <span style="visibility: hidden;">$lt{'rm'}</a>
4007: ENDREM
4008: } else {
1.538 raeburn 4009: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4010: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4011: $removelink=(<<ENDREM);
1.538 raeburn 4012: <form name="$formname" method="post" action="/adm/coursedocs">
4013: $form_common
1.542 raeburn 4014: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4015: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4016: <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 4017: $form_end
1.497 raeburn 4018: ENDREM
1.538 raeburn 4019: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4020: push(@{$filtersref->{'canremove'}},$orderidx);
4021: }
1.497 raeburn 4022: }
1.551 raeburn 4023: $renamelink=(<<ENDREN);
1.581 raeburn 4024: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4025: ENDREN
1.611 raeburn 4026: my ($uplink,$downlink);
4027: if ($canedit) {
4028: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4029: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4030: } else {
4031: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4032: $downlink = $uplink;
4033: }
1.329 droeschl 4034: $line.=(<<END);
4035: <td>
1.379 bisitz 4036: <div class="LC_docs_entry_move">
1.611 raeburn 4037: <a href="$uplink">
1.501 raeburn 4038: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4039: </a>
4040: </div>
4041: <div class="LC_docs_entry_move">
1.611 raeburn 4042: <a href="$downlink">
1.501 raeburn 4043: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4044: </a>
4045: </div>
1.329 droeschl 4046: </td>
4047: <td>
4048: $form_start
1.538 raeburn 4049: $form_param
1.478 raeburn 4050: $form_common
1.329 droeschl 4051: $selectbox
4052: $form_end
4053: </td>
1.540 raeburn 4054: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4055: $removelink
1.329 droeschl 4056: $cutlink
4057: $copylink
4058: </td>
4059: END
4060: }
4061: # Figure out what kind of a resource this is
4062: my ($extension)=($url=~/\.(\w+)$/);
4063: my $uploaded=($url=~/^\/*uploaded\//);
4064: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4065: my $isfolder;
4066: my $ispage;
4067: my $containerarg;
1.615 raeburn 4068: my $folderurl;
1.329 droeschl 4069: if ($uploaded) {
1.472 raeburn 4070: if (($extension eq 'sequence') || ($extension eq 'page')) {
4071: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4072: $containerarg = $1;
1.472 raeburn 4073: if ($extension eq 'sequence') {
4074: $icon=$iconpath.'navmap.folder.closed.gif';
4075: $isfolder=1;
4076: } else {
4077: $icon=$iconpath.'page.gif';
4078: $ispage=1;
4079: }
1.615 raeburn 4080: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4081: if ($allowed) {
4082: $url='/adm/coursedocs?';
4083: } else {
4084: $url='/adm/supplemental?';
4085: }
1.329 droeschl 4086: } else {
4087: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4088: }
4089: }
1.364 bisitz 4090:
1.621 raeburn 4091: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4092: my $orig_url = $url;
1.340 raeburn 4093: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 4094: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 4095: if (!$supplementalflag && $residx && $symb) {
4096: if ((!$isfolder) && (!$ispage)) {
4097: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4098: $url=&Apache::lonnet::clutter($url);
4099: if ($url=~/^\/*uploaded\//) {
4100: $url=~/\.(\w+)$/;
4101: my $embstyle=&Apache::loncommon::fileembstyle($1);
4102: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4103: $url='/adm/wrapper'.$url;
4104: } elsif ($embstyle eq 'ssi') {
4105: #do nothing with these
4106: } elsif ($url!~/\.(sequence|page)$/) {
4107: $url='/adm/coursedocs/showdoc'.$url;
4108: }
1.623 raeburn 4109: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4110: my $wrapped = $1;
4111: my $exturl = $2;
4112: if ($wrapped eq '') {
4113: $url='/adm/wrapper'.$url;
4114: }
4115: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4116: $nomodal = 1;
4117: }
1.626 raeburn 4118: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4119: $url='/adm/wrapper'.$url;
1.621 raeburn 4120: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4121: if (($ENV{'SERVER_PORT'} == 443) &&
4122: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4123: $url .= '?usehttp=1';
4124: $nomodal = 1;
4125: }
1.598 raeburn 4126: }
1.501 raeburn 4127: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4128: my $shownsymb = $symb;
4129: if ($isexternal) {
4130: if ($url =~ /^([^#]+)#([^#]+)$/) {
4131: $url = $1;
4132: $anchor = $2;
4133: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4134: $shownsymb = $1.&escape('#').$anchor;
4135: }
4136: }
4137: }
1.617 raeburn 4138: unless ($env{'request.role.adv'}) {
4139: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4140: $url = '';
4141: }
4142: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4143: $url = '';
4144: $hiddenres = 1;
4145: }
4146: }
4147: if ($url ne '') {
1.641 raeburn 4148: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.617 raeburn 4149: }
1.615 raeburn 4150: } elsif (!$env{'request.role.adv'}) {
4151: my $checkencrypt;
4152: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4153: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4154: $checkencrypt = 1;
1.620 raeburn 4155: } elsif (ref($navmapref)) {
1.615 raeburn 4156: unless (ref($$navmapref)) {
4157: $$navmapref = Apache::lonnavmaps::navmap->new();
4158: }
4159: if (ref($$navmapref)) {
4160: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4161: $checkencrypt = 1;
4162: }
4163: }
4164: }
4165: if ($checkencrypt) {
4166: my $shownsymb = &Apache::lonenc::encrypted($symb);
4167: my $shownurl = &Apache::lonenc::encrypted($url);
4168: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.641 raeburn 4169: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.615 raeburn 4170: if ($env{'request.enc'} ne '') {
4171: delete($env{'request.enc'});
4172: }
4173: } else {
4174: $url='';
1.613 raeburn 4175: }
1.612 raeburn 4176: } else {
4177: $url='';
4178: }
1.501 raeburn 4179: } else {
4180: $url='';
4181: }
1.329 droeschl 4182: }
1.621 raeburn 4183: } elsif ($supplementalflag) {
1.610 raeburn 4184: if ($isexternal) {
4185: if ($url =~ /^([^#]+)#([^#]+)$/) {
4186: $url = $1;
4187: $anchor = $2;
1.623 raeburn 4188: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4189: if ($hostname ne '') {
4190: $url = 'http://'.$hostname.$url;
4191: }
4192: $nomodal = 1;
4193: }
1.610 raeburn 4194: }
1.621 raeburn 4195: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4196: if (($ENV{'SERVER_PORT'} == 443) &&
4197: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.622 raeburn 4198: if ($hostname ne '') {
4199: $url = 'http://'.$hostname.$url;
4200: }
1.621 raeburn 4201: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4202: $nomodal = 1;
4203: }
1.610 raeburn 4204: }
1.329 droeschl 4205: }
1.615 raeburn 4206: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4207: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4208: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4209: my $foldername=&escape($foldertitle);
4210: my $folderpath=$env{'form.folderpath'};
4211: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4212: if (!$allowed && $supplementalflag) {
1.519 raeburn 4213: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4214: $url.='folderpath='.&escape($folderpath);
4215: } else {
1.617 raeburn 4216: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4217: 'parameter_randompick'))[0];
4218: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4219: 'parameter_randomorder'))[0]=~/^yes$/i);
4220: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4221: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4222: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4223: 'parameter_encrypturl'))[0]=~/^yes$/i);
4224: unless ($hiddenmap) {
1.620 raeburn 4225: if (ref($navmapref)) {
4226: unless (ref($$navmapref)) {
4227: $$navmapref = Apache::lonnavmaps::navmap->new();
4228: }
4229: if (ref($$navmapref)) {
4230: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4231: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4232: unless (@resources) {
4233: $hiddenmap = 1;
4234: unless ($env{'request.role.adv'}) {
4235: $url = '';
4236: $hiddenfolder = 1;
4237: }
1.617 raeburn 4238: }
1.615 raeburn 4239: }
4240: }
4241: }
4242: }
1.617 raeburn 4243: unless ($encryptmap) {
1.620 raeburn 4244: if ((ref($navmapref)) && (ref($$navmapref))) {
4245: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4246: $encryptmap = 1;
4247: }
1.617 raeburn 4248: }
4249: }
1.630 raeburn 4250:
1.617 raeburn 4251: # Append randompick number, hidden, and encrypted with ":" to foldername,
4252: # so it gets transferred between levels
4253: $folderpath.=$containerarg.'&'.$foldername.
4254: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4255: unless ($url eq '') {
1.612 raeburn 4256: $url.='folderpath='.&escape($folderpath);
4257: }
1.510 raeburn 4258: my $rpckchk;
4259: if ($rpicknum) {
4260: $rpckchk = ' checked="checked"';
1.543 raeburn 4261: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4262: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4263: }
1.510 raeburn 4264: }
1.537 raeburn 4265: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4266: $rand_pick_text =
1.478 raeburn 4267: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4268: $form_param."\n".
1.478 raeburn 4269: $form_common."\n".
1.611 raeburn 4270: '<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 4271: if ($rpicknum ne '') {
4272: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4273: }
1.537 raeburn 4274: $rand_pick_text .= '</span></span>'.
4275: $form_end;
1.543 raeburn 4276: my $ro_set;
1.617 raeburn 4277: if ($randorder) {
1.543 raeburn 4278: $ro_set = 'checked="checked"';
4279: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4280: push(@{$filtersref->{'randomorder'}},$orderidx);
4281: }
4282: }
1.564 raeburn 4283: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4284: $rand_order_text =
1.537 raeburn 4285: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4286: $form_param."\n".
1.537 raeburn 4287: $form_common."\n".
1.611 raeburn 4288: '<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 4289: $form_end;
1.510 raeburn 4290: }
1.509 raeburn 4291: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4292: my $isexttool;
1.626 raeburn 4293: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4294: $url='/adm/wrapper'.$url;
4295: $isexttool = 1;
4296: }
1.510 raeburn 4297: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4298: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4299: if ($title) {
4300: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4301: }
1.598 raeburn 4302: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4303: $url .= '&idx='.$orderidx;
4304: }
1.610 raeburn 4305: if ($anchor ne '') {
4306: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4307: }
1.329 droeschl 4308: }
1.519 raeburn 4309: my ($tdalign,$tdwidth);
1.501 raeburn 4310: if ($allowed) {
1.630 raeburn 4311: my $fileloc =
1.501 raeburn 4312: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4313: if ($isexternal) {
1.630 raeburn 4314: ($editlink,$extresform) =
1.611 raeburn 4315: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4316: undef,undef,undef,undef,undef,undef,
4317: undef,$disabled);
1.626 raeburn 4318: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4319: ($editlink,$extresform) =
4320: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4321: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4322: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4323: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4324: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4325: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4326: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4327: my $suppanchor;
4328: if ($supplementalflag) {
4329: $suppanchor = $anchor;
4330: }
1.630 raeburn 4331: my $jscall =
1.501 raeburn 4332: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4333: $switchserver,
1.503 raeburn 4334: $forceedit,
1.511 raeburn 4335: undef,$symb,
4336: &escape($env{'form.folderpath'}),
1.622 raeburn 4337: $renametitle,$hostname,
4338: '','',1,$suppanchor);
1.501 raeburn 4339: if ($jscall) {
1.518 raeburn 4340: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4341: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4342: }
4343: }
4344: }
1.519 raeburn 4345: $tdalign = ' align="right" valign="top"';
4346: $tdwidth = ' width="80%"';
1.329 droeschl 4347: }
1.408 raeburn 4348: my $reinit;
4349: if ($crstype eq 'Community') {
4350: $reinit = &mt('(re-initialize community to access)');
4351: } else {
4352: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4353: }
4354: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.633 raeburn 4355: if ($url =~ /$LONCAPA::assess_re/) {
4356: $line.= '<br />';
4357: if ($curralias ne '') {
4358: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4359: $lt{'da'}.'</a></span>';
4360: } else {
4361: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4362: $lt{'sa'}.'</a></span>';
4363: }
4364: }
4365: $line.='</td><td>';
1.621 raeburn 4366: my $link;
1.472 raeburn 4367: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4368: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4369: } elsif ($url) {
1.610 raeburn 4370: if ($anchor ne '') {
4371: if ($supplementalflag) {
4372: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4373: } else {
4374: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4375: }
4376: }
1.622 raeburn 4377: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4378: $link = 'http://'.$hostname.$url;
4379: } else {
4380: $link = $url;
4381: }
4382: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.621 raeburn 4383: (($anchor ne '')?$anchor:''));
4384: if ($nomodal) {
4385: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4386: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4387: } else {
4388: $line.=&Apache::loncommon::modal_link($link,
4389: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4390: }
1.469 www 4391: } else {
4392: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4393: }
1.519 raeburn 4394: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4395: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4396: $line.='<a href="'.$url.'">'.$title.'</a>';
4397: } elsif ($url) {
1.621 raeburn 4398: if ($nomodal) {
4399: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4400: $title.'</a>';
4401: } else {
4402: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4403: }
1.617 raeburn 4404: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4405: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4406: } else {
4407: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4408: }
1.633 raeburn 4409: if (($allowed) && ($curralias ne '')) {
4410: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4411: } else {
4412: $line .= $extresform;
4413: }
4414: $line .= '</td>';
1.478 raeburn 4415: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4416: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4417: if (($allowed) && ($folder!~/^supplemental/)) {
4418: my %lt=&Apache::lonlocal::texthash(
4419: 'hd' => 'Hidden',
4420: 'ec' => 'URL hidden');
1.543 raeburn 4421: my ($enctext,$hidtext);
4422: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4423: $enctext = ' checked="checked"';
4424: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4425: push(@{$filtersref->{'encrypturl'}},$orderidx);
4426: }
4427: }
4428: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4429: $hidtext = ' checked="checked"';
4430: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4431: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4432: }
4433: }
1.537 raeburn 4434: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4435: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4436: $line.=(<<ENDPARMS);
4437: <td class="LC_docs_entry_parameter">
1.537 raeburn 4438: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4439: $form_param
1.478 raeburn 4440: $form_common
1.611 raeburn 4441: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4442: $form_end
1.458 raeburn 4443: <br />
1.537 raeburn 4444: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4445: $form_param
1.478 raeburn 4446: $form_common
1.611 raeburn 4447: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4448: $form_end
4449: </td>
1.478 raeburn 4450: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4451: $rand_order_text</td>
1.329 droeschl 4452: ENDPARMS
4453: }
1.379 bisitz 4454: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4455: return $line;
4456: }
4457:
1.538 raeburn 4458: sub action_restrictions {
4459: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4460: my %denied = (
4461: cut => 0,
4462: copy => 0,
4463: remove => 0,
4464: );
4465: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4466: # no copy for published maps
4467: $denied{'copy'} = 1;
1.597 raeburn 4468: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4469: unless ($1 eq 'simpleproblem') {
4470: $denied{'copy'} = 1;
4471: }
4472: $denied{'cut'} = 1;
1.538 raeburn 4473: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4474: if ($folderpath =~ /^default&[^\&]+$/) {
4475: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4476: $denied{'remove'} = 1;
4477: }
4478: $denied{'cut'} = 1;
4479: $denied{'copy'} = 1;
4480: }
4481: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4482: my $group = $1;
4483: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4484: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4485: $denied{'remove'} = 1;
4486: }
4487: }
4488: $denied{'cut'} = 1;
4489: $denied{'copy'} = 1;
4490: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4491: my $group = $1;
4492: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4493: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4494: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4495: if (keys(%groupsettings) > 0) {
4496: $denied{'remove'} = 1;
4497: }
4498: $denied{'cut'} = 1;
4499: $denied{'copy'} = 1;
4500: }
4501: }
4502: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4503: my $group = $1;
4504: if ($url =~ /group_boards_\Q$group\E/) {
4505: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4506: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4507: if (keys(%groupsettings) > 0) {
4508: if (ref($groupsettings{'functions'}) eq 'HASH') {
4509: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4510: $denied{'remove'} = 1;
4511: }
4512: }
4513: }
4514: $denied{'cut'} = 1;
4515: $denied{'copy'} = 1;
4516: }
4517: }
4518: }
4519: return %denied;
4520: }
4521:
1.533 raeburn 4522: sub new_timebased_suffix {
1.538 raeburn 4523: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4524: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4525: if ($type eq 'paste') {
4526: $prefix = $type;
4527: $namespace = 'courseeditor';
1.587 raeburn 4528: $idtype = 'addcode';
1.538 raeburn 4529: } elsif ($type eq 'map') {
1.533 raeburn 4530: $prefix = 'docs';
4531: if ($area eq 'supplemental') {
4532: $prefix = 'supp';
4533: }
4534: $prefix .= $container;
4535: $namespace = 'uploadedmaps';
4536: } else {
4537: $prefix = $type;
4538: $namespace = 'templated';
1.504 raeburn 4539: }
4540: my ($suffix,$freedlock,$error) =
1.587 raeburn 4541: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4542: if (!$suffix) {
1.538 raeburn 4543: if ($type eq 'paste') {
4544: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4545: } elsif ($type eq 'map') {
1.533 raeburn 4546: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4547: } elsif ($type eq 'smppg') {
4548: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4549: } elsif ($type eq 'exttool') {
4550: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4551: } else {
1.565 bisitz 4552: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4553: }
1.504 raeburn 4554: if ($error) {
4555: $errtext .= '<br />'.$error;
4556: }
4557: }
4558: if ($freedlock ne 'ok') {
1.630 raeburn 4559: $locknotfreed =
1.533 raeburn 4560: '<div class="LC_error">'.
4561: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4562: if ($type eq 'paste') {
1.591 raeburn 4563: if ($freedlock eq 'nolock') {
4564: $locknotfreed =
4565: '<div class="LC_error">'.
4566: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4567:
1.593 droeschl 4568: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4569: } else {
4570: $locknotfreed .=
4571: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4572: }
1.538 raeburn 4573: } elsif ($type eq 'map') {
1.591 raeburn 4574: $locknotfreed .=
4575: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4576: } elsif ($type eq 'smppg') {
4577: $locknotfreed .=
4578: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4579: } elsif ($type eq 'exttool') {
4580: $locknotfreed .=
4581: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4582: } else {
4583: $locknotfreed .=
1.565 bisitz 4584: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4585: }
1.538 raeburn 4586: unless ($type eq 'paste') {
4587: $locknotfreed .=
1.560 raeburn 4588: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4589: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4590: }
4591: $locknotfreed .= '</div>';
1.504 raeburn 4592: }
4593: return ($suffix,$errtext,$locknotfreed);
4594: }
4595:
1.329 droeschl 4596: =pod
4597:
4598: =item tiehash()
4599:
4600: tie the hash
4601:
4602: =cut
4603:
4604: sub tiehash {
4605: my ($mode)=@_;
4606: $hashtied=0;
4607: if ($env{'request.course.fn'}) {
4608: if ($mode eq 'write') {
4609: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4610: &GDBM_WRCREAT(),0640)) {
4611: $hashtied=2;
4612: }
4613: } else {
4614: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4615: &GDBM_READER(),0640)) {
4616: $hashtied=1;
4617: }
4618: }
1.364 bisitz 4619: }
1.329 droeschl 4620: }
4621:
4622: sub untiehash {
4623: if ($hashtied) { untie %hash; }
4624: $hashtied=0;
4625: return OK;
4626: }
4627:
4628:
4629:
4630:
4631: sub checkonthis {
1.637 raeburn 4632: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4633: $url=&unescape($url);
4634: $alreadyseen{$url}=1;
4635: $r->rflush();
4636: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4637: $r->print("\n<br />");
4638: if ($level==0) {
4639: $r->print("<br />");
4640: }
4641: for (my $i=0;$i<=$level*5;$i++) {
4642: $r->print(' ');
4643: }
4644: $r->print('<a href="'.$url.'" target="cat">'.
4645: ($title?$title:$url).'</a> ');
4646: if ($url=~/^\/res\//) {
1.637 raeburn 4647: my $updated;
4648: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4649: ($url !~ /\.\d+\.\w+$/)) {
4650: $updated = &Apache::lonnet::remove_stale_resfile($url);
4651: }
1.329 droeschl 4652: my $result=&Apache::lonnet::repcopy(
4653: &Apache::lonnet::filelocation('',$url));
4654: if ($result eq 'ok') {
4655: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4656: if ($updated) {
4657: $r->print('<br />');
4658: for (my $i=0;$i<=$level*5;$i++) {
4659: $r->print(' ');
4660: }
4661: $r->print('- '.&mt('Outdated copy removed'));
4662: }
1.329 droeschl 4663: $r->rflush();
4664: &Apache::lonnet::countacc($url);
4665: $url=~/\.(\w+)$/;
4666: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4667: $r->print('<br />');
4668: $r->rflush();
4669: for (my $i=0;$i<=$level*5;$i++) {
4670: $r->print(' ');
4671: }
4672: $r->print('- '.&mt('Rendering:').' ');
4673: my ($errorcount,$warningcount)=split(/:/,
4674: &Apache::lonnet::ssi_body($url,
4675: ('grade_target'=>'web',
4676: 'return_only_error_and_warning_counts' => 1)));
4677: if (($errorcount) ||
4678: ($warningcount)) {
4679: if ($errorcount) {
1.369 bisitz 4680: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4681: &mt('[quant,_1,error]',$errorcount).'</span>');
4682: }
4683: if ($warningcount) {
4684: $r->print('<span class="LC_warning">'.
4685: &mt('[quant,_1,warning]',$warningcount).'</span>');
4686: }
4687: } else {
4688: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4689: }
4690: $r->rflush();
4691: }
4692: my $dependencies=
4693: &Apache::lonnet::metadata($url,'dependencies');
4694: foreach my $dep (split(/\,/,$dependencies)) {
4695: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4696: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4697: }
4698: }
4699: } elsif ($result eq 'unavailable') {
4700: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4701: } elsif ($result eq 'not_found') {
4702: unless ($url=~/\$/) {
1.521 bisitz 4703: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4704: } else {
1.366 bisitz 4705: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4706: }
4707: } else {
4708: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4709: }
1.637 raeburn 4710: if (($updated) && ($result ne 'ok')) {
4711: $r->print('<br />'.&mt('Outdated copy removed'));
4712: }
1.329 droeschl 4713: }
4714: }
4715: }
4716:
4717:
4718:
4719: =pod
4720:
4721: =item list_symbs()
4722:
1.485 raeburn 4723: List Content Identifiers
1.329 droeschl 4724:
4725: =cut
4726:
4727: sub list_symbs {
4728: my ($r) = @_;
4729:
1.408 raeburn 4730: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4731: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4732: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4733: $r->print(&startContentScreen('tools'));
1.329 droeschl 4734: my $navmap = Apache::lonnavmaps::navmap->new();
4735: if (!defined($navmap)) {
4736: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4737: '<div class="LC_error">'.
4738: &mt('Unable to retrieve information about course contents').
4739: '</div>');
1.408 raeburn 4740: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4741: } else {
1.484 raeburn 4742: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4743: &Apache::loncommon::start_data_table().
4744: &Apache::loncommon::start_data_table_header_row().
4745: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4746: &Apache::loncommon::end_data_table_header_row()."\n");
4747: my $count;
1.329 droeschl 4748: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4749: $r->print(&Apache::loncommon::start_data_table_row().
4750: '<td>'.$res->compTitle().'</td>'.
4751: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4752: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4753: $count ++;
4754: }
4755: if (!$count) {
4756: $r->print(&Apache::loncommon::start_data_table_row().
4757: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4758: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4759: }
1.484 raeburn 4760: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4761: }
1.521 bisitz 4762: $r->print(&endContentScreen());
1.329 droeschl 4763: }
4764:
1.637 raeburn 4765: sub contentverifyform {
4766: my ($r) = @_;
4767: my $crstype = &Apache::loncommon::course_type();
4768: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4769: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4770: $r->print(&startContentScreen('tools'));
4771: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4772: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4773: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4774: ' <span class="LC_nobreak">'.
4775: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4776: &mt('No').'</label>'.(' 'x2).
4777: '<label><input type="radio" name="checkstale" value="1" />'.
4778: &mt('Yes').'</label></span></p><p>'.
4779: '<input type="submit" value="'.&mt('Verify content').' "/>'.
4780: '<input type="hidden" value="1" name="tools" />'.
4781: '<input type="hidden" value="1" name="verify" /></p></form>');
4782: $r->print(&endContentScreen());
4783: return;
4784: }
1.329 droeschl 4785:
4786: sub verifycontent {
1.637 raeburn 4787: my ($r,$checkstale) = @_;
1.408 raeburn 4788: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4789: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4790: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4791: $r->print(&startContentScreen('tools'));
4792: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4793: $hashtied=0;
4794: undef %alreadyseen;
4795: %alreadyseen=();
4796: &tiehash();
1.484 raeburn 4797:
1.329 droeschl 4798: foreach my $key (keys(%hash)) {
4799: if ($hash{$key}=~/\.(page|sequence)$/) {
4800: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4801: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4802: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4803: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4804: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4805: }
4806: }
4807: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 4808: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4809: }
4810: }
4811: &untiehash();
1.442 www 4812: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4813: $r->print(&endContentScreen());
1.329 droeschl 4814: }
4815:
4816: sub devalidateversioncache {
4817: my $src=shift;
4818: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4819: &Apache::lonnet::clutter($src));
4820: }
4821:
4822: sub checkversions {
1.611 raeburn 4823: my ($r,$canedit) = @_;
1.408 raeburn 4824: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4825: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4826: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4827: $r->print(&startContentScreen('tools'));
1.442 www 4828:
1.329 droeschl 4829: my $header='';
4830: my $startsel='';
4831: my $monthsel='';
4832: my $weeksel='';
4833: my $daysel='';
4834: my $allsel='';
4835: my %changes=();
4836: my $starttime=0;
4837: my $haschanged=0;
4838: my %setversions=&Apache::lonnet::dump('resourceversions',
4839: $env{'course.'.$env{'request.course.id'}.'.domain'},
4840: $env{'course.'.$env{'request.course.id'}.'.num'});
4841:
4842: $hashtied=0;
4843: &tiehash();
1.611 raeburn 4844: if ($canedit) {
4845: my %newsetversions=();
4846: if ($env{'form.setmostrecent'}) {
4847: $haschanged=1;
4848: foreach my $key (keys(%hash)) {
4849: if ($key=~/^ids\_(\/res\/.+)$/) {
4850: $newsetversions{$1}='mostrecent';
4851: &devalidateversioncache($1);
4852: }
4853: }
4854: } elsif ($env{'form.setcurrent'}) {
4855: $haschanged=1;
4856: foreach my $key (keys(%hash)) {
4857: if ($key=~/^ids\_(\/res\/.+)$/) {
4858: my $getvers=&Apache::lonnet::getversion($1);
4859: if ($getvers>0) {
4860: $newsetversions{$1}=$getvers;
4861: &devalidateversioncache($1);
4862: }
4863: }
1.329 droeschl 4864: }
1.611 raeburn 4865: } elsif ($env{'form.setversions'}) {
4866: $haschanged=1;
4867: foreach my $key (keys(%env)) {
4868: if ($key=~/^form\.set_version_(.+)$/) {
4869: my $src=$1;
4870: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4871: $newsetversions{$src}=$env{$key};
4872: &devalidateversioncache($src);
4873: }
4874: }
1.329 droeschl 4875: }
1.611 raeburn 4876: }
4877: if ($haschanged) {
4878: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4879: $env{'course.'.$env{'request.course.id'}.'.domain'},
4880: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4881: $r->print(&Apache::loncommon::confirmwrapper(
4882: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4883: } else {
4884: $r->print(&Apache::loncommon::confirmwrapper(
4885: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4886: }
1.611 raeburn 4887: &mark_hash_old();
4888: }
4889: &changewarning($r,'');
1.329 droeschl 4890: }
4891: if ($env{'form.timerange'} eq 'all') {
4892: # show all documents
1.549 raeburn 4893: $header=&mt('All content in '.$crstype);
1.521 bisitz 4894: $allsel=' selected="selected"';
1.329 droeschl 4895: foreach my $key (keys(%hash)) {
4896: if ($key=~/^ids\_(\/res\/.+)$/) {
4897: my $src=$1;
4898: $changes{$src}=1;
4899: }
4900: }
4901: } else {
4902: # show documents which changed
4903: %changes=&Apache::lonnet::dump
4904: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4905: $env{'course.'.$env{'request.course.id'}.'.num'});
4906: my $firstkey=(keys(%changes))[0];
4907: unless ($firstkey=~/^error\:/) {
4908: unless ($env{'form.timerange'}) {
4909: $env{'form.timerange'}=604800;
4910: }
4911: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4912: .&mt('seconds');
4913: if ($env{'form.timerange'}==-1) {
4914: $seltext='since start of course';
1.521 bisitz 4915: $startsel=' selected="selected"';
1.329 droeschl 4916: $env{'form.timerange'}=time;
4917: }
4918: $starttime=time-$env{'form.timerange'};
4919: if ($env{'form.timerange'}==2592000) {
4920: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4921: $monthsel=' selected="selected"';
1.329 droeschl 4922: } elsif ($env{'form.timerange'}==604800) {
4923: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4924: $weeksel=' selected="selected"';
1.329 droeschl 4925: } elsif ($env{'form.timerange'}==86400) {
4926: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4927: $daysel=' selected="selected"';
1.329 droeschl 4928: }
4929: $header=&mt('Content changed').' '.$seltext;
4930: } else {
4931: $header=&mt('No content modifications yet.');
4932: }
4933: }
4934: %setversions=&Apache::lonnet::dump('resourceversions',
4935: $env{'course.'.$env{'request.course.id'}.'.domain'},
4936: $env{'course.'.$env{'request.course.id'}.'.num'});
4937: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4938: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4939: 'lm' => 'Version changes since last Month',
4940: 'lw' => 'Version changes since last Week',
4941: 'sy' => 'Version changes since Yesterday',
4942: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4943: 'cd' => 'Change display',
1.329 droeschl 4944: 'sd' => 'Display',
4945: 'fi' => 'File',
4946: 'md' => 'Modification Date',
4947: 'mr' => 'Most recently published Version',
1.408 raeburn 4948: 've' => 'Version used in '.$crstype,
4949: 'vu' => 'Set Version to be used in '.$crstype,
4950: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4951: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4952: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4953: 'di' => 'Differences',
1.484 raeburn 4954: 'save' => 'Save changes',
4955: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4956: 'act' => 'Actions');
1.611 raeburn 4957: my ($disabled,$readonly);
4958: unless ($canedit) {
4959: $disabled = 'disabled="disabled"';
4960: $readonly = 1;
4961: }
1.329 droeschl 4962: $r->print(<<ENDHEADERS);
1.484 raeburn 4963: <h4 class="LC_info">$header</h4>
1.329 droeschl 4964: <form action="/adm/coursedocs" method="post">
4965: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4966: <div class="LC_left_float">
1.479 golterma 4967: <fieldset>
1.484 raeburn 4968: <legend>$lt{'cd'}</legend>
1.329 droeschl 4969: <select name="timerange">
1.521 bisitz 4970: <option value='all'$allsel>$lt{'al'}</option>
4971: <option value="-1"$startsel>$lt{'st'}</option>
4972: <option value="2592000"$monthsel>$lt{'lm'}</option>
4973: <option value="604800"$weeksel>$lt{'lw'}</option>
4974: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4975: </select>
4976: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4977: </fieldset>
4978: </div>
4979: <div class="LC_left_float">
4980: <fieldset>
4981: <legend>$lt{'act'}</legend>
1.611 raeburn 4982: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4983: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4984: </fieldset>
4985: </div>
4986: <br clear="all" />
4987: <hr />
4988: <h4>$lt{'vers'}</h4>
1.329 droeschl 4989: ENDHEADERS
1.479 golterma 4990: #number of columns for version history
1.571 raeburn 4991: my %changedbytime;
4992: foreach my $key (keys(%changes)) {
4993: #excludes not versionable problems from resource version history:
4994: next if ($key =~ /^\/res\/lib\/templates/);
4995: my $chg;
4996: if ($env{'form.timerange'} eq 'all') {
4997: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4998: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4999: } else {
5000: $chg = $changes{$key};
5001: next if ($chg < $starttime);
5002: }
5003: push(@{$changedbytime{$chg}},$key);
5004: }
5005: if (keys(%changedbytime) == 0) {
5006: &untiehash();
5007: $r->print(&mt('No content changes in imported content in specified time frame').
5008: &endContentScreen());
5009: return;
5010: }
1.479 golterma 5011: $r->print(
1.611 raeburn 5012: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5013: &Apache::loncommon::start_data_table().
5014: &Apache::loncommon::start_data_table_header_row().
5015: '<th>'.&mt('Resources').'</th>'.
5016: "<th>$lt{'mr'}</th>".
5017: "<th>$lt{'ve'}</th>".
5018: "<th>$lt{'vu'}</th>".
5019: '<th>'.&mt('History').'</th>'.
5020: &Apache::loncommon::end_data_table_header_row()
5021: );
1.571 raeburn 5022: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5023: foreach my $key (sort(@{$changedbytime{$chg}})) {
5024: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5025: my $currentversion=&Apache::lonnet::getversion($key);
5026: if ($currentversion<0) {
5027: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5028: }
5029: my $linkurl=&Apache::lonnet::clutter($key);
5030: $r->print(
5031: &Apache::loncommon::start_data_table_row().
5032: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5033: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5034: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5035: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5036: '<td align="right">'
5037: );
5038: # Used in course
5039: my $usedversion=$hash{'version_'.$linkurl};
5040: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5041: if ($usedversion != $currentversion) {
1.479 golterma 5042: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5043: } else {
1.479 golterma 5044: $r->print($usedversion);
5045: }
1.329 droeschl 5046: } else {
1.521 bisitz 5047: $r->print($currentversion);
1.329 droeschl 5048: }
1.571 raeburn 5049: $r->print('</td><td title="'.$lt{'vu'}.'">');
5050: # Set version
5051: $r->print(&Apache::loncommon::select_form(
5052: $setversions{$linkurl},
5053: 'set_version_'.$linkurl,
5054: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5055: '' => '',
5056: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5057: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5058: my $lastold=1;
5059: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5060: my $url=$root.'.'.$prevvers.'.'.$extension;
5061: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5062: $lastold=$prevvers;
5063: }
5064: }
5065: $r->print('</td>');
5066: # List all available versions
5067: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5068: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5069: my $url=$root.'.'.$prevvers.'.'.$extension;
5070: $r->print(
5071: '<span class="LC_nobreak">'
5072: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5073: .&mt('Version [_1]',$prevvers).'</a>'
5074: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5075: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5076: .')');
5077: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5078: $r->print(
5079: ' <a href="/adm/diff?filename='.
5080: &Apache::lonnet::clutter($root.'.'.$extension).
5081: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5082: '" target="diffs">'.&mt('Diffs').'</a>');
5083: }
5084: $r->print('</span><br />');
1.329 droeschl 5085: }
1.571 raeburn 5086: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5087: }
1.329 droeschl 5088: }
1.521 bisitz 5089: $r->print(
5090: &Apache::loncommon::end_data_table().
1.611 raeburn 5091: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5092: '</form>'
5093: );
1.329 droeschl 5094:
5095: &untiehash();
1.521 bisitz 5096: $r->print(&endContentScreen());
1.571 raeburn 5097: return;
1.329 droeschl 5098: }
5099:
5100: sub mark_hash_old {
5101: my $retie_hash=0;
5102: if ($hashtied) {
5103: $retie_hash=1;
5104: &untiehash();
5105: }
5106: &tiehash('write');
5107: $hash{'old'}=1;
5108: &untiehash();
5109: if ($retie_hash) { &tiehash(); }
5110: }
5111:
5112: sub is_hash_old {
5113: my $untie_hash=0;
5114: if (!$hashtied) {
5115: $untie_hash=1;
5116: &tiehash();
5117: }
5118: my $return=$hash{'old'};
5119: if ($untie_hash) { &untiehash(); }
5120: return $return;
5121: }
5122:
5123: sub changewarning {
5124: my ($r,$postexec,$message,$url)=@_;
5125: if (!&is_hash_old()) { return; }
5126: my $pathvar='folderpath';
5127: my $path=&escape($env{'form.folderpath'});
5128: if (!defined($url)) {
5129: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5130: }
5131: my $course_type = &Apache::loncommon::course_type();
5132: if (!defined($message)) {
5133: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5134: }
5135: $r->print("\n\n".
1.372 bisitz 5136: '<script type="text/javascript">'."\n".
5137: '// <![CDATA['."\n".
5138: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5139: '// ]]>'."\n".
1.369 bisitz 5140: '</script>'."\n".
1.375 tempelho 5141: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5142: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5143: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5144: &mt($message,' <input type="hidden" name="'.
5145: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5146: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5147: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5148: }
5149:
5150:
5151: sub init_breadcrumbs {
1.571 raeburn 5152: my ($form,$text,$help)=@_;
1.329 droeschl 5153: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5154: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5155: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5156: faq=>273,
5157: bug=>'Instructor Interface',
1.571 raeburn 5158: help => $help});
1.329 droeschl 5159: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5160: text=>$text,
5161: faq=>273,
5162: bug=>'Instructor Interface'});
5163: }
5164:
1.441 www 5165: # subroutine to list form elements
5166: sub create_list_elements {
5167: my @formarr = @_;
5168: my $list = '';
1.501 raeburn 5169: foreach my $button (@formarr){
5170: foreach my $picture (keys(%{$button})) {
5171: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5172: }
5173: }
5174: return $list;
5175: }
1.329 droeschl 5176:
1.441 www 5177: # subroutine to create ul from list elements
5178: sub create_form_ul {
5179: my $list = shift;
5180: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5181: return $ul;
5182: }
1.329 droeschl 5183:
1.442 www 5184: #
5185: # Start tabs
5186: #
5187:
5188: sub startContentScreen {
1.484 raeburn 5189: my ($mode) = @_;
5190: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5191: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5192: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5193: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5194: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5195: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5196: } else {
1.549 raeburn 5197: $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 5198: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5199: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5200: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5201: }
5202: $output .= "\n".'</ul>'."\n";
5203: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5204: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5205: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5206: return $output;
1.442 www 5207: }
5208:
5209: #
5210: # End tabs
5211: #
5212:
5213: sub endContentScreen {
1.484 raeburn 5214: return '</div></div></div>';
1.442 www 5215: }
1.329 droeschl 5216:
1.446 www 5217: sub supplemental_base {
1.548 raeburn 5218: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5219: }
5220:
1.329 droeschl 5221: sub handler {
5222: my $r = shift;
5223: &Apache::loncommon::content_type($r,'text/html');
5224: $r->send_http_header;
5225: return OK if $r->header_only;
1.484 raeburn 5226:
5227: # get course data
1.408 raeburn 5228: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5229: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5230: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5231:
1.606 raeburn 5232: # get docroot
5233: my $londocroot = $r->dir_config('lonDocRoot');
5234:
1.484 raeburn 5235: # graphics settings
5236: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5237:
1.443 www 5238: #
1.329 droeschl 5239: # --------------------------------------------- Initialize help topics for this
5240: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5241: 'Adding_External_Resource','Adding_External_Tool',
5242: 'Navigate_Content','Adding_Folders','Docs_Overview',
5243: 'Load_Map','Supplemental','Score_Upload_Form',
5244: 'Adding_Pages','Importing_LON-CAPA_Resource',
5245: 'Importing_IMS_Course','Uploading_From_Harddrive',
5246: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5247: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5248: }
5249: # Composite help files
5250: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5251: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5252: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5253: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5254: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5255: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5256: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5257: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5258: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5259: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5260:
1.611 raeburn 5261: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5262: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5263: unless ($r->uri eq '/adm/supplemental') {
5264: # does this user have privileges to modify content.
1.611 raeburn 5265: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5266: $allowed = 1;
5267: $canedit = 1;
5268: $canview = 1;
5269: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5270: $allowed = 1;
5271: $canview = 1;
5272: }
5273: }
5274: unless ($canedit) {
5275: $disabled = ' disabled="disabled"';
1.472 raeburn 5276: }
1.582 raeburn 5277: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5278: if ($env{'form.inhibitmenu'}) {
5279: unless ($env{'form.inhibitmenu'} eq 'yes') {
5280: delete($env{'form.inhibitmenu'});
5281: }
5282: }
5283:
1.582 raeburn 5284: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5285: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5286: if (!$canedit) {
5287: &verifycontent($r);
5288: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5289: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5290: text=>'Results',
5291: faq=>273,
5292: bug=>'Instructor Interface'});
5293: &verifycontent($r,$env{'form.checkstale'});
5294: } else {
5295: &contentverifyform($r);
5296: }
1.329 droeschl 5297: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5298: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5299: &list_symbs($r);
5300: } elsif ($allowed && $env{'form.docslog'}) {
5301: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5302: my $folder = $env{'form.folder'};
5303: if ($folder eq '') {
5304: $folder='default';
5305: }
1.611 raeburn 5306: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5307: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5308: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5309: &checkversions($r,$canedit);
5310: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5311: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5312: &dumpcourse($r);
1.611 raeburn 5313: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5314: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5315: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5316: } else {
1.611 raeburn 5317: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5318: $noendpage = 1;
5319: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5320: if ($redirect) {
5321: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5322: my $container = 'sequence';
5323: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5324: $is_random_order,$container) =
5325: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5326: my (@folders)=split('&',$env{'form.folderpath'});
5327: $env{'form.foldername'}=&unescape(pop(@folders));
5328: my $folder=pop(@folders);
5329: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5330: $folder.'.'.$container);
5331: my $warning;
5332: if ($fatal) {
5333: if ($container eq 'page') {
5334: $warning = &mt('An error occurred retrieving the contents of the current page.');
5335: } else {
5336: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5337: }
5338: } else {
5339: my $url = $redirect;
5340: my $srcfile = $londocroot.$url;
5341: $url =~ s{^/priv/}{/res/};
5342: my $targetfile = $londocroot.$url;
5343: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5344: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5345: $env{'form.folder'} = $folder;
5346: &snapshotbefore();
5347: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5348: my $ext = 'false';
5349: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5350: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5351: ':'.$ext.':normal:res';
5352: push(@LONCAPA::map::order,$newidx);
5353: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5354: 'string_yesno');
5355: &remember_parms($newidx,'hiddenresource','set','yes');
5356: ($errtext,$fatal) =
5357: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5358: &log_differences($plain);
5359: &mark_hash_old();
5360: $r->internal_redirect($redirect);
5361: return OK;
5362: }
5363: }
5364: }
5365: }
1.445 www 5366: #
5367: # Done catching special calls
1.484 raeburn 5368: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5369: # Get the parameters that may be needed
5370: #
5371: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5372: ['folderpath',
5373: 'forcesupplement','forcestandard',
1.510 raeburn 5374: 'tools','symb','command','supppath']);
1.445 www 5375:
1.635 raeburn 5376: foreach my $item ('forcesupplement','forcestandard','tools') {
5377: next if ($env{'form.'.$item} eq '');
5378: unless ($env{'form.'.$item} eq '1') {
5379: delete($env{'form.'.$item});
5380: }
5381: }
5382:
5383: if ($env{'form.command'}) {
5384: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5385: delete($env{'form.command'});
5386: }
5387: }
5388:
5389: if ($env{'form.symb'}) {
5390: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5391: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5392: delete($env{'form.symb'});
5393: }
5394: }
5395:
1.445 www 5396: # standard=1: this is a "new-style" course with an uploaded map as top level
5397: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5398:
5399: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5400:
1.484 raeburn 5401: # Decide whether this should display supplemental or main content or utilities
1.445 www 5402: # supplementalflag=1: show supplemental documents
5403: # supplementalflag=0: show standard documents
1.484 raeburn 5404: # toolsflag=1: show utilities
1.445 www 5405:
1.561 raeburn 5406: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5407: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5408: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5409: $supplementalflag=0;
5410: }
5411: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5412: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5413: unless ($allowed) { $supplementalflag=1; }
5414: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5415: my $toolsflag=0;
5416: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5417:
1.635 raeburn 5418: if ($env{'form.folderpath'} ne '') {
5419: my @items = split(/\&/,$env{'form.folderpath'});
5420: my $badpath;
5421: for (my $i=0; $i<@items; $i++) {
5422: my $odd = $i%2;
5423: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5424: $badpath = 1;
5425: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5426: $badpath = 1;
5427: }
5428: last if ($badpath);
5429: }
5430: if ($badpath) {
5431: delete($env{'form.folderpath'});
5432: }
5433: }
5434:
5435: if ($env{'form.supppath'} ne '') {
5436: my @items = split(/\&/,$env{'form.supppath'});
5437: my $badpath;
5438: for (my $i=0; $i<@items; $i++) {
5439: my $odd = $i%2;
5440: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5441: $badpath = 1;
5442: }
5443: last if ($badpath);
5444: }
5445: if ($badpath) {
5446: delete($env{'form.supppath'});
5447: }
5448: }
5449:
1.329 droeschl 5450: my $script='';
5451: my $showdoc=0;
1.457 raeburn 5452: my $addentries = {};
1.475 raeburn 5453: my $container;
1.329 droeschl 5454: my $containertag;
1.508 raeburn 5455: my $pathitem;
1.598 raeburn 5456: my %ltitools;
1.617 raeburn 5457: my $hiddentop;
1.615 raeburn 5458: my $navmap;
1.617 raeburn 5459: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5460:
1.464 www 5461: # Do we directly jump somewhere?
1.525 raeburn 5462: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5463: if ($env{'form.symb'} ne '') {
1.522 raeburn 5464: $env{'form.folderpath'}=
1.617 raeburn 5465: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5466: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5467: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5468: } elsif ($env{'form.supppath'} ne '') {
5469: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5470: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5471: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5472: }
1.472 raeburn 5473: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5474: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5475: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5476: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5477: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5478: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5479: } elsif ($env{'form.command'} eq 'contents') {
5480: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5481: } elsif ($env{'form.command'} eq 'home') {
5482: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5483: }
5484:
1.525 raeburn 5485:
1.445 www 5486: # Where do we store these for when we come back?
5487: my $stored_folderpath='docs_folderpath';
5488: if ($supplementalflag) {
5489: $stored_folderpath='docs_sup_folderpath';
5490: }
1.464 www 5491:
1.519 raeburn 5492: # No folderpath, and in edit mode, see if we have something stored
5493: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5494: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5495: {'folderpath' => 'scalar'});
1.615 raeburn 5496:
5497: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5498: if ($supplementalflag) {
5499: undef($env{'form.folderpath'}) if ($1 eq 'default');
5500: } else {
5501: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5502: }
5503: } else {
1.523 raeburn 5504: undef($env{'form.folderpath'});
5505: }
1.329 droeschl 5506: }
1.446 www 5507:
5508: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5509: if (!$allowed) {
1.446 www 5510: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5511: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5512: }
5513: }
1.446 www 5514: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5515: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5516: $env{'form.folderpath'} = &supplemental_base()
5517: .'&'.
1.329 droeschl 5518: $env{'form.folderpath'};
5519: }
1.615 raeburn 5520: # If allowed and user's role is not advanced check folderpath is not hidden
5521: if (($allowed) && (!$env{'request.role.adv'}) &&
5522: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5523: my $folderurl;
5524: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5525: my $folder = $pathitems[-2];
5526: if ($folder eq '') {
5527: undef($env{'form.folderpath'});
5528: } else {
5529: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5530: if ((split(/\:/,$pathitems[-1]))[4]) {
5531: $folderurl .= '.page';
5532: } else {
5533: $folderurl .= '.sequence';
5534: }
1.617 raeburn 5535: unless (ref($navmap)) {
5536: $navmap = Apache::lonnavmaps::navmap->new();
5537: }
1.615 raeburn 5538: if (ref($navmap)) {
5539: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5540: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5541: unless (@resources) {
5542: undef($env{'form.folderpath'});
5543: }
1.615 raeburn 5544: }
5545: }
5546: }
5547: }
5548:
5549:
1.446 www 5550: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5551: unless ($env{'form.folderpath'}) {
1.446 www 5552: if ($supplementalflag) {
5553: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5554: } elsif ($allowed) {
5555: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5556: }
1.472 raeburn 5557: }
1.446 www 5558:
1.445 www 5559: # Store this
1.484 raeburn 5560: unless ($toolsflag) {
1.615 raeburn 5561: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5562: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5563: {'folderpath' => 'scalar'});
1.510 raeburn 5564: }
1.519 raeburn 5565: my $folderpath;
1.484 raeburn 5566: if ($env{'form.folderpath'}) {
1.519 raeburn 5567: $folderpath = $env{'form.folderpath'};
5568: my (@folders)=split('&',$env{'form.folderpath'});
5569: $env{'form.foldername'}=&unescape(pop(@folders));
5570: if ($env{'form.foldername'} =~ /\:1$/) {
5571: $container = 'page';
5572: } else {
5573: $container = 'sequence';
5574: }
5575: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5576: } else {
1.519 raeburn 5577: if ($env{'form.folder'} eq '' ||
5578: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5579: if ($env{'form.folder'} eq 'supplemental') {
5580: $folderpath=&supplemental_base();
5581: } elsif (!$hiddentop) {
5582: $folderpath='default&'.
5583: &escape(&mt('Main Content').':::::');
5584: }
1.484 raeburn 5585: }
5586: }
1.519 raeburn 5587: $containertag = '<input type="hidden" name="folderpath" value="" />';
5588: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5589: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5590: $showdoc='/'.$1;
5591: }
5592: if ($showdoc) { # got called in sequence from course
5593: $allowed=0;
5594: } else {
1.611 raeburn 5595: if ($canedit) {
1.484 raeburn 5596: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5597: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5598: }
5599: }
1.329 droeschl 5600: }
5601:
1.344 bisitz 5602: # get personal data
1.329 droeschl 5603: my $uname=$env{'user.name'};
5604: my $udom=$env{'user.domain'};
5605: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5606:
5607: if ($allowed) {
1.484 raeburn 5608: if ($toolsflag) {
5609: $script .= &inject_data_js();
5610: my ($home,$other,%outhash)=&authorhosts();
5611: if (!$home && $other) {
5612: my @hosts;
5613: foreach my $aurole (keys(%outhash)) {
5614: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5615: push(@hosts,$outhash{$aurole});
5616: }
5617: }
5618: $script .= &dump_switchserver_js(@hosts);
5619: }
1.458 raeburn 5620: } else {
1.570 raeburn 5621: my $tid = 1;
1.484 raeburn 5622: my @tabids;
5623: if ($supplementalflag) {
5624: @tabids = ('002','ee2','ff2');
1.570 raeburn 5625: $tid = 2;
1.484 raeburn 5626: } else {
5627: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5628: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5629: unshift(@tabids,'001');
5630: push(@tabids,('dd1','ee1'));
5631: }
1.458 raeburn 5632: }
1.484 raeburn 5633: my $tabidstr = join("','",@tabids);
1.644 raeburn 5634: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600 raeburn 5635: my $posslti = keys(%ltitools);
1.622 raeburn 5636: my $hostname = $r->hostname();
1.606 raeburn 5637: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5638: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5639: &history_tab_js().
5640: &inject_data_js().
1.570 raeburn 5641: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5642: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5643: $addentries = {
1.485 raeburn 5644: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5645: };
1.458 raeburn 5646: }
1.538 raeburn 5647: $script .= &paste_popup_js();
1.501 raeburn 5648: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5649: &mt('Switch server?');
5650:
5651:
1.329 droeschl 5652: }
5653: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5654: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5655: .'// <![CDATA['."\n"
5656: .$script."\n"
5657: .'// ]]>'."\n"
1.595 musolffc 5658: .'</script>'."\n"
5659: .'<script type="text/javascript"
5660: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5661:
5662: # Breadcrumbs
5663: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5664:
5665: if ($showdoc) {
5666: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5667: {'force_register' => $showdoc,}));
1.571 raeburn 5668: } elsif ($toolsflag) {
1.611 raeburn 5669: my ($breadtext,$breadtitle);
1.617 raeburn 5670: $breadtext = "$crstype Editor";
1.611 raeburn 5671: if ($canedit) {
5672: $breadtitle = 'Editing '.$crstype.' Contents';
5673: } else {
5674: $breadtext .= ' (View-only mode)';
5675: $breadtitle = 'Viewing '.$crstype.' Contents';
5676: }
1.571 raeburn 5677: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5678: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5679: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5680: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5681: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5682: $breadtitle)
1.571 raeburn 5683: );
1.510 raeburn 5684: } elsif ($r->uri eq '/adm/supplemental') {
5685: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5686: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5687: {'bread_crumbs' => $brcrum,}));
5688: } else {
1.611 raeburn 5689: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5690: $breadtext = "$crstype Editor";
1.611 raeburn 5691: if ($canedit) {
5692: $breadtitle = 'Editing '.$crstype.' Contents';
5693: $helpitem = 'Docs_Adding_Course_Doc';
5694: } else {
5695: $breadtext .= ' (View-only mode)';
5696: $breadtitle = 'Viewing '.$crstype.' Contents';
5697: $helpitem = 'Docs_Viewing_Course_Doc';
5698: }
1.392 raeburn 5699: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5700: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5701: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5702: {'add_entries' => $addentries}
5703: )
1.392 raeburn 5704: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5705: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5706: $breadtitle,
5707: $helpitem)
1.392 raeburn 5708: );
5709: }
1.364 bisitz 5710:
1.329 droeschl 5711: my %allfiles = ();
5712: my %codebase = ();
1.440 raeburn 5713: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5714: if ($canedit) {
1.329 droeschl 5715: if (($env{'form.uploaddoc.filename'}) &&
5716: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5717: my $context = $1;
5718: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5719: undef($hadchanges);
1.440 raeburn 5720: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5721: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 5722: undef($navmap);
1.329 droeschl 5723: if ($hadchanges) {
5724: &mark_hash_old();
5725: }
1.440 raeburn 5726: $r->print($upload_output);
5727: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5728: # Process file upload - phase two - upload embedded objects
5729: $uploadphase = 'check_embedded';
5730: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5731: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5732: $env{'form.newidx'});
5733: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5734: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5735: my ($destination,$dir_root) = &embedded_destination();
5736: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5737: my $actionurl = '/adm/coursedocs';
1.630 raeburn 5738: my ($result,$flag) =
1.440 raeburn 5739: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5740: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5741: $actionurl);
5742: $r->print($result.&return_to_editor());
5743: } elsif ($env{'form.phase'} eq 'check_embedded') {
5744: # Process file upload - phase three - modify references in HTML file
5745: $uploadphase = 'modified_orightml';
5746: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5747: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5748: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 5749: my $result =
1.482 raeburn 5750: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5751: $docuname,$docudom,undef,
5752: $dir_root);
1.630 raeburn 5753: $r->print($result.&return_to_editor());
1.476 raeburn 5754: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5755: $uploadphase = 'decompress_phase_one';
5756: $r->print(&decompression_phase_one().
5757: &return_to_editor());
5758: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5759: $uploadphase = 'decompress_phase_two';
5760: $r->print(&decompression_phase_two().
5761: &return_to_editor());
1.329 droeschl 5762: }
5763: }
5764:
1.484 raeburn 5765: if ($allowed && $toolsflag) {
5766: $r->print(&startContentScreen('tools'));
1.611 raeburn 5767: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5768: $r->print(&endContentScreen());
5769: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5770: # -----------------------------------------------------------------------------
5771: my %lt=&Apache::lonlocal::texthash(
5772: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5773: 'upfi' => 'Upload File',
1.553 raeburn 5774: 'upld' => 'Upload Content',
1.329 droeschl 5775: 'srch' => 'Search',
5776: 'impo' => 'Import',
1.487 raeburn 5777: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5778: 'impm' => 'Import from Assembled Map',
1.630 raeburn 5779: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5780: 'extr' => 'External Resource',
5781: 'extt' => 'External Tool',
1.329 droeschl 5782: 'selm' => 'Select Map',
5783: 'load' => 'Load Map',
5784: 'newf' => 'New Folder',
5785: 'newp' => 'New Composite Page',
5786: 'syll' => 'Syllabus',
1.425 raeburn 5787: 'navc' => 'Table of Contents',
1.343 biermanm 5788: 'sipa' => 'Simple Course Page',
1.329 droeschl 5789: 'sipr' => 'Simple Problem',
1.630 raeburn 5790: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5791: 'stpr' => 'Standard Problem',
5792: 'news' => 'New sub-directory',
5793: 'crpr' => 'Create Problem',
1.329 droeschl 5794: 'drbx' => 'Drop Box',
1.451 www 5795: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5796: 'bull' => 'Discussion Board',
1.347 weissno 5797: 'mypi' => 'My Personal Information Page',
1.353 weissno 5798: 'grpo' => 'Group Portfolio',
1.329 droeschl 5799: 'rost' => 'Course Roster',
1.528 raeburn 5800: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5801: 'imsf' => 'IMS Upload',
5802: 'imsl' => 'Upload IMS package',
1.501 raeburn 5803: 'cms' => 'Origin of IMS package',
5804: 'se' => 'Select',
1.329 droeschl 5805: 'file' => 'File',
5806: 'title' => 'Title',
1.606 raeburn 5807: 'addp' => 'Add Placeholder to course?',
5808: 'uste' => 'Use Template?',
5809: 'fnam' => 'File Name:',
5810: 'loca' => 'Location:',
5811: 'dire' => 'Directory:',
5812: 'cate' => 'Category:',
5813: 'tmpl' => 'Template:',
1.329 droeschl 5814: 'comment' => 'Comment',
1.403 raeburn 5815: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5816: 'bb5' => 'Blackboard 5',
5817: 'bb6' => 'Blackboard 6',
5818: 'angel5' => 'ANGEL 5.5',
5819: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5820: 'yes' => 'Yes',
5821: 'no' => 'No',
1.618 raeburn 5822: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5823: );
1.329 droeschl 5824: # -----------------------------------------------------------------------------
1.595 musolffc 5825:
5826: # Calculate free quota space for a user or course. A javascript function checks
5827: # file size to determine if upload should be allowed.
5828: my $quotatype = 'unofficial';
5829: if ($crstype eq 'Community') {
1.601 raeburn 5830: $quotatype = 'community';
5831: } elsif ($crstype eq 'Placement') {
5832: $quotatype = 'placement';
1.595 musolffc 5833: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5834: $quotatype = 'official';
5835: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5836: $quotatype = 'textbook';
5837: }
5838: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5839: 'course',$quotatype); # expressed in MB
5840: my $current_disk_usage = 0;
5841: foreach my $subdir ('docs','supplemental') {
5842: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5843: "userfiles/$subdir",1); # expressed in kB
5844: }
5845: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5846: my $usage = $current_disk_usage/1024; # in MB
5847: my $quota = $disk_quota;
5848: my $percent;
5849: if ($disk_quota == 0) {
5850: $percent = 100.0;
5851: } else {
1.619 raeburn 5852: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5853: }
5854: $usage = sprintf("%.2f",$usage);
5855: $quota = sprintf("%.2f",$quota);
5856: $percent = sprintf("%.0f",$percent);
5857: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5858: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5859:
1.329 droeschl 5860: my $fileupload=(<<FIUP);
1.605 raeburn 5861: $quotainfo
1.329 droeschl 5862: $lt{'file'}:<br />
1.611 raeburn 5863: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5864: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5865: FIUP
5866:
5867: my $checkbox=(<<CHBO);
5868: <!-- <label>$lt{'parse'}?
5869: <input type="checkbox" name="parserflag" />
5870: </label> -->
5871: <label>
1.611 raeburn 5872: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5873: </label>
5874: CHBO
1.501 raeburn 5875: my $imsfolder = $env{'form.folder'};
5876: if ($imsfolder eq '') {
5877: $imsfolder = 'default';
5878: }
5879: my $imspform=(<<IMSFORM);
5880: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5881: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5882: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5883: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5884: <legend>$lt{'imsf'}</legend>
5885: $fileupload
5886: <br />
5887: <p>
5888: $lt{'cms'}:
1.611 raeburn 5889: <select name="source" $disabled>
1.501 raeburn 5890: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5891: <option value="bb5">$lt{'bb5'}</option>
5892: <option value="bb6">$lt{'bb6'}</option>
5893: <option value="angel5">$lt{'angel5'}</option>
5894: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5895: </select>
5896: <input type="hidden" name="folder" value="$imsfolder" />
5897: </p>
5898: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5899: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5900: </fieldset>
5901: </form>
5902: IMSFORM
1.329 droeschl 5903:
5904: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5905: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5906: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5907: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5908: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5909: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5910: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5911: $fileupload
1.329 droeschl 5912: <br />
5913: $lt{'title'}:<br />
1.611 raeburn 5914: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5915: $pathitem
1.329 droeschl 5916: <input type="hidden" name="cmd" value="upload_default" />
5917: <br />
1.458 raeburn 5918: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5919: $checkbox
5920: </span>
1.501 raeburn 5921: <br clear="all" />
1.611 raeburn 5922: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5923: </fieldset>
5924: </form>
1.383 tempelho 5925: FUFORM
1.329 droeschl 5926:
1.611 raeburn 5927: my $mapimportjs;
5928: if ($canedit) {
5929: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5930: } else {
5931: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5932: }
1.502 raeburn 5933: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5934: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5935: $lt{'impm'}</a>$help{'Load_Map'}
5936: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5937: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5938: <legend>$lt{'impm'}</legend>
1.371 tempelho 5939: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5940: $lt{'copm'}<br />
5941: <span class="LC_nobreak">
5942: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5943: onfocus="this.blur();$mapimportjs" $disabled />
5944: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5945: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5946: </fieldset>
5947: </form>
5948:
1.383 tempelho 5949: SEDFFORM
1.606 raeburn 5950: my $importcrsresform;
1.608 raeburn 5951: my ($numdirs,$pickfile) =
5952: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5953: "resize_scrollbox('contentscroll','1','0');",
5954: undef,'res');
1.606 raeburn 5955: if ($pickfile) {
5956: $importcrsresform=(<<CRSFORM);
5957: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5958: $lt{'imcr'}</a>$help{'Course_Resources'}
5959: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5960: <fieldset id="importcrsresform" style="display: none;">
5961: <legend>$lt{'imcr'}</legend>
5962: <input type="hidden" name="active" value="bb" />
5963: $pickfile
5964: <p>
1.611 raeburn 5965: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5966: </p>
5967: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5968: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5969: </fieldset>
5970: </form>
5971: CRSFORM
5972: }
5973:
1.611 raeburn 5974: my $fromstoredjs;
5975: if ($canedit) {
5976: $fromstoredjs = 'open_StoredLinks_Import()';
5977: } else {
5978: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5979: }
5980:
1.502 raeburn 5981: my @importpubforma = (
1.508 raeburn 5982: { '<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 5983: { '<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 5984: { '<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 5985: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5986: );
5987: if ($pickfile) {
5988: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5989: }
1.502 raeburn 5990: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5991: my $extresourcesform =
5992: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5993: $help{'Adding_External_Resource'},
5994: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5995: my $exttoolform =
5996: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5997: $help{'Adding_External_Tool'},undef,
5998: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5999: \%ltitools,$disabled);
1.329 droeschl 6000: if ($allowed) {
1.492 raeburn 6001: my $folder = $env{'form.folder'};
6002: if ($folder eq '') {
6003: $folder='default';
6004: }
1.615 raeburn 6005: if ($canedit) {
6006: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6007: if ($output) {
6008: $r->print($output);
6009: }
1.538 raeburn 6010: }
1.337 ehlerst 6011: $r->print(<<HIDDENFORM);
6012: <form name="renameform" method="post" action="/adm/coursedocs">
6013: <input type="hidden" name="title" />
6014: <input type="hidden" name="cmd" />
6015: <input type="hidden" name="markcopy" />
6016: <input type="hidden" name="copyfolder" />
6017: $containertag
6018: </form>
1.633 raeburn 6019: <form name="aliasform" method="post" action="/adm/coursedocs">
6020: <input type="hidden" name="alias" />
6021: <input type="hidden" name="cmd" />
6022: $containertag
6023: </form>
1.484 raeburn 6024:
1.337 ehlerst 6025: HIDDENFORM
1.508 raeburn 6026: $r->print(&makesimpleeditform($pathitem)."\n".
6027: &makedocslogform($pathitem."\n".
1.484 raeburn 6028: '<input type="hidden" name="folder" value="'.
6029: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6030: }
1.442 www 6031:
6032: # Generate the tabs
1.510 raeburn 6033: my ($mode,$needs_end);
1.472 raeburn 6034: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6035: my @folders = split('&',$env{'form.folderpath'});
6036: unless (@folders > 2) {
6037: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6038: $needs_end = 1;
6039: }
1.472 raeburn 6040: } else {
1.484 raeburn 6041: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6042: $needs_end = 1;
1.472 raeburn 6043: }
1.443 www 6044:
1.442 www 6045: #
1.622 raeburn 6046: my $hostname = $r->hostname();
1.442 www 6047: my $savefolderpath;
6048:
1.395 raeburn 6049: if ($allowed) {
1.329 droeschl 6050: my $folder=$env{'form.folder'};
1.615 raeburn 6051: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6052: $folder='default';
1.356 tempelho 6053: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6054: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6055: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6056: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6057: }
6058: my $postexec='';
6059: if ($folder eq 'default') {
1.372 bisitz 6060: $r->print('<script type="text/javascript">'."\n"
6061: .'// <![CDATA['."\n"
6062: .'this.window.name="loncapaclient";'."\n"
6063: .'// ]]>'."\n"
6064: .'</script>'."\n"
1.369 bisitz 6065: );
1.329 droeschl 6066: } else {
6067: #$postexec='self.close();';
6068: }
1.504 raeburn 6069: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6070: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6071: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6072:
6073: my $newnavform=(<<NNFORM);
6074: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 6075: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6076: $pathitem
1.329 droeschl 6077: <input type="hidden" name="importdetail"
6078: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6079: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6080: $help{'Navigate_Content'}
6081: </form>
6082: NNFORM
6083: my $newsmppageform=(<<NSPFORM);
6084: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 6085: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6086: $pathitem
1.329 droeschl 6087: <input type="hidden" name="importdetail" value="" />
1.423 onken 6088: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6089: $help{'Simple Page'}
1.329 droeschl 6090: </form>
6091: NSPFORM
6092:
6093: my $newsmpproblemform=(<<NSPROBFORM);
6094: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6095: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6096: $pathitem
1.329 droeschl 6097: <input type="hidden" name="importdetail" value="" />
1.423 onken 6098: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6099: $help{'Simple_Problem'}
1.329 droeschl 6100: </form>
6101:
6102: NSPROBFORM
6103:
6104: my $newdropboxform=(<<NDBFORM);
6105: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6106: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6107: $pathitem
1.329 droeschl 6108: <input type="hidden" name="importdetail" value="" />
1.423 onken 6109: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6110: $help{'Dropbox'}
1.344 bisitz 6111: </form>
1.329 droeschl 6112: NDBFORM
6113:
6114: my $newexuploadform=(<<NEXUFORM);
6115: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6116: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6117: $pathitem
1.329 droeschl 6118: <input type="hidden" name="importdetail" value="" />
1.423 onken 6119: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6120: $help{'Score_Upload_Form'}
6121: </form>
6122: NEXUFORM
6123:
6124: my $newbulform=(<<NBFORM);
6125: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 6126: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6127: $pathitem
1.329 droeschl 6128: <input type="hidden" name="importdetail" value="" />
1.423 onken 6129: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6130: $help{'Bulletin Board'}
6131: </form>
6132: NBFORM
6133:
6134: my $newaboutmeform=(<<NAMFORM);
6135: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 6136: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6137: $pathitem
1.329 droeschl 6138: <input type="hidden" name="importdetail"
6139: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6140: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6141: $help{'My Personal Information Page'}
1.329 droeschl 6142: </form>
6143: NAMFORM
6144:
6145: my $newaboutsomeoneform=(<<NASOFORM);
6146: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 6147: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6148: $pathitem
1.329 droeschl 6149: <input type="hidden" name="importdetail" value="" />
1.423 onken 6150: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6151: </form>
6152: NASOFORM
6153:
6154: my $newrosterform=(<<NROSTFORM);
6155: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 6156: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6157: $pathitem
1.329 droeschl 6158: <input type="hidden" name="importdetail"
6159: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6160: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6161: $help{'Course_Roster'}
1.329 droeschl 6162: </form>
6163: NROSTFORM
6164:
1.534 raeburn 6165: my $newwebpage;
6166: if ($folder =~ /^default_?(\d*)$/) {
6167: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6168: if ($1) {
6169: $newwebpage .= $1;
6170: } else {
6171: $newwebpage .= 'default';
6172: }
6173: $newwebpage .= '/new.html';
6174: }
6175: my $newwebpageform =(<<NWEBFORM);
6176: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 6177: <input type="hidden" name="active" value="ee" />
1.534 raeburn 6178: $pathitem
6179: <input type="hidden" name="importdetail" value="$newwebpage" />
6180: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6181: $help{'Web_Page'}
1.534 raeburn 6182: </form>
6183: NWEBFORM
1.604 raeburn 6184:
1.606 raeburn 6185: my @ids=&Apache::lonnet::current_machine_ids();
6186: my %select_menus;
6187: my $numauthor = 0;
6188: my $numcrsdirs = 0;
6189: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6190: if ($env{'user.author'}) {
6191: $numauthor ++;
6192: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6193: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6194: my $is_home = 1;
6195: my %subdirs;
1.608 raeburn 6196: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6197: $select_menus{'author'}->{'default'} = '/';
6198: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6199: my @ordered = ('/');
6200: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6201: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6202: push(@ordered,$relpath);
6203: }
6204: $select_menus{'author'}->{'order'} = \@ordered;
6205: } else {
6206: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6207: $select_menus{'author'}->{'default'} = 'switch';
6208: $select_menus{'author'}->{'order'} = ['switch'];
6209: }
6210: }
6211: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6212: ['active'],['ca','aa']);
6213: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6214: my %by_roletype;
6215: if (keys(%roleshash)) {
6216: foreach my $entry (keys(%roleshash)) {
6217: my ($auname,$audom,$roletype) = split(/:/,$entry);
6218: my $key = $entry;
6219: $key =~ s/:/___/g;
6220: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6221: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6222: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6223: if (grep(/^\Q$rolehome\E$/,@ids)) {
6224: my $is_home = 1;
6225: my (%subdirs,@ordered);
6226: my $toppath="/priv/$audom/$auname";
1.608 raeburn 6227: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6228: $select_menus{$key}->{'default'} = '/';
6229: $select_menus{$key}->{'select2'}->{'/'} = '/';
6230: my @ordered = ('/');
6231: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6232: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6233: push(@ordered,$relpath);
6234: }
6235: $select_menus{$key}->{'order'} = \@ordered;
6236: } else {
6237: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6238: $select_menus{$key}->{'default'} = 'switch';
6239: $select_menus{$key}->{'order'} = ['switch'];
6240: }
6241: $numauthor ++;
6242: }
6243: }
1.631 raeburn 6244: my ($pickdir,$showtitle);
1.606 raeburn 6245: if ($numauthor) {
6246: my @order;
6247: my $defrole;
6248: if ($env{'user.author'}) {
6249: push(@order,'author');
6250: $defrole = 'author';
6251: }
6252: if (keys(%by_roletype)) {
6253: foreach my $possrole ('ca','aa') {
6254: if (ref($by_roletype{$possrole}) eq 'HASH') {
6255: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6256: unless ($defrole) {
6257: $defrole = $author;
6258: }
6259: push(@order,$author.'___'.$possrole);
6260: }
6261: }
6262: }
6263: }
6264: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6265: if (grep(/^\Q$crshome\E$/,@ids)) {
6266: my $is_home = 1;
6267: my %subdirs;
6268: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6269: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6270: $numcrsdirs = keys(%subdirs);
6271: $select_menus{'course'}->{'default'} = '/';
6272: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6273: my @ordered = ('/');
6274: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6275: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6276: push(@ordered,$relpath);
6277: }
6278: $select_menus{'course'}->{'order'} = \@ordered;
6279: } else {
6280: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6281: $select_menus{'course'}->{'default'} = 'switch';
6282: $select_menus{'course'}->{'order'} = ['switch'];
6283: }
6284: push(@order,'course');
6285: $pickdir = $lt{'loca'}.
6286: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6287: $defrole,'authorrole','authorpath',
6288: \%select_menus,\@order,'toggleCrsResTitle();',
6289: '','priv').'<br />';
6290: $showtitle = 'none';
6291: } else {
6292: my $is_home;
6293: $showtitle = 'inline';
6294: if (grep(/^\Q$crshome\E$/,@ids)) {
6295: $is_home = 1;
6296: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6297: my $toppath="/priv/$coursedom/$coursenum'}";
6298: my %subdirs;
1.608 raeburn 6299: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6300: $numcrsdirs = keys(%subdirs);
6301: if ($numcrsdirs) {
6302: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6303: '<option value="/">/</option>'."\n";
6304: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6305: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6306: }
6307: $pickdir .= '</select>';
6308: } else {
6309: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6310: }
6311: }
6312: }
6313:
6314: my %seltemplate_menus;
6315: my @files = &Apache::lonhomework::get_template_list('problem');
6316: my @noexamplelink = ('blank.problem','blank.library','script.library');
6317: my $currentcategory = '';
6318: my @ordered = ('');
6319: my %templatehelp;
6320: my $defcategory = '';
6321: my @catorder = ($defcategory);
6322: $seltemplate_menus{$defcategory}->{'order'} = [''];
6323: $seltemplate_menus{$defcategory}->{'text'} = '';
6324: foreach my $file (@files) {
6325: if (ref($file) eq 'ARRAY') {
6326: my ($path,$title,$category,$help) = @{$file};
6327: next if ($title !~ /\S/);
6328: if (&js_escape($category) ne $currentcategory) {
6329: $currentcategory = &js_escape($category);
6330: push(@catorder,&js_escape($currentcategory));
6331: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6332: $seltemplate_menus{$currentcategory}->{'default'} = '';
6333: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6334: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6335: }
6336: if ($path) {
6337: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6338: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6339: if ($help) {
6340: $templatehelp{$path} = $help;
6341: }
6342: }
6343: }
6344: }
6345:
6346: my $templates = $lt{'cate'}.' '.
6347: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6348: $defcategory,'tempcategory','template',
6349: \%seltemplate_menus,\@catorder,
6350: "resize_scrollbox('contentscroll','1','0');",
6351: "toggleExampleText();",'template').'<br />';
6352: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6353: '<span id="newresexample">'.&mt('Example').'<span></a>';
6354: my $crsresform=(<<RESFORM);
6355: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6356: $lt{'stpr'}</a>$help{'Course_Resource'}
6357: <form action="/adm/coursedocs" method="post" name="courseresform">
6358: <fieldset id="crsresform" style="display:none;">
6359: <legend>$lt{'stpr'}</legend>
6360: <input type="hidden" name="active" value="ee" />
6361: <p>
6362: $pickdir
6363: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6364: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6365:
1.611 raeburn 6366: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6367: </span><span id="newsubdir"></span>
6368: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6369: </p>
6370: $lt{'fnam'}
1.611 raeburn 6371: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6372: <p>
6373: <div id="newresource" style="display:$showtitle">
6374: $lt{'addp'}
1.611 raeburn 6375: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6376: $lt{'no'}</label>
1.611 raeburn 6377: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6378: $lt{'yes'}</label>
6379: <span id="newrestitle"></span>
1.611 raeburn 6380: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6381: </div>
6382: </p>
6383: <p>
6384: $lt{'uste'}
1.611 raeburn 6385: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6386: $lt{'no'}</label>
1.611 raeburn 6387: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6388: $lt{'yes'}</label>
6389: <div id="newrestemplate" style="display:none">
6390: $templates
6391: $templatepreview
6392: </div>
6393: </p>
6394: <span class="LC_nobreak">
6395: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6396: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6397: </span>
6398: </fieldset>
6399: </form>
6400:
6401: RESFORM
1.534 raeburn 6402:
1.342 ehlerst 6403: my $specialdocumentsform;
1.383 tempelho 6404: my @specialdocumentsforma;
1.451 www 6405: my $gradingform;
6406: my @gradingforma;
6407: my $communityform;
6408: my @communityforma;
1.351 ehlerst 6409: my $newfolderform;
1.390 tempelho 6410: my $newfolderb;
1.342 ehlerst 6411:
1.451 www 6412: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6413:
1.329 droeschl 6414: my $newpageform=(<<NPFORM);
6415: <form action="/adm/coursedocs" method="post" name="newpage">
6416: <input type="hidden" name="folderpath" value="$path" />
6417: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6418: <input type="hidden" name="active" value="ee" />
1.423 onken 6419: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6420: $help{'Adding_Pages'}
1.329 droeschl 6421: </form>
6422: NPFORM
1.390 tempelho 6423:
6424:
1.351 ehlerst 6425: $newfolderform=(<<NFFORM);
1.329 droeschl 6426: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6427: $pathitem
1.329 droeschl 6428: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6429: <input type="hidden" name="active" value="" />
1.422 onken 6430: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6431: </form>
6432: NFFORM
6433:
6434: my $newsylform=(<<NSYLFORM);
6435: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6436: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6437: $pathitem
1.329 droeschl 6438: <input type="hidden" name="importdetail"
6439: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6440: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6441: $help{'Syllabus'}
1.383 tempelho 6442:
1.329 droeschl 6443: </form>
6444: NSYLFORM
1.364 bisitz 6445:
1.329 droeschl 6446: my $newgroupfileform=(<<NGFFORM);
6447: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6448: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6449: $pathitem
1.329 droeschl 6450: <input type="hidden" name="importdetail"
6451: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6452: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6453: $help{'Group Portfolio'}
1.329 droeschl 6454: </form>
6455: NGFFORM
1.383 tempelho 6456: @specialdocumentsforma=(
1.421 onken 6457: {'<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 6458: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6459: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6460: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6461: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6462: );
6463: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6464:
1.434 raeburn 6465:
6466: my @importdoc = (
1.519 raeburn 6467: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6468: );
1.598 raeburn 6469: if (keys(%ltitools)) {
6470: push(@importdoc,
1.627 raeburn 6471: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
1.598 raeburn 6472: );
6473: }
1.519 raeburn 6474: unless ($container eq 'page') {
6475: push(@importdoc,
6476: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6477: );
6478: }
6479: push(@importdoc,
1.558 raeburn 6480: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6481: );
1.501 raeburn 6482: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6483:
1.451 www 6484: @gradingforma=(
6485: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6486: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6487: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6488: {'<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 6489: );
6490: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6491:
6492: @communityforma=(
6493: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6494: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6495: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6496: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6497: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6498: );
6499: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6500:
1.330 tempelho 6501: my %orderhash = (
1.553 raeburn 6502: 'aa' => ['Upload',$fileuploadform],
6503: 'bb' => ['Import',$importpubform],
6504: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6505: );
1.519 raeburn 6506: unless ($container eq 'page') {
1.434 raeburn 6507: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6508: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6509: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6510: }
6511:
1.341 ehlerst 6512: $hadchanges=0;
1.484 raeburn 6513: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6514: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6515: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6516: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6517: undef($navmap);
1.443 www 6518: if ($error) {
6519: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6520: }
1.639 raeburn 6521: if ($hadchanges) {
6522: unless (&is_hash_old()) {
1.638 raeburn 6523: &mark_hash_old();
6524: }
6525: }
1.341 ehlerst 6526:
1.443 www 6527: &changewarning($r,'');
6528: }
1.458 raeburn 6529: }
1.442 www 6530:
1.443 www 6531: # Supplemental documents start here
6532:
1.329 droeschl 6533: my $folder=$env{'form.folder'};
1.443 www 6534: unless ($supplementalflag) {
1.329 droeschl 6535: $folder='supplemental';
6536: }
6537: if ($folder =~ /^supplemental$/ &&
6538: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6539: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6540: } elsif ($allowed) {
1.356 tempelho 6541: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6542: }
1.508 raeburn 6543: $pathitem = '<input type="hidden" name="folderpath" value="'.
6544: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6545: if ($allowed) {
6546: my $folderseq=
1.504 raeburn 6547: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6548:
6549: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6550: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6551: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6552: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6553: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6554: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6555: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6556: $fileupload
6557: <br />
6558: <br />
6559: <span class="LC_nobreak">
6560: $checkbox
6561: </span>
6562: <br /><br />
6563: $lt{'comment'}:<br />
1.383 tempelho 6564: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6565: <br />
1.508 raeburn 6566: $pathitem
1.329 droeschl 6567: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6568: <input type='submit' value="$lt{'upld'}" />
6569: </form>
1.329 droeschl 6570: SUPDOCFORM
6571:
6572: my $supnewfolderform=(<<SNFFORM);
6573: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6574: <input type="hidden" name="active" value="" />
1.508 raeburn 6575: $pathitem
1.329 droeschl 6576: <input type="hidden" name="importdetail" value="" />
1.423 onken 6577: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6578: $help{'Adding_Folders'}
1.329 droeschl 6579: </form>
6580: SNFFORM
1.383 tempelho 6581:
1.510 raeburn 6582: my $supextform =
6583: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6584: $help{'Adding_External_Resource'},
6585: undef,undef,undef,undef,undef,undef,
6586: $disabled);
1.329 droeschl 6587:
1.598 raeburn 6588: my $supexttoolform =
6589: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6590: $help{'Adding_External_Tool'},
6591: undef,undef,'tool',$coursedom,
1.611 raeburn 6592: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6593:
1.329 droeschl 6594: my $supnewsylform=(<<SNSFORM);
6595: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6596: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6597: $pathitem
1.329 droeschl 6598: <input type="hidden" name="importdetail"
6599: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6600: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6601: $help{'Syllabus'}
6602: </form>
6603: SNSFORM
6604:
6605: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6606: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6607: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6608: $pathitem
1.329 droeschl 6609: <input type="hidden" name="importdetail"
6610: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6611: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6612: $help{'My Personal Information Page'}
1.329 droeschl 6613: </form>
6614: SNAMFORM
6615:
1.534 raeburn 6616: my $supwebpage;
6617: if ($folder =~ /^supplemental_?(\d*)$/) {
6618: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6619: if ($1) {
6620: $supwebpage .= $1;
6621: } else {
6622: $supwebpage .= 'default';
6623: }
6624: $supwebpage .= '/new.html';
6625: }
6626: my $supwebpageform =(<<SWEBFORM);
6627: <form action="/adm/coursedocs" method="post" name="supwebpage">
6628: <input type="hidden" name="active" value="cc" />
6629: $pathitem
6630: <input type="hidden" name="importdetail" value="$supwebpage" />
6631: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6632: $help{'Web_Page'}
1.534 raeburn 6633: </form>
6634: SWEBFORM
6635:
1.333 muellerd 6636:
1.383 tempelho 6637: my @specialdocs = (
1.618 raeburn 6638: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6639: =>$supnewsylform},
1.611 raeburn 6640: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6641: =>$supnewaboutmeform},
1.534 raeburn 6642: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6643:
1.383 tempelho 6644: );
1.417 droeschl 6645: my @supimportdoc = (
1.515 raeburn 6646: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6647: =>$supextform});
6648: if (keys(%ltitools)) {
6649: push(@supimportdoc,
1.627 raeburn 6650: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
1.598 raeburn 6651: =>$supexttoolform});
6652: }
6653: push(@supimportdoc,
6654: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6655: =>$supupdocform},
1.598 raeburn 6656: );
1.501 raeburn 6657:
6658: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6659: my %suporderhash = (
1.390 tempelho 6660: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6661: 'ee' => ['Upload',$supupdocform],
6662: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6663: );
1.443 www 6664: if ($supplementalflag) {
1.458 raeburn 6665: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6666: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6667: \%ltitools,$canedit,$hostname);
1.443 www 6668: if ($error) {
6669: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6670: } else {
6671: if ($suppchanges) {
6672: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6673: my @ids=&Apache::lonnet::current_machine_ids();
6674: foreach my $server (keys(%servers)) {
6675: next if (grep(/^\Q$server\E$/,@ids));
6676: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6677: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6678: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6679: }
6680: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6681: undef($suppchanges);
1.630 raeburn 6682: }
6683: }
1.393 raeburn 6684: }
1.443 www 6685: } elsif ($supplementalflag) {
1.458 raeburn 6686: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6687: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6688: if ($error) {
6689: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6690: }
1.393 raeburn 6691: }
1.389 tempelho 6692:
1.510 raeburn 6693: if ($needs_end) {
6694: $r->print(&endContentScreen());
6695: }
1.383 tempelho 6696:
1.329 droeschl 6697: if ($allowed) {
6698: $r->print('
6699: <form method="post" name="extimport" action="/adm/coursedocs">
6700: <input type="hidden" name="title" />
6701: <input type="hidden" name="url" />
6702: <input type="hidden" name="useform" />
6703: <input type="hidden" name="residx" />
6704: </form>');
6705: }
1.484 raeburn 6706: } elsif ($showdoc) {
1.329 droeschl 6707: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6708: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6709: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6710: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6711: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6712: }
6713: }
1.630 raeburn 6714: unless ($noendpage) {
1.606 raeburn 6715: $r->print(&Apache::loncommon::end_page());
6716: }
1.329 droeschl 6717: return OK;
1.364 bisitz 6718: }
1.329 droeschl 6719:
1.440 raeburn 6720: sub embedded_form_elems {
6721: my ($phase,$primaryurl,$newidx) = @_;
6722: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 6723: $newidx =~s /\D+//g;
1.440 raeburn 6724: return <<STATE;
6725: <input type="hidden" name="folderpath" value="$folderpath" />
6726: <input type="hidden" name="cmd" value="upload_embedded" />
6727: <input type="hidden" name="newidx" value="$newidx" />
6728: <input type="hidden" name="phase" value="$phase" />
6729: <input type="hidden" name="primaryurl" value="$primaryurl" />
6730: STATE
6731: }
6732:
6733: sub embedded_destination {
6734: my $folder=$env{'form.folder'};
6735: my $destination = 'docs/';
6736: if ($folder =~ /^supplemental/) {
6737: $destination = 'supplemental/';
6738: }
6739: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6740: $destination .= 'default/';
6741: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6742: $destination .= $2.'/';
6743: }
1.634 raeburn 6744: my $newidx = $env{'form.newidx'};
6745: $newidx =~s /\D+//g;
6746: if ($newidx) {
6747: $destination .= $newidx;
6748: }
1.440 raeburn 6749: my $dir_root = '/userfiles';
6750: return ($destination,$dir_root);
6751: }
6752:
6753: sub return_to_editor {
6754: my $actionurl = '/adm/coursedocs';
6755: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6756: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6757: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6758: '</a></p>';
6759: }
6760:
1.476 raeburn 6761: sub decompression_info {
6762: my ($destination,$dir_root) = &embedded_destination();
6763: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6764: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6765: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6766: my $container='sequence';
1.480 raeburn 6767: my ($pathitem,$hiddenelem);
1.583 raeburn 6768: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6769: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6770: $container='page';
6771: }
1.480 raeburn 6772: unshift(@hiddens,$pathitem);
6773: foreach my $item (@hiddens) {
1.634 raeburn 6774: if ($item eq 'newidx') {
6775: next if ($env{'form.'.$item} =~ /\D/);
6776: }
1.480 raeburn 6777: if ($env{'form.'.$item}) {
6778: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6779: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6780: }
1.477 raeburn 6781: }
1.476 raeburn 6782: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6783: $hiddenelem);
6784: }
6785:
6786: sub decompression_phase_one {
6787: my ($dir,$file,$warning,$error,$output);
6788: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6789: &decompression_info();
1.490 raeburn 6790: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6791: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6792: } else {
6793: my $file = $1;
1.630 raeburn 6794: $output =
1.481 raeburn 6795: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6796: $destination,$dir_root,
6797: $hiddenelem);
6798: if ($env{'form.autoextract_camtasia'}) {
6799: $output .= &remove_archive($docudom,$docuname,$container);
6800: }
1.476 raeburn 6801: }
6802: if ($error) {
6803: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6804: $error.'</p>'."\n";
6805: }
6806: if ($warning) {
6807: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6808: }
6809: return $output;
6810: }
6811:
6812: sub decompression_phase_two {
6813: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6814: &decompression_info();
1.481 raeburn 6815: my $output;
1.480 raeburn 6816: if ($env{'form.archivedelete'}) {
1.481 raeburn 6817: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6818: }
6819: $output .=
1.481 raeburn 6820: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6821: $destination,$dir_root,$hiddenelem);
6822: return $output;
6823: }
6824:
1.480 raeburn 6825: sub remove_archive {
6826: my ($docudom,$docuname,$container) = @_;
6827: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6828: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6829: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6830: if ($fatal) {
6831: if ($container eq 'page') {
6832: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6833: } else {
6834: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6835: }
1.583 raeburn 6836: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6837: } else {
6838: my $currcmd = $env{'form.cmd'};
6839: my $position = $env{'form.position'};
1.583 raeburn 6840: my $archiveidx = $position;
1.563 raeburn 6841: if ($position > 0) {
1.583 raeburn 6842: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6843: $archiveidx = $position-1;
6844: }
6845: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6846: my ($title,$url,@rrest) =
1.583 raeburn 6847: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6848: if ($url eq $env{'form.archiveurl'}) {
6849: if (&handle_edit_cmd($docuname,$docudom)) {
6850: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6851: if ($fatal) {
6852: if ($container eq 'page') {
6853: $delwarning = &mt('An error occurred updating the contents of the current page.');
6854: } else {
6855: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6856: }
1.480 raeburn 6857: } else {
1.583 raeburn 6858: $delresult = &mt('Archive file removed.');
1.480 raeburn 6859: }
6860: }
1.583 raeburn 6861: } else {
6862: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6863: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6864: }
6865: }
6866: $env{'form.cmd'} = $currcmd;
6867: }
6868: if ($delwarning) {
6869: $output = '<p class="LC_warning">'.
6870: $delwarning.
6871: '</p>';
6872: }
6873: if ($delresult) {
6874: $output .= '<p class="LC_info">'.
6875: $delresult.
6876: '</p>';
6877: }
1.481 raeburn 6878: return $output;
1.480 raeburn 6879: }
6880:
1.484 raeburn 6881: sub generate_admin_menu {
1.611 raeburn 6882: my ($crstype,$canedit) = @_;
1.484 raeburn 6883: my $lc_crstype = lc($crstype);
6884: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6885: my %lt= ( # do not translate here
1.484 raeburn 6886: 'vc' => 'Verify Content',
6887: 'cv' => 'Check/Set Resource Versions',
6888: 'ls' => 'List Resource Identifiers',
6889: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6890: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6891: );
1.484 raeburn 6892: my ($candump,$dumpurl);
6893: if ($home + $other > 0) {
6894: $candump = 'F';
6895: if ($home) {
6896: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6897: } else {
6898: my @hosts;
6899: foreach my $aurole (keys(%outhash)) {
6900: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6901: push(@hosts,$outhash{$aurole});
1.538 raeburn 6902: }
1.484 raeburn 6903: }
6904: if (@hosts == 1) {
6905: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6906: '&role='.
6907: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6908: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6909: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6910: } else {
6911: $dumpurl = "javascript:choose_switchserver_window()";
6912: }
6913: }
6914: }
6915: my @menu=
6916: ({ categorytitle=>'Administration',
6917: items =>[
6918: { linktext => $lt{'vc'},
6919: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6920: permission => 'F',
1.571 raeburn 6921: help => 'Docs_Verify_Content',
1.484 raeburn 6922: icon => 'verify.png',
6923: linktitle => 'Verify contents can be retrieved/rendered',
6924: },
6925: { linktext => $lt{'cv'},
6926: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6927: permission => 'F',
1.571 raeburn 6928: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6929: icon => 'resversion.png',
6930: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6931: },
6932: { linktext => $lt{'ls'},
6933: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6934: permission => 'F',
6935: #help => '',
6936: icon => 'symbs.png',
6937: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6938: },
6939: ]
1.611 raeburn 6940: });
6941: if ($canedit) {
6942: push(@menu,
1.484 raeburn 6943: { categorytitle=>'Export',
6944: items =>[
6945: { linktext => $lt{'imse'},
6946: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6947: permission => 'F',
6948: help => 'Docs_Export_Course_Docs',
6949: icon => 'imsexport.png',
6950: linktitle => $lt{'imse'},
6951: },
6952: { linktext => $lt{'dcd'},
6953: url => $dumpurl,
6954: permission => $candump,
1.571 raeburn 6955: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6956: icon => 'dump.png',
6957: linktitle => $lt{'dcd'},
6958: },
6959: ]
6960: });
1.611 raeburn 6961: }
1.484 raeburn 6962: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6963: '<input type="hidden" id="dummy" />'."\n".
6964: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6965: '</form>';
1.329 droeschl 6966: }
6967:
6968: sub generate_edit_table {
1.538 raeburn 6969: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6970: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6971: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6972: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6973: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6974: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6975: $activetab = $env{'form.active'};
6976: }
1.611 raeburn 6977: unless ($canedit) {
6978: $disabled = ' disabled="disabled"';
6979: }
1.472 raeburn 6980: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6981: my $backtext = &mt('Exit Editor');
1.458 raeburn 6982: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6983: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6984: '<li class="goback">'.
1.546 raeburn 6985: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6986: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6987: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6988: '<li>'.
6989: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6990: &mt('Undo Delete').'</a></li>'."\n";
6991: if ($env{'form.docslog'}) {
6992: $form .= '<li class="active">';
6993: } else {
6994: $form .= '<li>';
6995: }
6996: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6997: &mt('History').'</a></li>'."\n";
6998: if ($env{'form.docslog'}) {
6999: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7000: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7001: }
1.458 raeburn 7002: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7003: if($name ne '00'){
1.371 tempelho 7004: if($activetab eq '' || $activetab ne $name){
7005: $active = '';
7006: }elsif($activetab eq $name){
7007: $active = 'class="active"';
7008: }
1.458 raeburn 7009: $form .= '<li style="float:right" '.$active
1.484 raeburn 7010: .' 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 7011: } else {
1.570 raeburn 7012: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7013:
7014: }
1.329 droeschl 7015: }
1.484 raeburn 7016: $form .= '</ul>'."\n";
7017: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7018:
7019: if ($to_show ne '') {
1.538 raeburn 7020: my $saveform;
7021: if ($need_save) {
7022: my $button = &mt('Make changes');
7023: my $path;
7024: if ($env{'form.folderpath'}) {
7025: $path =
7026: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7027: }
7028: $saveform = <<"END";
7029: <div id="multisave" style="display:none; clear:both;" >
7030: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7031: <input type="hidden" name="folderpath" value="$path" />
7032: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7033: <input type="hidden" name="allhiddenresource" value="" />
7034: <input type="hidden" name="allencrypturl" value="" />
7035: <input type="hidden" name="allrandompick" value="" />
7036: <input type="hidden" name="allrandomorder" value="" />
7037: <input type="hidden" name="changeparms" value="" />
7038: <input type="hidden" name="multiremove" value="" />
7039: <input type="hidden" name="multicut" value="" />
7040: <input type="hidden" name="multicopy" value="" />
7041: <input type="hidden" name="multichange" value="" />
7042: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7043: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7044: </form>
7045: </div>
7046: END
7047: }
7048: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7049: }
1.363 ehlerst 7050: foreach my $field (keys(%orderhash)){
1.390 tempelho 7051: if($field ne '00'){
1.422 onken 7052: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7053: $active = 'style="display: none;float:left"';
1.422 onken 7054: }elsif($activetab eq $field){
1.458 raeburn 7055: $active = 'style="display:block;float:left"';
1.422 onken 7056: }
7057: $form .= '<div id="'.$field.$tid.'"'
7058: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7059: .'</div>'."\n";
1.363 ehlerst 7060: }
7061: }
1.484 raeburn 7062: unless ($env{'form.docslog'}) {
7063: $form .= '</div></div>'."\n";
7064: }
1.329 droeschl 7065: return $form;
7066: }
7067:
7068: sub editing_js {
1.622 raeburn 7069: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7070: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7071: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7072: p_mnf => 'Name of New Folder',
7073: t_mnf => 'New Folder',
7074: p_mnp => 'Name of New Page',
7075: t_mnp => 'New Page',
1.451 www 7076: p_mxu => 'Title for the External Score',
1.349 biermanm 7077: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7078: p_msb => 'Title for the Problem',
7079: p_mdb => 'Title for the Drop Box',
1.336 schafran 7080: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7081: p_mwp => 'Title for Web Page',
1.606 raeburn 7082: p_mnr => 'Title for the Resource',
1.348 weissno 7083: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7084: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7085: p_mab_alrt1 => 'Not a valid user:domain',
7086: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7087: p_chn => 'New Title',
7088: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7089: p_rmr2a => 'Remove',
7090: p_rmr2b => '?',
7091: p_rmr3a => 'Remove those',
7092: p_rmr3b => 'items?',
7093: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7094: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7095: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7096: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7097: p_ctr2a => 'Cut',
7098: p_ctr2b => '?',
7099: p_ctr3a => 'Cut those',
7100: p_ctr3b => 'items?',
1.633 raeburn 7101: setal => 'Enter a (unique) alias',
7102: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7103: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7104: imsfile => 'You must choose an IMS package for import',
7105: imscms => 'You must select which Course Management System was the source of the IMS package',
7106: invurl => 'Invalid URL',
7107: titbl => 'Title is blank',
1.538 raeburn 7108: more => '(More ...)',
7109: less => '(Less ...)',
1.543 raeburn 7110: noor => 'No actions selected or changes to settings specified.',
7111: noch => 'No changes to settings specified.',
7112: noac => 'No actions selected.',
1.606 raeburn 7113: nofi => 'No file selected',
7114: tinc => 'Title in course',
7115: sunm => 'Sub-directory name',
1.618 raeburn 7116: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7117: );
1.594 damieng 7118: &js_escape(\%js_lt);
1.433 raeburn 7119: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7120: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7121: my $main_container_page;
1.519 raeburn 7122: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7123: $main_container_page = 1;
1.434 raeburn 7124: }
1.617 raeburn 7125: my $backtourl;
7126: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7127: my $toplevelsupp = &supplemental_base();
1.433 raeburn 7128:
1.530 raeburn 7129: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7130: my $caller = $1;
1.525 raeburn 7131: if ($caller =~ /^supplemental/) {
7132: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7133: } else {
7134: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7135: $res = &Apache::lonnet::clutter($res);
7136: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7137: my ($url,$anchor);
7138: if ($res =~ /^([^#]+)#([^#]+)$/) {
7139: $url = $1;
7140: $anchor = $2;
7141: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7142: $caller = $1.&escape('#').$anchor;
7143: }
1.614 raeburn 7144: } else {
7145: $url = $res;
1.609 raeburn 7146: }
1.640 raeburn 7147: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7148: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7149: $backtourl .= '?navmap=1';
7150: } else {
7151: $backtourl .= '?symb='.
7152: &HTML::Entities::encode($caller,'<>&"');
7153: }
1.622 raeburn 7154: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7155: if (($ENV{'SERVER_PORT'} == 443) &&
7156: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
7157: if ($hostname ne '') {
7158: $backtourl = 'http://'.$hostname.$backtourl;
7159: }
1.627 raeburn 7160: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7161: }
1.623 raeburn 7162: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7163: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
7164: $backtourl = 'http://'.$hostname.$backtourl;
7165: }
1.622 raeburn 7166: }
1.609 raeburn 7167: if ($anchor ne '') {
7168: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7169: }
1.590 raeburn 7170: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7171: } else {
7172: $backtourl = '/adm/navmaps';
1.525 raeburn 7173: }
7174: }
7175: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7176: $backtourl = '/adm/menu';
7177: } elsif ($supplementalflag) {
1.472 raeburn 7178: $backtourl = '/adm/supplemental';
1.525 raeburn 7179: } else {
7180: $backtourl = '/adm/navmaps';
1.472 raeburn 7181: }
7182:
1.600 raeburn 7183: my $fieldsets = "'ext','doc'";
7184: if ($posslti) {
7185: $fieldsets .= ",'tool'";
7186: }
1.519 raeburn 7187: unless ($main_container_page) {
7188: $fieldsets .=",'ims'";
7189: }
1.501 raeburn 7190: if ($supplementalflag) {
1.600 raeburn 7191: $fieldsets = "'suppext','suppdoc'";
7192: if ($posslti) {
7193: $fieldsets .= ",'supptool'";
7194: }
1.501 raeburn 7195: }
1.611 raeburn 7196:
7197: my $jsmakefunctions;
7198: if ($canedit) {
7199: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7200: function makenewfolder(targetform,folderseq) {
1.594 damieng 7201: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7202: if (foldername) {
7203: targetform.importdetail.value=escape(foldername)+"="+folderseq;
7204: targetform.submit();
7205: }
7206: }
7207:
7208: function makenewpage(targetform,folderseq) {
1.594 damieng 7209: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7210: if (pagename) {
7211: targetform.importdetail.value=escape(pagename)+"="+folderseq;
7212: targetform.submit();
7213: }
7214: }
7215:
7216: function makeexamupload() {
1.594 damieng 7217: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7218: if (title) {
1.329 droeschl 7219: this.document.forms.newexamupload.importdetail.value=
7220: escape(title)+'=/res/lib/templates/examupload.problem';
7221: this.document.forms.newexamupload.submit();
7222: }
7223: }
7224:
7225: function makesmppage() {
1.594 damieng 7226: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7227: if (title) {
1.329 droeschl 7228: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 7229: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7230: this.document.forms.newsmppg.submit();
7231: }
7232: }
7233:
1.534 raeburn 7234: function makewebpage(type) {
1.594 damieng 7235: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7236: var formname;
7237: if (type == 'supp') {
7238: formname = this.document.forms.supwebpage;
7239: } else {
7240: formname = this.document.forms.newwebpage;
7241: }
7242: if (title) {
7243: var webpage = formname.importdetail.value;
7244: formname.importdetail.value = escape(title)+'='+webpage;
7245: formname.submit();
7246: }
7247: }
7248:
1.329 droeschl 7249: function makesmpproblem() {
1.594 damieng 7250: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7251: if (title) {
1.329 droeschl 7252: this.document.forms.newsmpproblem.importdetail.value=
7253: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7254: this.document.forms.newsmpproblem.submit();
7255: }
7256: }
7257:
7258: function makedropbox() {
1.594 damieng 7259: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7260: if (title) {
1.329 droeschl 7261: this.document.forms.newdropbox.importdetail.value=
7262: escape(title)+'=/res/lib/templates/DropBox.problem';
7263: this.document.forms.newdropbox.submit();
7264: }
7265: }
7266:
7267: function makebulboard() {
1.594 damieng 7268: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7269: if (title) {
7270: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7271: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7272: this.document.forms.newbul.submit();
7273: }
7274: }
7275:
7276: function makeabout() {
1.594 damieng 7277: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7278: if (user) {
7279: var comp=new Array();
7280: comp=user.split(':');
7281: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7282: if ((comp[0]) && (comp[1])) {
7283: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7284: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7285: this.document.forms.newaboutsomeone.submit();
7286: } else {
7287: alert("$js_lt{'p_mab_alrt1'}");
7288: }
7289: } else {
7290: alert("$js_lt{'p_mab_alrt2'}");
7291: }
7292: }
7293: }
7294:
7295: function makenew(targetform) {
7296: targetform.submit();
7297: }
7298:
7299: function changename(folderpath,index,oldtitle) {
7300: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7301: if (title) {
7302: this.document.forms.renameform.markcopy.value='';
7303: this.document.forms.renameform.title.value=title;
7304: this.document.forms.renameform.cmd.value='rename_'+index;
7305: this.document.forms.renameform.folderpath.value=folderpath;
7306: this.document.forms.renameform.submit();
7307: }
7308: }
7309:
1.633 raeburn 7310: function setalias(folderpath,index) {
7311: var alias = prompt('$js_lt{"setal"}');
7312: if ((alias != null) && (alias != '')) {
7313: this.document.forms.aliasform.alias.value=alias;
7314: this.document.forms.aliasform.cmd.value='setalias_'+index;
7315: this.document.forms.aliasform.folderpath.value=folderpath;
7316: this.document.forms.aliasform.submit();
7317: }
7318: }
7319:
7320: function delalias(folderpath,index) {
7321: if (confirm('$js_lt{"delal"}')) {
7322: this.document.forms.aliasform.cmd.value='delalias_'+index;
7323: this.document.forms.aliasform.folderpath.value=folderpath;
7324: this.document.forms.aliasform.submit();
7325: }
7326: }
7327:
1.611 raeburn 7328: ENDNEWSCRIPT
7329: } else {
7330: $jsmakefunctions = <<ENDNEWSCRIPT;
7331:
7332: function makenewfolder() {
7333: alert("$js_lt{'edri'}");
7334: }
7335:
7336: function makenewpage() {
7337: alert("$js_lt{'edri'}");
7338: }
7339:
7340: function makeexamupload() {
7341: alert("$js_lt{'edri'}");
7342: }
7343:
7344: function makesmppage() {
7345: alert("$js_lt{'edri'}");
7346: }
7347:
7348: function makewebpage(type) {
7349: alert("$js_lt{'edri'}");
7350: }
7351:
7352: function makesmpproblem() {
7353: alert("$js_lt{'edri'}");
7354: }
7355:
7356: function makedropbox() {
7357: alert("$js_lt{'edri'}");
7358: }
7359:
7360: function makebulboard() {
7361: alert("$js_lt{'edri'}");
7362: }
7363:
7364: function makeabout() {
7365: alert("$js_lt{'edri'}");
7366: }
7367:
7368: function changename() {
7369: alert("$js_lt{'edri'}");
7370: }
7371:
1.633 raeburn 7372: function setalias() {
7373: alert("$js_lt{'edri'}");
7374: }
7375:
7376: function delalias() {
7377: alert("$js_lt{'edri'}");
7378: }
7379:
1.611 raeburn 7380: function makenew() {
7381: alert("$js_lt{'edri'}");
7382: }
7383:
7384: function groupimport() {
7385: alert("$js_lt{'edri'}");
1.335 ehlerst 7386: }
1.611 raeburn 7387:
7388: function groupsearch() {
7389: alert("$js_lt{'edri'}");
1.335 ehlerst 7390: }
1.611 raeburn 7391:
7392: function groupopen(url,recover) {
7393: var options="scrollbars=1,resizable=1,menubar=0";
7394: idxflag=1;
7395: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7396: idx.focus();
1.329 droeschl 7397: }
7398:
1.611 raeburn 7399: ENDNEWSCRIPT
7400:
7401: }
7402: return <<ENDSCRIPT;
7403:
7404: $jsmakefunctions
7405:
1.501 raeburn 7406: function toggleUpload(caller) {
7407: var blocks = Array($fieldsets);
7408: for (var i=0; i<blocks.length; i++) {
7409: var disp = 'none';
7410: if (caller == blocks[i]) {
7411: var curr = document.getElementById('upload'+caller+'form').style.display;
7412: if (curr == 'none') {
7413: disp='block';
7414: }
7415: }
7416: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7417: if ((caller == 'tool') || (caller == 'supptool')) {
7418: if (disp == 'block') {
7419: if (document.getElementById('LC_exttoolid')) {
7420: var toolselector = document.getElementById('LC_exttoolid');
7421: var suppflag = 0;
7422: if (caller == 'supptool') {
7423: suppflag = 1;
7424: }
7425: currForm = document.getElementById('new'+caller);
7426: updateExttool(toolselector,currForm,suppflag);
7427: }
7428: }
7429: }
1.501 raeburn 7430: }
1.502 raeburn 7431: resize_scrollbox('contentscroll','1','1');
7432: return;
7433: }
7434:
1.514 raeburn 7435: function toggleMap(caller) {
1.502 raeburn 7436: var disp = 'none';
1.510 raeburn 7437: if (document.getElementById('importmapform')) {
1.514 raeburn 7438: if (caller == 'map') {
7439: var curr = document.getElementById('importmapform').style.display;
7440: if (curr == 'none') {
7441: disp='block';
7442: }
1.510 raeburn 7443: }
7444: document.getElementById('importmapform').style.display=disp;
7445: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7446: }
1.501 raeburn 7447: return;
1.329 droeschl 7448: }
7449:
1.606 raeburn 7450: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7451: var disp = 'none';
7452: if (document.getElementById('crsresform')) {
7453: if (caller == 'res') {
7454: var curr = document.getElementById('crsresform').style.display;
7455: if (curr == 'none') {
7456: disp='block';
7457: numauthor = parseInt(numauthorrole);
7458: if (numauthor > 0) {
7459: document.courseresform.authorrole.selectedIndex = 0;
7460: select1priv_changed();
7461: document.courseresform.authorpath.selectedIndex = 0;
7462: document.courseresform.newresourceadd.selectedIndex = 0;
7463: toggleNewInCourse(document.courseresform);
7464: if (document.getElementById('newresource')) {
7465: document.getElementById('newresource').style.display = 'none';
7466: }
7467: } else {
7468: if (numcrsdirs) {
7469: document.courseresform.authorpath.selectedIndex = 0;
7470: }
7471: }
7472: if (document.courseresform.newresusetemp.length) {
7473: document.courseresform.newresusetemp[0].checked = true;
7474: toggleWithTemplate(document.courseresform);
7475: }
7476: document.courseresform.newresourcename.value = '';
7477: }
7478: }
7479: if (document.courseresform.newsubdir.length) {
7480: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7481: if (document.courseresform.newsubdir[j].value == 0) {
7482: document.courseresform.newsubdir[j].checked = true;
7483: }
7484: break;
7485: }
7486: if (document.getElementById('newsubdirname')) {
7487: document.getElementById('newsubdirname').type = "hidden";
7488: document.getElementById('newsubdirname').value = "";
7489: }
7490: if (document.getElementById('newsubdir')) {
7491: document.getElementById('newsubdir').innerHTML = "";
7492: }
7493: }
7494: document.getElementById('crsresform').style.display=disp;
7495: resize_scrollbox('contentscroll','1','0');
7496: }
7497: return;
7498: }
7499:
7500: function toggleNewsubdir(form) {
7501: if (form.newsubdir.length) {
7502: for (var j=0; j<form.newsubdir.length; j++) {
7503: if (form.newsubdir[j].checked) {
7504: if (document.getElementById('newsubdirname')) {
7505: if (form.newsubdir[j].value == '1') {
7506: document.getElementById('newsubdirname').type = "text";
7507: if (document.getElementById('newsubdir')) {
7508: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7509: }
7510: } else {
7511: document.getElementById('newsubdirname').type = "hidden";
7512: document.getElementById('newsubdirname').value = "";
7513: document.getElementById('newsubdir').innerHTML = "";
7514: }
7515: }
7516: break;
7517: }
7518: }
7519: }
7520: }
7521:
7522: function toggleCrsResTitle() {
7523: if (document.getElementById('newresource')) {
7524: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7525: document.getElementById('newresource').style.display = 'inline';
7526: document.courseresform.newresourceadd[0].checked = true;
7527: toggleNewInCourse(document.courseresform);
7528: } else {
7529: document.getElementById('newresource').style.display = 'none';
7530: }
7531: }
7532: }
7533:
7534: function toggleNewInCourse(form) {
7535: if (form.newresourceadd.length) {
7536: for (var i=0; i<form.newresourceadd.length; i++) {
7537: if (form.newresourceadd[i].checked) {
7538: if (document.getElementById('newresourcetitle')) {
7539: if (form.newresourceadd[i].value == '1') {
7540: document.getElementById('newresourcetitle').type = 'text';
7541: if (document.getElementById('newrestitle')) {
7542: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7543: }
7544: } else {
7545: document.getElementById('newresourcetitle').type = 'hidden';
7546: document.getElementById('newresourcetitle').value = '';
7547: if (document.getElementById('newrestitle')) {
7548: document.getElementById('newrestitle').innerHTML = '';
7549: }
7550: }
7551: }
7552: break;
7553: }
7554: }
7555: }
7556: }
7557:
7558: function toggleWithTemplate(form) {
7559: if (form.newresusetemp.length) {
7560: for (var i=0; i<form.newresusetemp.length; i++) {
7561: if (form.newresusetemp[i].checked) {
7562: if (document.getElementById('newrestemplate')) {
7563: if (form.newresusetemp[i].value == '1') {
7564: document.getElementById('newrestemplate').style.display = 'inline';
7565: toggleExampleText();
7566: } else {
7567: form.tempcategory.selectedIndex = 0;
7568: select1template_changed();
7569: document.getElementById('newrestemplate').style.display = 'none';
7570: }
7571: }
7572: }
7573: }
7574: }
7575: }
7576:
7577: function toggleExampleText() {
7578: if (document.getElementById('newresexample')) {
7579: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7580: if (url == '') {
7581: document.getElementById('newresexample').style.fontWeight = 'normal';
7582: } else {
7583: document.getElementById('newresexample').style.fontWeight = 'bold';
7584: }
7585: }
7586: }
7587:
7588: function getExample(width,height,scrolling,transparency) {
7589: var url;
7590: if (document.courseresform.newresusetemp.length) {
7591: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7592: if (document.courseresform.newresusetemp[i].checked) {
7593: if (document.courseresform.newresusetemp[i].value == '1') {
7594: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7595: if (url == '') {
7596: alert('Pick a category and template');
7597: } else {
7598: url = url.replace("$londocroot","");
7599: url += '?inhibitmenu=yes';
7600: }
7601: }
7602: break;
7603: }
7604: }
7605: }
7606: if (url != '') {
7607: openMyModal(url,width,height,scrolling,transparency,'');
7608: }
7609: }
7610:
7611: function toggleImportCrsres(caller,dircount) {
7612: var disp = 'none';
7613: if (document.getElementById('importcrsresform')) {
7614: if (caller == 'res') {
7615: var numdirs = parseInt(dircount);
7616: var curr = document.getElementById('importcrsresform').style.display;
7617: if (curr == 'none') {
7618: disp='block';
7619: if (numdirs > 1) {
7620: select1res_changed();
7621: }
7622: }
7623: }
7624: document.getElementById('importcrsresform').style.display=disp;
7625: resize_scrollbox('contentscroll','1','0');
7626: }
7627: return;
7628: }
7629:
1.501 raeburn 7630: function makeims(imsform) {
7631: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7632: alert("$js_lt{'imsfile'}");
1.501 raeburn 7633: return;
7634: }
7635: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7636: alert("$js_lt{'imscms'}");
1.501 raeburn 7637: return;
7638: }
7639: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7640: imsform.submit();
7641: }
7642:
1.478 raeburn 7643: function updatePick(targetform,index,caller) {
1.537 raeburn 7644: var pickitem;
7645: var picknumitem;
7646: var picknumtext;
7647: if (index == 'all') {
7648: pickitem = document.getElementById('randompickall');
7649: picknumitem = document.getElementById('rpicknumall');
7650: picknumtext = document.getElementById('rpicktextall');
7651: } else {
7652: pickitem = document.getElementById('randompick_'+index);
7653: picknumitem = document.getElementById('rpicknum_'+index);
7654: picknumtext = document.getElementById('randompicknum_'+index);
7655: }
1.478 raeburn 7656: if (pickitem.checked) {
1.594 damieng 7657: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7658: if (picknum == '' || picknum == null) {
7659: if (caller == 'check') {
7660: pickitem.checked=false;
1.537 raeburn 7661: if (index == 'all') {
7662: picknumtext.innerHTML = '';
7663: if (caller == 'link') {
7664: propagateState(targetform,'rpicknum');
7665: }
7666: } else {
1.538 raeburn 7667: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7668: }
1.478 raeburn 7669: }
7670: } else {
7671: picknum.toString();
7672: var regexdigit=/^\\d+\$/;
7673: if (regexdigit.test(picknum)) {
7674: picknumitem.value = picknum;
1.537 raeburn 7675: if (index == 'all') {
1.538 raeburn 7676: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7677: if (caller == 'link') {
7678: propagateState(targetform,'rpicknum');
7679: }
7680: } else {
7681: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7682: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7683: }
1.478 raeburn 7684: } else {
7685: if (caller == 'check') {
1.537 raeburn 7686: if (index == 'all') {
7687: picknumtext.innerHTML = '';
7688: if (caller == 'link') {
7689: propagateState(targetform,'rpicknum');
7690: }
7691: } else {
7692: pickitem.checked=false;
1.538 raeburn 7693: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7694: }
1.478 raeburn 7695: }
7696: return;
7697: }
7698: }
7699: } else {
1.537 raeburn 7700: picknumitem.value = '';
7701: picknumtext.innerHTML = '';
7702: if (index == 'all') {
7703: if (caller == 'link') {
7704: propagateState(targetform,'rpicknum');
7705: }
7706: } else {
1.538 raeburn 7707: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7708: }
7709: }
7710: }
7711:
7712: function propagateState(form,param) {
7713: if (document.getElementById(param+'all')) {
7714: var setcheck = 0;
7715: var rpick = 0;
7716: if (param == 'rpicknum') {
7717: if (document.getElementById('randompickall')) {
7718: if (document.getElementById('randompickall').checked) {
7719: if (document.getElementById('rpicknumall')) {
7720: rpick = document.getElementById('rpicknumall').value;
7721: }
7722: }
7723: }
7724: } else {
7725: if (document.getElementById(param+'all').checked) {
7726: setcheck = 1;
7727: }
7728: }
1.538 raeburn 7729: var allidxlist;
7730: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7731: if (document.getElementById('all'+param+'idx')) {
7732: allidxlist = document.getElementById('all'+param+'idx').value;
7733: }
7734: var actions = new Array ('remove','cut','copy');
7735: for (var i=0; i<actions.length; i++) {
7736: if (actions[i] != param) {
7737: if (document.getElementById(actions[i]+'all')) {
7738: document.getElementById(actions[i]+'all').checked = false;
7739: }
7740: }
7741: }
7742: }
1.537 raeburn 7743: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7744: allidxlist = form.allidx.value;
7745: }
7746: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7747: allidxlist = form.allmapidx.value;
7748: }
7749: if ((allidxlist != '') && (allidxlist != null)) {
7750: var allidxs = allidxlist.split(',');
7751: if (allidxs.length > 1) {
7752: for (var i=0; i<allidxs.length; i++) {
7753: if (document.getElementById(param+'_'+allidxs[i])) {
7754: if (param == 'rpicknum') {
7755: if (document.getElementById('randompick_'+allidxs[i])) {
7756: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7757: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7758: if (rpick > 0) {
7759: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7760: } else {
7761: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7762: }
7763: }
7764: }
7765: } else {
1.537 raeburn 7766: if (setcheck == 1) {
7767: document.getElementById(param+'_'+allidxs[i]).checked = true;
7768: } else {
7769: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7770: if (param == 'randompick') {
7771: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7772: }
1.537 raeburn 7773: }
7774: }
7775: }
7776: }
1.538 raeburn 7777: if (setcheck == 1) {
7778: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7779: var actions = new Array('copy','cut','remove');
7780: for (var i=0; i<actions.length; i++) {
7781: var otheractions;
7782: var otheridxs;
7783: if (actions[i] === param) {
7784: continue;
7785: } else {
7786: if (document.getElementById('all'+actions[i]+'idx')) {
7787: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7788: otheridxs = otheractions.split(',');
7789: if (otheridxs.length > 1) {
7790: for (var j=0; j<otheridxs.length; j++) {
7791: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7792: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7793: }
1.537 raeburn 7794: }
7795: }
7796: }
1.538 raeburn 7797: }
7798: }
7799: }
7800: }
7801: }
7802: }
7803: }
7804: return;
7805: }
7806:
1.603 raeburn 7807: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7808: var canedit = '$canedit';
7809: if (canedit == '') {
7810: alert("$js_lt{'edri'}");
7811: return;
7812: }
1.539 raeburn 7813: var dosettings;
7814: var doaction;
1.538 raeburn 7815: var control = document.togglemultsettings;
7816: if (context == 'actions') {
7817: control = document.togglemultactions;
1.539 raeburn 7818: doaction = 1;
7819: } else {
7820: dosettings = 1;
1.538 raeburn 7821: }
1.539 raeburn 7822: if (control) {
7823: if (control.showmultpick.length) {
7824: for (var i=0; i<control.showmultpick.length; i++) {
7825: if (control.showmultpick[i].checked) {
7826: if (control.showmultpick[i].value == 1) {
7827: if (context == 'settings') {
7828: dosettings = 0;
7829: } else {
7830: doaction = 0;
1.538 raeburn 7831: }
7832: }
7833: }
1.537 raeburn 7834: }
7835: }
1.539 raeburn 7836: }
7837: if (context == 'settings') {
7838: if (dosettings == 1) {
1.538 raeburn 7839: targetform.changeparms.value=param;
7840: targetform.submit();
7841: }
1.537 raeburn 7842: }
1.539 raeburn 7843: if (context == 'actions') {
7844: if (doaction == 1) {
7845: targetform.cmd.value=param+'_'+index;
7846: targetform.folderpath.value=folderpath;
7847: targetform.markcopy.value=idx+':'+param;
7848: targetform.copyfolder.value=folder+'.'+container;
7849: if (param == 'remove') {
1.603 raeburn 7850: var doremove = 0;
7851: if (skip_confirm) {
7852: if (confirm_removal) {
7853: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7854: doremove = 1;
7855: }
7856: } else {
7857: doremove = 1;
7858: }
7859: } else {
7860: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7861: doremove = 1;
7862: }
7863: }
7864: if (doremove) {
1.539 raeburn 7865: targetform.markcopy.value='';
7866: targetform.copyfolder.value='';
7867: targetform.submit();
7868: }
7869: }
7870: if (param == 'cut') {
1.594 damieng 7871: 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 7872: targetform.submit();
7873: return;
7874: }
7875: }
7876: if (param == 'copy') {
7877: targetform.submit();
7878: return;
7879: }
7880: targetform.markcopy.value='';
7881: targetform.copyfolder.value='';
7882: targetform.cmd.value='';
7883: targetform.folderpath.value='';
7884: return;
7885: } else {
7886: if (document.getElementById(param+'_'+idx)) {
7887: item = document.getElementById(param+'_'+idx);
7888: if (item.type == 'checkbox') {
7889: if (item.checked) {
7890: item.checked = false;
7891: } else {
7892: item.checked = true;
7893: singleCheck(item,idx,param);
7894: }
7895: }
7896: }
7897: }
7898: }
1.537 raeburn 7899: return;
7900: }
7901:
1.538 raeburn 7902: function singleCheck(caller,idx,action) {
7903: actions = new Array('cut','copy','remove');
7904: if (caller.checked) {
7905: for (var i=0; i<actions.length; i++) {
7906: if (actions[i] != action) {
7907: if (document.getElementById(actions[i]+'_'+idx)) {
7908: if (document.getElementById(actions[i]+'_'+idx).checked) {
7909: document.getElementById(actions[i]+'_'+idx).checked = false;
7910: }
1.537 raeburn 7911: }
7912: }
7913: }
1.478 raeburn 7914: }
1.537 raeburn 7915: return;
1.478 raeburn 7916: }
7917:
1.334 muellerd 7918: function unselectInactive(nav) {
1.335 ehlerst 7919: currentNav = document.getElementById(nav);
7920: currentLis = currentNav.getElementsByTagName('LI');
7921: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7922: if (currentLis[i].className == 'goback') {
7923: currentLis[i].className = 'goback';
7924: } else {
7925: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7926: currentLis[i].className = 'right';
1.472 raeburn 7927: } else {
1.374 tempelho 7928: currentLis[i].className = 'i';
1.472 raeburn 7929: }
7930: }
1.335 ehlerst 7931: }
1.332 tempelho 7932: }
7933:
1.334 muellerd 7934: function hideAll(current, nav, data) {
1.335 ehlerst 7935: unselectInactive(nav);
1.570 raeburn 7936: if (current) {
7937: if (current.className == 'right'){
7938: current.className = 'right active'
7939: } else {
7940: current.className = 'active';
7941: }
1.374 tempelho 7942: }
1.335 ehlerst 7943: currentData = document.getElementById(data);
7944: currentDivs = currentData.getElementsByTagName('DIV');
7945: for (i = 0; i < currentDivs.length; i++) {
7946: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7947: currentDivs[i].style.display = 'none';
1.330 tempelho 7948: }
7949: }
1.335 ehlerst 7950: }
1.330 tempelho 7951:
1.374 tempelho 7952: function openTabs(pageId) {
7953: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7954: if(tabnav.length > 2 ){
1.389 tempelho 7955: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7956: currentLis = currentNav.getElementsByTagName('LI');
7957: for(i = 0; i< currentLis.length; i++){
7958: if(currentLis[i].className == 'active') {
1.375 tempelho 7959: funcString = currentLis[i].onclick.toString();
7960: tab = funcString.split('"');
1.420 onken 7961: if(tab.length < 2) {
7962: tab = funcString.split("'");
7963: }
1.375 tempelho 7964: currentData = document.getElementById(tab[1]);
7965: currentData.style.display = 'block';
1.374 tempelho 7966: }
7967: }
7968: }
7969: }
7970:
1.334 muellerd 7971: function showPage(current, pageId, nav, data) {
1.570 raeburn 7972: currstate = current.className;
1.334 muellerd 7973: hideAll(current, nav, data);
1.375 tempelho 7974: openTabs(pageId);
1.334 muellerd 7975: unselectInactive(nav);
1.570 raeburn 7976: if ((currstate == 'active') || (currstate == 'right active')) {
7977: if (currstate == 'active') {
7978: current.className = '';
7979: } else {
7980: current.className = 'right';
7981: }
7982: activeTab = '';
7983: toggleUpload();
7984: toggleMap();
1.606 raeburn 7985: toggleCrsRes();
7986: toggleImportCrsres();
1.570 raeburn 7987: resize_scrollbox('contentscroll','1','0');
7988: return;
7989: } else {
7990: current.className = 'active';
7991: }
1.330 tempelho 7992: currentData = document.getElementById(pageId);
7993: currentData.style.display = 'block';
1.458 raeburn 7994: activeTab = pageId;
1.501 raeburn 7995: toggleUpload();
1.503 raeburn 7996: toggleMap();
1.606 raeburn 7997: toggleCrsRes();
7998: toggleImportCrsres();
1.433 raeburn 7999: if (nav == 'mainnav') {
8000: var storedpath = "$docs_folderpath";
1.434 raeburn 8001: var storedpage = "$main_container_page";
1.433 raeburn 8002: var reg = new RegExp("^supplemental");
8003: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8004: if (storedpage == 1) {
8005: document.simpleedit.folderpath.value = '';
8006: document.uploaddocument.folderpath.value = '';
8007: } else {
8008: if (reg.test(storedpath)) {
8009: document.simpleedit.folderpath.value = '$toplevelmain';
8010: document.uploaddocument.folderpath.value = '$toplevelmain';
8011: document.newext.folderpath.value = '$toplevelmain';
8012: } else {
8013: document.simpleedit.folderpath.value = storedpath;
8014: document.uploaddocument.folderpath.value = storedpath;
8015: document.newext.folderpath.value = storedpath;
8016: }
1.433 raeburn 8017: }
8018: } else {
1.434 raeburn 8019: if (reg.test(storedpath)) {
8020: document.simpleedit.folderpath.value = storedpath;
8021: document.supuploaddocument.folderpath.value = storedpath;
8022: document.supnewext.folderpath.value = storedpath;
8023: } else {
1.433 raeburn 8024: document.simpleedit.folderpath.value = '$toplevelsupp';
8025: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8026: document.supnewext.folderpath.value = '$toplevelsupp';
8027: }
8028: }
8029: }
1.485 raeburn 8030: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8031: return false;
8032: }
1.329 droeschl 8033:
1.472 raeburn 8034: function toContents(jumpto) {
8035: var newurl = '$backtourl';
1.525 raeburn 8036: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8037: newurl = newurl+'?postdata='+jumpto;
8038: }
8039: location.href=newurl;
8040: }
8041:
1.538 raeburn 8042: function togglePick(caller,value) {
8043: var disp = 'none';
8044: if (document.getElementById('multi'+caller)) {
8045: var curr = document.getElementById('multi'+caller).style.display;
8046: if (value == 1) {
8047: disp='block';
8048: }
8049: if (curr == disp) {
8050: return;
8051: }
8052: document.getElementById('multi'+caller).style.display=disp;
8053: if (value == 1) {
1.594 damieng 8054: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8055: } else {
8056: document.getElementById('more'+caller).innerHTML = '';
8057: }
8058: if (caller == 'actions') {
8059: setClass(value);
8060: setBoxes(value);
8061: }
8062: }
8063: var showButton = multiSettings();
8064: if (showButton != 1) {
8065: showButton = multiActions();
8066: }
8067: if (document.getElementById('multisave')) {
8068: if (showButton == 1) {
8069: document.getElementById('multisave').style.display='block';
8070: } else {
8071: document.getElementById('multisave').style.display='none';
8072: }
8073: }
8074: resize_scrollbox('contentscroll','1','1');
8075: return;
8076: }
8077:
8078: function toggleCheckUncheck(caller,more) {
8079: if (more == 1) {
1.594 damieng 8080: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8081: document.getElementById('allfields'+caller).style.display='block';
8082: } else {
1.594 damieng 8083: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8084: document.getElementById('allfields'+caller).style.display='none';
8085: }
8086: resize_scrollbox('contentscroll','1','1');
8087: }
8088:
8089: function multiSettings() {
8090: var inuse = 0;
8091: var settingsform = document.togglemultsettings;
8092: if (settingsform.showmultpick.length > 1) {
8093: for (var i=0; i<settingsform.showmultpick.length; i++) {
8094: if (settingsform.showmultpick[i].checked) {
8095: if (settingsform.showmultpick[i].value == 1) {
8096: inuse = 1;
8097: }
8098: }
8099: }
8100: }
8101: return inuse;
8102: }
8103:
8104: function multiActions() {
8105: var inuse = 0;
8106: var actionsform = document.togglemultactions;
8107: if (actionsform.showmultpick.length > 1) {
8108: for (var i=0; i<actionsform.showmultpick.length; i++) {
8109: if (actionsform.showmultpick[i].checked) {
8110: if (actionsform.showmultpick[i].value == 1) {
8111: inuse = 1;
8112: }
8113: }
8114: }
8115: }
8116: return inuse;
8117: }
8118:
8119: function checkSubmits() {
8120: var numchanges = 0;
8121: var form = document.saveactions;
8122: var doactions = multiActions();
1.542 raeburn 8123: var cutwarnings = 0;
8124: var remwarnings = 0;
1.603 raeburn 8125: var removalinfo = 0;
1.538 raeburn 8126: if (doactions == 1) {
8127: var remidxlist = document.cumulativeactions.allremoveidx.value;
8128: if ((remidxlist != '') && (remidxlist != null)) {
8129: var remidxs = remidxlist.split(',');
8130: for (var i=0; i<remidxs.length; i++) {
8131: if (document.getElementById('remove_'+remidxs[i])) {
8132: if (document.getElementById('remove_'+remidxs[i]).checked) {
8133: form.multiremove.value += remidxs[i]+',';
8134: numchanges ++;
1.542 raeburn 8135: if (document.getElementById('skip_remove_'+remidxs[i])) {
8136: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8137: remwarnings ++;
8138: }
8139: }
1.603 raeburn 8140: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8141: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8142: removalinfo ++;
8143: }
8144: }
1.537 raeburn 8145: }
8146: }
1.538 raeburn 8147: }
8148: }
8149: var cutidxlist = document.cumulativeactions.allcutidx.value;
8150: if ((cutidxlist != '') && (cutidxlist != null)) {
8151: var cutidxs = cutidxlist.split(',');
8152: for (var i=0; i<cutidxs.length; i++) {
8153: if (document.getElementById('cut_'+cutidxs[i])) {
8154: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8155: form.multicut.value += cutidxs[i]+',';
8156: numchanges ++;
1.542 raeburn 8157: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8158: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8159: cutwarnings ++;
8160: }
8161: }
1.537 raeburn 8162: }
8163: }
8164: }
8165: }
1.538 raeburn 8166: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8167: if ((copyidxlist != '') && (copyidxlist != null)) {
8168: var copyidxs = copyidxlist.split(',');
8169: for (var i=0; i<copyidxs.length; i++) {
8170: if (document.getElementById('copy_'+copyidxs[i])) {
8171: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8172: form.multicopy.value += copyidxs[i]+',';
8173: numchanges ++;
8174: }
8175: }
8176: }
8177: }
8178: if (numchanges > 0) {
8179: form.multichange.value = numchanges;
8180: }
1.537 raeburn 8181: }
1.538 raeburn 8182: var dosettings = multiSettings();
1.543 raeburn 8183: var haschanges = 0;
1.538 raeburn 8184: if (dosettings == 1) {
8185: form.allencrypturl.value = '';
8186: form.allhiddenresource.value = '';
1.543 raeburn 8187: form.changeparms.value = 'all';
8188: var patt=new RegExp(",\$");
1.538 raeburn 8189: var allidxlist = document.cumulativesettings.allidx.value;
8190: if ((allidxlist != '') && (allidxlist != null)) {
8191: var allidxs = allidxlist.split(',');
8192: if (allidxs.length > 1) {
8193: for (var i=0; i<allidxs.length; i++) {
8194: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8195: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8196: form.allhiddenresource.value += allidxs[i]+',';
8197: }
8198: }
8199: if (document.getElementById('encrypturl_'+allidxs[i])) {
8200: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8201: form.allencrypturl.value += allidxs[i]+',';
8202: }
8203: }
8204: }
1.543 raeburn 8205: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8206: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8207: }
1.538 raeburn 8208: }
8209: form.allrandompick.value = '';
8210: form.allrandomorder.value = '';
8211: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8212: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8213: var allmapidxs = allmapidxlist.split(',');
8214: for (var i=0; i<allmapidxs.length; i++) {
8215: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8216: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8217: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8218: if ((randompick.checked) && (rpicknum.value != '')) {
8219: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8220: }
8221: if (randorder.checked) {
8222: form.allrandomorder.value += allmapidxs[i]+',';
8223: }
1.537 raeburn 8224: }
1.543 raeburn 8225: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8226: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8227: }
8228: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8229: haschanges = 1;
8230: }
8231: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8232: haschanges = 1;
8233: }
8234: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8235: haschanges = 1;
8236: }
8237: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8238: haschanges = 1;
1.537 raeburn 8239: }
8240: }
1.543 raeburn 8241: if (doactions == 1) {
1.542 raeburn 8242: if (numchanges > 0) {
1.603 raeburn 8243: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8244: if (remwarnings > 0) {
1.594 damieng 8245: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8246: return false;
8247: }
8248: }
1.603 raeburn 8249: if (removalinfo > 0) {
8250: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8251: return false;
8252: }
8253: }
1.542 raeburn 8254: if (cutwarnings > 0) {
1.594 damieng 8255: 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 8256: return false;
8257: }
8258: }
8259: }
8260: form.submit();
8261: return true;
1.543 raeburn 8262: }
8263: }
8264: if (dosettings == 1) {
8265: if (haschanges == 1) {
1.542 raeburn 8266: form.submit();
8267: return true;
8268: }
1.543 raeburn 8269: }
8270: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8271: alert("$js_lt{'noor'}");
1.543 raeburn 8272: } else {
8273: if (dosettings == 1) {
1.594 damieng 8274: alert("$js_lt{'noch'}");
1.543 raeburn 8275: } else {
1.594 damieng 8276: alert("$js_lt{'noac'}");
1.543 raeburn 8277: }
8278: }
1.538 raeburn 8279: return false;
8280: }
8281:
8282: function setClass(value) {
8283: var cutclass = 'LC_docs_cut';
8284: var copyclass = 'LC_docs_copy';
8285: var removeclass = 'LC_docs_remove';
8286: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8287: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8288: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8289: var links = document.getElementsByTagName('a');
8290: for (var i=0; i<links.length; i++) {
8291: var classes = links[i].className;
8292: if (cutreg.test(classes)) {
8293: links[i].className = cutclass;
8294: if (value == 1) {
8295: links[i].className += " LC_menubuttons_link";
8296: }
8297: } else {
8298: if (copyreg.test(classes)) {
8299: links[i].className = copyclass;
8300: if (value == 1) {
8301: links[i].className += " LC_menubuttons_link";
8302: }
8303: } else {
8304: if (removereg.test(classes)) {
8305: links[i].className = removeclass;
8306: if (value == 1) {
8307: links[i].className += " LC_menubuttons_link";
8308: }
8309: }
8310: }
8311: }
8312: }
8313: return;
1.537 raeburn 8314: }
8315:
1.538 raeburn 8316: function setBoxes(value) {
8317: var remidxlist = document.cumulativeactions.allremoveidx.value;
8318: if ((remidxlist != '') && (remidxlist != null)) {
8319: var remidxs = remidxlist.split(',');
8320: for (var i=0; i<remidxs.length; i++) {
8321: if (document.getElementById('remove_'+remidxs[i])) {
8322: var item = document.getElementById('remove_'+remidxs[i]);
8323: if (value == 1) {
8324: item.className = 'LC_docs_remove';
8325: } else {
8326: item.className = 'LC_hidden';
8327: }
8328: }
8329: }
8330: }
8331: var cutidxlist = document.cumulativeactions.allcutidx.value;
8332: if ((cutidxlist != '') && (cutidxlist != null)) {
8333: var cutidxs = cutidxlist.split(',');
8334: for (var i=0; i<cutidxs.length; i++) {
8335: if (document.getElementById('cut_'+cutidxs[i])) {
8336: var item = document.getElementById('cut_'+cutidxs[i]);
8337: if (value == 1) {
8338: item.className = 'LC_docs_cut';
8339: } else {
8340: item.className = 'LC_hidden';
8341: }
8342: }
1.537 raeburn 8343: }
8344: }
1.538 raeburn 8345: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8346: if ((copyidxlist != '') && (copyidxlist != null)) {
8347: var copyidxs = copyidxlist.split(',');
8348: for (var i=0; i<copyidxs.length; i++) {
8349: if (document.getElementById('copy_'+copyidxs[i])) {
8350: var item = document.getElementById('copy_'+copyidxs[i]);
8351: if (value == 1) {
8352: item.className = 'LC_docs_copy';
8353: } else {
8354: item.className = 'LC_hidden';
8355: }
8356: }
1.537 raeburn 8357: }
8358: }
8359: return;
8360: }
8361:
1.606 raeburn 8362: function validImportCrsRes() {
8363: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8364: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8365: if ((fname == '') || (fname == null)) {
8366: alert("$js_lt{'nofi'}");
8367: return false;
8368: }
8369: var url = '/res/$coursedom/$coursenum/';
8370: if (path && path != '/') {
8371: url += path+'/';
8372: }
8373: if (fname != '') {
8374: url += fname;
8375: }
8376: var title = document.crsresimportform.crsrestitle.value;
8377: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8378: return true;
8379: }
8380:
8381: function validateNewRes(caller) {
8382: if (caller == 'single') {
8383: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8384: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8385: var resname = document.courseresform.newresourcename.value;
8386: }
8387: }
8388:
1.611 raeburn 8389: ENDSCRIPT
1.329 droeschl 8390: }
1.457 raeburn 8391:
1.483 raeburn 8392: sub history_tab_js {
8393: return <<"ENDHIST";
8394: function toggleHistoryDisp(choice) {
8395: document.docslogform.docslog.value = choice;
8396: document.docslogform.submit();
8397: return;
8398: }
8399:
8400: ENDHIST
8401: }
8402:
1.484 raeburn 8403: sub inject_data_js {
8404: return <<ENDINJECT;
8405:
8406: function injectData(current, hiddenField, name, value) {
8407: currentElement = document.getElementById(hiddenField);
8408: currentElement.name = name;
8409: currentElement.value = value;
8410: current.submit();
8411: }
8412:
8413: ENDINJECT
8414: }
8415:
8416: sub dump_switchserver_js {
8417: my @hosts = @_;
1.594 damieng 8418: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8419: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8420: swit => 'Switch server?',
1.594 damieng 8421: );
8422: my %html_js_lt = &Apache::lonlocal::texthash(
8423: swit => 'Switch server?',
1.568 raeburn 8424: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8425: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8426: chos => 'Choose server',
8427: );
1.594 damieng 8428: &js_escape(\%js_lt);
8429: &html_escape(\%html_js_lt);
8430: &js_escape(\%html_js_lt);
1.484 raeburn 8431: my $role = $env{'request.role'};
8432: my $js = <<"ENDSWJS";
8433: <script type="text/javascript">
8434: function write_switchserver() {
8435: var server;
8436: if (document.setserver.posshosts.length > 0) {
8437: for (var i=0; i<document.setserver.posshosts.length; i++) {
8438: if (document.setserver.posshosts[i].checked) {
8439: server = document.setserver.posshosts[i].value;
8440: }
8441: }
8442: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8443: }
8444: window.close();
8445: }
8446: </script>
8447:
8448: ENDSWJS
8449:
8450: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8451: {'only_body' => 1,
8452: 'js_ready' => 1,});
8453: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8454:
8455: my $hostpicker;
8456: my $count = 0;
8457: foreach my $host (sort(@hosts)) {
8458: my $checked;
8459: if ($count == 0) {
8460: $checked = ' checked="checked"';
8461: }
8462: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8463: $host.'"'.$checked.' />'.$host.'</label> ';
8464: $count++;
8465: }
8466:
8467: return <<"ENDSWITCHJS";
8468:
8469: function dump_needs_switchserver(url) {
8470: if (url!='' && url!= null) {
1.594 damieng 8471: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8472: go(url);
8473: }
8474: }
8475: return;
8476: }
8477:
8478: function choose_switchserver_window() {
8479: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8480: newWindow.document.open();
8481: newWindow.document.writeln('$startpage');
1.594 damieng 8482: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8483: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8484: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8485: '<form name="setserver" method="post" action="" \\/>\\n'+
8486: '$hostpicker\\n'+
8487: '<br \\/><br \\/>\\n'+
1.594 damieng 8488: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8489: 'onclick="write_switchserver();" \\/>\\n'+
8490: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8491: newWindow.document.writeln('$endpage');
8492: newWindow.document.close();
8493: newWindow.focus();
8494: }
8495:
8496: ENDSWITCHJS
8497: }
8498:
8499: sub makedocslogform {
8500: my ($formelems,$docslog) = @_;
8501: return <<"LOGSFORM";
8502: <form action="/adm/coursedocs" method="post" name="docslogform">
8503: <input type="hidden" name="docslog" value="$docslog" />
8504: $formelems
8505: </form>
8506: LOGSFORM
8507: }
8508:
8509: sub makesimpleeditform {
8510: my ($formelems) = @_;
8511: return <<"SIMPFORM";
8512: <form name="simpleedit" method="post" action="/adm/coursedocs">
8513: <input type="hidden" name="importdetail" value="" />
8514: $formelems
8515: </form>
8516: SIMPFORM
8517: }
8518:
1.606 raeburn 8519: sub makenewproblem {
8520: my ($r,$coursedom,$coursenum) = @_;
8521: # Creating a new problem
8522: my ($redirect,$error);
8523: if ($env{'form.authorrole'}) {
8524: my ($newsubdir,$filename);
8525: if ($env{'form.newsubdir'}) {
8526: if ($env{'form.newsubdirname'} ne '') {
8527: $newsubdir = $env{'form.newsubdirname'};
8528: }
8529: }
8530: if ($env{'form.newresourcename'}) {
8531: $filename = $env{'form.newresourcename'};
8532: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8533: $filename =~ s/`//g;
8534: $filename =~ s{/\.\./}{_}g;
8535: $filename =~ s/\.+/./g;
8536: $filename =~ s{/+}{_}g;
8537: if ($filename ne '') {
8538: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8539: if (($ext) && ($ext ne '.problem')) {
8540: $filename = $name.'.problem';
8541: } elsif ($ext eq '') {
8542: $filename .= '.problem';
8543: }
8544: my $docroot = $r->dir_config('lonDocRoot');
8545: my @ids=&Apache::lonnet::current_machine_ids();
8546: if ($env{'form.authorrole'} eq 'author') {
8547: if ($env{'user.author'}) {
8548: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8549: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8550: my $path = $docroot.$url;
8551: my $subdir = $env{'form.authorpath'};
8552: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8553: }
8554: }
8555: } elsif ($env{'form.authorrole'} eq 'course') {
8556: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8557: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8558: my $url = "/priv/$coursedom/$coursenum";
8559: my $path=$docroot.$url;
8560: my $subdir = $env{'form.authorpath'};
8561: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8562: if ($redirect) {
8563: my $rightsfile = 'default.rights';
8564: my $sourcerights = "$path/$rightsfile";
8565: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8566: my $now = time;
8567: if (!-e $sourcerights) {
8568: my $cid = $coursedom.'_'.$coursenum;
8569: if (open(my $fh,">$sourcerights")) {
8570: print $fh <<END;
8571: <accessrule effect="deny" realm="" type="course" role="" />
8572: <accessrule effect="allow" realm="$cid" type="course" role="" />
8573: END
8574: close($fh);
8575: }
8576: }
8577: if (!-e "$sourcerights.meta") {
8578: if (open(my $fh,">$sourcerights.meta")) {
8579: my $author=$env{'environment.firstname'}.' '.
8580: $env{'environment.middlename'}.' '.
8581: $env{'environment.lastname'}.' '.
8582: $env{'environment.generation'};
8583: $author =~ s/\s+$//;
8584: print $fh <<"END";
8585:
8586: <abstract></abstract>
8587: <author>$author</author>
8588: <authorspace>$coursenum:$coursedom</authorspace>
8589: <copyright>private</copyright>
8590: <creationdate>$now</creationdate>
8591: <customdistributionfile></customdistributionfile>
8592: <dependencies></dependencies>
8593: <domain>$coursedom</domain>
8594: <highestgradelevel>0</highestgradelevel>
8595: <keywords></keywords>
8596: <language>notset </language>
8597: <lastrevisiondate>$now</lastrevisiondate>
8598: <lowestgradelevel>0</lowestgradelevel>
8599: <mime>rights</mime>
8600: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8601: <notes></notes>
8602: <obsolete></obsolete>
8603: <obsoletereplacement></obsoletereplacement>
8604: <owner>$coursenum:$coursedom</owner>
8605: <rule>deny:::course,allow:$cid::course</rule>
8606: <sourceavail></sourceavail>
8607: <standards></standards>
8608: <subject></subject>
8609: <title></title>
8610: END
8611: close($fh);
8612: }
8613: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8614: if (!-e "$docroot/res/$coursedom") {
8615: mkdir("$docroot/res/$coursedom",0755);
8616: }
8617: if (!-e "$docroot/res/$coursedom/$coursenum") {
8618: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8619: }
8620: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8621: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8622: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8623: }
8624: }
8625: }
8626: if ($env{'form.newresourceadd'}) {
8627: my $template = $env{'form.template'};
8628: my $source = $docroot.$redirect;
8629: my $target = $redirect;
8630: $target =~ s{^/priv/}{/res/};
8631: $target = $docroot.$target;
8632: if (!-e $source) {
8633: my $copyfrom;
8634: if ($template) {
8635: my %templates;
8636: my @files = &Apache::lonhomework::get_template_list('problem');
8637: foreach my $poss (@files) {
8638: if (ref($poss) eq 'ARRAY') {
8639: if ($template eq $poss->[0]) {
8640: $templates{$template} = 1;
8641: last;
8642: }
8643: }
8644: }
8645: if ($templates{$template}) {
8646: $copyfrom = $template;
8647: }
8648: }
8649: unless ($copyfrom) {
8650: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8651: }
8652: &File::Copy::copy($copyfrom,$source);
8653: }
8654: if (!-e "$source.meta") {
8655: my $cid = $coursedom.'_'.$coursenum;
8656: my $now = time;
8657: if (open(my $fh,">$source.meta")) {
8658: my $author=$env{'environment.firstname'}.' '.
8659: $env{'environment.middlename'}.' '.
8660: $env{'environment.lastname'}.' '.
8661: $env{'environment.generation'};
8662: $author =~ s/\s+$//;
8663: my $title = $env{'form.newresourcetitle'};
8664: $title =~ s/^\s+|\s+$//g;
8665: print $fh <<END;
8666:
8667: <abstract></abstract>
8668: <author>$author</author>
8669: <authorspace>$coursenum:$coursedom</authorspace>
8670: <copyright>custom</copyright>
8671: <creationdate>$now</creationdate>
8672: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8673: <dependencies></dependencies>
8674: <domain>$coursedom</domain>
8675: <highestgradelevel>0</highestgradelevel>
8676: <keywords></keywords>
8677: <language>notset </language>
8678: <lastrevisiondate>$now</lastrevisiondate>
8679: <lowestgradelevel>0</lowestgradelevel>
8680: <mime>problem</mime>
8681: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8682: <notes></notes>
8683: <obsolete></obsolete>
8684: <obsoletereplacement></obsoletereplacement>
8685: <owner>$coursenum:$coursedom</owner>
8686: <sourceavail></sourceavail>
8687: <standards></standards>
8688: <subject></subject>
8689: <title>$title</title>
8690: END
8691: close($fh);
8692: }
8693: }
8694: }
8695: }
8696: }
8697: } else {
8698: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8699: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8700: if (grep(/^\Q$rolehome\E$/,@ids)) {
8701: my $now = time;
8702: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8703: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8704: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8705: my $url = "/priv/$audom/$auname";
8706: my $path = $r->dir_config('lonDocRoot').$url;
8707: my $subdir = $env{'form.authorpath'};
8708: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8709: }
8710: }
8711: }
8712: }
8713: }
8714: }
8715: }
8716: return ($redirect,$error);
8717: }
8718:
8719: sub finishnewprob {
8720: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8721: unless (-d $path) {
8722: unless (mkdir($path,02770)) {
8723: return;
8724: }
8725: }
1.606 raeburn 8726: my $redirect;
8727: if ($subdir ne '/') {
8728: $subdir = &cleandir($subdir);
8729: if (($subdir ne '') && (-d "$path/$subdir")) {
8730: $path .= "/$subdir";
8731: $url .= "/$subdir";
8732: }
8733: }
8734: my $dest;
8735: if ($newsubdir ne '') {
8736: $newsubdir = &cleandir($newsubdir);
8737: }
8738: if ($newsubdir ne '') {
8739: if (-d "$path/$newsubdir") {
8740: $dest = "$path/$newsubdir/$filename";
8741: } else {
8742: my $dirok;
8743: unless (-e "$path/$newsubdir") {
8744: if (mkdir("$path/$newsubdir",02770)) {
8745: if (chmod(02770,"$path/$newsubdir")) {
8746: $dirok = 1;
8747: }
8748: }
8749: }
8750: if ($dirok) {
8751: $dest = "$path/$newsubdir/$filename";
8752: }
8753: }
8754: if (($dest ne '') && (!-e $dest)) {
8755: $redirect = "$url/$newsubdir/$filename";
8756: }
8757: } else {
8758: $dest = "$path/$filename";
8759: if (($dest ne '') && (!-e $dest)) {
8760: $redirect = "$url/$filename";
8761: }
8762: }
8763: return $redirect;
8764: }
8765:
8766: sub cleandir {
8767: my ($dir) = @_;
8768: $dir =~ s/^\s+//;
8769: $dir =~ s/\s+$//;
8770: $dir =~ s/\.+//g;
8771: $dir =~ s/[\#\?&%\":]//g;
8772: return $dir;
8773: }
8774:
1.329 droeschl 8775: 1;
8776: __END__
8777:
8778:
8779: =head1 NAME
8780:
8781: Apache::londocs.pm
8782:
8783: =head1 SYNOPSIS
8784:
8785: This is part of the LearningOnline Network with CAPA project
8786: described at http://www.lon-capa.org.
8787:
8788: =head1 SUBROUTINES
8789:
8790: =over
8791:
8792: =item %help=()
8793:
8794: Available help topics
8795:
8796: =item mapread()
8797:
1.344 bisitz 8798: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8799: @order and @resources, determines status
8800: sets @order - pointer to resources in right order
8801: sets @resources - array with the resources with correct idx
8802:
8803: =item authorhosts()
8804:
8805: Return hash with valid author names
8806:
8807: =item clean()
8808:
8809: =item dumpcourse()
8810:
8811: Actually dump course
8812:
8813: =item group_import()
8814:
8815: Imports the given (name, url) resources into the course
8816: coursenum, coursedom, and folder must precede the list
8817:
8818: =item breadcrumbs()
8819:
8820: =item log_docs()
8821:
8822: =item docs_change_log()
8823:
8824: =item update_paste_buffer()
8825:
8826: =item print_paste_buffer()
8827:
8828: =item do_paste_from_buffer()
8829:
1.538 raeburn 8830: =item do_buffer_empty()
8831:
8832: =item clear_from_buffer()
8833:
1.492 raeburn 8834: =item get_newmap_url()
8835:
8836: =item dbcopy()
8837:
8838: =item uniqueness_check()
8839:
8840: =item contained_map_check()
8841:
8842: =item url_paste_fixups()
8843:
8844: =item apply_fixups()
8845:
8846: =item copy_dependencies()
8847:
1.329 droeschl 8848: =item update_parameter()
8849:
8850: =item handle_edit_cmd()
8851:
8852: =item editor()
8853:
8854: =item process_file_upload()
8855:
8856: =item process_secondary_uploads()
8857:
8858: =item is_supplemental_title()
8859:
8860: =item entryline()
8861:
8862: =item tiehash()
8863:
8864: =item untiehash()
8865:
8866: =item checkonthis()
8867:
8868: check on this
8869:
8870: =item verifycontent()
8871:
8872: Verify Content
8873:
1.636 raeburn 8874: =item devalidateversioncache()
8875:
8876: =item checkversions()
1.329 droeschl 8877:
8878: Check Versions
8879:
8880: =item mark_hash_old()
8881:
8882: =item is_hash_old()
8883:
8884: =item changewarning()
8885:
8886: =item init_breadcrumbs()
8887:
8888: Breadcrumbs for special functions
8889:
1.484 raeburn 8890: =item create_list_elements()
8891:
8892: =item create_form_ul()
8893:
8894: =item startContentScreen()
8895:
8896: =item endContentScreen()
8897:
8898: =item supplemental_base()
8899:
8900: =item embedded_form_elems()
8901:
8902: =item embedded_destination()
8903:
8904: =item return_to_editor()
8905:
8906: =item decompression_info()
8907:
8908: =item decompression_phase_one()
8909:
8910: =item decompression_phase_two()
8911:
8912: =item remove_archive()
8913:
8914: =item generate_admin_menu()
8915:
8916: =item generate_edit_table()
8917:
8918: =item editing_js()
8919:
8920: =item history_tab_js()
8921:
8922: =item inject_data_js()
8923:
8924: =item dump_switchserver_js()
8925:
1.485 raeburn 8926: =item resize_scrollbox_js()
1.484 raeburn 8927:
8928: =item makedocslogform()
8929:
1.485 raeburn 8930: =item makesimpleeditform()
8931:
1.329 droeschl 8932: =back
8933:
8934: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>