Annotation of loncom/interface/londocs.pm, revision 1.664
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.664 ! raeburn 4: # $Id: londocs.pm,v 1.663 2019/08/11 15:15:39 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'; }
836: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 837: if ($name eq '') {
1.538 raeburn 838: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 839: }
840: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
841: my $filepath = $1;
842: my $fname = $name;
843: if ($fname =~ /^\W+$/) {
844: $fname = 'web';
845: } else {
846: $fname =~ s/\W/_/g;
847: }
1.599 damieng 848: if (length($fname) > 15) {
1.534 raeburn 849: $fname = substr($fname,0,14);
850: }
851: my $initialtext = &mt('Replace with your own content.');
852: my $newhtml = <<END;
1.545 raeburn 853: <html>
1.534 raeburn 854: <head>
855: <title>$name</title>
856: </head>
857: <body bgcolor="#ffffff">
858: $initialtext
859: </body>
860: </html>
861: END
862: $env{'form.output'}=$newhtml;
1.630 raeburn 863: my $result =
1.534 raeburn 864: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
865: 'output',
866: "$filepath/$residx/$fname.html");
867: if ($result =~ m{^/uploaded/}) {
868: $url = $result;
869: if ($filepath =~ /^supplemental/) {
870: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
871: $env{'user.domain'}.'___&&&___'.$name;
872: }
873: } else {
874: return (&mt('Failed to save new web page.'),1);
875: }
876: }
1.538 raeburn 877: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 878: $LONCAPA::map::resources[$residx] =
1.329 droeschl 879: join(':', ($name, $url, $ext, 'normal', 'res'));
880: }
881: }
1.529 raeburn 882: if ($importuploaded) {
883: my %import_errors;
884: my %updated = (
885: removefrommap => \%removefrommap,
886: removeparam => \%removeparam,
887: );
1.533 raeburn 888: my ($result,$msgsarray,$lockerror) =
889: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 890: if (keys(%import_errors) > 0) {
1.530 raeburn 891: $fixuperrors =
1.529 raeburn 892: '<p span class="LC_warning">'."\n".
893: &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".
894: '<ul>'."\n";
895: foreach my $key (sort(keys(%import_errors))) {
896: $fixuperrors .= '<li>'.$key.'</li>'."\n";
897: }
898: $fixuperrors .= '</ul></p>'."\n";
899: }
1.533 raeburn 900: if (ref($msgsarray) eq 'ARRAY') {
901: if (@{$msgsarray} > 0) {
902: $fixuperrors .= '<p class="LC_info">'.
903: join('<br />',@{$msgsarray}).
904: '</p>';
905: }
906: }
907: if ($lockerror) {
908: $fixuperrors .= '<p class="LC_error">'.
909: $lockerror.
910: '</p>';
911: }
1.529 raeburn 912: }
913: my ($errtext,$fatal) =
914: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 915: unless ($fatal) {
916: if ($folder =~ /^supplemental/) {
917: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 918: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
919: $folder.'.'.$container);
1.557 raeburn 920: }
921: }
1.529 raeburn 922: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 923: }
924:
925: sub log_docs {
1.494 raeburn 926: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 927: }
928:
929: {
930: my @oldresources=();
931: my @oldorder=();
932: my $parmidx;
933: my %parmaction=();
934: my %parmvalue=();
935: my $changedflag;
936:
937: sub snapshotbefore {
938: @oldresources=@LONCAPA::map::resources;
939: @oldorder=@LONCAPA::map::order;
940: $parmidx=undef;
941: %parmaction=();
942: %parmvalue=();
943: $changedflag=0;
944: }
945:
946: sub remember_parms {
947: my ($idx,$parameter,$action,$value)=@_;
948: $parmidx=$idx;
949: $parmaction{$parameter}=$action;
950: $parmvalue{$parameter}=$value;
951: $changedflag=1;
952: }
953:
954: sub log_differences {
955: my ($plain)=@_;
956: my %storehash=('folder' => $plain,
957: 'currentfolder' => $env{'form.folder'});
958: if ($parmidx) {
959: $storehash{'parameter_res'}=$oldresources[$parmidx];
960: foreach my $parm (keys(%parmaction)) {
961: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
962: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
963: }
964: }
965: my $maxidx=$#oldresources;
966: if ($#LONCAPA::map::resources>$#oldresources) {
967: $maxidx=$#LONCAPA::map::resources;
968: }
969: for (my $idx=0; $idx<=$maxidx; $idx++) {
970: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
971: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
972: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
973: $changedflag=1;
974: }
975: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
976: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
977: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
978: $changedflag=1;
979: }
980: }
981: $storehash{'maxidx'}=$maxidx;
982: if ($changedflag) { &log_docs(\%storehash); }
983: }
984: }
985:
986: sub docs_change_log {
1.611 raeburn 987: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 988: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 989: my $navmap;
1.483 raeburn 990: my $js = '<script type="text/javascript">'."\n".
991: '// <![CDATA['."\n".
992: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 993: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 994: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 995: &history_tab_js()."\n".
1.484 raeburn 996: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 997: '// ]]>'."\n".
998: '</script>'."\n";
1.484 raeburn 999: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1000: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 1001: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 1002: my %orderhash;
1003: my $container='sequence';
1004: my $pathitem;
1.519 raeburn 1005: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 1006: $container='page';
1007: }
1.519 raeburn 1008: my $folderpath=$env{'form.folderpath'};
1009: if ($folderpath eq '') {
1.617 raeburn 1010: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 1011: }
1.617 raeburn 1012: undef($navmap);
1.519 raeburn 1013: $pathitem = '<input type="hidden" name="folderpath" value="'.
1014: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 1015: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1016: my $jumpto = $readfile;
1017: $jumpto =~ s{^/}{};
1018: my $tid = 1;
1.489 raeburn 1019: if ($supplementalflag) {
1020: $tid = 2;
1021: }
1.630 raeburn 1022: my ($breadcrumbtrail) =
1.509 raeburn 1023: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 1024: $r->print($breadcrumbtrail.
1025: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1026: $readfile));
1.329 droeschl 1027: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1028: $env{'course.'.$env{'request.course.id'}.'.domain'},
1029: $env{'course.'.$env{'request.course.id'}.'.num'});
1030:
1031: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1032:
1033: my %saveable_parameters = ('show' => 'scalar',);
1034: &Apache::loncommon::store_course_settings('docs_log',
1035: \%saveable_parameters);
1036: &Apache::loncommon::restore_course_settings('docs_log',
1037: \%saveable_parameters);
1038: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1039: # FIXME: internationalization seems wrong here
1.329 droeschl 1040: my %lt=('hiddenresource' => 'Resources hidden',
1041: 'encrypturl' => 'URL hidden',
1042: 'randompick' => 'Randomly pick',
1043: 'randomorder' => 'Randomly ordered',
1.645 raeburn 1044: 'gradable' => 'Grade can be assigned to External Tool',
1.329 droeschl 1045: 'set' => 'set to',
1046: 'del' => 'deleted');
1.484 raeburn 1047: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1048: $pathitem."\n".
1049: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1050: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1051: $r->print('<div class="LC_left_float">'.
1052: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1053: &makedocslogform($filter,1).
1054: '</fieldset></div><br clear="all" />');
1.329 droeschl 1055: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1056: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1057: &mt('After').'</th>'.
1058: &Apache::loncommon::end_data_table_header_row());
1059: my $shown=0;
1060: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1061: if ($env{'form.displayfilter'} eq 'currentfolder') {
1062: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1063: }
1064: my @changes=keys(%{$docslog{$id}{'logentry'}});
1065: if ($env{'form.displayfilter'} eq 'containing') {
1066: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1067: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1068: foreach my $key (@changes) {
1069: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1070: }
1.344 bisitz 1071: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1072: }
1073: my $count = 0;
1074: my $time =
1075: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1076: my $plainname =
1077: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1078: $docslog{$id}{'exe_udom'});
1079: my $about_me_link =
1080: &Apache::loncommon::aboutmewrapper($plainname,
1081: $docslog{$id}{'exe_uname'},
1082: $docslog{$id}{'exe_udom'});
1083: my $send_msg_link='';
1084: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1085: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1086: $send_msg_link ='<br />'.
1087: &Apache::loncommon::messagewrapper(&mt('Send message'),
1088: $docslog{$id}{'exe_uname'},
1089: $docslog{$id}{'exe_udom'});
1090: }
1091: $r->print(&Apache::loncommon::start_data_table_row());
1092: $r->print('<td>'.$time.'</td>
1093: <td>'.$about_me_link.
1094: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1095: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1096: $send_msg_link.'</td><td>'.
1097: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1098: my $is_supp = 0;
1099: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1100: $is_supp = 1;
1101: }
1.329 droeschl 1102: # Before
1103: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1104: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1105: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1106: if ($oldname ne $newname) {
1.488 raeburn 1107: my $shown = &LONCAPA::map::qtescape($oldname);
1108: if ($is_supp) {
1109: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1110: }
1111: $r->print($shown);
1.329 droeschl 1112: }
1113: }
1114: $r->print('<ul>');
1115: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1116: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1117: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1118: if ($is_supp) {
1119: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1120: }
1121: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1122: }
1123: }
1124: $r->print('</ul>');
1125: # After
1126: $r->print('</td><td>');
1127:
1128: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1129: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1130: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1131: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1132: my $shown = &LONCAPA::map::qtescape($newname);
1133: if ($is_supp) {
1134: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1135: }
1136: $r->print($shown);
1.329 droeschl 1137: }
1.364 bisitz 1138: }
1.329 droeschl 1139: $r->print('<ul>');
1140: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1141: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1142: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1143: if ($is_supp) {
1144: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1145: }
1146: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1147: }
1148: }
1149: $r->print('</ul>');
1150: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1151: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1.645 raeburn 1152: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1.329 droeschl 1153: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1154: # FIXME: internationalization seems wrong here
1.329 droeschl 1155: $r->print('<li>'.
1156: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1157: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1158: .'</li>');
1159: }
1160: }
1161: $r->print('</ul>');
1162: }
1163: # End
1164: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1165: $shown++;
1166: if (!($env{'form.show'} eq &mt('all')
1167: || $shown<=$env{'form.show'})) { last; }
1168: }
1.484 raeburn 1169: $r->print(&Apache::loncommon::end_data_table()."\n".
1170: &makesimpleeditform($pathitem)."\n".
1171: '</div></div>');
1172: $r->print(&endContentScreen());
1.329 droeschl 1173: }
1174:
1175: sub update_paste_buffer {
1.492 raeburn 1176: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1177: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1178: if ($env{'form.multiremove'}) {
1179: $env{'form.multiremove'} =~ s/,$//;
1180: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1181: }
1182: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1183: if ($env{'form.multicut'}) {
1184: $env{'form.multicut'} =~ s/,$//;
1185: foreach my $item (split(/,/,$env{'form.multicut'})) {
1186: unless ($removals{$item}) {
1187: $cuts{$item} = 1;
1188: push(@possibles,$item.':cut');
1189: }
1190: }
1191: }
1192: if ($env{'form.multicopy'}) {
1193: $env{'form.multicopy'} =~ s/,$//;
1194: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1195: unless ($removals{$item} || $cuts{$item}) {
1196: push(@possibles,$item.':copy');
1197: }
1198: }
1199: }
1200: } elsif ($env{'form.markcopy'}) {
1201: @possibles = split(/,/,$env{'form.markcopy'});
1202: }
1.329 droeschl 1203:
1.538 raeburn 1204: return if (@possibles == 0);
1.329 droeschl 1205: return if (!defined($env{'form.copyfolder'}));
1206:
1207: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1208: $env{'form.copyfolder'});
1.538 raeburn 1209: return if ($fatal);
1210:
1211: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1212:
1.538 raeburn 1213: # Retrieve current paste buffer suffixes.
1214: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1215: my (%pasteurls,@newpaste);
1216:
1217: # Construct identifiers for current contents of user's paste buffer
1218: if (@currpaste) {
1219: foreach my $suffix (@currpaste) {
1220: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1221: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.630 raeburn 1222: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1223: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1224: ($url ne '')) {
1.597 raeburn 1225: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1226: }
1227: }
1228: }
1229:
1230: # Mark items for copying (skip any items already in user's paste buffer)
1231: my %addtoenv;
1.597 raeburn 1232:
1233: my @pathitems = split(/\&/,$env{'form.folderpath'});
1234: my @folderconf = split(/\:/,$pathitems[-1]);
1235: my $ispage = $folderconf[4];
1236:
1.538 raeburn 1237: foreach my $item (@possibles) {
1238: my ($orderidx,$cmd) = split(/:/,$item);
1239: next if ($orderidx =~ /\D/);
1240: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1241: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1242: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1243: my %denied = &action_restrictions($coursenum,$coursedom,
1244: &LONCAPA::map::qtescape($url),
1245: $env{'form.folderpath'},\%curr_groups);
1246: next if ($denied{'copy'});
1247: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1248: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1249: my ($suffix,$errortxt,$locknotfreed) =
1250: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1251: if ($suffix ne '') {
1252: push(@newpaste,$suffix);
1253: } else {
1254: if ($locknotfreed) {
1255: return $locknotfreed;
1256: }
1.538 raeburn 1257: }
1258: if (&is_supplemental_title($title)) {
1259: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1260: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1261: }
1.329 droeschl 1262:
1.538 raeburn 1263: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1264: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1265: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1266: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1267: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1268: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1269: my $prefix = $1;
1270: my $subdir =$2;
1271: if ($subdir eq '') {
1272: $subdir = $prefix;
1.492 raeburn 1273: }
1.538 raeburn 1274: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1275: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1276: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1277: if (ref($hierarchy{$url}) eq 'HASH') {
1278: my ($nested,$nestednames);
1279: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1280: $nested =~ s/\&$//;
1281: $nestednames =~ s/\Q___&&&___\E$//;
1282: if ($nested ne '') {
1283: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1284: }
1285: if ($nestednames ne '') {
1286: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1287: }
1.492 raeburn 1288: }
1289: }
1.591 raeburn 1290: if ($locknotfreed) {
1291: $output = $locknotfreed;
1292: last;
1293: }
1.492 raeburn 1294: }
1.538 raeburn 1295: if (@newpaste) {
1296: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1297: }
1.492 raeburn 1298: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1299: delete($env{'form.markcopy'});
1.591 raeburn 1300: return $output;
1.329 droeschl 1301: }
1302:
1.492 raeburn 1303: sub recurse_uploaded_maps {
1304: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1305: if (ref($hierarchy->{$url}) eq 'HASH') {
1306: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1307: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1308: my (@uploaded,@names,%shorter);
1309: for (my $i=0; $i<@maps; $i++) {
1310: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1311: if ($inner ne '') {
1312: push(@uploaded,$inner);
1313: push(@names,&escape($titles[$i]));
1314: $shorter{$maps[$i]} = $inner;
1315: }
1316: }
1317: $$nestref .= "$dir:".join(',',@uploaded).'&';
1318: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1319: foreach my $map (@maps) {
1320: if ($shorter{$map} ne '') {
1321: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1322: }
1323: }
1324: }
1325: return;
1326: }
1327:
1.329 droeschl 1328: sub print_paste_buffer {
1.492 raeburn 1329: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1330: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1331:
1.538 raeburn 1332: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1333: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1334: }
1335:
1.538 raeburn 1336: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1337: my ($pasteitems,@pasteable);
1.575 raeburn 1338: my $clipboardcount = 0;
1.488 raeburn 1339:
1.538 raeburn 1340: # Construct identifiers for current contents of user's paste buffer
1341: foreach my $suffix (@currpaste) {
1342: next if ($suffix =~ /\D/);
1343: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1344: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1345: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1346: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1347: ($url ne '')) {
1.575 raeburn 1348: $clipboardcount ++;
1.538 raeburn 1349: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1350: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1351: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1352: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1353: $is_external = 1;
1.626 raeburn 1354: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1355: $is_exttool = 1;
1.538 raeburn 1356: }
1357: if ($folder =~ /^supplemental/) {
1358: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1359: unless ($canpaste) {
1360: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1361: }
1362: } else {
1363: $canpaste = 1;
1364: }
1365: if ($canpaste) {
1366: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1367: my $srcdom = $1;
1368: my $srcnum = $2;
1369: my $rem = $3;
1370: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1371: $othercourse = 1;
1372: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1373: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1374: } else {
1375: $canpaste = 0;
1376: $nopaste = &mt('Paste from another course unavailable.');
1377: }
1378: }
1379: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1380: my $prefix = $1;
1381: $parent = $2;
1382: if ($folder !~ /^\Q$prefix\E/) {
1383: $areachange = 1;
1384: }
1385: $is_uploaded_map = 1;
1.492 raeburn 1386: }
1.597 raeburn 1387: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1388: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1389: if ($cid ne $env{'request.course.id'}) {
1390: my ($srcdom,$srcnum) = split(/_/,$cid);
1391: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1392: if (($is_exttool) && ($srcdom ne $coursedom)) {
1393: $canpaste = 0;
1394: $nopaste = &mt('Paste from another domain unavailable.');
1395: } else {
1396: $othercrs = '<br />'.&mt('(from another course)');
1397: }
1.596 raeburn 1398: } else {
1399: $canpaste = 0;
1400: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1401: }
1.596 raeburn 1402: }
1.492 raeburn 1403: }
1.596 raeburn 1404: if ($canpaste) {
1405: push(@pasteable,$suffix);
1.629 raeburn 1406: }
1.538 raeburn 1407: }
1408: my $buffer;
1.627 raeburn 1409: if ($is_external) {
1.538 raeburn 1410: $buffer = &mt('External Resource').': '.
1411: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1412: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1413: } elsif ($is_exttool) {
1414: $buffer = &mt('External Tool').': '.
1415: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1416: } else {
1417: my $icon = &Apache::loncommon::icon($extension);
1418: if ($extension eq 'sequence' &&
1419: $url =~ m{/default_\d+\.sequence$}x) {
1420: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1421: $icon .= '/navmap.folder.closed.gif';
1422: }
1.589 raeburn 1423: my $title = $env{'docs.markedcopy_title_'.$suffix};
1424: if ($title eq '') {
1425: ($title) = ($url =~ m{/([^/]+)$});
1426: }
1.538 raeburn 1427: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1428: ': '.
1429: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1430: &LONCAPA::map::qtescape($title));
1.538 raeburn 1431: }
1432: $pasteitems .= '<div class="LC_left_float">';
1433: my ($options,$onclick);
1434: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1435: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1436: if (($is_uploaded_map) ||
1437: ($url =~ /(bulletinboard|smppg)$/) ||
1438: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1439: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1440: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1441: }
1442: }
1443: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1444: if ($nopaste) {
1445: $pasteitems .= $nopaste;
1446: } else {
1447: if ($othercrs) {
1448: $pasteitems .= $othercrs;
1449: }
1450: if ($options) {
1451: $pasteitems .= $options;
1.492 raeburn 1452: }
1453: }
1.538 raeburn 1454: $pasteitems .= '</div>';
1455: }
1456: }
1457: if ($pasteitems eq '') {
1458: &Apache::lonnet::delenv('docs.markedcopies');
1459: }
1460: my ($pasteform,$form_start,$buttons,$form_end);
1461: if ($pasteitems) {
1462: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1463: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1464: if (@pasteable) {
1.575 raeburn 1465: my $value = &mt('Paste to current folder');
1466: if ($container eq 'page') {
1467: $value = &mt('Paste to current page');
1468: }
1469: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1470: }
1471: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1472: if ($clipboardcount > 1) {
1473: $buttons .=
1474: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1475: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1476: (' 'x2).
1477: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1478: (' 'x2);
1.492 raeburn 1479: }
1.575 raeburn 1480: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1481: '</form>';
1.538 raeburn 1482: } else {
1483: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1484: }
1.538 raeburn 1485: $r->print($form_start
1486: .'<fieldset>'
1487: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1488: .$pasteitems
1489: .'</fieldset>'
1490: .$form_end);
1491: }
1492:
1493: sub paste_options {
1494: my ($suffix,$is_uploaded_map,$parent) = @_;
1495: my ($copytext,$movetext);
1496: if ($is_uploaded_map) {
1497: $copytext = &mt('Copy to new folder');
1498: $movetext = &mt('Move old');
1499: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1500: $copytext = &mt('Copy to new board');
1501: $movetext = &mt('Move (not posts)');
1502: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1503: $copytext = &mt('Copy to new page');
1504: $movetext = &mt('Move');
1.533 raeburn 1505: } else {
1.538 raeburn 1506: $copytext = &mt('Copy to new file');
1507: $movetext = &mt('Move');
1508: }
1509: my $output = '<br />'.
1510: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1511: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1512: '<label>'.
1513: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1514: $copytext.'</label></span>'.(' 'x2).' '.
1515: '<span class="LC_nobreak"><label>'.
1516: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1517: $movetext.'</label></span>';
1518: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1519: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1520: '</legend><table border="0">';
1521: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1522: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1523: my $lastdir = $parent;
1524: my %depths = (
1525: $lastdir => 0,
1526: );
1527: my (%display,%deps);
1528: for (my $i=0; $i<@pastemaps; $i++) {
1529: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1530: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1531: my @subfolders = split(/,/,$subfolderstr);
1532: $deps{$lastdir} = \@subfolders;
1533: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1534: my $depth = $depths{$lastdir} + 1;
1535: my $offset = int($depth * 4);
1536: my $indent = (' ' x $offset);
1537: for (my $j=0; $j<@subfolders; $j++) {
1538: $depths{$subfolders[$j]} = $depth;
1539: $display{$subfolders[$j]} =
1540: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1541: '<td><label>'.
1542: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1543: '<label>'.
1544: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1545: &mt('Move old').'</label>'.
1546: '</td></tr>';
1547: }
1.492 raeburn 1548: }
1.538 raeburn 1549: &recurse_print(\$output,$parent,\%deps,\%display);
1550: $output .= '</table></fieldset>';
1.329 droeschl 1551: }
1.538 raeburn 1552: $output .= '</div>';
1553: return $output;
1.488 raeburn 1554: }
1555:
1.492 raeburn 1556: sub recurse_print {
1.538 raeburn 1557: my ($outputref,$dir,$deps,$display) = @_;
1558: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1559: if (ref($deps->{$dir}) eq 'ARRAY') {
1560: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1561: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1562: }
1563: }
1564: }
1565:
1.488 raeburn 1566: sub supp_pasteable {
1567: my ($url) = @_;
1568: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1569: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1570: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1571: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1572: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1573: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1574: return 1;
1575: }
1576: return;
1.329 droeschl 1577: }
1578:
1.492 raeburn 1579: sub paste_popup_js {
1.594 damieng 1580: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1581: show => 'Show Options',
1582: hide => 'Hide Options',
1.594 damieng 1583: );
1584: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1585: none => 'No items selected from clipboard.',
1.492 raeburn 1586: );
1.594 damieng 1587: &html_escape(\%html_js_lt);
1588: &js_escape(\%html_js_lt);
1589: &js_escape(\%js_lt);
1.492 raeburn 1590: return <<"END";
1591:
1.538 raeburn 1592: function showPasteOptions(suffix) {
1593: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1594: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1595: return;
1596: }
1597:
1.538 raeburn 1598: function hidePasteOptions(suffix) {
1599: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1600: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1601: return;
1602: }
1603:
1604: function showOptions(caller,suffix) {
1605: if (document.getElementById('pasteoptionstext_'+suffix)) {
1606: if (caller.checked) {
1.594 damieng 1607: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1608: } else {
1609: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1610: }
1611: if (document.getElementById('pasteoptions_'+suffix)) {
1612: document.getElementById('pasteoptions_'+suffix).style.display='none';
1613: }
1614: }
1.492 raeburn 1615: return;
1616: }
1617:
1.541 raeburn 1618: function validateClipboard() {
1619: var numchk = 0;
1620: if (document.pasteform.pasting.length > 1) {
1621: for (var i=0; i<document.pasteform.pasting.length; i++) {
1622: if (document.pasteform.pasting[i].checked) {
1623: numchk ++;
1624: }
1625: }
1626: } else {
1627: if (document.pasteform.pasting.type == 'checkbox') {
1628: if (document.pasteform.pasting.checked) {
1629: numchk ++;
1630: }
1631: }
1632: }
1633: if (numchk > 0) {
1634: return true;
1635: } else {
1.594 damieng 1636: alert("$js_lt{'none'}");
1.541 raeburn 1637: return false;
1638: }
1639: }
1640:
1.575 raeburn 1641: function checkClipboard() {
1642: if (document.pasteform.pasting.length > 1) {
1643: for (var i=0; i<document.pasteform.pasting.length; i++) {
1644: document.pasteform.pasting[i].checked = true;
1645: }
1646: }
1647: return;
1648: }
1649:
1650: function uncheckClipboard() {
1651: if (document.pasteform.pasting.length >1) {
1652: for (var i=0; i<document.pasteform.pasting.length; i++) {
1653: document.pasteform.pasting[i].checked = false;
1654: }
1655: }
1656: return;
1657: }
1658:
1.492 raeburn 1659: END
1660:
1661: }
1662:
1.329 droeschl 1663: sub do_paste_from_buffer {
1.492 raeburn 1664: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1665:
1.538 raeburn 1666: # Array of items in paste buffer
1667: my (@currpaste,%pastebuffer,%allerrors);
1668: @currpaste = split(/,/,$env{'docs.markedcopies'});
1669:
1.492 raeburn 1670: # Early out if paste buffer is empty
1.538 raeburn 1671: if (@currpaste == 0) {
1.492 raeburn 1672: return ();
1.538 raeburn 1673: }
1674: map { $pastebuffer{$_} = 1; } @currpaste;
1675:
1676: # Array of items selected items to paste
1677: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1678:
1679: # Early out if nothing selected to paste
1680: if (@reqpaste == 0) {
1681: return();
1682: }
1683: my @topaste;
1684: foreach my $suffix (@reqpaste) {
1685: next if ($suffix =~ /\D/);
1686: next unless (exists($pastebuffer{$suffix}));
1687: push(@topaste,$suffix);
1688: }
1689:
1690: # Early out if nothing available to paste
1691: if (@topaste == 0) {
1692: return();
1.329 droeschl 1693: }
1694:
1.627 raeburn 1695: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1696: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1697:
1698: foreach my $suffix (@topaste) {
1699: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1700: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1701: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1702: # Supplemental content may only include certain types of content
1703: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1704: if ($folder =~ /^supplemental/) {
1705: unless (&supp_pasteable($url)) {
1706: $notinsupp{$suffix} = 1;
1707: next;
1708: }
1.492 raeburn 1709: }
1.538 raeburn 1710: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1711: my $srcd = $1;
1712: my $srcn = $2;
1.492 raeburn 1713: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1714: # check for mdc privilege in the course from which the resource was pasted
1715: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1716: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1717: $notincrs{$suffix} = 1;
1718: next;
1719: }
1.491 raeburn 1720: }
1.538 raeburn 1721: $srcdom{$suffix} = $srcd;
1722: $srcnum{$suffix} = $srcn;
1.597 raeburn 1723: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1724: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1725: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1726: my ($srcd,$srcn) = split(/_/,$cid);
1727: # When paste buffer was populated using an active role in a different course
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: }
1734: }
1.632 raeburn 1735: # When buffer was populated using an active role in a different course
1736: # disallow pasting of External Tool if course is in a different domain.
1737: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1738: $notindom{$suffix} = 1;
1739: next;
1740: }
1.596 raeburn 1741: $srcdom{$suffix} = $srcd;
1742: $srcnum{$suffix} = $srcn;
1.491 raeburn 1743: }
1.597 raeburn 1744: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1745: push(@dopaste,$suffix);
1746: if ($url=~/\.(page|sequence)$/) {
1747: $is_map{$suffix} = 1;
1748: }
1749: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1750: my $oldprefix = $1;
1.492 raeburn 1751: # When pasting content from Main Content to Supplemental Content and vice versa
1752: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1753: # a folder/page or a document).
1.538 raeburn 1754: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1755: $prefixchg{$suffix} = 'docstosupp';
1756: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1757: $prefixchg{$suffix} = 'supptodocs';
1758: }
1.491 raeburn 1759:
1.492 raeburn 1760: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1761: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1762: my @nested;
1763: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1764: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1765: my @deps = map { /\d+:([\d,]+$)/ } @items;
1766: foreach my $dep (@deps) {
1767: if ($dep =~ /,/) {
1768: push(@nested,split(/,/,$dep));
1769: } else {
1770: push(@nested,$dep);
1771: }
1.492 raeburn 1772: }
1.538 raeburn 1773: foreach my $item (@nested) {
1774: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1775: push(@{$marktomove{$suffix}},$type.'_'.$item);
1776: }
1.492 raeburn 1777: }
1778: }
1.488 raeburn 1779: }
1780: }
1781:
1.538 raeburn 1782: # Early out if nothing available to paste
1783: if (@dopaste == 0) {
1784: return ();
1785: }
1786:
1787: # Populate message hash and hashes used for main content <=> supplemental content
1788: # changes
1789:
1790: %msgs = &Apache::lonlocal::texthash (
1791: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1792: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.661 raeburn 1793: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1.538 raeburn 1794: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1795: );
1796:
1797: %before = (
1798: docstosupp => {
1799: map => 'default',
1800: doc => 'docs',
1801: },
1802: supptodocs => {
1803: map => 'supplemental',
1804: doc => 'supplemental',
1805: },
1806: );
1807:
1808: %after = (
1809: docstosupp => {
1810: map => 'supplemental',
1811: doc => 'supplemental'
1812: },
1813: supptodocs => {
1814: map => 'default',
1815: doc => 'docs',
1816: },
1817: );
1818:
1819: # Retrieve information about all course maps in main content area
1820:
1821: my $allmaps = {};
1.660 raeburn 1822: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.538 raeburn 1823:
1824: # Loop over the items to paste
1825: foreach my $suffix (@dopaste) {
1.329 droeschl 1826: # Maps need to be copied first
1.538 raeburn 1827: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1828: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1829: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1830: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1831: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1832: }
1833: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1834: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1835: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1836: my $oldurl = $url;
1837: if ($is_map{$suffix}) {
1.491 raeburn 1838: # If pasting a map, check if map contains other maps
1.538 raeburn 1839: my (%hierarchy,%titles);
1.660 raeburn 1840: if (($folder =~ /^default/) && (!$donechk)) {
1841: $allmaps =
1842: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1843: $env{"course.$env{'request.course.id'}.home"},
1844: $env{'request.course.id'});
1845: $donechk = 1;
1846: }
1.627 raeburn 1847: &contained_map_check($url,$folder,$coursenum,$coursedom,
1848: \%removefrommap,\%removeparam,\%addedmaps,
1849: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1850: if ($url=~ m{^/uploaded/}) {
1851: my $newurl;
1852: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1853: ($newurl,my $error) =
1854: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1855: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1856: \$title,$allmaps,\%newurls);
1857: if ($error) {
1858: $allerrors{$suffix} = $error;
1859: next;
1860: }
1861: if ($newurl ne '') {
1862: if ($newurl ne $url) {
1863: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1864: $newsubdir{$url} = $1;
1865: }
1866: $mapchanges{$url} = 1;
1.492 raeburn 1867: }
1.538 raeburn 1868: }
1869: }
1870: if (($srcdom{$suffix} ne $coursedom) ||
1871: ($srcnum{$suffix} ne $coursenum) ||
1872: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1873: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1874: $coursedom,$coursenum,$srcdom{$suffix},
1875: $srcnum{$suffix},$allmaps,\%rewrites,
1876: \%retitles,\%copies,\%dbcopies,
1877: \%zombies,\%params,\%mapmoves,
1878: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1879: \%newurls,\%resdatacopy)) {
1.538 raeburn 1880: $mapmoves{$url} = 1;
1881: }
1882: $url = $newurl;
1883: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1884: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1885: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1886: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1887: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1888: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1889: }
1890: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1891: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1892: push(@toclear,$suffix);
1893: # if pasting published map (main content area only) check map not already in course
1894: if ($folder =~ /^default/) {
1895: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1896: $duplicate{$suffix} = 1;
1897: next;
1.492 raeburn 1898: }
1.491 raeburn 1899: }
1900: }
1.538 raeburn 1901: }
1.627 raeburn 1902: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1903: my $prefix = $1;
1.648 raeburn 1904: my $fromothercrs;
1.538 raeburn 1905: #need to copy the db contents to a new one, unless this is a move.
1906: my %info = (
1907: src => $url,
1908: cdom => $coursedom,
1909: cnum => $coursenum,
1.596 raeburn 1910: );
1.649 raeburn 1911: if ($prefix eq 'ext.tool') {
1.655 raeburn 1912: if ($prefixchg{$suffix} eq 'docstosupp') {
1.649 raeburn 1913: $info{'delgradable'} = 1;
1914: }
1915: }
1.596 raeburn 1916: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1917: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1918: $fromothercrs = 1;
1919: $info{'cdom'} = $srcdom{$suffix};
1920: $info{'cnum'} = $srcnum{$suffix};
1921: }
1922: }
1923: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 1924: my (%lockerr,$msg);
1.538 raeburn 1925: my ($newurl,$result,$errtext) =
1926: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1927: if ($result eq 'ok') {
1928: $url = $newurl;
1929: $title=&mt('Copy of').' '.$title;
1930: } else {
1931: if ($prefix eq 'smppg') {
1932: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1933: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1934: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 1935: } elsif ($prefix eq 'ext.tool') {
1936: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 1937: }
1938: $results{$suffix} = $result;
1939: $msgerrs{$suffix} = $msg;
1940: $lockerrs{$suffix} = $lockerr{$prefix};
1941: next;
1942: }
1943: if ($lockerr{$prefix}) {
1944: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1945: }
1.489 raeburn 1946: }
1947: }
1.538 raeburn 1948: $title = &LONCAPA::map::qtunescape($title);
1949: my $ext='false';
1950: if ($url=~m{^http(|s)://}) { $ext='true'; }
1951: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1952: if ($folder !~ /^supplemental/) {
1953: (undef,undef,$title) =
1954: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1955: }
1956: } else {
1957: if ($folder=~/^supplemental/) {
1958: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1959: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1960: }
1.533 raeburn 1961: }
1.491 raeburn 1962:
1963: # For uploaded files (excluding pages/sequences) path in copied file is changed
1964: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1965: # courses.
1966:
1.538 raeburn 1967: unless ($is_map{$suffix}) {
1968: my $newidx;
1.492 raeburn 1969: # Now insert the URL at the bottom
1.538 raeburn 1970: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1971: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1972: my $relpath = $1;
1973: if ($relpath ne '') {
1974: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1975: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1976: my $newprefix = $newloc;
1977: if ($newloc eq 'default') {
1978: $newprefix = 'docs';
1979: }
1980: if ($newdocsdir eq '') {
1981: $newdocsdir = 'default';
1982: }
1.630 raeburn 1983: if (($prefixchg{$suffix}) ||
1984: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 1985: ($srcnum{$suffix} ne $coursenum) ||
1986: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1987: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1988: $url =
1989: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1990: &Apache::lonnet::getfile($oldurl));
1991: if ($url eq '/adm/notfound.html') {
1992: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1993: next;
1994: } else {
1995: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1996: $newsubpath =~ s{/+$}{/};
1997: $docmoves{$oldurl} = $newsubpath;
1998: }
1.491 raeburn 1999: }
2000: }
1.597 raeburn 2001: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2002: my $template = $1;
2003: if ($newidx) {
2004: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2005: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2006: }
1.649 raeburn 2007: } elsif ($url =~ /ext\.tool$/) {
1.655 raeburn 2008: if (($newidx) && ($folder=~/^default/)) {
1.649 raeburn 2009: my $marker = (split(m{/},$url))[4];
2010: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2011: my $val = 'no';
2012: if ($toolsettings{'gradable'}) {
2013: $val = 'yes';
2014: }
2015: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2016: 'string_yesno');
2017: &remember_parms($newidx,'gradable','set',$val);
2018: }
1.491 raeburn 2019: }
1.538 raeburn 2020: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2021: ':'.$ext.':normal:res';
2022: push(@LONCAPA::map::order,$newidx);
2023: # Store the result
2024: my ($errtext,$fatal) =
2025: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2026: if ($fatal) {
2027: $save_err .= $errtext;
2028: $allresult = 'fail';
2029: }
1.488 raeburn 2030: }
1.538 raeburn 2031:
1.597 raeburn 2032: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2033: # resourcedata for simpleproblems copied from another course
1.538 raeburn 2034: unless ($allresult eq 'fail') {
2035: my %updated = (
2036: rewrites => \%rewrites,
2037: zombies => \%zombies,
2038: removefrommap => \%removefrommap,
2039: removeparam => \%removeparam,
2040: dbcopies => \%dbcopies,
1.597 raeburn 2041: resdatacopy => \%resdatacopy,
1.538 raeburn 2042: retitles => \%retitles,
2043: );
2044: my %info = (
2045: newsubdir => \%newsubdir,
2046: params => \%params,
2047: );
2048: if ($prefixchg{$suffix}) {
2049: $info{'before'} = $before{$prefixchg{$suffix}};
2050: $info{'after'} = $after{$prefixchg{$suffix}};
2051: }
2052: my %moves = (
2053: copies => \%copies,
2054: docmoves => \%docmoves,
2055: mapmoves => \%mapmoves,
2056: );
2057: (my $result,$msgs{$suffix},my $lockerror) =
2058: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2059: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2060: $url,'paste');
2061: $lockerrors .= $lockerror;
2062: if ($result eq 'ok') {
2063: if ($is_map{$suffix}) {
2064: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2065: $folder.'.'.$container);
2066: if ($fatal) {
2067: $allresult = 'failread';
2068: } else {
2069: if ($#LONCAPA::map::order<1) {
2070: my $idx=&LONCAPA::map::getresidx();
2071: if ($idx<=0) { $idx=1; }
2072: $LONCAPA::map::order[0]=$idx;
2073: $LONCAPA::map::resources[$idx]='';
2074: }
2075: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2076: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2077: ':'.$ext.':normal:res';
2078: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2079:
2080: # Store the result
1.538 raeburn 2081: my ($errtext,$fatal) =
2082: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2083: if ($fatal) {
2084: $save_err .= $errtext;
2085: $allresult = 'failstore';
2086: }
2087: }
2088: }
2089: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2090: push(@toclear,$suffix);
2091: }
2092: }
1.492 raeburn 2093: }
2094: }
1.538 raeburn 2095: &clear_from_buffer(\@toclear,\@currpaste);
2096: my $msgsarray;
2097: foreach my $suffix (keys(%msgs)) {
2098: if (ref($msgs{$suffix}) eq 'ARRAY') {
2099: $msgsarray .= join(',',@{$msgs{$suffix}});
2100: }
2101: }
2102: return ($allresult,$save_err,$msgsarray,$lockerrors);
2103: }
1.533 raeburn 2104:
1.538 raeburn 2105: sub do_buffer_empty {
2106: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2107: if (@currpaste == 0) {
2108: return &mt('Clipboard is already empty');
2109: }
2110: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2111: if (@toclear == 0) {
2112: return &mt('Nothing selected to clear from clipboard');
2113: }
2114: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2115: if ($numdel) {
2116: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2117: } else {
2118: return &mt('Clipboard unchanged');
1.492 raeburn 2119: }
1.538 raeburn 2120: return;
2121: }
2122:
2123: sub clear_from_buffer {
2124: my ($toclear,$currpaste) = @_;
2125: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2126: my %pastebuffer;
2127: map { $pastebuffer{$_} = 1; } @{$currpaste};
2128: my $numdel = 0;
2129: foreach my $suffix (@{$toclear}) {
2130: next if ($suffix =~ /\D/);
2131: next unless (exists($pastebuffer{$suffix}));
2132: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2133: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2134: delete($pastebuffer{$suffix});
2135: $numdel ++;
2136: }
2137: }
2138: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2139: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2140: return $numdel;
1.492 raeburn 2141: }
2142:
2143: sub get_newmap_url {
2144: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2145: $titleref,$allmaps,$newurls) = @_;
2146: my $newurl;
2147: if ($url=~ m{^/uploaded/}) {
2148: $$titleref=&mt('Copy of').' '.$$titleref;
2149: }
2150: my $now = time;
2151: my $suffix=$$.int(rand(100)).$now;
2152: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2153: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2154: my $path = $1;
2155: my $prefix = $2;
2156: my $ancestor = $3;
2157: if (length($ancestor) > 10) {
2158: $ancestor = substr($ancestor,-10,10);
2159: }
2160: my $newid;
2161: if ($prefixchg) {
2162: if ($folder =~ /^supplemental/) {
2163: $prefix =~ s/^default/supplemental/;
2164: } else {
2165: $prefix =~ s/^supplemental/default/;
2166: }
2167: }
2168: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2169: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2170: } else {
2171: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2172: }
2173: my $counter = 0;
2174: my $is_unique = &uniqueness_check($newurl);
2175: if ($folder =~ /^default/) {
2176: if ($allmaps->{$newurl}) {
2177: $is_unique = 0;
2178: }
2179: }
2180: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2181: $counter ++;
2182: $suffix ++;
2183: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2184: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2185: } else {
2186: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2187: }
2188: $is_unique = &uniqueness_check($newurl);
2189: }
2190: if ($is_unique) {
2191: $newurls->{$newurl} = 1;
2192: } else {
2193: if ($url=~/\.page$/) {
2194: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2195: } else {
2196: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2197: }
2198: }
1.329 droeschl 2199: }
1.492 raeburn 2200: return ($newurl);
1.329 droeschl 2201: }
2202:
1.488 raeburn 2203: sub dbcopy {
1.533 raeburn 2204: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2205: my ($url,$result,$errtext);
2206: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2207: $url = $dbref->{'src'};
1.627 raeburn 2208: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2209: my $prefix = $1;
1.627 raeburn 2210: if ($prefix eq 'ext.tool') {
2211: $prefix = 'exttool';
2212: }
1.533 raeburn 2213: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2214: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2215: my $db_name;
2216: my $marker = (split(m{/},$url))[4];
2217: $marker=~s/\D//g;
2218: if ($dbref->{'src'} =~ m{/smppg$}) {
2219: $db_name =
2220: &Apache::lonsimplepage::get_db_name($url,$marker,
2221: $dbref->{'cdom'},
2222: $dbref->{'cnum'});
1.627 raeburn 2223: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2224: $db_name = 'exttool_'.$marker;
1.533 raeburn 2225: } else {
2226: $db_name = 'bulletinpage_'.$marker;
2227: }
2228: my ($suffix,$freedlock,$error) =
2229: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2230: $coursedom,$coursenum,
2231: 'concat');
2232: if (!$suffix) {
2233: if ($prefix eq 'smppg') {
2234: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2235: } elsif ($prefix eq 'exttool') {
2236: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2237: } else {
1.565 bisitz 2238: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2239: }
2240: if ($error) {
2241: $errtext .= '<br />'.$error;
2242: }
2243: } else {
2244: #need to copy the db contents to a new one.
2245: my %contents=&Apache::lonnet::dump($db_name,
2246: $dbref->{'cdom'},
2247: $dbref->{'cnum'});
2248: if (exists($contents{'uploaded.photourl'})) {
2249: my $photo = $contents{'uploaded.photourl'};
2250: my ($subdir,$fname) =
2251: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2252: my $newphoto;
1.533 raeburn 2253: if ($fname ne '') {
2254: my $content = &Apache::lonnet::getfile($photo);
2255: unless ($content eq '-1') {
2256: $env{'form.'.$suffix.'.photourl'} = $content;
2257: $newphoto =
2258: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2259: delete($env{'form.'.$suffix.'.photourl'});
2260: }
2261: }
2262: if ($newphoto =~ m{^/uploaded/}) {
2263: $contents{'uploaded.photourl'} = $newphoto;
2264: }
2265: }
2266: $db_name =~ s{_\d*$ }{_$suffix}x;
1.649 raeburn 2267: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2268: delete($contents{'gradable'});
2269: }
1.533 raeburn 2270: $result=&Apache::lonnet::put($db_name,\%contents,
2271: $coursedom,$coursenum);
2272: if ($result eq 'ok') {
1.627 raeburn 2273: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2274: }
2275: }
2276: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2277: $lockerrorsref->{$prefix} =
1.533 raeburn 2278: '<div class="LC_error">'.
2279: &mt('There was a problem removing a lockfile.');
2280: if ($prefix eq 'smppg') {
1.560 raeburn 2281: $lockerrorsref->{$prefix} .=
1.559 raeburn 2282: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2283: } elsif ($prefix eq 'exttool') {
2284: $lockerrorsref->{$prefix} .=
2285: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2286: } else {
1.565 bisitz 2287: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2288: }
1.560 raeburn 2289: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2290: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2291: '</div>';
1.533 raeburn 2292: }
2293: }
2294: } elsif ($url =~ m{/syllabus$}) {
2295: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2296: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2297: if (($dbref->{'cdom'} ne $coursedom) ||
2298: ($dbref->{'cnum'} ne $coursenum)) {
2299: my %contents=&Apache::lonnet::dump('syllabus',
2300: $dbref->{'cdom'},
2301: $dbref->{'cnum'});
2302: $result=&Apache::lonnet::put('syllabus',\%contents,
2303: $coursedom,$coursenum);
2304: }
2305: }
1.488 raeburn 2306: }
2307: }
1.533 raeburn 2308: return ($url,$result,$errtext);
1.488 raeburn 2309: }
2310:
1.597 raeburn 2311: sub copy_templated_files {
2312: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2313: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2314: my $srccontainer = 'sequence';
2315: if ($srcwaspage) {
2316: $srccontainer = 'page';
2317: }
2318: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2319: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2320: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2321: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2322: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2323: $template.'.problem';
2324: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2325: if ($template eq 'simpleproblem') {
2326: $srcprefix .= '.0.';
2327: my $weightprefix = $newprefix;
2328: $newprefix .= '.0.';
2329: my @simpleprobqtypes = qw(radio option string essay numerical);
2330: my $qtype=$srcparms{$srcprefix.'questiontype'};
2331: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2332: my %newdata;
2333: foreach my $type (@simpleprobqtypes) {
2334: if ($type eq $qtype) {
2335: $newdata{"$weightprefix.$type.weight"}=1;
2336: } else {
2337: $newdata{"$weightprefix.$type.weight"}=0;
2338: }
2339: }
2340: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2341: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2342: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2343: if ($qtype eq 'numerical') {
2344: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2345: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2346: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2347: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2348: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2349: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2350: unless (defined($maxfoils)) { $maxfoils=10; }
2351: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2352: if ($maxfoils<=0) { $maxfoils=10; }
2353: my $randomize=$srcparms{$srcprefix.'randomize'};
2354: unless (defined($randomize)) { $randomize='yes'; }
2355: unless ($randomize eq 'no') { $randomize='yes'; }
2356: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2357: $newdata{$newprefix.'randomize'} = $randomize;
2358: if ($qtype eq 'option') {
2359: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2360: }
2361: for (my $i=1; $i<=10; $i++) {
2362: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2363: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2364: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2365: }
2366:
2367: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2368: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2369: unless (defined($maxfoils)) { $maxfoils=10; }
2370: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2371: if ($maxfoils<=0) { $maxfoils=10; }
2372: my $randomize=$srcparms{$srcprefix.'randomize'};
2373: unless (defined($randomize)) { $randomize='yes'; }
2374: unless ($randomize eq 'no') { $randomize='yes'; }
2375: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2376: $newdata{$newprefix.'randomize'} = $randomize;
2377: if ($qtype eq 'option') {
2378: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2379: }
2380: for (my $i=1; $i<=10; $i++) {
2381: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2382: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2383: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2384: }
2385: } elsif ($qtype eq 'string') {
2386: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2387: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2388: }
2389: if (keys(%newdata)) {
2390: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2391: $coursenum);
2392: if ($putres eq 'ok') {
2393: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2394: }
2395: }
2396: }
2397: }
2398: }
2399:
1.329 droeschl 2400: sub uniqueness_check {
2401: my ($newurl) = @_;
2402: my $unique = 1;
2403: foreach my $res (@LONCAPA::map::order) {
2404: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2405: $url=&LONCAPA::map::qtescape($url);
2406: if ($newurl eq $url) {
2407: $unique = 0;
1.344 bisitz 2408: last;
1.329 droeschl 2409: }
2410: }
2411: return $unique;
2412: }
2413:
1.488 raeburn 2414: sub contained_map_check {
1.627 raeburn 2415: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2416: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2417: my $content = &Apache::lonnet::getfile($url);
2418: unless ($content eq '-1') {
2419: my $parser = HTML::TokeParser->new(\$content);
2420: $parser->attr_encoded(1);
2421: while (my $token = $parser->get_token) {
2422: next if ($token->[0] ne 'S');
2423: if ($token->[1] eq 'resource') {
2424: next if ($token->[2]->{'type'} eq 'zombie');
2425: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2426: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2427: my $srcdom = $1;
2428: unless ($srcdom eq $coursedom) {
2429: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2430: next;
2431: }
2432: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2433: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2434: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2435: next;
2436: }
2437: }
1.492 raeburn 2438: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2439: if ($1 eq 'uploaded') {
2440: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2441: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2442: } else {
1.492 raeburn 2443: if ($allmaps->{$ressrc}) {
1.529 raeburn 2444: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2445: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2446: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2447: } else {
2448: $addedmaps->{$ressrc} = [$url];
2449: }
1.488 raeburn 2450: }
1.627 raeburn 2451: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2452: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2453: }
1.492 raeburn 2454: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2455: if ($folder =~ /^supplemental/) {
1.492 raeburn 2456: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2457: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2458: } else {
2459: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2460: }
1.488 raeburn 2461: }
2462: }
2463: }
2464: }
2465: return;
2466: }
2467:
2468: sub url_paste_fixups {
1.533 raeburn 2469: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2470: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2471: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2472: my $checktitle;
2473: if (($prefixchg) &&
1.492 raeburn 2474: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2475: $checktitle = 1;
2476: }
1.492 raeburn 2477: my $skip;
2478: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2479: my $mapid = $1.$2;
2480: if ($tomove->{$mapid}) {
2481: $skip = 1;
2482: }
2483: }
1.491 raeburn 2484: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2485: return if ($file eq '-1');
2486: my $parser = HTML::TokeParser->new(\$file);
2487: $parser->attr_encoded(1);
1.491 raeburn 2488: my $changed = 0;
1.488 raeburn 2489: while (my $token = $parser->get_token) {
2490: next if ($token->[0] ne 'S');
2491: if ($token->[1] eq 'resource') {
2492: my $ressrc = $token->[2]->{'src'};
2493: next if ($ressrc eq '');
1.491 raeburn 2494: my $id = $token->[2]->{'id'};
1.492 raeburn 2495: my $title = $token->[2]->{'title'};
1.491 raeburn 2496: if ($checktitle) {
2497: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2498: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2499: }
2500: }
1.488 raeburn 2501: next if ($token->[2]->{'type'} eq 'external');
2502: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2503: next if ($skip);
1.532 raeburn 2504: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2505: $changed = 1;
2506: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2507: my $srcdom = $1;
2508: my $srcnum = $2;
1.488 raeburn 2509: my $rem = $3;
1.492 raeburn 2510: my $newurl;
2511: my $mapname;
2512: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2513: my $prefix = $1;
2514: $mapname = $prefix.$2;
2515: if ($tomove->{$mapname}) {
1.533 raeburn 2516: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2517: $srcdom,$srcnum,$allmaps,$rewrites,
2518: $retitles,$copies,$dbcopies,$zombies,
2519: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2520: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2521: next;
2522: } else {
2523: ($newurl,my $error) =
2524: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2525: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2526: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2527: $newsubdir->{$ressrc} = $1;
2528: }
2529: if ($error) {
2530: next;
2531: }
2532: }
2533: }
2534: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2535: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2536:
1.488 raeburn 2537: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2538: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2539: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2540: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2541: $cnum,$srcdom,$srcnum,$allmaps,
2542: $rewrites,$retitles,$copies,$dbcopies,
2543: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2544: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2545: $mapmoves->{$ressrc} = 1;
2546: }
2547: $changed = 1;
1.488 raeburn 2548: } else {
1.532 raeburn 2549: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2550: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2551: $changed = 1;
1.488 raeburn 2552: }
2553: }
1.649 raeburn 2554: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.533 raeburn 2555: next if ($skip);
1.492 raeburn 2556: my $srcdom = $1;
2557: my $srcnum = $2;
1.649 raeburn 2558: my $rem = $3;
2559: my ($is_exttool,$exttoolchg);
2560: if ($rem =~ m{\d+/ext\.tool$}) {
1.655 raeburn 2561: $is_exttool = 1;
1.649 raeburn 2562: }
1.492 raeburn 2563: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2564: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2565: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2566: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2567: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2568: $changed = 1;
1.649 raeburn 2569: if ($is_exttool) {
2570: $exttoolchg = 1;
2571: }
2572: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2573: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2574: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2575: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2576: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2577: $changed = 1;
2578: $exttoolchg = 1;
2579: }
2580: if (($is_exttool) && ($prefixchg)) {
2581: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2582: if ($exttoolchg) {
2583: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2584: }
2585: }
1.533 raeburn 2586: }
2587: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2588: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2589: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2590: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2591: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2592: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2593: $changed = 1;
1.488 raeburn 2594: }
1.597 raeburn 2595: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2596: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2597: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2598: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2599: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2600: }
1.488 raeburn 2601: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2602: next if ($skip);
2603: my $srcdom = $1;
2604: my $srcnum = $2;
2605: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2606: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2607: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2608: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2609: $changed = 1;
1.488 raeburn 2610: }
2611: }
2612: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2613: next if ($skip);
1.488 raeburn 2614: my $to = $token->[2]->{'to'};
2615: if ($to ne '') {
2616: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2617: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2618: } else {
2619: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2620: }
2621: }
2622: }
2623: }
1.491 raeburn 2624: return $changed;
1.488 raeburn 2625: }
2626:
2627: sub apply_fixups {
1.529 raeburn 2628: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2629: $oldurl,$url,$caller) = @_;
2630: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2631: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2632: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2633: if (ref($updated) eq 'HASH') {
2634: if (ref($updated->{'rewrites'}) eq 'HASH') {
2635: %rewrites = %{$updated->{'rewrites'}};
2636: }
2637: if (ref($updated->{'zombies'}) eq 'HASH') {
2638: %zombies = %{$updated->{'zombies'}};
2639: }
2640: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2641: %removefrommap = %{$updated->{'removefrommap'}};
2642: }
2643: if (ref($updated->{'removeparam'}) eq 'HASH') {
2644: %removeparam = %{$updated->{'removeparam'}};
2645: }
2646: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2647: %dbcopies = %{$updated->{'dbcopies'}};
2648: }
2649: if (ref($updated->{'retitles'}) eq 'HASH') {
2650: %retitles = %{$updated->{'retitles'}};
2651: }
1.597 raeburn 2652: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2653: %resdatacopy = %{$updated->{'resdatacopy'}};
2654: }
1.529 raeburn 2655: }
2656: if (ref($info) eq 'HASH') {
2657: if (ref($info->{'newsubdir'}) eq 'HASH') {
2658: %newsubdir = %{$info->{'newsubdir'}};
2659: }
2660: if (ref($info->{'params'}) eq 'HASH') {
2661: %params = %{$info->{'params'}};
2662: }
2663: if (ref($info->{'before'}) eq 'HASH') {
2664: %before = %{$info->{'before'}};
2665: }
2666: if (ref($info->{'after'}) eq 'HASH') {
2667: %after = %{$info->{'after'}};
2668: }
2669: }
2670: if (ref($moves) eq 'HASH') {
2671: if (ref($moves->{'copies'}) eq 'HASH') {
2672: %copies = %{$moves->{'copies'}};
2673: }
2674: if (ref($moves->{'docmoves'}) eq 'HASH') {
2675: %docmoves = %{$moves->{'docmoves'}};
2676: }
2677: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2678: %mapmoves = %{$moves->{'mapmoves'}};
2679: }
2680: }
2681: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2682: my @allcopies;
1.529 raeburn 2683: if (exists($copies{$key})) {
2684: if (ref($copies{$key}) eq 'HASH') {
2685: my %added;
2686: foreach my $innerkey (keys(%{$copies{$key}})) {
2687: if (($innerkey ne '') && (!$added{$innerkey})) {
2688: push(@allcopies,$innerkey);
2689: $added{$innerkey} = 1;
2690: }
1.491 raeburn 2691: }
1.529 raeburn 2692: undef(%added);
1.491 raeburn 2693: }
2694: }
2695: if ($key eq $oldurl) {
1.529 raeburn 2696: if ((exists($docmoves{$key}))) {
1.532 raeburn 2697: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2698: push(@allcopies,$oldurl);
2699: }
2700: }
2701: }
2702: if (@allcopies > 0) {
2703: foreach my $item (@allcopies) {
1.492 raeburn 2704: my ($relpath,$oldsubdir,$fname) =
2705: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2706: if ($fname ne '') {
2707: my $content = &Apache::lonnet::getfile($item);
2708: unless ($content eq '-1') {
2709: my $storefn;
1.529 raeburn 2710: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2711: $storefn = $docmoves{$key};
1.491 raeburn 2712: } else {
2713: $storefn = $relpath;
2714: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2715: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2716: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2717: }
1.529 raeburn 2718: if ($newsubdir{$key}) {
1.532 raeburn 2719: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2720: }
2721: }
2722: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2723: my $copyurl =
2724: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2725: $storefn.$fname,$content);
2726: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2727: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2728: return &mt('Paste failed: an error occurred copying the file.');
2729: } elsif (ref($errors) eq 'HASH') {
2730: $errors->{$item} = 1;
1.489 raeburn 2731: }
2732: }
1.488 raeburn 2733: }
2734: }
1.491 raeburn 2735: }
2736: }
2737: }
1.529 raeburn 2738: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2739: my $storefn=$key;
2740: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2741: if ($prefixchg && $before{'map'} && $after{'map'}) {
2742: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2743: }
1.529 raeburn 2744: if ($newsubdir{$key}) {
2745: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2746: }
1.491 raeburn 2747: my $mapcontent = &Apache::lonnet::getfile($key);
2748: if ($mapcontent eq '-1') {
2749: if (ref($errors) eq 'HASH') {
2750: $errors->{$key} = 1;
2751: }
2752: } else {
2753: my $newmap =
2754: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2755: $mapcontent);
2756: if ($newmap eq '/adm/notfound.html') {
2757: if (ref($errors) eq 'HASH') {
2758: $errors->{$key} = 1;
1.489 raeburn 2759: }
1.488 raeburn 2760: }
2761: }
2762: }
1.491 raeburn 2763: my %updates;
2764: if ($is_map) {
1.529 raeburn 2765: if (ref($updated) eq 'HASH') {
2766: foreach my $type (keys(%{$updated})) {
2767: if (ref($updated->{$type}) eq 'HASH') {
2768: foreach my $key (keys(%{$updated->{$type}})) {
2769: $updates{$key} = 1;
2770: }
2771: }
2772: }
1.491 raeburn 2773: }
2774: foreach my $key (keys(%updates)) {
1.492 raeburn 2775: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2776: if (ref($rewrites{$key}) eq 'HASH') {
2777: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2778: }
1.529 raeburn 2779: if (ref($retitles{$key}) eq 'HASH') {
2780: %toretitle = %{$retitles{$key}};
1.491 raeburn 2781: }
1.529 raeburn 2782: if (ref($removefrommap{$key}) eq 'HASH') {
2783: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2784: }
1.529 raeburn 2785: if (ref($removeparam{$key}) eq 'HASH') {
2786: %remparam = %{$removeparam{$key}};
1.492 raeburn 2787: }
1.529 raeburn 2788: if (ref($zombies{$key}) eq 'HASH') {
2789: %zombie = %{$zombies{$key}};
1.491 raeburn 2790: }
1.529 raeburn 2791: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2792: foreach my $idx (keys(%{$dbcopies{$key}})) {
2793: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2794: my ($newurl,$result,$errtext) =
2795: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2796: if ($result eq 'ok') {
2797: $newdb{$idx} = $newurl;
2798: } elsif (ref($errors) eq 'HASH') {
2799: $errors->{$key} = 1;
2800: }
2801: push(@msgs,$errtext);
2802: }
1.491 raeburn 2803: }
2804: }
1.597 raeburn 2805: if (ref($resdatacopy{$key}) eq 'HASH') {
1.664 ! raeburn 2806: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
1.597 raeburn 2807: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2808: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2809: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2810: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2811: my $template = $1;
2812: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2813: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2814: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2815: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
1.664 ! raeburn 2816: unless ($gotnewmapname) {
! 2817: ($newmapname) = ($key =~ m{/([^/]+)$});
! 2818: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
! 2819: if ($newsubdir{$key}) {
! 2820: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
! 2821: }
! 2822: $gotnewmapname = 1;
! 2823: }
1.597 raeburn 2824: my $srcmapinfo = $srcfolder.':'.$idx;
2825: if ($srccontainer eq 'page') {
2826: $srcmapinfo .= ':1';
2827: }
2828: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2829: $cnum,$template,$idx,$newmapname);
2830: }
2831: }
2832: }
2833: }
2834: }
1.529 raeburn 2835: if (ref($params{$key}) eq 'HASH') {
2836: %currparam = %{$params{$key}};
1.492 raeburn 2837: }
2838: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2839: if ($fatal) {
1.533 raeburn 2840: return ($errtext);
1.492 raeburn 2841: }
2842: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2843: if (defined($LONCAPA::map::zombies[$i])) {
2844: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2845: if ($zombie{$i} eq $src) {
1.492 raeburn 2846: undef($LONCAPA::map::zombies[$i]);
2847: }
2848: }
2849: }
1.646 raeburn 2850: my $total = scalar(@LONCAPA::map::order) - 1;
2851: for (my $i=$total; $i>=0; $i--) {
1.529 raeburn 2852: my $idx = $LONCAPA::map::order[$i];
2853: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2854: my $changed;
1.529 raeburn 2855: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2856: if ((exists($toremove{$idx})) &&
2857: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2858: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2859: if (ref($currparam{$idx}) eq 'ARRAY') {
2860: foreach my $name (@{$currparam{$idx}}) {
1.647 raeburn 2861: &LONCAPA::map::delparameter($idx,$name);
1.492 raeburn 2862: }
2863: }
2864: next;
2865: }
2866: my $origsrc = $src;
1.532 raeburn 2867: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2868: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2869: $changed = 1;
1.491 raeburn 2870: }
1.492 raeburn 2871: }
1.532 raeburn 2872: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2873: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2874: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2875: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2876: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2877: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2878: } else {
1.529 raeburn 2879: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2880: }
1.491 raeburn 2881: }
1.532 raeburn 2882: if ($origsrc =~ /\.(page|sequence)$/) {
2883: if ($newsubdir{$origsrc}) {
1.529 raeburn 2884: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2885: }
1.532 raeburn 2886: } elsif ($newsubdir{$key}) {
2887: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2888: }
2889: }
1.492 raeburn 2890: $changed = 1;
1.533 raeburn 2891: } elsif ($newdb{$idx} ne '') {
2892: $src = $newdb{$idx};
1.492 raeburn 2893: $changed = 1;
2894: }
2895: if ($changed) {
1.538 raeburn 2896: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2897: }
2898: }
2899: }
2900: foreach my $idx (keys(%remparam)) {
2901: if (ref($remparam{$idx}) eq 'ARRAY') {
2902: foreach my $name (@{$remparam{$idx}}) {
1.647 raeburn 2903: &LONCAPA::map::delparameter($idx,$name);
1.491 raeburn 2904: }
2905: }
2906: }
1.533 raeburn 2907: if (values(%lockerrors) > 0) {
2908: $lockmsg = join('<br />',values(%lockerrors));
2909: }
1.491 raeburn 2910: my $storefn;
2911: if ($key eq $oldurl) {
2912: $storefn = $url;
2913: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2914: } else {
2915: $storefn = $key;
2916: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2917: if ($prefixchg && $before{'map'} && $after{'map'}) {
2918: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2919: }
1.529 raeburn 2920: if ($newsubdir{$key}) {
2921: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2922: }
1.491 raeburn 2923: }
1.492 raeburn 2924: my $report;
2925: if ($folder !~ /^supplemental/) {
2926: $report = 1;
2927: }
1.527 raeburn 2928: (my $outtext,$errtext) =
1.492 raeburn 2929: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2930: if ($errtext) {
1.529 raeburn 2931: if ($caller eq 'paste') {
1.533 raeburn 2932: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2933: }
1.491 raeburn 2934: }
2935: }
2936: }
1.533 raeburn 2937: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2938: }
2939:
2940: sub copy_dependencies {
2941: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2942: my $content;
2943: if (ref($contentref)) {
2944: $content = $$contentref;
2945: } else {
2946: $content = &Apache::lonnet::getfile($item);
2947: }
2948: unless ($content eq '-1') {
2949: my $mm = new File::MMagic;
2950: my $mimetype = $mm->checktype_contents($content);
2951: if ($mimetype eq 'text/html') {
2952: my (%allfiles,%codebase,$state);
2953: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2954: if ($res eq 'ok') {
2955: my ($numexisting,$numpathchanges,$existing);
2956: (undef,$numexisting,$numpathchanges,$existing) =
2957: &Apache::loncommon::ask_for_embedded_content(
2958: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2959: {'error_on_invalid_names' => 1,
2960: 'ignore_remote_references' => 1,
2961: 'docs_url' => $item,
2962: 'context' => 'paste'});
2963: if ($numexisting > 0) {
2964: if (ref($existing) eq 'HASH') {
2965: foreach my $dep (keys(%{$existing})) {
2966: my $depfile = $dep;
2967: unless ($depfile =~ m{^\Q$relpath\E}) {
2968: $depfile = $relpath.$dep;
2969: }
2970: my $depcontent = &Apache::lonnet::getfile($depfile);
2971: unless ($depcontent eq '-1') {
2972: my $storedep = $dep;
2973: $storedep =~ s{^\Q$relpath\E}{};
2974: my $dep_url =
2975: &Apache::lonclonecourse::writefile(
2976: $env{'request.course.id'},
2977: $storefn.$storedep,$depcontent);
2978: if ($dep_url eq '/adm/notfound.html') {
2979: if (ref($errors) eq 'HASH') {
2980: $errors->{$depfile} = 1;
2981: }
2982: } else {
2983: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2984: }
2985: }
2986: }
1.488 raeburn 2987: }
2988: }
2989: }
2990: }
2991: }
2992: return;
2993: }
2994:
1.329 droeschl 2995: my %parameter_type = ( 'randompick' => 'int_pos',
2996: 'hiddenresource' => 'string_yesno',
2997: 'encrypturl' => 'string_yesno',
2998: 'randomorder' => 'string_yesno',);
2999: my $valid_parameters_re = join('|',keys(%parameter_type));
3000: # set parameters
3001: sub update_parameter {
1.537 raeburn 3002: if ($env{'form.changeparms'} eq 'all') {
3003: my (@allidx,@allmapidx,%allchecked,%currchecked);
3004: %allchecked = (
3005: 'hiddenresource' => {},
3006: 'encrypturl' => {},
3007: 'randompick' => {},
3008: 'randomorder' => {},
3009: );
3010: foreach my $which (keys(%allchecked)) {
1.630 raeburn 3011: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 3012: if ($which eq 'randompick') {
3013: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3014: my ($res,$value) = split(/:/,$item);
3015: if ($value =~ /^\d+$/) {
3016: $allchecked{$which}{$res} = $value;
3017: }
3018: }
3019: } else {
1.539 raeburn 3020: if ($env{'form.all'.$which}) {
3021: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3022: }
1.537 raeburn 3023: }
3024: }
3025: my $haschanges = 0;
3026: foreach my $res (@LONCAPA::map::order) {
3027: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3028: $name=&LONCAPA::map::qtescape($name);
3029: $url=&LONCAPA::map::qtescape($url);
3030: next unless ($name && $url);
3031: my $is_map;
3032: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3033: $is_map = 1;
3034: }
3035: foreach my $which (keys(%allchecked)) {
3036: if (($which eq 'randompick' || $which eq 'randomorder')) {
3037: next if (!$is_map);
3038: }
3039: my $oldvalue = 0;
3040: my $newvalue = 0;
3041: if ($allchecked{$which}{$res}) {
3042: $newvalue = $allchecked{$which}{$res};
3043: }
3044: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3045: if ($which eq 'randompick') {
3046: if ($current =~ /^(\d+)$/) {
3047: $oldvalue = $1;
3048: }
3049: } else {
3050: if ($current =~ /^yes$/i) {
3051: $oldvalue = 1;
3052: }
3053: }
3054: if ($oldvalue ne $newvalue) {
3055: $haschanges = 1;
3056: if ($newvalue) {
3057: my $storeval = 'yes';
3058: if ($which eq 'randompick') {
3059: $storeval = $newvalue;
3060: }
3061: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3062: $storeval,
3063: $parameter_type{$which});
3064: &remember_parms($res,$which,'set',$storeval);
3065: } elsif ($oldvalue) {
3066: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3067: &remember_parms($res,$which,'del');
3068: }
3069: }
3070: }
3071: }
3072: return $haschanges;
3073: } else {
1.588 raeburn 3074: my $haschanges = 0;
3075: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 3076:
1.537 raeburn 3077: my $which = $env{'form.changeparms'};
3078: my $idx = $env{'form.setparms'};
1.588 raeburn 3079: my $oldvalue = 0;
3080: my $newvalue = 0;
3081: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3082: if ($which eq 'randompick') {
3083: if ($current =~ /^(\d+)$/) {
3084: $oldvalue = $1;
3085: }
3086: } elsif ($current =~ /^yes$/i) {
3087: $oldvalue = 1;
3088: }
1.537 raeburn 3089: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3090: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3091: : 1;
3092: }
3093: if ($oldvalue ne $newvalue) {
3094: $haschanges = 1;
3095: if ($newvalue) {
3096: my $storeval = 'yes';
3097: if ($which eq 'randompick') {
3098: $storeval = $newvalue;
3099: }
3100: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3101: $parameter_type{$which});
3102: &remember_parms($idx,$which,'set',$storeval);
3103: } else {
3104: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3105: &remember_parms($idx,$which,'del');
3106: }
1.537 raeburn 3107: }
1.588 raeburn 3108: return $haschanges;
1.329 droeschl 3109: }
3110: }
3111:
3112: sub handle_edit_cmd {
3113: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3114: my $haschanges = 0;
1.543 raeburn 3115: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3116: return $haschanges;
1.543 raeburn 3117: }
1.329 droeschl 3118: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3119:
3120: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3121: my ($title, $url, @rrest) = split(':', $ratstr);
3122:
1.538 raeburn 3123: if ($cmd eq 'remove') {
1.329 droeschl 3124: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3125: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3126: &Apache::lonnet::removeuploadedurl($url);
3127: } else {
3128: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3129: }
3130: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3131: $haschanges = 1;
1.329 droeschl 3132: } elsif ($cmd eq 'cut') {
3133: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3134: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3135: $haschanges = 1;
1.344 bisitz 3136: } elsif ($cmd eq 'up'
1.329 droeschl 3137: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3138: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3139: $haschanges = 1;
1.329 droeschl 3140: } elsif ($cmd eq 'down'
3141: && defined($LONCAPA::map::order[$idx+1])) {
3142: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3143: $haschanges = 1;
1.329 droeschl 3144: } elsif ($cmd eq 'rename') {
3145: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3146: if ($comment=~/\S/) {
3147: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3148: $comment.':'.join(':', $url, @rrest);
3149: }
3150: # Devalidate title cache
3151: my $renamed_url=&LONCAPA::map::qtescape($url);
3152: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3153: $haschanges = 1;
3154: } elsif ($cmd eq 'setalias') {
3155: my $newvalue = $env{'form.alias'};
3156: if ($newvalue ne '') {
3157: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3158: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3159: 'string');
3160: &remember_parms($idx,'mapalias','set',$newvalue);
3161: $haschanges = 1;
3162: }
3163: }
3164: } elsif ($cmd eq 'delalias') {
3165: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3166: if ($current ne '') {
3167: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3168: &remember_parms($idx,'mapalias','del');
3169: $haschanges = 1;
3170: }
1.329 droeschl 3171: }
1.633 raeburn 3172: return $haschanges;
1.329 droeschl 3173: }
3174:
3175: sub editor {
1.458 raeburn 3176: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3177: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3178: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3179: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3180: if ($allowed) {
1.519 raeburn 3181: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3182: $is_random_order,$container) =
1.510 raeburn 3183: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3184: $r->print($breadcrumbtrail);
1.519 raeburn 3185: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3186: $container = 'page';
3187: } else {
3188: $container = 'sequence';
1.510 raeburn 3189: }
1.484 raeburn 3190:
1.525 raeburn 3191: my $jumpto;
3192:
3193: unless ($supplementalflag) {
1.546 raeburn 3194: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3195: }
1.484 raeburn 3196:
3197: unless ($allowed) {
3198: $randompick = -1;
3199: }
3200:
1.615 raeburn 3201: my ($errtext,$fatal);
3202: if (($folder eq '') && (!$supplementalflag)) {
3203: if (@LONCAPA::map::order) {
3204: undef(@LONCAPA::map::order);
3205: undef(@LONCAPA::map::resources);
3206: undef(@LONCAPA::map::resparms);
3207: undef(@LONCAPA::map::zombies);
3208: }
3209: $folder = 'default';
3210: $container = 'sequence';
3211: } else {
3212: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3213: $folder.'.'.$container);
3214: return $errtext if ($fatal);
3215: }
1.329 droeschl 3216:
3217: if ($#LONCAPA::map::order<1) {
3218: my $idx=&LONCAPA::map::getresidx();
3219: if ($idx<=0) { $idx=1; }
3220: $LONCAPA::map::order[0]=$idx;
3221: $LONCAPA::map::resources[$idx]='';
3222: }
1.364 bisitz 3223:
1.329 droeschl 3224: # ------------------------------------------------------------ Process commands
3225:
3226: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3227: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3228: # set parameters and change order
3229: &snapshotbefore();
3230:
3231: if (&update_parameter()) {
1.588 raeburn 3232: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3233: return $errtext if ($fatal);
3234: }
3235:
3236: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3237: # change order
3238: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3239: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3240:
3241: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3242: return $errtext if ($fatal);
3243: }
1.364 bisitz 3244:
1.329 droeschl 3245: if ($env{'form.pastemarked'}) {
1.491 raeburn 3246: my %paste_errors;
1.533 raeburn 3247: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3248: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3249: \%paste_errors);
1.541 raeburn 3250: if (ref($pastemsgarray) eq 'ARRAY') {
3251: if (@{$pastemsgarray} > 0) {
3252: $r->print('<p class="LC_info">'.
3253: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3254: '</p>');
3255: }
1.541 raeburn 3256: }
3257: if ($lockerror) {
3258: $r->print('<p class="LC_error">'.
3259: $lockerror.
3260: '</p>');
3261: }
3262: if ($save_error ne '') {
3263: return $save_error;
3264: }
3265: if ($paste_res) {
3266: my %errortext = &Apache::lonlocal::texthash (
3267: fail => 'Storage of folder contents failed',
3268: failread => 'Reading folder contents failed',
3269: failstore => 'Storage of folder contents failed',
3270: );
3271: if ($errortext{$paste_res}) {
3272: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3273: }
1.329 droeschl 3274: }
1.491 raeburn 3275: if (keys(%paste_errors) > 0) {
1.538 raeburn 3276: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3277: &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".
3278: '<ul>'."\n");
3279: foreach my $key (sort(keys(%paste_errors))) {
3280: $r->print('<li>'.$key.'</li>'."\n");
3281: }
3282: $r->print('</ul></p>'."\n");
3283: }
1.538 raeburn 3284: } elsif ($env{'form.clearmarked'}) {
3285: my $output = &do_buffer_empty();
3286: if ($output) {
3287: $r->print('<p class="LC_info">'.$output.'</p>');
3288: }
3289: }
1.329 droeschl 3290:
3291: $r->print($upload_output);
3292:
1.538 raeburn 3293: # Rename, cut, copy or remove a single resource
1.602 raeburn 3294: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3295: my $contentchg;
1.633 raeburn 3296: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3297: $contentchg = 1;
3298: }
3299: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3300: return $errtext if ($fatal);
3301: }
1.538 raeburn 3302:
3303: # Cut, copy and/or remove multiple resources
3304: if ($env{'form.multichange'}) {
3305: my %allchecked = (
3306: cut => {},
3307: remove => {},
3308: );
3309: my $needsupdate;
3310: foreach my $which (keys(%allchecked)) {
3311: $env{'form.multi'.$which} =~ s/,$//;
3312: if ($env{'form.multi'.$which}) {
3313: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3314: if (ref($allchecked{$which}) eq 'HASH') {
3315: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3316: }
3317: }
3318: }
3319: if ($needsupdate) {
3320: my $haschanges = 0;
3321: my %curr_groups = &Apache::longroup::coursegroups();
3322: my $total = scalar(@LONCAPA::map::order) - 1;
3323: for (my $i=$total; $i>=0; $i--) {
3324: my $res = $LONCAPA::map::order[$i];
3325: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3326: $name=&LONCAPA::map::qtescape($name);
3327: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3328: next unless $url;
1.538 raeburn 3329: my %denied =
3330: &action_restrictions($coursenum,$coursedom,$url,
3331: $env{'form.folderpath'},\%curr_groups);
3332: foreach my $which (keys(%allchecked)) {
3333: next if ($denied{$which});
3334: next unless ($allchecked{$which}{$res});
3335: if ($which eq 'remove') {
3336: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3337: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3338: &Apache::lonnet::removeuploadedurl($url);
3339: } else {
3340: &LONCAPA::map::makezombie($res);
3341: }
3342: splice(@LONCAPA::map::order,$i,1);
3343: $haschanges ++;
3344: } elsif ($which eq 'cut') {
3345: &LONCAPA::map::makezombie($res);
3346: splice(@LONCAPA::map::order,$i,1);
3347: $haschanges ++;
3348: }
3349: }
3350: }
3351: if ($haschanges) {
3352: ($errtext,$fatal) =
3353: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3354: return $errtext if ($fatal);
3355: }
3356: }
3357: }
3358:
1.329 droeschl 3359: # Group import/search
3360: if ($env{'form.importdetail'}) {
3361: my @imports;
3362: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3363: if (defined($item)) {
3364: my ($name,$url,$residx)=
1.533 raeburn 3365: map { &unescape($_); } split(/\=/,$item);
3366: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3367: my ($suffix,$errortxt,$locknotfreed) =
3368: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3369: if ($locknotfreed) {
3370: $r->print($locknotfreed);
3371: }
3372: if ($suffix) {
3373: $url =~ s/_new\./_$suffix./;
3374: } else {
3375: return $errortxt;
3376: }
1.533 raeburn 3377: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3378: my $type = $1;
3379: my ($suffix,$errortxt,$locknotfreed) =
3380: &new_timebased_suffix($coursedom,$coursenum,$type);
3381: if ($locknotfreed) {
3382: $r->print($locknotfreed);
3383: }
3384: if ($suffix) {
3385: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3386: } else {
3387: return $errortxt;
3388: }
1.626 raeburn 3389: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3390: my ($suffix,$errortxt,$locknotfreed) =
3391: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3392: if ($locknotfreed) {
3393: $r->print($locknotfreed);
3394: }
3395: if ($suffix) {
3396: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3397: } else {
3398: return $errortxt;
3399: }
1.534 raeburn 3400: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3401: if ($supplementalflag) {
3402: next unless ($1 eq 'supplemental');
3403: if ($folder eq 'supplemental') {
3404: next unless ($2 eq 'default');
3405: } else {
3406: next unless ($folder eq 'supplemental_'.$2);
3407: }
3408: } else {
3409: next unless ($1 eq 'docs');
3410: if ($folder eq 'default') {
3411: next unless ($2 eq 'default');
3412: } else {
3413: next unless ($folder eq 'default_'.$2);
3414: }
3415: }
1.504 raeburn 3416: }
1.329 droeschl 3417: push(@imports, [$name, $url, $residx]);
3418: }
3419: }
1.530 raeburn 3420: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3421: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3422: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3423: return $errtext if ($fatal);
1.529 raeburn 3424: if ($fixuperrors) {
3425: $r->print($fixuperrors);
3426: }
1.329 droeschl 3427: }
3428: # Loading a complete map
3429: if ($env{'form.loadmap'}) {
3430: if ($env{'form.importmap'}=~/\w/) {
3431: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3432: my ($title,$url,$ext,$type)=split(/\:/,$res);
3433: my $idx=&LONCAPA::map::getresidx($url);
3434: $LONCAPA::map::resources[$idx]=$res;
3435: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3436: }
3437: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3438: $folder.'.'.$container,1);
1.329 droeschl 3439: return $errtext if ($fatal);
3440: } else {
3441: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3442:
1.329 droeschl 3443: }
3444: }
3445: &log_differences($plain);
3446: }
3447: # ---------------------------------------------------------------- End commands
3448: # ---------------------------------------------------------------- Print screen
3449: my $idx=0;
3450: my $shown=0;
3451: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3452: $r->print('<div class="LC_Box">'.
1.432 raeburn 3453: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3454: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3455: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3456: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3457: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3458: '</ol>');
1.381 bisitz 3459: if ($randompick>=0) {
3460: $r->print('<p class="LC_warning">'
3461: .&mt('Caution: this folder is set to randomly pick a subset'
3462: .' of resources. Adding or removing resources from this'
3463: .' folder will change the set of resources that the'
3464: .' students see, resulting in spurious or missing credit'
3465: .' for completed problems, not limited to ones you'
3466: .' modify. Do not modify the contents of this folder if'
3467: .' it is in active student use.')
3468: .'</p>'
3469: );
3470: }
3471: if ($is_random_order) {
3472: $r->print('<p class="LC_warning">'
3473: .&mt('Caution: this folder is set to randomly order its'
3474: .' contents. Adding or removing resources from this folder'
3475: .' will change the order of resources shown.')
3476: .'</p>'
3477: );
3478: }
3479: $r->print('</div>');
1.364 bisitz 3480: }
1.381 bisitz 3481:
1.538 raeburn 3482: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3483: %filters = (
1.543 raeburn 3484: canremove => [],
3485: cancut => [],
3486: cancopy => [],
3487: hiddenresource => [],
3488: encrypturl => [],
3489: randomorder => [],
3490: randompick => [],
1.538 raeburn 3491: );
3492: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3493: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3494: foreach my $res (@LONCAPA::map::order) {
3495: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3496: $name=&LONCAPA::map::qtescape($name);
3497: $url=&LONCAPA::map::qtescape($url);
3498: unless ($name) { $name=(split(/\//,$url))[-1]; }
3499: unless ($name) { $idx++; next; }
1.537 raeburn 3500: push(@allidx,$res);
3501: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3502: push(@allmapidx,$res);
3503: }
1.617 raeburn 3504:
1.381 bisitz 3505: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3506: $coursenum,$coursedom,$crstype,
1.538 raeburn 3507: $pathitem,$supplementalflag,$container,
1.620 raeburn 3508: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3509: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3510: $idx++;
3511: $shown++;
1.329 droeschl 3512: }
1.424 onken 3513: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3514:
1.538 raeburn 3515: my $need_save;
1.611 raeburn 3516: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3517: my $toolslink;
1.611 raeburn 3518: if ($allowed) {
1.544 raeburn 3519: $toolslink = '<table><tr><td>'
1.520 raeburn 3520: .&Apache::loncommon::help_open_menu('Navigation Screen',
3521: 'Navigation_Screen',undef,'RAT')
3522: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3523: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3524: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3525: .'id="LC_content_toolbar_edittoplevel" '
3526: .'class="LC_toolbarItem" '
3527: .'title="'.&mt('Supplemental Content Editor').'">'
3528: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3529: }
1.510 raeburn 3530: if ($shown) {
3531: if ($allowed) {
3532: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3533: .&Apache::loncommon::start_data_table(undef,'contentlist')
3534: .&Apache::loncommon::start_data_table_header_row()
3535: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3536: .'<th colspan="3">'.&mt('Actions').'</th>'
1.538 raeburn 3537: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3538: if ($folder !~ /^supplemental/) {
1.633 raeburn 3539: $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
1.510 raeburn 3540: }
1.537 raeburn 3541: $to_show .= &Apache::loncommon::end_data_table_header_row();
3542: if ($folder !~ /^supplemental/) {
1.538 raeburn 3543: $lists{'canhide'} = join(',',@allidx);
3544: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3545: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3546: 'randomorder','randompick');
3547: foreach my $item (@possfilters) {
1.538 raeburn 3548: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3549: if (@{$filters{$item}} > 0) {
3550: $lists{$item} = join(',',@{$filters{$item}});
3551: }
1.538 raeburn 3552: }
3553: }
1.537 raeburn 3554: if (@allidx > 0) {
3555: my $path;
3556: if ($env{'form.folderpath'}) {
1.630 raeburn 3557: $path =
1.537 raeburn 3558: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3559: }
1.538 raeburn 3560: if (@allidx > 1) {
1.630 raeburn 3561: $to_show .=
1.538 raeburn 3562: &Apache::loncommon::continue_data_table_row().
3563: '<td colspan="2"> </td>'.
3564: '<td>'.
1.611 raeburn 3565: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3566: '</td>'.
1.633 raeburn 3567: '<td colspan="3"> </td>'.
3568: '<td colspan="2">'.
1.611 raeburn 3569: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3570: '</td>'.
3571: &Apache::loncommon::end_data_table_row();
3572: $need_save = 1;
3573: }
1.537 raeburn 3574: }
3575: }
3576: $to_show .= $output.' '
1.510 raeburn 3577: .&Apache::loncommon::end_data_table()
3578: .'<br style="line-height:2px;" />'
3579: .&Apache::loncommon::end_scrollbox();
3580: } else {
1.520 raeburn 3581: $to_show .= $toolslink
1.510 raeburn 3582: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3583: .$output.' '
3584: .&Apache::loncommon::end_data_table();
1.393 raeburn 3585: }
1.510 raeburn 3586: } else {
1.520 raeburn 3587: if (!$allowed) {
3588: $to_show .= $toolslink;
3589: }
1.615 raeburn 3590: my $noresmsg;
3591: if ($allowed && $hiddentop && !$supplementalflag) {
3592: $noresmsg = &mt('Main Content Hidden');
3593: } else {
3594: $noresmsg = &mt('Currently empty');
3595: }
1.510 raeburn 3596: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3597: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3598: .$noresmsg
1.510 raeburn 3599: .'</div>'
3600: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3601: }
3602: } else {
1.510 raeburn 3603: if ($shown) {
3604: $to_show = '<div>'
3605: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3606: .$output
3607: .&Apache::loncommon::end_data_table()
3608: .'</div>';
3609: } else {
3610: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3611: .&mt('Currently empty')
1.510 raeburn 3612: .'</div>'
3613: }
1.458 raeburn 3614: }
3615: my $tid = 1;
3616: if ($supplementalflag) {
3617: $tid = 2;
1.329 droeschl 3618: }
3619: if ($allowed) {
1.484 raeburn 3620: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3621: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3622: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3623: if ($canedit) {
3624: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3625: }
1.460 raeburn 3626: } else {
3627: $r->print($to_show);
1.329 droeschl 3628: }
3629: return;
3630: }
3631:
1.538 raeburn 3632: sub multiple_check_form {
1.611 raeburn 3633: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3634: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3635: my $disabled;
3636: unless ($canedit) {
3637: $disabled = 'disabled="disabled"';
3638: }
1.538 raeburn 3639: my $output =
3640: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3641: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3642: '<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>'.
3643: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3644: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3645: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3646: if ($caller eq 'settings') {
3647: $output .=
3648: '<table><tr>'.
3649: '<td class="LC_docs_entry_parameter">'.
3650: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3651: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3652: '</label></span></td>'.
3653: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3654: '<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 3655: '</span></td>'.
3656: '</tr>'."\n".
3657: '<tr>'.
3658: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3659: '<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 3660: '</label></span>'.
3661: '</td></tr></table>'."\n";
3662: } else {
3663: $output .=
3664: '<table><tr>'.
3665: '<td class="LC_docs_entry_parameter">'.
3666: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3667: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3668: '</label></span></td>'.
3669: '<td class="LC_docs_entry_parameter">'.
3670: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3671: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3672: '</label></span></td>'."\n".
3673: '<td class="LC_docs_entry_parameter">'.
3674: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3675: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3676: '</label></span></td>'.
3677: '</tr></table>'."\n";
3678: }
3679: $output .=
3680: '</fieldset>'.
3681: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3682: if ($caller eq 'settings') {
3683: $output .=
1.543 raeburn 3684: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3685: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3686: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3687: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3688: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3689: } elsif ($caller eq 'actions') {
3690: $output .=
3691: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3692: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3693: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3694: }
3695: $output .=
3696: '</form>'.
3697: '</div>';
3698: return $output;
3699: }
3700:
1.329 droeschl 3701: sub process_file_upload {
1.552 raeburn 3702: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3703: # upload a file, if present
1.552 raeburn 3704: my $filesize = length($env{'form.uploaddoc'});
3705: if (!$filesize) {
3706: $$upload_output = '<div class="LC_error">'.
3707: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3708: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3709: $filesize).'<br />'.
3710: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3711: '</div>';
3712: return;
3713: }
3714: my $quotatype = 'unofficial';
3715: if ($crstype eq 'Community') {
1.601 raeburn 3716: $quotatype = 'community';
3717: } elsif ($crstype eq 'Placement') {
3718: $quotatype = 'placement';
1.580 raeburn 3719: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3720: $quotatype = 'official';
1.573 raeburn 3721: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3722: $quotatype = 'textbook';
1.552 raeburn 3723: }
3724: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3725: $filesize = int($filesize/1000); #expressed in kb
3726: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3727: $env{'form.uploaddoc.filename'},$filesize,
3728: 'upload',$quotatype);
1.552 raeburn 3729: return if ($$upload_output);
3730: }
1.440 raeburn 3731: my ($parseaction,$showupload,$nextphase,$mimetype);
3732: if ($env{'form.parserflag'}) {
1.329 droeschl 3733: $parseaction = 'parse';
3734: }
3735: my $folder=$env{'form.folder'};
3736: if ($folder eq '') {
3737: $folder='default';
3738: }
3739: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3740: my $errtext='';
3741: my $fatal=0;
3742: my $container='sequence';
1.519 raeburn 3743: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3744: $container='page';
3745: }
3746: ($errtext,$fatal)=
1.534 raeburn 3747: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3748: if ($#LONCAPA::map::order<1) {
3749: $LONCAPA::map::order[0]=1;
3750: $LONCAPA::map::resources[1]='';
3751: }
3752: my $destination = 'docs/';
3753: if ($folder =~ /^supplemental/) {
3754: $destination = 'supplemental/';
3755: }
3756: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3757: $destination .= 'default/';
3758: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3759: $destination .= $2.'/';
3760: }
1.534 raeburn 3761: if ($fatal) {
3762: $$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>';
3763: return;
3764: }
1.440 raeburn 3765: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3766: my $newidx=&LONCAPA::map::getresidx();
3767: $destination .= $newidx;
1.439 raeburn 3768: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3769: $parseaction,$allfiles,
1.440 raeburn 3770: $codebase,undef,undef,undef,undef,
3771: undef,undef,\$mimetype);
3772: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3773: my $stored = $1;
3774: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3775: $stored.'</span>').'</p>';
3776: } else {
3777: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3778:
1.457 raeburn 3779: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3780: return;
3781: }
1.329 droeschl 3782: my $ext='false';
3783: if ($url=~m{^http://}) { $ext='true'; }
3784: $url = &LONCAPA::map::qtunescape($url);
3785: my $comment=$env{'form.comment'};
3786: $comment = &LONCAPA::map::qtunescape($comment);
3787: if ($folder=~/^supplemental/) {
3788: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3789: $env{'user.domain'}.'___&&&___'.$comment;
3790: }
3791:
3792: $LONCAPA::map::resources[$newidx]=
3793: $comment.':'.$url.':'.$ext.':normal:res';
3794: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3795: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3796: $folder.'.'.$container,1);
1.329 droeschl 3797: if ($fatal) {
1.457 raeburn 3798: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3799: return;
1.329 droeschl 3800: } else {
1.440 raeburn 3801: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3802: $$upload_output = $showupload;
1.384 raeburn 3803: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3804: if ($total_embedded > 0) {
1.440 raeburn 3805: my $uploadphase = 'upload_embedded';
3806: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3807: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3808: my ($embedded,$num) =
1.440 raeburn 3809: &Apache::loncommon::ask_for_embedded_content(
3810: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3811: if ($embedded) {
3812: if ($num) {
3813: $$upload_output .=
3814: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3815: $nextphase = $uploadphase;
3816: } else {
3817: $$upload_output .= $embedded;
3818: }
3819: } else {
3820: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3821: }
1.329 droeschl 3822: } else {
1.440 raeburn 3823: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3824: }
1.457 raeburn 3825: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3826: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3827: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3828: $nextphase = 'decompress_uploaded';
3829: my $position = scalar(@LONCAPA::map::order)-1;
3830: my $noextract = &return_to_editor();
3831: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3832: my %archiveitems = (
3833: folderpath => $env{'form.folderpath'},
3834: cmd => $nextphase,
3835: newidx => $newidx,
3836: position => $position,
3837: phase => $nextphase,
1.477 raeburn 3838: comment => $comment,
1.480 raeburn 3839: );
3840: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3841: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3842: $$upload_output = $showupload.
3843: &Apache::loncommon::decompress_form($mimetype,
3844: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3845: \%archiveitems,\@current);
1.329 droeschl 3846: }
3847: }
3848: }
1.440 raeburn 3849: return $nextphase;
1.329 droeschl 3850: }
3851:
1.480 raeburn 3852: sub get_dir_list {
3853: my ($url,$coursenum,$coursedom,$newidx) = @_;
3854: my ($destination,$dir_root) = &embedded_destination();
3855: my ($dirlistref,$listerror) =
3856: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3857: my @dir_lines;
3858: my $dirptr=16384;
3859: if (ref($dirlistref) eq 'ARRAY') {
3860: foreach my $dir_line (sort
3861: {
3862: my ($afile)=split('&',$a,2);
3863: my ($bfile)=split('&',$b,2);
3864: return (lc($afile) cmp lc($bfile));
3865: } (@{$dirlistref})) {
3866: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3867: $filename =~ s/\s+$//;
3868: next if ($filename =~ /^\.\.?$/);
3869: my $isdir = 0;
3870: if ($dirptr&$testdir) {
3871: $isdir = 1;
3872: }
3873: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3874: }
3875: }
3876: return @dir_lines;
3877: }
3878:
1.329 droeschl 3879: sub is_supplemental_title {
3880: my ($title) = @_;
3881: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3882: }
3883:
3884: # --------------------------------------------------------------- An entry line
3885:
3886: sub entryline {
1.501 raeburn 3887: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3888: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3889: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3890: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3891: if (&is_supplemental_title($title)) {
1.488 raeburn 3892: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3893: } else {
3894: $title=&HTML::Entities::encode($title,'"<>&\'');
3895: $renametitle=$title;
3896: $foldertitle=$title;
3897: }
3898:
1.611 raeburn 3899: my ($disabled,$readonly,$js_lt);
3900: unless ($canedit) {
3901: $disabled = 'disabled="disabled"';
3902: $readonly = 1;
3903: }
3904:
1.329 droeschl 3905: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3906:
1.329 droeschl 3907: $renametitle=~s/\\/\\\\/g;
3908: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3909: $renametitle=~s/"/%22/g;
1.581 raeburn 3910: $renametitle=~s/ /%20/g;
3911: $oldtitle = $renametitle;
1.576 raeburn 3912: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3913: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3914: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3915: # Edit commands
1.633 raeburn 3916: my ($esc_path, $path, $symb, $curralias);
1.329 droeschl 3917: if ($env{'form.folderpath'}) {
3918: $esc_path=&escape($env{'form.folderpath'});
3919: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3920: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3921: }
1.505 raeburn 3922: my $isexternal;
1.510 raeburn 3923: if ($residx) {
1.501 raeburn 3924: my $currurl = $url;
3925: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3926: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3927: $isexternal = 1;
3928: }
1.510 raeburn 3929: if (!$supplementalflag) {
3930: my $path = 'uploaded/'.
3931: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3932: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3933: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3934: $residx,
3935: &Apache::lonnet::declutter($currurl));
3936: }
1.501 raeburn 3937: }
1.538 raeburn 3938: my ($renamelink,%lt,$ishash);
3939: if (ref($filtersref) eq 'HASH') {
3940: $ishash = 1;
3941: }
3942:
1.329 droeschl 3943: if ($allowed) {
1.538 raeburn 3944: $form_start = '
3945: <form action="/adm/coursedocs" method="post">
3946: ';
3947: $form_common=(<<END);
3948: <input type="hidden" name="folderpath" value="$path" />
3949: <input type="hidden" name="symb" value="$symb" />
3950: END
3951: $form_param=(<<END);
3952: <input type="hidden" name="setparms" value="$orderidx" />
3953: <input type="hidden" name="changeparms" value="0" />
3954: END
3955: $form_end = '</form>';
3956:
1.329 droeschl 3957: my $incindex=$index+1;
3958: my $selectbox='';
1.471 raeburn 3959: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3960: ((split(/\:/,
1.344 bisitz 3961: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3962: ne '') &&
1.329 droeschl 3963: ((split(/\:/,
1.344 bisitz 3964: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3965: ne '')) {
3966: $selectbox=
3967: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3968: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3969: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3970: if ($i==$incindex) {
1.358 bisitz 3971: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3972: } else {
3973: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3974: }
3975: }
3976: $selectbox.='</select>';
3977: }
1.501 raeburn 3978: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3979: 'up' => 'Move Up',
3980: 'dw' => 'Move Down',
3981: 'rm' => 'Remove',
3982: 'ct' => 'Cut',
3983: 'rn' => 'Rename',
1.501 raeburn 3984: 'cp' => 'Copy',
1.633 raeburn 3985: 'da' => 'Unset alias',
3986: 'sa' => 'Set alias',
1.501 raeburn 3987: 'ex' => 'External Resource',
1.598 raeburn 3988: 'et' => 'External Tool',
1.501 raeburn 3989: 'ed' => 'Edit',
3990: 'pr' => 'Preview',
3991: 'sv' => 'Save',
3992: 'ul' => 'URL',
1.611 raeburn 3993: 'ti' => 'Title',
1.618 raeburn 3994: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3995: );
1.538 raeburn 3996: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3997: $env{'form.folderpath'},
3998: $currgroups);
1.517 raeburn 3999: my ($copylink,$cutlink,$removelink);
1.329 droeschl 4000: my $skip_confirm = 0;
1.603 raeburn 4001: my $confirm_removal = 0;
1.329 droeschl 4002: if ( $folder =~ /^supplemental/
4003: || ($url =~ m{( /smppg$
4004: |/syllabus$
4005: |/aboutme$
4006: |/navmaps$
4007: |/bulletinboard$
1.626 raeburn 4008: |/ext\.tool$
1.505 raeburn 4009: |\.html$)}x)
4010: || $isexternal) {
1.329 droeschl 4011: $skip_confirm = 1;
4012: }
1.603 raeburn 4013: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4014: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4015: $confirm_removal = 1;
4016: }
1.633 raeburn 4017: if ($url =~ /$LONCAPA::assess_re/) {
4018: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4019: }
1.329 droeschl 4020:
1.538 raeburn 4021: if ($denied{'copy'}) {
1.543 raeburn 4022: $copylink=(<<ENDCOPY)
1.507 raeburn 4023: <span style="visibility: hidden;">$lt{'cp'}</span>
4024: ENDCOPY
4025: } else {
1.538 raeburn 4026: my $formname = 'edit_copy_'.$orderidx;
4027: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4028: $copylink=(<<ENDCOPY);
1.538 raeburn 4029: <form name="$formname" method="post" action="/adm/coursedocs">
4030: $form_common
1.611 raeburn 4031: <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 4032: $form_end
1.329 droeschl 4033: ENDCOPY
1.538 raeburn 4034: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4035: push(@{$filtersref->{'cancopy'}},$orderidx);
4036: }
1.329 droeschl 4037: }
1.538 raeburn 4038: if ($denied{'cut'}) {
1.507 raeburn 4039: $cutlink=(<<ENDCUT);
4040: <span style="visibility: hidden;">$lt{'ct'}</span>
4041: ENDCUT
4042: } else {
1.538 raeburn 4043: my $formname = 'edit_cut_'.$orderidx;
4044: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 4045: $cutlink=(<<ENDCUT);
1.538 raeburn 4046: <form name="$formname" method="post" action="/adm/coursedocs">
4047: $form_common
1.542 raeburn 4048: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 4049: <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 4050: $form_end
1.329 droeschl 4051: ENDCUT
1.538 raeburn 4052: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4053: push(@{$filtersref->{'cancut'}},$orderidx);
4054: }
1.329 droeschl 4055: }
1.538 raeburn 4056: if ($denied{'remove'}) {
1.507 raeburn 4057: $removelink=(<<ENDREM);
4058: <span style="visibility: hidden;">$lt{'rm'}</a>
4059: ENDREM
4060: } else {
1.538 raeburn 4061: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 4062: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 4063: $removelink=(<<ENDREM);
1.538 raeburn 4064: <form name="$formname" method="post" action="/adm/coursedocs">
4065: $form_common
1.542 raeburn 4066: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 4067: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 4068: <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 4069: $form_end
1.497 raeburn 4070: ENDREM
1.538 raeburn 4071: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4072: push(@{$filtersref->{'canremove'}},$orderidx);
4073: }
1.497 raeburn 4074: }
1.551 raeburn 4075: $renamelink=(<<ENDREN);
1.581 raeburn 4076: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 4077: ENDREN
1.611 raeburn 4078: my ($uplink,$downlink);
4079: if ($canedit) {
4080: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4081: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4082: } else {
4083: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4084: $downlink = $uplink;
4085: }
1.329 droeschl 4086: $line.=(<<END);
4087: <td>
1.379 bisitz 4088: <div class="LC_docs_entry_move">
1.611 raeburn 4089: <a href="$uplink">
1.501 raeburn 4090: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4091: </a>
4092: </div>
4093: <div class="LC_docs_entry_move">
1.611 raeburn 4094: <a href="$downlink">
1.501 raeburn 4095: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4096: </a>
4097: </div>
1.329 droeschl 4098: </td>
4099: <td>
4100: $form_start
1.538 raeburn 4101: $form_param
1.478 raeburn 4102: $form_common
1.329 droeschl 4103: $selectbox
4104: $form_end
4105: </td>
1.540 raeburn 4106: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4107: $removelink
1.329 droeschl 4108: $cutlink
4109: $copylink
4110: </td>
4111: END
4112: }
4113: # Figure out what kind of a resource this is
4114: my ($extension)=($url=~/\.(\w+)$/);
4115: my $uploaded=($url=~/^\/*uploaded\//);
4116: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4117: my $isfolder;
4118: my $ispage;
4119: my $containerarg;
1.615 raeburn 4120: my $folderurl;
1.329 droeschl 4121: if ($uploaded) {
1.472 raeburn 4122: if (($extension eq 'sequence') || ($extension eq 'page')) {
4123: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4124: $containerarg = $1;
1.472 raeburn 4125: if ($extension eq 'sequence') {
4126: $icon=$iconpath.'navmap.folder.closed.gif';
4127: $isfolder=1;
4128: } else {
4129: $icon=$iconpath.'page.gif';
4130: $ispage=1;
4131: }
1.615 raeburn 4132: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4133: if ($allowed) {
4134: $url='/adm/coursedocs?';
4135: } else {
4136: $url='/adm/supplemental?';
4137: }
1.329 droeschl 4138: } else {
4139: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4140: }
4141: }
1.364 bisitz 4142:
1.621 raeburn 4143: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4144: my $orig_url = $url;
1.340 raeburn 4145: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 4146: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 4147: if (!$supplementalflag && $residx && $symb) {
4148: if ((!$isfolder) && (!$ispage)) {
4149: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4150: $url=&Apache::lonnet::clutter($url);
4151: if ($url=~/^\/*uploaded\//) {
4152: $url=~/\.(\w+)$/;
4153: my $embstyle=&Apache::loncommon::fileembstyle($1);
4154: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4155: $url='/adm/wrapper'.$url;
4156: } elsif ($embstyle eq 'ssi') {
4157: #do nothing with these
4158: } elsif ($url!~/\.(sequence|page)$/) {
4159: $url='/adm/coursedocs/showdoc'.$url;
4160: }
1.623 raeburn 4161: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4162: my $wrapped = $1;
4163: my $exturl = $2;
4164: if ($wrapped eq '') {
4165: $url='/adm/wrapper'.$url;
4166: }
4167: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4168: $nomodal = 1;
4169: }
1.626 raeburn 4170: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4171: $url='/adm/wrapper'.$url;
1.621 raeburn 4172: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4173: if (($ENV{'SERVER_PORT'} == 443) &&
4174: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.657 raeburn 4175: unless (&Apache::lonnet::uses_sts()) {
4176: $url .= '?usehttp=1';
4177: }
1.621 raeburn 4178: $nomodal = 1;
4179: }
1.598 raeburn 4180: }
1.501 raeburn 4181: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4182: my $shownsymb = $symb;
4183: if ($isexternal) {
4184: if ($url =~ /^([^#]+)#([^#]+)$/) {
4185: $url = $1;
4186: $anchor = $2;
1.659 raeburn 4187: my $escan = &escape('#');
4188: $shownsymb =~ s/^([^\#]+)#([^\#]+)$/$1$escan$2/;
1.609 raeburn 4189: }
4190: }
1.617 raeburn 4191: unless ($env{'request.role.adv'}) {
4192: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4193: $url = '';
4194: }
4195: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4196: $url = '';
4197: $hiddenres = 1;
4198: }
4199: }
4200: if ($url ne '') {
1.641 raeburn 4201: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.617 raeburn 4202: }
1.615 raeburn 4203: } elsif (!$env{'request.role.adv'}) {
4204: my $checkencrypt;
4205: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4206: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4207: $checkencrypt = 1;
1.620 raeburn 4208: } elsif (ref($navmapref)) {
1.615 raeburn 4209: unless (ref($$navmapref)) {
4210: $$navmapref = Apache::lonnavmaps::navmap->new();
4211: }
4212: if (ref($$navmapref)) {
4213: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4214: $checkencrypt = 1;
4215: }
4216: }
4217: }
4218: if ($checkencrypt) {
4219: my $shownsymb = &Apache::lonenc::encrypted($symb);
4220: my $shownurl = &Apache::lonenc::encrypted($url);
4221: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.641 raeburn 4222: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.615 raeburn 4223: if ($env{'request.enc'} ne '') {
4224: delete($env{'request.enc'});
4225: }
4226: } else {
4227: $url='';
1.613 raeburn 4228: }
1.612 raeburn 4229: } else {
4230: $url='';
4231: }
1.501 raeburn 4232: } else {
4233: $url='';
4234: }
1.329 droeschl 4235: }
1.621 raeburn 4236: } elsif ($supplementalflag) {
1.610 raeburn 4237: if ($isexternal) {
4238: if ($url =~ /^([^#]+)#([^#]+)$/) {
4239: $url = $1;
4240: $anchor = $2;
1.623 raeburn 4241: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.657 raeburn 4242: unless (&Apache::lonnet::uses_sts()) {
4243: if ($hostname ne '') {
4244: $url = 'http://'.$hostname.$url;
4245: }
4246: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.623 raeburn 4247: }
4248: $nomodal = 1;
4249: }
1.610 raeburn 4250: }
1.621 raeburn 4251: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4252: if (($ENV{'SERVER_PORT'} == 443) &&
4253: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.657 raeburn 4254: unless (&Apache::lonnet::uses_sts()) {
4255: if ($hostname ne '') {
4256: $url = 'http://'.$hostname.$url;
4257: }
4258: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 4259: }
1.621 raeburn 4260: $nomodal = 1;
4261: }
1.610 raeburn 4262: }
1.329 droeschl 4263: }
1.615 raeburn 4264: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4265: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4266: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4267: my $foldername=&escape($foldertitle);
4268: my $folderpath=$env{'form.folderpath'};
4269: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4270: if (!$allowed && $supplementalflag) {
1.519 raeburn 4271: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4272: $url.='folderpath='.&escape($folderpath);
4273: } else {
1.617 raeburn 4274: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4275: 'parameter_randompick'))[0];
4276: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4277: 'parameter_randomorder'))[0]=~/^yes$/i);
4278: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4279: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4280: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4281: 'parameter_encrypturl'))[0]=~/^yes$/i);
4282: unless ($hiddenmap) {
1.620 raeburn 4283: if (ref($navmapref)) {
4284: unless (ref($$navmapref)) {
4285: $$navmapref = Apache::lonnavmaps::navmap->new();
4286: }
4287: if (ref($$navmapref)) {
4288: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4289: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4290: unless (@resources) {
4291: $hiddenmap = 1;
4292: unless ($env{'request.role.adv'}) {
4293: $url = '';
4294: $hiddenfolder = 1;
4295: }
1.617 raeburn 4296: }
1.615 raeburn 4297: }
4298: }
4299: }
4300: }
1.617 raeburn 4301: unless ($encryptmap) {
1.620 raeburn 4302: if ((ref($navmapref)) && (ref($$navmapref))) {
4303: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4304: $encryptmap = 1;
4305: }
1.617 raeburn 4306: }
4307: }
1.630 raeburn 4308:
1.617 raeburn 4309: # Append randompick number, hidden, and encrypted with ":" to foldername,
4310: # so it gets transferred between levels
4311: $folderpath.=$containerarg.'&'.$foldername.
4312: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4313: unless ($url eq '') {
1.612 raeburn 4314: $url.='folderpath='.&escape($folderpath);
4315: }
1.510 raeburn 4316: my $rpckchk;
4317: if ($rpicknum) {
4318: $rpckchk = ' checked="checked"';
1.543 raeburn 4319: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4320: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4321: }
1.510 raeburn 4322: }
1.537 raeburn 4323: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4324: $rand_pick_text =
1.478 raeburn 4325: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4326: $form_param."\n".
1.478 raeburn 4327: $form_common."\n".
1.611 raeburn 4328: '<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 4329: if ($rpicknum ne '') {
4330: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4331: }
1.537 raeburn 4332: $rand_pick_text .= '</span></span>'.
4333: $form_end;
1.543 raeburn 4334: my $ro_set;
1.617 raeburn 4335: if ($randorder) {
1.543 raeburn 4336: $ro_set = 'checked="checked"';
4337: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4338: push(@{$filtersref->{'randomorder'}},$orderidx);
4339: }
4340: }
1.564 raeburn 4341: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4342: $rand_order_text =
1.537 raeburn 4343: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4344: $form_param."\n".
1.537 raeburn 4345: $form_common."\n".
1.611 raeburn 4346: '<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 4347: $form_end;
1.510 raeburn 4348: }
1.509 raeburn 4349: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4350: my $isexttool;
1.626 raeburn 4351: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4352: $url='/adm/wrapper'.$url;
4353: $isexttool = 1;
4354: }
1.510 raeburn 4355: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4356: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4357: if ($title) {
4358: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4359: }
1.598 raeburn 4360: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4361: $url .= '&idx='.$orderidx;
4362: }
1.610 raeburn 4363: if ($anchor ne '') {
4364: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4365: }
1.329 droeschl 4366: }
1.519 raeburn 4367: my ($tdalign,$tdwidth);
1.501 raeburn 4368: if ($allowed) {
1.630 raeburn 4369: my $fileloc =
1.501 raeburn 4370: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4371: if ($isexternal) {
1.630 raeburn 4372: ($editlink,$extresform) =
1.611 raeburn 4373: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4374: undef,undef,undef,undef,undef,undef,
4375: undef,$disabled);
1.626 raeburn 4376: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4377: ($editlink,$extresform) =
4378: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4379: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4380: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4381: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4382: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4383: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4384: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4385: my $suppanchor;
4386: if ($supplementalflag) {
4387: $suppanchor = $anchor;
4388: }
1.630 raeburn 4389: my $jscall =
1.501 raeburn 4390: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4391: $switchserver,
1.503 raeburn 4392: $forceedit,
1.511 raeburn 4393: undef,$symb,
4394: &escape($env{'form.folderpath'}),
1.622 raeburn 4395: $renametitle,$hostname,
4396: '','',1,$suppanchor);
1.501 raeburn 4397: if ($jscall) {
1.518 raeburn 4398: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4399: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4400: }
4401: }
4402: }
1.519 raeburn 4403: $tdalign = ' align="right" valign="top"';
4404: $tdwidth = ' width="80%"';
1.329 droeschl 4405: }
1.408 raeburn 4406: my $reinit;
4407: if ($crstype eq 'Community') {
4408: $reinit = &mt('(re-initialize community to access)');
4409: } else {
4410: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4411: }
4412: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.650 raeburn 4413: if ($orig_url =~ /$LONCAPA::assess_re/) {
1.633 raeburn 4414: $line.= '<br />';
4415: if ($curralias ne '') {
4416: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4417: $lt{'da'}.'</a></span>';
4418: } else {
4419: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4420: $lt{'sa'}.'</a></span>';
4421: }
4422: }
4423: $line.='</td><td>';
1.621 raeburn 4424: my $link;
1.472 raeburn 4425: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4426: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4427: } elsif ($url) {
1.610 raeburn 4428: if ($anchor ne '') {
4429: if ($supplementalflag) {
4430: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4431: } else {
4432: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4433: }
4434: }
1.622 raeburn 4435: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4436: $link = 'http://'.$hostname.$url;
4437: } else {
4438: $link = $url;
4439: }
1.659 raeburn 4440: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.621 raeburn 4441: if ($nomodal) {
4442: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4443: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4444: } else {
4445: $line.=&Apache::loncommon::modal_link($link,
4446: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4447: }
1.469 www 4448: } else {
4449: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4450: }
1.519 raeburn 4451: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4452: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4453: $line.='<a href="'.$url.'">'.$title.'</a>';
4454: } elsif ($url) {
1.621 raeburn 4455: if ($nomodal) {
4456: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4457: $title.'</a>';
4458: } else {
4459: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4460: }
1.617 raeburn 4461: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4462: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4463: } else {
4464: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4465: }
1.633 raeburn 4466: if (($allowed) && ($curralias ne '')) {
4467: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4468: } else {
4469: $line .= $extresform;
4470: }
4471: $line .= '</td>';
1.478 raeburn 4472: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4473: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4474: if (($allowed) && ($folder!~/^supplemental/)) {
4475: my %lt=&Apache::lonlocal::texthash(
4476: 'hd' => 'Hidden',
4477: 'ec' => 'URL hidden');
1.543 raeburn 4478: my ($enctext,$hidtext);
4479: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4480: $enctext = ' checked="checked"';
4481: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4482: push(@{$filtersref->{'encrypturl'}},$orderidx);
4483: }
4484: }
4485: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4486: $hidtext = ' checked="checked"';
4487: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4488: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4489: }
4490: }
1.537 raeburn 4491: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4492: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4493: $line.=(<<ENDPARMS);
4494: <td class="LC_docs_entry_parameter">
1.537 raeburn 4495: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4496: $form_param
1.478 raeburn 4497: $form_common
1.611 raeburn 4498: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4499: $form_end
1.458 raeburn 4500: <br />
1.537 raeburn 4501: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4502: $form_param
1.478 raeburn 4503: $form_common
1.611 raeburn 4504: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4505: $form_end
4506: </td>
1.478 raeburn 4507: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4508: $rand_order_text</td>
1.329 droeschl 4509: ENDPARMS
4510: }
1.379 bisitz 4511: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4512: return $line;
4513: }
4514:
1.538 raeburn 4515: sub action_restrictions {
4516: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4517: my %denied = (
4518: cut => 0,
4519: copy => 0,
4520: remove => 0,
4521: );
4522: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4523: # no copy for published maps
4524: $denied{'copy'} = 1;
1.597 raeburn 4525: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4526: unless ($1 eq 'simpleproblem') {
4527: $denied{'copy'} = 1;
4528: }
4529: $denied{'cut'} = 1;
1.538 raeburn 4530: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4531: if ($folderpath =~ /^default&[^\&]+$/) {
4532: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4533: $denied{'remove'} = 1;
4534: }
4535: $denied{'cut'} = 1;
4536: $denied{'copy'} = 1;
4537: }
4538: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4539: my $group = $1;
4540: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4541: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4542: $denied{'remove'} = 1;
4543: }
4544: }
4545: $denied{'cut'} = 1;
4546: $denied{'copy'} = 1;
4547: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4548: my $group = $1;
4549: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4550: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4551: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4552: if (keys(%groupsettings) > 0) {
4553: $denied{'remove'} = 1;
4554: }
4555: $denied{'cut'} = 1;
4556: $denied{'copy'} = 1;
4557: }
4558: }
4559: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4560: my $group = $1;
4561: if ($url =~ /group_boards_\Q$group\E/) {
4562: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4563: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4564: if (keys(%groupsettings) > 0) {
4565: if (ref($groupsettings{'functions'}) eq 'HASH') {
4566: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4567: $denied{'remove'} = 1;
4568: }
4569: }
4570: }
4571: $denied{'cut'} = 1;
4572: $denied{'copy'} = 1;
4573: }
4574: }
4575: }
4576: return %denied;
4577: }
4578:
1.533 raeburn 4579: sub new_timebased_suffix {
1.538 raeburn 4580: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4581: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4582: if ($type eq 'paste') {
4583: $prefix = $type;
4584: $namespace = 'courseeditor';
1.587 raeburn 4585: $idtype = 'addcode';
1.538 raeburn 4586: } elsif ($type eq 'map') {
1.533 raeburn 4587: $prefix = 'docs';
4588: if ($area eq 'supplemental') {
4589: $prefix = 'supp';
4590: }
4591: $prefix .= $container;
4592: $namespace = 'uploadedmaps';
4593: } else {
4594: $prefix = $type;
4595: $namespace = 'templated';
1.504 raeburn 4596: }
4597: my ($suffix,$freedlock,$error) =
1.587 raeburn 4598: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4599: if (!$suffix) {
1.538 raeburn 4600: if ($type eq 'paste') {
4601: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4602: } elsif ($type eq 'map') {
1.533 raeburn 4603: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4604: } elsif ($type eq 'smppg') {
4605: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4606: } elsif ($type eq 'exttool') {
4607: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4608: } else {
1.565 bisitz 4609: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4610: }
1.504 raeburn 4611: if ($error) {
4612: $errtext .= '<br />'.$error;
4613: }
4614: }
4615: if ($freedlock ne 'ok') {
1.630 raeburn 4616: $locknotfreed =
1.533 raeburn 4617: '<div class="LC_error">'.
4618: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4619: if ($type eq 'paste') {
1.591 raeburn 4620: if ($freedlock eq 'nolock') {
4621: $locknotfreed =
4622: '<div class="LC_error">'.
4623: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4624:
1.593 droeschl 4625: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4626: } else {
4627: $locknotfreed .=
4628: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4629: }
1.538 raeburn 4630: } elsif ($type eq 'map') {
1.591 raeburn 4631: $locknotfreed .=
4632: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4633: } elsif ($type eq 'smppg') {
4634: $locknotfreed .=
4635: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4636: } elsif ($type eq 'exttool') {
4637: $locknotfreed .=
4638: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4639: } else {
4640: $locknotfreed .=
1.565 bisitz 4641: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4642: }
1.538 raeburn 4643: unless ($type eq 'paste') {
4644: $locknotfreed .=
1.560 raeburn 4645: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4646: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4647: }
4648: $locknotfreed .= '</div>';
1.504 raeburn 4649: }
4650: return ($suffix,$errtext,$locknotfreed);
4651: }
4652:
1.329 droeschl 4653: =pod
4654:
4655: =item tiehash()
4656:
4657: tie the hash
4658:
4659: =cut
4660:
4661: sub tiehash {
4662: my ($mode)=@_;
4663: $hashtied=0;
4664: if ($env{'request.course.fn'}) {
4665: if ($mode eq 'write') {
4666: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4667: &GDBM_WRCREAT(),0640)) {
4668: $hashtied=2;
4669: }
4670: } else {
4671: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4672: &GDBM_READER(),0640)) {
4673: $hashtied=1;
4674: }
4675: }
1.364 bisitz 4676: }
1.329 droeschl 4677: }
4678:
4679: sub untiehash {
4680: if ($hashtied) { untie %hash; }
4681: $hashtied=0;
4682: return OK;
4683: }
4684:
4685:
4686:
4687:
4688: sub checkonthis {
1.637 raeburn 4689: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4690: $url=&unescape($url);
4691: $alreadyseen{$url}=1;
4692: $r->rflush();
4693: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4694: $r->print("\n<br />");
4695: if ($level==0) {
4696: $r->print("<br />");
4697: }
4698: for (my $i=0;$i<=$level*5;$i++) {
4699: $r->print(' ');
4700: }
4701: $r->print('<a href="'.$url.'" target="cat">'.
4702: ($title?$title:$url).'</a> ');
4703: if ($url=~/^\/res\//) {
1.637 raeburn 4704: my $updated;
4705: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4706: ($url !~ /\.\d+\.\w+$/)) {
4707: $updated = &Apache::lonnet::remove_stale_resfile($url);
4708: }
1.329 droeschl 4709: my $result=&Apache::lonnet::repcopy(
4710: &Apache::lonnet::filelocation('',$url));
4711: if ($result eq 'ok') {
4712: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4713: if ($updated) {
4714: $r->print('<br />');
4715: for (my $i=0;$i<=$level*5;$i++) {
4716: $r->print(' ');
4717: }
4718: $r->print('- '.&mt('Outdated copy removed'));
4719: }
1.329 droeschl 4720: $r->rflush();
4721: &Apache::lonnet::countacc($url);
4722: $url=~/\.(\w+)$/;
4723: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4724: $r->print('<br />');
4725: $r->rflush();
4726: for (my $i=0;$i<=$level*5;$i++) {
4727: $r->print(' ');
4728: }
4729: $r->print('- '.&mt('Rendering:').' ');
4730: my ($errorcount,$warningcount)=split(/:/,
4731: &Apache::lonnet::ssi_body($url,
4732: ('grade_target'=>'web',
4733: 'return_only_error_and_warning_counts' => 1)));
4734: if (($errorcount) ||
4735: ($warningcount)) {
4736: if ($errorcount) {
1.369 bisitz 4737: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4738: &mt('[quant,_1,error]',$errorcount).'</span>');
4739: }
4740: if ($warningcount) {
4741: $r->print('<span class="LC_warning">'.
4742: &mt('[quant,_1,warning]',$warningcount).'</span>');
4743: }
4744: } else {
4745: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4746: }
4747: $r->rflush();
4748: }
4749: my $dependencies=
4750: &Apache::lonnet::metadata($url,'dependencies');
4751: foreach my $dep (split(/\,/,$dependencies)) {
4752: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4753: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4754: }
4755: }
4756: } elsif ($result eq 'unavailable') {
4757: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4758: } elsif ($result eq 'not_found') {
4759: unless ($url=~/\$/) {
1.521 bisitz 4760: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4761: } else {
1.366 bisitz 4762: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4763: }
4764: } else {
4765: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4766: }
1.637 raeburn 4767: if (($updated) && ($result ne 'ok')) {
4768: $r->print('<br />'.&mt('Outdated copy removed'));
4769: }
1.329 droeschl 4770: }
4771: }
4772: }
4773:
4774:
4775:
4776: =pod
4777:
4778: =item list_symbs()
4779:
1.485 raeburn 4780: List Content Identifiers
1.329 droeschl 4781:
4782: =cut
4783:
4784: sub list_symbs {
4785: my ($r) = @_;
4786:
1.408 raeburn 4787: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4788: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4789: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4790: $r->print(&startContentScreen('tools'));
1.329 droeschl 4791: my $navmap = Apache::lonnavmaps::navmap->new();
4792: if (!defined($navmap)) {
4793: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4794: '<div class="LC_error">'.
4795: &mt('Unable to retrieve information about course contents').
4796: '</div>');
1.408 raeburn 4797: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4798: } else {
1.484 raeburn 4799: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4800: &Apache::loncommon::start_data_table().
4801: &Apache::loncommon::start_data_table_header_row().
4802: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4803: &Apache::loncommon::end_data_table_header_row()."\n");
4804: my $count;
1.329 droeschl 4805: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4806: $r->print(&Apache::loncommon::start_data_table_row().
4807: '<td>'.$res->compTitle().'</td>'.
4808: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4809: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4810: $count ++;
4811: }
4812: if (!$count) {
4813: $r->print(&Apache::loncommon::start_data_table_row().
4814: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4815: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4816: }
1.484 raeburn 4817: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4818: }
1.521 bisitz 4819: $r->print(&endContentScreen());
1.329 droeschl 4820: }
4821:
1.651 raeburn 4822: sub short_urls {
4823: my ($r,$canedit) = @_;
4824: my $crstype = &Apache::loncommon::course_type();
4825: my $formname = 'shortenurl';
4826: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4827: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4828: $r->print(&startContentScreen('tools'));
4829: my ($navmap,$errormsg) =
4830: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4831: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4832: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4833: my (%maps,%resources,%titles);
4834: if (!ref($navmap)) {
4835: $r->print($errormsg.
4836: &endContentScreen());
4837: return '';
4838: } else {
1.652 raeburn 4839: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
1.651 raeburn 4840: $r->rflush();
4841: my $readonly;
4842: if ($canedit) {
4843: my ($numnew,$errors) = &Apache::loncommon::make_short_symbs($cdom,$cnum,$navmap);
4844: if ($numnew) {
4845: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4846: }
4847: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4848: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4849: foreach my $error (@{$errors}) {
4850: $r->print('<li>'.$error.'</li>');
4851: }
4852: $r->print('</ul><br />');
4853: }
4854: } else {
4855: $readonly = 1;
4856: }
4857: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4858: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4859: undef,undef,undef,undef,undef,\%currtiny,$readonly));
4860: }
4861: $r->print(&endContentScreen());
4862: }
4863:
1.637 raeburn 4864: sub contentverifyform {
4865: my ($r) = @_;
4866: my $crstype = &Apache::loncommon::course_type();
4867: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4868: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4869: $r->print(&startContentScreen('tools'));
4870: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4871: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4872: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4873: ' <span class="LC_nobreak">'.
4874: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4875: &mt('No').'</label>'.(' 'x2).
4876: '<label><input type="radio" name="checkstale" value="1" />'.
4877: &mt('Yes').'</label></span></p><p>'.
4878: '<input type="submit" value="'.&mt('Verify content').' "/>'.
4879: '<input type="hidden" value="1" name="tools" />'.
4880: '<input type="hidden" value="1" name="verify" /></p></form>');
4881: $r->print(&endContentScreen());
4882: return;
4883: }
1.329 droeschl 4884:
4885: sub verifycontent {
1.637 raeburn 4886: my ($r,$checkstale) = @_;
1.408 raeburn 4887: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4888: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4889: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4890: $r->print(&startContentScreen('tools'));
4891: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4892: $hashtied=0;
4893: undef %alreadyseen;
4894: %alreadyseen=();
4895: &tiehash();
1.484 raeburn 4896:
1.329 droeschl 4897: foreach my $key (keys(%hash)) {
4898: if ($hash{$key}=~/\.(page|sequence)$/) {
4899: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4900: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4901: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4902: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4903: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4904: }
4905: }
4906: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 4907: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4908: }
4909: }
4910: &untiehash();
1.442 www 4911: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4912: $r->print(&endContentScreen());
1.329 droeschl 4913: }
4914:
4915: sub devalidateversioncache {
4916: my $src=shift;
4917: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4918: &Apache::lonnet::clutter($src));
4919: }
4920:
4921: sub checkversions {
1.611 raeburn 4922: my ($r,$canedit) = @_;
1.408 raeburn 4923: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4924: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4925: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4926: $r->print(&startContentScreen('tools'));
1.442 www 4927:
1.329 droeschl 4928: my $header='';
4929: my $startsel='';
4930: my $monthsel='';
4931: my $weeksel='';
4932: my $daysel='';
4933: my $allsel='';
4934: my %changes=();
4935: my $starttime=0;
4936: my $haschanged=0;
4937: my %setversions=&Apache::lonnet::dump('resourceversions',
4938: $env{'course.'.$env{'request.course.id'}.'.domain'},
4939: $env{'course.'.$env{'request.course.id'}.'.num'});
4940:
4941: $hashtied=0;
4942: &tiehash();
1.611 raeburn 4943: if ($canedit) {
4944: my %newsetversions=();
4945: if ($env{'form.setmostrecent'}) {
4946: $haschanged=1;
4947: foreach my $key (keys(%hash)) {
4948: if ($key=~/^ids\_(\/res\/.+)$/) {
4949: $newsetversions{$1}='mostrecent';
4950: &devalidateversioncache($1);
4951: }
4952: }
4953: } elsif ($env{'form.setcurrent'}) {
4954: $haschanged=1;
4955: foreach my $key (keys(%hash)) {
4956: if ($key=~/^ids\_(\/res\/.+)$/) {
4957: my $getvers=&Apache::lonnet::getversion($1);
4958: if ($getvers>0) {
4959: $newsetversions{$1}=$getvers;
4960: &devalidateversioncache($1);
4961: }
4962: }
1.329 droeschl 4963: }
1.611 raeburn 4964: } elsif ($env{'form.setversions'}) {
4965: $haschanged=1;
4966: foreach my $key (keys(%env)) {
4967: if ($key=~/^form\.set_version_(.+)$/) {
4968: my $src=$1;
4969: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4970: $newsetversions{$src}=$env{$key};
4971: &devalidateversioncache($src);
4972: }
4973: }
1.329 droeschl 4974: }
1.611 raeburn 4975: }
4976: if ($haschanged) {
4977: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4978: $env{'course.'.$env{'request.course.id'}.'.domain'},
4979: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4980: $r->print(&Apache::loncommon::confirmwrapper(
4981: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4982: } else {
4983: $r->print(&Apache::loncommon::confirmwrapper(
4984: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4985: }
1.611 raeburn 4986: &mark_hash_old();
4987: }
4988: &changewarning($r,'');
1.329 droeschl 4989: }
4990: if ($env{'form.timerange'} eq 'all') {
4991: # show all documents
1.549 raeburn 4992: $header=&mt('All content in '.$crstype);
1.521 bisitz 4993: $allsel=' selected="selected"';
1.329 droeschl 4994: foreach my $key (keys(%hash)) {
4995: if ($key=~/^ids\_(\/res\/.+)$/) {
4996: my $src=$1;
4997: $changes{$src}=1;
4998: }
4999: }
5000: } else {
5001: # show documents which changed
5002: %changes=&Apache::lonnet::dump
5003: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5004: $env{'course.'.$env{'request.course.id'}.'.num'});
5005: my $firstkey=(keys(%changes))[0];
5006: unless ($firstkey=~/^error\:/) {
5007: unless ($env{'form.timerange'}) {
5008: $env{'form.timerange'}=604800;
5009: }
5010: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5011: .&mt('seconds');
5012: if ($env{'form.timerange'}==-1) {
5013: $seltext='since start of course';
1.521 bisitz 5014: $startsel=' selected="selected"';
1.329 droeschl 5015: $env{'form.timerange'}=time;
5016: }
5017: $starttime=time-$env{'form.timerange'};
5018: if ($env{'form.timerange'}==2592000) {
5019: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5020: $monthsel=' selected="selected"';
1.329 droeschl 5021: } elsif ($env{'form.timerange'}==604800) {
5022: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5023: $weeksel=' selected="selected"';
1.329 droeschl 5024: } elsif ($env{'form.timerange'}==86400) {
5025: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 5026: $daysel=' selected="selected"';
1.329 droeschl 5027: }
5028: $header=&mt('Content changed').' '.$seltext;
5029: } else {
5030: $header=&mt('No content modifications yet.');
5031: }
5032: }
5033: %setversions=&Apache::lonnet::dump('resourceversions',
5034: $env{'course.'.$env{'request.course.id'}.'.domain'},
5035: $env{'course.'.$env{'request.course.id'}.'.num'});
5036: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 5037: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 5038: 'lm' => 'Version changes since last Month',
5039: 'lw' => 'Version changes since last Week',
5040: 'sy' => 'Version changes since Yesterday',
5041: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 5042: 'cd' => 'Change display',
1.329 droeschl 5043: 'sd' => 'Display',
5044: 'fi' => 'File',
5045: 'md' => 'Modification Date',
5046: 'mr' => 'Most recently published Version',
1.408 raeburn 5047: 've' => 'Version used in '.$crstype,
5048: 'vu' => 'Set Version to be used in '.$crstype,
5049: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 5050: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5051: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 5052: 'di' => 'Differences',
1.484 raeburn 5053: 'save' => 'Save changes',
5054: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 5055: 'act' => 'Actions');
1.611 raeburn 5056: my ($disabled,$readonly);
5057: unless ($canedit) {
5058: $disabled = 'disabled="disabled"';
5059: $readonly = 1;
5060: }
1.329 droeschl 5061: $r->print(<<ENDHEADERS);
1.484 raeburn 5062: <h4 class="LC_info">$header</h4>
1.329 droeschl 5063: <form action="/adm/coursedocs" method="post">
5064: <input type="hidden" name="versions" value="1" />
1.484 raeburn 5065: <div class="LC_left_float">
1.479 golterma 5066: <fieldset>
1.484 raeburn 5067: <legend>$lt{'cd'}</legend>
1.329 droeschl 5068: <select name="timerange">
1.521 bisitz 5069: <option value='all'$allsel>$lt{'al'}</option>
5070: <option value="-1"$startsel>$lt{'st'}</option>
5071: <option value="2592000"$monthsel>$lt{'lm'}</option>
5072: <option value="604800"$weeksel>$lt{'lw'}</option>
5073: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 5074: </select>
5075: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 5076: </fieldset>
5077: </div>
5078: <div class="LC_left_float">
5079: <fieldset>
5080: <legend>$lt{'act'}</legend>
1.611 raeburn 5081: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5082: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 5083: </fieldset>
5084: </div>
5085: <br clear="all" />
5086: <hr />
5087: <h4>$lt{'vers'}</h4>
1.329 droeschl 5088: ENDHEADERS
1.479 golterma 5089: #number of columns for version history
1.571 raeburn 5090: my %changedbytime;
5091: foreach my $key (keys(%changes)) {
5092: #excludes not versionable problems from resource version history:
5093: next if ($key =~ /^\/res\/lib\/templates/);
5094: my $chg;
5095: if ($env{'form.timerange'} eq 'all') {
5096: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5097: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5098: } else {
5099: $chg = $changes{$key};
5100: next if ($chg < $starttime);
5101: }
5102: push(@{$changedbytime{$chg}},$key);
5103: }
5104: if (keys(%changedbytime) == 0) {
5105: &untiehash();
5106: $r->print(&mt('No content changes in imported content in specified time frame').
5107: &endContentScreen());
5108: return;
5109: }
1.479 golterma 5110: $r->print(
1.611 raeburn 5111: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5112: &Apache::loncommon::start_data_table().
5113: &Apache::loncommon::start_data_table_header_row().
5114: '<th>'.&mt('Resources').'</th>'.
5115: "<th>$lt{'mr'}</th>".
5116: "<th>$lt{'ve'}</th>".
5117: "<th>$lt{'vu'}</th>".
5118: '<th>'.&mt('History').'</th>'.
5119: &Apache::loncommon::end_data_table_header_row()
5120: );
1.571 raeburn 5121: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5122: foreach my $key (sort(@{$changedbytime{$chg}})) {
5123: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5124: my $currentversion=&Apache::lonnet::getversion($key);
5125: if ($currentversion<0) {
5126: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5127: }
5128: my $linkurl=&Apache::lonnet::clutter($key);
5129: $r->print(
5130: &Apache::loncommon::start_data_table_row().
5131: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5132: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5133: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5134: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5135: '<td align="right">'
5136: );
5137: # Used in course
5138: my $usedversion=$hash{'version_'.$linkurl};
5139: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5140: if ($usedversion != $currentversion) {
1.479 golterma 5141: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5142: } else {
1.479 golterma 5143: $r->print($usedversion);
5144: }
1.329 droeschl 5145: } else {
1.521 bisitz 5146: $r->print($currentversion);
1.329 droeschl 5147: }
1.571 raeburn 5148: $r->print('</td><td title="'.$lt{'vu'}.'">');
5149: # Set version
5150: $r->print(&Apache::loncommon::select_form(
5151: $setversions{$linkurl},
5152: 'set_version_'.$linkurl,
5153: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5154: '' => '',
5155: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5156: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5157: my $lastold=1;
5158: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5159: my $url=$root.'.'.$prevvers.'.'.$extension;
5160: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5161: $lastold=$prevvers;
5162: }
5163: }
5164: $r->print('</td>');
5165: # List all available versions
5166: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5167: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5168: my $url=$root.'.'.$prevvers.'.'.$extension;
5169: $r->print(
5170: '<span class="LC_nobreak">'
5171: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5172: .&mt('Version [_1]',$prevvers).'</a>'
5173: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5174: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5175: .')');
5176: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5177: $r->print(
5178: ' <a href="/adm/diff?filename='.
5179: &Apache::lonnet::clutter($root.'.'.$extension).
5180: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5181: '" target="diffs">'.&mt('Diffs').'</a>');
5182: }
5183: $r->print('</span><br />');
1.329 droeschl 5184: }
1.571 raeburn 5185: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5186: }
1.329 droeschl 5187: }
1.521 bisitz 5188: $r->print(
5189: &Apache::loncommon::end_data_table().
1.611 raeburn 5190: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5191: '</form>'
5192: );
1.329 droeschl 5193:
5194: &untiehash();
1.521 bisitz 5195: $r->print(&endContentScreen());
1.571 raeburn 5196: return;
1.329 droeschl 5197: }
5198:
5199: sub mark_hash_old {
5200: my $retie_hash=0;
5201: if ($hashtied) {
5202: $retie_hash=1;
5203: &untiehash();
5204: }
5205: &tiehash('write');
5206: $hash{'old'}=1;
5207: &untiehash();
5208: if ($retie_hash) { &tiehash(); }
5209: }
5210:
5211: sub is_hash_old {
5212: my $untie_hash=0;
5213: if (!$hashtied) {
5214: $untie_hash=1;
5215: &tiehash();
5216: }
5217: my $return=$hash{'old'};
5218: if ($untie_hash) { &untiehash(); }
5219: return $return;
5220: }
5221:
5222: sub changewarning {
5223: my ($r,$postexec,$message,$url)=@_;
5224: if (!&is_hash_old()) { return; }
5225: my $pathvar='folderpath';
5226: my $path=&escape($env{'form.folderpath'});
5227: if (!defined($url)) {
5228: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5229: }
5230: my $course_type = &Apache::loncommon::course_type();
5231: if (!defined($message)) {
5232: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5233: }
1.653 raeburn 5234: my $windowname = 'loncapaclient';
5235: if ($env{'request.lti.login'}) {
5236: $windowname .= 'lti';
5237: }
1.329 droeschl 5238: $r->print("\n\n".
1.372 bisitz 5239: '<script type="text/javascript">'."\n".
5240: '// <![CDATA['."\n".
5241: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5242: '// ]]>'."\n".
1.369 bisitz 5243: '</script>'."\n".
1.653 raeburn 5244: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
1.329 droeschl 5245: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5246: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5247: &mt($message,' <input type="hidden" name="'.
5248: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5249: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5250: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5251: }
5252:
5253:
5254: sub init_breadcrumbs {
1.571 raeburn 5255: my ($form,$text,$help)=@_;
1.329 droeschl 5256: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5257: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5258: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5259: faq=>273,
5260: bug=>'Instructor Interface',
1.571 raeburn 5261: help => $help});
1.329 droeschl 5262: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5263: text=>$text,
5264: faq=>273,
5265: bug=>'Instructor Interface'});
5266: }
5267:
1.441 www 5268: # subroutine to list form elements
5269: sub create_list_elements {
5270: my @formarr = @_;
5271: my $list = '';
1.501 raeburn 5272: foreach my $button (@formarr){
5273: foreach my $picture (keys(%{$button})) {
5274: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5275: }
5276: }
5277: return $list;
5278: }
1.329 droeschl 5279:
1.441 www 5280: # subroutine to create ul from list elements
5281: sub create_form_ul {
5282: my $list = shift;
5283: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5284: return $ul;
5285: }
1.329 droeschl 5286:
1.442 www 5287: #
5288: # Start tabs
5289: #
5290:
5291: sub startContentScreen {
1.484 raeburn 5292: my ($mode) = @_;
5293: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5294: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5295: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5296: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5297: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5298: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5299: } else {
1.549 raeburn 5300: $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 5301: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5302: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5303: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5304: }
5305: $output .= "\n".'</ul>'."\n";
5306: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5307: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5308: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5309: return $output;
1.442 www 5310: }
5311:
5312: #
5313: # End tabs
5314: #
5315:
5316: sub endContentScreen {
1.484 raeburn 5317: return '</div></div></div>';
1.442 www 5318: }
1.329 droeschl 5319:
1.446 www 5320: sub supplemental_base {
1.548 raeburn 5321: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5322: }
5323:
1.329 droeschl 5324: sub handler {
5325: my $r = shift;
5326: &Apache::loncommon::content_type($r,'text/html');
5327: $r->send_http_header;
5328: return OK if $r->header_only;
1.484 raeburn 5329:
5330: # get course data
1.408 raeburn 5331: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5332: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5333: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5334:
1.606 raeburn 5335: # get docroot
5336: my $londocroot = $r->dir_config('lonDocRoot');
5337:
1.484 raeburn 5338: # graphics settings
5339: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5340:
1.443 www 5341: #
1.329 droeschl 5342: # --------------------------------------------- Initialize help topics for this
5343: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5344: 'Adding_External_Resource','Adding_External_Tool',
5345: 'Navigate_Content','Adding_Folders','Docs_Overview',
5346: 'Load_Map','Supplemental','Score_Upload_Form',
5347: 'Adding_Pages','Importing_LON-CAPA_Resource',
5348: 'Importing_IMS_Course','Uploading_From_Harddrive',
5349: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5350: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5351: }
5352: # Composite help files
5353: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5354: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5355: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5356: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5357: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5358: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5359: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5360: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5361: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5362: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5363:
1.611 raeburn 5364: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5365: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5366: unless ($r->uri eq '/adm/supplemental') {
5367: # does this user have privileges to modify content.
1.611 raeburn 5368: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5369: $allowed = 1;
5370: $canedit = 1;
5371: $canview = 1;
5372: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5373: $allowed = 1;
5374: $canview = 1;
5375: }
5376: }
5377: unless ($canedit) {
5378: $disabled = ' disabled="disabled"';
1.472 raeburn 5379: }
1.582 raeburn 5380: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5381: if ($env{'form.inhibitmenu'}) {
5382: unless ($env{'form.inhibitmenu'} eq 'yes') {
5383: delete($env{'form.inhibitmenu'});
5384: }
5385: }
5386:
1.582 raeburn 5387: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5388: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5389: if (!$canedit) {
5390: &verifycontent($r);
5391: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5392: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5393: text=>'Results',
5394: faq=>273,
5395: bug=>'Instructor Interface'});
5396: &verifycontent($r,$env{'form.checkstale'});
5397: } else {
5398: &contentverifyform($r);
5399: }
1.329 droeschl 5400: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5401: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5402: &list_symbs($r);
1.651 raeburn 5403: } elsif ($allowed && $env{'form.shorturls'}) {
5404: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5405: &short_urls($r,$canedit);
1.329 droeschl 5406: } elsif ($allowed && $env{'form.docslog'}) {
5407: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5408: my $folder = $env{'form.folder'};
5409: if ($folder eq '') {
5410: $folder='default';
5411: }
1.611 raeburn 5412: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5413: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5414: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5415: &checkversions($r,$canedit);
5416: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5417: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5418: &dumpcourse($r);
1.611 raeburn 5419: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5420: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5421: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5422: } else {
1.611 raeburn 5423: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5424: $noendpage = 1;
5425: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5426: if ($redirect) {
5427: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5428: my $container = 'sequence';
5429: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5430: $is_random_order,$container) =
5431: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5432: my (@folders)=split('&',$env{'form.folderpath'});
5433: $env{'form.foldername'}=&unescape(pop(@folders));
5434: my $folder=pop(@folders);
5435: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5436: $folder.'.'.$container);
5437: my $warning;
5438: if ($fatal) {
5439: if ($container eq 'page') {
5440: $warning = &mt('An error occurred retrieving the contents of the current page.');
5441: } else {
5442: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5443: }
5444: } else {
5445: my $url = $redirect;
5446: my $srcfile = $londocroot.$url;
5447: $url =~ s{^/priv/}{/res/};
5448: my $targetfile = $londocroot.$url;
5449: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5450: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5451: $env{'form.folder'} = $folder;
5452: &snapshotbefore();
5453: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5454: my $ext = 'false';
5455: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5456: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5457: ':'.$ext.':normal:res';
5458: push(@LONCAPA::map::order,$newidx);
5459: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5460: 'string_yesno');
5461: &remember_parms($newidx,'hiddenresource','set','yes');
5462: ($errtext,$fatal) =
5463: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5464: &log_differences($plain);
5465: &mark_hash_old();
5466: $r->internal_redirect($redirect);
5467: return OK;
5468: }
1.654 raeburn 5469: } else {
5470: $r->internal_redirect($redirect);
1.606 raeburn 5471: }
5472: }
5473: }
1.445 www 5474: #
5475: # Done catching special calls
1.484 raeburn 5476: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5477: # Get the parameters that may be needed
5478: #
5479: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5480: ['folderpath',
5481: 'forcesupplement','forcestandard',
1.510 raeburn 5482: 'tools','symb','command','supppath']);
1.445 www 5483:
1.635 raeburn 5484: foreach my $item ('forcesupplement','forcestandard','tools') {
5485: next if ($env{'form.'.$item} eq '');
5486: unless ($env{'form.'.$item} eq '1') {
5487: delete($env{'form.'.$item});
5488: }
5489: }
5490:
5491: if ($env{'form.command'}) {
5492: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5493: delete($env{'form.command'});
5494: }
5495: }
5496:
5497: if ($env{'form.symb'}) {
5498: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5499: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5500: delete($env{'form.symb'});
5501: }
5502: }
5503:
1.445 www 5504: # standard=1: this is a "new-style" course with an uploaded map as top level
5505: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5506:
5507: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5508:
1.484 raeburn 5509: # Decide whether this should display supplemental or main content or utilities
1.445 www 5510: # supplementalflag=1: show supplemental documents
5511: # supplementalflag=0: show standard documents
1.484 raeburn 5512: # toolsflag=1: show utilities
1.445 www 5513:
1.561 raeburn 5514: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5515: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5516: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5517: $supplementalflag=0;
5518: }
5519: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5520: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5521: unless ($allowed) { $supplementalflag=1; }
5522: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5523: my $toolsflag=0;
5524: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5525:
1.635 raeburn 5526: if ($env{'form.folderpath'} ne '') {
5527: my @items = split(/\&/,$env{'form.folderpath'});
5528: my $badpath;
5529: for (my $i=0; $i<@items; $i++) {
5530: my $odd = $i%2;
5531: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5532: $badpath = 1;
5533: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5534: $badpath = 1;
5535: }
5536: last if ($badpath);
5537: }
5538: if ($badpath) {
5539: delete($env{'form.folderpath'});
5540: }
5541: }
5542:
5543: if ($env{'form.supppath'} ne '') {
5544: my @items = split(/\&/,$env{'form.supppath'});
5545: my $badpath;
5546: for (my $i=0; $i<@items; $i++) {
5547: my $odd = $i%2;
5548: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5549: $badpath = 1;
5550: }
5551: last if ($badpath);
5552: }
5553: if ($badpath) {
5554: delete($env{'form.supppath'});
5555: }
5556: }
5557:
1.329 droeschl 5558: my $script='';
5559: my $showdoc=0;
1.457 raeburn 5560: my $addentries = {};
1.475 raeburn 5561: my $container;
1.329 droeschl 5562: my $containertag;
1.508 raeburn 5563: my $pathitem;
1.598 raeburn 5564: my %ltitools;
1.617 raeburn 5565: my $hiddentop;
1.615 raeburn 5566: my $navmap;
1.617 raeburn 5567: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5568:
1.464 www 5569: # Do we directly jump somewhere?
1.525 raeburn 5570: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5571: if ($env{'form.symb'} ne '') {
1.522 raeburn 5572: $env{'form.folderpath'}=
1.617 raeburn 5573: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5574: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5575: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5576: } elsif ($env{'form.supppath'} ne '') {
5577: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5578: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5579: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5580: }
1.472 raeburn 5581: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5582: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5583: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5584: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5585: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5586: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5587: } elsif ($env{'form.command'} eq 'contents') {
5588: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5589: } elsif ($env{'form.command'} eq 'home') {
5590: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5591: }
5592:
1.525 raeburn 5593:
1.445 www 5594: # Where do we store these for when we come back?
5595: my $stored_folderpath='docs_folderpath';
5596: if ($supplementalflag) {
5597: $stored_folderpath='docs_sup_folderpath';
5598: }
1.464 www 5599:
1.519 raeburn 5600: # No folderpath, and in edit mode, see if we have something stored
5601: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5602: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5603: {'folderpath' => 'scalar'});
1.615 raeburn 5604:
5605: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5606: if ($supplementalflag) {
5607: undef($env{'form.folderpath'}) if ($1 eq 'default');
5608: } else {
5609: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5610: }
5611: } else {
1.523 raeburn 5612: undef($env{'form.folderpath'});
5613: }
1.329 droeschl 5614: }
1.446 www 5615:
5616: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5617: if (!$allowed) {
1.446 www 5618: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5619: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5620: }
5621: }
1.446 www 5622: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5623: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5624: $env{'form.folderpath'} = &supplemental_base()
5625: .'&'.
1.329 droeschl 5626: $env{'form.folderpath'};
5627: }
1.615 raeburn 5628: # If allowed and user's role is not advanced check folderpath is not hidden
5629: if (($allowed) && (!$env{'request.role.adv'}) &&
5630: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5631: my $folderurl;
5632: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5633: my $folder = $pathitems[-2];
5634: if ($folder eq '') {
5635: undef($env{'form.folderpath'});
5636: } else {
5637: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5638: if ((split(/\:/,$pathitems[-1]))[4]) {
5639: $folderurl .= '.page';
5640: } else {
5641: $folderurl .= '.sequence';
5642: }
1.617 raeburn 5643: unless (ref($navmap)) {
5644: $navmap = Apache::lonnavmaps::navmap->new();
5645: }
1.615 raeburn 5646: if (ref($navmap)) {
5647: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5648: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5649: unless (@resources) {
5650: undef($env{'form.folderpath'});
5651: }
1.615 raeburn 5652: }
5653: }
5654: }
5655: }
5656:
5657:
1.446 www 5658: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5659: unless ($env{'form.folderpath'}) {
1.446 www 5660: if ($supplementalflag) {
5661: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5662: } elsif ($allowed) {
5663: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5664: }
1.472 raeburn 5665: }
1.446 www 5666:
1.445 www 5667: # Store this
1.484 raeburn 5668: unless ($toolsflag) {
1.615 raeburn 5669: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5670: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5671: {'folderpath' => 'scalar'});
1.510 raeburn 5672: }
1.519 raeburn 5673: my $folderpath;
1.484 raeburn 5674: if ($env{'form.folderpath'}) {
1.519 raeburn 5675: $folderpath = $env{'form.folderpath'};
5676: my (@folders)=split('&',$env{'form.folderpath'});
5677: $env{'form.foldername'}=&unescape(pop(@folders));
5678: if ($env{'form.foldername'} =~ /\:1$/) {
5679: $container = 'page';
5680: } else {
5681: $container = 'sequence';
5682: }
5683: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5684: } else {
1.519 raeburn 5685: if ($env{'form.folder'} eq '' ||
5686: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5687: if ($env{'form.folder'} eq 'supplemental') {
5688: $folderpath=&supplemental_base();
5689: } elsif (!$hiddentop) {
5690: $folderpath='default&'.
5691: &escape(&mt('Main Content').':::::');
5692: }
1.484 raeburn 5693: }
5694: }
1.519 raeburn 5695: $containertag = '<input type="hidden" name="folderpath" value="" />';
5696: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5697: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5698: $showdoc='/'.$1;
5699: }
5700: if ($showdoc) { # got called in sequence from course
5701: $allowed=0;
5702: } else {
1.611 raeburn 5703: if ($canedit) {
1.484 raeburn 5704: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5705: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5706: }
5707: }
1.329 droeschl 5708: }
5709:
1.344 bisitz 5710: # get personal data
1.329 droeschl 5711: my $uname=$env{'user.name'};
5712: my $udom=$env{'user.domain'};
5713: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5714:
5715: if ($allowed) {
1.484 raeburn 5716: if ($toolsflag) {
5717: $script .= &inject_data_js();
5718: my ($home,$other,%outhash)=&authorhosts();
5719: if (!$home && $other) {
5720: my @hosts;
5721: foreach my $aurole (keys(%outhash)) {
5722: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5723: push(@hosts,$outhash{$aurole});
5724: }
5725: }
5726: $script .= &dump_switchserver_js(@hosts);
5727: }
1.458 raeburn 5728: } else {
1.570 raeburn 5729: my $tid = 1;
1.484 raeburn 5730: my @tabids;
5731: if ($supplementalflag) {
1.655 raeburn 5732: @tabids = ('002','dd2','ee2','ff2');
1.570 raeburn 5733: $tid = 2;
1.484 raeburn 5734: } else {
5735: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5736: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5737: unshift(@tabids,'001');
5738: push(@tabids,('dd1','ee1'));
5739: }
1.458 raeburn 5740: }
1.484 raeburn 5741: my $tabidstr = join("','",@tabids);
1.644 raeburn 5742: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
1.600 raeburn 5743: my $posslti = keys(%ltitools);
1.622 raeburn 5744: my $hostname = $r->hostname();
1.606 raeburn 5745: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5746: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5747: &history_tab_js().
5748: &inject_data_js().
1.570 raeburn 5749: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5750: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5751: $addentries = {
1.485 raeburn 5752: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5753: };
1.458 raeburn 5754: }
1.538 raeburn 5755: $script .= &paste_popup_js();
1.501 raeburn 5756: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5757: &mt('Switch server?');
5758:
5759:
1.329 droeschl 5760: }
5761: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5762: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5763: .'// <![CDATA['."\n"
5764: .$script."\n"
5765: .'// ]]>'."\n"
1.595 musolffc 5766: .'</script>'."\n"
5767: .'<script type="text/javascript"
5768: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5769:
5770: # Breadcrumbs
5771: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5772:
5773: if ($showdoc) {
5774: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5775: {'force_register' => $showdoc,}));
1.571 raeburn 5776: } elsif ($toolsflag) {
1.611 raeburn 5777: my ($breadtext,$breadtitle);
1.617 raeburn 5778: $breadtext = "$crstype Editor";
1.611 raeburn 5779: if ($canedit) {
5780: $breadtitle = 'Editing '.$crstype.' Contents';
5781: } else {
5782: $breadtext .= ' (View-only mode)';
5783: $breadtitle = 'Viewing '.$crstype.' Contents';
5784: }
1.571 raeburn 5785: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5786: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5787: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5788: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5789: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5790: $breadtitle)
1.571 raeburn 5791: );
1.510 raeburn 5792: } elsif ($r->uri eq '/adm/supplemental') {
5793: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5794: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5795: {'bread_crumbs' => $brcrum,}));
5796: } else {
1.611 raeburn 5797: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5798: $breadtext = "$crstype Editor";
1.611 raeburn 5799: if ($canedit) {
5800: $breadtitle = 'Editing '.$crstype.' Contents';
5801: $helpitem = 'Docs_Adding_Course_Doc';
5802: } else {
5803: $breadtext .= ' (View-only mode)';
5804: $breadtitle = 'Viewing '.$crstype.' Contents';
5805: $helpitem = 'Docs_Viewing_Course_Doc';
5806: }
1.392 raeburn 5807: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5808: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5809: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5810: {'add_entries' => $addentries}
5811: )
1.392 raeburn 5812: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5813: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5814: $breadtitle,
5815: $helpitem)
1.392 raeburn 5816: );
5817: }
1.364 bisitz 5818:
1.329 droeschl 5819: my %allfiles = ();
5820: my %codebase = ();
1.440 raeburn 5821: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5822: if ($canedit) {
1.329 droeschl 5823: if (($env{'form.uploaddoc.filename'}) &&
5824: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5825: my $context = $1;
5826: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5827: undef($hadchanges);
1.440 raeburn 5828: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5829: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 5830: undef($navmap);
1.329 droeschl 5831: if ($hadchanges) {
5832: &mark_hash_old();
5833: }
1.440 raeburn 5834: $r->print($upload_output);
5835: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5836: # Process file upload - phase two - upload embedded objects
5837: $uploadphase = 'check_embedded';
5838: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5839: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5840: $env{'form.newidx'});
5841: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5842: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5843: my ($destination,$dir_root) = &embedded_destination();
5844: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5845: my $actionurl = '/adm/coursedocs';
1.630 raeburn 5846: my ($result,$flag) =
1.440 raeburn 5847: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5848: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5849: $actionurl);
5850: $r->print($result.&return_to_editor());
5851: } elsif ($env{'form.phase'} eq 'check_embedded') {
5852: # Process file upload - phase three - modify references in HTML file
5853: $uploadphase = 'modified_orightml';
5854: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5855: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5856: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 5857: my $result =
1.482 raeburn 5858: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5859: $docuname,$docudom,undef,
5860: $dir_root);
1.630 raeburn 5861: $r->print($result.&return_to_editor());
1.476 raeburn 5862: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5863: $uploadphase = 'decompress_phase_one';
5864: $r->print(&decompression_phase_one().
5865: &return_to_editor());
5866: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5867: $uploadphase = 'decompress_phase_two';
5868: $r->print(&decompression_phase_two().
5869: &return_to_editor());
1.329 droeschl 5870: }
5871: }
5872:
1.484 raeburn 5873: if ($allowed && $toolsflag) {
5874: $r->print(&startContentScreen('tools'));
1.611 raeburn 5875: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5876: $r->print(&endContentScreen());
5877: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5878: # -----------------------------------------------------------------------------
5879: my %lt=&Apache::lonlocal::texthash(
5880: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5881: 'upfi' => 'Upload File',
1.553 raeburn 5882: 'upld' => 'Upload Content',
1.329 droeschl 5883: 'srch' => 'Search',
5884: 'impo' => 'Import',
1.487 raeburn 5885: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5886: 'impm' => 'Import from Assembled Map',
1.630 raeburn 5887: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5888: 'extr' => 'External Resource',
5889: 'extt' => 'External Tool',
1.329 droeschl 5890: 'selm' => 'Select Map',
5891: 'load' => 'Load Map',
5892: 'newf' => 'New Folder',
5893: 'newp' => 'New Composite Page',
5894: 'syll' => 'Syllabus',
1.425 raeburn 5895: 'navc' => 'Table of Contents',
1.343 biermanm 5896: 'sipa' => 'Simple Course Page',
1.329 droeschl 5897: 'sipr' => 'Simple Problem',
1.630 raeburn 5898: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5899: 'stpr' => 'Standard Problem',
5900: 'news' => 'New sub-directory',
5901: 'crpr' => 'Create Problem',
1.329 droeschl 5902: 'drbx' => 'Drop Box',
1.451 www 5903: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5904: 'bull' => 'Discussion Board',
1.347 weissno 5905: 'mypi' => 'My Personal Information Page',
1.353 weissno 5906: 'grpo' => 'Group Portfolio',
1.329 droeschl 5907: 'rost' => 'Course Roster',
1.528 raeburn 5908: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5909: 'imsf' => 'IMS Upload',
5910: 'imsl' => 'Upload IMS package',
1.501 raeburn 5911: 'cms' => 'Origin of IMS package',
5912: 'se' => 'Select',
1.329 droeschl 5913: 'file' => 'File',
5914: 'title' => 'Title',
1.606 raeburn 5915: 'addp' => 'Add Placeholder to course?',
5916: 'uste' => 'Use Template?',
5917: 'fnam' => 'File Name:',
5918: 'loca' => 'Location:',
5919: 'dire' => 'Directory:',
5920: 'cate' => 'Category:',
5921: 'tmpl' => 'Template:',
1.329 droeschl 5922: 'comment' => 'Comment',
1.403 raeburn 5923: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5924: 'bb5' => 'Blackboard 5',
5925: 'bb6' => 'Blackboard 6',
5926: 'angel5' => 'ANGEL 5.5',
5927: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5928: 'yes' => 'Yes',
5929: 'no' => 'No',
1.618 raeburn 5930: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5931: );
1.329 droeschl 5932: # -----------------------------------------------------------------------------
1.595 musolffc 5933:
5934: # Calculate free quota space for a user or course. A javascript function checks
5935: # file size to determine if upload should be allowed.
5936: my $quotatype = 'unofficial';
5937: if ($crstype eq 'Community') {
1.601 raeburn 5938: $quotatype = 'community';
5939: } elsif ($crstype eq 'Placement') {
5940: $quotatype = 'placement';
1.595 musolffc 5941: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5942: $quotatype = 'official';
5943: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5944: $quotatype = 'textbook';
5945: }
5946: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5947: 'course',$quotatype); # expressed in MB
5948: my $current_disk_usage = 0;
5949: foreach my $subdir ('docs','supplemental') {
5950: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5951: "userfiles/$subdir",1); # expressed in kB
5952: }
5953: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5954: my $usage = $current_disk_usage/1024; # in MB
5955: my $quota = $disk_quota;
5956: my $percent;
5957: if ($disk_quota == 0) {
5958: $percent = 100.0;
5959: } else {
1.619 raeburn 5960: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5961: }
5962: $usage = sprintf("%.2f",$usage);
5963: $quota = sprintf("%.2f",$quota);
5964: $percent = sprintf("%.0f",$percent);
5965: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5966: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5967:
1.329 droeschl 5968: my $fileupload=(<<FIUP);
1.605 raeburn 5969: $quotainfo
1.329 droeschl 5970: $lt{'file'}:<br />
1.662 raeburn 5971: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
1.663 raeburn 5972: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5973: FIUP
5974:
5975: my $checkbox=(<<CHBO);
5976: <!-- <label>$lt{'parse'}?
5977: <input type="checkbox" name="parserflag" />
5978: </label> -->
5979: <label>
1.611 raeburn 5980: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5981: </label>
5982: CHBO
1.501 raeburn 5983: my $imsfolder = $env{'form.folder'};
5984: if ($imsfolder eq '') {
5985: $imsfolder = 'default';
5986: }
5987: my $imspform=(<<IMSFORM);
5988: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5989: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5990: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5991: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5992: <legend>$lt{'imsf'}</legend>
5993: $fileupload
5994: <br />
5995: <p>
5996: $lt{'cms'}:
1.611 raeburn 5997: <select name="source" $disabled>
1.501 raeburn 5998: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5999: <option value="bb5">$lt{'bb5'}</option>
6000: <option value="bb6">$lt{'bb6'}</option>
6001: <option value="angel5">$lt{'angel5'}</option>
6002: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 6003: </select>
6004: <input type="hidden" name="folder" value="$imsfolder" />
6005: </p>
6006: <input type="hidden" name="phase" value="one" />
1.611 raeburn 6007: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 6008: </fieldset>
6009: </form>
6010: IMSFORM
1.329 droeschl 6011:
6012: my $fileuploadform=(<<FUFORM);
1.501 raeburn 6013: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6014: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6015: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 6016: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 6017: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6018: <input type="hidden" name="active" value="aa" />
1.595 musolffc 6019: $fileupload
1.329 droeschl 6020: <br />
6021: $lt{'title'}:<br />
1.611 raeburn 6022: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 6023: $pathitem
1.329 droeschl 6024: <input type="hidden" name="cmd" value="upload_default" />
6025: <br />
1.458 raeburn 6026: <span class="LC_nobreak" style="float:left">
1.329 droeschl 6027: $checkbox
6028: </span>
1.501 raeburn 6029: <br clear="all" />
1.611 raeburn 6030: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 6031: </fieldset>
6032: </form>
1.383 tempelho 6033: FUFORM
1.329 droeschl 6034:
1.611 raeburn 6035: my $mapimportjs;
6036: if ($canedit) {
6037: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6038: } else {
6039: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6040: }
1.502 raeburn 6041: my $importpubform=(<<SEDFFORM);
1.514 raeburn 6042: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 6043: $lt{'impm'}</a>$help{'Load_Map'}
6044: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 6045: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 6046: <legend>$lt{'impm'}</legend>
1.371 tempelho 6047: <input type="hidden" name="active" value="bb" />
1.502 raeburn 6048: $lt{'copm'}<br />
6049: <span class="LC_nobreak">
6050: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 6051: onfocus="this.blur();$mapimportjs" $disabled />
6052: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6053: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 6054: </fieldset>
6055: </form>
6056:
1.383 tempelho 6057: SEDFFORM
1.606 raeburn 6058: my $importcrsresform;
1.608 raeburn 6059: my ($numdirs,$pickfile) =
6060: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
6061: "resize_scrollbox('contentscroll','1','0');",
6062: undef,'res');
1.606 raeburn 6063: if ($pickfile) {
6064: $importcrsresform=(<<CRSFORM);
6065: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
6066: $lt{'imcr'}</a>$help{'Course_Resources'}
6067: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6068: <fieldset id="importcrsresform" style="display: none;">
6069: <legend>$lt{'imcr'}</legend>
6070: <input type="hidden" name="active" value="bb" />
6071: $pickfile
6072: <p>
1.611 raeburn 6073: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 6074: </p>
6075: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 6076: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 6077: </fieldset>
6078: </form>
6079: CRSFORM
6080: }
6081:
1.611 raeburn 6082: my $fromstoredjs;
6083: if ($canedit) {
6084: $fromstoredjs = 'open_StoredLinks_Import()';
6085: } else {
6086: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6087: }
6088:
1.502 raeburn 6089: my @importpubforma = (
1.508 raeburn 6090: { '<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 6091: { '<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 6092: { '<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 6093: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6094: );
6095: if ($pickfile) {
6096: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
6097: }
1.502 raeburn 6098: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 6099: my $extresourcesform =
6100: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 6101: $help{'Adding_External_Resource'},
6102: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 6103: my $exttoolform =
6104: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6105: $help{'Adding_External_Tool'},undef,
6106: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 6107: \%ltitools,$disabled);
1.329 droeschl 6108: if ($allowed) {
1.492 raeburn 6109: my $folder = $env{'form.folder'};
6110: if ($folder eq '') {
6111: $folder='default';
6112: }
1.615 raeburn 6113: if ($canedit) {
6114: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6115: if ($output) {
6116: $r->print($output);
6117: }
1.538 raeburn 6118: }
1.337 ehlerst 6119: $r->print(<<HIDDENFORM);
6120: <form name="renameform" method="post" action="/adm/coursedocs">
6121: <input type="hidden" name="title" />
6122: <input type="hidden" name="cmd" />
6123: <input type="hidden" name="markcopy" />
6124: <input type="hidden" name="copyfolder" />
6125: $containertag
6126: </form>
1.633 raeburn 6127: <form name="aliasform" method="post" action="/adm/coursedocs">
6128: <input type="hidden" name="alias" />
6129: <input type="hidden" name="cmd" />
6130: $containertag
6131: </form>
1.484 raeburn 6132:
1.337 ehlerst 6133: HIDDENFORM
1.508 raeburn 6134: $r->print(&makesimpleeditform($pathitem)."\n".
6135: &makedocslogform($pathitem."\n".
1.484 raeburn 6136: '<input type="hidden" name="folder" value="'.
6137: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6138: }
1.442 www 6139:
6140: # Generate the tabs
1.510 raeburn 6141: my ($mode,$needs_end);
1.472 raeburn 6142: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6143: my @folders = split('&',$env{'form.folderpath'});
6144: unless (@folders > 2) {
6145: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6146: $needs_end = 1;
6147: }
1.472 raeburn 6148: } else {
1.484 raeburn 6149: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6150: $needs_end = 1;
1.472 raeburn 6151: }
1.443 www 6152:
1.442 www 6153: #
1.622 raeburn 6154: my $hostname = $r->hostname();
1.442 www 6155: my $savefolderpath;
6156:
1.395 raeburn 6157: if ($allowed) {
1.329 droeschl 6158: my $folder=$env{'form.folder'};
1.615 raeburn 6159: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6160: $folder='default';
1.356 tempelho 6161: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6162: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6163: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6164: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6165: }
6166: my $postexec='';
6167: if ($folder eq 'default') {
1.653 raeburn 6168: my $windowname = 'loncapaclient';
6169: if ($env{'request.lti.login'}) {
6170: $windowname .= 'lti';
6171: }
1.372 bisitz 6172: $r->print('<script type="text/javascript">'."\n"
6173: .'// <![CDATA['."\n"
1.653 raeburn 6174: .'this.window.name="'.$windowname.'";'."\n"
1.372 bisitz 6175: .'// ]]>'."\n"
6176: .'</script>'."\n"
1.369 bisitz 6177: );
1.329 droeschl 6178: } else {
6179: #$postexec='self.close();';
6180: }
1.504 raeburn 6181: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6182: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6183: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6184:
6185: my $newnavform=(<<NNFORM);
6186: <form action="/adm/coursedocs" method="post" name="newnav">
1.655 raeburn 6187: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6188: $pathitem
1.329 droeschl 6189: <input type="hidden" name="importdetail"
6190: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6191: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6192: $help{'Navigate_Content'}
6193: </form>
6194: NNFORM
6195: my $newsmppageform=(<<NSPFORM);
6196: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.655 raeburn 6197: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6198: $pathitem
1.329 droeschl 6199: <input type="hidden" name="importdetail" value="" />
1.423 onken 6200: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6201: $help{'Simple Page'}
1.329 droeschl 6202: </form>
6203: NSPFORM
6204:
6205: my $newsmpproblemform=(<<NSPROBFORM);
6206: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.655 raeburn 6207: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6208: $pathitem
1.329 droeschl 6209: <input type="hidden" name="importdetail" value="" />
1.423 onken 6210: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6211: $help{'Simple_Problem'}
1.329 droeschl 6212: </form>
6213:
6214: NSPROBFORM
6215:
6216: my $newdropboxform=(<<NDBFORM);
6217: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.655 raeburn 6218: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6219: $pathitem
1.329 droeschl 6220: <input type="hidden" name="importdetail" value="" />
1.423 onken 6221: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6222: $help{'Dropbox'}
1.344 bisitz 6223: </form>
1.329 droeschl 6224: NDBFORM
6225:
6226: my $newexuploadform=(<<NEXUFORM);
6227: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.655 raeburn 6228: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6229: $pathitem
1.329 droeschl 6230: <input type="hidden" name="importdetail" value="" />
1.423 onken 6231: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6232: $help{'Score_Upload_Form'}
6233: </form>
6234: NEXUFORM
6235:
6236: my $newbulform=(<<NBFORM);
6237: <form action="/adm/coursedocs" method="post" name="newbul">
1.655 raeburn 6238: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6239: $pathitem
1.329 droeschl 6240: <input type="hidden" name="importdetail" value="" />
1.423 onken 6241: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6242: $help{'Bulletin Board'}
6243: </form>
6244: NBFORM
6245:
6246: my $newaboutmeform=(<<NAMFORM);
6247: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.655 raeburn 6248: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6249: $pathitem
1.329 droeschl 6250: <input type="hidden" name="importdetail"
6251: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6252: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6253: $help{'My Personal Information Page'}
1.329 droeschl 6254: </form>
6255: NAMFORM
6256:
6257: my $newaboutsomeoneform=(<<NASOFORM);
6258: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.655 raeburn 6259: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6260: $pathitem
1.329 droeschl 6261: <input type="hidden" name="importdetail" value="" />
1.423 onken 6262: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6263: </form>
6264: NASOFORM
6265:
6266: my $newrosterform=(<<NROSTFORM);
6267: <form action="/adm/coursedocs" method="post" name="newroster">
1.655 raeburn 6268: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6269: $pathitem
1.329 droeschl 6270: <input type="hidden" name="importdetail"
6271: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6272: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6273: $help{'Course_Roster'}
1.329 droeschl 6274: </form>
6275: NROSTFORM
6276:
1.534 raeburn 6277: my $newwebpage;
6278: if ($folder =~ /^default_?(\d*)$/) {
6279: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6280: if ($1) {
6281: $newwebpage .= $1;
6282: } else {
6283: $newwebpage .= 'default';
6284: }
6285: $newwebpage .= '/new.html';
6286: }
6287: my $newwebpageform =(<<NWEBFORM);
6288: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.655 raeburn 6289: <input type="hidden" name="active" value="ff" />
1.534 raeburn 6290: $pathitem
6291: <input type="hidden" name="importdetail" value="$newwebpage" />
6292: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6293: $help{'Web_Page'}
1.534 raeburn 6294: </form>
6295: NWEBFORM
1.604 raeburn 6296:
1.606 raeburn 6297: my @ids=&Apache::lonnet::current_machine_ids();
6298: my %select_menus;
6299: my $numauthor = 0;
6300: my $numcrsdirs = 0;
6301: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6302: if ($env{'user.author'}) {
6303: $numauthor ++;
6304: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6305: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6306: my $is_home = 1;
6307: my %subdirs;
1.608 raeburn 6308: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6309: $select_menus{'author'}->{'default'} = '/';
6310: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6311: my @ordered = ('/');
6312: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6313: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6314: push(@ordered,$relpath);
6315: }
6316: $select_menus{'author'}->{'order'} = \@ordered;
6317: } else {
6318: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6319: $select_menus{'author'}->{'default'} = 'switch';
6320: $select_menus{'author'}->{'order'} = ['switch'];
6321: }
6322: }
6323: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6324: ['active'],['ca','aa']);
6325: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6326: my %by_roletype;
6327: if (keys(%roleshash)) {
6328: foreach my $entry (keys(%roleshash)) {
6329: my ($auname,$audom,$roletype) = split(/:/,$entry);
6330: my $key = $entry;
6331: $key =~ s/:/___/g;
6332: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6333: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6334: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6335: if (grep(/^\Q$rolehome\E$/,@ids)) {
6336: my $is_home = 1;
6337: my (%subdirs,@ordered);
6338: my $toppath="/priv/$audom/$auname";
1.608 raeburn 6339: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6340: $select_menus{$key}->{'default'} = '/';
6341: $select_menus{$key}->{'select2'}->{'/'} = '/';
6342: my @ordered = ('/');
6343: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6344: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6345: push(@ordered,$relpath);
6346: }
6347: $select_menus{$key}->{'order'} = \@ordered;
6348: } else {
6349: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6350: $select_menus{$key}->{'default'} = 'switch';
6351: $select_menus{$key}->{'order'} = ['switch'];
6352: }
6353: $numauthor ++;
6354: }
6355: }
1.631 raeburn 6356: my ($pickdir,$showtitle);
1.606 raeburn 6357: if ($numauthor) {
6358: my @order;
6359: my $defrole;
6360: if ($env{'user.author'}) {
6361: push(@order,'author');
6362: $defrole = 'author';
6363: }
6364: if (keys(%by_roletype)) {
6365: foreach my $possrole ('ca','aa') {
6366: if (ref($by_roletype{$possrole}) eq 'HASH') {
6367: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6368: unless ($defrole) {
6369: $defrole = $author;
6370: }
6371: push(@order,$author.'___'.$possrole);
6372: }
6373: }
6374: }
6375: }
6376: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6377: if (grep(/^\Q$crshome\E$/,@ids)) {
6378: my $is_home = 1;
6379: my %subdirs;
6380: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6381: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6382: $numcrsdirs = keys(%subdirs);
6383: $select_menus{'course'}->{'default'} = '/';
6384: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6385: my @ordered = ('/');
6386: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6387: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6388: push(@ordered,$relpath);
6389: }
6390: $select_menus{'course'}->{'order'} = \@ordered;
6391: } else {
6392: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6393: $select_menus{'course'}->{'default'} = 'switch';
6394: $select_menus{'course'}->{'order'} = ['switch'];
6395: }
6396: push(@order,'course');
6397: $pickdir = $lt{'loca'}.
6398: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6399: $defrole,'authorrole','authorpath',
6400: \%select_menus,\@order,'toggleCrsResTitle();',
6401: '','priv').'<br />';
6402: $showtitle = 'none';
6403: } else {
6404: my $is_home;
6405: $showtitle = 'inline';
6406: if (grep(/^\Q$crshome\E$/,@ids)) {
6407: $is_home = 1;
6408: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6409: my $toppath="/priv/$coursedom/$coursenum'}";
6410: my %subdirs;
1.608 raeburn 6411: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6412: $numcrsdirs = keys(%subdirs);
6413: if ($numcrsdirs) {
6414: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6415: '<option value="/">/</option>'."\n";
6416: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6417: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6418: }
6419: $pickdir .= '</select>';
6420: } else {
6421: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6422: }
6423: }
6424: }
6425:
6426: my %seltemplate_menus;
6427: my @files = &Apache::lonhomework::get_template_list('problem');
6428: my @noexamplelink = ('blank.problem','blank.library','script.library');
6429: my $currentcategory = '';
6430: my @ordered = ('');
6431: my %templatehelp;
6432: my $defcategory = '';
6433: my @catorder = ($defcategory);
6434: $seltemplate_menus{$defcategory}->{'order'} = [''];
6435: $seltemplate_menus{$defcategory}->{'text'} = '';
6436: foreach my $file (@files) {
6437: if (ref($file) eq 'ARRAY') {
6438: my ($path,$title,$category,$help) = @{$file};
6439: next if ($title !~ /\S/);
6440: if (&js_escape($category) ne $currentcategory) {
6441: $currentcategory = &js_escape($category);
6442: push(@catorder,&js_escape($currentcategory));
6443: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6444: $seltemplate_menus{$currentcategory}->{'default'} = '';
6445: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6446: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6447: }
6448: if ($path) {
6449: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6450: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6451: if ($help) {
6452: $templatehelp{$path} = $help;
6453: }
6454: }
6455: }
6456: }
6457:
6458: my $templates = $lt{'cate'}.' '.
6459: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6460: $defcategory,'tempcategory','template',
6461: \%seltemplate_menus,\@catorder,
6462: "resize_scrollbox('contentscroll','1','0');",
6463: "toggleExampleText();",'template').'<br />';
6464: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6465: '<span id="newresexample">'.&mt('Example').'<span></a>';
6466: my $crsresform=(<<RESFORM);
6467: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6468: $lt{'stpr'}</a>$help{'Course_Resource'}
6469: <form action="/adm/coursedocs" method="post" name="courseresform">
6470: <fieldset id="crsresform" style="display:none;">
6471: <legend>$lt{'stpr'}</legend>
1.655 raeburn 6472: <input type="hidden" name="active" value="bb" />
1.606 raeburn 6473: <p>
6474: $pickdir
6475: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6476: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6477:
1.611 raeburn 6478: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6479: </span><span id="newsubdir"></span>
6480: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6481: </p>
6482: $lt{'fnam'}
1.611 raeburn 6483: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6484: <p>
6485: <div id="newresource" style="display:$showtitle">
6486: $lt{'addp'}
1.611 raeburn 6487: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6488: $lt{'no'}</label>
1.611 raeburn 6489: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6490: $lt{'yes'}</label>
6491: <span id="newrestitle"></span>
1.611 raeburn 6492: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6493: </div>
6494: </p>
6495: <p>
6496: $lt{'uste'}
1.611 raeburn 6497: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6498: $lt{'no'}</label>
1.611 raeburn 6499: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6500: $lt{'yes'}</label>
6501: <div id="newrestemplate" style="display:none">
6502: $templates
6503: $templatepreview
6504: </div>
6505: </p>
6506: <span class="LC_nobreak">
6507: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6508: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6509: </span>
6510: </fieldset>
6511: </form>
6512:
6513: RESFORM
1.534 raeburn 6514:
1.342 ehlerst 6515: my $specialdocumentsform;
1.383 tempelho 6516: my @specialdocumentsforma;
1.451 www 6517: my $gradingform;
6518: my @gradingforma;
6519: my $communityform;
6520: my @communityforma;
1.351 ehlerst 6521: my $newfolderform;
1.390 tempelho 6522: my $newfolderb;
1.342 ehlerst 6523:
1.451 www 6524: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6525:
1.329 droeschl 6526: my $newpageform=(<<NPFORM);
6527: <form action="/adm/coursedocs" method="post" name="newpage">
6528: <input type="hidden" name="folderpath" value="$path" />
6529: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6530: <input type="hidden" name="active" value="ee" />
1.423 onken 6531: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6532: $help{'Adding_Pages'}
1.329 droeschl 6533: </form>
6534: NPFORM
1.390 tempelho 6535:
6536:
1.351 ehlerst 6537: $newfolderform=(<<NFFORM);
1.329 droeschl 6538: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6539: $pathitem
1.329 droeschl 6540: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6541: <input type="hidden" name="active" value="" />
1.422 onken 6542: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6543: </form>
6544: NFFORM
6545:
6546: my $newsylform=(<<NSYLFORM);
6547: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6548: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6549: $pathitem
1.329 droeschl 6550: <input type="hidden" name="importdetail"
6551: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6552: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6553: $help{'Syllabus'}
1.383 tempelho 6554:
1.329 droeschl 6555: </form>
6556: NSYLFORM
1.364 bisitz 6557:
1.329 droeschl 6558: my $newgroupfileform=(<<NGFFORM);
6559: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.655 raeburn 6560: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6561: $pathitem
1.329 droeschl 6562: <input type="hidden" name="importdetail"
6563: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6564: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6565: $help{'Group Portfolio'}
1.329 droeschl 6566: </form>
6567: NGFFORM
1.383 tempelho 6568: @specialdocumentsforma=(
1.421 onken 6569: {'<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 6570: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6571: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6572: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6573: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6574: );
6575: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6576:
1.655 raeburn 6577: my @external = (
6578: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
1.519 raeburn 6579: );
1.598 raeburn 6580: if (keys(%ltitools)) {
1.655 raeburn 6581: push(@external,
6582: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6583: );
1.598 raeburn 6584: }
1.655 raeburn 6585: my $externalform = &create_form_ul(&create_list_elements(@external));
6586:
6587: my @importdoc = ();
1.519 raeburn 6588: unless ($container eq 'page') {
6589: push(@importdoc,
6590: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6591: );
6592: }
6593: push(@importdoc,
1.558 raeburn 6594: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6595: );
1.501 raeburn 6596: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6597:
1.451 www 6598: @gradingforma=(
6599: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6600: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6601: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6602: {'<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 6603: );
6604: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6605:
6606: @communityforma=(
6607: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6608: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6609: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6610: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6611: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6612: );
6613: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6614:
1.330 tempelho 6615: my %orderhash = (
1.553 raeburn 6616: 'aa' => ['Upload',$fileuploadform],
6617: 'bb' => ['Import',$importpubform],
1.655 raeburn 6618: 'cc' => ['External',$externalform],
6619: 'dd' => ['Grading',$gradingform],
1.330 tempelho 6620: );
1.519 raeburn 6621: unless ($container eq 'page') {
1.434 raeburn 6622: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.655 raeburn 6623: $orderhash{'ee'} = ['Collaboration',$communityform];
6624: $orderhash{'ff'} = ['Other',$specialdocumentsform];
1.434 raeburn 6625: }
6626:
1.341 ehlerst 6627: $hadchanges=0;
1.484 raeburn 6628: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6629: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6630: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6631: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6632: undef($navmap);
1.443 www 6633: if ($error) {
6634: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6635: }
1.639 raeburn 6636: if ($hadchanges) {
6637: unless (&is_hash_old()) {
1.638 raeburn 6638: &mark_hash_old();
6639: }
6640: }
1.341 ehlerst 6641:
1.443 www 6642: &changewarning($r,'');
6643: }
1.458 raeburn 6644: }
1.442 www 6645:
1.443 www 6646: # Supplemental documents start here
6647:
1.329 droeschl 6648: my $folder=$env{'form.folder'};
1.443 www 6649: unless ($supplementalflag) {
1.329 droeschl 6650: $folder='supplemental';
6651: }
6652: if ($folder =~ /^supplemental$/ &&
6653: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6654: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6655: } elsif ($allowed) {
1.356 tempelho 6656: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6657: }
1.508 raeburn 6658: $pathitem = '<input type="hidden" name="folderpath" value="'.
6659: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6660: if ($allowed) {
6661: my $folderseq=
1.504 raeburn 6662: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6663:
6664: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6665: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6666: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6667: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6668: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6669: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6670: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6671: $fileupload
6672: <br />
6673: <br />
6674: <span class="LC_nobreak">
6675: $checkbox
6676: </span>
6677: <br /><br />
6678: $lt{'comment'}:<br />
1.383 tempelho 6679: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6680: <br />
1.508 raeburn 6681: $pathitem
1.329 droeschl 6682: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6683: <input type='submit' value="$lt{'upld'}" />
6684: </form>
1.329 droeschl 6685: SUPDOCFORM
6686:
6687: my $supnewfolderform=(<<SNFFORM);
6688: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6689: <input type="hidden" name="active" value="" />
1.508 raeburn 6690: $pathitem
1.329 droeschl 6691: <input type="hidden" name="importdetail" value="" />
1.423 onken 6692: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6693: $help{'Adding_Folders'}
1.329 droeschl 6694: </form>
6695: SNFFORM
1.383 tempelho 6696:
1.510 raeburn 6697: my $supextform =
6698: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6699: $help{'Adding_External_Resource'},
6700: undef,undef,undef,undef,undef,undef,
6701: $disabled);
1.329 droeschl 6702:
1.598 raeburn 6703: my $supexttoolform =
6704: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6705: $help{'Adding_External_Tool'},
6706: undef,undef,'tool',$coursedom,
1.611 raeburn 6707: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6708:
1.329 droeschl 6709: my $supnewsylform=(<<SNSFORM);
6710: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6711: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6712: $pathitem
1.329 droeschl 6713: <input type="hidden" name="importdetail"
6714: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6715: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6716: $help{'Syllabus'}
6717: </form>
6718: SNSFORM
6719:
6720: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6721: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6722: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6723: $pathitem
1.329 droeschl 6724: <input type="hidden" name="importdetail"
6725: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6726: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6727: $help{'My Personal Information Page'}
1.329 droeschl 6728: </form>
6729: SNAMFORM
6730:
1.534 raeburn 6731: my $supwebpage;
6732: if ($folder =~ /^supplemental_?(\d*)$/) {
6733: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6734: if ($1) {
6735: $supwebpage .= $1;
6736: } else {
6737: $supwebpage .= 'default';
6738: }
6739: $supwebpage .= '/new.html';
6740: }
6741: my $supwebpageform =(<<SWEBFORM);
6742: <form action="/adm/coursedocs" method="post" name="supwebpage">
6743: <input type="hidden" name="active" value="cc" />
6744: $pathitem
6745: <input type="hidden" name="importdetail" value="$supwebpage" />
6746: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6747: $help{'Web_Page'}
1.534 raeburn 6748: </form>
6749: SWEBFORM
6750:
1.333 muellerd 6751:
1.383 tempelho 6752: my @specialdocs = (
1.618 raeburn 6753: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6754: =>$supnewsylform},
1.611 raeburn 6755: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6756: =>$supnewaboutmeform},
1.534 raeburn 6757: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6758:
1.383 tempelho 6759: );
1.655 raeburn 6760: my @supexternal = (
6761: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6762: =>$supextform});
1.598 raeburn 6763: if (keys(%ltitools)) {
1.655 raeburn 6764: push(@supexternal,
6765: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
1.598 raeburn 6766: =>$supexttoolform});
6767: }
1.655 raeburn 6768: my @supimportdoc = (
1.598 raeburn 6769: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6770: =>$supupdocform},
1.598 raeburn 6771: );
1.501 raeburn 6772:
6773: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6774: my %suporderhash = (
1.390 tempelho 6775: '00' => ['Supnewfolder', $supnewfolderform],
1.655 raeburn 6776: 'dd' => ['Upload',$supupdocform],
6777: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
1.553 raeburn 6778: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6779: );
1.443 www 6780: if ($supplementalflag) {
1.458 raeburn 6781: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6782: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6783: \%ltitools,$canedit,$hostname);
1.443 www 6784: if ($error) {
6785: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6786: } else {
6787: if ($suppchanges) {
6788: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6789: my @ids=&Apache::lonnet::current_machine_ids();
6790: foreach my $server (keys(%servers)) {
6791: next if (grep(/^\Q$server\E$/,@ids));
6792: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6793: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6794: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6795: }
6796: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6797: undef($suppchanges);
1.630 raeburn 6798: }
6799: }
1.393 raeburn 6800: }
1.443 www 6801: } elsif ($supplementalflag) {
1.458 raeburn 6802: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6803: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6804: if ($error) {
6805: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6806: }
1.393 raeburn 6807: }
1.389 tempelho 6808:
1.510 raeburn 6809: if ($needs_end) {
6810: $r->print(&endContentScreen());
6811: }
1.383 tempelho 6812:
1.329 droeschl 6813: if ($allowed) {
6814: $r->print('
6815: <form method="post" name="extimport" action="/adm/coursedocs">
6816: <input type="hidden" name="title" />
6817: <input type="hidden" name="url" />
6818: <input type="hidden" name="useform" />
6819: <input type="hidden" name="residx" />
6820: </form>');
6821: }
1.484 raeburn 6822: } elsif ($showdoc) {
1.329 droeschl 6823: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6824: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6825: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6826: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6827: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6828: }
6829: }
1.630 raeburn 6830: unless ($noendpage) {
1.606 raeburn 6831: $r->print(&Apache::loncommon::end_page());
6832: }
1.329 droeschl 6833: return OK;
1.364 bisitz 6834: }
1.329 droeschl 6835:
1.440 raeburn 6836: sub embedded_form_elems {
6837: my ($phase,$primaryurl,$newidx) = @_;
6838: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 6839: $newidx =~s /\D+//g;
1.440 raeburn 6840: return <<STATE;
6841: <input type="hidden" name="folderpath" value="$folderpath" />
6842: <input type="hidden" name="cmd" value="upload_embedded" />
6843: <input type="hidden" name="newidx" value="$newidx" />
6844: <input type="hidden" name="phase" value="$phase" />
6845: <input type="hidden" name="primaryurl" value="$primaryurl" />
6846: STATE
6847: }
6848:
6849: sub embedded_destination {
6850: my $folder=$env{'form.folder'};
6851: my $destination = 'docs/';
6852: if ($folder =~ /^supplemental/) {
6853: $destination = 'supplemental/';
6854: }
6855: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6856: $destination .= 'default/';
6857: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6858: $destination .= $2.'/';
6859: }
1.634 raeburn 6860: my $newidx = $env{'form.newidx'};
6861: $newidx =~s /\D+//g;
6862: if ($newidx) {
6863: $destination .= $newidx;
6864: }
1.440 raeburn 6865: my $dir_root = '/userfiles';
6866: return ($destination,$dir_root);
6867: }
6868:
6869: sub return_to_editor {
6870: my $actionurl = '/adm/coursedocs';
6871: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6872: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6873: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6874: '</a></p>';
6875: }
6876:
1.476 raeburn 6877: sub decompression_info {
6878: my ($destination,$dir_root) = &embedded_destination();
6879: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6880: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6881: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6882: my $container='sequence';
1.480 raeburn 6883: my ($pathitem,$hiddenelem);
1.583 raeburn 6884: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6885: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6886: $container='page';
6887: }
1.480 raeburn 6888: unshift(@hiddens,$pathitem);
6889: foreach my $item (@hiddens) {
1.634 raeburn 6890: if ($item eq 'newidx') {
6891: next if ($env{'form.'.$item} =~ /\D/);
6892: }
1.480 raeburn 6893: if ($env{'form.'.$item}) {
6894: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6895: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6896: }
1.477 raeburn 6897: }
1.476 raeburn 6898: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6899: $hiddenelem);
6900: }
6901:
6902: sub decompression_phase_one {
6903: my ($dir,$file,$warning,$error,$output);
6904: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6905: &decompression_info();
1.490 raeburn 6906: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6907: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6908: } else {
6909: my $file = $1;
1.630 raeburn 6910: $output =
1.481 raeburn 6911: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6912: $destination,$dir_root,
6913: $hiddenelem);
6914: if ($env{'form.autoextract_camtasia'}) {
6915: $output .= &remove_archive($docudom,$docuname,$container);
6916: }
1.476 raeburn 6917: }
6918: if ($error) {
6919: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6920: $error.'</p>'."\n";
6921: }
6922: if ($warning) {
6923: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6924: }
6925: return $output;
6926: }
6927:
6928: sub decompression_phase_two {
6929: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6930: &decompression_info();
1.481 raeburn 6931: my $output;
1.480 raeburn 6932: if ($env{'form.archivedelete'}) {
1.481 raeburn 6933: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6934: }
6935: $output .=
1.481 raeburn 6936: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6937: $destination,$dir_root,$hiddenelem);
6938: return $output;
6939: }
6940:
1.480 raeburn 6941: sub remove_archive {
6942: my ($docudom,$docuname,$container) = @_;
6943: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6944: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6945: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6946: if ($fatal) {
6947: if ($container eq 'page') {
6948: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6949: } else {
6950: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6951: }
1.583 raeburn 6952: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6953: } else {
6954: my $currcmd = $env{'form.cmd'};
6955: my $position = $env{'form.position'};
1.583 raeburn 6956: my $archiveidx = $position;
1.563 raeburn 6957: if ($position > 0) {
1.583 raeburn 6958: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6959: $archiveidx = $position-1;
6960: }
6961: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6962: my ($title,$url,@rrest) =
1.583 raeburn 6963: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6964: if ($url eq $env{'form.archiveurl'}) {
6965: if (&handle_edit_cmd($docuname,$docudom)) {
6966: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6967: if ($fatal) {
6968: if ($container eq 'page') {
6969: $delwarning = &mt('An error occurred updating the contents of the current page.');
6970: } else {
6971: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6972: }
1.480 raeburn 6973: } else {
1.583 raeburn 6974: $delresult = &mt('Archive file removed.');
1.480 raeburn 6975: }
6976: }
1.583 raeburn 6977: } else {
6978: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6979: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6980: }
6981: }
6982: $env{'form.cmd'} = $currcmd;
6983: }
6984: if ($delwarning) {
6985: $output = '<p class="LC_warning">'.
6986: $delwarning.
6987: '</p>';
6988: }
6989: if ($delresult) {
6990: $output .= '<p class="LC_info">'.
6991: $delresult.
6992: '</p>';
6993: }
1.481 raeburn 6994: return $output;
1.480 raeburn 6995: }
6996:
1.484 raeburn 6997: sub generate_admin_menu {
1.611 raeburn 6998: my ($crstype,$canedit) = @_;
1.484 raeburn 6999: my $lc_crstype = lc($crstype);
7000: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 7001: my %lt= ( # do not translate here
1.484 raeburn 7002: 'vc' => 'Verify Content',
7003: 'cv' => 'Check/Set Resource Versions',
7004: 'ls' => 'List Resource Identifiers',
1.651 raeburn 7005: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
1.484 raeburn 7006: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 7007: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 7008: );
1.484 raeburn 7009: my ($candump,$dumpurl);
7010: if ($home + $other > 0) {
7011: $candump = 'F';
7012: if ($home) {
7013: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7014: } else {
7015: my @hosts;
7016: foreach my $aurole (keys(%outhash)) {
7017: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7018: push(@hosts,$outhash{$aurole});
1.538 raeburn 7019: }
1.484 raeburn 7020: }
7021: if (@hosts == 1) {
7022: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7023: '&role='.
7024: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7025: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7026: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7027: } else {
7028: $dumpurl = "javascript:choose_switchserver_window()";
7029: }
7030: }
7031: }
7032: my @menu=
7033: ({ categorytitle=>'Administration',
7034: items =>[
7035: { linktext => $lt{'vc'},
7036: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7037: permission => 'F',
1.571 raeburn 7038: help => 'Docs_Verify_Content',
1.484 raeburn 7039: icon => 'verify.png',
7040: linktitle => 'Verify contents can be retrieved/rendered',
7041: },
7042: { linktext => $lt{'cv'},
7043: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7044: permission => 'F',
1.571 raeburn 7045: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 7046: icon => 'resversion.png',
7047: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7048: },
7049: { linktext => $lt{'ls'},
7050: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7051: permission => 'F',
7052: #help => '',
7053: icon => 'symbs.png',
7054: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7055: },
1.651 raeburn 7056: { linktext => $lt{'ct'},
7057: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7058: permission => 'F',
7059: help => 'Docs_Short_URLs',
7060: icon => 'shorturls.png',
7061: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7062: },
1.484 raeburn 7063: ]
1.611 raeburn 7064: });
7065: if ($canedit) {
7066: push(@menu,
1.484 raeburn 7067: { categorytitle=>'Export',
7068: items =>[
7069: { linktext => $lt{'imse'},
7070: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7071: permission => 'F',
7072: help => 'Docs_Export_Course_Docs',
7073: icon => 'imsexport.png',
7074: linktitle => $lt{'imse'},
7075: },
7076: { linktext => $lt{'dcd'},
7077: url => $dumpurl,
7078: permission => $candump,
1.571 raeburn 7079: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 7080: icon => 'dump.png',
7081: linktitle => $lt{'dcd'},
7082: },
7083: ]
7084: });
1.611 raeburn 7085: }
1.484 raeburn 7086: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7087: '<input type="hidden" id="dummy" />'."\n".
7088: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7089: '</form>';
1.329 droeschl 7090: }
7091:
7092: sub generate_edit_table {
1.538 raeburn 7093: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 7094: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 7095: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 7096: my %orderhash = %{$orderhash_ref};
1.611 raeburn 7097: my ($form, $activetab, $active, $disabled);
1.570 raeburn 7098: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 7099: $activetab = $env{'form.active'};
7100: }
1.611 raeburn 7101: unless ($canedit) {
7102: $disabled = ' disabled="disabled"';
7103: }
1.472 raeburn 7104: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 7105: my $backtext = &mt('Exit Editor');
1.458 raeburn 7106: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 7107: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7108: '<li class="goback">'.
1.546 raeburn 7109: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 7110: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7111: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7112: '<li>'.
7113: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7114: &mt('Undo Delete').'</a></li>'."\n";
7115: if ($env{'form.docslog'}) {
7116: $form .= '<li class="active">';
7117: } else {
7118: $form .= '<li>';
7119: }
7120: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7121: &mt('History').'</a></li>'."\n";
7122: if ($env{'form.docslog'}) {
7123: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7124: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 7125: }
1.458 raeburn 7126: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 7127: if($name ne '00'){
1.371 tempelho 7128: if($activetab eq '' || $activetab ne $name){
7129: $active = '';
7130: }elsif($activetab eq $name){
7131: $active = 'class="active"';
7132: }
1.458 raeburn 7133: $form .= '<li style="float:right" '.$active
1.484 raeburn 7134: .' 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 7135: } else {
1.570 raeburn 7136: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 7137:
7138: }
1.329 droeschl 7139: }
1.484 raeburn 7140: $form .= '</ul>'."\n";
7141: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 7142:
7143: if ($to_show ne '') {
1.538 raeburn 7144: my $saveform;
7145: if ($need_save) {
7146: my $button = &mt('Make changes');
7147: my $path;
7148: if ($env{'form.folderpath'}) {
7149: $path =
7150: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7151: }
7152: $saveform = <<"END";
7153: <div id="multisave" style="display:none; clear:both;" >
7154: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7155: <input type="hidden" name="folderpath" value="$path" />
7156: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7157: <input type="hidden" name="allhiddenresource" value="" />
7158: <input type="hidden" name="allencrypturl" value="" />
7159: <input type="hidden" name="allrandompick" value="" />
7160: <input type="hidden" name="allrandomorder" value="" />
7161: <input type="hidden" name="changeparms" value="" />
7162: <input type="hidden" name="multiremove" value="" />
7163: <input type="hidden" name="multicut" value="" />
7164: <input type="hidden" name="multicopy" value="" />
7165: <input type="hidden" name="multichange" value="" />
7166: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7167: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7168: </form>
7169: </div>
7170: END
7171: }
7172: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7173: }
1.363 ehlerst 7174: foreach my $field (keys(%orderhash)){
1.390 tempelho 7175: if($field ne '00'){
1.422 onken 7176: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7177: $active = 'style="display: none;float:left"';
1.422 onken 7178: }elsif($activetab eq $field){
1.458 raeburn 7179: $active = 'style="display:block;float:left"';
1.422 onken 7180: }
7181: $form .= '<div id="'.$field.$tid.'"'
7182: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7183: .'</div>'."\n";
1.363 ehlerst 7184: }
7185: }
1.484 raeburn 7186: unless ($env{'form.docslog'}) {
7187: $form .= '</div></div>'."\n";
7188: }
1.329 droeschl 7189: return $form;
7190: }
7191:
7192: sub editing_js {
1.622 raeburn 7193: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7194: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7195: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7196: p_mnf => 'Name of New Folder',
7197: t_mnf => 'New Folder',
7198: p_mnp => 'Name of New Page',
7199: t_mnp => 'New Page',
1.451 www 7200: p_mxu => 'Title for the External Score',
1.349 biermanm 7201: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7202: p_msb => 'Title for the Problem',
7203: p_mdb => 'Title for the Drop Box',
1.336 schafran 7204: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7205: p_mwp => 'Title for Web Page',
1.606 raeburn 7206: p_mnr => 'Title for the Resource',
1.348 weissno 7207: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7208: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7209: p_mab_alrt1 => 'Not a valid user:domain',
7210: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7211: p_chn => 'New Title',
7212: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7213: p_rmr2a => 'Remove',
7214: p_rmr2b => '?',
7215: p_rmr3a => 'Remove those',
7216: p_rmr3b => 'items?',
7217: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7218: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7219: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7220: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7221: p_ctr2a => 'Cut',
7222: p_ctr2b => '?',
7223: p_ctr3a => 'Cut those',
7224: p_ctr3b => 'items?',
1.633 raeburn 7225: setal => 'Enter a (unique) alias',
7226: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7227: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7228: imsfile => 'You must choose an IMS package for import',
7229: imscms => 'You must select which Course Management System was the source of the IMS package',
7230: invurl => 'Invalid URL',
7231: titbl => 'Title is blank',
1.538 raeburn 7232: more => '(More ...)',
7233: less => '(Less ...)',
1.543 raeburn 7234: noor => 'No actions selected or changes to settings specified.',
7235: noch => 'No changes to settings specified.',
7236: noac => 'No actions selected.',
1.606 raeburn 7237: nofi => 'No file selected',
7238: tinc => 'Title in course',
7239: sunm => 'Sub-directory name',
1.618 raeburn 7240: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7241: );
1.594 damieng 7242: &js_escape(\%js_lt);
1.433 raeburn 7243: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7244: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7245: my $main_container_page;
1.519 raeburn 7246: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7247: $main_container_page = 1;
1.434 raeburn 7248: }
1.617 raeburn 7249: my $backtourl;
7250: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7251: my $toplevelsupp = &supplemental_base();
1.433 raeburn 7252:
1.530 raeburn 7253: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7254: my $caller = $1;
1.525 raeburn 7255: if ($caller =~ /^supplemental/) {
7256: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7257: } else {
7258: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7259: $res = &Apache::lonnet::clutter($res);
7260: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7261: my ($url,$anchor);
7262: if ($res =~ /^([^#]+)#([^#]+)$/) {
7263: $url = $1;
7264: $anchor = $2;
7265: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7266: $caller = $1.&escape('#').$anchor;
7267: }
1.614 raeburn 7268: } else {
7269: $url = $res;
1.609 raeburn 7270: }
1.640 raeburn 7271: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7272: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7273: $backtourl .= '?navmap=1';
7274: } else {
7275: $backtourl .= '?symb='.
7276: &HTML::Entities::encode($caller,'<>&"');
7277: }
1.622 raeburn 7278: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7279: if (($ENV{'SERVER_PORT'} == 443) &&
7280: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.657 raeburn 7281: unless (&Apache::lonnet::uses_sts()) {
7282: if ($hostname ne '') {
7283: $backtourl = 'http://'.$hostname.$backtourl;
7284: }
7285: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7286: }
7287: }
1.623 raeburn 7288: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7289: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
1.657 raeburn 7290: unless (&Apache::lonnet::uses_sts()) {
1.658 raeburn 7291: if ($hostname ne '') {
7292: $backtourl = 'http://'.$hostname.$backtourl;
7293: }
7294: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.657 raeburn 7295: }
1.623 raeburn 7296: }
1.622 raeburn 7297: }
1.609 raeburn 7298: if ($anchor ne '') {
7299: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7300: }
1.590 raeburn 7301: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7302: } else {
7303: $backtourl = '/adm/navmaps';
1.525 raeburn 7304: }
7305: }
7306: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7307: $backtourl = '/adm/menu';
7308: } elsif ($supplementalflag) {
1.472 raeburn 7309: $backtourl = '/adm/supplemental';
1.525 raeburn 7310: } else {
7311: $backtourl = '/adm/navmaps';
1.472 raeburn 7312: }
7313:
1.655 raeburn 7314: my $fieldsets = "'doc'";
1.519 raeburn 7315: unless ($main_container_page) {
7316: $fieldsets .=",'ims'";
7317: }
1.655 raeburn 7318: my $extfieldsets = "'ext'";
7319: if ($posslti) {
7320: $extfieldsets .= ",'tool'";
7321: }
1.501 raeburn 7322: if ($supplementalflag) {
1.655 raeburn 7323: $fieldsets = "'suppdoc'";
7324: $extfieldsets = "'suppext'";
1.600 raeburn 7325: if ($posslti) {
1.655 raeburn 7326: $extfieldsets .= ",'supptool'";
1.600 raeburn 7327: }
1.501 raeburn 7328: }
1.655 raeburn 7329:
1.611 raeburn 7330: my $jsmakefunctions;
7331: if ($canedit) {
7332: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7333: function makenewfolder(targetform,folderseq) {
1.594 damieng 7334: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7335: if (foldername) {
7336: targetform.importdetail.value=escape(foldername)+"="+folderseq;
7337: targetform.submit();
7338: }
7339: }
7340:
7341: function makenewpage(targetform,folderseq) {
1.594 damieng 7342: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7343: if (pagename) {
7344: targetform.importdetail.value=escape(pagename)+"="+folderseq;
7345: targetform.submit();
7346: }
7347: }
7348:
7349: function makeexamupload() {
1.594 damieng 7350: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7351: if (title) {
1.329 droeschl 7352: this.document.forms.newexamupload.importdetail.value=
7353: escape(title)+'=/res/lib/templates/examupload.problem';
7354: this.document.forms.newexamupload.submit();
7355: }
7356: }
7357:
7358: function makesmppage() {
1.594 damieng 7359: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7360: if (title) {
1.329 droeschl 7361: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 7362: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7363: this.document.forms.newsmppg.submit();
7364: }
7365: }
7366:
1.534 raeburn 7367: function makewebpage(type) {
1.594 damieng 7368: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7369: var formname;
7370: if (type == 'supp') {
7371: formname = this.document.forms.supwebpage;
7372: } else {
7373: formname = this.document.forms.newwebpage;
7374: }
7375: if (title) {
7376: var webpage = formname.importdetail.value;
7377: formname.importdetail.value = escape(title)+'='+webpage;
7378: formname.submit();
7379: }
7380: }
7381:
1.329 droeschl 7382: function makesmpproblem() {
1.594 damieng 7383: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7384: if (title) {
1.329 droeschl 7385: this.document.forms.newsmpproblem.importdetail.value=
7386: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7387: this.document.forms.newsmpproblem.submit();
7388: }
7389: }
7390:
7391: function makedropbox() {
1.594 damieng 7392: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7393: if (title) {
1.329 droeschl 7394: this.document.forms.newdropbox.importdetail.value=
7395: escape(title)+'=/res/lib/templates/DropBox.problem';
7396: this.document.forms.newdropbox.submit();
7397: }
7398: }
7399:
7400: function makebulboard() {
1.594 damieng 7401: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7402: if (title) {
7403: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7404: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7405: this.document.forms.newbul.submit();
7406: }
7407: }
7408:
7409: function makeabout() {
1.594 damieng 7410: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7411: if (user) {
7412: var comp=new Array();
7413: comp=user.split(':');
7414: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7415: if ((comp[0]) && (comp[1])) {
7416: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7417: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7418: this.document.forms.newaboutsomeone.submit();
7419: } else {
7420: alert("$js_lt{'p_mab_alrt1'}");
7421: }
7422: } else {
7423: alert("$js_lt{'p_mab_alrt2'}");
7424: }
7425: }
7426: }
7427:
7428: function makenew(targetform) {
7429: targetform.submit();
7430: }
7431:
7432: function changename(folderpath,index,oldtitle) {
7433: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7434: if (title) {
7435: this.document.forms.renameform.markcopy.value='';
7436: this.document.forms.renameform.title.value=title;
7437: this.document.forms.renameform.cmd.value='rename_'+index;
7438: this.document.forms.renameform.folderpath.value=folderpath;
7439: this.document.forms.renameform.submit();
7440: }
7441: }
7442:
1.633 raeburn 7443: function setalias(folderpath,index) {
7444: var alias = prompt('$js_lt{"setal"}');
7445: if ((alias != null) && (alias != '')) {
7446: this.document.forms.aliasform.alias.value=alias;
7447: this.document.forms.aliasform.cmd.value='setalias_'+index;
7448: this.document.forms.aliasform.folderpath.value=folderpath;
7449: this.document.forms.aliasform.submit();
7450: }
7451: }
7452:
7453: function delalias(folderpath,index) {
7454: if (confirm('$js_lt{"delal"}')) {
7455: this.document.forms.aliasform.cmd.value='delalias_'+index;
7456: this.document.forms.aliasform.folderpath.value=folderpath;
7457: this.document.forms.aliasform.submit();
7458: }
7459: }
7460:
1.611 raeburn 7461: ENDNEWSCRIPT
7462: } else {
7463: $jsmakefunctions = <<ENDNEWSCRIPT;
7464:
7465: function makenewfolder() {
7466: alert("$js_lt{'edri'}");
7467: }
7468:
7469: function makenewpage() {
7470: alert("$js_lt{'edri'}");
7471: }
7472:
7473: function makeexamupload() {
7474: alert("$js_lt{'edri'}");
7475: }
7476:
7477: function makesmppage() {
7478: alert("$js_lt{'edri'}");
7479: }
7480:
7481: function makewebpage(type) {
7482: alert("$js_lt{'edri'}");
7483: }
7484:
7485: function makesmpproblem() {
7486: alert("$js_lt{'edri'}");
7487: }
7488:
7489: function makedropbox() {
7490: alert("$js_lt{'edri'}");
7491: }
7492:
7493: function makebulboard() {
7494: alert("$js_lt{'edri'}");
7495: }
7496:
7497: function makeabout() {
7498: alert("$js_lt{'edri'}");
7499: }
7500:
7501: function changename() {
7502: alert("$js_lt{'edri'}");
7503: }
7504:
1.633 raeburn 7505: function setalias() {
7506: alert("$js_lt{'edri'}");
7507: }
7508:
7509: function delalias() {
7510: alert("$js_lt{'edri'}");
7511: }
7512:
1.611 raeburn 7513: function makenew() {
7514: alert("$js_lt{'edri'}");
7515: }
7516:
7517: function groupimport() {
7518: alert("$js_lt{'edri'}");
1.335 ehlerst 7519: }
1.611 raeburn 7520:
7521: function groupsearch() {
7522: alert("$js_lt{'edri'}");
1.335 ehlerst 7523: }
1.611 raeburn 7524:
7525: function groupopen(url,recover) {
7526: var options="scrollbars=1,resizable=1,menubar=0";
7527: idxflag=1;
7528: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7529: idx.focus();
1.329 droeschl 7530: }
7531:
1.611 raeburn 7532: ENDNEWSCRIPT
7533:
7534: }
7535: return <<ENDSCRIPT;
7536:
7537: $jsmakefunctions
7538:
1.501 raeburn 7539: function toggleUpload(caller) {
7540: var blocks = Array($fieldsets);
7541: for (var i=0; i<blocks.length; i++) {
7542: var disp = 'none';
7543: if (caller == blocks[i]) {
7544: var curr = document.getElementById('upload'+caller+'form').style.display;
7545: if (curr == 'none') {
7546: disp='block';
7547: }
7548: }
7549: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.655 raeburn 7550: }
7551: resize_scrollbox('contentscroll','1','1');
7552: return;
7553: }
7554:
7555: function toggleExternal(caller) {
7556: var blocks = Array($extfieldsets);
7557: for (var i=0; i<blocks.length; i++) {
7558: var disp = 'none';
7559: if (caller == blocks[i]) {
7560: var curr = document.getElementById('external'+caller+'form').style.display;
7561: if (curr == 'none') {
7562: disp='block';
7563: }
7564: }
7565: document.getElementById('external'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7566: if ((caller == 'tool') || (caller == 'supptool')) {
7567: if (disp == 'block') {
1.655 raeburn 7568: if (document.getElementById('LC_exttoolid')) {
7569: var toolselector = document.getElementById('LC_exttoolid');
1.598 raeburn 7570: var suppflag = 0;
7571: if (caller == 'supptool') {
7572: suppflag = 1;
7573: }
7574: currForm = document.getElementById('new'+caller);
1.655 raeburn 7575: updateExttool(toolselector,currForm,suppflag);
1.598 raeburn 7576: }
7577: }
7578: }
1.501 raeburn 7579: }
1.502 raeburn 7580: resize_scrollbox('contentscroll','1','1');
7581: return;
7582: }
7583:
1.514 raeburn 7584: function toggleMap(caller) {
1.502 raeburn 7585: var disp = 'none';
1.510 raeburn 7586: if (document.getElementById('importmapform')) {
1.514 raeburn 7587: if (caller == 'map') {
7588: var curr = document.getElementById('importmapform').style.display;
7589: if (curr == 'none') {
7590: disp='block';
7591: }
1.510 raeburn 7592: }
7593: document.getElementById('importmapform').style.display=disp;
7594: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7595: }
1.501 raeburn 7596: return;
1.329 droeschl 7597: }
7598:
1.606 raeburn 7599: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7600: var disp = 'none';
7601: if (document.getElementById('crsresform')) {
7602: if (caller == 'res') {
7603: var curr = document.getElementById('crsresform').style.display;
7604: if (curr == 'none') {
7605: disp='block';
7606: numauthor = parseInt(numauthorrole);
7607: if (numauthor > 0) {
7608: document.courseresform.authorrole.selectedIndex = 0;
7609: select1priv_changed();
7610: document.courseresform.authorpath.selectedIndex = 0;
7611: document.courseresform.newresourceadd.selectedIndex = 0;
7612: toggleNewInCourse(document.courseresform);
7613: if (document.getElementById('newresource')) {
7614: document.getElementById('newresource').style.display = 'none';
7615: }
7616: } else {
7617: if (numcrsdirs) {
7618: document.courseresform.authorpath.selectedIndex = 0;
7619: }
7620: }
7621: if (document.courseresform.newresusetemp.length) {
7622: document.courseresform.newresusetemp[0].checked = true;
7623: toggleWithTemplate(document.courseresform);
7624: }
7625: document.courseresform.newresourcename.value = '';
7626: }
7627: }
7628: if (document.courseresform.newsubdir.length) {
7629: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7630: if (document.courseresform.newsubdir[j].value == 0) {
7631: document.courseresform.newsubdir[j].checked = true;
7632: }
7633: break;
7634: }
7635: if (document.getElementById('newsubdirname')) {
7636: document.getElementById('newsubdirname').type = "hidden";
7637: document.getElementById('newsubdirname').value = "";
7638: }
7639: if (document.getElementById('newsubdir')) {
7640: document.getElementById('newsubdir').innerHTML = "";
7641: }
7642: }
7643: document.getElementById('crsresform').style.display=disp;
7644: resize_scrollbox('contentscroll','1','0');
7645: }
7646: return;
7647: }
7648:
7649: function toggleNewsubdir(form) {
7650: if (form.newsubdir.length) {
7651: for (var j=0; j<form.newsubdir.length; j++) {
7652: if (form.newsubdir[j].checked) {
7653: if (document.getElementById('newsubdirname')) {
7654: if (form.newsubdir[j].value == '1') {
7655: document.getElementById('newsubdirname').type = "text";
7656: if (document.getElementById('newsubdir')) {
7657: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7658: }
7659: } else {
7660: document.getElementById('newsubdirname').type = "hidden";
7661: document.getElementById('newsubdirname').value = "";
7662: document.getElementById('newsubdir').innerHTML = "";
7663: }
7664: }
7665: break;
7666: }
7667: }
7668: }
7669: }
7670:
7671: function toggleCrsResTitle() {
7672: if (document.getElementById('newresource')) {
7673: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7674: document.getElementById('newresource').style.display = 'inline';
7675: document.courseresform.newresourceadd[0].checked = true;
7676: toggleNewInCourse(document.courseresform);
7677: } else {
7678: document.getElementById('newresource').style.display = 'none';
7679: }
7680: }
7681: }
7682:
7683: function toggleNewInCourse(form) {
7684: if (form.newresourceadd.length) {
7685: for (var i=0; i<form.newresourceadd.length; i++) {
7686: if (form.newresourceadd[i].checked) {
7687: if (document.getElementById('newresourcetitle')) {
7688: if (form.newresourceadd[i].value == '1') {
7689: document.getElementById('newresourcetitle').type = 'text';
7690: if (document.getElementById('newrestitle')) {
7691: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7692: }
7693: } else {
7694: document.getElementById('newresourcetitle').type = 'hidden';
7695: document.getElementById('newresourcetitle').value = '';
7696: if (document.getElementById('newrestitle')) {
7697: document.getElementById('newrestitle').innerHTML = '';
7698: }
7699: }
7700: }
7701: break;
7702: }
7703: }
7704: }
7705: }
7706:
7707: function toggleWithTemplate(form) {
7708: if (form.newresusetemp.length) {
7709: for (var i=0; i<form.newresusetemp.length; i++) {
7710: if (form.newresusetemp[i].checked) {
7711: if (document.getElementById('newrestemplate')) {
7712: if (form.newresusetemp[i].value == '1') {
7713: document.getElementById('newrestemplate').style.display = 'inline';
7714: toggleExampleText();
7715: } else {
7716: form.tempcategory.selectedIndex = 0;
7717: select1template_changed();
7718: document.getElementById('newrestemplate').style.display = 'none';
7719: }
7720: }
7721: }
7722: }
7723: }
7724: }
7725:
7726: function toggleExampleText() {
7727: if (document.getElementById('newresexample')) {
7728: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7729: if (url == '') {
7730: document.getElementById('newresexample').style.fontWeight = 'normal';
7731: } else {
7732: document.getElementById('newresexample').style.fontWeight = 'bold';
7733: }
7734: }
7735: }
7736:
7737: function getExample(width,height,scrolling,transparency) {
7738: var url;
7739: if (document.courseresform.newresusetemp.length) {
7740: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7741: if (document.courseresform.newresusetemp[i].checked) {
7742: if (document.courseresform.newresusetemp[i].value == '1') {
7743: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7744: if (url == '') {
7745: alert('Pick a category and template');
7746: } else {
7747: url = url.replace("$londocroot","");
7748: url += '?inhibitmenu=yes';
7749: }
7750: }
7751: break;
7752: }
7753: }
7754: }
7755: if (url != '') {
7756: openMyModal(url,width,height,scrolling,transparency,'');
7757: }
7758: }
7759:
7760: function toggleImportCrsres(caller,dircount) {
7761: var disp = 'none';
7762: if (document.getElementById('importcrsresform')) {
7763: if (caller == 'res') {
7764: var numdirs = parseInt(dircount);
7765: var curr = document.getElementById('importcrsresform').style.display;
7766: if (curr == 'none') {
7767: disp='block';
7768: if (numdirs > 1) {
7769: select1res_changed();
7770: }
7771: }
7772: }
7773: document.getElementById('importcrsresform').style.display=disp;
7774: resize_scrollbox('contentscroll','1','0');
7775: }
7776: return;
7777: }
7778:
1.501 raeburn 7779: function makeims(imsform) {
7780: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7781: alert("$js_lt{'imsfile'}");
1.501 raeburn 7782: return;
7783: }
7784: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7785: alert("$js_lt{'imscms'}");
1.501 raeburn 7786: return;
7787: }
7788: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7789: imsform.submit();
7790: }
7791:
1.478 raeburn 7792: function updatePick(targetform,index,caller) {
1.537 raeburn 7793: var pickitem;
7794: var picknumitem;
7795: var picknumtext;
7796: if (index == 'all') {
7797: pickitem = document.getElementById('randompickall');
7798: picknumitem = document.getElementById('rpicknumall');
7799: picknumtext = document.getElementById('rpicktextall');
7800: } else {
7801: pickitem = document.getElementById('randompick_'+index);
7802: picknumitem = document.getElementById('rpicknum_'+index);
7803: picknumtext = document.getElementById('randompicknum_'+index);
7804: }
1.478 raeburn 7805: if (pickitem.checked) {
1.594 damieng 7806: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7807: if (picknum == '' || picknum == null) {
7808: if (caller == 'check') {
7809: pickitem.checked=false;
1.537 raeburn 7810: if (index == 'all') {
7811: picknumtext.innerHTML = '';
7812: if (caller == 'link') {
7813: propagateState(targetform,'rpicknum');
7814: }
7815: } else {
1.538 raeburn 7816: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7817: }
1.478 raeburn 7818: }
7819: } else {
7820: picknum.toString();
7821: var regexdigit=/^\\d+\$/;
7822: if (regexdigit.test(picknum)) {
7823: picknumitem.value = picknum;
1.537 raeburn 7824: if (index == 'all') {
1.538 raeburn 7825: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7826: if (caller == 'link') {
7827: propagateState(targetform,'rpicknum');
7828: }
7829: } else {
7830: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7831: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7832: }
1.478 raeburn 7833: } else {
7834: if (caller == 'check') {
1.537 raeburn 7835: if (index == 'all') {
7836: picknumtext.innerHTML = '';
7837: if (caller == 'link') {
7838: propagateState(targetform,'rpicknum');
7839: }
7840: } else {
7841: pickitem.checked=false;
1.538 raeburn 7842: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7843: }
1.478 raeburn 7844: }
7845: return;
7846: }
7847: }
7848: } else {
1.537 raeburn 7849: picknumitem.value = '';
7850: picknumtext.innerHTML = '';
7851: if (index == 'all') {
7852: if (caller == 'link') {
7853: propagateState(targetform,'rpicknum');
7854: }
7855: } else {
1.538 raeburn 7856: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7857: }
7858: }
7859: }
7860:
7861: function propagateState(form,param) {
7862: if (document.getElementById(param+'all')) {
7863: var setcheck = 0;
7864: var rpick = 0;
7865: if (param == 'rpicknum') {
7866: if (document.getElementById('randompickall')) {
7867: if (document.getElementById('randompickall').checked) {
7868: if (document.getElementById('rpicknumall')) {
7869: rpick = document.getElementById('rpicknumall').value;
7870: }
7871: }
7872: }
7873: } else {
7874: if (document.getElementById(param+'all').checked) {
7875: setcheck = 1;
7876: }
7877: }
1.538 raeburn 7878: var allidxlist;
7879: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7880: if (document.getElementById('all'+param+'idx')) {
7881: allidxlist = document.getElementById('all'+param+'idx').value;
7882: }
7883: var actions = new Array ('remove','cut','copy');
7884: for (var i=0; i<actions.length; i++) {
7885: if (actions[i] != param) {
7886: if (document.getElementById(actions[i]+'all')) {
7887: document.getElementById(actions[i]+'all').checked = false;
7888: }
7889: }
7890: }
7891: }
1.537 raeburn 7892: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7893: allidxlist = form.allidx.value;
7894: }
7895: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7896: allidxlist = form.allmapidx.value;
7897: }
7898: if ((allidxlist != '') && (allidxlist != null)) {
7899: var allidxs = allidxlist.split(',');
7900: if (allidxs.length > 1) {
7901: for (var i=0; i<allidxs.length; i++) {
7902: if (document.getElementById(param+'_'+allidxs[i])) {
7903: if (param == 'rpicknum') {
7904: if (document.getElementById('randompick_'+allidxs[i])) {
7905: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7906: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7907: if (rpick > 0) {
7908: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7909: } else {
7910: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7911: }
7912: }
7913: }
7914: } else {
1.537 raeburn 7915: if (setcheck == 1) {
7916: document.getElementById(param+'_'+allidxs[i]).checked = true;
7917: } else {
7918: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7919: if (param == 'randompick') {
7920: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7921: }
1.537 raeburn 7922: }
7923: }
7924: }
7925: }
1.538 raeburn 7926: if (setcheck == 1) {
7927: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7928: var actions = new Array('copy','cut','remove');
7929: for (var i=0; i<actions.length; i++) {
7930: var otheractions;
7931: var otheridxs;
7932: if (actions[i] === param) {
7933: continue;
7934: } else {
7935: if (document.getElementById('all'+actions[i]+'idx')) {
7936: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7937: otheridxs = otheractions.split(',');
7938: if (otheridxs.length > 1) {
7939: for (var j=0; j<otheridxs.length; j++) {
7940: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7941: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7942: }
1.537 raeburn 7943: }
7944: }
7945: }
1.538 raeburn 7946: }
7947: }
7948: }
7949: }
7950: }
7951: }
7952: }
7953: return;
7954: }
7955:
1.603 raeburn 7956: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7957: var canedit = '$canedit';
7958: if (canedit == '') {
7959: alert("$js_lt{'edri'}");
7960: return;
7961: }
1.539 raeburn 7962: var dosettings;
7963: var doaction;
1.538 raeburn 7964: var control = document.togglemultsettings;
7965: if (context == 'actions') {
7966: control = document.togglemultactions;
1.539 raeburn 7967: doaction = 1;
7968: } else {
7969: dosettings = 1;
1.538 raeburn 7970: }
1.539 raeburn 7971: if (control) {
7972: if (control.showmultpick.length) {
7973: for (var i=0; i<control.showmultpick.length; i++) {
7974: if (control.showmultpick[i].checked) {
7975: if (control.showmultpick[i].value == 1) {
7976: if (context == 'settings') {
7977: dosettings = 0;
7978: } else {
7979: doaction = 0;
1.538 raeburn 7980: }
7981: }
7982: }
1.537 raeburn 7983: }
7984: }
1.539 raeburn 7985: }
7986: if (context == 'settings') {
7987: if (dosettings == 1) {
1.538 raeburn 7988: targetform.changeparms.value=param;
7989: targetform.submit();
7990: }
1.537 raeburn 7991: }
1.539 raeburn 7992: if (context == 'actions') {
7993: if (doaction == 1) {
7994: targetform.cmd.value=param+'_'+index;
7995: targetform.folderpath.value=folderpath;
7996: targetform.markcopy.value=idx+':'+param;
7997: targetform.copyfolder.value=folder+'.'+container;
7998: if (param == 'remove') {
1.603 raeburn 7999: var doremove = 0;
8000: if (skip_confirm) {
8001: if (confirm_removal) {
8002: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8003: doremove = 1;
8004: }
8005: } else {
8006: doremove = 1;
8007: }
8008: } else {
8009: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8010: doremove = 1;
8011: }
8012: }
8013: if (doremove) {
1.539 raeburn 8014: targetform.markcopy.value='';
8015: targetform.copyfolder.value='';
8016: targetform.submit();
8017: }
8018: }
8019: if (param == 'cut') {
1.594 damieng 8020: 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 8021: targetform.submit();
8022: return;
8023: }
8024: }
8025: if (param == 'copy') {
8026: targetform.submit();
8027: return;
8028: }
8029: targetform.markcopy.value='';
8030: targetform.copyfolder.value='';
8031: targetform.cmd.value='';
8032: targetform.folderpath.value='';
8033: return;
8034: } else {
8035: if (document.getElementById(param+'_'+idx)) {
8036: item = document.getElementById(param+'_'+idx);
8037: if (item.type == 'checkbox') {
8038: if (item.checked) {
8039: item.checked = false;
8040: } else {
8041: item.checked = true;
8042: singleCheck(item,idx,param);
8043: }
8044: }
8045: }
8046: }
8047: }
1.537 raeburn 8048: return;
8049: }
8050:
1.538 raeburn 8051: function singleCheck(caller,idx,action) {
8052: actions = new Array('cut','copy','remove');
8053: if (caller.checked) {
8054: for (var i=0; i<actions.length; i++) {
8055: if (actions[i] != action) {
8056: if (document.getElementById(actions[i]+'_'+idx)) {
8057: if (document.getElementById(actions[i]+'_'+idx).checked) {
8058: document.getElementById(actions[i]+'_'+idx).checked = false;
8059: }
1.537 raeburn 8060: }
8061: }
8062: }
1.478 raeburn 8063: }
1.537 raeburn 8064: return;
1.478 raeburn 8065: }
8066:
1.334 muellerd 8067: function unselectInactive(nav) {
1.335 ehlerst 8068: currentNav = document.getElementById(nav);
8069: currentLis = currentNav.getElementsByTagName('LI');
8070: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 8071: if (currentLis[i].className == 'goback') {
8072: currentLis[i].className = 'goback';
8073: } else {
8074: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 8075: currentLis[i].className = 'right';
1.472 raeburn 8076: } else {
1.374 tempelho 8077: currentLis[i].className = 'i';
1.472 raeburn 8078: }
8079: }
1.335 ehlerst 8080: }
1.332 tempelho 8081: }
8082:
1.334 muellerd 8083: function hideAll(current, nav, data) {
1.335 ehlerst 8084: unselectInactive(nav);
1.570 raeburn 8085: if (current) {
8086: if (current.className == 'right'){
8087: current.className = 'right active'
8088: } else {
8089: current.className = 'active';
8090: }
1.374 tempelho 8091: }
1.335 ehlerst 8092: currentData = document.getElementById(data);
8093: currentDivs = currentData.getElementsByTagName('DIV');
8094: for (i = 0; i < currentDivs.length; i++) {
8095: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 8096: currentDivs[i].style.display = 'none';
1.330 tempelho 8097: }
8098: }
1.335 ehlerst 8099: }
1.330 tempelho 8100:
1.374 tempelho 8101: function openTabs(pageId) {
8102: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 8103: if(tabnav.length > 2 ){
1.389 tempelho 8104: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 8105: currentLis = currentNav.getElementsByTagName('LI');
8106: for(i = 0; i< currentLis.length; i++){
8107: if(currentLis[i].className == 'active') {
1.375 tempelho 8108: funcString = currentLis[i].onclick.toString();
8109: tab = funcString.split('"');
1.420 onken 8110: if(tab.length < 2) {
8111: tab = funcString.split("'");
8112: }
1.375 tempelho 8113: currentData = document.getElementById(tab[1]);
8114: currentData.style.display = 'block';
1.374 tempelho 8115: }
8116: }
8117: }
8118: }
8119:
1.334 muellerd 8120: function showPage(current, pageId, nav, data) {
1.570 raeburn 8121: currstate = current.className;
1.334 muellerd 8122: hideAll(current, nav, data);
1.375 tempelho 8123: openTabs(pageId);
1.334 muellerd 8124: unselectInactive(nav);
1.570 raeburn 8125: if ((currstate == 'active') || (currstate == 'right active')) {
8126: if (currstate == 'active') {
8127: current.className = '';
8128: } else {
8129: current.className = 'right';
8130: }
8131: activeTab = '';
1.656 raeburn 8132: toggleExternal();
1.570 raeburn 8133: toggleUpload();
8134: toggleMap();
1.606 raeburn 8135: toggleCrsRes();
8136: toggleImportCrsres();
1.570 raeburn 8137: resize_scrollbox('contentscroll','1','0');
8138: return;
8139: } else {
8140: current.className = 'active';
8141: }
1.330 tempelho 8142: currentData = document.getElementById(pageId);
8143: currentData.style.display = 'block';
1.458 raeburn 8144: activeTab = pageId;
1.656 raeburn 8145: toggleExternal();
1.501 raeburn 8146: toggleUpload();
1.503 raeburn 8147: toggleMap();
1.606 raeburn 8148: toggleCrsRes();
8149: toggleImportCrsres();
1.433 raeburn 8150: if (nav == 'mainnav') {
8151: var storedpath = "$docs_folderpath";
1.434 raeburn 8152: var storedpage = "$main_container_page";
1.433 raeburn 8153: var reg = new RegExp("^supplemental");
8154: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 8155: if (storedpage == 1) {
8156: document.simpleedit.folderpath.value = '';
8157: document.uploaddocument.folderpath.value = '';
8158: } else {
8159: if (reg.test(storedpath)) {
8160: document.simpleedit.folderpath.value = '$toplevelmain';
8161: document.uploaddocument.folderpath.value = '$toplevelmain';
8162: document.newext.folderpath.value = '$toplevelmain';
8163: } else {
8164: document.simpleedit.folderpath.value = storedpath;
8165: document.uploaddocument.folderpath.value = storedpath;
8166: document.newext.folderpath.value = storedpath;
8167: }
1.433 raeburn 8168: }
8169: } else {
1.434 raeburn 8170: if (reg.test(storedpath)) {
8171: document.simpleedit.folderpath.value = storedpath;
8172: document.supuploaddocument.folderpath.value = storedpath;
8173: document.supnewext.folderpath.value = storedpath;
8174: } else {
1.433 raeburn 8175: document.simpleedit.folderpath.value = '$toplevelsupp';
8176: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8177: document.supnewext.folderpath.value = '$toplevelsupp';
8178: }
8179: }
8180: }
1.485 raeburn 8181: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8182: return false;
8183: }
1.329 droeschl 8184:
1.472 raeburn 8185: function toContents(jumpto) {
8186: var newurl = '$backtourl';
1.525 raeburn 8187: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8188: newurl = newurl+'?postdata='+jumpto;
8189: }
8190: location.href=newurl;
8191: }
8192:
1.538 raeburn 8193: function togglePick(caller,value) {
8194: var disp = 'none';
8195: if (document.getElementById('multi'+caller)) {
8196: var curr = document.getElementById('multi'+caller).style.display;
8197: if (value == 1) {
8198: disp='block';
8199: }
8200: if (curr == disp) {
8201: return;
8202: }
8203: document.getElementById('multi'+caller).style.display=disp;
8204: if (value == 1) {
1.594 damieng 8205: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8206: } else {
8207: document.getElementById('more'+caller).innerHTML = '';
8208: }
8209: if (caller == 'actions') {
8210: setClass(value);
8211: setBoxes(value);
8212: }
8213: }
8214: var showButton = multiSettings();
8215: if (showButton != 1) {
8216: showButton = multiActions();
8217: }
8218: if (document.getElementById('multisave')) {
8219: if (showButton == 1) {
8220: document.getElementById('multisave').style.display='block';
8221: } else {
8222: document.getElementById('multisave').style.display='none';
8223: }
8224: }
8225: resize_scrollbox('contentscroll','1','1');
8226: return;
8227: }
8228:
8229: function toggleCheckUncheck(caller,more) {
8230: if (more == 1) {
1.594 damieng 8231: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8232: document.getElementById('allfields'+caller).style.display='block';
8233: } else {
1.594 damieng 8234: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8235: document.getElementById('allfields'+caller).style.display='none';
8236: }
8237: resize_scrollbox('contentscroll','1','1');
8238: }
8239:
8240: function multiSettings() {
8241: var inuse = 0;
8242: var settingsform = document.togglemultsettings;
8243: if (settingsform.showmultpick.length > 1) {
8244: for (var i=0; i<settingsform.showmultpick.length; i++) {
8245: if (settingsform.showmultpick[i].checked) {
8246: if (settingsform.showmultpick[i].value == 1) {
8247: inuse = 1;
8248: }
8249: }
8250: }
8251: }
8252: return inuse;
8253: }
8254:
8255: function multiActions() {
8256: var inuse = 0;
8257: var actionsform = document.togglemultactions;
8258: if (actionsform.showmultpick.length > 1) {
8259: for (var i=0; i<actionsform.showmultpick.length; i++) {
8260: if (actionsform.showmultpick[i].checked) {
8261: if (actionsform.showmultpick[i].value == 1) {
8262: inuse = 1;
8263: }
8264: }
8265: }
8266: }
8267: return inuse;
8268: }
8269:
8270: function checkSubmits() {
8271: var numchanges = 0;
8272: var form = document.saveactions;
8273: var doactions = multiActions();
1.542 raeburn 8274: var cutwarnings = 0;
8275: var remwarnings = 0;
1.603 raeburn 8276: var removalinfo = 0;
1.538 raeburn 8277: if (doactions == 1) {
8278: var remidxlist = document.cumulativeactions.allremoveidx.value;
8279: if ((remidxlist != '') && (remidxlist != null)) {
8280: var remidxs = remidxlist.split(',');
8281: for (var i=0; i<remidxs.length; i++) {
8282: if (document.getElementById('remove_'+remidxs[i])) {
8283: if (document.getElementById('remove_'+remidxs[i]).checked) {
8284: form.multiremove.value += remidxs[i]+',';
8285: numchanges ++;
1.542 raeburn 8286: if (document.getElementById('skip_remove_'+remidxs[i])) {
8287: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8288: remwarnings ++;
8289: }
8290: }
1.603 raeburn 8291: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8292: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8293: removalinfo ++;
8294: }
8295: }
1.537 raeburn 8296: }
8297: }
1.538 raeburn 8298: }
8299: }
8300: var cutidxlist = document.cumulativeactions.allcutidx.value;
8301: if ((cutidxlist != '') && (cutidxlist != null)) {
8302: var cutidxs = cutidxlist.split(',');
8303: for (var i=0; i<cutidxs.length; i++) {
8304: if (document.getElementById('cut_'+cutidxs[i])) {
8305: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8306: form.multicut.value += cutidxs[i]+',';
8307: numchanges ++;
1.542 raeburn 8308: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8309: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8310: cutwarnings ++;
8311: }
8312: }
1.537 raeburn 8313: }
8314: }
8315: }
8316: }
1.538 raeburn 8317: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8318: if ((copyidxlist != '') && (copyidxlist != null)) {
8319: var copyidxs = copyidxlist.split(',');
8320: for (var i=0; i<copyidxs.length; i++) {
8321: if (document.getElementById('copy_'+copyidxs[i])) {
8322: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8323: form.multicopy.value += copyidxs[i]+',';
8324: numchanges ++;
8325: }
8326: }
8327: }
8328: }
8329: if (numchanges > 0) {
8330: form.multichange.value = numchanges;
8331: }
1.537 raeburn 8332: }
1.538 raeburn 8333: var dosettings = multiSettings();
1.543 raeburn 8334: var haschanges = 0;
1.538 raeburn 8335: if (dosettings == 1) {
8336: form.allencrypturl.value = '';
8337: form.allhiddenresource.value = '';
1.543 raeburn 8338: form.changeparms.value = 'all';
8339: var patt=new RegExp(",\$");
1.538 raeburn 8340: var allidxlist = document.cumulativesettings.allidx.value;
8341: if ((allidxlist != '') && (allidxlist != null)) {
8342: var allidxs = allidxlist.split(',');
8343: if (allidxs.length > 1) {
8344: for (var i=0; i<allidxs.length; i++) {
8345: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8346: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8347: form.allhiddenresource.value += allidxs[i]+',';
8348: }
8349: }
8350: if (document.getElementById('encrypturl_'+allidxs[i])) {
8351: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8352: form.allencrypturl.value += allidxs[i]+',';
8353: }
8354: }
8355: }
1.543 raeburn 8356: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8357: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8358: }
1.538 raeburn 8359: }
8360: form.allrandompick.value = '';
8361: form.allrandomorder.value = '';
8362: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8363: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8364: var allmapidxs = allmapidxlist.split(',');
8365: for (var i=0; i<allmapidxs.length; i++) {
8366: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8367: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8368: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8369: if ((randompick.checked) && (rpicknum.value != '')) {
8370: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8371: }
8372: if (randorder.checked) {
8373: form.allrandomorder.value += allmapidxs[i]+',';
8374: }
1.537 raeburn 8375: }
1.543 raeburn 8376: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8377: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8378: }
8379: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8380: haschanges = 1;
8381: }
8382: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8383: haschanges = 1;
8384: }
8385: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8386: haschanges = 1;
8387: }
8388: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8389: haschanges = 1;
1.537 raeburn 8390: }
8391: }
1.543 raeburn 8392: if (doactions == 1) {
1.542 raeburn 8393: if (numchanges > 0) {
1.603 raeburn 8394: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8395: if (remwarnings > 0) {
1.594 damieng 8396: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8397: return false;
8398: }
8399: }
1.603 raeburn 8400: if (removalinfo > 0) {
8401: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8402: return false;
8403: }
8404: }
1.542 raeburn 8405: if (cutwarnings > 0) {
1.594 damieng 8406: 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 8407: return false;
8408: }
8409: }
8410: }
8411: form.submit();
8412: return true;
1.543 raeburn 8413: }
8414: }
8415: if (dosettings == 1) {
8416: if (haschanges == 1) {
1.542 raeburn 8417: form.submit();
8418: return true;
8419: }
1.543 raeburn 8420: }
8421: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8422: alert("$js_lt{'noor'}");
1.543 raeburn 8423: } else {
8424: if (dosettings == 1) {
1.594 damieng 8425: alert("$js_lt{'noch'}");
1.543 raeburn 8426: } else {
1.594 damieng 8427: alert("$js_lt{'noac'}");
1.543 raeburn 8428: }
8429: }
1.538 raeburn 8430: return false;
8431: }
8432:
8433: function setClass(value) {
8434: var cutclass = 'LC_docs_cut';
8435: var copyclass = 'LC_docs_copy';
8436: var removeclass = 'LC_docs_remove';
8437: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8438: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8439: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8440: var links = document.getElementsByTagName('a');
8441: for (var i=0; i<links.length; i++) {
8442: var classes = links[i].className;
8443: if (cutreg.test(classes)) {
8444: links[i].className = cutclass;
8445: if (value == 1) {
8446: links[i].className += " LC_menubuttons_link";
8447: }
8448: } else {
8449: if (copyreg.test(classes)) {
8450: links[i].className = copyclass;
8451: if (value == 1) {
8452: links[i].className += " LC_menubuttons_link";
8453: }
8454: } else {
8455: if (removereg.test(classes)) {
8456: links[i].className = removeclass;
8457: if (value == 1) {
8458: links[i].className += " LC_menubuttons_link";
8459: }
8460: }
8461: }
8462: }
8463: }
8464: return;
1.537 raeburn 8465: }
8466:
1.538 raeburn 8467: function setBoxes(value) {
8468: var remidxlist = document.cumulativeactions.allremoveidx.value;
8469: if ((remidxlist != '') && (remidxlist != null)) {
8470: var remidxs = remidxlist.split(',');
8471: for (var i=0; i<remidxs.length; i++) {
8472: if (document.getElementById('remove_'+remidxs[i])) {
8473: var item = document.getElementById('remove_'+remidxs[i]);
8474: if (value == 1) {
8475: item.className = 'LC_docs_remove';
8476: } else {
8477: item.className = 'LC_hidden';
8478: }
8479: }
8480: }
8481: }
8482: var cutidxlist = document.cumulativeactions.allcutidx.value;
8483: if ((cutidxlist != '') && (cutidxlist != null)) {
8484: var cutidxs = cutidxlist.split(',');
8485: for (var i=0; i<cutidxs.length; i++) {
8486: if (document.getElementById('cut_'+cutidxs[i])) {
8487: var item = document.getElementById('cut_'+cutidxs[i]);
8488: if (value == 1) {
8489: item.className = 'LC_docs_cut';
8490: } else {
8491: item.className = 'LC_hidden';
8492: }
8493: }
1.537 raeburn 8494: }
8495: }
1.538 raeburn 8496: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8497: if ((copyidxlist != '') && (copyidxlist != null)) {
8498: var copyidxs = copyidxlist.split(',');
8499: for (var i=0; i<copyidxs.length; i++) {
8500: if (document.getElementById('copy_'+copyidxs[i])) {
8501: var item = document.getElementById('copy_'+copyidxs[i]);
8502: if (value == 1) {
8503: item.className = 'LC_docs_copy';
8504: } else {
8505: item.className = 'LC_hidden';
8506: }
8507: }
1.537 raeburn 8508: }
8509: }
8510: return;
8511: }
8512:
1.606 raeburn 8513: function validImportCrsRes() {
8514: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8515: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8516: if ((fname == '') || (fname == null)) {
8517: alert("$js_lt{'nofi'}");
8518: return false;
8519: }
8520: var url = '/res/$coursedom/$coursenum/';
8521: if (path && path != '/') {
8522: url += path+'/';
8523: }
8524: if (fname != '') {
8525: url += fname;
8526: }
8527: var title = document.crsresimportform.crsrestitle.value;
8528: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8529: return true;
8530: }
8531:
8532: function validateNewRes(caller) {
8533: if (caller == 'single') {
8534: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8535: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8536: var resname = document.courseresform.newresourcename.value;
8537: }
8538: }
8539:
1.611 raeburn 8540: ENDSCRIPT
1.329 droeschl 8541: }
1.457 raeburn 8542:
1.483 raeburn 8543: sub history_tab_js {
8544: return <<"ENDHIST";
8545: function toggleHistoryDisp(choice) {
8546: document.docslogform.docslog.value = choice;
8547: document.docslogform.submit();
8548: return;
8549: }
8550:
8551: ENDHIST
8552: }
8553:
1.484 raeburn 8554: sub inject_data_js {
8555: return <<ENDINJECT;
8556:
8557: function injectData(current, hiddenField, name, value) {
8558: currentElement = document.getElementById(hiddenField);
8559: currentElement.name = name;
8560: currentElement.value = value;
8561: current.submit();
8562: }
8563:
8564: ENDINJECT
8565: }
8566:
8567: sub dump_switchserver_js {
8568: my @hosts = @_;
1.594 damieng 8569: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8570: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8571: swit => 'Switch server?',
1.594 damieng 8572: );
8573: my %html_js_lt = &Apache::lonlocal::texthash(
8574: swit => 'Switch server?',
1.568 raeburn 8575: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8576: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8577: chos => 'Choose server',
8578: );
1.594 damieng 8579: &js_escape(\%js_lt);
8580: &html_escape(\%html_js_lt);
8581: &js_escape(\%html_js_lt);
1.484 raeburn 8582: my $role = $env{'request.role'};
8583: my $js = <<"ENDSWJS";
8584: <script type="text/javascript">
8585: function write_switchserver() {
8586: var server;
8587: if (document.setserver.posshosts.length > 0) {
8588: for (var i=0; i<document.setserver.posshosts.length; i++) {
8589: if (document.setserver.posshosts[i].checked) {
8590: server = document.setserver.posshosts[i].value;
8591: }
8592: }
8593: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8594: }
8595: window.close();
8596: }
8597: </script>
8598:
8599: ENDSWJS
8600:
8601: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8602: {'only_body' => 1,
8603: 'js_ready' => 1,});
8604: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8605:
8606: my $hostpicker;
8607: my $count = 0;
8608: foreach my $host (sort(@hosts)) {
8609: my $checked;
8610: if ($count == 0) {
8611: $checked = ' checked="checked"';
8612: }
8613: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8614: $host.'"'.$checked.' />'.$host.'</label> ';
8615: $count++;
8616: }
8617:
8618: return <<"ENDSWITCHJS";
8619:
8620: function dump_needs_switchserver(url) {
8621: if (url!='' && url!= null) {
1.594 damieng 8622: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8623: go(url);
8624: }
8625: }
8626: return;
8627: }
8628:
8629: function choose_switchserver_window() {
8630: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8631: newWindow.document.open();
8632: newWindow.document.writeln('$startpage');
1.594 damieng 8633: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8634: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8635: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8636: '<form name="setserver" method="post" action="" \\/>\\n'+
8637: '$hostpicker\\n'+
8638: '<br \\/><br \\/>\\n'+
1.594 damieng 8639: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8640: 'onclick="write_switchserver();" \\/>\\n'+
8641: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8642: newWindow.document.writeln('$endpage');
8643: newWindow.document.close();
8644: newWindow.focus();
8645: }
8646:
8647: ENDSWITCHJS
8648: }
8649:
8650: sub makedocslogform {
8651: my ($formelems,$docslog) = @_;
8652: return <<"LOGSFORM";
8653: <form action="/adm/coursedocs" method="post" name="docslogform">
8654: <input type="hidden" name="docslog" value="$docslog" />
8655: $formelems
8656: </form>
8657: LOGSFORM
8658: }
8659:
8660: sub makesimpleeditform {
8661: my ($formelems) = @_;
8662: return <<"SIMPFORM";
8663: <form name="simpleedit" method="post" action="/adm/coursedocs">
8664: <input type="hidden" name="importdetail" value="" />
8665: $formelems
8666: </form>
8667: SIMPFORM
8668: }
8669:
1.606 raeburn 8670: sub makenewproblem {
8671: my ($r,$coursedom,$coursenum) = @_;
8672: # Creating a new problem
8673: my ($redirect,$error);
8674: if ($env{'form.authorrole'}) {
8675: my ($newsubdir,$filename);
8676: if ($env{'form.newsubdir'}) {
8677: if ($env{'form.newsubdirname'} ne '') {
8678: $newsubdir = $env{'form.newsubdirname'};
1.654 raeburn 8679: }
1.606 raeburn 8680: }
8681: if ($env{'form.newresourcename'}) {
8682: $filename = $env{'form.newresourcename'};
8683: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8684: $filename =~ s/`//g;
8685: $filename =~ s{/\.\./}{_}g;
8686: $filename =~ s/\.+/./g;
8687: $filename =~ s{/+}{_}g;
8688: if ($filename ne '') {
8689: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8690: if (($ext) && ($ext ne '.problem')) {
8691: $filename = $name.'.problem';
8692: } elsif ($ext eq '') {
8693: $filename .= '.problem';
8694: }
8695: my $docroot = $r->dir_config('lonDocRoot');
8696: my @ids=&Apache::lonnet::current_machine_ids();
8697: if ($env{'form.authorrole'} eq 'author') {
8698: if ($env{'user.author'}) {
8699: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8700: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8701: my $path = $docroot.$url;
8702: my $subdir = $env{'form.authorpath'};
8703: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8704: }
8705: }
8706: } elsif ($env{'form.authorrole'} eq 'course') {
8707: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8708: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8709: my $url = "/priv/$coursedom/$coursenum";
8710: my $path=$docroot.$url;
8711: my $subdir = $env{'form.authorpath'};
8712: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8713: if ($redirect) {
8714: my $rightsfile = 'default.rights';
8715: my $sourcerights = "$path/$rightsfile";
8716: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8717: my $now = time;
8718: if (!-e $sourcerights) {
8719: my $cid = $coursedom.'_'.$coursenum;
8720: if (open(my $fh,">$sourcerights")) {
8721: print $fh <<END;
8722: <accessrule effect="deny" realm="" type="course" role="" />
8723: <accessrule effect="allow" realm="$cid" type="course" role="" />
8724: END
8725: close($fh);
8726: }
8727: }
8728: if (!-e "$sourcerights.meta") {
8729: if (open(my $fh,">$sourcerights.meta")) {
8730: my $author=$env{'environment.firstname'}.' '.
8731: $env{'environment.middlename'}.' '.
8732: $env{'environment.lastname'}.' '.
8733: $env{'environment.generation'};
8734: $author =~ s/\s+$//;
8735: print $fh <<"END";
8736:
8737: <abstract></abstract>
8738: <author>$author</author>
8739: <authorspace>$coursenum:$coursedom</authorspace>
8740: <copyright>private</copyright>
8741: <creationdate>$now</creationdate>
8742: <customdistributionfile></customdistributionfile>
8743: <dependencies></dependencies>
8744: <domain>$coursedom</domain>
8745: <highestgradelevel>0</highestgradelevel>
8746: <keywords></keywords>
8747: <language>notset </language>
8748: <lastrevisiondate>$now</lastrevisiondate>
8749: <lowestgradelevel>0</lowestgradelevel>
8750: <mime>rights</mime>
8751: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8752: <notes></notes>
8753: <obsolete></obsolete>
8754: <obsoletereplacement></obsoletereplacement>
8755: <owner>$coursenum:$coursedom</owner>
8756: <rule>deny:::course,allow:$cid::course</rule>
8757: <sourceavail></sourceavail>
8758: <standards></standards>
8759: <subject></subject>
8760: <title></title>
8761: END
1.654 raeburn 8762: close($fh);
8763: }
8764: }
8765: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8766: if (!-e "$docroot/res/$coursedom") {
8767: mkdir("$docroot/res/$coursedom",0755);
1.606 raeburn 8768: }
1.654 raeburn 8769: if (!-e "$docroot/res/$coursedom/$coursenum") {
8770: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8771: }
8772: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8773: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8774: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
1.606 raeburn 8775: }
8776: }
1.654 raeburn 8777: my $source = $docroot.$redirect;
8778: if (!-e "$source.meta") {
8779: my $cid = $coursedom.'_'.$coursenum;
8780: my $now = time;
8781: if (open(my $fh,">$source.meta")) {
8782: my $author=$env{'environment.firstname'}.' '.
8783: $env{'environment.middlename'}.' '.
8784: $env{'environment.lastname'}.' '.
8785: $env{'environment.generation'};
8786: $author =~ s/\s+$//;
8787: my $title = $env{'form.newresourcetitle'};
8788: $title =~ s/^\s+|\s+$//g;
8789: print $fh <<END;
1.606 raeburn 8790:
8791: <abstract></abstract>
8792: <author>$author</author>
8793: <authorspace>$coursenum:$coursedom</authorspace>
8794: <copyright>custom</copyright>
8795: <creationdate>$now</creationdate>
8796: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8797: <dependencies></dependencies>
8798: <domain>$coursedom</domain>
8799: <highestgradelevel>0</highestgradelevel>
8800: <keywords></keywords>
8801: <language>notset </language>
8802: <lastrevisiondate>$now</lastrevisiondate>
8803: <lowestgradelevel>0</lowestgradelevel>
8804: <mime>problem</mime>
8805: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8806: <notes></notes>
8807: <obsolete></obsolete>
8808: <obsoletereplacement></obsoletereplacement>
8809: <owner>$coursenum:$coursedom</owner>
8810: <sourceavail></sourceavail>
8811: <standards></standards>
8812: <subject></subject>
8813: <title>$title</title>
8814: END
1.654 raeburn 8815: close($fh);
1.606 raeburn 8816: }
8817: }
8818: }
8819: }
8820: } else {
8821: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8822: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8823: if (grep(/^\Q$rolehome\E$/,@ids)) {
8824: my $now = time;
8825: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8826: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8827: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8828: my $url = "/priv/$audom/$auname";
8829: my $path = $r->dir_config('lonDocRoot').$url;
8830: my $subdir = $env{'form.authorpath'};
8831: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8832: }
8833: }
8834: }
8835: }
8836: }
8837: }
8838: }
8839: return ($redirect,$error);
8840: }
8841:
8842: sub finishnewprob {
1.654 raeburn 8843: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
1.607 raeburn 8844: unless (-d $path) {
8845: unless (mkdir($path,02770)) {
8846: return;
8847: }
8848: }
1.606 raeburn 8849: my $redirect;
8850: if ($subdir ne '/') {
8851: $subdir = &cleandir($subdir);
8852: if (($subdir ne '') && (-d "$path/$subdir")) {
8853: $path .= "/$subdir";
8854: $url .= "/$subdir";
8855: }
8856: }
8857: my $dest;
8858: if ($newsubdir ne '') {
8859: $newsubdir = &cleandir($newsubdir);
8860: }
8861: if ($newsubdir ne '') {
8862: if (-d "$path/$newsubdir") {
8863: $dest = "$path/$newsubdir/$filename";
8864: } else {
8865: my $dirok;
8866: unless (-e "$path/$newsubdir") {
8867: if (mkdir("$path/$newsubdir",02770)) {
8868: if (chmod(02770,"$path/$newsubdir")) {
8869: $dirok = 1;
8870: }
8871: }
8872: }
8873: if ($dirok) {
8874: $dest = "$path/$newsubdir/$filename";
8875: }
8876: }
8877: if (($dest ne '') && (!-e $dest)) {
8878: $redirect = "$url/$newsubdir/$filename";
8879: }
8880: } else {
8881: $dest = "$path/$filename";
8882: if (($dest ne '') && (!-e $dest)) {
8883: $redirect = "$url/$filename";
8884: }
8885: }
1.654 raeburn 8886: if ((!-e $dest) && ($context ne 'upload')) {
8887: my $template = $env{'form.template'};
8888: my $copyfrom;
8889: if ($template ne '') {
8890: my %templates;
8891: my @files = &Apache::lonhomework::get_template_list('problem');
8892: foreach my $poss (@files) {
8893: if (ref($poss) eq 'ARRAY') {
8894: if ($template eq $poss->[0]) {
8895: $templates{$template} = 1;
8896: last;
8897: }
8898: }
8899: }
8900: if ($templates{$template}) {
8901: $copyfrom = $template;
8902: }
8903: }
8904: if ($filename =~ /\.problem$/) {
8905: unless ($copyfrom) {
8906: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
8907: }
8908: &File::Copy::copy($copyfrom,$dest);
8909: }
8910: }
1.606 raeburn 8911: return $redirect;
8912: }
8913:
8914: sub cleandir {
8915: my ($dir) = @_;
8916: $dir =~ s/^\s+//;
8917: $dir =~ s/\s+$//;
8918: $dir =~ s/\.+//g;
8919: $dir =~ s/[\#\?&%\":]//g;
8920: return $dir;
8921: }
8922:
1.329 droeschl 8923: 1;
8924: __END__
8925:
8926:
8927: =head1 NAME
8928:
8929: Apache::londocs.pm
8930:
8931: =head1 SYNOPSIS
8932:
8933: This is part of the LearningOnline Network with CAPA project
8934: described at http://www.lon-capa.org.
8935:
8936: =head1 SUBROUTINES
8937:
8938: =over
8939:
8940: =item %help=()
8941:
8942: Available help topics
8943:
8944: =item mapread()
8945:
1.344 bisitz 8946: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8947: @order and @resources, determines status
8948: sets @order - pointer to resources in right order
8949: sets @resources - array with the resources with correct idx
8950:
8951: =item authorhosts()
8952:
8953: Return hash with valid author names
8954:
8955: =item clean()
8956:
8957: =item dumpcourse()
8958:
8959: Actually dump course
8960:
8961: =item group_import()
8962:
8963: Imports the given (name, url) resources into the course
8964: coursenum, coursedom, and folder must precede the list
8965:
8966: =item breadcrumbs()
8967:
8968: =item log_docs()
8969:
8970: =item docs_change_log()
8971:
8972: =item update_paste_buffer()
8973:
8974: =item print_paste_buffer()
8975:
8976: =item do_paste_from_buffer()
8977:
1.538 raeburn 8978: =item do_buffer_empty()
8979:
8980: =item clear_from_buffer()
8981:
1.492 raeburn 8982: =item get_newmap_url()
8983:
8984: =item dbcopy()
8985:
8986: =item uniqueness_check()
8987:
8988: =item contained_map_check()
8989:
8990: =item url_paste_fixups()
8991:
8992: =item apply_fixups()
8993:
8994: =item copy_dependencies()
8995:
1.329 droeschl 8996: =item update_parameter()
8997:
8998: =item handle_edit_cmd()
8999:
9000: =item editor()
9001:
9002: =item process_file_upload()
9003:
9004: =item process_secondary_uploads()
9005:
9006: =item is_supplemental_title()
9007:
9008: =item entryline()
9009:
9010: =item tiehash()
9011:
9012: =item untiehash()
9013:
9014: =item checkonthis()
9015:
9016: check on this
9017:
9018: =item verifycontent()
9019:
9020: Verify Content
9021:
1.636 raeburn 9022: =item devalidateversioncache()
9023:
9024: =item checkversions()
1.329 droeschl 9025:
9026: Check Versions
9027:
9028: =item mark_hash_old()
9029:
9030: =item is_hash_old()
9031:
9032: =item changewarning()
9033:
9034: =item init_breadcrumbs()
9035:
9036: Breadcrumbs for special functions
9037:
1.484 raeburn 9038: =item create_list_elements()
9039:
9040: =item create_form_ul()
9041:
9042: =item startContentScreen()
9043:
9044: =item endContentScreen()
9045:
9046: =item supplemental_base()
9047:
9048: =item embedded_form_elems()
9049:
9050: =item embedded_destination()
9051:
9052: =item return_to_editor()
9053:
9054: =item decompression_info()
9055:
9056: =item decompression_phase_one()
9057:
9058: =item decompression_phase_two()
9059:
9060: =item remove_archive()
9061:
9062: =item generate_admin_menu()
9063:
9064: =item generate_edit_table()
9065:
9066: =item editing_js()
9067:
9068: =item history_tab_js()
9069:
9070: =item inject_data_js()
9071:
9072: =item dump_switchserver_js()
9073:
1.485 raeburn 9074: =item resize_scrollbox_js()
1.484 raeburn 9075:
9076: =item makedocslogform()
9077:
1.485 raeburn 9078: =item makesimpleeditform()
9079:
1.329 droeschl 9080: =back
9081:
9082: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>