Annotation of loncom/interface/londocs.pm, revision 1.695
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.695 ! raeburn 4: # $Id: londocs.pm,v 1.694 2023/01/20 16:19:56 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.651 raeburn 49: use Apache::loncourserespicker();
1.329 droeschl 50: use HTML::Entities;
1.488 raeburn 51: use HTML::TokeParser;
1.329 droeschl 52: use GDBM_File;
1.578 raeburn 53: use File::MMagic;
1.606 raeburn 54: use File::Copy;
1.329 droeschl 55: use Apache::lonlocal;
56: use Cwd;
1.643 raeburn 57: use UUID::Tiny ':std';
1.329 droeschl 58: use LONCAPA qw(:DEFAULT :match);
59:
60: my $iconpath;
61:
62: my %hash;
63:
64: my $hashtied;
65: my %alreadyseen=();
66:
67: my $hadchanges;
1.557 raeburn 68: my $suppchanges;
1.329 droeschl 69:
70:
71: my %help=();
72:
73:
74: sub mapread {
75: my ($coursenum,$coursedom,$map)=@_;
76: return
77: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
78: $map);
79: }
80:
81: sub storemap {
1.492 raeburn 82: my ($coursenum,$coursedom,$map,$contentchg)=@_;
83: my $report;
84: if (($contentchg) && ($map =~ /^default/)) {
85: $report = 1;
86: }
1.329 droeschl 87: my ($outtext,$errtext)=
88: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 89: $map,1,$report);
1.329 droeschl 90: if ($errtext) { return ($errtext,2); }
1.364 bisitz 91:
1.557 raeburn 92: if ($map =~ /^default/) {
93: $hadchanges=1;
1.682 raeburn 94: } elsif ($contentchg) {
1.557 raeburn 95: $suppchanges=1;
96: }
1.329 droeschl 97: return ($errtext,0);
98: }
99:
100:
101:
102: sub authorhosts {
103: my %outhash=();
104: my $home=0;
105: my $other=0;
106: foreach my $key (keys(%env)) {
107: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
108: my $role=$1;
109: my $realm=$2;
110: my ($start,$end)=split(/\./,$env{$key});
111: if (($start) && ($start>time)) { next; }
112: if (($end) && (time>$end)) { next; }
113: my ($ca,$cd);
114: if ($1 eq 'au') {
115: $ca=$env{'user.name'};
116: $cd=$env{'user.domain'};
117: } else {
118: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
119: }
120: my $allowed=0;
121: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
122: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 123: foreach my $id (@ids) {
124: if ($id eq $myhome) {
125: $allowed=1;
126: last;
127: }
128: }
1.329 droeschl 129: if ($allowed) {
130: $home++;
1.484 raeburn 131: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 132: } else {
1.484 raeburn 133: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 134: $other++;
135: }
136: }
137: }
138: return ($home,$other,%outhash);
139: }
140:
141:
142: sub clean {
143: my ($title)=@_;
144: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 145: return $title;
1.329 droeschl 146: }
147:
1.617 raeburn 148: sub default_folderpath {
149: my ($coursenum,$coursedom,$navmapref) = @_;
150: return unless ($coursenum && $coursedom && ref($navmapref));
151: # Check if entire course is hidden and/or encrypted
152: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
153: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
154: unless (ref($$navmapref)) {
155: $$navmapref = Apache::lonnavmaps::navmap->new();
156: }
157: if (ref($$navmapref)) {
158: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
159: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
160: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
161: unless (@resources) {
162: $hiddenmap = 1;
163: unless ($env{'request.role.adv'}) {
164: $hiddentop = 1;
165: if ($env{'form.folder'}) {
166: undef($env{'form.folder'});
167: }
168: }
169: }
170: }
171: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
172: $encryptmap = 1;
173: }
174: }
175: unless ($hiddentop) {
176: $folderpath='default&'.&escape(&mt('Main Content')).
177: '::'.$hiddenmap.':'.$encryptmap.'::';
178: }
179: if (wantarray) {
180: return ($folderpath,$hiddentop);
181: } else {
182: return $folderpath;
183: }
184: }
1.329 droeschl 185:
1.685 raeburn 186: sub validate_supppath {
187: my ($coursenum,$coursedom) = @_;
188: my $backto;
1.677 raeburn 189: if ($env{'form.supppath'} ne '') {
190: my @items = split(/\&/,$env{'form.supppath'});
1.685 raeburn 191: my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
1.677 raeburn 192: for (my $i=0; $i<@items; $i++) {
193: my $odd = $i%2;
194: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
195: $badpath = 1;
1.685 raeburn 196: last;
197: } elsif ($odd) {
198: my $suffix;
199: my $idx = $i-1;
200: if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
201: $backto .= '&'.$1;
202: } elsif ($items[$idx] eq 'supplemental') {
203: $backto .= '&'.$items[$i];
204: } else {
205: $backto .= '&'.$items[$i];
206: my $is_hidden;
207: unless ($got_supp) {
1.688 raeburn 208: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 209: if (ref($supplemental) eq 'HASH') {
210: if (ref($supplemental->{'hidden'}) eq 'HASH') {
211: %supphidden = %{$supplemental->{'hidden'}};
212: }
213: if (ref($supplemental->{'ids'}) eq 'HASH') {
214: %suppids = %{$supplemental->{'ids'}};
215: }
216: }
217: $got_supp = 1;
218: }
219: if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
220: my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
221: if ($supphidden{$mapid}) {
222: $is_hidden = 1;
223: }
224: }
225: $suffix = '::'.$is_hidden.':::';
226: }
227: $supppath .= '&'.$items[$i].$suffix;
228: } else {
229: $supppath .= '&'.$items[$i];
230: $backto .= '&'.$items[$i];
1.677 raeburn 231: }
232: }
233: if ($badpath) {
234: delete($env{'form.supppath'});
1.685 raeburn 235: } else {
236: $supppath =~ s/^\&//;
237: $backto =~ s/^\&//;
238: $env{'form.supppath'} = $supppath;
1.677 raeburn 239: }
240: }
1.685 raeburn 241: return $backto;
1.677 raeburn 242: }
243:
1.329 droeschl 244: sub dumpcourse {
245: my ($r) = @_;
1.408 raeburn 246: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 247: my ($starthash,$js);
248: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
249: $js = <<"ENDJS";
250: <script type="text/javascript">
251: // <![CDATA[
252:
253: function hide_searching() {
254: if (document.getElementById('searching')) {
255: document.getElementById('searching').style.display = 'none';
256: }
257: return;
258: }
259:
260: // ]]>
261: </script>
262: ENDJS
263: $starthash = {
264: add_entries => {'onload' => "hide_searching();"},
265: };
266: }
1.568 raeburn 267: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
268: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 269: $r->print(&startContentScreen('tools'));
1.329 droeschl 270: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 271: unless ($home) {
272: $r->print(&endContentScreen());
273: return '';
274: }
1.329 droeschl 275: my $origcrsid=$env{'request.course.id'};
276: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
277: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
278: # Do the dumping
1.484 raeburn 279: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
280: $r->print(&endContentScreen());
281: return '';
282: }
1.531 raeburn 283: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 284: $r->print('<h3>'.&mt('Copying Files').'</h3>');
285: my $title=$env{'form.authorfolder'};
286: $title=&clean($title);
1.567 raeburn 287: my ($navmap,$errormsg) =
288: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
289: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
290: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
291: my (%maps,%resources,%titles);
292: if (!ref($navmap)) {
293: $r->print($errormsg.
294: &endContentScreen());
295: return '';
296: } else {
297: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
298: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 299: }
1.567 raeburn 300: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
301: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
302: %newcontent,%has_simpleprobs);
303: foreach my $item (sort {$a <=> $b} (@todump)) {
304: my $name = $env{'form.namefor_'.$item};
305: if ($resources{$item}) {
306: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
307: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
308: $tocopy{$1} = $name;
309: $display{$item} = $1;
310: $lookup{$1} = $item;
311: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
312: $simpleproblems{$item} = {
313: symb => $resources{$item},
314: name => $name,
315: };
316: $display{$item} = 'simpleproblem_'.$name;
317: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
318: $has_simpleprobs{$1}{$id} = $item;
319: }
320: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
321: my $marker = $1;
322: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
323: $simplepages{$item} = {
324: res => $res,
325: title => $titles{$item},
326: db => $db_name,
327: marker => $marker,
328: symb => $resources{$item},
329: name => $name,
330: };
331: $display{$item} = '/'.$res;
332: }
333: } elsif ($maps{$item}) {
334: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
335: $tocopy{$1} = $name;
336: $display{$item} = $1;
337: $lookup{$1} = $item;
338: }
339: } else {
340: next;
341: }
342: }
1.329 droeschl 343: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
344: $crs=~s/\_/\//g;
1.567 raeburn 345: my $mm = new File::MMagic;
346: my $prefix = "/uploaded/$cdom/$cnum/";
347: %replacehash = %tocopy;
348: foreach my $item (sort(keys(%simpleproblems))) {
349: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
350: $newcontent{$display{$item}} = $content;
351: }
352: my $gateway = Apache::lonhtmlgateway->new('web');
353: foreach my $item (sort(keys(%simplepages))) {
354: if (ref($simplepages{$item}) eq 'HASH') {
355: my $pagetitle = $simplepages{$item}{'title'};
356: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
357: my %contents;
358: foreach my $field (keys(%fields)) {
359: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
360: my $name = $1;
361: my $msg = $fields{$field};
362: if ($name eq 'webreferences') {
363: if ($msg =~ m{^https?://}) {
364: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
365: }
366: } else {
367: $msg = &Encode::decode('utf8',$msg);
368: $msg = $gateway->process_outgoing_html($msg,1);
369: $contents{$name} = $msg;
370: }
371: } elsif ($field eq 'uploaded.photourl') {
372: my $marker = $simplepages{$item}{marker};
373: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
374: my $filepath = $1;
375: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
376: if ($fname ne '') {
377: $fname=~s/\.(\w+)$//;
378: my $ext=$1;
379: $fname = &clean($fname);
380: $fname.='.'.$ext;
381: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
382: $replacehash{$filepath} = $relpath.$fname;
383: $deps{$item}{$filepath} = 1;
384: }
385: }
386: }
387: }
388: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
389: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
390: my $content = '
391: <html>
392: <head>
393: <title>'.$pagetitle.'</title>
394: </head>
395: <body bgcolor="#ffffff">';
396: if ($contents{title}) {
397: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
398: }
399: if ($contents{image}) {
400: $content .= "\n".$contents{image};
401: }
402: if ($contents{content}) {
403: $content .= '
404: <div class="LC_Box">
1.577 bisitz 405: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 406: $contents{content}.'
407: </div>';
408: }
409: if ($contents{webreferences}) {
410: $content .= '
411: <div class="LC_Box">
1.577 bisitz 412: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 413: $contents{webreferences}.'
414: </div>';
415: }
416: $content .= '
417: </body>
418: </html>
419: ';
420: $newcontent{'/'.$simplepages{$item}{res}} = $content;
421: }
422: }
423: foreach my $item (keys(%tocopy)) {
424: unless ($item=~/\.(sequence|page)$/) {
425: my $currurlpath = $prefix.$item;
426: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
427: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
428: }
429: }
430: foreach my $num (sort {$a <=> $b} (@todump)) {
431: my $src = $display{$num};
432: next if ($src eq '');
433: my @needcopy = ();
434: if ($replacehash{$src}) {
435: push(@needcopy,$src);
436: if (ref($deps{$num}) eq 'HASH') {
437: foreach my $dep (sort(keys(%{$deps{$num}}))) {
438: if ($replacehash{$dep}) {
439: push(@needcopy,$dep);
440: }
441: }
442: }
443: } elsif ($src =~ /^simpleproblem_/) {
444: push(@needcopy,$src);
445: }
446: next if (@needcopy == 0);
447: my ($result,$depresult);
448: for (my $i=0; $i<@needcopy; $i++) {
449: my $item = $needcopy[$i];
450: my $newfilename;
451: if ($simpleproblems{$num}) {
452: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
453: } else {
454: $newfilename=$title.'/'.$replacehash{$item};
455: }
456: $newfilename=~s/\.(\w+)$//;
457: my $ext=$1;
458: $newfilename=&clean($newfilename);
459: $newfilename.='.'.$ext;
460: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
461: if ($newrelpath ne $replacehash{$item}) {
462: $replacehash{$item} = $newrelpath;
463: }
464: my @dirs=split(/\//,$newfilename);
465: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
466: my $makepath=$path;
467: my $fail;
468: my $origin;
469: for (my $i=0;$i<$#dirs;$i++) {
470: $makepath.='/'.$dirs[$i];
471: unless (-e $makepath) {
472: unless(mkdir($makepath,0755)) {
473: $fail = &mt('Directory creation failed.');
474: }
475: }
476: }
477: if ($i == 0) {
478: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
479: } else {
480: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
481: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
482: &mt('(dependency)').'</span>: ';
483: }
484: if (-e $path.'/'.$newfilename) {
485: $fail = &mt('Destination already exists -- not overwriting.');
486: } else {
487: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
488: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
489: ($item =~ /^simpleproblem_/)) {
490: print $fh $newcontent{$item};
491: } else {
492: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
493: if (-e $fileloc) {
494: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
495: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
496: (ref($has_simpleprobs{$item}) eq 'HASH')) {
497: my %changes = %{$has_simpleprobs{$item}};
498: my $content = &Apache::lonclonecourse::rewritefile(
499: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
500: (%replacehash,$crs => '')
501: );
502: my $updatedcontent = '';
503: my $parser = HTML::TokeParser->new(\$content);
504: $parser->attr_encoded(1);
505: while (my $token = $parser->get_token) {
506: if ($token->[0] eq 'S') {
507: if (($token->[1] eq 'resource') &&
508: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
509: ($changes{$token->[2]->{'id'}})) {
510: my $id = $token->[2]->{'id'};
511: $updatedcontent .= '<'.$token->[1];
512: foreach my $attrib (@{$token->[3]}) {
513: next unless ($attrib =~ /^(src|type|title|id)$/);
514: if ($attrib eq 'src') {
515: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
516: if ($file) {
517: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
518: } else {
519: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
520: }
521: } else {
522: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
523: }
524: }
525: $updatedcontent .= ' />'."\n";
526: } else {
527: $updatedcontent .= $token->[4]."\n";
528: }
529: } else {
530: $updatedcontent .= $token->[2];
531: }
532: }
533: print $fh $updatedcontent;
534: } else {
535: print $fh &Apache::lonclonecourse::rewritefile(
536: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
537: (%replacehash,$crs => '')
538: );
539: }
540: } else {
541: print $fh
542: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
543: }
544: } else {
545: $fail = &mt('Source does not exist.');
546: }
547: }
548: $fh->close();
549: } else {
550: $fail = &mt('Could not write to destination.');
551: }
552: }
553: my $text;
554: if ($fail) {
555: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
556: } else {
557: $text = '<span class="LC_success">'.&mt('ok').'</span>';
558: }
559: if ($i == 0) {
560: $result .= $text;
561: } else {
562: $depresult .= $text.'</li>';
563: }
564: }
565: $r->print($result);
566: if ($depresult) {
567: $r->print('<ul>'.$depresult.'</ul>');
568: }
569: }
570: } else {
571: my ($navmap,$errormsg) =
572: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
573: if (!ref($navmap)) {
574: $r->print($errormsg);
575: } else {
576: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
577: $r->rflush();
578: my ($preamble,$formname);
579: $formname = 'dumpdoc';
580: unless ($home==1) {
581: $preamble = '<div class="LC_left_float">'.
582: '<fieldset><legend>'.
583: &mt('Select the Authoring Space').
584: '</legend><select name="authorspace">';
1.329 droeschl 585: }
1.567 raeburn 586: my @orderspaces = ();
587: foreach my $key (sort(keys(%outhash))) {
588: if ($key=~/^home_(.+)$/) {
589: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
590: unshift(@orderspaces,$1);
591: } else {
592: push(@orderspaces,$1);
593: }
594: }
595: }
1.569 raeburn 596: if ($home>1) {
597: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
598: }
1.567 raeburn 599: foreach my $user (@orderspaces) {
1.329 droeschl 600: if ($home==1) {
1.567 raeburn 601: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 602: } else {
1.567 raeburn 603: $preamble .= '<option value="'.$user.'">'.$user.' - '.
604: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
605: }
1.329 droeschl 606: }
1.567 raeburn 607: unless ($home==1) {
608: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 609: }
1.567 raeburn 610: my $title=$origcrsdata{'description'};
611: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 612: $title=&clean($title);
1.567 raeburn 613: $preamble .= '<div class="LC_left_float">'.
614: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
615: '<input type="text" size="50" name="authorfolder" value="'.
616: $title.'" />'.
617: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
618: my %uploadedfiles;
619: &tiehash();
620: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
621: my ($ext)=($file=~/\.(\w+)$/);
622: # FIXME Check supplemental here
623: my $title=$hash{'title_'.$hash{
624: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
625: if (!$title) {
626: $title=$file;
627: } else {
628: $title=~s|/|_|g;
629: }
630: $title=~s/\.(\w+)$//;
631: $title=&clean($title);
632: $title.='.'.$ext;
633: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
634: $uploadedfiles{$file} = $title;
635: }
636: &untiehash();
637: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
638: undef,undef,$preamble,$home,\%uploadedfiles));
639: }
1.329 droeschl 640: }
1.484 raeburn 641: $r->print(&endContentScreen());
1.329 droeschl 642: }
643:
1.567 raeburn 644: sub recurse_html {
645: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
646: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
647: my (%allfiles,%codebase);
648: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
649: if (keys(%allfiles)) {
650: foreach my $dependency (keys(%allfiles)) {
651: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
652: my ($depurl,$relfile,$newcontainer);
653: if ($dependency =~ m{^/}) {
654: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
655: $relfile = $1;
656: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
657: $newcontainer = $1;
658: next if ($replacehash->{$newcontainer});
659: }
660: $depurl = $dependency;
661: } else {
662: next;
663: }
664: } else {
665: $relfile = $dependency;
666: $depurl = $currurlpath;
1.630 raeburn 667: $depurl =~ s{[^/]+$}{};
1.567 raeburn 668: $depurl .= $dependency;
1.630 raeburn 669: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 670: }
671: next if ($relfile eq '');
672: my $newname = $replacehash->{$container};
673: $newname =~ s{[^/]+$}{};
674: $replacehash->{$newcontainer} = $newname.$relfile;
675: $deps->{$item}{$newcontainer} = 1;
676: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
677: my $depfile = &Apache::lonnet::filelocation('',$depurl);
678: my $type = $mm->checktype_filename($depfile);
679: if ($type eq 'text/html') {
680: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
681: }
682: }
683: }
684: }
685: return;
686: }
687:
1.329 droeschl 688: sub group_import {
1.598 raeburn 689: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 690: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
691: %removeparam,$importuploaded,$fixuperrors);
692: $allmaps = {};
1.329 droeschl 693: while (@files) {
694: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 695: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 696: && ($caller eq 'londocs')
697: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 698:
1.329 droeschl 699: my $errtext = '';
700: my $fatal = 0;
701: my $newmapstr = '<map>'."\n".
702: '<resource id="1" src="" type="start"></resource>'."\n".
703: '<link from="1" to="2" index="1"></link>'."\n".
704: '<resource id="2" src="" type="finish"></resource>'."\n".
705: '</map>';
706: $env{'form.output'}=$newmapstr;
707: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
708: 'output',$1.$2);
1.534 raeburn 709: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 710: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
711: $fatal = 2;
712: }
713: if ($fatal) {
714: return ($errtext,$fatal);
715: }
716: }
717: if ($url) {
1.626 raeburn 718: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 719: $url = $1;
720: my $marker = $2;
721: my $info = $3;
1.604 raeburn 722: my ($toolid,%toolhash,%toolsettings);
1.642 raeburn 723: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 724: my @toolinfo = split(/:/,$info);
725: if ($residx) {
1.604 raeburn 726: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 727: $toolid = $toolsettings{'id'};
728: } else {
1.604 raeburn 729: $toolid = shift(@toolinfo);
1.598 raeburn 730: }
731: $toolid =~ s/\D//g;
1.604 raeburn 732: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 733: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
734: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 735: foreach my $item (@extras) {
736: $toolhash{$item} = &unescape($toolhash{$item});
737: }
1.645 raeburn 738: if ($folder =~ /^supplemental/) {
1.648 raeburn 739: delete($toolhash{'gradable'});
740: } else {
741: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 742: }
1.598 raeburn 743: if (ref($ltitoolsref) eq 'HASH') {
744: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
1.643 raeburn 745: my @deleted;
1.598 raeburn 746: $toolhash{'id'} = $toolid;
1.628 raeburn 747: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
748: ($toolhash{'target'} eq 'window')) {
1.604 raeburn 749: if ($toolhash{'target'} eq 'window') {
750: foreach my $item ('width','height') {
751: $toolhash{$item} =~ s/^\s+//;
752: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 753: if ($toolhash{$item} =~ /\D/) {
754: delete($toolhash{$item});
755: if ($residx) {
756: if ($toolsettings{$item}) {
757: push(@deleted,$item);
758: }
759: }
760: }
1.604 raeburn 761: }
762: }
763: } elsif ($residx) {
764: $toolhash{'target'} = $toolsettings{'target'};
765: if ($toolhash{'target'} eq 'window') {
1.630 raeburn 766: foreach my $item ('width','height') {
1.624 raeburn 767: $toolhash{$item} = $toolsettings{$item};
768: }
1.604 raeburn 769: }
770: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
771: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
772: if ($toolhash{'target'} eq 'window') {
773: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
774: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
775: }
776: }
1.598 raeburn 777: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 778: foreach my $item ('width','height','linktext','explanation') {
779: delete($toolhash{$item});
780: if ($residx) {
781: if ($toolsettings{$item}) {
782: push(@deleted,$item);
783: }
1.604 raeburn 784: }
785: }
1.628 raeburn 786: } elsif ($toolhash{'target'} eq 'tab') {
787: foreach my $item ('width','height') {
788: delete($toolhash{$item});
789: if ($residx) {
790: if ($toolsettings{$item}) {
791: push(@deleted,$item);
792: }
793: }
794: }
1.604 raeburn 795: }
796: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 797: foreach my $item ('label','title','linktext','explanation') {
798: my $crsitem;
799: if (($item eq 'label') || ($item eq 'title')) {
800: $crsitem = 'crs'.$item;
801: } else {
802: $crsitem = $item;
803: }
1.604 raeburn 804: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 805: $toolhash{$crsitem} =~ s/^\s+//;
806: $toolhash{$crsitem} =~ s/\s+$//;
807: if ($toolhash{$crsitem} eq '') {
808: delete($toolhash{$crsitem});
1.604 raeburn 809: }
810: } else {
1.624 raeburn 811: delete($toolhash{$crsitem});
1.604 raeburn 812: }
1.624 raeburn 813: if (($residx) && (exists($toolsettings{$crsitem}))) {
814: unless (exists($toolhash{$crsitem})) {
815: push(@deleted,$crsitem);
1.604 raeburn 816: }
817: }
1.598 raeburn 818: }
819: }
1.643 raeburn 820: if ($toolhash{'passback'}) {
821: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
822: $toolhash{'gradesecret'} = $gradesecret;
823: $toolhash{'gradesecretdate'} = time;
824: }
825: if ($toolhash{'roster'}) {
826: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
827: $toolhash{'rostersecret'} = $rostersecret;
828: $toolhash{'rostersecretdate'} = time;
829: }
1.645 raeburn 830: my $changegradable;
831: if (($residx) && ($folder =~ /^default/)) {
1.648 raeburn 832: if ($toolsettings{'gradable'}) {
833: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 834: push(@deleted,'gradable');
835: $changegradable = 1;
836: }
1.648 raeburn 837: } elsif ($toolhash{'gradable'}) {
838: $changegradable = 1;
839: }
840: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 841: $changegradable = 1;
1.648 raeburn 842: if ($toolsettings{'gradable'}) {
843: $toolhash{'gradable'} = 1;
844: }
1.645 raeburn 845: }
846: }
1.598 raeburn 847: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 848: if ($putres eq 'ok') {
849: if (@deleted) {
850: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.645 raeburn 851: }
852: if (($changegradable) && ($folder =~ /^default/)) {
853: my $val;
854: if ($toolhash{'gradable'}) {
855: $val = 'yes';
856: } else {
857: $val = 'no';
858: }
859: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
860: 'string_yesno');
861: &remember_parms($residx,'gradable','set',$val);
862: }
863: } else {
864: return (&mt('Failed to save update to external tool.'),1);
1.604 raeburn 865: }
1.598 raeburn 866: }
867: }
868: }
1.529 raeburn 869: if (($caller eq 'londocs') &&
870: ($folder =~ /^default/)) {
1.534 raeburn 871: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 872: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
873: my $cid = $coursedom.'_'.$coursenum;
874: $allmaps =
875: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
876: $chome,$cid);
877: $donechk = 1;
878: }
879: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 880: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
881: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 882: $importuploaded = 1;
883: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
884: next if ($allmaps->{$url});
885: }
886: }
1.344 bisitz 887: if (!$residx
1.329 droeschl 888: || defined($LONCAPA::map::zombies[$residx])) {
889: $residx = &LONCAPA::map::getresidx($url,$residx);
890: push(@LONCAPA::map::order, $residx);
891: }
892: my $ext = 'false';
893: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 894: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
895: my $filepath = $1;
1.675 raeburn 896: my $fname;
897: if ($name eq '') {
898: $name = &mt('Web Page');
1.534 raeburn 899: $fname = 'web';
900: } else {
1.675 raeburn 901: $fname = $name;
902: $fname=&Apache::lonnet::clean_filename($fname);
903: if ($fname eq '') {
904: $fname = 'web';
905: } elsif (length($fname) > 15) {
906: $fname = substr($fname,0,14);
907: }
1.534 raeburn 908: }
1.675 raeburn 909: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 910: my $initialtext = &mt('Replace with your own content.');
911: my $newhtml = <<END;
1.545 raeburn 912: <html>
1.534 raeburn 913: <head>
1.675 raeburn 914: <title>$title</title>
1.534 raeburn 915: </head>
916: <body bgcolor="#ffffff">
917: $initialtext
918: </body>
919: </html>
920: END
921: $env{'form.output'}=$newhtml;
1.630 raeburn 922: my $result =
1.534 raeburn 923: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
924: 'output',
925: "$filepath/$residx/$fname.html");
926: if ($result =~ m{^/uploaded/}) {
927: $url = $result;
928: if ($filepath =~ /^supplemental/) {
929: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
930: $env{'user.domain'}.'___&&&___'.$name;
931: }
932: } else {
933: return (&mt('Failed to save new web page.'),1);
934: }
935: }
1.675 raeburn 936: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 937: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 938: $LONCAPA::map::resources[$residx] =
1.329 droeschl 939: join(':', ($name, $url, $ext, 'normal', 'res'));
940: }
941: }
1.529 raeburn 942: if ($importuploaded) {
943: my %import_errors;
944: my %updated = (
945: removefrommap => \%removefrommap,
946: removeparam => \%removeparam,
947: );
1.533 raeburn 948: my ($result,$msgsarray,$lockerror) =
949: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 950: if (keys(%import_errors) > 0) {
1.530 raeburn 951: $fixuperrors =
1.529 raeburn 952: '<p span class="LC_warning">'."\n".
953: &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".
954: '<ul>'."\n";
955: foreach my $key (sort(keys(%import_errors))) {
956: $fixuperrors .= '<li>'.$key.'</li>'."\n";
957: }
958: $fixuperrors .= '</ul></p>'."\n";
959: }
1.533 raeburn 960: if (ref($msgsarray) eq 'ARRAY') {
961: if (@{$msgsarray} > 0) {
962: $fixuperrors .= '<p class="LC_info">'.
963: join('<br />',@{$msgsarray}).
964: '</p>';
965: }
966: }
967: if ($lockerror) {
968: $fixuperrors .= '<p class="LC_error">'.
969: $lockerror.
970: '</p>';
971: }
1.529 raeburn 972: }
973: my ($errtext,$fatal) =
974: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 975: unless ($fatal) {
976: if ($folder =~ /^supplemental/) {
1.561 raeburn 977: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
978: $folder.'.'.$container);
1.557 raeburn 979: }
980: }
1.529 raeburn 981: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 982: }
983:
984: sub log_docs {
1.494 raeburn 985: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 986: }
987:
988: {
989: my @oldresources=();
990: my @oldorder=();
991: my $parmidx;
992: my %parmaction=();
993: my %parmvalue=();
994: my $changedflag;
995:
996: sub snapshotbefore {
997: @oldresources=@LONCAPA::map::resources;
998: @oldorder=@LONCAPA::map::order;
999: $parmidx=undef;
1000: %parmaction=();
1001: %parmvalue=();
1002: $changedflag=0;
1003: }
1004:
1005: sub remember_parms {
1006: my ($idx,$parameter,$action,$value)=@_;
1007: $parmidx=$idx;
1008: $parmaction{$parameter}=$action;
1009: $parmvalue{$parameter}=$value;
1010: $changedflag=1;
1011: }
1012:
1013: sub log_differences {
1014: my ($plain)=@_;
1015: my %storehash=('folder' => $plain,
1016: 'currentfolder' => $env{'form.folder'});
1017: if ($parmidx) {
1018: $storehash{'parameter_res'}=$oldresources[$parmidx];
1019: foreach my $parm (keys(%parmaction)) {
1020: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1021: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1022: }
1023: }
1024: my $maxidx=$#oldresources;
1025: if ($#LONCAPA::map::resources>$#oldresources) {
1026: $maxidx=$#LONCAPA::map::resources;
1027: }
1028: for (my $idx=0; $idx<=$maxidx; $idx++) {
1029: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1030: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1031: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1032: $changedflag=1;
1033: }
1034: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1035: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1036: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1037: $changedflag=1;
1038: }
1039: }
1040: $storehash{'maxidx'}=$maxidx;
1041: if ($changedflag) { &log_docs(\%storehash); }
1042: }
1043: }
1044:
1045: sub docs_change_log {
1.611 raeburn 1046: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 1047: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 1048: my $navmap;
1.483 raeburn 1049: my $js = '<script type="text/javascript">'."\n".
1050: '// <![CDATA['."\n".
1051: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 1052: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 1053: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 1054: &history_tab_js()."\n".
1.484 raeburn 1055: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 1056: '// ]]>'."\n".
1057: '</script>'."\n";
1.484 raeburn 1058: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1059: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1060: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1061: my %orderhash;
1062: my $container='sequence';
1063: my $pathitem;
1.519 raeburn 1064: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1065: $container='page';
1066: }
1.519 raeburn 1067: my $folderpath=$env{'form.folderpath'};
1068: if ($folderpath eq '') {
1.617 raeburn 1069: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1070: }
1.617 raeburn 1071: undef($navmap);
1.519 raeburn 1072: $pathitem = '<input type="hidden" name="folderpath" value="'.
1073: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1074: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1075: my $jumpto = $readfile;
1076: $jumpto =~ s{^/}{};
1077: my $tid = 1;
1.489 raeburn 1078: if ($supplementalflag) {
1079: $tid = 2;
1080: }
1.630 raeburn 1081: my ($breadcrumbtrail) =
1.509 raeburn 1082: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1083: $r->print($breadcrumbtrail.
1084: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1085: $readfile));
1.329 droeschl 1086: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1087: $env{'course.'.$env{'request.course.id'}.'.domain'},
1088: $env{'course.'.$env{'request.course.id'}.'.num'});
1089:
1090: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1091:
1092: my %saveable_parameters = ('show' => 'scalar',);
1093: &Apache::loncommon::store_course_settings('docs_log',
1094: \%saveable_parameters);
1095: &Apache::loncommon::restore_course_settings('docs_log',
1096: \%saveable_parameters);
1097: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1098: # FIXME: internationalization seems wrong here
1.329 droeschl 1099: my %lt=('hiddenresource' => 'Resources hidden',
1100: 'encrypturl' => 'URL hidden',
1101: 'randompick' => 'Randomly pick',
1102: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1103: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1104: 'set' => 'set to',
1105: 'del' => 'deleted');
1.484 raeburn 1106: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1107: $pathitem."\n".
1108: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1109: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1110: $r->print('<div class="LC_left_float">'.
1111: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1112: &makedocslogform($filter,1).
1113: '</fieldset></div><br clear="all" />');
1.329 droeschl 1114: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1115: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1116: &mt('After').'</th>'.
1117: &Apache::loncommon::end_data_table_header_row());
1118: my $shown=0;
1119: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1120: if ($env{'form.displayfilter'} eq 'currentfolder') {
1121: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1122: }
1123: my @changes=keys(%{$docslog{$id}{'logentry'}});
1124: if ($env{'form.displayfilter'} eq 'containing') {
1125: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1126: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1127: foreach my $key (@changes) {
1128: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1129: }
1.344 bisitz 1130: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1131: }
1132: my $count = 0;
1133: my $time =
1134: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1135: my $plainname =
1136: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1137: $docslog{$id}{'exe_udom'});
1138: my $about_me_link =
1139: &Apache::loncommon::aboutmewrapper($plainname,
1140: $docslog{$id}{'exe_uname'},
1141: $docslog{$id}{'exe_udom'});
1142: my $send_msg_link='';
1143: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1144: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1145: $send_msg_link ='<br />'.
1146: &Apache::loncommon::messagewrapper(&mt('Send message'),
1147: $docslog{$id}{'exe_uname'},
1148: $docslog{$id}{'exe_udom'});
1149: }
1150: $r->print(&Apache::loncommon::start_data_table_row());
1151: $r->print('<td>'.$time.'</td>
1152: <td>'.$about_me_link.
1153: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1154: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1155: $send_msg_link.'</td><td>'.
1156: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1157: my $is_supp = 0;
1158: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1159: $is_supp = 1;
1160: }
1.329 droeschl 1161: # Before
1162: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1163: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1164: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1165: if ($oldname ne $newname) {
1.488 raeburn 1166: my $shown = &LONCAPA::map::qtescape($oldname);
1167: if ($is_supp) {
1168: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1169: }
1170: $r->print($shown);
1.329 droeschl 1171: }
1172: }
1173: $r->print('<ul>');
1174: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1175: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1176: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1177: if ($is_supp) {
1178: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1179: }
1180: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1181: }
1182: }
1183: $r->print('</ul>');
1184: # After
1185: $r->print('</td><td>');
1186:
1187: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1188: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1189: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1190: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1191: my $shown = &LONCAPA::map::qtescape($newname);
1192: if ($is_supp) {
1193: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1194: }
1195: $r->print($shown);
1.329 droeschl 1196: }
1.364 bisitz 1197: }
1.329 droeschl 1198: $r->print('<ul>');
1199: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1200: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1201: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1202: if ($is_supp) {
1203: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1204: }
1205: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1206: }
1207: }
1208: $r->print('</ul>');
1209: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1.693 raeburn 1210: my ($title,$url) = split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'},3);
1211: if ($title eq '') {
1212: ($title) = ($url =~ m{/([^/]+)$});
1.695 ! raeburn 1213: } elsif ($is_supp) {
! 1214: $title = &Apache::loncommon::parse_supplemental_title($title);
1.693 raeburn 1215: }
1216: $r->print(&LONCAPA::map::qtescape($title).':<ul>');
1.645 raeburn 1217: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1218: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1219: # FIXME: internationalization seems wrong here
1.329 droeschl 1220: $r->print('<li>'.
1221: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1222: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1223: .'</li>');
1224: }
1225: }
1226: $r->print('</ul>');
1227: }
1228: # End
1229: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1230: $shown++;
1231: if (!($env{'form.show'} eq &mt('all')
1232: || $shown<=$env{'form.show'})) { last; }
1233: }
1.484 raeburn 1234: $r->print(&Apache::loncommon::end_data_table()."\n".
1235: &makesimpleeditform($pathitem)."\n".
1236: '</div></div>');
1237: $r->print(&endContentScreen());
1.329 droeschl 1238: }
1239:
1240: sub update_paste_buffer {
1.492 raeburn 1241: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1242: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1243: if ($env{'form.multiremove'}) {
1244: $env{'form.multiremove'} =~ s/,$//;
1245: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1246: }
1247: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1248: if ($env{'form.multicut'}) {
1249: $env{'form.multicut'} =~ s/,$//;
1250: foreach my $item (split(/,/,$env{'form.multicut'})) {
1251: unless ($removals{$item}) {
1252: $cuts{$item} = 1;
1253: push(@possibles,$item.':cut');
1254: }
1255: }
1256: }
1257: if ($env{'form.multicopy'}) {
1258: $env{'form.multicopy'} =~ s/,$//;
1259: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1260: unless ($removals{$item} || $cuts{$item}) {
1261: push(@possibles,$item.':copy');
1262: }
1263: }
1264: }
1265: } elsif ($env{'form.markcopy'}) {
1266: @possibles = split(/,/,$env{'form.markcopy'});
1267: }
1.329 droeschl 1268:
1.538 raeburn 1269: return if (@possibles == 0);
1.329 droeschl 1270: return if (!defined($env{'form.copyfolder'}));
1271:
1272: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1273: $env{'form.copyfolder'});
1.538 raeburn 1274: return if ($fatal);
1275:
1276: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1277:
1.538 raeburn 1278: # Retrieve current paste buffer suffixes.
1279: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1280: my (%pasteurls,@newpaste);
1281:
1282: # Construct identifiers for current contents of user's paste buffer
1283: if (@currpaste) {
1284: foreach my $suffix (@currpaste) {
1.667 raeburn 1285: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1286: my $url = $env{'docs.markedcopy_url_'.$suffix};
1287: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1288: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1289: ($url ne '')) {
1290: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1291: $pasteurls{$cid.'_'.$mapidx} = 1;
1292: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1293: $pasteurls{$url} = 1;
1294: } else {
1.669 raeburn 1295: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1296: }
1297: }
1.538 raeburn 1298: }
1299: }
1300:
1301: # Mark items for copying (skip any items already in user's paste buffer)
1302: my %addtoenv;
1.597 raeburn 1303:
1304: my @pathitems = split(/\&/,$env{'form.folderpath'});
1305: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1306: my $ispage = $folderconf[5];
1.597 raeburn 1307:
1.538 raeburn 1308: foreach my $item (@possibles) {
1309: my ($orderidx,$cmd) = split(/:/,$item);
1310: next if ($orderidx =~ /\D/);
1311: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1312: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1313: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1314: my %denied = &action_restrictions($coursenum,$coursedom,
1315: &LONCAPA::map::qtescape($url),
1316: $env{'form.folderpath'},\%curr_groups);
1317: next if ($denied{'copy'});
1318: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1319: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1320: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1321: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1322: next if (exists($pasteurls{$url}));
1323: } else {
1324: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1325: }
1.538 raeburn 1326: my ($suffix,$errortxt,$locknotfreed) =
1327: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1328: if ($suffix ne '') {
1329: push(@newpaste,$suffix);
1330: } else {
1331: if ($locknotfreed) {
1332: return $locknotfreed;
1333: }
1.538 raeburn 1334: }
1335: if (&is_supplemental_title($title)) {
1336: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1337: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1338: }
1.329 droeschl 1339:
1.538 raeburn 1340: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1341: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1342: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1343: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1344: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1345: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1346: my $prefix = $1;
1347: my $subdir =$2;
1348: if ($subdir eq '') {
1349: $subdir = $prefix;
1.492 raeburn 1350: }
1.538 raeburn 1351: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1352: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1353: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1354: if (ref($hierarchy{$url}) eq 'HASH') {
1355: my ($nested,$nestednames);
1356: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1357: $nested =~ s/\&$//;
1358: $nestednames =~ s/\Q___&&&___\E$//;
1359: if ($nested ne '') {
1360: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1361: }
1362: if ($nestednames ne '') {
1363: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1364: }
1.492 raeburn 1365: }
1366: }
1.591 raeburn 1367: if ($locknotfreed) {
1368: $output = $locknotfreed;
1369: last;
1370: }
1.492 raeburn 1371: }
1.538 raeburn 1372: if (@newpaste) {
1373: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1374: }
1.492 raeburn 1375: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1376: delete($env{'form.markcopy'});
1.591 raeburn 1377: return $output;
1.329 droeschl 1378: }
1379:
1.492 raeburn 1380: sub recurse_uploaded_maps {
1381: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1382: if (ref($hierarchy->{$url}) eq 'HASH') {
1383: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1384: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1385: my (@uploaded,@names,%shorter);
1386: for (my $i=0; $i<@maps; $i++) {
1387: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1388: if ($inner ne '') {
1389: push(@uploaded,$inner);
1390: push(@names,&escape($titles[$i]));
1391: $shorter{$maps[$i]} = $inner;
1392: }
1393: }
1394: $$nestref .= "$dir:".join(',',@uploaded).'&';
1395: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1396: foreach my $map (@maps) {
1397: if ($shorter{$map} ne '') {
1398: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1399: }
1400: }
1401: }
1402: return;
1403: }
1404:
1.329 droeschl 1405: sub print_paste_buffer {
1.492 raeburn 1406: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1407: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1408:
1.538 raeburn 1409: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1410: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1411: }
1412:
1.538 raeburn 1413: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1414: my ($pasteitems,@pasteable);
1.575 raeburn 1415: my $clipboardcount = 0;
1.488 raeburn 1416:
1.538 raeburn 1417: # Construct identifiers for current contents of user's paste buffer
1418: foreach my $suffix (@currpaste) {
1419: next if ($suffix =~ /\D/);
1420: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1421: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1422: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1423: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1424: ($url ne '')) {
1.575 raeburn 1425: $clipboardcount ++;
1.538 raeburn 1426: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1427: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1428: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1429: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1430: $is_external = 1;
1.626 raeburn 1431: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1432: $is_exttool = 1;
1.538 raeburn 1433: }
1434: if ($folder =~ /^supplemental/) {
1435: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1436: unless ($canpaste) {
1437: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1438: }
1439: } else {
1440: $canpaste = 1;
1441: }
1442: if ($canpaste) {
1443: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1444: my $srcdom = $1;
1445: my $srcnum = $2;
1446: my $rem = $3;
1447: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1448: $othercourse = 1;
1449: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1450: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1451: } else {
1452: $canpaste = 0;
1453: $nopaste = &mt('Paste from another course unavailable.');
1454: }
1455: }
1456: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1457: my $prefix = $1;
1458: $parent = $2;
1459: if ($folder !~ /^\Q$prefix\E/) {
1460: $areachange = 1;
1461: }
1462: $is_uploaded_map = 1;
1.492 raeburn 1463: }
1.597 raeburn 1464: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1465: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1466: if ($cid ne $env{'request.course.id'}) {
1467: my ($srcdom,$srcnum) = split(/_/,$cid);
1468: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1469: if (($is_exttool) && ($srcdom ne $coursedom)) {
1470: $canpaste = 0;
1471: $nopaste = &mt('Paste from another domain unavailable.');
1472: } else {
1473: $othercrs = '<br />'.&mt('(from another course)');
1474: }
1.596 raeburn 1475: } else {
1476: $canpaste = 0;
1477: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1478: }
1.596 raeburn 1479: }
1.492 raeburn 1480: }
1.596 raeburn 1481: if ($canpaste) {
1482: push(@pasteable,$suffix);
1.629 raeburn 1483: }
1.538 raeburn 1484: }
1485: my $buffer;
1.627 raeburn 1486: if ($is_external) {
1.538 raeburn 1487: $buffer = &mt('External Resource').': '.
1488: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1489: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1490: } elsif ($is_exttool) {
1491: $buffer = &mt('External Tool').': '.
1492: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1493: } else {
1494: my $icon = &Apache::loncommon::icon($extension);
1495: if ($extension eq 'sequence' &&
1496: $url =~ m{/default_\d+\.sequence$}x) {
1497: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1498: $icon .= '/navmap.folder.closed.gif';
1499: }
1.589 raeburn 1500: my $title = $env{'docs.markedcopy_title_'.$suffix};
1501: if ($title eq '') {
1502: ($title) = ($url =~ m{/([^/]+)$});
1503: }
1.538 raeburn 1504: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1505: ': '.
1506: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1507: &LONCAPA::map::qtescape($title));
1.538 raeburn 1508: }
1509: $pasteitems .= '<div class="LC_left_float">';
1510: my ($options,$onclick);
1511: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1512: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1513: if (($is_uploaded_map) ||
1514: ($url =~ /(bulletinboard|smppg)$/) ||
1515: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1516: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1517: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1518: }
1519: }
1520: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1521: if ($nopaste) {
1.681 raeburn 1522: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1523: } else {
1524: if ($othercrs) {
1525: $pasteitems .= $othercrs;
1526: }
1527: if ($options) {
1528: $pasteitems .= $options;
1.492 raeburn 1529: }
1530: }
1.538 raeburn 1531: $pasteitems .= '</div>';
1532: }
1533: }
1534: if ($pasteitems eq '') {
1535: &Apache::lonnet::delenv('docs.markedcopies');
1536: }
1537: my ($pasteform,$form_start,$buttons,$form_end);
1538: if ($pasteitems) {
1539: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1540: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1541: if (@pasteable) {
1.575 raeburn 1542: my $value = &mt('Paste to current folder');
1543: if ($container eq 'page') {
1544: $value = &mt('Paste to current page');
1545: }
1546: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1547: }
1548: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1549: if ($clipboardcount > 1) {
1550: $buttons .=
1551: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1552: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1553: (' 'x2).
1554: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1555: (' 'x2);
1.492 raeburn 1556: }
1.575 raeburn 1557: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1558: '</form>';
1.538 raeburn 1559: } else {
1560: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1561: }
1.538 raeburn 1562: $r->print($form_start
1563: .'<fieldset>'
1564: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1565: .$pasteitems
1566: .'</fieldset>'
1567: .$form_end);
1568: }
1569:
1570: sub paste_options {
1571: my ($suffix,$is_uploaded_map,$parent) = @_;
1572: my ($copytext,$movetext);
1573: if ($is_uploaded_map) {
1574: $copytext = &mt('Copy to new folder');
1575: $movetext = &mt('Move old');
1576: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1577: $copytext = &mt('Copy to new board');
1578: $movetext = &mt('Move (not posts)');
1579: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1580: $copytext = &mt('Copy to new page');
1581: $movetext = &mt('Move');
1.533 raeburn 1582: } else {
1.538 raeburn 1583: $copytext = &mt('Copy to new file');
1584: $movetext = &mt('Move');
1585: }
1586: my $output = '<br />'.
1587: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1588: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1589: '<label>'.
1590: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1591: $copytext.'</label></span>'.(' 'x2).' '.
1592: '<span class="LC_nobreak"><label>'.
1593: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1594: $movetext.'</label></span>';
1595: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1596: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1597: '</legend><table border="0">';
1598: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1599: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1600: my $lastdir = $parent;
1601: my %depths = (
1602: $lastdir => 0,
1603: );
1604: my (%display,%deps);
1605: for (my $i=0; $i<@pastemaps; $i++) {
1606: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1607: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1608: my @subfolders = split(/,/,$subfolderstr);
1609: $deps{$lastdir} = \@subfolders;
1610: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1611: my $depth = $depths{$lastdir} + 1;
1612: my $offset = int($depth * 4);
1613: my $indent = (' ' x $offset);
1614: for (my $j=0; $j<@subfolders; $j++) {
1615: $depths{$subfolders[$j]} = $depth;
1616: $display{$subfolders[$j]} =
1617: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1618: '<td><label>'.
1619: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1620: '<label>'.
1621: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1622: &mt('Move old').'</label>'.
1623: '</td></tr>';
1624: }
1.492 raeburn 1625: }
1.538 raeburn 1626: &recurse_print(\$output,$parent,\%deps,\%display);
1627: $output .= '</table></fieldset>';
1.329 droeschl 1628: }
1.538 raeburn 1629: $output .= '</div>';
1630: return $output;
1.488 raeburn 1631: }
1632:
1.492 raeburn 1633: sub recurse_print {
1.538 raeburn 1634: my ($outputref,$dir,$deps,$display) = @_;
1635: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1636: if (ref($deps->{$dir}) eq 'ARRAY') {
1637: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1638: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1639: }
1640: }
1641: }
1642:
1.488 raeburn 1643: sub supp_pasteable {
1644: my ($url) = @_;
1645: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1646: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1647: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1648: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1649: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1650: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1651: return 1;
1652: }
1653: return;
1.329 droeschl 1654: }
1655:
1.492 raeburn 1656: sub paste_popup_js {
1.594 damieng 1657: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1658: show => 'Show Options',
1659: hide => 'Hide Options',
1.594 damieng 1660: );
1661: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1662: none => 'No items selected from clipboard.',
1.492 raeburn 1663: );
1.594 damieng 1664: &html_escape(\%html_js_lt);
1665: &js_escape(\%html_js_lt);
1666: &js_escape(\%js_lt);
1.492 raeburn 1667: return <<"END";
1668:
1.538 raeburn 1669: function showPasteOptions(suffix) {
1670: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1671: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1672: return;
1673: }
1674:
1.538 raeburn 1675: function hidePasteOptions(suffix) {
1676: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1677: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1678: return;
1679: }
1680:
1681: function showOptions(caller,suffix) {
1682: if (document.getElementById('pasteoptionstext_'+suffix)) {
1683: if (caller.checked) {
1.594 damieng 1684: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1685: } else {
1686: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1687: }
1688: if (document.getElementById('pasteoptions_'+suffix)) {
1689: document.getElementById('pasteoptions_'+suffix).style.display='none';
1690: }
1691: }
1.492 raeburn 1692: return;
1693: }
1694:
1.541 raeburn 1695: function validateClipboard() {
1696: var numchk = 0;
1697: if (document.pasteform.pasting.length > 1) {
1698: for (var i=0; i<document.pasteform.pasting.length; i++) {
1699: if (document.pasteform.pasting[i].checked) {
1700: numchk ++;
1701: }
1702: }
1703: } else {
1704: if (document.pasteform.pasting.type == 'checkbox') {
1705: if (document.pasteform.pasting.checked) {
1706: numchk ++;
1707: }
1708: }
1709: }
1710: if (numchk > 0) {
1711: return true;
1712: } else {
1.594 damieng 1713: alert("$js_lt{'none'}");
1.541 raeburn 1714: return false;
1715: }
1716: }
1717:
1.575 raeburn 1718: function checkClipboard() {
1719: if (document.pasteform.pasting.length > 1) {
1720: for (var i=0; i<document.pasteform.pasting.length; i++) {
1721: document.pasteform.pasting[i].checked = true;
1722: }
1723: }
1724: return;
1725: }
1726:
1727: function uncheckClipboard() {
1728: if (document.pasteform.pasting.length >1) {
1729: for (var i=0; i<document.pasteform.pasting.length; i++) {
1730: document.pasteform.pasting[i].checked = false;
1731: }
1732: }
1733: return;
1734: }
1735:
1.492 raeburn 1736: END
1737:
1738: }
1739:
1.329 droeschl 1740: sub do_paste_from_buffer {
1.492 raeburn 1741: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1742:
1.538 raeburn 1743: # Array of items in paste buffer
1744: my (@currpaste,%pastebuffer,%allerrors);
1745: @currpaste = split(/,/,$env{'docs.markedcopies'});
1746:
1.492 raeburn 1747: # Early out if paste buffer is empty
1.538 raeburn 1748: if (@currpaste == 0) {
1.492 raeburn 1749: return ();
1.538 raeburn 1750: }
1751: map { $pastebuffer{$_} = 1; } @currpaste;
1752:
1753: # Array of items selected items to paste
1754: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1755:
1756: # Early out if nothing selected to paste
1757: if (@reqpaste == 0) {
1758: return();
1759: }
1760: my @topaste;
1761: foreach my $suffix (@reqpaste) {
1762: next if ($suffix =~ /\D/);
1763: next unless (exists($pastebuffer{$suffix}));
1764: push(@topaste,$suffix);
1765: }
1766:
1767: # Early out if nothing available to paste
1768: if (@topaste == 0) {
1769: return();
1.329 droeschl 1770: }
1771:
1.627 raeburn 1772: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1773: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1774:
1775: foreach my $suffix (@topaste) {
1776: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1777: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1778: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1779: # Supplemental content may only include certain types of content
1780: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1781: if ($folder =~ /^supplemental/) {
1782: unless (&supp_pasteable($url)) {
1783: $notinsupp{$suffix} = 1;
1784: next;
1785: }
1.492 raeburn 1786: }
1.538 raeburn 1787: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1788: my $srcd = $1;
1789: my $srcn = $2;
1.492 raeburn 1790: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1791: # check for mdc privilege in the course from which the resource was pasted
1792: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1793: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1794: $notincrs{$suffix} = 1;
1795: next;
1796: }
1.491 raeburn 1797: }
1.538 raeburn 1798: $srcdom{$suffix} = $srcd;
1799: $srcnum{$suffix} = $srcn;
1.597 raeburn 1800: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1801: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1802: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1803: my ($srcd,$srcn) = split(/_/,$cid);
1804: # When paste buffer was populated using an active role in a different course
1805: # check for mdc privilege in the course from which the resource was pasted
1806: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1807: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1808: $notincrs{$suffix} = 1;
1809: next;
1810: }
1811: }
1.632 raeburn 1812: # When buffer was populated using an active role in a different course
1813: # disallow pasting of External Tool if course is in a different domain.
1814: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1815: $notindom{$suffix} = 1;
1816: next;
1817: }
1.596 raeburn 1818: $srcdom{$suffix} = $srcd;
1819: $srcnum{$suffix} = $srcn;
1.491 raeburn 1820: }
1.597 raeburn 1821: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1822: push(@dopaste,$suffix);
1823: if ($url=~/\.(page|sequence)$/) {
1824: $is_map{$suffix} = 1;
1825: }
1826: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1827: my $oldprefix = $1;
1.492 raeburn 1828: # When pasting content from Main Content to Supplemental Content and vice versa
1829: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1830: # a folder/page or a document).
1.538 raeburn 1831: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1832: $prefixchg{$suffix} = 'docstosupp';
1833: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1834: $prefixchg{$suffix} = 'supptodocs';
1835: }
1.491 raeburn 1836:
1.492 raeburn 1837: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1838: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1839: my @nested;
1840: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1841: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1842: my @deps = map { /\d+:([\d,]+$)/ } @items;
1843: foreach my $dep (@deps) {
1844: if ($dep =~ /,/) {
1845: push(@nested,split(/,/,$dep));
1846: } else {
1847: push(@nested,$dep);
1848: }
1.492 raeburn 1849: }
1.538 raeburn 1850: foreach my $item (@nested) {
1851: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1852: push(@{$marktomove{$suffix}},$type.'_'.$item);
1853: }
1.492 raeburn 1854: }
1855: }
1.488 raeburn 1856: }
1857: }
1858:
1.538 raeburn 1859: # Early out if nothing available to paste
1860: if (@dopaste == 0) {
1861: return ();
1862: }
1863:
1864: # Populate message hash and hashes used for main content <=> supplemental content
1865: # changes
1866:
1867: %msgs = &Apache::lonlocal::texthash (
1868: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1869: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1870: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538 raeburn 1871: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1872: );
1873:
1874: %before = (
1875: docstosupp => {
1876: map => 'default',
1877: doc => 'docs',
1878: },
1879: supptodocs => {
1880: map => 'supplemental',
1881: doc => 'supplemental',
1882: },
1883: );
1884:
1885: %after = (
1886: docstosupp => {
1887: map => 'supplemental',
1888: doc => 'supplemental'
1889: },
1890: supptodocs => {
1891: map => 'default',
1892: doc => 'docs',
1893: },
1894: );
1895:
1896: # Retrieve information about all course maps in main content area
1897:
1898: my $allmaps = {};
1.660 raeburn 1899: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538 raeburn 1900:
1901: # Loop over the items to paste
1902: foreach my $suffix (@dopaste) {
1.329 droeschl 1903: # Maps need to be copied first
1.538 raeburn 1904: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1905: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1906: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1907: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1908: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1909: }
1910: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1911: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1912: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1913: my $oldurl = $url;
1914: if ($is_map{$suffix}) {
1.491 raeburn 1915: # If pasting a map, check if map contains other maps
1.538 raeburn 1916: my (%hierarchy,%titles);
1.660 raeburn 1917: if (($folder =~ /^default/) && (!$donechk)) {
1918: $allmaps =
1919: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1920: $env{"course.$env{'request.course.id'}.home"},
1921: $env{'request.course.id'});
1922: $donechk = 1;
1923: }
1.627 raeburn 1924: &contained_map_check($url,$folder,$coursenum,$coursedom,
1925: \%removefrommap,\%removeparam,\%addedmaps,
1926: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1927: if ($url=~ m{^/uploaded/}) {
1928: my $newurl;
1929: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1930: ($newurl,my $error) =
1931: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1932: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1933: \$title,$allmaps,\%newurls);
1934: if ($error) {
1935: $allerrors{$suffix} = $error;
1936: next;
1937: }
1938: if ($newurl ne '') {
1939: if ($newurl ne $url) {
1940: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1941: $newsubdir{$url} = $1;
1942: }
1943: $mapchanges{$url} = 1;
1.492 raeburn 1944: }
1.538 raeburn 1945: }
1946: }
1947: if (($srcdom{$suffix} ne $coursedom) ||
1948: ($srcnum{$suffix} ne $coursenum) ||
1949: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1950: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1951: $coursedom,$coursenum,$srcdom{$suffix},
1952: $srcnum{$suffix},$allmaps,\%rewrites,
1953: \%retitles,\%copies,\%dbcopies,
1954: \%zombies,\%params,\%mapmoves,
1955: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1956: \%newurls,\%resdatacopy)) {
1.538 raeburn 1957: $mapmoves{$url} = 1;
1958: }
1959: $url = $newurl;
1960: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1961: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1962: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1963: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1964: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1965: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1966: }
1967: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1968: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1969: push(@toclear,$suffix);
1970: # if pasting published map (main content area only) check map not already in course
1971: if ($folder =~ /^default/) {
1972: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1973: $duplicate{$suffix} = 1;
1974: next;
1.492 raeburn 1975: }
1.491 raeburn 1976: }
1977: }
1.538 raeburn 1978: }
1.627 raeburn 1979: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1980: my $prefix = $1;
1.648 raeburn 1981: my $fromothercrs;
1.538 raeburn 1982: #need to copy the db contents to a new one, unless this is a move.
1983: my %info = (
1984: src => $url,
1985: cdom => $coursedom,
1986: cnum => $coursenum,
1.596 raeburn 1987: );
1.649 raeburn 1988: if ($prefix eq 'ext.tool') {
1.655 raeburn 1989: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 1990: $info{'delgradable'} = 1;
1991: }
1992: }
1.596 raeburn 1993: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1994: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1995: $fromothercrs = 1;
1996: $info{'cdom'} = $srcdom{$suffix};
1997: $info{'cnum'} = $srcnum{$suffix};
1998: }
1999: }
2000: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 2001: my (%lockerr,$msg);
1.538 raeburn 2002: my ($newurl,$result,$errtext) =
2003: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
2004: if ($result eq 'ok') {
2005: $url = $newurl;
2006: $title=&mt('Copy of').' '.$title;
2007: } else {
2008: if ($prefix eq 'smppg') {
2009: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2010: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2011: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2012: } elsif ($prefix eq 'ext.tool') {
2013: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2014: }
2015: $results{$suffix} = $result;
2016: $msgerrs{$suffix} = $msg;
2017: $lockerrs{$suffix} = $lockerr{$prefix};
2018: next;
2019: }
2020: if ($lockerr{$prefix}) {
2021: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2022: }
1.489 raeburn 2023: }
2024: }
1.538 raeburn 2025: $title = &LONCAPA::map::qtunescape($title);
2026: my $ext='false';
2027: if ($url=~m{^http(|s)://}) { $ext='true'; }
2028: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2029: if ($folder !~ /^supplemental/) {
2030: (undef,undef,$title) =
2031: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2032: }
2033: } else {
2034: if ($folder=~/^supplemental/) {
2035: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2036: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2037: }
1.533 raeburn 2038: }
1.491 raeburn 2039:
2040: # For uploaded files (excluding pages/sequences) path in copied file is changed
2041: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2042: # courses.
2043:
1.538 raeburn 2044: unless ($is_map{$suffix}) {
2045: my $newidx;
1.492 raeburn 2046: # Now insert the URL at the bottom
1.538 raeburn 2047: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2048: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2049: my $relpath = $1;
2050: if ($relpath ne '') {
2051: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2052: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2053: my $newprefix = $newloc;
2054: if ($newloc eq 'default') {
2055: $newprefix = 'docs';
2056: }
2057: if ($newdocsdir eq '') {
2058: $newdocsdir = 'default';
2059: }
1.630 raeburn 2060: if (($prefixchg{$suffix}) ||
2061: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2062: ($srcnum{$suffix} ne $coursenum) ||
2063: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2064: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2065: $url =
2066: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2067: &Apache::lonnet::getfile($oldurl));
2068: if ($url eq '/adm/notfound.html') {
2069: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2070: next;
2071: } else {
2072: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2073: $newsubpath =~ s{/+$}{/};
2074: $docmoves{$oldurl} = $newsubpath;
2075: }
1.491 raeburn 2076: }
2077: }
1.597 raeburn 2078: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2079: my $template = $1;
2080: if ($newidx) {
2081: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2082: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2083: }
1.649 raeburn 2084: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2085: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2086: my $marker = (split(m{/},$url))[4];
2087: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2088: my $val = 'no';
2089: if ($toolsettings{'gradable'}) {
2090: $val = 'yes';
2091: }
2092: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2093: 'string_yesno');
2094: &remember_parms($newidx,'gradable','set',$val);
2095: }
1.491 raeburn 2096: }
1.538 raeburn 2097: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2098: ':'.$ext.':normal:res';
2099: push(@LONCAPA::map::order,$newidx);
2100: # Store the result
2101: my ($errtext,$fatal) =
2102: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2103: if ($fatal) {
2104: $save_err .= $errtext;
2105: $allresult = 'fail';
2106: }
1.488 raeburn 2107: }
1.538 raeburn 2108:
1.597 raeburn 2109: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2110: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2111: unless ($allresult eq 'fail') {
2112: my %updated = (
2113: rewrites => \%rewrites,
2114: zombies => \%zombies,
2115: removefrommap => \%removefrommap,
2116: removeparam => \%removeparam,
2117: dbcopies => \%dbcopies,
1.597 raeburn 2118: resdatacopy => \%resdatacopy,
1.538 raeburn 2119: retitles => \%retitles,
2120: );
2121: my %info = (
2122: newsubdir => \%newsubdir,
2123: params => \%params,
2124: );
2125: if ($prefixchg{$suffix}) {
2126: $info{'before'} = $before{$prefixchg{$suffix}};
2127: $info{'after'} = $after{$prefixchg{$suffix}};
2128: }
2129: my %moves = (
2130: copies => \%copies,
2131: docmoves => \%docmoves,
2132: mapmoves => \%mapmoves,
2133: );
2134: (my $result,$msgs{$suffix},my $lockerror) =
2135: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2136: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2137: $url,'paste');
2138: $lockerrors .= $lockerror;
2139: if ($result eq 'ok') {
2140: if ($is_map{$suffix}) {
2141: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2142: $folder.'.'.$container);
2143: if ($fatal) {
2144: $allresult = 'failread';
2145: } else {
2146: if ($#LONCAPA::map::order<1) {
2147: my $idx=&LONCAPA::map::getresidx();
2148: if ($idx<=0) { $idx=1; }
2149: $LONCAPA::map::order[0]=$idx;
2150: $LONCAPA::map::resources[$idx]='';
2151: }
2152: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2153: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2154: ':'.$ext.':normal:res';
2155: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2156:
2157: # Store the result
1.538 raeburn 2158: my ($errtext,$fatal) =
2159: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2160: if ($fatal) {
2161: $save_err .= $errtext;
2162: $allresult = 'failstore';
2163: }
2164: }
2165: }
2166: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2167: push(@toclear,$suffix);
2168: }
2169: }
1.492 raeburn 2170: }
2171: }
1.538 raeburn 2172: &clear_from_buffer(\@toclear,\@currpaste);
2173: my $msgsarray;
2174: foreach my $suffix (keys(%msgs)) {
2175: if (ref($msgs{$suffix}) eq 'ARRAY') {
2176: $msgsarray .= join(',',@{$msgs{$suffix}});
2177: }
2178: }
2179: return ($allresult,$save_err,$msgsarray,$lockerrors);
2180: }
1.533 raeburn 2181:
1.538 raeburn 2182: sub do_buffer_empty {
2183: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2184: if (@currpaste == 0) {
2185: return &mt('Clipboard is already empty');
2186: }
2187: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2188: if (@toclear == 0) {
2189: return &mt('Nothing selected to clear from clipboard');
2190: }
2191: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2192: if ($numdel) {
2193: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2194: } else {
2195: return &mt('Clipboard unchanged');
1.492 raeburn 2196: }
1.538 raeburn 2197: return;
2198: }
2199:
2200: sub clear_from_buffer {
2201: my ($toclear,$currpaste) = @_;
2202: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2203: my %pastebuffer;
2204: map { $pastebuffer{$_} = 1; } @{$currpaste};
2205: my $numdel = 0;
2206: foreach my $suffix (@{$toclear}) {
2207: next if ($suffix =~ /\D/);
2208: next unless (exists($pastebuffer{$suffix}));
2209: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2210: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2211: delete($pastebuffer{$suffix});
2212: $numdel ++;
2213: }
2214: }
2215: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2216: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2217: return $numdel;
1.492 raeburn 2218: }
2219:
2220: sub get_newmap_url {
2221: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2222: $titleref,$allmaps,$newurls) = @_;
2223: my $newurl;
2224: if ($url=~ m{^/uploaded/}) {
2225: $$titleref=&mt('Copy of').' '.$$titleref;
2226: }
2227: my $now = time;
2228: my $suffix=$$.int(rand(100)).$now;
2229: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2230: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2231: my $path = $1;
2232: my $prefix = $2;
2233: my $ancestor = $3;
2234: if (length($ancestor) > 10) {
2235: $ancestor = substr($ancestor,-10,10);
2236: }
2237: my $newid;
2238: if ($prefixchg) {
2239: if ($folder =~ /^supplemental/) {
2240: $prefix =~ s/^default/supplemental/;
2241: } else {
2242: $prefix =~ s/^supplemental/default/;
2243: }
2244: }
2245: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2246: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2247: } else {
2248: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2249: }
2250: my $counter = 0;
2251: my $is_unique = &uniqueness_check($newurl);
2252: if ($folder =~ /^default/) {
2253: if ($allmaps->{$newurl}) {
2254: $is_unique = 0;
2255: }
2256: }
2257: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2258: $counter ++;
2259: $suffix ++;
2260: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2261: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2262: } else {
2263: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2264: }
2265: $is_unique = &uniqueness_check($newurl);
2266: }
2267: if ($is_unique) {
2268: $newurls->{$newurl} = 1;
2269: } else {
2270: if ($url=~/\.page$/) {
2271: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2272: } else {
2273: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2274: }
2275: }
1.329 droeschl 2276: }
1.492 raeburn 2277: return ($newurl);
1.329 droeschl 2278: }
2279:
1.488 raeburn 2280: sub dbcopy {
1.533 raeburn 2281: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2282: my ($url,$result,$errtext);
2283: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2284: $url = $dbref->{'src'};
1.627 raeburn 2285: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2286: my $prefix = $1;
1.627 raeburn 2287: if ($prefix eq 'ext.tool') {
2288: $prefix = 'exttool';
2289: }
1.533 raeburn 2290: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2291: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2292: my $db_name;
2293: my $marker = (split(m{/},$url))[4];
2294: $marker=~s/\D//g;
2295: if ($dbref->{'src'} =~ m{/smppg$}) {
2296: $db_name =
2297: &Apache::lonsimplepage::get_db_name($url,$marker,
2298: $dbref->{'cdom'},
2299: $dbref->{'cnum'});
1.627 raeburn 2300: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2301: $db_name = 'exttool_'.$marker;
1.533 raeburn 2302: } else {
2303: $db_name = 'bulletinpage_'.$marker;
2304: }
2305: my ($suffix,$freedlock,$error) =
2306: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2307: $coursedom,$coursenum,
2308: 'concat');
2309: if (!$suffix) {
2310: if ($prefix eq 'smppg') {
2311: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2312: } elsif ($prefix eq 'exttool') {
2313: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2314: } else {
1.565 bisitz 2315: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2316: }
2317: if ($error) {
2318: $errtext .= '<br />'.$error;
2319: }
2320: } else {
2321: #need to copy the db contents to a new one.
2322: my %contents=&Apache::lonnet::dump($db_name,
2323: $dbref->{'cdom'},
2324: $dbref->{'cnum'});
2325: if (exists($contents{'uploaded.photourl'})) {
2326: my $photo = $contents{'uploaded.photourl'};
2327: my ($subdir,$fname) =
2328: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2329: my $newphoto;
1.533 raeburn 2330: if ($fname ne '') {
2331: my $content = &Apache::lonnet::getfile($photo);
2332: unless ($content eq '-1') {
2333: $env{'form.'.$suffix.'.photourl'} = $content;
2334: $newphoto =
2335: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2336: delete($env{'form.'.$suffix.'.photourl'});
2337: }
2338: }
2339: if ($newphoto =~ m{^/uploaded/}) {
2340: $contents{'uploaded.photourl'} = $newphoto;
2341: }
2342: }
2343: $db_name =~ s{_\d*$ }{_$suffix}x;
1.649 raeburn 2344: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2345: delete($contents{'gradable'});
2346: }
1.533 raeburn 2347: $result=&Apache::lonnet::put($db_name,\%contents,
2348: $coursedom,$coursenum);
2349: if ($result eq 'ok') {
1.627 raeburn 2350: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2351: }
2352: }
2353: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2354: $lockerrorsref->{$prefix} =
1.533 raeburn 2355: '<div class="LC_error">'.
2356: &mt('There was a problem removing a lockfile.');
2357: if ($prefix eq 'smppg') {
1.560 raeburn 2358: $lockerrorsref->{$prefix} .=
1.559 raeburn 2359: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2360: } elsif ($prefix eq 'exttool') {
2361: $lockerrorsref->{$prefix} .=
2362: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2363: } else {
1.565 bisitz 2364: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2365: }
1.560 raeburn 2366: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2367: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2368: '</div>';
1.533 raeburn 2369: }
2370: }
2371: } elsif ($url =~ m{/syllabus$}) {
2372: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2373: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2374: if (($dbref->{'cdom'} ne $coursedom) ||
2375: ($dbref->{'cnum'} ne $coursenum)) {
2376: my %contents=&Apache::lonnet::dump('syllabus',
2377: $dbref->{'cdom'},
2378: $dbref->{'cnum'});
2379: $result=&Apache::lonnet::put('syllabus',\%contents,
2380: $coursedom,$coursenum);
2381: }
2382: }
1.488 raeburn 2383: }
2384: }
1.533 raeburn 2385: return ($url,$result,$errtext);
1.488 raeburn 2386: }
2387:
1.597 raeburn 2388: sub copy_templated_files {
2389: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2390: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2391: my $srccontainer = 'sequence';
2392: if ($srcwaspage) {
2393: $srccontainer = 'page';
2394: }
2395: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2396: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2397: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2398: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2399: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2400: $template.'.problem';
2401: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2402: if ($template eq 'simpleproblem') {
2403: $srcprefix .= '.0.';
2404: my $weightprefix = $newprefix;
2405: $newprefix .= '.0.';
2406: my @simpleprobqtypes = qw(radio option string essay numerical);
2407: my $qtype=$srcparms{$srcprefix.'questiontype'};
2408: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2409: my %newdata = (
2410: $newprefix.'questiontype' => $qtype,
2411: );
1.597 raeburn 2412: foreach my $type (@simpleprobqtypes) {
2413: if ($type eq $qtype) {
2414: $newdata{"$weightprefix.$type.weight"}=1;
2415: } else {
2416: $newdata{"$weightprefix.$type.weight"}=0;
2417: }
2418: }
2419: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2420: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2421: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2422: if ($qtype eq 'numerical') {
2423: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2424: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2425: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2426: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2427: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2428: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2429: unless (defined($maxfoils)) { $maxfoils=10; }
2430: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2431: if ($maxfoils<=0) { $maxfoils=10; }
2432: my $randomize=$srcparms{$srcprefix.'randomize'};
2433: unless (defined($randomize)) { $randomize='yes'; }
2434: unless ($randomize eq 'no') { $randomize='yes'; }
2435: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2436: $newdata{$newprefix.'randomize'} = $randomize;
2437: if ($qtype eq 'option') {
2438: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2439: }
2440: for (my $i=1; $i<=10; $i++) {
2441: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2442: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2443: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2444: }
2445:
2446: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2447: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2448: unless (defined($maxfoils)) { $maxfoils=10; }
2449: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2450: if ($maxfoils<=0) { $maxfoils=10; }
2451: my $randomize=$srcparms{$srcprefix.'randomize'};
2452: unless (defined($randomize)) { $randomize='yes'; }
2453: unless ($randomize eq 'no') { $randomize='yes'; }
2454: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2455: $newdata{$newprefix.'randomize'} = $randomize;
2456: if ($qtype eq 'option') {
2457: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2458: }
2459: for (my $i=1; $i<=10; $i++) {
2460: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2461: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2462: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2463: }
2464: } elsif ($qtype eq 'string') {
2465: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2466: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2467: }
2468: if (keys(%newdata)) {
2469: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2470: $coursenum);
2471: if ($putres eq 'ok') {
2472: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2473: }
2474: }
2475: }
2476: }
2477: }
2478:
1.329 droeschl 2479: sub uniqueness_check {
2480: my ($newurl) = @_;
2481: my $unique = 1;
2482: foreach my $res (@LONCAPA::map::order) {
2483: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2484: $url=&LONCAPA::map::qtescape($url);
2485: if ($newurl eq $url) {
2486: $unique = 0;
1.344 bisitz 2487: last;
1.329 droeschl 2488: }
2489: }
2490: return $unique;
2491: }
2492:
1.488 raeburn 2493: sub contained_map_check {
1.627 raeburn 2494: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2495: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2496: my $content = &Apache::lonnet::getfile($url);
2497: unless ($content eq '-1') {
2498: my $parser = HTML::TokeParser->new(\$content);
2499: $parser->attr_encoded(1);
2500: while (my $token = $parser->get_token) {
2501: next if ($token->[0] ne 'S');
2502: if ($token->[1] eq 'resource') {
2503: next if ($token->[2]->{'type'} eq 'zombie');
2504: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2505: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2506: my $srcdom = $1;
2507: unless ($srcdom eq $coursedom) {
2508: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2509: next;
2510: }
2511: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2512: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2513: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2514: next;
2515: }
2516: }
1.492 raeburn 2517: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2518: if ($1 eq 'uploaded') {
2519: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2520: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2521: } else {
1.492 raeburn 2522: if ($allmaps->{$ressrc}) {
1.529 raeburn 2523: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2524: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2525: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2526: } else {
2527: $addedmaps->{$ressrc} = [$url];
2528: }
1.488 raeburn 2529: }
1.627 raeburn 2530: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2531: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2532: }
1.492 raeburn 2533: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2534: if ($folder =~ /^supplemental/) {
1.492 raeburn 2535: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2536: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2537: } else {
2538: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2539: }
1.488 raeburn 2540: }
2541: }
2542: }
2543: }
2544: return;
2545: }
2546:
2547: sub url_paste_fixups {
1.533 raeburn 2548: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2549: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2550: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2551: my $checktitle;
2552: if (($prefixchg) &&
1.492 raeburn 2553: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2554: $checktitle = 1;
2555: }
1.492 raeburn 2556: my $skip;
2557: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2558: my $mapid = $1.$2;
2559: if ($tomove->{$mapid}) {
2560: $skip = 1;
2561: }
2562: }
1.491 raeburn 2563: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2564: return if ($file eq '-1');
2565: my $parser = HTML::TokeParser->new(\$file);
2566: $parser->attr_encoded(1);
1.491 raeburn 2567: my $changed = 0;
1.488 raeburn 2568: while (my $token = $parser->get_token) {
2569: next if ($token->[0] ne 'S');
2570: if ($token->[1] eq 'resource') {
2571: my $ressrc = $token->[2]->{'src'};
2572: next if ($ressrc eq '');
1.491 raeburn 2573: my $id = $token->[2]->{'id'};
1.492 raeburn 2574: my $title = $token->[2]->{'title'};
1.491 raeburn 2575: if ($checktitle) {
2576: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2577: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2578: }
2579: }
1.488 raeburn 2580: next if ($token->[2]->{'type'} eq 'external');
2581: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2582: next if ($skip);
1.532 raeburn 2583: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2584: $changed = 1;
2585: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2586: my $srcdom = $1;
2587: my $srcnum = $2;
1.488 raeburn 2588: my $rem = $3;
1.492 raeburn 2589: my $newurl;
2590: my $mapname;
2591: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2592: my $prefix = $1;
2593: $mapname = $prefix.$2;
2594: if ($tomove->{$mapname}) {
1.533 raeburn 2595: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2596: $srcdom,$srcnum,$allmaps,$rewrites,
2597: $retitles,$copies,$dbcopies,$zombies,
2598: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2599: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2600: next;
2601: } else {
2602: ($newurl,my $error) =
2603: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2604: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2605: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2606: $newsubdir->{$ressrc} = $1;
2607: }
2608: if ($error) {
2609: next;
2610: }
2611: }
2612: }
2613: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2614: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2615:
1.488 raeburn 2616: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2617: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2618: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2619: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2620: $cnum,$srcdom,$srcnum,$allmaps,
2621: $rewrites,$retitles,$copies,$dbcopies,
2622: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2623: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2624: $mapmoves->{$ressrc} = 1;
2625: }
2626: $changed = 1;
1.488 raeburn 2627: } else {
1.532 raeburn 2628: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2629: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2630: $changed = 1;
1.488 raeburn 2631: }
2632: }
1.649 raeburn 2633: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2634: next if ($skip);
1.492 raeburn 2635: my $srcdom = $1;
2636: my $srcnum = $2;
1.649 raeburn 2637: my $rem = $3;
2638: my ($is_exttool,$exttoolchg);
2639: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2640: $is_exttool = 1;
1.649 raeburn 2641: }
1.492 raeburn 2642: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2643: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2644: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2645: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2646: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2647: $changed = 1;
1.649 raeburn 2648: if ($is_exttool) {
2649: $exttoolchg = 1;
2650: }
2651: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2652: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2653: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2654: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2655: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2656: $changed = 1;
2657: $exttoolchg = 1;
2658: }
2659: if (($is_exttool) && ($prefixchg)) {
2660: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2661: if ($exttoolchg) {
2662: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2663: }
2664: }
1.533 raeburn 2665: }
2666: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2667: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2668: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2669: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2670: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2671: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2672: $changed = 1;
1.488 raeburn 2673: }
1.597 raeburn 2674: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2675: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2676: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2677: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2678: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2679: }
1.488 raeburn 2680: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2681: next if ($skip);
2682: my $srcdom = $1;
2683: my $srcnum = $2;
2684: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2685: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2686: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2687: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2688: $changed = 1;
1.488 raeburn 2689: }
2690: }
2691: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2692: next if ($skip);
1.488 raeburn 2693: my $to = $token->[2]->{'to'};
2694: if ($to ne '') {
2695: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2696: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2697: } else {
2698: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2699: }
2700: }
2701: }
2702: }
1.491 raeburn 2703: return $changed;
1.488 raeburn 2704: }
2705:
2706: sub apply_fixups {
1.529 raeburn 2707: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2708: $oldurl,$url,$caller) = @_;
2709: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2710: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2711: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2712: if (ref($updated) eq 'HASH') {
2713: if (ref($updated->{'rewrites'}) eq 'HASH') {
2714: %rewrites = %{$updated->{'rewrites'}};
2715: }
2716: if (ref($updated->{'zombies'}) eq 'HASH') {
2717: %zombies = %{$updated->{'zombies'}};
2718: }
2719: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2720: %removefrommap = %{$updated->{'removefrommap'}};
2721: }
2722: if (ref($updated->{'removeparam'}) eq 'HASH') {
2723: %removeparam = %{$updated->{'removeparam'}};
2724: }
2725: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2726: %dbcopies = %{$updated->{'dbcopies'}};
2727: }
2728: if (ref($updated->{'retitles'}) eq 'HASH') {
2729: %retitles = %{$updated->{'retitles'}};
2730: }
1.597 raeburn 2731: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2732: %resdatacopy = %{$updated->{'resdatacopy'}};
2733: }
1.529 raeburn 2734: }
2735: if (ref($info) eq 'HASH') {
2736: if (ref($info->{'newsubdir'}) eq 'HASH') {
2737: %newsubdir = %{$info->{'newsubdir'}};
2738: }
2739: if (ref($info->{'params'}) eq 'HASH') {
2740: %params = %{$info->{'params'}};
2741: }
2742: if (ref($info->{'before'}) eq 'HASH') {
2743: %before = %{$info->{'before'}};
2744: }
2745: if (ref($info->{'after'}) eq 'HASH') {
2746: %after = %{$info->{'after'}};
2747: }
2748: }
2749: if (ref($moves) eq 'HASH') {
2750: if (ref($moves->{'copies'}) eq 'HASH') {
2751: %copies = %{$moves->{'copies'}};
2752: }
2753: if (ref($moves->{'docmoves'}) eq 'HASH') {
2754: %docmoves = %{$moves->{'docmoves'}};
2755: }
2756: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2757: %mapmoves = %{$moves->{'mapmoves'}};
2758: }
2759: }
2760: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2761: my @allcopies;
1.529 raeburn 2762: if (exists($copies{$key})) {
2763: if (ref($copies{$key}) eq 'HASH') {
2764: my %added;
2765: foreach my $innerkey (keys(%{$copies{$key}})) {
2766: if (($innerkey ne '') && (!$added{$innerkey})) {
2767: push(@allcopies,$innerkey);
2768: $added{$innerkey} = 1;
2769: }
1.491 raeburn 2770: }
1.529 raeburn 2771: undef(%added);
1.491 raeburn 2772: }
2773: }
2774: if ($key eq $oldurl) {
1.529 raeburn 2775: if ((exists($docmoves{$key}))) {
1.532 raeburn 2776: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2777: push(@allcopies,$oldurl);
2778: }
2779: }
2780: }
2781: if (@allcopies > 0) {
2782: foreach my $item (@allcopies) {
1.492 raeburn 2783: my ($relpath,$oldsubdir,$fname) =
2784: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2785: if ($fname ne '') {
2786: my $content = &Apache::lonnet::getfile($item);
2787: unless ($content eq '-1') {
2788: my $storefn;
1.529 raeburn 2789: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2790: $storefn = $docmoves{$key};
1.491 raeburn 2791: } else {
2792: $storefn = $relpath;
2793: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2794: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2795: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2796: }
1.529 raeburn 2797: if ($newsubdir{$key}) {
1.532 raeburn 2798: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2799: }
2800: }
2801: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2802: my $copyurl =
2803: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2804: $storefn.$fname,$content);
2805: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2806: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2807: return &mt('Paste failed: an error occurred copying the file.');
2808: } elsif (ref($errors) eq 'HASH') {
2809: $errors->{$item} = 1;
1.489 raeburn 2810: }
2811: }
1.488 raeburn 2812: }
2813: }
1.491 raeburn 2814: }
2815: }
2816: }
1.529 raeburn 2817: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2818: my $storefn=$key;
2819: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2820: if ($prefixchg && $before{'map'} && $after{'map'}) {
2821: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2822: }
1.529 raeburn 2823: if ($newsubdir{$key}) {
2824: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2825: }
1.491 raeburn 2826: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 2827: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2828: ($after{'map'} eq 'default') &&
2829: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2830: $mapcontent = '<map>'."\n".
2831: '<resource id="1" src="" type="start" />'."\n".
2832: '<link from="1" to="2" index="1" />'."\n".
2833: '<resource id="2" src="" type="finish" />'."\n".
2834: '</map>';
2835: }
1.491 raeburn 2836: if ($mapcontent eq '-1') {
2837: if (ref($errors) eq 'HASH') {
2838: $errors->{$key} = 1;
2839: }
2840: } else {
2841: my $newmap =
2842: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2843: $mapcontent);
2844: if ($newmap eq '/adm/notfound.html') {
2845: if (ref($errors) eq 'HASH') {
2846: $errors->{$key} = 1;
1.489 raeburn 2847: }
1.488 raeburn 2848: }
2849: }
2850: }
1.491 raeburn 2851: my %updates;
2852: if ($is_map) {
1.529 raeburn 2853: if (ref($updated) eq 'HASH') {
2854: foreach my $type (keys(%{$updated})) {
2855: if (ref($updated->{$type}) eq 'HASH') {
2856: foreach my $key (keys(%{$updated->{$type}})) {
2857: $updates{$key} = 1;
2858: }
2859: }
2860: }
1.491 raeburn 2861: }
2862: foreach my $key (keys(%updates)) {
1.492 raeburn 2863: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2864: if (ref($rewrites{$key}) eq 'HASH') {
2865: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2866: }
1.529 raeburn 2867: if (ref($retitles{$key}) eq 'HASH') {
2868: %toretitle = %{$retitles{$key}};
1.491 raeburn 2869: }
1.529 raeburn 2870: if (ref($removefrommap{$key}) eq 'HASH') {
2871: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2872: }
1.529 raeburn 2873: if (ref($removeparam{$key}) eq 'HASH') {
2874: %remparam = %{$removeparam{$key}};
1.492 raeburn 2875: }
1.529 raeburn 2876: if (ref($zombies{$key}) eq 'HASH') {
2877: %zombie = %{$zombies{$key}};
1.491 raeburn 2878: }
1.529 raeburn 2879: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2880: foreach my $idx (keys(%{$dbcopies{$key}})) {
2881: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2882: my ($newurl,$result,$errtext) =
2883: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2884: if ($result eq 'ok') {
2885: $newdb{$idx} = $newurl;
2886: } elsif (ref($errors) eq 'HASH') {
2887: $errors->{$key} = 1;
2888: }
2889: push(@msgs,$errtext);
2890: }
1.491 raeburn 2891: }
2892: }
1.597 raeburn 2893: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 2894: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2895: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2896: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2897: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2898: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2899: my $template = $1;
2900: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2901: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2902: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2903: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 2904: unless ($gotnewmapname) {
2905: ($newmapname) = ($key =~ m{/([^/]+)$});
2906: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2907: if ($newsubdir{$key}) {
2908: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2909: }
2910: $gotnewmapname = 1;
2911: }
1.597 raeburn 2912: my $srcmapinfo = $srcfolder.':'.$idx;
2913: if ($srccontainer eq 'page') {
2914: $srcmapinfo .= ':1';
2915: }
2916: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2917: $cnum,$template,$idx,$newmapname);
2918: }
2919: }
2920: }
2921: }
2922: }
1.529 raeburn 2923: if (ref($params{$key}) eq 'HASH') {
2924: %currparam = %{$params{$key}};
1.492 raeburn 2925: }
2926: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2927: if ($fatal) {
1.533 raeburn 2928: return ($errtext);
1.492 raeburn 2929: }
2930: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2931: if (defined($LONCAPA::map::zombies[$i])) {
2932: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2933: if ($zombie{$i} eq $src) {
1.492 raeburn 2934: undef($LONCAPA::map::zombies[$i]);
2935: }
2936: }
2937: }
1.646 raeburn 2938: my $total = scalar(@LONCAPA::map::order) - 1;
2939: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2940: my $idx = $LONCAPA::map::order[$i];
2941: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2942: my $changed;
1.529 raeburn 2943: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2944: if ((exists($toremove{$idx})) &&
2945: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2946: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2947: if (ref($currparam{$idx}) eq 'ARRAY') {
2948: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2949: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2950: }
2951: }
2952: next;
2953: }
2954: my $origsrc = $src;
1.532 raeburn 2955: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2956: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2957: $changed = 1;
1.491 raeburn 2958: }
1.492 raeburn 2959: }
1.532 raeburn 2960: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2961: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2962: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2963: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2964: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2965: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2966: } else {
1.529 raeburn 2967: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2968: }
1.491 raeburn 2969: }
1.532 raeburn 2970: if ($origsrc =~ /\.(page|sequence)$/) {
2971: if ($newsubdir{$origsrc}) {
1.529 raeburn 2972: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2973: }
1.532 raeburn 2974: } elsif ($newsubdir{$key}) {
2975: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2976: }
2977: }
1.492 raeburn 2978: $changed = 1;
1.533 raeburn 2979: } elsif ($newdb{$idx} ne '') {
2980: $src = $newdb{$idx};
1.492 raeburn 2981: $changed = 1;
2982: }
2983: if ($changed) {
1.538 raeburn 2984: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2985: }
2986: }
2987: }
2988: foreach my $idx (keys(%remparam)) {
2989: if (ref($remparam{$idx}) eq 'ARRAY') {
2990: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 2991: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 2992: }
2993: }
2994: }
1.533 raeburn 2995: if (values(%lockerrors) > 0) {
2996: $lockmsg = join('<br />',values(%lockerrors));
2997: }
1.491 raeburn 2998: my $storefn;
2999: if ($key eq $oldurl) {
3000: $storefn = $url;
3001: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
3002: } else {
3003: $storefn = $key;
3004: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 3005: if ($prefixchg && $before{'map'} && $after{'map'}) {
3006: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3007: }
1.529 raeburn 3008: if ($newsubdir{$key}) {
3009: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3010: }
1.491 raeburn 3011: }
1.492 raeburn 3012: my $report;
3013: if ($folder !~ /^supplemental/) {
3014: $report = 1;
3015: }
1.527 raeburn 3016: (my $outtext,$errtext) =
1.492 raeburn 3017: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3018: if ($errtext) {
1.529 raeburn 3019: if ($caller eq 'paste') {
1.533 raeburn 3020: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3021: }
1.491 raeburn 3022: }
3023: }
3024: }
1.533 raeburn 3025: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3026: }
3027:
3028: sub copy_dependencies {
3029: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3030: my $content;
3031: if (ref($contentref)) {
3032: $content = $$contentref;
3033: } else {
3034: $content = &Apache::lonnet::getfile($item);
3035: }
3036: unless ($content eq '-1') {
3037: my $mm = new File::MMagic;
3038: my $mimetype = $mm->checktype_contents($content);
3039: if ($mimetype eq 'text/html') {
3040: my (%allfiles,%codebase,$state);
3041: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3042: if ($res eq 'ok') {
3043: my ($numexisting,$numpathchanges,$existing);
3044: (undef,$numexisting,$numpathchanges,$existing) =
3045: &Apache::loncommon::ask_for_embedded_content(
3046: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3047: {'error_on_invalid_names' => 1,
3048: 'ignore_remote_references' => 1,
3049: 'docs_url' => $item,
3050: 'context' => 'paste'});
3051: if ($numexisting > 0) {
3052: if (ref($existing) eq 'HASH') {
3053: foreach my $dep (keys(%{$existing})) {
3054: my $depfile = $dep;
3055: unless ($depfile =~ m{^\Q$relpath\E}) {
3056: $depfile = $relpath.$dep;
3057: }
3058: my $depcontent = &Apache::lonnet::getfile($depfile);
3059: unless ($depcontent eq '-1') {
3060: my $storedep = $dep;
3061: $storedep =~ s{^\Q$relpath\E}{};
3062: my $dep_url =
3063: &Apache::lonclonecourse::writefile(
3064: $env{'request.course.id'},
3065: $storefn.$storedep,$depcontent);
3066: if ($dep_url eq '/adm/notfound.html') {
3067: if (ref($errors) eq 'HASH') {
3068: $errors->{$depfile} = 1;
3069: }
3070: } else {
3071: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3072: }
3073: }
3074: }
1.488 raeburn 3075: }
3076: }
3077: }
3078: }
3079: }
3080: return;
3081: }
3082:
1.329 droeschl 3083: my %parameter_type = ( 'randompick' => 'int_pos',
3084: 'hiddenresource' => 'string_yesno',
3085: 'encrypturl' => 'string_yesno',
3086: 'randomorder' => 'string_yesno',);
3087: my $valid_parameters_re = join('|',keys(%parameter_type));
3088: # set parameters
3089: sub update_parameter {
1.537 raeburn 3090: if ($env{'form.changeparms'} eq 'all') {
3091: my (@allidx,@allmapidx,%allchecked,%currchecked);
3092: %allchecked = (
3093: 'hiddenresource' => {},
3094: 'encrypturl' => {},
3095: 'randompick' => {},
3096: 'randomorder' => {},
3097: );
3098: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3099: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3100: if ($which eq 'randompick') {
3101: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3102: my ($res,$value) = split(/:/,$item);
3103: if ($value =~ /^\d+$/) {
3104: $allchecked{$which}{$res} = $value;
3105: }
3106: }
3107: } else {
1.539 raeburn 3108: if ($env{'form.all'.$which}) {
3109: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3110: }
1.537 raeburn 3111: }
3112: }
3113: my $haschanges = 0;
3114: foreach my $res (@LONCAPA::map::order) {
3115: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3116: $name=&LONCAPA::map::qtescape($name);
3117: $url=&LONCAPA::map::qtescape($url);
1.692 raeburn 3118: next unless $url;
1.537 raeburn 3119: my $is_map;
3120: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3121: $is_map = 1;
3122: }
3123: foreach my $which (keys(%allchecked)) {
3124: if (($which eq 'randompick' || $which eq 'randomorder')) {
3125: next if (!$is_map);
3126: }
3127: my $oldvalue = 0;
3128: my $newvalue = 0;
3129: if ($allchecked{$which}{$res}) {
3130: $newvalue = $allchecked{$which}{$res};
3131: }
3132: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3133: if ($which eq 'randompick') {
3134: if ($current =~ /^(\d+)$/) {
3135: $oldvalue = $1;
3136: }
3137: } else {
3138: if ($current =~ /^yes$/i) {
3139: $oldvalue = 1;
3140: }
3141: }
3142: if ($oldvalue ne $newvalue) {
3143: $haschanges = 1;
3144: if ($newvalue) {
3145: my $storeval = 'yes';
3146: if ($which eq 'randompick') {
3147: $storeval = $newvalue;
3148: }
3149: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3150: $storeval,
3151: $parameter_type{$which});
3152: &remember_parms($res,$which,'set',$storeval);
3153: } elsif ($oldvalue) {
3154: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3155: &remember_parms($res,$which,'del');
3156: }
3157: }
3158: }
3159: }
3160: return $haschanges;
3161: } else {
1.588 raeburn 3162: my $haschanges = 0;
3163: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3164:
1.537 raeburn 3165: my $which = $env{'form.changeparms'};
3166: my $idx = $env{'form.setparms'};
1.588 raeburn 3167: my $oldvalue = 0;
3168: my $newvalue = 0;
3169: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3170: if ($which eq 'randompick') {
3171: if ($current =~ /^(\d+)$/) {
3172: $oldvalue = $1;
3173: }
3174: } elsif ($current =~ /^yes$/i) {
3175: $oldvalue = 1;
3176: }
1.537 raeburn 3177: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3178: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3179: : 1;
3180: }
3181: if ($oldvalue ne $newvalue) {
3182: $haschanges = 1;
3183: if ($newvalue) {
3184: my $storeval = 'yes';
3185: if ($which eq 'randompick') {
3186: $storeval = $newvalue;
3187: }
3188: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3189: $parameter_type{$which});
3190: &remember_parms($idx,$which,'set',$storeval);
3191: } else {
3192: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3193: &remember_parms($idx,$which,'del');
3194: }
1.537 raeburn 3195: }
1.588 raeburn 3196: return $haschanges;
1.329 droeschl 3197: }
3198: }
3199:
3200: sub handle_edit_cmd {
3201: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3202: my $haschanges = 0;
1.543 raeburn 3203: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3204: return $haschanges;
1.543 raeburn 3205: }
1.329 droeschl 3206: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3207:
3208: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3209: my ($title, $url, @rrest) = split(':', $ratstr);
3210:
1.538 raeburn 3211: if ($cmd eq 'remove') {
1.329 droeschl 3212: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3213: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3214: &Apache::lonnet::removeuploadedurl($url);
3215: } else {
3216: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3217: }
3218: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3219: $haschanges = 1;
1.329 droeschl 3220: } elsif ($cmd eq 'cut') {
3221: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3222: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3223: $haschanges = 1;
1.344 bisitz 3224: } elsif ($cmd eq 'up'
1.329 droeschl 3225: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3226: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3227: $haschanges = 1;
1.329 droeschl 3228: } elsif ($cmd eq 'down'
3229: && defined($LONCAPA::map::order[$idx+1])) {
3230: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3231: $haschanges = 1;
1.329 droeschl 3232: } elsif ($cmd eq 'rename') {
3233: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3234: if ($comment=~/\S/) {
3235: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3236: $comment.':'.join(':', $url, @rrest);
3237: }
3238: # Devalidate title cache
3239: my $renamed_url=&LONCAPA::map::qtescape($url);
3240: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3241: $haschanges = 1;
3242: } elsif ($cmd eq 'setalias') {
3243: my $newvalue = $env{'form.alias'};
3244: if ($newvalue ne '') {
3245: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3246: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3247: 'string');
3248: &remember_parms($idx,'mapalias','set',$newvalue);
3249: $haschanges = 1;
3250: }
3251: }
3252: } elsif ($cmd eq 'delalias') {
3253: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3254: if ($current ne '') {
3255: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3256: &remember_parms($idx,'mapalias','del');
3257: $haschanges = 1;
3258: }
1.329 droeschl 3259: }
1.633 raeburn 3260: return $haschanges;
1.329 droeschl 3261: }
3262:
3263: sub editor {
1.458 raeburn 3264: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3265: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3266: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3267: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3268: if ($allowed) {
1.519 raeburn 3269: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3270: $is_random_order,$container) =
1.510 raeburn 3271: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3272: $r->print($breadcrumbtrail);
1.519 raeburn 3273: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3274: $container = 'page';
3275: } else {
3276: $container = 'sequence';
1.510 raeburn 3277: }
1.484 raeburn 3278:
1.525 raeburn 3279: my $jumpto;
3280:
3281: unless ($supplementalflag) {
1.546 raeburn 3282: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3283: }
1.484 raeburn 3284:
3285: unless ($allowed) {
3286: $randompick = -1;
3287: }
3288:
1.615 raeburn 3289: my ($errtext,$fatal);
3290: if (($folder eq '') && (!$supplementalflag)) {
3291: if (@LONCAPA::map::order) {
3292: undef(@LONCAPA::map::order);
3293: undef(@LONCAPA::map::resources);
3294: undef(@LONCAPA::map::resparms);
3295: undef(@LONCAPA::map::zombies);
3296: }
3297: $folder = 'default';
3298: $container = 'sequence';
3299: } else {
3300: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3301: $folder.'.'.$container);
3302: return $errtext if ($fatal);
3303: }
1.329 droeschl 3304:
3305: if ($#LONCAPA::map::order<1) {
3306: my $idx=&LONCAPA::map::getresidx();
3307: if ($idx<=0) { $idx=1; }
3308: $LONCAPA::map::order[0]=$idx;
3309: $LONCAPA::map::resources[$idx]='';
3310: }
1.364 bisitz 3311:
1.329 droeschl 3312: # ------------------------------------------------------------ Process commands
3313:
3314: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3315: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3316: # set parameters and change order
3317: &snapshotbefore();
3318:
3319: if (&update_parameter()) {
1.588 raeburn 3320: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3321: return $errtext if ($fatal);
3322: }
3323:
3324: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3325: # change order
3326: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3327: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3328:
3329: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3330: return $errtext if ($fatal);
3331: }
1.364 bisitz 3332:
1.329 droeschl 3333: if ($env{'form.pastemarked'}) {
1.491 raeburn 3334: my %paste_errors;
1.533 raeburn 3335: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3336: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3337: \%paste_errors);
1.541 raeburn 3338: if (ref($pastemsgarray) eq 'ARRAY') {
3339: if (@{$pastemsgarray} > 0) {
3340: $r->print('<p class="LC_info">'.
3341: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3342: '</p>');
3343: }
1.541 raeburn 3344: }
3345: if ($lockerror) {
3346: $r->print('<p class="LC_error">'.
3347: $lockerror.
3348: '</p>');
3349: }
3350: if ($save_error ne '') {
3351: return $save_error;
3352: }
3353: if ($paste_res) {
3354: my %errortext = &Apache::lonlocal::texthash (
3355: fail => 'Storage of folder contents failed',
3356: failread => 'Reading folder contents failed',
3357: failstore => 'Storage of folder contents failed',
3358: );
3359: if ($errortext{$paste_res}) {
3360: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3361: }
1.329 droeschl 3362: }
1.491 raeburn 3363: if (keys(%paste_errors) > 0) {
1.538 raeburn 3364: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3365: &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".
3366: '<ul>'."\n");
3367: foreach my $key (sort(keys(%paste_errors))) {
3368: $r->print('<li>'.$key.'</li>'."\n");
3369: }
3370: $r->print('</ul></p>'."\n");
3371: }
1.538 raeburn 3372: } elsif ($env{'form.clearmarked'}) {
3373: my $output = &do_buffer_empty();
3374: if ($output) {
3375: $r->print('<p class="LC_info">'.$output.'</p>');
3376: }
3377: }
1.329 droeschl 3378:
3379: $r->print($upload_output);
3380:
1.538 raeburn 3381: # Rename, cut, copy or remove a single resource
1.602 raeburn 3382: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3383: my $contentchg;
1.633 raeburn 3384: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3385: $contentchg = 1;
3386: }
3387: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3388: return $errtext if ($fatal);
3389: }
1.538 raeburn 3390:
3391: # Cut, copy and/or remove multiple resources
3392: if ($env{'form.multichange'}) {
3393: my %allchecked = (
3394: cut => {},
3395: remove => {},
3396: );
3397: my $needsupdate;
3398: foreach my $which (keys(%allchecked)) {
3399: $env{'form.multi'.$which} =~ s/,$//;
3400: if ($env{'form.multi'.$which}) {
3401: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3402: if (ref($allchecked{$which}) eq 'HASH') {
3403: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3404: }
3405: }
3406: }
3407: if ($needsupdate) {
3408: my $haschanges = 0;
3409: my %curr_groups = &Apache::longroup::coursegroups();
3410: my $total = scalar(@LONCAPA::map::order) - 1;
3411: for (my $i=$total; $i>=0; $i--) {
3412: my $res = $LONCAPA::map::order[$i];
3413: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3414: $name=&LONCAPA::map::qtescape($name);
3415: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3416: next unless $url;
1.538 raeburn 3417: my %denied =
3418: &action_restrictions($coursenum,$coursedom,$url,
3419: $env{'form.folderpath'},\%curr_groups);
3420: foreach my $which (keys(%allchecked)) {
3421: next if ($denied{$which});
3422: next unless ($allchecked{$which}{$res});
3423: if ($which eq 'remove') {
3424: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3425: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3426: &Apache::lonnet::removeuploadedurl($url);
3427: } else {
3428: &LONCAPA::map::makezombie($res);
3429: }
3430: splice(@LONCAPA::map::order,$i,1);
3431: $haschanges ++;
3432: } elsif ($which eq 'cut') {
3433: &LONCAPA::map::makezombie($res);
3434: splice(@LONCAPA::map::order,$i,1);
3435: $haschanges ++;
3436: }
3437: }
3438: }
3439: if ($haschanges) {
3440: ($errtext,$fatal) =
3441: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3442: return $errtext if ($fatal);
3443: }
3444: }
3445: }
3446:
1.329 droeschl 3447: # Group import/search
3448: if ($env{'form.importdetail'}) {
3449: my @imports;
3450: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3451: if (defined($item)) {
3452: my ($name,$url,$residx)=
1.533 raeburn 3453: map { &unescape($_); } split(/\=/,$item);
3454: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3455: my ($suffix,$errortxt,$locknotfreed) =
3456: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3457: if ($locknotfreed) {
3458: $r->print($locknotfreed);
3459: }
3460: if ($suffix) {
3461: $url =~ s/_new\./_$suffix./;
3462: } else {
3463: return $errortxt;
3464: }
1.533 raeburn 3465: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3466: my $type = $1;
3467: my ($suffix,$errortxt,$locknotfreed) =
3468: &new_timebased_suffix($coursedom,$coursenum,$type);
3469: if ($locknotfreed) {
3470: $r->print($locknotfreed);
3471: }
3472: if ($suffix) {
3473: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3474: } else {
3475: return $errortxt;
3476: }
1.626 raeburn 3477: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3478: my ($suffix,$errortxt,$locknotfreed) =
3479: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3480: if ($locknotfreed) {
3481: $r->print($locknotfreed);
3482: }
3483: if ($suffix) {
3484: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3485: } else {
3486: return $errortxt;
3487: }
1.534 raeburn 3488: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3489: if ($supplementalflag) {
3490: next unless ($1 eq 'supplemental');
3491: if ($folder eq 'supplemental') {
3492: next unless ($2 eq 'default');
3493: } else {
3494: next unless ($folder eq 'supplemental_'.$2);
3495: }
3496: } else {
3497: next unless ($1 eq 'docs');
3498: if ($folder eq 'default') {
3499: next unless ($2 eq 'default');
3500: } else {
3501: next unless ($folder eq 'default_'.$2);
3502: }
3503: }
1.504 raeburn 3504: }
1.329 droeschl 3505: push(@imports, [$name, $url, $residx]);
3506: }
3507: }
1.530 raeburn 3508: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3509: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3510: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3511: return $errtext if ($fatal);
1.529 raeburn 3512: if ($fixuperrors) {
3513: $r->print($fixuperrors);
3514: }
1.329 droeschl 3515: }
3516: # Loading a complete map
3517: if ($env{'form.loadmap'}) {
3518: if ($env{'form.importmap'}=~/\w/) {
3519: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3520: my ($title,$url,$ext,$type)=split(/\:/,$res);
3521: my $idx=&LONCAPA::map::getresidx($url);
3522: $LONCAPA::map::resources[$idx]=$res;
3523: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3524: }
3525: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3526: $folder.'.'.$container,1);
1.329 droeschl 3527: return $errtext if ($fatal);
3528: } else {
3529: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3530:
1.329 droeschl 3531: }
3532: }
3533: &log_differences($plain);
3534: }
3535: # ---------------------------------------------------------------- End commands
3536: # ---------------------------------------------------------------- Print screen
3537: my $idx=0;
3538: my $shown=0;
3539: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3540: $r->print('<div class="LC_Box">'.
1.432 raeburn 3541: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3542: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3543: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3544: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3545: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3546: '</ol>');
1.381 bisitz 3547: if ($randompick>=0) {
3548: $r->print('<p class="LC_warning">'
3549: .&mt('Caution: this folder is set to randomly pick a subset'
3550: .' of resources. Adding or removing resources from this'
3551: .' folder will change the set of resources that the'
3552: .' students see, resulting in spurious or missing credit'
3553: .' for completed problems, not limited to ones you'
3554: .' modify. Do not modify the contents of this folder if'
3555: .' it is in active student use.')
3556: .'</p>'
3557: );
3558: }
3559: if ($is_random_order) {
3560: $r->print('<p class="LC_warning">'
3561: .&mt('Caution: this folder is set to randomly order its'
3562: .' contents. Adding or removing resources from this folder'
3563: .' will change the order of resources shown.')
3564: .'</p>'
3565: );
3566: }
3567: $r->print('</div>');
1.364 bisitz 3568: }
1.381 bisitz 3569:
1.685 raeburn 3570: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 3571: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 3572: if (ref($supplemental) eq 'HASH') {
3573: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3574: (ref($supplemental->{'ids'}) eq 'HASH')) {
3575: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3576: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3577: if ($supplemental->{'hidden'}->{$mapnum}) {
3578: $ishidden = 1;
3579: }
3580: }
3581: }
3582: }
3583: }
3584:
1.538 raeburn 3585: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3586: %filters = (
1.543 raeburn 3587: canremove => [],
3588: cancut => [],
3589: cancopy => [],
3590: hiddenresource => [],
3591: encrypturl => [],
3592: randomorder => [],
3593: randompick => [],
1.538 raeburn 3594: );
3595: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3596: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3597: foreach my $res (@LONCAPA::map::order) {
3598: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3599: $name=&LONCAPA::map::qtescape($name);
3600: $url=&LONCAPA::map::qtescape($url);
3601: unless ($name) { $name=(split(/\//,$url))[-1]; }
3602: unless ($name) { $idx++; next; }
1.537 raeburn 3603: push(@allidx,$res);
3604: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3605: push(@allmapidx,$res);
3606: }
1.617 raeburn 3607:
1.682 raeburn 3608: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 3609: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3610: $idx++;
3611: next;
3612: }
1.682 raeburn 3613: }
1.381 bisitz 3614: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3615: $coursenum,$coursedom,$crstype,
1.538 raeburn 3616: $pathitem,$supplementalflag,$container,
1.620 raeburn 3617: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 3618: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3619: $idx++;
3620: $shown++;
1.329 droeschl 3621: }
1.424 onken 3622: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3623:
1.538 raeburn 3624: my $need_save;
1.611 raeburn 3625: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3626: my $toolslink;
1.682 raeburn 3627: if ($allowed || $canedit) {
3628: my $helpitem = 'Navigation_Screen';
3629: if (!$allowed) {
3630: $helpitem = 'Supplemental_Navigation';
3631: }
1.544 raeburn 3632: $toolslink = '<table><tr><td>'
1.520 raeburn 3633: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 3634: $helpitem,undef,'RAT')
1.520 raeburn 3635: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3636: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3637: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3638: .'id="LC_content_toolbar_edittoplevel" '
3639: .'class="LC_toolbarItem" '
3640: .'title="'.&mt('Supplemental Content Editor').'">'
3641: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3642: }
1.510 raeburn 3643: if ($shown) {
3644: if ($allowed) {
3645: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3646: .&Apache::loncommon::start_data_table(undef,'contentlist')
3647: .&Apache::loncommon::start_data_table_header_row()
3648: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3649: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 3650: .'<th>'.&mt('Document').'</th>'
3651: .'<th colspan="2">'.&mt('Settings').'</th>'
3652: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 3653: if ($folder !~ /^supplemental/) {
1.538 raeburn 3654: $lists{'canhide'} = join(',',@allidx);
3655: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3656: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3657: 'randomorder','randompick');
3658: foreach my $item (@possfilters) {
1.538 raeburn 3659: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3660: if (@{$filters{$item}} > 0) {
3661: $lists{$item} = join(',',@{$filters{$item}});
3662: }
1.538 raeburn 3663: }
3664: }
1.537 raeburn 3665: if (@allidx > 0) {
3666: my $path;
3667: if ($env{'form.folderpath'}) {
1.630 raeburn 3668: $path =
1.537 raeburn 3669: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3670: }
1.538 raeburn 3671: if (@allidx > 1) {
1.630 raeburn 3672: $to_show .=
1.538 raeburn 3673: &Apache::loncommon::continue_data_table_row().
3674: '<td colspan="2"> </td>'.
3675: '<td>'.
1.611 raeburn 3676: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3677: '</td>'.
1.633 raeburn 3678: '<td colspan="3"> </td>'.
3679: '<td colspan="2">'.
1.611 raeburn 3680: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3681: '</td>'.
3682: &Apache::loncommon::end_data_table_row();
3683: $need_save = 1;
3684: }
1.537 raeburn 3685: }
3686: }
3687: $to_show .= $output.' '
1.510 raeburn 3688: .&Apache::loncommon::end_data_table()
3689: .'<br style="line-height:2px;" />'
3690: .&Apache::loncommon::end_scrollbox();
3691: } else {
1.520 raeburn 3692: $to_show .= $toolslink
1.510 raeburn 3693: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3694: .$output.' '
3695: .&Apache::loncommon::end_data_table();
1.393 raeburn 3696: }
1.510 raeburn 3697: } else {
1.520 raeburn 3698: if (!$allowed) {
3699: $to_show .= $toolslink;
3700: }
1.615 raeburn 3701: my $noresmsg;
3702: if ($allowed && $hiddentop && !$supplementalflag) {
3703: $noresmsg = &mt('Main Content Hidden');
3704: } else {
3705: $noresmsg = &mt('Currently empty');
3706: }
1.510 raeburn 3707: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3708: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3709: .$noresmsg
1.510 raeburn 3710: .'</div>'
3711: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3712: }
3713: } else {
1.510 raeburn 3714: if ($shown) {
3715: $to_show = '<div>'
3716: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3717: .$output
3718: .&Apache::loncommon::end_data_table()
3719: .'</div>';
3720: } else {
3721: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3722: .&mt('Currently empty')
1.510 raeburn 3723: .'</div>'
3724: }
1.458 raeburn 3725: }
3726: my $tid = 1;
3727: if ($supplementalflag) {
3728: $tid = 2;
1.329 droeschl 3729: }
3730: if ($allowed) {
1.484 raeburn 3731: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3732: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3733: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3734: if ($canedit) {
3735: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3736: }
1.460 raeburn 3737: } else {
3738: $r->print($to_show);
1.329 droeschl 3739: }
3740: return;
3741: }
3742:
1.538 raeburn 3743: sub multiple_check_form {
1.611 raeburn 3744: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3745: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3746: my $disabled;
3747: unless ($canedit) {
3748: $disabled = 'disabled="disabled"';
3749: }
1.538 raeburn 3750: my $output =
3751: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3752: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3753: '<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>'.
3754: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3755: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3756: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3757: if ($caller eq 'settings') {
3758: $output .=
3759: '<table><tr>'.
3760: '<td class="LC_docs_entry_parameter">'.
3761: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3762: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3763: '</label></span></td>'.
3764: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3765: '<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 3766: '</span></td>'.
3767: '</tr>'."\n".
3768: '<tr>'.
3769: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3770: '<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 3771: '</label></span>'.
3772: '</td></tr></table>'."\n";
3773: } else {
3774: $output .=
3775: '<table><tr>'.
3776: '<td class="LC_docs_entry_parameter">'.
3777: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3778: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3779: '</label></span></td>'.
3780: '<td class="LC_docs_entry_parameter">'.
3781: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3782: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3783: '</label></span></td>'."\n".
3784: '<td class="LC_docs_entry_parameter">'.
3785: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3786: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3787: '</label></span></td>'.
3788: '</tr></table>'."\n";
3789: }
3790: $output .=
3791: '</fieldset>'.
3792: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3793: if ($caller eq 'settings') {
3794: $output .=
1.543 raeburn 3795: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3796: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3797: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3798: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3799: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3800: } elsif ($caller eq 'actions') {
3801: $output .=
3802: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3803: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3804: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3805: }
3806: $output .=
3807: '</form>'.
3808: '</div>';
3809: return $output;
3810: }
3811:
1.329 droeschl 3812: sub process_file_upload {
1.552 raeburn 3813: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3814: # upload a file, if present
1.552 raeburn 3815: my $filesize = length($env{'form.uploaddoc'});
3816: if (!$filesize) {
3817: $$upload_output = '<div class="LC_error">'.
3818: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3819: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3820: $filesize).'<br />'.
3821: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3822: '</div>';
3823: return;
3824: }
3825: my $quotatype = 'unofficial';
3826: if ($crstype eq 'Community') {
1.601 raeburn 3827: $quotatype = 'community';
3828: } elsif ($crstype eq 'Placement') {
3829: $quotatype = 'placement';
1.580 raeburn 3830: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3831: $quotatype = 'official';
1.573 raeburn 3832: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3833: $quotatype = 'textbook';
1.552 raeburn 3834: }
3835: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3836: $filesize = int($filesize/1000); #expressed in kb
3837: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3838: $env{'form.uploaddoc.filename'},$filesize,
3839: 'upload',$quotatype);
1.552 raeburn 3840: return if ($$upload_output);
3841: }
1.440 raeburn 3842: my ($parseaction,$showupload,$nextphase,$mimetype);
3843: if ($env{'form.parserflag'}) {
1.329 droeschl 3844: $parseaction = 'parse';
3845: }
3846: my $folder=$env{'form.folder'};
3847: if ($folder eq '') {
3848: $folder='default';
3849: }
3850: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3851: my $errtext='';
3852: my $fatal=0;
3853: my $container='sequence';
1.519 raeburn 3854: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3855: $container='page';
3856: }
3857: ($errtext,$fatal)=
1.534 raeburn 3858: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3859: if ($#LONCAPA::map::order<1) {
3860: $LONCAPA::map::order[0]=1;
3861: $LONCAPA::map::resources[1]='';
3862: }
3863: my $destination = 'docs/';
3864: if ($folder =~ /^supplemental/) {
3865: $destination = 'supplemental/';
3866: }
3867: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3868: $destination .= 'default/';
3869: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3870: $destination .= $2.'/';
3871: }
1.534 raeburn 3872: if ($fatal) {
3873: $$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>';
3874: return;
3875: }
1.440 raeburn 3876: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3877: my $newidx=&LONCAPA::map::getresidx();
3878: $destination .= $newidx;
1.439 raeburn 3879: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3880: $parseaction,$allfiles,
1.440 raeburn 3881: $codebase,undef,undef,undef,undef,
3882: undef,undef,\$mimetype);
3883: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3884: my $stored = $1;
3885: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3886: $stored.'</span>').'</p>';
3887: } else {
3888: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3889:
1.457 raeburn 3890: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3891: return;
3892: }
1.329 droeschl 3893: my $ext='false';
3894: if ($url=~m{^http://}) { $ext='true'; }
3895: $url = &LONCAPA::map::qtunescape($url);
3896: my $comment=$env{'form.comment'};
3897: $comment = &LONCAPA::map::qtunescape($comment);
3898: if ($folder=~/^supplemental/) {
3899: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3900: $env{'user.domain'}.'___&&&___'.$comment;
3901: }
3902:
3903: $LONCAPA::map::resources[$newidx]=
3904: $comment.':'.$url.':'.$ext.':normal:res';
3905: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3906: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3907: $folder.'.'.$container,1);
1.329 droeschl 3908: if ($fatal) {
1.457 raeburn 3909: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3910: return;
1.329 droeschl 3911: } else {
1.440 raeburn 3912: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3913: $$upload_output = $showupload;
1.384 raeburn 3914: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3915: if ($total_embedded > 0) {
1.440 raeburn 3916: my $uploadphase = 'upload_embedded';
3917: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3918: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3919: my ($embedded,$num) =
1.440 raeburn 3920: &Apache::loncommon::ask_for_embedded_content(
3921: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3922: if ($embedded) {
3923: if ($num) {
3924: $$upload_output .=
3925: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3926: $nextphase = $uploadphase;
3927: } else {
3928: $$upload_output .= $embedded;
3929: }
3930: } else {
3931: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3932: }
1.329 droeschl 3933: } else {
1.440 raeburn 3934: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3935: }
1.457 raeburn 3936: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3937: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3938: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3939: $nextphase = 'decompress_uploaded';
3940: my $position = scalar(@LONCAPA::map::order)-1;
3941: my $noextract = &return_to_editor();
3942: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3943: my %archiveitems = (
3944: folderpath => $env{'form.folderpath'},
3945: cmd => $nextphase,
3946: newidx => $newidx,
3947: position => $position,
3948: phase => $nextphase,
1.477 raeburn 3949: comment => $comment,
1.480 raeburn 3950: );
3951: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3952: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3953: $$upload_output = $showupload.
3954: &Apache::loncommon::decompress_form($mimetype,
3955: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3956: \%archiveitems,\@current);
1.329 droeschl 3957: }
3958: }
3959: }
1.440 raeburn 3960: return $nextphase;
1.329 droeschl 3961: }
3962:
1.480 raeburn 3963: sub get_dir_list {
3964: my ($url,$coursenum,$coursedom,$newidx) = @_;
3965: my ($destination,$dir_root) = &embedded_destination();
3966: my ($dirlistref,$listerror) =
3967: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3968: my @dir_lines;
3969: my $dirptr=16384;
3970: if (ref($dirlistref) eq 'ARRAY') {
3971: foreach my $dir_line (sort
3972: {
3973: my ($afile)=split('&',$a,2);
3974: my ($bfile)=split('&',$b,2);
3975: return (lc($afile) cmp lc($bfile));
3976: } (@{$dirlistref})) {
3977: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3978: $filename =~ s/\s+$//;
3979: next if ($filename =~ /^\.\.?$/);
3980: my $isdir = 0;
3981: if ($dirptr&$testdir) {
3982: $isdir = 1;
3983: }
3984: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3985: }
3986: }
3987: return @dir_lines;
3988: }
3989:
1.329 droeschl 3990: sub is_supplemental_title {
3991: my ($title) = @_;
3992: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3993: }
3994:
3995: # --------------------------------------------------------------- An entry line
3996:
3997: sub entryline {
1.501 raeburn 3998: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3999: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 4000: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 4001: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 4002: if (&is_supplemental_title($title)) {
1.488 raeburn 4003: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 4004: $encodedtitle=$title;
1.329 droeschl 4005: } else {
4006: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4007: $encodedtitle=$title;
1.329 droeschl 4008: $renametitle=$title;
4009: $foldertitle=$title;
4010: }
4011:
1.611 raeburn 4012: my ($disabled,$readonly,$js_lt);
4013: unless ($canedit) {
4014: $disabled = 'disabled="disabled"';
4015: $readonly = 1;
4016: }
4017:
1.329 droeschl 4018: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4019:
1.329 droeschl 4020: $renametitle=~s/\\/\\\\/g;
4021: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4022: $renametitle=~s/"/%22/g;
1.581 raeburn 4023: $renametitle=~s/ /%20/g;
4024: $oldtitle = $renametitle;
1.576 raeburn 4025: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4026: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4027: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4028: # Edit commands
1.679 raeburn 4029: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 4030: if ($env{'form.folderpath'}) {
4031: $esc_path=&escape($env{'form.folderpath'});
4032: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4033: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4034: }
1.505 raeburn 4035: my $isexternal;
1.510 raeburn 4036: if ($residx) {
1.501 raeburn 4037: my $currurl = $url;
4038: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 4039: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4040: $isexternal = 1;
4041: }
1.510 raeburn 4042: if (!$supplementalflag) {
4043: my $path = 'uploaded/'.
4044: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4045: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4046: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4047: $residx,
4048: &Apache::lonnet::declutter($currurl));
4049: }
1.501 raeburn 4050: }
1.538 raeburn 4051: my ($renamelink,%lt,$ishash);
4052: if (ref($filtersref) eq 'HASH') {
4053: $ishash = 1;
4054: }
4055:
1.329 droeschl 4056: if ($allowed) {
1.538 raeburn 4057: $form_start = '
4058: <form action="/adm/coursedocs" method="post">
4059: ';
4060: $form_common=(<<END);
4061: <input type="hidden" name="folderpath" value="$path" />
4062: <input type="hidden" name="symb" value="$symb" />
4063: END
4064: $form_param=(<<END);
4065: <input type="hidden" name="setparms" value="$orderidx" />
4066: <input type="hidden" name="changeparms" value="0" />
4067: END
4068: $form_end = '</form>';
4069:
1.329 droeschl 4070: my $incindex=$index+1;
4071: my $selectbox='';
1.471 raeburn 4072: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4073: ((split(/\:/,
1.344 bisitz 4074: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4075: ne '') &&
1.329 droeschl 4076: ((split(/\:/,
1.344 bisitz 4077: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4078: ne '')) {
4079: $selectbox=
4080: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4081: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4082: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4083: if ($i==$incindex) {
1.358 bisitz 4084: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4085: } else {
4086: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4087: }
4088: }
4089: $selectbox.='</select>';
4090: }
1.501 raeburn 4091: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4092: 'up' => 'Move Up',
4093: 'dw' => 'Move Down',
4094: 'rm' => 'Remove',
4095: 'ct' => 'Cut',
4096: 'rn' => 'Rename',
1.501 raeburn 4097: 'cp' => 'Copy',
1.633 raeburn 4098: 'da' => 'Unset alias',
4099: 'sa' => 'Set alias',
1.501 raeburn 4100: 'ex' => 'External Resource',
1.598 raeburn 4101: 'et' => 'External Tool',
1.501 raeburn 4102: 'ed' => 'Edit',
4103: 'pr' => 'Preview',
4104: 'sv' => 'Save',
4105: 'ul' => 'URL',
1.611 raeburn 4106: 'ti' => 'Title',
1.618 raeburn 4107: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4108: );
1.538 raeburn 4109: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4110: $env{'form.folderpath'},
4111: $currgroups);
1.517 raeburn 4112: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4113: my $skip_confirm = 0;
1.603 raeburn 4114: my $confirm_removal = 0;
1.329 droeschl 4115: if ( $folder =~ /^supplemental/
4116: || ($url =~ m{( /smppg$
4117: |/syllabus$
4118: |/aboutme$
4119: |/navmaps$
4120: |/bulletinboard$
1.626 raeburn 4121: |/ext\.tool$
1.505 raeburn 4122: |\.html$)}x)
4123: || $isexternal) {
1.329 droeschl 4124: $skip_confirm = 1;
4125: }
1.603 raeburn 4126: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4127: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4128: $confirm_removal = 1;
4129: }
1.633 raeburn 4130: if ($url =~ /$LONCAPA::assess_re/) {
4131: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4132: }
1.329 droeschl 4133:
1.538 raeburn 4134: if ($denied{'copy'}) {
1.543 raeburn 4135: $copylink=(<<ENDCOPY)
1.507 raeburn 4136: <span style="visibility: hidden;">$lt{'cp'}</span>
4137: ENDCOPY
4138: } else {
1.538 raeburn 4139: my $formname = 'edit_copy_'.$orderidx;
4140: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4141: $copylink=(<<ENDCOPY);
1.538 raeburn 4142: <form name="$formname" method="post" action="/adm/coursedocs">
4143: $form_common
1.611 raeburn 4144: <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 4145: $form_end
1.329 droeschl 4146: ENDCOPY
1.538 raeburn 4147: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4148: push(@{$filtersref->{'cancopy'}},$orderidx);
4149: }
1.329 droeschl 4150: }
1.538 raeburn 4151: if ($denied{'cut'}) {
1.507 raeburn 4152: $cutlink=(<<ENDCUT);
4153: <span style="visibility: hidden;">$lt{'ct'}</span>
4154: ENDCUT
4155: } else {
1.538 raeburn 4156: my $formname = 'edit_cut_'.$orderidx;
4157: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4158: $cutlink=(<<ENDCUT);
1.538 raeburn 4159: <form name="$formname" method="post" action="/adm/coursedocs">
4160: $form_common
1.542 raeburn 4161: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4162: <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 4163: $form_end
1.329 droeschl 4164: ENDCUT
1.538 raeburn 4165: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4166: push(@{$filtersref->{'cancut'}},$orderidx);
4167: }
1.329 droeschl 4168: }
1.538 raeburn 4169: if ($denied{'remove'}) {
1.507 raeburn 4170: $removelink=(<<ENDREM);
4171: <span style="visibility: hidden;">$lt{'rm'}</a>
4172: ENDREM
4173: } else {
1.538 raeburn 4174: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4175: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4176: $removelink=(<<ENDREM);
1.538 raeburn 4177: <form name="$formname" method="post" action="/adm/coursedocs">
4178: $form_common
1.542 raeburn 4179: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4180: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4181: <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 4182: $form_end
1.497 raeburn 4183: ENDREM
1.538 raeburn 4184: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4185: push(@{$filtersref->{'canremove'}},$orderidx);
4186: }
1.497 raeburn 4187: }
1.551 raeburn 4188: $renamelink=(<<ENDREN);
1.581 raeburn 4189: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4190: ENDREN
1.611 raeburn 4191: my ($uplink,$downlink);
4192: if ($canedit) {
4193: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4194: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4195: } else {
4196: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4197: $downlink = $uplink;
4198: }
1.329 droeschl 4199: $line.=(<<END);
4200: <td>
1.379 bisitz 4201: <div class="LC_docs_entry_move">
1.611 raeburn 4202: <a href="$uplink">
1.501 raeburn 4203: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4204: </a>
4205: </div>
4206: <div class="LC_docs_entry_move">
1.611 raeburn 4207: <a href="$downlink">
1.501 raeburn 4208: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4209: </a>
4210: </div>
1.329 droeschl 4211: </td>
4212: <td>
4213: $form_start
1.538 raeburn 4214: $form_param
1.478 raeburn 4215: $form_common
1.329 droeschl 4216: $selectbox
4217: $form_end
4218: </td>
1.540 raeburn 4219: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4220: $removelink
1.329 droeschl 4221: $cutlink
4222: $copylink
4223: </td>
4224: END
4225: }
4226: # Figure out what kind of a resource this is
4227: my ($extension)=($url=~/\.(\w+)$/);
4228: my $uploaded=($url=~/^\/*uploaded\//);
4229: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4230: my $isfolder;
4231: my $ispage;
4232: my $containerarg;
1.615 raeburn 4233: my $folderurl;
1.685 raeburn 4234: my $plainurl;
1.329 droeschl 4235: if ($uploaded) {
1.472 raeburn 4236: if (($extension eq 'sequence') || ($extension eq 'page')) {
4237: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4238: $containerarg = $1;
1.472 raeburn 4239: if ($extension eq 'sequence') {
4240: $icon=$iconpath.'navmap.folder.closed.gif';
4241: $isfolder=1;
4242: } else {
4243: $icon=$iconpath.'page.gif';
4244: $ispage=1;
4245: }
1.615 raeburn 4246: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4247: if ($allowed) {
4248: $url='/adm/coursedocs?';
4249: } else {
4250: $url='/adm/supplemental?';
4251: }
1.329 droeschl 4252: } else {
1.685 raeburn 4253: $plainurl = $url;
1.329 droeschl 4254: }
4255: }
1.364 bisitz 4256:
1.621 raeburn 4257: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4258: my $orig_url = $url;
1.340 raeburn 4259: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4260: if ($container eq 'page') {
4261: $url=~s{^http(|s)(:|:)//}{/ext/};
4262: } else {
4263: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4264: }
1.501 raeburn 4265: if (!$supplementalflag && $residx && $symb) {
4266: if ((!$isfolder) && (!$ispage)) {
4267: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4268: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4269: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4270: } else {
4271: $url=&Apache::lonnet::clutter($url);
4272: }
1.501 raeburn 4273: if ($url=~/^\/*uploaded\//) {
4274: $url=~/\.(\w+)$/;
4275: my $embstyle=&Apache::loncommon::fileembstyle($1);
4276: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4277: $url='/adm/wrapper'.$url;
4278: } elsif ($embstyle eq 'ssi') {
4279: #do nothing with these
4280: } elsif ($url!~/\.(sequence|page)$/) {
4281: $url='/adm/coursedocs/showdoc'.$url;
4282: }
1.623 raeburn 4283: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4284: my $wrapped = $1;
4285: my $exturl = $2;
1.668 raeburn 4286: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4287: $url='/adm/wrapper'.$url;
4288: }
4289: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4290: $nomodal = 1;
4291: }
1.626 raeburn 4292: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4293: $url='/adm/wrapper'.$url;
1.621 raeburn 4294: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4295: if (($ENV{'SERVER_PORT'} == 443) &&
4296: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4297: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4298: $url .= '?usehttp=1';
4299: }
1.621 raeburn 4300: $nomodal = 1;
4301: }
1.598 raeburn 4302: }
1.680 raeburn 4303: my ($checkencrypt,$shownurl);
4304: if (!$env{'request.role.adv'}) {
1.615 raeburn 4305: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 4306: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4307: $checkencrypt = 1;
1.620 raeburn 4308: } elsif (ref($navmapref)) {
1.615 raeburn 4309: unless (ref($$navmapref)) {
4310: $$navmapref = Apache::lonnavmaps::navmap->new();
4311: }
4312: if (ref($$navmapref)) {
4313: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 4314: $checkencrypt = 1;
1.615 raeburn 4315: }
4316: }
4317: }
1.680 raeburn 4318: }
4319: if ($checkencrypt) {
4320: my $currenc = $env{'request.enc'};
4321: $env{'request.enc'} = 1;
4322: $shownsymb = &Apache::lonenc::encrypted($symb);
4323: $shownurl = &Apache::lonenc::encrypted($url);
4324: if (&Apache::lonnet::symbverify($symb,$url)) {
4325: $url = $shownurl;
4326: } else {
4327: $url = '';
4328: }
4329: $env{'request.enc'} = $currenc;
4330: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4331: $shownsymb = $symb;
4332: if ($isexternal) {
4333: $url =~ s/\#[^#]+$//;
4334: if ($container eq 'page') {
4335: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4336: }
1.612 raeburn 4337: }
1.680 raeburn 4338: $shownurl = $url;
4339: }
4340: unless ($env{'request.role.adv'}) {
4341: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4342: $url = '';
4343: }
4344: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4345: $url = '';
4346: $hiddenres = 1;
4347: }
4348: }
4349: if ($url ne '') {
4350: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4351: }
1.329 droeschl 4352: }
1.621 raeburn 4353: } elsif ($supplementalflag) {
1.610 raeburn 4354: if ($isexternal) {
4355: if ($url =~ /^([^#]+)#([^#]+)$/) {
4356: $url = $1;
4357: $anchor = $2;
1.623 raeburn 4358: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4359: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4360: if ($hostname ne '') {
4361: $url = 'http://'.$hostname.$url;
4362: }
4363: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4364: }
4365: $nomodal = 1;
4366: }
1.610 raeburn 4367: }
1.621 raeburn 4368: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4369: if (($ENV{'SERVER_PORT'} == 443) &&
4370: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4371: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4372: if ($hostname ne '') {
4373: $url = 'http://'.$hostname.$url;
4374: }
4375: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4376: }
1.621 raeburn 4377: $nomodal = 1;
4378: }
1.686 raeburn 4379: } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4380: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4381: unless ($embstyle eq 'ssi') {
4382: if (($embstyle eq 'img')
4383: || ($embstyle eq 'emb')
4384: || ($embstyle eq 'wrp')) {
4385: $url='/adm/wrapper'.$url;
4386: } elsif ($url !~ /\.(sequence|page)$/) {
4387: $url='/adm/coursedocs/showdoc'.$url;
4388: }
4389: }
1.610 raeburn 4390: }
1.685 raeburn 4391: unless ($allowed && $env{'request.role.adv'}) {
4392: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4393: $hiddenres = 1;
4394: }
4395: }
1.329 droeschl 4396: }
1.615 raeburn 4397: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4398: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4399: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4400: my $foldername=&escape($foldertitle);
4401: my $folderpath=$env{'form.folderpath'};
4402: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4403: if (!$allowed && $supplementalflag) {
1.519 raeburn 4404: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4405: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 4406: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4407: $hiddenfolder = 1;
1.682 raeburn 4408: }
1.510 raeburn 4409: } else {
1.617 raeburn 4410: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4411: 'parameter_randompick'))[0];
4412: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4413: 'parameter_randomorder'))[0]=~/^yes$/i);
4414: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4415: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4416: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4417: 'parameter_encrypturl'))[0]=~/^yes$/i);
4418: unless ($hiddenmap) {
1.620 raeburn 4419: if (ref($navmapref)) {
4420: unless (ref($$navmapref)) {
4421: $$navmapref = Apache::lonnavmaps::navmap->new();
4422: }
4423: if (ref($$navmapref)) {
4424: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4425: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4426: unless (@resources) {
4427: $hiddenmap = 1;
4428: unless ($env{'request.role.adv'}) {
4429: $url = '';
4430: $hiddenfolder = 1;
4431: }
1.617 raeburn 4432: }
1.615 raeburn 4433: }
4434: }
4435: }
4436: }
1.617 raeburn 4437: unless ($encryptmap) {
1.620 raeburn 4438: if ((ref($navmapref)) && (ref($$navmapref))) {
4439: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4440: $encryptmap = 1;
4441: }
1.617 raeburn 4442: }
4443: }
1.630 raeburn 4444:
1.617 raeburn 4445: # Append randompick number, hidden, and encrypted with ":" to foldername,
4446: # so it gets transferred between levels
4447: $folderpath.=$containerarg.'&'.$foldername.
4448: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4449: unless ($url eq '') {
1.612 raeburn 4450: $url.='folderpath='.&escape($folderpath);
4451: }
1.510 raeburn 4452: my $rpckchk;
4453: if ($rpicknum) {
4454: $rpckchk = ' checked="checked"';
1.543 raeburn 4455: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4456: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4457: }
1.510 raeburn 4458: }
1.537 raeburn 4459: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4460: $rand_pick_text =
1.478 raeburn 4461: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4462: $form_param."\n".
1.478 raeburn 4463: $form_common."\n".
1.611 raeburn 4464: '<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 4465: if ($rpicknum ne '') {
4466: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4467: }
1.537 raeburn 4468: $rand_pick_text .= '</span></span>'.
4469: $form_end;
1.543 raeburn 4470: my $ro_set;
1.617 raeburn 4471: if ($randorder) {
1.543 raeburn 4472: $ro_set = 'checked="checked"';
4473: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4474: push(@{$filtersref->{'randomorder'}},$orderidx);
4475: }
4476: }
1.564 raeburn 4477: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4478: $rand_order_text =
1.537 raeburn 4479: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4480: $form_param."\n".
1.537 raeburn 4481: $form_common."\n".
1.611 raeburn 4482: '<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 4483: $form_end;
1.510 raeburn 4484: }
1.509 raeburn 4485: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4486: my $isexttool;
1.626 raeburn 4487: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4488: $url='/adm/wrapper'.$url;
4489: $isexttool = 1;
4490: }
1.510 raeburn 4491: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4492: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4493: if ($title) {
1.687 raeburn 4494: $url .= '&title='.$encodedtitle;
1.510 raeburn 4495: }
1.598 raeburn 4496: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4497: $url .= '&idx='.$orderidx;
4498: }
1.610 raeburn 4499: if ($anchor ne '') {
4500: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4501: }
1.329 droeschl 4502: }
1.519 raeburn 4503: my ($tdalign,$tdwidth);
1.501 raeburn 4504: if ($allowed) {
1.630 raeburn 4505: my $fileloc =
1.501 raeburn 4506: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4507: if ($isexternal) {
1.630 raeburn 4508: ($editlink,$extresform) =
1.611 raeburn 4509: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4510: undef,undef,undef,undef,undef,undef,
4511: undef,$disabled);
1.626 raeburn 4512: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4513: ($editlink,$extresform) =
4514: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4515: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4516: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4517: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4518: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4519: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4520: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4521: my $suppanchor;
4522: if ($supplementalflag) {
4523: $suppanchor = $anchor;
4524: }
1.630 raeburn 4525: my $jscall =
1.501 raeburn 4526: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4527: $switchserver,
1.503 raeburn 4528: $forceedit,
1.679 raeburn 4529: undef,$symb,$shownsymb,
1.511 raeburn 4530: &escape($env{'form.folderpath'}),
1.622 raeburn 4531: $renametitle,$hostname,
4532: '','',1,$suppanchor);
1.501 raeburn 4533: if ($jscall) {
1.518 raeburn 4534: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4535: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4536: }
4537: }
4538: }
1.519 raeburn 4539: $tdalign = ' align="right" valign="top"';
4540: $tdwidth = ' width="80%"';
1.329 droeschl 4541: }
1.408 raeburn 4542: my $reinit;
4543: if ($crstype eq 'Community') {
4544: $reinit = &mt('(re-initialize community to access)');
4545: } else {
4546: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4547: }
4548: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650 raeburn 4549: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4550: $line.= '<br />';
4551: if ($curralias ne '') {
4552: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4553: $lt{'da'}.'</a></span>';
4554: } else {
4555: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4556: $lt{'sa'}.'</a></span>';
4557: }
4558: }
4559: $line.='</td><td>';
1.685 raeburn 4560: my ($link,$nolink);
1.472 raeburn 4561: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4562: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4563: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4564: $nolink = 1;
4565: }
4566: }
4567: if ($nolink) {
4568: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4569: } else {
4570: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4571: }
1.469 www 4572: } elsif ($url) {
1.610 raeburn 4573: if ($anchor ne '') {
4574: if ($supplementalflag) {
4575: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4576: } else {
4577: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4578: }
4579: }
1.622 raeburn 4580: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4581: $link = 'http://'.$hostname.$url;
4582: } else {
4583: $link = $url;
4584: }
1.659 raeburn 4585: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.685 raeburn 4586: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4587: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4588: $nolink = 1;
4589: }
4590: }
4591: if ($nolink) {
4592: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4593: } elsif ($nomodal) {
1.621 raeburn 4594: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4595: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4596: } else {
4597: $line.=&Apache::loncommon::modal_link($link,
4598: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4599: }
1.469 www 4600: } else {
4601: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4602: }
1.519 raeburn 4603: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4604: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4605: if ($nolink) {
4606: $line.=$title;
4607: } else {
4608: $line.='<a href="'.$url.'">'.$title.'</a>';
4609: }
1.682 raeburn 4610: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4611: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4612: my $editurl = $url;
4613: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4614: $line .= ' '.'<a href="'.$editurl.'">'.
4615: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4616: '</a>';
4617: }
4618: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4619: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4620: }
1.469 www 4621: } elsif ($url) {
1.685 raeburn 4622: if ($nolink) {
4623: $line.=$title;
4624: } elsif ($nomodal) {
1.621 raeburn 4625: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4626: $title.'</a>';
4627: } else {
4628: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4629: }
1.617 raeburn 4630: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4631: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4632: } else {
4633: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4634: }
1.633 raeburn 4635: if (($allowed) && ($curralias ne '')) {
4636: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4637: } else {
4638: $line .= $extresform;
4639: }
4640: $line .= '</td>';
1.478 raeburn 4641: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4642: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 4643: if ($uploaded && $url && !$isfolder && !$ispage) {
4644: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
4645: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
4646: }
4647: }
1.682 raeburn 4648: if ($allowed) {
4649: my %lt=&Apache::lonlocal::texthash(
4650: 'hd' => 'Hidden',
4651: 'ec' => 'URL hidden');
4652: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 4653: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4654: $hidtext = ' checked="checked"';
1.694 raeburn 4655: if (($ishash) && (ref($filtersref->{'hiddenresource'}) eq 'ARRAY')) {
1.543 raeburn 4656: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4657: }
4658: }
1.682 raeburn 4659: $formhidden = 'edit_hiddenresource_'.$orderidx;
4660: $line.=(<<ENDPARMS);
1.329 droeschl 4661: <td class="LC_docs_entry_parameter">
1.537 raeburn 4662: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4663: $form_param
1.478 raeburn 4664: $form_common
1.611 raeburn 4665: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4666: $form_end
1.682 raeburn 4667: ENDPARMS
4668: if ($folder =~/^supplemental/) {
4669: $line.= "\n <td>";
4670: } else {
4671: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4672: $enctext = ' checked="checked"';
4673: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4674: push(@{$filtersref->{'encrypturl'}},$orderidx);
4675: }
4676: }
4677: $formurlhidden = 'edit_encrypturl_'.$orderidx;
4678: $line.=(<<ENDPARMS);
1.458 raeburn 4679: <br />
1.537 raeburn 4680: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4681: $form_param
1.478 raeburn 4682: $form_common
1.611 raeburn 4683: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4684: $form_end
4685: </td>
1.478 raeburn 4686: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4687: $rand_order_text</td>
1.329 droeschl 4688: ENDPARMS
1.682 raeburn 4689: }
1.329 droeschl 4690: }
1.379 bisitz 4691: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4692: return $line;
4693: }
4694:
1.538 raeburn 4695: sub action_restrictions {
4696: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4697: my %denied = (
4698: cut => 0,
4699: copy => 0,
4700: remove => 0,
4701: );
4702: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4703: # no copy for published maps
4704: $denied{'copy'} = 1;
1.597 raeburn 4705: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4706: unless ($1 eq 'simpleproblem') {
4707: $denied{'copy'} = 1;
4708: }
4709: $denied{'cut'} = 1;
1.538 raeburn 4710: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4711: if ($folderpath =~ /^default&[^\&]+$/) {
4712: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4713: $denied{'remove'} = 1;
4714: }
4715: $denied{'cut'} = 1;
4716: $denied{'copy'} = 1;
4717: }
4718: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4719: my $group = $1;
4720: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4721: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4722: $denied{'remove'} = 1;
4723: }
4724: }
4725: $denied{'cut'} = 1;
4726: $denied{'copy'} = 1;
4727: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4728: my $group = $1;
4729: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4730: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4731: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4732: if (keys(%groupsettings) > 0) {
4733: $denied{'remove'} = 1;
4734: }
4735: $denied{'cut'} = 1;
4736: $denied{'copy'} = 1;
4737: }
4738: }
4739: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4740: my $group = $1;
4741: if ($url =~ /group_boards_\Q$group\E/) {
4742: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4743: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4744: if (keys(%groupsettings) > 0) {
4745: if (ref($groupsettings{'functions'}) eq 'HASH') {
4746: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4747: $denied{'remove'} = 1;
4748: }
4749: }
4750: }
4751: $denied{'cut'} = 1;
4752: $denied{'copy'} = 1;
4753: }
4754: }
4755: }
4756: return %denied;
4757: }
4758:
1.533 raeburn 4759: sub new_timebased_suffix {
1.538 raeburn 4760: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4761: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4762: if ($type eq 'paste') {
4763: $prefix = $type;
4764: $namespace = 'courseeditor';
1.587 raeburn 4765: $idtype = 'addcode';
1.538 raeburn 4766: } elsif ($type eq 'map') {
1.533 raeburn 4767: $prefix = 'docs';
4768: if ($area eq 'supplemental') {
4769: $prefix = 'supp';
4770: }
4771: $prefix .= $container;
4772: $namespace = 'uploadedmaps';
4773: } else {
4774: $prefix = $type;
4775: $namespace = 'templated';
1.504 raeburn 4776: }
4777: my ($suffix,$freedlock,$error) =
1.587 raeburn 4778: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4779: if (!$suffix) {
1.538 raeburn 4780: if ($type eq 'paste') {
4781: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4782: } elsif ($type eq 'map') {
1.533 raeburn 4783: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4784: } elsif ($type eq 'smppg') {
4785: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4786: } elsif ($type eq 'exttool') {
4787: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4788: } else {
1.565 bisitz 4789: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4790: }
1.504 raeburn 4791: if ($error) {
4792: $errtext .= '<br />'.$error;
4793: }
4794: }
4795: if ($freedlock ne 'ok') {
1.630 raeburn 4796: $locknotfreed =
1.533 raeburn 4797: '<div class="LC_error">'.
4798: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4799: if ($type eq 'paste') {
1.591 raeburn 4800: if ($freedlock eq 'nolock') {
4801: $locknotfreed =
4802: '<div class="LC_error">'.
4803: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4804:
1.593 droeschl 4805: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4806: } else {
4807: $locknotfreed .=
4808: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4809: }
1.538 raeburn 4810: } elsif ($type eq 'map') {
1.591 raeburn 4811: $locknotfreed .=
4812: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4813: } elsif ($type eq 'smppg') {
4814: $locknotfreed .=
4815: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4816: } elsif ($type eq 'exttool') {
4817: $locknotfreed .=
4818: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4819: } else {
4820: $locknotfreed .=
1.565 bisitz 4821: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4822: }
1.538 raeburn 4823: unless ($type eq 'paste') {
4824: $locknotfreed .=
1.560 raeburn 4825: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4826: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4827: }
4828: $locknotfreed .= '</div>';
1.504 raeburn 4829: }
4830: return ($suffix,$errtext,$locknotfreed);
4831: }
4832:
1.329 droeschl 4833: =pod
4834:
4835: =item tiehash()
4836:
4837: tie the hash
4838:
4839: =cut
4840:
4841: sub tiehash {
4842: my ($mode)=@_;
4843: $hashtied=0;
4844: if ($env{'request.course.fn'}) {
4845: if ($mode eq 'write') {
4846: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4847: &GDBM_WRCREAT(),0640)) {
4848: $hashtied=2;
4849: }
4850: } else {
4851: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4852: &GDBM_READER(),0640)) {
4853: $hashtied=1;
4854: }
4855: }
1.364 bisitz 4856: }
1.329 droeschl 4857: }
4858:
4859: sub untiehash {
4860: if ($hashtied) { untie %hash; }
4861: $hashtied=0;
4862: return OK;
4863: }
4864:
4865:
4866:
4867:
4868: sub checkonthis {
1.637 raeburn 4869: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4870: $url=&unescape($url);
4871: $alreadyseen{$url}=1;
4872: $r->rflush();
4873: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4874: $r->print("\n<br />");
4875: if ($level==0) {
4876: $r->print("<br />");
4877: }
4878: for (my $i=0;$i<=$level*5;$i++) {
4879: $r->print(' ');
4880: }
4881: $r->print('<a href="'.$url.'" target="cat">'.
4882: ($title?$title:$url).'</a> ');
4883: if ($url=~/^\/res\//) {
1.637 raeburn 4884: my $updated;
4885: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4886: ($url !~ /\.\d+\.\w+$/)) {
4887: $updated = &Apache::lonnet::remove_stale_resfile($url);
4888: }
1.329 droeschl 4889: my $result=&Apache::lonnet::repcopy(
4890: &Apache::lonnet::filelocation('',$url));
4891: if ($result eq 'ok') {
4892: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4893: if ($updated) {
4894: $r->print('<br />');
4895: for (my $i=0;$i<=$level*5;$i++) {
4896: $r->print(' ');
4897: }
4898: $r->print('- '.&mt('Outdated copy removed'));
4899: }
1.329 droeschl 4900: $r->rflush();
4901: &Apache::lonnet::countacc($url);
4902: $url=~/\.(\w+)$/;
4903: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4904: $r->print('<br />');
4905: $r->rflush();
4906: for (my $i=0;$i<=$level*5;$i++) {
4907: $r->print(' ');
4908: }
4909: $r->print('- '.&mt('Rendering:').' ');
4910: my ($errorcount,$warningcount)=split(/:/,
4911: &Apache::lonnet::ssi_body($url,
4912: ('grade_target'=>'web',
4913: 'return_only_error_and_warning_counts' => 1)));
4914: if (($errorcount) ||
4915: ($warningcount)) {
4916: if ($errorcount) {
1.369 bisitz 4917: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4918: &mt('[quant,_1,error]',$errorcount).'</span>');
4919: }
4920: if ($warningcount) {
4921: $r->print('<span class="LC_warning">'.
4922: &mt('[quant,_1,warning]',$warningcount).'</span>');
4923: }
4924: } else {
4925: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4926: }
4927: $r->rflush();
4928: }
4929: my $dependencies=
4930: &Apache::lonnet::metadata($url,'dependencies');
4931: foreach my $dep (split(/\,/,$dependencies)) {
4932: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4933: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4934: }
4935: }
4936: } elsif ($result eq 'unavailable') {
4937: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4938: } elsif ($result eq 'not_found') {
4939: unless ($url=~/\$/) {
1.521 bisitz 4940: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4941: } else {
1.366 bisitz 4942: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4943: }
4944: } else {
4945: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4946: }
1.637 raeburn 4947: if (($updated) && ($result ne 'ok')) {
4948: $r->print('<br />'.&mt('Outdated copy removed'));
4949: }
1.329 droeschl 4950: }
4951: }
4952: }
4953:
4954:
4955:
4956: =pod
4957:
4958: =item list_symbs()
4959:
1.485 raeburn 4960: List Content Identifiers
1.329 droeschl 4961:
4962: =cut
4963:
4964: sub list_symbs {
4965: my ($r) = @_;
4966:
1.408 raeburn 4967: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4968: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4969: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4970: $r->print(&startContentScreen('tools'));
1.329 droeschl 4971: my $navmap = Apache::lonnavmaps::navmap->new();
4972: if (!defined($navmap)) {
4973: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4974: '<div class="LC_error">'.
4975: &mt('Unable to retrieve information about course contents').
4976: '</div>');
1.408 raeburn 4977: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4978: } else {
1.484 raeburn 4979: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4980: &Apache::loncommon::start_data_table().
4981: &Apache::loncommon::start_data_table_header_row().
4982: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4983: &Apache::loncommon::end_data_table_header_row()."\n");
4984: my $count;
1.329 droeschl 4985: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4986: $r->print(&Apache::loncommon::start_data_table_row().
4987: '<td>'.$res->compTitle().'</td>'.
4988: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4989: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4990: $count ++;
4991: }
4992: if (!$count) {
4993: $r->print(&Apache::loncommon::start_data_table_row().
4994: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4995: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4996: }
1.484 raeburn 4997: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4998: }
1.521 bisitz 4999: $r->print(&endContentScreen());
1.329 droeschl 5000: }
5001:
1.651 raeburn 5002: sub short_urls {
5003: my ($r,$canedit) = @_;
5004: my $crstype = &Apache::loncommon::course_type();
5005: my $formname = 'shortenurl';
5006: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5007: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5008: $r->print(&startContentScreen('tools'));
5009: my ($navmap,$errormsg) =
5010: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5011: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5012: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5013: my (%maps,%resources,%titles);
5014: if (!ref($navmap)) {
5015: $r->print($errormsg.
5016: &endContentScreen());
5017: return '';
5018: } else {
1.652 raeburn 5019: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 5020: $r->rflush();
5021: my $readonly;
5022: if ($canedit) {
1.671 raeburn 5023: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 5024: if ($numnew) {
5025: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5026: }
5027: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5028: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5029: foreach my $error (@{$errors}) {
5030: $r->print('<li>'.$error.'</li>');
5031: }
5032: $r->print('</ul><br />');
5033: }
5034: } else {
5035: $readonly = 1;
5036: }
5037: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5038: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5039: undef,undef,undef,undef,undef,\%currtiny,$readonly));
5040: }
5041: $r->print(&endContentScreen());
5042: }
5043:
1.637 raeburn 5044: sub contentverifyform {
5045: my ($r) = @_;
5046: my $crstype = &Apache::loncommon::course_type();
5047: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5048: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5049: $r->print(&startContentScreen('tools'));
5050: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5051: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5052: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5053: ' <span class="LC_nobreak">'.
5054: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5055: &mt('No').'</label>'.(' 'x2).
5056: '<label><input type="radio" name="checkstale" value="1" />'.
5057: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 5058: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 5059: '<input type="hidden" value="1" name="tools" />'.
5060: '<input type="hidden" value="1" name="verify" /></p></form>');
5061: $r->print(&endContentScreen());
5062: return;
5063: }
1.329 droeschl 5064:
5065: sub verifycontent {
1.637 raeburn 5066: my ($r,$checkstale) = @_;
1.408 raeburn 5067: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 5068: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5069: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5070: $r->print(&startContentScreen('tools'));
5071: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5072: $hashtied=0;
5073: undef %alreadyseen;
5074: %alreadyseen=();
5075: &tiehash();
1.484 raeburn 5076:
1.329 droeschl 5077: foreach my $key (keys(%hash)) {
5078: if ($hash{$key}=~/\.(page|sequence)$/) {
5079: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5080: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5081: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5082: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5083: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5084: }
5085: }
5086: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 5087: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5088: }
5089: }
5090: &untiehash();
1.442 www 5091: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 5092: $r->print(&endContentScreen());
1.329 droeschl 5093: }
5094:
5095: sub devalidateversioncache {
5096: my $src=shift;
5097: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5098: &Apache::lonnet::clutter($src));
5099: }
5100:
5101: sub checkversions {
1.611 raeburn 5102: my ($r,$canedit) = @_;
1.408 raeburn 5103: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 5104: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5105: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5106: $r->print(&startContentScreen('tools'));
1.442 www 5107:
1.329 droeschl 5108: my $header='';
5109: my $startsel='';
5110: my $monthsel='';
5111: my $weeksel='';
5112: my $daysel='';
5113: my $allsel='';
5114: my %changes=();
5115: my $starttime=0;
5116: my $haschanged=0;
5117: my %setversions=&Apache::lonnet::dump('resourceversions',
5118: $env{'course.'.$env{'request.course.id'}.'.domain'},
5119: $env{'course.'.$env{'request.course.id'}.'.num'});
5120:
5121: $hashtied=0;
5122: &tiehash();
1.611 raeburn 5123: if ($canedit) {
5124: my %newsetversions=();
5125: if ($env{'form.setmostrecent'}) {
5126: $haschanged=1;
5127: foreach my $key (keys(%hash)) {
5128: if ($key=~/^ids\_(\/res\/.+)$/) {
5129: $newsetversions{$1}='mostrecent';
5130: &devalidateversioncache($1);
5131: }
5132: }
5133: } elsif ($env{'form.setcurrent'}) {
5134: $haschanged=1;
5135: foreach my $key (keys(%hash)) {
5136: if ($key=~/^ids\_(\/res\/.+)$/) {
5137: my $getvers=&Apache::lonnet::getversion($1);
5138: if ($getvers>0) {
5139: $newsetversions{$1}=$getvers;
5140: &devalidateversioncache($1);
5141: }
5142: }
1.329 droeschl 5143: }
1.611 raeburn 5144: } elsif ($env{'form.setversions'}) {
5145: $haschanged=1;
5146: foreach my $key (keys(%env)) {
5147: if ($key=~/^form\.set_version_(.+)$/) {
5148: my $src=$1;
5149: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5150: $newsetversions{$src}=$env{$key};
5151: &devalidateversioncache($src);
5152: }
5153: }
1.329 droeschl 5154: }
1.611 raeburn 5155: }
5156: if ($haschanged) {
5157: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5158: $env{'course.'.$env{'request.course.id'}.'.domain'},
5159: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5160: $r->print(&Apache::loncommon::confirmwrapper(
5161: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5162: } else {
5163: $r->print(&Apache::loncommon::confirmwrapper(
5164: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5165: }
1.611 raeburn 5166: &mark_hash_old();
5167: }
5168: &changewarning($r,'');
1.329 droeschl 5169: }
5170: if ($env{'form.timerange'} eq 'all') {
5171: # show all documents
1.549 raeburn 5172: $header=&mt('All content in '.$crstype);
1.521 bisitz 5173: $allsel=' selected="selected"';
1.329 droeschl 5174: foreach my $key (keys(%hash)) {
5175: if ($key=~/^ids\_(\/res\/.+)$/) {
5176: my $src=$1;
5177: $changes{$src}=1;
5178: }
5179: }
5180: } else {
5181: # show documents which changed
5182: %changes=&Apache::lonnet::dump
5183: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5184: $env{'course.'.$env{'request.course.id'}.'.num'});
5185: my $firstkey=(keys(%changes))[0];
5186: unless ($firstkey=~/^error\:/) {
5187: unless ($env{'form.timerange'}) {
5188: $env{'form.timerange'}=604800;
5189: }
5190: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5191: .&mt('seconds');
5192: if ($env{'form.timerange'}==-1) {
5193: $seltext='since start of course';
1.521 bisitz 5194: $startsel=' selected="selected"';
1.329 droeschl 5195: $env{'form.timerange'}=time;
5196: }
5197: $starttime=time-$env{'form.timerange'};
5198: if ($env{'form.timerange'}==2592000) {
5199: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5200: $monthsel=' selected="selected"';
1.329 droeschl 5201: } elsif ($env{'form.timerange'}==604800) {
5202: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5203: $weeksel=' selected="selected"';
1.329 droeschl 5204: } elsif ($env{'form.timerange'}==86400) {
5205: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5206: $daysel=' selected="selected"';
1.329 droeschl 5207: }
5208: $header=&mt('Content changed').' '.$seltext;
5209: } else {
5210: $header=&mt('No content modifications yet.');
5211: }
5212: }
5213: %setversions=&Apache::lonnet::dump('resourceversions',
5214: $env{'course.'.$env{'request.course.id'}.'.domain'},
5215: $env{'course.'.$env{'request.course.id'}.'.num'});
5216: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5217: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5218: 'lm' => 'Version changes since last Month',
5219: 'lw' => 'Version changes since last Week',
5220: 'sy' => 'Version changes since Yesterday',
5221: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5222: 'cd' => 'Change display',
1.329 droeschl 5223: 'sd' => 'Display',
5224: 'fi' => 'File',
5225: 'md' => 'Modification Date',
5226: 'mr' => 'Most recently published Version',
1.408 raeburn 5227: 've' => 'Version used in '.$crstype,
5228: 'vu' => 'Set Version to be used in '.$crstype,
5229: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5230: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5231: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5232: 'di' => 'Differences',
1.484 raeburn 5233: 'save' => 'Save changes',
5234: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5235: 'act' => 'Actions');
1.611 raeburn 5236: my ($disabled,$readonly);
5237: unless ($canedit) {
5238: $disabled = 'disabled="disabled"';
5239: $readonly = 1;
5240: }
1.329 droeschl 5241: $r->print(<<ENDHEADERS);
1.484 raeburn 5242: <h4 class="LC_info">$header</h4>
1.329 droeschl 5243: <form action="/adm/coursedocs" method="post">
5244: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5245: <div class="LC_left_float">
1.479 golterma 5246: <fieldset>
1.484 raeburn 5247: <legend>$lt{'cd'}</legend>
1.329 droeschl 5248: <select name="timerange">
1.521 bisitz 5249: <option value='all'$allsel>$lt{'al'}</option>
5250: <option value="-1"$startsel>$lt{'st'}</option>
5251: <option value="2592000"$monthsel>$lt{'lm'}</option>
5252: <option value="604800"$weeksel>$lt{'lw'}</option>
5253: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5254: </select>
5255: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5256: </fieldset>
5257: </div>
5258: <div class="LC_left_float">
5259: <fieldset>
5260: <legend>$lt{'act'}</legend>
1.611 raeburn 5261: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5262: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5263: </fieldset>
5264: </div>
5265: <br clear="all" />
5266: <hr />
5267: <h4>$lt{'vers'}</h4>
1.329 droeschl 5268: ENDHEADERS
1.479 golterma 5269: #number of columns for version history
1.571 raeburn 5270: my %changedbytime;
5271: foreach my $key (keys(%changes)) {
5272: #excludes not versionable problems from resource version history:
5273: next if ($key =~ /^\/res\/lib\/templates/);
5274: my $chg;
5275: if ($env{'form.timerange'} eq 'all') {
5276: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5277: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5278: } else {
5279: $chg = $changes{$key};
5280: next if ($chg < $starttime);
5281: }
5282: push(@{$changedbytime{$chg}},$key);
5283: }
5284: if (keys(%changedbytime) == 0) {
5285: &untiehash();
5286: $r->print(&mt('No content changes in imported content in specified time frame').
5287: &endContentScreen());
5288: return;
5289: }
1.479 golterma 5290: $r->print(
1.611 raeburn 5291: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5292: &Apache::loncommon::start_data_table().
5293: &Apache::loncommon::start_data_table_header_row().
5294: '<th>'.&mt('Resources').'</th>'.
5295: "<th>$lt{'mr'}</th>".
5296: "<th>$lt{'ve'}</th>".
5297: "<th>$lt{'vu'}</th>".
5298: '<th>'.&mt('History').'</th>'.
5299: &Apache::loncommon::end_data_table_header_row()
5300: );
1.571 raeburn 5301: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5302: foreach my $key (sort(@{$changedbytime{$chg}})) {
5303: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5304: my $currentversion=&Apache::lonnet::getversion($key);
5305: if ($currentversion<0) {
5306: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5307: }
5308: my $linkurl=&Apache::lonnet::clutter($key);
5309: $r->print(
5310: &Apache::loncommon::start_data_table_row().
5311: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5312: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5313: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5314: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5315: '<td align="right">'
5316: );
5317: # Used in course
5318: my $usedversion=$hash{'version_'.$linkurl};
5319: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5320: if ($usedversion != $currentversion) {
1.479 golterma 5321: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5322: } else {
1.479 golterma 5323: $r->print($usedversion);
5324: }
1.329 droeschl 5325: } else {
1.521 bisitz 5326: $r->print($currentversion);
1.329 droeschl 5327: }
1.571 raeburn 5328: $r->print('</td><td title="'.$lt{'vu'}.'">');
5329: # Set version
5330: $r->print(&Apache::loncommon::select_form(
5331: $setversions{$linkurl},
5332: 'set_version_'.$linkurl,
5333: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5334: '' => '',
5335: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5336: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5337: my $lastold=1;
5338: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5339: my $url=$root.'.'.$prevvers.'.'.$extension;
5340: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5341: $lastold=$prevvers;
5342: }
5343: }
5344: $r->print('</td>');
5345: # List all available versions
5346: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5347: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5348: my $url=$root.'.'.$prevvers.'.'.$extension;
5349: $r->print(
5350: '<span class="LC_nobreak">'
5351: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5352: .&mt('Version [_1]',$prevvers).'</a>'
5353: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5354: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5355: .')');
5356: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5357: $r->print(
5358: ' <a href="/adm/diff?filename='.
5359: &Apache::lonnet::clutter($root.'.'.$extension).
5360: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5361: '" target="diffs">'.&mt('Diffs').'</a>');
5362: }
5363: $r->print('</span><br />');
1.329 droeschl 5364: }
1.571 raeburn 5365: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5366: }
1.329 droeschl 5367: }
1.521 bisitz 5368: $r->print(
5369: &Apache::loncommon::end_data_table().
1.611 raeburn 5370: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5371: '</form>'
5372: );
1.329 droeschl 5373:
5374: &untiehash();
1.521 bisitz 5375: $r->print(&endContentScreen());
1.571 raeburn 5376: return;
1.329 droeschl 5377: }
5378:
5379: sub mark_hash_old {
5380: my $retie_hash=0;
5381: if ($hashtied) {
5382: $retie_hash=1;
5383: &untiehash();
5384: }
5385: &tiehash('write');
5386: $hash{'old'}=1;
5387: &untiehash();
5388: if ($retie_hash) { &tiehash(); }
5389: }
5390:
5391: sub is_hash_old {
5392: my $untie_hash=0;
5393: if (!$hashtied) {
5394: $untie_hash=1;
5395: &tiehash();
5396: }
5397: my $return=$hash{'old'};
5398: if ($untie_hash) { &untiehash(); }
5399: return $return;
5400: }
5401:
5402: sub changewarning {
5403: my ($r,$postexec,$message,$url)=@_;
5404: if (!&is_hash_old()) { return; }
5405: my $pathvar='folderpath';
5406: my $path=&escape($env{'form.folderpath'});
5407: if (!defined($url)) {
5408: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5409: }
5410: my $course_type = &Apache::loncommon::course_type();
5411: if (!defined($message)) {
5412: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5413: }
1.653 raeburn 5414: my $windowname = 'loncapaclient';
5415: if ($env{'request.lti.login'}) {
5416: $windowname .= 'lti';
5417: }
1.329 droeschl 5418: $r->print("\n\n".
1.372 bisitz 5419: '<script type="text/javascript">'."\n".
5420: '// <![CDATA['."\n".
5421: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5422: '// ]]>'."\n".
1.369 bisitz 5423: '</script>'."\n".
1.653 raeburn 5424: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5425: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5426: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5427: &mt($message,' <input type="hidden" name="'.
5428: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5429: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5430: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5431: }
5432:
5433:
5434: sub init_breadcrumbs {
1.571 raeburn 5435: my ($form,$text,$help)=@_;
1.329 droeschl 5436: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5437: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5438: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5439: faq=>273,
5440: bug=>'Instructor Interface',
1.571 raeburn 5441: help => $help});
1.329 droeschl 5442: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5443: text=>$text,
5444: faq=>273,
5445: bug=>'Instructor Interface'});
5446: }
5447:
1.441 www 5448: # subroutine to list form elements
5449: sub create_list_elements {
5450: my @formarr = @_;
5451: my $list = '';
1.501 raeburn 5452: foreach my $button (@formarr){
5453: foreach my $picture (keys(%{$button})) {
5454: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5455: }
5456: }
5457: return $list;
5458: }
1.329 droeschl 5459:
1.441 www 5460: # subroutine to create ul from list elements
5461: sub create_form_ul {
5462: my $list = shift;
5463: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5464: return $ul;
5465: }
1.329 droeschl 5466:
1.442 www 5467: #
5468: # Start tabs
5469: #
5470:
5471: sub startContentScreen {
1.484 raeburn 5472: my ($mode) = @_;
5473: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5474: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5475: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5476: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5477: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5478: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5479: } else {
1.549 raeburn 5480: $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 5481: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5482: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5483: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5484: }
5485: $output .= "\n".'</ul>'."\n";
5486: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5487: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5488: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5489: return $output;
1.442 www 5490: }
5491:
5492: #
5493: # End tabs
5494: #
5495:
5496: sub endContentScreen {
1.484 raeburn 5497: return '</div></div></div>';
1.442 www 5498: }
1.329 droeschl 5499:
1.446 www 5500: sub supplemental_base {
1.548 raeburn 5501: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5502: }
5503:
1.329 droeschl 5504: sub handler {
5505: my $r = shift;
5506: &Apache::loncommon::content_type($r,'text/html');
5507: $r->send_http_header;
5508: return OK if $r->header_only;
1.484 raeburn 5509:
5510: # get course data
1.408 raeburn 5511: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5512: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5513: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5514:
1.606 raeburn 5515: # get docroot
5516: my $londocroot = $r->dir_config('lonDocRoot');
5517:
1.484 raeburn 5518: # graphics settings
5519: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5520:
1.443 www 5521: #
1.329 droeschl 5522: # --------------------------------------------- Initialize help topics for this
5523: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5524: 'Adding_External_Resource','Adding_External_Tool',
5525: 'Navigate_Content','Adding_Folders','Docs_Overview',
5526: 'Load_Map','Supplemental','Score_Upload_Form',
5527: 'Adding_Pages','Importing_LON-CAPA_Resource',
5528: 'Importing_IMS_Course','Uploading_From_Harddrive',
5529: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5530: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5531: }
5532: # Composite help files
5533: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5534: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5535: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5536: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5537: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5538: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5539: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5540: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5541: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5542: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5543:
1.611 raeburn 5544: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 5545: # does this user have privileges to modify content.
5546: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5547: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 5548: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5549: $allowed = 1;
1.682 raeburn 5550: }
5551: $canedit = 1;
5552: $canview = 1;
5553: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5554: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5555: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5556: $allowed = 1;
5557: }
1.682 raeburn 5558: $canview = 1;
1.611 raeburn 5559: }
5560: unless ($canedit) {
5561: $disabled = ' disabled="disabled"';
1.472 raeburn 5562: }
1.582 raeburn 5563: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5564: if ($env{'form.inhibitmenu'}) {
5565: unless ($env{'form.inhibitmenu'} eq 'yes') {
5566: delete($env{'form.inhibitmenu'});
5567: }
5568: }
5569:
1.582 raeburn 5570: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5571: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5572: if (!$canedit) {
5573: &verifycontent($r);
5574: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5575: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5576: text=>'Results',
5577: faq=>273,
5578: bug=>'Instructor Interface'});
5579: &verifycontent($r,$env{'form.checkstale'});
5580: } else {
5581: &contentverifyform($r);
5582: }
1.329 droeschl 5583: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5584: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5585: &list_symbs($r);
1.651 raeburn 5586: } elsif ($allowed && $env{'form.shorturls'}) {
5587: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5588: &short_urls($r,$canedit);
1.329 droeschl 5589: } elsif ($allowed && $env{'form.docslog'}) {
5590: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5591: my $folder = $env{'form.folder'};
5592: if ($folder eq '') {
5593: $folder='default';
5594: }
1.611 raeburn 5595: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5596: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5597: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5598: &checkversions($r,$canedit);
5599: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5600: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5601: &dumpcourse($r);
1.611 raeburn 5602: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5603: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5604: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5605: } else {
1.611 raeburn 5606: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5607: $noendpage = 1;
5608: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5609: if ($redirect) {
5610: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5611: my $container = 'sequence';
5612: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5613: $is_random_order,$container) =
5614: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5615: my (@folders)=split('&',$env{'form.folderpath'});
5616: $env{'form.foldername'}=&unescape(pop(@folders));
5617: my $folder=pop(@folders);
5618: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5619: $folder.'.'.$container);
5620: my $warning;
5621: if ($fatal) {
5622: if ($container eq 'page') {
5623: $warning = &mt('An error occurred retrieving the contents of the current page.');
5624: } else {
5625: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5626: }
5627: } else {
5628: my $url = $redirect;
5629: my $srcfile = $londocroot.$url;
5630: $url =~ s{^/priv/}{/res/};
5631: my $targetfile = $londocroot.$url;
5632: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5633: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5634: $env{'form.folder'} = $folder;
5635: &snapshotbefore();
5636: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5637: my $ext = 'false';
5638: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5639: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5640: ':'.$ext.':normal:res';
5641: push(@LONCAPA::map::order,$newidx);
5642: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5643: 'string_yesno');
5644: &remember_parms($newidx,'hiddenresource','set','yes');
5645: ($errtext,$fatal) =
5646: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5647: &log_differences($plain);
5648: &mark_hash_old();
5649: $r->internal_redirect($redirect);
5650: return OK;
5651: }
1.654 raeburn 5652: } else {
5653: $r->internal_redirect($redirect);
1.606 raeburn 5654: }
5655: }
5656: }
1.445 www 5657: #
5658: # Done catching special calls
1.484 raeburn 5659: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5660: # Get the parameters that may be needed
5661: #
5662: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 5663: ['folderpath','title',
1.519 raeburn 5664: 'forcesupplement','forcestandard',
1.510 raeburn 5665: 'tools','symb','command','supppath']);
1.445 www 5666:
1.635 raeburn 5667: foreach my $item ('forcesupplement','forcestandard','tools') {
5668: next if ($env{'form.'.$item} eq '');
5669: unless ($env{'form.'.$item} eq '1') {
5670: delete($env{'form.'.$item});
5671: }
5672: }
5673:
5674: if ($env{'form.command'}) {
5675: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5676: delete($env{'form.command'});
5677: }
5678: }
5679:
5680: if ($env{'form.symb'}) {
5681: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5682: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5683: delete($env{'form.symb'});
5684: }
5685: }
5686:
1.445 www 5687: # standard=1: this is a "new-style" course with an uploaded map as top level
5688: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5689:
5690: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5691:
1.484 raeburn 5692: # Decide whether this should display supplemental or main content or utilities
1.445 www 5693: # supplementalflag=1: show supplemental documents
5694: # supplementalflag=0: show standard documents
1.484 raeburn 5695: # toolsflag=1: show utilities
1.445 www 5696:
1.561 raeburn 5697: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5698: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5699: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5700: $supplementalflag=0;
5701: }
5702: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5703: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5704: unless ($allowed) { $supplementalflag=1; }
5705: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5706: my $toolsflag=0;
5707: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5708:
1.635 raeburn 5709: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5710: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 5711: }
5712:
1.685 raeburn 5713: my $backto_supppath;
1.635 raeburn 5714: if ($env{'form.supppath'} ne '') {
1.685 raeburn 5715: if ($supplementalflag && $allowed) {
5716: $backto_supppath = &validate_supppath($coursenum,$coursedom);
5717: }
1.635 raeburn 5718: }
5719:
1.329 droeschl 5720: my $script='';
5721: my $showdoc=0;
1.457 raeburn 5722: my $addentries = {};
1.475 raeburn 5723: my $container;
1.329 droeschl 5724: my $containertag;
1.508 raeburn 5725: my $pathitem;
1.598 raeburn 5726: my %ltitools;
1.617 raeburn 5727: my $hiddentop;
1.615 raeburn 5728: my $navmap;
1.617 raeburn 5729: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5730:
1.464 www 5731: # Do we directly jump somewhere?
1.525 raeburn 5732: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5733: if ($env{'form.symb'} ne '') {
1.522 raeburn 5734: $env{'form.folderpath'}=
1.617 raeburn 5735: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5736: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5737: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 5738: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 5739: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5740: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 5741: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 5742: }
1.472 raeburn 5743: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5744: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5745: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5746: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5747: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5748: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5749: } elsif ($env{'form.command'} eq 'contents') {
5750: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5751: } elsif ($env{'form.command'} eq 'home') {
5752: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5753: }
5754:
1.525 raeburn 5755:
1.445 www 5756: # Where do we store these for when we come back?
5757: my $stored_folderpath='docs_folderpath';
5758: if ($supplementalflag) {
5759: $stored_folderpath='docs_sup_folderpath';
5760: }
1.464 www 5761:
1.519 raeburn 5762: # No folderpath, and in edit mode, see if we have something stored
5763: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5764: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5765: {'folderpath' => 'scalar'});
1.615 raeburn 5766:
5767: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5768: if ($supplementalflag) {
5769: undef($env{'form.folderpath'}) if ($1 eq 'default');
5770: } else {
5771: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5772: }
5773: } else {
1.523 raeburn 5774: undef($env{'form.folderpath'});
5775: }
1.677 raeburn 5776: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5777: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 5778: }
1.329 droeschl 5779: }
1.446 www 5780:
5781: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5782: if (!$allowed) {
1.446 www 5783: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5784: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5785: }
5786: }
1.446 www 5787: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5788: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5789: $env{'form.folderpath'} = &supplemental_base()
5790: .'&'.
1.329 droeschl 5791: $env{'form.folderpath'};
5792: }
1.685 raeburn 5793: # If allowed and user's role is not advanced check folderpath is not hidden
5794: my $hidden_and_empty;
1.687 raeburn 5795: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 5796: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 5797: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5798: my $folder = $pathitems[-2];
5799: if ($folder eq '') {
5800: undef($env{'form.folderpath'});
5801: } else {
5802: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 5803: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 5804: $folderurl .= '.page';
5805: } else {
5806: $folderurl .= '.sequence';
5807: }
1.685 raeburn 5808: if ($supplementalflag) {
5809: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
5810: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 5811: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 5812: if (ref($supplemental) eq 'HASH') {
5813: my ($suppmap,$suppmapnum);
5814: if ($folder eq 'supplemental') {
5815: $suppmap = 'default';
5816: $suppmapnum = 0;
5817: } elsif ($folder =~ /^supplemental_(\d+)$/) {
5818: $suppmap = $1;
5819: $suppmapnum = $suppmap;
5820: }
5821: if ($hiddenfolder) {
5822: my $hascontent;
5823: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
5824: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
5825: $hascontent = 1;
5826: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
5827: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
5828: if ($id =~ /^$suppmapnum\:/) {
5829: $hascontent = 1;
5830: last;
5831: }
5832: }
5833: }
5834: last if ($hascontent);
5835: }
5836: unless ($hascontent) {
5837: if ($foldername ne '') {
5838: $hidden_and_empty = $foldername;
5839: } else {
5840: $hidden_and_empty = $folder;
5841: }
5842: }
5843: }
5844: }
5845: } else {
5846: unless (ref($navmap)) {
5847: $navmap = Apache::lonnavmaps::navmap->new();
5848: }
5849: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
5850: $foldername = &HTML::Entities::decode(&unescape($foldername));
5851: if (ref($navmap)) {
5852: if ($hiddenfolder ||
5853: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
5854: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5855: unless (@resources) {
5856: if ($foldername ne '') {
5857: $hidden_and_empty = $foldername;
5858: } else {
5859: $hidden_and_empty = $folder;
5860: }
5861: }
5862: }
5863: }
1.617 raeburn 5864: }
1.685 raeburn 5865: if ($hidden_and_empty ne '') {
5866: splice(@pathitems,-2);
5867: if (@pathitems) {
5868: $env{'form.folderpath'} = join('&',@pathitems);
5869: } else {
5870: undef($env{'form.folderpath'});
1.615 raeburn 5871: }
5872: }
5873: }
5874: }
5875:
1.446 www 5876: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5877: unless ($env{'form.folderpath'}) {
1.446 www 5878: if ($supplementalflag) {
5879: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5880: } elsif ($allowed) {
5881: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5882: }
1.472 raeburn 5883: }
1.446 www 5884:
1.445 www 5885: # Store this
1.484 raeburn 5886: unless ($toolsflag) {
1.615 raeburn 5887: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5888: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5889: {'folderpath' => 'scalar'});
1.510 raeburn 5890: }
1.519 raeburn 5891: my $folderpath;
1.484 raeburn 5892: if ($env{'form.folderpath'}) {
1.519 raeburn 5893: $folderpath = $env{'form.folderpath'};
5894: my (@folders)=split('&',$env{'form.folderpath'});
5895: $env{'form.foldername'}=&unescape(pop(@folders));
5896: if ($env{'form.foldername'} =~ /\:1$/) {
5897: $container = 'page';
5898: } else {
5899: $container = 'sequence';
5900: }
5901: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5902: } else {
1.519 raeburn 5903: if ($env{'form.folder'} eq '' ||
5904: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5905: if ($env{'form.folder'} eq 'supplemental') {
5906: $folderpath=&supplemental_base();
5907: } elsif (!$hiddentop) {
5908: $folderpath='default&'.
5909: &escape(&mt('Main Content').':::::');
5910: }
1.484 raeburn 5911: }
5912: }
1.519 raeburn 5913: $containertag = '<input type="hidden" name="folderpath" value="" />';
5914: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5915: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5916: $showdoc='/'.$1;
5917: }
5918: if ($showdoc) { # got called in sequence from course
5919: $allowed=0;
5920: } else {
1.611 raeburn 5921: if ($canedit) {
1.484 raeburn 5922: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5923: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5924: }
5925: }
1.329 droeschl 5926: }
5927:
1.344 bisitz 5928: # get personal data
1.329 droeschl 5929: my $uname=$env{'user.name'};
5930: my $udom=$env{'user.domain'};
5931: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5932:
5933: if ($allowed) {
1.484 raeburn 5934: if ($toolsflag) {
5935: $script .= &inject_data_js();
5936: my ($home,$other,%outhash)=&authorhosts();
5937: if (!$home && $other) {
5938: my @hosts;
5939: foreach my $aurole (keys(%outhash)) {
5940: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5941: push(@hosts,$outhash{$aurole});
5942: }
5943: }
5944: $script .= &dump_switchserver_js(@hosts);
5945: }
1.458 raeburn 5946: } else {
1.570 raeburn 5947: my $tid = 1;
1.484 raeburn 5948: my @tabids;
5949: if ($supplementalflag) {
1.655 raeburn 5950: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5951: $tid = 2;
1.484 raeburn 5952: } else {
5953: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5954: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5955: unshift(@tabids,'001');
5956: push(@tabids,('dd1','ee1'));
5957: }
1.458 raeburn 5958: }
1.484 raeburn 5959: my $tabidstr = join("','",@tabids);
1.644 raeburn 5960: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600 raeburn 5961: my $posslti = keys(%ltitools);
1.622 raeburn 5962: my $hostname = $r->hostname();
1.606 raeburn 5963: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5964: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5965: &history_tab_js().
5966: &inject_data_js().
1.570 raeburn 5967: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5968: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 5969: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
5970: if ($hidden_and_empty ne '') {
5971: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
5972: $hidden_and_empty);
5973: $onload .= "javascript:alert('".&js_escape($alert)."');";
5974: }
1.484 raeburn 5975: $addentries = {
1.685 raeburn 5976: onload => $onload,
1.484 raeburn 5977: };
1.458 raeburn 5978: }
1.538 raeburn 5979: $script .= &paste_popup_js();
1.501 raeburn 5980: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5981: &mt('Switch server?');
5982:
5983:
1.329 droeschl 5984: }
5985: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5986: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5987: .'// <![CDATA['."\n"
5988: .$script."\n"
5989: .'// ]]>'."\n"
1.595 musolffc 5990: .'</script>'."\n"
5991: .'<script type="text/javascript"
5992: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5993:
5994: # Breadcrumbs
5995: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5996:
5997: if ($showdoc) {
1.682 raeburn 5998: my $args;
5999: if ($supplementalflag) {
1.687 raeburn 6000: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
6001: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.682 raeburn 6002: $args = {'bread_crumbs' => $brcrum};
6003: } else {
6004: $args = {'force_register' => $showdoc};
6005: }
6006: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 6007: } elsif ($toolsflag) {
1.611 raeburn 6008: my ($breadtext,$breadtitle);
1.617 raeburn 6009: $breadtext = "$crstype Editor";
1.611 raeburn 6010: if ($canedit) {
6011: $breadtitle = 'Editing '.$crstype.' Contents';
6012: } else {
6013: $breadtext .= ' (View-only mode)';
6014: $breadtitle = 'Viewing '.$crstype.' Contents';
6015: }
1.571 raeburn 6016: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6017: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 6018: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6019: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6020: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6021: $breadtitle)
1.571 raeburn 6022: );
1.510 raeburn 6023: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 6024: unless ($env{'request.role.adv'}) {
6025: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6026: $r->internal_redirect('/adm/navmaps');
6027: return OK;
6028: }
6029: }
1.510 raeburn 6030: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
6031: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
6032: {'bread_crumbs' => $brcrum,}));
6033: } else {
1.611 raeburn 6034: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 6035: $breadtext = "$crstype Editor";
1.611 raeburn 6036: if ($canedit) {
6037: $breadtitle = 'Editing '.$crstype.' Contents';
6038: $helpitem = 'Docs_Adding_Course_Doc';
6039: } else {
6040: $breadtext .= ' (View-only mode)';
6041: $breadtitle = 'Viewing '.$crstype.' Contents';
6042: $helpitem = 'Docs_Viewing_Course_Doc';
6043: }
1.392 raeburn 6044: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6045: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6046: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 6047: {'add_entries' => $addentries}
6048: )
1.392 raeburn 6049: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6050: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6051: $breadtitle,
6052: $helpitem)
1.392 raeburn 6053: );
6054: }
1.364 bisitz 6055:
1.329 droeschl 6056: my %allfiles = ();
6057: my %codebase = ();
1.440 raeburn 6058: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 6059: if ($canedit) {
1.684 raeburn 6060: undef($suppchanges);
1.329 droeschl 6061: if (($env{'form.uploaddoc.filename'}) &&
6062: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6063: my $context = $1;
6064: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6065: undef($hadchanges);
1.440 raeburn 6066: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 6067: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 6068: undef($navmap);
1.329 droeschl 6069: if ($hadchanges) {
6070: &mark_hash_old();
6071: }
1.684 raeburn 6072: if ($suppchanges) {
6073: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6074: undef($suppchanges);
6075: }
1.440 raeburn 6076: $r->print($upload_output);
6077: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6078: # Process file upload - phase two - upload embedded objects
6079: $uploadphase = 'check_embedded';
6080: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6081: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6082: $env{'form.newidx'});
6083: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6084: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6085: my ($destination,$dir_root) = &embedded_destination();
6086: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6087: my $actionurl = '/adm/coursedocs';
1.630 raeburn 6088: my ($result,$flag) =
1.440 raeburn 6089: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6090: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6091: $actionurl);
6092: $r->print($result.&return_to_editor());
6093: } elsif ($env{'form.phase'} eq 'check_embedded') {
6094: # Process file upload - phase three - modify references in HTML file
6095: $uploadphase = 'modified_orightml';
6096: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6097: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6098: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 6099: my $result =
1.482 raeburn 6100: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6101: $docuname,$docudom,undef,
6102: $dir_root);
1.630 raeburn 6103: $r->print($result.&return_to_editor());
1.476 raeburn 6104: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6105: $uploadphase = 'decompress_phase_one';
6106: $r->print(&decompression_phase_one().
6107: &return_to_editor());
6108: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6109: $uploadphase = 'decompress_phase_two';
6110: $r->print(&decompression_phase_two().
6111: &return_to_editor());
1.329 droeschl 6112: }
6113: }
6114:
1.484 raeburn 6115: if ($allowed && $toolsflag) {
6116: $r->print(&startContentScreen('tools'));
1.611 raeburn 6117: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 6118: $r->print(&endContentScreen());
6119: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6120: # -----------------------------------------------------------------------------
6121: my %lt=&Apache::lonlocal::texthash(
6122: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 6123: 'upfi' => 'Upload File',
1.553 raeburn 6124: 'upld' => 'Upload Content',
1.329 droeschl 6125: 'srch' => 'Search',
6126: 'impo' => 'Import',
1.487 raeburn 6127: 'lnks' => 'Import from Stored Links',
1.502 raeburn 6128: 'impm' => 'Import from Assembled Map',
1.630 raeburn 6129: 'imcr' => 'Import from Course Resources',
1.598 raeburn 6130: 'extr' => 'External Resource',
6131: 'extt' => 'External Tool',
1.329 droeschl 6132: 'selm' => 'Select Map',
6133: 'load' => 'Load Map',
6134: 'newf' => 'New Folder',
6135: 'newp' => 'New Composite Page',
6136: 'syll' => 'Syllabus',
1.425 raeburn 6137: 'navc' => 'Table of Contents',
1.343 biermanm 6138: 'sipa' => 'Simple Course Page',
1.329 droeschl 6139: 'sipr' => 'Simple Problem',
1.630 raeburn 6140: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 6141: 'stpr' => 'Standard Problem',
6142: 'news' => 'New sub-directory',
6143: 'crpr' => 'Create Problem',
1.689 raeburn 6144: 'swit' => 'Switch Server',
1.329 droeschl 6145: 'drbx' => 'Drop Box',
1.451 www 6146: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6147: 'bull' => 'Discussion Board',
1.347 weissno 6148: 'mypi' => 'My Personal Information Page',
1.353 weissno 6149: 'grpo' => 'Group Portfolio',
1.329 droeschl 6150: 'rost' => 'Course Roster',
1.528 raeburn 6151: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 6152: 'imsf' => 'IMS Upload',
6153: 'imsl' => 'Upload IMS package',
1.501 raeburn 6154: 'cms' => 'Origin of IMS package',
6155: 'se' => 'Select',
1.329 droeschl 6156: 'file' => 'File',
6157: 'title' => 'Title',
1.606 raeburn 6158: 'addp' => 'Add Placeholder to course?',
6159: 'uste' => 'Use Template?',
6160: 'fnam' => 'File Name:',
6161: 'loca' => 'Location:',
6162: 'dire' => 'Directory:',
6163: 'cate' => 'Category:',
6164: 'tmpl' => 'Template:',
1.329 droeschl 6165: 'comment' => 'Comment',
1.403 raeburn 6166: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 6167: 'bb5' => 'Blackboard 5',
6168: 'bb6' => 'Blackboard 6',
6169: 'angel5' => 'ANGEL 5.5',
6170: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 6171: 'yes' => 'Yes',
6172: 'no' => 'No',
1.618 raeburn 6173: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 6174: );
1.329 droeschl 6175: # -----------------------------------------------------------------------------
1.595 musolffc 6176:
6177: # Calculate free quota space for a user or course. A javascript function checks
6178: # file size to determine if upload should be allowed.
6179: my $quotatype = 'unofficial';
6180: if ($crstype eq 'Community') {
1.601 raeburn 6181: $quotatype = 'community';
6182: } elsif ($crstype eq 'Placement') {
6183: $quotatype = 'placement';
1.595 musolffc 6184: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6185: $quotatype = 'official';
6186: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6187: $quotatype = 'textbook';
6188: }
6189: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6190: 'course',$quotatype); # expressed in MB
6191: my $current_disk_usage = 0;
6192: foreach my $subdir ('docs','supplemental') {
6193: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6194: "userfiles/$subdir",1); # expressed in kB
6195: }
6196: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 6197: my $usage = $current_disk_usage/1024; # in MB
6198: my $quota = $disk_quota;
6199: my $percent;
6200: if ($disk_quota == 0) {
6201: $percent = 100.0;
6202: } else {
1.619 raeburn 6203: $percent = 100*($usage/$disk_quota);
1.605 raeburn 6204: }
6205: $usage = sprintf("%.2f",$usage);
6206: $quota = sprintf("%.2f",$quota);
6207: $percent = sprintf("%.0f",$percent);
6208: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6209: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6210:
1.329 droeschl 6211: my $fileupload=(<<FIUP);
1.605 raeburn 6212: $quotainfo
1.329 droeschl 6213: $lt{'file'}:<br />
1.662 raeburn 6214: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663 raeburn 6215: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6216: FIUP
6217:
6218: my $checkbox=(<<CHBO);
6219: <!-- <label>$lt{'parse'}?
6220: <input type="checkbox" name="parserflag" />
6221: </label> -->
6222: <label>
1.611 raeburn 6223: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6224: </label>
6225: CHBO
1.501 raeburn 6226: my $imsfolder = $env{'form.folder'};
6227: if ($imsfolder eq '') {
6228: $imsfolder = 'default';
6229: }
6230: my $imspform=(<<IMSFORM);
6231: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6232: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6233: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6234: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6235: <legend>$lt{'imsf'}</legend>
6236: $fileupload
6237: <br />
6238: <p>
6239: $lt{'cms'}:
1.611 raeburn 6240: <select name="source" $disabled>
1.501 raeburn 6241: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6242: <option value="bb5">$lt{'bb5'}</option>
6243: <option value="bb6">$lt{'bb6'}</option>
6244: <option value="angel5">$lt{'angel5'}</option>
6245: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6246: </select>
6247: <input type="hidden" name="folder" value="$imsfolder" />
6248: </p>
6249: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6250: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6251: </fieldset>
6252: </form>
6253: IMSFORM
1.329 droeschl 6254:
6255: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6256: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6257: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6258: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6259: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6260: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6261: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6262: $fileupload
1.329 droeschl 6263: <br />
6264: $lt{'title'}:<br />
1.611 raeburn 6265: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6266: $pathitem
1.329 droeschl 6267: <input type="hidden" name="cmd" value="upload_default" />
6268: <br />
1.458 raeburn 6269: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6270: $checkbox
6271: </span>
1.501 raeburn 6272: <br clear="all" />
1.611 raeburn 6273: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6274: </fieldset>
6275: </form>
1.383 tempelho 6276: FUFORM
1.329 droeschl 6277:
1.611 raeburn 6278: my $mapimportjs;
6279: if ($canedit) {
6280: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6281: } else {
6282: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6283: }
1.502 raeburn 6284: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6285: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6286: $lt{'impm'}</a>$help{'Load_Map'}
6287: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6288: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6289: <legend>$lt{'impm'}</legend>
1.371 tempelho 6290: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6291: $lt{'copm'}<br />
6292: <span class="LC_nobreak">
6293: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6294: onfocus="this.blur();$mapimportjs" $disabled />
6295: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6296: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6297: </fieldset>
6298: </form>
6299:
1.383 tempelho 6300: SEDFFORM
1.606 raeburn 6301: my $importcrsresform;
1.608 raeburn 6302: my ($numdirs,$pickfile) =
1.690 raeburn 6303: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
1.608 raeburn 6304: "resize_scrollbox('contentscroll','1','0');",
6305: undef,'res');
1.606 raeburn 6306: if ($pickfile) {
6307: $importcrsresform=(<<CRSFORM);
1.690 raeburn 6308: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 6309: $lt{'imcr'}</a>$help{'Course_Resources'}
6310: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6311: <fieldset id="importcrsresform" style="display: none;">
6312: <legend>$lt{'imcr'}</legend>
6313: <input type="hidden" name="active" value="bb" />
6314: $pickfile
6315: <p>
1.611 raeburn 6316: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 6317: </p>
6318: <input type="hidden" name="importdetail" value="" />
1.690 raeburn 6319: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.606 raeburn 6320: </fieldset>
6321: </form>
6322: CRSFORM
6323: }
6324:
1.611 raeburn 6325: my $fromstoredjs;
6326: if ($canedit) {
6327: $fromstoredjs = 'open_StoredLinks_Import()';
6328: } else {
6329: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6330: }
6331:
1.502 raeburn 6332: my @importpubforma = (
1.508 raeburn 6333: { '<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 6334: { '<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 6335: { '<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 6336: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6337: );
6338: if ($pickfile) {
1.690 raeburn 6339: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\');" />' => $importcrsresform});
1.606 raeburn 6340: }
1.502 raeburn 6341: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6342: my $extresourcesform =
6343: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6344: $help{'Adding_External_Resource'},
6345: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6346: my $exttoolform =
6347: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6348: $help{'Adding_External_Tool'},undef,
6349: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6350: \%ltitools,$disabled);
1.329 droeschl 6351: if ($allowed) {
1.492 raeburn 6352: my $folder = $env{'form.folder'};
6353: if ($folder eq '') {
6354: $folder='default';
6355: }
1.615 raeburn 6356: if ($canedit) {
6357: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6358: if ($output) {
6359: $r->print($output);
6360: }
1.538 raeburn 6361: }
1.337 ehlerst 6362: $r->print(<<HIDDENFORM);
6363: <form name="renameform" method="post" action="/adm/coursedocs">
6364: <input type="hidden" name="title" />
6365: <input type="hidden" name="cmd" />
6366: <input type="hidden" name="markcopy" />
6367: <input type="hidden" name="copyfolder" />
6368: $containertag
6369: </form>
1.633 raeburn 6370: <form name="aliasform" method="post" action="/adm/coursedocs">
6371: <input type="hidden" name="alias" />
6372: <input type="hidden" name="cmd" />
6373: $containertag
6374: </form>
1.484 raeburn 6375:
1.337 ehlerst 6376: HIDDENFORM
1.508 raeburn 6377: $r->print(&makesimpleeditform($pathitem)."\n".
6378: &makedocslogform($pathitem."\n".
1.484 raeburn 6379: '<input type="hidden" name="folder" value="'.
6380: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6381: }
1.442 www 6382:
6383: # Generate the tabs
1.510 raeburn 6384: my ($mode,$needs_end);
1.472 raeburn 6385: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6386: my @folders = split('&',$env{'form.folderpath'});
6387: unless (@folders > 2) {
6388: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6389: $needs_end = 1;
6390: }
1.472 raeburn 6391: } else {
1.484 raeburn 6392: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6393: $needs_end = 1;
1.472 raeburn 6394: }
1.443 www 6395:
1.442 www 6396: #
1.622 raeburn 6397: my $hostname = $r->hostname();
1.442 www 6398: my $savefolderpath;
6399:
1.395 raeburn 6400: if ($allowed) {
1.329 droeschl 6401: my $folder=$env{'form.folder'};
1.615 raeburn 6402: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6403: $folder='default';
1.356 tempelho 6404: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6405: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6406: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6407: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6408: }
6409: my $postexec='';
6410: if ($folder eq 'default') {
1.653 raeburn 6411: my $windowname = 'loncapaclient';
6412: if ($env{'request.lti.login'}) {
6413: $windowname .= 'lti';
6414: }
1.372 bisitz 6415: $r->print('<script type="text/javascript">'."\n"
6416: .'// <![CDATA['."\n"
1.653 raeburn 6417: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6418: .'// ]]>'."\n"
6419: .'</script>'."\n"
1.369 bisitz 6420: );
1.329 droeschl 6421: } else {
6422: #$postexec='self.close();';
6423: }
1.504 raeburn 6424: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6425: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6426: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6427:
6428: my $newnavform=(<<NNFORM);
6429: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6430: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6431: $pathitem
1.329 droeschl 6432: <input type="hidden" name="importdetail"
6433: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6434: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6435: $help{'Navigate_Content'}
6436: </form>
6437: NNFORM
6438: my $newsmppageform=(<<NSPFORM);
6439: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6440: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6441: $pathitem
1.329 droeschl 6442: <input type="hidden" name="importdetail" value="" />
1.423 onken 6443: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6444: $help{'Simple Page'}
1.329 droeschl 6445: </form>
6446: NSPFORM
6447:
6448: my $newsmpproblemform=(<<NSPROBFORM);
6449: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6450: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6451: $pathitem
1.329 droeschl 6452: <input type="hidden" name="importdetail" value="" />
1.423 onken 6453: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6454: $help{'Simple_Problem'}
1.329 droeschl 6455: </form>
6456:
6457: NSPROBFORM
6458:
6459: my $newdropboxform=(<<NDBFORM);
6460: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6461: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6462: $pathitem
1.329 droeschl 6463: <input type="hidden" name="importdetail" value="" />
1.423 onken 6464: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6465: $help{'Dropbox'}
1.344 bisitz 6466: </form>
1.329 droeschl 6467: NDBFORM
6468:
6469: my $newexuploadform=(<<NEXUFORM);
6470: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6471: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6472: $pathitem
1.329 droeschl 6473: <input type="hidden" name="importdetail" value="" />
1.423 onken 6474: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6475: $help{'Score_Upload_Form'}
6476: </form>
6477: NEXUFORM
6478:
6479: my $newbulform=(<<NBFORM);
6480: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6481: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6482: $pathitem
1.329 droeschl 6483: <input type="hidden" name="importdetail" value="" />
1.423 onken 6484: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6485: $help{'Bulletin Board'}
6486: </form>
6487: NBFORM
6488:
6489: my $newaboutmeform=(<<NAMFORM);
6490: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6491: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6492: $pathitem
1.329 droeschl 6493: <input type="hidden" name="importdetail"
6494: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6495: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6496: $help{'My Personal Information Page'}
1.329 droeschl 6497: </form>
6498: NAMFORM
6499:
6500: my $newaboutsomeoneform=(<<NASOFORM);
6501: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6502: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6503: $pathitem
1.329 droeschl 6504: <input type="hidden" name="importdetail" value="" />
1.423 onken 6505: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6506: </form>
6507: NASOFORM
6508:
6509: my $newrosterform=(<<NROSTFORM);
6510: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6511: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6512: $pathitem
1.329 droeschl 6513: <input type="hidden" name="importdetail"
6514: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6515: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6516: $help{'Course_Roster'}
1.329 droeschl 6517: </form>
6518: NROSTFORM
6519:
1.534 raeburn 6520: my $newwebpage;
6521: if ($folder =~ /^default_?(\d*)$/) {
6522: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6523: if ($1) {
6524: $newwebpage .= $1;
6525: } else {
6526: $newwebpage .= 'default';
6527: }
6528: $newwebpage .= '/new.html';
6529: }
6530: my $newwebpageform =(<<NWEBFORM);
6531: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6532: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6533: $pathitem
6534: <input type="hidden" name="importdetail" value="$newwebpage" />
6535: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6536: $help{'Web_Page'}
1.534 raeburn 6537: </form>
6538: NWEBFORM
1.604 raeburn 6539:
1.606 raeburn 6540: my @ids=&Apache::lonnet::current_machine_ids();
1.691 raeburn 6541: my $machines_str = "'".join("','",@ids)."'";
6542: my (%is_home,%toppath,$rolehomes);
1.606 raeburn 6543: if ($env{'user.author'}) {
6544: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
1.691 raeburn 6545: $is_home{'author'} = 1;
1.606 raeburn 6546: }
1.691 raeburn 6547: $rolehomes = '<input type="hidden" id="rolehome_author" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 6548: }
6549: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6550: ['active'],['ca','aa']);
1.691 raeburn 6551: my %by_roletype;
1.606 raeburn 6552: if (keys(%roleshash)) {
6553: foreach my $entry (keys(%roleshash)) {
6554: my ($auname,$audom,$roletype) = split(/:/,$entry);
6555: my $key = $entry;
6556: $key =~ s/:/___/g;
1.691 raeburn 6557: my $author = $auname.'___'.$audom;
6558: $by_roletype{$roletype}{$author} = 1;
1.606 raeburn 6559: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
1.691 raeburn 6560: $toppath{$author} = "/priv/$audom/$auname";
6561: if (grep(/^\Q$rolehome\E$/,@ids)) {
6562: $is_home{$author} = 1;
1.606 raeburn 6563: }
1.691 raeburn 6564: $rolehomes .= '<input type="hidden" id="rolehome_coauthor_'.$roletype.'_'.$audom.'/'.$auname.'" '.
6565: 'name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 6566: }
1.691 raeburn 6567: }
6568: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6569: if (grep(/^\Q$crshome\E$/,@ids)) {
6570: $is_home{'course'} = 1;
6571: }
6572: $rolehomes .= '<input type="hidden" id="rolehome_course" name="rolehome_course" value="'.$crshome.'" />'."\n";
6573: my $pickdir = $lt{'loca'}.
6574: '<select name="authorrole" onchange="populateDirSelects(this.form,'."'authorrole','authorpath'".',1,1,0);">'."\n".
6575: '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
6576: if ($env{'user.author'}) {
6577: $pickdir .= '<option value="author">'.&Apache::lonnet::plaintext('au').'</option>'."\n";
6578: }
6579: if (keys(%by_roletype)) {
6580: foreach my $possrole ('ca','aa') {
6581: if (ref($by_roletype{$possrole}) eq 'HASH') {
6582: my $roletitle = &Apache::lonnet::plaintext($possrole);
6583: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6584: my ($none,$where,$auname,$audom) = split(/\//,$toppath{$author});
6585: $pickdir .= '<option value="'.$author.'___'.$possrole.'">'.
6586: $roletitle." ($audom/$auname)</option>\n";
1.606 raeburn 6587: }
6588: }
6589: }
6590: }
1.691 raeburn 6591: $pickdir .= '<option value="course">'.&mt('Course Resource').'</option>'."\n".
6592: '</select><br />'."\n".
6593: $lt{'dire'}.
6594: '<select name="authorpath" onchange="toggleCrsResTitle();">'.
6595: '<option value=""></option>'.
6596: '</select><br />'."\n";
1.606 raeburn 6597:
6598: my %seltemplate_menus;
6599: my @files = &Apache::lonhomework::get_template_list('problem');
6600: my @noexamplelink = ('blank.problem','blank.library','script.library');
6601: my $currentcategory = '';
6602: my @ordered = ('');
6603: my %templatehelp;
6604: my $defcategory = '';
6605: my @catorder = ($defcategory);
6606: $seltemplate_menus{$defcategory}->{'order'} = [''];
6607: $seltemplate_menus{$defcategory}->{'text'} = '';
6608: foreach my $file (@files) {
6609: if (ref($file) eq 'ARRAY') {
6610: my ($path,$title,$category,$help) = @{$file};
6611: next if ($title !~ /\S/);
6612: if (&js_escape($category) ne $currentcategory) {
6613: $currentcategory = &js_escape($category);
6614: push(@catorder,&js_escape($currentcategory));
6615: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6616: $seltemplate_menus{$currentcategory}->{'default'} = '';
6617: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6618: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6619: }
6620: if ($path) {
6621: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6622: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6623: if ($help) {
6624: $templatehelp{$path} = $help;
6625: }
6626: }
6627: }
6628: }
6629:
6630: my $templates = $lt{'cate'}.' '.
6631: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6632: $defcategory,'tempcategory','template',
6633: \%seltemplate_menus,\@catorder,
6634: "resize_scrollbox('contentscroll','1','0');",
6635: "toggleExampleText();",'template').'<br />';
6636: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6637: '<span id="newresexample">'.&mt('Example').'<span></a>';
6638: my $crsresform=(<<RESFORM);
1.691 raeburn 6639: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res');">
1.606 raeburn 6640: $lt{'stpr'}</a>$help{'Course_Resource'}
6641: <form action="/adm/coursedocs" method="post" name="courseresform">
6642: <fieldset id="crsresform" style="display:none;">
6643: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6644: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6645: <p>
6646: $pickdir
1.691 raeburn 6647: <div id="newstdproblem" style="display:none;">
1.606 raeburn 6648: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6649: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6650:
1.611 raeburn 6651: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6652: </span><span id="newsubdir"></span>
6653: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6654: </p>
6655: $lt{'fnam'}
1.611 raeburn 6656: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6657: <p>
1.691 raeburn 6658: <div id="newresource" style="display:none">
1.606 raeburn 6659: $lt{'addp'}
1.611 raeburn 6660: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6661: $lt{'no'}</label>
1.611 raeburn 6662: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6663: $lt{'yes'}</label>
6664: <span id="newrestitle"></span>
1.611 raeburn 6665: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6666: </div>
6667: </p>
6668: <p>
6669: $lt{'uste'}
1.611 raeburn 6670: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6671: $lt{'no'}</label>
1.611 raeburn 6672: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6673: $lt{'yes'}</label>
6674: <div id="newrestemplate" style="display:none">
6675: $templates
6676: $templatepreview
6677: </div>
6678: </p>
6679: <span class="LC_nobreak">
6680: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6681: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6682: </span>
1.689 raeburn 6683: </div>
1.691 raeburn 6684: <div id="stdprobswitch" style="display:none;">
1.689 raeburn 6685: $rolehomes
6686: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
6687: </div>
1.606 raeburn 6688: </fieldset>
6689: </form>
6690:
6691: RESFORM
1.534 raeburn 6692:
1.342 ehlerst 6693: my $specialdocumentsform;
1.383 tempelho 6694: my @specialdocumentsforma;
1.451 www 6695: my $gradingform;
6696: my @gradingforma;
6697: my $communityform;
6698: my @communityforma;
1.351 ehlerst 6699: my $newfolderform;
1.390 tempelho 6700: my $newfolderb;
1.342 ehlerst 6701:
1.451 www 6702: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6703:
1.329 droeschl 6704: my $newpageform=(<<NPFORM);
6705: <form action="/adm/coursedocs" method="post" name="newpage">
6706: <input type="hidden" name="folderpath" value="$path" />
6707: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6708: <input type="hidden" name="active" value="ee" />
1.423 onken 6709: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6710: $help{'Adding_Pages'}
1.329 droeschl 6711: </form>
6712: NPFORM
1.390 tempelho 6713:
6714:
1.351 ehlerst 6715: $newfolderform=(<<NFFORM);
1.329 droeschl 6716: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6717: $pathitem
1.329 droeschl 6718: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6719: <input type="hidden" name="active" value="" />
1.422 onken 6720: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6721: </form>
6722: NFFORM
6723:
6724: my $newsylform=(<<NSYLFORM);
6725: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6726: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6727: $pathitem
1.329 droeschl 6728: <input type="hidden" name="importdetail"
6729: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6730: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6731: $help{'Syllabus'}
1.383 tempelho 6732:
1.329 droeschl 6733: </form>
6734: NSYLFORM
1.364 bisitz 6735:
1.329 droeschl 6736: my $newgroupfileform=(<<NGFFORM);
6737: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6738: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6739: $pathitem
1.329 droeschl 6740: <input type="hidden" name="importdetail"
6741: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6742: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6743: $help{'Group Portfolio'}
1.329 droeschl 6744: </form>
6745: NGFFORM
1.672 raeburn 6746: if ($container eq 'page') {
6747: @specialdocumentsforma=(
6748: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6749: );
6750: } else {
6751: @specialdocumentsforma=(
1.421 onken 6752: {'<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 6753: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6754: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6755: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6756: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 6757: );
6758: }
1.451 www 6759: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6760:
1.655 raeburn 6761: my @external = (
6762: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6763: );
1.598 raeburn 6764: if (keys(%ltitools)) {
1.655 raeburn 6765: push(@external,
6766: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6767: );
1.598 raeburn 6768: }
1.655 raeburn 6769: my $externalform = &create_form_ul(&create_list_elements(@external));
6770:
6771: my @importdoc = ();
1.519 raeburn 6772: unless ($container eq 'page') {
6773: push(@importdoc,
6774: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6775: );
6776: }
6777: push(@importdoc,
1.558 raeburn 6778: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6779: );
1.501 raeburn 6780: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6781:
1.451 www 6782: @gradingforma=(
6783: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6784: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6785: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.691 raeburn 6786: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\');" />'=>$crsresform},
1.451 www 6787: );
6788: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6789:
6790: @communityforma=(
6791: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6792: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6793: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6794: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6795: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6796: );
6797: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6798:
1.330 tempelho 6799: my %orderhash = (
1.553 raeburn 6800: 'aa' => ['Upload',$fileuploadform],
6801: 'bb' => ['Import',$importpubform],
1.655 raeburn 6802: 'cc' => ['External',$externalform],
6803: 'dd' => ['Grading',$gradingform],
1.673 raeburn 6804: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 6805: );
1.519 raeburn 6806: unless ($container eq 'page') {
1.434 raeburn 6807: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6808: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 6809: }
6810:
1.341 ehlerst 6811: $hadchanges=0;
1.484 raeburn 6812: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6813: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6814: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6815: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6816: undef($navmap);
1.443 www 6817: if ($error) {
6818: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6819: }
1.639 raeburn 6820: if ($hadchanges) {
6821: unless (&is_hash_old()) {
1.638 raeburn 6822: &mark_hash_old();
6823: }
6824: }
1.341 ehlerst 6825:
1.443 www 6826: &changewarning($r,'');
6827: }
1.458 raeburn 6828: }
1.442 www 6829:
1.443 www 6830: # Supplemental documents start here
6831:
1.329 droeschl 6832: my $folder=$env{'form.folder'};
1.443 www 6833: unless ($supplementalflag) {
1.329 droeschl 6834: $folder='supplemental';
6835: }
1.685 raeburn 6836: if (($folder eq 'supplemental') &&
1.329 droeschl 6837: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6838: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6839: } elsif ($allowed) {
1.356 tempelho 6840: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6841: }
1.508 raeburn 6842: $pathitem = '<input type="hidden" name="folderpath" value="'.
6843: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6844: if ($allowed) {
6845: my $folderseq=
1.504 raeburn 6846: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6847:
6848: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6849: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6850: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6851: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6852: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6853: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6854: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6855: $fileupload
6856: <br />
6857: <br />
6858: <span class="LC_nobreak">
6859: $checkbox
6860: </span>
6861: <br /><br />
6862: $lt{'comment'}:<br />
1.383 tempelho 6863: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6864: <br />
1.508 raeburn 6865: $pathitem
1.329 droeschl 6866: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6867: <input type='submit' value="$lt{'upld'}" />
6868: </form>
1.329 droeschl 6869: SUPDOCFORM
6870:
6871: my $supnewfolderform=(<<SNFFORM);
6872: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6873: <input type="hidden" name="active" value="" />
1.508 raeburn 6874: $pathitem
1.329 droeschl 6875: <input type="hidden" name="importdetail" value="" />
1.423 onken 6876: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6877: $help{'Adding_Folders'}
1.329 droeschl 6878: </form>
6879: SNFFORM
1.383 tempelho 6880:
1.510 raeburn 6881: my $supextform =
6882: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6883: $help{'Adding_External_Resource'},
6884: undef,undef,undef,undef,undef,undef,
6885: $disabled);
1.329 droeschl 6886:
1.598 raeburn 6887: my $supexttoolform =
6888: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6889: $help{'Adding_External_Tool'},
6890: undef,undef,'tool',$coursedom,
1.611 raeburn 6891: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6892:
1.329 droeschl 6893: my $supnewsylform=(<<SNSFORM);
6894: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6895: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6896: $pathitem
1.329 droeschl 6897: <input type="hidden" name="importdetail"
6898: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6899: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6900: $help{'Syllabus'}
6901: </form>
6902: SNSFORM
6903:
6904: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6905: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6906: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6907: $pathitem
1.329 droeschl 6908: <input type="hidden" name="importdetail"
6909: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6910: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6911: $help{'My Personal Information Page'}
1.329 droeschl 6912: </form>
6913: SNAMFORM
6914:
1.534 raeburn 6915: my $supwebpage;
6916: if ($folder =~ /^supplemental_?(\d*)$/) {
6917: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6918: if ($1) {
6919: $supwebpage .= $1;
6920: } else {
6921: $supwebpage .= 'default';
6922: }
6923: $supwebpage .= '/new.html';
6924: }
6925: my $supwebpageform =(<<SWEBFORM);
6926: <form action="/adm/coursedocs" method="post" name="supwebpage">
6927: <input type="hidden" name="active" value="cc" />
6928: $pathitem
6929: <input type="hidden" name="importdetail" value="$supwebpage" />
6930: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6931: $help{'Web_Page'}
1.534 raeburn 6932: </form>
6933: SWEBFORM
6934:
1.333 muellerd 6935:
1.383 tempelho 6936: my @specialdocs = (
1.618 raeburn 6937: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6938: =>$supnewsylform},
1.611 raeburn 6939: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6940: =>$supnewaboutmeform},
1.534 raeburn 6941: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6942:
1.383 tempelho 6943: );
1.655 raeburn 6944: my @supexternal = (
6945: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6946: =>$supextform});
1.598 raeburn 6947: if (keys(%ltitools)) {
1.655 raeburn 6948: push(@supexternal,
6949: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 6950: =>$supexttoolform});
6951: }
1.655 raeburn 6952: my @supimportdoc = (
1.598 raeburn 6953: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6954: =>$supupdocform},
1.598 raeburn 6955: );
1.501 raeburn 6956:
6957: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6958: my %suporderhash = (
1.390 tempelho 6959: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 6960: 'dd' => ['Upload',$supupdocform],
6961: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 6962: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6963: );
1.443 www 6964: if ($supplementalflag) {
1.682 raeburn 6965: $suppchanges = 0;
6966: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6967: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6968: \%ltitools,$canedit,$hostname);
6969: if ($error) {
6970: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6971: }
6972: if ($suppchanges) {
1.684 raeburn 6973: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 6974: undef($suppchanges);
6975: }
1.393 raeburn 6976: }
1.443 www 6977: } elsif ($supplementalflag) {
1.458 raeburn 6978: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 6979: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
6980: $hostname);
1.393 raeburn 6981: if ($error) {
6982: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6983: }
1.393 raeburn 6984: }
1.389 tempelho 6985:
1.510 raeburn 6986: if ($needs_end) {
6987: $r->print(&endContentScreen());
6988: }
1.383 tempelho 6989:
1.329 droeschl 6990: if ($allowed) {
6991: $r->print('
6992: <form method="post" name="extimport" action="/adm/coursedocs">
6993: <input type="hidden" name="title" />
6994: <input type="hidden" name="url" />
6995: <input type="hidden" name="useform" />
6996: <input type="hidden" name="residx" />
6997: </form>');
6998: }
1.484 raeburn 6999: } elsif ($showdoc) {
1.329 droeschl 7000: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 7001: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 7002: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7003: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7004: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7005: }
7006: }
1.630 raeburn 7007: unless ($noendpage) {
1.606 raeburn 7008: $r->print(&Apache::loncommon::end_page());
7009: }
1.329 droeschl 7010: return OK;
1.364 bisitz 7011: }
1.329 droeschl 7012:
1.440 raeburn 7013: sub embedded_form_elems {
7014: my ($phase,$primaryurl,$newidx) = @_;
7015: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 7016: $newidx =~s /\D+//g;
1.440 raeburn 7017: return <<STATE;
7018: <input type="hidden" name="folderpath" value="$folderpath" />
7019: <input type="hidden" name="cmd" value="upload_embedded" />
7020: <input type="hidden" name="newidx" value="$newidx" />
7021: <input type="hidden" name="phase" value="$phase" />
7022: <input type="hidden" name="primaryurl" value="$primaryurl" />
7023: STATE
7024: }
7025:
7026: sub embedded_destination {
7027: my $folder=$env{'form.folder'};
7028: my $destination = 'docs/';
7029: if ($folder =~ /^supplemental/) {
7030: $destination = 'supplemental/';
7031: }
7032: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7033: $destination .= 'default/';
7034: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7035: $destination .= $2.'/';
7036: }
1.634 raeburn 7037: my $newidx = $env{'form.newidx'};
7038: $newidx =~s /\D+//g;
7039: if ($newidx) {
7040: $destination .= $newidx;
7041: }
1.440 raeburn 7042: my $dir_root = '/userfiles';
7043: return ($destination,$dir_root);
7044: }
7045:
7046: sub return_to_editor {
7047: my $actionurl = '/adm/coursedocs';
7048: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7049: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7050: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7051: '</a></p>';
7052: }
7053:
1.476 raeburn 7054: sub decompression_info {
7055: my ($destination,$dir_root) = &embedded_destination();
7056: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7057: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7058: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7059: my $container='sequence';
1.480 raeburn 7060: my ($pathitem,$hiddenelem);
1.583 raeburn 7061: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 7062: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7063: $container='page';
7064: }
1.480 raeburn 7065: unshift(@hiddens,$pathitem);
7066: foreach my $item (@hiddens) {
1.634 raeburn 7067: if ($item eq 'newidx') {
7068: next if ($env{'form.'.$item} =~ /\D/);
7069: }
1.480 raeburn 7070: if ($env{'form.'.$item}) {
7071: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 7072: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7073: }
1.477 raeburn 7074: }
1.476 raeburn 7075: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7076: $hiddenelem);
7077: }
7078:
7079: sub decompression_phase_one {
7080: my ($dir,$file,$warning,$error,$output);
7081: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7082: &decompression_info();
1.490 raeburn 7083: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7084: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7085: } else {
7086: my $file = $1;
1.630 raeburn 7087: $output =
1.481 raeburn 7088: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7089: $destination,$dir_root,
7090: $hiddenelem);
7091: if ($env{'form.autoextract_camtasia'}) {
7092: $output .= &remove_archive($docudom,$docuname,$container);
7093: }
1.476 raeburn 7094: }
7095: if ($error) {
7096: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7097: $error.'</p>'."\n";
7098: }
7099: if ($warning) {
7100: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7101: }
7102: return $output;
7103: }
7104:
7105: sub decompression_phase_two {
7106: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7107: &decompression_info();
1.481 raeburn 7108: my $output;
1.480 raeburn 7109: if ($env{'form.archivedelete'}) {
1.481 raeburn 7110: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7111: }
7112: $output .=
1.481 raeburn 7113: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7114: $destination,$dir_root,$hiddenelem);
7115: return $output;
7116: }
7117:
1.480 raeburn 7118: sub remove_archive {
7119: my ($docudom,$docuname,$container) = @_;
7120: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7121: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7122: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7123: if ($fatal) {
7124: if ($container eq 'page') {
7125: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7126: } else {
7127: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7128: }
1.583 raeburn 7129: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7130: } else {
7131: my $currcmd = $env{'form.cmd'};
7132: my $position = $env{'form.position'};
1.583 raeburn 7133: my $archiveidx = $position;
1.563 raeburn 7134: if ($position > 0) {
1.583 raeburn 7135: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7136: $archiveidx = $position-1;
7137: }
7138: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7139: my ($title,$url,@rrest) =
1.583 raeburn 7140: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7141: if ($url eq $env{'form.archiveurl'}) {
7142: if (&handle_edit_cmd($docuname,$docudom)) {
7143: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 7144: if ($suppchanges) {
7145: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7146: undef($suppchanges);
7147: }
1.583 raeburn 7148: if ($fatal) {
7149: if ($container eq 'page') {
7150: $delwarning = &mt('An error occurred updating the contents of the current page.');
7151: } else {
7152: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7153: }
1.480 raeburn 7154: } else {
1.583 raeburn 7155: $delresult = &mt('Archive file removed.');
1.480 raeburn 7156: }
7157: }
1.583 raeburn 7158: } else {
7159: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7160: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7161: }
7162: }
7163: $env{'form.cmd'} = $currcmd;
7164: }
7165: if ($delwarning) {
7166: $output = '<p class="LC_warning">'.
7167: $delwarning.
7168: '</p>';
7169: }
7170: if ($delresult) {
7171: $output .= '<p class="LC_info">'.
7172: $delresult.
7173: '</p>';
7174: }
1.481 raeburn 7175: return $output;
1.480 raeburn 7176: }
7177:
1.484 raeburn 7178: sub generate_admin_menu {
1.611 raeburn 7179: my ($crstype,$canedit) = @_;
1.484 raeburn 7180: my $lc_crstype = lc($crstype);
7181: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7182: my %lt= ( # do not translate here
1.484 raeburn 7183: 'vc' => 'Verify Content',
7184: 'cv' => 'Check/Set Resource Versions',
7185: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7186: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7187: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7188: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7189: );
1.484 raeburn 7190: my ($candump,$dumpurl);
7191: if ($home + $other > 0) {
7192: $candump = 'F';
7193: if ($home) {
7194: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7195: } else {
7196: my @hosts;
7197: foreach my $aurole (keys(%outhash)) {
7198: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7199: push(@hosts,$outhash{$aurole});
1.538 raeburn 7200: }
1.484 raeburn 7201: }
7202: if (@hosts == 1) {
7203: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7204: '&role='.
7205: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7206: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7207: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7208: } else {
7209: $dumpurl = "javascript:choose_switchserver_window()";
7210: }
7211: }
7212: }
7213: my @menu=
7214: ({ categorytitle=>'Administration',
7215: items =>[
7216: { linktext => $lt{'vc'},
7217: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7218: permission => 'F',
1.571 raeburn 7219: help => 'Docs_Verify_Content',
1.484 raeburn 7220: icon => 'verify.png',
7221: linktitle => 'Verify contents can be retrieved/rendered',
7222: },
7223: { linktext => $lt{'cv'},
7224: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7225: permission => 'F',
1.571 raeburn 7226: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7227: icon => 'resversion.png',
7228: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7229: },
7230: { linktext => $lt{'ls'},
7231: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7232: permission => 'F',
7233: #help => '',
7234: icon => 'symbs.png',
7235: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7236: },
1.651 raeburn 7237: { linktext => $lt{'ct'},
7238: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7239: permission => 'F',
7240: help => 'Docs_Short_URLs',
7241: icon => 'shorturls.png',
7242: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7243: },
1.484 raeburn 7244: ]
1.611 raeburn 7245: });
7246: if ($canedit) {
7247: push(@menu,
1.484 raeburn 7248: { categorytitle=>'Export',
7249: items =>[
7250: { linktext => $lt{'imse'},
7251: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7252: permission => 'F',
7253: help => 'Docs_Export_Course_Docs',
7254: icon => 'imsexport.png',
7255: linktitle => $lt{'imse'},
7256: },
7257: { linktext => $lt{'dcd'},
7258: url => $dumpurl,
7259: permission => $candump,
1.571 raeburn 7260: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7261: icon => 'dump.png',
7262: linktitle => $lt{'dcd'},
7263: },
7264: ]
7265: });
1.611 raeburn 7266: }
1.484 raeburn 7267: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7268: '<input type="hidden" id="dummy" />'."\n".
7269: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7270: '</form>';
1.329 droeschl 7271: }
7272:
7273: sub generate_edit_table {
1.538 raeburn 7274: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7275: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7276: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7277: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7278: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7279: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7280: $activetab = $env{'form.active'};
7281: }
1.611 raeburn 7282: unless ($canedit) {
7283: $disabled = ' disabled="disabled"';
7284: }
1.472 raeburn 7285: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7286: my $backtext = &mt('Exit Editor');
1.458 raeburn 7287: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7288: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7289: '<li class="goback">'.
1.546 raeburn 7290: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7291: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7292: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7293: '<li>'.
7294: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7295: &mt('Undo Delete').'</a></li>'."\n";
7296: if ($env{'form.docslog'}) {
7297: $form .= '<li class="active">';
7298: } else {
7299: $form .= '<li>';
7300: }
7301: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7302: &mt('History').'</a></li>'."\n";
7303: if ($env{'form.docslog'}) {
7304: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7305: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7306: }
1.458 raeburn 7307: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7308: if($name ne '00'){
1.371 tempelho 7309: if($activetab eq '' || $activetab ne $name){
7310: $active = '';
7311: }elsif($activetab eq $name){
7312: $active = 'class="active"';
7313: }
1.458 raeburn 7314: $form .= '<li style="float:right" '.$active
1.484 raeburn 7315: .' 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 7316: } else {
1.570 raeburn 7317: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7318:
7319: }
1.329 droeschl 7320: }
1.484 raeburn 7321: $form .= '</ul>'."\n";
7322: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7323:
7324: if ($to_show ne '') {
1.538 raeburn 7325: my $saveform;
7326: if ($need_save) {
7327: my $button = &mt('Make changes');
7328: my $path;
7329: if ($env{'form.folderpath'}) {
7330: $path =
7331: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7332: }
7333: $saveform = <<"END";
7334: <div id="multisave" style="display:none; clear:both;" >
7335: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7336: <input type="hidden" name="folderpath" value="$path" />
7337: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7338: <input type="hidden" name="allhiddenresource" value="" />
7339: <input type="hidden" name="allencrypturl" value="" />
7340: <input type="hidden" name="allrandompick" value="" />
7341: <input type="hidden" name="allrandomorder" value="" />
7342: <input type="hidden" name="changeparms" value="" />
7343: <input type="hidden" name="multiremove" value="" />
7344: <input type="hidden" name="multicut" value="" />
7345: <input type="hidden" name="multicopy" value="" />
7346: <input type="hidden" name="multichange" value="" />
7347: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7348: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7349: </form>
7350: </div>
7351: END
7352: }
7353: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7354: }
1.363 ehlerst 7355: foreach my $field (keys(%orderhash)){
1.390 tempelho 7356: if($field ne '00'){
1.422 onken 7357: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7358: $active = 'style="display: none;float:left"';
1.422 onken 7359: }elsif($activetab eq $field){
1.458 raeburn 7360: $active = 'style="display:block;float:left"';
1.422 onken 7361: }
7362: $form .= '<div id="'.$field.$tid.'"'
7363: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7364: .'</div>'."\n";
1.363 ehlerst 7365: }
7366: }
1.484 raeburn 7367: unless ($env{'form.docslog'}) {
7368: $form .= '</div></div>'."\n";
7369: }
1.329 droeschl 7370: return $form;
7371: }
7372:
7373: sub editing_js {
1.622 raeburn 7374: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7375: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7376: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7377: p_mnf => 'Name of New Folder',
7378: t_mnf => 'New Folder',
7379: p_mnp => 'Name of New Page',
7380: t_mnp => 'New Page',
1.451 www 7381: p_mxu => 'Title for the External Score',
1.349 biermanm 7382: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7383: p_msb => 'Title for the Problem',
7384: p_mdb => 'Title for the Drop Box',
1.336 schafran 7385: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7386: p_mwp => 'Title for Web Page',
1.606 raeburn 7387: p_mnr => 'Title for the Resource',
1.348 weissno 7388: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7389: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7390: p_mab_alrt1 => 'Not a valid user:domain',
7391: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7392: p_chn => 'New Title',
7393: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7394: p_rmr2a => 'Remove',
7395: p_rmr2b => '?',
7396: p_rmr3a => 'Remove those',
7397: p_rmr3b => 'items?',
7398: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7399: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7400: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7401: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7402: p_ctr2a => 'Cut',
7403: p_ctr2b => '?',
7404: p_ctr3a => 'Cut those',
7405: p_ctr3b => 'items?',
1.633 raeburn 7406: setal => 'Enter a (unique) alias',
7407: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7408: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7409: imsfile => 'You must choose an IMS package for import',
7410: imscms => 'You must select which Course Management System was the source of the IMS package',
7411: invurl => 'Invalid URL',
7412: titbl => 'Title is blank',
1.538 raeburn 7413: more => '(More ...)',
7414: less => '(Less ...)',
1.543 raeburn 7415: noor => 'No actions selected or changes to settings specified.',
7416: noch => 'No changes to settings specified.',
7417: noac => 'No actions selected.',
1.606 raeburn 7418: nofi => 'No file selected',
7419: tinc => 'Title in course',
7420: sunm => 'Sub-directory name',
1.618 raeburn 7421: edri => 'Editing rights unavailable for your current role.',
1.691 raeburn 7422: sele => 'Select',
7423: swit => 'Switch server required',
1.329 droeschl 7424: );
1.594 damieng 7425: &js_escape(\%js_lt);
1.433 raeburn 7426: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7427: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7428: my $main_container_page;
1.519 raeburn 7429: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7430: $main_container_page = 1;
1.434 raeburn 7431: }
1.617 raeburn 7432: my $backtourl;
7433: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7434: my $toplevelsupp = &supplemental_base();
1.690 raeburn 7435: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.691 raeburn 7436: my @ids=&Apache::lonnet::current_machine_ids();
7437: my $machines_str = "'".join("','",@ids)."'";
1.530 raeburn 7438: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7439: my $caller = $1;
1.525 raeburn 7440: if ($caller =~ /^supplemental/) {
7441: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7442: } else {
7443: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7444: $res = &Apache::lonnet::clutter($res);
7445: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7446: my ($url,$anchor);
7447: if ($res =~ /^([^#]+)#([^#]+)$/) {
7448: $url = $1;
7449: $anchor = $2;
7450: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7451: $caller = $1.&escape('#').$anchor;
7452: }
1.614 raeburn 7453: } else {
7454: $url = $res;
1.609 raeburn 7455: }
1.640 raeburn 7456: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7457: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7458: $backtourl .= '?navmap=1';
7459: } else {
7460: $backtourl .= '?symb='.
7461: &HTML::Entities::encode($caller,'<>&"');
7462: }
1.622 raeburn 7463: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7464: if (($ENV{'SERVER_PORT'} == 443) &&
7465: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7466: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7467: if ($hostname ne '') {
7468: $backtourl = 'http://'.$hostname.$backtourl;
7469: }
7470: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7471: }
7472: }
1.623 raeburn 7473: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7474: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7475: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7476: if ($hostname ne '') {
7477: $backtourl = 'http://'.$hostname.$backtourl;
7478: }
7479: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7480: }
1.623 raeburn 7481: }
1.622 raeburn 7482: }
1.609 raeburn 7483: if ($anchor ne '') {
7484: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7485: }
1.590 raeburn 7486: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7487: } else {
7488: $backtourl = '/adm/navmaps';
1.525 raeburn 7489: }
7490: }
7491: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7492: $backtourl = '/adm/menu';
7493: } elsif ($supplementalflag) {
1.682 raeburn 7494: if (($env{'request.role.adv'}) ||
7495: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7496: $backtourl = '/adm/supplemental';
7497: } else {
7498: $backtourl = '/adm/navmaps';
7499: }
1.525 raeburn 7500: } else {
7501: $backtourl = '/adm/navmaps';
1.472 raeburn 7502: }
7503:
1.655 raeburn 7504: my $fieldsets = "'doc'";
1.519 raeburn 7505: unless ($main_container_page) {
7506: $fieldsets .=",'ims'";
7507: }
1.655 raeburn 7508: my $extfieldsets = "'ext'";
7509: if ($posslti) {
7510: $extfieldsets .= ",'tool'";
7511: }
1.501 raeburn 7512: if ($supplementalflag) {
1.655 raeburn 7513: $fieldsets = "'suppdoc'";
7514: $extfieldsets = "'suppext'";
1.600 raeburn 7515: if ($posslti) {
1.655 raeburn 7516: $extfieldsets .= ",'supptool'";
1.600 raeburn 7517: }
1.501 raeburn 7518: }
1.655 raeburn 7519:
1.611 raeburn 7520: my $jsmakefunctions;
7521: if ($canedit) {
7522: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7523: function makenewfolder(targetform,folderseq) {
1.594 damieng 7524: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7525: if (foldername) {
1.676 raeburn 7526: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7527: targetform.submit();
7528: }
7529: }
7530:
7531: function makenewpage(targetform,folderseq) {
1.594 damieng 7532: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7533: if (pagename) {
1.676 raeburn 7534: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7535: targetform.submit();
7536: }
7537: }
7538:
7539: function makeexamupload() {
1.594 damieng 7540: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7541: if (title) {
1.329 droeschl 7542: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 7543: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7544: this.document.forms.newexamupload.submit();
7545: }
7546: }
7547:
7548: function makesmppage() {
1.594 damieng 7549: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7550: if (title) {
1.329 droeschl 7551: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 7552: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7553: this.document.forms.newsmppg.submit();
7554: }
7555: }
7556:
1.534 raeburn 7557: function makewebpage(type) {
1.594 damieng 7558: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7559: var formname;
7560: if (type == 'supp') {
7561: formname = this.document.forms.supwebpage;
7562: } else {
7563: formname = this.document.forms.newwebpage;
7564: }
7565: if (title) {
7566: var webpage = formname.importdetail.value;
1.675 raeburn 7567: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7568: formname.submit();
7569: }
7570: }
7571:
1.329 droeschl 7572: function makesmpproblem() {
1.594 damieng 7573: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7574: if (title) {
1.329 droeschl 7575: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 7576: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7577: this.document.forms.newsmpproblem.submit();
7578: }
7579: }
7580:
7581: function makedropbox() {
1.594 damieng 7582: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7583: if (title) {
1.329 droeschl 7584: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 7585: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7586: this.document.forms.newdropbox.submit();
7587: }
7588: }
7589:
7590: function makebulboard() {
1.594 damieng 7591: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7592: if (title) {
7593: this.document.forms.newbul.importdetail.value=
1.676 raeburn 7594: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7595: this.document.forms.newbul.submit();
7596: }
7597: }
7598:
7599: function makeabout() {
1.594 damieng 7600: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7601: if (user) {
7602: var comp=new Array();
7603: comp=user.split(':');
7604: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7605: if ((comp[0]) && (comp[1])) {
7606: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7607: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7608: this.document.forms.newaboutsomeone.submit();
7609: } else {
7610: alert("$js_lt{'p_mab_alrt1'}");
7611: }
7612: } else {
7613: alert("$js_lt{'p_mab_alrt2'}");
7614: }
7615: }
7616: }
7617:
7618: function makenew(targetform) {
7619: targetform.submit();
7620: }
7621:
7622: function changename(folderpath,index,oldtitle) {
7623: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7624: if (title) {
7625: this.document.forms.renameform.markcopy.value='';
7626: this.document.forms.renameform.title.value=title;
7627: this.document.forms.renameform.cmd.value='rename_'+index;
7628: this.document.forms.renameform.folderpath.value=folderpath;
7629: this.document.forms.renameform.submit();
7630: }
7631: }
7632:
1.633 raeburn 7633: function setalias(folderpath,index) {
7634: var alias = prompt('$js_lt{"setal"}');
7635: if ((alias != null) && (alias != '')) {
7636: this.document.forms.aliasform.alias.value=alias;
7637: this.document.forms.aliasform.cmd.value='setalias_'+index;
7638: this.document.forms.aliasform.folderpath.value=folderpath;
7639: this.document.forms.aliasform.submit();
7640: }
7641: }
7642:
7643: function delalias(folderpath,index) {
7644: if (confirm('$js_lt{"delal"}')) {
7645: this.document.forms.aliasform.cmd.value='delalias_'+index;
7646: this.document.forms.aliasform.folderpath.value=folderpath;
7647: this.document.forms.aliasform.submit();
7648: }
7649: }
7650:
1.611 raeburn 7651: ENDNEWSCRIPT
7652: } else {
7653: $jsmakefunctions = <<ENDNEWSCRIPT;
7654:
7655: function makenewfolder() {
7656: alert("$js_lt{'edri'}");
7657: }
7658:
7659: function makenewpage() {
7660: alert("$js_lt{'edri'}");
7661: }
7662:
7663: function makeexamupload() {
7664: alert("$js_lt{'edri'}");
7665: }
7666:
7667: function makesmppage() {
7668: alert("$js_lt{'edri'}");
7669: }
7670:
7671: function makewebpage(type) {
7672: alert("$js_lt{'edri'}");
7673: }
7674:
7675: function makesmpproblem() {
7676: alert("$js_lt{'edri'}");
7677: }
7678:
7679: function makedropbox() {
7680: alert("$js_lt{'edri'}");
7681: }
7682:
7683: function makebulboard() {
7684: alert("$js_lt{'edri'}");
7685: }
7686:
7687: function makeabout() {
7688: alert("$js_lt{'edri'}");
7689: }
7690:
7691: function changename() {
7692: alert("$js_lt{'edri'}");
7693: }
7694:
1.633 raeburn 7695: function setalias() {
7696: alert("$js_lt{'edri'}");
7697: }
7698:
7699: function delalias() {
7700: alert("$js_lt{'edri'}");
7701: }
7702:
1.611 raeburn 7703: function makenew() {
7704: alert("$js_lt{'edri'}");
7705: }
7706:
7707: function groupimport() {
7708: alert("$js_lt{'edri'}");
1.335 ehlerst 7709: }
1.611 raeburn 7710:
7711: function groupsearch() {
7712: alert("$js_lt{'edri'}");
1.335 ehlerst 7713: }
1.611 raeburn 7714:
7715: function groupopen(url,recover) {
7716: var options="scrollbars=1,resizable=1,menubar=0";
7717: idxflag=1;
7718: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7719: idx.focus();
1.329 droeschl 7720: }
7721:
1.611 raeburn 7722: ENDNEWSCRIPT
7723:
7724: }
7725: return <<ENDSCRIPT;
7726:
7727: $jsmakefunctions
7728:
1.501 raeburn 7729: function toggleUpload(caller) {
7730: var blocks = Array($fieldsets);
7731: for (var i=0; i<blocks.length; i++) {
7732: var disp = 'none';
7733: if (caller == blocks[i]) {
7734: var curr = document.getElementById('upload'+caller+'form').style.display;
7735: if (curr == 'none') {
7736: disp='block';
7737: }
7738: }
7739: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7740: }
7741: resize_scrollbox('contentscroll','1','1');
7742: return;
7743: }
7744:
7745: function toggleExternal(caller) {
7746: var blocks = Array($extfieldsets);
7747: for (var i=0; i<blocks.length; i++) {
7748: var disp = 'none';
7749: if (caller == blocks[i]) {
7750: var curr = document.getElementById('external'+caller+'form').style.display;
7751: if (curr == 'none') {
7752: disp='block';
7753: }
7754: }
7755: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7756: if ((caller == 'tool') || (caller == 'supptool')) {
7757: if (disp == 'block') {
1.655 raeburn 7758: if (document.getElementById('LC_exttoolid')) {
7759: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7760: var suppflag = 0;
7761: if (caller == 'supptool') {
7762: suppflag = 1;
7763: }
7764: currForm = document.getElementById('new'+caller);
1.655 raeburn 7765: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7766: }
7767: }
7768: }
1.501 raeburn 7769: }
1.502 raeburn 7770: resize_scrollbox('contentscroll','1','1');
7771: return;
7772: }
7773:
1.514 raeburn 7774: function toggleMap(caller) {
1.502 raeburn 7775: var disp = 'none';
1.510 raeburn 7776: if (document.getElementById('importmapform')) {
1.514 raeburn 7777: if (caller == 'map') {
7778: var curr = document.getElementById('importmapform').style.display;
7779: if (curr == 'none') {
7780: disp='block';
7781: }
1.510 raeburn 7782: }
7783: document.getElementById('importmapform').style.display=disp;
7784: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7785: }
1.501 raeburn 7786: return;
1.329 droeschl 7787: }
7788:
1.691 raeburn 7789: function toggleCrsRes(caller) {
1.606 raeburn 7790: var disp = 'none';
7791: if (document.getElementById('crsresform')) {
7792: if (caller == 'res') {
1.691 raeburn 7793: var form = document.getElementById('crsresform');
7794: var curr = form.style.display;
1.606 raeburn 7795: if (curr == 'none') {
7796: disp='block';
1.691 raeburn 7797: document.courseresform.authorrole.selectedIndex = 0;
7798: document.courseresform.authorpath.selectedIndex = 0;
7799: document.courseresform.newresourceadd.selectedIndex = 0;
7800: populateDirSelects(form,'authorrole','authorpath',1,0,0);
7801: toggleNewInCourse(document.courseresform);
7802: if (document.getElementById('newresource')) {
7803: document.getElementById('newresource').style.display = 'none';
1.606 raeburn 7804: }
7805: if (document.courseresform.newresusetemp.length) {
7806: document.courseresform.newresusetemp[0].checked = true;
7807: toggleWithTemplate(document.courseresform);
7808: }
7809: document.courseresform.newresourcename.value = '';
7810: }
7811: }
7812: if (document.courseresform.newsubdir.length) {
7813: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7814: if (document.courseresform.newsubdir[j].value == 0) {
7815: document.courseresform.newsubdir[j].checked = true;
7816: }
7817: break;
7818: }
7819: if (document.getElementById('newsubdirname')) {
7820: document.getElementById('newsubdirname').type = "hidden";
7821: document.getElementById('newsubdirname').value = "";
7822: }
7823: if (document.getElementById('newsubdir')) {
7824: document.getElementById('newsubdir').innerHTML = "";
7825: }
7826: }
7827: document.getElementById('crsresform').style.display=disp;
7828: resize_scrollbox('contentscroll','1','0');
7829: }
7830: return;
7831: }
7832:
7833: function toggleNewsubdir(form) {
7834: if (form.newsubdir.length) {
7835: for (var j=0; j<form.newsubdir.length; j++) {
7836: if (form.newsubdir[j].checked) {
7837: if (document.getElementById('newsubdirname')) {
7838: if (form.newsubdir[j].value == '1') {
7839: document.getElementById('newsubdirname').type = "text";
7840: if (document.getElementById('newsubdir')) {
7841: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7842: }
7843: } else {
7844: document.getElementById('newsubdirname').type = "hidden";
7845: document.getElementById('newsubdirname').value = "";
7846: document.getElementById('newsubdir').innerHTML = "";
7847: }
7848: }
7849: break;
7850: }
7851: }
7852: }
7853: }
7854:
7855: function toggleCrsResTitle() {
7856: if (document.getElementById('newresource')) {
1.691 raeburn 7857: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
7858: if (selloc == 'course') {
1.606 raeburn 7859: document.getElementById('newresource').style.display = 'inline';
7860: document.courseresform.newresourceadd[0].checked = true;
7861: toggleNewInCourse(document.courseresform);
7862: } else {
7863: document.getElementById('newresource').style.display = 'none';
7864: }
1.689 raeburn 7865: }
7866: if (document.getElementById('newstdproblem')) {
7867: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
7868: document.getElementById('newstdproblem').style.display = 'none';
7869: if (document.getElementById('stdprobswitch')) {
7870: document.getElementById('stdprobswitch').style.display = 'block';
7871: }
7872: } else {
7873: document.getElementById('newstdproblem').style.display = 'block';
7874: if (document.getElementById('stdprobswitch')) {
7875: document.getElementById('stdprobswitch').style.display = 'none';
7876: }
7877: }
7878: }
1.606 raeburn 7879: }
7880:
7881: function toggleNewInCourse(form) {
7882: if (form.newresourceadd.length) {
7883: for (var i=0; i<form.newresourceadd.length; i++) {
7884: if (form.newresourceadd[i].checked) {
7885: if (document.getElementById('newresourcetitle')) {
7886: if (form.newresourceadd[i].value == '1') {
7887: document.getElementById('newresourcetitle').type = 'text';
7888: if (document.getElementById('newrestitle')) {
7889: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7890: }
7891: } else {
7892: document.getElementById('newresourcetitle').type = 'hidden';
7893: document.getElementById('newresourcetitle').value = '';
7894: if (document.getElementById('newrestitle')) {
7895: document.getElementById('newrestitle').innerHTML = '';
7896: }
7897: }
7898: }
7899: break;
7900: }
7901: }
7902: }
7903: }
7904:
7905: function toggleWithTemplate(form) {
7906: if (form.newresusetemp.length) {
7907: for (var i=0; i<form.newresusetemp.length; i++) {
7908: if (form.newresusetemp[i].checked) {
7909: if (document.getElementById('newrestemplate')) {
7910: if (form.newresusetemp[i].value == '1') {
7911: document.getElementById('newrestemplate').style.display = 'inline';
7912: toggleExampleText();
7913: } else {
7914: form.tempcategory.selectedIndex = 0;
7915: select1template_changed();
7916: document.getElementById('newrestemplate').style.display = 'none';
7917: }
7918: }
7919: }
7920: }
7921: }
7922: }
7923:
7924: function toggleExampleText() {
7925: if (document.getElementById('newresexample')) {
7926: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7927: if (url == '') {
7928: document.getElementById('newresexample').style.fontWeight = 'normal';
7929: } else {
7930: document.getElementById('newresexample').style.fontWeight = 'bold';
7931: }
7932: }
7933: }
7934:
7935: function getExample(width,height,scrolling,transparency) {
7936: var url;
7937: if (document.courseresform.newresusetemp.length) {
7938: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7939: if (document.courseresform.newresusetemp[i].checked) {
7940: if (document.courseresform.newresusetemp[i].value == '1') {
7941: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7942: if (url == '') {
7943: alert('Pick a category and template');
7944: } else {
7945: url = url.replace("$londocroot","");
7946: url += '?inhibitmenu=yes';
7947: }
7948: }
7949: break;
7950: }
7951: }
7952: }
7953: if (url != '') {
7954: openMyModal(url,width,height,scrolling,transparency,'');
7955: }
7956: }
7957:
1.690 raeburn 7958: function toggleImportCrsres(caller) {
1.606 raeburn 7959: var disp = 'none';
7960: if (document.getElementById('importcrsresform')) {
7961: if (caller == 'res') {
7962: var curr = document.getElementById('importcrsresform').style.display;
7963: if (curr == 'none') {
7964: disp='block';
1.690 raeburn 7965: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1);
1.606 raeburn 7966: }
7967: }
7968: document.getElementById('importcrsresform').style.display=disp;
7969: resize_scrollbox('contentscroll','1','0');
7970: }
7971: return;
7972: }
7973:
1.690 raeburn 7974: $showfile_js
7975:
1.691 raeburn 7976: function populateDirSelects(form,locsel,dirsel,setdir,recurse,nonemptydir) {
7977: var location = form.elements[locsel].options[form.elements[locsel].selectedIndex].value;
7978: if ((setdir) && (dirsel != null) && (dirsel != 'undefined') && (dirsel != '')) {
7979: var selelem = form.elements[dirsel];
7980: var i, numfiles = selelem.options.length -1;
7981: if (numfiles >=0) {
7982: for (i = numfiles; i >= 0; i--) {
7983: selelem.remove(i);
7984: }
7985: }
7986: if ((location == '') || (location == null) || (location == 'undefined')) {
7987: if (selelem.options.length == 0) {
7988: selelem.options[selelem.options.length] = new Option('','');
7989: selelem.selectedIndex = 0;
7990: }
7991: if (document.getElementById('newstdproblem')) {
7992: document.getElementById('newstdproblem').style.display = 'none';
7993: }
7994: return;
7995: }
7996: var machineIds = new Array($machines_str);
7997: var athome = 0;
7998: var role = location;
7999: if ((location == 'author') || (location == 'course')) {
8000: if (document.getElementById('rolehome_'+location)) {
8001: var currhome = document.getElementById('rolehome_'+location).value;
8002: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8003: if (machineIds.includes(currhome)) {
8004: athome = 1;
8005: }
8006: }
8007: }
8008: } else {
8009: const roleinfo = location.split('___');
8010: role = encodeURIComponent(roleinfo[0]+'./'+roleinfo[1]);
8011: if (document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0])) {
8012: var currhome = document.getElementById('rolehome_coauthor_'+roleinfo[1]+'_'+roleinfo[0]).value;
8013: if ((currhome != '') && (currhome != null) && (currhome != 'undefined')) {
8014: if (machineIds.includes(currhome)) {
8015: athome = 1;
8016: }
8017: }
8018: }
8019: }
8020: if (athome) {
8021: if (document.getElementById('stdprobswitch')) {
8022: document.getElementById('stdprobswitch').style.display = 'none';
8023: }
8024: if (document.getElementById('newstdproblem')) {
8025: document.getElementById('newstdproblem').style.display = 'none';
8026: }
8027: var http = new XMLHttpRequest();
8028: var url = "/adm/courseauthor";
8029: var params = "role="+role+"&rec="+recurse+"&nonempty="+nonemptydir;
8030: http.open("POST", url, true);
8031: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
8032: http.onreadystatechange = function() {
8033: if (http.readyState == 4 && http.status == 200) {
8034: var data = JSON.parse(http.responseText);
8035: if (Array.isArray(data.dirs)) {
8036: var len = data.dirs.length;
8037: if (len) {
8038: if (len > 1) {
8039: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','');
8040: }
8041: }
8042: if (len) {
8043: var j;
8044: for (j = 0; j < len; j++) {
8045: selelem.options[selelem.options.length] = new Option(data.dirs[j],data.dirs[j]);
8046: }
8047: selelem.selectedIndex = 0;
8048: }
8049: }
8050: }
8051: }
8052: http.send(params);
8053: } else {
8054: selelem.options[selelem.options.length] = new Option('$js_lt{swit}','switch');
8055: selelem.selectedIndex = 0;
8056: if (document.getElementById('stdprobswitch')) {
8057: document.getElementById('stdprobswitch').style.display = 'block';
8058: }
8059: if (document.getElementById('newstdproblem')) {
8060: document.getElementById('newstdproblem').style.display = 'none';
8061: }
8062: }
8063: }
8064: return;
8065: }
8066:
1.689 raeburn 8067: function switchForProb() {
8068: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8069: var url = '/adm/switchserver?otherserver=';
8070: var newhostid = '';
8071: var role = '';
8072: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8073: if (selloc == 'author') {
8074: newhostid = document.courseresform.rolehome_author.value;
8075: role = "au./&js_escape($env{'user.domain'})/";
8076: } else if (selloc == 'course') {
8077: newhostid = document.courseresform.rolehome_course.value;
8078: role = "&js_escape($env{'request.role'})";
8079: } else {
8080: var items = new Array();
8081: items = selloc.split('___');
8082: var len = document.courseresform.rolehome_coauthor.length;
8083: if (null == len) {
8084: var currval = document.courseresform.rolehome_coauthor.value;
8085: if (null != currval) {
8086: var info = new Array();
8087: info = currval.split('=');
8088: newhostid = info[2];
8089: role = info[0]+'./'+info[1];
8090: }
8091: } else {
8092: for (var i=0; i<len; i++) {
8093: var currval = document.courseresform.rolehome_coauthor[i].value;
8094: if (null != currval) {
8095: var info = new Array();
8096: info = currval.split('=');
8097: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8098: newhostid = info[2];
8099: role = info[0]+'./'+info[1];
8100: break;
8101: }
8102: }
8103: }
8104: }
8105: }
8106: if (newhostid != '') {
8107: url += newhostid;
8108: if (role != '') {
8109: url += '&role='+role;
8110: }
8111: document.location.href = url;
8112: }
8113: }
8114: return;
8115: }
8116:
1.501 raeburn 8117: function makeims(imsform) {
8118: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 8119: alert("$js_lt{'imsfile'}");
1.501 raeburn 8120: return;
8121: }
8122: if (imsform.source.selectedIndex == 0) {
1.594 damieng 8123: alert("$js_lt{'imscms'}");
1.501 raeburn 8124: return;
8125: }
8126: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8127: imsform.submit();
8128: }
8129:
1.478 raeburn 8130: function updatePick(targetform,index,caller) {
1.537 raeburn 8131: var pickitem;
8132: var picknumitem;
8133: var picknumtext;
8134: if (index == 'all') {
8135: pickitem = document.getElementById('randompickall');
8136: picknumitem = document.getElementById('rpicknumall');
8137: picknumtext = document.getElementById('rpicktextall');
8138: } else {
8139: pickitem = document.getElementById('randompick_'+index);
8140: picknumitem = document.getElementById('rpicknum_'+index);
8141: picknumtext = document.getElementById('randompicknum_'+index);
8142: }
1.478 raeburn 8143: if (pickitem.checked) {
1.594 damieng 8144: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 8145: if (picknum == '' || picknum == null) {
8146: if (caller == 'check') {
8147: pickitem.checked=false;
1.537 raeburn 8148: if (index == 'all') {
8149: picknumtext.innerHTML = '';
8150: if (caller == 'link') {
8151: propagateState(targetform,'rpicknum');
8152: }
8153: } else {
1.538 raeburn 8154: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8155: }
1.478 raeburn 8156: }
8157: } else {
8158: picknum.toString();
8159: var regexdigit=/^\\d+\$/;
8160: if (regexdigit.test(picknum)) {
8161: picknumitem.value = picknum;
1.537 raeburn 8162: if (index == 'all') {
1.538 raeburn 8163: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 8164: if (caller == 'link') {
8165: propagateState(targetform,'rpicknum');
8166: }
8167: } else {
8168: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 8169: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8170: }
1.478 raeburn 8171: } else {
8172: if (caller == 'check') {
1.537 raeburn 8173: if (index == 'all') {
8174: picknumtext.innerHTML = '';
8175: if (caller == 'link') {
8176: propagateState(targetform,'rpicknum');
8177: }
8178: } else {
8179: pickitem.checked=false;
1.538 raeburn 8180: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8181: }
1.478 raeburn 8182: }
8183: return;
8184: }
8185: }
8186: } else {
1.537 raeburn 8187: picknumitem.value = '';
8188: picknumtext.innerHTML = '';
8189: if (index == 'all') {
8190: if (caller == 'link') {
8191: propagateState(targetform,'rpicknum');
8192: }
8193: } else {
1.538 raeburn 8194: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8195: }
8196: }
8197: }
8198:
8199: function propagateState(form,param) {
8200: if (document.getElementById(param+'all')) {
8201: var setcheck = 0;
8202: var rpick = 0;
8203: if (param == 'rpicknum') {
8204: if (document.getElementById('randompickall')) {
8205: if (document.getElementById('randompickall').checked) {
8206: if (document.getElementById('rpicknumall')) {
8207: rpick = document.getElementById('rpicknumall').value;
8208: }
8209: }
8210: }
8211: } else {
8212: if (document.getElementById(param+'all').checked) {
8213: setcheck = 1;
8214: }
8215: }
1.538 raeburn 8216: var allidxlist;
8217: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8218: if (document.getElementById('all'+param+'idx')) {
8219: allidxlist = document.getElementById('all'+param+'idx').value;
8220: }
8221: var actions = new Array ('remove','cut','copy');
8222: for (var i=0; i<actions.length; i++) {
8223: if (actions[i] != param) {
8224: if (document.getElementById(actions[i]+'all')) {
8225: document.getElementById(actions[i]+'all').checked = false;
8226: }
8227: }
8228: }
8229: }
1.537 raeburn 8230: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 8231: allidxlist = form.allidx.value;
8232: }
8233: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8234: allidxlist = form.allmapidx.value;
8235: }
8236: if ((allidxlist != '') && (allidxlist != null)) {
8237: var allidxs = allidxlist.split(',');
8238: if (allidxs.length > 1) {
8239: for (var i=0; i<allidxs.length; i++) {
8240: if (document.getElementById(param+'_'+allidxs[i])) {
8241: if (param == 'rpicknum') {
8242: if (document.getElementById('randompick_'+allidxs[i])) {
8243: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8244: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8245: if (rpick > 0) {
8246: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8247: } else {
8248: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8249: }
8250: }
8251: }
8252: } else {
1.537 raeburn 8253: if (setcheck == 1) {
8254: document.getElementById(param+'_'+allidxs[i]).checked = true;
8255: } else {
8256: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 8257: if (param == 'randompick') {
8258: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8259: }
1.537 raeburn 8260: }
8261: }
8262: }
8263: }
1.538 raeburn 8264: if (setcheck == 1) {
8265: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8266: var actions = new Array('copy','cut','remove');
8267: for (var i=0; i<actions.length; i++) {
8268: var otheractions;
8269: var otheridxs;
8270: if (actions[i] === param) {
8271: continue;
8272: } else {
8273: if (document.getElementById('all'+actions[i]+'idx')) {
8274: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8275: otheridxs = otheractions.split(',');
8276: if (otheridxs.length > 1) {
8277: for (var j=0; j<otheridxs.length; j++) {
8278: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8279: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8280: }
1.537 raeburn 8281: }
8282: }
8283: }
1.538 raeburn 8284: }
8285: }
8286: }
8287: }
8288: }
8289: }
8290: }
8291: return;
8292: }
8293:
1.603 raeburn 8294: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8295: var canedit = '$canedit';
8296: if (canedit == '') {
8297: alert("$js_lt{'edri'}");
8298: return;
8299: }
1.539 raeburn 8300: var dosettings;
8301: var doaction;
1.538 raeburn 8302: var control = document.togglemultsettings;
8303: if (context == 'actions') {
8304: control = document.togglemultactions;
1.539 raeburn 8305: doaction = 1;
8306: } else {
8307: dosettings = 1;
1.538 raeburn 8308: }
1.539 raeburn 8309: if (control) {
8310: if (control.showmultpick.length) {
8311: for (var i=0; i<control.showmultpick.length; i++) {
8312: if (control.showmultpick[i].checked) {
8313: if (control.showmultpick[i].value == 1) {
8314: if (context == 'settings') {
8315: dosettings = 0;
8316: } else {
8317: doaction = 0;
1.538 raeburn 8318: }
8319: }
8320: }
1.537 raeburn 8321: }
8322: }
1.539 raeburn 8323: }
8324: if (context == 'settings') {
8325: if (dosettings == 1) {
1.538 raeburn 8326: targetform.changeparms.value=param;
8327: targetform.submit();
8328: }
1.537 raeburn 8329: }
1.539 raeburn 8330: if (context == 'actions') {
8331: if (doaction == 1) {
8332: targetform.cmd.value=param+'_'+index;
8333: targetform.folderpath.value=folderpath;
8334: targetform.markcopy.value=idx+':'+param;
8335: targetform.copyfolder.value=folder+'.'+container;
8336: if (param == 'remove') {
1.603 raeburn 8337: var doremove = 0;
8338: if (skip_confirm) {
8339: if (confirm_removal) {
8340: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8341: doremove = 1;
8342: }
8343: } else {
8344: doremove = 1;
8345: }
8346: } else {
8347: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8348: doremove = 1;
8349: }
8350: }
8351: if (doremove) {
1.539 raeburn 8352: targetform.markcopy.value='';
8353: targetform.copyfolder.value='';
8354: targetform.submit();
8355: }
8356: }
8357: if (param == 'cut') {
1.594 damieng 8358: 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 8359: targetform.submit();
8360: return;
8361: }
8362: }
8363: if (param == 'copy') {
8364: targetform.submit();
8365: return;
8366: }
8367: targetform.markcopy.value='';
8368: targetform.copyfolder.value='';
8369: targetform.cmd.value='';
8370: targetform.folderpath.value='';
8371: return;
8372: } else {
8373: if (document.getElementById(param+'_'+idx)) {
8374: item = document.getElementById(param+'_'+idx);
8375: if (item.type == 'checkbox') {
8376: if (item.checked) {
8377: item.checked = false;
8378: } else {
8379: item.checked = true;
8380: singleCheck(item,idx,param);
8381: }
8382: }
8383: }
8384: }
8385: }
1.537 raeburn 8386: return;
8387: }
8388:
1.538 raeburn 8389: function singleCheck(caller,idx,action) {
8390: actions = new Array('cut','copy','remove');
8391: if (caller.checked) {
8392: for (var i=0; i<actions.length; i++) {
8393: if (actions[i] != action) {
8394: if (document.getElementById(actions[i]+'_'+idx)) {
8395: if (document.getElementById(actions[i]+'_'+idx).checked) {
8396: document.getElementById(actions[i]+'_'+idx).checked = false;
8397: }
1.537 raeburn 8398: }
8399: }
8400: }
1.478 raeburn 8401: }
1.537 raeburn 8402: return;
1.478 raeburn 8403: }
8404:
1.334 muellerd 8405: function unselectInactive(nav) {
1.335 ehlerst 8406: currentNav = document.getElementById(nav);
8407: currentLis = currentNav.getElementsByTagName('LI');
8408: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8409: if (currentLis[i].className == 'goback') {
8410: currentLis[i].className = 'goback';
8411: } else {
8412: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8413: currentLis[i].className = 'right';
1.472 raeburn 8414: } else {
1.374 tempelho 8415: currentLis[i].className = 'i';
1.472 raeburn 8416: }
8417: }
1.335 ehlerst 8418: }
1.332 tempelho 8419: }
8420:
1.334 muellerd 8421: function hideAll(current, nav, data) {
1.335 ehlerst 8422: unselectInactive(nav);
1.570 raeburn 8423: if (current) {
8424: if (current.className == 'right'){
8425: current.className = 'right active'
8426: } else {
8427: current.className = 'active';
8428: }
1.374 tempelho 8429: }
1.335 ehlerst 8430: currentData = document.getElementById(data);
8431: currentDivs = currentData.getElementsByTagName('DIV');
8432: for (i = 0; i < currentDivs.length; i++) {
8433: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8434: currentDivs[i].style.display = 'none';
1.330 tempelho 8435: }
8436: }
1.335 ehlerst 8437: }
1.330 tempelho 8438:
1.374 tempelho 8439: function openTabs(pageId) {
8440: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8441: if(tabnav.length > 2 ){
1.389 tempelho 8442: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8443: currentLis = currentNav.getElementsByTagName('LI');
8444: for(i = 0; i< currentLis.length; i++){
8445: if(currentLis[i].className == 'active') {
1.375 tempelho 8446: funcString = currentLis[i].onclick.toString();
8447: tab = funcString.split('"');
1.420 onken 8448: if(tab.length < 2) {
8449: tab = funcString.split("'");
8450: }
1.375 tempelho 8451: currentData = document.getElementById(tab[1]);
8452: currentData.style.display = 'block';
1.374 tempelho 8453: }
8454: }
8455: }
8456: }
8457:
1.334 muellerd 8458: function showPage(current, pageId, nav, data) {
1.570 raeburn 8459: currstate = current.className;
1.334 muellerd 8460: hideAll(current, nav, data);
1.375 tempelho 8461: openTabs(pageId);
1.334 muellerd 8462: unselectInactive(nav);
1.570 raeburn 8463: if ((currstate == 'active') || (currstate == 'right active')) {
8464: if (currstate == 'active') {
8465: current.className = '';
8466: } else {
8467: current.className = 'right';
8468: }
8469: activeTab = '';
1.656 raeburn 8470: toggleExternal();
1.570 raeburn 8471: toggleUpload();
8472: toggleMap();
1.606 raeburn 8473: toggleCrsRes();
8474: toggleImportCrsres();
1.570 raeburn 8475: resize_scrollbox('contentscroll','1','0');
8476: return;
8477: } else {
8478: current.className = 'active';
8479: }
1.330 tempelho 8480: currentData = document.getElementById(pageId);
8481: currentData.style.display = 'block';
1.458 raeburn 8482: activeTab = pageId;
1.656 raeburn 8483: toggleExternal();
1.501 raeburn 8484: toggleUpload();
1.503 raeburn 8485: toggleMap();
1.606 raeburn 8486: toggleCrsRes();
8487: toggleImportCrsres();
1.433 raeburn 8488: if (nav == 'mainnav') {
8489: var storedpath = "$docs_folderpath";
1.434 raeburn 8490: var storedpage = "$main_container_page";
1.433 raeburn 8491: var reg = new RegExp("^supplemental");
8492: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8493: if (storedpage == 1) {
8494: document.simpleedit.folderpath.value = '';
8495: document.uploaddocument.folderpath.value = '';
8496: } else {
8497: if (reg.test(storedpath)) {
8498: document.simpleedit.folderpath.value = '$toplevelmain';
8499: document.uploaddocument.folderpath.value = '$toplevelmain';
8500: document.newext.folderpath.value = '$toplevelmain';
8501: } else {
8502: document.simpleedit.folderpath.value = storedpath;
8503: document.uploaddocument.folderpath.value = storedpath;
8504: document.newext.folderpath.value = storedpath;
8505: }
1.433 raeburn 8506: }
8507: } else {
1.434 raeburn 8508: if (reg.test(storedpath)) {
8509: document.simpleedit.folderpath.value = storedpath;
8510: document.supuploaddocument.folderpath.value = storedpath;
8511: document.supnewext.folderpath.value = storedpath;
8512: } else {
1.433 raeburn 8513: document.simpleedit.folderpath.value = '$toplevelsupp';
8514: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8515: document.supnewext.folderpath.value = '$toplevelsupp';
8516: }
8517: }
8518: }
1.485 raeburn 8519: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8520: return false;
8521: }
1.329 droeschl 8522:
1.472 raeburn 8523: function toContents(jumpto) {
8524: var newurl = '$backtourl';
1.525 raeburn 8525: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8526: newurl = newurl+'?postdata='+jumpto;
8527: }
8528: location.href=newurl;
8529: }
8530:
1.538 raeburn 8531: function togglePick(caller,value) {
8532: var disp = 'none';
8533: if (document.getElementById('multi'+caller)) {
8534: var curr = document.getElementById('multi'+caller).style.display;
8535: if (value == 1) {
8536: disp='block';
8537: }
8538: if (curr == disp) {
8539: return;
8540: }
8541: document.getElementById('multi'+caller).style.display=disp;
8542: if (value == 1) {
1.594 damieng 8543: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8544: } else {
8545: document.getElementById('more'+caller).innerHTML = '';
8546: }
8547: if (caller == 'actions') {
8548: setClass(value);
8549: setBoxes(value);
8550: }
8551: }
8552: var showButton = multiSettings();
8553: if (showButton != 1) {
8554: showButton = multiActions();
8555: }
8556: if (document.getElementById('multisave')) {
8557: if (showButton == 1) {
8558: document.getElementById('multisave').style.display='block';
8559: } else {
8560: document.getElementById('multisave').style.display='none';
8561: }
8562: }
8563: resize_scrollbox('contentscroll','1','1');
8564: return;
8565: }
8566:
8567: function toggleCheckUncheck(caller,more) {
8568: if (more == 1) {
1.594 damieng 8569: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8570: document.getElementById('allfields'+caller).style.display='block';
8571: } else {
1.594 damieng 8572: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8573: document.getElementById('allfields'+caller).style.display='none';
8574: }
8575: resize_scrollbox('contentscroll','1','1');
8576: }
8577:
8578: function multiSettings() {
8579: var inuse = 0;
8580: var settingsform = document.togglemultsettings;
8581: if (settingsform.showmultpick.length > 1) {
8582: for (var i=0; i<settingsform.showmultpick.length; i++) {
8583: if (settingsform.showmultpick[i].checked) {
8584: if (settingsform.showmultpick[i].value == 1) {
8585: inuse = 1;
8586: }
8587: }
8588: }
8589: }
8590: return inuse;
8591: }
8592:
8593: function multiActions() {
8594: var inuse = 0;
8595: var actionsform = document.togglemultactions;
8596: if (actionsform.showmultpick.length > 1) {
8597: for (var i=0; i<actionsform.showmultpick.length; i++) {
8598: if (actionsform.showmultpick[i].checked) {
8599: if (actionsform.showmultpick[i].value == 1) {
8600: inuse = 1;
8601: }
8602: }
8603: }
8604: }
8605: return inuse;
8606: }
8607:
8608: function checkSubmits() {
8609: var numchanges = 0;
8610: var form = document.saveactions;
8611: var doactions = multiActions();
1.542 raeburn 8612: var cutwarnings = 0;
8613: var remwarnings = 0;
1.603 raeburn 8614: var removalinfo = 0;
1.538 raeburn 8615: if (doactions == 1) {
8616: var remidxlist = document.cumulativeactions.allremoveidx.value;
8617: if ((remidxlist != '') && (remidxlist != null)) {
8618: var remidxs = remidxlist.split(',');
8619: for (var i=0; i<remidxs.length; i++) {
8620: if (document.getElementById('remove_'+remidxs[i])) {
8621: if (document.getElementById('remove_'+remidxs[i]).checked) {
8622: form.multiremove.value += remidxs[i]+',';
8623: numchanges ++;
1.542 raeburn 8624: if (document.getElementById('skip_remove_'+remidxs[i])) {
8625: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8626: remwarnings ++;
8627: }
8628: }
1.603 raeburn 8629: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8630: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8631: removalinfo ++;
8632: }
8633: }
1.537 raeburn 8634: }
8635: }
1.538 raeburn 8636: }
8637: }
8638: var cutidxlist = document.cumulativeactions.allcutidx.value;
8639: if ((cutidxlist != '') && (cutidxlist != null)) {
8640: var cutidxs = cutidxlist.split(',');
8641: for (var i=0; i<cutidxs.length; i++) {
8642: if (document.getElementById('cut_'+cutidxs[i])) {
8643: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8644: form.multicut.value += cutidxs[i]+',';
8645: numchanges ++;
1.542 raeburn 8646: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8647: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8648: cutwarnings ++;
8649: }
8650: }
1.537 raeburn 8651: }
8652: }
8653: }
8654: }
1.538 raeburn 8655: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8656: if ((copyidxlist != '') && (copyidxlist != null)) {
8657: var copyidxs = copyidxlist.split(',');
8658: for (var i=0; i<copyidxs.length; i++) {
8659: if (document.getElementById('copy_'+copyidxs[i])) {
8660: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8661: form.multicopy.value += copyidxs[i]+',';
8662: numchanges ++;
8663: }
8664: }
8665: }
8666: }
8667: if (numchanges > 0) {
8668: form.multichange.value = numchanges;
8669: }
1.537 raeburn 8670: }
1.538 raeburn 8671: var dosettings = multiSettings();
1.543 raeburn 8672: var haschanges = 0;
1.538 raeburn 8673: if (dosettings == 1) {
8674: form.allencrypturl.value = '';
8675: form.allhiddenresource.value = '';
1.543 raeburn 8676: form.changeparms.value = 'all';
8677: var patt=new RegExp(",\$");
1.538 raeburn 8678: var allidxlist = document.cumulativesettings.allidx.value;
8679: if ((allidxlist != '') && (allidxlist != null)) {
8680: var allidxs = allidxlist.split(',');
8681: if (allidxs.length > 1) {
8682: for (var i=0; i<allidxs.length; i++) {
8683: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8684: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8685: form.allhiddenresource.value += allidxs[i]+',';
8686: }
8687: }
8688: if (document.getElementById('encrypturl_'+allidxs[i])) {
8689: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8690: form.allencrypturl.value += allidxs[i]+',';
8691: }
8692: }
8693: }
1.543 raeburn 8694: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8695: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8696: }
1.538 raeburn 8697: }
8698: form.allrandompick.value = '';
8699: form.allrandomorder.value = '';
8700: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8701: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8702: var allmapidxs = allmapidxlist.split(',');
8703: for (var i=0; i<allmapidxs.length; i++) {
8704: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8705: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8706: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8707: if ((randompick.checked) && (rpicknum.value != '')) {
8708: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8709: }
8710: if (randorder.checked) {
8711: form.allrandomorder.value += allmapidxs[i]+',';
8712: }
1.537 raeburn 8713: }
1.543 raeburn 8714: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8715: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8716: }
8717: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8718: haschanges = 1;
8719: }
8720: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8721: haschanges = 1;
8722: }
8723: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8724: haschanges = 1;
8725: }
8726: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8727: haschanges = 1;
1.537 raeburn 8728: }
8729: }
1.543 raeburn 8730: if (doactions == 1) {
1.542 raeburn 8731: if (numchanges > 0) {
1.603 raeburn 8732: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8733: if (remwarnings > 0) {
1.594 damieng 8734: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8735: return false;
8736: }
8737: }
1.603 raeburn 8738: if (removalinfo > 0) {
8739: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8740: return false;
8741: }
8742: }
1.542 raeburn 8743: if (cutwarnings > 0) {
1.594 damieng 8744: 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 8745: return false;
8746: }
8747: }
8748: }
8749: form.submit();
8750: return true;
1.543 raeburn 8751: }
8752: }
8753: if (dosettings == 1) {
8754: if (haschanges == 1) {
1.542 raeburn 8755: form.submit();
8756: return true;
8757: }
1.543 raeburn 8758: }
8759: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8760: alert("$js_lt{'noor'}");
1.543 raeburn 8761: } else {
8762: if (dosettings == 1) {
1.594 damieng 8763: alert("$js_lt{'noch'}");
1.543 raeburn 8764: } else {
1.594 damieng 8765: alert("$js_lt{'noac'}");
1.543 raeburn 8766: }
8767: }
1.538 raeburn 8768: return false;
8769: }
8770:
8771: function setClass(value) {
8772: var cutclass = 'LC_docs_cut';
8773: var copyclass = 'LC_docs_copy';
8774: var removeclass = 'LC_docs_remove';
8775: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8776: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8777: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8778: var links = document.getElementsByTagName('a');
8779: for (var i=0; i<links.length; i++) {
8780: var classes = links[i].className;
8781: if (cutreg.test(classes)) {
8782: links[i].className = cutclass;
8783: if (value == 1) {
8784: links[i].className += " LC_menubuttons_link";
8785: }
8786: } else {
8787: if (copyreg.test(classes)) {
8788: links[i].className = copyclass;
8789: if (value == 1) {
8790: links[i].className += " LC_menubuttons_link";
8791: }
8792: } else {
8793: if (removereg.test(classes)) {
8794: links[i].className = removeclass;
8795: if (value == 1) {
8796: links[i].className += " LC_menubuttons_link";
8797: }
8798: }
8799: }
8800: }
8801: }
8802: return;
1.537 raeburn 8803: }
8804:
1.538 raeburn 8805: function setBoxes(value) {
8806: var remidxlist = document.cumulativeactions.allremoveidx.value;
8807: if ((remidxlist != '') && (remidxlist != null)) {
8808: var remidxs = remidxlist.split(',');
8809: for (var i=0; i<remidxs.length; i++) {
8810: if (document.getElementById('remove_'+remidxs[i])) {
8811: var item = document.getElementById('remove_'+remidxs[i]);
8812: if (value == 1) {
8813: item.className = 'LC_docs_remove';
8814: } else {
8815: item.className = 'LC_hidden';
8816: }
8817: }
8818: }
8819: }
8820: var cutidxlist = document.cumulativeactions.allcutidx.value;
8821: if ((cutidxlist != '') && (cutidxlist != null)) {
8822: var cutidxs = cutidxlist.split(',');
8823: for (var i=0; i<cutidxs.length; i++) {
8824: if (document.getElementById('cut_'+cutidxs[i])) {
8825: var item = document.getElementById('cut_'+cutidxs[i]);
8826: if (value == 1) {
8827: item.className = 'LC_docs_cut';
8828: } else {
8829: item.className = 'LC_hidden';
8830: }
8831: }
1.537 raeburn 8832: }
8833: }
1.538 raeburn 8834: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8835: if ((copyidxlist != '') && (copyidxlist != null)) {
8836: var copyidxs = copyidxlist.split(',');
8837: for (var i=0; i<copyidxs.length; i++) {
8838: if (document.getElementById('copy_'+copyidxs[i])) {
8839: var item = document.getElementById('copy_'+copyidxs[i]);
8840: if (value == 1) {
8841: item.className = 'LC_docs_copy';
8842: } else {
8843: item.className = 'LC_hidden';
8844: }
8845: }
1.537 raeburn 8846: }
8847: }
8848: return;
8849: }
8850:
1.606 raeburn 8851: function validImportCrsRes() {
8852: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8853: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8854: if ((fname == '') || (fname == null)) {
8855: alert("$js_lt{'nofi'}");
8856: return false;
8857: }
8858: var url = '/res/$coursedom/$coursenum/';
8859: if (path && path != '/') {
8860: url += path+'/';
8861: }
8862: if (fname != '') {
8863: url += fname;
8864: }
8865: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 8866: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 8867: return true;
8868: }
8869:
8870: function validateNewRes(caller) {
8871: if (caller == 'single') {
8872: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8873: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8874: var resname = document.courseresform.newresourcename.value;
8875: }
8876: }
8877:
1.611 raeburn 8878: ENDSCRIPT
1.329 droeschl 8879: }
1.457 raeburn 8880:
1.483 raeburn 8881: sub history_tab_js {
8882: return <<"ENDHIST";
8883: function toggleHistoryDisp(choice) {
8884: document.docslogform.docslog.value = choice;
8885: document.docslogform.submit();
8886: return;
8887: }
8888:
8889: ENDHIST
8890: }
8891:
1.484 raeburn 8892: sub inject_data_js {
8893: return <<ENDINJECT;
8894:
8895: function injectData(current, hiddenField, name, value) {
8896: currentElement = document.getElementById(hiddenField);
8897: currentElement.name = name;
8898: currentElement.value = value;
8899: current.submit();
8900: }
8901:
8902: ENDINJECT
8903: }
8904:
8905: sub dump_switchserver_js {
8906: my @hosts = @_;
1.594 damieng 8907: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8908: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8909: swit => 'Switch server?',
1.594 damieng 8910: );
8911: my %html_js_lt = &Apache::lonlocal::texthash(
8912: swit => 'Switch server?',
1.568 raeburn 8913: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8914: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8915: chos => 'Choose server',
8916: );
1.594 damieng 8917: &js_escape(\%js_lt);
8918: &html_escape(\%html_js_lt);
8919: &js_escape(\%html_js_lt);
1.484 raeburn 8920: my $role = $env{'request.role'};
8921: my $js = <<"ENDSWJS";
8922: <script type="text/javascript">
8923: function write_switchserver() {
8924: var server;
8925: if (document.setserver.posshosts.length > 0) {
8926: for (var i=0; i<document.setserver.posshosts.length; i++) {
8927: if (document.setserver.posshosts[i].checked) {
8928: server = document.setserver.posshosts[i].value;
8929: }
8930: }
8931: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8932: }
8933: window.close();
8934: }
8935: </script>
8936:
8937: ENDSWJS
8938:
8939: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8940: {'only_body' => 1,
8941: 'js_ready' => 1,});
8942: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8943:
8944: my $hostpicker;
8945: my $count = 0;
8946: foreach my $host (sort(@hosts)) {
8947: my $checked;
8948: if ($count == 0) {
8949: $checked = ' checked="checked"';
8950: }
8951: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8952: $host.'"'.$checked.' />'.$host.'</label> ';
8953: $count++;
8954: }
8955:
8956: return <<"ENDSWITCHJS";
8957:
8958: function dump_needs_switchserver(url) {
8959: if (url!='' && url!= null) {
1.594 damieng 8960: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8961: go(url);
8962: }
8963: }
8964: return;
8965: }
8966:
8967: function choose_switchserver_window() {
8968: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8969: newWindow.document.open();
8970: newWindow.document.writeln('$startpage');
1.594 damieng 8971: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8972: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8973: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8974: '<form name="setserver" method="post" action="" \\/>\\n'+
8975: '$hostpicker\\n'+
8976: '<br \\/><br \\/>\\n'+
1.594 damieng 8977: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8978: 'onclick="write_switchserver();" \\/>\\n'+
8979: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8980: newWindow.document.writeln('$endpage');
8981: newWindow.document.close();
8982: newWindow.focus();
8983: }
8984:
8985: ENDSWITCHJS
8986: }
8987:
8988: sub makedocslogform {
8989: my ($formelems,$docslog) = @_;
8990: return <<"LOGSFORM";
8991: <form action="/adm/coursedocs" method="post" name="docslogform">
8992: <input type="hidden" name="docslog" value="$docslog" />
8993: $formelems
8994: </form>
8995: LOGSFORM
8996: }
8997:
8998: sub makesimpleeditform {
8999: my ($formelems) = @_;
9000: return <<"SIMPFORM";
9001: <form name="simpleedit" method="post" action="/adm/coursedocs">
9002: <input type="hidden" name="importdetail" value="" />
9003: $formelems
9004: </form>
9005: SIMPFORM
9006: }
9007:
1.606 raeburn 9008: sub makenewproblem {
9009: my ($r,$coursedom,$coursenum) = @_;
9010: # Creating a new problem
9011: my ($redirect,$error);
9012: if ($env{'form.authorrole'}) {
9013: my ($newsubdir,$filename);
9014: if ($env{'form.newsubdir'}) {
9015: if ($env{'form.newsubdirname'} ne '') {
9016: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 9017: }
1.606 raeburn 9018: }
9019: if ($env{'form.newresourcename'}) {
9020: $filename = $env{'form.newresourcename'};
9021: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9022: $filename =~ s/`//g;
9023: $filename =~ s{/\.\./}{_}g;
9024: $filename =~ s/\.+/./g;
9025: $filename =~ s{/+}{_}g;
9026: if ($filename ne '') {
9027: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9028: if (($ext) && ($ext ne '.problem')) {
9029: $filename = $name.'.problem';
9030: } elsif ($ext eq '') {
9031: $filename .= '.problem';
9032: }
9033: my $docroot = $r->dir_config('lonDocRoot');
9034: my @ids=&Apache::lonnet::current_machine_ids();
9035: if ($env{'form.authorrole'} eq 'author') {
9036: if ($env{'user.author'}) {
9037: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9038: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9039: my $path = $docroot.$url;
9040: my $subdir = $env{'form.authorpath'};
9041: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9042: }
9043: }
9044: } elsif ($env{'form.authorrole'} eq 'course') {
9045: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9046: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9047: my $url = "/priv/$coursedom/$coursenum";
9048: my $path=$docroot.$url;
9049: my $subdir = $env{'form.authorpath'};
9050: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9051: if ($redirect) {
9052: my $rightsfile = 'default.rights';
9053: my $sourcerights = "$path/$rightsfile";
9054: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
9055: my $now = time;
9056: if (!-e $sourcerights) {
9057: my $cid = $coursedom.'_'.$coursenum;
9058: if (open(my $fh,">$sourcerights")) {
9059: print $fh <<END;
9060: <accessrule effect="deny" realm="" type="course" role="" />
9061: <accessrule effect="allow" realm="$cid" type="course" role="" />
9062: END
9063: close($fh);
9064: }
9065: }
9066: if (!-e "$sourcerights.meta") {
9067: if (open(my $fh,">$sourcerights.meta")) {
9068: my $author=$env{'environment.firstname'}.' '.
9069: $env{'environment.middlename'}.' '.
9070: $env{'environment.lastname'}.' '.
9071: $env{'environment.generation'};
9072: $author =~ s/\s+$//;
9073: print $fh <<"END";
9074:
9075: <abstract></abstract>
9076: <author>$author</author>
9077: <authorspace>$coursenum:$coursedom</authorspace>
9078: <copyright>private</copyright>
9079: <creationdate>$now</creationdate>
9080: <customdistributionfile></customdistributionfile>
9081: <dependencies></dependencies>
9082: <domain>$coursedom</domain>
9083: <highestgradelevel>0</highestgradelevel>
9084: <keywords></keywords>
9085: <language>notset </language>
9086: <lastrevisiondate>$now</lastrevisiondate>
9087: <lowestgradelevel>0</lowestgradelevel>
9088: <mime>rights</mime>
9089: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
9090: <notes></notes>
9091: <obsolete></obsolete>
9092: <obsoletereplacement></obsoletereplacement>
9093: <owner>$coursenum:$coursedom</owner>
9094: <rule>deny:::course,allow:$cid::course</rule>
9095: <sourceavail></sourceavail>
9096: <standards></standards>
9097: <subject></subject>
9098: <title></title>
9099: END
1.654 raeburn 9100: close($fh);
9101: }
9102: }
9103: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9104: if (!-e "$docroot/res/$coursedom") {
9105: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 9106: }
1.654 raeburn 9107: if (!-e "$docroot/res/$coursedom/$coursenum") {
9108: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9109: }
9110: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9111: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9112: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 9113: }
9114: }
1.654 raeburn 9115: my $source = $docroot.$redirect;
9116: if (!-e "$source.meta") {
9117: my $cid = $coursedom.'_'.$coursenum;
9118: my $now = time;
9119: if (open(my $fh,">$source.meta")) {
9120: my $author=$env{'environment.firstname'}.' '.
9121: $env{'environment.middlename'}.' '.
9122: $env{'environment.lastname'}.' '.
9123: $env{'environment.generation'};
9124: $author =~ s/\s+$//;
9125: my $title = $env{'form.newresourcetitle'};
9126: $title =~ s/^\s+|\s+$//g;
9127: print $fh <<END;
1.606 raeburn 9128:
9129: <abstract></abstract>
9130: <author>$author</author>
9131: <authorspace>$coursenum:$coursedom</authorspace>
9132: <copyright>custom</copyright>
9133: <creationdate>$now</creationdate>
9134: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9135: <dependencies></dependencies>
9136: <domain>$coursedom</domain>
9137: <highestgradelevel>0</highestgradelevel>
9138: <keywords></keywords>
9139: <language>notset </language>
9140: <lastrevisiondate>$now</lastrevisiondate>
9141: <lowestgradelevel>0</lowestgradelevel>
9142: <mime>problem</mime>
9143: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9144: <notes></notes>
9145: <obsolete></obsolete>
9146: <obsoletereplacement></obsoletereplacement>
9147: <owner>$coursenum:$coursedom</owner>
9148: <sourceavail></sourceavail>
9149: <standards></standards>
9150: <subject></subject>
9151: <title>$title</title>
9152: END
1.654 raeburn 9153: close($fh);
1.606 raeburn 9154: }
9155: }
9156: }
9157: }
9158: } else {
9159: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9160: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9161: if (grep(/^\Q$rolehome\E$/,@ids)) {
9162: my $now = time;
9163: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9164: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9165: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9166: my $url = "/priv/$audom/$auname";
9167: my $path = $r->dir_config('lonDocRoot').$url;
9168: my $subdir = $env{'form.authorpath'};
9169: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9170: }
9171: }
9172: }
9173: }
9174: }
9175: }
9176: }
9177: return ($redirect,$error);
9178: }
9179:
9180: sub finishnewprob {
1.654 raeburn 9181: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 9182: unless (-d $path) {
9183: unless (mkdir($path,02770)) {
9184: return;
9185: }
9186: }
1.606 raeburn 9187: my $redirect;
9188: if ($subdir ne '/') {
9189: $subdir = &cleandir($subdir);
9190: if (($subdir ne '') && (-d "$path/$subdir")) {
9191: $path .= "/$subdir";
9192: $url .= "/$subdir";
9193: }
9194: }
9195: my $dest;
9196: if ($newsubdir ne '') {
9197: $newsubdir = &cleandir($newsubdir);
9198: }
9199: if ($newsubdir ne '') {
9200: if (-d "$path/$newsubdir") {
9201: $dest = "$path/$newsubdir/$filename";
9202: } else {
9203: my $dirok;
9204: unless (-e "$path/$newsubdir") {
9205: if (mkdir("$path/$newsubdir",02770)) {
9206: if (chmod(02770,"$path/$newsubdir")) {
9207: $dirok = 1;
9208: }
9209: }
9210: }
9211: if ($dirok) {
9212: $dest = "$path/$newsubdir/$filename";
9213: }
9214: }
9215: if (($dest ne '') && (!-e $dest)) {
9216: $redirect = "$url/$newsubdir/$filename";
9217: }
9218: } else {
9219: $dest = "$path/$filename";
9220: if (($dest ne '') && (!-e $dest)) {
9221: $redirect = "$url/$filename";
9222: }
9223: }
1.654 raeburn 9224: if ((!-e $dest) && ($context ne 'upload')) {
9225: my $template = $env{'form.template'};
9226: my $copyfrom;
9227: if ($template ne '') {
9228: my %templates;
9229: my @files = &Apache::lonhomework::get_template_list('problem');
9230: foreach my $poss (@files) {
9231: if (ref($poss) eq 'ARRAY') {
9232: if ($template eq $poss->[0]) {
9233: $templates{$template} = 1;
9234: last;
9235: }
9236: }
9237: }
9238: if ($templates{$template}) {
9239: $copyfrom = $template;
9240: }
9241: }
9242: if ($filename =~ /\.problem$/) {
9243: unless ($copyfrom) {
9244: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9245: }
9246: &File::Copy::copy($copyfrom,$dest);
9247: }
9248: }
1.606 raeburn 9249: return $redirect;
9250: }
9251:
9252: sub cleandir {
9253: my ($dir) = @_;
9254: $dir =~ s/^\s+//;
9255: $dir =~ s/\s+$//;
9256: $dir =~ s/\.+//g;
9257: $dir =~ s/[\#\?&%\":]//g;
9258: return $dir;
9259: }
9260:
1.329 droeschl 9261: 1;
9262: __END__
9263:
9264:
9265: =head1 NAME
9266:
9267: Apache::londocs.pm
9268:
9269: =head1 SYNOPSIS
9270:
9271: This is part of the LearningOnline Network with CAPA project
9272: described at http://www.lon-capa.org.
9273:
9274: =head1 SUBROUTINES
9275:
9276: =over
9277:
9278: =item %help=()
9279:
9280: Available help topics
9281:
9282: =item mapread()
9283:
1.344 bisitz 9284: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 9285: @order and @resources, determines status
9286: sets @order - pointer to resources in right order
9287: sets @resources - array with the resources with correct idx
9288:
9289: =item authorhosts()
9290:
9291: Return hash with valid author names
9292:
9293: =item clean()
9294:
9295: =item dumpcourse()
9296:
9297: Actually dump course
9298:
9299: =item group_import()
9300:
9301: Imports the given (name, url) resources into the course
9302: coursenum, coursedom, and folder must precede the list
9303:
9304: =item breadcrumbs()
9305:
9306: =item log_docs()
9307:
9308: =item docs_change_log()
9309:
9310: =item update_paste_buffer()
9311:
9312: =item print_paste_buffer()
9313:
9314: =item do_paste_from_buffer()
9315:
1.538 raeburn 9316: =item do_buffer_empty()
9317:
9318: =item clear_from_buffer()
9319:
1.492 raeburn 9320: =item get_newmap_url()
9321:
9322: =item dbcopy()
9323:
9324: =item uniqueness_check()
9325:
9326: =item contained_map_check()
9327:
9328: =item url_paste_fixups()
9329:
9330: =item apply_fixups()
9331:
9332: =item copy_dependencies()
9333:
1.329 droeschl 9334: =item update_parameter()
9335:
9336: =item handle_edit_cmd()
9337:
9338: =item editor()
9339:
9340: =item process_file_upload()
9341:
9342: =item process_secondary_uploads()
9343:
9344: =item is_supplemental_title()
9345:
9346: =item entryline()
9347:
9348: =item tiehash()
9349:
9350: =item untiehash()
9351:
9352: =item checkonthis()
9353:
9354: check on this
9355:
9356: =item verifycontent()
9357:
9358: Verify Content
9359:
1.636 raeburn 9360: =item devalidateversioncache()
9361:
9362: =item checkversions()
1.329 droeschl 9363:
9364: Check Versions
9365:
9366: =item mark_hash_old()
9367:
9368: =item is_hash_old()
9369:
9370: =item changewarning()
9371:
9372: =item init_breadcrumbs()
9373:
9374: Breadcrumbs for special functions
9375:
1.484 raeburn 9376: =item create_list_elements()
9377:
9378: =item create_form_ul()
9379:
9380: =item startContentScreen()
9381:
9382: =item endContentScreen()
9383:
9384: =item supplemental_base()
9385:
9386: =item embedded_form_elems()
9387:
9388: =item embedded_destination()
9389:
9390: =item return_to_editor()
9391:
9392: =item decompression_info()
9393:
9394: =item decompression_phase_one()
9395:
9396: =item decompression_phase_two()
9397:
9398: =item remove_archive()
9399:
9400: =item generate_admin_menu()
9401:
9402: =item generate_edit_table()
9403:
9404: =item editing_js()
9405:
9406: =item history_tab_js()
9407:
9408: =item inject_data_js()
9409:
9410: =item dump_switchserver_js()
9411:
1.485 raeburn 9412: =item resize_scrollbox_js()
1.484 raeburn 9413:
9414: =item makedocslogform()
9415:
1.485 raeburn 9416: =item makesimpleeditform()
9417:
1.329 droeschl 9418: =back
9419:
9420: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>