Annotation of loncom/interface/londocs.pm, revision 1.690
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.690 ! raeburn 4: # $Id: londocs.pm,v 1.689 2022/12/17 18:07:47 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'}) {
1210: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1.645 raeburn 1211: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1212: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1213: # FIXME: internationalization seems wrong here
1.329 droeschl 1214: $r->print('<li>'.
1215: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1216: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1217: .'</li>');
1218: }
1219: }
1220: $r->print('</ul>');
1221: }
1222: # End
1223: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1224: $shown++;
1225: if (!($env{'form.show'} eq &mt('all')
1226: || $shown<=$env{'form.show'})) { last; }
1227: }
1.484 raeburn 1228: $r->print(&Apache::loncommon::end_data_table()."\n".
1229: &makesimpleeditform($pathitem)."\n".
1230: '</div></div>');
1231: $r->print(&endContentScreen());
1.329 droeschl 1232: }
1233:
1234: sub update_paste_buffer {
1.492 raeburn 1235: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1236: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1237: if ($env{'form.multiremove'}) {
1238: $env{'form.multiremove'} =~ s/,$//;
1239: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1240: }
1241: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1242: if ($env{'form.multicut'}) {
1243: $env{'form.multicut'} =~ s/,$//;
1244: foreach my $item (split(/,/,$env{'form.multicut'})) {
1245: unless ($removals{$item}) {
1246: $cuts{$item} = 1;
1247: push(@possibles,$item.':cut');
1248: }
1249: }
1250: }
1251: if ($env{'form.multicopy'}) {
1252: $env{'form.multicopy'} =~ s/,$//;
1253: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1254: unless ($removals{$item} || $cuts{$item}) {
1255: push(@possibles,$item.':copy');
1256: }
1257: }
1258: }
1259: } elsif ($env{'form.markcopy'}) {
1260: @possibles = split(/,/,$env{'form.markcopy'});
1261: }
1.329 droeschl 1262:
1.538 raeburn 1263: return if (@possibles == 0);
1.329 droeschl 1264: return if (!defined($env{'form.copyfolder'}));
1265:
1266: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1267: $env{'form.copyfolder'});
1.538 raeburn 1268: return if ($fatal);
1269:
1270: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1271:
1.538 raeburn 1272: # Retrieve current paste buffer suffixes.
1273: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1274: my (%pasteurls,@newpaste);
1275:
1276: # Construct identifiers for current contents of user's paste buffer
1277: if (@currpaste) {
1278: foreach my $suffix (@currpaste) {
1.667 raeburn 1279: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1280: my $url = $env{'docs.markedcopy_url_'.$suffix};
1281: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1282: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1283: ($url ne '')) {
1284: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1285: $pasteurls{$cid.'_'.$mapidx} = 1;
1286: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1287: $pasteurls{$url} = 1;
1288: } else {
1.669 raeburn 1289: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1290: }
1291: }
1.538 raeburn 1292: }
1293: }
1294:
1295: # Mark items for copying (skip any items already in user's paste buffer)
1296: my %addtoenv;
1.597 raeburn 1297:
1298: my @pathitems = split(/\&/,$env{'form.folderpath'});
1299: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1300: my $ispage = $folderconf[5];
1.597 raeburn 1301:
1.538 raeburn 1302: foreach my $item (@possibles) {
1303: my ($orderidx,$cmd) = split(/:/,$item);
1304: next if ($orderidx =~ /\D/);
1305: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1306: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1307: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1308: my %denied = &action_restrictions($coursenum,$coursedom,
1309: &LONCAPA::map::qtescape($url),
1310: $env{'form.folderpath'},\%curr_groups);
1311: next if ($denied{'copy'});
1312: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1313: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1314: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1315: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1316: next if (exists($pasteurls{$url}));
1317: } else {
1318: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1319: }
1.538 raeburn 1320: my ($suffix,$errortxt,$locknotfreed) =
1321: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1322: if ($suffix ne '') {
1323: push(@newpaste,$suffix);
1324: } else {
1325: if ($locknotfreed) {
1326: return $locknotfreed;
1327: }
1.538 raeburn 1328: }
1329: if (&is_supplemental_title($title)) {
1330: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1331: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1332: }
1.329 droeschl 1333:
1.538 raeburn 1334: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1335: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1336: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1337: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1338: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1339: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1340: my $prefix = $1;
1341: my $subdir =$2;
1342: if ($subdir eq '') {
1343: $subdir = $prefix;
1.492 raeburn 1344: }
1.538 raeburn 1345: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1346: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1347: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1348: if (ref($hierarchy{$url}) eq 'HASH') {
1349: my ($nested,$nestednames);
1350: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1351: $nested =~ s/\&$//;
1352: $nestednames =~ s/\Q___&&&___\E$//;
1353: if ($nested ne '') {
1354: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1355: }
1356: if ($nestednames ne '') {
1357: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1358: }
1.492 raeburn 1359: }
1360: }
1.591 raeburn 1361: if ($locknotfreed) {
1362: $output = $locknotfreed;
1363: last;
1364: }
1.492 raeburn 1365: }
1.538 raeburn 1366: if (@newpaste) {
1367: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1368: }
1.492 raeburn 1369: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1370: delete($env{'form.markcopy'});
1.591 raeburn 1371: return $output;
1.329 droeschl 1372: }
1373:
1.492 raeburn 1374: sub recurse_uploaded_maps {
1375: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1376: if (ref($hierarchy->{$url}) eq 'HASH') {
1377: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1378: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1379: my (@uploaded,@names,%shorter);
1380: for (my $i=0; $i<@maps; $i++) {
1381: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1382: if ($inner ne '') {
1383: push(@uploaded,$inner);
1384: push(@names,&escape($titles[$i]));
1385: $shorter{$maps[$i]} = $inner;
1386: }
1387: }
1388: $$nestref .= "$dir:".join(',',@uploaded).'&';
1389: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1390: foreach my $map (@maps) {
1391: if ($shorter{$map} ne '') {
1392: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1393: }
1394: }
1395: }
1396: return;
1397: }
1398:
1.329 droeschl 1399: sub print_paste_buffer {
1.492 raeburn 1400: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1401: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1402:
1.538 raeburn 1403: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1404: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1405: }
1406:
1.538 raeburn 1407: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1408: my ($pasteitems,@pasteable);
1.575 raeburn 1409: my $clipboardcount = 0;
1.488 raeburn 1410:
1.538 raeburn 1411: # Construct identifiers for current contents of user's paste buffer
1412: foreach my $suffix (@currpaste) {
1413: next if ($suffix =~ /\D/);
1414: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1415: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1416: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1417: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1418: ($url ne '')) {
1.575 raeburn 1419: $clipboardcount ++;
1.538 raeburn 1420: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1421: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1422: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1423: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1424: $is_external = 1;
1.626 raeburn 1425: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1426: $is_exttool = 1;
1.538 raeburn 1427: }
1428: if ($folder =~ /^supplemental/) {
1429: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1430: unless ($canpaste) {
1431: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1432: }
1433: } else {
1434: $canpaste = 1;
1435: }
1436: if ($canpaste) {
1437: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1438: my $srcdom = $1;
1439: my $srcnum = $2;
1440: my $rem = $3;
1441: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1442: $othercourse = 1;
1443: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1444: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1445: } else {
1446: $canpaste = 0;
1447: $nopaste = &mt('Paste from another course unavailable.');
1448: }
1449: }
1450: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1451: my $prefix = $1;
1452: $parent = $2;
1453: if ($folder !~ /^\Q$prefix\E/) {
1454: $areachange = 1;
1455: }
1456: $is_uploaded_map = 1;
1.492 raeburn 1457: }
1.597 raeburn 1458: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1459: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1460: if ($cid ne $env{'request.course.id'}) {
1461: my ($srcdom,$srcnum) = split(/_/,$cid);
1462: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1463: if (($is_exttool) && ($srcdom ne $coursedom)) {
1464: $canpaste = 0;
1465: $nopaste = &mt('Paste from another domain unavailable.');
1466: } else {
1467: $othercrs = '<br />'.&mt('(from another course)');
1468: }
1.596 raeburn 1469: } else {
1470: $canpaste = 0;
1471: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1472: }
1.596 raeburn 1473: }
1.492 raeburn 1474: }
1.596 raeburn 1475: if ($canpaste) {
1476: push(@pasteable,$suffix);
1.629 raeburn 1477: }
1.538 raeburn 1478: }
1479: my $buffer;
1.627 raeburn 1480: if ($is_external) {
1.538 raeburn 1481: $buffer = &mt('External Resource').': '.
1482: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1483: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1484: } elsif ($is_exttool) {
1485: $buffer = &mt('External Tool').': '.
1486: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1487: } else {
1488: my $icon = &Apache::loncommon::icon($extension);
1489: if ($extension eq 'sequence' &&
1490: $url =~ m{/default_\d+\.sequence$}x) {
1491: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1492: $icon .= '/navmap.folder.closed.gif';
1493: }
1.589 raeburn 1494: my $title = $env{'docs.markedcopy_title_'.$suffix};
1495: if ($title eq '') {
1496: ($title) = ($url =~ m{/([^/]+)$});
1497: }
1.538 raeburn 1498: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1499: ': '.
1500: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1501: &LONCAPA::map::qtescape($title));
1.538 raeburn 1502: }
1503: $pasteitems .= '<div class="LC_left_float">';
1504: my ($options,$onclick);
1505: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1506: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1507: if (($is_uploaded_map) ||
1508: ($url =~ /(bulletinboard|smppg)$/) ||
1509: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1510: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1511: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1512: }
1513: }
1514: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1515: if ($nopaste) {
1.681 raeburn 1516: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1.538 raeburn 1517: } else {
1518: if ($othercrs) {
1519: $pasteitems .= $othercrs;
1520: }
1521: if ($options) {
1522: $pasteitems .= $options;
1.492 raeburn 1523: }
1524: }
1.538 raeburn 1525: $pasteitems .= '</div>';
1526: }
1527: }
1528: if ($pasteitems eq '') {
1529: &Apache::lonnet::delenv('docs.markedcopies');
1530: }
1531: my ($pasteform,$form_start,$buttons,$form_end);
1532: if ($pasteitems) {
1533: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1534: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1535: if (@pasteable) {
1.575 raeburn 1536: my $value = &mt('Paste to current folder');
1537: if ($container eq 'page') {
1538: $value = &mt('Paste to current page');
1539: }
1540: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1541: }
1542: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1543: if ($clipboardcount > 1) {
1544: $buttons .=
1545: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1546: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1547: (' 'x2).
1548: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1549: (' 'x2);
1.492 raeburn 1550: }
1.575 raeburn 1551: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1552: '</form>';
1.538 raeburn 1553: } else {
1554: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1555: }
1.538 raeburn 1556: $r->print($form_start
1557: .'<fieldset>'
1558: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1559: .$pasteitems
1560: .'</fieldset>'
1561: .$form_end);
1562: }
1563:
1564: sub paste_options {
1565: my ($suffix,$is_uploaded_map,$parent) = @_;
1566: my ($copytext,$movetext);
1567: if ($is_uploaded_map) {
1568: $copytext = &mt('Copy to new folder');
1569: $movetext = &mt('Move old');
1570: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1571: $copytext = &mt('Copy to new board');
1572: $movetext = &mt('Move (not posts)');
1573: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1574: $copytext = &mt('Copy to new page');
1575: $movetext = &mt('Move');
1.533 raeburn 1576: } else {
1.538 raeburn 1577: $copytext = &mt('Copy to new file');
1578: $movetext = &mt('Move');
1579: }
1580: my $output = '<br />'.
1581: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1582: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1583: '<label>'.
1584: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1585: $copytext.'</label></span>'.(' 'x2).' '.
1586: '<span class="LC_nobreak"><label>'.
1587: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1588: $movetext.'</label></span>';
1589: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1590: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1591: '</legend><table border="0">';
1592: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1593: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1594: my $lastdir = $parent;
1595: my %depths = (
1596: $lastdir => 0,
1597: );
1598: my (%display,%deps);
1599: for (my $i=0; $i<@pastemaps; $i++) {
1600: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1601: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1602: my @subfolders = split(/,/,$subfolderstr);
1603: $deps{$lastdir} = \@subfolders;
1604: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1605: my $depth = $depths{$lastdir} + 1;
1606: my $offset = int($depth * 4);
1607: my $indent = (' ' x $offset);
1608: for (my $j=0; $j<@subfolders; $j++) {
1609: $depths{$subfolders[$j]} = $depth;
1610: $display{$subfolders[$j]} =
1611: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1612: '<td><label>'.
1613: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1614: '<label>'.
1615: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1616: &mt('Move old').'</label>'.
1617: '</td></tr>';
1618: }
1.492 raeburn 1619: }
1.538 raeburn 1620: &recurse_print(\$output,$parent,\%deps,\%display);
1621: $output .= '</table></fieldset>';
1.329 droeschl 1622: }
1.538 raeburn 1623: $output .= '</div>';
1624: return $output;
1.488 raeburn 1625: }
1626:
1.492 raeburn 1627: sub recurse_print {
1.538 raeburn 1628: my ($outputref,$dir,$deps,$display) = @_;
1629: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1630: if (ref($deps->{$dir}) eq 'ARRAY') {
1631: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1632: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1633: }
1634: }
1635: }
1636:
1.488 raeburn 1637: sub supp_pasteable {
1638: my ($url) = @_;
1639: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1640: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1641: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1642: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1643: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1644: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1645: return 1;
1646: }
1647: return;
1.329 droeschl 1648: }
1649:
1.492 raeburn 1650: sub paste_popup_js {
1.594 damieng 1651: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1652: show => 'Show Options',
1653: hide => 'Hide Options',
1.594 damieng 1654: );
1655: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1656: none => 'No items selected from clipboard.',
1.492 raeburn 1657: );
1.594 damieng 1658: &html_escape(\%html_js_lt);
1659: &js_escape(\%html_js_lt);
1660: &js_escape(\%js_lt);
1.492 raeburn 1661: return <<"END";
1662:
1.538 raeburn 1663: function showPasteOptions(suffix) {
1664: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1665: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1666: return;
1667: }
1668:
1.538 raeburn 1669: function hidePasteOptions(suffix) {
1670: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1671: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1672: return;
1673: }
1674:
1675: function showOptions(caller,suffix) {
1676: if (document.getElementById('pasteoptionstext_'+suffix)) {
1677: if (caller.checked) {
1.594 damieng 1678: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1679: } else {
1680: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1681: }
1682: if (document.getElementById('pasteoptions_'+suffix)) {
1683: document.getElementById('pasteoptions_'+suffix).style.display='none';
1684: }
1685: }
1.492 raeburn 1686: return;
1687: }
1688:
1.541 raeburn 1689: function validateClipboard() {
1690: var numchk = 0;
1691: if (document.pasteform.pasting.length > 1) {
1692: for (var i=0; i<document.pasteform.pasting.length; i++) {
1693: if (document.pasteform.pasting[i].checked) {
1694: numchk ++;
1695: }
1696: }
1697: } else {
1698: if (document.pasteform.pasting.type == 'checkbox') {
1699: if (document.pasteform.pasting.checked) {
1700: numchk ++;
1701: }
1702: }
1703: }
1704: if (numchk > 0) {
1705: return true;
1706: } else {
1.594 damieng 1707: alert("$js_lt{'none'}");
1.541 raeburn 1708: return false;
1709: }
1710: }
1711:
1.575 raeburn 1712: function checkClipboard() {
1713: if (document.pasteform.pasting.length > 1) {
1714: for (var i=0; i<document.pasteform.pasting.length; i++) {
1715: document.pasteform.pasting[i].checked = true;
1716: }
1717: }
1718: return;
1719: }
1720:
1721: function uncheckClipboard() {
1722: if (document.pasteform.pasting.length >1) {
1723: for (var i=0; i<document.pasteform.pasting.length; i++) {
1724: document.pasteform.pasting[i].checked = false;
1725: }
1726: }
1727: return;
1728: }
1729:
1.492 raeburn 1730: END
1731:
1732: }
1733:
1.329 droeschl 1734: sub do_paste_from_buffer {
1.492 raeburn 1735: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1736:
1.538 raeburn 1737: # Array of items in paste buffer
1738: my (@currpaste,%pastebuffer,%allerrors);
1739: @currpaste = split(/,/,$env{'docs.markedcopies'});
1740:
1.492 raeburn 1741: # Early out if paste buffer is empty
1.538 raeburn 1742: if (@currpaste == 0) {
1.492 raeburn 1743: return ();
1.538 raeburn 1744: }
1745: map { $pastebuffer{$_} = 1; } @currpaste;
1746:
1747: # Array of items selected items to paste
1748: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1749:
1750: # Early out if nothing selected to paste
1751: if (@reqpaste == 0) {
1752: return();
1753: }
1754: my @topaste;
1755: foreach my $suffix (@reqpaste) {
1756: next if ($suffix =~ /\D/);
1757: next unless (exists($pastebuffer{$suffix}));
1758: push(@topaste,$suffix);
1759: }
1760:
1761: # Early out if nothing available to paste
1762: if (@topaste == 0) {
1763: return();
1.329 droeschl 1764: }
1765:
1.627 raeburn 1766: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1767: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1768:
1769: foreach my $suffix (@topaste) {
1770: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1771: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1772: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1773: # Supplemental content may only include certain types of content
1774: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1775: if ($folder =~ /^supplemental/) {
1776: unless (&supp_pasteable($url)) {
1777: $notinsupp{$suffix} = 1;
1778: next;
1779: }
1.492 raeburn 1780: }
1.538 raeburn 1781: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1782: my $srcd = $1;
1783: my $srcn = $2;
1.492 raeburn 1784: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1785: # check for mdc privilege in the course from which the resource was pasted
1786: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1787: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1788: $notincrs{$suffix} = 1;
1789: next;
1790: }
1.491 raeburn 1791: }
1.538 raeburn 1792: $srcdom{$suffix} = $srcd;
1793: $srcnum{$suffix} = $srcn;
1.597 raeburn 1794: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1795: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1796: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1797: my ($srcd,$srcn) = split(/_/,$cid);
1798: # When paste buffer was populated using an active role in a different course
1799: # check for mdc privilege in the course from which the resource was pasted
1800: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1801: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1802: $notincrs{$suffix} = 1;
1803: next;
1804: }
1805: }
1.632 raeburn 1806: # When buffer was populated using an active role in a different course
1807: # disallow pasting of External Tool if course is in a different domain.
1808: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1809: $notindom{$suffix} = 1;
1810: next;
1811: }
1.596 raeburn 1812: $srcdom{$suffix} = $srcd;
1813: $srcnum{$suffix} = $srcn;
1.491 raeburn 1814: }
1.597 raeburn 1815: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1816: push(@dopaste,$suffix);
1817: if ($url=~/\.(page|sequence)$/) {
1818: $is_map{$suffix} = 1;
1819: }
1820: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1821: my $oldprefix = $1;
1.492 raeburn 1822: # When pasting content from Main Content to Supplemental Content and vice versa
1823: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1824: # a folder/page or a document).
1.538 raeburn 1825: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1826: $prefixchg{$suffix} = 'docstosupp';
1827: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1828: $prefixchg{$suffix} = 'supptodocs';
1829: }
1.491 raeburn 1830:
1.492 raeburn 1831: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1832: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1833: my @nested;
1834: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1835: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1836: my @deps = map { /\d+:([\d,]+$)/ } @items;
1837: foreach my $dep (@deps) {
1838: if ($dep =~ /,/) {
1839: push(@nested,split(/,/,$dep));
1840: } else {
1841: push(@nested,$dep);
1842: }
1.492 raeburn 1843: }
1.538 raeburn 1844: foreach my $item (@nested) {
1845: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1846: push(@{$marktomove{$suffix}},$type.'_'.$item);
1847: }
1.492 raeburn 1848: }
1849: }
1.488 raeburn 1850: }
1851: }
1852:
1.538 raeburn 1853: # Early out if nothing available to paste
1854: if (@dopaste == 0) {
1855: return ();
1856: }
1857:
1858: # Populate message hash and hashes used for main content <=> supplemental content
1859: # changes
1860:
1861: %msgs = &Apache::lonlocal::texthash (
1862: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1863: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1864: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538 raeburn 1865: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1866: );
1867:
1868: %before = (
1869: docstosupp => {
1870: map => 'default',
1871: doc => 'docs',
1872: },
1873: supptodocs => {
1874: map => 'supplemental',
1875: doc => 'supplemental',
1876: },
1877: );
1878:
1879: %after = (
1880: docstosupp => {
1881: map => 'supplemental',
1882: doc => 'supplemental'
1883: },
1884: supptodocs => {
1885: map => 'default',
1886: doc => 'docs',
1887: },
1888: );
1889:
1890: # Retrieve information about all course maps in main content area
1891:
1892: my $allmaps = {};
1.660 raeburn 1893: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538 raeburn 1894:
1895: # Loop over the items to paste
1896: foreach my $suffix (@dopaste) {
1.329 droeschl 1897: # Maps need to be copied first
1.538 raeburn 1898: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1899: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1900: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1901: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1902: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1903: }
1904: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1905: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1906: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1907: my $oldurl = $url;
1908: if ($is_map{$suffix}) {
1.491 raeburn 1909: # If pasting a map, check if map contains other maps
1.538 raeburn 1910: my (%hierarchy,%titles);
1.660 raeburn 1911: if (($folder =~ /^default/) && (!$donechk)) {
1912: $allmaps =
1913: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1914: $env{"course.$env{'request.course.id'}.home"},
1915: $env{'request.course.id'});
1916: $donechk = 1;
1917: }
1.627 raeburn 1918: &contained_map_check($url,$folder,$coursenum,$coursedom,
1919: \%removefrommap,\%removeparam,\%addedmaps,
1920: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1921: if ($url=~ m{^/uploaded/}) {
1922: my $newurl;
1923: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1924: ($newurl,my $error) =
1925: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1926: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1927: \$title,$allmaps,\%newurls);
1928: if ($error) {
1929: $allerrors{$suffix} = $error;
1930: next;
1931: }
1932: if ($newurl ne '') {
1933: if ($newurl ne $url) {
1934: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1935: $newsubdir{$url} = $1;
1936: }
1937: $mapchanges{$url} = 1;
1.492 raeburn 1938: }
1.538 raeburn 1939: }
1940: }
1941: if (($srcdom{$suffix} ne $coursedom) ||
1942: ($srcnum{$suffix} ne $coursenum) ||
1943: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1944: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1945: $coursedom,$coursenum,$srcdom{$suffix},
1946: $srcnum{$suffix},$allmaps,\%rewrites,
1947: \%retitles,\%copies,\%dbcopies,
1948: \%zombies,\%params,\%mapmoves,
1949: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1950: \%newurls,\%resdatacopy)) {
1.538 raeburn 1951: $mapmoves{$url} = 1;
1952: }
1953: $url = $newurl;
1954: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1955: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1956: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1957: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1958: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1959: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1960: }
1961: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1962: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1963: push(@toclear,$suffix);
1964: # if pasting published map (main content area only) check map not already in course
1965: if ($folder =~ /^default/) {
1966: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1967: $duplicate{$suffix} = 1;
1968: next;
1.492 raeburn 1969: }
1.491 raeburn 1970: }
1971: }
1.538 raeburn 1972: }
1.627 raeburn 1973: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1974: my $prefix = $1;
1.648 raeburn 1975: my $fromothercrs;
1.538 raeburn 1976: #need to copy the db contents to a new one, unless this is a move.
1977: my %info = (
1978: src => $url,
1979: cdom => $coursedom,
1980: cnum => $coursenum,
1.596 raeburn 1981: );
1.649 raeburn 1982: if ($prefix eq 'ext.tool') {
1.655 raeburn 1983: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 1984: $info{'delgradable'} = 1;
1985: }
1986: }
1.596 raeburn 1987: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1988: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1989: $fromothercrs = 1;
1990: $info{'cdom'} = $srcdom{$suffix};
1991: $info{'cnum'} = $srcnum{$suffix};
1992: }
1993: }
1994: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 1995: my (%lockerr,$msg);
1.538 raeburn 1996: my ($newurl,$result,$errtext) =
1997: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1998: if ($result eq 'ok') {
1999: $url = $newurl;
2000: $title=&mt('Copy of').' '.$title;
2001: } else {
2002: if ($prefix eq 'smppg') {
2003: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
2004: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 2005: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 2006: } elsif ($prefix eq 'ext.tool') {
2007: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 2008: }
2009: $results{$suffix} = $result;
2010: $msgerrs{$suffix} = $msg;
2011: $lockerrs{$suffix} = $lockerr{$prefix};
2012: next;
2013: }
2014: if ($lockerr{$prefix}) {
2015: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 2016: }
1.489 raeburn 2017: }
2018: }
1.538 raeburn 2019: $title = &LONCAPA::map::qtunescape($title);
2020: my $ext='false';
2021: if ($url=~m{^http(|s)://}) { $ext='true'; }
2022: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2023: if ($folder !~ /^supplemental/) {
2024: (undef,undef,$title) =
2025: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2026: }
2027: } else {
2028: if ($folder=~/^supplemental/) {
2029: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2030: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 2031: }
1.533 raeburn 2032: }
1.491 raeburn 2033:
2034: # For uploaded files (excluding pages/sequences) path in copied file is changed
2035: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2036: # courses.
2037:
1.538 raeburn 2038: unless ($is_map{$suffix}) {
2039: my $newidx;
1.492 raeburn 2040: # Now insert the URL at the bottom
1.538 raeburn 2041: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2042: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2043: my $relpath = $1;
2044: if ($relpath ne '') {
2045: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2046: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2047: my $newprefix = $newloc;
2048: if ($newloc eq 'default') {
2049: $newprefix = 'docs';
2050: }
2051: if ($newdocsdir eq '') {
2052: $newdocsdir = 'default';
2053: }
1.630 raeburn 2054: if (($prefixchg{$suffix}) ||
2055: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 2056: ($srcnum{$suffix} ne $coursenum) ||
2057: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2058: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2059: $url =
2060: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2061: &Apache::lonnet::getfile($oldurl));
2062: if ($url eq '/adm/notfound.html') {
2063: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2064: next;
2065: } else {
2066: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2067: $newsubpath =~ s{/+$}{/};
2068: $docmoves{$oldurl} = $newsubpath;
2069: }
1.491 raeburn 2070: }
2071: }
1.597 raeburn 2072: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2073: my $template = $1;
2074: if ($newidx) {
2075: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2076: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2077: }
1.649 raeburn 2078: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2079: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2080: my $marker = (split(m{/},$url))[4];
2081: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2082: my $val = 'no';
2083: if ($toolsettings{'gradable'}) {
2084: $val = 'yes';
2085: }
2086: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2087: 'string_yesno');
2088: &remember_parms($newidx,'gradable','set',$val);
2089: }
1.491 raeburn 2090: }
1.538 raeburn 2091: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2092: ':'.$ext.':normal:res';
2093: push(@LONCAPA::map::order,$newidx);
2094: # Store the result
2095: my ($errtext,$fatal) =
2096: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2097: if ($fatal) {
2098: $save_err .= $errtext;
2099: $allresult = 'fail';
2100: }
1.488 raeburn 2101: }
1.538 raeburn 2102:
1.597 raeburn 2103: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2104: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2105: unless ($allresult eq 'fail') {
2106: my %updated = (
2107: rewrites => \%rewrites,
2108: zombies => \%zombies,
2109: removefrommap => \%removefrommap,
2110: removeparam => \%removeparam,
2111: dbcopies => \%dbcopies,
1.597 raeburn 2112: resdatacopy => \%resdatacopy,
1.538 raeburn 2113: retitles => \%retitles,
2114: );
2115: my %info = (
2116: newsubdir => \%newsubdir,
2117: params => \%params,
2118: );
2119: if ($prefixchg{$suffix}) {
2120: $info{'before'} = $before{$prefixchg{$suffix}};
2121: $info{'after'} = $after{$prefixchg{$suffix}};
2122: }
2123: my %moves = (
2124: copies => \%copies,
2125: docmoves => \%docmoves,
2126: mapmoves => \%mapmoves,
2127: );
2128: (my $result,$msgs{$suffix},my $lockerror) =
2129: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2130: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2131: $url,'paste');
2132: $lockerrors .= $lockerror;
2133: if ($result eq 'ok') {
2134: if ($is_map{$suffix}) {
2135: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2136: $folder.'.'.$container);
2137: if ($fatal) {
2138: $allresult = 'failread';
2139: } else {
2140: if ($#LONCAPA::map::order<1) {
2141: my $idx=&LONCAPA::map::getresidx();
2142: if ($idx<=0) { $idx=1; }
2143: $LONCAPA::map::order[0]=$idx;
2144: $LONCAPA::map::resources[$idx]='';
2145: }
2146: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2147: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2148: ':'.$ext.':normal:res';
2149: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2150:
2151: # Store the result
1.538 raeburn 2152: my ($errtext,$fatal) =
2153: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2154: if ($fatal) {
2155: $save_err .= $errtext;
2156: $allresult = 'failstore';
2157: }
2158: }
2159: }
2160: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2161: push(@toclear,$suffix);
2162: }
2163: }
1.492 raeburn 2164: }
2165: }
1.538 raeburn 2166: &clear_from_buffer(\@toclear,\@currpaste);
2167: my $msgsarray;
2168: foreach my $suffix (keys(%msgs)) {
2169: if (ref($msgs{$suffix}) eq 'ARRAY') {
2170: $msgsarray .= join(',',@{$msgs{$suffix}});
2171: }
2172: }
2173: return ($allresult,$save_err,$msgsarray,$lockerrors);
2174: }
1.533 raeburn 2175:
1.538 raeburn 2176: sub do_buffer_empty {
2177: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2178: if (@currpaste == 0) {
2179: return &mt('Clipboard is already empty');
2180: }
2181: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2182: if (@toclear == 0) {
2183: return &mt('Nothing selected to clear from clipboard');
2184: }
2185: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2186: if ($numdel) {
2187: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2188: } else {
2189: return &mt('Clipboard unchanged');
1.492 raeburn 2190: }
1.538 raeburn 2191: return;
2192: }
2193:
2194: sub clear_from_buffer {
2195: my ($toclear,$currpaste) = @_;
2196: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2197: my %pastebuffer;
2198: map { $pastebuffer{$_} = 1; } @{$currpaste};
2199: my $numdel = 0;
2200: foreach my $suffix (@{$toclear}) {
2201: next if ($suffix =~ /\D/);
2202: next unless (exists($pastebuffer{$suffix}));
2203: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2204: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2205: delete($pastebuffer{$suffix});
2206: $numdel ++;
2207: }
2208: }
2209: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2210: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2211: return $numdel;
1.492 raeburn 2212: }
2213:
2214: sub get_newmap_url {
2215: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2216: $titleref,$allmaps,$newurls) = @_;
2217: my $newurl;
2218: if ($url=~ m{^/uploaded/}) {
2219: $$titleref=&mt('Copy of').' '.$$titleref;
2220: }
2221: my $now = time;
2222: my $suffix=$$.int(rand(100)).$now;
2223: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2224: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2225: my $path = $1;
2226: my $prefix = $2;
2227: my $ancestor = $3;
2228: if (length($ancestor) > 10) {
2229: $ancestor = substr($ancestor,-10,10);
2230: }
2231: my $newid;
2232: if ($prefixchg) {
2233: if ($folder =~ /^supplemental/) {
2234: $prefix =~ s/^default/supplemental/;
2235: } else {
2236: $prefix =~ s/^supplemental/default/;
2237: }
2238: }
2239: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2240: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2241: } else {
2242: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2243: }
2244: my $counter = 0;
2245: my $is_unique = &uniqueness_check($newurl);
2246: if ($folder =~ /^default/) {
2247: if ($allmaps->{$newurl}) {
2248: $is_unique = 0;
2249: }
2250: }
2251: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2252: $counter ++;
2253: $suffix ++;
2254: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2255: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2256: } else {
2257: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2258: }
2259: $is_unique = &uniqueness_check($newurl);
2260: }
2261: if ($is_unique) {
2262: $newurls->{$newurl} = 1;
2263: } else {
2264: if ($url=~/\.page$/) {
2265: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2266: } else {
2267: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2268: }
2269: }
1.329 droeschl 2270: }
1.492 raeburn 2271: return ($newurl);
1.329 droeschl 2272: }
2273:
1.488 raeburn 2274: sub dbcopy {
1.533 raeburn 2275: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2276: my ($url,$result,$errtext);
2277: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2278: $url = $dbref->{'src'};
1.627 raeburn 2279: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2280: my $prefix = $1;
1.627 raeburn 2281: if ($prefix eq 'ext.tool') {
2282: $prefix = 'exttool';
2283: }
1.533 raeburn 2284: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2285: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2286: my $db_name;
2287: my $marker = (split(m{/},$url))[4];
2288: $marker=~s/\D//g;
2289: if ($dbref->{'src'} =~ m{/smppg$}) {
2290: $db_name =
2291: &Apache::lonsimplepage::get_db_name($url,$marker,
2292: $dbref->{'cdom'},
2293: $dbref->{'cnum'});
1.627 raeburn 2294: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2295: $db_name = 'exttool_'.$marker;
1.533 raeburn 2296: } else {
2297: $db_name = 'bulletinpage_'.$marker;
2298: }
2299: my ($suffix,$freedlock,$error) =
2300: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2301: $coursedom,$coursenum,
2302: 'concat');
2303: if (!$suffix) {
2304: if ($prefix eq 'smppg') {
2305: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2306: } elsif ($prefix eq 'exttool') {
2307: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2308: } else {
1.565 bisitz 2309: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2310: }
2311: if ($error) {
2312: $errtext .= '<br />'.$error;
2313: }
2314: } else {
2315: #need to copy the db contents to a new one.
2316: my %contents=&Apache::lonnet::dump($db_name,
2317: $dbref->{'cdom'},
2318: $dbref->{'cnum'});
2319: if (exists($contents{'uploaded.photourl'})) {
2320: my $photo = $contents{'uploaded.photourl'};
2321: my ($subdir,$fname) =
2322: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2323: my $newphoto;
1.533 raeburn 2324: if ($fname ne '') {
2325: my $content = &Apache::lonnet::getfile($photo);
2326: unless ($content eq '-1') {
2327: $env{'form.'.$suffix.'.photourl'} = $content;
2328: $newphoto =
2329: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2330: delete($env{'form.'.$suffix.'.photourl'});
2331: }
2332: }
2333: if ($newphoto =~ m{^/uploaded/}) {
2334: $contents{'uploaded.photourl'} = $newphoto;
2335: }
2336: }
2337: $db_name =~ s{_\d*$ }{_$suffix}x;
1.649 raeburn 2338: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2339: delete($contents{'gradable'});
2340: }
1.533 raeburn 2341: $result=&Apache::lonnet::put($db_name,\%contents,
2342: $coursedom,$coursenum);
2343: if ($result eq 'ok') {
1.627 raeburn 2344: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2345: }
2346: }
2347: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2348: $lockerrorsref->{$prefix} =
1.533 raeburn 2349: '<div class="LC_error">'.
2350: &mt('There was a problem removing a lockfile.');
2351: if ($prefix eq 'smppg') {
1.560 raeburn 2352: $lockerrorsref->{$prefix} .=
1.559 raeburn 2353: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2354: } elsif ($prefix eq 'exttool') {
2355: $lockerrorsref->{$prefix} .=
2356: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2357: } else {
1.565 bisitz 2358: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2359: }
1.560 raeburn 2360: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2361: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2362: '</div>';
1.533 raeburn 2363: }
2364: }
2365: } elsif ($url =~ m{/syllabus$}) {
2366: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2367: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2368: if (($dbref->{'cdom'} ne $coursedom) ||
2369: ($dbref->{'cnum'} ne $coursenum)) {
2370: my %contents=&Apache::lonnet::dump('syllabus',
2371: $dbref->{'cdom'},
2372: $dbref->{'cnum'});
2373: $result=&Apache::lonnet::put('syllabus',\%contents,
2374: $coursedom,$coursenum);
2375: }
2376: }
1.488 raeburn 2377: }
2378: }
1.533 raeburn 2379: return ($url,$result,$errtext);
1.488 raeburn 2380: }
2381:
1.597 raeburn 2382: sub copy_templated_files {
2383: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2384: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2385: my $srccontainer = 'sequence';
2386: if ($srcwaspage) {
2387: $srccontainer = 'page';
2388: }
2389: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2390: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2391: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2392: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2393: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2394: $template.'.problem';
2395: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2396: if ($template eq 'simpleproblem') {
2397: $srcprefix .= '.0.';
2398: my $weightprefix = $newprefix;
2399: $newprefix .= '.0.';
2400: my @simpleprobqtypes = qw(radio option string essay numerical);
2401: my $qtype=$srcparms{$srcprefix.'questiontype'};
2402: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2403: my %newdata = (
2404: $newprefix.'questiontype' => $qtype,
2405: );
1.597 raeburn 2406: foreach my $type (@simpleprobqtypes) {
2407: if ($type eq $qtype) {
2408: $newdata{"$weightprefix.$type.weight"}=1;
2409: } else {
2410: $newdata{"$weightprefix.$type.weight"}=0;
2411: }
2412: }
2413: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2414: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2415: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2416: if ($qtype eq 'numerical') {
2417: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2418: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2419: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2420: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2421: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2422: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2423: unless (defined($maxfoils)) { $maxfoils=10; }
2424: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2425: if ($maxfoils<=0) { $maxfoils=10; }
2426: my $randomize=$srcparms{$srcprefix.'randomize'};
2427: unless (defined($randomize)) { $randomize='yes'; }
2428: unless ($randomize eq 'no') { $randomize='yes'; }
2429: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2430: $newdata{$newprefix.'randomize'} = $randomize;
2431: if ($qtype eq 'option') {
2432: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2433: }
2434: for (my $i=1; $i<=10; $i++) {
2435: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2436: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2437: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2438: }
2439:
2440: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2441: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2442: unless (defined($maxfoils)) { $maxfoils=10; }
2443: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2444: if ($maxfoils<=0) { $maxfoils=10; }
2445: my $randomize=$srcparms{$srcprefix.'randomize'};
2446: unless (defined($randomize)) { $randomize='yes'; }
2447: unless ($randomize eq 'no') { $randomize='yes'; }
2448: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2449: $newdata{$newprefix.'randomize'} = $randomize;
2450: if ($qtype eq 'option') {
2451: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2452: }
2453: for (my $i=1; $i<=10; $i++) {
2454: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2455: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2456: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2457: }
2458: } elsif ($qtype eq 'string') {
2459: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2460: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2461: }
2462: if (keys(%newdata)) {
2463: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2464: $coursenum);
2465: if ($putres eq 'ok') {
2466: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2467: }
2468: }
2469: }
2470: }
2471: }
2472:
1.329 droeschl 2473: sub uniqueness_check {
2474: my ($newurl) = @_;
2475: my $unique = 1;
2476: foreach my $res (@LONCAPA::map::order) {
2477: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2478: $url=&LONCAPA::map::qtescape($url);
2479: if ($newurl eq $url) {
2480: $unique = 0;
1.344 bisitz 2481: last;
1.329 droeschl 2482: }
2483: }
2484: return $unique;
2485: }
2486:
1.488 raeburn 2487: sub contained_map_check {
1.627 raeburn 2488: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2489: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2490: my $content = &Apache::lonnet::getfile($url);
2491: unless ($content eq '-1') {
2492: my $parser = HTML::TokeParser->new(\$content);
2493: $parser->attr_encoded(1);
2494: while (my $token = $parser->get_token) {
2495: next if ($token->[0] ne 'S');
2496: if ($token->[1] eq 'resource') {
2497: next if ($token->[2]->{'type'} eq 'zombie');
2498: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2499: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2500: my $srcdom = $1;
2501: unless ($srcdom eq $coursedom) {
2502: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2503: next;
2504: }
2505: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2506: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2507: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2508: next;
2509: }
2510: }
1.492 raeburn 2511: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2512: if ($1 eq 'uploaded') {
2513: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2514: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2515: } else {
1.492 raeburn 2516: if ($allmaps->{$ressrc}) {
1.529 raeburn 2517: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2518: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2519: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2520: } else {
2521: $addedmaps->{$ressrc} = [$url];
2522: }
1.488 raeburn 2523: }
1.627 raeburn 2524: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2525: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2526: }
1.492 raeburn 2527: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2528: if ($folder =~ /^supplemental/) {
1.492 raeburn 2529: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2530: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2531: } else {
2532: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2533: }
1.488 raeburn 2534: }
2535: }
2536: }
2537: }
2538: return;
2539: }
2540:
2541: sub url_paste_fixups {
1.533 raeburn 2542: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2543: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2544: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2545: my $checktitle;
2546: if (($prefixchg) &&
1.492 raeburn 2547: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2548: $checktitle = 1;
2549: }
1.492 raeburn 2550: my $skip;
2551: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2552: my $mapid = $1.$2;
2553: if ($tomove->{$mapid}) {
2554: $skip = 1;
2555: }
2556: }
1.491 raeburn 2557: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2558: return if ($file eq '-1');
2559: my $parser = HTML::TokeParser->new(\$file);
2560: $parser->attr_encoded(1);
1.491 raeburn 2561: my $changed = 0;
1.488 raeburn 2562: while (my $token = $parser->get_token) {
2563: next if ($token->[0] ne 'S');
2564: if ($token->[1] eq 'resource') {
2565: my $ressrc = $token->[2]->{'src'};
2566: next if ($ressrc eq '');
1.491 raeburn 2567: my $id = $token->[2]->{'id'};
1.492 raeburn 2568: my $title = $token->[2]->{'title'};
1.491 raeburn 2569: if ($checktitle) {
2570: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2571: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2572: }
2573: }
1.488 raeburn 2574: next if ($token->[2]->{'type'} eq 'external');
2575: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2576: next if ($skip);
1.532 raeburn 2577: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2578: $changed = 1;
2579: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2580: my $srcdom = $1;
2581: my $srcnum = $2;
1.488 raeburn 2582: my $rem = $3;
1.492 raeburn 2583: my $newurl;
2584: my $mapname;
2585: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2586: my $prefix = $1;
2587: $mapname = $prefix.$2;
2588: if ($tomove->{$mapname}) {
1.533 raeburn 2589: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2590: $srcdom,$srcnum,$allmaps,$rewrites,
2591: $retitles,$copies,$dbcopies,$zombies,
2592: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2593: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2594: next;
2595: } else {
2596: ($newurl,my $error) =
2597: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2598: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2599: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2600: $newsubdir->{$ressrc} = $1;
2601: }
2602: if ($error) {
2603: next;
2604: }
2605: }
2606: }
2607: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2608: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2609:
1.488 raeburn 2610: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2611: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2612: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2613: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2614: $cnum,$srcdom,$srcnum,$allmaps,
2615: $rewrites,$retitles,$copies,$dbcopies,
2616: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2617: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2618: $mapmoves->{$ressrc} = 1;
2619: }
2620: $changed = 1;
1.488 raeburn 2621: } else {
1.532 raeburn 2622: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2623: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2624: $changed = 1;
1.488 raeburn 2625: }
2626: }
1.649 raeburn 2627: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2628: next if ($skip);
1.492 raeburn 2629: my $srcdom = $1;
2630: my $srcnum = $2;
1.649 raeburn 2631: my $rem = $3;
2632: my ($is_exttool,$exttoolchg);
2633: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2634: $is_exttool = 1;
1.649 raeburn 2635: }
1.492 raeburn 2636: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2637: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2638: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2639: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2640: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2641: $changed = 1;
1.649 raeburn 2642: if ($is_exttool) {
2643: $exttoolchg = 1;
2644: }
2645: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2646: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2647: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2648: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2649: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2650: $changed = 1;
2651: $exttoolchg = 1;
2652: }
2653: if (($is_exttool) && ($prefixchg)) {
2654: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2655: if ($exttoolchg) {
2656: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2657: }
2658: }
1.533 raeburn 2659: }
2660: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2661: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2662: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2663: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2664: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2665: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2666: $changed = 1;
1.488 raeburn 2667: }
1.597 raeburn 2668: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2669: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2670: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2671: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2672: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2673: }
1.488 raeburn 2674: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2675: next if ($skip);
2676: my $srcdom = $1;
2677: my $srcnum = $2;
2678: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2679: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2680: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2681: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2682: $changed = 1;
1.488 raeburn 2683: }
2684: }
2685: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2686: next if ($skip);
1.488 raeburn 2687: my $to = $token->[2]->{'to'};
2688: if ($to ne '') {
2689: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2690: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2691: } else {
2692: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2693: }
2694: }
2695: }
2696: }
1.491 raeburn 2697: return $changed;
1.488 raeburn 2698: }
2699:
2700: sub apply_fixups {
1.529 raeburn 2701: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2702: $oldurl,$url,$caller) = @_;
2703: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2704: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2705: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2706: if (ref($updated) eq 'HASH') {
2707: if (ref($updated->{'rewrites'}) eq 'HASH') {
2708: %rewrites = %{$updated->{'rewrites'}};
2709: }
2710: if (ref($updated->{'zombies'}) eq 'HASH') {
2711: %zombies = %{$updated->{'zombies'}};
2712: }
2713: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2714: %removefrommap = %{$updated->{'removefrommap'}};
2715: }
2716: if (ref($updated->{'removeparam'}) eq 'HASH') {
2717: %removeparam = %{$updated->{'removeparam'}};
2718: }
2719: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2720: %dbcopies = %{$updated->{'dbcopies'}};
2721: }
2722: if (ref($updated->{'retitles'}) eq 'HASH') {
2723: %retitles = %{$updated->{'retitles'}};
2724: }
1.597 raeburn 2725: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2726: %resdatacopy = %{$updated->{'resdatacopy'}};
2727: }
1.529 raeburn 2728: }
2729: if (ref($info) eq 'HASH') {
2730: if (ref($info->{'newsubdir'}) eq 'HASH') {
2731: %newsubdir = %{$info->{'newsubdir'}};
2732: }
2733: if (ref($info->{'params'}) eq 'HASH') {
2734: %params = %{$info->{'params'}};
2735: }
2736: if (ref($info->{'before'}) eq 'HASH') {
2737: %before = %{$info->{'before'}};
2738: }
2739: if (ref($info->{'after'}) eq 'HASH') {
2740: %after = %{$info->{'after'}};
2741: }
2742: }
2743: if (ref($moves) eq 'HASH') {
2744: if (ref($moves->{'copies'}) eq 'HASH') {
2745: %copies = %{$moves->{'copies'}};
2746: }
2747: if (ref($moves->{'docmoves'}) eq 'HASH') {
2748: %docmoves = %{$moves->{'docmoves'}};
2749: }
2750: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2751: %mapmoves = %{$moves->{'mapmoves'}};
2752: }
2753: }
2754: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2755: my @allcopies;
1.529 raeburn 2756: if (exists($copies{$key})) {
2757: if (ref($copies{$key}) eq 'HASH') {
2758: my %added;
2759: foreach my $innerkey (keys(%{$copies{$key}})) {
2760: if (($innerkey ne '') && (!$added{$innerkey})) {
2761: push(@allcopies,$innerkey);
2762: $added{$innerkey} = 1;
2763: }
1.491 raeburn 2764: }
1.529 raeburn 2765: undef(%added);
1.491 raeburn 2766: }
2767: }
2768: if ($key eq $oldurl) {
1.529 raeburn 2769: if ((exists($docmoves{$key}))) {
1.532 raeburn 2770: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2771: push(@allcopies,$oldurl);
2772: }
2773: }
2774: }
2775: if (@allcopies > 0) {
2776: foreach my $item (@allcopies) {
1.492 raeburn 2777: my ($relpath,$oldsubdir,$fname) =
2778: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2779: if ($fname ne '') {
2780: my $content = &Apache::lonnet::getfile($item);
2781: unless ($content eq '-1') {
2782: my $storefn;
1.529 raeburn 2783: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2784: $storefn = $docmoves{$key};
1.491 raeburn 2785: } else {
2786: $storefn = $relpath;
2787: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2788: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2789: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2790: }
1.529 raeburn 2791: if ($newsubdir{$key}) {
1.532 raeburn 2792: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2793: }
2794: }
2795: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2796: my $copyurl =
2797: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2798: $storefn.$fname,$content);
2799: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2800: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2801: return &mt('Paste failed: an error occurred copying the file.');
2802: } elsif (ref($errors) eq 'HASH') {
2803: $errors->{$item} = 1;
1.489 raeburn 2804: }
2805: }
1.488 raeburn 2806: }
2807: }
1.491 raeburn 2808: }
2809: }
2810: }
1.529 raeburn 2811: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2812: my $storefn=$key;
2813: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2814: if ($prefixchg && $before{'map'} && $after{'map'}) {
2815: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2816: }
1.529 raeburn 2817: if ($newsubdir{$key}) {
2818: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2819: }
1.491 raeburn 2820: my $mapcontent = &Apache::lonnet::getfile($key);
1.681 raeburn 2821: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2822: ($after{'map'} eq 'default') &&
2823: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2824: $mapcontent = '<map>'."\n".
2825: '<resource id="1" src="" type="start" />'."\n".
2826: '<link from="1" to="2" index="1" />'."\n".
2827: '<resource id="2" src="" type="finish" />'."\n".
2828: '</map>';
2829: }
1.491 raeburn 2830: if ($mapcontent eq '-1') {
2831: if (ref($errors) eq 'HASH') {
2832: $errors->{$key} = 1;
2833: }
2834: } else {
2835: my $newmap =
2836: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2837: $mapcontent);
2838: if ($newmap eq '/adm/notfound.html') {
2839: if (ref($errors) eq 'HASH') {
2840: $errors->{$key} = 1;
1.489 raeburn 2841: }
1.488 raeburn 2842: }
2843: }
2844: }
1.491 raeburn 2845: my %updates;
2846: if ($is_map) {
1.529 raeburn 2847: if (ref($updated) eq 'HASH') {
2848: foreach my $type (keys(%{$updated})) {
2849: if (ref($updated->{$type}) eq 'HASH') {
2850: foreach my $key (keys(%{$updated->{$type}})) {
2851: $updates{$key} = 1;
2852: }
2853: }
2854: }
1.491 raeburn 2855: }
2856: foreach my $key (keys(%updates)) {
1.492 raeburn 2857: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2858: if (ref($rewrites{$key}) eq 'HASH') {
2859: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2860: }
1.529 raeburn 2861: if (ref($retitles{$key}) eq 'HASH') {
2862: %toretitle = %{$retitles{$key}};
1.491 raeburn 2863: }
1.529 raeburn 2864: if (ref($removefrommap{$key}) eq 'HASH') {
2865: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2866: }
1.529 raeburn 2867: if (ref($removeparam{$key}) eq 'HASH') {
2868: %remparam = %{$removeparam{$key}};
1.492 raeburn 2869: }
1.529 raeburn 2870: if (ref($zombies{$key}) eq 'HASH') {
2871: %zombie = %{$zombies{$key}};
1.491 raeburn 2872: }
1.529 raeburn 2873: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2874: foreach my $idx (keys(%{$dbcopies{$key}})) {
2875: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2876: my ($newurl,$result,$errtext) =
2877: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2878: if ($result eq 'ok') {
2879: $newdb{$idx} = $newurl;
2880: } elsif (ref($errors) eq 'HASH') {
2881: $errors->{$key} = 1;
2882: }
2883: push(@msgs,$errtext);
2884: }
1.491 raeburn 2885: }
2886: }
1.597 raeburn 2887: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 2888: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2889: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2890: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2891: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2892: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2893: my $template = $1;
2894: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2895: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2896: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2897: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 2898: unless ($gotnewmapname) {
2899: ($newmapname) = ($key =~ m{/([^/]+)$});
2900: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2901: if ($newsubdir{$key}) {
2902: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2903: }
2904: $gotnewmapname = 1;
2905: }
1.597 raeburn 2906: my $srcmapinfo = $srcfolder.':'.$idx;
2907: if ($srccontainer eq 'page') {
2908: $srcmapinfo .= ':1';
2909: }
2910: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2911: $cnum,$template,$idx,$newmapname);
2912: }
2913: }
2914: }
2915: }
2916: }
1.529 raeburn 2917: if (ref($params{$key}) eq 'HASH') {
2918: %currparam = %{$params{$key}};
1.492 raeburn 2919: }
2920: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2921: if ($fatal) {
1.533 raeburn 2922: return ($errtext);
1.492 raeburn 2923: }
2924: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2925: if (defined($LONCAPA::map::zombies[$i])) {
2926: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2927: if ($zombie{$i} eq $src) {
1.492 raeburn 2928: undef($LONCAPA::map::zombies[$i]);
2929: }
2930: }
2931: }
1.646 raeburn 2932: my $total = scalar(@LONCAPA::map::order) - 1;
2933: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2934: my $idx = $LONCAPA::map::order[$i];
2935: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2936: my $changed;
1.529 raeburn 2937: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2938: if ((exists($toremove{$idx})) &&
2939: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2940: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2941: if (ref($currparam{$idx}) eq 'ARRAY') {
2942: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2943: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2944: }
2945: }
2946: next;
2947: }
2948: my $origsrc = $src;
1.532 raeburn 2949: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2950: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2951: $changed = 1;
1.491 raeburn 2952: }
1.492 raeburn 2953: }
1.532 raeburn 2954: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2955: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2956: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2957: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2958: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2959: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2960: } else {
1.529 raeburn 2961: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2962: }
1.491 raeburn 2963: }
1.532 raeburn 2964: if ($origsrc =~ /\.(page|sequence)$/) {
2965: if ($newsubdir{$origsrc}) {
1.529 raeburn 2966: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2967: }
1.532 raeburn 2968: } elsif ($newsubdir{$key}) {
2969: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2970: }
2971: }
1.492 raeburn 2972: $changed = 1;
1.533 raeburn 2973: } elsif ($newdb{$idx} ne '') {
2974: $src = $newdb{$idx};
1.492 raeburn 2975: $changed = 1;
2976: }
2977: if ($changed) {
1.538 raeburn 2978: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2979: }
2980: }
2981: }
2982: foreach my $idx (keys(%remparam)) {
2983: if (ref($remparam{$idx}) eq 'ARRAY') {
2984: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 2985: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 2986: }
2987: }
2988: }
1.533 raeburn 2989: if (values(%lockerrors) > 0) {
2990: $lockmsg = join('<br />',values(%lockerrors));
2991: }
1.491 raeburn 2992: my $storefn;
2993: if ($key eq $oldurl) {
2994: $storefn = $url;
2995: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2996: } else {
2997: $storefn = $key;
2998: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2999: if ($prefixchg && $before{'map'} && $after{'map'}) {
3000: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 3001: }
1.529 raeburn 3002: if ($newsubdir{$key}) {
3003: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 3004: }
1.491 raeburn 3005: }
1.492 raeburn 3006: my $report;
3007: if ($folder !~ /^supplemental/) {
3008: $report = 1;
3009: }
1.527 raeburn 3010: (my $outtext,$errtext) =
1.492 raeburn 3011: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
3012: if ($errtext) {
1.529 raeburn 3013: if ($caller eq 'paste') {
1.533 raeburn 3014: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 3015: }
1.491 raeburn 3016: }
3017: }
3018: }
1.533 raeburn 3019: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 3020: }
3021:
3022: sub copy_dependencies {
3023: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3024: my $content;
3025: if (ref($contentref)) {
3026: $content = $$contentref;
3027: } else {
3028: $content = &Apache::lonnet::getfile($item);
3029: }
3030: unless ($content eq '-1') {
3031: my $mm = new File::MMagic;
3032: my $mimetype = $mm->checktype_contents($content);
3033: if ($mimetype eq 'text/html') {
3034: my (%allfiles,%codebase,$state);
3035: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3036: if ($res eq 'ok') {
3037: my ($numexisting,$numpathchanges,$existing);
3038: (undef,$numexisting,$numpathchanges,$existing) =
3039: &Apache::loncommon::ask_for_embedded_content(
3040: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3041: {'error_on_invalid_names' => 1,
3042: 'ignore_remote_references' => 1,
3043: 'docs_url' => $item,
3044: 'context' => 'paste'});
3045: if ($numexisting > 0) {
3046: if (ref($existing) eq 'HASH') {
3047: foreach my $dep (keys(%{$existing})) {
3048: my $depfile = $dep;
3049: unless ($depfile =~ m{^\Q$relpath\E}) {
3050: $depfile = $relpath.$dep;
3051: }
3052: my $depcontent = &Apache::lonnet::getfile($depfile);
3053: unless ($depcontent eq '-1') {
3054: my $storedep = $dep;
3055: $storedep =~ s{^\Q$relpath\E}{};
3056: my $dep_url =
3057: &Apache::lonclonecourse::writefile(
3058: $env{'request.course.id'},
3059: $storefn.$storedep,$depcontent);
3060: if ($dep_url eq '/adm/notfound.html') {
3061: if (ref($errors) eq 'HASH') {
3062: $errors->{$depfile} = 1;
3063: }
3064: } else {
3065: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3066: }
3067: }
3068: }
1.488 raeburn 3069: }
3070: }
3071: }
3072: }
3073: }
3074: return;
3075: }
3076:
1.329 droeschl 3077: my %parameter_type = ( 'randompick' => 'int_pos',
3078: 'hiddenresource' => 'string_yesno',
3079: 'encrypturl' => 'string_yesno',
3080: 'randomorder' => 'string_yesno',);
3081: my $valid_parameters_re = join('|',keys(%parameter_type));
3082: # set parameters
3083: sub update_parameter {
1.537 raeburn 3084: if ($env{'form.changeparms'} eq 'all') {
3085: my (@allidx,@allmapidx,%allchecked,%currchecked);
3086: %allchecked = (
3087: 'hiddenresource' => {},
3088: 'encrypturl' => {},
3089: 'randompick' => {},
3090: 'randomorder' => {},
3091: );
3092: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3093: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3094: if ($which eq 'randompick') {
3095: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3096: my ($res,$value) = split(/:/,$item);
3097: if ($value =~ /^\d+$/) {
3098: $allchecked{$which}{$res} = $value;
3099: }
3100: }
3101: } else {
1.539 raeburn 3102: if ($env{'form.all'.$which}) {
3103: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3104: }
1.537 raeburn 3105: }
3106: }
3107: my $haschanges = 0;
3108: foreach my $res (@LONCAPA::map::order) {
3109: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3110: $name=&LONCAPA::map::qtescape($name);
3111: $url=&LONCAPA::map::qtescape($url);
3112: next unless ($name && $url);
3113: my $is_map;
3114: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3115: $is_map = 1;
3116: }
3117: foreach my $which (keys(%allchecked)) {
3118: if (($which eq 'randompick' || $which eq 'randomorder')) {
3119: next if (!$is_map);
3120: }
3121: my $oldvalue = 0;
3122: my $newvalue = 0;
3123: if ($allchecked{$which}{$res}) {
3124: $newvalue = $allchecked{$which}{$res};
3125: }
3126: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3127: if ($which eq 'randompick') {
3128: if ($current =~ /^(\d+)$/) {
3129: $oldvalue = $1;
3130: }
3131: } else {
3132: if ($current =~ /^yes$/i) {
3133: $oldvalue = 1;
3134: }
3135: }
3136: if ($oldvalue ne $newvalue) {
3137: $haschanges = 1;
3138: if ($newvalue) {
3139: my $storeval = 'yes';
3140: if ($which eq 'randompick') {
3141: $storeval = $newvalue;
3142: }
3143: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3144: $storeval,
3145: $parameter_type{$which});
3146: &remember_parms($res,$which,'set',$storeval);
3147: } elsif ($oldvalue) {
3148: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3149: &remember_parms($res,$which,'del');
3150: }
3151: }
3152: }
3153: }
3154: return $haschanges;
3155: } else {
1.588 raeburn 3156: my $haschanges = 0;
3157: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3158:
1.537 raeburn 3159: my $which = $env{'form.changeparms'};
3160: my $idx = $env{'form.setparms'};
1.588 raeburn 3161: my $oldvalue = 0;
3162: my $newvalue = 0;
3163: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3164: if ($which eq 'randompick') {
3165: if ($current =~ /^(\d+)$/) {
3166: $oldvalue = $1;
3167: }
3168: } elsif ($current =~ /^yes$/i) {
3169: $oldvalue = 1;
3170: }
1.537 raeburn 3171: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3172: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3173: : 1;
3174: }
3175: if ($oldvalue ne $newvalue) {
3176: $haschanges = 1;
3177: if ($newvalue) {
3178: my $storeval = 'yes';
3179: if ($which eq 'randompick') {
3180: $storeval = $newvalue;
3181: }
3182: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3183: $parameter_type{$which});
3184: &remember_parms($idx,$which,'set',$storeval);
3185: } else {
3186: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3187: &remember_parms($idx,$which,'del');
3188: }
1.537 raeburn 3189: }
1.588 raeburn 3190: return $haschanges;
1.329 droeschl 3191: }
3192: }
3193:
3194: sub handle_edit_cmd {
3195: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3196: my $haschanges = 0;
1.543 raeburn 3197: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3198: return $haschanges;
1.543 raeburn 3199: }
1.329 droeschl 3200: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3201:
3202: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3203: my ($title, $url, @rrest) = split(':', $ratstr);
3204:
1.538 raeburn 3205: if ($cmd eq 'remove') {
1.329 droeschl 3206: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3207: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3208: &Apache::lonnet::removeuploadedurl($url);
3209: } else {
3210: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3211: }
3212: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3213: $haschanges = 1;
1.329 droeschl 3214: } elsif ($cmd eq 'cut') {
3215: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3216: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3217: $haschanges = 1;
1.344 bisitz 3218: } elsif ($cmd eq 'up'
1.329 droeschl 3219: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3220: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3221: $haschanges = 1;
1.329 droeschl 3222: } elsif ($cmd eq 'down'
3223: && defined($LONCAPA::map::order[$idx+1])) {
3224: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3225: $haschanges = 1;
1.329 droeschl 3226: } elsif ($cmd eq 'rename') {
3227: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3228: if ($comment=~/\S/) {
3229: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3230: $comment.':'.join(':', $url, @rrest);
3231: }
3232: # Devalidate title cache
3233: my $renamed_url=&LONCAPA::map::qtescape($url);
3234: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3235: $haschanges = 1;
3236: } elsif ($cmd eq 'setalias') {
3237: my $newvalue = $env{'form.alias'};
3238: if ($newvalue ne '') {
3239: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3240: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3241: 'string');
3242: &remember_parms($idx,'mapalias','set',$newvalue);
3243: $haschanges = 1;
3244: }
3245: }
3246: } elsif ($cmd eq 'delalias') {
3247: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3248: if ($current ne '') {
3249: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3250: &remember_parms($idx,'mapalias','del');
3251: $haschanges = 1;
3252: }
1.329 droeschl 3253: }
1.633 raeburn 3254: return $haschanges;
1.329 droeschl 3255: }
3256:
3257: sub editor {
1.458 raeburn 3258: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3259: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3260: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3261: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3262: if ($allowed) {
1.519 raeburn 3263: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3264: $is_random_order,$container) =
1.510 raeburn 3265: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3266: $r->print($breadcrumbtrail);
1.519 raeburn 3267: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3268: $container = 'page';
3269: } else {
3270: $container = 'sequence';
1.510 raeburn 3271: }
1.484 raeburn 3272:
1.525 raeburn 3273: my $jumpto;
3274:
3275: unless ($supplementalflag) {
1.546 raeburn 3276: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3277: }
1.484 raeburn 3278:
3279: unless ($allowed) {
3280: $randompick = -1;
3281: }
3282:
1.615 raeburn 3283: my ($errtext,$fatal);
3284: if (($folder eq '') && (!$supplementalflag)) {
3285: if (@LONCAPA::map::order) {
3286: undef(@LONCAPA::map::order);
3287: undef(@LONCAPA::map::resources);
3288: undef(@LONCAPA::map::resparms);
3289: undef(@LONCAPA::map::zombies);
3290: }
3291: $folder = 'default';
3292: $container = 'sequence';
3293: } else {
3294: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3295: $folder.'.'.$container);
3296: return $errtext if ($fatal);
3297: }
1.329 droeschl 3298:
3299: if ($#LONCAPA::map::order<1) {
3300: my $idx=&LONCAPA::map::getresidx();
3301: if ($idx<=0) { $idx=1; }
3302: $LONCAPA::map::order[0]=$idx;
3303: $LONCAPA::map::resources[$idx]='';
3304: }
1.364 bisitz 3305:
1.329 droeschl 3306: # ------------------------------------------------------------ Process commands
3307:
3308: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3309: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3310: # set parameters and change order
3311: &snapshotbefore();
3312:
3313: if (&update_parameter()) {
1.588 raeburn 3314: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3315: return $errtext if ($fatal);
3316: }
3317:
3318: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3319: # change order
3320: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3321: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3322:
3323: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3324: return $errtext if ($fatal);
3325: }
1.364 bisitz 3326:
1.329 droeschl 3327: if ($env{'form.pastemarked'}) {
1.491 raeburn 3328: my %paste_errors;
1.533 raeburn 3329: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3330: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3331: \%paste_errors);
1.541 raeburn 3332: if (ref($pastemsgarray) eq 'ARRAY') {
3333: if (@{$pastemsgarray} > 0) {
3334: $r->print('<p class="LC_info">'.
3335: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3336: '</p>');
3337: }
1.541 raeburn 3338: }
3339: if ($lockerror) {
3340: $r->print('<p class="LC_error">'.
3341: $lockerror.
3342: '</p>');
3343: }
3344: if ($save_error ne '') {
3345: return $save_error;
3346: }
3347: if ($paste_res) {
3348: my %errortext = &Apache::lonlocal::texthash (
3349: fail => 'Storage of folder contents failed',
3350: failread => 'Reading folder contents failed',
3351: failstore => 'Storage of folder contents failed',
3352: );
3353: if ($errortext{$paste_res}) {
3354: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3355: }
1.329 droeschl 3356: }
1.491 raeburn 3357: if (keys(%paste_errors) > 0) {
1.538 raeburn 3358: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3359: &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".
3360: '<ul>'."\n");
3361: foreach my $key (sort(keys(%paste_errors))) {
3362: $r->print('<li>'.$key.'</li>'."\n");
3363: }
3364: $r->print('</ul></p>'."\n");
3365: }
1.538 raeburn 3366: } elsif ($env{'form.clearmarked'}) {
3367: my $output = &do_buffer_empty();
3368: if ($output) {
3369: $r->print('<p class="LC_info">'.$output.'</p>');
3370: }
3371: }
1.329 droeschl 3372:
3373: $r->print($upload_output);
3374:
1.538 raeburn 3375: # Rename, cut, copy or remove a single resource
1.602 raeburn 3376: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3377: my $contentchg;
1.633 raeburn 3378: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3379: $contentchg = 1;
3380: }
3381: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3382: return $errtext if ($fatal);
3383: }
1.538 raeburn 3384:
3385: # Cut, copy and/or remove multiple resources
3386: if ($env{'form.multichange'}) {
3387: my %allchecked = (
3388: cut => {},
3389: remove => {},
3390: );
3391: my $needsupdate;
3392: foreach my $which (keys(%allchecked)) {
3393: $env{'form.multi'.$which} =~ s/,$//;
3394: if ($env{'form.multi'.$which}) {
3395: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3396: if (ref($allchecked{$which}) eq 'HASH') {
3397: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3398: }
3399: }
3400: }
3401: if ($needsupdate) {
3402: my $haschanges = 0;
3403: my %curr_groups = &Apache::longroup::coursegroups();
3404: my $total = scalar(@LONCAPA::map::order) - 1;
3405: for (my $i=$total; $i>=0; $i--) {
3406: my $res = $LONCAPA::map::order[$i];
3407: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3408: $name=&LONCAPA::map::qtescape($name);
3409: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3410: next unless $url;
1.538 raeburn 3411: my %denied =
3412: &action_restrictions($coursenum,$coursedom,$url,
3413: $env{'form.folderpath'},\%curr_groups);
3414: foreach my $which (keys(%allchecked)) {
3415: next if ($denied{$which});
3416: next unless ($allchecked{$which}{$res});
3417: if ($which eq 'remove') {
3418: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3419: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3420: &Apache::lonnet::removeuploadedurl($url);
3421: } else {
3422: &LONCAPA::map::makezombie($res);
3423: }
3424: splice(@LONCAPA::map::order,$i,1);
3425: $haschanges ++;
3426: } elsif ($which eq 'cut') {
3427: &LONCAPA::map::makezombie($res);
3428: splice(@LONCAPA::map::order,$i,1);
3429: $haschanges ++;
3430: }
3431: }
3432: }
3433: if ($haschanges) {
3434: ($errtext,$fatal) =
3435: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3436: return $errtext if ($fatal);
3437: }
3438: }
3439: }
3440:
1.329 droeschl 3441: # Group import/search
3442: if ($env{'form.importdetail'}) {
3443: my @imports;
3444: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3445: if (defined($item)) {
3446: my ($name,$url,$residx)=
1.533 raeburn 3447: map { &unescape($_); } split(/\=/,$item);
3448: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3449: my ($suffix,$errortxt,$locknotfreed) =
3450: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3451: if ($locknotfreed) {
3452: $r->print($locknotfreed);
3453: }
3454: if ($suffix) {
3455: $url =~ s/_new\./_$suffix./;
3456: } else {
3457: return $errortxt;
3458: }
1.533 raeburn 3459: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3460: my $type = $1;
3461: my ($suffix,$errortxt,$locknotfreed) =
3462: &new_timebased_suffix($coursedom,$coursenum,$type);
3463: if ($locknotfreed) {
3464: $r->print($locknotfreed);
3465: }
3466: if ($suffix) {
3467: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3468: } else {
3469: return $errortxt;
3470: }
1.626 raeburn 3471: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3472: my ($suffix,$errortxt,$locknotfreed) =
3473: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3474: if ($locknotfreed) {
3475: $r->print($locknotfreed);
3476: }
3477: if ($suffix) {
3478: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3479: } else {
3480: return $errortxt;
3481: }
1.534 raeburn 3482: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3483: if ($supplementalflag) {
3484: next unless ($1 eq 'supplemental');
3485: if ($folder eq 'supplemental') {
3486: next unless ($2 eq 'default');
3487: } else {
3488: next unless ($folder eq 'supplemental_'.$2);
3489: }
3490: } else {
3491: next unless ($1 eq 'docs');
3492: if ($folder eq 'default') {
3493: next unless ($2 eq 'default');
3494: } else {
3495: next unless ($folder eq 'default_'.$2);
3496: }
3497: }
1.504 raeburn 3498: }
1.329 droeschl 3499: push(@imports, [$name, $url, $residx]);
3500: }
3501: }
1.530 raeburn 3502: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3503: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3504: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3505: return $errtext if ($fatal);
1.529 raeburn 3506: if ($fixuperrors) {
3507: $r->print($fixuperrors);
3508: }
1.329 droeschl 3509: }
3510: # Loading a complete map
3511: if ($env{'form.loadmap'}) {
3512: if ($env{'form.importmap'}=~/\w/) {
3513: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3514: my ($title,$url,$ext,$type)=split(/\:/,$res);
3515: my $idx=&LONCAPA::map::getresidx($url);
3516: $LONCAPA::map::resources[$idx]=$res;
3517: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3518: }
3519: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3520: $folder.'.'.$container,1);
1.329 droeschl 3521: return $errtext if ($fatal);
3522: } else {
3523: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3524:
1.329 droeschl 3525: }
3526: }
3527: &log_differences($plain);
3528: }
3529: # ---------------------------------------------------------------- End commands
3530: # ---------------------------------------------------------------- Print screen
3531: my $idx=0;
3532: my $shown=0;
3533: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3534: $r->print('<div class="LC_Box">'.
1.432 raeburn 3535: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3536: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3537: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3538: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3539: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3540: '</ol>');
1.381 bisitz 3541: if ($randompick>=0) {
3542: $r->print('<p class="LC_warning">'
3543: .&mt('Caution: this folder is set to randomly pick a subset'
3544: .' of resources. Adding or removing resources from this'
3545: .' folder will change the set of resources that the'
3546: .' students see, resulting in spurious or missing credit'
3547: .' for completed problems, not limited to ones you'
3548: .' modify. Do not modify the contents of this folder if'
3549: .' it is in active student use.')
3550: .'</p>'
3551: );
3552: }
3553: if ($is_random_order) {
3554: $r->print('<p class="LC_warning">'
3555: .&mt('Caution: this folder is set to randomly order its'
3556: .' contents. Adding or removing resources from this folder'
3557: .' will change the order of resources shown.')
3558: .'</p>'
3559: );
3560: }
3561: $r->print('</div>');
1.364 bisitz 3562: }
1.381 bisitz 3563:
1.685 raeburn 3564: if ((!$allowed) && ($folder =~ /^supplemental_\d+$/)) {
1.688 raeburn 3565: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 3566: if (ref($supplemental) eq 'HASH') {
3567: if ((ref($supplemental->{'hidden'}) eq 'HASH') &&
3568: (ref($supplemental->{'ids'}) eq 'HASH')) {
3569: if (ref($supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}) eq 'ARRAY') {
3570: my $mapnum = $supplemental->{'ids'}->{"/uploaded/$coursedom/$coursenum/$folder.$container"}->[0];
3571: if ($supplemental->{'hidden'}->{$mapnum}) {
3572: $ishidden = 1;
3573: }
3574: }
3575: }
3576: }
3577: }
3578:
1.538 raeburn 3579: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3580: %filters = (
1.543 raeburn 3581: canremove => [],
3582: cancut => [],
3583: cancopy => [],
3584: hiddenresource => [],
3585: encrypturl => [],
3586: randomorder => [],
3587: randompick => [],
1.538 raeburn 3588: );
3589: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3590: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3591: foreach my $res (@LONCAPA::map::order) {
3592: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3593: $name=&LONCAPA::map::qtescape($name);
3594: $url=&LONCAPA::map::qtescape($url);
3595: unless ($name) { $name=(split(/\//,$url))[-1]; }
3596: unless ($name) { $idx++; next; }
1.537 raeburn 3597: push(@allidx,$res);
3598: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3599: push(@allmapidx,$res);
3600: }
1.617 raeburn 3601:
1.682 raeburn 3602: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
1.685 raeburn 3603: if (($ishidden) || ((&LONCAPA::map::getparameter($res,'parameter_hiddenresource'))[0]=~/^yes$/i)) {
3604: $idx++;
3605: next;
3606: }
1.682 raeburn 3607: }
1.381 bisitz 3608: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3609: $coursenum,$coursedom,$crstype,
1.538 raeburn 3610: $pathitem,$supplementalflag,$container,
1.620 raeburn 3611: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.685 raeburn 3612: $isencrypted,$ishidden,$navmapref,$hostname);
1.381 bisitz 3613: $idx++;
3614: $shown++;
1.329 droeschl 3615: }
1.424 onken 3616: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3617:
1.538 raeburn 3618: my $need_save;
1.611 raeburn 3619: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3620: my $toolslink;
1.682 raeburn 3621: if ($allowed || $canedit) {
3622: my $helpitem = 'Navigation_Screen';
3623: if (!$allowed) {
3624: $helpitem = 'Supplemental_Navigation';
3625: }
1.544 raeburn 3626: $toolslink = '<table><tr><td>'
1.520 raeburn 3627: .&Apache::loncommon::help_open_menu('Navigation Screen',
1.682 raeburn 3628: $helpitem,undef,'RAT')
1.520 raeburn 3629: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3630: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3631: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3632: .'id="LC_content_toolbar_edittoplevel" '
3633: .'class="LC_toolbarItem" '
3634: .'title="'.&mt('Supplemental Content Editor').'">'
3635: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3636: }
1.510 raeburn 3637: if ($shown) {
3638: if ($allowed) {
3639: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3640: .&Apache::loncommon::start_data_table(undef,'contentlist')
3641: .&Apache::loncommon::start_data_table_header_row()
3642: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3643: .'<th colspan="3">'.&mt('Actions').'</th>'
1.682 raeburn 3644: .'<th>'.&mt('Document').'</th>'
3645: .'<th colspan="2">'.&mt('Settings').'</th>'
3646: .&Apache::loncommon::end_data_table_header_row();
1.537 raeburn 3647: if ($folder !~ /^supplemental/) {
1.538 raeburn 3648: $lists{'canhide'} = join(',',@allidx);
3649: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3650: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3651: 'randomorder','randompick');
3652: foreach my $item (@possfilters) {
1.538 raeburn 3653: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3654: if (@{$filters{$item}} > 0) {
3655: $lists{$item} = join(',',@{$filters{$item}});
3656: }
1.538 raeburn 3657: }
3658: }
1.537 raeburn 3659: if (@allidx > 0) {
3660: my $path;
3661: if ($env{'form.folderpath'}) {
1.630 raeburn 3662: $path =
1.537 raeburn 3663: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3664: }
1.538 raeburn 3665: if (@allidx > 1) {
1.630 raeburn 3666: $to_show .=
1.538 raeburn 3667: &Apache::loncommon::continue_data_table_row().
3668: '<td colspan="2"> </td>'.
3669: '<td>'.
1.611 raeburn 3670: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3671: '</td>'.
1.633 raeburn 3672: '<td colspan="3"> </td>'.
3673: '<td colspan="2">'.
1.611 raeburn 3674: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3675: '</td>'.
3676: &Apache::loncommon::end_data_table_row();
3677: $need_save = 1;
3678: }
1.537 raeburn 3679: }
3680: }
3681: $to_show .= $output.' '
1.510 raeburn 3682: .&Apache::loncommon::end_data_table()
3683: .'<br style="line-height:2px;" />'
3684: .&Apache::loncommon::end_scrollbox();
3685: } else {
1.520 raeburn 3686: $to_show .= $toolslink
1.510 raeburn 3687: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3688: .$output.' '
3689: .&Apache::loncommon::end_data_table();
1.393 raeburn 3690: }
1.510 raeburn 3691: } else {
1.520 raeburn 3692: if (!$allowed) {
3693: $to_show .= $toolslink;
3694: }
1.615 raeburn 3695: my $noresmsg;
3696: if ($allowed && $hiddentop && !$supplementalflag) {
3697: $noresmsg = &mt('Main Content Hidden');
3698: } else {
3699: $noresmsg = &mt('Currently empty');
3700: }
1.510 raeburn 3701: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3702: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3703: .$noresmsg
1.510 raeburn 3704: .'</div>'
3705: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3706: }
3707: } else {
1.510 raeburn 3708: if ($shown) {
3709: $to_show = '<div>'
3710: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3711: .$output
3712: .&Apache::loncommon::end_data_table()
3713: .'</div>';
3714: } else {
3715: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3716: .&mt('Currently empty')
1.510 raeburn 3717: .'</div>'
3718: }
1.458 raeburn 3719: }
3720: my $tid = 1;
3721: if ($supplementalflag) {
3722: $tid = 2;
1.329 droeschl 3723: }
3724: if ($allowed) {
1.484 raeburn 3725: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3726: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3727: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3728: if ($canedit) {
3729: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3730: }
1.460 raeburn 3731: } else {
3732: $r->print($to_show);
1.329 droeschl 3733: }
3734: return;
3735: }
3736:
1.538 raeburn 3737: sub multiple_check_form {
1.611 raeburn 3738: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3739: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3740: my $disabled;
3741: unless ($canedit) {
3742: $disabled = 'disabled="disabled"';
3743: }
1.538 raeburn 3744: my $output =
3745: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3746: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3747: '<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>'.
3748: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3749: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3750: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3751: if ($caller eq 'settings') {
3752: $output .=
3753: '<table><tr>'.
3754: '<td class="LC_docs_entry_parameter">'.
3755: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3756: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3757: '</label></span></td>'.
3758: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3759: '<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 3760: '</span></td>'.
3761: '</tr>'."\n".
3762: '<tr>'.
3763: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3764: '<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 3765: '</label></span>'.
3766: '</td></tr></table>'."\n";
3767: } else {
3768: $output .=
3769: '<table><tr>'.
3770: '<td class="LC_docs_entry_parameter">'.
3771: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3772: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3773: '</label></span></td>'.
3774: '<td class="LC_docs_entry_parameter">'.
3775: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3776: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3777: '</label></span></td>'."\n".
3778: '<td class="LC_docs_entry_parameter">'.
3779: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3780: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3781: '</label></span></td>'.
3782: '</tr></table>'."\n";
3783: }
3784: $output .=
3785: '</fieldset>'.
3786: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3787: if ($caller eq 'settings') {
3788: $output .=
1.543 raeburn 3789: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3790: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3791: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3792: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3793: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3794: } elsif ($caller eq 'actions') {
3795: $output .=
3796: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3797: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3798: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3799: }
3800: $output .=
3801: '</form>'.
3802: '</div>';
3803: return $output;
3804: }
3805:
1.329 droeschl 3806: sub process_file_upload {
1.552 raeburn 3807: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3808: # upload a file, if present
1.552 raeburn 3809: my $filesize = length($env{'form.uploaddoc'});
3810: if (!$filesize) {
3811: $$upload_output = '<div class="LC_error">'.
3812: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3813: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3814: $filesize).'<br />'.
3815: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3816: '</div>';
3817: return;
3818: }
3819: my $quotatype = 'unofficial';
3820: if ($crstype eq 'Community') {
1.601 raeburn 3821: $quotatype = 'community';
3822: } elsif ($crstype eq 'Placement') {
3823: $quotatype = 'placement';
1.580 raeburn 3824: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3825: $quotatype = 'official';
1.573 raeburn 3826: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3827: $quotatype = 'textbook';
1.552 raeburn 3828: }
3829: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3830: $filesize = int($filesize/1000); #expressed in kb
3831: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3832: $env{'form.uploaddoc.filename'},$filesize,
3833: 'upload',$quotatype);
1.552 raeburn 3834: return if ($$upload_output);
3835: }
1.440 raeburn 3836: my ($parseaction,$showupload,$nextphase,$mimetype);
3837: if ($env{'form.parserflag'}) {
1.329 droeschl 3838: $parseaction = 'parse';
3839: }
3840: my $folder=$env{'form.folder'};
3841: if ($folder eq '') {
3842: $folder='default';
3843: }
3844: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3845: my $errtext='';
3846: my $fatal=0;
3847: my $container='sequence';
1.519 raeburn 3848: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3849: $container='page';
3850: }
3851: ($errtext,$fatal)=
1.534 raeburn 3852: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3853: if ($#LONCAPA::map::order<1) {
3854: $LONCAPA::map::order[0]=1;
3855: $LONCAPA::map::resources[1]='';
3856: }
3857: my $destination = 'docs/';
3858: if ($folder =~ /^supplemental/) {
3859: $destination = 'supplemental/';
3860: }
3861: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3862: $destination .= 'default/';
3863: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3864: $destination .= $2.'/';
3865: }
1.534 raeburn 3866: if ($fatal) {
3867: $$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>';
3868: return;
3869: }
1.440 raeburn 3870: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3871: my $newidx=&LONCAPA::map::getresidx();
3872: $destination .= $newidx;
1.439 raeburn 3873: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3874: $parseaction,$allfiles,
1.440 raeburn 3875: $codebase,undef,undef,undef,undef,
3876: undef,undef,\$mimetype);
3877: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3878: my $stored = $1;
3879: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3880: $stored.'</span>').'</p>';
3881: } else {
3882: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3883:
1.457 raeburn 3884: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3885: return;
3886: }
1.329 droeschl 3887: my $ext='false';
3888: if ($url=~m{^http://}) { $ext='true'; }
3889: $url = &LONCAPA::map::qtunescape($url);
3890: my $comment=$env{'form.comment'};
3891: $comment = &LONCAPA::map::qtunescape($comment);
3892: if ($folder=~/^supplemental/) {
3893: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3894: $env{'user.domain'}.'___&&&___'.$comment;
3895: }
3896:
3897: $LONCAPA::map::resources[$newidx]=
3898: $comment.':'.$url.':'.$ext.':normal:res';
3899: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3900: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3901: $folder.'.'.$container,1);
1.329 droeschl 3902: if ($fatal) {
1.457 raeburn 3903: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3904: return;
1.329 droeschl 3905: } else {
1.440 raeburn 3906: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3907: $$upload_output = $showupload;
1.384 raeburn 3908: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3909: if ($total_embedded > 0) {
1.440 raeburn 3910: my $uploadphase = 'upload_embedded';
3911: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3912: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3913: my ($embedded,$num) =
1.440 raeburn 3914: &Apache::loncommon::ask_for_embedded_content(
3915: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3916: if ($embedded) {
3917: if ($num) {
3918: $$upload_output .=
3919: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3920: $nextphase = $uploadphase;
3921: } else {
3922: $$upload_output .= $embedded;
3923: }
3924: } else {
3925: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3926: }
1.329 droeschl 3927: } else {
1.440 raeburn 3928: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3929: }
1.457 raeburn 3930: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3931: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3932: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3933: $nextphase = 'decompress_uploaded';
3934: my $position = scalar(@LONCAPA::map::order)-1;
3935: my $noextract = &return_to_editor();
3936: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3937: my %archiveitems = (
3938: folderpath => $env{'form.folderpath'},
3939: cmd => $nextphase,
3940: newidx => $newidx,
3941: position => $position,
3942: phase => $nextphase,
1.477 raeburn 3943: comment => $comment,
1.480 raeburn 3944: );
3945: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3946: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3947: $$upload_output = $showupload.
3948: &Apache::loncommon::decompress_form($mimetype,
3949: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3950: \%archiveitems,\@current);
1.329 droeschl 3951: }
3952: }
3953: }
1.440 raeburn 3954: return $nextphase;
1.329 droeschl 3955: }
3956:
1.480 raeburn 3957: sub get_dir_list {
3958: my ($url,$coursenum,$coursedom,$newidx) = @_;
3959: my ($destination,$dir_root) = &embedded_destination();
3960: my ($dirlistref,$listerror) =
3961: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3962: my @dir_lines;
3963: my $dirptr=16384;
3964: if (ref($dirlistref) eq 'ARRAY') {
3965: foreach my $dir_line (sort
3966: {
3967: my ($afile)=split('&',$a,2);
3968: my ($bfile)=split('&',$b,2);
3969: return (lc($afile) cmp lc($bfile));
3970: } (@{$dirlistref})) {
3971: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3972: $filename =~ s/\s+$//;
3973: next if ($filename =~ /^\.\.?$/);
3974: my $isdir = 0;
3975: if ($dirptr&$testdir) {
3976: $isdir = 1;
3977: }
3978: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3979: }
3980: }
3981: return @dir_lines;
3982: }
3983:
1.329 droeschl 3984: sub is_supplemental_title {
3985: my ($title) = @_;
3986: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3987: }
3988:
3989: # --------------------------------------------------------------- An entry line
3990:
3991: sub entryline {
1.501 raeburn 3992: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3993: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.685 raeburn 3994: $ltitoolsref,$canedit,$isencrypted,$ishidden,$navmapref,$hostname)=@_;
1.687 raeburn 3995: my ($foldertitle,$renametitle,$oldtitle,$encodedtitle);
1.329 droeschl 3996: if (&is_supplemental_title($title)) {
1.488 raeburn 3997: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.687 raeburn 3998: $encodedtitle=$title;
1.329 droeschl 3999: } else {
4000: $title=&HTML::Entities::encode($title,'"<>&\'');
1.687 raeburn 4001: $encodedtitle=$title;
1.329 droeschl 4002: $renametitle=$title;
4003: $foldertitle=$title;
4004: }
4005:
1.611 raeburn 4006: my ($disabled,$readonly,$js_lt);
4007: unless ($canedit) {
4008: $disabled = 'disabled="disabled"';
4009: $readonly = 1;
4010: }
4011:
1.329 droeschl 4012: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 4013:
1.329 droeschl 4014: $renametitle=~s/\\/\\\\/g;
4015: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 4016: $renametitle=~s/"/%22/g;
1.581 raeburn 4017: $renametitle=~s/ /%20/g;
4018: $oldtitle = $renametitle;
1.576 raeburn 4019: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 4020: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 4021: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 4022: # Edit commands
1.679 raeburn 4023: my ($esc_path, $path, $symb, $shownsymb, $curralias);
1.329 droeschl 4024: if ($env{'form.folderpath'}) {
4025: $esc_path=&escape($env{'form.folderpath'});
4026: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4027: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4028: }
1.505 raeburn 4029: my $isexternal;
1.510 raeburn 4030: if ($residx) {
1.501 raeburn 4031: my $currurl = $url;
4032: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 4033: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4034: $isexternal = 1;
4035: }
1.510 raeburn 4036: if (!$supplementalflag) {
4037: my $path = 'uploaded/'.
4038: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4039: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4040: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4041: $residx,
4042: &Apache::lonnet::declutter($currurl));
4043: }
1.501 raeburn 4044: }
1.538 raeburn 4045: my ($renamelink,%lt,$ishash);
4046: if (ref($filtersref) eq 'HASH') {
4047: $ishash = 1;
4048: }
4049:
1.329 droeschl 4050: if ($allowed) {
1.538 raeburn 4051: $form_start = '
4052: <form action="/adm/coursedocs" method="post">
4053: ';
4054: $form_common=(<<END);
4055: <input type="hidden" name="folderpath" value="$path" />
4056: <input type="hidden" name="symb" value="$symb" />
4057: END
4058: $form_param=(<<END);
4059: <input type="hidden" name="setparms" value="$orderidx" />
4060: <input type="hidden" name="changeparms" value="0" />
4061: END
4062: $form_end = '</form>';
4063:
1.329 droeschl 4064: my $incindex=$index+1;
4065: my $selectbox='';
1.471 raeburn 4066: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 4067: ((split(/\:/,
1.344 bisitz 4068: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4069: ne '') &&
1.329 droeschl 4070: ((split(/\:/,
1.344 bisitz 4071: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 4072: ne '')) {
4073: $selectbox=
4074: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 4075: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 4076: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4077: if ($i==$incindex) {
1.358 bisitz 4078: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 4079: } else {
4080: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4081: }
4082: }
4083: $selectbox.='</select>';
4084: }
1.501 raeburn 4085: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 4086: 'up' => 'Move Up',
4087: 'dw' => 'Move Down',
4088: 'rm' => 'Remove',
4089: 'ct' => 'Cut',
4090: 'rn' => 'Rename',
1.501 raeburn 4091: 'cp' => 'Copy',
1.633 raeburn 4092: 'da' => 'Unset alias',
4093: 'sa' => 'Set alias',
1.501 raeburn 4094: 'ex' => 'External Resource',
1.598 raeburn 4095: 'et' => 'External Tool',
1.501 raeburn 4096: 'ed' => 'Edit',
4097: 'pr' => 'Preview',
4098: 'sv' => 'Save',
4099: 'ul' => 'URL',
1.611 raeburn 4100: 'ti' => 'Title',
1.618 raeburn 4101: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4102: );
1.538 raeburn 4103: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4104: $env{'form.folderpath'},
4105: $currgroups);
1.517 raeburn 4106: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4107: my $skip_confirm = 0;
1.603 raeburn 4108: my $confirm_removal = 0;
1.329 droeschl 4109: if ( $folder =~ /^supplemental/
4110: || ($url =~ m{( /smppg$
4111: |/syllabus$
4112: |/aboutme$
4113: |/navmaps$
4114: |/bulletinboard$
1.626 raeburn 4115: |/ext\.tool$
1.505 raeburn 4116: |\.html$)}x)
4117: || $isexternal) {
1.329 droeschl 4118: $skip_confirm = 1;
4119: }
1.603 raeburn 4120: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4121: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4122: $confirm_removal = 1;
4123: }
1.633 raeburn 4124: if ($url =~ /$LONCAPA::assess_re/) {
4125: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4126: }
1.329 droeschl 4127:
1.538 raeburn 4128: if ($denied{'copy'}) {
1.543 raeburn 4129: $copylink=(<<ENDCOPY)
1.507 raeburn 4130: <span style="visibility: hidden;">$lt{'cp'}</span>
4131: ENDCOPY
4132: } else {
1.538 raeburn 4133: my $formname = 'edit_copy_'.$orderidx;
4134: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4135: $copylink=(<<ENDCOPY);
1.538 raeburn 4136: <form name="$formname" method="post" action="/adm/coursedocs">
4137: $form_common
1.611 raeburn 4138: <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 4139: $form_end
1.329 droeschl 4140: ENDCOPY
1.538 raeburn 4141: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4142: push(@{$filtersref->{'cancopy'}},$orderidx);
4143: }
1.329 droeschl 4144: }
1.538 raeburn 4145: if ($denied{'cut'}) {
1.507 raeburn 4146: $cutlink=(<<ENDCUT);
4147: <span style="visibility: hidden;">$lt{'ct'}</span>
4148: ENDCUT
4149: } else {
1.538 raeburn 4150: my $formname = 'edit_cut_'.$orderidx;
4151: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4152: $cutlink=(<<ENDCUT);
1.538 raeburn 4153: <form name="$formname" method="post" action="/adm/coursedocs">
4154: $form_common
1.542 raeburn 4155: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4156: <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 4157: $form_end
1.329 droeschl 4158: ENDCUT
1.538 raeburn 4159: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4160: push(@{$filtersref->{'cancut'}},$orderidx);
4161: }
1.329 droeschl 4162: }
1.538 raeburn 4163: if ($denied{'remove'}) {
1.507 raeburn 4164: $removelink=(<<ENDREM);
4165: <span style="visibility: hidden;">$lt{'rm'}</a>
4166: ENDREM
4167: } else {
1.538 raeburn 4168: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4169: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4170: $removelink=(<<ENDREM);
1.538 raeburn 4171: <form name="$formname" method="post" action="/adm/coursedocs">
4172: $form_common
1.542 raeburn 4173: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4174: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4175: <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 4176: $form_end
1.497 raeburn 4177: ENDREM
1.538 raeburn 4178: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4179: push(@{$filtersref->{'canremove'}},$orderidx);
4180: }
1.497 raeburn 4181: }
1.551 raeburn 4182: $renamelink=(<<ENDREN);
1.581 raeburn 4183: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4184: ENDREN
1.611 raeburn 4185: my ($uplink,$downlink);
4186: if ($canedit) {
4187: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4188: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4189: } else {
4190: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4191: $downlink = $uplink;
4192: }
1.329 droeschl 4193: $line.=(<<END);
4194: <td>
1.379 bisitz 4195: <div class="LC_docs_entry_move">
1.611 raeburn 4196: <a href="$uplink">
1.501 raeburn 4197: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4198: </a>
4199: </div>
4200: <div class="LC_docs_entry_move">
1.611 raeburn 4201: <a href="$downlink">
1.501 raeburn 4202: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4203: </a>
4204: </div>
1.329 droeschl 4205: </td>
4206: <td>
4207: $form_start
1.538 raeburn 4208: $form_param
1.478 raeburn 4209: $form_common
1.329 droeschl 4210: $selectbox
4211: $form_end
4212: </td>
1.540 raeburn 4213: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4214: $removelink
1.329 droeschl 4215: $cutlink
4216: $copylink
4217: </td>
4218: END
4219: }
4220: # Figure out what kind of a resource this is
4221: my ($extension)=($url=~/\.(\w+)$/);
4222: my $uploaded=($url=~/^\/*uploaded\//);
4223: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4224: my $isfolder;
4225: my $ispage;
4226: my $containerarg;
1.615 raeburn 4227: my $folderurl;
1.685 raeburn 4228: my $plainurl;
1.329 droeschl 4229: if ($uploaded) {
1.472 raeburn 4230: if (($extension eq 'sequence') || ($extension eq 'page')) {
4231: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4232: $containerarg = $1;
1.472 raeburn 4233: if ($extension eq 'sequence') {
4234: $icon=$iconpath.'navmap.folder.closed.gif';
4235: $isfolder=1;
4236: } else {
4237: $icon=$iconpath.'page.gif';
4238: $ispage=1;
4239: }
1.615 raeburn 4240: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4241: if ($allowed) {
4242: $url='/adm/coursedocs?';
4243: } else {
4244: $url='/adm/supplemental?';
4245: }
1.329 droeschl 4246: } else {
1.685 raeburn 4247: $plainurl = $url;
1.329 droeschl 4248: }
4249: }
1.364 bisitz 4250:
1.621 raeburn 4251: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4252: my $orig_url = $url;
1.340 raeburn 4253: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4254: if ($container eq 'page') {
4255: $url=~s{^http(|s)(:|:)//}{/ext/};
4256: } else {
4257: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4258: }
1.501 raeburn 4259: if (!$supplementalflag && $residx && $symb) {
4260: if ((!$isfolder) && (!$ispage)) {
4261: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4262: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4263: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4264: } else {
4265: $url=&Apache::lonnet::clutter($url);
4266: }
1.501 raeburn 4267: if ($url=~/^\/*uploaded\//) {
4268: $url=~/\.(\w+)$/;
4269: my $embstyle=&Apache::loncommon::fileembstyle($1);
4270: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4271: $url='/adm/wrapper'.$url;
4272: } elsif ($embstyle eq 'ssi') {
4273: #do nothing with these
4274: } elsif ($url!~/\.(sequence|page)$/) {
4275: $url='/adm/coursedocs/showdoc'.$url;
4276: }
1.623 raeburn 4277: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4278: my $wrapped = $1;
4279: my $exturl = $2;
1.668 raeburn 4280: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4281: $url='/adm/wrapper'.$url;
4282: }
4283: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4284: $nomodal = 1;
4285: }
1.626 raeburn 4286: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4287: $url='/adm/wrapper'.$url;
1.621 raeburn 4288: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4289: if (($ENV{'SERVER_PORT'} == 443) &&
4290: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4291: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4292: $url .= '?usehttp=1';
4293: }
1.621 raeburn 4294: $nomodal = 1;
4295: }
1.598 raeburn 4296: }
1.680 raeburn 4297: my ($checkencrypt,$shownurl);
4298: if (!$env{'request.role.adv'}) {
1.615 raeburn 4299: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
1.680 raeburn 4300: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
1.615 raeburn 4301: $checkencrypt = 1;
1.620 raeburn 4302: } elsif (ref($navmapref)) {
1.615 raeburn 4303: unless (ref($$navmapref)) {
4304: $$navmapref = Apache::lonnavmaps::navmap->new();
4305: }
4306: if (ref($$navmapref)) {
4307: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
1.680 raeburn 4308: $checkencrypt = 1;
1.615 raeburn 4309: }
4310: }
4311: }
1.680 raeburn 4312: }
4313: if ($checkencrypt) {
4314: my $currenc = $env{'request.enc'};
4315: $env{'request.enc'} = 1;
4316: $shownsymb = &Apache::lonenc::encrypted($symb);
4317: $shownurl = &Apache::lonenc::encrypted($url);
4318: if (&Apache::lonnet::symbverify($symb,$url)) {
4319: $url = $shownurl;
4320: } else {
4321: $url = '';
4322: }
4323: $env{'request.enc'} = $currenc;
4324: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4325: $shownsymb = $symb;
4326: if ($isexternal) {
4327: $url =~ s/\#[^#]+$//;
4328: if ($container eq 'page') {
4329: $url = &Apache::lonnet::clutter($url);
1.613 raeburn 4330: }
1.612 raeburn 4331: }
1.680 raeburn 4332: $shownurl = $url;
4333: }
4334: unless ($env{'request.role.adv'}) {
4335: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4336: $url = '';
4337: }
4338: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4339: $url = '';
4340: $hiddenres = 1;
4341: }
4342: }
4343: if ($url ne '') {
4344: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.501 raeburn 4345: }
1.329 droeschl 4346: }
1.621 raeburn 4347: } elsif ($supplementalflag) {
1.610 raeburn 4348: if ($isexternal) {
4349: if ($url =~ /^([^#]+)#([^#]+)$/) {
4350: $url = $1;
4351: $anchor = $2;
1.623 raeburn 4352: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.678 raeburn 4353: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4354: if ($hostname ne '') {
4355: $url = 'http://'.$hostname.$url;
4356: }
4357: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4358: }
4359: $nomodal = 1;
4360: }
1.610 raeburn 4361: }
1.621 raeburn 4362: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4363: if (($ENV{'SERVER_PORT'} == 443) &&
4364: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 4365: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 4366: if ($hostname ne '') {
4367: $url = 'http://'.$hostname.$url;
4368: }
4369: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4370: }
1.621 raeburn 4371: $nomodal = 1;
4372: }
1.686 raeburn 4373: } elsif (($uploaded) && (!$allowed) && ($url ne '/adm/supplemental?')) {
4374: my $embstyle=&Apache::loncommon::fileembstyle($extension);
4375: unless ($embstyle eq 'ssi') {
4376: if (($embstyle eq 'img')
4377: || ($embstyle eq 'emb')
4378: || ($embstyle eq 'wrp')) {
4379: $url='/adm/wrapper'.$url;
4380: } elsif ($url !~ /\.(sequence|page)$/) {
4381: $url='/adm/coursedocs/showdoc'.$url;
4382: }
4383: }
1.610 raeburn 4384: }
1.685 raeburn 4385: unless ($allowed && $env{'request.role.adv'}) {
4386: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4387: $hiddenres = 1;
4388: }
4389: }
1.329 droeschl 4390: }
1.615 raeburn 4391: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4392: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4393: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4394: my $foldername=&escape($foldertitle);
4395: my $folderpath=$env{'form.folderpath'};
4396: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4397: if (!$allowed && $supplementalflag) {
1.519 raeburn 4398: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4399: $url.='folderpath='.&escape($folderpath);
1.685 raeburn 4400: if ($ishidden || (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4401: $hiddenfolder = 1;
1.682 raeburn 4402: }
1.510 raeburn 4403: } else {
1.617 raeburn 4404: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4405: 'parameter_randompick'))[0];
4406: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4407: 'parameter_randomorder'))[0]=~/^yes$/i);
4408: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4409: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4410: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4411: 'parameter_encrypturl'))[0]=~/^yes$/i);
4412: unless ($hiddenmap) {
1.620 raeburn 4413: if (ref($navmapref)) {
4414: unless (ref($$navmapref)) {
4415: $$navmapref = Apache::lonnavmaps::navmap->new();
4416: }
4417: if (ref($$navmapref)) {
4418: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4419: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4420: unless (@resources) {
4421: $hiddenmap = 1;
4422: unless ($env{'request.role.adv'}) {
4423: $url = '';
4424: $hiddenfolder = 1;
4425: }
1.617 raeburn 4426: }
1.615 raeburn 4427: }
4428: }
4429: }
4430: }
1.617 raeburn 4431: unless ($encryptmap) {
1.620 raeburn 4432: if ((ref($navmapref)) && (ref($$navmapref))) {
4433: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4434: $encryptmap = 1;
4435: }
1.617 raeburn 4436: }
4437: }
1.630 raeburn 4438:
1.617 raeburn 4439: # Append randompick number, hidden, and encrypted with ":" to foldername,
4440: # so it gets transferred between levels
4441: $folderpath.=$containerarg.'&'.$foldername.
4442: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4443: unless ($url eq '') {
1.612 raeburn 4444: $url.='folderpath='.&escape($folderpath);
4445: }
1.510 raeburn 4446: my $rpckchk;
4447: if ($rpicknum) {
4448: $rpckchk = ' checked="checked"';
1.543 raeburn 4449: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4450: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4451: }
1.510 raeburn 4452: }
1.537 raeburn 4453: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4454: $rand_pick_text =
1.478 raeburn 4455: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4456: $form_param."\n".
1.478 raeburn 4457: $form_common."\n".
1.611 raeburn 4458: '<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 4459: if ($rpicknum ne '') {
4460: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4461: }
1.537 raeburn 4462: $rand_pick_text .= '</span></span>'.
4463: $form_end;
1.543 raeburn 4464: my $ro_set;
1.617 raeburn 4465: if ($randorder) {
1.543 raeburn 4466: $ro_set = 'checked="checked"';
4467: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4468: push(@{$filtersref->{'randomorder'}},$orderidx);
4469: }
4470: }
1.564 raeburn 4471: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4472: $rand_order_text =
1.537 raeburn 4473: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4474: $form_param."\n".
1.537 raeburn 4475: $form_common."\n".
1.611 raeburn 4476: '<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 4477: $form_end;
1.510 raeburn 4478: }
1.509 raeburn 4479: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4480: my $isexttool;
1.626 raeburn 4481: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4482: $url='/adm/wrapper'.$url;
4483: $isexttool = 1;
4484: }
1.510 raeburn 4485: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4486: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4487: if ($title) {
1.687 raeburn 4488: $url .= '&title='.$encodedtitle;
1.510 raeburn 4489: }
1.598 raeburn 4490: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4491: $url .= '&idx='.$orderidx;
4492: }
1.610 raeburn 4493: if ($anchor ne '') {
4494: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4495: }
1.329 droeschl 4496: }
1.519 raeburn 4497: my ($tdalign,$tdwidth);
1.501 raeburn 4498: if ($allowed) {
1.630 raeburn 4499: my $fileloc =
1.501 raeburn 4500: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4501: if ($isexternal) {
1.630 raeburn 4502: ($editlink,$extresform) =
1.611 raeburn 4503: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4504: undef,undef,undef,undef,undef,undef,
4505: undef,$disabled);
1.626 raeburn 4506: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4507: ($editlink,$extresform) =
4508: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4509: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4510: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4511: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4512: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4513: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4514: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4515: my $suppanchor;
4516: if ($supplementalflag) {
4517: $suppanchor = $anchor;
4518: }
1.630 raeburn 4519: my $jscall =
1.501 raeburn 4520: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4521: $switchserver,
1.503 raeburn 4522: $forceedit,
1.679 raeburn 4523: undef,$symb,$shownsymb,
1.511 raeburn 4524: &escape($env{'form.folderpath'}),
1.622 raeburn 4525: $renametitle,$hostname,
4526: '','',1,$suppanchor);
1.501 raeburn 4527: if ($jscall) {
1.518 raeburn 4528: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4529: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4530: }
4531: }
4532: }
1.519 raeburn 4533: $tdalign = ' align="right" valign="top"';
4534: $tdwidth = ' width="80%"';
1.329 droeschl 4535: }
1.408 raeburn 4536: my $reinit;
4537: if ($crstype eq 'Community') {
4538: $reinit = &mt('(re-initialize community to access)');
4539: } else {
4540: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4541: }
4542: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650 raeburn 4543: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4544: $line.= '<br />';
4545: if ($curralias ne '') {
4546: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4547: $lt{'da'}.'</a></span>';
4548: } else {
4549: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4550: $lt{'sa'}.'</a></span>';
4551: }
4552: }
4553: $line.='</td><td>';
1.685 raeburn 4554: my ($link,$nolink);
1.472 raeburn 4555: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4556: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage) {
4557: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4558: $nolink = 1;
4559: }
4560: }
4561: if ($nolink) {
4562: $line .= '<img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4563: } else {
4564: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4565: }
1.469 www 4566: } elsif ($url) {
1.610 raeburn 4567: if ($anchor ne '') {
4568: if ($supplementalflag) {
4569: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4570: } else {
4571: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4572: }
4573: }
1.622 raeburn 4574: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4575: $link = 'http://'.$hostname.$url;
4576: } else {
4577: $link = $url;
4578: }
1.659 raeburn 4579: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.685 raeburn 4580: if ($allowed && !$env{'request.role.adv'} && !$isfolder && !$ispage && !$uploaded) {
4581: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4582: $nolink = 1;
4583: }
4584: }
4585: if ($nolink) {
4586: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4587: } elsif ($nomodal) {
1.621 raeburn 4588: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4589: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4590: } else {
4591: $line.=&Apache::loncommon::modal_link($link,
4592: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4593: }
1.469 www 4594: } else {
4595: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4596: }
1.519 raeburn 4597: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4598: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.685 raeburn 4599: if ($nolink) {
4600: $line.=$title;
4601: } else {
4602: $line.='<a href="'.$url.'">'.$title.'</a>';
4603: }
1.682 raeburn 4604: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4605: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4606: my $editurl = $url;
4607: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4608: $line .= ' '.'<a href="'.$editurl.'">'.
4609: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4610: '</a>';
4611: }
4612: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4613: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4614: }
1.469 www 4615: } elsif ($url) {
1.685 raeburn 4616: if ($nolink) {
4617: $line.=$title;
4618: } elsif ($nomodal) {
1.621 raeburn 4619: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4620: $title.'</a>';
4621: } else {
4622: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4623: }
1.617 raeburn 4624: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4625: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4626: } else {
4627: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4628: }
1.633 raeburn 4629: if (($allowed) && ($curralias ne '')) {
4630: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4631: } else {
4632: $line .= $extresform;
4633: }
4634: $line .= '</td>';
1.478 raeburn 4635: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4636: $rand_order_text = ' ' if ($rand_order_text eq '');
1.685 raeburn 4637: if ($uploaded && $url && !$isfolder && !$ispage) {
4638: if (($plainurl ne '') && ($env{'request.role.adv'} || $allowed || !$hiddenres)) {
4639: &Apache::lonnet::allowuploaded('/adm/coursedoc',$plainurl);
4640: }
4641: }
1.682 raeburn 4642: if ($allowed) {
4643: my %lt=&Apache::lonlocal::texthash(
4644: 'hd' => 'Hidden',
4645: 'ec' => 'URL hidden');
4646: my ($enctext,$hidtext,$formhidden,$formurlhidden);
1.543 raeburn 4647: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4648: $hidtext = ' checked="checked"';
4649: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4650: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4651: }
4652: }
1.682 raeburn 4653: $formhidden = 'edit_hiddenresource_'.$orderidx;
4654: $line.=(<<ENDPARMS);
1.329 droeschl 4655: <td class="LC_docs_entry_parameter">
1.537 raeburn 4656: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4657: $form_param
1.478 raeburn 4658: $form_common
1.611 raeburn 4659: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4660: $form_end
1.682 raeburn 4661: ENDPARMS
4662: if ($folder =~/^supplemental/) {
4663: $line.= "\n <td>";
4664: } else {
4665: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4666: $enctext = ' checked="checked"';
4667: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4668: push(@{$filtersref->{'encrypturl'}},$orderidx);
4669: }
4670: }
4671: $formurlhidden = 'edit_encrypturl_'.$orderidx;
4672: $line.=(<<ENDPARMS);
1.458 raeburn 4673: <br />
1.537 raeburn 4674: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4675: $form_param
1.478 raeburn 4676: $form_common
1.611 raeburn 4677: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4678: $form_end
4679: </td>
1.478 raeburn 4680: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4681: $rand_order_text</td>
1.329 droeschl 4682: ENDPARMS
1.682 raeburn 4683: }
1.329 droeschl 4684: }
1.379 bisitz 4685: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4686: return $line;
4687: }
4688:
1.538 raeburn 4689: sub action_restrictions {
4690: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4691: my %denied = (
4692: cut => 0,
4693: copy => 0,
4694: remove => 0,
4695: );
4696: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4697: # no copy for published maps
4698: $denied{'copy'} = 1;
1.597 raeburn 4699: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4700: unless ($1 eq 'simpleproblem') {
4701: $denied{'copy'} = 1;
4702: }
4703: $denied{'cut'} = 1;
1.538 raeburn 4704: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4705: if ($folderpath =~ /^default&[^\&]+$/) {
4706: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4707: $denied{'remove'} = 1;
4708: }
4709: $denied{'cut'} = 1;
4710: $denied{'copy'} = 1;
4711: }
4712: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4713: my $group = $1;
4714: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4715: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4716: $denied{'remove'} = 1;
4717: }
4718: }
4719: $denied{'cut'} = 1;
4720: $denied{'copy'} = 1;
4721: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4722: my $group = $1;
4723: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4724: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4725: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4726: if (keys(%groupsettings) > 0) {
4727: $denied{'remove'} = 1;
4728: }
4729: $denied{'cut'} = 1;
4730: $denied{'copy'} = 1;
4731: }
4732: }
4733: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4734: my $group = $1;
4735: if ($url =~ /group_boards_\Q$group\E/) {
4736: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4737: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4738: if (keys(%groupsettings) > 0) {
4739: if (ref($groupsettings{'functions'}) eq 'HASH') {
4740: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4741: $denied{'remove'} = 1;
4742: }
4743: }
4744: }
4745: $denied{'cut'} = 1;
4746: $denied{'copy'} = 1;
4747: }
4748: }
4749: }
4750: return %denied;
4751: }
4752:
1.533 raeburn 4753: sub new_timebased_suffix {
1.538 raeburn 4754: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4755: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4756: if ($type eq 'paste') {
4757: $prefix = $type;
4758: $namespace = 'courseeditor';
1.587 raeburn 4759: $idtype = 'addcode';
1.538 raeburn 4760: } elsif ($type eq 'map') {
1.533 raeburn 4761: $prefix = 'docs';
4762: if ($area eq 'supplemental') {
4763: $prefix = 'supp';
4764: }
4765: $prefix .= $container;
4766: $namespace = 'uploadedmaps';
4767: } else {
4768: $prefix = $type;
4769: $namespace = 'templated';
1.504 raeburn 4770: }
4771: my ($suffix,$freedlock,$error) =
1.587 raeburn 4772: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4773: if (!$suffix) {
1.538 raeburn 4774: if ($type eq 'paste') {
4775: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4776: } elsif ($type eq 'map') {
1.533 raeburn 4777: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4778: } elsif ($type eq 'smppg') {
4779: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4780: } elsif ($type eq 'exttool') {
4781: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4782: } else {
1.565 bisitz 4783: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4784: }
1.504 raeburn 4785: if ($error) {
4786: $errtext .= '<br />'.$error;
4787: }
4788: }
4789: if ($freedlock ne 'ok') {
1.630 raeburn 4790: $locknotfreed =
1.533 raeburn 4791: '<div class="LC_error">'.
4792: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4793: if ($type eq 'paste') {
1.591 raeburn 4794: if ($freedlock eq 'nolock') {
4795: $locknotfreed =
4796: '<div class="LC_error">'.
4797: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4798:
1.593 droeschl 4799: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4800: } else {
4801: $locknotfreed .=
4802: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4803: }
1.538 raeburn 4804: } elsif ($type eq 'map') {
1.591 raeburn 4805: $locknotfreed .=
4806: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4807: } elsif ($type eq 'smppg') {
4808: $locknotfreed .=
4809: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4810: } elsif ($type eq 'exttool') {
4811: $locknotfreed .=
4812: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4813: } else {
4814: $locknotfreed .=
1.565 bisitz 4815: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4816: }
1.538 raeburn 4817: unless ($type eq 'paste') {
4818: $locknotfreed .=
1.560 raeburn 4819: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4820: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4821: }
4822: $locknotfreed .= '</div>';
1.504 raeburn 4823: }
4824: return ($suffix,$errtext,$locknotfreed);
4825: }
4826:
1.329 droeschl 4827: =pod
4828:
4829: =item tiehash()
4830:
4831: tie the hash
4832:
4833: =cut
4834:
4835: sub tiehash {
4836: my ($mode)=@_;
4837: $hashtied=0;
4838: if ($env{'request.course.fn'}) {
4839: if ($mode eq 'write') {
4840: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4841: &GDBM_WRCREAT(),0640)) {
4842: $hashtied=2;
4843: }
4844: } else {
4845: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4846: &GDBM_READER(),0640)) {
4847: $hashtied=1;
4848: }
4849: }
1.364 bisitz 4850: }
1.329 droeschl 4851: }
4852:
4853: sub untiehash {
4854: if ($hashtied) { untie %hash; }
4855: $hashtied=0;
4856: return OK;
4857: }
4858:
4859:
4860:
4861:
4862: sub checkonthis {
1.637 raeburn 4863: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4864: $url=&unescape($url);
4865: $alreadyseen{$url}=1;
4866: $r->rflush();
4867: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4868: $r->print("\n<br />");
4869: if ($level==0) {
4870: $r->print("<br />");
4871: }
4872: for (my $i=0;$i<=$level*5;$i++) {
4873: $r->print(' ');
4874: }
4875: $r->print('<a href="'.$url.'" target="cat">'.
4876: ($title?$title:$url).'</a> ');
4877: if ($url=~/^\/res\//) {
1.637 raeburn 4878: my $updated;
4879: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4880: ($url !~ /\.\d+\.\w+$/)) {
4881: $updated = &Apache::lonnet::remove_stale_resfile($url);
4882: }
1.329 droeschl 4883: my $result=&Apache::lonnet::repcopy(
4884: &Apache::lonnet::filelocation('',$url));
4885: if ($result eq 'ok') {
4886: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4887: if ($updated) {
4888: $r->print('<br />');
4889: for (my $i=0;$i<=$level*5;$i++) {
4890: $r->print(' ');
4891: }
4892: $r->print('- '.&mt('Outdated copy removed'));
4893: }
1.329 droeschl 4894: $r->rflush();
4895: &Apache::lonnet::countacc($url);
4896: $url=~/\.(\w+)$/;
4897: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4898: $r->print('<br />');
4899: $r->rflush();
4900: for (my $i=0;$i<=$level*5;$i++) {
4901: $r->print(' ');
4902: }
4903: $r->print('- '.&mt('Rendering:').' ');
4904: my ($errorcount,$warningcount)=split(/:/,
4905: &Apache::lonnet::ssi_body($url,
4906: ('grade_target'=>'web',
4907: 'return_only_error_and_warning_counts' => 1)));
4908: if (($errorcount) ||
4909: ($warningcount)) {
4910: if ($errorcount) {
1.369 bisitz 4911: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4912: &mt('[quant,_1,error]',$errorcount).'</span>');
4913: }
4914: if ($warningcount) {
4915: $r->print('<span class="LC_warning">'.
4916: &mt('[quant,_1,warning]',$warningcount).'</span>');
4917: }
4918: } else {
4919: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4920: }
4921: $r->rflush();
4922: }
4923: my $dependencies=
4924: &Apache::lonnet::metadata($url,'dependencies');
4925: foreach my $dep (split(/\,/,$dependencies)) {
4926: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4927: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4928: }
4929: }
4930: } elsif ($result eq 'unavailable') {
4931: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4932: } elsif ($result eq 'not_found') {
4933: unless ($url=~/\$/) {
1.521 bisitz 4934: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4935: } else {
1.366 bisitz 4936: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4937: }
4938: } else {
4939: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4940: }
1.637 raeburn 4941: if (($updated) && ($result ne 'ok')) {
4942: $r->print('<br />'.&mt('Outdated copy removed'));
4943: }
1.329 droeschl 4944: }
4945: }
4946: }
4947:
4948:
4949:
4950: =pod
4951:
4952: =item list_symbs()
4953:
1.485 raeburn 4954: List Content Identifiers
1.329 droeschl 4955:
4956: =cut
4957:
4958: sub list_symbs {
4959: my ($r) = @_;
4960:
1.408 raeburn 4961: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4962: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4963: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4964: $r->print(&startContentScreen('tools'));
1.329 droeschl 4965: my $navmap = Apache::lonnavmaps::navmap->new();
4966: if (!defined($navmap)) {
4967: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4968: '<div class="LC_error">'.
4969: &mt('Unable to retrieve information about course contents').
4970: '</div>');
1.408 raeburn 4971: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4972: } else {
1.484 raeburn 4973: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4974: &Apache::loncommon::start_data_table().
4975: &Apache::loncommon::start_data_table_header_row().
4976: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4977: &Apache::loncommon::end_data_table_header_row()."\n");
4978: my $count;
1.329 droeschl 4979: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4980: $r->print(&Apache::loncommon::start_data_table_row().
4981: '<td>'.$res->compTitle().'</td>'.
4982: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4983: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4984: $count ++;
4985: }
4986: if (!$count) {
4987: $r->print(&Apache::loncommon::start_data_table_row().
4988: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4989: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4990: }
1.484 raeburn 4991: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4992: }
1.521 bisitz 4993: $r->print(&endContentScreen());
1.329 droeschl 4994: }
4995:
1.651 raeburn 4996: sub short_urls {
4997: my ($r,$canedit) = @_;
4998: my $crstype = &Apache::loncommon::course_type();
4999: my $formname = 'shortenurl';
5000: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
5001: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
5002: $r->print(&startContentScreen('tools'));
5003: my ($navmap,$errormsg) =
5004: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
5005: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5006: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5007: my (%maps,%resources,%titles);
5008: if (!ref($navmap)) {
5009: $r->print($errormsg.
5010: &endContentScreen());
5011: return '';
5012: } else {
1.652 raeburn 5013: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 5014: $r->rflush();
5015: my $readonly;
5016: if ($canedit) {
1.671 raeburn 5017: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 5018: if ($numnew) {
5019: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
5020: }
5021: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
5022: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
5023: foreach my $error (@{$errors}) {
5024: $r->print('<li>'.$error.'</li>');
5025: }
5026: $r->print('</ul><br />');
5027: }
5028: } else {
5029: $readonly = 1;
5030: }
5031: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
5032: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
5033: undef,undef,undef,undef,undef,\%currtiny,$readonly));
5034: }
5035: $r->print(&endContentScreen());
5036: }
5037:
1.637 raeburn 5038: sub contentverifyform {
5039: my ($r) = @_;
5040: my $crstype = &Apache::loncommon::course_type();
5041: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5042: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5043: $r->print(&startContentScreen('tools'));
5044: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5045: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
5046: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
5047: ' <span class="LC_nobreak">'.
5048: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
5049: &mt('No').'</label>'.(' 'x2).
5050: '<label><input type="radio" name="checkstale" value="1" />'.
5051: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 5052: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 5053: '<input type="hidden" value="1" name="tools" />'.
5054: '<input type="hidden" value="1" name="verify" /></p></form>');
5055: $r->print(&endContentScreen());
5056: return;
5057: }
1.329 droeschl 5058:
5059: sub verifycontent {
1.637 raeburn 5060: my ($r,$checkstale) = @_;
1.408 raeburn 5061: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 5062: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5063: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 5064: $r->print(&startContentScreen('tools'));
5065: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 5066: $hashtied=0;
5067: undef %alreadyseen;
5068: %alreadyseen=();
5069: &tiehash();
1.484 raeburn 5070:
1.329 droeschl 5071: foreach my $key (keys(%hash)) {
5072: if ($hash{$key}=~/\.(page|sequence)$/) {
5073: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5074: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 5075: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 5076: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 5077: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 5078: }
5079: }
5080: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 5081: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 5082: }
5083: }
5084: &untiehash();
1.442 www 5085: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 5086: $r->print(&endContentScreen());
1.329 droeschl 5087: }
5088:
5089: sub devalidateversioncache {
5090: my $src=shift;
5091: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5092: &Apache::lonnet::clutter($src));
5093: }
5094:
5095: sub checkversions {
1.611 raeburn 5096: my ($r,$canedit) = @_;
1.408 raeburn 5097: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 5098: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5099: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 5100: $r->print(&startContentScreen('tools'));
1.442 www 5101:
1.329 droeschl 5102: my $header='';
5103: my $startsel='';
5104: my $monthsel='';
5105: my $weeksel='';
5106: my $daysel='';
5107: my $allsel='';
5108: my %changes=();
5109: my $starttime=0;
5110: my $haschanged=0;
5111: my %setversions=&Apache::lonnet::dump('resourceversions',
5112: $env{'course.'.$env{'request.course.id'}.'.domain'},
5113: $env{'course.'.$env{'request.course.id'}.'.num'});
5114:
5115: $hashtied=0;
5116: &tiehash();
1.611 raeburn 5117: if ($canedit) {
5118: my %newsetversions=();
5119: if ($env{'form.setmostrecent'}) {
5120: $haschanged=1;
5121: foreach my $key (keys(%hash)) {
5122: if ($key=~/^ids\_(\/res\/.+)$/) {
5123: $newsetversions{$1}='mostrecent';
5124: &devalidateversioncache($1);
5125: }
5126: }
5127: } elsif ($env{'form.setcurrent'}) {
5128: $haschanged=1;
5129: foreach my $key (keys(%hash)) {
5130: if ($key=~/^ids\_(\/res\/.+)$/) {
5131: my $getvers=&Apache::lonnet::getversion($1);
5132: if ($getvers>0) {
5133: $newsetversions{$1}=$getvers;
5134: &devalidateversioncache($1);
5135: }
5136: }
1.329 droeschl 5137: }
1.611 raeburn 5138: } elsif ($env{'form.setversions'}) {
5139: $haschanged=1;
5140: foreach my $key (keys(%env)) {
5141: if ($key=~/^form\.set_version_(.+)$/) {
5142: my $src=$1;
5143: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5144: $newsetversions{$src}=$env{$key};
5145: &devalidateversioncache($src);
5146: }
5147: }
1.329 droeschl 5148: }
1.611 raeburn 5149: }
5150: if ($haschanged) {
5151: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5152: $env{'course.'.$env{'request.course.id'}.'.domain'},
5153: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5154: $r->print(&Apache::loncommon::confirmwrapper(
5155: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5156: } else {
5157: $r->print(&Apache::loncommon::confirmwrapper(
5158: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5159: }
1.611 raeburn 5160: &mark_hash_old();
5161: }
5162: &changewarning($r,'');
1.329 droeschl 5163: }
5164: if ($env{'form.timerange'} eq 'all') {
5165: # show all documents
1.549 raeburn 5166: $header=&mt('All content in '.$crstype);
1.521 bisitz 5167: $allsel=' selected="selected"';
1.329 droeschl 5168: foreach my $key (keys(%hash)) {
5169: if ($key=~/^ids\_(\/res\/.+)$/) {
5170: my $src=$1;
5171: $changes{$src}=1;
5172: }
5173: }
5174: } else {
5175: # show documents which changed
5176: %changes=&Apache::lonnet::dump
5177: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5178: $env{'course.'.$env{'request.course.id'}.'.num'});
5179: my $firstkey=(keys(%changes))[0];
5180: unless ($firstkey=~/^error\:/) {
5181: unless ($env{'form.timerange'}) {
5182: $env{'form.timerange'}=604800;
5183: }
5184: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5185: .&mt('seconds');
5186: if ($env{'form.timerange'}==-1) {
5187: $seltext='since start of course';
1.521 bisitz 5188: $startsel=' selected="selected"';
1.329 droeschl 5189: $env{'form.timerange'}=time;
5190: }
5191: $starttime=time-$env{'form.timerange'};
5192: if ($env{'form.timerange'}==2592000) {
5193: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5194: $monthsel=' selected="selected"';
1.329 droeschl 5195: } elsif ($env{'form.timerange'}==604800) {
5196: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5197: $weeksel=' selected="selected"';
1.329 droeschl 5198: } elsif ($env{'form.timerange'}==86400) {
5199: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5200: $daysel=' selected="selected"';
1.329 droeschl 5201: }
5202: $header=&mt('Content changed').' '.$seltext;
5203: } else {
5204: $header=&mt('No content modifications yet.');
5205: }
5206: }
5207: %setversions=&Apache::lonnet::dump('resourceversions',
5208: $env{'course.'.$env{'request.course.id'}.'.domain'},
5209: $env{'course.'.$env{'request.course.id'}.'.num'});
5210: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5211: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5212: 'lm' => 'Version changes since last Month',
5213: 'lw' => 'Version changes since last Week',
5214: 'sy' => 'Version changes since Yesterday',
5215: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5216: 'cd' => 'Change display',
1.329 droeschl 5217: 'sd' => 'Display',
5218: 'fi' => 'File',
5219: 'md' => 'Modification Date',
5220: 'mr' => 'Most recently published Version',
1.408 raeburn 5221: 've' => 'Version used in '.$crstype,
5222: 'vu' => 'Set Version to be used in '.$crstype,
5223: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5224: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5225: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5226: 'di' => 'Differences',
1.484 raeburn 5227: 'save' => 'Save changes',
5228: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5229: 'act' => 'Actions');
1.611 raeburn 5230: my ($disabled,$readonly);
5231: unless ($canedit) {
5232: $disabled = 'disabled="disabled"';
5233: $readonly = 1;
5234: }
1.329 droeschl 5235: $r->print(<<ENDHEADERS);
1.484 raeburn 5236: <h4 class="LC_info">$header</h4>
1.329 droeschl 5237: <form action="/adm/coursedocs" method="post">
5238: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5239: <div class="LC_left_float">
1.479 golterma 5240: <fieldset>
1.484 raeburn 5241: <legend>$lt{'cd'}</legend>
1.329 droeschl 5242: <select name="timerange">
1.521 bisitz 5243: <option value='all'$allsel>$lt{'al'}</option>
5244: <option value="-1"$startsel>$lt{'st'}</option>
5245: <option value="2592000"$monthsel>$lt{'lm'}</option>
5246: <option value="604800"$weeksel>$lt{'lw'}</option>
5247: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5248: </select>
5249: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5250: </fieldset>
5251: </div>
5252: <div class="LC_left_float">
5253: <fieldset>
5254: <legend>$lt{'act'}</legend>
1.611 raeburn 5255: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5256: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5257: </fieldset>
5258: </div>
5259: <br clear="all" />
5260: <hr />
5261: <h4>$lt{'vers'}</h4>
1.329 droeschl 5262: ENDHEADERS
1.479 golterma 5263: #number of columns for version history
1.571 raeburn 5264: my %changedbytime;
5265: foreach my $key (keys(%changes)) {
5266: #excludes not versionable problems from resource version history:
5267: next if ($key =~ /^\/res\/lib\/templates/);
5268: my $chg;
5269: if ($env{'form.timerange'} eq 'all') {
5270: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5271: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5272: } else {
5273: $chg = $changes{$key};
5274: next if ($chg < $starttime);
5275: }
5276: push(@{$changedbytime{$chg}},$key);
5277: }
5278: if (keys(%changedbytime) == 0) {
5279: &untiehash();
5280: $r->print(&mt('No content changes in imported content in specified time frame').
5281: &endContentScreen());
5282: return;
5283: }
1.479 golterma 5284: $r->print(
1.611 raeburn 5285: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5286: &Apache::loncommon::start_data_table().
5287: &Apache::loncommon::start_data_table_header_row().
5288: '<th>'.&mt('Resources').'</th>'.
5289: "<th>$lt{'mr'}</th>".
5290: "<th>$lt{'ve'}</th>".
5291: "<th>$lt{'vu'}</th>".
5292: '<th>'.&mt('History').'</th>'.
5293: &Apache::loncommon::end_data_table_header_row()
5294: );
1.571 raeburn 5295: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5296: foreach my $key (sort(@{$changedbytime{$chg}})) {
5297: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5298: my $currentversion=&Apache::lonnet::getversion($key);
5299: if ($currentversion<0) {
5300: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5301: }
5302: my $linkurl=&Apache::lonnet::clutter($key);
5303: $r->print(
5304: &Apache::loncommon::start_data_table_row().
5305: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5306: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5307: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5308: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5309: '<td align="right">'
5310: );
5311: # Used in course
5312: my $usedversion=$hash{'version_'.$linkurl};
5313: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5314: if ($usedversion != $currentversion) {
1.479 golterma 5315: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5316: } else {
1.479 golterma 5317: $r->print($usedversion);
5318: }
1.329 droeschl 5319: } else {
1.521 bisitz 5320: $r->print($currentversion);
1.329 droeschl 5321: }
1.571 raeburn 5322: $r->print('</td><td title="'.$lt{'vu'}.'">');
5323: # Set version
5324: $r->print(&Apache::loncommon::select_form(
5325: $setversions{$linkurl},
5326: 'set_version_'.$linkurl,
5327: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5328: '' => '',
5329: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5330: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5331: my $lastold=1;
5332: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5333: my $url=$root.'.'.$prevvers.'.'.$extension;
5334: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5335: $lastold=$prevvers;
5336: }
5337: }
5338: $r->print('</td>');
5339: # List all available versions
5340: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5341: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5342: my $url=$root.'.'.$prevvers.'.'.$extension;
5343: $r->print(
5344: '<span class="LC_nobreak">'
5345: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5346: .&mt('Version [_1]',$prevvers).'</a>'
5347: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5348: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5349: .')');
5350: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5351: $r->print(
5352: ' <a href="/adm/diff?filename='.
5353: &Apache::lonnet::clutter($root.'.'.$extension).
5354: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5355: '" target="diffs">'.&mt('Diffs').'</a>');
5356: }
5357: $r->print('</span><br />');
1.329 droeschl 5358: }
1.571 raeburn 5359: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5360: }
1.329 droeschl 5361: }
1.521 bisitz 5362: $r->print(
5363: &Apache::loncommon::end_data_table().
1.611 raeburn 5364: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5365: '</form>'
5366: );
1.329 droeschl 5367:
5368: &untiehash();
1.521 bisitz 5369: $r->print(&endContentScreen());
1.571 raeburn 5370: return;
1.329 droeschl 5371: }
5372:
5373: sub mark_hash_old {
5374: my $retie_hash=0;
5375: if ($hashtied) {
5376: $retie_hash=1;
5377: &untiehash();
5378: }
5379: &tiehash('write');
5380: $hash{'old'}=1;
5381: &untiehash();
5382: if ($retie_hash) { &tiehash(); }
5383: }
5384:
5385: sub is_hash_old {
5386: my $untie_hash=0;
5387: if (!$hashtied) {
5388: $untie_hash=1;
5389: &tiehash();
5390: }
5391: my $return=$hash{'old'};
5392: if ($untie_hash) { &untiehash(); }
5393: return $return;
5394: }
5395:
5396: sub changewarning {
5397: my ($r,$postexec,$message,$url)=@_;
5398: if (!&is_hash_old()) { return; }
5399: my $pathvar='folderpath';
5400: my $path=&escape($env{'form.folderpath'});
5401: if (!defined($url)) {
5402: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5403: }
5404: my $course_type = &Apache::loncommon::course_type();
5405: if (!defined($message)) {
5406: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5407: }
1.653 raeburn 5408: my $windowname = 'loncapaclient';
5409: if ($env{'request.lti.login'}) {
5410: $windowname .= 'lti';
5411: }
1.329 droeschl 5412: $r->print("\n\n".
1.372 bisitz 5413: '<script type="text/javascript">'."\n".
5414: '// <![CDATA['."\n".
5415: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5416: '// ]]>'."\n".
1.369 bisitz 5417: '</script>'."\n".
1.653 raeburn 5418: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5419: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5420: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5421: &mt($message,' <input type="hidden" name="'.
5422: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5423: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5424: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5425: }
5426:
5427:
5428: sub init_breadcrumbs {
1.571 raeburn 5429: my ($form,$text,$help)=@_;
1.329 droeschl 5430: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5431: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5432: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5433: faq=>273,
5434: bug=>'Instructor Interface',
1.571 raeburn 5435: help => $help});
1.329 droeschl 5436: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5437: text=>$text,
5438: faq=>273,
5439: bug=>'Instructor Interface'});
5440: }
5441:
1.441 www 5442: # subroutine to list form elements
5443: sub create_list_elements {
5444: my @formarr = @_;
5445: my $list = '';
1.501 raeburn 5446: foreach my $button (@formarr){
5447: foreach my $picture (keys(%{$button})) {
5448: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5449: }
5450: }
5451: return $list;
5452: }
1.329 droeschl 5453:
1.441 www 5454: # subroutine to create ul from list elements
5455: sub create_form_ul {
5456: my $list = shift;
5457: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5458: return $ul;
5459: }
1.329 droeschl 5460:
1.442 www 5461: #
5462: # Start tabs
5463: #
5464:
5465: sub startContentScreen {
1.484 raeburn 5466: my ($mode) = @_;
5467: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5468: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5469: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5470: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5471: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5472: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5473: } else {
1.549 raeburn 5474: $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 5475: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5476: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5477: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5478: }
5479: $output .= "\n".'</ul>'."\n";
5480: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5481: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5482: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5483: return $output;
1.442 www 5484: }
5485:
5486: #
5487: # End tabs
5488: #
5489:
5490: sub endContentScreen {
1.484 raeburn 5491: return '</div></div></div>';
1.442 www 5492: }
1.329 droeschl 5493:
1.446 www 5494: sub supplemental_base {
1.548 raeburn 5495: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5496: }
5497:
1.329 droeschl 5498: sub handler {
5499: my $r = shift;
5500: &Apache::loncommon::content_type($r,'text/html');
5501: $r->send_http_header;
5502: return OK if $r->header_only;
1.484 raeburn 5503:
5504: # get course data
1.408 raeburn 5505: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5506: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5507: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5508:
1.606 raeburn 5509: # get docroot
5510: my $londocroot = $r->dir_config('lonDocRoot');
5511:
1.484 raeburn 5512: # graphics settings
5513: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5514:
1.443 www 5515: #
1.329 droeschl 5516: # --------------------------------------------- Initialize help topics for this
5517: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5518: 'Adding_External_Resource','Adding_External_Tool',
5519: 'Navigate_Content','Adding_Folders','Docs_Overview',
5520: 'Load_Map','Supplemental','Score_Upload_Form',
5521: 'Adding_Pages','Importing_LON-CAPA_Resource',
5522: 'Importing_IMS_Course','Uploading_From_Harddrive',
5523: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5524: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5525: }
5526: # Composite help files
5527: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5528: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5529: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5530: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5531: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5532: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5533: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5534: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5535: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5536: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5537:
1.611 raeburn 5538: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.682 raeburn 5539: # does this user have privileges to modify content.
5540: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1.472 raeburn 5541: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
1.682 raeburn 5542: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5543: $allowed = 1;
1.682 raeburn 5544: }
5545: $canedit = 1;
5546: $canview = 1;
5547: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5548: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5549: unless ($r->uri eq '/adm/supplemental') {
1.611 raeburn 5550: $allowed = 1;
5551: }
1.682 raeburn 5552: $canview = 1;
1.611 raeburn 5553: }
5554: unless ($canedit) {
5555: $disabled = ' disabled="disabled"';
1.472 raeburn 5556: }
1.582 raeburn 5557: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5558: if ($env{'form.inhibitmenu'}) {
5559: unless ($env{'form.inhibitmenu'} eq 'yes') {
5560: delete($env{'form.inhibitmenu'});
5561: }
5562: }
5563:
1.582 raeburn 5564: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5565: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5566: if (!$canedit) {
5567: &verifycontent($r);
5568: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5569: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5570: text=>'Results',
5571: faq=>273,
5572: bug=>'Instructor Interface'});
5573: &verifycontent($r,$env{'form.checkstale'});
5574: } else {
5575: &contentverifyform($r);
5576: }
1.329 droeschl 5577: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5578: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5579: &list_symbs($r);
1.651 raeburn 5580: } elsif ($allowed && $env{'form.shorturls'}) {
5581: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5582: &short_urls($r,$canedit);
1.329 droeschl 5583: } elsif ($allowed && $env{'form.docslog'}) {
5584: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5585: my $folder = $env{'form.folder'};
5586: if ($folder eq '') {
5587: $folder='default';
5588: }
1.611 raeburn 5589: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5590: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5591: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5592: &checkversions($r,$canedit);
5593: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5594: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5595: &dumpcourse($r);
1.611 raeburn 5596: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5597: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5598: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5599: } else {
1.611 raeburn 5600: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5601: $noendpage = 1;
5602: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5603: if ($redirect) {
5604: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5605: my $container = 'sequence';
5606: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5607: $is_random_order,$container) =
5608: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5609: my (@folders)=split('&',$env{'form.folderpath'});
5610: $env{'form.foldername'}=&unescape(pop(@folders));
5611: my $folder=pop(@folders);
5612: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5613: $folder.'.'.$container);
5614: my $warning;
5615: if ($fatal) {
5616: if ($container eq 'page') {
5617: $warning = &mt('An error occurred retrieving the contents of the current page.');
5618: } else {
5619: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5620: }
5621: } else {
5622: my $url = $redirect;
5623: my $srcfile = $londocroot.$url;
5624: $url =~ s{^/priv/}{/res/};
5625: my $targetfile = $londocroot.$url;
5626: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5627: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5628: $env{'form.folder'} = $folder;
5629: &snapshotbefore();
5630: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5631: my $ext = 'false';
5632: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5633: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5634: ':'.$ext.':normal:res';
5635: push(@LONCAPA::map::order,$newidx);
5636: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5637: 'string_yesno');
5638: &remember_parms($newidx,'hiddenresource','set','yes');
5639: ($errtext,$fatal) =
5640: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5641: &log_differences($plain);
5642: &mark_hash_old();
5643: $r->internal_redirect($redirect);
5644: return OK;
5645: }
1.654 raeburn 5646: } else {
5647: $r->internal_redirect($redirect);
1.606 raeburn 5648: }
5649: }
5650: }
1.445 www 5651: #
5652: # Done catching special calls
1.484 raeburn 5653: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5654: # Get the parameters that may be needed
5655: #
5656: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.682 raeburn 5657: ['folderpath','title',
1.519 raeburn 5658: 'forcesupplement','forcestandard',
1.510 raeburn 5659: 'tools','symb','command','supppath']);
1.445 www 5660:
1.635 raeburn 5661: foreach my $item ('forcesupplement','forcestandard','tools') {
5662: next if ($env{'form.'.$item} eq '');
5663: unless ($env{'form.'.$item} eq '1') {
5664: delete($env{'form.'.$item});
5665: }
5666: }
5667:
5668: if ($env{'form.command'}) {
5669: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5670: delete($env{'form.command'});
5671: }
5672: }
5673:
5674: if ($env{'form.symb'}) {
5675: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5676: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5677: delete($env{'form.symb'});
5678: }
5679: }
5680:
1.445 www 5681: # standard=1: this is a "new-style" course with an uploaded map as top level
5682: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5683:
5684: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5685:
1.484 raeburn 5686: # Decide whether this should display supplemental or main content or utilities
1.445 www 5687: # supplementalflag=1: show supplemental documents
5688: # supplementalflag=0: show standard documents
1.484 raeburn 5689: # toolsflag=1: show utilities
1.445 www 5690:
1.561 raeburn 5691: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5692: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5693: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5694: $supplementalflag=0;
5695: }
5696: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5697: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5698: unless ($allowed) { $supplementalflag=1; }
5699: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5700: my $toolsflag=0;
5701: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5702:
1.635 raeburn 5703: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5704: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.635 raeburn 5705: }
5706:
1.685 raeburn 5707: my $backto_supppath;
1.635 raeburn 5708: if ($env{'form.supppath'} ne '') {
1.685 raeburn 5709: if ($supplementalflag && $allowed) {
5710: $backto_supppath = &validate_supppath($coursenum,$coursedom);
5711: }
1.635 raeburn 5712: }
5713:
1.329 droeschl 5714: my $script='';
5715: my $showdoc=0;
1.457 raeburn 5716: my $addentries = {};
1.475 raeburn 5717: my $container;
1.329 droeschl 5718: my $containertag;
1.508 raeburn 5719: my $pathitem;
1.598 raeburn 5720: my %ltitools;
1.617 raeburn 5721: my $hiddentop;
1.615 raeburn 5722: my $navmap;
1.617 raeburn 5723: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5724:
1.464 www 5725: # Do we directly jump somewhere?
1.525 raeburn 5726: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5727: if ($env{'form.symb'} ne '') {
1.522 raeburn 5728: $env{'form.folderpath'}=
1.617 raeburn 5729: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5730: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5731: $env{'form.command'}.'_'.$env{'form.symb'}});
1.685 raeburn 5732: } elsif (($env{'form.supppath'} ne '') && $supplementalflag && $allowed) {
1.472 raeburn 5733: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5734: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.685 raeburn 5735: $env{'form.command'}.'_'.$backto_supppath});
1.466 www 5736: }
1.472 raeburn 5737: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5738: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5739: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5740: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5741: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5742: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5743: } elsif ($env{'form.command'} eq 'contents') {
5744: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5745: } elsif ($env{'form.command'} eq 'home') {
5746: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5747: }
5748:
1.525 raeburn 5749:
1.445 www 5750: # Where do we store these for when we come back?
5751: my $stored_folderpath='docs_folderpath';
5752: if ($supplementalflag) {
5753: $stored_folderpath='docs_sup_folderpath';
5754: }
1.464 www 5755:
1.519 raeburn 5756: # No folderpath, and in edit mode, see if we have something stored
5757: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5758: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5759: {'folderpath' => 'scalar'});
1.615 raeburn 5760:
5761: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5762: if ($supplementalflag) {
5763: undef($env{'form.folderpath'}) if ($1 eq 'default');
5764: } else {
5765: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5766: }
5767: } else {
1.523 raeburn 5768: undef($env{'form.folderpath'});
5769: }
1.677 raeburn 5770: if ($env{'form.folderpath'} ne '') {
1.685 raeburn 5771: &Apache::loncommon::validate_folderpath($supplementalflag,$allowed,$coursenum,$coursedom);
1.677 raeburn 5772: }
1.329 droeschl 5773: }
1.446 www 5774:
5775: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5776: if (!$allowed) {
1.446 www 5777: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5778: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5779: }
5780: }
1.446 www 5781: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5782: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5783: $env{'form.folderpath'} = &supplemental_base()
5784: .'&'.
1.329 droeschl 5785: $env{'form.folderpath'};
5786: }
1.685 raeburn 5787: # If allowed and user's role is not advanced check folderpath is not hidden
5788: my $hidden_and_empty;
1.687 raeburn 5789: if (($allowed) && (!$env{'request.role.adv'}) && ($env{'form.folderpath'} ne '')) {
1.685 raeburn 5790: my ($folderurl,$foldername,$hiddenfolder);
1.615 raeburn 5791: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5792: my $folder = $pathitems[-2];
5793: if ($folder eq '') {
5794: undef($env{'form.folderpath'});
5795: } else {
5796: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 5797: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 5798: $folderurl .= '.page';
5799: } else {
5800: $folderurl .= '.sequence';
5801: }
1.685 raeburn 5802: if ($supplementalflag) {
5803: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*)::(|1):::$/);
5804: $foldername = &HTML::Entities::decode(&unescape($foldername));
1.688 raeburn 5805: my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
1.685 raeburn 5806: if (ref($supplemental) eq 'HASH') {
5807: my ($suppmap,$suppmapnum);
5808: if ($folder eq 'supplemental') {
5809: $suppmap = 'default';
5810: $suppmapnum = 0;
5811: } elsif ($folder =~ /^supplemental_(\d+)$/) {
5812: $suppmap = $1;
5813: $suppmapnum = $suppmap;
5814: }
5815: if ($hiddenfolder) {
5816: my $hascontent;
5817: foreach my $key (reverse(sort(keys(%{$supplemental->{'ids'}})))) {
5818: if ($key =~ m{^\Q/uploaded/$coursedom/$coursenum/supplemental/$suppmap/\E}) {
5819: $hascontent = 1;
5820: } elsif (ref($supplemental->{'ids'}->{$key}) eq 'ARRAY') {
5821: foreach my $id (@{$supplemental->{'ids'}->{$key}}) {
5822: if ($id =~ /^$suppmapnum\:/) {
5823: $hascontent = 1;
5824: last;
5825: }
5826: }
5827: }
5828: last if ($hascontent);
5829: }
5830: unless ($hascontent) {
5831: if ($foldername ne '') {
5832: $hidden_and_empty = $foldername;
5833: } else {
5834: $hidden_and_empty = $folder;
5835: }
5836: }
5837: }
5838: }
5839: } else {
5840: unless (ref($navmap)) {
5841: $navmap = Apache::lonnavmaps::navmap->new();
5842: }
5843: ($foldername,$hiddenfolder) = ($pathitems[-1] =~ /^([^:]*):|\d+:|1:(|1):|1:|1$/);
5844: $foldername = &HTML::Entities::decode(&unescape($foldername));
5845: if (ref($navmap)) {
5846: if ($hiddenfolder ||
5847: (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes')) {
5848: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5849: unless (@resources) {
5850: if ($foldername ne '') {
5851: $hidden_and_empty = $foldername;
5852: } else {
5853: $hidden_and_empty = $folder;
5854: }
5855: }
5856: }
5857: }
1.617 raeburn 5858: }
1.685 raeburn 5859: if ($hidden_and_empty ne '') {
5860: splice(@pathitems,-2);
5861: if (@pathitems) {
5862: $env{'form.folderpath'} = join('&',@pathitems);
5863: } else {
5864: undef($env{'form.folderpath'});
1.615 raeburn 5865: }
5866: }
5867: }
5868: }
5869:
1.446 www 5870: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5871: unless ($env{'form.folderpath'}) {
1.446 www 5872: if ($supplementalflag) {
5873: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5874: } elsif ($allowed) {
5875: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5876: }
1.472 raeburn 5877: }
1.446 www 5878:
1.445 www 5879: # Store this
1.484 raeburn 5880: unless ($toolsflag) {
1.615 raeburn 5881: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5882: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5883: {'folderpath' => 'scalar'});
1.510 raeburn 5884: }
1.519 raeburn 5885: my $folderpath;
1.484 raeburn 5886: if ($env{'form.folderpath'}) {
1.519 raeburn 5887: $folderpath = $env{'form.folderpath'};
5888: my (@folders)=split('&',$env{'form.folderpath'});
5889: $env{'form.foldername'}=&unescape(pop(@folders));
5890: if ($env{'form.foldername'} =~ /\:1$/) {
5891: $container = 'page';
5892: } else {
5893: $container = 'sequence';
5894: }
5895: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5896: } else {
1.519 raeburn 5897: if ($env{'form.folder'} eq '' ||
5898: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5899: if ($env{'form.folder'} eq 'supplemental') {
5900: $folderpath=&supplemental_base();
5901: } elsif (!$hiddentop) {
5902: $folderpath='default&'.
5903: &escape(&mt('Main Content').':::::');
5904: }
1.484 raeburn 5905: }
5906: }
1.519 raeburn 5907: $containertag = '<input type="hidden" name="folderpath" value="" />';
5908: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5909: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5910: $showdoc='/'.$1;
5911: }
5912: if ($showdoc) { # got called in sequence from course
5913: $allowed=0;
5914: } else {
1.611 raeburn 5915: if ($canedit) {
1.484 raeburn 5916: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5917: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5918: }
5919: }
1.329 droeschl 5920: }
5921:
1.344 bisitz 5922: # get personal data
1.329 droeschl 5923: my $uname=$env{'user.name'};
5924: my $udom=$env{'user.domain'};
5925: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5926:
5927: if ($allowed) {
1.484 raeburn 5928: if ($toolsflag) {
5929: $script .= &inject_data_js();
5930: my ($home,$other,%outhash)=&authorhosts();
5931: if (!$home && $other) {
5932: my @hosts;
5933: foreach my $aurole (keys(%outhash)) {
5934: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5935: push(@hosts,$outhash{$aurole});
5936: }
5937: }
5938: $script .= &dump_switchserver_js(@hosts);
5939: }
1.458 raeburn 5940: } else {
1.570 raeburn 5941: my $tid = 1;
1.484 raeburn 5942: my @tabids;
5943: if ($supplementalflag) {
1.655 raeburn 5944: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5945: $tid = 2;
1.484 raeburn 5946: } else {
5947: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5948: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5949: unshift(@tabids,'001');
5950: push(@tabids,('dd1','ee1'));
5951: }
1.458 raeburn 5952: }
1.484 raeburn 5953: my $tabidstr = join("','",@tabids);
1.644 raeburn 5954: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600 raeburn 5955: my $posslti = keys(%ltitools);
1.622 raeburn 5956: my $hostname = $r->hostname();
1.606 raeburn 5957: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5958: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5959: &history_tab_js().
5960: &inject_data_js().
1.570 raeburn 5961: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5962: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.685 raeburn 5963: my $onload = "javascript:resize_scrollbox('contentscroll','1','1');";
5964: if ($hidden_and_empty ne '') {
5965: my $alert = &mt("Additional privileges required to edit empty and hidden folder: '[_1]'",
5966: $hidden_and_empty);
5967: $onload .= "javascript:alert('".&js_escape($alert)."');";
5968: }
1.484 raeburn 5969: $addentries = {
1.685 raeburn 5970: onload => $onload,
1.484 raeburn 5971: };
1.458 raeburn 5972: }
1.538 raeburn 5973: $script .= &paste_popup_js();
1.501 raeburn 5974: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5975: &mt('Switch server?');
5976:
5977:
1.329 droeschl 5978: }
5979: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5980: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5981: .'// <![CDATA['."\n"
5982: .$script."\n"
5983: .'// ]]>'."\n"
1.595 musolffc 5984: .'</script>'."\n"
5985: .'<script type="text/javascript"
5986: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5987:
5988: # Breadcrumbs
5989: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5990:
5991: if ($showdoc) {
1.682 raeburn 5992: my $args;
5993: if ($supplementalflag) {
1.687 raeburn 5994: my $title = &HTML::Entities::encode($env{'form.title'},'\'"<>&');
5995: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.682 raeburn 5996: $args = {'bread_crumbs' => $brcrum};
5997: } else {
5998: $args = {'force_register' => $showdoc};
5999: }
6000: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
1.571 raeburn 6001: } elsif ($toolsflag) {
1.611 raeburn 6002: my ($breadtext,$breadtitle);
1.617 raeburn 6003: $breadtext = "$crstype Editor";
1.611 raeburn 6004: if ($canedit) {
6005: $breadtitle = 'Editing '.$crstype.' Contents';
6006: } else {
6007: $breadtext .= ' (View-only mode)';
6008: $breadtitle = 'Viewing '.$crstype.' Contents';
6009: }
1.571 raeburn 6010: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6011: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 6012: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
6013: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6014: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6015: $breadtitle)
1.571 raeburn 6016: );
1.510 raeburn 6017: } elsif ($r->uri eq '/adm/supplemental') {
1.682 raeburn 6018: unless ($env{'request.role.adv'}) {
6019: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
6020: $r->internal_redirect('/adm/navmaps');
6021: return OK;
6022: }
6023: }
1.510 raeburn 6024: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
6025: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
6026: {'bread_crumbs' => $brcrum,}));
6027: } else {
1.611 raeburn 6028: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 6029: $breadtext = "$crstype Editor";
1.611 raeburn 6030: if ($canedit) {
6031: $breadtitle = 'Editing '.$crstype.' Contents';
6032: $helpitem = 'Docs_Adding_Course_Doc';
6033: } else {
6034: $breadtext .= ' (View-only mode)';
6035: $breadtitle = 'Viewing '.$crstype.' Contents';
6036: $helpitem = 'Docs_Viewing_Course_Doc';
6037: }
1.392 raeburn 6038: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 6039: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 6040: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 6041: {'add_entries' => $addentries}
6042: )
1.392 raeburn 6043: .&Apache::loncommon::help_open_menu('','',273,'RAT')
6044: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 6045: $breadtitle,
6046: $helpitem)
1.392 raeburn 6047: );
6048: }
1.364 bisitz 6049:
1.329 droeschl 6050: my %allfiles = ();
6051: my %codebase = ();
1.440 raeburn 6052: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 6053: if ($canedit) {
1.684 raeburn 6054: undef($suppchanges);
1.329 droeschl 6055: if (($env{'form.uploaddoc.filename'}) &&
6056: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 6057: my $context = $1;
6058: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 6059: undef($hadchanges);
1.440 raeburn 6060: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 6061: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 6062: undef($navmap);
1.329 droeschl 6063: if ($hadchanges) {
6064: &mark_hash_old();
6065: }
1.684 raeburn 6066: if ($suppchanges) {
6067: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
6068: undef($suppchanges);
6069: }
1.440 raeburn 6070: $r->print($upload_output);
6071: } elsif ($env{'form.phase'} eq 'upload_embedded') {
6072: # Process file upload - phase two - upload embedded objects
6073: $uploadphase = 'check_embedded';
6074: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
6075: my $state = &embedded_form_elems($uploadphase,$primaryurl,
6076: $env{'form.newidx'});
6077: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6078: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6079: my ($destination,$dir_root) = &embedded_destination();
6080: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
6081: my $actionurl = '/adm/coursedocs';
1.630 raeburn 6082: my ($result,$flag) =
1.440 raeburn 6083: &Apache::loncommon::upload_embedded('coursedoc',$destination,
6084: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
6085: $actionurl);
6086: $r->print($result.&return_to_editor());
6087: } elsif ($env{'form.phase'} eq 'check_embedded') {
6088: # Process file upload - phase three - modify references in HTML file
6089: $uploadphase = 'modified_orightml';
6090: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6091: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6092: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 6093: my $result =
1.482 raeburn 6094: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
6095: $docuname,$docudom,undef,
6096: $dir_root);
1.630 raeburn 6097: $r->print($result.&return_to_editor());
1.476 raeburn 6098: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
6099: $uploadphase = 'decompress_phase_one';
6100: $r->print(&decompression_phase_one().
6101: &return_to_editor());
6102: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
6103: $uploadphase = 'decompress_phase_two';
6104: $r->print(&decompression_phase_two().
6105: &return_to_editor());
1.329 droeschl 6106: }
6107: }
6108:
1.484 raeburn 6109: if ($allowed && $toolsflag) {
6110: $r->print(&startContentScreen('tools'));
1.611 raeburn 6111: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 6112: $r->print(&endContentScreen());
6113: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 6114: # -----------------------------------------------------------------------------
6115: my %lt=&Apache::lonlocal::texthash(
6116: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 6117: 'upfi' => 'Upload File',
1.553 raeburn 6118: 'upld' => 'Upload Content',
1.329 droeschl 6119: 'srch' => 'Search',
6120: 'impo' => 'Import',
1.487 raeburn 6121: 'lnks' => 'Import from Stored Links',
1.502 raeburn 6122: 'impm' => 'Import from Assembled Map',
1.630 raeburn 6123: 'imcr' => 'Import from Course Resources',
1.598 raeburn 6124: 'extr' => 'External Resource',
6125: 'extt' => 'External Tool',
1.329 droeschl 6126: 'selm' => 'Select Map',
6127: 'load' => 'Load Map',
6128: 'newf' => 'New Folder',
6129: 'newp' => 'New Composite Page',
6130: 'syll' => 'Syllabus',
1.425 raeburn 6131: 'navc' => 'Table of Contents',
1.343 biermanm 6132: 'sipa' => 'Simple Course Page',
1.329 droeschl 6133: 'sipr' => 'Simple Problem',
1.630 raeburn 6134: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 6135: 'stpr' => 'Standard Problem',
6136: 'news' => 'New sub-directory',
6137: 'crpr' => 'Create Problem',
1.689 raeburn 6138: 'swit' => 'Switch Server',
1.329 droeschl 6139: 'drbx' => 'Drop Box',
1.451 www 6140: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 6141: 'bull' => 'Discussion Board',
1.347 weissno 6142: 'mypi' => 'My Personal Information Page',
1.353 weissno 6143: 'grpo' => 'Group Portfolio',
1.329 droeschl 6144: 'rost' => 'Course Roster',
1.528 raeburn 6145: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 6146: 'imsf' => 'IMS Upload',
6147: 'imsl' => 'Upload IMS package',
1.501 raeburn 6148: 'cms' => 'Origin of IMS package',
6149: 'se' => 'Select',
1.329 droeschl 6150: 'file' => 'File',
6151: 'title' => 'Title',
1.606 raeburn 6152: 'addp' => 'Add Placeholder to course?',
6153: 'uste' => 'Use Template?',
6154: 'fnam' => 'File Name:',
6155: 'loca' => 'Location:',
6156: 'dire' => 'Directory:',
6157: 'cate' => 'Category:',
6158: 'tmpl' => 'Template:',
1.329 droeschl 6159: 'comment' => 'Comment',
1.403 raeburn 6160: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 6161: 'bb5' => 'Blackboard 5',
6162: 'bb6' => 'Blackboard 6',
6163: 'angel5' => 'ANGEL 5.5',
6164: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 6165: 'yes' => 'Yes',
6166: 'no' => 'No',
1.618 raeburn 6167: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 6168: );
1.329 droeschl 6169: # -----------------------------------------------------------------------------
1.595 musolffc 6170:
6171: # Calculate free quota space for a user or course. A javascript function checks
6172: # file size to determine if upload should be allowed.
6173: my $quotatype = 'unofficial';
6174: if ($crstype eq 'Community') {
1.601 raeburn 6175: $quotatype = 'community';
6176: } elsif ($crstype eq 'Placement') {
6177: $quotatype = 'placement';
1.595 musolffc 6178: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6179: $quotatype = 'official';
6180: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6181: $quotatype = 'textbook';
6182: }
6183: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6184: 'course',$quotatype); # expressed in MB
6185: my $current_disk_usage = 0;
6186: foreach my $subdir ('docs','supplemental') {
6187: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6188: "userfiles/$subdir",1); # expressed in kB
6189: }
6190: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 6191: my $usage = $current_disk_usage/1024; # in MB
6192: my $quota = $disk_quota;
6193: my $percent;
6194: if ($disk_quota == 0) {
6195: $percent = 100.0;
6196: } else {
1.619 raeburn 6197: $percent = 100*($usage/$disk_quota);
1.605 raeburn 6198: }
6199: $usage = sprintf("%.2f",$usage);
6200: $quota = sprintf("%.2f",$quota);
6201: $percent = sprintf("%.0f",$percent);
6202: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6203: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 6204:
1.329 droeschl 6205: my $fileupload=(<<FIUP);
1.605 raeburn 6206: $quotainfo
1.329 droeschl 6207: $lt{'file'}:<br />
1.662 raeburn 6208: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663 raeburn 6209: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 6210: FIUP
6211:
6212: my $checkbox=(<<CHBO);
6213: <!-- <label>$lt{'parse'}?
6214: <input type="checkbox" name="parserflag" />
6215: </label> -->
6216: <label>
1.611 raeburn 6217: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6218: </label>
6219: CHBO
1.501 raeburn 6220: my $imsfolder = $env{'form.folder'};
6221: if ($imsfolder eq '') {
6222: $imsfolder = 'default';
6223: }
6224: my $imspform=(<<IMSFORM);
6225: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6226: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6227: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6228: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6229: <legend>$lt{'imsf'}</legend>
6230: $fileupload
6231: <br />
6232: <p>
6233: $lt{'cms'}:
1.611 raeburn 6234: <select name="source" $disabled>
1.501 raeburn 6235: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6236: <option value="bb5">$lt{'bb5'}</option>
6237: <option value="bb6">$lt{'bb6'}</option>
6238: <option value="angel5">$lt{'angel5'}</option>
6239: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6240: </select>
6241: <input type="hidden" name="folder" value="$imsfolder" />
6242: </p>
6243: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6244: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6245: </fieldset>
6246: </form>
6247: IMSFORM
1.329 droeschl 6248:
6249: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6250: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6251: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6252: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6253: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6254: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6255: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6256: $fileupload
1.329 droeschl 6257: <br />
6258: $lt{'title'}:<br />
1.611 raeburn 6259: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6260: $pathitem
1.329 droeschl 6261: <input type="hidden" name="cmd" value="upload_default" />
6262: <br />
1.458 raeburn 6263: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6264: $checkbox
6265: </span>
1.501 raeburn 6266: <br clear="all" />
1.611 raeburn 6267: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6268: </fieldset>
6269: </form>
1.383 tempelho 6270: FUFORM
1.329 droeschl 6271:
1.611 raeburn 6272: my $mapimportjs;
6273: if ($canedit) {
6274: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6275: } else {
6276: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6277: }
1.502 raeburn 6278: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6279: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6280: $lt{'impm'}</a>$help{'Load_Map'}
6281: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6282: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6283: <legend>$lt{'impm'}</legend>
1.371 tempelho 6284: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6285: $lt{'copm'}<br />
6286: <span class="LC_nobreak">
6287: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6288: onfocus="this.blur();$mapimportjs" $disabled />
6289: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6290: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6291: </fieldset>
6292: </form>
6293:
1.383 tempelho 6294: SEDFFORM
1.606 raeburn 6295: my $importcrsresform;
1.608 raeburn 6296: my ($numdirs,$pickfile) =
1.690 ! raeburn 6297: &Apache::loncommon::import_crsauthor_form('coursepath','coursefile',
1.608 raeburn 6298: "resize_scrollbox('contentscroll','1','0');",
6299: undef,'res');
1.606 raeburn 6300: if ($pickfile) {
6301: $importcrsresform=(<<CRSFORM);
1.690 ! raeburn 6302: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res');">
1.606 raeburn 6303: $lt{'imcr'}</a>$help{'Course_Resources'}
6304: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6305: <fieldset id="importcrsresform" style="display: none;">
6306: <legend>$lt{'imcr'}</legend>
6307: <input type="hidden" name="active" value="bb" />
6308: $pickfile
6309: <p>
1.611 raeburn 6310: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 6311: </p>
6312: <input type="hidden" name="importdetail" value="" />
1.690 ! raeburn 6313: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled /><br />
1.606 raeburn 6314: </fieldset>
6315: </form>
6316: CRSFORM
6317: }
6318:
1.611 raeburn 6319: my $fromstoredjs;
6320: if ($canedit) {
6321: $fromstoredjs = 'open_StoredLinks_Import()';
6322: } else {
6323: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6324: }
6325:
1.502 raeburn 6326: my @importpubforma = (
1.508 raeburn 6327: { '<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 6328: { '<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 6329: { '<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 6330: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6331: );
6332: if ($pickfile) {
1.690 ! raeburn 6333: 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 6334: }
1.502 raeburn 6335: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6336: my $extresourcesform =
6337: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6338: $help{'Adding_External_Resource'},
6339: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6340: my $exttoolform =
6341: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6342: $help{'Adding_External_Tool'},undef,
6343: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6344: \%ltitools,$disabled);
1.329 droeschl 6345: if ($allowed) {
1.492 raeburn 6346: my $folder = $env{'form.folder'};
6347: if ($folder eq '') {
6348: $folder='default';
6349: }
1.615 raeburn 6350: if ($canedit) {
6351: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6352: if ($output) {
6353: $r->print($output);
6354: }
1.538 raeburn 6355: }
1.337 ehlerst 6356: $r->print(<<HIDDENFORM);
6357: <form name="renameform" method="post" action="/adm/coursedocs">
6358: <input type="hidden" name="title" />
6359: <input type="hidden" name="cmd" />
6360: <input type="hidden" name="markcopy" />
6361: <input type="hidden" name="copyfolder" />
6362: $containertag
6363: </form>
1.633 raeburn 6364: <form name="aliasform" method="post" action="/adm/coursedocs">
6365: <input type="hidden" name="alias" />
6366: <input type="hidden" name="cmd" />
6367: $containertag
6368: </form>
1.484 raeburn 6369:
1.337 ehlerst 6370: HIDDENFORM
1.508 raeburn 6371: $r->print(&makesimpleeditform($pathitem)."\n".
6372: &makedocslogform($pathitem."\n".
1.484 raeburn 6373: '<input type="hidden" name="folder" value="'.
6374: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6375: }
1.442 www 6376:
6377: # Generate the tabs
1.510 raeburn 6378: my ($mode,$needs_end);
1.472 raeburn 6379: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6380: my @folders = split('&',$env{'form.folderpath'});
6381: unless (@folders > 2) {
6382: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6383: $needs_end = 1;
6384: }
1.472 raeburn 6385: } else {
1.484 raeburn 6386: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6387: $needs_end = 1;
1.472 raeburn 6388: }
1.443 www 6389:
1.442 www 6390: #
1.622 raeburn 6391: my $hostname = $r->hostname();
1.442 www 6392: my $savefolderpath;
6393:
1.395 raeburn 6394: if ($allowed) {
1.329 droeschl 6395: my $folder=$env{'form.folder'};
1.615 raeburn 6396: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6397: $folder='default';
1.356 tempelho 6398: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6399: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6400: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6401: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6402: }
6403: my $postexec='';
6404: if ($folder eq 'default') {
1.653 raeburn 6405: my $windowname = 'loncapaclient';
6406: if ($env{'request.lti.login'}) {
6407: $windowname .= 'lti';
6408: }
1.372 bisitz 6409: $r->print('<script type="text/javascript">'."\n"
6410: .'// <![CDATA['."\n"
1.653 raeburn 6411: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6412: .'// ]]>'."\n"
6413: .'</script>'."\n"
1.369 bisitz 6414: );
1.329 droeschl 6415: } else {
6416: #$postexec='self.close();';
6417: }
1.504 raeburn 6418: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6419: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6420: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6421:
6422: my $newnavform=(<<NNFORM);
6423: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6424: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6425: $pathitem
1.329 droeschl 6426: <input type="hidden" name="importdetail"
6427: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6428: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6429: $help{'Navigate_Content'}
6430: </form>
6431: NNFORM
6432: my $newsmppageform=(<<NSPFORM);
6433: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6434: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6435: $pathitem
1.329 droeschl 6436: <input type="hidden" name="importdetail" value="" />
1.423 onken 6437: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6438: $help{'Simple Page'}
1.329 droeschl 6439: </form>
6440: NSPFORM
6441:
6442: my $newsmpproblemform=(<<NSPROBFORM);
6443: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6444: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6445: $pathitem
1.329 droeschl 6446: <input type="hidden" name="importdetail" value="" />
1.423 onken 6447: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6448: $help{'Simple_Problem'}
1.329 droeschl 6449: </form>
6450:
6451: NSPROBFORM
6452:
6453: my $newdropboxform=(<<NDBFORM);
6454: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6455: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6456: $pathitem
1.329 droeschl 6457: <input type="hidden" name="importdetail" value="" />
1.423 onken 6458: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6459: $help{'Dropbox'}
1.344 bisitz 6460: </form>
1.329 droeschl 6461: NDBFORM
6462:
6463: my $newexuploadform=(<<NEXUFORM);
6464: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6465: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6466: $pathitem
1.329 droeschl 6467: <input type="hidden" name="importdetail" value="" />
1.423 onken 6468: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6469: $help{'Score_Upload_Form'}
6470: </form>
6471: NEXUFORM
6472:
6473: my $newbulform=(<<NBFORM);
6474: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6475: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6476: $pathitem
1.329 droeschl 6477: <input type="hidden" name="importdetail" value="" />
1.423 onken 6478: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6479: $help{'Bulletin Board'}
6480: </form>
6481: NBFORM
6482:
6483: my $newaboutmeform=(<<NAMFORM);
6484: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6485: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6486: $pathitem
1.329 droeschl 6487: <input type="hidden" name="importdetail"
6488: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6489: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6490: $help{'My Personal Information Page'}
1.329 droeschl 6491: </form>
6492: NAMFORM
6493:
6494: my $newaboutsomeoneform=(<<NASOFORM);
6495: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6496: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6497: $pathitem
1.329 droeschl 6498: <input type="hidden" name="importdetail" value="" />
1.423 onken 6499: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6500: </form>
6501: NASOFORM
6502:
6503: my $newrosterform=(<<NROSTFORM);
6504: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6505: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6506: $pathitem
1.329 droeschl 6507: <input type="hidden" name="importdetail"
6508: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6509: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6510: $help{'Course_Roster'}
1.329 droeschl 6511: </form>
6512: NROSTFORM
6513:
1.534 raeburn 6514: my $newwebpage;
6515: if ($folder =~ /^default_?(\d*)$/) {
6516: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6517: if ($1) {
6518: $newwebpage .= $1;
6519: } else {
6520: $newwebpage .= 'default';
6521: }
6522: $newwebpage .= '/new.html';
6523: }
6524: my $newwebpageform =(<<NWEBFORM);
6525: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6526: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6527: $pathitem
6528: <input type="hidden" name="importdetail" value="$newwebpage" />
6529: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6530: $help{'Web_Page'}
1.534 raeburn 6531: </form>
6532: NWEBFORM
1.604 raeburn 6533:
1.606 raeburn 6534: my @ids=&Apache::lonnet::current_machine_ids();
1.689 raeburn 6535: my (%select_menus,$rolehomes);
1.606 raeburn 6536: my $numauthor = 0;
6537: my $numcrsdirs = 0;
1.689 raeburn 6538: my ($showstdprob,$showswitch,$switchlink);
1.606 raeburn 6539: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
1.690 ! raeburn 6540: my $exclude = &Apache::lonnet::priv_exclude();
1.606 raeburn 6541: if ($env{'user.author'}) {
6542: $numauthor ++;
6543: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6544: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6545: my $is_home = 1;
6546: my %subdirs;
1.690 ! raeburn 6547: &Apache::lonnet::recursedirs($is_home,1,'',$exclude,0,$toppath,'',\%subdirs);
1.606 raeburn 6548: $select_menus{'author'}->{'default'} = '/';
1.690 ! raeburn 6549: my @ordered = ();
1.606 raeburn 6550: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6551: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6552: push(@ordered,$relpath);
6553: }
6554: $select_menus{'author'}->{'order'} = \@ordered;
1.689 raeburn 6555: $showstdprob = 'block';
1.606 raeburn 6556: } else {
1.689 raeburn 6557: $rolehomes = '<input type="hidden" name="rolehome_author" value="'.$env{'user.home'}.'" />'."\n";
1.606 raeburn 6558: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6559: $select_menus{'author'}->{'default'} = 'switch';
6560: $select_menus{'author'}->{'order'} = ['switch'];
1.689 raeburn 6561: $showstdprob = 'none';
1.606 raeburn 6562: }
6563: }
6564: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6565: ['active'],['ca','aa']);
6566: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
1.689 raeburn 6567: my (%by_roletype,%at_home);
1.606 raeburn 6568: if (keys(%roleshash)) {
6569: foreach my $entry (keys(%roleshash)) {
6570: my ($auname,$audom,$roletype) = split(/:/,$entry);
6571: my $key = $entry;
6572: $key =~ s/:/___/g;
6573: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6574: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6575: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6576: if (grep(/^\Q$rolehome\E$/,@ids)) {
1.689 raeburn 6577: $at_home{$auname.'___'.$audom} = 1;
1.606 raeburn 6578: my $is_home = 1;
6579: my (%subdirs,@ordered);
6580: my $toppath="/priv/$audom/$auname";
1.690 ! raeburn 6581: &Apache::lonnet::recursedirs($is_home,1,'',$exclude,0,$toppath,'',\%subdirs);
1.606 raeburn 6582: $select_menus{$key}->{'default'} = '/';
6583: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6584: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6585: push(@ordered,$relpath);
6586: }
6587: $select_menus{$key}->{'order'} = \@ordered;
6588: } else {
1.689 raeburn 6589: $rolehomes .= '<input type="hidden" name="rolehome_coauthor" value="'.$roletype.'='.$audom.'/'.$auname.'='.$rolehome.'" />'."\n";
1.606 raeburn 6590: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6591: $select_menus{$key}->{'default'} = 'switch';
6592: $select_menus{$key}->{'order'} = ['switch'];
6593: }
6594: $numauthor ++;
6595: }
6596: }
1.631 raeburn 6597: my ($pickdir,$showtitle);
1.606 raeburn 6598: if ($numauthor) {
6599: my @order;
6600: my $defrole;
6601: if ($env{'user.author'}) {
6602: push(@order,'author');
6603: $defrole = 'author';
6604: }
6605: if (keys(%by_roletype)) {
6606: foreach my $possrole ('ca','aa') {
6607: if (ref($by_roletype{$possrole}) eq 'HASH') {
6608: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6609: unless ($defrole) {
6610: $defrole = $author;
1.689 raeburn 6611: if ($at_home{$author}) {
6612: $showstdprob = 'block';
6613: } else {
6614: $showstdprob = 'none';
6615: }
1.606 raeburn 6616: }
6617: push(@order,$author.'___'.$possrole);
6618: }
6619: }
6620: }
6621: }
6622: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6623: if (grep(/^\Q$crshome\E$/,@ids)) {
6624: my $is_home = 1;
6625: my %subdirs;
6626: my $toppath="/priv/$coursedom/$coursenum";
1.690 ! raeburn 6627: &Apache::lonnet::recursedirs($is_home,1,'',$exclude,0,$toppath,'',\%subdirs);
1.606 raeburn 6628: $numcrsdirs = keys(%subdirs);
6629: $select_menus{'course'}->{'default'} = '/';
1.690 ! raeburn 6630: my @ordered = ();
1.606 raeburn 6631: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6632: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6633: push(@ordered,$relpath);
6634: }
6635: $select_menus{'course'}->{'order'} = \@ordered;
6636: } else {
1.689 raeburn 6637: $rolehomes .= '<input type="hidden" name="rolehome_course" value="'.$crshome.'" />'."\n";
1.606 raeburn 6638: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6639: $select_menus{'course'}->{'default'} = 'switch';
6640: $select_menus{'course'}->{'order'} = ['switch'];
6641: }
6642: push(@order,'course');
6643: $pickdir = $lt{'loca'}.
6644: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6645: $defrole,'authorrole','authorpath',
6646: \%select_menus,\@order,'toggleCrsResTitle();',
6647: '','priv').'<br />';
6648: $showtitle = 'none';
6649: } else {
6650: my $is_home;
6651: $showtitle = 'inline';
6652: if (grep(/^\Q$crshome\E$/,@ids)) {
6653: $is_home = 1;
1.689 raeburn 6654: $showstdprob = 'block';
1.606 raeburn 6655: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6656: my $toppath="/priv/$coursedom/$coursenum'}";
6657: my %subdirs;
1.690 ! raeburn 6658: &Apache::lonnet::recursedirs($is_home,1,'',$exclude,0,$toppath,'',\%subdirs);
1.606 raeburn 6659: $numcrsdirs = keys(%subdirs);
6660: if ($numcrsdirs) {
1.689 raeburn 6661: $pickdir .= $lt{'dire'}.' <select name="authorpath">'."\n".
1.606 raeburn 6662: '<option value="/">/</option>'."\n";
6663: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6664: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6665: }
6666: $pickdir .= '</select>';
6667: } else {
6668: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6669: }
1.689 raeburn 6670: } else {
6671: $showstdprob = 'none';
6672: $rolehomes .= '<input type="hidden" name="rolehome_course" value="'.$crshome.'" />'."\n";
6673: my @order;
6674: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6675: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6676: $select_menus{'course'}->{'default'} = 'switch';
6677: $select_menus{'course'}->{'order'} = ['switch'];
6678: push(@order,'course');
1.690 ! raeburn 6679: my $defrole = 'course';
1.689 raeburn 6680: $pickdir = $lt{'loca'}.
6681: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6682: $defrole,'authorrole','authorpath',
6683: \%select_menus,\@order,'toggleCrsResTitle();',
6684: '','priv').'<br />';
6685: $showtitle = 'none';
6686:
1.606 raeburn 6687: }
6688: }
1.689 raeburn 6689: if ($showstdprob eq 'none') {
6690: $showswitch = 'block';
6691: } else {
6692: $showswitch = 'none';
6693: }
1.606 raeburn 6694:
6695: my %seltemplate_menus;
6696: my @files = &Apache::lonhomework::get_template_list('problem');
6697: my @noexamplelink = ('blank.problem','blank.library','script.library');
6698: my $currentcategory = '';
6699: my @ordered = ('');
6700: my %templatehelp;
6701: my $defcategory = '';
6702: my @catorder = ($defcategory);
6703: $seltemplate_menus{$defcategory}->{'order'} = [''];
6704: $seltemplate_menus{$defcategory}->{'text'} = '';
6705: foreach my $file (@files) {
6706: if (ref($file) eq 'ARRAY') {
6707: my ($path,$title,$category,$help) = @{$file};
6708: next if ($title !~ /\S/);
6709: if (&js_escape($category) ne $currentcategory) {
6710: $currentcategory = &js_escape($category);
6711: push(@catorder,&js_escape($currentcategory));
6712: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6713: $seltemplate_menus{$currentcategory}->{'default'} = '';
6714: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6715: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6716: }
6717: if ($path) {
6718: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6719: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6720: if ($help) {
6721: $templatehelp{$path} = $help;
6722: }
6723: }
6724: }
6725: }
6726:
6727: my $templates = $lt{'cate'}.' '.
6728: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6729: $defcategory,'tempcategory','template',
6730: \%seltemplate_menus,\@catorder,
6731: "resize_scrollbox('contentscroll','1','0');",
6732: "toggleExampleText();",'template').'<br />';
6733: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6734: '<span id="newresexample">'.&mt('Example').'<span></a>';
6735: my $crsresform=(<<RESFORM);
6736: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6737: $lt{'stpr'}</a>$help{'Course_Resource'}
6738: <form action="/adm/coursedocs" method="post" name="courseresform">
6739: <fieldset id="crsresform" style="display:none;">
6740: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6741: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6742: <p>
6743: $pickdir
1.689 raeburn 6744: <div id="newstdproblem" style="display:$showstdprob;">
1.606 raeburn 6745: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6746: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6747:
1.611 raeburn 6748: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6749: </span><span id="newsubdir"></span>
6750: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6751: </p>
6752: $lt{'fnam'}
1.611 raeburn 6753: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6754: <p>
6755: <div id="newresource" style="display:$showtitle">
6756: $lt{'addp'}
1.611 raeburn 6757: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6758: $lt{'no'}</label>
1.611 raeburn 6759: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6760: $lt{'yes'}</label>
6761: <span id="newrestitle"></span>
1.611 raeburn 6762: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6763: </div>
6764: </p>
6765: <p>
6766: $lt{'uste'}
1.611 raeburn 6767: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6768: $lt{'no'}</label>
1.611 raeburn 6769: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6770: $lt{'yes'}</label>
6771: <div id="newrestemplate" style="display:none">
6772: $templates
6773: $templatepreview
6774: </div>
6775: </p>
6776: <span class="LC_nobreak">
6777: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6778: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6779: </span>
1.689 raeburn 6780: </div>
6781: <div id="stdprobswitch" style="display:$showswitch;">
6782: $rolehomes
6783: <input type="button" name="switchfornewprob" value="$lt{'swit'}" onclick="switchForProb();" />
6784: </div>
1.606 raeburn 6785: </fieldset>
6786: </form>
6787:
6788: RESFORM
1.534 raeburn 6789:
1.342 ehlerst 6790: my $specialdocumentsform;
1.383 tempelho 6791: my @specialdocumentsforma;
1.451 www 6792: my $gradingform;
6793: my @gradingforma;
6794: my $communityform;
6795: my @communityforma;
1.351 ehlerst 6796: my $newfolderform;
1.390 tempelho 6797: my $newfolderb;
1.342 ehlerst 6798:
1.451 www 6799: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6800:
1.329 droeschl 6801: my $newpageform=(<<NPFORM);
6802: <form action="/adm/coursedocs" method="post" name="newpage">
6803: <input type="hidden" name="folderpath" value="$path" />
6804: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6805: <input type="hidden" name="active" value="ee" />
1.423 onken 6806: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6807: $help{'Adding_Pages'}
1.329 droeschl 6808: </form>
6809: NPFORM
1.390 tempelho 6810:
6811:
1.351 ehlerst 6812: $newfolderform=(<<NFFORM);
1.329 droeschl 6813: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6814: $pathitem
1.329 droeschl 6815: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6816: <input type="hidden" name="active" value="" />
1.422 onken 6817: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6818: </form>
6819: NFFORM
6820:
6821: my $newsylform=(<<NSYLFORM);
6822: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6823: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6824: $pathitem
1.329 droeschl 6825: <input type="hidden" name="importdetail"
6826: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6827: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6828: $help{'Syllabus'}
1.383 tempelho 6829:
1.329 droeschl 6830: </form>
6831: NSYLFORM
1.364 bisitz 6832:
1.329 droeschl 6833: my $newgroupfileform=(<<NGFFORM);
6834: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6835: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6836: $pathitem
1.329 droeschl 6837: <input type="hidden" name="importdetail"
6838: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6839: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6840: $help{'Group Portfolio'}
1.329 droeschl 6841: </form>
6842: NGFFORM
1.672 raeburn 6843: if ($container eq 'page') {
6844: @specialdocumentsforma=(
6845: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6846: );
6847: } else {
6848: @specialdocumentsforma=(
1.421 onken 6849: {'<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 6850: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6851: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6852: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6853: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 6854: );
6855: }
1.451 www 6856: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6857:
1.655 raeburn 6858: my @external = (
6859: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6860: );
1.598 raeburn 6861: if (keys(%ltitools)) {
1.655 raeburn 6862: push(@external,
6863: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6864: );
1.598 raeburn 6865: }
1.655 raeburn 6866: my $externalform = &create_form_ul(&create_list_elements(@external));
6867:
6868: my @importdoc = ();
1.519 raeburn 6869: unless ($container eq 'page') {
6870: push(@importdoc,
6871: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6872: );
6873: }
6874: push(@importdoc,
1.558 raeburn 6875: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6876: );
1.501 raeburn 6877: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6878:
1.451 www 6879: @gradingforma=(
6880: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6881: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6882: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6883: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
1.451 www 6884: );
6885: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6886:
6887: @communityforma=(
6888: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6889: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6890: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6891: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6892: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6893: );
6894: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6895:
1.330 tempelho 6896: my %orderhash = (
1.553 raeburn 6897: 'aa' => ['Upload',$fileuploadform],
6898: 'bb' => ['Import',$importpubform],
1.655 raeburn 6899: 'cc' => ['External',$externalform],
6900: 'dd' => ['Grading',$gradingform],
1.673 raeburn 6901: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 6902: );
1.519 raeburn 6903: unless ($container eq 'page') {
1.434 raeburn 6904: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6905: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 6906: }
6907:
1.341 ehlerst 6908: $hadchanges=0;
1.484 raeburn 6909: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6910: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6911: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6912: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6913: undef($navmap);
1.443 www 6914: if ($error) {
6915: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6916: }
1.639 raeburn 6917: if ($hadchanges) {
6918: unless (&is_hash_old()) {
1.638 raeburn 6919: &mark_hash_old();
6920: }
6921: }
1.341 ehlerst 6922:
1.443 www 6923: &changewarning($r,'');
6924: }
1.458 raeburn 6925: }
1.442 www 6926:
1.443 www 6927: # Supplemental documents start here
6928:
1.329 droeschl 6929: my $folder=$env{'form.folder'};
1.443 www 6930: unless ($supplementalflag) {
1.329 droeschl 6931: $folder='supplemental';
6932: }
1.685 raeburn 6933: if (($folder eq 'supplemental') &&
1.329 droeschl 6934: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6935: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6936: } elsif ($allowed) {
1.356 tempelho 6937: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6938: }
1.508 raeburn 6939: $pathitem = '<input type="hidden" name="folderpath" value="'.
6940: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6941: if ($allowed) {
6942: my $folderseq=
1.504 raeburn 6943: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6944:
6945: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6946: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6947: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6948: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6949: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6950: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6951: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6952: $fileupload
6953: <br />
6954: <br />
6955: <span class="LC_nobreak">
6956: $checkbox
6957: </span>
6958: <br /><br />
6959: $lt{'comment'}:<br />
1.383 tempelho 6960: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6961: <br />
1.508 raeburn 6962: $pathitem
1.329 droeschl 6963: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6964: <input type='submit' value="$lt{'upld'}" />
6965: </form>
1.329 droeschl 6966: SUPDOCFORM
6967:
6968: my $supnewfolderform=(<<SNFFORM);
6969: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6970: <input type="hidden" name="active" value="" />
1.508 raeburn 6971: $pathitem
1.329 droeschl 6972: <input type="hidden" name="importdetail" value="" />
1.423 onken 6973: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6974: $help{'Adding_Folders'}
1.329 droeschl 6975: </form>
6976: SNFFORM
1.383 tempelho 6977:
1.510 raeburn 6978: my $supextform =
6979: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6980: $help{'Adding_External_Resource'},
6981: undef,undef,undef,undef,undef,undef,
6982: $disabled);
1.329 droeschl 6983:
1.598 raeburn 6984: my $supexttoolform =
6985: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6986: $help{'Adding_External_Tool'},
6987: undef,undef,'tool',$coursedom,
1.611 raeburn 6988: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6989:
1.329 droeschl 6990: my $supnewsylform=(<<SNSFORM);
6991: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6992: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6993: $pathitem
1.329 droeschl 6994: <input type="hidden" name="importdetail"
6995: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6996: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6997: $help{'Syllabus'}
6998: </form>
6999: SNSFORM
7000:
7001: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 7002: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 7003: <input type="hidden" name="active" value="ff" />
1.508 raeburn 7004: $pathitem
1.329 droeschl 7005: <input type="hidden" name="importdetail"
7006: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 7007: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 7008: $help{'My Personal Information Page'}
1.329 droeschl 7009: </form>
7010: SNAMFORM
7011:
1.534 raeburn 7012: my $supwebpage;
7013: if ($folder =~ /^supplemental_?(\d*)$/) {
7014: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
7015: if ($1) {
7016: $supwebpage .= $1;
7017: } else {
7018: $supwebpage .= 'default';
7019: }
7020: $supwebpage .= '/new.html';
7021: }
7022: my $supwebpageform =(<<SWEBFORM);
7023: <form action="/adm/coursedocs" method="post" name="supwebpage">
7024: <input type="hidden" name="active" value="cc" />
7025: $pathitem
7026: <input type="hidden" name="importdetail" value="$supwebpage" />
7027: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 7028: $help{'Web_Page'}
1.534 raeburn 7029: </form>
7030: SWEBFORM
7031:
1.333 muellerd 7032:
1.383 tempelho 7033: my @specialdocs = (
1.618 raeburn 7034: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 7035: =>$supnewsylform},
1.611 raeburn 7036: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 7037: =>$supnewaboutmeform},
1.534 raeburn 7038: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
7039:
1.383 tempelho 7040: );
1.655 raeburn 7041: my @supexternal = (
7042: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
7043: =>$supextform});
1.598 raeburn 7044: if (keys(%ltitools)) {
1.655 raeburn 7045: push(@supexternal,
7046: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 7047: =>$supexttoolform});
7048: }
1.655 raeburn 7049: my @supimportdoc = (
1.598 raeburn 7050: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 7051: =>$supupdocform},
1.598 raeburn 7052: );
1.501 raeburn 7053:
7054: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 7055: my %suporderhash = (
1.390 tempelho 7056: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 7057: 'dd' => ['Upload',$supupdocform],
7058: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 7059: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 7060: );
1.443 www 7061: if ($supplementalflag) {
1.682 raeburn 7062: $suppchanges = 0;
7063: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
7064: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
7065: \%ltitools,$canedit,$hostname);
7066: if ($error) {
7067: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
7068: }
7069: if ($suppchanges) {
1.684 raeburn 7070: &Apache::lonnet::update_supp_caches($coursedom,$coursenum);
1.682 raeburn 7071: undef($suppchanges);
7072: }
1.393 raeburn 7073: }
1.443 www 7074: } elsif ($supplementalflag) {
1.458 raeburn 7075: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.682 raeburn 7076: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
7077: $hostname);
1.393 raeburn 7078: if ($error) {
7079: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 7080: }
1.393 raeburn 7081: }
1.389 tempelho 7082:
1.510 raeburn 7083: if ($needs_end) {
7084: $r->print(&endContentScreen());
7085: }
1.383 tempelho 7086:
1.329 droeschl 7087: if ($allowed) {
7088: $r->print('
7089: <form method="post" name="extimport" action="/adm/coursedocs">
7090: <input type="hidden" name="title" />
7091: <input type="hidden" name="url" />
7092: <input type="hidden" name="useform" />
7093: <input type="hidden" name="residx" />
7094: </form>');
7095: }
1.484 raeburn 7096: } elsif ($showdoc) {
1.329 droeschl 7097: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 7098: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 7099: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 7100: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 7101: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 7102: }
7103: }
1.630 raeburn 7104: unless ($noendpage) {
1.606 raeburn 7105: $r->print(&Apache::loncommon::end_page());
7106: }
1.329 droeschl 7107: return OK;
1.364 bisitz 7108: }
1.329 droeschl 7109:
1.440 raeburn 7110: sub embedded_form_elems {
7111: my ($phase,$primaryurl,$newidx) = @_;
7112: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 7113: $newidx =~s /\D+//g;
1.440 raeburn 7114: return <<STATE;
7115: <input type="hidden" name="folderpath" value="$folderpath" />
7116: <input type="hidden" name="cmd" value="upload_embedded" />
7117: <input type="hidden" name="newidx" value="$newidx" />
7118: <input type="hidden" name="phase" value="$phase" />
7119: <input type="hidden" name="primaryurl" value="$primaryurl" />
7120: STATE
7121: }
7122:
7123: sub embedded_destination {
7124: my $folder=$env{'form.folder'};
7125: my $destination = 'docs/';
7126: if ($folder =~ /^supplemental/) {
7127: $destination = 'supplemental/';
7128: }
7129: if (($folder eq 'default') || ($folder eq 'supplemental')) {
7130: $destination .= 'default/';
7131: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
7132: $destination .= $2.'/';
7133: }
1.634 raeburn 7134: my $newidx = $env{'form.newidx'};
7135: $newidx =~s /\D+//g;
7136: if ($newidx) {
7137: $destination .= $newidx;
7138: }
1.440 raeburn 7139: my $dir_root = '/userfiles';
7140: return ($destination,$dir_root);
7141: }
7142:
7143: sub return_to_editor {
7144: my $actionurl = '/adm/coursedocs';
7145: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7146: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7147: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7148: '</a></p>';
7149: }
7150:
1.476 raeburn 7151: sub decompression_info {
7152: my ($destination,$dir_root) = &embedded_destination();
7153: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7154: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7155: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7156: my $container='sequence';
1.480 raeburn 7157: my ($pathitem,$hiddenelem);
1.583 raeburn 7158: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 7159: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 7160: $container='page';
7161: }
1.480 raeburn 7162: unshift(@hiddens,$pathitem);
7163: foreach my $item (@hiddens) {
1.634 raeburn 7164: if ($item eq 'newidx') {
7165: next if ($env{'form.'.$item} =~ /\D/);
7166: }
1.480 raeburn 7167: if ($env{'form.'.$item}) {
7168: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 7169: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 7170: }
1.477 raeburn 7171: }
1.476 raeburn 7172: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7173: $hiddenelem);
7174: }
7175:
7176: sub decompression_phase_one {
7177: my ($dir,$file,$warning,$error,$output);
7178: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7179: &decompression_info();
1.490 raeburn 7180: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 7181: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7182: } else {
7183: my $file = $1;
1.630 raeburn 7184: $output =
1.481 raeburn 7185: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7186: $destination,$dir_root,
7187: $hiddenelem);
7188: if ($env{'form.autoextract_camtasia'}) {
7189: $output .= &remove_archive($docudom,$docuname,$container);
7190: }
1.476 raeburn 7191: }
7192: if ($error) {
7193: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7194: $error.'</p>'."\n";
7195: }
7196: if ($warning) {
7197: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7198: }
7199: return $output;
7200: }
7201:
7202: sub decompression_phase_two {
7203: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7204: &decompression_info();
1.481 raeburn 7205: my $output;
1.480 raeburn 7206: if ($env{'form.archivedelete'}) {
1.481 raeburn 7207: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 7208: }
7209: $output .=
1.481 raeburn 7210: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 7211: $destination,$dir_root,$hiddenelem);
7212: return $output;
7213: }
7214:
1.480 raeburn 7215: sub remove_archive {
7216: my ($docudom,$docuname,$container) = @_;
7217: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 7218: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 7219: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7220: if ($fatal) {
7221: if ($container eq 'page') {
7222: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7223: } else {
7224: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7225: }
1.583 raeburn 7226: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7227: } else {
7228: my $currcmd = $env{'form.cmd'};
7229: my $position = $env{'form.position'};
1.583 raeburn 7230: my $archiveidx = $position;
1.563 raeburn 7231: if ($position > 0) {
1.583 raeburn 7232: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7233: $archiveidx = $position-1;
7234: }
7235: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 7236: my ($title,$url,@rrest) =
1.583 raeburn 7237: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7238: if ($url eq $env{'form.archiveurl'}) {
7239: if (&handle_edit_cmd($docuname,$docudom)) {
7240: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.684 raeburn 7241: if ($suppchanges) {
7242: &Apache::lonnet::update_supp_caches($docudom,$docuname);
7243: undef($suppchanges);
7244: }
1.583 raeburn 7245: if ($fatal) {
7246: if ($container eq 'page') {
7247: $delwarning = &mt('An error occurred updating the contents of the current page.');
7248: } else {
7249: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7250: }
1.480 raeburn 7251: } else {
1.583 raeburn 7252: $delresult = &mt('Archive file removed.');
1.480 raeburn 7253: }
7254: }
1.583 raeburn 7255: } else {
7256: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7257: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7258: }
7259: }
7260: $env{'form.cmd'} = $currcmd;
7261: }
7262: if ($delwarning) {
7263: $output = '<p class="LC_warning">'.
7264: $delwarning.
7265: '</p>';
7266: }
7267: if ($delresult) {
7268: $output .= '<p class="LC_info">'.
7269: $delresult.
7270: '</p>';
7271: }
1.481 raeburn 7272: return $output;
1.480 raeburn 7273: }
7274:
1.484 raeburn 7275: sub generate_admin_menu {
1.611 raeburn 7276: my ($crstype,$canedit) = @_;
1.484 raeburn 7277: my $lc_crstype = lc($crstype);
7278: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7279: my %lt= ( # do not translate here
1.484 raeburn 7280: 'vc' => 'Verify Content',
7281: 'cv' => 'Check/Set Resource Versions',
7282: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7283: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7284: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7285: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7286: );
1.484 raeburn 7287: my ($candump,$dumpurl);
7288: if ($home + $other > 0) {
7289: $candump = 'F';
7290: if ($home) {
7291: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7292: } else {
7293: my @hosts;
7294: foreach my $aurole (keys(%outhash)) {
7295: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7296: push(@hosts,$outhash{$aurole});
1.538 raeburn 7297: }
1.484 raeburn 7298: }
7299: if (@hosts == 1) {
7300: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7301: '&role='.
7302: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7303: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7304: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7305: } else {
7306: $dumpurl = "javascript:choose_switchserver_window()";
7307: }
7308: }
7309: }
7310: my @menu=
7311: ({ categorytitle=>'Administration',
7312: items =>[
7313: { linktext => $lt{'vc'},
7314: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7315: permission => 'F',
1.571 raeburn 7316: help => 'Docs_Verify_Content',
1.484 raeburn 7317: icon => 'verify.png',
7318: linktitle => 'Verify contents can be retrieved/rendered',
7319: },
7320: { linktext => $lt{'cv'},
7321: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7322: permission => 'F',
1.571 raeburn 7323: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7324: icon => 'resversion.png',
7325: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7326: },
7327: { linktext => $lt{'ls'},
7328: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7329: permission => 'F',
7330: #help => '',
7331: icon => 'symbs.png',
7332: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7333: },
1.651 raeburn 7334: { linktext => $lt{'ct'},
7335: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7336: permission => 'F',
7337: help => 'Docs_Short_URLs',
7338: icon => 'shorturls.png',
7339: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7340: },
1.484 raeburn 7341: ]
1.611 raeburn 7342: });
7343: if ($canedit) {
7344: push(@menu,
1.484 raeburn 7345: { categorytitle=>'Export',
7346: items =>[
7347: { linktext => $lt{'imse'},
7348: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7349: permission => 'F',
7350: help => 'Docs_Export_Course_Docs',
7351: icon => 'imsexport.png',
7352: linktitle => $lt{'imse'},
7353: },
7354: { linktext => $lt{'dcd'},
7355: url => $dumpurl,
7356: permission => $candump,
1.571 raeburn 7357: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7358: icon => 'dump.png',
7359: linktitle => $lt{'dcd'},
7360: },
7361: ]
7362: });
1.611 raeburn 7363: }
1.484 raeburn 7364: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7365: '<input type="hidden" id="dummy" />'."\n".
7366: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7367: '</form>';
1.329 droeschl 7368: }
7369:
7370: sub generate_edit_table {
1.538 raeburn 7371: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7372: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7373: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7374: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7375: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7376: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7377: $activetab = $env{'form.active'};
7378: }
1.611 raeburn 7379: unless ($canedit) {
7380: $disabled = ' disabled="disabled"';
7381: }
1.472 raeburn 7382: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7383: my $backtext = &mt('Exit Editor');
1.458 raeburn 7384: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7385: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7386: '<li class="goback">'.
1.546 raeburn 7387: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7388: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7389: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7390: '<li>'.
7391: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7392: &mt('Undo Delete').'</a></li>'."\n";
7393: if ($env{'form.docslog'}) {
7394: $form .= '<li class="active">';
7395: } else {
7396: $form .= '<li>';
7397: }
7398: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7399: &mt('History').'</a></li>'."\n";
7400: if ($env{'form.docslog'}) {
7401: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7402: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7403: }
1.458 raeburn 7404: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7405: if($name ne '00'){
1.371 tempelho 7406: if($activetab eq '' || $activetab ne $name){
7407: $active = '';
7408: }elsif($activetab eq $name){
7409: $active = 'class="active"';
7410: }
1.458 raeburn 7411: $form .= '<li style="float:right" '.$active
1.484 raeburn 7412: .' 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 7413: } else {
1.570 raeburn 7414: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7415:
7416: }
1.329 droeschl 7417: }
1.484 raeburn 7418: $form .= '</ul>'."\n";
7419: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7420:
7421: if ($to_show ne '') {
1.538 raeburn 7422: my $saveform;
7423: if ($need_save) {
7424: my $button = &mt('Make changes');
7425: my $path;
7426: if ($env{'form.folderpath'}) {
7427: $path =
7428: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7429: }
7430: $saveform = <<"END";
7431: <div id="multisave" style="display:none; clear:both;" >
7432: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7433: <input type="hidden" name="folderpath" value="$path" />
7434: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7435: <input type="hidden" name="allhiddenresource" value="" />
7436: <input type="hidden" name="allencrypturl" value="" />
7437: <input type="hidden" name="allrandompick" value="" />
7438: <input type="hidden" name="allrandomorder" value="" />
7439: <input type="hidden" name="changeparms" value="" />
7440: <input type="hidden" name="multiremove" value="" />
7441: <input type="hidden" name="multicut" value="" />
7442: <input type="hidden" name="multicopy" value="" />
7443: <input type="hidden" name="multichange" value="" />
7444: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7445: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7446: </form>
7447: </div>
7448: END
7449: }
7450: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7451: }
1.363 ehlerst 7452: foreach my $field (keys(%orderhash)){
1.390 tempelho 7453: if($field ne '00'){
1.422 onken 7454: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7455: $active = 'style="display: none;float:left"';
1.422 onken 7456: }elsif($activetab eq $field){
1.458 raeburn 7457: $active = 'style="display:block;float:left"';
1.422 onken 7458: }
7459: $form .= '<div id="'.$field.$tid.'"'
7460: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7461: .'</div>'."\n";
1.363 ehlerst 7462: }
7463: }
1.484 raeburn 7464: unless ($env{'form.docslog'}) {
7465: $form .= '</div></div>'."\n";
7466: }
1.329 droeschl 7467: return $form;
7468: }
7469:
7470: sub editing_js {
1.622 raeburn 7471: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7472: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7473: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7474: p_mnf => 'Name of New Folder',
7475: t_mnf => 'New Folder',
7476: p_mnp => 'Name of New Page',
7477: t_mnp => 'New Page',
1.451 www 7478: p_mxu => 'Title for the External Score',
1.349 biermanm 7479: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7480: p_msb => 'Title for the Problem',
7481: p_mdb => 'Title for the Drop Box',
1.336 schafran 7482: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7483: p_mwp => 'Title for Web Page',
1.606 raeburn 7484: p_mnr => 'Title for the Resource',
1.348 weissno 7485: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7486: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7487: p_mab_alrt1 => 'Not a valid user:domain',
7488: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7489: p_chn => 'New Title',
7490: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7491: p_rmr2a => 'Remove',
7492: p_rmr2b => '?',
7493: p_rmr3a => 'Remove those',
7494: p_rmr3b => 'items?',
7495: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7496: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7497: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7498: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7499: p_ctr2a => 'Cut',
7500: p_ctr2b => '?',
7501: p_ctr3a => 'Cut those',
7502: p_ctr3b => 'items?',
1.633 raeburn 7503: setal => 'Enter a (unique) alias',
7504: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7505: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7506: imsfile => 'You must choose an IMS package for import',
7507: imscms => 'You must select which Course Management System was the source of the IMS package',
7508: invurl => 'Invalid URL',
7509: titbl => 'Title is blank',
1.538 raeburn 7510: more => '(More ...)',
7511: less => '(Less ...)',
1.543 raeburn 7512: noor => 'No actions selected or changes to settings specified.',
7513: noch => 'No changes to settings specified.',
7514: noac => 'No actions selected.',
1.606 raeburn 7515: nofi => 'No file selected',
7516: tinc => 'Title in course',
7517: sunm => 'Sub-directory name',
1.618 raeburn 7518: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7519: );
1.594 damieng 7520: &js_escape(\%js_lt);
1.433 raeburn 7521: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7522: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7523: my $main_container_page;
1.519 raeburn 7524: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7525: $main_container_page = 1;
1.434 raeburn 7526: }
1.617 raeburn 7527: my $backtourl;
7528: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7529: my $toplevelsupp = &supplemental_base();
1.690 ! raeburn 7530: my $showfile_js = &Apache::loncommon::show_crsfiles_js();
1.530 raeburn 7531: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7532: my $caller = $1;
1.525 raeburn 7533: if ($caller =~ /^supplemental/) {
7534: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7535: } else {
7536: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7537: $res = &Apache::lonnet::clutter($res);
7538: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7539: my ($url,$anchor);
7540: if ($res =~ /^([^#]+)#([^#]+)$/) {
7541: $url = $1;
7542: $anchor = $2;
7543: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7544: $caller = $1.&escape('#').$anchor;
7545: }
1.614 raeburn 7546: } else {
7547: $url = $res;
1.609 raeburn 7548: }
1.640 raeburn 7549: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7550: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7551: $backtourl .= '?navmap=1';
7552: } else {
7553: $backtourl .= '?symb='.
7554: &HTML::Entities::encode($caller,'<>&"');
7555: }
1.622 raeburn 7556: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7557: if (($ENV{'SERVER_PORT'} == 443) &&
7558: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.678 raeburn 7559: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.657 raeburn 7560: if ($hostname ne '') {
7561: $backtourl = 'http://'.$hostname.$backtourl;
7562: }
7563: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7564: }
7565: }
1.623 raeburn 7566: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7567: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.678 raeburn 7568: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.658 raeburn 7569: if ($hostname ne '') {
7570: $backtourl = 'http://'.$hostname.$backtourl;
7571: }
7572: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7573: }
1.623 raeburn 7574: }
1.622 raeburn 7575: }
1.609 raeburn 7576: if ($anchor ne '') {
7577: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7578: }
1.590 raeburn 7579: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7580: } else {
7581: $backtourl = '/adm/navmaps';
1.525 raeburn 7582: }
7583: }
7584: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7585: $backtourl = '/adm/menu';
7586: } elsif ($supplementalflag) {
1.682 raeburn 7587: if (($env{'request.role.adv'}) ||
7588: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7589: $backtourl = '/adm/supplemental';
7590: } else {
7591: $backtourl = '/adm/navmaps';
7592: }
1.525 raeburn 7593: } else {
7594: $backtourl = '/adm/navmaps';
1.472 raeburn 7595: }
7596:
1.655 raeburn 7597: my $fieldsets = "'doc'";
1.519 raeburn 7598: unless ($main_container_page) {
7599: $fieldsets .=",'ims'";
7600: }
1.655 raeburn 7601: my $extfieldsets = "'ext'";
7602: if ($posslti) {
7603: $extfieldsets .= ",'tool'";
7604: }
1.501 raeburn 7605: if ($supplementalflag) {
1.655 raeburn 7606: $fieldsets = "'suppdoc'";
7607: $extfieldsets = "'suppext'";
1.600 raeburn 7608: if ($posslti) {
1.655 raeburn 7609: $extfieldsets .= ",'supptool'";
1.600 raeburn 7610: }
1.501 raeburn 7611: }
1.655 raeburn 7612:
1.611 raeburn 7613: my $jsmakefunctions;
7614: if ($canedit) {
7615: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7616: function makenewfolder(targetform,folderseq) {
1.594 damieng 7617: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7618: if (foldername) {
1.676 raeburn 7619: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 7620: targetform.submit();
7621: }
7622: }
7623:
7624: function makenewpage(targetform,folderseq) {
1.594 damieng 7625: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7626: if (pagename) {
1.676 raeburn 7627: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 7628: targetform.submit();
7629: }
7630: }
7631:
7632: function makeexamupload() {
1.594 damieng 7633: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7634: if (title) {
1.329 droeschl 7635: this.document.forms.newexamupload.importdetail.value=
1.676 raeburn 7636: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 7637: this.document.forms.newexamupload.submit();
7638: }
7639: }
7640:
7641: function makesmppage() {
1.594 damieng 7642: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7643: if (title) {
1.329 droeschl 7644: this.document.forms.newsmppg.importdetail.value=
1.676 raeburn 7645: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7646: this.document.forms.newsmppg.submit();
7647: }
7648: }
7649:
1.534 raeburn 7650: function makewebpage(type) {
1.594 damieng 7651: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7652: var formname;
7653: if (type == 'supp') {
7654: formname = this.document.forms.supwebpage;
7655: } else {
7656: formname = this.document.forms.newwebpage;
7657: }
7658: if (title) {
7659: var webpage = formname.importdetail.value;
1.675 raeburn 7660: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7661: formname.submit();
7662: }
7663: }
7664:
1.329 droeschl 7665: function makesmpproblem() {
1.594 damieng 7666: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7667: if (title) {
1.329 droeschl 7668: this.document.forms.newsmpproblem.importdetail.value=
1.676 raeburn 7669: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 7670: this.document.forms.newsmpproblem.submit();
7671: }
7672: }
7673:
7674: function makedropbox() {
1.594 damieng 7675: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7676: if (title) {
1.329 droeschl 7677: this.document.forms.newdropbox.importdetail.value=
1.676 raeburn 7678: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 7679: this.document.forms.newdropbox.submit();
7680: }
7681: }
7682:
7683: function makebulboard() {
1.594 damieng 7684: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7685: if (title) {
7686: this.document.forms.newbul.importdetail.value=
1.676 raeburn 7687: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7688: this.document.forms.newbul.submit();
7689: }
7690: }
7691:
7692: function makeabout() {
1.594 damieng 7693: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7694: if (user) {
7695: var comp=new Array();
7696: comp=user.split(':');
7697: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7698: if ((comp[0]) && (comp[1])) {
7699: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7700: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7701: this.document.forms.newaboutsomeone.submit();
7702: } else {
7703: alert("$js_lt{'p_mab_alrt1'}");
7704: }
7705: } else {
7706: alert("$js_lt{'p_mab_alrt2'}");
7707: }
7708: }
7709: }
7710:
7711: function makenew(targetform) {
7712: targetform.submit();
7713: }
7714:
7715: function changename(folderpath,index,oldtitle) {
7716: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7717: if (title) {
7718: this.document.forms.renameform.markcopy.value='';
7719: this.document.forms.renameform.title.value=title;
7720: this.document.forms.renameform.cmd.value='rename_'+index;
7721: this.document.forms.renameform.folderpath.value=folderpath;
7722: this.document.forms.renameform.submit();
7723: }
7724: }
7725:
1.633 raeburn 7726: function setalias(folderpath,index) {
7727: var alias = prompt('$js_lt{"setal"}');
7728: if ((alias != null) && (alias != '')) {
7729: this.document.forms.aliasform.alias.value=alias;
7730: this.document.forms.aliasform.cmd.value='setalias_'+index;
7731: this.document.forms.aliasform.folderpath.value=folderpath;
7732: this.document.forms.aliasform.submit();
7733: }
7734: }
7735:
7736: function delalias(folderpath,index) {
7737: if (confirm('$js_lt{"delal"}')) {
7738: this.document.forms.aliasform.cmd.value='delalias_'+index;
7739: this.document.forms.aliasform.folderpath.value=folderpath;
7740: this.document.forms.aliasform.submit();
7741: }
7742: }
7743:
1.611 raeburn 7744: ENDNEWSCRIPT
7745: } else {
7746: $jsmakefunctions = <<ENDNEWSCRIPT;
7747:
7748: function makenewfolder() {
7749: alert("$js_lt{'edri'}");
7750: }
7751:
7752: function makenewpage() {
7753: alert("$js_lt{'edri'}");
7754: }
7755:
7756: function makeexamupload() {
7757: alert("$js_lt{'edri'}");
7758: }
7759:
7760: function makesmppage() {
7761: alert("$js_lt{'edri'}");
7762: }
7763:
7764: function makewebpage(type) {
7765: alert("$js_lt{'edri'}");
7766: }
7767:
7768: function makesmpproblem() {
7769: alert("$js_lt{'edri'}");
7770: }
7771:
7772: function makedropbox() {
7773: alert("$js_lt{'edri'}");
7774: }
7775:
7776: function makebulboard() {
7777: alert("$js_lt{'edri'}");
7778: }
7779:
7780: function makeabout() {
7781: alert("$js_lt{'edri'}");
7782: }
7783:
7784: function changename() {
7785: alert("$js_lt{'edri'}");
7786: }
7787:
1.633 raeburn 7788: function setalias() {
7789: alert("$js_lt{'edri'}");
7790: }
7791:
7792: function delalias() {
7793: alert("$js_lt{'edri'}");
7794: }
7795:
1.611 raeburn 7796: function makenew() {
7797: alert("$js_lt{'edri'}");
7798: }
7799:
7800: function groupimport() {
7801: alert("$js_lt{'edri'}");
1.335 ehlerst 7802: }
1.611 raeburn 7803:
7804: function groupsearch() {
7805: alert("$js_lt{'edri'}");
1.335 ehlerst 7806: }
1.611 raeburn 7807:
7808: function groupopen(url,recover) {
7809: var options="scrollbars=1,resizable=1,menubar=0";
7810: idxflag=1;
7811: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7812: idx.focus();
1.329 droeschl 7813: }
7814:
1.611 raeburn 7815: ENDNEWSCRIPT
7816:
7817: }
7818: return <<ENDSCRIPT;
7819:
7820: $jsmakefunctions
7821:
1.501 raeburn 7822: function toggleUpload(caller) {
7823: var blocks = Array($fieldsets);
7824: for (var i=0; i<blocks.length; i++) {
7825: var disp = 'none';
7826: if (caller == blocks[i]) {
7827: var curr = document.getElementById('upload'+caller+'form').style.display;
7828: if (curr == 'none') {
7829: disp='block';
7830: }
7831: }
7832: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7833: }
7834: resize_scrollbox('contentscroll','1','1');
7835: return;
7836: }
7837:
7838: function toggleExternal(caller) {
7839: var blocks = Array($extfieldsets);
7840: for (var i=0; i<blocks.length; i++) {
7841: var disp = 'none';
7842: if (caller == blocks[i]) {
7843: var curr = document.getElementById('external'+caller+'form').style.display;
7844: if (curr == 'none') {
7845: disp='block';
7846: }
7847: }
7848: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7849: if ((caller == 'tool') || (caller == 'supptool')) {
7850: if (disp == 'block') {
1.655 raeburn 7851: if (document.getElementById('LC_exttoolid')) {
7852: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7853: var suppflag = 0;
7854: if (caller == 'supptool') {
7855: suppflag = 1;
7856: }
7857: currForm = document.getElementById('new'+caller);
1.655 raeburn 7858: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7859: }
7860: }
7861: }
1.501 raeburn 7862: }
1.502 raeburn 7863: resize_scrollbox('contentscroll','1','1');
7864: return;
7865: }
7866:
1.514 raeburn 7867: function toggleMap(caller) {
1.502 raeburn 7868: var disp = 'none';
1.510 raeburn 7869: if (document.getElementById('importmapform')) {
1.514 raeburn 7870: if (caller == 'map') {
7871: var curr = document.getElementById('importmapform').style.display;
7872: if (curr == 'none') {
7873: disp='block';
7874: }
1.510 raeburn 7875: }
7876: document.getElementById('importmapform').style.display=disp;
7877: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7878: }
1.501 raeburn 7879: return;
1.329 droeschl 7880: }
7881:
1.606 raeburn 7882: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7883: var disp = 'none';
7884: if (document.getElementById('crsresform')) {
7885: if (caller == 'res') {
7886: var curr = document.getElementById('crsresform').style.display;
7887: if (curr == 'none') {
7888: disp='block';
7889: numauthor = parseInt(numauthorrole);
7890: if (numauthor > 0) {
7891: document.courseresform.authorrole.selectedIndex = 0;
7892: select1priv_changed();
7893: document.courseresform.authorpath.selectedIndex = 0;
7894: document.courseresform.newresourceadd.selectedIndex = 0;
7895: toggleNewInCourse(document.courseresform);
7896: if (document.getElementById('newresource')) {
7897: document.getElementById('newresource').style.display = 'none';
7898: }
7899: } else {
7900: if (numcrsdirs) {
7901: document.courseresform.authorpath.selectedIndex = 0;
7902: }
7903: }
7904: if (document.courseresform.newresusetemp.length) {
7905: document.courseresform.newresusetemp[0].checked = true;
7906: toggleWithTemplate(document.courseresform);
7907: }
7908: document.courseresform.newresourcename.value = '';
7909: }
7910: }
7911: if (document.courseresform.newsubdir.length) {
7912: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7913: if (document.courseresform.newsubdir[j].value == 0) {
7914: document.courseresform.newsubdir[j].checked = true;
7915: }
7916: break;
7917: }
7918: if (document.getElementById('newsubdirname')) {
7919: document.getElementById('newsubdirname').type = "hidden";
7920: document.getElementById('newsubdirname').value = "";
7921: }
7922: if (document.getElementById('newsubdir')) {
7923: document.getElementById('newsubdir').innerHTML = "";
7924: }
7925: }
7926: document.getElementById('crsresform').style.display=disp;
7927: resize_scrollbox('contentscroll','1','0');
7928: }
7929: return;
7930: }
7931:
7932: function toggleNewsubdir(form) {
7933: if (form.newsubdir.length) {
7934: for (var j=0; j<form.newsubdir.length; j++) {
7935: if (form.newsubdir[j].checked) {
7936: if (document.getElementById('newsubdirname')) {
7937: if (form.newsubdir[j].value == '1') {
7938: document.getElementById('newsubdirname').type = "text";
7939: if (document.getElementById('newsubdir')) {
7940: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7941: }
7942: } else {
7943: document.getElementById('newsubdirname').type = "hidden";
7944: document.getElementById('newsubdirname').value = "";
7945: document.getElementById('newsubdir').innerHTML = "";
7946: }
7947: }
7948: break;
7949: }
7950: }
7951: }
7952: }
7953:
7954: function toggleCrsResTitle() {
7955: if (document.getElementById('newresource')) {
7956: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7957: document.getElementById('newresource').style.display = 'inline';
7958: document.courseresform.newresourceadd[0].checked = true;
7959: toggleNewInCourse(document.courseresform);
7960: } else {
7961: document.getElementById('newresource').style.display = 'none';
7962: }
1.689 raeburn 7963: }
7964: if (document.getElementById('newstdproblem')) {
7965: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
7966: document.getElementById('newstdproblem').style.display = 'none';
7967: if (document.getElementById('stdprobswitch')) {
7968: document.getElementById('stdprobswitch').style.display = 'block';
7969: }
7970: } else {
7971: document.getElementById('newstdproblem').style.display = 'block';
7972: if (document.getElementById('stdprobswitch')) {
7973: document.getElementById('stdprobswitch').style.display = 'none';
7974: }
7975: }
7976: }
1.606 raeburn 7977: }
7978:
7979: function toggleNewInCourse(form) {
7980: if (form.newresourceadd.length) {
7981: for (var i=0; i<form.newresourceadd.length; i++) {
7982: if (form.newresourceadd[i].checked) {
7983: if (document.getElementById('newresourcetitle')) {
7984: if (form.newresourceadd[i].value == '1') {
7985: document.getElementById('newresourcetitle').type = 'text';
7986: if (document.getElementById('newrestitle')) {
7987: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7988: }
7989: } else {
7990: document.getElementById('newresourcetitle').type = 'hidden';
7991: document.getElementById('newresourcetitle').value = '';
7992: if (document.getElementById('newrestitle')) {
7993: document.getElementById('newrestitle').innerHTML = '';
7994: }
7995: }
7996: }
7997: break;
7998: }
7999: }
8000: }
8001: }
8002:
8003: function toggleWithTemplate(form) {
8004: if (form.newresusetemp.length) {
8005: for (var i=0; i<form.newresusetemp.length; i++) {
8006: if (form.newresusetemp[i].checked) {
8007: if (document.getElementById('newrestemplate')) {
8008: if (form.newresusetemp[i].value == '1') {
8009: document.getElementById('newrestemplate').style.display = 'inline';
8010: toggleExampleText();
8011: } else {
8012: form.tempcategory.selectedIndex = 0;
8013: select1template_changed();
8014: document.getElementById('newrestemplate').style.display = 'none';
8015: }
8016: }
8017: }
8018: }
8019: }
8020: }
8021:
8022: function toggleExampleText() {
8023: if (document.getElementById('newresexample')) {
8024: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8025: if (url == '') {
8026: document.getElementById('newresexample').style.fontWeight = 'normal';
8027: } else {
8028: document.getElementById('newresexample').style.fontWeight = 'bold';
8029: }
8030: }
8031: }
8032:
8033: function getExample(width,height,scrolling,transparency) {
8034: var url;
8035: if (document.courseresform.newresusetemp.length) {
8036: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
8037: if (document.courseresform.newresusetemp[i].checked) {
8038: if (document.courseresform.newresusetemp[i].value == '1') {
8039: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
8040: if (url == '') {
8041: alert('Pick a category and template');
8042: } else {
8043: url = url.replace("$londocroot","");
8044: url += '?inhibitmenu=yes';
8045: }
8046: }
8047: break;
8048: }
8049: }
8050: }
8051: if (url != '') {
8052: openMyModal(url,width,height,scrolling,transparency,'');
8053: }
8054: }
8055:
1.690 ! raeburn 8056: function toggleImportCrsres(caller) {
1.606 raeburn 8057: var disp = 'none';
8058: if (document.getElementById('importcrsresform')) {
8059: if (caller == 'res') {
8060: var curr = document.getElementById('importcrsresform').style.display;
8061: if (curr == 'none') {
8062: disp='block';
1.690 ! raeburn 8063: populateCrsSelects(document.crsresimportform,'coursepath','coursefile',1,'',1,0,1,1);
1.606 raeburn 8064: }
8065: }
8066: document.getElementById('importcrsresform').style.display=disp;
8067: resize_scrollbox('contentscroll','1','0');
8068: }
8069: return;
8070: }
8071:
1.690 ! raeburn 8072: $showfile_js
! 8073:
1.689 raeburn 8074: function switchForProb() {
8075: if (document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value == 'switch') {
8076: var url = '/adm/switchserver?otherserver=';
8077: var newhostid = '';
8078: var role = '';
8079: var selloc = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8080: if (selloc == 'author') {
8081: newhostid = document.courseresform.rolehome_author.value;
8082: role = "au./&js_escape($env{'user.domain'})/";
8083: } else if (selloc == 'course') {
8084: newhostid = document.courseresform.rolehome_course.value;
8085: role = "&js_escape($env{'request.role'})";
8086: } else {
8087: var items = new Array();
8088: items = selloc.split('___');
8089: var len = document.courseresform.rolehome_coauthor.length;
8090: if (null == len) {
8091: var currval = document.courseresform.rolehome_coauthor.value;
8092: if (null != currval) {
8093: var info = new Array();
8094: info = currval.split('=');
8095: newhostid = info[2];
8096: role = info[0]+'./'+info[1];
8097: }
8098: } else {
8099: for (var i=0; i<len; i++) {
8100: var currval = document.courseresform.rolehome_coauthor[i].value;
8101: if (null != currval) {
8102: var info = new Array();
8103: info = currval.split('=');
8104: if ((info[1] == items[1]+'/'+items[0]) && (info[0] == items[2])) {
8105: newhostid = info[2];
8106: role = info[0]+'./'+info[1];
8107: break;
8108: }
8109: }
8110: }
8111: }
8112: }
8113: if (newhostid != '') {
8114: url += newhostid;
8115: if (role != '') {
8116: url += '&role='+role;
8117: }
8118: document.location.href = url;
8119: }
8120: }
8121: return;
8122: }
8123:
1.501 raeburn 8124: function makeims(imsform) {
8125: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 8126: alert("$js_lt{'imsfile'}");
1.501 raeburn 8127: return;
8128: }
8129: if (imsform.source.selectedIndex == 0) {
1.594 damieng 8130: alert("$js_lt{'imscms'}");
1.501 raeburn 8131: return;
8132: }
8133: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
8134: imsform.submit();
8135: }
8136:
1.478 raeburn 8137: function updatePick(targetform,index,caller) {
1.537 raeburn 8138: var pickitem;
8139: var picknumitem;
8140: var picknumtext;
8141: if (index == 'all') {
8142: pickitem = document.getElementById('randompickall');
8143: picknumitem = document.getElementById('rpicknumall');
8144: picknumtext = document.getElementById('rpicktextall');
8145: } else {
8146: pickitem = document.getElementById('randompick_'+index);
8147: picknumitem = document.getElementById('rpicknum_'+index);
8148: picknumtext = document.getElementById('randompicknum_'+index);
8149: }
1.478 raeburn 8150: if (pickitem.checked) {
1.594 damieng 8151: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 8152: if (picknum == '' || picknum == null) {
8153: if (caller == 'check') {
8154: pickitem.checked=false;
1.537 raeburn 8155: if (index == 'all') {
8156: picknumtext.innerHTML = '';
8157: if (caller == 'link') {
8158: propagateState(targetform,'rpicknum');
8159: }
8160: } else {
1.538 raeburn 8161: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8162: }
1.478 raeburn 8163: }
8164: } else {
8165: picknum.toString();
8166: var regexdigit=/^\\d+\$/;
8167: if (regexdigit.test(picknum)) {
8168: picknumitem.value = picknum;
1.537 raeburn 8169: if (index == 'all') {
1.538 raeburn 8170: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 8171: if (caller == 'link') {
8172: propagateState(targetform,'rpicknum');
8173: }
8174: } else {
8175: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 8176: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8177: }
1.478 raeburn 8178: } else {
8179: if (caller == 'check') {
1.537 raeburn 8180: if (index == 'all') {
8181: picknumtext.innerHTML = '';
8182: if (caller == 'link') {
8183: propagateState(targetform,'rpicknum');
8184: }
8185: } else {
8186: pickitem.checked=false;
1.538 raeburn 8187: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8188: }
1.478 raeburn 8189: }
8190: return;
8191: }
8192: }
8193: } else {
1.537 raeburn 8194: picknumitem.value = '';
8195: picknumtext.innerHTML = '';
8196: if (index == 'all') {
8197: if (caller == 'link') {
8198: propagateState(targetform,'rpicknum');
8199: }
8200: } else {
1.538 raeburn 8201: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 8202: }
8203: }
8204: }
8205:
8206: function propagateState(form,param) {
8207: if (document.getElementById(param+'all')) {
8208: var setcheck = 0;
8209: var rpick = 0;
8210: if (param == 'rpicknum') {
8211: if (document.getElementById('randompickall')) {
8212: if (document.getElementById('randompickall').checked) {
8213: if (document.getElementById('rpicknumall')) {
8214: rpick = document.getElementById('rpicknumall').value;
8215: }
8216: }
8217: }
8218: } else {
8219: if (document.getElementById(param+'all').checked) {
8220: setcheck = 1;
8221: }
8222: }
1.538 raeburn 8223: var allidxlist;
8224: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8225: if (document.getElementById('all'+param+'idx')) {
8226: allidxlist = document.getElementById('all'+param+'idx').value;
8227: }
8228: var actions = new Array ('remove','cut','copy');
8229: for (var i=0; i<actions.length; i++) {
8230: if (actions[i] != param) {
8231: if (document.getElementById(actions[i]+'all')) {
8232: document.getElementById(actions[i]+'all').checked = false;
8233: }
8234: }
8235: }
8236: }
1.537 raeburn 8237: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 8238: allidxlist = form.allidx.value;
8239: }
8240: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8241: allidxlist = form.allmapidx.value;
8242: }
8243: if ((allidxlist != '') && (allidxlist != null)) {
8244: var allidxs = allidxlist.split(',');
8245: if (allidxs.length > 1) {
8246: for (var i=0; i<allidxs.length; i++) {
8247: if (document.getElementById(param+'_'+allidxs[i])) {
8248: if (param == 'rpicknum') {
8249: if (document.getElementById('randompick_'+allidxs[i])) {
8250: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8251: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8252: if (rpick > 0) {
8253: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8254: } else {
8255: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8256: }
8257: }
8258: }
8259: } else {
1.537 raeburn 8260: if (setcheck == 1) {
8261: document.getElementById(param+'_'+allidxs[i]).checked = true;
8262: } else {
8263: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 8264: if (param == 'randompick') {
8265: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8266: }
1.537 raeburn 8267: }
8268: }
8269: }
8270: }
1.538 raeburn 8271: if (setcheck == 1) {
8272: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8273: var actions = new Array('copy','cut','remove');
8274: for (var i=0; i<actions.length; i++) {
8275: var otheractions;
8276: var otheridxs;
8277: if (actions[i] === param) {
8278: continue;
8279: } else {
8280: if (document.getElementById('all'+actions[i]+'idx')) {
8281: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8282: otheridxs = otheractions.split(',');
8283: if (otheridxs.length > 1) {
8284: for (var j=0; j<otheridxs.length; j++) {
8285: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8286: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8287: }
1.537 raeburn 8288: }
8289: }
8290: }
1.538 raeburn 8291: }
8292: }
8293: }
8294: }
8295: }
8296: }
8297: }
8298: return;
8299: }
8300:
1.603 raeburn 8301: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 8302: var canedit = '$canedit';
8303: if (canedit == '') {
8304: alert("$js_lt{'edri'}");
8305: return;
8306: }
1.539 raeburn 8307: var dosettings;
8308: var doaction;
1.538 raeburn 8309: var control = document.togglemultsettings;
8310: if (context == 'actions') {
8311: control = document.togglemultactions;
1.539 raeburn 8312: doaction = 1;
8313: } else {
8314: dosettings = 1;
1.538 raeburn 8315: }
1.539 raeburn 8316: if (control) {
8317: if (control.showmultpick.length) {
8318: for (var i=0; i<control.showmultpick.length; i++) {
8319: if (control.showmultpick[i].checked) {
8320: if (control.showmultpick[i].value == 1) {
8321: if (context == 'settings') {
8322: dosettings = 0;
8323: } else {
8324: doaction = 0;
1.538 raeburn 8325: }
8326: }
8327: }
1.537 raeburn 8328: }
8329: }
1.539 raeburn 8330: }
8331: if (context == 'settings') {
8332: if (dosettings == 1) {
1.538 raeburn 8333: targetform.changeparms.value=param;
8334: targetform.submit();
8335: }
1.537 raeburn 8336: }
1.539 raeburn 8337: if (context == 'actions') {
8338: if (doaction == 1) {
8339: targetform.cmd.value=param+'_'+index;
8340: targetform.folderpath.value=folderpath;
8341: targetform.markcopy.value=idx+':'+param;
8342: targetform.copyfolder.value=folder+'.'+container;
8343: if (param == 'remove') {
1.603 raeburn 8344: var doremove = 0;
8345: if (skip_confirm) {
8346: if (confirm_removal) {
8347: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8348: doremove = 1;
8349: }
8350: } else {
8351: doremove = 1;
8352: }
8353: } else {
8354: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8355: doremove = 1;
8356: }
8357: }
8358: if (doremove) {
1.539 raeburn 8359: targetform.markcopy.value='';
8360: targetform.copyfolder.value='';
8361: targetform.submit();
8362: }
8363: }
8364: if (param == 'cut') {
1.594 damieng 8365: 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 8366: targetform.submit();
8367: return;
8368: }
8369: }
8370: if (param == 'copy') {
8371: targetform.submit();
8372: return;
8373: }
8374: targetform.markcopy.value='';
8375: targetform.copyfolder.value='';
8376: targetform.cmd.value='';
8377: targetform.folderpath.value='';
8378: return;
8379: } else {
8380: if (document.getElementById(param+'_'+idx)) {
8381: item = document.getElementById(param+'_'+idx);
8382: if (item.type == 'checkbox') {
8383: if (item.checked) {
8384: item.checked = false;
8385: } else {
8386: item.checked = true;
8387: singleCheck(item,idx,param);
8388: }
8389: }
8390: }
8391: }
8392: }
1.537 raeburn 8393: return;
8394: }
8395:
1.538 raeburn 8396: function singleCheck(caller,idx,action) {
8397: actions = new Array('cut','copy','remove');
8398: if (caller.checked) {
8399: for (var i=0; i<actions.length; i++) {
8400: if (actions[i] != action) {
8401: if (document.getElementById(actions[i]+'_'+idx)) {
8402: if (document.getElementById(actions[i]+'_'+idx).checked) {
8403: document.getElementById(actions[i]+'_'+idx).checked = false;
8404: }
1.537 raeburn 8405: }
8406: }
8407: }
1.478 raeburn 8408: }
1.537 raeburn 8409: return;
1.478 raeburn 8410: }
8411:
1.334 muellerd 8412: function unselectInactive(nav) {
1.335 ehlerst 8413: currentNav = document.getElementById(nav);
8414: currentLis = currentNav.getElementsByTagName('LI');
8415: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8416: if (currentLis[i].className == 'goback') {
8417: currentLis[i].className = 'goback';
8418: } else {
8419: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8420: currentLis[i].className = 'right';
1.472 raeburn 8421: } else {
1.374 tempelho 8422: currentLis[i].className = 'i';
1.472 raeburn 8423: }
8424: }
1.335 ehlerst 8425: }
1.332 tempelho 8426: }
8427:
1.334 muellerd 8428: function hideAll(current, nav, data) {
1.335 ehlerst 8429: unselectInactive(nav);
1.570 raeburn 8430: if (current) {
8431: if (current.className == 'right'){
8432: current.className = 'right active'
8433: } else {
8434: current.className = 'active';
8435: }
1.374 tempelho 8436: }
1.335 ehlerst 8437: currentData = document.getElementById(data);
8438: currentDivs = currentData.getElementsByTagName('DIV');
8439: for (i = 0; i < currentDivs.length; i++) {
8440: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8441: currentDivs[i].style.display = 'none';
1.330 tempelho 8442: }
8443: }
1.335 ehlerst 8444: }
1.330 tempelho 8445:
1.374 tempelho 8446: function openTabs(pageId) {
8447: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8448: if(tabnav.length > 2 ){
1.389 tempelho 8449: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8450: currentLis = currentNav.getElementsByTagName('LI');
8451: for(i = 0; i< currentLis.length; i++){
8452: if(currentLis[i].className == 'active') {
1.375 tempelho 8453: funcString = currentLis[i].onclick.toString();
8454: tab = funcString.split('"');
1.420 onken 8455: if(tab.length < 2) {
8456: tab = funcString.split("'");
8457: }
1.375 tempelho 8458: currentData = document.getElementById(tab[1]);
8459: currentData.style.display = 'block';
1.374 tempelho 8460: }
8461: }
8462: }
8463: }
8464:
1.334 muellerd 8465: function showPage(current, pageId, nav, data) {
1.570 raeburn 8466: currstate = current.className;
1.334 muellerd 8467: hideAll(current, nav, data);
1.375 tempelho 8468: openTabs(pageId);
1.334 muellerd 8469: unselectInactive(nav);
1.570 raeburn 8470: if ((currstate == 'active') || (currstate == 'right active')) {
8471: if (currstate == 'active') {
8472: current.className = '';
8473: } else {
8474: current.className = 'right';
8475: }
8476: activeTab = '';
1.656 raeburn 8477: toggleExternal();
1.570 raeburn 8478: toggleUpload();
8479: toggleMap();
1.606 raeburn 8480: toggleCrsRes();
8481: toggleImportCrsres();
1.570 raeburn 8482: resize_scrollbox('contentscroll','1','0');
8483: return;
8484: } else {
8485: current.className = 'active';
8486: }
1.330 tempelho 8487: currentData = document.getElementById(pageId);
8488: currentData.style.display = 'block';
1.458 raeburn 8489: activeTab = pageId;
1.656 raeburn 8490: toggleExternal();
1.501 raeburn 8491: toggleUpload();
1.503 raeburn 8492: toggleMap();
1.606 raeburn 8493: toggleCrsRes();
8494: toggleImportCrsres();
1.433 raeburn 8495: if (nav == 'mainnav') {
8496: var storedpath = "$docs_folderpath";
1.434 raeburn 8497: var storedpage = "$main_container_page";
1.433 raeburn 8498: var reg = new RegExp("^supplemental");
8499: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8500: if (storedpage == 1) {
8501: document.simpleedit.folderpath.value = '';
8502: document.uploaddocument.folderpath.value = '';
8503: } else {
8504: if (reg.test(storedpath)) {
8505: document.simpleedit.folderpath.value = '$toplevelmain';
8506: document.uploaddocument.folderpath.value = '$toplevelmain';
8507: document.newext.folderpath.value = '$toplevelmain';
8508: } else {
8509: document.simpleedit.folderpath.value = storedpath;
8510: document.uploaddocument.folderpath.value = storedpath;
8511: document.newext.folderpath.value = storedpath;
8512: }
1.433 raeburn 8513: }
8514: } else {
1.434 raeburn 8515: if (reg.test(storedpath)) {
8516: document.simpleedit.folderpath.value = storedpath;
8517: document.supuploaddocument.folderpath.value = storedpath;
8518: document.supnewext.folderpath.value = storedpath;
8519: } else {
1.433 raeburn 8520: document.simpleedit.folderpath.value = '$toplevelsupp';
8521: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8522: document.supnewext.folderpath.value = '$toplevelsupp';
8523: }
8524: }
8525: }
1.485 raeburn 8526: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8527: return false;
8528: }
1.329 droeschl 8529:
1.472 raeburn 8530: function toContents(jumpto) {
8531: var newurl = '$backtourl';
1.525 raeburn 8532: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8533: newurl = newurl+'?postdata='+jumpto;
8534: }
8535: location.href=newurl;
8536: }
8537:
1.538 raeburn 8538: function togglePick(caller,value) {
8539: var disp = 'none';
8540: if (document.getElementById('multi'+caller)) {
8541: var curr = document.getElementById('multi'+caller).style.display;
8542: if (value == 1) {
8543: disp='block';
8544: }
8545: if (curr == disp) {
8546: return;
8547: }
8548: document.getElementById('multi'+caller).style.display=disp;
8549: if (value == 1) {
1.594 damieng 8550: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8551: } else {
8552: document.getElementById('more'+caller).innerHTML = '';
8553: }
8554: if (caller == 'actions') {
8555: setClass(value);
8556: setBoxes(value);
8557: }
8558: }
8559: var showButton = multiSettings();
8560: if (showButton != 1) {
8561: showButton = multiActions();
8562: }
8563: if (document.getElementById('multisave')) {
8564: if (showButton == 1) {
8565: document.getElementById('multisave').style.display='block';
8566: } else {
8567: document.getElementById('multisave').style.display='none';
8568: }
8569: }
8570: resize_scrollbox('contentscroll','1','1');
8571: return;
8572: }
8573:
8574: function toggleCheckUncheck(caller,more) {
8575: if (more == 1) {
1.594 damieng 8576: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8577: document.getElementById('allfields'+caller).style.display='block';
8578: } else {
1.594 damieng 8579: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8580: document.getElementById('allfields'+caller).style.display='none';
8581: }
8582: resize_scrollbox('contentscroll','1','1');
8583: }
8584:
8585: function multiSettings() {
8586: var inuse = 0;
8587: var settingsform = document.togglemultsettings;
8588: if (settingsform.showmultpick.length > 1) {
8589: for (var i=0; i<settingsform.showmultpick.length; i++) {
8590: if (settingsform.showmultpick[i].checked) {
8591: if (settingsform.showmultpick[i].value == 1) {
8592: inuse = 1;
8593: }
8594: }
8595: }
8596: }
8597: return inuse;
8598: }
8599:
8600: function multiActions() {
8601: var inuse = 0;
8602: var actionsform = document.togglemultactions;
8603: if (actionsform.showmultpick.length > 1) {
8604: for (var i=0; i<actionsform.showmultpick.length; i++) {
8605: if (actionsform.showmultpick[i].checked) {
8606: if (actionsform.showmultpick[i].value == 1) {
8607: inuse = 1;
8608: }
8609: }
8610: }
8611: }
8612: return inuse;
8613: }
8614:
8615: function checkSubmits() {
8616: var numchanges = 0;
8617: var form = document.saveactions;
8618: var doactions = multiActions();
1.542 raeburn 8619: var cutwarnings = 0;
8620: var remwarnings = 0;
1.603 raeburn 8621: var removalinfo = 0;
1.538 raeburn 8622: if (doactions == 1) {
8623: var remidxlist = document.cumulativeactions.allremoveidx.value;
8624: if ((remidxlist != '') && (remidxlist != null)) {
8625: var remidxs = remidxlist.split(',');
8626: for (var i=0; i<remidxs.length; i++) {
8627: if (document.getElementById('remove_'+remidxs[i])) {
8628: if (document.getElementById('remove_'+remidxs[i]).checked) {
8629: form.multiremove.value += remidxs[i]+',';
8630: numchanges ++;
1.542 raeburn 8631: if (document.getElementById('skip_remove_'+remidxs[i])) {
8632: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8633: remwarnings ++;
8634: }
8635: }
1.603 raeburn 8636: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8637: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8638: removalinfo ++;
8639: }
8640: }
1.537 raeburn 8641: }
8642: }
1.538 raeburn 8643: }
8644: }
8645: var cutidxlist = document.cumulativeactions.allcutidx.value;
8646: if ((cutidxlist != '') && (cutidxlist != null)) {
8647: var cutidxs = cutidxlist.split(',');
8648: for (var i=0; i<cutidxs.length; i++) {
8649: if (document.getElementById('cut_'+cutidxs[i])) {
8650: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8651: form.multicut.value += cutidxs[i]+',';
8652: numchanges ++;
1.542 raeburn 8653: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8654: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8655: cutwarnings ++;
8656: }
8657: }
1.537 raeburn 8658: }
8659: }
8660: }
8661: }
1.538 raeburn 8662: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8663: if ((copyidxlist != '') && (copyidxlist != null)) {
8664: var copyidxs = copyidxlist.split(',');
8665: for (var i=0; i<copyidxs.length; i++) {
8666: if (document.getElementById('copy_'+copyidxs[i])) {
8667: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8668: form.multicopy.value += copyidxs[i]+',';
8669: numchanges ++;
8670: }
8671: }
8672: }
8673: }
8674: if (numchanges > 0) {
8675: form.multichange.value = numchanges;
8676: }
1.537 raeburn 8677: }
1.538 raeburn 8678: var dosettings = multiSettings();
1.543 raeburn 8679: var haschanges = 0;
1.538 raeburn 8680: if (dosettings == 1) {
8681: form.allencrypturl.value = '';
8682: form.allhiddenresource.value = '';
1.543 raeburn 8683: form.changeparms.value = 'all';
8684: var patt=new RegExp(",\$");
1.538 raeburn 8685: var allidxlist = document.cumulativesettings.allidx.value;
8686: if ((allidxlist != '') && (allidxlist != null)) {
8687: var allidxs = allidxlist.split(',');
8688: if (allidxs.length > 1) {
8689: for (var i=0; i<allidxs.length; i++) {
8690: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8691: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8692: form.allhiddenresource.value += allidxs[i]+',';
8693: }
8694: }
8695: if (document.getElementById('encrypturl_'+allidxs[i])) {
8696: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8697: form.allencrypturl.value += allidxs[i]+',';
8698: }
8699: }
8700: }
1.543 raeburn 8701: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8702: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8703: }
1.538 raeburn 8704: }
8705: form.allrandompick.value = '';
8706: form.allrandomorder.value = '';
8707: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8708: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8709: var allmapidxs = allmapidxlist.split(',');
8710: for (var i=0; i<allmapidxs.length; i++) {
8711: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8712: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8713: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8714: if ((randompick.checked) && (rpicknum.value != '')) {
8715: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8716: }
8717: if (randorder.checked) {
8718: form.allrandomorder.value += allmapidxs[i]+',';
8719: }
1.537 raeburn 8720: }
1.543 raeburn 8721: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8722: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8723: }
8724: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8725: haschanges = 1;
8726: }
8727: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8728: haschanges = 1;
8729: }
8730: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8731: haschanges = 1;
8732: }
8733: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8734: haschanges = 1;
1.537 raeburn 8735: }
8736: }
1.543 raeburn 8737: if (doactions == 1) {
1.542 raeburn 8738: if (numchanges > 0) {
1.603 raeburn 8739: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8740: if (remwarnings > 0) {
1.594 damieng 8741: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8742: return false;
8743: }
8744: }
1.603 raeburn 8745: if (removalinfo > 0) {
8746: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8747: return false;
8748: }
8749: }
1.542 raeburn 8750: if (cutwarnings > 0) {
1.594 damieng 8751: 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 8752: return false;
8753: }
8754: }
8755: }
8756: form.submit();
8757: return true;
1.543 raeburn 8758: }
8759: }
8760: if (dosettings == 1) {
8761: if (haschanges == 1) {
1.542 raeburn 8762: form.submit();
8763: return true;
8764: }
1.543 raeburn 8765: }
8766: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8767: alert("$js_lt{'noor'}");
1.543 raeburn 8768: } else {
8769: if (dosettings == 1) {
1.594 damieng 8770: alert("$js_lt{'noch'}");
1.543 raeburn 8771: } else {
1.594 damieng 8772: alert("$js_lt{'noac'}");
1.543 raeburn 8773: }
8774: }
1.538 raeburn 8775: return false;
8776: }
8777:
8778: function setClass(value) {
8779: var cutclass = 'LC_docs_cut';
8780: var copyclass = 'LC_docs_copy';
8781: var removeclass = 'LC_docs_remove';
8782: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8783: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8784: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8785: var links = document.getElementsByTagName('a');
8786: for (var i=0; i<links.length; i++) {
8787: var classes = links[i].className;
8788: if (cutreg.test(classes)) {
8789: links[i].className = cutclass;
8790: if (value == 1) {
8791: links[i].className += " LC_menubuttons_link";
8792: }
8793: } else {
8794: if (copyreg.test(classes)) {
8795: links[i].className = copyclass;
8796: if (value == 1) {
8797: links[i].className += " LC_menubuttons_link";
8798: }
8799: } else {
8800: if (removereg.test(classes)) {
8801: links[i].className = removeclass;
8802: if (value == 1) {
8803: links[i].className += " LC_menubuttons_link";
8804: }
8805: }
8806: }
8807: }
8808: }
8809: return;
1.537 raeburn 8810: }
8811:
1.538 raeburn 8812: function setBoxes(value) {
8813: var remidxlist = document.cumulativeactions.allremoveidx.value;
8814: if ((remidxlist != '') && (remidxlist != null)) {
8815: var remidxs = remidxlist.split(',');
8816: for (var i=0; i<remidxs.length; i++) {
8817: if (document.getElementById('remove_'+remidxs[i])) {
8818: var item = document.getElementById('remove_'+remidxs[i]);
8819: if (value == 1) {
8820: item.className = 'LC_docs_remove';
8821: } else {
8822: item.className = 'LC_hidden';
8823: }
8824: }
8825: }
8826: }
8827: var cutidxlist = document.cumulativeactions.allcutidx.value;
8828: if ((cutidxlist != '') && (cutidxlist != null)) {
8829: var cutidxs = cutidxlist.split(',');
8830: for (var i=0; i<cutidxs.length; i++) {
8831: if (document.getElementById('cut_'+cutidxs[i])) {
8832: var item = document.getElementById('cut_'+cutidxs[i]);
8833: if (value == 1) {
8834: item.className = 'LC_docs_cut';
8835: } else {
8836: item.className = 'LC_hidden';
8837: }
8838: }
1.537 raeburn 8839: }
8840: }
1.538 raeburn 8841: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8842: if ((copyidxlist != '') && (copyidxlist != null)) {
8843: var copyidxs = copyidxlist.split(',');
8844: for (var i=0; i<copyidxs.length; i++) {
8845: if (document.getElementById('copy_'+copyidxs[i])) {
8846: var item = document.getElementById('copy_'+copyidxs[i]);
8847: if (value == 1) {
8848: item.className = 'LC_docs_copy';
8849: } else {
8850: item.className = 'LC_hidden';
8851: }
8852: }
1.537 raeburn 8853: }
8854: }
8855: return;
8856: }
8857:
1.606 raeburn 8858: function validImportCrsRes() {
8859: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8860: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8861: if ((fname == '') || (fname == null)) {
8862: alert("$js_lt{'nofi'}");
8863: return false;
8864: }
8865: var url = '/res/$coursedom/$coursenum/';
8866: if (path && path != '/') {
8867: url += path+'/';
8868: }
8869: if (fname != '') {
8870: url += fname;
8871: }
8872: var title = document.crsresimportform.crsrestitle.value;
1.676 raeburn 8873: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
1.606 raeburn 8874: return true;
8875: }
8876:
8877: function validateNewRes(caller) {
8878: if (caller == 'single') {
8879: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8880: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8881: var resname = document.courseresform.newresourcename.value;
8882: }
8883: }
8884:
1.611 raeburn 8885: ENDSCRIPT
1.329 droeschl 8886: }
1.457 raeburn 8887:
1.483 raeburn 8888: sub history_tab_js {
8889: return <<"ENDHIST";
8890: function toggleHistoryDisp(choice) {
8891: document.docslogform.docslog.value = choice;
8892: document.docslogform.submit();
8893: return;
8894: }
8895:
8896: ENDHIST
8897: }
8898:
1.484 raeburn 8899: sub inject_data_js {
8900: return <<ENDINJECT;
8901:
8902: function injectData(current, hiddenField, name, value) {
8903: currentElement = document.getElementById(hiddenField);
8904: currentElement.name = name;
8905: currentElement.value = value;
8906: current.submit();
8907: }
8908:
8909: ENDINJECT
8910: }
8911:
8912: sub dump_switchserver_js {
8913: my @hosts = @_;
1.594 damieng 8914: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8915: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8916: swit => 'Switch server?',
1.594 damieng 8917: );
8918: my %html_js_lt = &Apache::lonlocal::texthash(
8919: swit => 'Switch server?',
1.568 raeburn 8920: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8921: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8922: chos => 'Choose server',
8923: );
1.594 damieng 8924: &js_escape(\%js_lt);
8925: &html_escape(\%html_js_lt);
8926: &js_escape(\%html_js_lt);
1.484 raeburn 8927: my $role = $env{'request.role'};
8928: my $js = <<"ENDSWJS";
8929: <script type="text/javascript">
8930: function write_switchserver() {
8931: var server;
8932: if (document.setserver.posshosts.length > 0) {
8933: for (var i=0; i<document.setserver.posshosts.length; i++) {
8934: if (document.setserver.posshosts[i].checked) {
8935: server = document.setserver.posshosts[i].value;
8936: }
8937: }
8938: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8939: }
8940: window.close();
8941: }
8942: </script>
8943:
8944: ENDSWJS
8945:
8946: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8947: {'only_body' => 1,
8948: 'js_ready' => 1,});
8949: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8950:
8951: my $hostpicker;
8952: my $count = 0;
8953: foreach my $host (sort(@hosts)) {
8954: my $checked;
8955: if ($count == 0) {
8956: $checked = ' checked="checked"';
8957: }
8958: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8959: $host.'"'.$checked.' />'.$host.'</label> ';
8960: $count++;
8961: }
8962:
8963: return <<"ENDSWITCHJS";
8964:
8965: function dump_needs_switchserver(url) {
8966: if (url!='' && url!= null) {
1.594 damieng 8967: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8968: go(url);
8969: }
8970: }
8971: return;
8972: }
8973:
8974: function choose_switchserver_window() {
8975: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8976: newWindow.document.open();
8977: newWindow.document.writeln('$startpage');
1.594 damieng 8978: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8979: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8980: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8981: '<form name="setserver" method="post" action="" \\/>\\n'+
8982: '$hostpicker\\n'+
8983: '<br \\/><br \\/>\\n'+
1.594 damieng 8984: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8985: 'onclick="write_switchserver();" \\/>\\n'+
8986: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8987: newWindow.document.writeln('$endpage');
8988: newWindow.document.close();
8989: newWindow.focus();
8990: }
8991:
8992: ENDSWITCHJS
8993: }
8994:
8995: sub makedocslogform {
8996: my ($formelems,$docslog) = @_;
8997: return <<"LOGSFORM";
8998: <form action="/adm/coursedocs" method="post" name="docslogform">
8999: <input type="hidden" name="docslog" value="$docslog" />
9000: $formelems
9001: </form>
9002: LOGSFORM
9003: }
9004:
9005: sub makesimpleeditform {
9006: my ($formelems) = @_;
9007: return <<"SIMPFORM";
9008: <form name="simpleedit" method="post" action="/adm/coursedocs">
9009: <input type="hidden" name="importdetail" value="" />
9010: $formelems
9011: </form>
9012: SIMPFORM
9013: }
9014:
1.606 raeburn 9015: sub makenewproblem {
9016: my ($r,$coursedom,$coursenum) = @_;
9017: # Creating a new problem
9018: my ($redirect,$error);
9019: if ($env{'form.authorrole'}) {
9020: my ($newsubdir,$filename);
9021: if ($env{'form.newsubdir'}) {
9022: if ($env{'form.newsubdirname'} ne '') {
9023: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 9024: }
1.606 raeburn 9025: }
9026: if ($env{'form.newresourcename'}) {
9027: $filename = $env{'form.newresourcename'};
9028: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
9029: $filename =~ s/`//g;
9030: $filename =~ s{/\.\./}{_}g;
9031: $filename =~ s/\.+/./g;
9032: $filename =~ s{/+}{_}g;
9033: if ($filename ne '') {
9034: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
9035: if (($ext) && ($ext ne '.problem')) {
9036: $filename = $name.'.problem';
9037: } elsif ($ext eq '') {
9038: $filename .= '.problem';
9039: }
9040: my $docroot = $r->dir_config('lonDocRoot');
9041: my @ids=&Apache::lonnet::current_machine_ids();
9042: if ($env{'form.authorrole'} eq 'author') {
9043: if ($env{'user.author'}) {
9044: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
9045: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
9046: my $path = $docroot.$url;
9047: my $subdir = $env{'form.authorpath'};
9048: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9049: }
9050: }
9051: } elsif ($env{'form.authorrole'} eq 'course') {
9052: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
9053: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
9054: my $url = "/priv/$coursedom/$coursenum";
9055: my $path=$docroot.$url;
9056: my $subdir = $env{'form.authorpath'};
9057: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9058: if ($redirect) {
9059: my $rightsfile = 'default.rights';
9060: my $sourcerights = "$path/$rightsfile";
9061: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
9062: my $now = time;
9063: if (!-e $sourcerights) {
9064: my $cid = $coursedom.'_'.$coursenum;
9065: if (open(my $fh,">$sourcerights")) {
9066: print $fh <<END;
9067: <accessrule effect="deny" realm="" type="course" role="" />
9068: <accessrule effect="allow" realm="$cid" type="course" role="" />
9069: END
9070: close($fh);
9071: }
9072: }
9073: if (!-e "$sourcerights.meta") {
9074: if (open(my $fh,">$sourcerights.meta")) {
9075: my $author=$env{'environment.firstname'}.' '.
9076: $env{'environment.middlename'}.' '.
9077: $env{'environment.lastname'}.' '.
9078: $env{'environment.generation'};
9079: $author =~ s/\s+$//;
9080: print $fh <<"END";
9081:
9082: <abstract></abstract>
9083: <author>$author</author>
9084: <authorspace>$coursenum:$coursedom</authorspace>
9085: <copyright>private</copyright>
9086: <creationdate>$now</creationdate>
9087: <customdistributionfile></customdistributionfile>
9088: <dependencies></dependencies>
9089: <domain>$coursedom</domain>
9090: <highestgradelevel>0</highestgradelevel>
9091: <keywords></keywords>
9092: <language>notset </language>
9093: <lastrevisiondate>$now</lastrevisiondate>
9094: <lowestgradelevel>0</lowestgradelevel>
9095: <mime>rights</mime>
9096: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
9097: <notes></notes>
9098: <obsolete></obsolete>
9099: <obsoletereplacement></obsoletereplacement>
9100: <owner>$coursenum:$coursedom</owner>
9101: <rule>deny:::course,allow:$cid::course</rule>
9102: <sourceavail></sourceavail>
9103: <standards></standards>
9104: <subject></subject>
9105: <title></title>
9106: END
1.654 raeburn 9107: close($fh);
9108: }
9109: }
9110: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
9111: if (!-e "$docroot/res/$coursedom") {
9112: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 9113: }
1.654 raeburn 9114: if (!-e "$docroot/res/$coursedom/$coursenum") {
9115: mkdir("$docroot/res/$coursedom/$coursenum",0755);
9116: }
9117: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
9118: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
9119: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 9120: }
9121: }
1.654 raeburn 9122: my $source = $docroot.$redirect;
9123: if (!-e "$source.meta") {
9124: my $cid = $coursedom.'_'.$coursenum;
9125: my $now = time;
9126: if (open(my $fh,">$source.meta")) {
9127: my $author=$env{'environment.firstname'}.' '.
9128: $env{'environment.middlename'}.' '.
9129: $env{'environment.lastname'}.' '.
9130: $env{'environment.generation'};
9131: $author =~ s/\s+$//;
9132: my $title = $env{'form.newresourcetitle'};
9133: $title =~ s/^\s+|\s+$//g;
9134: print $fh <<END;
1.606 raeburn 9135:
9136: <abstract></abstract>
9137: <author>$author</author>
9138: <authorspace>$coursenum:$coursedom</authorspace>
9139: <copyright>custom</copyright>
9140: <creationdate>$now</creationdate>
9141: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
9142: <dependencies></dependencies>
9143: <domain>$coursedom</domain>
9144: <highestgradelevel>0</highestgradelevel>
9145: <keywords></keywords>
9146: <language>notset </language>
9147: <lastrevisiondate>$now</lastrevisiondate>
9148: <lowestgradelevel>0</lowestgradelevel>
9149: <mime>problem</mime>
9150: <modifyinguser>$coursenum:$coursedom</modifyinguser>
9151: <notes></notes>
9152: <obsolete></obsolete>
9153: <obsoletereplacement></obsoletereplacement>
9154: <owner>$coursenum:$coursedom</owner>
9155: <sourceavail></sourceavail>
9156: <standards></standards>
9157: <subject></subject>
9158: <title>$title</title>
9159: END
1.654 raeburn 9160: close($fh);
1.606 raeburn 9161: }
9162: }
9163: }
9164: }
9165: } else {
9166: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
9167: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
9168: if (grep(/^\Q$rolehome\E$/,@ids)) {
9169: my $now = time;
9170: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
9171: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
9172: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
9173: my $url = "/priv/$audom/$auname";
9174: my $path = $r->dir_config('lonDocRoot').$url;
9175: my $subdir = $env{'form.authorpath'};
9176: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
9177: }
9178: }
9179: }
9180: }
9181: }
9182: }
9183: }
9184: return ($redirect,$error);
9185: }
9186:
9187: sub finishnewprob {
1.654 raeburn 9188: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 9189: unless (-d $path) {
9190: unless (mkdir($path,02770)) {
9191: return;
9192: }
9193: }
1.606 raeburn 9194: my $redirect;
9195: if ($subdir ne '/') {
9196: $subdir = &cleandir($subdir);
9197: if (($subdir ne '') && (-d "$path/$subdir")) {
9198: $path .= "/$subdir";
9199: $url .= "/$subdir";
9200: }
9201: }
9202: my $dest;
9203: if ($newsubdir ne '') {
9204: $newsubdir = &cleandir($newsubdir);
9205: }
9206: if ($newsubdir ne '') {
9207: if (-d "$path/$newsubdir") {
9208: $dest = "$path/$newsubdir/$filename";
9209: } else {
9210: my $dirok;
9211: unless (-e "$path/$newsubdir") {
9212: if (mkdir("$path/$newsubdir",02770)) {
9213: if (chmod(02770,"$path/$newsubdir")) {
9214: $dirok = 1;
9215: }
9216: }
9217: }
9218: if ($dirok) {
9219: $dest = "$path/$newsubdir/$filename";
9220: }
9221: }
9222: if (($dest ne '') && (!-e $dest)) {
9223: $redirect = "$url/$newsubdir/$filename";
9224: }
9225: } else {
9226: $dest = "$path/$filename";
9227: if (($dest ne '') && (!-e $dest)) {
9228: $redirect = "$url/$filename";
9229: }
9230: }
1.654 raeburn 9231: if ((!-e $dest) && ($context ne 'upload')) {
9232: my $template = $env{'form.template'};
9233: my $copyfrom;
9234: if ($template ne '') {
9235: my %templates;
9236: my @files = &Apache::lonhomework::get_template_list('problem');
9237: foreach my $poss (@files) {
9238: if (ref($poss) eq 'ARRAY') {
9239: if ($template eq $poss->[0]) {
9240: $templates{$template} = 1;
9241: last;
9242: }
9243: }
9244: }
9245: if ($templates{$template}) {
9246: $copyfrom = $template;
9247: }
9248: }
9249: if ($filename =~ /\.problem$/) {
9250: unless ($copyfrom) {
9251: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9252: }
9253: &File::Copy::copy($copyfrom,$dest);
9254: }
9255: }
1.606 raeburn 9256: return $redirect;
9257: }
9258:
9259: sub cleandir {
9260: my ($dir) = @_;
9261: $dir =~ s/^\s+//;
9262: $dir =~ s/\s+$//;
9263: $dir =~ s/\.+//g;
9264: $dir =~ s/[\#\?&%\":]//g;
9265: return $dir;
9266: }
9267:
1.329 droeschl 9268: 1;
9269: __END__
9270:
9271:
9272: =head1 NAME
9273:
9274: Apache::londocs.pm
9275:
9276: =head1 SYNOPSIS
9277:
9278: This is part of the LearningOnline Network with CAPA project
9279: described at http://www.lon-capa.org.
9280:
9281: =head1 SUBROUTINES
9282:
9283: =over
9284:
9285: =item %help=()
9286:
9287: Available help topics
9288:
9289: =item mapread()
9290:
1.344 bisitz 9291: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 9292: @order and @resources, determines status
9293: sets @order - pointer to resources in right order
9294: sets @resources - array with the resources with correct idx
9295:
9296: =item authorhosts()
9297:
9298: Return hash with valid author names
9299:
9300: =item clean()
9301:
9302: =item dumpcourse()
9303:
9304: Actually dump course
9305:
9306: =item group_import()
9307:
9308: Imports the given (name, url) resources into the course
9309: coursenum, coursedom, and folder must precede the list
9310:
9311: =item breadcrumbs()
9312:
9313: =item log_docs()
9314:
9315: =item docs_change_log()
9316:
9317: =item update_paste_buffer()
9318:
9319: =item print_paste_buffer()
9320:
9321: =item do_paste_from_buffer()
9322:
1.538 raeburn 9323: =item do_buffer_empty()
9324:
9325: =item clear_from_buffer()
9326:
1.492 raeburn 9327: =item get_newmap_url()
9328:
9329: =item dbcopy()
9330:
9331: =item uniqueness_check()
9332:
9333: =item contained_map_check()
9334:
9335: =item url_paste_fixups()
9336:
9337: =item apply_fixups()
9338:
9339: =item copy_dependencies()
9340:
1.329 droeschl 9341: =item update_parameter()
9342:
9343: =item handle_edit_cmd()
9344:
9345: =item editor()
9346:
9347: =item process_file_upload()
9348:
9349: =item process_secondary_uploads()
9350:
9351: =item is_supplemental_title()
9352:
9353: =item entryline()
9354:
9355: =item tiehash()
9356:
9357: =item untiehash()
9358:
9359: =item checkonthis()
9360:
9361: check on this
9362:
9363: =item verifycontent()
9364:
9365: Verify Content
9366:
1.636 raeburn 9367: =item devalidateversioncache()
9368:
9369: =item checkversions()
1.329 droeschl 9370:
9371: Check Versions
9372:
9373: =item mark_hash_old()
9374:
9375: =item is_hash_old()
9376:
9377: =item changewarning()
9378:
9379: =item init_breadcrumbs()
9380:
9381: Breadcrumbs for special functions
9382:
1.484 raeburn 9383: =item create_list_elements()
9384:
9385: =item create_form_ul()
9386:
9387: =item startContentScreen()
9388:
9389: =item endContentScreen()
9390:
9391: =item supplemental_base()
9392:
9393: =item embedded_form_elems()
9394:
9395: =item embedded_destination()
9396:
9397: =item return_to_editor()
9398:
9399: =item decompression_info()
9400:
9401: =item decompression_phase_one()
9402:
9403: =item decompression_phase_two()
9404:
9405: =item remove_archive()
9406:
9407: =item generate_admin_menu()
9408:
9409: =item generate_edit_table()
9410:
9411: =item editing_js()
9412:
9413: =item history_tab_js()
9414:
9415: =item inject_data_js()
9416:
9417: =item dump_switchserver_js()
9418:
1.485 raeburn 9419: =item resize_scrollbox_js()
1.484 raeburn 9420:
9421: =item makedocslogform()
9422:
1.485 raeburn 9423: =item makesimpleeditform()
9424:
1.329 droeschl 9425: =back
9426:
9427: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>