Annotation of loncom/interface/londocs.pm, revision 1.675
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.675 ! raeburn 4: # $Id: londocs.pm,v 1.674 2020/09/08 19:15:18 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.645 raeburn 48: use Apache::lonparmset();
1.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;
94: } else {
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:
186: sub dumpcourse {
187: my ($r) = @_;
1.408 raeburn 188: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 189: my ($starthash,$js);
190: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
191: $js = <<"ENDJS";
192: <script type="text/javascript">
193: // <![CDATA[
194:
195: function hide_searching() {
196: if (document.getElementById('searching')) {
197: document.getElementById('searching').style.display = 'none';
198: }
199: return;
200: }
201:
202: // ]]>
203: </script>
204: ENDJS
205: $starthash = {
206: add_entries => {'onload' => "hide_searching();"},
207: };
208: }
1.568 raeburn 209: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
210: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 211: $r->print(&startContentScreen('tools'));
1.329 droeschl 212: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 213: unless ($home) {
214: $r->print(&endContentScreen());
215: return '';
216: }
1.329 droeschl 217: my $origcrsid=$env{'request.course.id'};
218: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
219: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
220: # Do the dumping
1.484 raeburn 221: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
222: $r->print(&endContentScreen());
223: return '';
224: }
1.531 raeburn 225: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 226: $r->print('<h3>'.&mt('Copying Files').'</h3>');
227: my $title=$env{'form.authorfolder'};
228: $title=&clean($title);
1.567 raeburn 229: my ($navmap,$errormsg) =
230: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
231: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
232: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
233: my (%maps,%resources,%titles);
234: if (!ref($navmap)) {
235: $r->print($errormsg.
236: &endContentScreen());
237: return '';
238: } else {
239: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
240: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 241: }
1.567 raeburn 242: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
243: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
244: %newcontent,%has_simpleprobs);
245: foreach my $item (sort {$a <=> $b} (@todump)) {
246: my $name = $env{'form.namefor_'.$item};
247: if ($resources{$item}) {
248: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
249: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
250: $tocopy{$1} = $name;
251: $display{$item} = $1;
252: $lookup{$1} = $item;
253: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
254: $simpleproblems{$item} = {
255: symb => $resources{$item},
256: name => $name,
257: };
258: $display{$item} = 'simpleproblem_'.$name;
259: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
260: $has_simpleprobs{$1}{$id} = $item;
261: }
262: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
263: my $marker = $1;
264: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
265: $simplepages{$item} = {
266: res => $res,
267: title => $titles{$item},
268: db => $db_name,
269: marker => $marker,
270: symb => $resources{$item},
271: name => $name,
272: };
273: $display{$item} = '/'.$res;
274: }
275: } elsif ($maps{$item}) {
276: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
277: $tocopy{$1} = $name;
278: $display{$item} = $1;
279: $lookup{$1} = $item;
280: }
281: } else {
282: next;
283: }
284: }
1.329 droeschl 285: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
286: $crs=~s/\_/\//g;
1.567 raeburn 287: my $mm = new File::MMagic;
288: my $prefix = "/uploaded/$cdom/$cnum/";
289: %replacehash = %tocopy;
290: foreach my $item (sort(keys(%simpleproblems))) {
291: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
292: $newcontent{$display{$item}} = $content;
293: }
294: my $gateway = Apache::lonhtmlgateway->new('web');
295: foreach my $item (sort(keys(%simplepages))) {
296: if (ref($simplepages{$item}) eq 'HASH') {
297: my $pagetitle = $simplepages{$item}{'title'};
298: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
299: my %contents;
300: foreach my $field (keys(%fields)) {
301: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
302: my $name = $1;
303: my $msg = $fields{$field};
304: if ($name eq 'webreferences') {
305: if ($msg =~ m{^https?://}) {
306: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
307: }
308: } else {
309: $msg = &Encode::decode('utf8',$msg);
310: $msg = $gateway->process_outgoing_html($msg,1);
311: $contents{$name} = $msg;
312: }
313: } elsif ($field eq 'uploaded.photourl') {
314: my $marker = $simplepages{$item}{marker};
315: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
316: my $filepath = $1;
317: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
318: if ($fname ne '') {
319: $fname=~s/\.(\w+)$//;
320: my $ext=$1;
321: $fname = &clean($fname);
322: $fname.='.'.$ext;
323: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
324: $replacehash{$filepath} = $relpath.$fname;
325: $deps{$item}{$filepath} = 1;
326: }
327: }
328: }
329: }
330: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
331: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
332: my $content = '
333: <html>
334: <head>
335: <title>'.$pagetitle.'</title>
336: </head>
337: <body bgcolor="#ffffff">';
338: if ($contents{title}) {
339: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
340: }
341: if ($contents{image}) {
342: $content .= "\n".$contents{image};
343: }
344: if ($contents{content}) {
345: $content .= '
346: <div class="LC_Box">
1.577 bisitz 347: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 348: $contents{content}.'
349: </div>';
350: }
351: if ($contents{webreferences}) {
352: $content .= '
353: <div class="LC_Box">
1.577 bisitz 354: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 355: $contents{webreferences}.'
356: </div>';
357: }
358: $content .= '
359: </body>
360: </html>
361: ';
362: $newcontent{'/'.$simplepages{$item}{res}} = $content;
363: }
364: }
365: foreach my $item (keys(%tocopy)) {
366: unless ($item=~/\.(sequence|page)$/) {
367: my $currurlpath = $prefix.$item;
368: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
369: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
370: }
371: }
372: foreach my $num (sort {$a <=> $b} (@todump)) {
373: my $src = $display{$num};
374: next if ($src eq '');
375: my @needcopy = ();
376: if ($replacehash{$src}) {
377: push(@needcopy,$src);
378: if (ref($deps{$num}) eq 'HASH') {
379: foreach my $dep (sort(keys(%{$deps{$num}}))) {
380: if ($replacehash{$dep}) {
381: push(@needcopy,$dep);
382: }
383: }
384: }
385: } elsif ($src =~ /^simpleproblem_/) {
386: push(@needcopy,$src);
387: }
388: next if (@needcopy == 0);
389: my ($result,$depresult);
390: for (my $i=0; $i<@needcopy; $i++) {
391: my $item = $needcopy[$i];
392: my $newfilename;
393: if ($simpleproblems{$num}) {
394: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
395: } else {
396: $newfilename=$title.'/'.$replacehash{$item};
397: }
398: $newfilename=~s/\.(\w+)$//;
399: my $ext=$1;
400: $newfilename=&clean($newfilename);
401: $newfilename.='.'.$ext;
402: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
403: if ($newrelpath ne $replacehash{$item}) {
404: $replacehash{$item} = $newrelpath;
405: }
406: my @dirs=split(/\//,$newfilename);
407: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
408: my $makepath=$path;
409: my $fail;
410: my $origin;
411: for (my $i=0;$i<$#dirs;$i++) {
412: $makepath.='/'.$dirs[$i];
413: unless (-e $makepath) {
414: unless(mkdir($makepath,0755)) {
415: $fail = &mt('Directory creation failed.');
416: }
417: }
418: }
419: if ($i == 0) {
420: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
421: } else {
422: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
423: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
424: &mt('(dependency)').'</span>: ';
425: }
426: if (-e $path.'/'.$newfilename) {
427: $fail = &mt('Destination already exists -- not overwriting.');
428: } else {
429: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
430: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
431: ($item =~ /^simpleproblem_/)) {
432: print $fh $newcontent{$item};
433: } else {
434: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
435: if (-e $fileloc) {
436: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
437: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
438: (ref($has_simpleprobs{$item}) eq 'HASH')) {
439: my %changes = %{$has_simpleprobs{$item}};
440: my $content = &Apache::lonclonecourse::rewritefile(
441: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
442: (%replacehash,$crs => '')
443: );
444: my $updatedcontent = '';
445: my $parser = HTML::TokeParser->new(\$content);
446: $parser->attr_encoded(1);
447: while (my $token = $parser->get_token) {
448: if ($token->[0] eq 'S') {
449: if (($token->[1] eq 'resource') &&
450: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
451: ($changes{$token->[2]->{'id'}})) {
452: my $id = $token->[2]->{'id'};
453: $updatedcontent .= '<'.$token->[1];
454: foreach my $attrib (@{$token->[3]}) {
455: next unless ($attrib =~ /^(src|type|title|id)$/);
456: if ($attrib eq 'src') {
457: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
458: if ($file) {
459: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
460: } else {
461: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
462: }
463: } else {
464: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
465: }
466: }
467: $updatedcontent .= ' />'."\n";
468: } else {
469: $updatedcontent .= $token->[4]."\n";
470: }
471: } else {
472: $updatedcontent .= $token->[2];
473: }
474: }
475: print $fh $updatedcontent;
476: } else {
477: print $fh &Apache::lonclonecourse::rewritefile(
478: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
479: (%replacehash,$crs => '')
480: );
481: }
482: } else {
483: print $fh
484: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
485: }
486: } else {
487: $fail = &mt('Source does not exist.');
488: }
489: }
490: $fh->close();
491: } else {
492: $fail = &mt('Could not write to destination.');
493: }
494: }
495: my $text;
496: if ($fail) {
497: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
498: } else {
499: $text = '<span class="LC_success">'.&mt('ok').'</span>';
500: }
501: if ($i == 0) {
502: $result .= $text;
503: } else {
504: $depresult .= $text.'</li>';
505: }
506: }
507: $r->print($result);
508: if ($depresult) {
509: $r->print('<ul>'.$depresult.'</ul>');
510: }
511: }
512: } else {
513: my ($navmap,$errormsg) =
514: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
515: if (!ref($navmap)) {
516: $r->print($errormsg);
517: } else {
518: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
519: $r->rflush();
520: my ($preamble,$formname);
521: $formname = 'dumpdoc';
522: unless ($home==1) {
523: $preamble = '<div class="LC_left_float">'.
524: '<fieldset><legend>'.
525: &mt('Select the Authoring Space').
526: '</legend><select name="authorspace">';
1.329 droeschl 527: }
1.567 raeburn 528: my @orderspaces = ();
529: foreach my $key (sort(keys(%outhash))) {
530: if ($key=~/^home_(.+)$/) {
531: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
532: unshift(@orderspaces,$1);
533: } else {
534: push(@orderspaces,$1);
535: }
536: }
537: }
1.569 raeburn 538: if ($home>1) {
539: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
540: }
1.567 raeburn 541: foreach my $user (@orderspaces) {
1.329 droeschl 542: if ($home==1) {
1.567 raeburn 543: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 544: } else {
1.567 raeburn 545: $preamble .= '<option value="'.$user.'">'.$user.' - '.
546: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
547: }
1.329 droeschl 548: }
1.567 raeburn 549: unless ($home==1) {
550: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 551: }
1.567 raeburn 552: my $title=$origcrsdata{'description'};
553: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 554: $title=&clean($title);
1.567 raeburn 555: $preamble .= '<div class="LC_left_float">'.
556: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
557: '<input type="text" size="50" name="authorfolder" value="'.
558: $title.'" />'.
559: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
560: my %uploadedfiles;
561: &tiehash();
562: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
563: my ($ext)=($file=~/\.(\w+)$/);
564: # FIXME Check supplemental here
565: my $title=$hash{'title_'.$hash{
566: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
567: if (!$title) {
568: $title=$file;
569: } else {
570: $title=~s|/|_|g;
571: }
572: $title=~s/\.(\w+)$//;
573: $title=&clean($title);
574: $title.='.'.$ext;
575: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
576: $uploadedfiles{$file} = $title;
577: }
578: &untiehash();
579: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
580: undef,undef,$preamble,$home,\%uploadedfiles));
581: }
1.329 droeschl 582: }
1.484 raeburn 583: $r->print(&endContentScreen());
1.329 droeschl 584: }
585:
1.567 raeburn 586: sub recurse_html {
587: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
588: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
589: my (%allfiles,%codebase);
590: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
591: if (keys(%allfiles)) {
592: foreach my $dependency (keys(%allfiles)) {
593: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
594: my ($depurl,$relfile,$newcontainer);
595: if ($dependency =~ m{^/}) {
596: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
597: $relfile = $1;
598: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
599: $newcontainer = $1;
600: next if ($replacehash->{$newcontainer});
601: }
602: $depurl = $dependency;
603: } else {
604: next;
605: }
606: } else {
607: $relfile = $dependency;
608: $depurl = $currurlpath;
1.630 raeburn 609: $depurl =~ s{[^/]+$}{};
1.567 raeburn 610: $depurl .= $dependency;
1.630 raeburn 611: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 612: }
613: next if ($relfile eq '');
614: my $newname = $replacehash->{$container};
615: $newname =~ s{[^/]+$}{};
616: $replacehash->{$newcontainer} = $newname.$relfile;
617: $deps->{$item}{$newcontainer} = 1;
618: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
619: my $depfile = &Apache::lonnet::filelocation('',$depurl);
620: my $type = $mm->checktype_filename($depfile);
621: if ($type eq 'text/html') {
622: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
623: }
624: }
625: }
626: }
627: return;
628: }
629:
1.329 droeschl 630: sub group_import {
1.598 raeburn 631: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 632: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
633: %removeparam,$importuploaded,$fixuperrors);
634: $allmaps = {};
1.329 droeschl 635: while (@files) {
636: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 637: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 638: && ($caller eq 'londocs')
639: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 640:
1.329 droeschl 641: my $errtext = '';
642: my $fatal = 0;
643: my $newmapstr = '<map>'."\n".
644: '<resource id="1" src="" type="start"></resource>'."\n".
645: '<link from="1" to="2" index="1"></link>'."\n".
646: '<resource id="2" src="" type="finish"></resource>'."\n".
647: '</map>';
648: $env{'form.output'}=$newmapstr;
649: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
650: 'output',$1.$2);
1.534 raeburn 651: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 652: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
653: $fatal = 2;
654: }
655: if ($fatal) {
656: return ($errtext,$fatal);
657: }
658: }
659: if ($url) {
1.626 raeburn 660: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 661: $url = $1;
662: my $marker = $2;
663: my $info = $3;
1.604 raeburn 664: my ($toolid,%toolhash,%toolsettings);
1.642 raeburn 665: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 666: my @toolinfo = split(/:/,$info);
667: if ($residx) {
1.604 raeburn 668: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 669: $toolid = $toolsettings{'id'};
670: } else {
1.604 raeburn 671: $toolid = shift(@toolinfo);
1.598 raeburn 672: }
673: $toolid =~ s/\D//g;
1.604 raeburn 674: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.645 raeburn 675: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
676: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
1.624 raeburn 677: foreach my $item (@extras) {
678: $toolhash{$item} = &unescape($toolhash{$item});
679: }
1.645 raeburn 680: if ($folder =~ /^supplemental/) {
1.648 raeburn 681: delete($toolhash{'gradable'});
682: } else {
683: $toolhash{'gradable'} =~ s/\D+//g;
1.645 raeburn 684: }
1.598 raeburn 685: if (ref($ltitoolsref) eq 'HASH') {
686: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
1.643 raeburn 687: my @deleted;
1.598 raeburn 688: $toolhash{'id'} = $toolid;
1.628 raeburn 689: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
690: ($toolhash{'target'} eq 'window')) {
1.604 raeburn 691: if ($toolhash{'target'} eq 'window') {
692: foreach my $item ('width','height') {
693: $toolhash{$item} =~ s/^\s+//;
694: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 695: if ($toolhash{$item} =~ /\D/) {
696: delete($toolhash{$item});
697: if ($residx) {
698: if ($toolsettings{$item}) {
699: push(@deleted,$item);
700: }
701: }
702: }
1.604 raeburn 703: }
704: }
705: } elsif ($residx) {
706: $toolhash{'target'} = $toolsettings{'target'};
707: if ($toolhash{'target'} eq 'window') {
1.630 raeburn 708: foreach my $item ('width','height') {
1.624 raeburn 709: $toolhash{$item} = $toolsettings{$item};
710: }
1.604 raeburn 711: }
712: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
713: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
714: if ($toolhash{'target'} eq 'window') {
715: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
716: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
717: }
718: }
1.598 raeburn 719: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 720: foreach my $item ('width','height','linktext','explanation') {
721: delete($toolhash{$item});
722: if ($residx) {
723: if ($toolsettings{$item}) {
724: push(@deleted,$item);
725: }
1.604 raeburn 726: }
727: }
1.628 raeburn 728: } elsif ($toolhash{'target'} eq 'tab') {
729: foreach my $item ('width','height') {
730: delete($toolhash{$item});
731: if ($residx) {
732: if ($toolsettings{$item}) {
733: push(@deleted,$item);
734: }
735: }
736: }
1.604 raeburn 737: }
738: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 739: foreach my $item ('label','title','linktext','explanation') {
740: my $crsitem;
741: if (($item eq 'label') || ($item eq 'title')) {
742: $crsitem = 'crs'.$item;
743: } else {
744: $crsitem = $item;
745: }
1.604 raeburn 746: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 747: $toolhash{$crsitem} =~ s/^\s+//;
748: $toolhash{$crsitem} =~ s/\s+$//;
749: if ($toolhash{$crsitem} eq '') {
750: delete($toolhash{$crsitem});
1.604 raeburn 751: }
752: } else {
1.624 raeburn 753: delete($toolhash{$crsitem});
1.604 raeburn 754: }
1.624 raeburn 755: if (($residx) && (exists($toolsettings{$crsitem}))) {
756: unless (exists($toolhash{$crsitem})) {
757: push(@deleted,$crsitem);
1.604 raeburn 758: }
759: }
1.598 raeburn 760: }
761: }
1.643 raeburn 762: if ($toolhash{'passback'}) {
763: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
764: $toolhash{'gradesecret'} = $gradesecret;
765: $toolhash{'gradesecretdate'} = time;
766: }
767: if ($toolhash{'roster'}) {
768: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
769: $toolhash{'rostersecret'} = $rostersecret;
770: $toolhash{'rostersecretdate'} = time;
771: }
1.645 raeburn 772: my $changegradable;
773: if (($residx) && ($folder =~ /^default/)) {
1.648 raeburn 774: if ($toolsettings{'gradable'}) {
775: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 776: push(@deleted,'gradable');
777: $changegradable = 1;
778: }
1.648 raeburn 779: } elsif ($toolhash{'gradable'}) {
780: $changegradable = 1;
781: }
782: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
1.645 raeburn 783: $changegradable = 1;
1.648 raeburn 784: if ($toolsettings{'gradable'}) {
785: $toolhash{'gradable'} = 1;
786: }
1.645 raeburn 787: }
788: }
1.598 raeburn 789: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 790: if ($putres eq 'ok') {
791: if (@deleted) {
792: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
1.645 raeburn 793: }
794: if (($changegradable) && ($folder =~ /^default/)) {
795: my $val;
796: if ($toolhash{'gradable'}) {
797: $val = 'yes';
798: } else {
799: $val = 'no';
800: }
801: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
802: 'string_yesno');
803: &remember_parms($residx,'gradable','set',$val);
804: }
805: } else {
806: return (&mt('Failed to save update to external tool.'),1);
1.604 raeburn 807: }
1.598 raeburn 808: }
809: }
810: }
1.529 raeburn 811: if (($caller eq 'londocs') &&
812: ($folder =~ /^default/)) {
1.534 raeburn 813: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 814: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
815: my $cid = $coursedom.'_'.$coursenum;
816: $allmaps =
817: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
818: $chome,$cid);
819: $donechk = 1;
820: }
821: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 822: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
823: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 824: $importuploaded = 1;
825: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
826: next if ($allmaps->{$url});
827: }
828: }
1.344 bisitz 829: if (!$residx
1.329 droeschl 830: || defined($LONCAPA::map::zombies[$residx])) {
831: $residx = &LONCAPA::map::getresidx($url,$residx);
832: push(@LONCAPA::map::order, $residx);
833: }
834: my $ext = 'false';
835: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
1.534 raeburn 836: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
837: my $filepath = $1;
1.675 ! raeburn 838: my $fname;
! 839: if ($name eq '') {
! 840: $name = &mt('Web Page');
1.534 raeburn 841: $fname = 'web';
842: } else {
1.675 ! raeburn 843: $fname = $name;
! 844: $fname=&Apache::lonnet::clean_filename($fname);
! 845: if ($fname eq '') {
! 846: $fname = 'web';
! 847: } elsif (length($fname) > 15) {
! 848: $fname = substr($fname,0,14);
! 849: }
1.534 raeburn 850: }
1.675 ! raeburn 851: my $title = &Apache::loncommon::cleanup_html($name);
1.534 raeburn 852: my $initialtext = &mt('Replace with your own content.');
853: my $newhtml = <<END;
1.545 raeburn 854: <html>
1.534 raeburn 855: <head>
1.675 ! raeburn 856: <title>$title</title>
1.534 raeburn 857: </head>
858: <body bgcolor="#ffffff">
859: $initialtext
860: </body>
861: </html>
862: END
863: $env{'form.output'}=$newhtml;
1.630 raeburn 864: my $result =
1.534 raeburn 865: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
866: 'output',
867: "$filepath/$residx/$fname.html");
868: if ($result =~ m{^/uploaded/}) {
869: $url = $result;
870: if ($filepath =~ /^supplemental/) {
871: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
872: $env{'user.domain'}.'___&&&___'.$name;
873: }
874: } else {
875: return (&mt('Failed to save new web page.'),1);
876: }
877: }
1.675 ! raeburn 878: $name = &LONCAPA::map::qtunescape($name);
1.538 raeburn 879: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 880: $LONCAPA::map::resources[$residx] =
1.329 droeschl 881: join(':', ($name, $url, $ext, 'normal', 'res'));
882: }
883: }
1.529 raeburn 884: if ($importuploaded) {
885: my %import_errors;
886: my %updated = (
887: removefrommap => \%removefrommap,
888: removeparam => \%removeparam,
889: );
1.533 raeburn 890: my ($result,$msgsarray,$lockerror) =
891: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 892: if (keys(%import_errors) > 0) {
1.530 raeburn 893: $fixuperrors =
1.529 raeburn 894: '<p span class="LC_warning">'."\n".
895: &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".
896: '<ul>'."\n";
897: foreach my $key (sort(keys(%import_errors))) {
898: $fixuperrors .= '<li>'.$key.'</li>'."\n";
899: }
900: $fixuperrors .= '</ul></p>'."\n";
901: }
1.533 raeburn 902: if (ref($msgsarray) eq 'ARRAY') {
903: if (@{$msgsarray} > 0) {
904: $fixuperrors .= '<p class="LC_info">'.
905: join('<br />',@{$msgsarray}).
906: '</p>';
907: }
908: }
909: if ($lockerror) {
910: $fixuperrors .= '<p class="LC_error">'.
911: $lockerror.
912: '</p>';
913: }
1.529 raeburn 914: }
915: my ($errtext,$fatal) =
916: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 917: unless ($fatal) {
918: if ($folder =~ /^supplemental/) {
919: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 920: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
921: $folder.'.'.$container);
1.557 raeburn 922: }
923: }
1.529 raeburn 924: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 925: }
926:
927: sub log_docs {
1.494 raeburn 928: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 929: }
930:
931: {
932: my @oldresources=();
933: my @oldorder=();
934: my $parmidx;
935: my %parmaction=();
936: my %parmvalue=();
937: my $changedflag;
938:
939: sub snapshotbefore {
940: @oldresources=@LONCAPA::map::resources;
941: @oldorder=@LONCAPA::map::order;
942: $parmidx=undef;
943: %parmaction=();
944: %parmvalue=();
945: $changedflag=0;
946: }
947:
948: sub remember_parms {
949: my ($idx,$parameter,$action,$value)=@_;
950: $parmidx=$idx;
951: $parmaction{$parameter}=$action;
952: $parmvalue{$parameter}=$value;
953: $changedflag=1;
954: }
955:
956: sub log_differences {
957: my ($plain)=@_;
958: my %storehash=('folder' => $plain,
959: 'currentfolder' => $env{'form.folder'});
960: if ($parmidx) {
961: $storehash{'parameter_res'}=$oldresources[$parmidx];
962: foreach my $parm (keys(%parmaction)) {
963: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
964: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
965: }
966: }
967: my $maxidx=$#oldresources;
968: if ($#LONCAPA::map::resources>$#oldresources) {
969: $maxidx=$#LONCAPA::map::resources;
970: }
971: for (my $idx=0; $idx<=$maxidx; $idx++) {
972: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
973: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
974: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
975: $changedflag=1;
976: }
977: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
978: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
979: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
980: $changedflag=1;
981: }
982: }
983: $storehash{'maxidx'}=$maxidx;
984: if ($changedflag) { &log_docs(\%storehash); }
985: }
986: }
987:
988: sub docs_change_log {
1.611 raeburn 989: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 990: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 991: my $navmap;
1.483 raeburn 992: my $js = '<script type="text/javascript">'."\n".
993: '// <![CDATA['."\n".
994: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 995: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 996: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 997: &history_tab_js()."\n".
1.484 raeburn 998: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 999: '// ]]>'."\n".
1000: '</script>'."\n";
1.484 raeburn 1001: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1002: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1003: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1004: my %orderhash;
1005: my $container='sequence';
1006: my $pathitem;
1.519 raeburn 1007: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1008: $container='page';
1009: }
1.519 raeburn 1010: my $folderpath=$env{'form.folderpath'};
1011: if ($folderpath eq '') {
1.617 raeburn 1012: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1013: }
1.617 raeburn 1014: undef($navmap);
1.519 raeburn 1015: $pathitem = '<input type="hidden" name="folderpath" value="'.
1016: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1017: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1018: my $jumpto = $readfile;
1019: $jumpto =~ s{^/}{};
1020: my $tid = 1;
1.489 raeburn 1021: if ($supplementalflag) {
1022: $tid = 2;
1023: }
1.630 raeburn 1024: my ($breadcrumbtrail) =
1.509 raeburn 1025: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1026: $r->print($breadcrumbtrail.
1027: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1028: $readfile));
1.329 droeschl 1029: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1030: $env{'course.'.$env{'request.course.id'}.'.domain'},
1031: $env{'course.'.$env{'request.course.id'}.'.num'});
1032:
1033: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1034:
1035: my %saveable_parameters = ('show' => 'scalar',);
1036: &Apache::loncommon::store_course_settings('docs_log',
1037: \%saveable_parameters);
1038: &Apache::loncommon::restore_course_settings('docs_log',
1039: \%saveable_parameters);
1040: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1041: # FIXME: internationalization seems wrong here
1.329 droeschl 1042: my %lt=('hiddenresource' => 'Resources hidden',
1043: 'encrypturl' => 'URL hidden',
1044: 'randompick' => 'Randomly pick',
1045: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1046: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1047: 'set' => 'set to',
1048: 'del' => 'deleted');
1.484 raeburn 1049: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1050: $pathitem."\n".
1051: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1052: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1053: $r->print('<div class="LC_left_float">'.
1054: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1055: &makedocslogform($filter,1).
1056: '</fieldset></div><br clear="all" />');
1.329 droeschl 1057: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1058: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1059: &mt('After').'</th>'.
1060: &Apache::loncommon::end_data_table_header_row());
1061: my $shown=0;
1062: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1063: if ($env{'form.displayfilter'} eq 'currentfolder') {
1064: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1065: }
1066: my @changes=keys(%{$docslog{$id}{'logentry'}});
1067: if ($env{'form.displayfilter'} eq 'containing') {
1068: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1069: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1070: foreach my $key (@changes) {
1071: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1072: }
1.344 bisitz 1073: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1074: }
1075: my $count = 0;
1076: my $time =
1077: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1078: my $plainname =
1079: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1080: $docslog{$id}{'exe_udom'});
1081: my $about_me_link =
1082: &Apache::loncommon::aboutmewrapper($plainname,
1083: $docslog{$id}{'exe_uname'},
1084: $docslog{$id}{'exe_udom'});
1085: my $send_msg_link='';
1086: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1087: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1088: $send_msg_link ='<br />'.
1089: &Apache::loncommon::messagewrapper(&mt('Send message'),
1090: $docslog{$id}{'exe_uname'},
1091: $docslog{$id}{'exe_udom'});
1092: }
1093: $r->print(&Apache::loncommon::start_data_table_row());
1094: $r->print('<td>'.$time.'</td>
1095: <td>'.$about_me_link.
1096: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1097: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1098: $send_msg_link.'</td><td>'.
1099: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1100: my $is_supp = 0;
1101: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1102: $is_supp = 1;
1103: }
1.329 droeschl 1104: # Before
1105: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1106: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1107: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1108: if ($oldname ne $newname) {
1.488 raeburn 1109: my $shown = &LONCAPA::map::qtescape($oldname);
1110: if ($is_supp) {
1111: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1112: }
1113: $r->print($shown);
1.329 droeschl 1114: }
1115: }
1116: $r->print('<ul>');
1117: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1118: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1119: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1120: if ($is_supp) {
1121: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1122: }
1123: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1124: }
1125: }
1126: $r->print('</ul>');
1127: # After
1128: $r->print('</td><td>');
1129:
1130: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1131: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1132: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1133: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1134: my $shown = &LONCAPA::map::qtescape($newname);
1135: if ($is_supp) {
1136: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1137: }
1138: $r->print($shown);
1.329 droeschl 1139: }
1.364 bisitz 1140: }
1.329 droeschl 1141: $r->print('<ul>');
1142: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1143: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1144: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1145: if ($is_supp) {
1146: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1147: }
1148: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1149: }
1150: }
1151: $r->print('</ul>');
1152: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1153: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1.645 raeburn 1154: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1155: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1156: # FIXME: internationalization seems wrong here
1.329 droeschl 1157: $r->print('<li>'.
1158: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1159: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1160: .'</li>');
1161: }
1162: }
1163: $r->print('</ul>');
1164: }
1165: # End
1166: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1167: $shown++;
1168: if (!($env{'form.show'} eq &mt('all')
1169: || $shown<=$env{'form.show'})) { last; }
1170: }
1.484 raeburn 1171: $r->print(&Apache::loncommon::end_data_table()."\n".
1172: &makesimpleeditform($pathitem)."\n".
1173: '</div></div>');
1174: $r->print(&endContentScreen());
1.329 droeschl 1175: }
1176:
1177: sub update_paste_buffer {
1.492 raeburn 1178: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1179: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1180: if ($env{'form.multiremove'}) {
1181: $env{'form.multiremove'} =~ s/,$//;
1182: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1183: }
1184: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1185: if ($env{'form.multicut'}) {
1186: $env{'form.multicut'} =~ s/,$//;
1187: foreach my $item (split(/,/,$env{'form.multicut'})) {
1188: unless ($removals{$item}) {
1189: $cuts{$item} = 1;
1190: push(@possibles,$item.':cut');
1191: }
1192: }
1193: }
1194: if ($env{'form.multicopy'}) {
1195: $env{'form.multicopy'} =~ s/,$//;
1196: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1197: unless ($removals{$item} || $cuts{$item}) {
1198: push(@possibles,$item.':copy');
1199: }
1200: }
1201: }
1202: } elsif ($env{'form.markcopy'}) {
1203: @possibles = split(/,/,$env{'form.markcopy'});
1204: }
1.329 droeschl 1205:
1.538 raeburn 1206: return if (@possibles == 0);
1.329 droeschl 1207: return if (!defined($env{'form.copyfolder'}));
1208:
1209: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1210: $env{'form.copyfolder'});
1.538 raeburn 1211: return if ($fatal);
1212:
1213: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1214:
1.538 raeburn 1215: # Retrieve current paste buffer suffixes.
1216: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1217: my (%pasteurls,@newpaste);
1218:
1219: # Construct identifiers for current contents of user's paste buffer
1220: if (@currpaste) {
1221: foreach my $suffix (@currpaste) {
1.667 raeburn 1222: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1223: my $url = $env{'docs.markedcopy_url_'.$suffix};
1224: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1225: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1226: ($url ne '')) {
1227: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1228: $pasteurls{$cid.'_'.$mapidx} = 1;
1229: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1230: $pasteurls{$url} = 1;
1231: } else {
1.669 raeburn 1232: $pasteurls{$cid.'_'.$url} = 1;
1.667 raeburn 1233: }
1234: }
1.538 raeburn 1235: }
1236: }
1237:
1238: # Mark items for copying (skip any items already in user's paste buffer)
1239: my %addtoenv;
1.597 raeburn 1240:
1241: my @pathitems = split(/\&/,$env{'form.folderpath'});
1242: my @folderconf = split(/\:/,$pathitems[-1]);
1.666 raeburn 1243: my $ispage = $folderconf[5];
1.597 raeburn 1244:
1.538 raeburn 1245: foreach my $item (@possibles) {
1246: my ($orderidx,$cmd) = split(/:/,$item);
1247: next if ($orderidx =~ /\D/);
1248: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1249: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1250: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1251: my %denied = &action_restrictions($coursenum,$coursedom,
1252: &LONCAPA::map::qtescape($url),
1253: $env{'form.folderpath'},\%curr_groups);
1254: next if ($denied{'copy'});
1255: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.667 raeburn 1256: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1257: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1258: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1259: next if (exists($pasteurls{$url}));
1260: } else {
1261: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1262: }
1.538 raeburn 1263: my ($suffix,$errortxt,$locknotfreed) =
1264: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1265: if ($suffix ne '') {
1266: push(@newpaste,$suffix);
1267: } else {
1268: if ($locknotfreed) {
1269: return $locknotfreed;
1270: }
1.538 raeburn 1271: }
1272: if (&is_supplemental_title($title)) {
1273: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1274: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1275: }
1.329 droeschl 1276:
1.538 raeburn 1277: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1278: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1279: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1280: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1281: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1282: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1283: my $prefix = $1;
1284: my $subdir =$2;
1285: if ($subdir eq '') {
1286: $subdir = $prefix;
1.492 raeburn 1287: }
1.538 raeburn 1288: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1289: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1290: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1291: if (ref($hierarchy{$url}) eq 'HASH') {
1292: my ($nested,$nestednames);
1293: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1294: $nested =~ s/\&$//;
1295: $nestednames =~ s/\Q___&&&___\E$//;
1296: if ($nested ne '') {
1297: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1298: }
1299: if ($nestednames ne '') {
1300: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1301: }
1.492 raeburn 1302: }
1303: }
1.591 raeburn 1304: if ($locknotfreed) {
1305: $output = $locknotfreed;
1306: last;
1307: }
1.492 raeburn 1308: }
1.538 raeburn 1309: if (@newpaste) {
1310: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1311: }
1.492 raeburn 1312: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1313: delete($env{'form.markcopy'});
1.591 raeburn 1314: return $output;
1.329 droeschl 1315: }
1316:
1.492 raeburn 1317: sub recurse_uploaded_maps {
1318: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1319: if (ref($hierarchy->{$url}) eq 'HASH') {
1320: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1321: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1322: my (@uploaded,@names,%shorter);
1323: for (my $i=0; $i<@maps; $i++) {
1324: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1325: if ($inner ne '') {
1326: push(@uploaded,$inner);
1327: push(@names,&escape($titles[$i]));
1328: $shorter{$maps[$i]} = $inner;
1329: }
1330: }
1331: $$nestref .= "$dir:".join(',',@uploaded).'&';
1332: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1333: foreach my $map (@maps) {
1334: if ($shorter{$map} ne '') {
1335: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1336: }
1337: }
1338: }
1339: return;
1340: }
1341:
1.329 droeschl 1342: sub print_paste_buffer {
1.492 raeburn 1343: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1344: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1345:
1.538 raeburn 1346: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1347: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1348: }
1349:
1.538 raeburn 1350: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1351: my ($pasteitems,@pasteable);
1.575 raeburn 1352: my $clipboardcount = 0;
1.488 raeburn 1353:
1.538 raeburn 1354: # Construct identifiers for current contents of user's paste buffer
1355: foreach my $suffix (@currpaste) {
1356: next if ($suffix =~ /\D/);
1357: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1358: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1359: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1360: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1361: ($url ne '')) {
1.575 raeburn 1362: $clipboardcount ++;
1.538 raeburn 1363: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1364: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1365: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1366: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1367: $is_external = 1;
1.626 raeburn 1368: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1369: $is_exttool = 1;
1.538 raeburn 1370: }
1371: if ($folder =~ /^supplemental/) {
1372: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1373: unless ($canpaste) {
1374: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1375: }
1376: } else {
1377: $canpaste = 1;
1378: }
1379: if ($canpaste) {
1380: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1381: my $srcdom = $1;
1382: my $srcnum = $2;
1383: my $rem = $3;
1384: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1385: $othercourse = 1;
1386: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1387: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1388: } else {
1389: $canpaste = 0;
1390: $nopaste = &mt('Paste from another course unavailable.');
1391: }
1392: }
1393: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1394: my $prefix = $1;
1395: $parent = $2;
1396: if ($folder !~ /^\Q$prefix\E/) {
1397: $areachange = 1;
1398: }
1399: $is_uploaded_map = 1;
1.492 raeburn 1400: }
1.597 raeburn 1401: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1402: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1403: if ($cid ne $env{'request.course.id'}) {
1404: my ($srcdom,$srcnum) = split(/_/,$cid);
1405: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1406: if (($is_exttool) && ($srcdom ne $coursedom)) {
1407: $canpaste = 0;
1408: $nopaste = &mt('Paste from another domain unavailable.');
1409: } else {
1410: $othercrs = '<br />'.&mt('(from another course)');
1411: }
1.596 raeburn 1412: } else {
1413: $canpaste = 0;
1414: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1415: }
1.596 raeburn 1416: }
1.492 raeburn 1417: }
1.596 raeburn 1418: if ($canpaste) {
1419: push(@pasteable,$suffix);
1.629 raeburn 1420: }
1.538 raeburn 1421: }
1422: my $buffer;
1.627 raeburn 1423: if ($is_external) {
1.538 raeburn 1424: $buffer = &mt('External Resource').': '.
1425: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1426: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1427: } elsif ($is_exttool) {
1428: $buffer = &mt('External Tool').': '.
1429: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1430: } else {
1431: my $icon = &Apache::loncommon::icon($extension);
1432: if ($extension eq 'sequence' &&
1433: $url =~ m{/default_\d+\.sequence$}x) {
1434: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1435: $icon .= '/navmap.folder.closed.gif';
1436: }
1.589 raeburn 1437: my $title = $env{'docs.markedcopy_title_'.$suffix};
1438: if ($title eq '') {
1439: ($title) = ($url =~ m{/([^/]+)$});
1440: }
1.538 raeburn 1441: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1442: ': '.
1443: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1444: &LONCAPA::map::qtescape($title));
1.538 raeburn 1445: }
1446: $pasteitems .= '<div class="LC_left_float">';
1447: my ($options,$onclick);
1448: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1449: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1450: if (($is_uploaded_map) ||
1451: ($url =~ /(bulletinboard|smppg)$/) ||
1452: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1453: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1454: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1455: }
1456: }
1457: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1458: if ($nopaste) {
1459: $pasteitems .= $nopaste;
1460: } else {
1461: if ($othercrs) {
1462: $pasteitems .= $othercrs;
1463: }
1464: if ($options) {
1465: $pasteitems .= $options;
1.492 raeburn 1466: }
1467: }
1.538 raeburn 1468: $pasteitems .= '</div>';
1469: }
1470: }
1471: if ($pasteitems eq '') {
1472: &Apache::lonnet::delenv('docs.markedcopies');
1473: }
1474: my ($pasteform,$form_start,$buttons,$form_end);
1475: if ($pasteitems) {
1476: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1477: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1478: if (@pasteable) {
1.575 raeburn 1479: my $value = &mt('Paste to current folder');
1480: if ($container eq 'page') {
1481: $value = &mt('Paste to current page');
1482: }
1483: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1484: }
1485: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1486: if ($clipboardcount > 1) {
1487: $buttons .=
1488: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1489: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1490: (' 'x2).
1491: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1492: (' 'x2);
1.492 raeburn 1493: }
1.575 raeburn 1494: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1495: '</form>';
1.538 raeburn 1496: } else {
1497: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1498: }
1.538 raeburn 1499: $r->print($form_start
1500: .'<fieldset>'
1501: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1502: .$pasteitems
1503: .'</fieldset>'
1504: .$form_end);
1505: }
1506:
1507: sub paste_options {
1508: my ($suffix,$is_uploaded_map,$parent) = @_;
1509: my ($copytext,$movetext);
1510: if ($is_uploaded_map) {
1511: $copytext = &mt('Copy to new folder');
1512: $movetext = &mt('Move old');
1513: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1514: $copytext = &mt('Copy to new board');
1515: $movetext = &mt('Move (not posts)');
1516: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1517: $copytext = &mt('Copy to new page');
1518: $movetext = &mt('Move');
1.533 raeburn 1519: } else {
1.538 raeburn 1520: $copytext = &mt('Copy to new file');
1521: $movetext = &mt('Move');
1522: }
1523: my $output = '<br />'.
1524: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1525: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1526: '<label>'.
1527: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1528: $copytext.'</label></span>'.(' 'x2).' '.
1529: '<span class="LC_nobreak"><label>'.
1530: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1531: $movetext.'</label></span>';
1532: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1533: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1534: '</legend><table border="0">';
1535: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1536: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1537: my $lastdir = $parent;
1538: my %depths = (
1539: $lastdir => 0,
1540: );
1541: my (%display,%deps);
1542: for (my $i=0; $i<@pastemaps; $i++) {
1543: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1544: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1545: my @subfolders = split(/,/,$subfolderstr);
1546: $deps{$lastdir} = \@subfolders;
1547: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1548: my $depth = $depths{$lastdir} + 1;
1549: my $offset = int($depth * 4);
1550: my $indent = (' ' x $offset);
1551: for (my $j=0; $j<@subfolders; $j++) {
1552: $depths{$subfolders[$j]} = $depth;
1553: $display{$subfolders[$j]} =
1554: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1555: '<td><label>'.
1556: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1557: '<label>'.
1558: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1559: &mt('Move old').'</label>'.
1560: '</td></tr>';
1561: }
1.492 raeburn 1562: }
1.538 raeburn 1563: &recurse_print(\$output,$parent,\%deps,\%display);
1564: $output .= '</table></fieldset>';
1.329 droeschl 1565: }
1.538 raeburn 1566: $output .= '</div>';
1567: return $output;
1.488 raeburn 1568: }
1569:
1.492 raeburn 1570: sub recurse_print {
1.538 raeburn 1571: my ($outputref,$dir,$deps,$display) = @_;
1572: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1573: if (ref($deps->{$dir}) eq 'ARRAY') {
1574: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1575: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1576: }
1577: }
1578: }
1579:
1.488 raeburn 1580: sub supp_pasteable {
1581: my ($url) = @_;
1582: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1583: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1584: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1585: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1586: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1587: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1588: return 1;
1589: }
1590: return;
1.329 droeschl 1591: }
1592:
1.492 raeburn 1593: sub paste_popup_js {
1.594 damieng 1594: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1595: show => 'Show Options',
1596: hide => 'Hide Options',
1.594 damieng 1597: );
1598: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1599: none => 'No items selected from clipboard.',
1.492 raeburn 1600: );
1.594 damieng 1601: &html_escape(\%html_js_lt);
1602: &js_escape(\%html_js_lt);
1603: &js_escape(\%js_lt);
1.492 raeburn 1604: return <<"END";
1605:
1.538 raeburn 1606: function showPasteOptions(suffix) {
1607: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1608: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1609: return;
1610: }
1611:
1.538 raeburn 1612: function hidePasteOptions(suffix) {
1613: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1614: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1615: return;
1616: }
1617:
1618: function showOptions(caller,suffix) {
1619: if (document.getElementById('pasteoptionstext_'+suffix)) {
1620: if (caller.checked) {
1.594 damieng 1621: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1622: } else {
1623: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1624: }
1625: if (document.getElementById('pasteoptions_'+suffix)) {
1626: document.getElementById('pasteoptions_'+suffix).style.display='none';
1627: }
1628: }
1.492 raeburn 1629: return;
1630: }
1631:
1.541 raeburn 1632: function validateClipboard() {
1633: var numchk = 0;
1634: if (document.pasteform.pasting.length > 1) {
1635: for (var i=0; i<document.pasteform.pasting.length; i++) {
1636: if (document.pasteform.pasting[i].checked) {
1637: numchk ++;
1638: }
1639: }
1640: } else {
1641: if (document.pasteform.pasting.type == 'checkbox') {
1642: if (document.pasteform.pasting.checked) {
1643: numchk ++;
1644: }
1645: }
1646: }
1647: if (numchk > 0) {
1648: return true;
1649: } else {
1.594 damieng 1650: alert("$js_lt{'none'}");
1.541 raeburn 1651: return false;
1652: }
1653: }
1654:
1.575 raeburn 1655: function checkClipboard() {
1656: if (document.pasteform.pasting.length > 1) {
1657: for (var i=0; i<document.pasteform.pasting.length; i++) {
1658: document.pasteform.pasting[i].checked = true;
1659: }
1660: }
1661: return;
1662: }
1663:
1664: function uncheckClipboard() {
1665: if (document.pasteform.pasting.length >1) {
1666: for (var i=0; i<document.pasteform.pasting.length; i++) {
1667: document.pasteform.pasting[i].checked = false;
1668: }
1669: }
1670: return;
1671: }
1672:
1.492 raeburn 1673: END
1674:
1675: }
1676:
1.329 droeschl 1677: sub do_paste_from_buffer {
1.492 raeburn 1678: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1679:
1.538 raeburn 1680: # Array of items in paste buffer
1681: my (@currpaste,%pastebuffer,%allerrors);
1682: @currpaste = split(/,/,$env{'docs.markedcopies'});
1683:
1.492 raeburn 1684: # Early out if paste buffer is empty
1.538 raeburn 1685: if (@currpaste == 0) {
1.492 raeburn 1686: return ();
1.538 raeburn 1687: }
1688: map { $pastebuffer{$_} = 1; } @currpaste;
1689:
1690: # Array of items selected items to paste
1691: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1692:
1693: # Early out if nothing selected to paste
1694: if (@reqpaste == 0) {
1695: return();
1696: }
1697: my @topaste;
1698: foreach my $suffix (@reqpaste) {
1699: next if ($suffix =~ /\D/);
1700: next unless (exists($pastebuffer{$suffix}));
1701: push(@topaste,$suffix);
1702: }
1703:
1704: # Early out if nothing available to paste
1705: if (@topaste == 0) {
1706: return();
1.329 droeschl 1707: }
1708:
1.627 raeburn 1709: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1710: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1711:
1712: foreach my $suffix (@topaste) {
1713: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1714: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1715: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1716: # Supplemental content may only include certain types of content
1717: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1718: if ($folder =~ /^supplemental/) {
1719: unless (&supp_pasteable($url)) {
1720: $notinsupp{$suffix} = 1;
1721: next;
1722: }
1.492 raeburn 1723: }
1.538 raeburn 1724: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1725: my $srcd = $1;
1726: my $srcn = $2;
1.492 raeburn 1727: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1728: # check for mdc privilege in the course from which the resource was pasted
1729: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1730: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1731: $notincrs{$suffix} = 1;
1732: next;
1733: }
1.491 raeburn 1734: }
1.538 raeburn 1735: $srcdom{$suffix} = $srcd;
1736: $srcnum{$suffix} = $srcn;
1.597 raeburn 1737: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1738: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1739: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1740: my ($srcd,$srcn) = split(/_/,$cid);
1741: # When paste buffer was populated using an active role in a different course
1742: # check for mdc privilege in the course from which the resource was pasted
1743: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1744: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1745: $notincrs{$suffix} = 1;
1746: next;
1747: }
1748: }
1.632 raeburn 1749: # When buffer was populated using an active role in a different course
1750: # disallow pasting of External Tool if course is in a different domain.
1751: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1752: $notindom{$suffix} = 1;
1753: next;
1754: }
1.596 raeburn 1755: $srcdom{$suffix} = $srcd;
1756: $srcnum{$suffix} = $srcn;
1.491 raeburn 1757: }
1.597 raeburn 1758: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1759: push(@dopaste,$suffix);
1760: if ($url=~/\.(page|sequence)$/) {
1761: $is_map{$suffix} = 1;
1762: }
1763: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1764: my $oldprefix = $1;
1.492 raeburn 1765: # When pasting content from Main Content to Supplemental Content and vice versa
1766: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1767: # a folder/page or a document).
1.538 raeburn 1768: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1769: $prefixchg{$suffix} = 'docstosupp';
1770: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1771: $prefixchg{$suffix} = 'supptodocs';
1772: }
1.491 raeburn 1773:
1.492 raeburn 1774: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1775: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1776: my @nested;
1777: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1778: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1779: my @deps = map { /\d+:([\d,]+$)/ } @items;
1780: foreach my $dep (@deps) {
1781: if ($dep =~ /,/) {
1782: push(@nested,split(/,/,$dep));
1783: } else {
1784: push(@nested,$dep);
1785: }
1.492 raeburn 1786: }
1.538 raeburn 1787: foreach my $item (@nested) {
1788: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1789: push(@{$marktomove{$suffix}},$type.'_'.$item);
1790: }
1.492 raeburn 1791: }
1792: }
1.488 raeburn 1793: }
1794: }
1795:
1.538 raeburn 1796: # Early out if nothing available to paste
1797: if (@dopaste == 0) {
1798: return ();
1799: }
1800:
1801: # Populate message hash and hashes used for main content <=> supplemental content
1802: # changes
1803:
1804: %msgs = &Apache::lonlocal::texthash (
1805: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1806: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1807: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538 raeburn 1808: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1809: );
1810:
1811: %before = (
1812: docstosupp => {
1813: map => 'default',
1814: doc => 'docs',
1815: },
1816: supptodocs => {
1817: map => 'supplemental',
1818: doc => 'supplemental',
1819: },
1820: );
1821:
1822: %after = (
1823: docstosupp => {
1824: map => 'supplemental',
1825: doc => 'supplemental'
1826: },
1827: supptodocs => {
1828: map => 'default',
1829: doc => 'docs',
1830: },
1831: );
1832:
1833: # Retrieve information about all course maps in main content area
1834:
1835: my $allmaps = {};
1.660 raeburn 1836: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538 raeburn 1837:
1838: # Loop over the items to paste
1839: foreach my $suffix (@dopaste) {
1.329 droeschl 1840: # Maps need to be copied first
1.538 raeburn 1841: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1842: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1843: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1844: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1845: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1846: }
1847: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1848: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1849: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1850: my $oldurl = $url;
1851: if ($is_map{$suffix}) {
1.491 raeburn 1852: # If pasting a map, check if map contains other maps
1.538 raeburn 1853: my (%hierarchy,%titles);
1.660 raeburn 1854: if (($folder =~ /^default/) && (!$donechk)) {
1855: $allmaps =
1856: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1857: $env{"course.$env{'request.course.id'}.home"},
1858: $env{'request.course.id'});
1859: $donechk = 1;
1860: }
1.627 raeburn 1861: &contained_map_check($url,$folder,$coursenum,$coursedom,
1862: \%removefrommap,\%removeparam,\%addedmaps,
1863: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1864: if ($url=~ m{^/uploaded/}) {
1865: my $newurl;
1866: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1867: ($newurl,my $error) =
1868: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1869: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1870: \$title,$allmaps,\%newurls);
1871: if ($error) {
1872: $allerrors{$suffix} = $error;
1873: next;
1874: }
1875: if ($newurl ne '') {
1876: if ($newurl ne $url) {
1877: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1878: $newsubdir{$url} = $1;
1879: }
1880: $mapchanges{$url} = 1;
1.492 raeburn 1881: }
1.538 raeburn 1882: }
1883: }
1884: if (($srcdom{$suffix} ne $coursedom) ||
1885: ($srcnum{$suffix} ne $coursenum) ||
1886: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1887: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1888: $coursedom,$coursenum,$srcdom{$suffix},
1889: $srcnum{$suffix},$allmaps,\%rewrites,
1890: \%retitles,\%copies,\%dbcopies,
1891: \%zombies,\%params,\%mapmoves,
1892: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1893: \%newurls,\%resdatacopy)) {
1.538 raeburn 1894: $mapmoves{$url} = 1;
1895: }
1896: $url = $newurl;
1897: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1898: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1899: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1900: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1901: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1902: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1903: }
1904: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1905: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1906: push(@toclear,$suffix);
1907: # if pasting published map (main content area only) check map not already in course
1908: if ($folder =~ /^default/) {
1909: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1910: $duplicate{$suffix} = 1;
1911: next;
1.492 raeburn 1912: }
1.491 raeburn 1913: }
1914: }
1.538 raeburn 1915: }
1.627 raeburn 1916: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1917: my $prefix = $1;
1.648 raeburn 1918: my $fromothercrs;
1.538 raeburn 1919: #need to copy the db contents to a new one, unless this is a move.
1920: my %info = (
1921: src => $url,
1922: cdom => $coursedom,
1923: cnum => $coursenum,
1.596 raeburn 1924: );
1.649 raeburn 1925: if ($prefix eq 'ext.tool') {
1.655 raeburn 1926: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 1927: $info{'delgradable'} = 1;
1928: }
1929: }
1.596 raeburn 1930: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1931: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1932: $fromothercrs = 1;
1933: $info{'cdom'} = $srcdom{$suffix};
1934: $info{'cnum'} = $srcnum{$suffix};
1935: }
1936: }
1937: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 1938: my (%lockerr,$msg);
1.538 raeburn 1939: my ($newurl,$result,$errtext) =
1940: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1941: if ($result eq 'ok') {
1942: $url = $newurl;
1943: $title=&mt('Copy of').' '.$title;
1944: } else {
1945: if ($prefix eq 'smppg') {
1946: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1947: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1948: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 1949: } elsif ($prefix eq 'ext.tool') {
1950: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 1951: }
1952: $results{$suffix} = $result;
1953: $msgerrs{$suffix} = $msg;
1954: $lockerrs{$suffix} = $lockerr{$prefix};
1955: next;
1956: }
1957: if ($lockerr{$prefix}) {
1958: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1959: }
1.489 raeburn 1960: }
1961: }
1.538 raeburn 1962: $title = &LONCAPA::map::qtunescape($title);
1963: my $ext='false';
1964: if ($url=~m{^http(|s)://}) { $ext='true'; }
1965: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1966: if ($folder !~ /^supplemental/) {
1967: (undef,undef,$title) =
1968: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1969: }
1970: } else {
1971: if ($folder=~/^supplemental/) {
1972: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1973: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1974: }
1.533 raeburn 1975: }
1.491 raeburn 1976:
1977: # For uploaded files (excluding pages/sequences) path in copied file is changed
1978: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1979: # courses.
1980:
1.538 raeburn 1981: unless ($is_map{$suffix}) {
1982: my $newidx;
1.492 raeburn 1983: # Now insert the URL at the bottom
1.538 raeburn 1984: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1985: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1986: my $relpath = $1;
1987: if ($relpath ne '') {
1988: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1989: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1990: my $newprefix = $newloc;
1991: if ($newloc eq 'default') {
1992: $newprefix = 'docs';
1993: }
1994: if ($newdocsdir eq '') {
1995: $newdocsdir = 'default';
1996: }
1.630 raeburn 1997: if (($prefixchg{$suffix}) ||
1998: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 1999: ($srcnum{$suffix} ne $coursenum) ||
2000: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2001: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2002: $url =
2003: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2004: &Apache::lonnet::getfile($oldurl));
2005: if ($url eq '/adm/notfound.html') {
2006: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2007: next;
2008: } else {
2009: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2010: $newsubpath =~ s{/+$}{/};
2011: $docmoves{$oldurl} = $newsubpath;
2012: }
1.491 raeburn 2013: }
2014: }
1.597 raeburn 2015: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2016: my $template = $1;
2017: if ($newidx) {
2018: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2019: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2020: }
1.649 raeburn 2021: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2022: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2023: my $marker = (split(m{/},$url))[4];
2024: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2025: my $val = 'no';
2026: if ($toolsettings{'gradable'}) {
2027: $val = 'yes';
2028: }
2029: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2030: 'string_yesno');
2031: &remember_parms($newidx,'gradable','set',$val);
2032: }
1.491 raeburn 2033: }
1.538 raeburn 2034: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2035: ':'.$ext.':normal:res';
2036: push(@LONCAPA::map::order,$newidx);
2037: # Store the result
2038: my ($errtext,$fatal) =
2039: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2040: if ($fatal) {
2041: $save_err .= $errtext;
2042: $allresult = 'fail';
2043: }
1.488 raeburn 2044: }
1.538 raeburn 2045:
1.597 raeburn 2046: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2047: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2048: unless ($allresult eq 'fail') {
2049: my %updated = (
2050: rewrites => \%rewrites,
2051: zombies => \%zombies,
2052: removefrommap => \%removefrommap,
2053: removeparam => \%removeparam,
2054: dbcopies => \%dbcopies,
1.597 raeburn 2055: resdatacopy => \%resdatacopy,
1.538 raeburn 2056: retitles => \%retitles,
2057: );
2058: my %info = (
2059: newsubdir => \%newsubdir,
2060: params => \%params,
2061: );
2062: if ($prefixchg{$suffix}) {
2063: $info{'before'} = $before{$prefixchg{$suffix}};
2064: $info{'after'} = $after{$prefixchg{$suffix}};
2065: }
2066: my %moves = (
2067: copies => \%copies,
2068: docmoves => \%docmoves,
2069: mapmoves => \%mapmoves,
2070: );
2071: (my $result,$msgs{$suffix},my $lockerror) =
2072: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2073: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2074: $url,'paste');
2075: $lockerrors .= $lockerror;
2076: if ($result eq 'ok') {
2077: if ($is_map{$suffix}) {
2078: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2079: $folder.'.'.$container);
2080: if ($fatal) {
2081: $allresult = 'failread';
2082: } else {
2083: if ($#LONCAPA::map::order<1) {
2084: my $idx=&LONCAPA::map::getresidx();
2085: if ($idx<=0) { $idx=1; }
2086: $LONCAPA::map::order[0]=$idx;
2087: $LONCAPA::map::resources[$idx]='';
2088: }
2089: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2090: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2091: ':'.$ext.':normal:res';
2092: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2093:
2094: # Store the result
1.538 raeburn 2095: my ($errtext,$fatal) =
2096: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2097: if ($fatal) {
2098: $save_err .= $errtext;
2099: $allresult = 'failstore';
2100: }
2101: }
2102: }
2103: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2104: push(@toclear,$suffix);
2105: }
2106: }
1.492 raeburn 2107: }
2108: }
1.538 raeburn 2109: &clear_from_buffer(\@toclear,\@currpaste);
2110: my $msgsarray;
2111: foreach my $suffix (keys(%msgs)) {
2112: if (ref($msgs{$suffix}) eq 'ARRAY') {
2113: $msgsarray .= join(',',@{$msgs{$suffix}});
2114: }
2115: }
2116: return ($allresult,$save_err,$msgsarray,$lockerrors);
2117: }
1.533 raeburn 2118:
1.538 raeburn 2119: sub do_buffer_empty {
2120: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2121: if (@currpaste == 0) {
2122: return &mt('Clipboard is already empty');
2123: }
2124: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2125: if (@toclear == 0) {
2126: return &mt('Nothing selected to clear from clipboard');
2127: }
2128: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2129: if ($numdel) {
2130: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2131: } else {
2132: return &mt('Clipboard unchanged');
1.492 raeburn 2133: }
1.538 raeburn 2134: return;
2135: }
2136:
2137: sub clear_from_buffer {
2138: my ($toclear,$currpaste) = @_;
2139: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2140: my %pastebuffer;
2141: map { $pastebuffer{$_} = 1; } @{$currpaste};
2142: my $numdel = 0;
2143: foreach my $suffix (@{$toclear}) {
2144: next if ($suffix =~ /\D/);
2145: next unless (exists($pastebuffer{$suffix}));
2146: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2147: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2148: delete($pastebuffer{$suffix});
2149: $numdel ++;
2150: }
2151: }
2152: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2153: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2154: return $numdel;
1.492 raeburn 2155: }
2156:
2157: sub get_newmap_url {
2158: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2159: $titleref,$allmaps,$newurls) = @_;
2160: my $newurl;
2161: if ($url=~ m{^/uploaded/}) {
2162: $$titleref=&mt('Copy of').' '.$$titleref;
2163: }
2164: my $now = time;
2165: my $suffix=$$.int(rand(100)).$now;
2166: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2167: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2168: my $path = $1;
2169: my $prefix = $2;
2170: my $ancestor = $3;
2171: if (length($ancestor) > 10) {
2172: $ancestor = substr($ancestor,-10,10);
2173: }
2174: my $newid;
2175: if ($prefixchg) {
2176: if ($folder =~ /^supplemental/) {
2177: $prefix =~ s/^default/supplemental/;
2178: } else {
2179: $prefix =~ s/^supplemental/default/;
2180: }
2181: }
2182: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2183: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2184: } else {
2185: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2186: }
2187: my $counter = 0;
2188: my $is_unique = &uniqueness_check($newurl);
2189: if ($folder =~ /^default/) {
2190: if ($allmaps->{$newurl}) {
2191: $is_unique = 0;
2192: }
2193: }
2194: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2195: $counter ++;
2196: $suffix ++;
2197: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2198: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2199: } else {
2200: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2201: }
2202: $is_unique = &uniqueness_check($newurl);
2203: }
2204: if ($is_unique) {
2205: $newurls->{$newurl} = 1;
2206: } else {
2207: if ($url=~/\.page$/) {
2208: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2209: } else {
2210: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2211: }
2212: }
1.329 droeschl 2213: }
1.492 raeburn 2214: return ($newurl);
1.329 droeschl 2215: }
2216:
1.488 raeburn 2217: sub dbcopy {
1.533 raeburn 2218: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2219: my ($url,$result,$errtext);
2220: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2221: $url = $dbref->{'src'};
1.627 raeburn 2222: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2223: my $prefix = $1;
1.627 raeburn 2224: if ($prefix eq 'ext.tool') {
2225: $prefix = 'exttool';
2226: }
1.533 raeburn 2227: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2228: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2229: my $db_name;
2230: my $marker = (split(m{/},$url))[4];
2231: $marker=~s/\D//g;
2232: if ($dbref->{'src'} =~ m{/smppg$}) {
2233: $db_name =
2234: &Apache::lonsimplepage::get_db_name($url,$marker,
2235: $dbref->{'cdom'},
2236: $dbref->{'cnum'});
1.627 raeburn 2237: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2238: $db_name = 'exttool_'.$marker;
1.533 raeburn 2239: } else {
2240: $db_name = 'bulletinpage_'.$marker;
2241: }
2242: my ($suffix,$freedlock,$error) =
2243: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2244: $coursedom,$coursenum,
2245: 'concat');
2246: if (!$suffix) {
2247: if ($prefix eq 'smppg') {
2248: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2249: } elsif ($prefix eq 'exttool') {
2250: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2251: } else {
1.565 bisitz 2252: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2253: }
2254: if ($error) {
2255: $errtext .= '<br />'.$error;
2256: }
2257: } else {
2258: #need to copy the db contents to a new one.
2259: my %contents=&Apache::lonnet::dump($db_name,
2260: $dbref->{'cdom'},
2261: $dbref->{'cnum'});
2262: if (exists($contents{'uploaded.photourl'})) {
2263: my $photo = $contents{'uploaded.photourl'};
2264: my ($subdir,$fname) =
2265: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2266: my $newphoto;
1.533 raeburn 2267: if ($fname ne '') {
2268: my $content = &Apache::lonnet::getfile($photo);
2269: unless ($content eq '-1') {
2270: $env{'form.'.$suffix.'.photourl'} = $content;
2271: $newphoto =
2272: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2273: delete($env{'form.'.$suffix.'.photourl'});
2274: }
2275: }
2276: if ($newphoto =~ m{^/uploaded/}) {
2277: $contents{'uploaded.photourl'} = $newphoto;
2278: }
2279: }
2280: $db_name =~ s{_\d*$ }{_$suffix}x;
1.649 raeburn 2281: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2282: delete($contents{'gradable'});
2283: }
1.533 raeburn 2284: $result=&Apache::lonnet::put($db_name,\%contents,
2285: $coursedom,$coursenum);
2286: if ($result eq 'ok') {
1.627 raeburn 2287: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2288: }
2289: }
2290: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2291: $lockerrorsref->{$prefix} =
1.533 raeburn 2292: '<div class="LC_error">'.
2293: &mt('There was a problem removing a lockfile.');
2294: if ($prefix eq 'smppg') {
1.560 raeburn 2295: $lockerrorsref->{$prefix} .=
1.559 raeburn 2296: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2297: } elsif ($prefix eq 'exttool') {
2298: $lockerrorsref->{$prefix} .=
2299: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2300: } else {
1.565 bisitz 2301: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2302: }
1.560 raeburn 2303: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2304: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2305: '</div>';
1.533 raeburn 2306: }
2307: }
2308: } elsif ($url =~ m{/syllabus$}) {
2309: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2310: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2311: if (($dbref->{'cdom'} ne $coursedom) ||
2312: ($dbref->{'cnum'} ne $coursenum)) {
2313: my %contents=&Apache::lonnet::dump('syllabus',
2314: $dbref->{'cdom'},
2315: $dbref->{'cnum'});
2316: $result=&Apache::lonnet::put('syllabus',\%contents,
2317: $coursedom,$coursenum);
2318: }
2319: }
1.488 raeburn 2320: }
2321: }
1.533 raeburn 2322: return ($url,$result,$errtext);
1.488 raeburn 2323: }
2324:
1.597 raeburn 2325: sub copy_templated_files {
2326: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2327: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2328: my $srccontainer = 'sequence';
2329: if ($srcwaspage) {
2330: $srccontainer = 'page';
2331: }
2332: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2333: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2334: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2335: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2336: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2337: $template.'.problem';
2338: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2339: if ($template eq 'simpleproblem') {
2340: $srcprefix .= '.0.';
2341: my $weightprefix = $newprefix;
2342: $newprefix .= '.0.';
2343: my @simpleprobqtypes = qw(radio option string essay numerical);
2344: my $qtype=$srcparms{$srcprefix.'questiontype'};
2345: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
1.665 raeburn 2346: my %newdata = (
2347: $newprefix.'questiontype' => $qtype,
2348: );
1.597 raeburn 2349: foreach my $type (@simpleprobqtypes) {
2350: if ($type eq $qtype) {
2351: $newdata{"$weightprefix.$type.weight"}=1;
2352: } else {
2353: $newdata{"$weightprefix.$type.weight"}=0;
2354: }
2355: }
2356: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2357: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2358: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2359: if ($qtype eq 'numerical') {
2360: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2361: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2362: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2363: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2364: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2365: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2366: unless (defined($maxfoils)) { $maxfoils=10; }
2367: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2368: if ($maxfoils<=0) { $maxfoils=10; }
2369: my $randomize=$srcparms{$srcprefix.'randomize'};
2370: unless (defined($randomize)) { $randomize='yes'; }
2371: unless ($randomize eq 'no') { $randomize='yes'; }
2372: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2373: $newdata{$newprefix.'randomize'} = $randomize;
2374: if ($qtype eq 'option') {
2375: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2376: }
2377: for (my $i=1; $i<=10; $i++) {
2378: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2379: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2380: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2381: }
2382:
2383: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2384: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2385: unless (defined($maxfoils)) { $maxfoils=10; }
2386: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2387: if ($maxfoils<=0) { $maxfoils=10; }
2388: my $randomize=$srcparms{$srcprefix.'randomize'};
2389: unless (defined($randomize)) { $randomize='yes'; }
2390: unless ($randomize eq 'no') { $randomize='yes'; }
2391: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2392: $newdata{$newprefix.'randomize'} = $randomize;
2393: if ($qtype eq 'option') {
2394: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2395: }
2396: for (my $i=1; $i<=10; $i++) {
2397: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2398: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2399: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2400: }
2401: } elsif ($qtype eq 'string') {
2402: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2403: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2404: }
2405: if (keys(%newdata)) {
2406: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2407: $coursenum);
2408: if ($putres eq 'ok') {
2409: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2410: }
2411: }
2412: }
2413: }
2414: }
2415:
1.329 droeschl 2416: sub uniqueness_check {
2417: my ($newurl) = @_;
2418: my $unique = 1;
2419: foreach my $res (@LONCAPA::map::order) {
2420: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2421: $url=&LONCAPA::map::qtescape($url);
2422: if ($newurl eq $url) {
2423: $unique = 0;
1.344 bisitz 2424: last;
1.329 droeschl 2425: }
2426: }
2427: return $unique;
2428: }
2429:
1.488 raeburn 2430: sub contained_map_check {
1.627 raeburn 2431: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2432: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2433: my $content = &Apache::lonnet::getfile($url);
2434: unless ($content eq '-1') {
2435: my $parser = HTML::TokeParser->new(\$content);
2436: $parser->attr_encoded(1);
2437: while (my $token = $parser->get_token) {
2438: next if ($token->[0] ne 'S');
2439: if ($token->[1] eq 'resource') {
2440: next if ($token->[2]->{'type'} eq 'zombie');
2441: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2442: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2443: my $srcdom = $1;
2444: unless ($srcdom eq $coursedom) {
2445: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2446: next;
2447: }
2448: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2449: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2450: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2451: next;
2452: }
2453: }
1.492 raeburn 2454: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2455: if ($1 eq 'uploaded') {
2456: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2457: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2458: } else {
1.492 raeburn 2459: if ($allmaps->{$ressrc}) {
1.529 raeburn 2460: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2461: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2462: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2463: } else {
2464: $addedmaps->{$ressrc} = [$url];
2465: }
1.488 raeburn 2466: }
1.627 raeburn 2467: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2468: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2469: }
1.492 raeburn 2470: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2471: if ($folder =~ /^supplemental/) {
1.492 raeburn 2472: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2473: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2474: } else {
2475: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2476: }
1.488 raeburn 2477: }
2478: }
2479: }
2480: }
2481: return;
2482: }
2483:
2484: sub url_paste_fixups {
1.533 raeburn 2485: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2486: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2487: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2488: my $checktitle;
2489: if (($prefixchg) &&
1.492 raeburn 2490: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2491: $checktitle = 1;
2492: }
1.492 raeburn 2493: my $skip;
2494: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2495: my $mapid = $1.$2;
2496: if ($tomove->{$mapid}) {
2497: $skip = 1;
2498: }
2499: }
1.491 raeburn 2500: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2501: return if ($file eq '-1');
2502: my $parser = HTML::TokeParser->new(\$file);
2503: $parser->attr_encoded(1);
1.491 raeburn 2504: my $changed = 0;
1.488 raeburn 2505: while (my $token = $parser->get_token) {
2506: next if ($token->[0] ne 'S');
2507: if ($token->[1] eq 'resource') {
2508: my $ressrc = $token->[2]->{'src'};
2509: next if ($ressrc eq '');
1.491 raeburn 2510: my $id = $token->[2]->{'id'};
1.492 raeburn 2511: my $title = $token->[2]->{'title'};
1.491 raeburn 2512: if ($checktitle) {
2513: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2514: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2515: }
2516: }
1.488 raeburn 2517: next if ($token->[2]->{'type'} eq 'external');
2518: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2519: next if ($skip);
1.532 raeburn 2520: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2521: $changed = 1;
2522: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2523: my $srcdom = $1;
2524: my $srcnum = $2;
1.488 raeburn 2525: my $rem = $3;
1.492 raeburn 2526: my $newurl;
2527: my $mapname;
2528: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2529: my $prefix = $1;
2530: $mapname = $prefix.$2;
2531: if ($tomove->{$mapname}) {
1.533 raeburn 2532: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2533: $srcdom,$srcnum,$allmaps,$rewrites,
2534: $retitles,$copies,$dbcopies,$zombies,
2535: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2536: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2537: next;
2538: } else {
2539: ($newurl,my $error) =
2540: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2541: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2542: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2543: $newsubdir->{$ressrc} = $1;
2544: }
2545: if ($error) {
2546: next;
2547: }
2548: }
2549: }
2550: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2551: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2552:
1.488 raeburn 2553: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2554: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2555: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2556: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2557: $cnum,$srcdom,$srcnum,$allmaps,
2558: $rewrites,$retitles,$copies,$dbcopies,
2559: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2560: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2561: $mapmoves->{$ressrc} = 1;
2562: }
2563: $changed = 1;
1.488 raeburn 2564: } else {
1.532 raeburn 2565: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2566: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2567: $changed = 1;
1.488 raeburn 2568: }
2569: }
1.649 raeburn 2570: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2571: next if ($skip);
1.492 raeburn 2572: my $srcdom = $1;
2573: my $srcnum = $2;
1.649 raeburn 2574: my $rem = $3;
2575: my ($is_exttool,$exttoolchg);
2576: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2577: $is_exttool = 1;
1.649 raeburn 2578: }
1.492 raeburn 2579: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2580: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2581: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2582: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2583: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2584: $changed = 1;
1.649 raeburn 2585: if ($is_exttool) {
2586: $exttoolchg = 1;
2587: }
2588: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2589: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2590: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2591: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2592: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2593: $changed = 1;
2594: $exttoolchg = 1;
2595: }
2596: if (($is_exttool) && ($prefixchg)) {
2597: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2598: if ($exttoolchg) {
2599: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2600: }
2601: }
1.533 raeburn 2602: }
2603: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2604: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2605: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2606: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2607: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2608: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2609: $changed = 1;
1.488 raeburn 2610: }
1.597 raeburn 2611: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2612: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2613: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2614: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2615: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2616: }
1.488 raeburn 2617: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2618: next if ($skip);
2619: my $srcdom = $1;
2620: my $srcnum = $2;
2621: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2622: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2623: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2624: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2625: $changed = 1;
1.488 raeburn 2626: }
2627: }
2628: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2629: next if ($skip);
1.488 raeburn 2630: my $to = $token->[2]->{'to'};
2631: if ($to ne '') {
2632: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2633: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2634: } else {
2635: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2636: }
2637: }
2638: }
2639: }
1.491 raeburn 2640: return $changed;
1.488 raeburn 2641: }
2642:
2643: sub apply_fixups {
1.529 raeburn 2644: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2645: $oldurl,$url,$caller) = @_;
2646: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2647: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2648: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2649: if (ref($updated) eq 'HASH') {
2650: if (ref($updated->{'rewrites'}) eq 'HASH') {
2651: %rewrites = %{$updated->{'rewrites'}};
2652: }
2653: if (ref($updated->{'zombies'}) eq 'HASH') {
2654: %zombies = %{$updated->{'zombies'}};
2655: }
2656: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2657: %removefrommap = %{$updated->{'removefrommap'}};
2658: }
2659: if (ref($updated->{'removeparam'}) eq 'HASH') {
2660: %removeparam = %{$updated->{'removeparam'}};
2661: }
2662: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2663: %dbcopies = %{$updated->{'dbcopies'}};
2664: }
2665: if (ref($updated->{'retitles'}) eq 'HASH') {
2666: %retitles = %{$updated->{'retitles'}};
2667: }
1.597 raeburn 2668: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2669: %resdatacopy = %{$updated->{'resdatacopy'}};
2670: }
1.529 raeburn 2671: }
2672: if (ref($info) eq 'HASH') {
2673: if (ref($info->{'newsubdir'}) eq 'HASH') {
2674: %newsubdir = %{$info->{'newsubdir'}};
2675: }
2676: if (ref($info->{'params'}) eq 'HASH') {
2677: %params = %{$info->{'params'}};
2678: }
2679: if (ref($info->{'before'}) eq 'HASH') {
2680: %before = %{$info->{'before'}};
2681: }
2682: if (ref($info->{'after'}) eq 'HASH') {
2683: %after = %{$info->{'after'}};
2684: }
2685: }
2686: if (ref($moves) eq 'HASH') {
2687: if (ref($moves->{'copies'}) eq 'HASH') {
2688: %copies = %{$moves->{'copies'}};
2689: }
2690: if (ref($moves->{'docmoves'}) eq 'HASH') {
2691: %docmoves = %{$moves->{'docmoves'}};
2692: }
2693: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2694: %mapmoves = %{$moves->{'mapmoves'}};
2695: }
2696: }
2697: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2698: my @allcopies;
1.529 raeburn 2699: if (exists($copies{$key})) {
2700: if (ref($copies{$key}) eq 'HASH') {
2701: my %added;
2702: foreach my $innerkey (keys(%{$copies{$key}})) {
2703: if (($innerkey ne '') && (!$added{$innerkey})) {
2704: push(@allcopies,$innerkey);
2705: $added{$innerkey} = 1;
2706: }
1.491 raeburn 2707: }
1.529 raeburn 2708: undef(%added);
1.491 raeburn 2709: }
2710: }
2711: if ($key eq $oldurl) {
1.529 raeburn 2712: if ((exists($docmoves{$key}))) {
1.532 raeburn 2713: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2714: push(@allcopies,$oldurl);
2715: }
2716: }
2717: }
2718: if (@allcopies > 0) {
2719: foreach my $item (@allcopies) {
1.492 raeburn 2720: my ($relpath,$oldsubdir,$fname) =
2721: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2722: if ($fname ne '') {
2723: my $content = &Apache::lonnet::getfile($item);
2724: unless ($content eq '-1') {
2725: my $storefn;
1.529 raeburn 2726: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2727: $storefn = $docmoves{$key};
1.491 raeburn 2728: } else {
2729: $storefn = $relpath;
2730: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2731: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2732: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2733: }
1.529 raeburn 2734: if ($newsubdir{$key}) {
1.532 raeburn 2735: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2736: }
2737: }
2738: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2739: my $copyurl =
2740: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2741: $storefn.$fname,$content);
2742: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2743: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2744: return &mt('Paste failed: an error occurred copying the file.');
2745: } elsif (ref($errors) eq 'HASH') {
2746: $errors->{$item} = 1;
1.489 raeburn 2747: }
2748: }
1.488 raeburn 2749: }
2750: }
1.491 raeburn 2751: }
2752: }
2753: }
1.529 raeburn 2754: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2755: my $storefn=$key;
2756: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2757: if ($prefixchg && $before{'map'} && $after{'map'}) {
2758: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2759: }
1.529 raeburn 2760: if ($newsubdir{$key}) {
2761: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2762: }
1.491 raeburn 2763: my $mapcontent = &Apache::lonnet::getfile($key);
2764: if ($mapcontent eq '-1') {
2765: if (ref($errors) eq 'HASH') {
2766: $errors->{$key} = 1;
2767: }
2768: } else {
2769: my $newmap =
2770: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2771: $mapcontent);
2772: if ($newmap eq '/adm/notfound.html') {
2773: if (ref($errors) eq 'HASH') {
2774: $errors->{$key} = 1;
1.489 raeburn 2775: }
1.488 raeburn 2776: }
2777: }
2778: }
1.491 raeburn 2779: my %updates;
2780: if ($is_map) {
1.529 raeburn 2781: if (ref($updated) eq 'HASH') {
2782: foreach my $type (keys(%{$updated})) {
2783: if (ref($updated->{$type}) eq 'HASH') {
2784: foreach my $key (keys(%{$updated->{$type}})) {
2785: $updates{$key} = 1;
2786: }
2787: }
2788: }
1.491 raeburn 2789: }
2790: foreach my $key (keys(%updates)) {
1.492 raeburn 2791: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2792: if (ref($rewrites{$key}) eq 'HASH') {
2793: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2794: }
1.529 raeburn 2795: if (ref($retitles{$key}) eq 'HASH') {
2796: %toretitle = %{$retitles{$key}};
1.491 raeburn 2797: }
1.529 raeburn 2798: if (ref($removefrommap{$key}) eq 'HASH') {
2799: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2800: }
1.529 raeburn 2801: if (ref($removeparam{$key}) eq 'HASH') {
2802: %remparam = %{$removeparam{$key}};
1.492 raeburn 2803: }
1.529 raeburn 2804: if (ref($zombies{$key}) eq 'HASH') {
2805: %zombie = %{$zombies{$key}};
1.491 raeburn 2806: }
1.529 raeburn 2807: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2808: foreach my $idx (keys(%{$dbcopies{$key}})) {
2809: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2810: my ($newurl,$result,$errtext) =
2811: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2812: if ($result eq 'ok') {
2813: $newdb{$idx} = $newurl;
2814: } elsif (ref($errors) eq 'HASH') {
2815: $errors->{$key} = 1;
2816: }
2817: push(@msgs,$errtext);
2818: }
1.491 raeburn 2819: }
2820: }
1.597 raeburn 2821: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 raeburn 2822: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2823: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2824: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2825: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2826: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2827: my $template = $1;
2828: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2829: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2830: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2831: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 raeburn 2832: unless ($gotnewmapname) {
2833: ($newmapname) = ($key =~ m{/([^/]+)$});
2834: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2835: if ($newsubdir{$key}) {
2836: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2837: }
2838: $gotnewmapname = 1;
2839: }
1.597 raeburn 2840: my $srcmapinfo = $srcfolder.':'.$idx;
2841: if ($srccontainer eq 'page') {
2842: $srcmapinfo .= ':1';
2843: }
2844: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2845: $cnum,$template,$idx,$newmapname);
2846: }
2847: }
2848: }
2849: }
2850: }
1.529 raeburn 2851: if (ref($params{$key}) eq 'HASH') {
2852: %currparam = %{$params{$key}};
1.492 raeburn 2853: }
2854: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2855: if ($fatal) {
1.533 raeburn 2856: return ($errtext);
1.492 raeburn 2857: }
2858: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2859: if (defined($LONCAPA::map::zombies[$i])) {
2860: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2861: if ($zombie{$i} eq $src) {
1.492 raeburn 2862: undef($LONCAPA::map::zombies[$i]);
2863: }
2864: }
2865: }
1.646 raeburn 2866: my $total = scalar(@LONCAPA::map::order) - 1;
2867: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2868: my $idx = $LONCAPA::map::order[$i];
2869: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2870: my $changed;
1.529 raeburn 2871: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2872: if ((exists($toremove{$idx})) &&
2873: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2874: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2875: if (ref($currparam{$idx}) eq 'ARRAY') {
2876: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2877: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2878: }
2879: }
2880: next;
2881: }
2882: my $origsrc = $src;
1.532 raeburn 2883: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2884: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2885: $changed = 1;
1.491 raeburn 2886: }
1.492 raeburn 2887: }
1.532 raeburn 2888: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2889: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2890: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2891: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2892: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2893: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2894: } else {
1.529 raeburn 2895: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2896: }
1.491 raeburn 2897: }
1.532 raeburn 2898: if ($origsrc =~ /\.(page|sequence)$/) {
2899: if ($newsubdir{$origsrc}) {
1.529 raeburn 2900: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2901: }
1.532 raeburn 2902: } elsif ($newsubdir{$key}) {
2903: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2904: }
2905: }
1.492 raeburn 2906: $changed = 1;
1.533 raeburn 2907: } elsif ($newdb{$idx} ne '') {
2908: $src = $newdb{$idx};
1.492 raeburn 2909: $changed = 1;
2910: }
2911: if ($changed) {
1.538 raeburn 2912: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2913: }
2914: }
2915: }
2916: foreach my $idx (keys(%remparam)) {
2917: if (ref($remparam{$idx}) eq 'ARRAY') {
2918: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 2919: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 2920: }
2921: }
2922: }
1.533 raeburn 2923: if (values(%lockerrors) > 0) {
2924: $lockmsg = join('<br />',values(%lockerrors));
2925: }
1.491 raeburn 2926: my $storefn;
2927: if ($key eq $oldurl) {
2928: $storefn = $url;
2929: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2930: } else {
2931: $storefn = $key;
2932: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2933: if ($prefixchg && $before{'map'} && $after{'map'}) {
2934: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2935: }
1.529 raeburn 2936: if ($newsubdir{$key}) {
2937: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2938: }
1.491 raeburn 2939: }
1.492 raeburn 2940: my $report;
2941: if ($folder !~ /^supplemental/) {
2942: $report = 1;
2943: }
1.527 raeburn 2944: (my $outtext,$errtext) =
1.492 raeburn 2945: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2946: if ($errtext) {
1.529 raeburn 2947: if ($caller eq 'paste') {
1.533 raeburn 2948: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2949: }
1.491 raeburn 2950: }
2951: }
2952: }
1.533 raeburn 2953: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2954: }
2955:
2956: sub copy_dependencies {
2957: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2958: my $content;
2959: if (ref($contentref)) {
2960: $content = $$contentref;
2961: } else {
2962: $content = &Apache::lonnet::getfile($item);
2963: }
2964: unless ($content eq '-1') {
2965: my $mm = new File::MMagic;
2966: my $mimetype = $mm->checktype_contents($content);
2967: if ($mimetype eq 'text/html') {
2968: my (%allfiles,%codebase,$state);
2969: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2970: if ($res eq 'ok') {
2971: my ($numexisting,$numpathchanges,$existing);
2972: (undef,$numexisting,$numpathchanges,$existing) =
2973: &Apache::loncommon::ask_for_embedded_content(
2974: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2975: {'error_on_invalid_names' => 1,
2976: 'ignore_remote_references' => 1,
2977: 'docs_url' => $item,
2978: 'context' => 'paste'});
2979: if ($numexisting > 0) {
2980: if (ref($existing) eq 'HASH') {
2981: foreach my $dep (keys(%{$existing})) {
2982: my $depfile = $dep;
2983: unless ($depfile =~ m{^\Q$relpath\E}) {
2984: $depfile = $relpath.$dep;
2985: }
2986: my $depcontent = &Apache::lonnet::getfile($depfile);
2987: unless ($depcontent eq '-1') {
2988: my $storedep = $dep;
2989: $storedep =~ s{^\Q$relpath\E}{};
2990: my $dep_url =
2991: &Apache::lonclonecourse::writefile(
2992: $env{'request.course.id'},
2993: $storefn.$storedep,$depcontent);
2994: if ($dep_url eq '/adm/notfound.html') {
2995: if (ref($errors) eq 'HASH') {
2996: $errors->{$depfile} = 1;
2997: }
2998: } else {
2999: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3000: }
3001: }
3002: }
1.488 raeburn 3003: }
3004: }
3005: }
3006: }
3007: }
3008: return;
3009: }
3010:
1.329 droeschl 3011: my %parameter_type = ( 'randompick' => 'int_pos',
3012: 'hiddenresource' => 'string_yesno',
3013: 'encrypturl' => 'string_yesno',
3014: 'randomorder' => 'string_yesno',);
3015: my $valid_parameters_re = join('|',keys(%parameter_type));
3016: # set parameters
3017: sub update_parameter {
1.537 raeburn 3018: if ($env{'form.changeparms'} eq 'all') {
3019: my (@allidx,@allmapidx,%allchecked,%currchecked);
3020: %allchecked = (
3021: 'hiddenresource' => {},
3022: 'encrypturl' => {},
3023: 'randompick' => {},
3024: 'randomorder' => {},
3025: );
3026: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3027: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3028: if ($which eq 'randompick') {
3029: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3030: my ($res,$value) = split(/:/,$item);
3031: if ($value =~ /^\d+$/) {
3032: $allchecked{$which}{$res} = $value;
3033: }
3034: }
3035: } else {
1.539 raeburn 3036: if ($env{'form.all'.$which}) {
3037: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3038: }
1.537 raeburn 3039: }
3040: }
3041: my $haschanges = 0;
3042: foreach my $res (@LONCAPA::map::order) {
3043: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3044: $name=&LONCAPA::map::qtescape($name);
3045: $url=&LONCAPA::map::qtescape($url);
3046: next unless ($name && $url);
3047: my $is_map;
3048: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3049: $is_map = 1;
3050: }
3051: foreach my $which (keys(%allchecked)) {
3052: if (($which eq 'randompick' || $which eq 'randomorder')) {
3053: next if (!$is_map);
3054: }
3055: my $oldvalue = 0;
3056: my $newvalue = 0;
3057: if ($allchecked{$which}{$res}) {
3058: $newvalue = $allchecked{$which}{$res};
3059: }
3060: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3061: if ($which eq 'randompick') {
3062: if ($current =~ /^(\d+)$/) {
3063: $oldvalue = $1;
3064: }
3065: } else {
3066: if ($current =~ /^yes$/i) {
3067: $oldvalue = 1;
3068: }
3069: }
3070: if ($oldvalue ne $newvalue) {
3071: $haschanges = 1;
3072: if ($newvalue) {
3073: my $storeval = 'yes';
3074: if ($which eq 'randompick') {
3075: $storeval = $newvalue;
3076: }
3077: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3078: $storeval,
3079: $parameter_type{$which});
3080: &remember_parms($res,$which,'set',$storeval);
3081: } elsif ($oldvalue) {
3082: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3083: &remember_parms($res,$which,'del');
3084: }
3085: }
3086: }
3087: }
3088: return $haschanges;
3089: } else {
1.588 raeburn 3090: my $haschanges = 0;
3091: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3092:
1.537 raeburn 3093: my $which = $env{'form.changeparms'};
3094: my $idx = $env{'form.setparms'};
1.588 raeburn 3095: my $oldvalue = 0;
3096: my $newvalue = 0;
3097: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3098: if ($which eq 'randompick') {
3099: if ($current =~ /^(\d+)$/) {
3100: $oldvalue = $1;
3101: }
3102: } elsif ($current =~ /^yes$/i) {
3103: $oldvalue = 1;
3104: }
1.537 raeburn 3105: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3106: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3107: : 1;
3108: }
3109: if ($oldvalue ne $newvalue) {
3110: $haschanges = 1;
3111: if ($newvalue) {
3112: my $storeval = 'yes';
3113: if ($which eq 'randompick') {
3114: $storeval = $newvalue;
3115: }
3116: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3117: $parameter_type{$which});
3118: &remember_parms($idx,$which,'set',$storeval);
3119: } else {
3120: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3121: &remember_parms($idx,$which,'del');
3122: }
1.537 raeburn 3123: }
1.588 raeburn 3124: return $haschanges;
1.329 droeschl 3125: }
3126: }
3127:
3128: sub handle_edit_cmd {
3129: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3130: my $haschanges = 0;
1.543 raeburn 3131: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3132: return $haschanges;
1.543 raeburn 3133: }
1.329 droeschl 3134: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3135:
3136: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3137: my ($title, $url, @rrest) = split(':', $ratstr);
3138:
1.538 raeburn 3139: if ($cmd eq 'remove') {
1.329 droeschl 3140: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3141: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3142: &Apache::lonnet::removeuploadedurl($url);
3143: } else {
3144: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3145: }
3146: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3147: $haschanges = 1;
1.329 droeschl 3148: } elsif ($cmd eq 'cut') {
3149: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3150: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3151: $haschanges = 1;
1.344 bisitz 3152: } elsif ($cmd eq 'up'
1.329 droeschl 3153: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3154: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3155: $haschanges = 1;
1.329 droeschl 3156: } elsif ($cmd eq 'down'
3157: && defined($LONCAPA::map::order[$idx+1])) {
3158: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3159: $haschanges = 1;
1.329 droeschl 3160: } elsif ($cmd eq 'rename') {
3161: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3162: if ($comment=~/\S/) {
3163: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3164: $comment.':'.join(':', $url, @rrest);
3165: }
3166: # Devalidate title cache
3167: my $renamed_url=&LONCAPA::map::qtescape($url);
3168: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3169: $haschanges = 1;
3170: } elsif ($cmd eq 'setalias') {
3171: my $newvalue = $env{'form.alias'};
3172: if ($newvalue ne '') {
3173: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3174: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3175: 'string');
3176: &remember_parms($idx,'mapalias','set',$newvalue);
3177: $haschanges = 1;
3178: }
3179: }
3180: } elsif ($cmd eq 'delalias') {
3181: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3182: if ($current ne '') {
3183: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3184: &remember_parms($idx,'mapalias','del');
3185: $haschanges = 1;
3186: }
1.329 droeschl 3187: }
1.633 raeburn 3188: return $haschanges;
1.329 droeschl 3189: }
3190:
3191: sub editor {
1.458 raeburn 3192: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3193: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3194: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3195: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3196: if ($allowed) {
1.519 raeburn 3197: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3198: $is_random_order,$container) =
1.510 raeburn 3199: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3200: $r->print($breadcrumbtrail);
1.519 raeburn 3201: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3202: $container = 'page';
3203: } else {
3204: $container = 'sequence';
1.510 raeburn 3205: }
1.484 raeburn 3206:
1.525 raeburn 3207: my $jumpto;
3208:
3209: unless ($supplementalflag) {
1.546 raeburn 3210: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3211: }
1.484 raeburn 3212:
3213: unless ($allowed) {
3214: $randompick = -1;
3215: }
3216:
1.615 raeburn 3217: my ($errtext,$fatal);
3218: if (($folder eq '') && (!$supplementalflag)) {
3219: if (@LONCAPA::map::order) {
3220: undef(@LONCAPA::map::order);
3221: undef(@LONCAPA::map::resources);
3222: undef(@LONCAPA::map::resparms);
3223: undef(@LONCAPA::map::zombies);
3224: }
3225: $folder = 'default';
3226: $container = 'sequence';
3227: } else {
3228: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3229: $folder.'.'.$container);
3230: return $errtext if ($fatal);
3231: }
1.329 droeschl 3232:
3233: if ($#LONCAPA::map::order<1) {
3234: my $idx=&LONCAPA::map::getresidx();
3235: if ($idx<=0) { $idx=1; }
3236: $LONCAPA::map::order[0]=$idx;
3237: $LONCAPA::map::resources[$idx]='';
3238: }
1.364 bisitz 3239:
1.329 droeschl 3240: # ------------------------------------------------------------ Process commands
3241:
3242: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3243: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3244: # set parameters and change order
3245: &snapshotbefore();
3246:
3247: if (&update_parameter()) {
1.588 raeburn 3248: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3249: return $errtext if ($fatal);
3250: }
3251:
3252: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3253: # change order
3254: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3255: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3256:
3257: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3258: return $errtext if ($fatal);
3259: }
1.364 bisitz 3260:
1.329 droeschl 3261: if ($env{'form.pastemarked'}) {
1.491 raeburn 3262: my %paste_errors;
1.533 raeburn 3263: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3264: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3265: \%paste_errors);
1.541 raeburn 3266: if (ref($pastemsgarray) eq 'ARRAY') {
3267: if (@{$pastemsgarray} > 0) {
3268: $r->print('<p class="LC_info">'.
3269: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3270: '</p>');
3271: }
1.541 raeburn 3272: }
3273: if ($lockerror) {
3274: $r->print('<p class="LC_error">'.
3275: $lockerror.
3276: '</p>');
3277: }
3278: if ($save_error ne '') {
3279: return $save_error;
3280: }
3281: if ($paste_res) {
3282: my %errortext = &Apache::lonlocal::texthash (
3283: fail => 'Storage of folder contents failed',
3284: failread => 'Reading folder contents failed',
3285: failstore => 'Storage of folder contents failed',
3286: );
3287: if ($errortext{$paste_res}) {
3288: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3289: }
1.329 droeschl 3290: }
1.491 raeburn 3291: if (keys(%paste_errors) > 0) {
1.538 raeburn 3292: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3293: &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".
3294: '<ul>'."\n");
3295: foreach my $key (sort(keys(%paste_errors))) {
3296: $r->print('<li>'.$key.'</li>'."\n");
3297: }
3298: $r->print('</ul></p>'."\n");
3299: }
1.538 raeburn 3300: } elsif ($env{'form.clearmarked'}) {
3301: my $output = &do_buffer_empty();
3302: if ($output) {
3303: $r->print('<p class="LC_info">'.$output.'</p>');
3304: }
3305: }
1.329 droeschl 3306:
3307: $r->print($upload_output);
3308:
1.538 raeburn 3309: # Rename, cut, copy or remove a single resource
1.602 raeburn 3310: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3311: my $contentchg;
1.633 raeburn 3312: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3313: $contentchg = 1;
3314: }
3315: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3316: return $errtext if ($fatal);
3317: }
1.538 raeburn 3318:
3319: # Cut, copy and/or remove multiple resources
3320: if ($env{'form.multichange'}) {
3321: my %allchecked = (
3322: cut => {},
3323: remove => {},
3324: );
3325: my $needsupdate;
3326: foreach my $which (keys(%allchecked)) {
3327: $env{'form.multi'.$which} =~ s/,$//;
3328: if ($env{'form.multi'.$which}) {
3329: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3330: if (ref($allchecked{$which}) eq 'HASH') {
3331: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3332: }
3333: }
3334: }
3335: if ($needsupdate) {
3336: my $haschanges = 0;
3337: my %curr_groups = &Apache::longroup::coursegroups();
3338: my $total = scalar(@LONCAPA::map::order) - 1;
3339: for (my $i=$total; $i>=0; $i--) {
3340: my $res = $LONCAPA::map::order[$i];
3341: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3342: $name=&LONCAPA::map::qtescape($name);
3343: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3344: next unless $url;
1.538 raeburn 3345: my %denied =
3346: &action_restrictions($coursenum,$coursedom,$url,
3347: $env{'form.folderpath'},\%curr_groups);
3348: foreach my $which (keys(%allchecked)) {
3349: next if ($denied{$which});
3350: next unless ($allchecked{$which}{$res});
3351: if ($which eq 'remove') {
3352: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3353: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3354: &Apache::lonnet::removeuploadedurl($url);
3355: } else {
3356: &LONCAPA::map::makezombie($res);
3357: }
3358: splice(@LONCAPA::map::order,$i,1);
3359: $haschanges ++;
3360: } elsif ($which eq 'cut') {
3361: &LONCAPA::map::makezombie($res);
3362: splice(@LONCAPA::map::order,$i,1);
3363: $haschanges ++;
3364: }
3365: }
3366: }
3367: if ($haschanges) {
3368: ($errtext,$fatal) =
3369: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3370: return $errtext if ($fatal);
3371: }
3372: }
3373: }
3374:
1.329 droeschl 3375: # Group import/search
3376: if ($env{'form.importdetail'}) {
3377: my @imports;
3378: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3379: if (defined($item)) {
3380: my ($name,$url,$residx)=
1.533 raeburn 3381: map { &unescape($_); } split(/\=/,$item);
3382: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3383: my ($suffix,$errortxt,$locknotfreed) =
3384: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3385: if ($locknotfreed) {
3386: $r->print($locknotfreed);
3387: }
3388: if ($suffix) {
3389: $url =~ s/_new\./_$suffix./;
3390: } else {
3391: return $errortxt;
3392: }
1.533 raeburn 3393: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3394: my $type = $1;
3395: my ($suffix,$errortxt,$locknotfreed) =
3396: &new_timebased_suffix($coursedom,$coursenum,$type);
3397: if ($locknotfreed) {
3398: $r->print($locknotfreed);
3399: }
3400: if ($suffix) {
3401: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3402: } else {
3403: return $errortxt;
3404: }
1.626 raeburn 3405: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3406: my ($suffix,$errortxt,$locknotfreed) =
3407: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3408: if ($locknotfreed) {
3409: $r->print($locknotfreed);
3410: }
3411: if ($suffix) {
3412: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3413: } else {
3414: return $errortxt;
3415: }
1.534 raeburn 3416: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3417: if ($supplementalflag) {
3418: next unless ($1 eq 'supplemental');
3419: if ($folder eq 'supplemental') {
3420: next unless ($2 eq 'default');
3421: } else {
3422: next unless ($folder eq 'supplemental_'.$2);
3423: }
3424: } else {
3425: next unless ($1 eq 'docs');
3426: if ($folder eq 'default') {
3427: next unless ($2 eq 'default');
3428: } else {
3429: next unless ($folder eq 'default_'.$2);
3430: }
3431: }
1.504 raeburn 3432: }
1.329 droeschl 3433: push(@imports, [$name, $url, $residx]);
3434: }
3435: }
1.530 raeburn 3436: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3437: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3438: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3439: return $errtext if ($fatal);
1.529 raeburn 3440: if ($fixuperrors) {
3441: $r->print($fixuperrors);
3442: }
1.329 droeschl 3443: }
3444: # Loading a complete map
3445: if ($env{'form.loadmap'}) {
3446: if ($env{'form.importmap'}=~/\w/) {
3447: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3448: my ($title,$url,$ext,$type)=split(/\:/,$res);
3449: my $idx=&LONCAPA::map::getresidx($url);
3450: $LONCAPA::map::resources[$idx]=$res;
3451: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3452: }
3453: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3454: $folder.'.'.$container,1);
1.329 droeschl 3455: return $errtext if ($fatal);
3456: } else {
3457: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3458:
1.329 droeschl 3459: }
3460: }
3461: &log_differences($plain);
3462: }
3463: # ---------------------------------------------------------------- End commands
3464: # ---------------------------------------------------------------- Print screen
3465: my $idx=0;
3466: my $shown=0;
3467: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3468: $r->print('<div class="LC_Box">'.
1.432 raeburn 3469: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3470: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3471: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3472: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3473: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3474: '</ol>');
1.381 bisitz 3475: if ($randompick>=0) {
3476: $r->print('<p class="LC_warning">'
3477: .&mt('Caution: this folder is set to randomly pick a subset'
3478: .' of resources. Adding or removing resources from this'
3479: .' folder will change the set of resources that the'
3480: .' students see, resulting in spurious or missing credit'
3481: .' for completed problems, not limited to ones you'
3482: .' modify. Do not modify the contents of this folder if'
3483: .' it is in active student use.')
3484: .'</p>'
3485: );
3486: }
3487: if ($is_random_order) {
3488: $r->print('<p class="LC_warning">'
3489: .&mt('Caution: this folder is set to randomly order its'
3490: .' contents. Adding or removing resources from this folder'
3491: .' will change the order of resources shown.')
3492: .'</p>'
3493: );
3494: }
3495: $r->print('</div>');
1.364 bisitz 3496: }
1.381 bisitz 3497:
1.538 raeburn 3498: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3499: %filters = (
1.543 raeburn 3500: canremove => [],
3501: cancut => [],
3502: cancopy => [],
3503: hiddenresource => [],
3504: encrypturl => [],
3505: randomorder => [],
3506: randompick => [],
1.538 raeburn 3507: );
3508: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3509: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3510: foreach my $res (@LONCAPA::map::order) {
3511: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3512: $name=&LONCAPA::map::qtescape($name);
3513: $url=&LONCAPA::map::qtescape($url);
3514: unless ($name) { $name=(split(/\//,$url))[-1]; }
3515: unless ($name) { $idx++; next; }
1.537 raeburn 3516: push(@allidx,$res);
3517: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3518: push(@allmapidx,$res);
3519: }
1.617 raeburn 3520:
1.381 bisitz 3521: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3522: $coursenum,$coursedom,$crstype,
1.538 raeburn 3523: $pathitem,$supplementalflag,$container,
1.620 raeburn 3524: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3525: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3526: $idx++;
3527: $shown++;
1.329 droeschl 3528: }
1.424 onken 3529: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3530:
1.538 raeburn 3531: my $need_save;
1.611 raeburn 3532: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3533: my $toolslink;
1.611 raeburn 3534: if ($allowed) {
1.544 raeburn 3535: $toolslink = '<table><tr><td>'
1.520 raeburn 3536: .&Apache::loncommon::help_open_menu('Navigation Screen',
3537: 'Navigation_Screen',undef,'RAT')
3538: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3539: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3540: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3541: .'id="LC_content_toolbar_edittoplevel" '
3542: .'class="LC_toolbarItem" '
3543: .'title="'.&mt('Supplemental Content Editor').'">'
3544: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3545: }
1.510 raeburn 3546: if ($shown) {
3547: if ($allowed) {
3548: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3549: .&Apache::loncommon::start_data_table(undef,'contentlist')
3550: .&Apache::loncommon::start_data_table_header_row()
3551: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3552: .'<th colspan="3">'.&mt('Actions').'</th>'
1.538 raeburn 3553: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3554: if ($folder !~ /^supplemental/) {
1.633 raeburn 3555: $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
1.510 raeburn 3556: }
1.537 raeburn 3557: $to_show .= &Apache::loncommon::end_data_table_header_row();
3558: if ($folder !~ /^supplemental/) {
1.538 raeburn 3559: $lists{'canhide'} = join(',',@allidx);
3560: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3561: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3562: 'randomorder','randompick');
3563: foreach my $item (@possfilters) {
1.538 raeburn 3564: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3565: if (@{$filters{$item}} > 0) {
3566: $lists{$item} = join(',',@{$filters{$item}});
3567: }
1.538 raeburn 3568: }
3569: }
1.537 raeburn 3570: if (@allidx > 0) {
3571: my $path;
3572: if ($env{'form.folderpath'}) {
1.630 raeburn 3573: $path =
1.537 raeburn 3574: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3575: }
1.538 raeburn 3576: if (@allidx > 1) {
1.630 raeburn 3577: $to_show .=
1.538 raeburn 3578: &Apache::loncommon::continue_data_table_row().
3579: '<td colspan="2"> </td>'.
3580: '<td>'.
1.611 raeburn 3581: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3582: '</td>'.
1.633 raeburn 3583: '<td colspan="3"> </td>'.
3584: '<td colspan="2">'.
1.611 raeburn 3585: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3586: '</td>'.
3587: &Apache::loncommon::end_data_table_row();
3588: $need_save = 1;
3589: }
1.537 raeburn 3590: }
3591: }
3592: $to_show .= $output.' '
1.510 raeburn 3593: .&Apache::loncommon::end_data_table()
3594: .'<br style="line-height:2px;" />'
3595: .&Apache::loncommon::end_scrollbox();
3596: } else {
1.520 raeburn 3597: $to_show .= $toolslink
1.510 raeburn 3598: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3599: .$output.' '
3600: .&Apache::loncommon::end_data_table();
1.393 raeburn 3601: }
1.510 raeburn 3602: } else {
1.520 raeburn 3603: if (!$allowed) {
3604: $to_show .= $toolslink;
3605: }
1.615 raeburn 3606: my $noresmsg;
3607: if ($allowed && $hiddentop && !$supplementalflag) {
3608: $noresmsg = &mt('Main Content Hidden');
3609: } else {
3610: $noresmsg = &mt('Currently empty');
3611: }
1.510 raeburn 3612: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3613: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3614: .$noresmsg
1.510 raeburn 3615: .'</div>'
3616: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3617: }
3618: } else {
1.510 raeburn 3619: if ($shown) {
3620: $to_show = '<div>'
3621: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3622: .$output
3623: .&Apache::loncommon::end_data_table()
3624: .'</div>';
3625: } else {
3626: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3627: .&mt('Currently empty')
1.510 raeburn 3628: .'</div>'
3629: }
1.458 raeburn 3630: }
3631: my $tid = 1;
3632: if ($supplementalflag) {
3633: $tid = 2;
1.329 droeschl 3634: }
3635: if ($allowed) {
1.484 raeburn 3636: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3637: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3638: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3639: if ($canedit) {
3640: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3641: }
1.460 raeburn 3642: } else {
3643: $r->print($to_show);
1.329 droeschl 3644: }
3645: return;
3646: }
3647:
1.538 raeburn 3648: sub multiple_check_form {
1.611 raeburn 3649: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3650: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3651: my $disabled;
3652: unless ($canedit) {
3653: $disabled = 'disabled="disabled"';
3654: }
1.538 raeburn 3655: my $output =
3656: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3657: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3658: '<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>'.
3659: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3660: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3661: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3662: if ($caller eq 'settings') {
3663: $output .=
3664: '<table><tr>'.
3665: '<td class="LC_docs_entry_parameter">'.
3666: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3667: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3668: '</label></span></td>'.
3669: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3670: '<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 3671: '</span></td>'.
3672: '</tr>'."\n".
3673: '<tr>'.
3674: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3675: '<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 3676: '</label></span>'.
3677: '</td></tr></table>'."\n";
3678: } else {
3679: $output .=
3680: '<table><tr>'.
3681: '<td class="LC_docs_entry_parameter">'.
3682: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3683: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3684: '</label></span></td>'.
3685: '<td class="LC_docs_entry_parameter">'.
3686: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3687: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3688: '</label></span></td>'."\n".
3689: '<td class="LC_docs_entry_parameter">'.
3690: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3691: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3692: '</label></span></td>'.
3693: '</tr></table>'."\n";
3694: }
3695: $output .=
3696: '</fieldset>'.
3697: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3698: if ($caller eq 'settings') {
3699: $output .=
1.543 raeburn 3700: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3701: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3702: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3703: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3704: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3705: } elsif ($caller eq 'actions') {
3706: $output .=
3707: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3708: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3709: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3710: }
3711: $output .=
3712: '</form>'.
3713: '</div>';
3714: return $output;
3715: }
3716:
1.329 droeschl 3717: sub process_file_upload {
1.552 raeburn 3718: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3719: # upload a file, if present
1.552 raeburn 3720: my $filesize = length($env{'form.uploaddoc'});
3721: if (!$filesize) {
3722: $$upload_output = '<div class="LC_error">'.
3723: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3724: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3725: $filesize).'<br />'.
3726: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3727: '</div>';
3728: return;
3729: }
3730: my $quotatype = 'unofficial';
3731: if ($crstype eq 'Community') {
1.601 raeburn 3732: $quotatype = 'community';
3733: } elsif ($crstype eq 'Placement') {
3734: $quotatype = 'placement';
1.580 raeburn 3735: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3736: $quotatype = 'official';
1.573 raeburn 3737: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3738: $quotatype = 'textbook';
1.552 raeburn 3739: }
3740: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3741: $filesize = int($filesize/1000); #expressed in kb
3742: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3743: $env{'form.uploaddoc.filename'},$filesize,
3744: 'upload',$quotatype);
1.552 raeburn 3745: return if ($$upload_output);
3746: }
1.440 raeburn 3747: my ($parseaction,$showupload,$nextphase,$mimetype);
3748: if ($env{'form.parserflag'}) {
1.329 droeschl 3749: $parseaction = 'parse';
3750: }
3751: my $folder=$env{'form.folder'};
3752: if ($folder eq '') {
3753: $folder='default';
3754: }
3755: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3756: my $errtext='';
3757: my $fatal=0;
3758: my $container='sequence';
1.519 raeburn 3759: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3760: $container='page';
3761: }
3762: ($errtext,$fatal)=
1.534 raeburn 3763: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3764: if ($#LONCAPA::map::order<1) {
3765: $LONCAPA::map::order[0]=1;
3766: $LONCAPA::map::resources[1]='';
3767: }
3768: my $destination = 'docs/';
3769: if ($folder =~ /^supplemental/) {
3770: $destination = 'supplemental/';
3771: }
3772: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3773: $destination .= 'default/';
3774: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3775: $destination .= $2.'/';
3776: }
1.534 raeburn 3777: if ($fatal) {
3778: $$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>';
3779: return;
3780: }
1.440 raeburn 3781: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3782: my $newidx=&LONCAPA::map::getresidx();
3783: $destination .= $newidx;
1.439 raeburn 3784: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3785: $parseaction,$allfiles,
1.440 raeburn 3786: $codebase,undef,undef,undef,undef,
3787: undef,undef,\$mimetype);
3788: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3789: my $stored = $1;
3790: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3791: $stored.'</span>').'</p>';
3792: } else {
3793: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3794:
1.457 raeburn 3795: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3796: return;
3797: }
1.329 droeschl 3798: my $ext='false';
3799: if ($url=~m{^http://}) { $ext='true'; }
3800: $url = &LONCAPA::map::qtunescape($url);
3801: my $comment=$env{'form.comment'};
3802: $comment = &LONCAPA::map::qtunescape($comment);
3803: if ($folder=~/^supplemental/) {
3804: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3805: $env{'user.domain'}.'___&&&___'.$comment;
3806: }
3807:
3808: $LONCAPA::map::resources[$newidx]=
3809: $comment.':'.$url.':'.$ext.':normal:res';
3810: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3811: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3812: $folder.'.'.$container,1);
1.329 droeschl 3813: if ($fatal) {
1.457 raeburn 3814: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3815: return;
1.329 droeschl 3816: } else {
1.440 raeburn 3817: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3818: $$upload_output = $showupload;
1.384 raeburn 3819: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3820: if ($total_embedded > 0) {
1.440 raeburn 3821: my $uploadphase = 'upload_embedded';
3822: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3823: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3824: my ($embedded,$num) =
1.440 raeburn 3825: &Apache::loncommon::ask_for_embedded_content(
3826: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3827: if ($embedded) {
3828: if ($num) {
3829: $$upload_output .=
3830: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3831: $nextphase = $uploadphase;
3832: } else {
3833: $$upload_output .= $embedded;
3834: }
3835: } else {
3836: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3837: }
1.329 droeschl 3838: } else {
1.440 raeburn 3839: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3840: }
1.457 raeburn 3841: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3842: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3843: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3844: $nextphase = 'decompress_uploaded';
3845: my $position = scalar(@LONCAPA::map::order)-1;
3846: my $noextract = &return_to_editor();
3847: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3848: my %archiveitems = (
3849: folderpath => $env{'form.folderpath'},
3850: cmd => $nextphase,
3851: newidx => $newidx,
3852: position => $position,
3853: phase => $nextphase,
1.477 raeburn 3854: comment => $comment,
1.480 raeburn 3855: );
3856: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3857: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3858: $$upload_output = $showupload.
3859: &Apache::loncommon::decompress_form($mimetype,
3860: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3861: \%archiveitems,\@current);
1.329 droeschl 3862: }
3863: }
3864: }
1.440 raeburn 3865: return $nextphase;
1.329 droeschl 3866: }
3867:
1.480 raeburn 3868: sub get_dir_list {
3869: my ($url,$coursenum,$coursedom,$newidx) = @_;
3870: my ($destination,$dir_root) = &embedded_destination();
3871: my ($dirlistref,$listerror) =
3872: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3873: my @dir_lines;
3874: my $dirptr=16384;
3875: if (ref($dirlistref) eq 'ARRAY') {
3876: foreach my $dir_line (sort
3877: {
3878: my ($afile)=split('&',$a,2);
3879: my ($bfile)=split('&',$b,2);
3880: return (lc($afile) cmp lc($bfile));
3881: } (@{$dirlistref})) {
3882: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3883: $filename =~ s/\s+$//;
3884: next if ($filename =~ /^\.\.?$/);
3885: my $isdir = 0;
3886: if ($dirptr&$testdir) {
3887: $isdir = 1;
3888: }
3889: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3890: }
3891: }
3892: return @dir_lines;
3893: }
3894:
1.329 droeschl 3895: sub is_supplemental_title {
3896: my ($title) = @_;
3897: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3898: }
3899:
3900: # --------------------------------------------------------------- An entry line
3901:
3902: sub entryline {
1.501 raeburn 3903: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3904: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3905: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3906: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3907: if (&is_supplemental_title($title)) {
1.488 raeburn 3908: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3909: } else {
3910: $title=&HTML::Entities::encode($title,'"<>&\'');
3911: $renametitle=$title;
3912: $foldertitle=$title;
3913: }
3914:
1.611 raeburn 3915: my ($disabled,$readonly,$js_lt);
3916: unless ($canedit) {
3917: $disabled = 'disabled="disabled"';
3918: $readonly = 1;
3919: }
3920:
1.329 droeschl 3921: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3922:
1.329 droeschl 3923: $renametitle=~s/\\/\\\\/g;
3924: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3925: $renametitle=~s/"/%22/g;
1.581 raeburn 3926: $renametitle=~s/ /%20/g;
3927: $oldtitle = $renametitle;
1.576 raeburn 3928: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3929: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3930: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3931: # Edit commands
1.633 raeburn 3932: my ($esc_path, $path, $symb, $curralias);
1.329 droeschl 3933: if ($env{'form.folderpath'}) {
3934: $esc_path=&escape($env{'form.folderpath'});
3935: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3936: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3937: }
1.505 raeburn 3938: my $isexternal;
1.510 raeburn 3939: if ($residx) {
1.501 raeburn 3940: my $currurl = $url;
3941: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3942: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3943: $isexternal = 1;
3944: }
1.510 raeburn 3945: if (!$supplementalflag) {
3946: my $path = 'uploaded/'.
3947: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3948: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3949: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3950: $residx,
3951: &Apache::lonnet::declutter($currurl));
3952: }
1.501 raeburn 3953: }
1.538 raeburn 3954: my ($renamelink,%lt,$ishash);
3955: if (ref($filtersref) eq 'HASH') {
3956: $ishash = 1;
3957: }
3958:
1.329 droeschl 3959: if ($allowed) {
1.538 raeburn 3960: $form_start = '
3961: <form action="/adm/coursedocs" method="post">
3962: ';
3963: $form_common=(<<END);
3964: <input type="hidden" name="folderpath" value="$path" />
3965: <input type="hidden" name="symb" value="$symb" />
3966: END
3967: $form_param=(<<END);
3968: <input type="hidden" name="setparms" value="$orderidx" />
3969: <input type="hidden" name="changeparms" value="0" />
3970: END
3971: $form_end = '</form>';
3972:
1.329 droeschl 3973: my $incindex=$index+1;
3974: my $selectbox='';
1.471 raeburn 3975: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3976: ((split(/\:/,
1.344 bisitz 3977: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3978: ne '') &&
1.329 droeschl 3979: ((split(/\:/,
1.344 bisitz 3980: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3981: ne '')) {
3982: $selectbox=
3983: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3984: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3985: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3986: if ($i==$incindex) {
1.358 bisitz 3987: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3988: } else {
3989: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3990: }
3991: }
3992: $selectbox.='</select>';
3993: }
1.501 raeburn 3994: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3995: 'up' => 'Move Up',
3996: 'dw' => 'Move Down',
3997: 'rm' => 'Remove',
3998: 'ct' => 'Cut',
3999: 'rn' => 'Rename',
1.501 raeburn 4000: 'cp' => 'Copy',
1.633 raeburn 4001: 'da' => 'Unset alias',
4002: 'sa' => 'Set alias',
1.501 raeburn 4003: 'ex' => 'External Resource',
1.598 raeburn 4004: 'et' => 'External Tool',
1.501 raeburn 4005: 'ed' => 'Edit',
4006: 'pr' => 'Preview',
4007: 'sv' => 'Save',
4008: 'ul' => 'URL',
1.611 raeburn 4009: 'ti' => 'Title',
1.618 raeburn 4010: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 4011: );
1.538 raeburn 4012: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4013: $env{'form.folderpath'},
4014: $currgroups);
1.517 raeburn 4015: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4016: my $skip_confirm = 0;
1.603 raeburn 4017: my $confirm_removal = 0;
1.329 droeschl 4018: if ( $folder =~ /^supplemental/
4019: || ($url =~ m{( /smppg$
4020: |/syllabus$
4021: |/aboutme$
4022: |/navmaps$
4023: |/bulletinboard$
1.626 raeburn 4024: |/ext\.tool$
1.505 raeburn 4025: |\.html$)}x)
4026: || $isexternal) {
1.329 droeschl 4027: $skip_confirm = 1;
4028: }
1.603 raeburn 4029: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4030: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4031: $confirm_removal = 1;
4032: }
1.633 raeburn 4033: if ($url =~ /$LONCAPA::assess_re/) {
4034: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4035: }
1.329 droeschl 4036:
1.538 raeburn 4037: if ($denied{'copy'}) {
1.543 raeburn 4038: $copylink=(<<ENDCOPY)
1.507 raeburn 4039: <span style="visibility: hidden;">$lt{'cp'}</span>
4040: ENDCOPY
4041: } else {
1.538 raeburn 4042: my $formname = 'edit_copy_'.$orderidx;
4043: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4044: $copylink=(<<ENDCOPY);
1.538 raeburn 4045: <form name="$formname" method="post" action="/adm/coursedocs">
4046: $form_common
1.611 raeburn 4047: <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 4048: $form_end
1.329 droeschl 4049: ENDCOPY
1.538 raeburn 4050: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4051: push(@{$filtersref->{'cancopy'}},$orderidx);
4052: }
1.329 droeschl 4053: }
1.538 raeburn 4054: if ($denied{'cut'}) {
1.507 raeburn 4055: $cutlink=(<<ENDCUT);
4056: <span style="visibility: hidden;">$lt{'ct'}</span>
4057: ENDCUT
4058: } else {
1.538 raeburn 4059: my $formname = 'edit_cut_'.$orderidx;
4060: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4061: $cutlink=(<<ENDCUT);
1.538 raeburn 4062: <form name="$formname" method="post" action="/adm/coursedocs">
4063: $form_common
1.542 raeburn 4064: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4065: <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 4066: $form_end
1.329 droeschl 4067: ENDCUT
1.538 raeburn 4068: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4069: push(@{$filtersref->{'cancut'}},$orderidx);
4070: }
1.329 droeschl 4071: }
1.538 raeburn 4072: if ($denied{'remove'}) {
1.507 raeburn 4073: $removelink=(<<ENDREM);
4074: <span style="visibility: hidden;">$lt{'rm'}</a>
4075: ENDREM
4076: } else {
1.538 raeburn 4077: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4078: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4079: $removelink=(<<ENDREM);
1.538 raeburn 4080: <form name="$formname" method="post" action="/adm/coursedocs">
4081: $form_common
1.542 raeburn 4082: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4083: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4084: <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 4085: $form_end
1.497 raeburn 4086: ENDREM
1.538 raeburn 4087: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4088: push(@{$filtersref->{'canremove'}},$orderidx);
4089: }
1.497 raeburn 4090: }
1.551 raeburn 4091: $renamelink=(<<ENDREN);
1.581 raeburn 4092: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4093: ENDREN
1.611 raeburn 4094: my ($uplink,$downlink);
4095: if ($canedit) {
4096: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4097: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4098: } else {
4099: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4100: $downlink = $uplink;
4101: }
1.329 droeschl 4102: $line.=(<<END);
4103: <td>
1.379 bisitz 4104: <div class="LC_docs_entry_move">
1.611 raeburn 4105: <a href="$uplink">
1.501 raeburn 4106: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4107: </a>
4108: </div>
4109: <div class="LC_docs_entry_move">
1.611 raeburn 4110: <a href="$downlink">
1.501 raeburn 4111: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4112: </a>
4113: </div>
1.329 droeschl 4114: </td>
4115: <td>
4116: $form_start
1.538 raeburn 4117: $form_param
1.478 raeburn 4118: $form_common
1.329 droeschl 4119: $selectbox
4120: $form_end
4121: </td>
1.540 raeburn 4122: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4123: $removelink
1.329 droeschl 4124: $cutlink
4125: $copylink
4126: </td>
4127: END
4128: }
4129: # Figure out what kind of a resource this is
4130: my ($extension)=($url=~/\.(\w+)$/);
4131: my $uploaded=($url=~/^\/*uploaded\//);
4132: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4133: my $isfolder;
4134: my $ispage;
4135: my $containerarg;
1.615 raeburn 4136: my $folderurl;
1.329 droeschl 4137: if ($uploaded) {
1.472 raeburn 4138: if (($extension eq 'sequence') || ($extension eq 'page')) {
4139: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4140: $containerarg = $1;
1.472 raeburn 4141: if ($extension eq 'sequence') {
4142: $icon=$iconpath.'navmap.folder.closed.gif';
4143: $isfolder=1;
4144: } else {
4145: $icon=$iconpath.'page.gif';
4146: $ispage=1;
4147: }
1.615 raeburn 4148: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4149: if ($allowed) {
4150: $url='/adm/coursedocs?';
4151: } else {
4152: $url='/adm/supplemental?';
4153: }
1.329 droeschl 4154: } else {
4155: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4156: }
4157: }
1.364 bisitz 4158:
1.621 raeburn 4159: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4160: my $orig_url = $url;
1.340 raeburn 4161: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.668 raeburn 4162: if ($container eq 'page') {
4163: $url=~s{^http(|s)(:|:)//}{/ext/};
4164: } else {
4165: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4166: }
1.501 raeburn 4167: if (!$supplementalflag && $residx && $symb) {
4168: if ((!$isfolder) && (!$ispage)) {
4169: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.668 raeburn 4170: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4171: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4172: } else {
4173: $url=&Apache::lonnet::clutter($url);
4174: }
1.501 raeburn 4175: if ($url=~/^\/*uploaded\//) {
4176: $url=~/\.(\w+)$/;
4177: my $embstyle=&Apache::loncommon::fileembstyle($1);
4178: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4179: $url='/adm/wrapper'.$url;
4180: } elsif ($embstyle eq 'ssi') {
4181: #do nothing with these
4182: } elsif ($url!~/\.(sequence|page)$/) {
4183: $url='/adm/coursedocs/showdoc'.$url;
4184: }
1.623 raeburn 4185: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4186: my $wrapped = $1;
4187: my $exturl = $2;
1.668 raeburn 4188: if (($wrapped eq '') && ($container ne 'page')) {
1.623 raeburn 4189: $url='/adm/wrapper'.$url;
4190: }
4191: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4192: $nomodal = 1;
4193: }
1.626 raeburn 4194: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4195: $url='/adm/wrapper'.$url;
1.621 raeburn 4196: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4197: if (($ENV{'SERVER_PORT'} == 443) &&
4198: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.657 raeburn 4199: unless (&Apache::lonnet::uses_sts()) {
4200: $url .= '?usehttp=1';
4201: }
1.621 raeburn 4202: $nomodal = 1;
4203: }
1.598 raeburn 4204: }
1.501 raeburn 4205: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4206: my $shownsymb = $symb;
4207: if ($isexternal) {
1.670 raeburn 4208: $url =~ s/\#[^#]+$//;
1.668 raeburn 4209: if ($container eq 'page') {
4210: $url = &Apache::lonnet::clutter($url);
4211: }
1.609 raeburn 4212: }
1.617 raeburn 4213: unless ($env{'request.role.adv'}) {
4214: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4215: $url = '';
4216: }
4217: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4218: $url = '';
4219: $hiddenres = 1;
4220: }
4221: }
4222: if ($url ne '') {
1.641 raeburn 4223: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.617 raeburn 4224: }
1.615 raeburn 4225: } elsif (!$env{'request.role.adv'}) {
4226: my $checkencrypt;
4227: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4228: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4229: $checkencrypt = 1;
1.620 raeburn 4230: } elsif (ref($navmapref)) {
1.615 raeburn 4231: unless (ref($$navmapref)) {
4232: $$navmapref = Apache::lonnavmaps::navmap->new();
4233: }
4234: if (ref($$navmapref)) {
4235: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4236: $checkencrypt = 1;
4237: }
4238: }
4239: }
4240: if ($checkencrypt) {
4241: my $shownsymb = &Apache::lonenc::encrypted($symb);
4242: my $shownurl = &Apache::lonenc::encrypted($url);
4243: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.641 raeburn 4244: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.615 raeburn 4245: if ($env{'request.enc'} ne '') {
4246: delete($env{'request.enc'});
4247: }
4248: } else {
4249: $url='';
1.613 raeburn 4250: }
1.612 raeburn 4251: } else {
4252: $url='';
4253: }
1.501 raeburn 4254: } else {
4255: $url='';
4256: }
1.329 droeschl 4257: }
1.621 raeburn 4258: } elsif ($supplementalflag) {
1.610 raeburn 4259: if ($isexternal) {
4260: if ($url =~ /^([^#]+)#([^#]+)$/) {
4261: $url = $1;
4262: $anchor = $2;
1.623 raeburn 4263: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.657 raeburn 4264: unless (&Apache::lonnet::uses_sts()) {
4265: if ($hostname ne '') {
4266: $url = 'http://'.$hostname.$url;
4267: }
4268: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4269: }
4270: $nomodal = 1;
4271: }
1.610 raeburn 4272: }
1.621 raeburn 4273: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4274: if (($ENV{'SERVER_PORT'} == 443) &&
4275: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.657 raeburn 4276: unless (&Apache::lonnet::uses_sts()) {
4277: if ($hostname ne '') {
4278: $url = 'http://'.$hostname.$url;
4279: }
4280: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4281: }
1.621 raeburn 4282: $nomodal = 1;
4283: }
1.610 raeburn 4284: }
1.329 droeschl 4285: }
1.615 raeburn 4286: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4287: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4288: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4289: my $foldername=&escape($foldertitle);
4290: my $folderpath=$env{'form.folderpath'};
4291: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4292: if (!$allowed && $supplementalflag) {
1.519 raeburn 4293: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4294: $url.='folderpath='.&escape($folderpath);
4295: } else {
1.617 raeburn 4296: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4297: 'parameter_randompick'))[0];
4298: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4299: 'parameter_randomorder'))[0]=~/^yes$/i);
4300: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4301: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4302: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4303: 'parameter_encrypturl'))[0]=~/^yes$/i);
4304: unless ($hiddenmap) {
1.620 raeburn 4305: if (ref($navmapref)) {
4306: unless (ref($$navmapref)) {
4307: $$navmapref = Apache::lonnavmaps::navmap->new();
4308: }
4309: if (ref($$navmapref)) {
4310: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4311: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4312: unless (@resources) {
4313: $hiddenmap = 1;
4314: unless ($env{'request.role.adv'}) {
4315: $url = '';
4316: $hiddenfolder = 1;
4317: }
1.617 raeburn 4318: }
1.615 raeburn 4319: }
4320: }
4321: }
4322: }
1.617 raeburn 4323: unless ($encryptmap) {
1.620 raeburn 4324: if ((ref($navmapref)) && (ref($$navmapref))) {
4325: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4326: $encryptmap = 1;
4327: }
1.617 raeburn 4328: }
4329: }
1.630 raeburn 4330:
1.617 raeburn 4331: # Append randompick number, hidden, and encrypted with ":" to foldername,
4332: # so it gets transferred between levels
4333: $folderpath.=$containerarg.'&'.$foldername.
4334: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4335: unless ($url eq '') {
1.612 raeburn 4336: $url.='folderpath='.&escape($folderpath);
4337: }
1.510 raeburn 4338: my $rpckchk;
4339: if ($rpicknum) {
4340: $rpckchk = ' checked="checked"';
1.543 raeburn 4341: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4342: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4343: }
1.510 raeburn 4344: }
1.537 raeburn 4345: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4346: $rand_pick_text =
1.478 raeburn 4347: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4348: $form_param."\n".
1.478 raeburn 4349: $form_common."\n".
1.611 raeburn 4350: '<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 4351: if ($rpicknum ne '') {
4352: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4353: }
1.537 raeburn 4354: $rand_pick_text .= '</span></span>'.
4355: $form_end;
1.543 raeburn 4356: my $ro_set;
1.617 raeburn 4357: if ($randorder) {
1.543 raeburn 4358: $ro_set = 'checked="checked"';
4359: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4360: push(@{$filtersref->{'randomorder'}},$orderidx);
4361: }
4362: }
1.564 raeburn 4363: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4364: $rand_order_text =
1.537 raeburn 4365: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4366: $form_param."\n".
1.537 raeburn 4367: $form_common."\n".
1.611 raeburn 4368: '<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 4369: $form_end;
1.510 raeburn 4370: }
1.509 raeburn 4371: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4372: my $isexttool;
1.626 raeburn 4373: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4374: $url='/adm/wrapper'.$url;
4375: $isexttool = 1;
4376: }
1.510 raeburn 4377: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4378: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4379: if ($title) {
4380: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4381: }
1.598 raeburn 4382: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4383: $url .= '&idx='.$orderidx;
4384: }
1.610 raeburn 4385: if ($anchor ne '') {
4386: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4387: }
1.329 droeschl 4388: }
1.519 raeburn 4389: my ($tdalign,$tdwidth);
1.501 raeburn 4390: if ($allowed) {
1.630 raeburn 4391: my $fileloc =
1.501 raeburn 4392: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4393: if ($isexternal) {
1.630 raeburn 4394: ($editlink,$extresform) =
1.611 raeburn 4395: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4396: undef,undef,undef,undef,undef,undef,
4397: undef,$disabled);
1.626 raeburn 4398: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4399: ($editlink,$extresform) =
4400: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4401: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4402: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4403: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4404: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4405: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4406: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4407: my $suppanchor;
4408: if ($supplementalflag) {
4409: $suppanchor = $anchor;
4410: }
1.630 raeburn 4411: my $jscall =
1.501 raeburn 4412: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4413: $switchserver,
1.503 raeburn 4414: $forceedit,
1.511 raeburn 4415: undef,$symb,
4416: &escape($env{'form.folderpath'}),
1.622 raeburn 4417: $renametitle,$hostname,
4418: '','',1,$suppanchor);
1.501 raeburn 4419: if ($jscall) {
1.518 raeburn 4420: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4421: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4422: }
4423: }
4424: }
1.519 raeburn 4425: $tdalign = ' align="right" valign="top"';
4426: $tdwidth = ' width="80%"';
1.329 droeschl 4427: }
1.408 raeburn 4428: my $reinit;
4429: if ($crstype eq 'Community') {
4430: $reinit = &mt('(re-initialize community to access)');
4431: } else {
4432: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4433: }
4434: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650 raeburn 4435: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4436: $line.= '<br />';
4437: if ($curralias ne '') {
4438: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4439: $lt{'da'}.'</a></span>';
4440: } else {
4441: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4442: $lt{'sa'}.'</a></span>';
4443: }
4444: }
4445: $line.='</td><td>';
1.621 raeburn 4446: my $link;
1.472 raeburn 4447: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4448: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4449: } elsif ($url) {
1.610 raeburn 4450: if ($anchor ne '') {
4451: if ($supplementalflag) {
4452: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4453: } else {
4454: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4455: }
4456: }
1.622 raeburn 4457: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4458: $link = 'http://'.$hostname.$url;
4459: } else {
4460: $link = $url;
4461: }
1.659 raeburn 4462: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.621 raeburn 4463: if ($nomodal) {
4464: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4465: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4466: } else {
4467: $line.=&Apache::loncommon::modal_link($link,
4468: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4469: }
1.469 www 4470: } else {
4471: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4472: }
1.519 raeburn 4473: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4474: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4475: $line.='<a href="'.$url.'">'.$title.'</a>';
4476: } elsif ($url) {
1.621 raeburn 4477: if ($nomodal) {
4478: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4479: $title.'</a>';
4480: } else {
4481: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4482: }
1.617 raeburn 4483: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4484: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4485: } else {
4486: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4487: }
1.633 raeburn 4488: if (($allowed) && ($curralias ne '')) {
4489: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4490: } else {
4491: $line .= $extresform;
4492: }
4493: $line .= '</td>';
1.478 raeburn 4494: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4495: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4496: if (($allowed) && ($folder!~/^supplemental/)) {
4497: my %lt=&Apache::lonlocal::texthash(
4498: 'hd' => 'Hidden',
4499: 'ec' => 'URL hidden');
1.543 raeburn 4500: my ($enctext,$hidtext);
4501: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4502: $enctext = ' checked="checked"';
4503: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4504: push(@{$filtersref->{'encrypturl'}},$orderidx);
4505: }
4506: }
4507: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4508: $hidtext = ' checked="checked"';
4509: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4510: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4511: }
4512: }
1.537 raeburn 4513: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4514: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4515: $line.=(<<ENDPARMS);
4516: <td class="LC_docs_entry_parameter">
1.537 raeburn 4517: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4518: $form_param
1.478 raeburn 4519: $form_common
1.611 raeburn 4520: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4521: $form_end
1.458 raeburn 4522: <br />
1.537 raeburn 4523: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4524: $form_param
1.478 raeburn 4525: $form_common
1.611 raeburn 4526: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4527: $form_end
4528: </td>
1.478 raeburn 4529: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4530: $rand_order_text</td>
1.329 droeschl 4531: ENDPARMS
4532: }
1.379 bisitz 4533: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4534: return $line;
4535: }
4536:
1.538 raeburn 4537: sub action_restrictions {
4538: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4539: my %denied = (
4540: cut => 0,
4541: copy => 0,
4542: remove => 0,
4543: );
4544: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4545: # no copy for published maps
4546: $denied{'copy'} = 1;
1.597 raeburn 4547: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4548: unless ($1 eq 'simpleproblem') {
4549: $denied{'copy'} = 1;
4550: }
4551: $denied{'cut'} = 1;
1.538 raeburn 4552: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4553: if ($folderpath =~ /^default&[^\&]+$/) {
4554: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4555: $denied{'remove'} = 1;
4556: }
4557: $denied{'cut'} = 1;
4558: $denied{'copy'} = 1;
4559: }
4560: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4561: my $group = $1;
4562: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4563: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4564: $denied{'remove'} = 1;
4565: }
4566: }
4567: $denied{'cut'} = 1;
4568: $denied{'copy'} = 1;
4569: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4570: my $group = $1;
4571: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4572: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4573: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4574: if (keys(%groupsettings) > 0) {
4575: $denied{'remove'} = 1;
4576: }
4577: $denied{'cut'} = 1;
4578: $denied{'copy'} = 1;
4579: }
4580: }
4581: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4582: my $group = $1;
4583: if ($url =~ /group_boards_\Q$group\E/) {
4584: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4585: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4586: if (keys(%groupsettings) > 0) {
4587: if (ref($groupsettings{'functions'}) eq 'HASH') {
4588: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4589: $denied{'remove'} = 1;
4590: }
4591: }
4592: }
4593: $denied{'cut'} = 1;
4594: $denied{'copy'} = 1;
4595: }
4596: }
4597: }
4598: return %denied;
4599: }
4600:
1.533 raeburn 4601: sub new_timebased_suffix {
1.538 raeburn 4602: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4603: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4604: if ($type eq 'paste') {
4605: $prefix = $type;
4606: $namespace = 'courseeditor';
1.587 raeburn 4607: $idtype = 'addcode';
1.538 raeburn 4608: } elsif ($type eq 'map') {
1.533 raeburn 4609: $prefix = 'docs';
4610: if ($area eq 'supplemental') {
4611: $prefix = 'supp';
4612: }
4613: $prefix .= $container;
4614: $namespace = 'uploadedmaps';
4615: } else {
4616: $prefix = $type;
4617: $namespace = 'templated';
1.504 raeburn 4618: }
4619: my ($suffix,$freedlock,$error) =
1.587 raeburn 4620: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4621: if (!$suffix) {
1.538 raeburn 4622: if ($type eq 'paste') {
4623: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4624: } elsif ($type eq 'map') {
1.533 raeburn 4625: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4626: } elsif ($type eq 'smppg') {
4627: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4628: } elsif ($type eq 'exttool') {
4629: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4630: } else {
1.565 bisitz 4631: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4632: }
1.504 raeburn 4633: if ($error) {
4634: $errtext .= '<br />'.$error;
4635: }
4636: }
4637: if ($freedlock ne 'ok') {
1.630 raeburn 4638: $locknotfreed =
1.533 raeburn 4639: '<div class="LC_error">'.
4640: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4641: if ($type eq 'paste') {
1.591 raeburn 4642: if ($freedlock eq 'nolock') {
4643: $locknotfreed =
4644: '<div class="LC_error">'.
4645: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4646:
1.593 droeschl 4647: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4648: } else {
4649: $locknotfreed .=
4650: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4651: }
1.538 raeburn 4652: } elsif ($type eq 'map') {
1.591 raeburn 4653: $locknotfreed .=
4654: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4655: } elsif ($type eq 'smppg') {
4656: $locknotfreed .=
4657: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4658: } elsif ($type eq 'exttool') {
4659: $locknotfreed .=
4660: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4661: } else {
4662: $locknotfreed .=
1.565 bisitz 4663: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4664: }
1.538 raeburn 4665: unless ($type eq 'paste') {
4666: $locknotfreed .=
1.560 raeburn 4667: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4668: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4669: }
4670: $locknotfreed .= '</div>';
1.504 raeburn 4671: }
4672: return ($suffix,$errtext,$locknotfreed);
4673: }
4674:
1.329 droeschl 4675: =pod
4676:
4677: =item tiehash()
4678:
4679: tie the hash
4680:
4681: =cut
4682:
4683: sub tiehash {
4684: my ($mode)=@_;
4685: $hashtied=0;
4686: if ($env{'request.course.fn'}) {
4687: if ($mode eq 'write') {
4688: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4689: &GDBM_WRCREAT(),0640)) {
4690: $hashtied=2;
4691: }
4692: } else {
4693: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4694: &GDBM_READER(),0640)) {
4695: $hashtied=1;
4696: }
4697: }
1.364 bisitz 4698: }
1.329 droeschl 4699: }
4700:
4701: sub untiehash {
4702: if ($hashtied) { untie %hash; }
4703: $hashtied=0;
4704: return OK;
4705: }
4706:
4707:
4708:
4709:
4710: sub checkonthis {
1.637 raeburn 4711: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4712: $url=&unescape($url);
4713: $alreadyseen{$url}=1;
4714: $r->rflush();
4715: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4716: $r->print("\n<br />");
4717: if ($level==0) {
4718: $r->print("<br />");
4719: }
4720: for (my $i=0;$i<=$level*5;$i++) {
4721: $r->print(' ');
4722: }
4723: $r->print('<a href="'.$url.'" target="cat">'.
4724: ($title?$title:$url).'</a> ');
4725: if ($url=~/^\/res\//) {
1.637 raeburn 4726: my $updated;
4727: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4728: ($url !~ /\.\d+\.\w+$/)) {
4729: $updated = &Apache::lonnet::remove_stale_resfile($url);
4730: }
1.329 droeschl 4731: my $result=&Apache::lonnet::repcopy(
4732: &Apache::lonnet::filelocation('',$url));
4733: if ($result eq 'ok') {
4734: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4735: if ($updated) {
4736: $r->print('<br />');
4737: for (my $i=0;$i<=$level*5;$i++) {
4738: $r->print(' ');
4739: }
4740: $r->print('- '.&mt('Outdated copy removed'));
4741: }
1.329 droeschl 4742: $r->rflush();
4743: &Apache::lonnet::countacc($url);
4744: $url=~/\.(\w+)$/;
4745: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4746: $r->print('<br />');
4747: $r->rflush();
4748: for (my $i=0;$i<=$level*5;$i++) {
4749: $r->print(' ');
4750: }
4751: $r->print('- '.&mt('Rendering:').' ');
4752: my ($errorcount,$warningcount)=split(/:/,
4753: &Apache::lonnet::ssi_body($url,
4754: ('grade_target'=>'web',
4755: 'return_only_error_and_warning_counts' => 1)));
4756: if (($errorcount) ||
4757: ($warningcount)) {
4758: if ($errorcount) {
1.369 bisitz 4759: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4760: &mt('[quant,_1,error]',$errorcount).'</span>');
4761: }
4762: if ($warningcount) {
4763: $r->print('<span class="LC_warning">'.
4764: &mt('[quant,_1,warning]',$warningcount).'</span>');
4765: }
4766: } else {
4767: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4768: }
4769: $r->rflush();
4770: }
4771: my $dependencies=
4772: &Apache::lonnet::metadata($url,'dependencies');
4773: foreach my $dep (split(/\,/,$dependencies)) {
4774: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4775: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4776: }
4777: }
4778: } elsif ($result eq 'unavailable') {
4779: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4780: } elsif ($result eq 'not_found') {
4781: unless ($url=~/\$/) {
1.521 bisitz 4782: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4783: } else {
1.366 bisitz 4784: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4785: }
4786: } else {
4787: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4788: }
1.637 raeburn 4789: if (($updated) && ($result ne 'ok')) {
4790: $r->print('<br />'.&mt('Outdated copy removed'));
4791: }
1.329 droeschl 4792: }
4793: }
4794: }
4795:
4796:
4797:
4798: =pod
4799:
4800: =item list_symbs()
4801:
1.485 raeburn 4802: List Content Identifiers
1.329 droeschl 4803:
4804: =cut
4805:
4806: sub list_symbs {
4807: my ($r) = @_;
4808:
1.408 raeburn 4809: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4810: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4811: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4812: $r->print(&startContentScreen('tools'));
1.329 droeschl 4813: my $navmap = Apache::lonnavmaps::navmap->new();
4814: if (!defined($navmap)) {
4815: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4816: '<div class="LC_error">'.
4817: &mt('Unable to retrieve information about course contents').
4818: '</div>');
1.408 raeburn 4819: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4820: } else {
1.484 raeburn 4821: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4822: &Apache::loncommon::start_data_table().
4823: &Apache::loncommon::start_data_table_header_row().
4824: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4825: &Apache::loncommon::end_data_table_header_row()."\n");
4826: my $count;
1.329 droeschl 4827: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4828: $r->print(&Apache::loncommon::start_data_table_row().
4829: '<td>'.$res->compTitle().'</td>'.
4830: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4831: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4832: $count ++;
4833: }
4834: if (!$count) {
4835: $r->print(&Apache::loncommon::start_data_table_row().
4836: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4837: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4838: }
1.484 raeburn 4839: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4840: }
1.521 bisitz 4841: $r->print(&endContentScreen());
1.329 droeschl 4842: }
4843:
1.651 raeburn 4844: sub short_urls {
4845: my ($r,$canedit) = @_;
4846: my $crstype = &Apache::loncommon::course_type();
4847: my $formname = 'shortenurl';
4848: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4849: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4850: $r->print(&startContentScreen('tools'));
4851: my ($navmap,$errormsg) =
4852: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4853: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4854: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4855: my (%maps,%resources,%titles);
4856: if (!ref($navmap)) {
4857: $r->print($errormsg.
4858: &endContentScreen());
4859: return '';
4860: } else {
1.652 raeburn 4861: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 4862: $r->rflush();
4863: my $readonly;
4864: if ($canedit) {
1.671 raeburn 4865: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
1.651 raeburn 4866: if ($numnew) {
4867: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4868: }
4869: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4870: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4871: foreach my $error (@{$errors}) {
4872: $r->print('<li>'.$error.'</li>');
4873: }
4874: $r->print('</ul><br />');
4875: }
4876: } else {
4877: $readonly = 1;
4878: }
4879: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4880: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4881: undef,undef,undef,undef,undef,\%currtiny,$readonly));
4882: }
4883: $r->print(&endContentScreen());
4884: }
4885:
1.637 raeburn 4886: sub contentverifyform {
4887: my ($r) = @_;
4888: my $crstype = &Apache::loncommon::course_type();
4889: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4890: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4891: $r->print(&startContentScreen('tools'));
4892: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4893: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4894: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4895: ' <span class="LC_nobreak">'.
4896: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4897: &mt('No').'</label>'.(' 'x2).
4898: '<label><input type="radio" name="checkstale" value="1" />'.
4899: &mt('Yes').'</label></span></p><p>'.
1.674 raeburn 4900: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.637 raeburn 4901: '<input type="hidden" value="1" name="tools" />'.
4902: '<input type="hidden" value="1" name="verify" /></p></form>');
4903: $r->print(&endContentScreen());
4904: return;
4905: }
1.329 droeschl 4906:
4907: sub verifycontent {
1.637 raeburn 4908: my ($r,$checkstale) = @_;
1.408 raeburn 4909: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4910: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4911: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4912: $r->print(&startContentScreen('tools'));
4913: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4914: $hashtied=0;
4915: undef %alreadyseen;
4916: %alreadyseen=();
4917: &tiehash();
1.484 raeburn 4918:
1.329 droeschl 4919: foreach my $key (keys(%hash)) {
4920: if ($hash{$key}=~/\.(page|sequence)$/) {
4921: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4922: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4923: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4924: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4925: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4926: }
4927: }
4928: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 4929: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4930: }
4931: }
4932: &untiehash();
1.442 www 4933: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4934: $r->print(&endContentScreen());
1.329 droeschl 4935: }
4936:
4937: sub devalidateversioncache {
4938: my $src=shift;
4939: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4940: &Apache::lonnet::clutter($src));
4941: }
4942:
4943: sub checkversions {
1.611 raeburn 4944: my ($r,$canedit) = @_;
1.408 raeburn 4945: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4946: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4947: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4948: $r->print(&startContentScreen('tools'));
1.442 www 4949:
1.329 droeschl 4950: my $header='';
4951: my $startsel='';
4952: my $monthsel='';
4953: my $weeksel='';
4954: my $daysel='';
4955: my $allsel='';
4956: my %changes=();
4957: my $starttime=0;
4958: my $haschanged=0;
4959: my %setversions=&Apache::lonnet::dump('resourceversions',
4960: $env{'course.'.$env{'request.course.id'}.'.domain'},
4961: $env{'course.'.$env{'request.course.id'}.'.num'});
4962:
4963: $hashtied=0;
4964: &tiehash();
1.611 raeburn 4965: if ($canedit) {
4966: my %newsetversions=();
4967: if ($env{'form.setmostrecent'}) {
4968: $haschanged=1;
4969: foreach my $key (keys(%hash)) {
4970: if ($key=~/^ids\_(\/res\/.+)$/) {
4971: $newsetversions{$1}='mostrecent';
4972: &devalidateversioncache($1);
4973: }
4974: }
4975: } elsif ($env{'form.setcurrent'}) {
4976: $haschanged=1;
4977: foreach my $key (keys(%hash)) {
4978: if ($key=~/^ids\_(\/res\/.+)$/) {
4979: my $getvers=&Apache::lonnet::getversion($1);
4980: if ($getvers>0) {
4981: $newsetversions{$1}=$getvers;
4982: &devalidateversioncache($1);
4983: }
4984: }
1.329 droeschl 4985: }
1.611 raeburn 4986: } elsif ($env{'form.setversions'}) {
4987: $haschanged=1;
4988: foreach my $key (keys(%env)) {
4989: if ($key=~/^form\.set_version_(.+)$/) {
4990: my $src=$1;
4991: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4992: $newsetversions{$src}=$env{$key};
4993: &devalidateversioncache($src);
4994: }
4995: }
1.329 droeschl 4996: }
1.611 raeburn 4997: }
4998: if ($haschanged) {
4999: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5000: $env{'course.'.$env{'request.course.id'}.'.domain'},
5001: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5002: $r->print(&Apache::loncommon::confirmwrapper(
5003: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5004: } else {
5005: $r->print(&Apache::loncommon::confirmwrapper(
5006: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 5007: }
1.611 raeburn 5008: &mark_hash_old();
5009: }
5010: &changewarning($r,'');
1.329 droeschl 5011: }
5012: if ($env{'form.timerange'} eq 'all') {
5013: # show all documents
1.549 raeburn 5014: $header=&mt('All content in '.$crstype);
1.521 bisitz 5015: $allsel=' selected="selected"';
1.329 droeschl 5016: foreach my $key (keys(%hash)) {
5017: if ($key=~/^ids\_(\/res\/.+)$/) {
5018: my $src=$1;
5019: $changes{$src}=1;
5020: }
5021: }
5022: } else {
5023: # show documents which changed
5024: %changes=&Apache::lonnet::dump
5025: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5026: $env{'course.'.$env{'request.course.id'}.'.num'});
5027: my $firstkey=(keys(%changes))[0];
5028: unless ($firstkey=~/^error\:/) {
5029: unless ($env{'form.timerange'}) {
5030: $env{'form.timerange'}=604800;
5031: }
5032: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5033: .&mt('seconds');
5034: if ($env{'form.timerange'}==-1) {
5035: $seltext='since start of course';
1.521 bisitz 5036: $startsel=' selected="selected"';
1.329 droeschl 5037: $env{'form.timerange'}=time;
5038: }
5039: $starttime=time-$env{'form.timerange'};
5040: if ($env{'form.timerange'}==2592000) {
5041: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5042: $monthsel=' selected="selected"';
1.329 droeschl 5043: } elsif ($env{'form.timerange'}==604800) {
5044: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5045: $weeksel=' selected="selected"';
1.329 droeschl 5046: } elsif ($env{'form.timerange'}==86400) {
5047: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5048: $daysel=' selected="selected"';
1.329 droeschl 5049: }
5050: $header=&mt('Content changed').' '.$seltext;
5051: } else {
5052: $header=&mt('No content modifications yet.');
5053: }
5054: }
5055: %setversions=&Apache::lonnet::dump('resourceversions',
5056: $env{'course.'.$env{'request.course.id'}.'.domain'},
5057: $env{'course.'.$env{'request.course.id'}.'.num'});
5058: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5059: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5060: 'lm' => 'Version changes since last Month',
5061: 'lw' => 'Version changes since last Week',
5062: 'sy' => 'Version changes since Yesterday',
5063: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5064: 'cd' => 'Change display',
1.329 droeschl 5065: 'sd' => 'Display',
5066: 'fi' => 'File',
5067: 'md' => 'Modification Date',
5068: 'mr' => 'Most recently published Version',
1.408 raeburn 5069: 've' => 'Version used in '.$crstype,
5070: 'vu' => 'Set Version to be used in '.$crstype,
5071: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5072: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5073: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5074: 'di' => 'Differences',
1.484 raeburn 5075: 'save' => 'Save changes',
5076: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5077: 'act' => 'Actions');
1.611 raeburn 5078: my ($disabled,$readonly);
5079: unless ($canedit) {
5080: $disabled = 'disabled="disabled"';
5081: $readonly = 1;
5082: }
1.329 droeschl 5083: $r->print(<<ENDHEADERS);
1.484 raeburn 5084: <h4 class="LC_info">$header</h4>
1.329 droeschl 5085: <form action="/adm/coursedocs" method="post">
5086: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5087: <div class="LC_left_float">
1.479 golterma 5088: <fieldset>
1.484 raeburn 5089: <legend>$lt{'cd'}</legend>
1.329 droeschl 5090: <select name="timerange">
1.521 bisitz 5091: <option value='all'$allsel>$lt{'al'}</option>
5092: <option value="-1"$startsel>$lt{'st'}</option>
5093: <option value="2592000"$monthsel>$lt{'lm'}</option>
5094: <option value="604800"$weeksel>$lt{'lw'}</option>
5095: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5096: </select>
5097: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5098: </fieldset>
5099: </div>
5100: <div class="LC_left_float">
5101: <fieldset>
5102: <legend>$lt{'act'}</legend>
1.611 raeburn 5103: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5104: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5105: </fieldset>
5106: </div>
5107: <br clear="all" />
5108: <hr />
5109: <h4>$lt{'vers'}</h4>
1.329 droeschl 5110: ENDHEADERS
1.479 golterma 5111: #number of columns for version history
1.571 raeburn 5112: my %changedbytime;
5113: foreach my $key (keys(%changes)) {
5114: #excludes not versionable problems from resource version history:
5115: next if ($key =~ /^\/res\/lib\/templates/);
5116: my $chg;
5117: if ($env{'form.timerange'} eq 'all') {
5118: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5119: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5120: } else {
5121: $chg = $changes{$key};
5122: next if ($chg < $starttime);
5123: }
5124: push(@{$changedbytime{$chg}},$key);
5125: }
5126: if (keys(%changedbytime) == 0) {
5127: &untiehash();
5128: $r->print(&mt('No content changes in imported content in specified time frame').
5129: &endContentScreen());
5130: return;
5131: }
1.479 golterma 5132: $r->print(
1.611 raeburn 5133: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5134: &Apache::loncommon::start_data_table().
5135: &Apache::loncommon::start_data_table_header_row().
5136: '<th>'.&mt('Resources').'</th>'.
5137: "<th>$lt{'mr'}</th>".
5138: "<th>$lt{'ve'}</th>".
5139: "<th>$lt{'vu'}</th>".
5140: '<th>'.&mt('History').'</th>'.
5141: &Apache::loncommon::end_data_table_header_row()
5142: );
1.571 raeburn 5143: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5144: foreach my $key (sort(@{$changedbytime{$chg}})) {
5145: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5146: my $currentversion=&Apache::lonnet::getversion($key);
5147: if ($currentversion<0) {
5148: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5149: }
5150: my $linkurl=&Apache::lonnet::clutter($key);
5151: $r->print(
5152: &Apache::loncommon::start_data_table_row().
5153: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5154: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5155: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5156: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5157: '<td align="right">'
5158: );
5159: # Used in course
5160: my $usedversion=$hash{'version_'.$linkurl};
5161: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5162: if ($usedversion != $currentversion) {
1.479 golterma 5163: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5164: } else {
1.479 golterma 5165: $r->print($usedversion);
5166: }
1.329 droeschl 5167: } else {
1.521 bisitz 5168: $r->print($currentversion);
1.329 droeschl 5169: }
1.571 raeburn 5170: $r->print('</td><td title="'.$lt{'vu'}.'">');
5171: # Set version
5172: $r->print(&Apache::loncommon::select_form(
5173: $setversions{$linkurl},
5174: 'set_version_'.$linkurl,
5175: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5176: '' => '',
5177: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5178: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5179: my $lastold=1;
5180: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5181: my $url=$root.'.'.$prevvers.'.'.$extension;
5182: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5183: $lastold=$prevvers;
5184: }
5185: }
5186: $r->print('</td>');
5187: # List all available versions
5188: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5189: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5190: my $url=$root.'.'.$prevvers.'.'.$extension;
5191: $r->print(
5192: '<span class="LC_nobreak">'
5193: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5194: .&mt('Version [_1]',$prevvers).'</a>'
5195: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5196: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5197: .')');
5198: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5199: $r->print(
5200: ' <a href="/adm/diff?filename='.
5201: &Apache::lonnet::clutter($root.'.'.$extension).
5202: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5203: '" target="diffs">'.&mt('Diffs').'</a>');
5204: }
5205: $r->print('</span><br />');
1.329 droeschl 5206: }
1.571 raeburn 5207: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5208: }
1.329 droeschl 5209: }
1.521 bisitz 5210: $r->print(
5211: &Apache::loncommon::end_data_table().
1.611 raeburn 5212: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5213: '</form>'
5214: );
1.329 droeschl 5215:
5216: &untiehash();
1.521 bisitz 5217: $r->print(&endContentScreen());
1.571 raeburn 5218: return;
1.329 droeschl 5219: }
5220:
5221: sub mark_hash_old {
5222: my $retie_hash=0;
5223: if ($hashtied) {
5224: $retie_hash=1;
5225: &untiehash();
5226: }
5227: &tiehash('write');
5228: $hash{'old'}=1;
5229: &untiehash();
5230: if ($retie_hash) { &tiehash(); }
5231: }
5232:
5233: sub is_hash_old {
5234: my $untie_hash=0;
5235: if (!$hashtied) {
5236: $untie_hash=1;
5237: &tiehash();
5238: }
5239: my $return=$hash{'old'};
5240: if ($untie_hash) { &untiehash(); }
5241: return $return;
5242: }
5243:
5244: sub changewarning {
5245: my ($r,$postexec,$message,$url)=@_;
5246: if (!&is_hash_old()) { return; }
5247: my $pathvar='folderpath';
5248: my $path=&escape($env{'form.folderpath'});
5249: if (!defined($url)) {
5250: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5251: }
5252: my $course_type = &Apache::loncommon::course_type();
5253: if (!defined($message)) {
5254: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5255: }
1.653 raeburn 5256: my $windowname = 'loncapaclient';
5257: if ($env{'request.lti.login'}) {
5258: $windowname .= 'lti';
5259: }
1.329 droeschl 5260: $r->print("\n\n".
1.372 bisitz 5261: '<script type="text/javascript">'."\n".
5262: '// <![CDATA['."\n".
5263: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5264: '// ]]>'."\n".
1.369 bisitz 5265: '</script>'."\n".
1.653 raeburn 5266: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5267: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5268: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5269: &mt($message,' <input type="hidden" name="'.
5270: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5271: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5272: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5273: }
5274:
5275:
5276: sub init_breadcrumbs {
1.571 raeburn 5277: my ($form,$text,$help)=@_;
1.329 droeschl 5278: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5279: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5280: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5281: faq=>273,
5282: bug=>'Instructor Interface',
1.571 raeburn 5283: help => $help});
1.329 droeschl 5284: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5285: text=>$text,
5286: faq=>273,
5287: bug=>'Instructor Interface'});
5288: }
5289:
1.441 www 5290: # subroutine to list form elements
5291: sub create_list_elements {
5292: my @formarr = @_;
5293: my $list = '';
1.501 raeburn 5294: foreach my $button (@formarr){
5295: foreach my $picture (keys(%{$button})) {
5296: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5297: }
5298: }
5299: return $list;
5300: }
1.329 droeschl 5301:
1.441 www 5302: # subroutine to create ul from list elements
5303: sub create_form_ul {
5304: my $list = shift;
5305: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5306: return $ul;
5307: }
1.329 droeschl 5308:
1.442 www 5309: #
5310: # Start tabs
5311: #
5312:
5313: sub startContentScreen {
1.484 raeburn 5314: my ($mode) = @_;
5315: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5316: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5317: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5318: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5319: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5320: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5321: } else {
1.549 raeburn 5322: $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 5323: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5324: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5325: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5326: }
5327: $output .= "\n".'</ul>'."\n";
5328: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5329: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5330: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5331: return $output;
1.442 www 5332: }
5333:
5334: #
5335: # End tabs
5336: #
5337:
5338: sub endContentScreen {
1.484 raeburn 5339: return '</div></div></div>';
1.442 www 5340: }
1.329 droeschl 5341:
1.446 www 5342: sub supplemental_base {
1.548 raeburn 5343: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5344: }
5345:
1.329 droeschl 5346: sub handler {
5347: my $r = shift;
5348: &Apache::loncommon::content_type($r,'text/html');
5349: $r->send_http_header;
5350: return OK if $r->header_only;
1.484 raeburn 5351:
5352: # get course data
1.408 raeburn 5353: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5354: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5355: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5356:
1.606 raeburn 5357: # get docroot
5358: my $londocroot = $r->dir_config('lonDocRoot');
5359:
1.484 raeburn 5360: # graphics settings
5361: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5362:
1.443 www 5363: #
1.329 droeschl 5364: # --------------------------------------------- Initialize help topics for this
5365: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5366: 'Adding_External_Resource','Adding_External_Tool',
5367: 'Navigate_Content','Adding_Folders','Docs_Overview',
5368: 'Load_Map','Supplemental','Score_Upload_Form',
5369: 'Adding_Pages','Importing_LON-CAPA_Resource',
5370: 'Importing_IMS_Course','Uploading_From_Harddrive',
5371: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5372: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5373: }
5374: # Composite help files
5375: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5376: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5377: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5378: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5379: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5380: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5381: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5382: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5383: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5384: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5385:
1.611 raeburn 5386: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5387: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5388: unless ($r->uri eq '/adm/supplemental') {
5389: # does this user have privileges to modify content.
1.611 raeburn 5390: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5391: $allowed = 1;
5392: $canedit = 1;
5393: $canview = 1;
5394: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5395: $allowed = 1;
5396: $canview = 1;
5397: }
5398: }
5399: unless ($canedit) {
5400: $disabled = ' disabled="disabled"';
1.472 raeburn 5401: }
1.582 raeburn 5402: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5403: if ($env{'form.inhibitmenu'}) {
5404: unless ($env{'form.inhibitmenu'} eq 'yes') {
5405: delete($env{'form.inhibitmenu'});
5406: }
5407: }
5408:
1.582 raeburn 5409: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5410: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5411: if (!$canedit) {
5412: &verifycontent($r);
5413: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5414: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5415: text=>'Results',
5416: faq=>273,
5417: bug=>'Instructor Interface'});
5418: &verifycontent($r,$env{'form.checkstale'});
5419: } else {
5420: &contentverifyform($r);
5421: }
1.329 droeschl 5422: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5423: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5424: &list_symbs($r);
1.651 raeburn 5425: } elsif ($allowed && $env{'form.shorturls'}) {
5426: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5427: &short_urls($r,$canedit);
1.329 droeschl 5428: } elsif ($allowed && $env{'form.docslog'}) {
5429: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5430: my $folder = $env{'form.folder'};
5431: if ($folder eq '') {
5432: $folder='default';
5433: }
1.611 raeburn 5434: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5435: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5436: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5437: &checkversions($r,$canedit);
5438: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5439: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5440: &dumpcourse($r);
1.611 raeburn 5441: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5442: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5443: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5444: } else {
1.611 raeburn 5445: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5446: $noendpage = 1;
5447: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5448: if ($redirect) {
5449: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5450: my $container = 'sequence';
5451: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5452: $is_random_order,$container) =
5453: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5454: my (@folders)=split('&',$env{'form.folderpath'});
5455: $env{'form.foldername'}=&unescape(pop(@folders));
5456: my $folder=pop(@folders);
5457: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5458: $folder.'.'.$container);
5459: my $warning;
5460: if ($fatal) {
5461: if ($container eq 'page') {
5462: $warning = &mt('An error occurred retrieving the contents of the current page.');
5463: } else {
5464: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5465: }
5466: } else {
5467: my $url = $redirect;
5468: my $srcfile = $londocroot.$url;
5469: $url =~ s{^/priv/}{/res/};
5470: my $targetfile = $londocroot.$url;
5471: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5472: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5473: $env{'form.folder'} = $folder;
5474: &snapshotbefore();
5475: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5476: my $ext = 'false';
5477: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5478: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5479: ':'.$ext.':normal:res';
5480: push(@LONCAPA::map::order,$newidx);
5481: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5482: 'string_yesno');
5483: &remember_parms($newidx,'hiddenresource','set','yes');
5484: ($errtext,$fatal) =
5485: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5486: &log_differences($plain);
5487: &mark_hash_old();
5488: $r->internal_redirect($redirect);
5489: return OK;
5490: }
1.654 raeburn 5491: } else {
5492: $r->internal_redirect($redirect);
1.606 raeburn 5493: }
5494: }
5495: }
1.445 www 5496: #
5497: # Done catching special calls
1.484 raeburn 5498: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5499: # Get the parameters that may be needed
5500: #
5501: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5502: ['folderpath',
5503: 'forcesupplement','forcestandard',
1.510 raeburn 5504: 'tools','symb','command','supppath']);
1.445 www 5505:
1.635 raeburn 5506: foreach my $item ('forcesupplement','forcestandard','tools') {
5507: next if ($env{'form.'.$item} eq '');
5508: unless ($env{'form.'.$item} eq '1') {
5509: delete($env{'form.'.$item});
5510: }
5511: }
5512:
5513: if ($env{'form.command'}) {
5514: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5515: delete($env{'form.command'});
5516: }
5517: }
5518:
5519: if ($env{'form.symb'}) {
5520: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5521: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5522: delete($env{'form.symb'});
5523: }
5524: }
5525:
1.445 www 5526: # standard=1: this is a "new-style" course with an uploaded map as top level
5527: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5528:
5529: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5530:
1.484 raeburn 5531: # Decide whether this should display supplemental or main content or utilities
1.445 www 5532: # supplementalflag=1: show supplemental documents
5533: # supplementalflag=0: show standard documents
1.484 raeburn 5534: # toolsflag=1: show utilities
1.445 www 5535:
1.561 raeburn 5536: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5537: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5538: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5539: $supplementalflag=0;
5540: }
5541: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5542: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5543: unless ($allowed) { $supplementalflag=1; }
5544: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5545: my $toolsflag=0;
5546: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5547:
1.635 raeburn 5548: if ($env{'form.folderpath'} ne '') {
5549: my @items = split(/\&/,$env{'form.folderpath'});
5550: my $badpath;
5551: for (my $i=0; $i<@items; $i++) {
5552: my $odd = $i%2;
5553: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5554: $badpath = 1;
5555: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5556: $badpath = 1;
5557: }
5558: last if ($badpath);
5559: }
5560: if ($badpath) {
5561: delete($env{'form.folderpath'});
5562: }
5563: }
5564:
5565: if ($env{'form.supppath'} ne '') {
5566: my @items = split(/\&/,$env{'form.supppath'});
5567: my $badpath;
5568: for (my $i=0; $i<@items; $i++) {
5569: my $odd = $i%2;
5570: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5571: $badpath = 1;
5572: }
5573: last if ($badpath);
5574: }
5575: if ($badpath) {
5576: delete($env{'form.supppath'});
5577: }
5578: }
5579:
1.329 droeschl 5580: my $script='';
5581: my $showdoc=0;
1.457 raeburn 5582: my $addentries = {};
1.475 raeburn 5583: my $container;
1.329 droeschl 5584: my $containertag;
1.508 raeburn 5585: my $pathitem;
1.598 raeburn 5586: my %ltitools;
1.617 raeburn 5587: my $hiddentop;
1.615 raeburn 5588: my $navmap;
1.617 raeburn 5589: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5590:
1.464 www 5591: # Do we directly jump somewhere?
1.525 raeburn 5592: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5593: if ($env{'form.symb'} ne '') {
1.522 raeburn 5594: $env{'form.folderpath'}=
1.617 raeburn 5595: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5596: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5597: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5598: } elsif ($env{'form.supppath'} ne '') {
5599: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5600: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5601: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5602: }
1.472 raeburn 5603: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5604: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5605: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5606: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5607: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5608: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5609: } elsif ($env{'form.command'} eq 'contents') {
5610: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5611: } elsif ($env{'form.command'} eq 'home') {
5612: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5613: }
5614:
1.525 raeburn 5615:
1.445 www 5616: # Where do we store these for when we come back?
5617: my $stored_folderpath='docs_folderpath';
5618: if ($supplementalflag) {
5619: $stored_folderpath='docs_sup_folderpath';
5620: }
1.464 www 5621:
1.519 raeburn 5622: # No folderpath, and in edit mode, see if we have something stored
5623: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5624: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5625: {'folderpath' => 'scalar'});
1.615 raeburn 5626:
5627: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5628: if ($supplementalflag) {
5629: undef($env{'form.folderpath'}) if ($1 eq 'default');
5630: } else {
5631: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5632: }
5633: } else {
1.523 raeburn 5634: undef($env{'form.folderpath'});
5635: }
1.329 droeschl 5636: }
1.446 www 5637:
5638: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5639: if (!$allowed) {
1.446 www 5640: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5641: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5642: }
5643: }
1.446 www 5644: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5645: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5646: $env{'form.folderpath'} = &supplemental_base()
5647: .'&'.
1.329 droeschl 5648: $env{'form.folderpath'};
5649: }
1.615 raeburn 5650: # If allowed and user's role is not advanced check folderpath is not hidden
5651: if (($allowed) && (!$env{'request.role.adv'}) &&
5652: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5653: my $folderurl;
5654: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5655: my $folder = $pathitems[-2];
5656: if ($folder eq '') {
5657: undef($env{'form.folderpath'});
5658: } else {
5659: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.666 raeburn 5660: if ((split(/\:/,$pathitems[-1]))[5]) {
1.615 raeburn 5661: $folderurl .= '.page';
5662: } else {
5663: $folderurl .= '.sequence';
5664: }
1.617 raeburn 5665: unless (ref($navmap)) {
5666: $navmap = Apache::lonnavmaps::navmap->new();
5667: }
1.615 raeburn 5668: if (ref($navmap)) {
5669: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5670: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5671: unless (@resources) {
5672: undef($env{'form.folderpath'});
5673: }
1.615 raeburn 5674: }
5675: }
5676: }
5677: }
5678:
5679:
1.446 www 5680: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5681: unless ($env{'form.folderpath'}) {
1.446 www 5682: if ($supplementalflag) {
5683: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5684: } elsif ($allowed) {
5685: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5686: }
1.472 raeburn 5687: }
1.446 www 5688:
1.445 www 5689: # Store this
1.484 raeburn 5690: unless ($toolsflag) {
1.615 raeburn 5691: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5692: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5693: {'folderpath' => 'scalar'});
1.510 raeburn 5694: }
1.519 raeburn 5695: my $folderpath;
1.484 raeburn 5696: if ($env{'form.folderpath'}) {
1.519 raeburn 5697: $folderpath = $env{'form.folderpath'};
5698: my (@folders)=split('&',$env{'form.folderpath'});
5699: $env{'form.foldername'}=&unescape(pop(@folders));
5700: if ($env{'form.foldername'} =~ /\:1$/) {
5701: $container = 'page';
5702: } else {
5703: $container = 'sequence';
5704: }
5705: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5706: } else {
1.519 raeburn 5707: if ($env{'form.folder'} eq '' ||
5708: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5709: if ($env{'form.folder'} eq 'supplemental') {
5710: $folderpath=&supplemental_base();
5711: } elsif (!$hiddentop) {
5712: $folderpath='default&'.
5713: &escape(&mt('Main Content').':::::');
5714: }
1.484 raeburn 5715: }
5716: }
1.519 raeburn 5717: $containertag = '<input type="hidden" name="folderpath" value="" />';
5718: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5719: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5720: $showdoc='/'.$1;
5721: }
5722: if ($showdoc) { # got called in sequence from course
5723: $allowed=0;
5724: } else {
1.611 raeburn 5725: if ($canedit) {
1.484 raeburn 5726: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5727: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5728: }
5729: }
1.329 droeschl 5730: }
5731:
1.344 bisitz 5732: # get personal data
1.329 droeschl 5733: my $uname=$env{'user.name'};
5734: my $udom=$env{'user.domain'};
5735: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5736:
5737: if ($allowed) {
1.484 raeburn 5738: if ($toolsflag) {
5739: $script .= &inject_data_js();
5740: my ($home,$other,%outhash)=&authorhosts();
5741: if (!$home && $other) {
5742: my @hosts;
5743: foreach my $aurole (keys(%outhash)) {
5744: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5745: push(@hosts,$outhash{$aurole});
5746: }
5747: }
5748: $script .= &dump_switchserver_js(@hosts);
5749: }
1.458 raeburn 5750: } else {
1.570 raeburn 5751: my $tid = 1;
1.484 raeburn 5752: my @tabids;
5753: if ($supplementalflag) {
1.655 raeburn 5754: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5755: $tid = 2;
1.484 raeburn 5756: } else {
5757: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5758: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5759: unshift(@tabids,'001');
5760: push(@tabids,('dd1','ee1'));
5761: }
1.458 raeburn 5762: }
1.484 raeburn 5763: my $tabidstr = join("','",@tabids);
1.644 raeburn 5764: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600 raeburn 5765: my $posslti = keys(%ltitools);
1.622 raeburn 5766: my $hostname = $r->hostname();
1.606 raeburn 5767: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5768: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5769: &history_tab_js().
5770: &inject_data_js().
1.570 raeburn 5771: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5772: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5773: $addentries = {
1.485 raeburn 5774: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5775: };
1.458 raeburn 5776: }
1.538 raeburn 5777: $script .= &paste_popup_js();
1.501 raeburn 5778: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5779: &mt('Switch server?');
5780:
5781:
1.329 droeschl 5782: }
5783: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5784: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5785: .'// <![CDATA['."\n"
5786: .$script."\n"
5787: .'// ]]>'."\n"
1.595 musolffc 5788: .'</script>'."\n"
5789: .'<script type="text/javascript"
5790: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5791:
5792: # Breadcrumbs
5793: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5794:
5795: if ($showdoc) {
5796: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5797: {'force_register' => $showdoc,}));
1.571 raeburn 5798: } elsif ($toolsflag) {
1.611 raeburn 5799: my ($breadtext,$breadtitle);
1.617 raeburn 5800: $breadtext = "$crstype Editor";
1.611 raeburn 5801: if ($canedit) {
5802: $breadtitle = 'Editing '.$crstype.' Contents';
5803: } else {
5804: $breadtext .= ' (View-only mode)';
5805: $breadtitle = 'Viewing '.$crstype.' Contents';
5806: }
1.571 raeburn 5807: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5808: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5809: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5810: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5811: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5812: $breadtitle)
1.571 raeburn 5813: );
1.510 raeburn 5814: } elsif ($r->uri eq '/adm/supplemental') {
5815: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5816: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5817: {'bread_crumbs' => $brcrum,}));
5818: } else {
1.611 raeburn 5819: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5820: $breadtext = "$crstype Editor";
1.611 raeburn 5821: if ($canedit) {
5822: $breadtitle = 'Editing '.$crstype.' Contents';
5823: $helpitem = 'Docs_Adding_Course_Doc';
5824: } else {
5825: $breadtext .= ' (View-only mode)';
5826: $breadtitle = 'Viewing '.$crstype.' Contents';
5827: $helpitem = 'Docs_Viewing_Course_Doc';
5828: }
1.392 raeburn 5829: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5830: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5831: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5832: {'add_entries' => $addentries}
5833: )
1.392 raeburn 5834: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5835: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5836: $breadtitle,
5837: $helpitem)
1.392 raeburn 5838: );
5839: }
1.364 bisitz 5840:
1.329 droeschl 5841: my %allfiles = ();
5842: my %codebase = ();
1.440 raeburn 5843: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5844: if ($canedit) {
1.329 droeschl 5845: if (($env{'form.uploaddoc.filename'}) &&
5846: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5847: my $context = $1;
5848: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5849: undef($hadchanges);
1.440 raeburn 5850: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5851: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 5852: undef($navmap);
1.329 droeschl 5853: if ($hadchanges) {
5854: &mark_hash_old();
5855: }
1.440 raeburn 5856: $r->print($upload_output);
5857: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5858: # Process file upload - phase two - upload embedded objects
5859: $uploadphase = 'check_embedded';
5860: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5861: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5862: $env{'form.newidx'});
5863: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5864: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5865: my ($destination,$dir_root) = &embedded_destination();
5866: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5867: my $actionurl = '/adm/coursedocs';
1.630 raeburn 5868: my ($result,$flag) =
1.440 raeburn 5869: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5870: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5871: $actionurl);
5872: $r->print($result.&return_to_editor());
5873: } elsif ($env{'form.phase'} eq 'check_embedded') {
5874: # Process file upload - phase three - modify references in HTML file
5875: $uploadphase = 'modified_orightml';
5876: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5877: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5878: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 5879: my $result =
1.482 raeburn 5880: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5881: $docuname,$docudom,undef,
5882: $dir_root);
1.630 raeburn 5883: $r->print($result.&return_to_editor());
1.476 raeburn 5884: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5885: $uploadphase = 'decompress_phase_one';
5886: $r->print(&decompression_phase_one().
5887: &return_to_editor());
5888: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5889: $uploadphase = 'decompress_phase_two';
5890: $r->print(&decompression_phase_two().
5891: &return_to_editor());
1.329 droeschl 5892: }
5893: }
5894:
1.484 raeburn 5895: if ($allowed && $toolsflag) {
5896: $r->print(&startContentScreen('tools'));
1.611 raeburn 5897: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5898: $r->print(&endContentScreen());
5899: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5900: # -----------------------------------------------------------------------------
5901: my %lt=&Apache::lonlocal::texthash(
5902: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5903: 'upfi' => 'Upload File',
1.553 raeburn 5904: 'upld' => 'Upload Content',
1.329 droeschl 5905: 'srch' => 'Search',
5906: 'impo' => 'Import',
1.487 raeburn 5907: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5908: 'impm' => 'Import from Assembled Map',
1.630 raeburn 5909: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5910: 'extr' => 'External Resource',
5911: 'extt' => 'External Tool',
1.329 droeschl 5912: 'selm' => 'Select Map',
5913: 'load' => 'Load Map',
5914: 'newf' => 'New Folder',
5915: 'newp' => 'New Composite Page',
5916: 'syll' => 'Syllabus',
1.425 raeburn 5917: 'navc' => 'Table of Contents',
1.343 biermanm 5918: 'sipa' => 'Simple Course Page',
1.329 droeschl 5919: 'sipr' => 'Simple Problem',
1.630 raeburn 5920: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5921: 'stpr' => 'Standard Problem',
5922: 'news' => 'New sub-directory',
5923: 'crpr' => 'Create Problem',
1.329 droeschl 5924: 'drbx' => 'Drop Box',
1.451 www 5925: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5926: 'bull' => 'Discussion Board',
1.347 weissno 5927: 'mypi' => 'My Personal Information Page',
1.353 weissno 5928: 'grpo' => 'Group Portfolio',
1.329 droeschl 5929: 'rost' => 'Course Roster',
1.528 raeburn 5930: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5931: 'imsf' => 'IMS Upload',
5932: 'imsl' => 'Upload IMS package',
1.501 raeburn 5933: 'cms' => 'Origin of IMS package',
5934: 'se' => 'Select',
1.329 droeschl 5935: 'file' => 'File',
5936: 'title' => 'Title',
1.606 raeburn 5937: 'addp' => 'Add Placeholder to course?',
5938: 'uste' => 'Use Template?',
5939: 'fnam' => 'File Name:',
5940: 'loca' => 'Location:',
5941: 'dire' => 'Directory:',
5942: 'cate' => 'Category:',
5943: 'tmpl' => 'Template:',
1.329 droeschl 5944: 'comment' => 'Comment',
1.403 raeburn 5945: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5946: 'bb5' => 'Blackboard 5',
5947: 'bb6' => 'Blackboard 6',
5948: 'angel5' => 'ANGEL 5.5',
5949: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5950: 'yes' => 'Yes',
5951: 'no' => 'No',
1.618 raeburn 5952: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5953: );
1.329 droeschl 5954: # -----------------------------------------------------------------------------
1.595 musolffc 5955:
5956: # Calculate free quota space for a user or course. A javascript function checks
5957: # file size to determine if upload should be allowed.
5958: my $quotatype = 'unofficial';
5959: if ($crstype eq 'Community') {
1.601 raeburn 5960: $quotatype = 'community';
5961: } elsif ($crstype eq 'Placement') {
5962: $quotatype = 'placement';
1.595 musolffc 5963: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5964: $quotatype = 'official';
5965: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5966: $quotatype = 'textbook';
5967: }
5968: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5969: 'course',$quotatype); # expressed in MB
5970: my $current_disk_usage = 0;
5971: foreach my $subdir ('docs','supplemental') {
5972: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5973: "userfiles/$subdir",1); # expressed in kB
5974: }
5975: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5976: my $usage = $current_disk_usage/1024; # in MB
5977: my $quota = $disk_quota;
5978: my $percent;
5979: if ($disk_quota == 0) {
5980: $percent = 100.0;
5981: } else {
1.619 raeburn 5982: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5983: }
5984: $usage = sprintf("%.2f",$usage);
5985: $quota = sprintf("%.2f",$quota);
5986: $percent = sprintf("%.0f",$percent);
5987: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5988: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5989:
1.329 droeschl 5990: my $fileupload=(<<FIUP);
1.605 raeburn 5991: $quotainfo
1.329 droeschl 5992: $lt{'file'}:<br />
1.662 raeburn 5993: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663 raeburn 5994: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5995: FIUP
5996:
5997: my $checkbox=(<<CHBO);
5998: <!-- <label>$lt{'parse'}?
5999: <input type="checkbox" name="parserflag" />
6000: </label> -->
6001: <label>
1.611 raeburn 6002: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 6003: </label>
6004: CHBO
1.501 raeburn 6005: my $imsfolder = $env{'form.folder'};
6006: if ($imsfolder eq '') {
6007: $imsfolder = 'default';
6008: }
6009: my $imspform=(<<IMSFORM);
6010: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6011: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6012: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 6013: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 6014: <legend>$lt{'imsf'}</legend>
6015: $fileupload
6016: <br />
6017: <p>
6018: $lt{'cms'}:
1.611 raeburn 6019: <select name="source" $disabled>
1.501 raeburn 6020: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 6021: <option value="bb5">$lt{'bb5'}</option>
6022: <option value="bb6">$lt{'bb6'}</option>
6023: <option value="angel5">$lt{'angel5'}</option>
6024: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6025: </select>
6026: <input type="hidden" name="folder" value="$imsfolder" />
6027: </p>
6028: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6029: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6030: </fieldset>
6031: </form>
6032: IMSFORM
1.329 droeschl 6033:
6034: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6035: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6036: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6037: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6038: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6039: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6040: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6041: $fileupload
1.329 droeschl 6042: <br />
6043: $lt{'title'}:<br />
1.611 raeburn 6044: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6045: $pathitem
1.329 droeschl 6046: <input type="hidden" name="cmd" value="upload_default" />
6047: <br />
1.458 raeburn 6048: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6049: $checkbox
6050: </span>
1.501 raeburn 6051: <br clear="all" />
1.611 raeburn 6052: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6053: </fieldset>
6054: </form>
1.383 tempelho 6055: FUFORM
1.329 droeschl 6056:
1.611 raeburn 6057: my $mapimportjs;
6058: if ($canedit) {
6059: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6060: } else {
6061: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6062: }
1.502 raeburn 6063: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6064: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6065: $lt{'impm'}</a>$help{'Load_Map'}
6066: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6067: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6068: <legend>$lt{'impm'}</legend>
1.371 tempelho 6069: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6070: $lt{'copm'}<br />
6071: <span class="LC_nobreak">
6072: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6073: onfocus="this.blur();$mapimportjs" $disabled />
6074: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6075: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6076: </fieldset>
6077: </form>
6078:
1.383 tempelho 6079: SEDFFORM
1.606 raeburn 6080: my $importcrsresform;
1.608 raeburn 6081: my ($numdirs,$pickfile) =
6082: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
6083: "resize_scrollbox('contentscroll','1','0');",
6084: undef,'res');
1.606 raeburn 6085: if ($pickfile) {
6086: $importcrsresform=(<<CRSFORM);
6087: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
6088: $lt{'imcr'}</a>$help{'Course_Resources'}
6089: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6090: <fieldset id="importcrsresform" style="display: none;">
6091: <legend>$lt{'imcr'}</legend>
6092: <input type="hidden" name="active" value="bb" />
6093: $pickfile
6094: <p>
1.611 raeburn 6095: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 6096: </p>
6097: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 6098: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 6099: </fieldset>
6100: </form>
6101: CRSFORM
6102: }
6103:
1.611 raeburn 6104: my $fromstoredjs;
6105: if ($canedit) {
6106: $fromstoredjs = 'open_StoredLinks_Import()';
6107: } else {
6108: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6109: }
6110:
1.502 raeburn 6111: my @importpubforma = (
1.508 raeburn 6112: { '<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 6113: { '<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 6114: { '<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 6115: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6116: );
6117: if ($pickfile) {
6118: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
6119: }
1.502 raeburn 6120: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6121: my $extresourcesform =
6122: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6123: $help{'Adding_External_Resource'},
6124: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6125: my $exttoolform =
6126: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6127: $help{'Adding_External_Tool'},undef,
6128: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6129: \%ltitools,$disabled);
1.329 droeschl 6130: if ($allowed) {
1.492 raeburn 6131: my $folder = $env{'form.folder'};
6132: if ($folder eq '') {
6133: $folder='default';
6134: }
1.615 raeburn 6135: if ($canedit) {
6136: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6137: if ($output) {
6138: $r->print($output);
6139: }
1.538 raeburn 6140: }
1.337 ehlerst 6141: $r->print(<<HIDDENFORM);
6142: <form name="renameform" method="post" action="/adm/coursedocs">
6143: <input type="hidden" name="title" />
6144: <input type="hidden" name="cmd" />
6145: <input type="hidden" name="markcopy" />
6146: <input type="hidden" name="copyfolder" />
6147: $containertag
6148: </form>
1.633 raeburn 6149: <form name="aliasform" method="post" action="/adm/coursedocs">
6150: <input type="hidden" name="alias" />
6151: <input type="hidden" name="cmd" />
6152: $containertag
6153: </form>
1.484 raeburn 6154:
1.337 ehlerst 6155: HIDDENFORM
1.508 raeburn 6156: $r->print(&makesimpleeditform($pathitem)."\n".
6157: &makedocslogform($pathitem."\n".
1.484 raeburn 6158: '<input type="hidden" name="folder" value="'.
6159: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6160: }
1.442 www 6161:
6162: # Generate the tabs
1.510 raeburn 6163: my ($mode,$needs_end);
1.472 raeburn 6164: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6165: my @folders = split('&',$env{'form.folderpath'});
6166: unless (@folders > 2) {
6167: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6168: $needs_end = 1;
6169: }
1.472 raeburn 6170: } else {
1.484 raeburn 6171: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6172: $needs_end = 1;
1.472 raeburn 6173: }
1.443 www 6174:
1.442 www 6175: #
1.622 raeburn 6176: my $hostname = $r->hostname();
1.442 www 6177: my $savefolderpath;
6178:
1.395 raeburn 6179: if ($allowed) {
1.329 droeschl 6180: my $folder=$env{'form.folder'};
1.615 raeburn 6181: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6182: $folder='default';
1.356 tempelho 6183: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6184: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6185: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6186: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6187: }
6188: my $postexec='';
6189: if ($folder eq 'default') {
1.653 raeburn 6190: my $windowname = 'loncapaclient';
6191: if ($env{'request.lti.login'}) {
6192: $windowname .= 'lti';
6193: }
1.372 bisitz 6194: $r->print('<script type="text/javascript">'."\n"
6195: .'// <![CDATA['."\n"
1.653 raeburn 6196: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6197: .'// ]]>'."\n"
6198: .'</script>'."\n"
1.369 bisitz 6199: );
1.329 droeschl 6200: } else {
6201: #$postexec='self.close();';
6202: }
1.504 raeburn 6203: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6204: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6205: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6206:
6207: my $newnavform=(<<NNFORM);
6208: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6209: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6210: $pathitem
1.329 droeschl 6211: <input type="hidden" name="importdetail"
6212: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6213: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6214: $help{'Navigate_Content'}
6215: </form>
6216: NNFORM
6217: my $newsmppageform=(<<NSPFORM);
6218: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6219: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6220: $pathitem
1.329 droeschl 6221: <input type="hidden" name="importdetail" value="" />
1.423 onken 6222: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6223: $help{'Simple Page'}
1.329 droeschl 6224: </form>
6225: NSPFORM
6226:
6227: my $newsmpproblemform=(<<NSPROBFORM);
6228: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6229: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6230: $pathitem
1.329 droeschl 6231: <input type="hidden" name="importdetail" value="" />
1.423 onken 6232: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6233: $help{'Simple_Problem'}
1.329 droeschl 6234: </form>
6235:
6236: NSPROBFORM
6237:
6238: my $newdropboxform=(<<NDBFORM);
6239: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6240: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6241: $pathitem
1.329 droeschl 6242: <input type="hidden" name="importdetail" value="" />
1.423 onken 6243: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6244: $help{'Dropbox'}
1.344 bisitz 6245: </form>
1.329 droeschl 6246: NDBFORM
6247:
6248: my $newexuploadform=(<<NEXUFORM);
6249: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6250: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6251: $pathitem
1.329 droeschl 6252: <input type="hidden" name="importdetail" value="" />
1.423 onken 6253: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6254: $help{'Score_Upload_Form'}
6255: </form>
6256: NEXUFORM
6257:
6258: my $newbulform=(<<NBFORM);
6259: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6260: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6261: $pathitem
1.329 droeschl 6262: <input type="hidden" name="importdetail" value="" />
1.423 onken 6263: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6264: $help{'Bulletin Board'}
6265: </form>
6266: NBFORM
6267:
6268: my $newaboutmeform=(<<NAMFORM);
6269: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6270: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6271: $pathitem
1.329 droeschl 6272: <input type="hidden" name="importdetail"
6273: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6274: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6275: $help{'My Personal Information Page'}
1.329 droeschl 6276: </form>
6277: NAMFORM
6278:
6279: my $newaboutsomeoneform=(<<NASOFORM);
6280: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6281: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6282: $pathitem
1.329 droeschl 6283: <input type="hidden" name="importdetail" value="" />
1.423 onken 6284: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6285: </form>
6286: NASOFORM
6287:
6288: my $newrosterform=(<<NROSTFORM);
6289: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6290: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6291: $pathitem
1.329 droeschl 6292: <input type="hidden" name="importdetail"
6293: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6294: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6295: $help{'Course_Roster'}
1.329 droeschl 6296: </form>
6297: NROSTFORM
6298:
1.534 raeburn 6299: my $newwebpage;
6300: if ($folder =~ /^default_?(\d*)$/) {
6301: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6302: if ($1) {
6303: $newwebpage .= $1;
6304: } else {
6305: $newwebpage .= 'default';
6306: }
6307: $newwebpage .= '/new.html';
6308: }
6309: my $newwebpageform =(<<NWEBFORM);
6310: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6311: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6312: $pathitem
6313: <input type="hidden" name="importdetail" value="$newwebpage" />
6314: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6315: $help{'Web_Page'}
1.534 raeburn 6316: </form>
6317: NWEBFORM
1.604 raeburn 6318:
1.606 raeburn 6319: my @ids=&Apache::lonnet::current_machine_ids();
6320: my %select_menus;
6321: my $numauthor = 0;
6322: my $numcrsdirs = 0;
6323: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6324: if ($env{'user.author'}) {
6325: $numauthor ++;
6326: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6327: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6328: my $is_home = 1;
6329: my %subdirs;
1.608 raeburn 6330: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6331: $select_menus{'author'}->{'default'} = '/';
6332: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6333: my @ordered = ('/');
6334: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6335: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6336: push(@ordered,$relpath);
6337: }
6338: $select_menus{'author'}->{'order'} = \@ordered;
6339: } else {
6340: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6341: $select_menus{'author'}->{'default'} = 'switch';
6342: $select_menus{'author'}->{'order'} = ['switch'];
6343: }
6344: }
6345: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6346: ['active'],['ca','aa']);
6347: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6348: my %by_roletype;
6349: if (keys(%roleshash)) {
6350: foreach my $entry (keys(%roleshash)) {
6351: my ($auname,$audom,$roletype) = split(/:/,$entry);
6352: my $key = $entry;
6353: $key =~ s/:/___/g;
6354: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6355: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6356: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6357: if (grep(/^\Q$rolehome\E$/,@ids)) {
6358: my $is_home = 1;
6359: my (%subdirs,@ordered);
6360: my $toppath="/priv/$audom/$auname";
1.608 raeburn 6361: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6362: $select_menus{$key}->{'default'} = '/';
6363: $select_menus{$key}->{'select2'}->{'/'} = '/';
6364: my @ordered = ('/');
6365: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6366: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6367: push(@ordered,$relpath);
6368: }
6369: $select_menus{$key}->{'order'} = \@ordered;
6370: } else {
6371: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6372: $select_menus{$key}->{'default'} = 'switch';
6373: $select_menus{$key}->{'order'} = ['switch'];
6374: }
6375: $numauthor ++;
6376: }
6377: }
1.631 raeburn 6378: my ($pickdir,$showtitle);
1.606 raeburn 6379: if ($numauthor) {
6380: my @order;
6381: my $defrole;
6382: if ($env{'user.author'}) {
6383: push(@order,'author');
6384: $defrole = 'author';
6385: }
6386: if (keys(%by_roletype)) {
6387: foreach my $possrole ('ca','aa') {
6388: if (ref($by_roletype{$possrole}) eq 'HASH') {
6389: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6390: unless ($defrole) {
6391: $defrole = $author;
6392: }
6393: push(@order,$author.'___'.$possrole);
6394: }
6395: }
6396: }
6397: }
6398: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6399: if (grep(/^\Q$crshome\E$/,@ids)) {
6400: my $is_home = 1;
6401: my %subdirs;
6402: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6403: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6404: $numcrsdirs = keys(%subdirs);
6405: $select_menus{'course'}->{'default'} = '/';
6406: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6407: my @ordered = ('/');
6408: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6409: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6410: push(@ordered,$relpath);
6411: }
6412: $select_menus{'course'}->{'order'} = \@ordered;
6413: } else {
6414: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6415: $select_menus{'course'}->{'default'} = 'switch';
6416: $select_menus{'course'}->{'order'} = ['switch'];
6417: }
6418: push(@order,'course');
6419: $pickdir = $lt{'loca'}.
6420: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6421: $defrole,'authorrole','authorpath',
6422: \%select_menus,\@order,'toggleCrsResTitle();',
6423: '','priv').'<br />';
6424: $showtitle = 'none';
6425: } else {
6426: my $is_home;
6427: $showtitle = 'inline';
6428: if (grep(/^\Q$crshome\E$/,@ids)) {
6429: $is_home = 1;
6430: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6431: my $toppath="/priv/$coursedom/$coursenum'}";
6432: my %subdirs;
1.608 raeburn 6433: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6434: $numcrsdirs = keys(%subdirs);
6435: if ($numcrsdirs) {
6436: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6437: '<option value="/">/</option>'."\n";
6438: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6439: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6440: }
6441: $pickdir .= '</select>';
6442: } else {
6443: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6444: }
6445: }
6446: }
6447:
6448: my %seltemplate_menus;
6449: my @files = &Apache::lonhomework::get_template_list('problem');
6450: my @noexamplelink = ('blank.problem','blank.library','script.library');
6451: my $currentcategory = '';
6452: my @ordered = ('');
6453: my %templatehelp;
6454: my $defcategory = '';
6455: my @catorder = ($defcategory);
6456: $seltemplate_menus{$defcategory}->{'order'} = [''];
6457: $seltemplate_menus{$defcategory}->{'text'} = '';
6458: foreach my $file (@files) {
6459: if (ref($file) eq 'ARRAY') {
6460: my ($path,$title,$category,$help) = @{$file};
6461: next if ($title !~ /\S/);
6462: if (&js_escape($category) ne $currentcategory) {
6463: $currentcategory = &js_escape($category);
6464: push(@catorder,&js_escape($currentcategory));
6465: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6466: $seltemplate_menus{$currentcategory}->{'default'} = '';
6467: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6468: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6469: }
6470: if ($path) {
6471: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6472: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6473: if ($help) {
6474: $templatehelp{$path} = $help;
6475: }
6476: }
6477: }
6478: }
6479:
6480: my $templates = $lt{'cate'}.' '.
6481: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6482: $defcategory,'tempcategory','template',
6483: \%seltemplate_menus,\@catorder,
6484: "resize_scrollbox('contentscroll','1','0');",
6485: "toggleExampleText();",'template').'<br />';
6486: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6487: '<span id="newresexample">'.&mt('Example').'<span></a>';
6488: my $crsresform=(<<RESFORM);
6489: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6490: $lt{'stpr'}</a>$help{'Course_Resource'}
6491: <form action="/adm/coursedocs" method="post" name="courseresform">
6492: <fieldset id="crsresform" style="display:none;">
6493: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6494: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6495: <p>
6496: $pickdir
6497: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6498: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6499:
1.611 raeburn 6500: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6501: </span><span id="newsubdir"></span>
6502: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6503: </p>
6504: $lt{'fnam'}
1.611 raeburn 6505: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6506: <p>
6507: <div id="newresource" style="display:$showtitle">
6508: $lt{'addp'}
1.611 raeburn 6509: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6510: $lt{'no'}</label>
1.611 raeburn 6511: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6512: $lt{'yes'}</label>
6513: <span id="newrestitle"></span>
1.611 raeburn 6514: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6515: </div>
6516: </p>
6517: <p>
6518: $lt{'uste'}
1.611 raeburn 6519: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6520: $lt{'no'}</label>
1.611 raeburn 6521: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6522: $lt{'yes'}</label>
6523: <div id="newrestemplate" style="display:none">
6524: $templates
6525: $templatepreview
6526: </div>
6527: </p>
6528: <span class="LC_nobreak">
6529: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6530: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6531: </span>
6532: </fieldset>
6533: </form>
6534:
6535: RESFORM
1.534 raeburn 6536:
1.342 ehlerst 6537: my $specialdocumentsform;
1.383 tempelho 6538: my @specialdocumentsforma;
1.451 www 6539: my $gradingform;
6540: my @gradingforma;
6541: my $communityform;
6542: my @communityforma;
1.351 ehlerst 6543: my $newfolderform;
1.390 tempelho 6544: my $newfolderb;
1.342 ehlerst 6545:
1.451 www 6546: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6547:
1.329 droeschl 6548: my $newpageform=(<<NPFORM);
6549: <form action="/adm/coursedocs" method="post" name="newpage">
6550: <input type="hidden" name="folderpath" value="$path" />
6551: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6552: <input type="hidden" name="active" value="ee" />
1.423 onken 6553: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6554: $help{'Adding_Pages'}
1.329 droeschl 6555: </form>
6556: NPFORM
1.390 tempelho 6557:
6558:
1.351 ehlerst 6559: $newfolderform=(<<NFFORM);
1.329 droeschl 6560: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6561: $pathitem
1.329 droeschl 6562: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6563: <input type="hidden" name="active" value="" />
1.422 onken 6564: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6565: </form>
6566: NFFORM
6567:
6568: my $newsylform=(<<NSYLFORM);
6569: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6570: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6571: $pathitem
1.329 droeschl 6572: <input type="hidden" name="importdetail"
6573: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6574: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6575: $help{'Syllabus'}
1.383 tempelho 6576:
1.329 droeschl 6577: </form>
6578: NSYLFORM
1.364 bisitz 6579:
1.329 droeschl 6580: my $newgroupfileform=(<<NGFFORM);
6581: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6582: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6583: $pathitem
1.329 droeschl 6584: <input type="hidden" name="importdetail"
6585: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6586: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6587: $help{'Group Portfolio'}
1.329 droeschl 6588: </form>
6589: NGFFORM
1.672 raeburn 6590: if ($container eq 'page') {
6591: @specialdocumentsforma=(
6592: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6593: );
6594: } else {
6595: @specialdocumentsforma=(
1.421 onken 6596: {'<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 6597: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6598: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6599: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6600: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.672 raeburn 6601: );
6602: }
1.451 www 6603: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6604:
1.655 raeburn 6605: my @external = (
6606: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6607: );
1.598 raeburn 6608: if (keys(%ltitools)) {
1.655 raeburn 6609: push(@external,
6610: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6611: );
1.598 raeburn 6612: }
1.655 raeburn 6613: my $externalform = &create_form_ul(&create_list_elements(@external));
6614:
6615: my @importdoc = ();
1.519 raeburn 6616: unless ($container eq 'page') {
6617: push(@importdoc,
6618: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6619: );
6620: }
6621: push(@importdoc,
1.558 raeburn 6622: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6623: );
1.501 raeburn 6624: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6625:
1.451 www 6626: @gradingforma=(
6627: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6628: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6629: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6630: {'<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 6631: );
6632: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6633:
6634: @communityforma=(
6635: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6636: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6637: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6638: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6639: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6640: );
6641: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6642:
1.330 tempelho 6643: my %orderhash = (
1.553 raeburn 6644: 'aa' => ['Upload',$fileuploadform],
6645: 'bb' => ['Import',$importpubform],
1.655 raeburn 6646: 'cc' => ['External',$externalform],
6647: 'dd' => ['Grading',$gradingform],
1.673 raeburn 6648: 'ff' => ['Other',$specialdocumentsform],
1.330 tempelho 6649: );
1.519 raeburn 6650: unless ($container eq 'page') {
1.434 raeburn 6651: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6652: $orderhash{'ee'} = ['Collaboration',$communityform];
1.434 raeburn 6653: }
6654:
1.341 ehlerst 6655: $hadchanges=0;
1.484 raeburn 6656: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6657: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6658: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6659: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6660: undef($navmap);
1.443 www 6661: if ($error) {
6662: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6663: }
1.639 raeburn 6664: if ($hadchanges) {
6665: unless (&is_hash_old()) {
1.638 raeburn 6666: &mark_hash_old();
6667: }
6668: }
1.341 ehlerst 6669:
1.443 www 6670: &changewarning($r,'');
6671: }
1.458 raeburn 6672: }
1.442 www 6673:
1.443 www 6674: # Supplemental documents start here
6675:
1.329 droeschl 6676: my $folder=$env{'form.folder'};
1.443 www 6677: unless ($supplementalflag) {
1.329 droeschl 6678: $folder='supplemental';
6679: }
6680: if ($folder =~ /^supplemental$/ &&
6681: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6682: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6683: } elsif ($allowed) {
1.356 tempelho 6684: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6685: }
1.508 raeburn 6686: $pathitem = '<input type="hidden" name="folderpath" value="'.
6687: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6688: if ($allowed) {
6689: my $folderseq=
1.504 raeburn 6690: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6691:
6692: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6693: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6694: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6695: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6696: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6697: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6698: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6699: $fileupload
6700: <br />
6701: <br />
6702: <span class="LC_nobreak">
6703: $checkbox
6704: </span>
6705: <br /><br />
6706: $lt{'comment'}:<br />
1.383 tempelho 6707: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6708: <br />
1.508 raeburn 6709: $pathitem
1.329 droeschl 6710: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6711: <input type='submit' value="$lt{'upld'}" />
6712: </form>
1.329 droeschl 6713: SUPDOCFORM
6714:
6715: my $supnewfolderform=(<<SNFFORM);
6716: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6717: <input type="hidden" name="active" value="" />
1.508 raeburn 6718: $pathitem
1.329 droeschl 6719: <input type="hidden" name="importdetail" value="" />
1.423 onken 6720: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6721: $help{'Adding_Folders'}
1.329 droeschl 6722: </form>
6723: SNFFORM
1.383 tempelho 6724:
1.510 raeburn 6725: my $supextform =
6726: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6727: $help{'Adding_External_Resource'},
6728: undef,undef,undef,undef,undef,undef,
6729: $disabled);
1.329 droeschl 6730:
1.598 raeburn 6731: my $supexttoolform =
6732: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6733: $help{'Adding_External_Tool'},
6734: undef,undef,'tool',$coursedom,
1.611 raeburn 6735: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6736:
1.329 droeschl 6737: my $supnewsylform=(<<SNSFORM);
6738: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6739: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6740: $pathitem
1.329 droeschl 6741: <input type="hidden" name="importdetail"
6742: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6743: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6744: $help{'Syllabus'}
6745: </form>
6746: SNSFORM
6747:
6748: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6749: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6750: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6751: $pathitem
1.329 droeschl 6752: <input type="hidden" name="importdetail"
6753: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6754: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6755: $help{'My Personal Information Page'}
1.329 droeschl 6756: </form>
6757: SNAMFORM
6758:
1.534 raeburn 6759: my $supwebpage;
6760: if ($folder =~ /^supplemental_?(\d*)$/) {
6761: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6762: if ($1) {
6763: $supwebpage .= $1;
6764: } else {
6765: $supwebpage .= 'default';
6766: }
6767: $supwebpage .= '/new.html';
6768: }
6769: my $supwebpageform =(<<SWEBFORM);
6770: <form action="/adm/coursedocs" method="post" name="supwebpage">
6771: <input type="hidden" name="active" value="cc" />
6772: $pathitem
6773: <input type="hidden" name="importdetail" value="$supwebpage" />
6774: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6775: $help{'Web_Page'}
1.534 raeburn 6776: </form>
6777: SWEBFORM
6778:
1.333 muellerd 6779:
1.383 tempelho 6780: my @specialdocs = (
1.618 raeburn 6781: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6782: =>$supnewsylform},
1.611 raeburn 6783: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6784: =>$supnewaboutmeform},
1.534 raeburn 6785: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6786:
1.383 tempelho 6787: );
1.655 raeburn 6788: my @supexternal = (
6789: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6790: =>$supextform});
1.598 raeburn 6791: if (keys(%ltitools)) {
1.655 raeburn 6792: push(@supexternal,
6793: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 6794: =>$supexttoolform});
6795: }
1.655 raeburn 6796: my @supimportdoc = (
1.598 raeburn 6797: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6798: =>$supupdocform},
1.598 raeburn 6799: );
1.501 raeburn 6800:
6801: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6802: my %suporderhash = (
1.390 tempelho 6803: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 6804: 'dd' => ['Upload',$supupdocform],
6805: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 6806: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6807: );
1.443 www 6808: if ($supplementalflag) {
1.458 raeburn 6809: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6810: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6811: \%ltitools,$canedit,$hostname);
1.443 www 6812: if ($error) {
6813: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6814: } else {
6815: if ($suppchanges) {
6816: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6817: my @ids=&Apache::lonnet::current_machine_ids();
6818: foreach my $server (keys(%servers)) {
6819: next if (grep(/^\Q$server\E$/,@ids));
6820: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6821: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6822: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6823: }
6824: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6825: undef($suppchanges);
1.630 raeburn 6826: }
6827: }
1.393 raeburn 6828: }
1.443 www 6829: } elsif ($supplementalflag) {
1.458 raeburn 6830: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6831: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6832: if ($error) {
6833: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6834: }
1.393 raeburn 6835: }
1.389 tempelho 6836:
1.510 raeburn 6837: if ($needs_end) {
6838: $r->print(&endContentScreen());
6839: }
1.383 tempelho 6840:
1.329 droeschl 6841: if ($allowed) {
6842: $r->print('
6843: <form method="post" name="extimport" action="/adm/coursedocs">
6844: <input type="hidden" name="title" />
6845: <input type="hidden" name="url" />
6846: <input type="hidden" name="useform" />
6847: <input type="hidden" name="residx" />
6848: </form>');
6849: }
1.484 raeburn 6850: } elsif ($showdoc) {
1.329 droeschl 6851: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6852: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6853: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6854: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6855: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6856: }
6857: }
1.630 raeburn 6858: unless ($noendpage) {
1.606 raeburn 6859: $r->print(&Apache::loncommon::end_page());
6860: }
1.329 droeschl 6861: return OK;
1.364 bisitz 6862: }
1.329 droeschl 6863:
1.440 raeburn 6864: sub embedded_form_elems {
6865: my ($phase,$primaryurl,$newidx) = @_;
6866: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 6867: $newidx =~s /\D+//g;
1.440 raeburn 6868: return <<STATE;
6869: <input type="hidden" name="folderpath" value="$folderpath" />
6870: <input type="hidden" name="cmd" value="upload_embedded" />
6871: <input type="hidden" name="newidx" value="$newidx" />
6872: <input type="hidden" name="phase" value="$phase" />
6873: <input type="hidden" name="primaryurl" value="$primaryurl" />
6874: STATE
6875: }
6876:
6877: sub embedded_destination {
6878: my $folder=$env{'form.folder'};
6879: my $destination = 'docs/';
6880: if ($folder =~ /^supplemental/) {
6881: $destination = 'supplemental/';
6882: }
6883: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6884: $destination .= 'default/';
6885: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6886: $destination .= $2.'/';
6887: }
1.634 raeburn 6888: my $newidx = $env{'form.newidx'};
6889: $newidx =~s /\D+//g;
6890: if ($newidx) {
6891: $destination .= $newidx;
6892: }
1.440 raeburn 6893: my $dir_root = '/userfiles';
6894: return ($destination,$dir_root);
6895: }
6896:
6897: sub return_to_editor {
6898: my $actionurl = '/adm/coursedocs';
6899: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6900: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6901: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6902: '</a></p>';
6903: }
6904:
1.476 raeburn 6905: sub decompression_info {
6906: my ($destination,$dir_root) = &embedded_destination();
6907: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6908: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6909: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6910: my $container='sequence';
1.480 raeburn 6911: my ($pathitem,$hiddenelem);
1.583 raeburn 6912: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6913: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6914: $container='page';
6915: }
1.480 raeburn 6916: unshift(@hiddens,$pathitem);
6917: foreach my $item (@hiddens) {
1.634 raeburn 6918: if ($item eq 'newidx') {
6919: next if ($env{'form.'.$item} =~ /\D/);
6920: }
1.480 raeburn 6921: if ($env{'form.'.$item}) {
6922: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6923: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6924: }
1.477 raeburn 6925: }
1.476 raeburn 6926: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6927: $hiddenelem);
6928: }
6929:
6930: sub decompression_phase_one {
6931: my ($dir,$file,$warning,$error,$output);
6932: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6933: &decompression_info();
1.490 raeburn 6934: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6935: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6936: } else {
6937: my $file = $1;
1.630 raeburn 6938: $output =
1.481 raeburn 6939: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6940: $destination,$dir_root,
6941: $hiddenelem);
6942: if ($env{'form.autoextract_camtasia'}) {
6943: $output .= &remove_archive($docudom,$docuname,$container);
6944: }
1.476 raeburn 6945: }
6946: if ($error) {
6947: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6948: $error.'</p>'."\n";
6949: }
6950: if ($warning) {
6951: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6952: }
6953: return $output;
6954: }
6955:
6956: sub decompression_phase_two {
6957: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6958: &decompression_info();
1.481 raeburn 6959: my $output;
1.480 raeburn 6960: if ($env{'form.archivedelete'}) {
1.481 raeburn 6961: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6962: }
6963: $output .=
1.481 raeburn 6964: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6965: $destination,$dir_root,$hiddenelem);
6966: return $output;
6967: }
6968:
1.480 raeburn 6969: sub remove_archive {
6970: my ($docudom,$docuname,$container) = @_;
6971: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6972: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6973: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6974: if ($fatal) {
6975: if ($container eq 'page') {
6976: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6977: } else {
6978: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6979: }
1.583 raeburn 6980: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6981: } else {
6982: my $currcmd = $env{'form.cmd'};
6983: my $position = $env{'form.position'};
1.583 raeburn 6984: my $archiveidx = $position;
1.563 raeburn 6985: if ($position > 0) {
1.583 raeburn 6986: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6987: $archiveidx = $position-1;
6988: }
6989: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6990: my ($title,$url,@rrest) =
1.583 raeburn 6991: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6992: if ($url eq $env{'form.archiveurl'}) {
6993: if (&handle_edit_cmd($docuname,$docudom)) {
6994: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6995: if ($fatal) {
6996: if ($container eq 'page') {
6997: $delwarning = &mt('An error occurred updating the contents of the current page.');
6998: } else {
6999: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7000: }
1.480 raeburn 7001: } else {
1.583 raeburn 7002: $delresult = &mt('Archive file removed.');
1.480 raeburn 7003: }
7004: }
1.583 raeburn 7005: } else {
7006: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7007: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 7008: }
7009: }
7010: $env{'form.cmd'} = $currcmd;
7011: }
7012: if ($delwarning) {
7013: $output = '<p class="LC_warning">'.
7014: $delwarning.
7015: '</p>';
7016: }
7017: if ($delresult) {
7018: $output .= '<p class="LC_info">'.
7019: $delresult.
7020: '</p>';
7021: }
1.481 raeburn 7022: return $output;
1.480 raeburn 7023: }
7024:
1.484 raeburn 7025: sub generate_admin_menu {
1.611 raeburn 7026: my ($crstype,$canedit) = @_;
1.484 raeburn 7027: my $lc_crstype = lc($crstype);
7028: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7029: my %lt= ( # do not translate here
1.484 raeburn 7030: 'vc' => 'Verify Content',
7031: 'cv' => 'Check/Set Resource Versions',
7032: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7033: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7034: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7035: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7036: );
1.484 raeburn 7037: my ($candump,$dumpurl);
7038: if ($home + $other > 0) {
7039: $candump = 'F';
7040: if ($home) {
7041: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7042: } else {
7043: my @hosts;
7044: foreach my $aurole (keys(%outhash)) {
7045: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7046: push(@hosts,$outhash{$aurole});
1.538 raeburn 7047: }
1.484 raeburn 7048: }
7049: if (@hosts == 1) {
7050: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7051: '&role='.
7052: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7053: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7054: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7055: } else {
7056: $dumpurl = "javascript:choose_switchserver_window()";
7057: }
7058: }
7059: }
7060: my @menu=
7061: ({ categorytitle=>'Administration',
7062: items =>[
7063: { linktext => $lt{'vc'},
7064: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7065: permission => 'F',
1.571 raeburn 7066: help => 'Docs_Verify_Content',
1.484 raeburn 7067: icon => 'verify.png',
7068: linktitle => 'Verify contents can be retrieved/rendered',
7069: },
7070: { linktext => $lt{'cv'},
7071: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7072: permission => 'F',
1.571 raeburn 7073: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7074: icon => 'resversion.png',
7075: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7076: },
7077: { linktext => $lt{'ls'},
7078: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7079: permission => 'F',
7080: #help => '',
7081: icon => 'symbs.png',
7082: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7083: },
1.651 raeburn 7084: { linktext => $lt{'ct'},
7085: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7086: permission => 'F',
7087: help => 'Docs_Short_URLs',
7088: icon => 'shorturls.png',
7089: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7090: },
1.484 raeburn 7091: ]
1.611 raeburn 7092: });
7093: if ($canedit) {
7094: push(@menu,
1.484 raeburn 7095: { categorytitle=>'Export',
7096: items =>[
7097: { linktext => $lt{'imse'},
7098: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7099: permission => 'F',
7100: help => 'Docs_Export_Course_Docs',
7101: icon => 'imsexport.png',
7102: linktitle => $lt{'imse'},
7103: },
7104: { linktext => $lt{'dcd'},
7105: url => $dumpurl,
7106: permission => $candump,
1.571 raeburn 7107: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7108: icon => 'dump.png',
7109: linktitle => $lt{'dcd'},
7110: },
7111: ]
7112: });
1.611 raeburn 7113: }
1.484 raeburn 7114: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7115: '<input type="hidden" id="dummy" />'."\n".
7116: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7117: '</form>';
1.329 droeschl 7118: }
7119:
7120: sub generate_edit_table {
1.538 raeburn 7121: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7122: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7123: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7124: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7125: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7126: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7127: $activetab = $env{'form.active'};
7128: }
1.611 raeburn 7129: unless ($canedit) {
7130: $disabled = ' disabled="disabled"';
7131: }
1.472 raeburn 7132: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7133: my $backtext = &mt('Exit Editor');
1.458 raeburn 7134: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7135: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7136: '<li class="goback">'.
1.546 raeburn 7137: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7138: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7139: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7140: '<li>'.
7141: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7142: &mt('Undo Delete').'</a></li>'."\n";
7143: if ($env{'form.docslog'}) {
7144: $form .= '<li class="active">';
7145: } else {
7146: $form .= '<li>';
7147: }
7148: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7149: &mt('History').'</a></li>'."\n";
7150: if ($env{'form.docslog'}) {
7151: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7152: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7153: }
1.458 raeburn 7154: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7155: if($name ne '00'){
1.371 tempelho 7156: if($activetab eq '' || $activetab ne $name){
7157: $active = '';
7158: }elsif($activetab eq $name){
7159: $active = 'class="active"';
7160: }
1.458 raeburn 7161: $form .= '<li style="float:right" '.$active
1.484 raeburn 7162: .' 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 7163: } else {
1.570 raeburn 7164: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7165:
7166: }
1.329 droeschl 7167: }
1.484 raeburn 7168: $form .= '</ul>'."\n";
7169: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7170:
7171: if ($to_show ne '') {
1.538 raeburn 7172: my $saveform;
7173: if ($need_save) {
7174: my $button = &mt('Make changes');
7175: my $path;
7176: if ($env{'form.folderpath'}) {
7177: $path =
7178: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7179: }
7180: $saveform = <<"END";
7181: <div id="multisave" style="display:none; clear:both;" >
7182: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7183: <input type="hidden" name="folderpath" value="$path" />
7184: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7185: <input type="hidden" name="allhiddenresource" value="" />
7186: <input type="hidden" name="allencrypturl" value="" />
7187: <input type="hidden" name="allrandompick" value="" />
7188: <input type="hidden" name="allrandomorder" value="" />
7189: <input type="hidden" name="changeparms" value="" />
7190: <input type="hidden" name="multiremove" value="" />
7191: <input type="hidden" name="multicut" value="" />
7192: <input type="hidden" name="multicopy" value="" />
7193: <input type="hidden" name="multichange" value="" />
7194: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7195: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7196: </form>
7197: </div>
7198: END
7199: }
7200: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7201: }
1.363 ehlerst 7202: foreach my $field (keys(%orderhash)){
1.390 tempelho 7203: if($field ne '00'){
1.422 onken 7204: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7205: $active = 'style="display: none;float:left"';
1.422 onken 7206: }elsif($activetab eq $field){
1.458 raeburn 7207: $active = 'style="display:block;float:left"';
1.422 onken 7208: }
7209: $form .= '<div id="'.$field.$tid.'"'
7210: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7211: .'</div>'."\n";
1.363 ehlerst 7212: }
7213: }
1.484 raeburn 7214: unless ($env{'form.docslog'}) {
7215: $form .= '</div></div>'."\n";
7216: }
1.329 droeschl 7217: return $form;
7218: }
7219:
7220: sub editing_js {
1.622 raeburn 7221: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7222: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7223: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7224: p_mnf => 'Name of New Folder',
7225: t_mnf => 'New Folder',
7226: p_mnp => 'Name of New Page',
7227: t_mnp => 'New Page',
1.451 www 7228: p_mxu => 'Title for the External Score',
1.349 biermanm 7229: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7230: p_msb => 'Title for the Problem',
7231: p_mdb => 'Title for the Drop Box',
1.336 schafran 7232: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7233: p_mwp => 'Title for Web Page',
1.606 raeburn 7234: p_mnr => 'Title for the Resource',
1.348 weissno 7235: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7236: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7237: p_mab_alrt1 => 'Not a valid user:domain',
7238: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7239: p_chn => 'New Title',
7240: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7241: p_rmr2a => 'Remove',
7242: p_rmr2b => '?',
7243: p_rmr3a => 'Remove those',
7244: p_rmr3b => 'items?',
7245: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7246: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7247: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7248: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7249: p_ctr2a => 'Cut',
7250: p_ctr2b => '?',
7251: p_ctr3a => 'Cut those',
7252: p_ctr3b => 'items?',
1.633 raeburn 7253: setal => 'Enter a (unique) alias',
7254: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7255: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7256: imsfile => 'You must choose an IMS package for import',
7257: imscms => 'You must select which Course Management System was the source of the IMS package',
7258: invurl => 'Invalid URL',
7259: titbl => 'Title is blank',
1.538 raeburn 7260: more => '(More ...)',
7261: less => '(Less ...)',
1.543 raeburn 7262: noor => 'No actions selected or changes to settings specified.',
7263: noch => 'No changes to settings specified.',
7264: noac => 'No actions selected.',
1.606 raeburn 7265: nofi => 'No file selected',
7266: tinc => 'Title in course',
7267: sunm => 'Sub-directory name',
1.618 raeburn 7268: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7269: );
1.594 damieng 7270: &js_escape(\%js_lt);
1.433 raeburn 7271: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7272: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7273: my $main_container_page;
1.519 raeburn 7274: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7275: $main_container_page = 1;
1.434 raeburn 7276: }
1.617 raeburn 7277: my $backtourl;
7278: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7279: my $toplevelsupp = &supplemental_base();
1.433 raeburn 7280:
1.530 raeburn 7281: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7282: my $caller = $1;
1.525 raeburn 7283: if ($caller =~ /^supplemental/) {
7284: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7285: } else {
7286: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7287: $res = &Apache::lonnet::clutter($res);
7288: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7289: my ($url,$anchor);
7290: if ($res =~ /^([^#]+)#([^#]+)$/) {
7291: $url = $1;
7292: $anchor = $2;
7293: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7294: $caller = $1.&escape('#').$anchor;
7295: }
1.614 raeburn 7296: } else {
7297: $url = $res;
1.609 raeburn 7298: }
1.640 raeburn 7299: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7300: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7301: $backtourl .= '?navmap=1';
7302: } else {
7303: $backtourl .= '?symb='.
7304: &HTML::Entities::encode($caller,'<>&"');
7305: }
1.622 raeburn 7306: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7307: if (($ENV{'SERVER_PORT'} == 443) &&
7308: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.657 raeburn 7309: unless (&Apache::lonnet::uses_sts()) {
7310: if ($hostname ne '') {
7311: $backtourl = 'http://'.$hostname.$backtourl;
7312: }
7313: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7314: }
7315: }
1.623 raeburn 7316: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7317: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.657 raeburn 7318: unless (&Apache::lonnet::uses_sts()) {
1.658 raeburn 7319: if ($hostname ne '') {
7320: $backtourl = 'http://'.$hostname.$backtourl;
7321: }
7322: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7323: }
1.623 raeburn 7324: }
1.622 raeburn 7325: }
1.609 raeburn 7326: if ($anchor ne '') {
7327: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7328: }
1.590 raeburn 7329: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7330: } else {
7331: $backtourl = '/adm/navmaps';
1.525 raeburn 7332: }
7333: }
7334: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7335: $backtourl = '/adm/menu';
7336: } elsif ($supplementalflag) {
1.472 raeburn 7337: $backtourl = '/adm/supplemental';
1.525 raeburn 7338: } else {
7339: $backtourl = '/adm/navmaps';
1.472 raeburn 7340: }
7341:
1.655 raeburn 7342: my $fieldsets = "'doc'";
1.519 raeburn 7343: unless ($main_container_page) {
7344: $fieldsets .=",'ims'";
7345: }
1.655 raeburn 7346: my $extfieldsets = "'ext'";
7347: if ($posslti) {
7348: $extfieldsets .= ",'tool'";
7349: }
1.501 raeburn 7350: if ($supplementalflag) {
1.655 raeburn 7351: $fieldsets = "'suppdoc'";
7352: $extfieldsets = "'suppext'";
1.600 raeburn 7353: if ($posslti) {
1.655 raeburn 7354: $extfieldsets .= ",'supptool'";
1.600 raeburn 7355: }
1.501 raeburn 7356: }
1.655 raeburn 7357:
1.611 raeburn 7358: my $jsmakefunctions;
7359: if ($canedit) {
7360: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7361: function makenewfolder(targetform,folderseq) {
1.594 damieng 7362: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7363: if (foldername) {
7364: targetform.importdetail.value=escape(foldername)+"="+folderseq;
7365: targetform.submit();
7366: }
7367: }
7368:
7369: function makenewpage(targetform,folderseq) {
1.594 damieng 7370: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7371: if (pagename) {
7372: targetform.importdetail.value=escape(pagename)+"="+folderseq;
7373: targetform.submit();
7374: }
7375: }
7376:
7377: function makeexamupload() {
1.594 damieng 7378: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7379: if (title) {
1.329 droeschl 7380: this.document.forms.newexamupload.importdetail.value=
7381: escape(title)+'=/res/lib/templates/examupload.problem';
7382: this.document.forms.newexamupload.submit();
7383: }
7384: }
7385:
7386: function makesmppage() {
1.594 damieng 7387: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7388: if (title) {
1.329 droeschl 7389: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 7390: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7391: this.document.forms.newsmppg.submit();
7392: }
7393: }
7394:
1.534 raeburn 7395: function makewebpage(type) {
1.594 damieng 7396: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7397: var formname;
7398: if (type == 'supp') {
7399: formname = this.document.forms.supwebpage;
7400: } else {
7401: formname = this.document.forms.newwebpage;
7402: }
7403: if (title) {
7404: var webpage = formname.importdetail.value;
1.675 ! raeburn 7405: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.534 raeburn 7406: formname.submit();
7407: }
7408: }
7409:
1.329 droeschl 7410: function makesmpproblem() {
1.594 damieng 7411: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7412: if (title) {
1.329 droeschl 7413: this.document.forms.newsmpproblem.importdetail.value=
7414: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7415: this.document.forms.newsmpproblem.submit();
7416: }
7417: }
7418:
7419: function makedropbox() {
1.594 damieng 7420: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7421: if (title) {
1.329 droeschl 7422: this.document.forms.newdropbox.importdetail.value=
7423: escape(title)+'=/res/lib/templates/DropBox.problem';
7424: this.document.forms.newdropbox.submit();
7425: }
7426: }
7427:
7428: function makebulboard() {
1.594 damieng 7429: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7430: if (title) {
7431: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7432: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7433: this.document.forms.newbul.submit();
7434: }
7435: }
7436:
7437: function makeabout() {
1.594 damieng 7438: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7439: if (user) {
7440: var comp=new Array();
7441: comp=user.split(':');
7442: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7443: if ((comp[0]) && (comp[1])) {
7444: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7445: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7446: this.document.forms.newaboutsomeone.submit();
7447: } else {
7448: alert("$js_lt{'p_mab_alrt1'}");
7449: }
7450: } else {
7451: alert("$js_lt{'p_mab_alrt2'}");
7452: }
7453: }
7454: }
7455:
7456: function makenew(targetform) {
7457: targetform.submit();
7458: }
7459:
7460: function changename(folderpath,index,oldtitle) {
7461: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7462: if (title) {
7463: this.document.forms.renameform.markcopy.value='';
7464: this.document.forms.renameform.title.value=title;
7465: this.document.forms.renameform.cmd.value='rename_'+index;
7466: this.document.forms.renameform.folderpath.value=folderpath;
7467: this.document.forms.renameform.submit();
7468: }
7469: }
7470:
1.633 raeburn 7471: function setalias(folderpath,index) {
7472: var alias = prompt('$js_lt{"setal"}');
7473: if ((alias != null) && (alias != '')) {
7474: this.document.forms.aliasform.alias.value=alias;
7475: this.document.forms.aliasform.cmd.value='setalias_'+index;
7476: this.document.forms.aliasform.folderpath.value=folderpath;
7477: this.document.forms.aliasform.submit();
7478: }
7479: }
7480:
7481: function delalias(folderpath,index) {
7482: if (confirm('$js_lt{"delal"}')) {
7483: this.document.forms.aliasform.cmd.value='delalias_'+index;
7484: this.document.forms.aliasform.folderpath.value=folderpath;
7485: this.document.forms.aliasform.submit();
7486: }
7487: }
7488:
1.611 raeburn 7489: ENDNEWSCRIPT
7490: } else {
7491: $jsmakefunctions = <<ENDNEWSCRIPT;
7492:
7493: function makenewfolder() {
7494: alert("$js_lt{'edri'}");
7495: }
7496:
7497: function makenewpage() {
7498: alert("$js_lt{'edri'}");
7499: }
7500:
7501: function makeexamupload() {
7502: alert("$js_lt{'edri'}");
7503: }
7504:
7505: function makesmppage() {
7506: alert("$js_lt{'edri'}");
7507: }
7508:
7509: function makewebpage(type) {
7510: alert("$js_lt{'edri'}");
7511: }
7512:
7513: function makesmpproblem() {
7514: alert("$js_lt{'edri'}");
7515: }
7516:
7517: function makedropbox() {
7518: alert("$js_lt{'edri'}");
7519: }
7520:
7521: function makebulboard() {
7522: alert("$js_lt{'edri'}");
7523: }
7524:
7525: function makeabout() {
7526: alert("$js_lt{'edri'}");
7527: }
7528:
7529: function changename() {
7530: alert("$js_lt{'edri'}");
7531: }
7532:
1.633 raeburn 7533: function setalias() {
7534: alert("$js_lt{'edri'}");
7535: }
7536:
7537: function delalias() {
7538: alert("$js_lt{'edri'}");
7539: }
7540:
1.611 raeburn 7541: function makenew() {
7542: alert("$js_lt{'edri'}");
7543: }
7544:
7545: function groupimport() {
7546: alert("$js_lt{'edri'}");
1.335 ehlerst 7547: }
1.611 raeburn 7548:
7549: function groupsearch() {
7550: alert("$js_lt{'edri'}");
1.335 ehlerst 7551: }
1.611 raeburn 7552:
7553: function groupopen(url,recover) {
7554: var options="scrollbars=1,resizable=1,menubar=0";
7555: idxflag=1;
7556: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7557: idx.focus();
1.329 droeschl 7558: }
7559:
1.611 raeburn 7560: ENDNEWSCRIPT
7561:
7562: }
7563: return <<ENDSCRIPT;
7564:
7565: $jsmakefunctions
7566:
1.501 raeburn 7567: function toggleUpload(caller) {
7568: var blocks = Array($fieldsets);
7569: for (var i=0; i<blocks.length; i++) {
7570: var disp = 'none';
7571: if (caller == blocks[i]) {
7572: var curr = document.getElementById('upload'+caller+'form').style.display;
7573: if (curr == 'none') {
7574: disp='block';
7575: }
7576: }
7577: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7578: }
7579: resize_scrollbox('contentscroll','1','1');
7580: return;
7581: }
7582:
7583: function toggleExternal(caller) {
7584: var blocks = Array($extfieldsets);
7585: for (var i=0; i<blocks.length; i++) {
7586: var disp = 'none';
7587: if (caller == blocks[i]) {
7588: var curr = document.getElementById('external'+caller+'form').style.display;
7589: if (curr == 'none') {
7590: disp='block';
7591: }
7592: }
7593: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7594: if ((caller == 'tool') || (caller == 'supptool')) {
7595: if (disp == 'block') {
1.655 raeburn 7596: if (document.getElementById('LC_exttoolid')) {
7597: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7598: var suppflag = 0;
7599: if (caller == 'supptool') {
7600: suppflag = 1;
7601: }
7602: currForm = document.getElementById('new'+caller);
1.655 raeburn 7603: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7604: }
7605: }
7606: }
1.501 raeburn 7607: }
1.502 raeburn 7608: resize_scrollbox('contentscroll','1','1');
7609: return;
7610: }
7611:
1.514 raeburn 7612: function toggleMap(caller) {
1.502 raeburn 7613: var disp = 'none';
1.510 raeburn 7614: if (document.getElementById('importmapform')) {
1.514 raeburn 7615: if (caller == 'map') {
7616: var curr = document.getElementById('importmapform').style.display;
7617: if (curr == 'none') {
7618: disp='block';
7619: }
1.510 raeburn 7620: }
7621: document.getElementById('importmapform').style.display=disp;
7622: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7623: }
1.501 raeburn 7624: return;
1.329 droeschl 7625: }
7626:
1.606 raeburn 7627: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7628: var disp = 'none';
7629: if (document.getElementById('crsresform')) {
7630: if (caller == 'res') {
7631: var curr = document.getElementById('crsresform').style.display;
7632: if (curr == 'none') {
7633: disp='block';
7634: numauthor = parseInt(numauthorrole);
7635: if (numauthor > 0) {
7636: document.courseresform.authorrole.selectedIndex = 0;
7637: select1priv_changed();
7638: document.courseresform.authorpath.selectedIndex = 0;
7639: document.courseresform.newresourceadd.selectedIndex = 0;
7640: toggleNewInCourse(document.courseresform);
7641: if (document.getElementById('newresource')) {
7642: document.getElementById('newresource').style.display = 'none';
7643: }
7644: } else {
7645: if (numcrsdirs) {
7646: document.courseresform.authorpath.selectedIndex = 0;
7647: }
7648: }
7649: if (document.courseresform.newresusetemp.length) {
7650: document.courseresform.newresusetemp[0].checked = true;
7651: toggleWithTemplate(document.courseresform);
7652: }
7653: document.courseresform.newresourcename.value = '';
7654: }
7655: }
7656: if (document.courseresform.newsubdir.length) {
7657: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7658: if (document.courseresform.newsubdir[j].value == 0) {
7659: document.courseresform.newsubdir[j].checked = true;
7660: }
7661: break;
7662: }
7663: if (document.getElementById('newsubdirname')) {
7664: document.getElementById('newsubdirname').type = "hidden";
7665: document.getElementById('newsubdirname').value = "";
7666: }
7667: if (document.getElementById('newsubdir')) {
7668: document.getElementById('newsubdir').innerHTML = "";
7669: }
7670: }
7671: document.getElementById('crsresform').style.display=disp;
7672: resize_scrollbox('contentscroll','1','0');
7673: }
7674: return;
7675: }
7676:
7677: function toggleNewsubdir(form) {
7678: if (form.newsubdir.length) {
7679: for (var j=0; j<form.newsubdir.length; j++) {
7680: if (form.newsubdir[j].checked) {
7681: if (document.getElementById('newsubdirname')) {
7682: if (form.newsubdir[j].value == '1') {
7683: document.getElementById('newsubdirname').type = "text";
7684: if (document.getElementById('newsubdir')) {
7685: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7686: }
7687: } else {
7688: document.getElementById('newsubdirname').type = "hidden";
7689: document.getElementById('newsubdirname').value = "";
7690: document.getElementById('newsubdir').innerHTML = "";
7691: }
7692: }
7693: break;
7694: }
7695: }
7696: }
7697: }
7698:
7699: function toggleCrsResTitle() {
7700: if (document.getElementById('newresource')) {
7701: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7702: document.getElementById('newresource').style.display = 'inline';
7703: document.courseresform.newresourceadd[0].checked = true;
7704: toggleNewInCourse(document.courseresform);
7705: } else {
7706: document.getElementById('newresource').style.display = 'none';
7707: }
7708: }
7709: }
7710:
7711: function toggleNewInCourse(form) {
7712: if (form.newresourceadd.length) {
7713: for (var i=0; i<form.newresourceadd.length; i++) {
7714: if (form.newresourceadd[i].checked) {
7715: if (document.getElementById('newresourcetitle')) {
7716: if (form.newresourceadd[i].value == '1') {
7717: document.getElementById('newresourcetitle').type = 'text';
7718: if (document.getElementById('newrestitle')) {
7719: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7720: }
7721: } else {
7722: document.getElementById('newresourcetitle').type = 'hidden';
7723: document.getElementById('newresourcetitle').value = '';
7724: if (document.getElementById('newrestitle')) {
7725: document.getElementById('newrestitle').innerHTML = '';
7726: }
7727: }
7728: }
7729: break;
7730: }
7731: }
7732: }
7733: }
7734:
7735: function toggleWithTemplate(form) {
7736: if (form.newresusetemp.length) {
7737: for (var i=0; i<form.newresusetemp.length; i++) {
7738: if (form.newresusetemp[i].checked) {
7739: if (document.getElementById('newrestemplate')) {
7740: if (form.newresusetemp[i].value == '1') {
7741: document.getElementById('newrestemplate').style.display = 'inline';
7742: toggleExampleText();
7743: } else {
7744: form.tempcategory.selectedIndex = 0;
7745: select1template_changed();
7746: document.getElementById('newrestemplate').style.display = 'none';
7747: }
7748: }
7749: }
7750: }
7751: }
7752: }
7753:
7754: function toggleExampleText() {
7755: if (document.getElementById('newresexample')) {
7756: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7757: if (url == '') {
7758: document.getElementById('newresexample').style.fontWeight = 'normal';
7759: } else {
7760: document.getElementById('newresexample').style.fontWeight = 'bold';
7761: }
7762: }
7763: }
7764:
7765: function getExample(width,height,scrolling,transparency) {
7766: var url;
7767: if (document.courseresform.newresusetemp.length) {
7768: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7769: if (document.courseresform.newresusetemp[i].checked) {
7770: if (document.courseresform.newresusetemp[i].value == '1') {
7771: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7772: if (url == '') {
7773: alert('Pick a category and template');
7774: } else {
7775: url = url.replace("$londocroot","");
7776: url += '?inhibitmenu=yes';
7777: }
7778: }
7779: break;
7780: }
7781: }
7782: }
7783: if (url != '') {
7784: openMyModal(url,width,height,scrolling,transparency,'');
7785: }
7786: }
7787:
7788: function toggleImportCrsres(caller,dircount) {
7789: var disp = 'none';
7790: if (document.getElementById('importcrsresform')) {
7791: if (caller == 'res') {
7792: var numdirs = parseInt(dircount);
7793: var curr = document.getElementById('importcrsresform').style.display;
7794: if (curr == 'none') {
7795: disp='block';
7796: if (numdirs > 1) {
7797: select1res_changed();
7798: }
7799: }
7800: }
7801: document.getElementById('importcrsresform').style.display=disp;
7802: resize_scrollbox('contentscroll','1','0');
7803: }
7804: return;
7805: }
7806:
1.501 raeburn 7807: function makeims(imsform) {
7808: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7809: alert("$js_lt{'imsfile'}");
1.501 raeburn 7810: return;
7811: }
7812: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7813: alert("$js_lt{'imscms'}");
1.501 raeburn 7814: return;
7815: }
7816: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7817: imsform.submit();
7818: }
7819:
1.478 raeburn 7820: function updatePick(targetform,index,caller) {
1.537 raeburn 7821: var pickitem;
7822: var picknumitem;
7823: var picknumtext;
7824: if (index == 'all') {
7825: pickitem = document.getElementById('randompickall');
7826: picknumitem = document.getElementById('rpicknumall');
7827: picknumtext = document.getElementById('rpicktextall');
7828: } else {
7829: pickitem = document.getElementById('randompick_'+index);
7830: picknumitem = document.getElementById('rpicknum_'+index);
7831: picknumtext = document.getElementById('randompicknum_'+index);
7832: }
1.478 raeburn 7833: if (pickitem.checked) {
1.594 damieng 7834: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7835: if (picknum == '' || picknum == null) {
7836: if (caller == 'check') {
7837: pickitem.checked=false;
1.537 raeburn 7838: if (index == 'all') {
7839: picknumtext.innerHTML = '';
7840: if (caller == 'link') {
7841: propagateState(targetform,'rpicknum');
7842: }
7843: } else {
1.538 raeburn 7844: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7845: }
1.478 raeburn 7846: }
7847: } else {
7848: picknum.toString();
7849: var regexdigit=/^\\d+\$/;
7850: if (regexdigit.test(picknum)) {
7851: picknumitem.value = picknum;
1.537 raeburn 7852: if (index == 'all') {
1.538 raeburn 7853: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7854: if (caller == 'link') {
7855: propagateState(targetform,'rpicknum');
7856: }
7857: } else {
7858: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7859: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7860: }
1.478 raeburn 7861: } else {
7862: if (caller == 'check') {
1.537 raeburn 7863: if (index == 'all') {
7864: picknumtext.innerHTML = '';
7865: if (caller == 'link') {
7866: propagateState(targetform,'rpicknum');
7867: }
7868: } else {
7869: pickitem.checked=false;
1.538 raeburn 7870: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7871: }
1.478 raeburn 7872: }
7873: return;
7874: }
7875: }
7876: } else {
1.537 raeburn 7877: picknumitem.value = '';
7878: picknumtext.innerHTML = '';
7879: if (index == 'all') {
7880: if (caller == 'link') {
7881: propagateState(targetform,'rpicknum');
7882: }
7883: } else {
1.538 raeburn 7884: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7885: }
7886: }
7887: }
7888:
7889: function propagateState(form,param) {
7890: if (document.getElementById(param+'all')) {
7891: var setcheck = 0;
7892: var rpick = 0;
7893: if (param == 'rpicknum') {
7894: if (document.getElementById('randompickall')) {
7895: if (document.getElementById('randompickall').checked) {
7896: if (document.getElementById('rpicknumall')) {
7897: rpick = document.getElementById('rpicknumall').value;
7898: }
7899: }
7900: }
7901: } else {
7902: if (document.getElementById(param+'all').checked) {
7903: setcheck = 1;
7904: }
7905: }
1.538 raeburn 7906: var allidxlist;
7907: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7908: if (document.getElementById('all'+param+'idx')) {
7909: allidxlist = document.getElementById('all'+param+'idx').value;
7910: }
7911: var actions = new Array ('remove','cut','copy');
7912: for (var i=0; i<actions.length; i++) {
7913: if (actions[i] != param) {
7914: if (document.getElementById(actions[i]+'all')) {
7915: document.getElementById(actions[i]+'all').checked = false;
7916: }
7917: }
7918: }
7919: }
1.537 raeburn 7920: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7921: allidxlist = form.allidx.value;
7922: }
7923: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7924: allidxlist = form.allmapidx.value;
7925: }
7926: if ((allidxlist != '') && (allidxlist != null)) {
7927: var allidxs = allidxlist.split(',');
7928: if (allidxs.length > 1) {
7929: for (var i=0; i<allidxs.length; i++) {
7930: if (document.getElementById(param+'_'+allidxs[i])) {
7931: if (param == 'rpicknum') {
7932: if (document.getElementById('randompick_'+allidxs[i])) {
7933: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7934: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7935: if (rpick > 0) {
7936: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7937: } else {
7938: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7939: }
7940: }
7941: }
7942: } else {
1.537 raeburn 7943: if (setcheck == 1) {
7944: document.getElementById(param+'_'+allidxs[i]).checked = true;
7945: } else {
7946: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7947: if (param == 'randompick') {
7948: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7949: }
1.537 raeburn 7950: }
7951: }
7952: }
7953: }
1.538 raeburn 7954: if (setcheck == 1) {
7955: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7956: var actions = new Array('copy','cut','remove');
7957: for (var i=0; i<actions.length; i++) {
7958: var otheractions;
7959: var otheridxs;
7960: if (actions[i] === param) {
7961: continue;
7962: } else {
7963: if (document.getElementById('all'+actions[i]+'idx')) {
7964: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7965: otheridxs = otheractions.split(',');
7966: if (otheridxs.length > 1) {
7967: for (var j=0; j<otheridxs.length; j++) {
7968: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7969: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7970: }
1.537 raeburn 7971: }
7972: }
7973: }
1.538 raeburn 7974: }
7975: }
7976: }
7977: }
7978: }
7979: }
7980: }
7981: return;
7982: }
7983:
1.603 raeburn 7984: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7985: var canedit = '$canedit';
7986: if (canedit == '') {
7987: alert("$js_lt{'edri'}");
7988: return;
7989: }
1.539 raeburn 7990: var dosettings;
7991: var doaction;
1.538 raeburn 7992: var control = document.togglemultsettings;
7993: if (context == 'actions') {
7994: control = document.togglemultactions;
1.539 raeburn 7995: doaction = 1;
7996: } else {
7997: dosettings = 1;
1.538 raeburn 7998: }
1.539 raeburn 7999: if (control) {
8000: if (control.showmultpick.length) {
8001: for (var i=0; i<control.showmultpick.length; i++) {
8002: if (control.showmultpick[i].checked) {
8003: if (control.showmultpick[i].value == 1) {
8004: if (context == 'settings') {
8005: dosettings = 0;
8006: } else {
8007: doaction = 0;
1.538 raeburn 8008: }
8009: }
8010: }
1.537 raeburn 8011: }
8012: }
1.539 raeburn 8013: }
8014: if (context == 'settings') {
8015: if (dosettings == 1) {
1.538 raeburn 8016: targetform.changeparms.value=param;
8017: targetform.submit();
8018: }
1.537 raeburn 8019: }
1.539 raeburn 8020: if (context == 'actions') {
8021: if (doaction == 1) {
8022: targetform.cmd.value=param+'_'+index;
8023: targetform.folderpath.value=folderpath;
8024: targetform.markcopy.value=idx+':'+param;
8025: targetform.copyfolder.value=folder+'.'+container;
8026: if (param == 'remove') {
1.603 raeburn 8027: var doremove = 0;
8028: if (skip_confirm) {
8029: if (confirm_removal) {
8030: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8031: doremove = 1;
8032: }
8033: } else {
8034: doremove = 1;
8035: }
8036: } else {
8037: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8038: doremove = 1;
8039: }
8040: }
8041: if (doremove) {
1.539 raeburn 8042: targetform.markcopy.value='';
8043: targetform.copyfolder.value='';
8044: targetform.submit();
8045: }
8046: }
8047: if (param == 'cut') {
1.594 damieng 8048: 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 8049: targetform.submit();
8050: return;
8051: }
8052: }
8053: if (param == 'copy') {
8054: targetform.submit();
8055: return;
8056: }
8057: targetform.markcopy.value='';
8058: targetform.copyfolder.value='';
8059: targetform.cmd.value='';
8060: targetform.folderpath.value='';
8061: return;
8062: } else {
8063: if (document.getElementById(param+'_'+idx)) {
8064: item = document.getElementById(param+'_'+idx);
8065: if (item.type == 'checkbox') {
8066: if (item.checked) {
8067: item.checked = false;
8068: } else {
8069: item.checked = true;
8070: singleCheck(item,idx,param);
8071: }
8072: }
8073: }
8074: }
8075: }
1.537 raeburn 8076: return;
8077: }
8078:
1.538 raeburn 8079: function singleCheck(caller,idx,action) {
8080: actions = new Array('cut','copy','remove');
8081: if (caller.checked) {
8082: for (var i=0; i<actions.length; i++) {
8083: if (actions[i] != action) {
8084: if (document.getElementById(actions[i]+'_'+idx)) {
8085: if (document.getElementById(actions[i]+'_'+idx).checked) {
8086: document.getElementById(actions[i]+'_'+idx).checked = false;
8087: }
1.537 raeburn 8088: }
8089: }
8090: }
1.478 raeburn 8091: }
1.537 raeburn 8092: return;
1.478 raeburn 8093: }
8094:
1.334 muellerd 8095: function unselectInactive(nav) {
1.335 ehlerst 8096: currentNav = document.getElementById(nav);
8097: currentLis = currentNav.getElementsByTagName('LI');
8098: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8099: if (currentLis[i].className == 'goback') {
8100: currentLis[i].className = 'goback';
8101: } else {
8102: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8103: currentLis[i].className = 'right';
1.472 raeburn 8104: } else {
1.374 tempelho 8105: currentLis[i].className = 'i';
1.472 raeburn 8106: }
8107: }
1.335 ehlerst 8108: }
1.332 tempelho 8109: }
8110:
1.334 muellerd 8111: function hideAll(current, nav, data) {
1.335 ehlerst 8112: unselectInactive(nav);
1.570 raeburn 8113: if (current) {
8114: if (current.className == 'right'){
8115: current.className = 'right active'
8116: } else {
8117: current.className = 'active';
8118: }
1.374 tempelho 8119: }
1.335 ehlerst 8120: currentData = document.getElementById(data);
8121: currentDivs = currentData.getElementsByTagName('DIV');
8122: for (i = 0; i < currentDivs.length; i++) {
8123: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8124: currentDivs[i].style.display = 'none';
1.330 tempelho 8125: }
8126: }
1.335 ehlerst 8127: }
1.330 tempelho 8128:
1.374 tempelho 8129: function openTabs(pageId) {
8130: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8131: if(tabnav.length > 2 ){
1.389 tempelho 8132: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8133: currentLis = currentNav.getElementsByTagName('LI');
8134: for(i = 0; i< currentLis.length; i++){
8135: if(currentLis[i].className == 'active') {
1.375 tempelho 8136: funcString = currentLis[i].onclick.toString();
8137: tab = funcString.split('"');
1.420 onken 8138: if(tab.length < 2) {
8139: tab = funcString.split("'");
8140: }
1.375 tempelho 8141: currentData = document.getElementById(tab[1]);
8142: currentData.style.display = 'block';
1.374 tempelho 8143: }
8144: }
8145: }
8146: }
8147:
1.334 muellerd 8148: function showPage(current, pageId, nav, data) {
1.570 raeburn 8149: currstate = current.className;
1.334 muellerd 8150: hideAll(current, nav, data);
1.375 tempelho 8151: openTabs(pageId);
1.334 muellerd 8152: unselectInactive(nav);
1.570 raeburn 8153: if ((currstate == 'active') || (currstate == 'right active')) {
8154: if (currstate == 'active') {
8155: current.className = '';
8156: } else {
8157: current.className = 'right';
8158: }
8159: activeTab = '';
1.656 raeburn 8160: toggleExternal();
1.570 raeburn 8161: toggleUpload();
8162: toggleMap();
1.606 raeburn 8163: toggleCrsRes();
8164: toggleImportCrsres();
1.570 raeburn 8165: resize_scrollbox('contentscroll','1','0');
8166: return;
8167: } else {
8168: current.className = 'active';
8169: }
1.330 tempelho 8170: currentData = document.getElementById(pageId);
8171: currentData.style.display = 'block';
1.458 raeburn 8172: activeTab = pageId;
1.656 raeburn 8173: toggleExternal();
1.501 raeburn 8174: toggleUpload();
1.503 raeburn 8175: toggleMap();
1.606 raeburn 8176: toggleCrsRes();
8177: toggleImportCrsres();
1.433 raeburn 8178: if (nav == 'mainnav') {
8179: var storedpath = "$docs_folderpath";
1.434 raeburn 8180: var storedpage = "$main_container_page";
1.433 raeburn 8181: var reg = new RegExp("^supplemental");
8182: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8183: if (storedpage == 1) {
8184: document.simpleedit.folderpath.value = '';
8185: document.uploaddocument.folderpath.value = '';
8186: } else {
8187: if (reg.test(storedpath)) {
8188: document.simpleedit.folderpath.value = '$toplevelmain';
8189: document.uploaddocument.folderpath.value = '$toplevelmain';
8190: document.newext.folderpath.value = '$toplevelmain';
8191: } else {
8192: document.simpleedit.folderpath.value = storedpath;
8193: document.uploaddocument.folderpath.value = storedpath;
8194: document.newext.folderpath.value = storedpath;
8195: }
1.433 raeburn 8196: }
8197: } else {
1.434 raeburn 8198: if (reg.test(storedpath)) {
8199: document.simpleedit.folderpath.value = storedpath;
8200: document.supuploaddocument.folderpath.value = storedpath;
8201: document.supnewext.folderpath.value = storedpath;
8202: } else {
1.433 raeburn 8203: document.simpleedit.folderpath.value = '$toplevelsupp';
8204: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8205: document.supnewext.folderpath.value = '$toplevelsupp';
8206: }
8207: }
8208: }
1.485 raeburn 8209: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8210: return false;
8211: }
1.329 droeschl 8212:
1.472 raeburn 8213: function toContents(jumpto) {
8214: var newurl = '$backtourl';
1.525 raeburn 8215: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8216: newurl = newurl+'?postdata='+jumpto;
8217: }
8218: location.href=newurl;
8219: }
8220:
1.538 raeburn 8221: function togglePick(caller,value) {
8222: var disp = 'none';
8223: if (document.getElementById('multi'+caller)) {
8224: var curr = document.getElementById('multi'+caller).style.display;
8225: if (value == 1) {
8226: disp='block';
8227: }
8228: if (curr == disp) {
8229: return;
8230: }
8231: document.getElementById('multi'+caller).style.display=disp;
8232: if (value == 1) {
1.594 damieng 8233: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8234: } else {
8235: document.getElementById('more'+caller).innerHTML = '';
8236: }
8237: if (caller == 'actions') {
8238: setClass(value);
8239: setBoxes(value);
8240: }
8241: }
8242: var showButton = multiSettings();
8243: if (showButton != 1) {
8244: showButton = multiActions();
8245: }
8246: if (document.getElementById('multisave')) {
8247: if (showButton == 1) {
8248: document.getElementById('multisave').style.display='block';
8249: } else {
8250: document.getElementById('multisave').style.display='none';
8251: }
8252: }
8253: resize_scrollbox('contentscroll','1','1');
8254: return;
8255: }
8256:
8257: function toggleCheckUncheck(caller,more) {
8258: if (more == 1) {
1.594 damieng 8259: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8260: document.getElementById('allfields'+caller).style.display='block';
8261: } else {
1.594 damieng 8262: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8263: document.getElementById('allfields'+caller).style.display='none';
8264: }
8265: resize_scrollbox('contentscroll','1','1');
8266: }
8267:
8268: function multiSettings() {
8269: var inuse = 0;
8270: var settingsform = document.togglemultsettings;
8271: if (settingsform.showmultpick.length > 1) {
8272: for (var i=0; i<settingsform.showmultpick.length; i++) {
8273: if (settingsform.showmultpick[i].checked) {
8274: if (settingsform.showmultpick[i].value == 1) {
8275: inuse = 1;
8276: }
8277: }
8278: }
8279: }
8280: return inuse;
8281: }
8282:
8283: function multiActions() {
8284: var inuse = 0;
8285: var actionsform = document.togglemultactions;
8286: if (actionsform.showmultpick.length > 1) {
8287: for (var i=0; i<actionsform.showmultpick.length; i++) {
8288: if (actionsform.showmultpick[i].checked) {
8289: if (actionsform.showmultpick[i].value == 1) {
8290: inuse = 1;
8291: }
8292: }
8293: }
8294: }
8295: return inuse;
8296: }
8297:
8298: function checkSubmits() {
8299: var numchanges = 0;
8300: var form = document.saveactions;
8301: var doactions = multiActions();
1.542 raeburn 8302: var cutwarnings = 0;
8303: var remwarnings = 0;
1.603 raeburn 8304: var removalinfo = 0;
1.538 raeburn 8305: if (doactions == 1) {
8306: var remidxlist = document.cumulativeactions.allremoveidx.value;
8307: if ((remidxlist != '') && (remidxlist != null)) {
8308: var remidxs = remidxlist.split(',');
8309: for (var i=0; i<remidxs.length; i++) {
8310: if (document.getElementById('remove_'+remidxs[i])) {
8311: if (document.getElementById('remove_'+remidxs[i]).checked) {
8312: form.multiremove.value += remidxs[i]+',';
8313: numchanges ++;
1.542 raeburn 8314: if (document.getElementById('skip_remove_'+remidxs[i])) {
8315: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8316: remwarnings ++;
8317: }
8318: }
1.603 raeburn 8319: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8320: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8321: removalinfo ++;
8322: }
8323: }
1.537 raeburn 8324: }
8325: }
1.538 raeburn 8326: }
8327: }
8328: var cutidxlist = document.cumulativeactions.allcutidx.value;
8329: if ((cutidxlist != '') && (cutidxlist != null)) {
8330: var cutidxs = cutidxlist.split(',');
8331: for (var i=0; i<cutidxs.length; i++) {
8332: if (document.getElementById('cut_'+cutidxs[i])) {
8333: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8334: form.multicut.value += cutidxs[i]+',';
8335: numchanges ++;
1.542 raeburn 8336: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8337: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8338: cutwarnings ++;
8339: }
8340: }
1.537 raeburn 8341: }
8342: }
8343: }
8344: }
1.538 raeburn 8345: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8346: if ((copyidxlist != '') && (copyidxlist != null)) {
8347: var copyidxs = copyidxlist.split(',');
8348: for (var i=0; i<copyidxs.length; i++) {
8349: if (document.getElementById('copy_'+copyidxs[i])) {
8350: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8351: form.multicopy.value += copyidxs[i]+',';
8352: numchanges ++;
8353: }
8354: }
8355: }
8356: }
8357: if (numchanges > 0) {
8358: form.multichange.value = numchanges;
8359: }
1.537 raeburn 8360: }
1.538 raeburn 8361: var dosettings = multiSettings();
1.543 raeburn 8362: var haschanges = 0;
1.538 raeburn 8363: if (dosettings == 1) {
8364: form.allencrypturl.value = '';
8365: form.allhiddenresource.value = '';
1.543 raeburn 8366: form.changeparms.value = 'all';
8367: var patt=new RegExp(",\$");
1.538 raeburn 8368: var allidxlist = document.cumulativesettings.allidx.value;
8369: if ((allidxlist != '') && (allidxlist != null)) {
8370: var allidxs = allidxlist.split(',');
8371: if (allidxs.length > 1) {
8372: for (var i=0; i<allidxs.length; i++) {
8373: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8374: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8375: form.allhiddenresource.value += allidxs[i]+',';
8376: }
8377: }
8378: if (document.getElementById('encrypturl_'+allidxs[i])) {
8379: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8380: form.allencrypturl.value += allidxs[i]+',';
8381: }
8382: }
8383: }
1.543 raeburn 8384: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8385: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8386: }
1.538 raeburn 8387: }
8388: form.allrandompick.value = '';
8389: form.allrandomorder.value = '';
8390: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8391: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8392: var allmapidxs = allmapidxlist.split(',');
8393: for (var i=0; i<allmapidxs.length; i++) {
8394: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8395: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8396: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8397: if ((randompick.checked) && (rpicknum.value != '')) {
8398: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8399: }
8400: if (randorder.checked) {
8401: form.allrandomorder.value += allmapidxs[i]+',';
8402: }
1.537 raeburn 8403: }
1.543 raeburn 8404: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8405: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8406: }
8407: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8408: haschanges = 1;
8409: }
8410: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8411: haschanges = 1;
8412: }
8413: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8414: haschanges = 1;
8415: }
8416: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8417: haschanges = 1;
1.537 raeburn 8418: }
8419: }
1.543 raeburn 8420: if (doactions == 1) {
1.542 raeburn 8421: if (numchanges > 0) {
1.603 raeburn 8422: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8423: if (remwarnings > 0) {
1.594 damieng 8424: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8425: return false;
8426: }
8427: }
1.603 raeburn 8428: if (removalinfo > 0) {
8429: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8430: return false;
8431: }
8432: }
1.542 raeburn 8433: if (cutwarnings > 0) {
1.594 damieng 8434: 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 8435: return false;
8436: }
8437: }
8438: }
8439: form.submit();
8440: return true;
1.543 raeburn 8441: }
8442: }
8443: if (dosettings == 1) {
8444: if (haschanges == 1) {
1.542 raeburn 8445: form.submit();
8446: return true;
8447: }
1.543 raeburn 8448: }
8449: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8450: alert("$js_lt{'noor'}");
1.543 raeburn 8451: } else {
8452: if (dosettings == 1) {
1.594 damieng 8453: alert("$js_lt{'noch'}");
1.543 raeburn 8454: } else {
1.594 damieng 8455: alert("$js_lt{'noac'}");
1.543 raeburn 8456: }
8457: }
1.538 raeburn 8458: return false;
8459: }
8460:
8461: function setClass(value) {
8462: var cutclass = 'LC_docs_cut';
8463: var copyclass = 'LC_docs_copy';
8464: var removeclass = 'LC_docs_remove';
8465: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8466: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8467: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8468: var links = document.getElementsByTagName('a');
8469: for (var i=0; i<links.length; i++) {
8470: var classes = links[i].className;
8471: if (cutreg.test(classes)) {
8472: links[i].className = cutclass;
8473: if (value == 1) {
8474: links[i].className += " LC_menubuttons_link";
8475: }
8476: } else {
8477: if (copyreg.test(classes)) {
8478: links[i].className = copyclass;
8479: if (value == 1) {
8480: links[i].className += " LC_menubuttons_link";
8481: }
8482: } else {
8483: if (removereg.test(classes)) {
8484: links[i].className = removeclass;
8485: if (value == 1) {
8486: links[i].className += " LC_menubuttons_link";
8487: }
8488: }
8489: }
8490: }
8491: }
8492: return;
1.537 raeburn 8493: }
8494:
1.538 raeburn 8495: function setBoxes(value) {
8496: var remidxlist = document.cumulativeactions.allremoveidx.value;
8497: if ((remidxlist != '') && (remidxlist != null)) {
8498: var remidxs = remidxlist.split(',');
8499: for (var i=0; i<remidxs.length; i++) {
8500: if (document.getElementById('remove_'+remidxs[i])) {
8501: var item = document.getElementById('remove_'+remidxs[i]);
8502: if (value == 1) {
8503: item.className = 'LC_docs_remove';
8504: } else {
8505: item.className = 'LC_hidden';
8506: }
8507: }
8508: }
8509: }
8510: var cutidxlist = document.cumulativeactions.allcutidx.value;
8511: if ((cutidxlist != '') && (cutidxlist != null)) {
8512: var cutidxs = cutidxlist.split(',');
8513: for (var i=0; i<cutidxs.length; i++) {
8514: if (document.getElementById('cut_'+cutidxs[i])) {
8515: var item = document.getElementById('cut_'+cutidxs[i]);
8516: if (value == 1) {
8517: item.className = 'LC_docs_cut';
8518: } else {
8519: item.className = 'LC_hidden';
8520: }
8521: }
1.537 raeburn 8522: }
8523: }
1.538 raeburn 8524: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8525: if ((copyidxlist != '') && (copyidxlist != null)) {
8526: var copyidxs = copyidxlist.split(',');
8527: for (var i=0; i<copyidxs.length; i++) {
8528: if (document.getElementById('copy_'+copyidxs[i])) {
8529: var item = document.getElementById('copy_'+copyidxs[i]);
8530: if (value == 1) {
8531: item.className = 'LC_docs_copy';
8532: } else {
8533: item.className = 'LC_hidden';
8534: }
8535: }
1.537 raeburn 8536: }
8537: }
8538: return;
8539: }
8540:
1.606 raeburn 8541: function validImportCrsRes() {
8542: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8543: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8544: if ((fname == '') || (fname == null)) {
8545: alert("$js_lt{'nofi'}");
8546: return false;
8547: }
8548: var url = '/res/$coursedom/$coursenum/';
8549: if (path && path != '/') {
8550: url += path+'/';
8551: }
8552: if (fname != '') {
8553: url += fname;
8554: }
8555: var title = document.crsresimportform.crsrestitle.value;
8556: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8557: return true;
8558: }
8559:
8560: function validateNewRes(caller) {
8561: if (caller == 'single') {
8562: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8563: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8564: var resname = document.courseresform.newresourcename.value;
8565: }
8566: }
8567:
1.611 raeburn 8568: ENDSCRIPT
1.329 droeschl 8569: }
1.457 raeburn 8570:
1.483 raeburn 8571: sub history_tab_js {
8572: return <<"ENDHIST";
8573: function toggleHistoryDisp(choice) {
8574: document.docslogform.docslog.value = choice;
8575: document.docslogform.submit();
8576: return;
8577: }
8578:
8579: ENDHIST
8580: }
8581:
1.484 raeburn 8582: sub inject_data_js {
8583: return <<ENDINJECT;
8584:
8585: function injectData(current, hiddenField, name, value) {
8586: currentElement = document.getElementById(hiddenField);
8587: currentElement.name = name;
8588: currentElement.value = value;
8589: current.submit();
8590: }
8591:
8592: ENDINJECT
8593: }
8594:
8595: sub dump_switchserver_js {
8596: my @hosts = @_;
1.594 damieng 8597: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8598: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8599: swit => 'Switch server?',
1.594 damieng 8600: );
8601: my %html_js_lt = &Apache::lonlocal::texthash(
8602: swit => 'Switch server?',
1.568 raeburn 8603: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8604: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8605: chos => 'Choose server',
8606: );
1.594 damieng 8607: &js_escape(\%js_lt);
8608: &html_escape(\%html_js_lt);
8609: &js_escape(\%html_js_lt);
1.484 raeburn 8610: my $role = $env{'request.role'};
8611: my $js = <<"ENDSWJS";
8612: <script type="text/javascript">
8613: function write_switchserver() {
8614: var server;
8615: if (document.setserver.posshosts.length > 0) {
8616: for (var i=0; i<document.setserver.posshosts.length; i++) {
8617: if (document.setserver.posshosts[i].checked) {
8618: server = document.setserver.posshosts[i].value;
8619: }
8620: }
8621: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8622: }
8623: window.close();
8624: }
8625: </script>
8626:
8627: ENDSWJS
8628:
8629: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8630: {'only_body' => 1,
8631: 'js_ready' => 1,});
8632: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8633:
8634: my $hostpicker;
8635: my $count = 0;
8636: foreach my $host (sort(@hosts)) {
8637: my $checked;
8638: if ($count == 0) {
8639: $checked = ' checked="checked"';
8640: }
8641: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8642: $host.'"'.$checked.' />'.$host.'</label> ';
8643: $count++;
8644: }
8645:
8646: return <<"ENDSWITCHJS";
8647:
8648: function dump_needs_switchserver(url) {
8649: if (url!='' && url!= null) {
1.594 damieng 8650: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8651: go(url);
8652: }
8653: }
8654: return;
8655: }
8656:
8657: function choose_switchserver_window() {
8658: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8659: newWindow.document.open();
8660: newWindow.document.writeln('$startpage');
1.594 damieng 8661: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8662: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8663: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8664: '<form name="setserver" method="post" action="" \\/>\\n'+
8665: '$hostpicker\\n'+
8666: '<br \\/><br \\/>\\n'+
1.594 damieng 8667: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8668: 'onclick="write_switchserver();" \\/>\\n'+
8669: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8670: newWindow.document.writeln('$endpage');
8671: newWindow.document.close();
8672: newWindow.focus();
8673: }
8674:
8675: ENDSWITCHJS
8676: }
8677:
8678: sub makedocslogform {
8679: my ($formelems,$docslog) = @_;
8680: return <<"LOGSFORM";
8681: <form action="/adm/coursedocs" method="post" name="docslogform">
8682: <input type="hidden" name="docslog" value="$docslog" />
8683: $formelems
8684: </form>
8685: LOGSFORM
8686: }
8687:
8688: sub makesimpleeditform {
8689: my ($formelems) = @_;
8690: return <<"SIMPFORM";
8691: <form name="simpleedit" method="post" action="/adm/coursedocs">
8692: <input type="hidden" name="importdetail" value="" />
8693: $formelems
8694: </form>
8695: SIMPFORM
8696: }
8697:
1.606 raeburn 8698: sub makenewproblem {
8699: my ($r,$coursedom,$coursenum) = @_;
8700: # Creating a new problem
8701: my ($redirect,$error);
8702: if ($env{'form.authorrole'}) {
8703: my ($newsubdir,$filename);
8704: if ($env{'form.newsubdir'}) {
8705: if ($env{'form.newsubdirname'} ne '') {
8706: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 8707: }
1.606 raeburn 8708: }
8709: if ($env{'form.newresourcename'}) {
8710: $filename = $env{'form.newresourcename'};
8711: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8712: $filename =~ s/`//g;
8713: $filename =~ s{/\.\./}{_}g;
8714: $filename =~ s/\.+/./g;
8715: $filename =~ s{/+}{_}g;
8716: if ($filename ne '') {
8717: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8718: if (($ext) && ($ext ne '.problem')) {
8719: $filename = $name.'.problem';
8720: } elsif ($ext eq '') {
8721: $filename .= '.problem';
8722: }
8723: my $docroot = $r->dir_config('lonDocRoot');
8724: my @ids=&Apache::lonnet::current_machine_ids();
8725: if ($env{'form.authorrole'} eq 'author') {
8726: if ($env{'user.author'}) {
8727: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8728: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8729: my $path = $docroot.$url;
8730: my $subdir = $env{'form.authorpath'};
8731: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8732: }
8733: }
8734: } elsif ($env{'form.authorrole'} eq 'course') {
8735: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8736: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8737: my $url = "/priv/$coursedom/$coursenum";
8738: my $path=$docroot.$url;
8739: my $subdir = $env{'form.authorpath'};
8740: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8741: if ($redirect) {
8742: my $rightsfile = 'default.rights';
8743: my $sourcerights = "$path/$rightsfile";
8744: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8745: my $now = time;
8746: if (!-e $sourcerights) {
8747: my $cid = $coursedom.'_'.$coursenum;
8748: if (open(my $fh,">$sourcerights")) {
8749: print $fh <<END;
8750: <accessrule effect="deny" realm="" type="course" role="" />
8751: <accessrule effect="allow" realm="$cid" type="course" role="" />
8752: END
8753: close($fh);
8754: }
8755: }
8756: if (!-e "$sourcerights.meta") {
8757: if (open(my $fh,">$sourcerights.meta")) {
8758: my $author=$env{'environment.firstname'}.' '.
8759: $env{'environment.middlename'}.' '.
8760: $env{'environment.lastname'}.' '.
8761: $env{'environment.generation'};
8762: $author =~ s/\s+$//;
8763: print $fh <<"END";
8764:
8765: <abstract></abstract>
8766: <author>$author</author>
8767: <authorspace>$coursenum:$coursedom</authorspace>
8768: <copyright>private</copyright>
8769: <creationdate>$now</creationdate>
8770: <customdistributionfile></customdistributionfile>
8771: <dependencies></dependencies>
8772: <domain>$coursedom</domain>
8773: <highestgradelevel>0</highestgradelevel>
8774: <keywords></keywords>
8775: <language>notset </language>
8776: <lastrevisiondate>$now</lastrevisiondate>
8777: <lowestgradelevel>0</lowestgradelevel>
8778: <mime>rights</mime>
8779: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8780: <notes></notes>
8781: <obsolete></obsolete>
8782: <obsoletereplacement></obsoletereplacement>
8783: <owner>$coursenum:$coursedom</owner>
8784: <rule>deny:::course,allow:$cid::course</rule>
8785: <sourceavail></sourceavail>
8786: <standards></standards>
8787: <subject></subject>
8788: <title></title>
8789: END
1.654 raeburn 8790: close($fh);
8791: }
8792: }
8793: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8794: if (!-e "$docroot/res/$coursedom") {
8795: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 8796: }
1.654 raeburn 8797: if (!-e "$docroot/res/$coursedom/$coursenum") {
8798: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8799: }
8800: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8801: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8802: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 8803: }
8804: }
1.654 raeburn 8805: my $source = $docroot.$redirect;
8806: if (!-e "$source.meta") {
8807: my $cid = $coursedom.'_'.$coursenum;
8808: my $now = time;
8809: if (open(my $fh,">$source.meta")) {
8810: my $author=$env{'environment.firstname'}.' '.
8811: $env{'environment.middlename'}.' '.
8812: $env{'environment.lastname'}.' '.
8813: $env{'environment.generation'};
8814: $author =~ s/\s+$//;
8815: my $title = $env{'form.newresourcetitle'};
8816: $title =~ s/^\s+|\s+$//g;
8817: print $fh <<END;
1.606 raeburn 8818:
8819: <abstract></abstract>
8820: <author>$author</author>
8821: <authorspace>$coursenum:$coursedom</authorspace>
8822: <copyright>custom</copyright>
8823: <creationdate>$now</creationdate>
8824: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8825: <dependencies></dependencies>
8826: <domain>$coursedom</domain>
8827: <highestgradelevel>0</highestgradelevel>
8828: <keywords></keywords>
8829: <language>notset </language>
8830: <lastrevisiondate>$now</lastrevisiondate>
8831: <lowestgradelevel>0</lowestgradelevel>
8832: <mime>problem</mime>
8833: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8834: <notes></notes>
8835: <obsolete></obsolete>
8836: <obsoletereplacement></obsoletereplacement>
8837: <owner>$coursenum:$coursedom</owner>
8838: <sourceavail></sourceavail>
8839: <standards></standards>
8840: <subject></subject>
8841: <title>$title</title>
8842: END
1.654 raeburn 8843: close($fh);
1.606 raeburn 8844: }
8845: }
8846: }
8847: }
8848: } else {
8849: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8850: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8851: if (grep(/^\Q$rolehome\E$/,@ids)) {
8852: my $now = time;
8853: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8854: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8855: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8856: my $url = "/priv/$audom/$auname";
8857: my $path = $r->dir_config('lonDocRoot').$url;
8858: my $subdir = $env{'form.authorpath'};
8859: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8860: }
8861: }
8862: }
8863: }
8864: }
8865: }
8866: }
8867: return ($redirect,$error);
8868: }
8869:
8870: sub finishnewprob {
1.654 raeburn 8871: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 8872: unless (-d $path) {
8873: unless (mkdir($path,02770)) {
8874: return;
8875: }
8876: }
1.606 raeburn 8877: my $redirect;
8878: if ($subdir ne '/') {
8879: $subdir = &cleandir($subdir);
8880: if (($subdir ne '') && (-d "$path/$subdir")) {
8881: $path .= "/$subdir";
8882: $url .= "/$subdir";
8883: }
8884: }
8885: my $dest;
8886: if ($newsubdir ne '') {
8887: $newsubdir = &cleandir($newsubdir);
8888: }
8889: if ($newsubdir ne '') {
8890: if (-d "$path/$newsubdir") {
8891: $dest = "$path/$newsubdir/$filename";
8892: } else {
8893: my $dirok;
8894: unless (-e "$path/$newsubdir") {
8895: if (mkdir("$path/$newsubdir",02770)) {
8896: if (chmod(02770,"$path/$newsubdir")) {
8897: $dirok = 1;
8898: }
8899: }
8900: }
8901: if ($dirok) {
8902: $dest = "$path/$newsubdir/$filename";
8903: }
8904: }
8905: if (($dest ne '') && (!-e $dest)) {
8906: $redirect = "$url/$newsubdir/$filename";
8907: }
8908: } else {
8909: $dest = "$path/$filename";
8910: if (($dest ne '') && (!-e $dest)) {
8911: $redirect = "$url/$filename";
8912: }
8913: }
1.654 raeburn 8914: if ((!-e $dest) && ($context ne 'upload')) {
8915: my $template = $env{'form.template'};
8916: my $copyfrom;
8917: if ($template ne '') {
8918: my %templates;
8919: my @files = &Apache::lonhomework::get_template_list('problem');
8920: foreach my $poss (@files) {
8921: if (ref($poss) eq 'ARRAY') {
8922: if ($template eq $poss->[0]) {
8923: $templates{$template} = 1;
8924: last;
8925: }
8926: }
8927: }
8928: if ($templates{$template}) {
8929: $copyfrom = $template;
8930: }
8931: }
8932: if ($filename =~ /\.problem$/) {
8933: unless ($copyfrom) {
8934: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
8935: }
8936: &File::Copy::copy($copyfrom,$dest);
8937: }
8938: }
1.606 raeburn 8939: return $redirect;
8940: }
8941:
8942: sub cleandir {
8943: my ($dir) = @_;
8944: $dir =~ s/^\s+//;
8945: $dir =~ s/\s+$//;
8946: $dir =~ s/\.+//g;
8947: $dir =~ s/[\#\?&%\":]//g;
8948: return $dir;
8949: }
8950:
1.329 droeschl 8951: 1;
8952: __END__
8953:
8954:
8955: =head1 NAME
8956:
8957: Apache::londocs.pm
8958:
8959: =head1 SYNOPSIS
8960:
8961: This is part of the LearningOnline Network with CAPA project
8962: described at http://www.lon-capa.org.
8963:
8964: =head1 SUBROUTINES
8965:
8966: =over
8967:
8968: =item %help=()
8969:
8970: Available help topics
8971:
8972: =item mapread()
8973:
1.344 bisitz 8974: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8975: @order and @resources, determines status
8976: sets @order - pointer to resources in right order
8977: sets @resources - array with the resources with correct idx
8978:
8979: =item authorhosts()
8980:
8981: Return hash with valid author names
8982:
8983: =item clean()
8984:
8985: =item dumpcourse()
8986:
8987: Actually dump course
8988:
8989: =item group_import()
8990:
8991: Imports the given (name, url) resources into the course
8992: coursenum, coursedom, and folder must precede the list
8993:
8994: =item breadcrumbs()
8995:
8996: =item log_docs()
8997:
8998: =item docs_change_log()
8999:
9000: =item update_paste_buffer()
9001:
9002: =item print_paste_buffer()
9003:
9004: =item do_paste_from_buffer()
9005:
1.538 raeburn 9006: =item do_buffer_empty()
9007:
9008: =item clear_from_buffer()
9009:
1.492 raeburn 9010: =item get_newmap_url()
9011:
9012: =item dbcopy()
9013:
9014: =item uniqueness_check()
9015:
9016: =item contained_map_check()
9017:
9018: =item url_paste_fixups()
9019:
9020: =item apply_fixups()
9021:
9022: =item copy_dependencies()
9023:
1.329 droeschl 9024: =item update_parameter()
9025:
9026: =item handle_edit_cmd()
9027:
9028: =item editor()
9029:
9030: =item process_file_upload()
9031:
9032: =item process_secondary_uploads()
9033:
9034: =item is_supplemental_title()
9035:
9036: =item entryline()
9037:
9038: =item tiehash()
9039:
9040: =item untiehash()
9041:
9042: =item checkonthis()
9043:
9044: check on this
9045:
9046: =item verifycontent()
9047:
9048: Verify Content
9049:
1.636 raeburn 9050: =item devalidateversioncache()
9051:
9052: =item checkversions()
1.329 droeschl 9053:
9054: Check Versions
9055:
9056: =item mark_hash_old()
9057:
9058: =item is_hash_old()
9059:
9060: =item changewarning()
9061:
9062: =item init_breadcrumbs()
9063:
9064: Breadcrumbs for special functions
9065:
1.484 raeburn 9066: =item create_list_elements()
9067:
9068: =item create_form_ul()
9069:
9070: =item startContentScreen()
9071:
9072: =item endContentScreen()
9073:
9074: =item supplemental_base()
9075:
9076: =item embedded_form_elems()
9077:
9078: =item embedded_destination()
9079:
9080: =item return_to_editor()
9081:
9082: =item decompression_info()
9083:
9084: =item decompression_phase_one()
9085:
9086: =item decompression_phase_two()
9087:
9088: =item remove_archive()
9089:
9090: =item generate_admin_menu()
9091:
9092: =item generate_edit_table()
9093:
9094: =item editing_js()
9095:
9096: =item history_tab_js()
9097:
9098: =item inject_data_js()
9099:
9100: =item dump_switchserver_js()
9101:
1.485 raeburn 9102: =item resize_scrollbox_js()
1.484 raeburn 9103:
9104: =item makedocslogform()
9105:
1.485 raeburn 9106: =item makesimpleeditform()
9107:
1.329 droeschl 9108: =back
9109:
9110: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>