Annotation of loncom/interface/londocs.pm, revision 1.484.2.76
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.76! raeburn 4: # $Id: londocs.pm,v 1.484.2.75 2017/11/10 15:52:26 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.484.2.19 raeburn 43: use Apache::lonextresedit();
1.484.2.43 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.329 droeschl 46: use HTML::Entities;
1.484.2.7 raeburn 47: use HTML::TokeParser;
1.329 droeschl 48: use GDBM_File;
1.484.2.51 raeburn 49: use File::MMagic;
1.329 droeschl 50: use Apache::lonlocal;
51: use Cwd;
52: use LONCAPA qw(:DEFAULT :match);
53:
54: my $iconpath;
55:
56: my %hash;
57:
58: my $hashtied;
59: my %alreadyseen=();
60:
61: my $hadchanges;
1.484.2.37 raeburn 62: my $suppchanges;
1.329 droeschl 63:
64:
65: my %help=();
66:
67:
68: sub mapread {
69: my ($coursenum,$coursedom,$map)=@_;
70: return
71: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
72: $map);
73: }
74:
75: sub storemap {
1.484.2.7 raeburn 76: my ($coursenum,$coursedom,$map,$contentchg)=@_;
77: my $report;
78: if (($contentchg) && ($map =~ /^default/)) {
79: $report = 1;
80: }
1.329 droeschl 81: my ($outtext,$errtext)=
82: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 83: $map,1,$report);
1.329 droeschl 84: if ($errtext) { return ($errtext,2); }
1.364 bisitz 85:
1.484.2.37 raeburn 86: if ($map =~ /^default/) {
87: $hadchanges=1;
88: } else {
89: $suppchanges=1;
90: }
1.329 droeschl 91: return ($errtext,0);
92: }
93:
94:
95:
96: sub authorhosts {
97: my %outhash=();
98: my $home=0;
99: my $other=0;
100: foreach my $key (keys(%env)) {
101: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
102: my $role=$1;
103: my $realm=$2;
104: my ($start,$end)=split(/\./,$env{$key});
105: if (($start) && ($start>time)) { next; }
106: if (($end) && (time>$end)) { next; }
107: my ($ca,$cd);
108: if ($1 eq 'au') {
109: $ca=$env{'user.name'};
110: $cd=$env{'user.domain'};
111: } else {
112: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
113: }
114: my $allowed=0;
115: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
116: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 117: foreach my $id (@ids) {
118: if ($id eq $myhome) {
119: $allowed=1;
120: last;
121: }
122: }
1.329 droeschl 123: if ($allowed) {
124: $home++;
1.484 raeburn 125: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 126: } else {
1.484 raeburn 127: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 128: $other++;
129: }
130: }
131: }
132: return ($home,$other,%outhash);
133: }
134:
135:
136: sub clean {
137: my ($title)=@_;
138: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 139: return $title;
1.329 droeschl 140: }
141:
1.484.2.67 raeburn 142: sub default_folderpath {
143: my ($coursenum,$coursedom,$navmapref) = @_;
144: return unless ($coursenum && $coursedom && ref($navmapref));
145: # Check if entire course is hidden and/or encrypted
146: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
147: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
148: unless (ref($$navmapref)) {
149: $$navmapref = Apache::lonnavmaps::navmap->new();
150: }
151: if (ref($$navmapref)) {
152: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
153: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
154: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
155: unless (@resources) {
156: $hiddenmap = 1;
157: unless ($env{'request.role.adv'}) {
158: $hiddentop = 1;
159: if ($env{'form.folder'}) {
160: undef($env{'form.folder'});
161: }
162: }
163: }
164: }
165: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
166: $encryptmap = 1;
167: }
168: }
169: unless ($hiddentop) {
170: $folderpath='default&'.&escape(&mt('Main Content')).
171: '::'.$hiddenmap.':'.$encryptmap.'::';
172: }
173: if (wantarray) {
174: return ($folderpath,$hiddentop);
175: } else {
176: return $folderpath;
177: }
178: }
1.329 droeschl 179:
180: sub dumpcourse {
181: my ($r) = @_;
1.408 raeburn 182: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 183: my ($starthash,$js);
184: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
185: $js = <<"ENDJS";
186: <script type="text/javascript">
187: // <![CDATA[
188:
189: function hide_searching() {
190: if (document.getElementById('searching')) {
191: document.getElementById('searching').style.display = 'none';
192: }
193: return;
194: }
195:
196: // ]]>
197: </script>
198: ENDJS
199: $starthash = {
200: add_entries => {'onload' => "hide_searching();"},
201: };
202: }
203: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
204: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 205: $r->print(&startContentScreen('tools'));
1.329 droeschl 206: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 207: unless ($home) {
208: $r->print(&endContentScreen());
209: return '';
210: }
1.329 droeschl 211: my $origcrsid=$env{'request.course.id'};
212: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
213: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
214: # Do the dumping
1.484 raeburn 215: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
216: $r->print(&endContentScreen());
217: return '';
218: }
1.484.2.24 raeburn 219: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 220: $r->print('<h3>'.&mt('Copying Files').'</h3>');
221: my $title=$env{'form.authorfolder'};
222: $title=&clean($title);
1.484.2.43 raeburn 223: my ($navmap,$errormsg) =
224: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
225: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
226: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
227: my (%maps,%resources,%titles);
228: if (!ref($navmap)) {
229: $r->print($errormsg.
230: &endContentScreen());
231: return '';
232: } else {
233: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
234: 'dumpdocs',$cdom,$cnum);
235: }
236: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
237: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
238: %newcontent,%has_simpleprobs);
239: foreach my $item (sort {$a <=> $b} (@todump)) {
240: my $name = $env{'form.namefor_'.$item};
241: if ($resources{$item}) {
242: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
243: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
244: $tocopy{$1} = $name;
245: $display{$item} = $1;
246: $lookup{$1} = $item;
247: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
248: $simpleproblems{$item} = {
249: symb => $resources{$item},
250: name => $name,
251: };
252: $display{$item} = 'simpleproblem_'.$name;
253: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
254: $has_simpleprobs{$1}{$id} = $item;
255: }
256: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
257: my $marker = $1;
258: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
259: $simplepages{$item} = {
260: res => $res,
261: title => $titles{$item},
262: db => $db_name,
263: marker => $marker,
264: symb => $resources{$item},
265: name => $name,
266: };
267: $display{$item} = '/'.$res;
268: }
269: } elsif ($maps{$item}) {
270: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
271: $tocopy{$1} = $name;
272: $display{$item} = $1;
273: $lookup{$1} = $item;
274: }
275: } else {
276: next;
277: }
278: }
1.329 droeschl 279: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
280: $crs=~s/\_/\//g;
1.484.2.43 raeburn 281: my $mm = new File::MMagic;
282: my $prefix = "/uploaded/$cdom/$cnum/";
283: %replacehash = %tocopy;
284: foreach my $item (sort(keys(%simpleproblems))) {
285: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
286: $newcontent{$display{$item}} = $content;
287: }
288: my $gateway = Apache::lonhtmlgateway->new('web');
289: foreach my $item (sort(keys(%simplepages))) {
290: if (ref($simplepages{$item}) eq 'HASH') {
291: my $pagetitle = $simplepages{$item}{'title'};
292: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
293: my %contents;
294: foreach my $field (keys(%fields)) {
295: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
296: my $name = $1;
297: my $msg = $fields{$field};
298: if ($name eq 'webreferences') {
299: if ($msg =~ m{^https?://}) {
300: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
301: }
302: } else {
303: $msg = &Encode::decode('utf8',$msg);
304: $msg = $gateway->process_outgoing_html($msg,1);
305: $contents{$name} = $msg;
306: }
307: } elsif ($field eq 'uploaded.photourl') {
308: my $marker = $simplepages{$item}{marker};
309: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
310: my $filepath = $1;
311: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
312: if ($fname ne '') {
313: $fname=~s/\.(\w+)$//;
314: my $ext=$1;
315: $fname = &clean($fname);
316: $fname.='.'.$ext;
317: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
318: $replacehash{$filepath} = $relpath.$fname;
319: $deps{$item}{$filepath} = 1;
320: }
321: }
322: }
323: }
324: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
325: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
326: my $content = '
327: <html>
328: <head>
329: <title>'.$pagetitle.'</title>
330: </head>
331: <body bgcolor="#ffffff">';
332: if ($contents{title}) {
333: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
334: }
335: if ($contents{image}) {
336: $content .= "\n".$contents{image};
337: }
338: if ($contents{content}) {
339: $content .= '
340: <div class="LC_Box">
1.484.2.50 raeburn 341: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 342: $contents{content}.'
343: </div>';
344: }
345: if ($contents{webreferences}) {
346: $content .= '
347: <div class="LC_Box">
1.484.2.50 raeburn 348: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 349: $contents{webreferences}.'
350: </div>';
351: }
352: $content .= '
353: </body>
354: </html>
355: ';
356: $newcontent{'/'.$simplepages{$item}{res}} = $content;
357: }
358: }
359: foreach my $item (keys(%tocopy)) {
360: unless ($item=~/\.(sequence|page)$/) {
361: my $currurlpath = $prefix.$item;
362: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
363: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
364: }
365: }
366: foreach my $num (sort {$a <=> $b} (@todump)) {
367: my $src = $display{$num};
368: next if ($src eq '');
369: my @needcopy = ();
370: if ($replacehash{$src}) {
371: push(@needcopy,$src);
372: if (ref($deps{$num}) eq 'HASH') {
373: foreach my $dep (sort(keys(%{$deps{$num}}))) {
374: if ($replacehash{$dep}) {
375: push(@needcopy,$dep);
376: }
377: }
378: }
379: } elsif ($src =~ /^simpleproblem_/) {
380: push(@needcopy,$src);
381: }
382: next if (@needcopy == 0);
383: my ($result,$depresult);
384: for (my $i=0; $i<@needcopy; $i++) {
385: my $item = $needcopy[$i];
386: my $newfilename;
387: if ($simpleproblems{$num}) {
388: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
389: } else {
390: $newfilename=$title.'/'.$replacehash{$item};
391: }
392: $newfilename=~s/\.(\w+)$//;
393: my $ext=$1;
394: $newfilename=&clean($newfilename);
395: $newfilename.='.'.$ext;
396: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
397: if ($newrelpath ne $replacehash{$item}) {
398: $replacehash{$item} = $newrelpath;
399: }
400: my @dirs=split(/\//,$newfilename);
401: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
402: my $makepath=$path;
403: my $fail;
404: my $origin;
405: for (my $i=0;$i<$#dirs;$i++) {
406: $makepath.='/'.$dirs[$i];
407: unless (-e $makepath) {
408: unless(mkdir($makepath,0755)) {
409: $fail = &mt('Directory creation failed.');
410: }
411: }
412: }
413: if ($i == 0) {
414: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
415: } else {
416: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
417: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
418: &mt('(dependency)').'</span>: ';
419: }
420: if (-e $path.'/'.$newfilename) {
421: $fail = &mt('Destination already exists -- not overwriting.');
422: } else {
423: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
424: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
425: ($item =~ /^simpleproblem_/)) {
426: print $fh $newcontent{$item};
427: } else {
428: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
429: if (-e $fileloc) {
430: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
431: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
432: (ref($has_simpleprobs{$item}) eq 'HASH')) {
433: my %changes = %{$has_simpleprobs{$item}};
434: my $content = &Apache::lonclonecourse::rewritefile(
435: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
436: (%replacehash,$crs => '')
437: );
438: my $updatedcontent = '';
439: my $parser = HTML::TokeParser->new(\$content);
440: $parser->attr_encoded(1);
441: while (my $token = $parser->get_token) {
442: if ($token->[0] eq 'S') {
443: if (($token->[1] eq 'resource') &&
444: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
445: ($changes{$token->[2]->{'id'}})) {
446: my $id = $token->[2]->{'id'};
447: $updatedcontent .= '<'.$token->[1];
448: foreach my $attrib (@{$token->[3]}) {
449: next unless ($attrib =~ /^(src|type|title|id)$/);
450: if ($attrib eq 'src') {
451: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
452: if ($file) {
453: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
454: } else {
455: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
456: }
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: }
461: $updatedcontent .= ' />'."\n";
462: } else {
463: $updatedcontent .= $token->[4]."\n";
464: }
465: } else {
466: $updatedcontent .= $token->[2];
467: }
468: }
469: print $fh $updatedcontent;
470: } else {
471: print $fh &Apache::lonclonecourse::rewritefile(
472: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
473: (%replacehash,$crs => '')
474: );
475: }
476: } else {
477: print $fh
478: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
479: }
480: } else {
481: $fail = &mt('Source does not exist.');
482: }
483: }
484: $fh->close();
485: } else {
486: $fail = &mt('Could not write to destination.');
487: }
488: }
489: my $text;
490: if ($fail) {
491: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
492: } else {
493: $text = '<span class="LC_success">'.&mt('ok').'</span>';
494: }
495: if ($i == 0) {
496: $result .= $text;
497: } else {
498: $depresult .= $text.'</li>';
499: }
500: }
501: $r->print($result);
502: if ($depresult) {
503: $r->print('<ul>'.$depresult.'</ul>');
504: }
505: }
1.329 droeschl 506: } else {
1.484.2.43 raeburn 507: my ($navmap,$errormsg) =
508: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
509: if (!ref($navmap)) {
510: $r->print($errormsg);
511: } else {
512: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
513: $r->rflush();
514: my ($preamble,$formname);
515: $formname = 'dumpdoc';
516: unless ($home==1) {
517: $preamble = '<div class="LC_left_float">'.
518: '<fieldset><legend>'.
519: &mt('Select the Authoring Space').
520: '</legend><select name="authorspace">';
521: }
522: my @orderspaces = ();
523: foreach my $key (sort(keys(%outhash))) {
524: if ($key=~/^home_(.+)$/) {
525: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
526: unshift(@orderspaces,$1);
527: } else {
528: push(@orderspaces,$1);
529: }
530: }
531: }
532: if ($home>1) {
533: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
534: }
535: foreach my $user (@orderspaces) {
536: if ($home==1) {
537: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
538: } else {
539: $preamble .= '<option value="'.$user.'">'.$user.' - '.
540: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
541: }
542: }
543: unless ($home==1) {
544: $preamble .= '</select></fieldset></div>'."\n";
545: }
546: my $title=$origcrsdata{'description'};
547: $title=~s/[\/\s]+/\_/gs;
548: $title=&clean($title);
549: $preamble .= '<div class="LC_left_float">'.
550: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
551: '<input type="text" size="50" name="authorfolder" value="'.
552: $title.'" />'.
553: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
554: my %uploadedfiles;
555: &tiehash();
556: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
557: my ($ext)=($file=~/\.(\w+)$/);
558: # FIXME Check supplemental here
559: my $title=$hash{'title_'.$hash{
560: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
561: if (!$title) {
562: $title=$file;
563: } else {
564: $title=~s|/|_|g;
565: }
566: $title=~s/\.(\w+)$//;
567: $title=&clean($title);
568: $title.='.'.$ext;
569: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
570: $uploadedfiles{$file} = $title;
571: }
572: &untiehash();
573: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
574: undef,undef,$preamble,$home,\%uploadedfiles));
575: }
1.329 droeschl 576: }
1.484 raeburn 577: $r->print(&endContentScreen());
1.329 droeschl 578: }
579:
1.484.2.43 raeburn 580: sub recurse_html {
581: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
582: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
583: my (%allfiles,%codebase);
584: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
585: if (keys(%allfiles)) {
586: foreach my $dependency (keys(%allfiles)) {
587: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
588: my ($depurl,$relfile,$newcontainer);
589: if ($dependency =~ m{^/}) {
590: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
591: $relfile = $1;
592: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
593: $newcontainer = $1;
594: next if ($replacehash->{$newcontainer});
595: }
596: $depurl = $dependency;
597: } else {
598: next;
599: }
600: } else {
601: $relfile = $dependency;
602: $depurl = $currurlpath;
603: $depurl =~ s{[^/]+$}{};
604: $depurl .= $dependency;
605: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
606: }
607: next if ($relfile eq '');
608: my $newname = $replacehash->{$container};
609: $newname =~ s{[^/]+$}{};
610: $replacehash->{$newcontainer} = $newname.$relfile;
611: $deps->{$item}{$newcontainer} = 1;
612: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
613: my $depfile = &Apache::lonnet::filelocation('',$depurl);
614: my $type = $mm->checktype_filename($depfile);
615: if ($type eq 'text/html') {
616: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
617: }
618: }
619: }
620: }
621: return;
622: }
623:
1.329 droeschl 624: sub group_import {
625: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
1.484.2.23 raeburn 626: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
627: %removeparam,$importuploaded,$fixuperrors);
628: $allmaps = {};
1.329 droeschl 629: while (@files) {
630: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 631: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 632: && ($caller eq 'londocs')
633: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 634:
1.329 droeschl 635: my $errtext = '';
636: my $fatal = 0;
637: my $newmapstr = '<map>'."\n".
638: '<resource id="1" src="" type="start"></resource>'."\n".
639: '<link from="1" to="2" index="1"></link>'."\n".
640: '<resource id="2" src="" type="finish"></resource>'."\n".
641: '</map>';
642: $env{'form.output'}=$newmapstr;
643: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
644: 'output',$1.$2);
1.484.2.27 raeburn 645: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 646: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
647: $fatal = 2;
648: }
649: if ($fatal) {
650: return ($errtext,$fatal);
651: }
652: }
653: if ($url) {
1.484.2.23 raeburn 654: if (($caller eq 'londocs') &&
655: ($folder =~ /^default/)) {
1.484.2.27 raeburn 656: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 657: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
658: my $cid = $coursedom.'_'.$coursenum;
659: $allmaps =
660: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
661: $chome,$cid);
662: $donechk = 1;
663: }
664: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
665: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
666: \%addedmaps,\%hierarchy,\%titles,$allmaps);
667: $importuploaded = 1;
668: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
669: next if ($allmaps->{$url});
670: }
671: }
1.344 bisitz 672: if (!$residx
1.329 droeschl 673: || defined($LONCAPA::map::zombies[$residx])) {
674: $residx = &LONCAPA::map::getresidx($url,$residx);
675: push(@LONCAPA::map::order, $residx);
676: }
677: my $ext = 'false';
678: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
679: $name = &LONCAPA::map::qtunescape($name);
1.484.2.27 raeburn 680: if ($name eq '') {
1.484.2.30 raeburn 681: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.484.2.27 raeburn 682: }
683: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
684: my $filepath = $1;
685: my $fname = $name;
686: if ($fname =~ /^\W+$/) {
687: $fname = 'web';
688: } else {
689: $fname =~ s/\W/_/g;
690: }
1.484.2.62 raeburn 691: if (length($fname) > 15) {
1.484.2.27 raeburn 692: $fname = substr($fname,0,14);
693: }
694: my $initialtext = &mt('Replace with your own content.');
695: my $newhtml = <<END;
1.484.2.31 raeburn 696: <html>
1.484.2.27 raeburn 697: <head>
698: <title>$name</title>
699: </head>
700: <body bgcolor="#ffffff">
701: $initialtext
702: </body>
703: </html>
704: END
705: $env{'form.output'}=$newhtml;
706: my $result =
707: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
708: 'output',
709: "$filepath/$residx/$fname.html");
710: if ($result =~ m{^/uploaded/}) {
711: $url = $result;
712: if ($filepath =~ /^supplemental/) {
713: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
714: $env{'user.domain'}.'___&&&___'.$name;
715: }
716: } else {
717: return (&mt('Failed to save new web page.'),1);
718: }
719: }
1.484.2.30 raeburn 720: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 721: $LONCAPA::map::resources[$residx] =
1.329 droeschl 722: join(':', ($name, $url, $ext, 'normal', 'res'));
723: }
724: }
1.484.2.23 raeburn 725: if ($importuploaded) {
726: my %import_errors;
727: my %updated = (
728: removefrommap => \%removefrommap,
729: removeparam => \%removeparam,
730: );
1.484.2.26 raeburn 731: my ($result,$msgsarray,$lockerror) =
732: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 733: if (keys(%import_errors) > 0) {
734: $fixuperrors =
735: '<p span class="LC_warning">'."\n".
736: &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".
737: '<ul>'."\n";
738: foreach my $key (sort(keys(%import_errors))) {
739: $fixuperrors .= '<li>'.$key.'</li>'."\n";
740: }
741: $fixuperrors .= '</ul></p>'."\n";
742: }
1.484.2.26 raeburn 743: if (ref($msgsarray) eq 'ARRAY') {
744: if (@{$msgsarray} > 0) {
745: $fixuperrors .= '<p class="LC_info">'.
746: join('<br />',@{$msgsarray}).
747: '</p>';
748: }
749: }
750: if ($lockerror) {
751: $fixuperrors .= '<p class="LC_error">'.
752: $lockerror.
753: '</p>';
754: }
1.484.2.23 raeburn 755: }
756: my ($errtext,$fatal) =
757: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 758: unless ($fatal) {
759: if ($folder =~ /^supplemental/) {
760: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 761: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
762: $folder.'.'.$container);
1.484.2.37 raeburn 763: }
764: }
1.484.2.23 raeburn 765: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 766: }
767:
768: sub log_docs {
1.484.2.8 raeburn 769: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 770: }
771:
772: {
773: my @oldresources=();
774: my @oldorder=();
775: my $parmidx;
776: my %parmaction=();
777: my %parmvalue=();
778: my $changedflag;
779:
780: sub snapshotbefore {
781: @oldresources=@LONCAPA::map::resources;
782: @oldorder=@LONCAPA::map::order;
783: $parmidx=undef;
784: %parmaction=();
785: %parmvalue=();
786: $changedflag=0;
787: }
788:
789: sub remember_parms {
790: my ($idx,$parameter,$action,$value)=@_;
791: $parmidx=$idx;
792: $parmaction{$parameter}=$action;
793: $parmvalue{$parameter}=$value;
794: $changedflag=1;
795: }
796:
797: sub log_differences {
798: my ($plain)=@_;
799: my %storehash=('folder' => $plain,
800: 'currentfolder' => $env{'form.folder'});
801: if ($parmidx) {
802: $storehash{'parameter_res'}=$oldresources[$parmidx];
803: foreach my $parm (keys(%parmaction)) {
804: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
805: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
806: }
807: }
808: my $maxidx=$#oldresources;
809: if ($#LONCAPA::map::resources>$#oldresources) {
810: $maxidx=$#LONCAPA::map::resources;
811: }
812: for (my $idx=0; $idx<=$maxidx; $idx++) {
813: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
814: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
815: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
816: $changedflag=1;
817: }
818: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
819: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
820: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
821: $changedflag=1;
822: }
823: }
824: $storehash{'maxidx'}=$maxidx;
825: if ($changedflag) { &log_docs(\%storehash); }
826: }
827: }
828:
829: sub docs_change_log {
1.484.2.67 raeburn 830: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 831: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 832: my $navmap;
1.483 raeburn 833: my $js = '<script type="text/javascript">'."\n".
834: '// <![CDATA['."\n".
835: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 836: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
837: $coursedom,$coursenum,$canedit,\$navmap)."\n".
1.483 raeburn 838: &history_tab_js()."\n".
1.484 raeburn 839: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 840: '// ]]>'."\n".
841: '</script>'."\n";
1.484 raeburn 842: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
843: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 844: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 845: my %orderhash;
846: my $container='sequence';
847: my $pathitem;
1.484.2.19 raeburn 848: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 849: $container='page';
850: }
1.484.2.19 raeburn 851: my $folderpath=$env{'form.folderpath'};
852: if ($folderpath eq '') {
1.484.2.67 raeburn 853: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 854: }
1.484.2.67 raeburn 855: undef($navmap);
1.484.2.19 raeburn 856: $pathitem = '<input type="hidden" name="folderpath" value="'.
857: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 858: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
859: my $jumpto = $readfile;
860: $jumpto =~ s{^/}{};
861: my $tid = 1;
1.484.2.7 raeburn 862: if ($supplementalflag) {
863: $tid = 2;
864: }
1.484.2.19 raeburn 865: my ($breadcrumbtrail) =
1.484.2.18 raeburn 866: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 867: $r->print($breadcrumbtrail.
868: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
869: $readfile));
1.329 droeschl 870: my %docslog=&Apache::lonnet::dump('nohist_docslog',
871: $env{'course.'.$env{'request.course.id'}.'.domain'},
872: $env{'course.'.$env{'request.course.id'}.'.num'});
873:
874: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
875:
876: my %saveable_parameters = ('show' => 'scalar',);
877: &Apache::loncommon::store_course_settings('docs_log',
878: \%saveable_parameters);
879: &Apache::loncommon::restore_course_settings('docs_log',
880: \%saveable_parameters);
881: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 882: # FIXME: internationalization seems wrong here
1.329 droeschl 883: my %lt=('hiddenresource' => 'Resources hidden',
884: 'encrypturl' => 'URL hidden',
885: 'randompick' => 'Randomly pick',
886: 'randomorder' => 'Randomly ordered',
887: 'set' => 'set to',
888: 'del' => 'deleted');
1.484 raeburn 889: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
890: $pathitem."\n".
891: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
892: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
893: $r->print('<div class="LC_left_float">'.
894: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
895: &makedocslogform($filter,1).
896: '</fieldset></div><br clear="all" />');
1.329 droeschl 897: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
898: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
899: &mt('After').'</th>'.
900: &Apache::loncommon::end_data_table_header_row());
901: my $shown=0;
902: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
903: if ($env{'form.displayfilter'} eq 'currentfolder') {
904: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
905: }
906: my @changes=keys(%{$docslog{$id}{'logentry'}});
907: if ($env{'form.displayfilter'} eq 'containing') {
908: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
909: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
910: foreach my $key (@changes) {
911: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
912: }
1.344 bisitz 913: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 914: }
915: my $count = 0;
916: my $time =
917: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
918: my $plainname =
919: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
920: $docslog{$id}{'exe_udom'});
921: my $about_me_link =
922: &Apache::loncommon::aboutmewrapper($plainname,
923: $docslog{$id}{'exe_uname'},
924: $docslog{$id}{'exe_udom'});
925: my $send_msg_link='';
926: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
927: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
928: $send_msg_link ='<br />'.
929: &Apache::loncommon::messagewrapper(&mt('Send message'),
930: $docslog{$id}{'exe_uname'},
931: $docslog{$id}{'exe_udom'});
932: }
933: $r->print(&Apache::loncommon::start_data_table_row());
934: $r->print('<td>'.$time.'</td>
935: <td>'.$about_me_link.
936: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
937: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
938: $send_msg_link.'</td><td>'.
939: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 940: my $is_supp = 0;
1.484.2.7 raeburn 941: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
942: $is_supp = 1;
943: }
1.329 droeschl 944: # Before
945: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
946: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
947: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
948: if ($oldname ne $newname) {
1.484.2.7 raeburn 949: my $shown = &LONCAPA::map::qtescape($oldname);
950: if ($is_supp) {
951: $shown = &Apache::loncommon::parse_supplemental_title($shown);
952: }
953: $r->print($shown);
1.329 droeschl 954: }
955: }
956: $r->print('<ul>');
957: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
958: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 959: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
960: if ($is_supp) {
961: $shown = &Apache::loncommon::parse_supplemental_title($shown);
962: }
1.484.2.19 raeburn 963: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 964: }
965: }
966: $r->print('</ul>');
967: # After
968: $r->print('</td><td>');
969:
970: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
971: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
972: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
973: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 974: my $shown = &LONCAPA::map::qtescape($newname);
975: if ($is_supp) {
976: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
977: }
978: $r->print($shown);
1.329 droeschl 979: }
1.364 bisitz 980: }
1.329 droeschl 981: $r->print('<ul>');
982: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
983: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 984: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
985: if ($is_supp) {
986: $shown = &Apache::loncommon::parse_supplemental_title($shown);
987: }
988: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 989: }
990: }
991: $r->print('</ul>');
992: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
993: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
994: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
995: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 996: # FIXME: internationalization seems wrong here
1.329 droeschl 997: $r->print('<li>'.
998: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
999: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1000: .'</li>');
1001: }
1002: }
1003: $r->print('</ul>');
1004: }
1005: # End
1006: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1007: $shown++;
1008: if (!($env{'form.show'} eq &mt('all')
1009: || $shown<=$env{'form.show'})) { last; }
1010: }
1.484 raeburn 1011: $r->print(&Apache::loncommon::end_data_table()."\n".
1012: &makesimpleeditform($pathitem)."\n".
1013: '</div></div>');
1014: $r->print(&endContentScreen());
1.329 droeschl 1015: }
1016:
1017: sub update_paste_buffer {
1.484.2.7 raeburn 1018: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1019: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1020: if ($env{'form.multiremove'}) {
1021: $env{'form.multiremove'} =~ s/,$//;
1022: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1023: }
1024: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1025: if ($env{'form.multicut'}) {
1026: $env{'form.multicut'} =~ s/,$//;
1027: foreach my $item (split(/,/,$env{'form.multicut'})) {
1028: unless ($removals{$item}) {
1029: $cuts{$item} = 1;
1030: push(@possibles,$item.':cut');
1031: }
1032: }
1033: }
1034: if ($env{'form.multicopy'}) {
1035: $env{'form.multicopy'} =~ s/,$//;
1036: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1037: unless ($removals{$item} || $cuts{$item}) {
1038: push(@possibles,$item.':copy');
1039: }
1040: }
1041: }
1042: } elsif ($env{'form.markcopy'}) {
1043: @possibles = split(/,/,$env{'form.markcopy'});
1044: }
1.329 droeschl 1045:
1.484.2.30 raeburn 1046: return if (@possibles == 0);
1.329 droeschl 1047: return if (!defined($env{'form.copyfolder'}));
1048:
1049: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1050: $env{'form.copyfolder'});
1051: return if ($fatal);
1052:
1.484.2.30 raeburn 1053: my %curr_groups = &Apache::longroup::coursegroups();
1054:
1055: # Retrieve current paste buffer suffixes.
1056: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1057: my (%pasteurls,@newpaste);
1058:
1059: # Construct identifiers for current contents of user's paste buffer
1060: if (@currpaste) {
1061: foreach my $suffix (@currpaste) {
1062: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1063: my $url = $env{'docs.markedcopy_url_'.$suffix};
1064: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1065: ($url ne '')) {
1.484.2.41 raeburn 1066: $pasteurls{$cid.'_'.$url} = 1;
1.484.2.30 raeburn 1067: }
1068: }
1069: }
1070:
1071: # Mark items for copying (skip any items already in user's paste buffer)
1072: my %addtoenv;
1073:
1074: foreach my $item (@possibles) {
1075: my ($orderidx,$cmd) = split(/:/,$item);
1076: next if ($orderidx =~ /\D/);
1077: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1078: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1079: my %denied = &action_restrictions($coursenum,$coursedom,
1080: &LONCAPA::map::qtescape($url),
1081: $env{'form.folderpath'},\%curr_groups);
1082: next if ($denied{'copy'});
1083: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1084: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1085: my ($suffix,$errortxt,$locknotfreed) =
1086: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1087: if ($suffix ne '') {
1088: push(@newpaste,$suffix);
1089: } else {
1090: if ($locknotfreed) {
1091: return $locknotfreed;
1092: }
1.484.2.30 raeburn 1093: }
1094: if (&is_supplemental_title($title)) {
1095: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1096: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1097: }
1098:
1099: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1100: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1101: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1102: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1103:
1104: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1105: my $prefix = $1;
1106: my $subdir =$2;
1107: if ($subdir eq '') {
1108: $subdir = $prefix;
1.484.2.7 raeburn 1109: }
1.484.2.30 raeburn 1110: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1111: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1112: \%hierarchy,\%titles,\%allmaps);
1113: if (ref($hierarchy{$url}) eq 'HASH') {
1114: my ($nested,$nestednames);
1115: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1116: $nested =~ s/\&$//;
1117: $nestednames =~ s/\Q___&&&___\E$//;
1118: if ($nested ne '') {
1119: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1120: }
1121: if ($nestednames ne '') {
1122: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1123: }
1.484.2.7 raeburn 1124: }
1125: }
1.484.2.57 raeburn 1126: if ($locknotfreed) {
1127: $output = $locknotfreed;
1128: last;
1129: }
1.484.2.7 raeburn 1130: }
1.484.2.30 raeburn 1131: if (@newpaste) {
1132: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1133: }
1.484.2.7 raeburn 1134: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1135: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1136: return $output;
1.329 droeschl 1137: }
1138:
1.484.2.7 raeburn 1139: sub recurse_uploaded_maps {
1140: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1141: if (ref($hierarchy->{$url}) eq 'HASH') {
1142: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1143: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1144: my (@uploaded,@names,%shorter);
1145: for (my $i=0; $i<@maps; $i++) {
1146: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1147: if ($inner ne '') {
1148: push(@uploaded,$inner);
1149: push(@names,&escape($titles[$i]));
1150: $shorter{$maps[$i]} = $inner;
1151: }
1152: }
1153: $$nestref .= "$dir:".join(',',@uploaded).'&';
1154: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1155: foreach my $map (@maps) {
1156: if ($shorter{$map} ne '') {
1157: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1158: }
1159: }
1160: }
1161: return;
1162: }
1163:
1.329 droeschl 1164: sub print_paste_buffer {
1.484.2.7 raeburn 1165: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1166: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1167:
1.484.2.30 raeburn 1168: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1169: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1170: }
1171:
1.484.2.30 raeburn 1172: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1173: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1174: my $clipboardcount = 0;
1.484.2.7 raeburn 1175:
1.484.2.30 raeburn 1176: # Construct identifiers for current contents of user's paste buffer
1177: foreach my $suffix (@currpaste) {
1178: next if ($suffix =~ /\D/);
1179: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1180: my $url = $env{'docs.markedcopy_url_'.$suffix};
1181: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1182: ($url ne '')) {
1.484.2.47 raeburn 1183: $clipboardcount ++;
1.484.2.30 raeburn 1184: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1185: $canpaste,$nopaste,$othercrs,$areachange);
1186: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1187: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1188: $is_external = 1;
1.484.2.7 raeburn 1189: }
1.484.2.30 raeburn 1190: if ($folder =~ /^supplemental/) {
1191: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1192: unless ($canpaste) {
1193: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1194: }
1.484.2.30 raeburn 1195: } else {
1196: $canpaste = 1;
1.484.2.7 raeburn 1197: }
1.484.2.30 raeburn 1198: if ($canpaste) {
1199: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1200: my $srcdom = $1;
1201: my $srcnum = $2;
1202: my $rem = $3;
1203: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1204: $othercourse = 1;
1205: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76! raeburn 1206: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1207: } else {
1208: $canpaste = 0;
1209: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1210: }
1211: }
1.484.2.30 raeburn 1212: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1213: my $prefix = $1;
1214: $parent = $2;
1215: if ($folder !~ /^\Q$prefix\E/) {
1216: $areachange = 1;
1217: }
1218: $is_uploaded_map = 1;
1219: }
1.484.2.76! raeburn 1220: } elsif ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$}) {
! 1221: if ($cid ne $env{'request.course.id'}) {
! 1222: my ($srcdom,$srcnum) = split(/_/,$cid);
! 1223: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
! 1224: $othercrs = '<br />'.&mt('(from another course)');
! 1225: } else {
! 1226: $canpaste = 0;
! 1227: $nopaste = &mt('Paste from another course unavailable.');
! 1228: }
! 1229: }
! 1230: }
! 1231: if ($canpaste) {
! 1232: push(@pasteable,$suffix);
1.484.2.30 raeburn 1233: }
1234: }
1235: my $buffer;
1236: if ($is_external) {
1237: $buffer = &mt('External Resource').': '.
1238: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1239: &LONCAPA::map::qtescape($url).')';
1240: } else {
1241: my $icon = &Apache::loncommon::icon($extension);
1242: if ($extension eq 'sequence' &&
1243: $url =~ m{/default_\d+\.sequence$}x) {
1244: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1245: $icon .= '/navmap.folder.closed.gif';
1246: }
1.484.2.57 raeburn 1247: my $title = $env{'docs.markedcopy_title_'.$suffix};
1248: if ($title eq '') {
1249: ($title) = ($url =~ m{/([^/]+)$});
1250: }
1.484.2.30 raeburn 1251: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1252: ': '.
1253: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1254: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1255: }
1256: $pasteitems .= '<div class="LC_left_float">';
1257: my ($options,$onclick);
1258: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1259: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1260: if (($is_uploaded_map) ||
1261: ($url =~ /(bulletinboard|smppg)$/) ||
1262: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1263: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1264: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1265: }
1266: }
1267: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1268: if ($nopaste) {
1269: $pasteitems .= $nopaste;
1270: } else {
1271: if ($othercrs) {
1272: $pasteitems .= $othercrs;
1273: }
1274: if ($options) {
1275: $pasteitems .= $options;
1.484.2.7 raeburn 1276: }
1277: }
1.484.2.30 raeburn 1278: $pasteitems .= '</div>';
1279: }
1280: }
1281: if ($pasteitems eq '') {
1282: &Apache::lonnet::delenv('docs.markedcopies');
1283: }
1284: my ($pasteform,$form_start,$buttons,$form_end);
1285: if ($pasteitems) {
1286: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1287: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1288: if (@pasteable) {
1.484.2.47 raeburn 1289: my $value = &mt('Paste to current folder');
1290: if ($container eq 'page') {
1291: $value = &mt('Paste to current page');
1292: }
1293: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1294: }
1295: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.(' 'x2);
1296: if ($clipboardcount > 1) {
1297: $buttons .=
1298: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1299: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1300: (' 'x2).
1301: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1302: (' 'x2);
1.484.2.7 raeburn 1303: }
1.484.2.48 raeburn 1304: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1305: '</form>';
1.484.2.30 raeburn 1306: } else {
1307: $pasteitems = &mt('Clipboard is empty');
1308: }
1309: $r->print($form_start
1310: .'<fieldset>'
1311: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1312: .$pasteitems
1313: .'</fieldset>'
1314: .$form_end);
1315: }
1316:
1317: sub paste_options {
1318: my ($suffix,$is_uploaded_map,$parent) = @_;
1319: my ($copytext,$movetext);
1320: if ($is_uploaded_map) {
1321: $copytext = &mt('Copy to new folder');
1322: $movetext = &mt('Move old');
1323: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1324: $copytext = &mt('Copy to new board');
1325: $movetext = &mt('Move (not posts)');
1326: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1327: $copytext = &mt('Copy to new page');
1328: $movetext = &mt('Move');
1.484.2.7 raeburn 1329: } else {
1.484.2.30 raeburn 1330: $copytext = &mt('Copy to new file');
1331: $movetext = &mt('Move');
1332: }
1333: my $output = '<br />'.
1334: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1335: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1336: '<label>'.
1337: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1338: $copytext.'</label></span>'.(' 'x2).' '.
1339: '<span class="LC_nobreak"><label>'.
1340: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1341: $movetext.'</label></span>';
1342: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1343: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1344: '</legend><table border="0">';
1345: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1346: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1347: my $lastdir = $parent;
1348: my %depths = (
1349: $lastdir => 0,
1350: );
1351: my (%display,%deps);
1352: for (my $i=0; $i<@pastemaps; $i++) {
1353: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1354: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1355: my @subfolders = split(/,/,$subfolderstr);
1356: $deps{$lastdir} = \@subfolders;
1357: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1358: my $depth = $depths{$lastdir} + 1;
1359: my $offset = int($depth * 4);
1360: my $indent = (' ' x $offset);
1361: for (my $j=0; $j<@subfolders; $j++) {
1362: $depths{$subfolders[$j]} = $depth;
1363: $display{$subfolders[$j]} =
1364: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1365: '<td><label>'.
1366: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1367: '<label>'.
1368: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1369: &mt('Move old').'</label>'.
1370: '</td></tr>';
1371: }
1372: }
1373: &recurse_print(\$output,$parent,\%deps,\%display);
1374: $output .= '</table></fieldset>';
1.329 droeschl 1375: }
1.484.2.30 raeburn 1376: $output .= '</div>';
1377: return $output;
1.329 droeschl 1378: }
1379:
1.484.2.7 raeburn 1380: sub recurse_print {
1.484.2.30 raeburn 1381: my ($outputref,$dir,$deps,$display) = @_;
1382: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1383: if (ref($deps->{$dir}) eq 'ARRAY') {
1384: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1385: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1386: }
1387: }
1388: }
1389:
1390: sub supp_pasteable {
1391: my ($url) = @_;
1392: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1393: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1394: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1395: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1396: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1397: return 1;
1398: }
1399: return;
1400: }
1401:
1402: sub paste_popup_js {
1.484.2.61 raeburn 1403: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1404: show => 'Show Options',
1405: hide => 'Hide Options',
1.484.2.61 raeburn 1406: );
1407: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1408: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1409: );
1.484.2.61 raeburn 1410: &html_escape(\%html_js_lt);
1411: &js_escape(\%html_js_lt);
1412: &js_escape(\%js_lt);
1.484.2.7 raeburn 1413: return <<"END";
1414:
1.484.2.30 raeburn 1415: function showPasteOptions(suffix) {
1416: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1417: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1418: return;
1419: }
1420:
1.484.2.30 raeburn 1421: function hidePasteOptions(suffix) {
1422: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1423: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1424: return;
1425: }
1426:
1.484.2.30 raeburn 1427: function showOptions(caller,suffix) {
1428: if (document.getElementById('pasteoptionstext_'+suffix)) {
1429: if (caller.checked) {
1.484.2.61 raeburn 1430: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1431: } else {
1432: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1433: }
1434: if (document.getElementById('pasteoptions_'+suffix)) {
1435: document.getElementById('pasteoptions_'+suffix).style.display='none';
1436: }
1437: }
1438: return;
1439: }
1.484.2.7 raeburn 1440:
1.484.2.30 raeburn 1441: function validateClipboard() {
1442: var numchk = 0;
1443: if (document.pasteform.pasting.length > 1) {
1444: for (var i=0; i<document.pasteform.pasting.length; i++) {
1445: if (document.pasteform.pasting[i].checked) {
1446: numchk ++;
1447: }
1448: }
1449: } else {
1450: if (document.pasteform.pasting.type == 'checkbox') {
1451: if (document.pasteform.pasting.checked) {
1452: numchk ++;
1453: }
1454: }
1455: }
1456: if (numchk > 0) {
1457: return true;
1458: } else {
1.484.2.61 raeburn 1459: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1460: return false;
1461: }
1.484.2.7 raeburn 1462: }
1463:
1.484.2.47 raeburn 1464: function checkClipboard() {
1465: if (document.pasteform.pasting.length > 1) {
1466: for (var i=0; i<document.pasteform.pasting.length; i++) {
1467: document.pasteform.pasting[i].checked = true;
1468: }
1469: }
1470: return;
1471: }
1472:
1473: function uncheckClipboard() {
1474: if (document.pasteform.pasting.length >1) {
1475: for (var i=0; i<document.pasteform.pasting.length; i++) {
1476: document.pasteform.pasting[i].checked = false;
1477: }
1478: }
1479: return;
1480: }
1481:
1.484.2.30 raeburn 1482: END
1483:
1484: }
1.484.2.7 raeburn 1485:
1.329 droeschl 1486: sub do_paste_from_buffer {
1.484.2.7 raeburn 1487: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1488:
1.484.2.30 raeburn 1489: # Array of items in paste buffer
1490: my (@currpaste,%pastebuffer,%allerrors);
1491: @currpaste = split(/,/,$env{'docs.markedcopies'});
1492:
1.484.2.7 raeburn 1493: # Early out if paste buffer is empty
1.484.2.30 raeburn 1494: if (@currpaste == 0) {
1.484.2.7 raeburn 1495: return ();
1.484.2.30 raeburn 1496: }
1497: map { $pastebuffer{$_} = 1; } @currpaste;
1498:
1499: # Array of items selected items to paste
1500: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1501:
1502: # Early out if nothing selected to paste
1503: if (@reqpaste == 0) {
1504: return();
1505: }
1506: my @topaste;
1507: foreach my $suffix (@reqpaste) {
1508: next if ($suffix =~ /\D/);
1509: next unless (exists($pastebuffer{$suffix}));
1510: push(@topaste,$suffix);
1.484.2.7 raeburn 1511: }
1512:
1.484.2.30 raeburn 1513: # Early out if nothing available to paste
1514: if (@topaste == 0) {
1515: return();
1.329 droeschl 1516: }
1517:
1.484.2.30 raeburn 1518: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.484.2.41 raeburn 1519: %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1520:
1.484.2.30 raeburn 1521: foreach my $suffix (@topaste) {
1522: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76! raeburn 1523: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1524: # Supplemental content may only include certain types of content
1525: # Early out if pasted content is not supported in Supplemental area
1526: if ($folder =~ /^supplemental/) {
1527: unless (&supp_pasteable($url)) {
1528: $notinsupp{$suffix} = 1;
1529: next;
1530: }
1531: }
1532: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1533: my $srcd = $1;
1534: my $srcn = $2;
1.484.2.7 raeburn 1535: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1536: # check for mdc privilege in the course from which the resource was pasted
1537: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1538: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1539: $notincrs{$suffix} = 1;
1540: next;
1541: }
1.329 droeschl 1542: }
1.484.2.30 raeburn 1543: $srcdom{$suffix} = $srcd;
1544: $srcnum{$suffix} = $srcn;
1.484.2.76! raeburn 1545: } elsif ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) {
! 1546: my ($srcd,$srcn) = split(/_/,$cid);
! 1547: # When paste buffer was populated using an active role in a different course
! 1548: # check for mdc privilege in the course from which the resource was pasted
! 1549: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
! 1550: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
! 1551: $notincrs{$suffix} = 1;
! 1552: next;
! 1553: }
! 1554: }
! 1555: $srcdom{$suffix} = $srcd;
! 1556: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1557: }
1558: push(@dopaste,$suffix);
1559: if ($url=~/\.(page|sequence)$/) {
1560: $is_map{$suffix} = 1;
1.329 droeschl 1561: }
1.484.2.30 raeburn 1562:
1563: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1564: my $oldprefix = $1;
1.484.2.19 raeburn 1565: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1566: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.19 raeburn 1567: # a folder/page or a document.
1.484.2.30 raeburn 1568: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1569: $prefixchg{$suffix} = 'docstosupp';
1570: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1571: $prefixchg{$suffix} = 'supptodocs';
1572: }
1.484.2.7 raeburn 1573:
1574: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1575: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1576: my @nested;
1577: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1578: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1579: my @deps = map { /\d+:([\d,]+$)/ } @items;
1580: foreach my $dep (@deps) {
1581: if ($dep =~ /,/) {
1582: push(@nested,split(/,/,$dep));
1583: } else {
1584: push(@nested,$dep);
1585: }
1.484.2.7 raeburn 1586: }
1.484.2.30 raeburn 1587: foreach my $item (@nested) {
1588: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1589: push(@{$marktomove{$suffix}},$type.'_'.$item);
1590: }
1.484.2.7 raeburn 1591: }
1592: }
1.329 droeschl 1593: }
1.484.2.7 raeburn 1594: }
1595:
1.484.2.30 raeburn 1596: # Early out if nothing available to paste
1597: if (@dopaste == 0) {
1598: return ();
1599: }
1600:
1601: # Populate message hash and hashes used for main content <=> supplemental content
1602: # changes
1603:
1604: %msgs = &Apache::lonlocal::texthash (
1605: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1606: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1607: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1608: );
1609:
1610: %before = (
1611: docstosupp => {
1612: map => 'default',
1613: doc => 'docs',
1614: },
1615: supptodocs => {
1616: map => 'supplemental',
1617: doc => 'supplemental',
1618: },
1619: );
1620:
1621: %after = (
1622: docstosupp => {
1623: map => 'supplemental',
1624: doc => 'supplemental'
1625: },
1626: supptodocs => {
1627: map => 'default',
1628: doc => 'docs',
1629: },
1630: );
1631:
1632: # Retrieve information about all course maps in main content area
1633:
1634: my $allmaps = {};
1635: if ($folder =~ /^default/) {
1636: $allmaps =
1637: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1638: $env{"course.$env{'request.course.id'}.home"},
1639: $env{'request.course.id'});
1640: }
1641:
1642: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1643:
1644: # Loop over the items to paste
1645: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1646: # Maps need to be copied first
1.484.2.30 raeburn 1647: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1648: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1649: %newurls,%tomove);
1650: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1651: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1652: }
1653: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1654: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76! raeburn 1655: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1656: my $oldurl = $url;
1657: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1658: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1659: my (%hierarchy,%titles);
1660: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1661: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1662: if ($url=~ m{^/uploaded/}) {
1663: my $newurl;
1664: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1665: ($newurl,my $error) =
1666: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1667: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1668: \$title,$allmaps,\%newurls);
1669: if ($error) {
1670: $allerrors{$suffix} = $error;
1671: next;
1672: }
1673: if ($newurl ne '') {
1674: if ($newurl ne $url) {
1675: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1676: $newsubdir{$url} = $1;
1677: }
1678: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1679: }
1680: }
1681: }
1.484.2.30 raeburn 1682: if (($srcdom{$suffix} ne $coursedom) ||
1683: ($srcnum{$suffix} ne $coursenum) ||
1684: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1685: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1686: $coursedom,$coursenum,$srcdom{$suffix},
1687: $srcnum{$suffix},$allmaps,\%rewrites,
1688: \%retitles,\%copies,\%dbcopies,
1689: \%zombies,\%params,\%mapmoves,
1690: \%mapchanges,\%tomove,\%newsubdir,
1691: \%newurls)) {
1692: $mapmoves{$url} = 1;
1693: }
1694: $url = $newurl;
1695: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1696: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1697: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1698: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1699: \%zombies,\%params,\%mapmoves,\%mapchanges,
1700: \%tomove,\%newsubdir,\%newurls);
1701: }
1702: } elsif ($url=~m {^/res/}) {
1703: # published map can only exists once, so remove from paste buffer when done
1704: push(@toclear,$suffix);
1705: # if pasting published map (main content area only) check map not already in course
1706: if ($folder =~ /^default/) {
1707: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1708: $duplicate{$suffix} = 1;
1709: next;
1710: }
1.484.2.7 raeburn 1711: }
1712: }
1713: }
1.484.2.30 raeburn 1714: if ($url=~ m{/(bulletinboard|smppg)$}) {
1715: my $prefix = $1;
1.484.2.76! raeburn 1716: my $fromothercrs;
1.484.2.30 raeburn 1717: #need to copy the db contents to a new one, unless this is a move.
1718: my %info = (
1719: src => $url,
1720: cdom => $coursedom,
1721: cnum => $coursenum,
1.484.2.76! raeburn 1722: );
! 1723: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
! 1724: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
! 1725: $fromothercrs = 1;
! 1726: $info{'cdom'} = $srcdom{$suffix};
! 1727: $info{'cnum'} = $srcnum{$suffix};
! 1728: }
! 1729: }
! 1730: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1731: my (%lockerr,$msg);
1732: my ($newurl,$result,$errtext) =
1733: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1734: if ($result eq 'ok') {
1735: $url = $newurl;
1736: $title=&mt('Copy of').' '.$title;
1737: } else {
1738: if ($prefix eq 'smppg') {
1739: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1740: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1741: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.30 raeburn 1742: }
1743: $results{$suffix} = $result;
1744: $msgerrs{$suffix} = $msg;
1745: $lockerrs{$suffix} = $lockerr{$prefix};
1746: next;
1747: }
1748: if ($lockerr{$prefix}) {
1749: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1750: }
1.484.2.7 raeburn 1751: }
1.484.2.30 raeburn 1752: }
1753: $title = &LONCAPA::map::qtunescape($title);
1754: my $ext='false';
1755: if ($url=~m{^http(|s)://}) { $ext='true'; }
1756: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1757: if ($folder !~ /^supplemental/) {
1758: (undef,undef,$title) =
1759: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1760: }
1761: } else {
1762: if ($folder=~/^supplemental/) {
1763: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1764: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1765: }
1766: }
1.484.2.7 raeburn 1767:
1768: # For uploaded files (excluding pages/sequences) path in copied file is changed
1769: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1770: # courses.
1771:
1.484.2.30 raeburn 1772: unless ($is_map{$suffix}) {
1773: my $newidx;
1.329 droeschl 1774: # Now insert the URL at the bottom
1.484.2.30 raeburn 1775: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1776: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1777: my $relpath = $1;
1778: if ($relpath ne '') {
1779: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1780: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1781: my $newprefix = $newloc;
1782: if ($newloc eq 'default') {
1783: $newprefix = 'docs';
1784: }
1785: if ($newdocsdir eq '') {
1786: $newdocsdir = 'default';
1787: }
1788: if (($prefixchg{$suffix}) ||
1789: ($srcdom{$suffix} ne $coursedom) ||
1790: ($srcnum{$suffix} ne $coursenum) ||
1791: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1792: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1793: $url =
1794: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1795: &Apache::lonnet::getfile($oldurl));
1796: if ($url eq '/adm/notfound.html') {
1797: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1798: next;
1799: } else {
1800: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1801: $newsubpath =~ s{/+$}{/};
1802: $docmoves{$oldurl} = $newsubpath;
1803: }
1.484.2.7 raeburn 1804: }
1805: }
1806: }
1.484.2.30 raeburn 1807: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1808: ':'.$ext.':normal:res';
1809: push(@LONCAPA::map::order,$newidx);
1810: # Store the result
1811: my ($errtext,$fatal) =
1812: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1813: if ($fatal) {
1814: $save_err .= $errtext;
1815: $allresult = 'fail';
1.484.2.7 raeburn 1816: }
1.329 droeschl 1817: }
1.484.2.30 raeburn 1818:
1819: # Apply any changes to maps, or copy dependencies for uploaded HTML pages
1820: unless ($allresult eq 'fail') {
1821: my %updated = (
1822: rewrites => \%rewrites,
1823: zombies => \%zombies,
1824: removefrommap => \%removefrommap,
1825: removeparam => \%removeparam,
1826: dbcopies => \%dbcopies,
1827: retitles => \%retitles,
1828: );
1829: my %info = (
1830: newsubdir => \%newsubdir,
1831: params => \%params,
1832: );
1833: if ($prefixchg{$suffix}) {
1834: $info{'before'} = $before{$prefixchg{$suffix}};
1835: $info{'after'} = $after{$prefixchg{$suffix}};
1836: }
1837: my %moves = (
1838: copies => \%copies,
1839: docmoves => \%docmoves,
1840: mapmoves => \%mapmoves,
1841: );
1842: (my $result,$msgs{$suffix},my $lockerror) =
1843: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1844: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1845: $url,'paste');
1846: $lockerrors .= $lockerror;
1847: if ($result eq 'ok') {
1848: if ($is_map{$suffix}) {
1849: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1850: $folder.'.'.$container);
1851: if ($fatal) {
1852: $allresult = 'failread';
1853: } else {
1854: if ($#LONCAPA::map::order<1) {
1855: my $idx=&LONCAPA::map::getresidx();
1856: if ($idx<=0) { $idx=1; }
1857: $LONCAPA::map::order[0]=$idx;
1858: $LONCAPA::map::resources[$idx]='';
1859: }
1860: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1861: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1862: ':'.$ext.':normal:res';
1863: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 1864:
1865: # Store the result
1.484.2.30 raeburn 1866: my ($errtext,$fatal) =
1867: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1868: if ($fatal) {
1869: $save_err .= $errtext;
1870: $allresult = 'failstore';
1871: }
1872: }
1873: }
1874: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1875: push(@toclear,$suffix);
1876: }
1877: }
1.329 droeschl 1878: }
1879: }
1.484.2.30 raeburn 1880: &clear_from_buffer(\@toclear,\@currpaste);
1881: my $msgsarray;
1882: foreach my $suffix (keys(%msgs)) {
1883: if (ref($msgs{$suffix}) eq 'ARRAY') {
1884: $msgsarray .= join(',',@{$msgs{$suffix}});
1885: }
1886: }
1887: return ($allresult,$save_err,$msgsarray,$lockerrors);
1888: }
1889:
1890: sub do_buffer_empty {
1891: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1892: if (@currpaste == 0) {
1893: return &mt('Clipboard is already empty');
1894: }
1895: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1896: if (@toclear == 0) {
1897: return &mt('Nothing selected to clear from clipboard');
1898: }
1899: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1900: if ($numdel) {
1901: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1902: } else {
1903: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 1904: }
1.484.2.30 raeburn 1905: return;
1906: }
1907:
1908: sub clear_from_buffer {
1909: my ($toclear,$currpaste) = @_;
1910: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1911: my %pastebuffer;
1912: map { $pastebuffer{$_} = 1; } @{$currpaste};
1913: my $numdel = 0;
1914: foreach my $suffix (@{$toclear}) {
1915: next if ($suffix =~ /\D/);
1916: next unless (exists($pastebuffer{$suffix}));
1917: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1918: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1919: delete($pastebuffer{$suffix});
1920: $numdel ++;
1921: }
1922: }
1923: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1924: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1925: return $numdel;
1.484.2.7 raeburn 1926: }
1927:
1928: sub get_newmap_url {
1929: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1930: $titleref,$allmaps,$newurls) = @_;
1931: my $newurl;
1932: if ($url=~ m{^/uploaded/}) {
1933: $$titleref=&mt('Copy of').' '.$$titleref;
1934: }
1935: my $now = time;
1936: my $suffix=$$.int(rand(100)).$now;
1937: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1938: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1939: my $path = $1;
1940: my $prefix = $2;
1941: my $ancestor = $3;
1942: if (length($ancestor) > 10) {
1943: $ancestor = substr($ancestor,-10,10);
1944: }
1945: my $newid;
1946: if ($prefixchg) {
1947: if ($folder =~ /^supplemental/) {
1948: $prefix =~ s/^default/supplemental/;
1949: } else {
1950: $prefix =~ s/^supplemental/default/;
1951: }
1952: }
1953: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1954: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1955: } else {
1956: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1957: }
1958: my $counter = 0;
1959: my $is_unique = &uniqueness_check($newurl);
1960: if ($folder =~ /^default/) {
1961: if ($allmaps->{$newurl}) {
1962: $is_unique = 0;
1963: }
1964: }
1965: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1966: $counter ++;
1967: $suffix ++;
1968: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1969: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1970: } else {
1971: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
1972: }
1973: $is_unique = &uniqueness_check($newurl);
1974: }
1975: if ($is_unique) {
1976: $newurls->{$newurl} = 1;
1977: } else {
1978: if ($url=~/\.page$/) {
1979: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
1980: } else {
1981: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
1982: }
1983: }
1984: }
1985: return ($newurl);
1986: }
1987:
1988: sub dbcopy {
1.484.2.26 raeburn 1989: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
1990: my ($url,$result,$errtext);
1991: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 1992: $url = $dbref->{'src'};
1.484.2.26 raeburn 1993: if ($url =~ m{/(smppg|bulletinboard)$}) {
1994: my $prefix = $1;
1995: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
1996: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
1997: my $db_name;
1998: my $marker = (split(m{/},$url))[4];
1999: $marker=~s/\D//g;
2000: if ($dbref->{'src'} =~ m{/smppg$}) {
2001: $db_name =
2002: &Apache::lonsimplepage::get_db_name($url,$marker,
2003: $dbref->{'cdom'},
2004: $dbref->{'cnum'});
2005: } else {
2006: $db_name = 'bulletinpage_'.$marker;
2007: }
2008: my ($suffix,$freedlock,$error) =
2009: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2010: $coursedom,$coursenum,
2011: 'concat');
2012: if (!$suffix) {
2013: if ($prefix eq 'smppg') {
2014: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2015: } else {
1.484.2.42 raeburn 2016: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2017: }
2018: if ($error) {
2019: $errtext .= '<br />'.$error;
2020: }
2021: } else {
2022: #need to copy the db contents to a new one.
2023: my %contents=&Apache::lonnet::dump($db_name,
2024: $dbref->{'cdom'},
2025: $dbref->{'cnum'});
2026: if (exists($contents{'uploaded.photourl'})) {
2027: my $photo = $contents{'uploaded.photourl'};
2028: my ($subdir,$fname) =
2029: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2030: my $newphoto;
2031: if ($fname ne '') {
2032: my $content = &Apache::lonnet::getfile($photo);
2033: unless ($content eq '-1') {
2034: $env{'form.'.$suffix.'.photourl'} = $content;
2035: $newphoto =
2036: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2037: delete($env{'form.'.$suffix.'.photourl'});
2038: }
2039: }
2040: if ($newphoto =~ m{^/uploaded/}) {
2041: $contents{'uploaded.photourl'} = $newphoto;
2042: }
2043: }
2044: $db_name =~ s{_\d*$ }{_$suffix}x;
2045: $result=&Apache::lonnet::put($db_name,\%contents,
2046: $coursedom,$coursenum);
2047: if ($result eq 'ok') {
2048: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2049: }
2050: }
2051: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2052: $lockerrorsref->{$prefix} =
2053: '<div class="LC_error">'.
2054: &mt('There was a problem removing a lockfile.');
2055: if ($prefix eq 'smppg') {
2056: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2057: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.26 raeburn 2058: } else {
1.484.2.42 raeburn 2059: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2060: }
1.484.2.38 raeburn 2061: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2062: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2063: '</div>';
1.484.2.26 raeburn 2064: }
2065: }
2066: } elsif ($url =~ m{/syllabus$}) {
2067: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2068: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2069: if (($dbref->{'cdom'} ne $coursedom) ||
2070: ($dbref->{'cnum'} ne $coursenum)) {
2071: my %contents=&Apache::lonnet::dump('syllabus',
2072: $dbref->{'cdom'},
2073: $dbref->{'cnum'});
2074: $result=&Apache::lonnet::put('syllabus',\%contents,
2075: $coursedom,$coursenum);
2076: }
2077: }
1.484.2.7 raeburn 2078: }
2079: }
1.484.2.26 raeburn 2080: return ($url,$result,$errtext);
1.329 droeschl 2081: }
2082:
2083: sub uniqueness_check {
2084: my ($newurl) = @_;
2085: my $unique = 1;
2086: foreach my $res (@LONCAPA::map::order) {
2087: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2088: $url=&LONCAPA::map::qtescape($url);
2089: if ($newurl eq $url) {
2090: $unique = 0;
1.344 bisitz 2091: last;
1.329 droeschl 2092: }
2093: }
2094: return $unique;
2095: }
2096:
1.484.2.7 raeburn 2097: sub contained_map_check {
2098: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2099: $allmaps) = @_;
2100: my $content = &Apache::lonnet::getfile($url);
2101: unless ($content eq '-1') {
2102: my $parser = HTML::TokeParser->new(\$content);
2103: $parser->attr_encoded(1);
2104: while (my $token = $parser->get_token) {
2105: next if ($token->[0] ne 'S');
2106: if ($token->[1] eq 'resource') {
2107: next if ($token->[2]->{'type'} eq 'zombie');
2108: my $ressrc = $token->[2]->{'src'};
2109: if ($folder =~ /^supplemental/) {
2110: unless (&supp_pasteable($ressrc)) {
2111: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2112: next;
2113: }
2114: }
2115: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2116: if ($1 eq 'uploaded') {
2117: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2118: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2119: } else {
2120: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2121: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2122: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2123: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2124: } else {
2125: $addedmaps->{$ressrc} = [$url];
2126: }
2127: }
2128: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2129: $addedmaps,$hierarchy,$titles,$allmaps);
2130: }
2131: } elsif ($token->[1] eq 'param') {
2132: if ($folder =~ /^supplemental/) {
2133: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2134: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2135: } else {
1.484.2.19 raeburn 2136: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2137: }
2138: }
2139: }
2140: }
2141: }
2142: return;
2143: }
2144:
2145: sub url_paste_fixups {
1.484.2.26 raeburn 2146: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2147: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2148: $mapchanges,$tomove,$newsubdir,$newurls) = @_;
1.484.2.7 raeburn 2149: my $checktitle;
2150: if (($prefixchg) &&
2151: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2152: $checktitle = 1;
2153: }
2154: my $skip;
2155: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2156: my $mapid = $1.$2;
2157: if ($tomove->{$mapid}) {
2158: $skip = 1;
2159: }
2160: }
2161: my $file = &Apache::lonnet::getfile($oldurl);
2162: return if ($file eq '-1');
2163: my $parser = HTML::TokeParser->new(\$file);
2164: $parser->attr_encoded(1);
2165: my $changed = 0;
2166: while (my $token = $parser->get_token) {
2167: next if ($token->[0] ne 'S');
2168: if ($token->[1] eq 'resource') {
2169: my $ressrc = $token->[2]->{'src'};
2170: next if ($ressrc eq '');
2171: my $id = $token->[2]->{'id'};
2172: my $title = $token->[2]->{'title'};
2173: if ($checktitle) {
2174: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2175: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2176: }
2177: }
2178: next if ($token->[2]->{'type'} eq 'external');
2179: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2180: next if ($skip);
1.484.2.25 raeburn 2181: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2182: $changed = 1;
2183: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2184: my $srcdom = $1;
2185: my $srcnum = $2;
2186: my $rem = $3;
2187: my $newurl;
2188: my $mapname;
2189: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2190: my $prefix = $1;
2191: $mapname = $prefix.$2;
2192: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2193: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2194: $srcdom,$srcnum,$allmaps,$rewrites,
2195: $retitles,$copies,$dbcopies,$zombies,
2196: $params,$mapmoves,$mapchanges,$tomove,
2197: $newsubdir,$newurls);
1.484.2.7 raeburn 2198: next;
2199: } else {
2200: ($newurl,my $error) =
2201: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2202: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2203: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2204: $newsubdir->{$ressrc} = $1;
2205: }
2206: if ($error) {
2207: next;
2208: }
2209: }
2210: }
2211: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2212: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2213:
1.484.2.7 raeburn 2214: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2215: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2216: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2217: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2218: $cnum,$srcdom,$srcnum,$allmaps,
2219: $rewrites,$retitles,$copies,$dbcopies,
2220: $zombies,$params,$mapmoves,$mapchanges,
2221: $tomove,$newsubdir,$newurls)) {
1.484.2.7 raeburn 2222: $mapmoves->{$ressrc} = 1;
2223: }
2224: $changed = 1;
2225: } else {
1.484.2.25 raeburn 2226: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2227: $copies->{$oldurl}{$ressrc} = $id;
2228: $changed = 1;
2229: }
2230: }
1.484.2.26 raeburn 2231: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2232: next if ($skip);
1.484.2.7 raeburn 2233: my $srcdom = $1;
2234: my $srcnum = $2;
2235: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2236: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2237: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2238: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2239: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2240: $changed = 1;
2241: }
2242: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2243: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2244: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2245: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2246: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2247: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2248: $changed = 1;
2249: }
2250: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2251: next if ($skip);
2252: my $srcdom = $1;
2253: my $srcnum = $2;
2254: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2255: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2256: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2257: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2258: $changed = 1;
2259: }
2260: }
2261: } elsif ($token->[1] eq 'param') {
2262: next if ($skip);
1.484.2.19 raeburn 2263: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2264: if ($to ne '') {
2265: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2266: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2267: } else {
2268: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2269: }
2270: }
2271: }
2272: }
2273: return $changed;
2274: }
2275:
2276: sub apply_fixups {
1.484.2.23 raeburn 2277: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2278: $oldurl,$url,$caller) = @_;
2279: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2280: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2281: %lockerrors,$lockmsg);
1.484.2.23 raeburn 2282: if (ref($updated) eq 'HASH') {
2283: if (ref($updated->{'rewrites'}) eq 'HASH') {
2284: %rewrites = %{$updated->{'rewrites'}};
2285: }
2286: if (ref($updated->{'zombies'}) eq 'HASH') {
2287: %zombies = %{$updated->{'zombies'}};
2288: }
2289: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2290: %removefrommap = %{$updated->{'removefrommap'}};
2291: }
2292: if (ref($updated->{'removeparam'}) eq 'HASH') {
2293: %removeparam = %{$updated->{'removeparam'}};
2294: }
2295: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2296: %dbcopies = %{$updated->{'dbcopies'}};
2297: }
2298: if (ref($updated->{'retitles'}) eq 'HASH') {
2299: %retitles = %{$updated->{'retitles'}};
2300: }
2301: }
2302: if (ref($info) eq 'HASH') {
2303: if (ref($info->{'newsubdir'}) eq 'HASH') {
2304: %newsubdir = %{$info->{'newsubdir'}};
2305: }
2306: if (ref($info->{'params'}) eq 'HASH') {
2307: %params = %{$info->{'params'}};
2308: }
2309: if (ref($info->{'before'}) eq 'HASH') {
2310: %before = %{$info->{'before'}};
2311: }
2312: if (ref($info->{'after'}) eq 'HASH') {
2313: %after = %{$info->{'after'}};
2314: }
2315: }
2316: if (ref($moves) eq 'HASH') {
2317: if (ref($moves->{'copies'}) eq 'HASH') {
2318: %copies = %{$moves->{'copies'}};
2319: }
2320: if (ref($moves->{'docmoves'}) eq 'HASH') {
2321: %docmoves = %{$moves->{'docmoves'}};
2322: }
2323: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2324: %mapmoves = %{$moves->{'mapmoves'}};
2325: }
2326: }
2327: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2328: my @allcopies;
1.484.2.23 raeburn 2329: if (exists($copies{$key})) {
2330: if (ref($copies{$key}) eq 'HASH') {
2331: my %added;
2332: foreach my $innerkey (keys(%{$copies{$key}})) {
2333: if (($innerkey ne '') && (!$added{$innerkey})) {
2334: push(@allcopies,$innerkey);
2335: $added{$innerkey} = 1;
2336: }
1.484.2.7 raeburn 2337: }
1.484.2.23 raeburn 2338: undef(%added);
1.484.2.7 raeburn 2339: }
2340: }
2341: if ($key eq $oldurl) {
1.484.2.23 raeburn 2342: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2343: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2344: push(@allcopies,$oldurl);
2345: }
2346: }
2347: }
2348: if (@allcopies > 0) {
2349: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2350: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2351: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2352: if ($fname ne '') {
2353: my $content = &Apache::lonnet::getfile($item);
2354: unless ($content eq '-1') {
2355: my $storefn;
1.484.2.23 raeburn 2356: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2357: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2358: } else {
2359: $storefn = $relpath;
2360: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2361: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2362: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2363: }
1.484.2.23 raeburn 2364: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2365: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2366: }
2367: }
2368: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2369: my $copyurl =
1.484.2.7 raeburn 2370: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2371: $storefn.$fname,$content);
2372: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2373: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2374: return &mt('Paste failed: an error occurred copying the file.');
2375: } elsif (ref($errors) eq 'HASH') {
2376: $errors->{$item} = 1;
2377: }
2378: }
2379: }
2380: }
2381: }
2382: }
2383: }
1.484.2.23 raeburn 2384: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2385: my $storefn=$key;
2386: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2387: if ($prefixchg && $before{'map'} && $after{'map'}) {
2388: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2389: }
1.484.2.23 raeburn 2390: if ($newsubdir{$key}) {
2391: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2392: }
2393: my $mapcontent = &Apache::lonnet::getfile($key);
2394: if ($mapcontent eq '-1') {
2395: if (ref($errors) eq 'HASH') {
2396: $errors->{$key} = 1;
2397: }
2398: } else {
2399: my $newmap =
2400: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2401: $mapcontent);
2402: if ($newmap eq '/adm/notfound.html') {
2403: if (ref($errors) eq 'HASH') {
2404: $errors->{$key} = 1;
2405: }
2406: }
2407: }
2408: }
2409: my %updates;
2410: if ($is_map) {
1.484.2.23 raeburn 2411: if (ref($updated) eq 'HASH') {
2412: foreach my $type (keys(%{$updated})) {
2413: if (ref($updated->{$type}) eq 'HASH') {
2414: foreach my $key (keys(%{$updated->{$type}})) {
2415: $updates{$key} = 1;
2416: }
2417: }
2418: }
1.484.2.7 raeburn 2419: }
2420: foreach my $key (keys(%updates)) {
2421: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2422: if (ref($rewrites{$key}) eq 'HASH') {
2423: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2424: }
1.484.2.23 raeburn 2425: if (ref($retitles{$key}) eq 'HASH') {
2426: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2427: }
1.484.2.23 raeburn 2428: if (ref($removefrommap{$key}) eq 'HASH') {
2429: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2430: }
1.484.2.23 raeburn 2431: if (ref($removeparam{$key}) eq 'HASH') {
2432: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2433: }
1.484.2.23 raeburn 2434: if (ref($zombies{$key}) eq 'HASH') {
2435: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2436: }
1.484.2.23 raeburn 2437: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2438: foreach my $idx (keys(%{$dbcopies{$key}})) {
2439: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2440: my ($newurl,$result,$errtext) =
2441: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2442: if ($result eq 'ok') {
2443: $newdb{$idx} = $newurl;
2444: } elsif (ref($errors) eq 'HASH') {
2445: $errors->{$key} = 1;
2446: }
2447: push(@msgs,$errtext);
2448: }
1.484.2.7 raeburn 2449: }
2450: }
1.484.2.23 raeburn 2451: if (ref($params{$key}) eq 'HASH') {
2452: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2453: }
2454: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2455: if ($fatal) {
1.484.2.26 raeburn 2456: return ($errtext);
1.484.2.7 raeburn 2457: }
2458: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2459: if (defined($LONCAPA::map::zombies[$i])) {
2460: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2461: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2462: undef($LONCAPA::map::zombies[$i]);
2463: }
2464: }
2465: }
1.484.2.23 raeburn 2466: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2467: my $idx = $LONCAPA::map::order[$i];
2468: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2469: my $changed;
1.484.2.23 raeburn 2470: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2471: if ((exists($toremove{$idx})) &&
2472: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2473: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2474: if (ref($currparam{$idx}) eq 'ARRAY') {
2475: foreach my $name (@{$currparam{$idx}}) {
2476: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.484.2.7 raeburn 2477: }
2478: }
2479: next;
2480: }
2481: my $origsrc = $src;
1.484.2.25 raeburn 2482: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2483: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2484: $changed = 1;
2485: }
2486: }
1.484.2.25 raeburn 2487: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2488: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2489: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2490: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2491: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2492: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2493: } else {
1.484.2.23 raeburn 2494: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2495: }
2496: }
1.484.2.25 raeburn 2497: if ($origsrc =~ /\.(page|sequence)$/) {
2498: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2499: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2500: }
1.484.2.25 raeburn 2501: } elsif ($newsubdir{$key}) {
2502: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2503: }
2504: }
2505: $changed = 1;
1.484.2.26 raeburn 2506: } elsif ($newdb{$idx} ne '') {
2507: $src = $newdb{$idx};
1.484.2.7 raeburn 2508: $changed = 1;
2509: }
2510: if ($changed) {
1.484.2.30 raeburn 2511: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2512: }
2513: }
2514: }
2515: foreach my $idx (keys(%remparam)) {
2516: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2517: foreach my $name (@{$remparam{$idx}}) {
1.484.2.7 raeburn 2518: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
2519: }
2520: }
2521: }
1.484.2.26 raeburn 2522: if (values(%lockerrors) > 0) {
2523: $lockmsg = join('<br />',values(%lockerrors));
2524: }
1.484.2.7 raeburn 2525: my $storefn;
2526: if ($key eq $oldurl) {
2527: $storefn = $url;
2528: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2529: } else {
2530: $storefn = $key;
2531: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2532: if ($prefixchg && $before{'map'} && $after{'map'}) {
2533: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2534: }
1.484.2.23 raeburn 2535: if ($newsubdir{$key}) {
2536: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2537: }
2538: }
2539: my $report;
2540: if ($folder !~ /^supplemental/) {
2541: $report = 1;
2542: }
1.484.2.20 raeburn 2543: (my $outtext,$errtext) =
1.484.2.7 raeburn 2544: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2545: if ($errtext) {
1.484.2.23 raeburn 2546: if ($caller eq 'paste') {
1.484.2.26 raeburn 2547: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2548: }
1.484.2.7 raeburn 2549: }
2550: }
2551: }
1.484.2.26 raeburn 2552: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2553: }
2554:
2555: sub copy_dependencies {
2556: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2557: my $content;
2558: if (ref($contentref)) {
2559: $content = $$contentref;
2560: } else {
2561: $content = &Apache::lonnet::getfile($item);
2562: }
2563: unless ($content eq '-1') {
2564: my $mm = new File::MMagic;
2565: my $mimetype = $mm->checktype_contents($content);
2566: if ($mimetype eq 'text/html') {
2567: my (%allfiles,%codebase,$state);
2568: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2569: if ($res eq 'ok') {
2570: my ($numexisting,$numpathchanges,$existing);
2571: (undef,$numexisting,$numpathchanges,$existing) =
2572: &Apache::loncommon::ask_for_embedded_content(
2573: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2574: {'error_on_invalid_names' => 1,
2575: 'ignore_remote_references' => 1,
2576: 'docs_url' => $item,
2577: 'context' => 'paste'});
2578: if ($numexisting > 0) {
2579: if (ref($existing) eq 'HASH') {
2580: foreach my $dep (keys(%{$existing})) {
2581: my $depfile = $dep;
2582: unless ($depfile =~ m{^\Q$relpath\E}) {
2583: $depfile = $relpath.$dep;
2584: }
2585: my $depcontent = &Apache::lonnet::getfile($depfile);
2586: unless ($depcontent eq '-1') {
2587: my $storedep = $dep;
2588: $storedep =~ s{^\Q$relpath\E}{};
2589: my $dep_url =
2590: &Apache::lonclonecourse::writefile(
2591: $env{'request.course.id'},
2592: $storefn.$storedep,$depcontent);
2593: if ($dep_url eq '/adm/notfound.html') {
2594: if (ref($errors) eq 'HASH') {
2595: $errors->{$depfile} = 1;
2596: }
2597: } else {
2598: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2599: }
2600: }
2601: }
2602: }
2603: }
2604: }
2605: }
2606: }
2607: return;
2608: }
2609:
1.329 droeschl 2610: my %parameter_type = ( 'randompick' => 'int_pos',
2611: 'hiddenresource' => 'string_yesno',
2612: 'encrypturl' => 'string_yesno',
2613: 'randomorder' => 'string_yesno',);
2614: my $valid_parameters_re = join('|',keys(%parameter_type));
2615: # set parameters
2616: sub update_parameter {
1.484.2.29 raeburn 2617: if ($env{'form.changeparms'} eq 'all') {
2618: my (@allidx,@allmapidx,%allchecked,%currchecked);
2619: %allchecked = (
2620: 'hiddenresource' => {},
2621: 'encrypturl' => {},
2622: 'randompick' => {},
2623: 'randomorder' => {},
2624: );
2625: foreach my $which (keys(%allchecked)) {
2626: $env{'form.all'.$which} =~ s/,$//;
2627: if ($which eq 'randompick') {
2628: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2629: my ($res,$value) = split(/:/,$item);
2630: if ($value =~ /^\d+$/) {
2631: $allchecked{$which}{$res} = $value;
2632: }
2633: }
2634: } else {
1.484.2.30 raeburn 2635: if ($env{'form.all'.$which}) {
2636: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2637: }
1.484.2.29 raeburn 2638: }
2639: }
2640: my $haschanges = 0;
2641: foreach my $res (@LONCAPA::map::order) {
2642: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2643: $name=&LONCAPA::map::qtescape($name);
2644: $url=&LONCAPA::map::qtescape($url);
2645: next unless ($name && $url);
2646: my $is_map;
2647: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2648: $is_map = 1;
2649: }
2650: foreach my $which (keys(%allchecked)) {
2651: if (($which eq 'randompick' || $which eq 'randomorder')) {
2652: next if (!$is_map);
2653: }
2654: my $oldvalue = 0;
2655: my $newvalue = 0;
2656: if ($allchecked{$which}{$res}) {
2657: $newvalue = $allchecked{$which}{$res};
2658: }
2659: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2660: if ($which eq 'randompick') {
2661: if ($current =~ /^(\d+)$/) {
2662: $oldvalue = $1;
2663: }
2664: } else {
2665: if ($current =~ /^yes$/i) {
2666: $oldvalue = 1;
2667: }
2668: }
2669: if ($oldvalue ne $newvalue) {
2670: $haschanges = 1;
2671: if ($newvalue) {
2672: my $storeval = 'yes';
2673: if ($which eq 'randompick') {
2674: $storeval = $newvalue;
2675: }
2676: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2677: $storeval,
2678: $parameter_type{$which});
2679: &remember_parms($res,$which,'set',$storeval);
2680: } elsif ($oldvalue) {
2681: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2682: &remember_parms($res,$which,'del');
2683: }
2684: }
2685: }
2686: }
2687: return $haschanges;
1.329 droeschl 2688: } else {
1.484.2.59 raeburn 2689: my $haschanges = 0;
2690: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 2691:
1.484.2.29 raeburn 2692: my $which = $env{'form.changeparms'};
2693: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 2694: my $oldvalue = 0;
2695: my $newvalue = 0;
2696: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2697: if ($which eq 'randompick') {
2698: if ($current =~ /^(\d+)$/) {
2699: $oldvalue = $1;
2700: }
2701: } elsif ($current =~ /^yes$/i) {
2702: $oldvalue = 1;
2703: }
1.484.2.29 raeburn 2704: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 2705: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2706: : 1;
1.484.2.29 raeburn 2707: }
1.484.2.59 raeburn 2708: if ($oldvalue ne $newvalue) {
2709: $haschanges = 1;
2710: if ($newvalue) {
2711: my $storeval = 'yes';
2712: if ($which eq 'randompick') {
2713: $storeval = $newvalue;
2714: }
2715: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2716: $parameter_type{$which});
2717: &remember_parms($idx,$which,'set',$storeval);
2718: } else {
2719: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2720: &remember_parms($idx,$which,'del');
2721: }
2722: }
2723: return $haschanges;
1.329 droeschl 2724: }
1.484.2.59 raeburn 2725: return;
1.329 droeschl 2726: }
2727:
2728: sub handle_edit_cmd {
2729: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 2730: if ($env{'form.cmd'} eq '') {
2731: return 0;
2732: }
1.329 droeschl 2733: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2734:
2735: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2736: my ($title, $url, @rrest) = split(':', $ratstr);
2737:
1.484.2.30 raeburn 2738: if ($cmd eq 'remove') {
1.329 droeschl 2739: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2740: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2741: &Apache::lonnet::removeuploadedurl($url);
2742: } else {
2743: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2744: }
2745: splice(@LONCAPA::map::order, $idx, 1);
2746:
2747: } elsif ($cmd eq 'cut') {
2748: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2749: splice(@LONCAPA::map::order, $idx, 1);
2750:
1.344 bisitz 2751: } elsif ($cmd eq 'up'
1.329 droeschl 2752: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2753: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2754:
2755: } elsif ($cmd eq 'down'
2756: && defined($LONCAPA::map::order[$idx+1])) {
2757: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2758:
2759: } elsif ($cmd eq 'rename') {
2760: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2761: if ($comment=~/\S/) {
2762: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2763: $comment.':'.join(':', $url, @rrest);
2764: }
2765: # Devalidate title cache
2766: my $renamed_url=&LONCAPA::map::qtescape($url);
2767: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 2768:
1.329 droeschl 2769: } else {
2770: return 0;
2771: }
2772: return 1;
2773: }
2774:
2775: sub editor {
1.458 raeburn 2776: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.67 raeburn 2777: $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,$navmapref,
2778: $hiddentop)=@_;
1.484.2.19 raeburn 2779: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2780: if ($allowed) {
2781: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2782: $is_random_order,$container) =
2783: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2784: $r->print($breadcrumbtrail);
2785: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2786: $container = 'page';
2787: } else {
2788: $container = 'sequence';
2789: }
1.484 raeburn 2790:
1.484.2.21 raeburn 2791: my $jumpto;
2792:
2793: unless ($supplementalflag) {
1.484.2.32 raeburn 2794: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 2795: }
1.484 raeburn 2796:
2797: unless ($allowed) {
2798: $randompick = -1;
2799: }
2800:
1.484.2.67 raeburn 2801: my ($errtext,$fatal);
2802: if (($folder eq '') && (!$supplementalflag)) {
2803: if (@LONCAPA::map::order) {
2804: undef(@LONCAPA::map::order);
2805: undef(@LONCAPA::map::resources);
2806: undef(@LONCAPA::map::resparms);
2807: undef(@LONCAPA::map::zombies);
2808: }
2809: $folder = 'default';
2810: $container = 'sequence';
2811: } else {
2812: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2813: $folder.'.'.$container);
2814: return $errtext if ($fatal);
2815: }
1.329 droeschl 2816:
2817: if ($#LONCAPA::map::order<1) {
2818: my $idx=&LONCAPA::map::getresidx();
2819: if ($idx<=0) { $idx=1; }
2820: $LONCAPA::map::order[0]=$idx;
2821: $LONCAPA::map::resources[$idx]='';
2822: }
1.364 bisitz 2823:
1.329 droeschl 2824: # ------------------------------------------------------------ Process commands
2825:
2826: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 2827: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 2828: # set parameters and change order
2829: &snapshotbefore();
2830:
2831: if (&update_parameter()) {
1.484.2.59 raeburn 2832: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 2833: return $errtext if ($fatal);
2834: }
2835:
2836: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2837: # change order
2838: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
2839: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
2840:
2841: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2842: return $errtext if ($fatal);
2843: }
1.364 bisitz 2844:
1.329 droeschl 2845: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 2846: my %paste_errors;
1.484.2.26 raeburn 2847: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 2848: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
2849: \%paste_errors);
1.484.2.30 raeburn 2850: if (ref($pastemsgarray) eq 'ARRAY') {
2851: if (@{$pastemsgarray} > 0) {
2852: $r->print('<p class="LC_info">'.
2853: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 2854: '</p>');
2855: }
1.484.2.30 raeburn 2856: }
2857: if ($lockerror) {
2858: $r->print('<p class="LC_error">'.
2859: $lockerror.
2860: '</p>');
2861: }
2862: if ($save_error ne '') {
2863: return $save_error;
2864: }
2865: if ($paste_res) {
2866: my %errortext = &Apache::lonlocal::texthash (
2867: fail => 'Storage of folder contents failed',
2868: failread => 'Reading folder contents failed',
2869: failstore => 'Storage of folder contents failed',
2870: );
2871: if ($errortext{$paste_res}) {
2872: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 2873: }
1.329 droeschl 2874: }
1.484.2.7 raeburn 2875: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 2876: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 2877: &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".
2878: '<ul>'."\n");
2879: foreach my $key (sort(keys(%paste_errors))) {
2880: $r->print('<li>'.$key.'</li>'."\n");
2881: }
2882: $r->print('</ul></p>'."\n");
2883: }
1.484.2.30 raeburn 2884: } elsif ($env{'form.clearmarked'}) {
2885: my $output = &do_buffer_empty();
2886: if ($output) {
2887: $r->print('<p class="LC_info">'.$output.'</p>');
2888: }
2889: }
1.329 droeschl 2890:
2891: $r->print($upload_output);
2892:
1.484.2.30 raeburn 2893: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 2894: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 2895: my $contentchg;
1.484.2.58 raeburn 2896: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 2897: $contentchg = 1;
2898: }
2899: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 2900: return $errtext if ($fatal);
2901: }
1.484.2.30 raeburn 2902:
2903: # Cut, copy and/or remove multiple resources
2904: if ($env{'form.multichange'}) {
2905: my %allchecked = (
2906: cut => {},
2907: remove => {},
2908: );
2909: my $needsupdate;
2910: foreach my $which (keys(%allchecked)) {
2911: $env{'form.multi'.$which} =~ s/,$//;
2912: if ($env{'form.multi'.$which}) {
2913: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
2914: if (ref($allchecked{$which}) eq 'HASH') {
2915: $needsupdate += scalar(keys(%{$allchecked{$which}}));
2916: }
2917: }
2918: }
2919: if ($needsupdate) {
2920: my $haschanges = 0;
2921: my %curr_groups = &Apache::longroup::coursegroups();
2922: my $total = scalar(@LONCAPA::map::order) - 1;
2923: for (my $i=$total; $i>=0; $i--) {
2924: my $res = $LONCAPA::map::order[$i];
2925: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2926: $name=&LONCAPA::map::qtescape($name);
2927: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 2928: next unless $url;
1.484.2.30 raeburn 2929: my %denied =
2930: &action_restrictions($coursenum,$coursedom,$url,
2931: $env{'form.folderpath'},\%curr_groups);
2932: foreach my $which (keys(%allchecked)) {
2933: next if ($denied{$which});
2934: next unless ($allchecked{$which}{$res});
2935: if ($which eq 'remove') {
2936: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
2937: ($url!~/$LONCAPA::assess_page_seq_re/)) {
2938: &Apache::lonnet::removeuploadedurl($url);
2939: } else {
2940: &LONCAPA::map::makezombie($res);
2941: }
2942: splice(@LONCAPA::map::order,$i,1);
2943: $haschanges ++;
2944: } elsif ($which eq 'cut') {
2945: &LONCAPA::map::makezombie($res);
2946: splice(@LONCAPA::map::order,$i,1);
2947: $haschanges ++;
2948: }
2949: }
2950: }
2951: if ($haschanges) {
2952: ($errtext,$fatal) =
2953: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2954: return $errtext if ($fatal);
2955: }
2956: }
2957: }
2958:
1.329 droeschl 2959: # Group import/search
2960: if ($env{'form.importdetail'}) {
2961: my @imports;
2962: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
2963: if (defined($item)) {
2964: my ($name,$url,$residx)=
1.484.2.26 raeburn 2965: map { &unescape($_); } split(/\=/,$item);
2966: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 2967: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 2968: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 2969: if ($locknotfreed) {
2970: $r->print($locknotfreed);
2971: }
2972: if ($suffix) {
1.484.2.19 raeburn 2973: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 2974: } else {
2975: return $errortxt;
2976: }
1.484.2.26 raeburn 2977: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
2978: my $type = $1;
2979: my ($suffix,$errortxt,$locknotfreed) =
2980: &new_timebased_suffix($coursedom,$coursenum,$type);
2981: if ($locknotfreed) {
2982: $r->print($locknotfreed);
2983: }
2984: if ($suffix) {
2985: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
2986: } else {
2987: return $errortxt;
2988: }
1.484.2.27 raeburn 2989: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
2990: if ($supplementalflag) {
2991: next unless ($1 eq 'supplemental');
2992: if ($folder eq 'supplemental') {
2993: next unless ($2 eq 'default');
2994: } else {
2995: next unless ($folder eq 'supplemental_'.$2);
2996: }
2997: } else {
2998: next unless ($1 eq 'docs');
2999: if ($folder eq 'default') {
3000: next unless ($2 eq 'default');
3001: } else {
3002: next unless ($folder eq 'default_'.$2);
3003: }
3004: }
1.484.2.15 raeburn 3005: }
1.329 droeschl 3006: push(@imports, [$name, $url, $residx]);
3007: }
3008: }
1.484.2.23 raeburn 3009: ($errtext,$fatal,my $fixuperrors) =
3010: &group_import($coursenum, $coursedom, $folder,$container,
3011: 'londocs',@imports);
1.329 droeschl 3012: return $errtext if ($fatal);
1.484.2.23 raeburn 3013: if ($fixuperrors) {
3014: $r->print($fixuperrors);
3015: }
1.329 droeschl 3016: }
3017: # Loading a complete map
3018: if ($env{'form.loadmap'}) {
3019: if ($env{'form.importmap'}=~/\w/) {
3020: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3021: my ($title,$url,$ext,$type)=split(/\:/,$res);
3022: my $idx=&LONCAPA::map::getresidx($url);
3023: $LONCAPA::map::resources[$idx]=$res;
3024: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3025: }
3026: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3027: $folder.'.'.$container,1);
1.329 droeschl 3028: return $errtext if ($fatal);
3029: } else {
3030: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3031:
1.329 droeschl 3032: }
3033: }
3034: &log_differences($plain);
3035: }
3036: # ---------------------------------------------------------------- End commands
3037: # ---------------------------------------------------------------- Print screen
3038: my $idx=0;
3039: my $shown=0;
3040: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3041: $r->print('<div class="LC_Box">'.
1.432 raeburn 3042: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3043: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3044: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3045: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3046: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3047: '</ol>');
1.381 bisitz 3048: if ($randompick>=0) {
3049: $r->print('<p class="LC_warning">'
3050: .&mt('Caution: this folder is set to randomly pick a subset'
3051: .' of resources. Adding or removing resources from this'
3052: .' folder will change the set of resources that the'
3053: .' students see, resulting in spurious or missing credit'
3054: .' for completed problems, not limited to ones you'
3055: .' modify. Do not modify the contents of this folder if'
3056: .' it is in active student use.')
3057: .'</p>'
3058: );
3059: }
3060: if ($is_random_order) {
3061: $r->print('<p class="LC_warning">'
3062: .&mt('Caution: this folder is set to randomly order its'
3063: .' contents. Adding or removing resources from this folder'
3064: .' will change the order of resources shown.')
3065: .'</p>'
3066: );
3067: }
3068: $r->print('</div>');
1.364 bisitz 3069: }
1.381 bisitz 3070:
1.484.2.30 raeburn 3071: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3072: %filters = (
3073: canremove => [],
3074: cancut => [],
3075: cancopy => [],
3076: hiddenresource => [],
3077: encrypturl => [],
3078: randomorder => [],
3079: randompick => [],
3080: );
3081: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3082: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3083: foreach my $res (@LONCAPA::map::order) {
3084: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3085: $name=&LONCAPA::map::qtescape($name);
3086: $url=&LONCAPA::map::qtescape($url);
3087: unless ($name) { $name=(split(/\//,$url))[-1]; }
3088: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3089: push(@allidx,$res);
3090: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3091: push(@allmapidx,$res);
3092: }
1.484.2.67 raeburn 3093:
1.381 bisitz 3094: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3095: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3096: $pathitem,$supplementalflag,$container,
1.484.2.70 raeburn 3097: \%filters,\%curr_groups,$canedit,
3098: $isencrypted,$navmapref);
1.381 bisitz 3099: $idx++;
3100: $shown++;
1.329 droeschl 3101: }
1.424 onken 3102: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3103:
1.484.2.30 raeburn 3104: my $need_save;
1.484.2.67 raeburn 3105: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3106: my $toolslink;
1.484.2.67 raeburn 3107: if ($allowed) {
1.484.2.31 raeburn 3108: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3109: .&Apache::loncommon::help_open_menu('Navigation Screen',
3110: 'Navigation_Screen',undef,'RAT')
3111: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3112: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3113: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3114: .'id="LC_content_toolbar_edittoplevel" '
3115: .'class="LC_toolbarItem" '
3116: .'title="'.&mt('Supplemental Content Editor').'">'
3117: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3118: }
1.484.2.19 raeburn 3119: if ($shown) {
3120: if ($allowed) {
3121: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3122: .&Apache::loncommon::start_data_table(undef,'contentlist')
3123: .&Apache::loncommon::start_data_table_header_row()
3124: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3125: .'<th colspan="2">'.&mt('Actions').'</th>'
3126: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3127: if ($folder !~ /^supplemental/) {
3128: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3129: }
1.484.2.29 raeburn 3130: $to_show .= &Apache::loncommon::end_data_table_header_row();
3131: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3132: $lists{'canhide'} = join(',',@allidx);
3133: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3134: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3135: 'randomorder','randompick');
3136: foreach my $item (@possfilters) {
3137: if (ref($filters{$item}) eq 'ARRAY') {
3138: if (@{$filters{$item}} > 0) {
3139: $lists{$item} = join(',',@{$filters{$item}});
3140: }
3141: }
3142: }
1.484.2.29 raeburn 3143: if (@allidx > 0) {
3144: my $path;
3145: if ($env{'form.folderpath'}) {
3146: $path =
3147: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3148: }
1.484.2.30 raeburn 3149: if (@allidx > 1) {
3150: $to_show .=
3151: &Apache::loncommon::continue_data_table_row().
3152: '<td colspan="2"> </td>'.
3153: '<td>'.
1.484.2.67 raeburn 3154: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3155: '</td>'.
3156: '<td> </td>'.
3157: '<td> </td>'.
3158: '<td colspan="4">'.
1.484.2.67 raeburn 3159: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3160: '</td>'.
3161: &Apache::loncommon::end_data_table_row();
3162: $need_save = 1;
3163: }
1.484.2.29 raeburn 3164: }
3165: }
3166: $to_show .= $output.' '
1.484.2.19 raeburn 3167: .&Apache::loncommon::end_data_table()
3168: .'<br style="line-height:2px;" />'
3169: .&Apache::loncommon::end_scrollbox();
3170: } else {
3171: $to_show .= $toolslink
3172: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3173: .$output.' '
3174: .&Apache::loncommon::end_data_table();
3175: }
3176: } else {
3177: if (!$allowed) {
3178: $to_show .= $toolslink;
1.393 raeburn 3179: }
1.484.2.67 raeburn 3180: my $noresmsg;
3181: if ($allowed && $hiddentop && !$supplementalflag) {
3182: $noresmsg = &mt('Main Content Hidden');
3183: } else {
3184: $noresmsg = &mt('Currently empty');
3185: }
1.484.2.19 raeburn 3186: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3187: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3188: .$noresmsg
1.484.2.19 raeburn 3189: .'</div>'
3190: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3191: }
3192: } else {
1.484.2.19 raeburn 3193: if ($shown) {
3194: $to_show = '<div>'
3195: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3196: .$output
3197: .&Apache::loncommon::end_data_table()
3198: .'</div>';
3199: } else {
3200: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3201: .&mt('Currently empty')
1.484.2.19 raeburn 3202: .'</div>'
3203: }
1.458 raeburn 3204: }
3205: my $tid = 1;
3206: if ($supplementalflag) {
3207: $tid = 2;
1.329 droeschl 3208: }
3209: if ($allowed) {
1.484 raeburn 3210: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3211: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3212: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3213: if ($canedit) {
1.484.2.67 raeburn 3214: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3215: }
1.460 raeburn 3216: } else {
3217: $r->print($to_show);
1.329 droeschl 3218: }
3219: return;
3220: }
3221:
1.484.2.30 raeburn 3222: sub multiple_check_form {
1.484.2.67 raeburn 3223: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3224: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3225: my $disabled;
3226: unless ($canedit) {
3227: $disabled = 'disabled="disabled"';
3228: }
1.484.2.30 raeburn 3229: my $output =
3230: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3231: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3232: '<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>'.
3233: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3234: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3235: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3236: if ($caller eq 'settings') {
3237: $output .=
3238: '<table><tr>'.
3239: '<td class="LC_docs_entry_parameter">'.
3240: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3241: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3242: '</label></span></td>'.
3243: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3244: '<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.484.2.30 raeburn 3245: '</span></td>'.
3246: '</tr>'."\n".
3247: '<tr>'.
3248: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3249: '<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.484.2.30 raeburn 3250: '</label></span>'.
3251: '</td></tr></table>'."\n";
3252: } else {
3253: $output .=
3254: '<table><tr>'.
3255: '<td class="LC_docs_entry_parameter">'.
3256: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3257: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3258: '</label></span></td>'.
3259: '<td class="LC_docs_entry_parameter">'.
3260: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3261: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3262: '</label></span></td>'."\n".
3263: '<td class="LC_docs_entry_parameter">'.
3264: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3265: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3266: '</label></span></td>'.
3267: '</tr></table>'."\n";
3268: }
3269: $output .=
3270: '</fieldset>'.
3271: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3272: if ($caller eq 'settings') {
3273: $output .=
3274: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3275: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3276: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3277: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3278: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3279: } elsif ($caller eq 'actions') {
3280: $output .=
3281: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3282: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3283: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3284: }
3285: $output .=
3286: '</form>'.
3287: '</div>';
3288: return $output;
3289: }
3290:
1.329 droeschl 3291: sub process_file_upload {
1.484.2.36 raeburn 3292: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3293: # upload a file, if present
1.484.2.36 raeburn 3294: my $filesize = length($env{'form.uploaddoc'});
3295: if (!$filesize) {
3296: $$upload_output = '<div class="LC_error">'.
3297: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3298: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3299: $filesize).'<br />'.
3300: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3301: '</div>';
3302: return;
3303: }
3304: my $quotatype = 'unofficial';
3305: if ($crstype eq 'Community') {
3306: $quotatype = 'community';
1.484.2.51 raeburn 3307: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3308: $quotatype = 'official';
1.484.2.45 raeburn 3309: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3310: $quotatype = 'textbook';
1.484.2.36 raeburn 3311: }
3312: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3313: $filesize = int($filesize/1000); #expressed in kb
3314: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3315: $env{'form.uploaddoc.filename'},$filesize,
3316: 'upload',$quotatype);
1.484.2.36 raeburn 3317: return if ($$upload_output);
3318: }
1.440 raeburn 3319: my ($parseaction,$showupload,$nextphase,$mimetype);
3320: if ($env{'form.parserflag'}) {
1.329 droeschl 3321: $parseaction = 'parse';
3322: }
3323: my $folder=$env{'form.folder'};
3324: if ($folder eq '') {
3325: $folder='default';
3326: }
3327: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3328: my $errtext='';
3329: my $fatal=0;
3330: my $container='sequence';
1.484.2.19 raeburn 3331: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3332: $container='page';
3333: }
3334: ($errtext,$fatal)=
1.484.2.27 raeburn 3335: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3336: if ($#LONCAPA::map::order<1) {
3337: $LONCAPA::map::order[0]=1;
3338: $LONCAPA::map::resources[1]='';
3339: }
3340: my $destination = 'docs/';
3341: if ($folder =~ /^supplemental/) {
3342: $destination = 'supplemental/';
3343: }
3344: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3345: $destination .= 'default/';
3346: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3347: $destination .= $2.'/';
3348: }
1.484.2.27 raeburn 3349: if ($fatal) {
3350: $$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>';
3351: return;
3352: }
1.440 raeburn 3353: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3354: my $newidx=&LONCAPA::map::getresidx();
3355: $destination .= $newidx;
1.439 raeburn 3356: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3357: $parseaction,$allfiles,
1.440 raeburn 3358: $codebase,undef,undef,undef,undef,
3359: undef,undef,\$mimetype);
3360: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3361: my $stored = $1;
3362: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3363: $stored.'</span>').'</p>';
3364: } else {
3365: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3366:
1.457 raeburn 3367: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3368: return;
3369: }
1.329 droeschl 3370: my $ext='false';
3371: if ($url=~m{^http://}) { $ext='true'; }
3372: $url = &LONCAPA::map::qtunescape($url);
3373: my $comment=$env{'form.comment'};
3374: $comment = &LONCAPA::map::qtunescape($comment);
3375: if ($folder=~/^supplemental/) {
3376: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3377: $env{'user.domain'}.'___&&&___'.$comment;
3378: }
3379:
3380: $LONCAPA::map::resources[$newidx]=
3381: $comment.':'.$url.':'.$ext.':normal:res';
3382: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3383: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3384: $folder.'.'.$container,1);
1.329 droeschl 3385: if ($fatal) {
1.457 raeburn 3386: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3387: return;
1.329 droeschl 3388: } else {
1.440 raeburn 3389: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3390: $$upload_output = $showupload;
1.384 raeburn 3391: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3392: if ($total_embedded > 0) {
1.440 raeburn 3393: my $uploadphase = 'upload_embedded';
3394: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3395: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3396: my ($embedded,$num) =
3397: &Apache::loncommon::ask_for_embedded_content(
3398: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3399: if ($embedded) {
3400: if ($num) {
3401: $$upload_output .=
3402: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3403: $nextphase = $uploadphase;
3404: } else {
3405: $$upload_output .= $embedded;
3406: }
3407: } else {
3408: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3409: }
1.329 droeschl 3410: } else {
1.440 raeburn 3411: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3412: }
1.457 raeburn 3413: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3414: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3415: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3416: $nextphase = 'decompress_uploaded';
3417: my $position = scalar(@LONCAPA::map::order)-1;
3418: my $noextract = &return_to_editor();
3419: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3420: my %archiveitems = (
3421: folderpath => $env{'form.folderpath'},
3422: cmd => $nextphase,
3423: newidx => $newidx,
3424: position => $position,
3425: phase => $nextphase,
1.477 raeburn 3426: comment => $comment,
1.480 raeburn 3427: );
3428: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3429: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3430: $$upload_output = $showupload.
3431: &Apache::loncommon::decompress_form($mimetype,
3432: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3433: \%archiveitems,\@current);
1.329 droeschl 3434: }
3435: }
3436: }
1.440 raeburn 3437: return $nextphase;
1.329 droeschl 3438: }
3439:
1.480 raeburn 3440: sub get_dir_list {
3441: my ($url,$coursenum,$coursedom,$newidx) = @_;
3442: my ($destination,$dir_root) = &embedded_destination();
3443: my ($dirlistref,$listerror) =
3444: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3445: my @dir_lines;
3446: my $dirptr=16384;
3447: if (ref($dirlistref) eq 'ARRAY') {
3448: foreach my $dir_line (sort
3449: {
3450: my ($afile)=split('&',$a,2);
3451: my ($bfile)=split('&',$b,2);
3452: return (lc($afile) cmp lc($bfile));
3453: } (@{$dirlistref})) {
3454: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3455: $filename =~ s/\s+$//;
3456: next if ($filename =~ /^\.\.?$/);
3457: my $isdir = 0;
3458: if ($dirptr&$testdir) {
3459: $isdir = 1;
3460: }
3461: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3462: }
3463: }
3464: return @dir_lines;
3465: }
3466:
1.329 droeschl 3467: sub is_supplemental_title {
3468: my ($title) = @_;
3469: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3470: }
3471:
3472: # --------------------------------------------------------------- An entry line
3473:
3474: sub entryline {
1.484.2.12 raeburn 3475: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3476: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3477: $canedit,$isencrypted,$navmapref)=@_;
1.484.2.52 raeburn 3478: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3479: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3480: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3481: } else {
3482: $title=&HTML::Entities::encode($title,'"<>&\'');
3483: $renametitle=$title;
3484: $foldertitle=$title;
3485: }
3486:
1.484.2.67 raeburn 3487: my ($disabled,$readonly,$js_lt);
3488: unless ($canedit) {
3489: $disabled = 'disabled="disabled"';
3490: $readonly = 1;
3491: }
3492:
1.329 droeschl 3493: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3494:
1.329 droeschl 3495: $renametitle=~s/\\/\\\\/g;
3496: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3497: $renametitle=~s/"/%22/g;
1.329 droeschl 3498: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3499: $oldtitle = $renametitle;
3500: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3501: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3502: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3503: # Edit commands
1.484.2.28 raeburn 3504: my ($esc_path, $path, $symb);
1.329 droeschl 3505: if ($env{'form.folderpath'}) {
3506: $esc_path=&escape($env{'form.folderpath'});
3507: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3508: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3509: }
1.484.2.16 raeburn 3510: my $isexternal;
1.484.2.19 raeburn 3511: if ($residx) {
1.484.2.12 raeburn 3512: my $currurl = $url;
3513: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3514: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3515: $isexternal = 1;
3516: }
1.484.2.19 raeburn 3517: if (!$supplementalflag) {
3518: my $path = 'uploaded/'.
3519: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3520: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3521: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3522: $residx,
3523: &Apache::lonnet::declutter($currurl));
3524: }
1.484.2.12 raeburn 3525: }
1.484.2.30 raeburn 3526: my ($renamelink,%lt,$ishash);
3527: if (ref($filtersref) eq 'HASH') {
3528: $ishash = 1;
3529: }
3530:
1.329 droeschl 3531: if ($allowed) {
1.484.2.30 raeburn 3532: $form_start = '
3533: <form action="/adm/coursedocs" method="post">
3534: ';
3535: $form_common=(<<END);
3536: <input type="hidden" name="folderpath" value="$path" />
3537: <input type="hidden" name="symb" value="$symb" />
3538: END
3539: $form_param=(<<END);
3540: <input type="hidden" name="setparms" value="$orderidx" />
3541: <input type="hidden" name="changeparms" value="0" />
3542: END
3543: $form_end = '</form>';
3544:
1.329 droeschl 3545: my $incindex=$index+1;
3546: my $selectbox='';
1.471 raeburn 3547: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3548: ((split(/\:/,
1.344 bisitz 3549: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3550: ne '') &&
1.329 droeschl 3551: ((split(/\:/,
1.344 bisitz 3552: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3553: ne '')) {
3554: $selectbox=
3555: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3556: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3557: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3558: if ($i==$incindex) {
1.358 bisitz 3559: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3560: } else {
3561: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3562: }
3563: }
3564: $selectbox.='</select>';
3565: }
1.484.2.12 raeburn 3566: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3567: 'up' => 'Move Up',
3568: 'dw' => 'Move Down',
3569: 'rm' => 'Remove',
3570: 'ct' => 'Cut',
3571: 'rn' => 'Rename',
1.484.2.12 raeburn 3572: 'cp' => 'Copy',
3573: 'ex' => 'External Resource',
3574: 'ed' => 'Edit',
3575: 'pr' => 'Preview',
3576: 'sv' => 'Save',
3577: 'ul' => 'URL',
1.484.2.67 raeburn 3578: 'ti' => 'Title',
3579: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3580: );
1.484.2.30 raeburn 3581: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3582: $env{'form.folderpath'},
3583: $currgroups);
1.484.2.19 raeburn 3584: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3585: my $skip_confirm = 0;
1.484.2.63 raeburn 3586: my $confirm_removal = 0;
1.329 droeschl 3587: if ( $folder =~ /^supplemental/
3588: || ($url =~ m{( /smppg$
3589: |/syllabus$
3590: |/aboutme$
3591: |/navmaps$
3592: |/bulletinboard$
1.484.2.16 raeburn 3593: |\.html$)}x)
1.484.2.19 raeburn 3594: || $isexternal) {
1.329 droeschl 3595: $skip_confirm = 1;
3596: }
1.484.2.63 raeburn 3597: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3598: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3599: $confirm_removal = 1;
3600: }
1.484.2.19 raeburn 3601:
1.484.2.30 raeburn 3602: if ($denied{'copy'}) {
3603: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3604: <span style="visibility: hidden;">$lt{'cp'}</span>
3605: ENDCOPY
3606: } else {
1.484.2.30 raeburn 3607: my $formname = 'edit_copy_'.$orderidx;
3608: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3609: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3610: <form name="$formname" method="post" action="/adm/coursedocs">
3611: $form_common
1.484.2.67 raeburn 3612: <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.484.2.30 raeburn 3613: $form_end
1.329 droeschl 3614: ENDCOPY
1.484.2.30 raeburn 3615: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3616: push(@{$filtersref->{'cancopy'}},$orderidx);
3617: }
1.329 droeschl 3618: }
1.484.2.30 raeburn 3619: if ($denied{'cut'}) {
1.484.2.16 raeburn 3620: $cutlink=(<<ENDCUT);
3621: <span style="visibility: hidden;">$lt{'ct'}</span>
3622: ENDCUT
3623: } else {
1.484.2.30 raeburn 3624: my $formname = 'edit_cut_'.$orderidx;
3625: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3626: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3627: <form name="$formname" method="post" action="/adm/coursedocs">
3628: $form_common
3629: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3630: <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.484.2.30 raeburn 3631: $form_end
1.329 droeschl 3632: ENDCUT
1.484.2.30 raeburn 3633: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3634: push(@{$filtersref->{'cancut'}},$orderidx);
3635: }
1.329 droeschl 3636: }
1.484.2.30 raeburn 3637: if ($denied{'remove'}) {
1.484.2.16 raeburn 3638: $removelink=(<<ENDREM);
3639: <span style="visibility: hidden;">$lt{'rm'}</a>
3640: ENDREM
3641: } else {
1.484.2.30 raeburn 3642: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3643: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.484.2.9 raeburn 3644: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3645: <form name="$formname" method="post" action="/adm/coursedocs">
3646: $form_common
3647: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3648: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3649: <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.484.2.30 raeburn 3650: $form_end
1.484.2.9 raeburn 3651: ENDREM
1.484.2.30 raeburn 3652: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3653: push(@{$filtersref->{'canremove'}},$orderidx);
3654: }
1.484.2.9 raeburn 3655: }
1.484.2.35 raeburn 3656: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3657: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3658: ENDREN
1.484.2.67 raeburn 3659: my ($uplink,$downlink);
3660: if ($canedit) {
3661: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3662: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3663: } else {
3664: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3665: $downlink = $uplink;
3666: }
1.329 droeschl 3667: $line.=(<<END);
3668: <td>
1.379 bisitz 3669: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3670: <a href="$uplink">
1.484.2.12 raeburn 3671: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3672: </a>
3673: </div>
3674: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3675: <a href="$downlink">
1.484.2.12 raeburn 3676: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3677: </a>
3678: </div>
1.329 droeschl 3679: </td>
3680: <td>
3681: $form_start
1.484.2.30 raeburn 3682: $form_param
1.478 raeburn 3683: $form_common
1.329 droeschl 3684: $selectbox
3685: $form_end
3686: </td>
1.484.2.30 raeburn 3687: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3688: $removelink
1.329 droeschl 3689: $cutlink
3690: $copylink
3691: </td>
3692: END
3693: }
3694: # Figure out what kind of a resource this is
3695: my ($extension)=($url=~/\.(\w+)$/);
3696: my $uploaded=($url=~/^\/*uploaded\//);
3697: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3698: my $isfolder;
3699: my $ispage;
3700: my $containerarg;
1.484.2.67 raeburn 3701: my $folderurl;
1.329 droeschl 3702: if ($uploaded) {
1.472 raeburn 3703: if (($extension eq 'sequence') || ($extension eq 'page')) {
3704: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3705: $containerarg = $1;
1.472 raeburn 3706: if ($extension eq 'sequence') {
3707: $icon=$iconpath.'navmap.folder.closed.gif';
3708: $isfolder=1;
3709: } else {
3710: $icon=$iconpath.'page.gif';
3711: $ispage=1;
3712: }
1.484.2.67 raeburn 3713: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3714: if ($allowed) {
3715: $url='/adm/coursedocs?';
3716: } else {
3717: $url='/adm/supplemental?';
3718: }
1.329 droeschl 3719: } else {
3720: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3721: }
3722: }
1.364 bisitz 3723:
1.484.2.70 raeburn 3724: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3725: my $orig_url = $url;
1.340 raeburn 3726: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.19 raeburn 3727: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.12 raeburn 3728: if (!$supplementalflag && $residx && $symb) {
3729: if ((!$isfolder) && (!$ispage)) {
3730: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3731: $url=&Apache::lonnet::clutter($url);
3732: if ($url=~/^\/*uploaded\//) {
3733: $url=~/\.(\w+)$/;
3734: my $embstyle=&Apache::loncommon::fileembstyle($1);
3735: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3736: $url='/adm/wrapper'.$url;
3737: } elsif ($embstyle eq 'ssi') {
3738: #do nothing with these
3739: } elsif ($url!~/\.(sequence|page)$/) {
3740: $url='/adm/coursedocs/showdoc'.$url;
3741: }
1.484.2.70 raeburn 3742: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
3743: my $wrapped = $1;
3744: my $exturl = $2;
3745: if ($wrapped eq '') {
3746: $url='/adm/wrapper'.$url;
3747: }
3748: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
3749: $nomodal = 1;
3750: }
3751: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3752: if (($ENV{'SERVER_PORT'} == 443) &&
3753: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
3754: $nomodal = 1;
3755: }
1.484.2.19 raeburn 3756: }
1.484.2.12 raeburn 3757: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3758: my $shownsymb = $symb;
3759: if ($isexternal) {
3760: if ($url =~ /^([^#]+)#([^#]+)$/) {
3761: $url = $1;
3762: $anchor = $2;
3763: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
3764: $shownsymb = $1.&escape('#').$anchor;
3765: }
3766: }
3767: }
1.484.2.67 raeburn 3768: unless ($env{'request.role.adv'}) {
3769: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3770: $url = '';
3771: }
3772: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3773: $url = '';
3774: $hiddenres = 1;
3775: }
3776: }
3777: if ($url ne '') {
1.484.2.75 raeburn 3778: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3779: }
3780: } elsif (!$env{'request.role.adv'}) {
3781: my $checkencrypt;
3782: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3783: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3784: $checkencrypt = 1;
1.484.2.70 raeburn 3785: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3786: unless (ref($$navmapref)) {
3787: $$navmapref = Apache::lonnavmaps::navmap->new();
3788: }
3789: if (ref($$navmapref)) {
3790: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
3791: $checkencrypt = 1;
3792: }
3793: }
3794: }
3795: if ($checkencrypt) {
3796: my $shownsymb = &Apache::lonenc::encrypted($symb);
3797: my $shownurl = &Apache::lonenc::encrypted($url);
3798: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
3799: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
3800: if ($env{'request.enc'} ne '') {
3801: delete($env{'request.enc'});
3802: }
3803: } else {
3804: $url='';
3805: }
3806: } else {
3807: $url='';
3808: }
1.484.2.12 raeburn 3809: } else {
3810: $url='';
3811: }
1.484.2.19 raeburn 3812: }
1.484.2.66 raeburn 3813: } elsif ($supplementalflag) {
3814: if ($isexternal) {
3815: if ($url =~ /^([^#]+)#([^#]+)$/) {
3816: $url = $1;
3817: $anchor = $2;
1.484.2.70 raeburn 3818: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
3819: $nomodal = 1;
3820: }
3821: }
3822: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
3823: if (($ENV{'SERVER_PORT'} == 443) &&
3824: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
3825: $nomodal = 1;
1.484.2.66 raeburn 3826: }
3827: }
1.329 droeschl 3828: }
1.484.2.67 raeburn 3829: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
3830: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 3831: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3832: my $foldername=&escape($foldertitle);
3833: my $folderpath=$env{'form.folderpath'};
3834: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 3835: if (!$allowed && $supplementalflag) {
3836: $folderpath.=$containerarg.'&'.$foldername;
3837: $url.='folderpath='.&escape($folderpath);
3838: } else {
3839: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3840: 'parameter_randompick'))[0];
1.484.2.67 raeburn 3841: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
3842: 'parameter_randomorder'))[0]=~/^yes$/i);
3843: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
3844: 'parameter_hiddenresource'))[0]=~/^yes$/i);
3845: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
3846: 'parameter_encrypturl'))[0]=~/^yes$/i);
3847: unless ($hiddenmap) {
1.484.2.70 raeburn 3848: if (ref($navmapref)) {
3849: unless (ref($$navmapref)) {
3850: $$navmapref = Apache::lonnavmaps::navmap->new();
3851: }
3852: if (ref($$navmapref)) {
3853: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
3854: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
3855: unless (@resources) {
3856: $hiddenmap = 1;
3857: unless ($env{'request.role.adv'}) {
3858: $url = '';
3859: $hiddenfolder = 1;
3860: }
1.484.2.67 raeburn 3861: }
3862: }
3863: }
3864: }
3865: }
3866: unless ($encryptmap) {
1.484.2.70 raeburn 3867: if ((ref($navmapref)) && (ref($$navmapref))) {
3868: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
3869: $encryptmap = 1;
3870: }
1.484.2.67 raeburn 3871: }
3872: }
3873:
3874: # Append randompick number, hidden, and encrypted with ":" to foldername,
3875: # so it gets transferred between levels
3876: $folderpath.=$containerarg.'&'.$foldername.
3877: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
3878: unless ($url eq '') {
3879: $url.='folderpath='.&escape($folderpath);
3880: }
1.484.2.19 raeburn 3881: my $rpckchk;
3882: if ($rpicknum) {
3883: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 3884: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3885: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3886: }
1.484.2.19 raeburn 3887: }
1.484.2.29 raeburn 3888: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 3889: $rand_pick_text =
1.478 raeburn 3890: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3891: $form_param."\n".
1.478 raeburn 3892: $form_common."\n".
1.484.2.67 raeburn 3893: '<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.484.2.19 raeburn 3894: if ($rpicknum ne '') {
3895: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3896: }
1.484.2.29 raeburn 3897: $rand_pick_text .= '</span></span>'.
3898: $form_end;
1.484.2.30 raeburn 3899: my $ro_set;
1.484.2.67 raeburn 3900: if ($randorder) {
1.484.2.30 raeburn 3901: $ro_set = 'checked="checked"';
3902: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3903: push(@{$filtersref->{'randomorder'}},$orderidx);
3904: }
3905: }
1.484.2.41 raeburn 3906: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 3907: $rand_order_text =
1.484.2.29 raeburn 3908: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3909: $form_param."\n".
1.484.2.29 raeburn 3910: $form_common."\n".
1.484.2.67 raeburn 3911: '<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.484.2.29 raeburn 3912: $form_end;
1.484.2.19 raeburn 3913: }
1.484.2.18 raeburn 3914: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 3915: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 3916: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 3917: if ($title) {
3918: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3919: }
3920: if ($isexternal && $orderidx) {
3921: $url .= '&idx='.$orderidx;
3922: }
1.484.2.66 raeburn 3923: if ($anchor ne '') {
3924: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
3925: }
1.329 droeschl 3926: }
1.484.2.19 raeburn 3927: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 3928: if ($allowed) {
1.484.2.19 raeburn 3929: my $fileloc =
1.484.2.12 raeburn 3930: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 3931: if ($isexternal) {
3932: ($editlink,$extresform) =
1.484.2.67 raeburn 3933: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
3934: undef,undef,undef,$disabled);
1.484.2.19 raeburn 3935: } elsif (!$isfolder && !$ispage) {
3936: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 3937: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 3938: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 3939: my $suppanchor;
3940: if ($supplementalflag) {
3941: $suppanchor = $anchor;
3942: }
1.484.2.19 raeburn 3943: my $jscall =
1.484.2.12 raeburn 3944: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
3945: $switchserver,
1.484.2.14 raeburn 3946: $forceedit,
1.484.2.19 raeburn 3947: undef,$symb,
3948: &escape($env{'form.folderpath'}),
1.484.2.66 raeburn 3949: $renametitle,'','',1,$suppanchor);
1.484.2.12 raeburn 3950: if ($jscall) {
1.484.2.19 raeburn 3951: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
3952: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 3953: }
3954: }
3955: }
1.484.2.19 raeburn 3956: $tdalign = ' align="right" valign="top"';
3957: $tdwidth = ' width="80%"';
1.329 droeschl 3958: }
1.408 raeburn 3959: my $reinit;
3960: if ($crstype eq 'Community') {
3961: $reinit = &mt('(re-initialize community to access)');
3962: } else {
3963: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 3964: }
3965: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 3966: my $link;
1.472 raeburn 3967: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3968: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
3969: } elsif ($url) {
1.484.2.66 raeburn 3970: if ($anchor ne '') {
3971: if ($supplementalflag) {
3972: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
3973: } else {
3974: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
3975: }
3976: }
1.484.2.70 raeburn 3977: $link = &js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
3978: (($anchor ne '')?$anchor:''));
3979: if ($nomodal) {
3980: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
3981: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
3982: } else {
3983: $line.=&Apache::loncommon::modal_link($link,
3984: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
3985: }
1.469 www 3986: } else {
3987: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
3988: }
1.484.2.19 raeburn 3989: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 3990: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3991: $line.='<a href="'.$url.'">'.$title.'</a>';
3992: } elsif ($url) {
1.484.2.70 raeburn 3993: if ($nomodal) {
3994: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
3995: $title.'</a>';
3996: } else {
3997: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
3998: }
1.484.2.67 raeburn 3999: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4000: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4001: } else {
4002: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4003: }
1.484.2.19 raeburn 4004: $line.="$extresform</td>";
1.478 raeburn 4005: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4006: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4007: if (($allowed) && ($folder!~/^supplemental/)) {
4008: my %lt=&Apache::lonlocal::texthash(
4009: 'hd' => 'Hidden',
4010: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4011: my ($enctext,$hidtext);
4012: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4013: $enctext = ' checked="checked"';
4014: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4015: push(@{$filtersref->{'encrypturl'}},$orderidx);
4016: }
4017: }
4018: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4019: $hidtext = ' checked="checked"';
4020: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4021: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4022: }
4023: }
1.484.2.29 raeburn 4024: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4025: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4026: $line.=(<<ENDPARMS);
4027: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4028: <form action="/adm/coursedocs" method="post" name="$formhidden">
4029: $form_param
1.478 raeburn 4030: $form_common
1.484.2.67 raeburn 4031: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4032: $form_end
1.458 raeburn 4033: <br />
1.484.2.29 raeburn 4034: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4035: $form_param
1.478 raeburn 4036: $form_common
1.484.2.67 raeburn 4037: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4038: $form_end
4039: </td>
1.478 raeburn 4040: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4041: $rand_order_text</td>
1.329 droeschl 4042: ENDPARMS
4043: }
1.379 bisitz 4044: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4045: return $line;
4046: }
4047:
1.484.2.30 raeburn 4048: sub action_restrictions {
4049: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4050: my %denied = (
4051: cut => 0,
4052: copy => 0,
4053: remove => 0,
4054: );
4055: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4056: # no copy for published maps
4057: $denied{'copy'} = 1;
4058: } elsif ($url=~m{^/res/lib/templates/}) {
4059: $denied{'copy'} = 1;
4060: $denied{'cut'} = 1;
4061: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4062: if ($folderpath =~ /^default&[^\&]+$/) {
4063: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4064: $denied{'remove'} = 1;
4065: }
4066: $denied{'cut'} = 1;
4067: $denied{'copy'} = 1;
4068: }
4069: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4070: my $group = $1;
4071: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4072: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4073: $denied{'remove'} = 1;
4074: }
4075: }
4076: $denied{'cut'} = 1;
4077: $denied{'copy'} = 1;
4078: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4079: my $group = $1;
4080: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4081: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4082: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4083: if (keys(%groupsettings) > 0) {
4084: $denied{'remove'} = 1;
4085: }
4086: $denied{'cut'} = 1;
4087: $denied{'copy'} = 1;
4088: }
4089: }
4090: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4091: my $group = $1;
4092: if ($url =~ /group_boards_\Q$group\E/) {
4093: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4094: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4095: if (keys(%groupsettings) > 0) {
4096: if (ref($groupsettings{'functions'}) eq 'HASH') {
4097: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4098: $denied{'remove'} = 1;
4099: }
4100: }
4101: }
4102: $denied{'cut'} = 1;
4103: $denied{'copy'} = 1;
4104: }
4105: }
4106: }
4107: return %denied;
4108: }
4109:
1.484.2.26 raeburn 4110: sub new_timebased_suffix {
1.484.2.30 raeburn 4111: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4112: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4113: if ($type eq 'paste') {
4114: $prefix = $type;
4115: $namespace = 'courseeditor';
1.484.2.56 raeburn 4116: $idtype = 'addcode';
1.484.2.30 raeburn 4117: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4118: $prefix = 'docs';
4119: if ($area eq 'supplemental') {
4120: $prefix = 'supp';
4121: }
4122: $prefix .= $container;
4123: $namespace = 'uploadedmaps';
4124: } else {
4125: $prefix = $type;
4126: $namespace = 'templated';
1.484.2.15 raeburn 4127: }
4128: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4129: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4130: if (!$suffix) {
1.484.2.30 raeburn 4131: if ($type eq 'paste') {
4132: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4133: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4134: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4135: } elsif ($type eq 'smppg') {
4136: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4137: } else {
1.484.2.42 raeburn 4138: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4139: }
1.484.2.15 raeburn 4140: if ($error) {
4141: $errtext .= '<br />'.$error;
4142: }
4143: }
4144: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4145: $locknotfreed =
4146: '<div class="LC_error">'.
4147: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4148: if ($type eq 'paste') {
1.484.2.57 raeburn 4149: if ($freedlock eq 'nolock') {
4150: $locknotfreed =
4151: '<div class="LC_error">'.
4152: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4153:
1.484.2.60 raeburn 4154: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4155: } else {
4156: $locknotfreed .=
4157: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4158: }
1.484.2.30 raeburn 4159: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4160: $locknotfreed .=
4161: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4162: } elsif ($type eq 'smppg') {
4163: $locknotfreed .=
4164: &mt('This will prevent creation of additional simple pages in this course.');
4165: } else {
4166: $locknotfreed .=
1.484.2.42 raeburn 4167: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4168: }
1.484.2.30 raeburn 4169: unless ($type eq 'paste') {
4170: $locknotfreed .=
1.484.2.38 raeburn 4171: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4172: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4173: }
4174: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4175: }
4176: return ($suffix,$errtext,$locknotfreed);
4177: }
4178:
1.329 droeschl 4179: =pod
4180:
4181: =item tiehash()
4182:
4183: tie the hash
4184:
4185: =cut
4186:
4187: sub tiehash {
4188: my ($mode)=@_;
4189: $hashtied=0;
4190: if ($env{'request.course.fn'}) {
4191: if ($mode eq 'write') {
4192: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4193: &GDBM_WRCREAT(),0640)) {
4194: $hashtied=2;
4195: }
4196: } else {
4197: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4198: &GDBM_READER(),0640)) {
4199: $hashtied=1;
4200: }
4201: }
1.364 bisitz 4202: }
1.329 droeschl 4203: }
4204:
4205: sub untiehash {
4206: if ($hashtied) { untie %hash; }
4207: $hashtied=0;
4208: return OK;
4209: }
4210:
4211:
4212:
4213:
4214: sub checkonthis {
4215: my ($r,$url,$level,$title)=@_;
4216: $url=&unescape($url);
4217: $alreadyseen{$url}=1;
4218: $r->rflush();
4219: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4220: $r->print("\n<br />");
4221: if ($level==0) {
4222: $r->print("<br />");
4223: }
4224: for (my $i=0;$i<=$level*5;$i++) {
4225: $r->print(' ');
4226: }
4227: $r->print('<a href="'.$url.'" target="cat">'.
4228: ($title?$title:$url).'</a> ');
4229: if ($url=~/^\/res\//) {
4230: my $result=&Apache::lonnet::repcopy(
4231: &Apache::lonnet::filelocation('',$url));
4232: if ($result eq 'ok') {
4233: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4234: $r->rflush();
4235: &Apache::lonnet::countacc($url);
4236: $url=~/\.(\w+)$/;
4237: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4238: $r->print('<br />');
4239: $r->rflush();
4240: for (my $i=0;$i<=$level*5;$i++) {
4241: $r->print(' ');
4242: }
4243: $r->print('- '.&mt('Rendering:').' ');
4244: my ($errorcount,$warningcount)=split(/:/,
4245: &Apache::lonnet::ssi_body($url,
4246: ('grade_target'=>'web',
4247: 'return_only_error_and_warning_counts' => 1)));
4248: if (($errorcount) ||
4249: ($warningcount)) {
4250: if ($errorcount) {
1.369 bisitz 4251: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4252: &mt('[quant,_1,error]',$errorcount).'</span>');
4253: }
4254: if ($warningcount) {
4255: $r->print('<span class="LC_warning">'.
4256: &mt('[quant,_1,warning]',$warningcount).'</span>');
4257: }
4258: } else {
4259: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4260: }
4261: $r->rflush();
4262: }
4263: my $dependencies=
4264: &Apache::lonnet::metadata($url,'dependencies');
4265: foreach my $dep (split(/\,/,$dependencies)) {
4266: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4267: &checkonthis($r,$dep,$level+1);
4268: }
4269: }
4270: } elsif ($result eq 'unavailable') {
4271: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4272: } elsif ($result eq 'not_found') {
4273: unless ($url=~/\$/) {
1.484.2.19 raeburn 4274: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4275: } else {
1.366 bisitz 4276: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4277: }
4278: } else {
4279: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4280: }
4281: }
4282: }
4283: }
4284:
4285:
4286:
4287: =pod
4288:
4289: =item list_symbs()
4290:
1.484.2.3 raeburn 4291: List Content Identifiers
1.329 droeschl 4292:
4293: =cut
4294:
4295: sub list_symbs {
4296: my ($r) = @_;
4297:
1.408 raeburn 4298: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4299: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4300: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4301: $r->print(&startContentScreen('tools'));
1.329 droeschl 4302: my $navmap = Apache::lonnavmaps::navmap->new();
4303: if (!defined($navmap)) {
4304: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4305: '<div class="LC_error">'.
4306: &mt('Unable to retrieve information about course contents').
4307: '</div>');
1.408 raeburn 4308: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4309: } else {
1.484 raeburn 4310: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4311: &Apache::loncommon::start_data_table().
4312: &Apache::loncommon::start_data_table_header_row().
4313: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4314: &Apache::loncommon::end_data_table_header_row()."\n");
4315: my $count;
1.329 droeschl 4316: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4317: $r->print(&Apache::loncommon::start_data_table_row().
4318: '<td>'.$res->compTitle().'</td>'.
4319: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4320: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4321: $count ++;
4322: }
4323: if (!$count) {
4324: $r->print(&Apache::loncommon::start_data_table_row().
4325: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4326: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4327: }
1.484 raeburn 4328: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4329: }
1.484.2.19 raeburn 4330: $r->print(&endContentScreen());
1.329 droeschl 4331: }
4332:
4333:
4334: sub verifycontent {
4335: my ($r) = @_;
1.408 raeburn 4336: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4337: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4338: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4339: $r->print(&startContentScreen('tools'));
4340: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4341: $hashtied=0;
4342: undef %alreadyseen;
4343: %alreadyseen=();
4344: &tiehash();
1.484 raeburn 4345:
1.329 droeschl 4346: foreach my $key (keys(%hash)) {
4347: if ($hash{$key}=~/\.(page|sequence)$/) {
4348: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4349: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4350: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4351: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4352: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4353: }
4354: }
4355: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4356: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4357: }
4358: }
4359: &untiehash();
1.442 www 4360: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4361: $r->print(&endContentScreen());
1.329 droeschl 4362: }
4363:
4364:
4365: sub devalidateversioncache {
4366: my $src=shift;
4367: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4368: &Apache::lonnet::clutter($src));
4369: }
4370:
4371: sub checkversions {
1.484.2.67 raeburn 4372: my ($r,$canedit) = @_;
1.408 raeburn 4373: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4374: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4375: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4376: $r->print(&startContentScreen('tools'));
1.442 www 4377:
1.329 droeschl 4378: my $header='';
4379: my $startsel='';
4380: my $monthsel='';
4381: my $weeksel='';
4382: my $daysel='';
4383: my $allsel='';
4384: my %changes=();
4385: my $starttime=0;
4386: my $haschanged=0;
4387: my %setversions=&Apache::lonnet::dump('resourceversions',
4388: $env{'course.'.$env{'request.course.id'}.'.domain'},
4389: $env{'course.'.$env{'request.course.id'}.'.num'});
4390:
4391: $hashtied=0;
4392: &tiehash();
1.484.2.67 raeburn 4393: if ($canedit) {
4394: my %newsetversions=();
4395: if ($env{'form.setmostrecent'}) {
4396: $haschanged=1;
4397: foreach my $key (keys(%hash)) {
4398: if ($key=~/^ids\_(\/res\/.+)$/) {
4399: $newsetversions{$1}='mostrecent';
4400: &devalidateversioncache($1);
4401: }
1.329 droeschl 4402: }
1.484.2.67 raeburn 4403: } elsif ($env{'form.setcurrent'}) {
4404: $haschanged=1;
4405: foreach my $key (keys(%hash)) {
4406: if ($key=~/^ids\_(\/res\/.+)$/) {
4407: my $getvers=&Apache::lonnet::getversion($1);
4408: if ($getvers>0) {
4409: $newsetversions{$1}=$getvers;
4410: &devalidateversioncache($1);
4411: }
4412: }
1.329 droeschl 4413: }
1.484.2.67 raeburn 4414: } elsif ($env{'form.setversions'}) {
4415: $haschanged=1;
4416: foreach my $key (keys(%env)) {
4417: if ($key=~/^form\.set_version_(.+)$/) {
4418: my $src=$1;
4419: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4420: $newsetversions{$src}=$env{$key};
4421: &devalidateversioncache($src);
4422: }
4423: }
1.329 droeschl 4424: }
1.484.2.67 raeburn 4425: }
4426: if ($haschanged) {
4427: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4428: $env{'course.'.$env{'request.course.id'}.'.domain'},
4429: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4430: $r->print(&Apache::loncommon::confirmwrapper(
4431: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4432: } else {
4433: $r->print(&Apache::loncommon::confirmwrapper(
4434: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4435: }
4436: &mark_hash_old();
4437: }
4438: &changewarning($r,'');
1.329 droeschl 4439: }
4440: if ($env{'form.timerange'} eq 'all') {
4441: # show all documents
1.484.2.34 raeburn 4442: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4443: $allsel=' selected="selected"';
1.329 droeschl 4444: foreach my $key (keys(%hash)) {
4445: if ($key=~/^ids\_(\/res\/.+)$/) {
4446: my $src=$1;
4447: $changes{$src}=1;
4448: }
4449: }
4450: } else {
4451: # show documents which changed
4452: %changes=&Apache::lonnet::dump
4453: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4454: $env{'course.'.$env{'request.course.id'}.'.num'});
4455: my $firstkey=(keys(%changes))[0];
4456: unless ($firstkey=~/^error\:/) {
4457: unless ($env{'form.timerange'}) {
4458: $env{'form.timerange'}=604800;
4459: }
4460: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4461: .&mt('seconds');
4462: if ($env{'form.timerange'}==-1) {
4463: $seltext='since start of course';
1.484.2.19 raeburn 4464: $startsel=' selected="selected"';
1.329 droeschl 4465: $env{'form.timerange'}=time;
4466: }
4467: $starttime=time-$env{'form.timerange'};
4468: if ($env{'form.timerange'}==2592000) {
4469: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4470: $monthsel=' selected="selected"';
1.329 droeschl 4471: } elsif ($env{'form.timerange'}==604800) {
4472: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4473: $weeksel=' selected="selected"';
1.329 droeschl 4474: } elsif ($env{'form.timerange'}==86400) {
4475: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4476: $daysel=' selected="selected"';
1.329 droeschl 4477: }
4478: $header=&mt('Content changed').' '.$seltext;
4479: } else {
4480: $header=&mt('No content modifications yet.');
4481: }
4482: }
4483: %setversions=&Apache::lonnet::dump('resourceversions',
4484: $env{'course.'.$env{'request.course.id'}.'.domain'},
4485: $env{'course.'.$env{'request.course.id'}.'.num'});
4486: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4487: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4488: 'lm' => 'Version changes since last Month',
4489: 'lw' => 'Version changes since last Week',
4490: 'sy' => 'Version changes since Yesterday',
4491: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4492: 'cd' => 'Change display',
1.329 droeschl 4493: 'sd' => 'Display',
4494: 'fi' => 'File',
4495: 'md' => 'Modification Date',
4496: 'mr' => 'Most recently published Version',
1.408 raeburn 4497: 've' => 'Version used in '.$crstype,
4498: 'vu' => 'Set Version to be used in '.$crstype,
4499: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4500: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4501: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4502: 'di' => 'Differences',
1.484 raeburn 4503: 'save' => 'Save changes',
4504: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4505: 'act' => 'Actions');
1.484.2.67 raeburn 4506: my ($disabled,$readonly);
4507: unless ($canedit) {
4508: $disabled = 'disabled="disabled"';
4509: $readonly = 1;
4510: }
1.329 droeschl 4511: $r->print(<<ENDHEADERS);
1.484 raeburn 4512: <h4 class="LC_info">$header</h4>
1.329 droeschl 4513: <form action="/adm/coursedocs" method="post">
4514: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4515: <div class="LC_left_float">
1.479 golterma 4516: <fieldset>
1.484 raeburn 4517: <legend>$lt{'cd'}</legend>
1.329 droeschl 4518: <select name="timerange">
1.484.2.19 raeburn 4519: <option value='all'$allsel>$lt{'al'}</option>
4520: <option value="-1"$startsel>$lt{'st'}</option>
4521: <option value="2592000"$monthsel>$lt{'lm'}</option>
4522: <option value="604800"$weeksel>$lt{'lw'}</option>
4523: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4524: </select>
4525: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4526: </fieldset>
4527: </div>
4528: <div class="LC_left_float">
4529: <fieldset>
4530: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4531: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4532: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4533: </fieldset>
4534: </div>
4535: <br clear="all" />
4536: <hr />
4537: <h4>$lt{'vers'}</h4>
1.329 droeschl 4538: ENDHEADERS
1.479 golterma 4539: #number of columns for version history
1.484.2.44 raeburn 4540: my %changedbytime;
4541: foreach my $key (keys(%changes)) {
4542: #excludes not versionable problems from resource version history:
4543: next if ($key =~ /^\/res\/lib\/templates/);
4544: my $chg;
4545: if ($env{'form.timerange'} eq 'all') {
4546: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4547: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4548: } else {
4549: $chg = $changes{$key};
4550: next if ($chg < $starttime);
4551: }
4552: push(@{$changedbytime{$chg}},$key);
4553: }
4554: if (keys(%changedbytime) == 0) {
4555: &untiehash();
4556: $r->print(&mt('No content changes in imported content in specified time frame').
4557: &endContentScreen());
4558: return;
4559: }
1.479 golterma 4560: $r->print(
1.484.2.67 raeburn 4561: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4562: &Apache::loncommon::start_data_table().
4563: &Apache::loncommon::start_data_table_header_row().
4564: '<th>'.&mt('Resources').'</th>'.
4565: "<th>$lt{'mr'}</th>".
4566: "<th>$lt{'ve'}</th>".
4567: "<th>$lt{'vu'}</th>".
4568: '<th>'.&mt('History').'</th>'.
4569: &Apache::loncommon::end_data_table_header_row()
4570: );
1.484.2.44 raeburn 4571: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4572: foreach my $key (sort(@{$changedbytime{$chg}})) {
4573: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4574: my $currentversion=&Apache::lonnet::getversion($key);
4575: if ($currentversion<0) {
4576: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4577: }
4578: my $linkurl=&Apache::lonnet::clutter($key);
4579: $r->print(
4580: &Apache::loncommon::start_data_table_row().
4581: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4582: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4583: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4584: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4585: '<td align="right">'
4586: );
4587: # Used in course
4588: my $usedversion=$hash{'version_'.$linkurl};
4589: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4590: if ($usedversion != $currentversion) {
1.479 golterma 4591: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4592: } else {
1.479 golterma 4593: $r->print($usedversion);
4594: }
1.329 droeschl 4595: } else {
1.484.2.19 raeburn 4596: $r->print($currentversion);
1.329 droeschl 4597: }
1.484.2.44 raeburn 4598: $r->print('</td><td title="'.$lt{'vu'}.'">');
4599: # Set version
4600: $r->print(&Apache::loncommon::select_form(
4601: $setversions{$linkurl},
4602: 'set_version_'.$linkurl,
4603: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4604: '' => '',
4605: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4606: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4607: my $lastold=1;
4608: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4609: my $url=$root.'.'.$prevvers.'.'.$extension;
4610: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4611: $lastold=$prevvers;
4612: }
4613: }
4614: $r->print('</td>');
4615: # List all available versions
4616: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4617: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4618: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4619: $r->print(
1.484.2.44 raeburn 4620: '<span class="LC_nobreak">'
4621: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4622: .&mt('Version [_1]',$prevvers).'</a>'
4623: .' ('.&Apache::lonlocal::locallocaltime(
4624: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4625: .')');
4626: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4627: $r->print(
4628: ' <a href="/adm/diff?filename='.
4629: &Apache::lonnet::clutter($root.'.'.$extension).
4630: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4631: '" target="diffs">'.&mt('Diffs').'</a>');
4632: }
4633: $r->print('</span><br />');
1.329 droeschl 4634: }
1.484.2.44 raeburn 4635: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4636: }
1.329 droeschl 4637: }
1.484.2.19 raeburn 4638: $r->print(
4639: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4640: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4641: '</form>'
4642: );
1.329 droeschl 4643:
4644: &untiehash();
1.484.2.19 raeburn 4645: $r->print(&endContentScreen());
1.484.2.44 raeburn 4646: return;
1.329 droeschl 4647: }
4648:
4649: sub mark_hash_old {
4650: my $retie_hash=0;
4651: if ($hashtied) {
4652: $retie_hash=1;
4653: &untiehash();
4654: }
4655: &tiehash('write');
4656: $hash{'old'}=1;
4657: &untiehash();
4658: if ($retie_hash) { &tiehash(); }
4659: }
4660:
4661: sub is_hash_old {
4662: my $untie_hash=0;
4663: if (!$hashtied) {
4664: $untie_hash=1;
4665: &tiehash();
4666: }
4667: my $return=$hash{'old'};
4668: if ($untie_hash) { &untiehash(); }
4669: return $return;
4670: }
4671:
4672: sub changewarning {
4673: my ($r,$postexec,$message,$url)=@_;
4674: if (!&is_hash_old()) { return; }
4675: my $pathvar='folderpath';
4676: my $path=&escape($env{'form.folderpath'});
4677: if (!defined($url)) {
4678: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4679: }
4680: my $course_type = &Apache::loncommon::course_type();
4681: if (!defined($message)) {
4682: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4683: }
4684: $r->print("\n\n".
1.372 bisitz 4685: '<script type="text/javascript">'."\n".
4686: '// <![CDATA['."\n".
4687: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4688: '// ]]>'."\n".
1.369 bisitz 4689: '</script>'."\n".
1.375 tempelho 4690: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4691: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4692: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4693: &mt($message,' <input type="hidden" name="'.
4694: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4695: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4696: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4697: }
4698:
4699:
4700: sub init_breadcrumbs {
1.484.2.44 raeburn 4701: my ($form,$text,$help)=@_;
1.329 droeschl 4702: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4703: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4704: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4705: faq=>273,
4706: bug=>'Instructor Interface',
1.484.2.44 raeburn 4707: help => $help});
1.329 droeschl 4708: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4709: text=>$text,
4710: faq=>273,
4711: bug=>'Instructor Interface'});
4712: }
4713:
1.441 www 4714: # subroutine to list form elements
4715: sub create_list_elements {
4716: my @formarr = @_;
4717: my $list = '';
1.484.2.12 raeburn 4718: foreach my $button (@formarr){
4719: foreach my $picture (keys(%{$button})) {
4720: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4721: }
4722: }
4723: return $list;
4724: }
1.329 droeschl 4725:
1.441 www 4726: # subroutine to create ul from list elements
4727: sub create_form_ul {
4728: my $list = shift;
4729: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4730: return $ul;
4731: }
1.329 droeschl 4732:
1.442 www 4733: #
4734: # Start tabs
4735: #
4736:
4737: sub startContentScreen {
1.484 raeburn 4738: my ($mode) = @_;
4739: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4740: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4741: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4742: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4743: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4744: } else {
1.484.2.34 raeburn 4745: $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 4746: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4747: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4748: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4749: }
4750: $output .= "\n".'</ul>'."\n";
4751: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4752: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4753: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4754: return $output;
1.442 www 4755: }
4756:
4757: #
4758: # End tabs
4759: #
4760:
4761: sub endContentScreen {
1.484 raeburn 4762: return '</div></div></div>';
1.442 www 4763: }
1.329 droeschl 4764:
1.446 www 4765: sub supplemental_base {
1.484.2.33 raeburn 4766: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4767: }
4768:
1.329 droeschl 4769: sub handler {
4770: my $r = shift;
4771: &Apache::loncommon::content_type($r,'text/html');
4772: $r->send_http_header;
4773: return OK if $r->header_only;
1.484 raeburn 4774:
4775: # get course data
1.408 raeburn 4776: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4777: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4778: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4779:
4780: # graphics settings
4781: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4782:
1.443 www 4783: #
1.329 droeschl 4784: # --------------------------------------------- Initialize help topics for this
4785: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4786: 'Adding_External_Resource','Navigate_Content',
4787: 'Adding_Folders','Docs_Overview', 'Load_Map',
4788: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 4789: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 4790: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
4791: 'Dropbox','Simple_Problem') {
1.329 droeschl 4792: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4793: }
4794: # Composite help files
4795: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4796: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4797: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4798: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4799: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4800: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4801: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4802: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4803: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4804: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 4805:
1.484.2.67 raeburn 4806: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 4807: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4808: unless ($r->uri eq '/adm/supplemental') {
4809: # does this user have privileges to modify content.
1.484.2.67 raeburn 4810: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
4811: $allowed = 1;
4812: $canedit = 1;
4813: $canview = 1;
4814: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
4815: $allowed = 1;
4816: $canview = 1;
4817: }
4818: }
4819: unless ($canedit) {
4820: $disabled = ' disabled="disabled"';
1.472 raeburn 4821: }
1.484.2.53 raeburn 4822: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
4823: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 4824: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 4825: &verifycontent($r);
4826: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4827: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4828: &list_symbs($r);
4829: } elsif ($allowed && $env{'form.docslog'}) {
4830: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4831: my $folder = $env{'form.folder'};
4832: if ($folder eq '') {
4833: $folder='default';
4834: }
1.484.2.67 raeburn 4835: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 4836: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 4837: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 4838: &checkversions($r,$canedit);
4839: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 4840: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4841: &dumpcourse($r);
4842: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 4843: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4844: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4845: } else {
1.445 www 4846: #
4847: # Done catching special calls
1.484 raeburn 4848: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 4849: # Get the parameters that may be needed
4850: #
4851: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 4852: ['folderpath',
4853: 'forcesupplement','forcestandard',
4854: 'tools','symb','command','supppath']);
1.445 www 4855:
4856: # standard=1: this is a "new-style" course with an uploaded map as top level
4857: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 4858:
4859: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 4860:
1.484 raeburn 4861: # Decide whether this should display supplemental or main content or utilities
1.445 www 4862: # supplementalflag=1: show supplemental documents
4863: # supplementalflag=0: show standard documents
1.484 raeburn 4864: # toolsflag=1: show utilities
1.445 www 4865:
1.484.2.39 raeburn 4866: my $unesc_folderpath = &unescape($env{'form.folderpath'});
4867: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
4868: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 4869: $supplementalflag=0;
4870: }
4871: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4872: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4873: unless ($allowed) { $supplementalflag=1; }
4874: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 4875: my $toolsflag=0;
4876: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 4877:
1.329 droeschl 4878: my $script='';
4879: my $showdoc=0;
1.457 raeburn 4880: my $addentries = {};
1.475 raeburn 4881: my $container;
1.329 droeschl 4882: my $containertag;
1.484.2.17 raeburn 4883: my $pathitem;
1.484.2.67 raeburn 4884: my $hiddentop;
4885: my $navmap;
4886: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 4887:
1.464 www 4888: # Do we directly jump somewhere?
1.484.2.21 raeburn 4889: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 4890: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 4891: $env{'form.folderpath'}=
1.484.2.67 raeburn 4892: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 4893: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4894: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 4895: } elsif ($env{'form.supppath'} ne '') {
4896: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 4897: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4898: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 4899: }
1.472 raeburn 4900: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 4901: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 4902: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 4903: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 4904: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 4905: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
4906: } elsif ($env{'form.command'} eq 'contents') {
4907: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
4908: } elsif ($env{'form.command'} eq 'home') {
4909: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 4910: }
4911:
1.484.2.23 raeburn 4912:
1.445 www 4913: # Where do we store these for when we come back?
4914: my $stored_folderpath='docs_folderpath';
4915: if ($supplementalflag) {
4916: $stored_folderpath='docs_sup_folderpath';
4917: }
1.464 www 4918:
1.484.2.19 raeburn 4919: # No folderpath, and in edit mode, see if we have something stored
4920: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 4921: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 4922: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 4923:
4924: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
4925: if ($supplementalflag) {
4926: undef($env{'form.folderpath'}) if ($1 eq 'default');
4927: } else {
4928: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
4929: }
4930: } else {
1.484.2.19 raeburn 4931: undef($env{'form.folderpath'});
4932: }
1.329 droeschl 4933: }
1.446 www 4934:
4935: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 4936: if (!$allowed) {
1.446 www 4937: unless ($env{'form.folderpath'} =~ /^supplemental/) {
4938: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 4939: }
4940: }
1.446 www 4941: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 4942: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 4943: $env{'form.folderpath'} = &supplemental_base()
4944: .'&'.
1.329 droeschl 4945: $env{'form.folderpath'};
4946: }
1.484.2.67 raeburn 4947: # If allowed and user's role is not advanced check folderpath is not hidden
4948: if (($allowed) && (!$env{'request.role.adv'}) &&
4949: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
4950: my $folderurl;
4951: my @pathitems = split(/\&/,$env{'form.folderpath'});
4952: my $folder = $pathitems[-2];
4953: if ($folder eq '') {
4954: undef($env{'form.folderpath'});
4955: } else {
4956: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
4957: if ((split(/\:/,$pathitems[-1]))[4]) {
4958: $folderurl .= '.page';
4959: } else {
4960: $folderurl .= '.sequence';
4961: }
4962: unless (ref($navmap)) {
4963: $navmap = Apache::lonnavmaps::navmap->new();
4964: }
4965: if (ref($navmap)) {
4966: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4967: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
4968: unless (@resources) {
4969: undef($env{'form.folderpath'});
4970: }
4971: }
4972: }
4973: }
4974: }
4975:
4976:
1.446 www 4977: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 4978: unless ($env{'form.folderpath'}) {
1.446 www 4979: if ($supplementalflag) {
4980: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 4981: } elsif ($allowed) {
4982: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 4983: }
1.472 raeburn 4984: }
1.446 www 4985:
1.445 www 4986: # Store this
1.484 raeburn 4987: unless ($toolsflag) {
1.484.2.67 raeburn 4988: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 4989: &Apache::loncommon::store_course_settings($stored_folderpath,
4990: {'folderpath' => 'scalar'});
4991: }
4992: my $folderpath;
1.484 raeburn 4993: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 4994: $folderpath = $env{'form.folderpath'};
4995: my (@folders)=split('&',$env{'form.folderpath'});
4996: $env{'form.foldername'}=&unescape(pop(@folders));
4997: if ($env{'form.foldername'} =~ /\:1$/) {
4998: $container = 'page';
4999: } else {
5000: $container = 'sequence';
5001: }
5002: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5003: } else {
1.484.2.19 raeburn 5004: if ($env{'form.folder'} eq '' ||
5005: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5006: if ($env{'form.folder'} eq 'supplemental') {
5007: $folderpath=&supplemental_base();
5008: } elsif (!$hiddentop) {
5009: $folderpath='default&'.
5010: &escape(&mt('Main Content').':::::');
5011: }
1.484 raeburn 5012: }
5013: }
1.484.2.19 raeburn 5014: $containertag = '<input type="hidden" name="folderpath" value="" />';
5015: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5016: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5017: $showdoc='/'.$1;
5018: }
5019: if ($showdoc) { # got called in sequence from course
5020: $allowed=0;
5021: } else {
1.484.2.67 raeburn 5022: if ($canedit) {
1.484 raeburn 5023: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5024: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5025: }
5026: }
1.329 droeschl 5027: }
5028:
1.344 bisitz 5029: # get personal data
1.329 droeschl 5030: my $uname=$env{'user.name'};
5031: my $udom=$env{'user.domain'};
5032: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5033:
5034: if ($allowed) {
1.484 raeburn 5035: if ($toolsflag) {
5036: $script .= &inject_data_js();
5037: my ($home,$other,%outhash)=&authorhosts();
5038: if (!$home && $other) {
5039: my @hosts;
5040: foreach my $aurole (keys(%outhash)) {
5041: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5042: push(@hosts,$outhash{$aurole});
5043: }
5044: }
5045: $script .= &dump_switchserver_js(@hosts);
5046: }
1.458 raeburn 5047: } else {
1.484.2.43 raeburn 5048: my $tid = 1;
1.484 raeburn 5049: my @tabids;
5050: if ($supplementalflag) {
5051: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5052: $tid = 2;
1.484 raeburn 5053: } else {
5054: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5055: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5056: unshift(@tabids,'001');
5057: push(@tabids,('dd1','ee1'));
5058: }
1.458 raeburn 5059: }
1.484 raeburn 5060: my $tabidstr = join("','",@tabids);
1.484.2.68 raeburn 5061: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.67 raeburn 5062: $canedit,\$navmap).
1.484 raeburn 5063: &history_tab_js().
5064: &inject_data_js().
1.484.2.43 raeburn 5065: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5066: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5067: $addentries = {
1.484.2.3 raeburn 5068: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5069: };
1.458 raeburn 5070: }
1.484.2.30 raeburn 5071: $script .= &paste_popup_js();
1.484.2.12 raeburn 5072: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5073: &mt('Switch server?');
1.484.2.19 raeburn 5074:
5075:
1.329 droeschl 5076: }
5077: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5078: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5079: .'// <![CDATA['."\n"
5080: .$script."\n"
5081: .'// ]]>'."\n"
5082: .'</script>'."\n";
1.385 bisitz 5083:
5084: # Breadcrumbs
5085: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5086:
5087: if ($showdoc) {
5088: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5089: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5090: } elsif ($toolsflag) {
1.484.2.67 raeburn 5091: my ($breadtext,$breadtitle);
5092: $breadtext = "$crstype Editor";
5093: if ($canedit) {
5094: $breadtitle = 'Editing '.$crstype.' Contents';
5095: } else {
5096: $breadtext .= ' (View-only mode)';
5097: $breadtitle = 'Viewing '.$crstype.' Contents';
5098: }
1.484.2.44 raeburn 5099: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5100: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5101: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5102: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5103: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5104: $breadtitle)
1.484.2.44 raeburn 5105: );
1.484.2.19 raeburn 5106: } elsif ($r->uri eq '/adm/supplemental') {
5107: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5108: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5109: {'bread_crumbs' => $brcrum,}));
5110: } else {
1.484.2.67 raeburn 5111: my ($breadtext,$breadtitle,$helpitem);
5112: $breadtext = "$crstype Editor";
5113: if ($canedit) {
5114: $breadtitle = 'Editing '.$crstype.' Contents';
5115: $helpitem = 'Docs_Adding_Course_Doc';
5116: } else {
5117: $breadtext .= ' (View-only mode)';
5118: $breadtitle = 'Viewing '.$crstype.' Contents';
5119: $helpitem = 'Docs_Viewing_Course_Doc';
5120: }
1.392 raeburn 5121: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5122: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5123: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5124: {'add_entries' => $addentries}
5125: )
1.392 raeburn 5126: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5127: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5128: $breadtitle,
5129: $helpitem)
1.392 raeburn 5130: );
5131: }
1.364 bisitz 5132:
1.329 droeschl 5133: my %allfiles = ();
5134: my %codebase = ();
1.440 raeburn 5135: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5136: if ($canedit) {
1.329 droeschl 5137: if (($env{'form.uploaddoc.filename'}) &&
5138: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5139: my $context = $1;
5140: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5141: undef($hadchanges);
1.440 raeburn 5142: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5143: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5144: undef($navmap);
1.329 droeschl 5145: if ($hadchanges) {
5146: &mark_hash_old();
5147: }
1.440 raeburn 5148: $r->print($upload_output);
5149: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5150: # Process file upload - phase two - upload embedded objects
5151: $uploadphase = 'check_embedded';
5152: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5153: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5154: $env{'form.newidx'});
5155: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5156: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5157: my ($destination,$dir_root) = &embedded_destination();
5158: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5159: my $actionurl = '/adm/coursedocs';
5160: my ($result,$flag) =
5161: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5162: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5163: $actionurl);
5164: $r->print($result.&return_to_editor());
5165: } elsif ($env{'form.phase'} eq 'check_embedded') {
5166: # Process file upload - phase three - modify references in HTML file
5167: $uploadphase = 'modified_orightml';
5168: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5169: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5170: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5171: my $result =
5172: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5173: $docuname,$docudom,undef,
5174: $dir_root);
5175: $r->print($result.&return_to_editor());
1.476 raeburn 5176: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5177: $uploadphase = 'decompress_phase_one';
5178: $r->print(&decompression_phase_one().
5179: &return_to_editor());
5180: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5181: $uploadphase = 'decompress_phase_two';
5182: $r->print(&decompression_phase_two().
5183: &return_to_editor());
1.329 droeschl 5184: }
5185: }
5186:
1.484 raeburn 5187: if ($allowed && $toolsflag) {
5188: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5189: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5190: $r->print(&endContentScreen());
5191: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5192: # -----------------------------------------------------------------------------
5193: my %lt=&Apache::lonlocal::texthash(
5194: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5195: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5196: 'upld' => 'Upload Content',
1.329 droeschl 5197: 'srch' => 'Search',
5198: 'impo' => 'Import',
1.484.2.19 raeburn 5199: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5200: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5201: 'selm' => 'Select Map',
5202: 'load' => 'Load Map',
5203: 'newf' => 'New Folder',
5204: 'newp' => 'New Composite Page',
5205: 'syll' => 'Syllabus',
1.425 raeburn 5206: 'navc' => 'Table of Contents',
1.343 biermanm 5207: 'sipa' => 'Simple Course Page',
1.329 droeschl 5208: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5209: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5210: 'drbx' => 'Drop Box',
1.451 www 5211: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5212: 'bull' => 'Discussion Board',
1.347 weissno 5213: 'mypi' => 'My Personal Information Page',
1.353 weissno 5214: 'grpo' => 'Group Portfolio',
1.329 droeschl 5215: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5216: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5217: 'imsf' => 'IMS Upload',
5218: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5219: 'cms' => 'Origin of IMS package',
5220: 'se' => 'Select',
1.484.2.19 raeburn 5221: 'file' => 'File',
1.329 droeschl 5222: 'title' => 'Title',
5223: 'comment' => 'Comment',
1.403 raeburn 5224: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5225: 'bb5' => 'Blackboard 5',
5226: 'bb6' => 'Blackboard 6',
5227: 'angel5' => 'ANGEL 5.5',
5228: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5229: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5230: );
1.329 droeschl 5231: # -----------------------------------------------------------------------------
1.484.2.64 raeburn 5232: # Calculate free quota space for a user or course.
5233: my $quotatype = 'unofficial';
5234: if ($crstype eq 'Community') {
5235: $quotatype = 'community';
5236: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5237: $quotatype = 'official';
5238: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5239: $quotatype = 'textbook';
5240: }
5241: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5242: 'course',$quotatype); # expressed in MB
5243: my $current_disk_usage = 0;
5244: foreach my $subdir ('docs','supplemental') {
5245: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5246: "userfiles/$subdir",1); # expressed in kB
5247: }
5248: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5249: my $usage = $current_disk_usage/1024; # in MB
5250: my $quota = $disk_quota;
5251: my $percent;
5252: if ($disk_quota == 0) {
5253: $percent = 100.0;
5254: } else {
1.484.2.69 raeburn 5255: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5256: }
5257: $usage = sprintf("%.2f",$usage);
5258: $quota = sprintf("%.2f",$quota);
5259: $percent = sprintf("%.0f",$percent);
5260: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5261: $percent.'%',$quota.' MB').'</p>';
5262:
1.329 droeschl 5263: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5264: $quotainfo
1.329 droeschl 5265: $lt{'file'}:<br />
1.484.2.67 raeburn 5266: <input type="file" name="uploaddoc" size="40" $disabled />
1.329 droeschl 5267: FIUP
5268:
5269: my $checkbox=(<<CHBO);
5270: <!-- <label>$lt{'parse'}?
5271: <input type="checkbox" name="parserflag" />
5272: </label> -->
5273: <label>
1.484.2.67 raeburn 5274: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5275: </label>
5276: CHBO
1.484.2.12 raeburn 5277: my $imsfolder = $env{'form.folder'};
5278: if ($imsfolder eq '') {
1.484.2.19 raeburn 5279: $imsfolder = 'default';
1.484.2.12 raeburn 5280: }
5281: my $imspform=(<<IMSFORM);
5282: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5283: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5284: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5285: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5286: <legend>$lt{'imsf'}</legend>
5287: $fileupload
5288: <br />
5289: <p>
1.484.2.19 raeburn 5290: $lt{'cms'}:
1.484.2.67 raeburn 5291: <select name="source" $disabled>
1.484.2.12 raeburn 5292: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5293: <option value="bb5">$lt{'bb5'}</option>
5294: <option value="bb6">$lt{'bb6'}</option>
5295: <option value="angel5">$lt{'angel5'}</option>
5296: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5297: </select>
5298: <input type="hidden" name="folder" value="$imsfolder" />
5299: </p>
5300: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5301: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5302: </fieldset>
5303: </form>
5304: IMSFORM
5305:
1.484.2.19 raeburn 5306: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5307: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5308: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5309: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5310: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5311: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5312: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5313: $fileupload
5314: <br />
5315: $lt{'title'}:<br />
1.484.2.67 raeburn 5316: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5317: $pathitem
1.329 droeschl 5318: <input type="hidden" name="cmd" value="upload_default" />
5319: <br />
1.458 raeburn 5320: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5321: $checkbox
5322: </span>
1.484.2.12 raeburn 5323: <br clear="all" />
1.484.2.67 raeburn 5324: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5325: </fieldset>
5326: </form>
1.383 tempelho 5327: FUFORM
1.329 droeschl 5328:
1.484.2.67 raeburn 5329: my $mapimportjs;
5330: if ($canedit) {
5331: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5332: } else {
5333: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5334: }
1.484.2.19 raeburn 5335: my $importpubform=(<<SEDFFORM);
5336: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5337: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5338: <form action="/adm/coursedocs" method="post" name="mapimportform">
5339: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5340: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5341: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5342: $lt{'copm'}<br />
5343: <span class="LC_nobreak">
1.484.2.19 raeburn 5344: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5345: onfocus="this.blur();$mapimportjs" $disabled />
5346: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5347: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5348: </fieldset>
5349: </form>
5350:
1.383 tempelho 5351: SEDFFORM
1.484.2.67 raeburn 5352:
5353: my $fromstoredjs;
5354: if ($canedit) {
5355: $fromstoredjs = 'open_StoredLinks_Import()';
5356: } else {
5357: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5358: }
5359:
1.484.2.19 raeburn 5360: my @importpubforma = (
5361: { '<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 5362: { '<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.484.2.67 raeburn 5363: { '<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.484.2.19 raeburn 5364: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5365: );
5366: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5367: my $extresourcesform =
5368: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5369: $help{'Adding_External_Resource'},
5370: undef,undef,$disabled);
1.329 droeschl 5371: if ($allowed) {
1.484.2.7 raeburn 5372: my $folder = $env{'form.folder'};
5373: if ($folder eq '') {
5374: $folder='default';
5375: }
1.484.2.67 raeburn 5376: if ($canedit) {
5377: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5378: if ($output) {
5379: $r->print($output);
5380: }
1.484.2.30 raeburn 5381: }
1.337 ehlerst 5382: $r->print(<<HIDDENFORM);
5383: <form name="renameform" method="post" action="/adm/coursedocs">
5384: <input type="hidden" name="title" />
5385: <input type="hidden" name="cmd" />
5386: <input type="hidden" name="markcopy" />
5387: <input type="hidden" name="copyfolder" />
5388: $containertag
5389: </form>
1.484 raeburn 5390:
1.337 ehlerst 5391: HIDDENFORM
1.484.2.17 raeburn 5392: $r->print(&makesimpleeditform($pathitem)."\n".
5393: &makedocslogform($pathitem."\n".
1.484 raeburn 5394: '<input type="hidden" name="folder" value="'.
5395: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5396: }
1.442 www 5397:
5398: # Generate the tabs
1.484.2.19 raeburn 5399: my ($mode,$needs_end);
1.472 raeburn 5400: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5401: my @folders = split('&',$env{'form.folderpath'});
5402: unless (@folders > 2) {
5403: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5404: $needs_end = 1;
5405: }
1.472 raeburn 5406: } else {
1.484 raeburn 5407: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5408: $needs_end = 1;
1.472 raeburn 5409: }
1.443 www 5410:
1.442 www 5411: #
5412:
5413: my $savefolderpath;
5414:
1.395 raeburn 5415: if ($allowed) {
1.329 droeschl 5416: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5417: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5418: $folder='default';
1.356 tempelho 5419: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5420: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5421: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5422: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5423: }
5424: my $postexec='';
5425: if ($folder eq 'default') {
1.372 bisitz 5426: $r->print('<script type="text/javascript">'."\n"
5427: .'// <![CDATA['."\n"
5428: .'this.window.name="loncapaclient";'."\n"
5429: .'// ]]>'."\n"
5430: .'</script>'."\n"
1.369 bisitz 5431: );
1.329 droeschl 5432: } else {
5433: #$postexec='self.close();';
5434: }
1.484.2.15 raeburn 5435: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5436: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5437: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5438:
5439: my $newnavform=(<<NNFORM);
5440: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5441: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5442: $pathitem
1.329 droeschl 5443: <input type="hidden" name="importdetail"
5444: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5445: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5446: $help{'Navigate_Content'}
5447: </form>
5448: NNFORM
5449: my $newsmppageform=(<<NSPFORM);
5450: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5451: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5452: $pathitem
1.329 droeschl 5453: <input type="hidden" name="importdetail" value="" />
1.423 onken 5454: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5455: $help{'Simple Page'}
1.329 droeschl 5456: </form>
5457: NSPFORM
5458:
5459: my $newsmpproblemform=(<<NSPROBFORM);
5460: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5461: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5462: $pathitem
1.329 droeschl 5463: <input type="hidden" name="importdetail" value="" />
1.423 onken 5464: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5465: $help{'Simple_Problem'}
1.329 droeschl 5466: </form>
5467:
5468: NSPROBFORM
5469:
5470: my $newdropboxform=(<<NDBFORM);
5471: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5472: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5473: $pathitem
1.329 droeschl 5474: <input type="hidden" name="importdetail" value="" />
1.423 onken 5475: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5476: $help{'Dropbox'}
1.344 bisitz 5477: </form>
1.329 droeschl 5478: NDBFORM
5479:
5480: my $newexuploadform=(<<NEXUFORM);
5481: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5482: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5483: $pathitem
1.329 droeschl 5484: <input type="hidden" name="importdetail" value="" />
1.423 onken 5485: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5486: $help{'Score_Upload_Form'}
5487: </form>
5488: NEXUFORM
5489:
5490: my $newbulform=(<<NBFORM);
5491: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5492: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5493: $pathitem
1.329 droeschl 5494: <input type="hidden" name="importdetail" value="" />
1.423 onken 5495: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5496: $help{'Bulletin Board'}
5497: </form>
5498: NBFORM
5499:
5500: my $newaboutmeform=(<<NAMFORM);
5501: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5502: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5503: $pathitem
1.329 droeschl 5504: <input type="hidden" name="importdetail"
5505: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5506: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5507: $help{'My Personal Information Page'}
1.329 droeschl 5508: </form>
5509: NAMFORM
5510:
5511: my $newaboutsomeoneform=(<<NASOFORM);
5512: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5513: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5514: $pathitem
1.329 droeschl 5515: <input type="hidden" name="importdetail" value="" />
1.423 onken 5516: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5517: </form>
5518: NASOFORM
5519:
5520: my $newrosterform=(<<NROSTFORM);
5521: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5522: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5523: $pathitem
1.329 droeschl 5524: <input type="hidden" name="importdetail"
5525: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5526: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5527: $help{'Course_Roster'}
1.329 droeschl 5528: </form>
5529: NROSTFORM
5530:
1.484.2.27 raeburn 5531: my $newwebpage;
5532: if ($folder =~ /^default_?(\d*)$/) {
5533: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5534: if ($1) {
5535: $newwebpage .= $1;
5536: } else {
5537: $newwebpage .= 'default';
5538: }
5539: $newwebpage .= '/new.html';
5540: }
5541: my $newwebpageform =(<<NWEBFORM);
5542: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5543: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5544: $pathitem
5545: <input type="hidden" name="importdetail" value="$newwebpage" />
5546: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5547: $help{'Web_Page'}
1.484.2.27 raeburn 5548: </form>
5549: NWEBFORM
1.484.2.30 raeburn 5550:
1.484.2.27 raeburn 5551:
1.342 ehlerst 5552: my $specialdocumentsform;
1.383 tempelho 5553: my @specialdocumentsforma;
1.451 www 5554: my $gradingform;
5555: my @gradingforma;
5556: my $communityform;
5557: my @communityforma;
1.351 ehlerst 5558: my $newfolderform;
1.390 tempelho 5559: my $newfolderb;
1.342 ehlerst 5560:
1.451 www 5561: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5562:
1.329 droeschl 5563: my $newpageform=(<<NPFORM);
5564: <form action="/adm/coursedocs" method="post" name="newpage">
5565: <input type="hidden" name="folderpath" value="$path" />
5566: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5567: <input type="hidden" name="active" value="ee" />
1.423 onken 5568: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5569: $help{'Adding_Pages'}
1.329 droeschl 5570: </form>
5571: NPFORM
1.390 tempelho 5572:
5573:
1.351 ehlerst 5574: $newfolderform=(<<NFFORM);
1.329 droeschl 5575: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5576: $pathitem
1.329 droeschl 5577: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5578: <input type="hidden" name="active" value="" />
1.422 onken 5579: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5580: </form>
5581: NFFORM
5582:
5583: my $newsylform=(<<NSYLFORM);
5584: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5585: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5586: $pathitem
1.329 droeschl 5587: <input type="hidden" name="importdetail"
5588: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5589: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5590: $help{'Syllabus'}
1.383 tempelho 5591:
1.329 droeschl 5592: </form>
5593: NSYLFORM
1.364 bisitz 5594:
1.329 droeschl 5595: my $newgroupfileform=(<<NGFFORM);
5596: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5597: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5598: $pathitem
1.329 droeschl 5599: <input type="hidden" name="importdetail"
5600: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5601: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5602: $help{'Group Portfolio'}
1.329 droeschl 5603: </form>
5604: NGFFORM
1.383 tempelho 5605: @specialdocumentsforma=(
1.421 onken 5606: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.484.2.67 raeburn 5607: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5608: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5609: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5610: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5611: );
5612: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5613:
1.434 raeburn 5614:
5615: my @importdoc = (
1.484.2.19 raeburn 5616: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5617: );
5618: unless ($container eq 'page') {
5619: push(@importdoc,
5620: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5621: );
5622: }
5623: push(@importdoc,
1.484.2.38 raeburn 5624: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.484.2.19 raeburn 5625: );
1.484.2.12 raeburn 5626: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5627:
1.451 www 5628: @gradingforma=(
5629: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5630: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5631: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5632:
5633: );
5634: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5635:
5636: @communityforma=(
5637: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5638: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5639: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5640: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5641: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5642: );
5643: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5644:
1.330 tempelho 5645: my %orderhash = (
1.484.2.36 raeburn 5646: 'aa' => ['Upload',$fileuploadform],
5647: 'bb' => ['Import',$importpubform],
5648: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5649: );
1.484.2.19 raeburn 5650: unless ($container eq 'page') {
1.434 raeburn 5651: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5652: $orderhash{'dd'} = ['Collaboration',$communityform];
1.484.2.36 raeburn 5653: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5654: }
5655:
1.341 ehlerst 5656: $hadchanges=0;
1.484 raeburn 5657: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5658: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5659: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.68 raeburn 5660: $canedit,\$navmap,$hiddentop);
1.484.2.67 raeburn 5661: undef($navmap);
1.443 www 5662: if ($error) {
5663: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5664: }
5665: if ($hadchanges) {
1.484.2.73 raeburn 5666: unless (&is_hash_old()) {
5667: &mark_hash_old();
5668: }
1.443 www 5669: }
1.341 ehlerst 5670:
1.443 www 5671: &changewarning($r,'');
5672: }
1.458 raeburn 5673: }
1.442 www 5674:
1.443 www 5675: # Supplemental documents start here
5676:
1.329 droeschl 5677: my $folder=$env{'form.folder'};
1.443 www 5678: unless ($supplementalflag) {
1.329 droeschl 5679: $folder='supplemental';
5680: }
5681: if ($folder =~ /^supplemental$/ &&
5682: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5683: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5684: } elsif ($allowed) {
1.356 tempelho 5685: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5686: }
1.484.2.17 raeburn 5687: $pathitem = '<input type="hidden" name="folderpath" value="'.
5688: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5689: if ($allowed) {
5690: my $folderseq=
1.484.2.15 raeburn 5691: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5692:
5693: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 5694: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5695: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5696: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 5697: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 5698: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5699: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5700: $fileupload
5701: <br />
5702: <br />
5703: <span class="LC_nobreak">
5704: $checkbox
5705: </span>
5706: <br /><br />
5707: $lt{'comment'}:<br />
1.383 tempelho 5708: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5709: <br />
1.484.2.19 raeburn 5710: $pathitem
1.329 droeschl 5711: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 5712: <input type='submit' value="$lt{'upld'}" />
5713: </form>
1.484.2.19 raeburn 5714: SUPDOCFORM
1.329 droeschl 5715:
5716: my $supnewfolderform=(<<SNFFORM);
5717: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 5718: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 5719: $pathitem
1.329 droeschl 5720: <input type="hidden" name="importdetail" value="" />
1.423 onken 5721: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 5722: $help{'Adding_Folders'}
1.329 droeschl 5723: </form>
5724: SNFFORM
1.383 tempelho 5725:
1.484.2.19 raeburn 5726: my $supextform =
5727: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5728: $help{'Adding_External_Resource'},
5729: undef,undef,$disabled);
1.329 droeschl 5730:
5731: my $supnewsylform=(<<SNSFORM);
5732: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 5733: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5734: $pathitem
1.329 droeschl 5735: <input type="hidden" name="importdetail"
5736: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5737: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 5738: $help{'Syllabus'}
5739: </form>
5740: SNSFORM
5741:
5742: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 5743: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 5744: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5745: $pathitem
1.329 droeschl 5746: <input type="hidden" name="importdetail"
5747: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5748: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 5749: $help{'My Personal Information Page'}
1.329 droeschl 5750: </form>
5751: SNAMFORM
5752:
1.484.2.27 raeburn 5753: my $supwebpage;
5754: if ($folder =~ /^supplemental_?(\d*)$/) {
5755: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5756: if ($1) {
5757: $supwebpage .= $1;
5758: } else {
5759: $supwebpage .= 'default';
5760: }
5761: $supwebpage .= '/new.html';
5762: }
5763: my $supwebpageform =(<<SWEBFORM);
5764: <form action="/adm/coursedocs" method="post" name="supwebpage">
5765: <input type="hidden" name="active" value="cc" />
5766: $pathitem
5767: <input type="hidden" name="importdetail" value="$supwebpage" />
5768: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 5769: $help{'Web_Page'}
1.484.2.27 raeburn 5770: </form>
5771: SWEBFORM
5772:
1.333 muellerd 5773:
1.383 tempelho 5774: my @specialdocs = (
1.484.2.67 raeburn 5775: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 5776: =>$supnewsylform},
1.484.2.67 raeburn 5777: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 5778: =>$supnewaboutmeform},
1.484.2.27 raeburn 5779: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
5780:
1.383 tempelho 5781: );
1.417 droeschl 5782: my @supimportdoc = (
1.484.2.19 raeburn 5783: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 5784: =>$supextform},
5785: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
5786: =>$supupdocform},
1.484.2.19 raeburn 5787: );
5788:
1.484.2.12 raeburn 5789: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 5790: my %suporderhash = (
1.390 tempelho 5791: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 5792: 'ee' => ['Upload',$supupdocform],
5793: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 5794: );
1.443 www 5795: if ($supplementalflag) {
1.458 raeburn 5796: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5797: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
5798: $canedit);
1.443 www 5799: if ($error) {
5800: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 5801: } else {
5802: if ($suppchanges) {
5803: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
5804: my @ids=&Apache::lonnet::current_machine_ids();
5805: foreach my $server (keys(%servers)) {
5806: next if (grep(/^\Q$server\E$/,@ids));
5807: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 5808: my $cachekey = &escape('suppcount').':'.&escape($hashid);
5809: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 5810: }
5811: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
5812: undef($suppchanges);
5813: }
1.443 www 5814: }
1.393 raeburn 5815: }
1.443 www 5816: } elsif ($supplementalflag) {
1.458 raeburn 5817: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 5818: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 5819: if ($error) {
5820: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 5821: }
1.393 raeburn 5822: }
1.389 tempelho 5823:
1.484.2.19 raeburn 5824: if ($needs_end) {
5825: $r->print(&endContentScreen());
5826: }
1.383 tempelho 5827:
1.329 droeschl 5828: if ($allowed) {
5829: $r->print('
5830: <form method="post" name="extimport" action="/adm/coursedocs">
5831: <input type="hidden" name="title" />
5832: <input type="hidden" name="url" />
5833: <input type="hidden" name="useform" />
5834: <input type="hidden" name="residx" />
5835: </form>');
5836: }
1.484 raeburn 5837: } elsif ($showdoc) {
1.329 droeschl 5838: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 5839: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 5840: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 5841: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 5842: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 5843: }
5844: }
5845: $r->print(&Apache::loncommon::end_page());
5846: return OK;
1.364 bisitz 5847: }
1.329 droeschl 5848:
1.440 raeburn 5849: sub embedded_form_elems {
5850: my ($phase,$primaryurl,$newidx) = @_;
5851: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5852: return <<STATE;
5853: <input type="hidden" name="folderpath" value="$folderpath" />
5854: <input type="hidden" name="cmd" value="upload_embedded" />
5855: <input type="hidden" name="newidx" value="$newidx" />
5856: <input type="hidden" name="phase" value="$phase" />
5857: <input type="hidden" name="primaryurl" value="$primaryurl" />
5858: STATE
5859: }
5860:
5861: sub embedded_destination {
5862: my $folder=$env{'form.folder'};
5863: my $destination = 'docs/';
5864: if ($folder =~ /^supplemental/) {
5865: $destination = 'supplemental/';
5866: }
5867: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5868: $destination .= 'default/';
5869: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5870: $destination .= $2.'/';
5871: }
5872: $destination .= $env{'form.newidx'};
5873: my $dir_root = '/userfiles';
5874: return ($destination,$dir_root);
5875: }
5876:
5877: sub return_to_editor {
5878: my $actionurl = '/adm/coursedocs';
5879: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
5880: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
5881: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
5882: '</a></p>';
5883: }
5884:
1.476 raeburn 5885: sub decompression_info {
5886: my ($destination,$dir_root) = &embedded_destination();
5887: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5888: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5889: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5890: my $container='sequence';
1.480 raeburn 5891: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 5892: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 5893: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 5894: $container='page';
5895: }
1.480 raeburn 5896: unshift(@hiddens,$pathitem);
5897: foreach my $item (@hiddens) {
5898: if ($env{'form.'.$item}) {
5899: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 5900: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 5901: }
1.477 raeburn 5902: }
1.476 raeburn 5903: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
5904: $hiddenelem);
5905: }
5906:
5907: sub decompression_phase_one {
5908: my ($dir,$file,$warning,$error,$output);
5909: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5910: &decompression_info();
1.484.2.7 raeburn 5911: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 5912: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
5913: } else {
5914: my $file = $1;
1.481 raeburn 5915: $output =
5916: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
5917: $destination,$dir_root,
5918: $hiddenelem);
5919: if ($env{'form.autoextract_camtasia'}) {
5920: $output .= &remove_archive($docudom,$docuname,$container);
5921: }
1.476 raeburn 5922: }
5923: if ($error) {
5924: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
5925: $error.'</p>'."\n";
5926: }
5927: if ($warning) {
5928: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
5929: }
5930: return $output;
5931: }
5932:
5933: sub decompression_phase_two {
5934: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5935: &decompression_info();
1.481 raeburn 5936: my $output;
1.480 raeburn 5937: if ($env{'form.archivedelete'}) {
1.481 raeburn 5938: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 5939: }
5940: $output .=
1.481 raeburn 5941: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 5942: $destination,$dir_root,$hiddenelem);
5943: return $output;
5944: }
5945:
1.480 raeburn 5946: sub remove_archive {
5947: my ($docudom,$docuname,$container) = @_;
5948: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 5949: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 5950: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
5951: if ($fatal) {
5952: if ($container eq 'page') {
5953: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
5954: } else {
5955: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
5956: }
1.484.2.54 raeburn 5957: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5958: } else {
5959: my $currcmd = $env{'form.cmd'};
5960: my $position = $env{'form.position'};
1.484.2.54 raeburn 5961: my $archiveidx = $position;
5962: if ($position > 0) {
5963: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
5964: $archiveidx = $position-1;
5965: }
5966: $env{'form.cmd'} = 'remove_'.$archiveidx;
5967: my ($title,$url,@rrest) =
5968: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
5969: if ($url eq $env{'form.archiveurl'}) {
5970: if (&handle_edit_cmd($docuname,$docudom)) {
5971: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
5972: if ($fatal) {
5973: if ($container eq 'page') {
5974: $delwarning = &mt('An error occurred updating the contents of the current page.');
5975: } else {
5976: $delwarning = &mt('An error occurred updating the contents of the current folder.');
5977: }
1.480 raeburn 5978: } else {
1.484.2.54 raeburn 5979: $delresult = &mt('Archive file removed.');
1.480 raeburn 5980: }
5981: }
1.484.2.54 raeburn 5982: } else {
5983: $delwarning .= &mt('Archive file had unexpected item number in folder.').
5984: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5985: }
5986: }
5987: $env{'form.cmd'} = $currcmd;
5988: }
5989: if ($delwarning) {
5990: $output = '<p class="LC_warning">'.
5991: $delwarning.
5992: '</p>';
5993: }
5994: if ($delresult) {
5995: $output .= '<p class="LC_info">'.
5996: $delresult.
5997: '</p>';
5998: }
1.481 raeburn 5999: return $output;
1.480 raeburn 6000: }
6001:
1.484 raeburn 6002: sub generate_admin_menu {
1.484.2.67 raeburn 6003: my ($crstype,$canedit) = @_;
1.484 raeburn 6004: my $lc_crstype = lc($crstype);
6005: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6006: my %lt= ( # do not translate here
1.484 raeburn 6007: 'vc' => 'Verify Content',
6008: 'cv' => 'Check/Set Resource Versions',
6009: 'ls' => 'List Resource Identifiers',
6010: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6011: 'dcd' => "Copy $crstype Content to Authoring Space",
6012: );
1.484 raeburn 6013: my ($candump,$dumpurl);
6014: if ($home + $other > 0) {
6015: $candump = 'F';
6016: if ($home) {
6017: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6018: } else {
6019: my @hosts;
6020: foreach my $aurole (keys(%outhash)) {
6021: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6022: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6023: }
1.484 raeburn 6024: }
6025: if (@hosts == 1) {
6026: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6027: '&role='.
6028: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6029: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6030: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6031: } else {
6032: $dumpurl = "javascript:choose_switchserver_window()";
6033: }
6034: }
6035: }
6036: my @menu=
6037: ({ categorytitle=>'Administration',
6038: items =>[
6039: { linktext => $lt{'vc'},
6040: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6041: permission => 'F',
1.484.2.44 raeburn 6042: help => 'Docs_Verify_Content',
1.484 raeburn 6043: icon => 'verify.png',
6044: linktitle => 'Verify contents can be retrieved/rendered',
6045: },
6046: { linktext => $lt{'cv'},
6047: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6048: permission => 'F',
1.484.2.44 raeburn 6049: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6050: icon => 'resversion.png',
6051: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6052: },
6053: { linktext => $lt{'ls'},
6054: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6055: permission => 'F',
6056: #help => '',
6057: icon => 'symbs.png',
6058: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6059: },
6060: ]
1.484.2.67 raeburn 6061: });
6062: if ($canedit) {
6063: push(@menu,
1.484 raeburn 6064: { categorytitle=>'Export',
6065: items =>[
6066: { linktext => $lt{'imse'},
6067: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6068: permission => 'F',
6069: help => 'Docs_Export_Course_Docs',
6070: icon => 'imsexport.png',
6071: linktitle => $lt{'imse'},
6072: },
6073: { linktext => $lt{'dcd'},
6074: url => $dumpurl,
6075: permission => $candump,
1.484.2.44 raeburn 6076: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6077: icon => 'dump.png',
6078: linktitle => $lt{'dcd'},
6079: },
6080: ]
6081: });
1.484.2.67 raeburn 6082: }
1.484 raeburn 6083: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6084: '<input type="hidden" id="dummy" />'."\n".
6085: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6086: '</form>';
1.329 droeschl 6087: }
6088:
6089: sub generate_edit_table {
1.484.2.30 raeburn 6090: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6091: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6092: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6093: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6094: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6095: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6096: $activetab = $env{'form.active'};
6097: }
1.484.2.67 raeburn 6098: unless ($canedit) {
6099: $disabled = ' disabled="disabled"';
6100: }
1.472 raeburn 6101: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6102: my $backtext = &mt('Exit Editor');
1.458 raeburn 6103: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6104: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6105: '<li class="goback">'.
1.484.2.32 raeburn 6106: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6107: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6108: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6109: '<li>'.
6110: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6111: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6112: if ($env{'form.docslog'}) {
6113: $form .= '<li class="active">';
6114: } else {
6115: $form .= '<li>';
6116: }
6117: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6118: &mt('History').'</a></li>'."\n";
6119: if ($env{'form.docslog'}) {
6120: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6121: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6122: }
1.458 raeburn 6123: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6124: if($name ne '00'){
1.371 tempelho 6125: if($activetab eq '' || $activetab ne $name){
6126: $active = '';
6127: }elsif($activetab eq $name){
6128: $active = 'class="active"';
6129: }
1.458 raeburn 6130: $form .= '<li style="float:right" '.$active
1.484 raeburn 6131: .' 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 6132: } else {
1.484.2.43 raeburn 6133: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6134:
6135: }
1.329 droeschl 6136: }
1.484 raeburn 6137: $form .= '</ul>'."\n";
6138: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6139:
6140: if ($to_show ne '') {
1.484.2.30 raeburn 6141: my $saveform;
6142: if ($need_save) {
6143: my $button = &mt('Make changes');
6144: my $path;
6145: if ($env{'form.folderpath'}) {
6146: $path =
6147: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6148: }
6149: $saveform = <<"END";
6150: <div id="multisave" style="display:none; clear:both;" >
6151: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6152: <input type="hidden" name="folderpath" value="$path" />
6153: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6154: <input type="hidden" name="allhiddenresource" value="" />
6155: <input type="hidden" name="allencrypturl" value="" />
6156: <input type="hidden" name="allrandompick" value="" />
6157: <input type="hidden" name="allrandomorder" value="" />
6158: <input type="hidden" name="changeparms" value="" />
6159: <input type="hidden" name="multiremove" value="" />
6160: <input type="hidden" name="multicut" value="" />
6161: <input type="hidden" name="multicopy" value="" />
6162: <input type="hidden" name="multichange" value="" />
6163: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6164: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6165: </form>
6166: </div>
6167: END
6168: }
6169: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6170: }
1.363 ehlerst 6171: foreach my $field (keys(%orderhash)){
1.390 tempelho 6172: if($field ne '00'){
1.422 onken 6173: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6174: $active = 'style="display: none;float:left"';
1.422 onken 6175: }elsif($activetab eq $field){
1.458 raeburn 6176: $active = 'style="display:block;float:left"';
1.422 onken 6177: }
6178: $form .= '<div id="'.$field.$tid.'"'
6179: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6180: .'</div>'."\n";
1.363 ehlerst 6181: }
6182: }
1.484 raeburn 6183: unless ($env{'form.docslog'}) {
6184: $form .= '</div></div>'."\n";
6185: }
1.329 droeschl 6186: return $form;
6187: }
6188:
6189: sub editing_js {
1.484.2.67 raeburn 6190: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$canedit,$navmapref) = @_;
1.484.2.61 raeburn 6191: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6192: p_mnf => 'Name of New Folder',
6193: t_mnf => 'New Folder',
6194: p_mnp => 'Name of New Page',
6195: t_mnp => 'New Page',
1.451 www 6196: p_mxu => 'Title for the External Score',
1.349 biermanm 6197: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6198: p_msb => 'Title for the Problem',
6199: p_mdb => 'Title for the Drop Box',
1.336 schafran 6200: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6201: p_mwp => 'Title for Web Page',
1.348 weissno 6202: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6203: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6204: p_mab_alrt1 => 'Not a valid user:domain',
6205: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6206: p_chn => 'New Title',
6207: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6208: p_rmr2a => 'Remove',
6209: p_rmr2b => '?',
6210: p_rmr3a => 'Remove those',
6211: p_rmr3b => 'items?',
6212: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6213: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6214: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6215: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6216: p_ctr2a => 'Cut',
6217: p_ctr2b => '?',
6218: p_ctr3a => 'Cut those',
6219: p_ctr3b => 'items?',
1.478 raeburn 6220: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6221: imsfile => 'You must choose an IMS package for import',
6222: imscms => 'You must select which Course Management System was the source of the IMS package',
6223: invurl => 'Invalid URL',
6224: titbl => 'Title is blank',
1.484.2.30 raeburn 6225: more => '(More ...)',
6226: less => '(Less ...)',
6227: noor => 'No actions selected or changes to settings specified.',
6228: noch => 'No changes to settings specified.',
6229: noac => 'No actions selected.',
1.484.2.67 raeburn 6230: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6231: );
6232:
1.484.2.61 raeburn 6233: &js_escape(\%js_lt);
1.433 raeburn 6234: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6235: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6236: my $main_container_page;
1.484.2.19 raeburn 6237: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6238: $main_container_page = 1;
1.434 raeburn 6239: }
1.484.2.67 raeburn 6240: my $backtourl;
6241: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6242: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6243:
1.484.2.21 raeburn 6244: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6245: my $caller = $1;
6246: if ($caller =~ /^supplemental/) {
6247: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6248: } else {
6249: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6250: $res = &Apache::lonnet::clutter($res);
6251: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6252: my ($url,$anchor);
6253: if ($res =~ /^([^#]+)#([^#]+)$/) {
6254: $url = $1;
6255: $anchor = $2;
6256: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6257: $caller = $1.&escape('#').$anchor;
6258: }
1.484.2.67 raeburn 6259: } else {
6260: $url = $res;
1.484.2.66 raeburn 6261: }
6262: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.484.2.21 raeburn 6263: &HTML::Entities::encode($caller,'<>&"');
1.484.2.66 raeburn 6264: if ($anchor ne '') {
6265: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6266: }
1.484.2.57 raeburn 6267: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6268: } else {
6269: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6270: }
6271: }
6272: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6273: $backtourl = '/adm/menu';
6274: } elsif ($supplementalflag) {
1.472 raeburn 6275: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6276: } else {
6277: $backtourl = '/adm/navmaps';
1.472 raeburn 6278: }
6279:
1.484.2.19 raeburn 6280: my $fieldsets = "'ext','doc'";
6281: unless ($main_container_page) {
6282: $fieldsets .=",'ims'";
6283: }
1.484.2.12 raeburn 6284: if ($supplementalflag) {
6285: $fieldsets = "'suppext','suppdoc'";
6286: }
6287:
1.484.2.67 raeburn 6288: my $jsmakefunctions;
6289: if ($canedit) {
6290: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6291: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6292: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6293: if (foldername) {
6294: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6295: targetform.submit();
6296: }
6297: }
6298:
6299: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6300: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6301: if (pagename) {
6302: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6303: targetform.submit();
6304: }
6305: }
6306:
6307: function makeexamupload() {
1.484.2.61 raeburn 6308: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6309: if (title) {
1.329 droeschl 6310: this.document.forms.newexamupload.importdetail.value=
6311: escape(title)+'=/res/lib/templates/examupload.problem';
6312: this.document.forms.newexamupload.submit();
6313: }
6314: }
6315:
6316: function makesmppage() {
1.484.2.61 raeburn 6317: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6318: if (title) {
1.329 droeschl 6319: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6320: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6321: this.document.forms.newsmppg.submit();
6322: }
6323: }
6324:
1.484.2.27 raeburn 6325: function makewebpage(type) {
1.484.2.61 raeburn 6326: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6327: var formname;
6328: if (type == 'supp') {
6329: formname = this.document.forms.supwebpage;
6330: } else {
6331: formname = this.document.forms.newwebpage;
6332: }
6333: if (title) {
6334: var webpage = formname.importdetail.value;
6335: formname.importdetail.value = escape(title)+'='+webpage;
6336: formname.submit();
6337: }
6338: }
6339:
1.329 droeschl 6340: function makesmpproblem() {
1.484.2.61 raeburn 6341: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6342: if (title) {
1.329 droeschl 6343: this.document.forms.newsmpproblem.importdetail.value=
6344: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6345: this.document.forms.newsmpproblem.submit();
6346: }
6347: }
6348:
6349: function makedropbox() {
1.484.2.61 raeburn 6350: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6351: if (title) {
1.329 droeschl 6352: this.document.forms.newdropbox.importdetail.value=
6353: escape(title)+'=/res/lib/templates/DropBox.problem';
6354: this.document.forms.newdropbox.submit();
6355: }
6356: }
6357:
6358: function makebulboard() {
1.484.2.61 raeburn 6359: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6360: if (title) {
6361: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6362: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6363: this.document.forms.newbul.submit();
6364: }
6365: }
6366:
6367: function makeabout() {
1.484.2.61 raeburn 6368: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6369: if (user) {
6370: var comp=new Array();
6371: comp=user.split(':');
6372: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6373: if ((comp[0]) && (comp[1])) {
6374: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6375: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6376: this.document.forms.newaboutsomeone.submit();
6377: } else {
6378: alert("$js_lt{'p_mab_alrt1'}");
6379: }
6380: } else {
6381: alert("$js_lt{'p_mab_alrt2'}");
6382: }
6383: }
1.335 ehlerst 6384: }
1.484.2.67 raeburn 6385:
6386: function makenew(targetform) {
6387: targetform.submit();
1.335 ehlerst 6388: }
1.484.2.67 raeburn 6389:
6390: function changename(folderpath,index,oldtitle) {
6391: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6392: if (title) {
6393: this.document.forms.renameform.markcopy.value='';
6394: this.document.forms.renameform.title.value=title;
6395: this.document.forms.renameform.cmd.value='rename_'+index;
6396: this.document.forms.renameform.folderpath.value=folderpath;
6397: this.document.forms.renameform.submit();
6398: }
1.329 droeschl 6399: }
6400:
1.484.2.67 raeburn 6401: ENDNEWSCRIPT
6402: } else {
6403: $jsmakefunctions = <<ENDNEWSCRIPT;
6404:
6405: function makenewfolder() {
6406: alert("$js_lt{'edri'}");
6407: }
6408:
6409: function makenewpage() {
6410: alert("$js_lt{'edri'}");
6411: }
6412:
6413: function makeexamupload() {
6414: alert("$js_lt{'edri'}");
6415: }
6416:
6417: function makesmppage() {
6418: alert("$js_lt{'edri'}");
6419: }
6420:
6421: function makewebpage(type) {
6422: alert("$js_lt{'edri'}");
6423: }
6424:
6425: function makesmpproblem() {
6426: alert("$js_lt{'edri'}");
6427: }
6428:
6429: function makedropbox() {
6430: alert("$js_lt{'edri'}");
6431: }
6432:
6433: function makebulboard() {
6434: alert("$js_lt{'edri'}");
6435: }
6436:
6437: function makeabout() {
6438: alert("$js_lt{'edri'}");
6439: }
6440:
6441: function changename() {
6442: alert("$js_lt{'edri'}");
6443: }
6444:
6445: function makenew() {
6446: alert("$js_lt{'edri'}");
6447: }
6448:
6449: function groupimport() {
6450: alert("$js_lt{'edri'}");
6451: }
6452:
6453: function groupsearch() {
6454: alert("$js_lt{'edri'}");
6455: }
6456:
6457: function groupopen(url,recover) {
6458: var options="scrollbars=1,resizable=1,menubar=0";
6459: idxflag=1;
6460: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6461: idx.focus();
6462: }
6463:
6464: ENDNEWSCRIPT
6465:
6466: }
6467: return <<ENDSCRIPT;
6468:
6469: $jsmakefunctions
6470:
1.484.2.13 raeburn 6471: function toggleUpload(caller) {
6472: var blocks = Array($fieldsets);
6473: for (var i=0; i<blocks.length; i++) {
6474: var disp = 'none';
6475: if (caller == blocks[i]) {
6476: var curr = document.getElementById('upload'+caller+'form').style.display;
6477: if (curr == 'none') {
6478: disp='block';
6479: }
6480: }
6481: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6482: }
6483: resize_scrollbox('contentscroll','1','1');
6484: return;
6485: }
6486:
1.484.2.19 raeburn 6487: function toggleMap(caller) {
1.484.2.13 raeburn 6488: var disp = 'none';
1.484.2.19 raeburn 6489: if (document.getElementById('importmapform')) {
6490: if (caller == 'map') {
6491: var curr = document.getElementById('importmapform').style.display;
6492: if (curr == 'none') {
6493: disp='block';
6494: }
1.484.2.12 raeburn 6495: }
1.484.2.19 raeburn 6496: document.getElementById('importmapform').style.display=disp;
6497: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6498: }
1.484.2.19 raeburn 6499: return;
1.329 droeschl 6500: }
6501:
1.484.2.12 raeburn 6502: function makeims(imsform) {
6503: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6504: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6505: return;
6506: }
6507: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6508: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6509: return;
6510: }
6511: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6512: imsform.submit();
6513: }
6514:
1.478 raeburn 6515: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6516: var pickitem;
6517: var picknumitem;
6518: var picknumtext;
6519: if (index == 'all') {
6520: pickitem = document.getElementById('randompickall');
6521: picknumitem = document.getElementById('rpicknumall');
6522: picknumtext = document.getElementById('rpicktextall');
6523: } else {
6524: pickitem = document.getElementById('randompick_'+index);
6525: picknumitem = document.getElementById('rpicknum_'+index);
6526: picknumtext = document.getElementById('randompicknum_'+index);
6527: }
1.478 raeburn 6528: if (pickitem.checked) {
1.484.2.61 raeburn 6529: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6530: if (picknum == '' || picknum == null) {
6531: if (caller == 'check') {
6532: pickitem.checked=false;
1.484.2.29 raeburn 6533: if (index == 'all') {
6534: picknumtext.innerHTML = '';
6535: if (caller == 'link') {
6536: propagateState(targetform,'rpicknum');
6537: }
6538: } else {
1.484.2.30 raeburn 6539: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6540: }
1.478 raeburn 6541: }
6542: } else {
6543: picknum.toString();
6544: var regexdigit=/^\\d+\$/;
6545: if (regexdigit.test(picknum)) {
6546: picknumitem.value = picknum;
1.484.2.29 raeburn 6547: if (index == 'all') {
1.484.2.30 raeburn 6548: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6549: if (caller == 'link') {
6550: propagateState(targetform,'rpicknum');
6551: }
6552: } else {
6553: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6554: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6555: }
1.478 raeburn 6556: } else {
6557: if (caller == 'check') {
1.484.2.29 raeburn 6558: if (index == 'all') {
6559: picknumtext.innerHTML = '';
6560: if (caller == 'link') {
6561: propagateState(targetform,'rpicknum');
6562: }
6563: } else {
6564: pickitem.checked=false;
1.484.2.30 raeburn 6565: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6566: }
1.478 raeburn 6567: }
6568: return;
6569: }
6570: }
6571: } else {
1.484.2.29 raeburn 6572: picknumitem.value = '';
6573: picknumtext.innerHTML = '';
6574: if (index == 'all') {
6575: if (caller == 'link') {
6576: propagateState(targetform,'rpicknum');
6577: }
6578: } else {
1.484.2.30 raeburn 6579: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6580: }
6581: }
6582: }
6583:
6584: function propagateState(form,param) {
6585: if (document.getElementById(param+'all')) {
6586: var setcheck = 0;
6587: var rpick = 0;
6588: if (param == 'rpicknum') {
6589: if (document.getElementById('randompickall')) {
6590: if (document.getElementById('randompickall').checked) {
6591: if (document.getElementById('rpicknumall')) {
6592: rpick = document.getElementById('rpicknumall').value;
6593: }
6594: }
6595: }
6596: } else {
6597: if (document.getElementById(param+'all').checked) {
6598: setcheck = 1;
6599: }
6600: }
1.484.2.30 raeburn 6601: var allidxlist;
6602: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6603: if (document.getElementById('all'+param+'idx')) {
6604: allidxlist = document.getElementById('all'+param+'idx').value;
6605: }
6606: var actions = new Array ('remove','cut','copy');
6607: for (var i=0; i<actions.length; i++) {
6608: if (actions[i] != param) {
6609: if (document.getElementById(actions[i]+'all')) {
6610: document.getElementById(actions[i]+'all').checked = false;
6611: }
6612: }
6613: }
6614: }
1.484.2.29 raeburn 6615: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6616: allidxlist = form.allidx.value;
6617: }
6618: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6619: allidxlist = form.allmapidx.value;
6620: }
6621: if ((allidxlist != '') && (allidxlist != null)) {
6622: var allidxs = allidxlist.split(',');
6623: if (allidxs.length > 1) {
6624: for (var i=0; i<allidxs.length; i++) {
6625: if (document.getElementById(param+'_'+allidxs[i])) {
6626: if (param == 'rpicknum') {
6627: if (document.getElementById('randompick_'+allidxs[i])) {
6628: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6629: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6630: if (rpick > 0) {
6631: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6632: } else {
6633: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6634: }
6635: }
6636: }
6637: } else {
1.484.2.29 raeburn 6638: if (setcheck == 1) {
6639: document.getElementById(param+'_'+allidxs[i]).checked = true;
6640: } else {
6641: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6642: if (param == 'randompick') {
6643: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6644: }
1.484.2.29 raeburn 6645: }
6646: }
6647: }
6648: }
1.484.2.30 raeburn 6649: if (setcheck == 1) {
6650: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6651: var actions = new Array('copy','cut','remove');
6652: for (var i=0; i<actions.length; i++) {
6653: var otheractions;
6654: var otheridxs;
6655: if (actions[i] === param) {
6656: continue;
6657: } else {
6658: if (document.getElementById('all'+actions[i]+'idx')) {
6659: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6660: otheridxs = otheractions.split(',');
6661: if (otheridxs.length > 1) {
6662: for (var j=0; j<otheridxs.length; j++) {
6663: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6664: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6665: }
1.484.2.29 raeburn 6666: }
6667: }
6668: }
6669: }
1.484.2.30 raeburn 6670: }
1.484.2.29 raeburn 6671: }
6672: }
6673: }
6674: }
1.478 raeburn 6675: }
1.484.2.29 raeburn 6676: return;
6677: }
6678:
1.484.2.63 raeburn 6679: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 6680: var canedit = '$canedit';
6681: if (canedit == '') {
6682: alert("$js_lt{'edri'}");
6683: return;
6684: }
1.484.2.30 raeburn 6685: var dosettings;
6686: var doaction;
6687: var control = document.togglemultsettings;
6688: if (context == 'actions') {
6689: control = document.togglemultactions;
6690: doaction = 1;
6691: } else {
6692: dosettings = 1;
6693: }
6694: if (control) {
6695: if (control.showmultpick.length) {
6696: for (var i=0; i<control.showmultpick.length; i++) {
6697: if (control.showmultpick[i].checked) {
6698: if (control.showmultpick[i].value == 1) {
6699: if (context == 'settings') {
6700: dosettings = 0;
6701: } else {
6702: doaction = 0;
6703: }
6704: }
6705: }
6706: }
6707: }
6708: }
6709: if (context == 'settings') {
6710: if (dosettings == 1) {
6711: targetform.changeparms.value=param;
6712: targetform.submit();
6713: }
6714: }
6715: if (context == 'actions') {
6716: if (doaction == 1) {
6717: targetform.cmd.value=param+'_'+index;
6718: targetform.folderpath.value=folderpath;
6719: targetform.markcopy.value=idx+':'+param;
6720: targetform.copyfolder.value=folder+'.'+container;
6721: if (param == 'remove') {
1.484.2.63 raeburn 6722: var doremove = 0;
6723: if (skip_confirm) {
6724: if (confirm_removal) {
6725: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
6726: doremove = 1;
6727: }
6728: } else {
6729: doremove = 1;
6730: }
6731: } else {
6732: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
6733: doremove = 1;
6734: }
6735: }
6736: if (doremove) {
1.484.2.30 raeburn 6737: targetform.markcopy.value='';
6738: targetform.copyfolder.value='';
1.484.2.29 raeburn 6739: targetform.submit();
6740: }
6741: }
1.484.2.30 raeburn 6742: if (param == 'cut') {
1.484.2.61 raeburn 6743: 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.484.2.30 raeburn 6744: targetform.submit();
6745: return;
6746: }
6747: }
6748: if (param == 'copy') {
6749: targetform.submit();
6750: return;
6751: }
6752: targetform.markcopy.value='';
6753: targetform.copyfolder.value='';
6754: targetform.cmd.value='';
6755: targetform.folderpath.value='';
6756: return;
6757: } else {
6758: if (document.getElementById(param+'_'+idx)) {
6759: item = document.getElementById(param+'_'+idx);
6760: if (item.type == 'checkbox') {
6761: if (item.checked) {
6762: item.checked = false;
6763: } else {
6764: item.checked = true;
6765: singleCheck(item,idx,param);
6766: }
6767: }
6768: }
6769: }
6770: }
6771: return;
6772: }
6773:
6774: function singleCheck(caller,idx,action) {
6775: actions = new Array('cut','copy','remove');
6776: if (caller.checked) {
6777: for (var i=0; i<actions.length; i++) {
6778: if (actions[i] != action) {
6779: if (document.getElementById(actions[i]+'_'+idx)) {
6780: if (document.getElementById(actions[i]+'_'+idx).checked) {
6781: document.getElementById(actions[i]+'_'+idx).checked = false;
6782: }
6783: }
6784: }
1.484.2.29 raeburn 6785: }
6786: }
6787: return;
1.478 raeburn 6788: }
6789:
1.334 muellerd 6790: function unselectInactive(nav) {
1.335 ehlerst 6791: currentNav = document.getElementById(nav);
6792: currentLis = currentNav.getElementsByTagName('LI');
6793: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 6794: if (currentLis[i].className == 'goback') {
6795: currentLis[i].className = 'goback';
6796: } else {
6797: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 6798: currentLis[i].className = 'right';
1.472 raeburn 6799: } else {
1.374 tempelho 6800: currentLis[i].className = 'i';
1.472 raeburn 6801: }
6802: }
1.335 ehlerst 6803: }
1.332 tempelho 6804: }
6805:
1.334 muellerd 6806: function hideAll(current, nav, data) {
1.335 ehlerst 6807: unselectInactive(nav);
1.484.2.43 raeburn 6808: if (current) {
6809: if (current.className == 'right'){
1.374 tempelho 6810: current.className = 'right active'
1.484.2.43 raeburn 6811: } else {
1.374 tempelho 6812: current.className = 'active';
1.484.2.43 raeburn 6813: }
1.374 tempelho 6814: }
1.335 ehlerst 6815: currentData = document.getElementById(data);
6816: currentDivs = currentData.getElementsByTagName('DIV');
6817: for (i = 0; i < currentDivs.length; i++) {
6818: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 6819: currentDivs[i].style.display = 'none';
1.330 tempelho 6820: }
6821: }
1.335 ehlerst 6822: }
1.330 tempelho 6823:
1.374 tempelho 6824: function openTabs(pageId) {
6825: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 6826: if(tabnav.length > 2 ){
1.389 tempelho 6827: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 6828: currentLis = currentNav.getElementsByTagName('LI');
6829: for(i = 0; i< currentLis.length; i++){
6830: if(currentLis[i].className == 'active') {
1.375 tempelho 6831: funcString = currentLis[i].onclick.toString();
6832: tab = funcString.split('"');
1.420 onken 6833: if(tab.length < 2) {
6834: tab = funcString.split("'");
6835: }
1.375 tempelho 6836: currentData = document.getElementById(tab[1]);
6837: currentData.style.display = 'block';
1.374 tempelho 6838: }
6839: }
6840: }
6841: }
6842:
1.334 muellerd 6843: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 6844: currstate = current.className;
1.334 muellerd 6845: hideAll(current, nav, data);
1.375 tempelho 6846: openTabs(pageId);
1.334 muellerd 6847: unselectInactive(nav);
1.484.2.43 raeburn 6848: if ((currstate == 'active') || (currstate == 'right active')) {
6849: if (currstate == 'active') {
6850: current.className = '';
6851: } else {
6852: current.className = 'right';
6853: }
6854: activeTab = '';
6855: toggleUpload();
6856: toggleMap();
6857: resize_scrollbox('contentscroll','1','0');
6858: return;
6859: } else {
6860: current.className = 'active';
6861: }
1.330 tempelho 6862: currentData = document.getElementById(pageId);
6863: currentData.style.display = 'block';
1.458 raeburn 6864: activeTab = pageId;
1.484.2.12 raeburn 6865: toggleUpload();
1.484.2.14 raeburn 6866: toggleMap();
1.433 raeburn 6867: if (nav == 'mainnav') {
6868: var storedpath = "$docs_folderpath";
1.434 raeburn 6869: var storedpage = "$main_container_page";
1.433 raeburn 6870: var reg = new RegExp("^supplemental");
6871: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 6872: if (storedpage == 1) {
6873: document.simpleedit.folderpath.value = '';
6874: document.uploaddocument.folderpath.value = '';
6875: } else {
6876: if (reg.test(storedpath)) {
6877: document.simpleedit.folderpath.value = '$toplevelmain';
6878: document.uploaddocument.folderpath.value = '$toplevelmain';
6879: document.newext.folderpath.value = '$toplevelmain';
6880: } else {
6881: document.simpleedit.folderpath.value = storedpath;
6882: document.uploaddocument.folderpath.value = storedpath;
6883: document.newext.folderpath.value = storedpath;
6884: }
1.433 raeburn 6885: }
6886: } else {
1.434 raeburn 6887: if (reg.test(storedpath)) {
6888: document.simpleedit.folderpath.value = storedpath;
6889: document.supuploaddocument.folderpath.value = storedpath;
6890: document.supnewext.folderpath.value = storedpath;
6891: } else {
1.433 raeburn 6892: document.simpleedit.folderpath.value = '$toplevelsupp';
6893: document.supuploaddocument.folderpath.value = '$toplevelsupp';
6894: document.supnewext.folderpath.value = '$toplevelsupp';
6895: }
6896: }
6897: }
1.484.2.3 raeburn 6898: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 6899: return false;
6900: }
1.329 droeschl 6901:
1.472 raeburn 6902: function toContents(jumpto) {
6903: var newurl = '$backtourl';
1.484.2.21 raeburn 6904: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 6905: newurl = newurl+'?postdata='+jumpto;
6906: }
6907: location.href=newurl;
6908: }
6909:
1.484.2.30 raeburn 6910: function togglePick(caller,value) {
6911: var disp = 'none';
6912: if (document.getElementById('multi'+caller)) {
6913: var curr = document.getElementById('multi'+caller).style.display;
6914: if (value == 1) {
6915: disp='block';
6916: }
6917: if (curr == disp) {
6918: return;
6919: }
6920: document.getElementById('multi'+caller).style.display=disp;
6921: if (value == 1) {
1.484.2.61 raeburn 6922: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 6923: } else {
6924: document.getElementById('more'+caller).innerHTML = '';
6925: }
6926: if (caller == 'actions') {
6927: setClass(value);
6928: setBoxes(value);
6929: }
6930: }
6931: var showButton = multiSettings();
6932: if (showButton != 1) {
6933: showButton = multiActions();
6934: }
6935: if (document.getElementById('multisave')) {
6936: if (showButton == 1) {
6937: document.getElementById('multisave').style.display='block';
6938: } else {
6939: document.getElementById('multisave').style.display='none';
6940: }
6941: }
6942: resize_scrollbox('contentscroll','1','1');
6943: return;
6944: }
6945:
6946: function toggleCheckUncheck(caller,more) {
6947: if (more == 1) {
1.484.2.61 raeburn 6948: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 6949: document.getElementById('allfields'+caller).style.display='block';
6950: } else {
1.484.2.61 raeburn 6951: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 6952: document.getElementById('allfields'+caller).style.display='none';
6953: }
6954: resize_scrollbox('contentscroll','1','1');
6955: }
6956:
6957: function multiSettings() {
6958: var inuse = 0;
6959: var settingsform = document.togglemultsettings;
6960: if (settingsform.showmultpick.length > 1) {
6961: for (var i=0; i<settingsform.showmultpick.length; i++) {
6962: if (settingsform.showmultpick[i].checked) {
6963: if (settingsform.showmultpick[i].value == 1) {
6964: inuse = 1;
6965: }
6966: }
6967: }
6968: }
6969: return inuse;
6970: }
6971:
6972: function multiActions() {
6973: var inuse = 0;
6974: var actionsform = document.togglemultactions;
6975: if (actionsform.showmultpick.length > 1) {
6976: for (var i=0; i<actionsform.showmultpick.length; i++) {
6977: if (actionsform.showmultpick[i].checked) {
6978: if (actionsform.showmultpick[i].value == 1) {
6979: inuse = 1;
6980: }
6981: }
6982: }
6983: }
6984: return inuse;
6985: }
6986:
6987: function checkSubmits() {
6988: var numchanges = 0;
6989: var form = document.saveactions;
6990: var doactions = multiActions();
6991: var cutwarnings = 0;
6992: var remwarnings = 0;
1.484.2.63 raeburn 6993: var removalinfo = 0;
1.484.2.30 raeburn 6994: if (doactions == 1) {
6995: var remidxlist = document.cumulativeactions.allremoveidx.value;
6996: if ((remidxlist != '') && (remidxlist != null)) {
6997: var remidxs = remidxlist.split(',');
6998: for (var i=0; i<remidxs.length; i++) {
6999: if (document.getElementById('remove_'+remidxs[i])) {
7000: if (document.getElementById('remove_'+remidxs[i]).checked) {
7001: form.multiremove.value += remidxs[i]+',';
7002: numchanges ++;
7003: if (document.getElementById('skip_remove_'+remidxs[i])) {
7004: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7005: remwarnings ++;
7006: }
7007: }
1.484.2.63 raeburn 7008: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7009: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7010: removalinfo ++;
7011: }
7012: }
1.484.2.30 raeburn 7013: }
7014: }
7015: }
7016: }
7017: var cutidxlist = document.cumulativeactions.allcutidx.value;
7018: if ((cutidxlist != '') && (cutidxlist != null)) {
7019: var cutidxs = cutidxlist.split(',');
7020: for (var i=0; i<cutidxs.length; i++) {
7021: if (document.getElementById('cut_'+cutidxs[i])) {
7022: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7023: form.multicut.value += cutidxs[i]+',';
7024: numchanges ++;
7025: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7026: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7027: cutwarnings ++;
7028: }
7029: }
7030: }
7031: }
7032: }
7033: }
7034: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7035: if ((copyidxlist != '') && (copyidxlist != null)) {
7036: var copyidxs = copyidxlist.split(',');
7037: for (var i=0; i<copyidxs.length; i++) {
7038: if (document.getElementById('copy_'+copyidxs[i])) {
7039: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7040: form.multicopy.value += copyidxs[i]+',';
7041: numchanges ++;
7042: }
7043: }
7044: }
7045: }
7046: if (numchanges > 0) {
7047: form.multichange.value = numchanges;
7048: }
7049: }
7050: var dosettings = multiSettings();
7051: var haschanges = 0;
7052: if (dosettings == 1) {
7053: form.allencrypturl.value = '';
7054: form.allhiddenresource.value = '';
7055: form.changeparms.value = 'all';
7056: var patt=new RegExp(",\$");
7057: var allidxlist = document.cumulativesettings.allidx.value;
7058: if ((allidxlist != '') && (allidxlist != null)) {
7059: var allidxs = allidxlist.split(',');
7060: if (allidxs.length > 1) {
7061: for (var i=0; i<allidxs.length; i++) {
7062: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7063: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7064: form.allhiddenresource.value += allidxs[i]+',';
7065: }
7066: }
7067: if (document.getElementById('encrypturl_'+allidxs[i])) {
7068: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7069: form.allencrypturl.value += allidxs[i]+',';
7070: }
1.484.2.29 raeburn 7071: }
7072: }
1.484.2.30 raeburn 7073: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7074: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7075: }
7076: }
7077: form.allrandompick.value = '';
7078: form.allrandomorder.value = '';
7079: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7080: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7081: var allmapidxs = allmapidxlist.split(',');
7082: for (var i=0; i<allmapidxs.length; i++) {
7083: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7084: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7085: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7086: if ((randompick.checked) && (rpicknum.value != '')) {
7087: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7088: }
7089: if (randorder.checked) {
7090: form.allrandomorder.value += allmapidxs[i]+',';
7091: }
7092: }
7093: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7094: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7095: }
7096: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7097: haschanges = 1;
7098: }
7099: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7100: haschanges = 1;
7101: }
7102: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7103: haschanges = 1;
7104: }
7105: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7106: haschanges = 1;
7107: }
7108: }
7109: if (doactions == 1) {
7110: if (numchanges > 0) {
1.484.2.63 raeburn 7111: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7112: if (remwarnings > 0) {
1.484.2.61 raeburn 7113: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7114: return false;
7115: }
7116: }
1.484.2.63 raeburn 7117: if (removalinfo > 0) {
7118: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7119: return false;
7120: }
7121: }
1.484.2.30 raeburn 7122: if (cutwarnings > 0) {
1.484.2.61 raeburn 7123: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
1.484.2.30 raeburn 7124: return false;
1.484.2.29 raeburn 7125: }
7126: }
7127: }
1.484.2.30 raeburn 7128: form.submit();
7129: return true;
7130: }
7131: }
7132: if (dosettings == 1) {
7133: if (haschanges == 1) {
7134: form.submit();
7135: return true;
1.484.2.29 raeburn 7136: }
7137: }
1.484.2.30 raeburn 7138: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7139: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7140: } else {
7141: if (dosettings == 1) {
1.484.2.61 raeburn 7142: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7143: } else {
1.484.2.61 raeburn 7144: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7145: }
7146: }
7147: return false;
7148: }
7149:
7150: function setClass(value) {
7151: var cutclass = 'LC_docs_cut';
7152: var copyclass = 'LC_docs_copy';
7153: var removeclass = 'LC_docs_remove';
7154: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7155: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7156: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7157: var links = document.getElementsByTagName('a');
7158: for (var i=0; i<links.length; i++) {
7159: var classes = links[i].className;
7160: if (cutreg.test(classes)) {
7161: links[i].className = cutclass;
7162: if (value == 1) {
7163: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7164: }
1.484.2.30 raeburn 7165: } else {
7166: if (copyreg.test(classes)) {
7167: links[i].className = copyclass;
7168: if (value == 1) {
7169: links[i].className += " LC_menubuttons_link";
7170: }
7171: } else {
7172: if (removereg.test(classes)) {
7173: links[i].className = removeclass;
7174: if (value == 1) {
7175: links[i].className += " LC_menubuttons_link";
7176: }
7177: }
1.484.2.29 raeburn 7178: }
7179: }
7180: }
1.484.2.30 raeburn 7181: return;
1.484.2.29 raeburn 7182: }
7183:
1.484.2.30 raeburn 7184: function setBoxes(value) {
7185: var remidxlist = document.cumulativeactions.allremoveidx.value;
7186: if ((remidxlist != '') && (remidxlist != null)) {
7187: var remidxs = remidxlist.split(',');
7188: for (var i=0; i<remidxs.length; i++) {
7189: if (document.getElementById('remove_'+remidxs[i])) {
7190: var item = document.getElementById('remove_'+remidxs[i]);
7191: if (value == 1) {
7192: item.className = 'LC_docs_remove';
7193: } else {
7194: item.className = 'LC_hidden';
7195: }
7196: }
1.484.2.29 raeburn 7197: }
7198: }
1.484.2.30 raeburn 7199: var cutidxlist = document.cumulativeactions.allcutidx.value;
7200: if ((cutidxlist != '') && (cutidxlist != null)) {
7201: var cutidxs = cutidxlist.split(',');
7202: for (var i=0; i<cutidxs.length; i++) {
7203: if (document.getElementById('cut_'+cutidxs[i])) {
7204: var item = document.getElementById('cut_'+cutidxs[i]);
7205: if (value == 1) {
7206: item.className = 'LC_docs_cut';
7207: } else {
7208: item.className = 'LC_hidden';
7209: }
7210: }
7211: }
7212: }
7213: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7214: if ((copyidxlist != '') && (copyidxlist != null)) {
7215: var copyidxs = copyidxlist.split(',');
7216: for (var i=0; i<copyidxs.length; i++) {
7217: if (document.getElementById('copy_'+copyidxs[i])) {
7218: var item = document.getElementById('copy_'+copyidxs[i]);
7219: if (value == 1) {
7220: item.className = 'LC_docs_copy';
7221: } else {
7222: item.className = 'LC_hidden';
7223: }
7224: }
1.484.2.29 raeburn 7225: }
7226: }
7227: return;
7228: }
7229:
1.484.2.67 raeburn 7230: ENDSCRIPT
1.329 droeschl 7231: }
1.457 raeburn 7232:
1.483 raeburn 7233: sub history_tab_js {
7234: return <<"ENDHIST";
7235: function toggleHistoryDisp(choice) {
7236: document.docslogform.docslog.value = choice;
7237: document.docslogform.submit();
7238: return;
7239: }
7240:
7241: ENDHIST
7242: }
7243:
1.484 raeburn 7244: sub inject_data_js {
7245: return <<ENDINJECT;
7246:
7247: function injectData(current, hiddenField, name, value) {
7248: currentElement = document.getElementById(hiddenField);
7249: currentElement.name = name;
7250: currentElement.value = value;
7251: current.submit();
7252: }
7253:
7254: ENDINJECT
7255: }
7256:
7257: sub dump_switchserver_js {
7258: my @hosts = @_;
1.484.2.61 raeburn 7259: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7260: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7261: swit => 'Switch server?',
1.484.2.61 raeburn 7262: );
7263: my %html_js_lt = &Apache::lonlocal::texthash(
7264: swit => 'Switch server?',
1.484.2.43 raeburn 7265: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7266: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7267: chos => 'Choose server',
7268: );
1.484.2.61 raeburn 7269: &js_escape(\%js_lt);
7270: &html_escape(\%html_js_lt);
7271: &js_escape(\%html_js_lt);
1.484 raeburn 7272: my $role = $env{'request.role'};
7273: my $js = <<"ENDSWJS";
7274: <script type="text/javascript">
7275: function write_switchserver() {
7276: var server;
7277: if (document.setserver.posshosts.length > 0) {
7278: for (var i=0; i<document.setserver.posshosts.length; i++) {
7279: if (document.setserver.posshosts[i].checked) {
7280: server = document.setserver.posshosts[i].value;
7281: }
7282: }
7283: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7284: }
7285: window.close();
7286: }
7287: </script>
7288:
7289: ENDSWJS
7290:
7291: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7292: {'only_body' => 1,
7293: 'js_ready' => 1,});
7294: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7295:
7296: my $hostpicker;
7297: my $count = 0;
7298: foreach my $host (sort(@hosts)) {
7299: my $checked;
7300: if ($count == 0) {
7301: $checked = ' checked="checked"';
7302: }
7303: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7304: $host.'"'.$checked.' />'.$host.'</label> ';
7305: $count++;
7306: }
7307:
7308: return <<"ENDSWITCHJS";
7309:
7310: function dump_needs_switchserver(url) {
7311: if (url!='' && url!= null) {
1.484.2.61 raeburn 7312: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7313: go(url);
7314: }
7315: }
7316: return;
7317: }
7318:
7319: function choose_switchserver_window() {
7320: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7321: newWindow.document.open();
7322: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7323: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7324: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7325: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7326: '<form name="setserver" method="post" action="" \\/>\\n'+
7327: '$hostpicker\\n'+
7328: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7329: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7330: 'onclick="write_switchserver();" \\/>\\n'+
7331: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7332: newWindow.document.writeln('$endpage');
7333: newWindow.document.close();
7334: newWindow.focus();
7335: }
7336:
7337: ENDSWITCHJS
7338: }
7339:
7340: sub makedocslogform {
7341: my ($formelems,$docslog) = @_;
7342: return <<"LOGSFORM";
7343: <form action="/adm/coursedocs" method="post" name="docslogform">
7344: <input type="hidden" name="docslog" value="$docslog" />
7345: $formelems
7346: </form>
7347: LOGSFORM
7348: }
7349:
7350: sub makesimpleeditform {
7351: my ($formelems) = @_;
7352: return <<"SIMPFORM";
7353: <form name="simpleedit" method="post" action="/adm/coursedocs">
7354: <input type="hidden" name="importdetail" value="" />
7355: $formelems
7356: </form>
7357: SIMPFORM
7358: }
7359:
1.329 droeschl 7360: 1;
7361: __END__
7362:
7363:
7364: =head1 NAME
7365:
7366: Apache::londocs.pm
7367:
7368: =head1 SYNOPSIS
7369:
7370: This is part of the LearningOnline Network with CAPA project
7371: described at http://www.lon-capa.org.
7372:
7373: =head1 SUBROUTINES
7374:
7375: =over
7376:
7377: =item %help=()
7378:
7379: Available help topics
7380:
7381: =item mapread()
7382:
1.344 bisitz 7383: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7384: @order and @resources, determines status
7385: sets @order - pointer to resources in right order
7386: sets @resources - array with the resources with correct idx
7387:
7388: =item authorhosts()
7389:
7390: Return hash with valid author names
7391:
7392: =item clean()
7393:
7394: =item dumpcourse()
7395:
7396: Actually dump course
7397:
7398: =item group_import()
7399:
7400: Imports the given (name, url) resources into the course
7401: coursenum, coursedom, and folder must precede the list
7402:
7403: =item breadcrumbs()
7404:
7405: =item log_docs()
7406:
7407: =item docs_change_log()
7408:
7409: =item update_paste_buffer()
7410:
7411: =item print_paste_buffer()
7412:
7413: =item do_paste_from_buffer()
7414:
1.484.2.30 raeburn 7415: =item do_buffer_empty()
7416:
7417: =item clear_from_buffer()
7418:
1.484.2.7 raeburn 7419: =item get_newmap_url()
7420:
7421: =item dbcopy()
7422:
7423: =item uniqueness_check()
7424:
7425: =item contained_map_check()
7426:
7427: =item url_paste_fixups()
7428:
7429: =item apply_fixups()
7430:
7431: =item copy_dependencies()
7432:
1.329 droeschl 7433: =item update_parameter()
7434:
7435: =item handle_edit_cmd()
7436:
7437: =item editor()
7438:
7439: =item process_file_upload()
7440:
7441: =item process_secondary_uploads()
7442:
7443: =item is_supplemental_title()
7444:
7445: =item entryline()
7446:
7447: =item tiehash()
7448:
7449: =item untiehash()
7450:
7451: =item checkonthis()
7452:
7453: check on this
7454:
7455: =item verifycontent()
7456:
7457: Verify Content
7458:
7459: =item devalidateversioncache() & checkversions()
7460:
7461: Check Versions
7462:
7463: =item mark_hash_old()
7464:
7465: =item is_hash_old()
7466:
7467: =item changewarning()
7468:
7469: =item init_breadcrumbs()
7470:
7471: Breadcrumbs for special functions
7472:
1.484 raeburn 7473: =item create_list_elements()
7474:
7475: =item create_form_ul()
7476:
7477: =item startContentScreen()
7478:
7479: =item endContentScreen()
7480:
7481: =item supplemental_base()
7482:
7483: =item embedded_form_elems()
7484:
7485: =item embedded_destination()
7486:
7487: =item return_to_editor()
7488:
7489: =item decompression_info()
7490:
7491: =item decompression_phase_one()
7492:
7493: =item decompression_phase_two()
7494:
7495: =item remove_archive()
7496:
7497: =item generate_admin_menu()
7498:
7499: =item generate_edit_table()
7500:
7501: =item editing_js()
7502:
7503: =item history_tab_js()
7504:
7505: =item inject_data_js()
7506:
7507: =item dump_switchserver_js()
7508:
1.484.2.3 raeburn 7509: =item resize_scrollbox_js()
1.484 raeburn 7510:
7511: =item makedocslogform()
7512:
1.484.2.3 raeburn 7513: =item makesimpleeditform()
7514:
1.329 droeschl 7515: =back
7516:
7517: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>