Annotation of loncom/interface/londocs.pm, revision 1.484.2.77
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.77! raeburn 4: # $Id: londocs.pm,v 1.484.2.76 2018/01/27 03:46:52 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.77! raeburn 2466: my $total = scalar(@LONCAPA::map::order) - 1;
! 2467: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2468: my $idx = $LONCAPA::map::order[$i];
2469: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2470: my $changed;
1.484.2.23 raeburn 2471: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2472: if ((exists($toremove{$idx})) &&
2473: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2474: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2475: if (ref($currparam{$idx}) eq 'ARRAY') {
2476: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77! raeburn 2477: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2478: }
2479: }
2480: next;
2481: }
2482: my $origsrc = $src;
1.484.2.25 raeburn 2483: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2484: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2485: $changed = 1;
2486: }
2487: }
1.484.2.25 raeburn 2488: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2489: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2490: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2491: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2492: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2493: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2494: } else {
1.484.2.23 raeburn 2495: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2496: }
2497: }
1.484.2.25 raeburn 2498: if ($origsrc =~ /\.(page|sequence)$/) {
2499: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2500: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2501: }
1.484.2.25 raeburn 2502: } elsif ($newsubdir{$key}) {
2503: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2504: }
2505: }
2506: $changed = 1;
1.484.2.26 raeburn 2507: } elsif ($newdb{$idx} ne '') {
2508: $src = $newdb{$idx};
1.484.2.7 raeburn 2509: $changed = 1;
2510: }
2511: if ($changed) {
1.484.2.30 raeburn 2512: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2513: }
2514: }
2515: }
2516: foreach my $idx (keys(%remparam)) {
2517: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2518: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77! raeburn 2519: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2520: }
2521: }
2522: }
1.484.2.26 raeburn 2523: if (values(%lockerrors) > 0) {
2524: $lockmsg = join('<br />',values(%lockerrors));
2525: }
1.484.2.7 raeburn 2526: my $storefn;
2527: if ($key eq $oldurl) {
2528: $storefn = $url;
2529: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2530: } else {
2531: $storefn = $key;
2532: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2533: if ($prefixchg && $before{'map'} && $after{'map'}) {
2534: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2535: }
1.484.2.23 raeburn 2536: if ($newsubdir{$key}) {
2537: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2538: }
2539: }
2540: my $report;
2541: if ($folder !~ /^supplemental/) {
2542: $report = 1;
2543: }
1.484.2.20 raeburn 2544: (my $outtext,$errtext) =
1.484.2.7 raeburn 2545: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2546: if ($errtext) {
1.484.2.23 raeburn 2547: if ($caller eq 'paste') {
1.484.2.26 raeburn 2548: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2549: }
1.484.2.7 raeburn 2550: }
2551: }
2552: }
1.484.2.26 raeburn 2553: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2554: }
2555:
2556: sub copy_dependencies {
2557: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2558: my $content;
2559: if (ref($contentref)) {
2560: $content = $$contentref;
2561: } else {
2562: $content = &Apache::lonnet::getfile($item);
2563: }
2564: unless ($content eq '-1') {
2565: my $mm = new File::MMagic;
2566: my $mimetype = $mm->checktype_contents($content);
2567: if ($mimetype eq 'text/html') {
2568: my (%allfiles,%codebase,$state);
2569: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2570: if ($res eq 'ok') {
2571: my ($numexisting,$numpathchanges,$existing);
2572: (undef,$numexisting,$numpathchanges,$existing) =
2573: &Apache::loncommon::ask_for_embedded_content(
2574: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2575: {'error_on_invalid_names' => 1,
2576: 'ignore_remote_references' => 1,
2577: 'docs_url' => $item,
2578: 'context' => 'paste'});
2579: if ($numexisting > 0) {
2580: if (ref($existing) eq 'HASH') {
2581: foreach my $dep (keys(%{$existing})) {
2582: my $depfile = $dep;
2583: unless ($depfile =~ m{^\Q$relpath\E}) {
2584: $depfile = $relpath.$dep;
2585: }
2586: my $depcontent = &Apache::lonnet::getfile($depfile);
2587: unless ($depcontent eq '-1') {
2588: my $storedep = $dep;
2589: $storedep =~ s{^\Q$relpath\E}{};
2590: my $dep_url =
2591: &Apache::lonclonecourse::writefile(
2592: $env{'request.course.id'},
2593: $storefn.$storedep,$depcontent);
2594: if ($dep_url eq '/adm/notfound.html') {
2595: if (ref($errors) eq 'HASH') {
2596: $errors->{$depfile} = 1;
2597: }
2598: } else {
2599: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2600: }
2601: }
2602: }
2603: }
2604: }
2605: }
2606: }
2607: }
2608: return;
2609: }
2610:
1.329 droeschl 2611: my %parameter_type = ( 'randompick' => 'int_pos',
2612: 'hiddenresource' => 'string_yesno',
2613: 'encrypturl' => 'string_yesno',
2614: 'randomorder' => 'string_yesno',);
2615: my $valid_parameters_re = join('|',keys(%parameter_type));
2616: # set parameters
2617: sub update_parameter {
1.484.2.29 raeburn 2618: if ($env{'form.changeparms'} eq 'all') {
2619: my (@allidx,@allmapidx,%allchecked,%currchecked);
2620: %allchecked = (
2621: 'hiddenresource' => {},
2622: 'encrypturl' => {},
2623: 'randompick' => {},
2624: 'randomorder' => {},
2625: );
2626: foreach my $which (keys(%allchecked)) {
2627: $env{'form.all'.$which} =~ s/,$//;
2628: if ($which eq 'randompick') {
2629: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2630: my ($res,$value) = split(/:/,$item);
2631: if ($value =~ /^\d+$/) {
2632: $allchecked{$which}{$res} = $value;
2633: }
2634: }
2635: } else {
1.484.2.30 raeburn 2636: if ($env{'form.all'.$which}) {
2637: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2638: }
1.484.2.29 raeburn 2639: }
2640: }
2641: my $haschanges = 0;
2642: foreach my $res (@LONCAPA::map::order) {
2643: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2644: $name=&LONCAPA::map::qtescape($name);
2645: $url=&LONCAPA::map::qtescape($url);
2646: next unless ($name && $url);
2647: my $is_map;
2648: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2649: $is_map = 1;
2650: }
2651: foreach my $which (keys(%allchecked)) {
2652: if (($which eq 'randompick' || $which eq 'randomorder')) {
2653: next if (!$is_map);
2654: }
2655: my $oldvalue = 0;
2656: my $newvalue = 0;
2657: if ($allchecked{$which}{$res}) {
2658: $newvalue = $allchecked{$which}{$res};
2659: }
2660: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2661: if ($which eq 'randompick') {
2662: if ($current =~ /^(\d+)$/) {
2663: $oldvalue = $1;
2664: }
2665: } else {
2666: if ($current =~ /^yes$/i) {
2667: $oldvalue = 1;
2668: }
2669: }
2670: if ($oldvalue ne $newvalue) {
2671: $haschanges = 1;
2672: if ($newvalue) {
2673: my $storeval = 'yes';
2674: if ($which eq 'randompick') {
2675: $storeval = $newvalue;
2676: }
2677: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2678: $storeval,
2679: $parameter_type{$which});
2680: &remember_parms($res,$which,'set',$storeval);
2681: } elsif ($oldvalue) {
2682: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2683: &remember_parms($res,$which,'del');
2684: }
2685: }
2686: }
2687: }
2688: return $haschanges;
1.329 droeschl 2689: } else {
1.484.2.59 raeburn 2690: my $haschanges = 0;
2691: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 2692:
1.484.2.29 raeburn 2693: my $which = $env{'form.changeparms'};
2694: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 2695: my $oldvalue = 0;
2696: my $newvalue = 0;
2697: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2698: if ($which eq 'randompick') {
2699: if ($current =~ /^(\d+)$/) {
2700: $oldvalue = $1;
2701: }
2702: } elsif ($current =~ /^yes$/i) {
2703: $oldvalue = 1;
2704: }
1.484.2.29 raeburn 2705: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 2706: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2707: : 1;
1.484.2.29 raeburn 2708: }
1.484.2.59 raeburn 2709: if ($oldvalue ne $newvalue) {
2710: $haschanges = 1;
2711: if ($newvalue) {
2712: my $storeval = 'yes';
2713: if ($which eq 'randompick') {
2714: $storeval = $newvalue;
2715: }
2716: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2717: $parameter_type{$which});
2718: &remember_parms($idx,$which,'set',$storeval);
2719: } else {
2720: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2721: &remember_parms($idx,$which,'del');
2722: }
2723: }
2724: return $haschanges;
1.329 droeschl 2725: }
1.484.2.59 raeburn 2726: return;
1.329 droeschl 2727: }
2728:
2729: sub handle_edit_cmd {
2730: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 2731: if ($env{'form.cmd'} eq '') {
2732: return 0;
2733: }
1.329 droeschl 2734: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2735:
2736: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2737: my ($title, $url, @rrest) = split(':', $ratstr);
2738:
1.484.2.30 raeburn 2739: if ($cmd eq 'remove') {
1.329 droeschl 2740: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2741: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2742: &Apache::lonnet::removeuploadedurl($url);
2743: } else {
2744: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2745: }
2746: splice(@LONCAPA::map::order, $idx, 1);
2747:
2748: } elsif ($cmd eq 'cut') {
2749: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2750: splice(@LONCAPA::map::order, $idx, 1);
2751:
1.344 bisitz 2752: } elsif ($cmd eq 'up'
1.329 droeschl 2753: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2754: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2755:
2756: } elsif ($cmd eq 'down'
2757: && defined($LONCAPA::map::order[$idx+1])) {
2758: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2759:
2760: } elsif ($cmd eq 'rename') {
2761: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2762: if ($comment=~/\S/) {
2763: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2764: $comment.':'.join(':', $url, @rrest);
2765: }
2766: # Devalidate title cache
2767: my $renamed_url=&LONCAPA::map::qtescape($url);
2768: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 2769:
1.329 droeschl 2770: } else {
2771: return 0;
2772: }
2773: return 1;
2774: }
2775:
2776: sub editor {
1.458 raeburn 2777: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.67 raeburn 2778: $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,$navmapref,
2779: $hiddentop)=@_;
1.484.2.19 raeburn 2780: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2781: if ($allowed) {
2782: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2783: $is_random_order,$container) =
2784: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2785: $r->print($breadcrumbtrail);
2786: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2787: $container = 'page';
2788: } else {
2789: $container = 'sequence';
2790: }
1.484 raeburn 2791:
1.484.2.21 raeburn 2792: my $jumpto;
2793:
2794: unless ($supplementalflag) {
1.484.2.32 raeburn 2795: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 2796: }
1.484 raeburn 2797:
2798: unless ($allowed) {
2799: $randompick = -1;
2800: }
2801:
1.484.2.67 raeburn 2802: my ($errtext,$fatal);
2803: if (($folder eq '') && (!$supplementalflag)) {
2804: if (@LONCAPA::map::order) {
2805: undef(@LONCAPA::map::order);
2806: undef(@LONCAPA::map::resources);
2807: undef(@LONCAPA::map::resparms);
2808: undef(@LONCAPA::map::zombies);
2809: }
2810: $folder = 'default';
2811: $container = 'sequence';
2812: } else {
2813: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2814: $folder.'.'.$container);
2815: return $errtext if ($fatal);
2816: }
1.329 droeschl 2817:
2818: if ($#LONCAPA::map::order<1) {
2819: my $idx=&LONCAPA::map::getresidx();
2820: if ($idx<=0) { $idx=1; }
2821: $LONCAPA::map::order[0]=$idx;
2822: $LONCAPA::map::resources[$idx]='';
2823: }
1.364 bisitz 2824:
1.329 droeschl 2825: # ------------------------------------------------------------ Process commands
2826:
2827: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 2828: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 2829: # set parameters and change order
2830: &snapshotbefore();
2831:
2832: if (&update_parameter()) {
1.484.2.59 raeburn 2833: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 2834: return $errtext if ($fatal);
2835: }
2836:
2837: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2838: # change order
2839: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
2840: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
2841:
2842: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2843: return $errtext if ($fatal);
2844: }
1.364 bisitz 2845:
1.329 droeschl 2846: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 2847: my %paste_errors;
1.484.2.26 raeburn 2848: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 2849: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
2850: \%paste_errors);
1.484.2.30 raeburn 2851: if (ref($pastemsgarray) eq 'ARRAY') {
2852: if (@{$pastemsgarray} > 0) {
2853: $r->print('<p class="LC_info">'.
2854: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 2855: '</p>');
2856: }
1.484.2.30 raeburn 2857: }
2858: if ($lockerror) {
2859: $r->print('<p class="LC_error">'.
2860: $lockerror.
2861: '</p>');
2862: }
2863: if ($save_error ne '') {
2864: return $save_error;
2865: }
2866: if ($paste_res) {
2867: my %errortext = &Apache::lonlocal::texthash (
2868: fail => 'Storage of folder contents failed',
2869: failread => 'Reading folder contents failed',
2870: failstore => 'Storage of folder contents failed',
2871: );
2872: if ($errortext{$paste_res}) {
2873: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 2874: }
1.329 droeschl 2875: }
1.484.2.7 raeburn 2876: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 2877: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 2878: &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".
2879: '<ul>'."\n");
2880: foreach my $key (sort(keys(%paste_errors))) {
2881: $r->print('<li>'.$key.'</li>'."\n");
2882: }
2883: $r->print('</ul></p>'."\n");
2884: }
1.484.2.30 raeburn 2885: } elsif ($env{'form.clearmarked'}) {
2886: my $output = &do_buffer_empty();
2887: if ($output) {
2888: $r->print('<p class="LC_info">'.$output.'</p>');
2889: }
2890: }
1.329 droeschl 2891:
2892: $r->print($upload_output);
2893:
1.484.2.30 raeburn 2894: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 2895: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 2896: my $contentchg;
1.484.2.58 raeburn 2897: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 2898: $contentchg = 1;
2899: }
2900: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 2901: return $errtext if ($fatal);
2902: }
1.484.2.30 raeburn 2903:
2904: # Cut, copy and/or remove multiple resources
2905: if ($env{'form.multichange'}) {
2906: my %allchecked = (
2907: cut => {},
2908: remove => {},
2909: );
2910: my $needsupdate;
2911: foreach my $which (keys(%allchecked)) {
2912: $env{'form.multi'.$which} =~ s/,$//;
2913: if ($env{'form.multi'.$which}) {
2914: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
2915: if (ref($allchecked{$which}) eq 'HASH') {
2916: $needsupdate += scalar(keys(%{$allchecked{$which}}));
2917: }
2918: }
2919: }
2920: if ($needsupdate) {
2921: my $haschanges = 0;
2922: my %curr_groups = &Apache::longroup::coursegroups();
2923: my $total = scalar(@LONCAPA::map::order) - 1;
2924: for (my $i=$total; $i>=0; $i--) {
2925: my $res = $LONCAPA::map::order[$i];
2926: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2927: $name=&LONCAPA::map::qtescape($name);
2928: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 2929: next unless $url;
1.484.2.30 raeburn 2930: my %denied =
2931: &action_restrictions($coursenum,$coursedom,$url,
2932: $env{'form.folderpath'},\%curr_groups);
2933: foreach my $which (keys(%allchecked)) {
2934: next if ($denied{$which});
2935: next unless ($allchecked{$which}{$res});
2936: if ($which eq 'remove') {
2937: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
2938: ($url!~/$LONCAPA::assess_page_seq_re/)) {
2939: &Apache::lonnet::removeuploadedurl($url);
2940: } else {
2941: &LONCAPA::map::makezombie($res);
2942: }
2943: splice(@LONCAPA::map::order,$i,1);
2944: $haschanges ++;
2945: } elsif ($which eq 'cut') {
2946: &LONCAPA::map::makezombie($res);
2947: splice(@LONCAPA::map::order,$i,1);
2948: $haschanges ++;
2949: }
2950: }
2951: }
2952: if ($haschanges) {
2953: ($errtext,$fatal) =
2954: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2955: return $errtext if ($fatal);
2956: }
2957: }
2958: }
2959:
1.329 droeschl 2960: # Group import/search
2961: if ($env{'form.importdetail'}) {
2962: my @imports;
2963: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
2964: if (defined($item)) {
2965: my ($name,$url,$residx)=
1.484.2.26 raeburn 2966: map { &unescape($_); } split(/\=/,$item);
2967: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 2968: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 2969: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 2970: if ($locknotfreed) {
2971: $r->print($locknotfreed);
2972: }
2973: if ($suffix) {
1.484.2.19 raeburn 2974: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 2975: } else {
2976: return $errortxt;
2977: }
1.484.2.26 raeburn 2978: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
2979: my $type = $1;
2980: my ($suffix,$errortxt,$locknotfreed) =
2981: &new_timebased_suffix($coursedom,$coursenum,$type);
2982: if ($locknotfreed) {
2983: $r->print($locknotfreed);
2984: }
2985: if ($suffix) {
2986: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
2987: } else {
2988: return $errortxt;
2989: }
1.484.2.27 raeburn 2990: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
2991: if ($supplementalflag) {
2992: next unless ($1 eq 'supplemental');
2993: if ($folder eq 'supplemental') {
2994: next unless ($2 eq 'default');
2995: } else {
2996: next unless ($folder eq 'supplemental_'.$2);
2997: }
2998: } else {
2999: next unless ($1 eq 'docs');
3000: if ($folder eq 'default') {
3001: next unless ($2 eq 'default');
3002: } else {
3003: next unless ($folder eq 'default_'.$2);
3004: }
3005: }
1.484.2.15 raeburn 3006: }
1.329 droeschl 3007: push(@imports, [$name, $url, $residx]);
3008: }
3009: }
1.484.2.23 raeburn 3010: ($errtext,$fatal,my $fixuperrors) =
3011: &group_import($coursenum, $coursedom, $folder,$container,
3012: 'londocs',@imports);
1.329 droeschl 3013: return $errtext if ($fatal);
1.484.2.23 raeburn 3014: if ($fixuperrors) {
3015: $r->print($fixuperrors);
3016: }
1.329 droeschl 3017: }
3018: # Loading a complete map
3019: if ($env{'form.loadmap'}) {
3020: if ($env{'form.importmap'}=~/\w/) {
3021: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3022: my ($title,$url,$ext,$type)=split(/\:/,$res);
3023: my $idx=&LONCAPA::map::getresidx($url);
3024: $LONCAPA::map::resources[$idx]=$res;
3025: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3026: }
3027: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3028: $folder.'.'.$container,1);
1.329 droeschl 3029: return $errtext if ($fatal);
3030: } else {
3031: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3032:
1.329 droeschl 3033: }
3034: }
3035: &log_differences($plain);
3036: }
3037: # ---------------------------------------------------------------- End commands
3038: # ---------------------------------------------------------------- Print screen
3039: my $idx=0;
3040: my $shown=0;
3041: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3042: $r->print('<div class="LC_Box">'.
1.432 raeburn 3043: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3044: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3045: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3046: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3047: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3048: '</ol>');
1.381 bisitz 3049: if ($randompick>=0) {
3050: $r->print('<p class="LC_warning">'
3051: .&mt('Caution: this folder is set to randomly pick a subset'
3052: .' of resources. Adding or removing resources from this'
3053: .' folder will change the set of resources that the'
3054: .' students see, resulting in spurious or missing credit'
3055: .' for completed problems, not limited to ones you'
3056: .' modify. Do not modify the contents of this folder if'
3057: .' it is in active student use.')
3058: .'</p>'
3059: );
3060: }
3061: if ($is_random_order) {
3062: $r->print('<p class="LC_warning">'
3063: .&mt('Caution: this folder is set to randomly order its'
3064: .' contents. Adding or removing resources from this folder'
3065: .' will change the order of resources shown.')
3066: .'</p>'
3067: );
3068: }
3069: $r->print('</div>');
1.364 bisitz 3070: }
1.381 bisitz 3071:
1.484.2.30 raeburn 3072: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3073: %filters = (
3074: canremove => [],
3075: cancut => [],
3076: cancopy => [],
3077: hiddenresource => [],
3078: encrypturl => [],
3079: randomorder => [],
3080: randompick => [],
3081: );
3082: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3083: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3084: foreach my $res (@LONCAPA::map::order) {
3085: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3086: $name=&LONCAPA::map::qtescape($name);
3087: $url=&LONCAPA::map::qtescape($url);
3088: unless ($name) { $name=(split(/\//,$url))[-1]; }
3089: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3090: push(@allidx,$res);
3091: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3092: push(@allmapidx,$res);
3093: }
1.484.2.67 raeburn 3094:
1.381 bisitz 3095: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3096: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3097: $pathitem,$supplementalflag,$container,
1.484.2.70 raeburn 3098: \%filters,\%curr_groups,$canedit,
3099: $isencrypted,$navmapref);
1.381 bisitz 3100: $idx++;
3101: $shown++;
1.329 droeschl 3102: }
1.424 onken 3103: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3104:
1.484.2.30 raeburn 3105: my $need_save;
1.484.2.67 raeburn 3106: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3107: my $toolslink;
1.484.2.67 raeburn 3108: if ($allowed) {
1.484.2.31 raeburn 3109: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3110: .&Apache::loncommon::help_open_menu('Navigation Screen',
3111: 'Navigation_Screen',undef,'RAT')
3112: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3113: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3114: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3115: .'id="LC_content_toolbar_edittoplevel" '
3116: .'class="LC_toolbarItem" '
3117: .'title="'.&mt('Supplemental Content Editor').'">'
3118: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3119: }
1.484.2.19 raeburn 3120: if ($shown) {
3121: if ($allowed) {
3122: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3123: .&Apache::loncommon::start_data_table(undef,'contentlist')
3124: .&Apache::loncommon::start_data_table_header_row()
3125: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3126: .'<th colspan="2">'.&mt('Actions').'</th>'
3127: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3128: if ($folder !~ /^supplemental/) {
3129: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3130: }
1.484.2.29 raeburn 3131: $to_show .= &Apache::loncommon::end_data_table_header_row();
3132: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3133: $lists{'canhide'} = join(',',@allidx);
3134: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3135: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3136: 'randomorder','randompick');
3137: foreach my $item (@possfilters) {
3138: if (ref($filters{$item}) eq 'ARRAY') {
3139: if (@{$filters{$item}} > 0) {
3140: $lists{$item} = join(',',@{$filters{$item}});
3141: }
3142: }
3143: }
1.484.2.29 raeburn 3144: if (@allidx > 0) {
3145: my $path;
3146: if ($env{'form.folderpath'}) {
3147: $path =
3148: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3149: }
1.484.2.30 raeburn 3150: if (@allidx > 1) {
3151: $to_show .=
3152: &Apache::loncommon::continue_data_table_row().
3153: '<td colspan="2"> </td>'.
3154: '<td>'.
1.484.2.67 raeburn 3155: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3156: '</td>'.
3157: '<td> </td>'.
3158: '<td> </td>'.
3159: '<td colspan="4">'.
1.484.2.67 raeburn 3160: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3161: '</td>'.
3162: &Apache::loncommon::end_data_table_row();
3163: $need_save = 1;
3164: }
1.484.2.29 raeburn 3165: }
3166: }
3167: $to_show .= $output.' '
1.484.2.19 raeburn 3168: .&Apache::loncommon::end_data_table()
3169: .'<br style="line-height:2px;" />'
3170: .&Apache::loncommon::end_scrollbox();
3171: } else {
3172: $to_show .= $toolslink
3173: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3174: .$output.' '
3175: .&Apache::loncommon::end_data_table();
3176: }
3177: } else {
3178: if (!$allowed) {
3179: $to_show .= $toolslink;
1.393 raeburn 3180: }
1.484.2.67 raeburn 3181: my $noresmsg;
3182: if ($allowed && $hiddentop && !$supplementalflag) {
3183: $noresmsg = &mt('Main Content Hidden');
3184: } else {
3185: $noresmsg = &mt('Currently empty');
3186: }
1.484.2.19 raeburn 3187: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3188: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3189: .$noresmsg
1.484.2.19 raeburn 3190: .'</div>'
3191: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3192: }
3193: } else {
1.484.2.19 raeburn 3194: if ($shown) {
3195: $to_show = '<div>'
3196: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3197: .$output
3198: .&Apache::loncommon::end_data_table()
3199: .'</div>';
3200: } else {
3201: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3202: .&mt('Currently empty')
1.484.2.19 raeburn 3203: .'</div>'
3204: }
1.458 raeburn 3205: }
3206: my $tid = 1;
3207: if ($supplementalflag) {
3208: $tid = 2;
1.329 droeschl 3209: }
3210: if ($allowed) {
1.484 raeburn 3211: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3212: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3213: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3214: if ($canedit) {
1.484.2.67 raeburn 3215: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3216: }
1.460 raeburn 3217: } else {
3218: $r->print($to_show);
1.329 droeschl 3219: }
3220: return;
3221: }
3222:
1.484.2.30 raeburn 3223: sub multiple_check_form {
1.484.2.67 raeburn 3224: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3225: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3226: my $disabled;
3227: unless ($canedit) {
3228: $disabled = 'disabled="disabled"';
3229: }
1.484.2.30 raeburn 3230: my $output =
3231: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3232: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3233: '<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>'.
3234: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3235: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3236: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3237: if ($caller eq 'settings') {
3238: $output .=
3239: '<table><tr>'.
3240: '<td class="LC_docs_entry_parameter">'.
3241: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3242: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3243: '</label></span></td>'.
3244: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3245: '<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 3246: '</span></td>'.
3247: '</tr>'."\n".
3248: '<tr>'.
3249: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3250: '<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 3251: '</label></span>'.
3252: '</td></tr></table>'."\n";
3253: } else {
3254: $output .=
3255: '<table><tr>'.
3256: '<td class="LC_docs_entry_parameter">'.
3257: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3258: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3259: '</label></span></td>'.
3260: '<td class="LC_docs_entry_parameter">'.
3261: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3262: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3263: '</label></span></td>'."\n".
3264: '<td class="LC_docs_entry_parameter">'.
3265: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3266: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3267: '</label></span></td>'.
3268: '</tr></table>'."\n";
3269: }
3270: $output .=
3271: '</fieldset>'.
3272: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3273: if ($caller eq 'settings') {
3274: $output .=
3275: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3276: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3277: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3278: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3279: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3280: } elsif ($caller eq 'actions') {
3281: $output .=
3282: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3283: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3284: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3285: }
3286: $output .=
3287: '</form>'.
3288: '</div>';
3289: return $output;
3290: }
3291:
1.329 droeschl 3292: sub process_file_upload {
1.484.2.36 raeburn 3293: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3294: # upload a file, if present
1.484.2.36 raeburn 3295: my $filesize = length($env{'form.uploaddoc'});
3296: if (!$filesize) {
3297: $$upload_output = '<div class="LC_error">'.
3298: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3299: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3300: $filesize).'<br />'.
3301: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3302: '</div>';
3303: return;
3304: }
3305: my $quotatype = 'unofficial';
3306: if ($crstype eq 'Community') {
3307: $quotatype = 'community';
1.484.2.51 raeburn 3308: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3309: $quotatype = 'official';
1.484.2.45 raeburn 3310: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3311: $quotatype = 'textbook';
1.484.2.36 raeburn 3312: }
3313: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3314: $filesize = int($filesize/1000); #expressed in kb
3315: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3316: $env{'form.uploaddoc.filename'},$filesize,
3317: 'upload',$quotatype);
1.484.2.36 raeburn 3318: return if ($$upload_output);
3319: }
1.440 raeburn 3320: my ($parseaction,$showupload,$nextphase,$mimetype);
3321: if ($env{'form.parserflag'}) {
1.329 droeschl 3322: $parseaction = 'parse';
3323: }
3324: my $folder=$env{'form.folder'};
3325: if ($folder eq '') {
3326: $folder='default';
3327: }
3328: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3329: my $errtext='';
3330: my $fatal=0;
3331: my $container='sequence';
1.484.2.19 raeburn 3332: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3333: $container='page';
3334: }
3335: ($errtext,$fatal)=
1.484.2.27 raeburn 3336: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3337: if ($#LONCAPA::map::order<1) {
3338: $LONCAPA::map::order[0]=1;
3339: $LONCAPA::map::resources[1]='';
3340: }
3341: my $destination = 'docs/';
3342: if ($folder =~ /^supplemental/) {
3343: $destination = 'supplemental/';
3344: }
3345: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3346: $destination .= 'default/';
3347: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3348: $destination .= $2.'/';
3349: }
1.484.2.27 raeburn 3350: if ($fatal) {
3351: $$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>';
3352: return;
3353: }
1.440 raeburn 3354: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3355: my $newidx=&LONCAPA::map::getresidx();
3356: $destination .= $newidx;
1.439 raeburn 3357: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3358: $parseaction,$allfiles,
1.440 raeburn 3359: $codebase,undef,undef,undef,undef,
3360: undef,undef,\$mimetype);
3361: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3362: my $stored = $1;
3363: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3364: $stored.'</span>').'</p>';
3365: } else {
3366: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3367:
1.457 raeburn 3368: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3369: return;
3370: }
1.329 droeschl 3371: my $ext='false';
3372: if ($url=~m{^http://}) { $ext='true'; }
3373: $url = &LONCAPA::map::qtunescape($url);
3374: my $comment=$env{'form.comment'};
3375: $comment = &LONCAPA::map::qtunescape($comment);
3376: if ($folder=~/^supplemental/) {
3377: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3378: $env{'user.domain'}.'___&&&___'.$comment;
3379: }
3380:
3381: $LONCAPA::map::resources[$newidx]=
3382: $comment.':'.$url.':'.$ext.':normal:res';
3383: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3384: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3385: $folder.'.'.$container,1);
1.329 droeschl 3386: if ($fatal) {
1.457 raeburn 3387: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3388: return;
1.329 droeschl 3389: } else {
1.440 raeburn 3390: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3391: $$upload_output = $showupload;
1.384 raeburn 3392: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3393: if ($total_embedded > 0) {
1.440 raeburn 3394: my $uploadphase = 'upload_embedded';
3395: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3396: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3397: my ($embedded,$num) =
3398: &Apache::loncommon::ask_for_embedded_content(
3399: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3400: if ($embedded) {
3401: if ($num) {
3402: $$upload_output .=
3403: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3404: $nextphase = $uploadphase;
3405: } else {
3406: $$upload_output .= $embedded;
3407: }
3408: } else {
3409: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3410: }
1.329 droeschl 3411: } else {
1.440 raeburn 3412: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3413: }
1.457 raeburn 3414: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3415: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3416: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3417: $nextphase = 'decompress_uploaded';
3418: my $position = scalar(@LONCAPA::map::order)-1;
3419: my $noextract = &return_to_editor();
3420: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3421: my %archiveitems = (
3422: folderpath => $env{'form.folderpath'},
3423: cmd => $nextphase,
3424: newidx => $newidx,
3425: position => $position,
3426: phase => $nextphase,
1.477 raeburn 3427: comment => $comment,
1.480 raeburn 3428: );
3429: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3430: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3431: $$upload_output = $showupload.
3432: &Apache::loncommon::decompress_form($mimetype,
3433: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3434: \%archiveitems,\@current);
1.329 droeschl 3435: }
3436: }
3437: }
1.440 raeburn 3438: return $nextphase;
1.329 droeschl 3439: }
3440:
1.480 raeburn 3441: sub get_dir_list {
3442: my ($url,$coursenum,$coursedom,$newidx) = @_;
3443: my ($destination,$dir_root) = &embedded_destination();
3444: my ($dirlistref,$listerror) =
3445: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3446: my @dir_lines;
3447: my $dirptr=16384;
3448: if (ref($dirlistref) eq 'ARRAY') {
3449: foreach my $dir_line (sort
3450: {
3451: my ($afile)=split('&',$a,2);
3452: my ($bfile)=split('&',$b,2);
3453: return (lc($afile) cmp lc($bfile));
3454: } (@{$dirlistref})) {
3455: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3456: $filename =~ s/\s+$//;
3457: next if ($filename =~ /^\.\.?$/);
3458: my $isdir = 0;
3459: if ($dirptr&$testdir) {
3460: $isdir = 1;
3461: }
3462: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3463: }
3464: }
3465: return @dir_lines;
3466: }
3467:
1.329 droeschl 3468: sub is_supplemental_title {
3469: my ($title) = @_;
3470: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3471: }
3472:
3473: # --------------------------------------------------------------- An entry line
3474:
3475: sub entryline {
1.484.2.12 raeburn 3476: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3477: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3478: $canedit,$isencrypted,$navmapref)=@_;
1.484.2.52 raeburn 3479: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3480: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3481: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3482: } else {
3483: $title=&HTML::Entities::encode($title,'"<>&\'');
3484: $renametitle=$title;
3485: $foldertitle=$title;
3486: }
3487:
1.484.2.67 raeburn 3488: my ($disabled,$readonly,$js_lt);
3489: unless ($canedit) {
3490: $disabled = 'disabled="disabled"';
3491: $readonly = 1;
3492: }
3493:
1.329 droeschl 3494: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3495:
1.329 droeschl 3496: $renametitle=~s/\\/\\\\/g;
3497: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3498: $renametitle=~s/"/%22/g;
1.329 droeschl 3499: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3500: $oldtitle = $renametitle;
3501: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3502: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3503: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3504: # Edit commands
1.484.2.28 raeburn 3505: my ($esc_path, $path, $symb);
1.329 droeschl 3506: if ($env{'form.folderpath'}) {
3507: $esc_path=&escape($env{'form.folderpath'});
3508: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3509: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3510: }
1.484.2.16 raeburn 3511: my $isexternal;
1.484.2.19 raeburn 3512: if ($residx) {
1.484.2.12 raeburn 3513: my $currurl = $url;
3514: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3515: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3516: $isexternal = 1;
3517: }
1.484.2.19 raeburn 3518: if (!$supplementalflag) {
3519: my $path = 'uploaded/'.
3520: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3521: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3522: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3523: $residx,
3524: &Apache::lonnet::declutter($currurl));
3525: }
1.484.2.12 raeburn 3526: }
1.484.2.30 raeburn 3527: my ($renamelink,%lt,$ishash);
3528: if (ref($filtersref) eq 'HASH') {
3529: $ishash = 1;
3530: }
3531:
1.329 droeschl 3532: if ($allowed) {
1.484.2.30 raeburn 3533: $form_start = '
3534: <form action="/adm/coursedocs" method="post">
3535: ';
3536: $form_common=(<<END);
3537: <input type="hidden" name="folderpath" value="$path" />
3538: <input type="hidden" name="symb" value="$symb" />
3539: END
3540: $form_param=(<<END);
3541: <input type="hidden" name="setparms" value="$orderidx" />
3542: <input type="hidden" name="changeparms" value="0" />
3543: END
3544: $form_end = '</form>';
3545:
1.329 droeschl 3546: my $incindex=$index+1;
3547: my $selectbox='';
1.471 raeburn 3548: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3549: ((split(/\:/,
1.344 bisitz 3550: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3551: ne '') &&
1.329 droeschl 3552: ((split(/\:/,
1.344 bisitz 3553: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3554: ne '')) {
3555: $selectbox=
3556: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3557: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3558: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3559: if ($i==$incindex) {
1.358 bisitz 3560: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3561: } else {
3562: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3563: }
3564: }
3565: $selectbox.='</select>';
3566: }
1.484.2.12 raeburn 3567: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3568: 'up' => 'Move Up',
3569: 'dw' => 'Move Down',
3570: 'rm' => 'Remove',
3571: 'ct' => 'Cut',
3572: 'rn' => 'Rename',
1.484.2.12 raeburn 3573: 'cp' => 'Copy',
3574: 'ex' => 'External Resource',
3575: 'ed' => 'Edit',
3576: 'pr' => 'Preview',
3577: 'sv' => 'Save',
3578: 'ul' => 'URL',
1.484.2.67 raeburn 3579: 'ti' => 'Title',
3580: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3581: );
1.484.2.30 raeburn 3582: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3583: $env{'form.folderpath'},
3584: $currgroups);
1.484.2.19 raeburn 3585: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3586: my $skip_confirm = 0;
1.484.2.63 raeburn 3587: my $confirm_removal = 0;
1.329 droeschl 3588: if ( $folder =~ /^supplemental/
3589: || ($url =~ m{( /smppg$
3590: |/syllabus$
3591: |/aboutme$
3592: |/navmaps$
3593: |/bulletinboard$
1.484.2.16 raeburn 3594: |\.html$)}x)
1.484.2.19 raeburn 3595: || $isexternal) {
1.329 droeschl 3596: $skip_confirm = 1;
3597: }
1.484.2.63 raeburn 3598: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3599: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3600: $confirm_removal = 1;
3601: }
1.484.2.19 raeburn 3602:
1.484.2.30 raeburn 3603: if ($denied{'copy'}) {
3604: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3605: <span style="visibility: hidden;">$lt{'cp'}</span>
3606: ENDCOPY
3607: } else {
1.484.2.30 raeburn 3608: my $formname = 'edit_copy_'.$orderidx;
3609: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3610: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3611: <form name="$formname" method="post" action="/adm/coursedocs">
3612: $form_common
1.484.2.67 raeburn 3613: <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 3614: $form_end
1.329 droeschl 3615: ENDCOPY
1.484.2.30 raeburn 3616: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3617: push(@{$filtersref->{'cancopy'}},$orderidx);
3618: }
1.329 droeschl 3619: }
1.484.2.30 raeburn 3620: if ($denied{'cut'}) {
1.484.2.16 raeburn 3621: $cutlink=(<<ENDCUT);
3622: <span style="visibility: hidden;">$lt{'ct'}</span>
3623: ENDCUT
3624: } else {
1.484.2.30 raeburn 3625: my $formname = 'edit_cut_'.$orderidx;
3626: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3627: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3628: <form name="$formname" method="post" action="/adm/coursedocs">
3629: $form_common
3630: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3631: <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 3632: $form_end
1.329 droeschl 3633: ENDCUT
1.484.2.30 raeburn 3634: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3635: push(@{$filtersref->{'cancut'}},$orderidx);
3636: }
1.329 droeschl 3637: }
1.484.2.30 raeburn 3638: if ($denied{'remove'}) {
1.484.2.16 raeburn 3639: $removelink=(<<ENDREM);
3640: <span style="visibility: hidden;">$lt{'rm'}</a>
3641: ENDREM
3642: } else {
1.484.2.30 raeburn 3643: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3644: 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 3645: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3646: <form name="$formname" method="post" action="/adm/coursedocs">
3647: $form_common
3648: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3649: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3650: <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 3651: $form_end
1.484.2.9 raeburn 3652: ENDREM
1.484.2.30 raeburn 3653: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3654: push(@{$filtersref->{'canremove'}},$orderidx);
3655: }
1.484.2.9 raeburn 3656: }
1.484.2.35 raeburn 3657: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3658: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3659: ENDREN
1.484.2.67 raeburn 3660: my ($uplink,$downlink);
3661: if ($canedit) {
3662: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3663: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3664: } else {
3665: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3666: $downlink = $uplink;
3667: }
1.329 droeschl 3668: $line.=(<<END);
3669: <td>
1.379 bisitz 3670: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3671: <a href="$uplink">
1.484.2.12 raeburn 3672: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3673: </a>
3674: </div>
3675: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3676: <a href="$downlink">
1.484.2.12 raeburn 3677: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3678: </a>
3679: </div>
1.329 droeschl 3680: </td>
3681: <td>
3682: $form_start
1.484.2.30 raeburn 3683: $form_param
1.478 raeburn 3684: $form_common
1.329 droeschl 3685: $selectbox
3686: $form_end
3687: </td>
1.484.2.30 raeburn 3688: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3689: $removelink
1.329 droeschl 3690: $cutlink
3691: $copylink
3692: </td>
3693: END
3694: }
3695: # Figure out what kind of a resource this is
3696: my ($extension)=($url=~/\.(\w+)$/);
3697: my $uploaded=($url=~/^\/*uploaded\//);
3698: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3699: my $isfolder;
3700: my $ispage;
3701: my $containerarg;
1.484.2.67 raeburn 3702: my $folderurl;
1.329 droeschl 3703: if ($uploaded) {
1.472 raeburn 3704: if (($extension eq 'sequence') || ($extension eq 'page')) {
3705: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3706: $containerarg = $1;
1.472 raeburn 3707: if ($extension eq 'sequence') {
3708: $icon=$iconpath.'navmap.folder.closed.gif';
3709: $isfolder=1;
3710: } else {
3711: $icon=$iconpath.'page.gif';
3712: $ispage=1;
3713: }
1.484.2.67 raeburn 3714: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3715: if ($allowed) {
3716: $url='/adm/coursedocs?';
3717: } else {
3718: $url='/adm/supplemental?';
3719: }
1.329 droeschl 3720: } else {
3721: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3722: }
3723: }
1.364 bisitz 3724:
1.484.2.70 raeburn 3725: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3726: my $orig_url = $url;
1.340 raeburn 3727: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.19 raeburn 3728: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.12 raeburn 3729: if (!$supplementalflag && $residx && $symb) {
3730: if ((!$isfolder) && (!$ispage)) {
3731: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3732: $url=&Apache::lonnet::clutter($url);
3733: if ($url=~/^\/*uploaded\//) {
3734: $url=~/\.(\w+)$/;
3735: my $embstyle=&Apache::loncommon::fileembstyle($1);
3736: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3737: $url='/adm/wrapper'.$url;
3738: } elsif ($embstyle eq 'ssi') {
3739: #do nothing with these
3740: } elsif ($url!~/\.(sequence|page)$/) {
3741: $url='/adm/coursedocs/showdoc'.$url;
3742: }
1.484.2.70 raeburn 3743: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
3744: my $wrapped = $1;
3745: my $exturl = $2;
3746: if ($wrapped eq '') {
3747: $url='/adm/wrapper'.$url;
3748: }
3749: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
3750: $nomodal = 1;
3751: }
3752: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3753: if (($ENV{'SERVER_PORT'} == 443) &&
3754: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
3755: $nomodal = 1;
3756: }
1.484.2.19 raeburn 3757: }
1.484.2.12 raeburn 3758: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3759: my $shownsymb = $symb;
3760: if ($isexternal) {
3761: if ($url =~ /^([^#]+)#([^#]+)$/) {
3762: $url = $1;
3763: $anchor = $2;
3764: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
3765: $shownsymb = $1.&escape('#').$anchor;
3766: }
3767: }
3768: }
1.484.2.67 raeburn 3769: unless ($env{'request.role.adv'}) {
3770: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3771: $url = '';
3772: }
3773: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3774: $url = '';
3775: $hiddenres = 1;
3776: }
3777: }
3778: if ($url ne '') {
1.484.2.75 raeburn 3779: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3780: }
3781: } elsif (!$env{'request.role.adv'}) {
3782: my $checkencrypt;
3783: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3784: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3785: $checkencrypt = 1;
1.484.2.70 raeburn 3786: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3787: unless (ref($$navmapref)) {
3788: $$navmapref = Apache::lonnavmaps::navmap->new();
3789: }
3790: if (ref($$navmapref)) {
3791: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
3792: $checkencrypt = 1;
3793: }
3794: }
3795: }
3796: if ($checkencrypt) {
3797: my $shownsymb = &Apache::lonenc::encrypted($symb);
3798: my $shownurl = &Apache::lonenc::encrypted($url);
3799: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
3800: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
3801: if ($env{'request.enc'} ne '') {
3802: delete($env{'request.enc'});
3803: }
3804: } else {
3805: $url='';
3806: }
3807: } else {
3808: $url='';
3809: }
1.484.2.12 raeburn 3810: } else {
3811: $url='';
3812: }
1.484.2.19 raeburn 3813: }
1.484.2.66 raeburn 3814: } elsif ($supplementalflag) {
3815: if ($isexternal) {
3816: if ($url =~ /^([^#]+)#([^#]+)$/) {
3817: $url = $1;
3818: $anchor = $2;
1.484.2.70 raeburn 3819: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
3820: $nomodal = 1;
3821: }
3822: }
3823: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
3824: if (($ENV{'SERVER_PORT'} == 443) &&
3825: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
3826: $nomodal = 1;
1.484.2.66 raeburn 3827: }
3828: }
1.329 droeschl 3829: }
1.484.2.67 raeburn 3830: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
3831: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 3832: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3833: my $foldername=&escape($foldertitle);
3834: my $folderpath=$env{'form.folderpath'};
3835: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 3836: if (!$allowed && $supplementalflag) {
3837: $folderpath.=$containerarg.'&'.$foldername;
3838: $url.='folderpath='.&escape($folderpath);
3839: } else {
3840: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3841: 'parameter_randompick'))[0];
1.484.2.67 raeburn 3842: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
3843: 'parameter_randomorder'))[0]=~/^yes$/i);
3844: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
3845: 'parameter_hiddenresource'))[0]=~/^yes$/i);
3846: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
3847: 'parameter_encrypturl'))[0]=~/^yes$/i);
3848: unless ($hiddenmap) {
1.484.2.70 raeburn 3849: if (ref($navmapref)) {
3850: unless (ref($$navmapref)) {
3851: $$navmapref = Apache::lonnavmaps::navmap->new();
3852: }
3853: if (ref($$navmapref)) {
3854: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
3855: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
3856: unless (@resources) {
3857: $hiddenmap = 1;
3858: unless ($env{'request.role.adv'}) {
3859: $url = '';
3860: $hiddenfolder = 1;
3861: }
1.484.2.67 raeburn 3862: }
3863: }
3864: }
3865: }
3866: }
3867: unless ($encryptmap) {
1.484.2.70 raeburn 3868: if ((ref($navmapref)) && (ref($$navmapref))) {
3869: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
3870: $encryptmap = 1;
3871: }
1.484.2.67 raeburn 3872: }
3873: }
3874:
3875: # Append randompick number, hidden, and encrypted with ":" to foldername,
3876: # so it gets transferred between levels
3877: $folderpath.=$containerarg.'&'.$foldername.
3878: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
3879: unless ($url eq '') {
3880: $url.='folderpath='.&escape($folderpath);
3881: }
1.484.2.19 raeburn 3882: my $rpckchk;
3883: if ($rpicknum) {
3884: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 3885: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3886: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3887: }
1.484.2.19 raeburn 3888: }
1.484.2.29 raeburn 3889: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 3890: $rand_pick_text =
1.478 raeburn 3891: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3892: $form_param."\n".
1.478 raeburn 3893: $form_common."\n".
1.484.2.67 raeburn 3894: '<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 3895: if ($rpicknum ne '') {
3896: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3897: }
1.484.2.29 raeburn 3898: $rand_pick_text .= '</span></span>'.
3899: $form_end;
1.484.2.30 raeburn 3900: my $ro_set;
1.484.2.67 raeburn 3901: if ($randorder) {
1.484.2.30 raeburn 3902: $ro_set = 'checked="checked"';
3903: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3904: push(@{$filtersref->{'randomorder'}},$orderidx);
3905: }
3906: }
1.484.2.41 raeburn 3907: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 3908: $rand_order_text =
1.484.2.29 raeburn 3909: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3910: $form_param."\n".
1.484.2.29 raeburn 3911: $form_common."\n".
1.484.2.67 raeburn 3912: '<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 3913: $form_end;
1.484.2.19 raeburn 3914: }
1.484.2.18 raeburn 3915: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 3916: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 3917: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 3918: if ($title) {
3919: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3920: }
3921: if ($isexternal && $orderidx) {
3922: $url .= '&idx='.$orderidx;
3923: }
1.484.2.66 raeburn 3924: if ($anchor ne '') {
3925: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
3926: }
1.329 droeschl 3927: }
1.484.2.19 raeburn 3928: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 3929: if ($allowed) {
1.484.2.19 raeburn 3930: my $fileloc =
1.484.2.12 raeburn 3931: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 3932: if ($isexternal) {
3933: ($editlink,$extresform) =
1.484.2.67 raeburn 3934: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
3935: undef,undef,undef,$disabled);
1.484.2.19 raeburn 3936: } elsif (!$isfolder && !$ispage) {
3937: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 3938: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 3939: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 3940: my $suppanchor;
3941: if ($supplementalflag) {
3942: $suppanchor = $anchor;
3943: }
1.484.2.19 raeburn 3944: my $jscall =
1.484.2.12 raeburn 3945: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
3946: $switchserver,
1.484.2.14 raeburn 3947: $forceedit,
1.484.2.19 raeburn 3948: undef,$symb,
3949: &escape($env{'form.folderpath'}),
1.484.2.66 raeburn 3950: $renametitle,'','',1,$suppanchor);
1.484.2.12 raeburn 3951: if ($jscall) {
1.484.2.19 raeburn 3952: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
3953: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 3954: }
3955: }
3956: }
1.484.2.19 raeburn 3957: $tdalign = ' align="right" valign="top"';
3958: $tdwidth = ' width="80%"';
1.329 droeschl 3959: }
1.408 raeburn 3960: my $reinit;
3961: if ($crstype eq 'Community') {
3962: $reinit = &mt('(re-initialize community to access)');
3963: } else {
3964: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 3965: }
3966: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 3967: my $link;
1.472 raeburn 3968: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3969: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
3970: } elsif ($url) {
1.484.2.66 raeburn 3971: if ($anchor ne '') {
3972: if ($supplementalflag) {
3973: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
3974: } else {
3975: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
3976: }
3977: }
1.484.2.70 raeburn 3978: $link = &js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
3979: (($anchor ne '')?$anchor:''));
3980: if ($nomodal) {
3981: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
3982: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
3983: } else {
3984: $line.=&Apache::loncommon::modal_link($link,
3985: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
3986: }
1.469 www 3987: } else {
3988: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
3989: }
1.484.2.19 raeburn 3990: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 3991: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3992: $line.='<a href="'.$url.'">'.$title.'</a>';
3993: } elsif ($url) {
1.484.2.70 raeburn 3994: if ($nomodal) {
3995: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
3996: $title.'</a>';
3997: } else {
3998: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
3999: }
1.484.2.67 raeburn 4000: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4001: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4002: } else {
4003: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4004: }
1.484.2.19 raeburn 4005: $line.="$extresform</td>";
1.478 raeburn 4006: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4007: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4008: if (($allowed) && ($folder!~/^supplemental/)) {
4009: my %lt=&Apache::lonlocal::texthash(
4010: 'hd' => 'Hidden',
4011: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4012: my ($enctext,$hidtext);
4013: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4014: $enctext = ' checked="checked"';
4015: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4016: push(@{$filtersref->{'encrypturl'}},$orderidx);
4017: }
4018: }
4019: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4020: $hidtext = ' checked="checked"';
4021: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4022: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4023: }
4024: }
1.484.2.29 raeburn 4025: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4026: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4027: $line.=(<<ENDPARMS);
4028: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4029: <form action="/adm/coursedocs" method="post" name="$formhidden">
4030: $form_param
1.478 raeburn 4031: $form_common
1.484.2.67 raeburn 4032: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4033: $form_end
1.458 raeburn 4034: <br />
1.484.2.29 raeburn 4035: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4036: $form_param
1.478 raeburn 4037: $form_common
1.484.2.67 raeburn 4038: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4039: $form_end
4040: </td>
1.478 raeburn 4041: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4042: $rand_order_text</td>
1.329 droeschl 4043: ENDPARMS
4044: }
1.379 bisitz 4045: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4046: return $line;
4047: }
4048:
1.484.2.30 raeburn 4049: sub action_restrictions {
4050: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4051: my %denied = (
4052: cut => 0,
4053: copy => 0,
4054: remove => 0,
4055: );
4056: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4057: # no copy for published maps
4058: $denied{'copy'} = 1;
4059: } elsif ($url=~m{^/res/lib/templates/}) {
4060: $denied{'copy'} = 1;
4061: $denied{'cut'} = 1;
4062: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4063: if ($folderpath =~ /^default&[^\&]+$/) {
4064: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4065: $denied{'remove'} = 1;
4066: }
4067: $denied{'cut'} = 1;
4068: $denied{'copy'} = 1;
4069: }
4070: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4071: my $group = $1;
4072: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4073: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4074: $denied{'remove'} = 1;
4075: }
4076: }
4077: $denied{'cut'} = 1;
4078: $denied{'copy'} = 1;
4079: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4080: my $group = $1;
4081: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4082: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4083: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4084: if (keys(%groupsettings) > 0) {
4085: $denied{'remove'} = 1;
4086: }
4087: $denied{'cut'} = 1;
4088: $denied{'copy'} = 1;
4089: }
4090: }
4091: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4092: my $group = $1;
4093: if ($url =~ /group_boards_\Q$group\E/) {
4094: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4095: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4096: if (keys(%groupsettings) > 0) {
4097: if (ref($groupsettings{'functions'}) eq 'HASH') {
4098: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4099: $denied{'remove'} = 1;
4100: }
4101: }
4102: }
4103: $denied{'cut'} = 1;
4104: $denied{'copy'} = 1;
4105: }
4106: }
4107: }
4108: return %denied;
4109: }
4110:
1.484.2.26 raeburn 4111: sub new_timebased_suffix {
1.484.2.30 raeburn 4112: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4113: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4114: if ($type eq 'paste') {
4115: $prefix = $type;
4116: $namespace = 'courseeditor';
1.484.2.56 raeburn 4117: $idtype = 'addcode';
1.484.2.30 raeburn 4118: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4119: $prefix = 'docs';
4120: if ($area eq 'supplemental') {
4121: $prefix = 'supp';
4122: }
4123: $prefix .= $container;
4124: $namespace = 'uploadedmaps';
4125: } else {
4126: $prefix = $type;
4127: $namespace = 'templated';
1.484.2.15 raeburn 4128: }
4129: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4130: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4131: if (!$suffix) {
1.484.2.30 raeburn 4132: if ($type eq 'paste') {
4133: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4134: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4135: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4136: } elsif ($type eq 'smppg') {
4137: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4138: } else {
1.484.2.42 raeburn 4139: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4140: }
1.484.2.15 raeburn 4141: if ($error) {
4142: $errtext .= '<br />'.$error;
4143: }
4144: }
4145: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4146: $locknotfreed =
4147: '<div class="LC_error">'.
4148: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4149: if ($type eq 'paste') {
1.484.2.57 raeburn 4150: if ($freedlock eq 'nolock') {
4151: $locknotfreed =
4152: '<div class="LC_error">'.
4153: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4154:
1.484.2.60 raeburn 4155: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4156: } else {
4157: $locknotfreed .=
4158: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4159: }
1.484.2.30 raeburn 4160: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4161: $locknotfreed .=
4162: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4163: } elsif ($type eq 'smppg') {
4164: $locknotfreed .=
4165: &mt('This will prevent creation of additional simple pages in this course.');
4166: } else {
4167: $locknotfreed .=
1.484.2.42 raeburn 4168: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4169: }
1.484.2.30 raeburn 4170: unless ($type eq 'paste') {
4171: $locknotfreed .=
1.484.2.38 raeburn 4172: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4173: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4174: }
4175: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4176: }
4177: return ($suffix,$errtext,$locknotfreed);
4178: }
4179:
1.329 droeschl 4180: =pod
4181:
4182: =item tiehash()
4183:
4184: tie the hash
4185:
4186: =cut
4187:
4188: sub tiehash {
4189: my ($mode)=@_;
4190: $hashtied=0;
4191: if ($env{'request.course.fn'}) {
4192: if ($mode eq 'write') {
4193: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4194: &GDBM_WRCREAT(),0640)) {
4195: $hashtied=2;
4196: }
4197: } else {
4198: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4199: &GDBM_READER(),0640)) {
4200: $hashtied=1;
4201: }
4202: }
1.364 bisitz 4203: }
1.329 droeschl 4204: }
4205:
4206: sub untiehash {
4207: if ($hashtied) { untie %hash; }
4208: $hashtied=0;
4209: return OK;
4210: }
4211:
4212:
4213:
4214:
4215: sub checkonthis {
4216: my ($r,$url,$level,$title)=@_;
4217: $url=&unescape($url);
4218: $alreadyseen{$url}=1;
4219: $r->rflush();
4220: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4221: $r->print("\n<br />");
4222: if ($level==0) {
4223: $r->print("<br />");
4224: }
4225: for (my $i=0;$i<=$level*5;$i++) {
4226: $r->print(' ');
4227: }
4228: $r->print('<a href="'.$url.'" target="cat">'.
4229: ($title?$title:$url).'</a> ');
4230: if ($url=~/^\/res\//) {
4231: my $result=&Apache::lonnet::repcopy(
4232: &Apache::lonnet::filelocation('',$url));
4233: if ($result eq 'ok') {
4234: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4235: $r->rflush();
4236: &Apache::lonnet::countacc($url);
4237: $url=~/\.(\w+)$/;
4238: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4239: $r->print('<br />');
4240: $r->rflush();
4241: for (my $i=0;$i<=$level*5;$i++) {
4242: $r->print(' ');
4243: }
4244: $r->print('- '.&mt('Rendering:').' ');
4245: my ($errorcount,$warningcount)=split(/:/,
4246: &Apache::lonnet::ssi_body($url,
4247: ('grade_target'=>'web',
4248: 'return_only_error_and_warning_counts' => 1)));
4249: if (($errorcount) ||
4250: ($warningcount)) {
4251: if ($errorcount) {
1.369 bisitz 4252: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4253: &mt('[quant,_1,error]',$errorcount).'</span>');
4254: }
4255: if ($warningcount) {
4256: $r->print('<span class="LC_warning">'.
4257: &mt('[quant,_1,warning]',$warningcount).'</span>');
4258: }
4259: } else {
4260: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4261: }
4262: $r->rflush();
4263: }
4264: my $dependencies=
4265: &Apache::lonnet::metadata($url,'dependencies');
4266: foreach my $dep (split(/\,/,$dependencies)) {
4267: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4268: &checkonthis($r,$dep,$level+1);
4269: }
4270: }
4271: } elsif ($result eq 'unavailable') {
4272: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4273: } elsif ($result eq 'not_found') {
4274: unless ($url=~/\$/) {
1.484.2.19 raeburn 4275: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4276: } else {
1.366 bisitz 4277: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4278: }
4279: } else {
4280: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4281: }
4282: }
4283: }
4284: }
4285:
4286:
4287:
4288: =pod
4289:
4290: =item list_symbs()
4291:
1.484.2.3 raeburn 4292: List Content Identifiers
1.329 droeschl 4293:
4294: =cut
4295:
4296: sub list_symbs {
4297: my ($r) = @_;
4298:
1.408 raeburn 4299: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4300: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4301: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4302: $r->print(&startContentScreen('tools'));
1.329 droeschl 4303: my $navmap = Apache::lonnavmaps::navmap->new();
4304: if (!defined($navmap)) {
4305: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4306: '<div class="LC_error">'.
4307: &mt('Unable to retrieve information about course contents').
4308: '</div>');
1.408 raeburn 4309: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4310: } else {
1.484 raeburn 4311: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4312: &Apache::loncommon::start_data_table().
4313: &Apache::loncommon::start_data_table_header_row().
4314: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4315: &Apache::loncommon::end_data_table_header_row()."\n");
4316: my $count;
1.329 droeschl 4317: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4318: $r->print(&Apache::loncommon::start_data_table_row().
4319: '<td>'.$res->compTitle().'</td>'.
4320: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4321: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4322: $count ++;
4323: }
4324: if (!$count) {
4325: $r->print(&Apache::loncommon::start_data_table_row().
4326: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4327: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4328: }
1.484 raeburn 4329: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4330: }
1.484.2.19 raeburn 4331: $r->print(&endContentScreen());
1.329 droeschl 4332: }
4333:
4334:
4335: sub verifycontent {
4336: my ($r) = @_;
1.408 raeburn 4337: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4338: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4339: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4340: $r->print(&startContentScreen('tools'));
4341: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4342: $hashtied=0;
4343: undef %alreadyseen;
4344: %alreadyseen=();
4345: &tiehash();
1.484 raeburn 4346:
1.329 droeschl 4347: foreach my $key (keys(%hash)) {
4348: if ($hash{$key}=~/\.(page|sequence)$/) {
4349: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4350: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4351: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4352: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4353: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4354: }
4355: }
4356: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4357: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4358: }
4359: }
4360: &untiehash();
1.442 www 4361: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4362: $r->print(&endContentScreen());
1.329 droeschl 4363: }
4364:
4365:
4366: sub devalidateversioncache {
4367: my $src=shift;
4368: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4369: &Apache::lonnet::clutter($src));
4370: }
4371:
4372: sub checkversions {
1.484.2.67 raeburn 4373: my ($r,$canedit) = @_;
1.408 raeburn 4374: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4375: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4376: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4377: $r->print(&startContentScreen('tools'));
1.442 www 4378:
1.329 droeschl 4379: my $header='';
4380: my $startsel='';
4381: my $monthsel='';
4382: my $weeksel='';
4383: my $daysel='';
4384: my $allsel='';
4385: my %changes=();
4386: my $starttime=0;
4387: my $haschanged=0;
4388: my %setversions=&Apache::lonnet::dump('resourceversions',
4389: $env{'course.'.$env{'request.course.id'}.'.domain'},
4390: $env{'course.'.$env{'request.course.id'}.'.num'});
4391:
4392: $hashtied=0;
4393: &tiehash();
1.484.2.67 raeburn 4394: if ($canedit) {
4395: my %newsetversions=();
4396: if ($env{'form.setmostrecent'}) {
4397: $haschanged=1;
4398: foreach my $key (keys(%hash)) {
4399: if ($key=~/^ids\_(\/res\/.+)$/) {
4400: $newsetversions{$1}='mostrecent';
4401: &devalidateversioncache($1);
4402: }
1.329 droeschl 4403: }
1.484.2.67 raeburn 4404: } elsif ($env{'form.setcurrent'}) {
4405: $haschanged=1;
4406: foreach my $key (keys(%hash)) {
4407: if ($key=~/^ids\_(\/res\/.+)$/) {
4408: my $getvers=&Apache::lonnet::getversion($1);
4409: if ($getvers>0) {
4410: $newsetversions{$1}=$getvers;
4411: &devalidateversioncache($1);
4412: }
4413: }
1.329 droeschl 4414: }
1.484.2.67 raeburn 4415: } elsif ($env{'form.setversions'}) {
4416: $haschanged=1;
4417: foreach my $key (keys(%env)) {
4418: if ($key=~/^form\.set_version_(.+)$/) {
4419: my $src=$1;
4420: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4421: $newsetversions{$src}=$env{$key};
4422: &devalidateversioncache($src);
4423: }
4424: }
1.329 droeschl 4425: }
1.484.2.67 raeburn 4426: }
4427: if ($haschanged) {
4428: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4429: $env{'course.'.$env{'request.course.id'}.'.domain'},
4430: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4431: $r->print(&Apache::loncommon::confirmwrapper(
4432: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4433: } else {
4434: $r->print(&Apache::loncommon::confirmwrapper(
4435: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4436: }
4437: &mark_hash_old();
4438: }
4439: &changewarning($r,'');
1.329 droeschl 4440: }
4441: if ($env{'form.timerange'} eq 'all') {
4442: # show all documents
1.484.2.34 raeburn 4443: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4444: $allsel=' selected="selected"';
1.329 droeschl 4445: foreach my $key (keys(%hash)) {
4446: if ($key=~/^ids\_(\/res\/.+)$/) {
4447: my $src=$1;
4448: $changes{$src}=1;
4449: }
4450: }
4451: } else {
4452: # show documents which changed
4453: %changes=&Apache::lonnet::dump
4454: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4455: $env{'course.'.$env{'request.course.id'}.'.num'});
4456: my $firstkey=(keys(%changes))[0];
4457: unless ($firstkey=~/^error\:/) {
4458: unless ($env{'form.timerange'}) {
4459: $env{'form.timerange'}=604800;
4460: }
4461: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4462: .&mt('seconds');
4463: if ($env{'form.timerange'}==-1) {
4464: $seltext='since start of course';
1.484.2.19 raeburn 4465: $startsel=' selected="selected"';
1.329 droeschl 4466: $env{'form.timerange'}=time;
4467: }
4468: $starttime=time-$env{'form.timerange'};
4469: if ($env{'form.timerange'}==2592000) {
4470: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4471: $monthsel=' selected="selected"';
1.329 droeschl 4472: } elsif ($env{'form.timerange'}==604800) {
4473: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4474: $weeksel=' selected="selected"';
1.329 droeschl 4475: } elsif ($env{'form.timerange'}==86400) {
4476: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4477: $daysel=' selected="selected"';
1.329 droeschl 4478: }
4479: $header=&mt('Content changed').' '.$seltext;
4480: } else {
4481: $header=&mt('No content modifications yet.');
4482: }
4483: }
4484: %setversions=&Apache::lonnet::dump('resourceversions',
4485: $env{'course.'.$env{'request.course.id'}.'.domain'},
4486: $env{'course.'.$env{'request.course.id'}.'.num'});
4487: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4488: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4489: 'lm' => 'Version changes since last Month',
4490: 'lw' => 'Version changes since last Week',
4491: 'sy' => 'Version changes since Yesterday',
4492: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4493: 'cd' => 'Change display',
1.329 droeschl 4494: 'sd' => 'Display',
4495: 'fi' => 'File',
4496: 'md' => 'Modification Date',
4497: 'mr' => 'Most recently published Version',
1.408 raeburn 4498: 've' => 'Version used in '.$crstype,
4499: 'vu' => 'Set Version to be used in '.$crstype,
4500: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4501: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4502: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4503: 'di' => 'Differences',
1.484 raeburn 4504: 'save' => 'Save changes',
4505: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4506: 'act' => 'Actions');
1.484.2.67 raeburn 4507: my ($disabled,$readonly);
4508: unless ($canedit) {
4509: $disabled = 'disabled="disabled"';
4510: $readonly = 1;
4511: }
1.329 droeschl 4512: $r->print(<<ENDHEADERS);
1.484 raeburn 4513: <h4 class="LC_info">$header</h4>
1.329 droeschl 4514: <form action="/adm/coursedocs" method="post">
4515: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4516: <div class="LC_left_float">
1.479 golterma 4517: <fieldset>
1.484 raeburn 4518: <legend>$lt{'cd'}</legend>
1.329 droeschl 4519: <select name="timerange">
1.484.2.19 raeburn 4520: <option value='all'$allsel>$lt{'al'}</option>
4521: <option value="-1"$startsel>$lt{'st'}</option>
4522: <option value="2592000"$monthsel>$lt{'lm'}</option>
4523: <option value="604800"$weeksel>$lt{'lw'}</option>
4524: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4525: </select>
4526: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4527: </fieldset>
4528: </div>
4529: <div class="LC_left_float">
4530: <fieldset>
4531: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4532: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4533: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4534: </fieldset>
4535: </div>
4536: <br clear="all" />
4537: <hr />
4538: <h4>$lt{'vers'}</h4>
1.329 droeschl 4539: ENDHEADERS
1.479 golterma 4540: #number of columns for version history
1.484.2.44 raeburn 4541: my %changedbytime;
4542: foreach my $key (keys(%changes)) {
4543: #excludes not versionable problems from resource version history:
4544: next if ($key =~ /^\/res\/lib\/templates/);
4545: my $chg;
4546: if ($env{'form.timerange'} eq 'all') {
4547: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4548: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4549: } else {
4550: $chg = $changes{$key};
4551: next if ($chg < $starttime);
4552: }
4553: push(@{$changedbytime{$chg}},$key);
4554: }
4555: if (keys(%changedbytime) == 0) {
4556: &untiehash();
4557: $r->print(&mt('No content changes in imported content in specified time frame').
4558: &endContentScreen());
4559: return;
4560: }
1.479 golterma 4561: $r->print(
1.484.2.67 raeburn 4562: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4563: &Apache::loncommon::start_data_table().
4564: &Apache::loncommon::start_data_table_header_row().
4565: '<th>'.&mt('Resources').'</th>'.
4566: "<th>$lt{'mr'}</th>".
4567: "<th>$lt{'ve'}</th>".
4568: "<th>$lt{'vu'}</th>".
4569: '<th>'.&mt('History').'</th>'.
4570: &Apache::loncommon::end_data_table_header_row()
4571: );
1.484.2.44 raeburn 4572: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4573: foreach my $key (sort(@{$changedbytime{$chg}})) {
4574: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4575: my $currentversion=&Apache::lonnet::getversion($key);
4576: if ($currentversion<0) {
4577: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4578: }
4579: my $linkurl=&Apache::lonnet::clutter($key);
4580: $r->print(
4581: &Apache::loncommon::start_data_table_row().
4582: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4583: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4584: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4585: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4586: '<td align="right">'
4587: );
4588: # Used in course
4589: my $usedversion=$hash{'version_'.$linkurl};
4590: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4591: if ($usedversion != $currentversion) {
1.479 golterma 4592: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4593: } else {
1.479 golterma 4594: $r->print($usedversion);
4595: }
1.329 droeschl 4596: } else {
1.484.2.19 raeburn 4597: $r->print($currentversion);
1.329 droeschl 4598: }
1.484.2.44 raeburn 4599: $r->print('</td><td title="'.$lt{'vu'}.'">');
4600: # Set version
4601: $r->print(&Apache::loncommon::select_form(
4602: $setversions{$linkurl},
4603: 'set_version_'.$linkurl,
4604: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4605: '' => '',
4606: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4607: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4608: my $lastold=1;
4609: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4610: my $url=$root.'.'.$prevvers.'.'.$extension;
4611: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4612: $lastold=$prevvers;
4613: }
4614: }
4615: $r->print('</td>');
4616: # List all available versions
4617: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4618: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4619: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4620: $r->print(
1.484.2.44 raeburn 4621: '<span class="LC_nobreak">'
4622: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4623: .&mt('Version [_1]',$prevvers).'</a>'
4624: .' ('.&Apache::lonlocal::locallocaltime(
4625: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4626: .')');
4627: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4628: $r->print(
4629: ' <a href="/adm/diff?filename='.
4630: &Apache::lonnet::clutter($root.'.'.$extension).
4631: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4632: '" target="diffs">'.&mt('Diffs').'</a>');
4633: }
4634: $r->print('</span><br />');
1.329 droeschl 4635: }
1.484.2.44 raeburn 4636: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4637: }
1.329 droeschl 4638: }
1.484.2.19 raeburn 4639: $r->print(
4640: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4641: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4642: '</form>'
4643: );
1.329 droeschl 4644:
4645: &untiehash();
1.484.2.19 raeburn 4646: $r->print(&endContentScreen());
1.484.2.44 raeburn 4647: return;
1.329 droeschl 4648: }
4649:
4650: sub mark_hash_old {
4651: my $retie_hash=0;
4652: if ($hashtied) {
4653: $retie_hash=1;
4654: &untiehash();
4655: }
4656: &tiehash('write');
4657: $hash{'old'}=1;
4658: &untiehash();
4659: if ($retie_hash) { &tiehash(); }
4660: }
4661:
4662: sub is_hash_old {
4663: my $untie_hash=0;
4664: if (!$hashtied) {
4665: $untie_hash=1;
4666: &tiehash();
4667: }
4668: my $return=$hash{'old'};
4669: if ($untie_hash) { &untiehash(); }
4670: return $return;
4671: }
4672:
4673: sub changewarning {
4674: my ($r,$postexec,$message,$url)=@_;
4675: if (!&is_hash_old()) { return; }
4676: my $pathvar='folderpath';
4677: my $path=&escape($env{'form.folderpath'});
4678: if (!defined($url)) {
4679: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4680: }
4681: my $course_type = &Apache::loncommon::course_type();
4682: if (!defined($message)) {
4683: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4684: }
4685: $r->print("\n\n".
1.372 bisitz 4686: '<script type="text/javascript">'."\n".
4687: '// <![CDATA['."\n".
4688: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4689: '// ]]>'."\n".
1.369 bisitz 4690: '</script>'."\n".
1.375 tempelho 4691: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4692: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4693: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4694: &mt($message,' <input type="hidden" name="'.
4695: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4696: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4697: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4698: }
4699:
4700:
4701: sub init_breadcrumbs {
1.484.2.44 raeburn 4702: my ($form,$text,$help)=@_;
1.329 droeschl 4703: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4704: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4705: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4706: faq=>273,
4707: bug=>'Instructor Interface',
1.484.2.44 raeburn 4708: help => $help});
1.329 droeschl 4709: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4710: text=>$text,
4711: faq=>273,
4712: bug=>'Instructor Interface'});
4713: }
4714:
1.441 www 4715: # subroutine to list form elements
4716: sub create_list_elements {
4717: my @formarr = @_;
4718: my $list = '';
1.484.2.12 raeburn 4719: foreach my $button (@formarr){
4720: foreach my $picture (keys(%{$button})) {
4721: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4722: }
4723: }
4724: return $list;
4725: }
1.329 droeschl 4726:
1.441 www 4727: # subroutine to create ul from list elements
4728: sub create_form_ul {
4729: my $list = shift;
4730: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4731: return $ul;
4732: }
1.329 droeschl 4733:
1.442 www 4734: #
4735: # Start tabs
4736: #
4737:
4738: sub startContentScreen {
1.484 raeburn 4739: my ($mode) = @_;
4740: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4741: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4742: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4743: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4744: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4745: } else {
1.484.2.34 raeburn 4746: $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 4747: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4748: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4749: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4750: }
4751: $output .= "\n".'</ul>'."\n";
4752: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4753: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4754: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4755: return $output;
1.442 www 4756: }
4757:
4758: #
4759: # End tabs
4760: #
4761:
4762: sub endContentScreen {
1.484 raeburn 4763: return '</div></div></div>';
1.442 www 4764: }
1.329 droeschl 4765:
1.446 www 4766: sub supplemental_base {
1.484.2.33 raeburn 4767: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4768: }
4769:
1.329 droeschl 4770: sub handler {
4771: my $r = shift;
4772: &Apache::loncommon::content_type($r,'text/html');
4773: $r->send_http_header;
4774: return OK if $r->header_only;
1.484 raeburn 4775:
4776: # get course data
1.408 raeburn 4777: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4778: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4779: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4780:
4781: # graphics settings
4782: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4783:
1.443 www 4784: #
1.329 droeschl 4785: # --------------------------------------------- Initialize help topics for this
4786: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4787: 'Adding_External_Resource','Navigate_Content',
4788: 'Adding_Folders','Docs_Overview', 'Load_Map',
4789: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 4790: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 4791: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
4792: 'Dropbox','Simple_Problem') {
1.329 droeschl 4793: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4794: }
4795: # Composite help files
4796: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4797: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4798: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4799: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4800: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4801: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4802: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4803: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4804: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4805: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 4806:
1.484.2.67 raeburn 4807: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 4808: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4809: unless ($r->uri eq '/adm/supplemental') {
4810: # does this user have privileges to modify content.
1.484.2.67 raeburn 4811: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
4812: $allowed = 1;
4813: $canedit = 1;
4814: $canview = 1;
4815: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
4816: $allowed = 1;
4817: $canview = 1;
4818: }
4819: }
4820: unless ($canedit) {
4821: $disabled = ' disabled="disabled"';
1.472 raeburn 4822: }
1.484.2.53 raeburn 4823: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
4824: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 4825: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 4826: &verifycontent($r);
4827: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4828: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4829: &list_symbs($r);
4830: } elsif ($allowed && $env{'form.docslog'}) {
4831: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4832: my $folder = $env{'form.folder'};
4833: if ($folder eq '') {
4834: $folder='default';
4835: }
1.484.2.67 raeburn 4836: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 4837: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 4838: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 4839: &checkversions($r,$canedit);
4840: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 4841: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4842: &dumpcourse($r);
4843: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 4844: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4845: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4846: } else {
1.445 www 4847: #
4848: # Done catching special calls
1.484 raeburn 4849: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 4850: # Get the parameters that may be needed
4851: #
4852: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 4853: ['folderpath',
4854: 'forcesupplement','forcestandard',
4855: 'tools','symb','command','supppath']);
1.445 www 4856:
4857: # standard=1: this is a "new-style" course with an uploaded map as top level
4858: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 4859:
4860: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 4861:
1.484 raeburn 4862: # Decide whether this should display supplemental or main content or utilities
1.445 www 4863: # supplementalflag=1: show supplemental documents
4864: # supplementalflag=0: show standard documents
1.484 raeburn 4865: # toolsflag=1: show utilities
1.445 www 4866:
1.484.2.39 raeburn 4867: my $unesc_folderpath = &unescape($env{'form.folderpath'});
4868: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
4869: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 4870: $supplementalflag=0;
4871: }
4872: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4873: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4874: unless ($allowed) { $supplementalflag=1; }
4875: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 4876: my $toolsflag=0;
4877: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 4878:
1.329 droeschl 4879: my $script='';
4880: my $showdoc=0;
1.457 raeburn 4881: my $addentries = {};
1.475 raeburn 4882: my $container;
1.329 droeschl 4883: my $containertag;
1.484.2.17 raeburn 4884: my $pathitem;
1.484.2.67 raeburn 4885: my $hiddentop;
4886: my $navmap;
4887: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 4888:
1.464 www 4889: # Do we directly jump somewhere?
1.484.2.21 raeburn 4890: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 4891: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 4892: $env{'form.folderpath'}=
1.484.2.67 raeburn 4893: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 4894: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4895: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 4896: } elsif ($env{'form.supppath'} ne '') {
4897: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 4898: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4899: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 4900: }
1.472 raeburn 4901: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 4902: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 4903: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 4904: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 4905: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 4906: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
4907: } elsif ($env{'form.command'} eq 'contents') {
4908: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
4909: } elsif ($env{'form.command'} eq 'home') {
4910: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 4911: }
4912:
1.484.2.23 raeburn 4913:
1.445 www 4914: # Where do we store these for when we come back?
4915: my $stored_folderpath='docs_folderpath';
4916: if ($supplementalflag) {
4917: $stored_folderpath='docs_sup_folderpath';
4918: }
1.464 www 4919:
1.484.2.19 raeburn 4920: # No folderpath, and in edit mode, see if we have something stored
4921: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 4922: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 4923: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 4924:
4925: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
4926: if ($supplementalflag) {
4927: undef($env{'form.folderpath'}) if ($1 eq 'default');
4928: } else {
4929: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
4930: }
4931: } else {
1.484.2.19 raeburn 4932: undef($env{'form.folderpath'});
4933: }
1.329 droeschl 4934: }
1.446 www 4935:
4936: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 4937: if (!$allowed) {
1.446 www 4938: unless ($env{'form.folderpath'} =~ /^supplemental/) {
4939: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 4940: }
4941: }
1.446 www 4942: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 4943: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 4944: $env{'form.folderpath'} = &supplemental_base()
4945: .'&'.
1.329 droeschl 4946: $env{'form.folderpath'};
4947: }
1.484.2.67 raeburn 4948: # If allowed and user's role is not advanced check folderpath is not hidden
4949: if (($allowed) && (!$env{'request.role.adv'}) &&
4950: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
4951: my $folderurl;
4952: my @pathitems = split(/\&/,$env{'form.folderpath'});
4953: my $folder = $pathitems[-2];
4954: if ($folder eq '') {
4955: undef($env{'form.folderpath'});
4956: } else {
4957: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
4958: if ((split(/\:/,$pathitems[-1]))[4]) {
4959: $folderurl .= '.page';
4960: } else {
4961: $folderurl .= '.sequence';
4962: }
4963: unless (ref($navmap)) {
4964: $navmap = Apache::lonnavmaps::navmap->new();
4965: }
4966: if (ref($navmap)) {
4967: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4968: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
4969: unless (@resources) {
4970: undef($env{'form.folderpath'});
4971: }
4972: }
4973: }
4974: }
4975: }
4976:
4977:
1.446 www 4978: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 4979: unless ($env{'form.folderpath'}) {
1.446 www 4980: if ($supplementalflag) {
4981: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 4982: } elsif ($allowed) {
4983: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 4984: }
1.472 raeburn 4985: }
1.446 www 4986:
1.445 www 4987: # Store this
1.484 raeburn 4988: unless ($toolsflag) {
1.484.2.67 raeburn 4989: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 4990: &Apache::loncommon::store_course_settings($stored_folderpath,
4991: {'folderpath' => 'scalar'});
4992: }
4993: my $folderpath;
1.484 raeburn 4994: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 4995: $folderpath = $env{'form.folderpath'};
4996: my (@folders)=split('&',$env{'form.folderpath'});
4997: $env{'form.foldername'}=&unescape(pop(@folders));
4998: if ($env{'form.foldername'} =~ /\:1$/) {
4999: $container = 'page';
5000: } else {
5001: $container = 'sequence';
5002: }
5003: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5004: } else {
1.484.2.19 raeburn 5005: if ($env{'form.folder'} eq '' ||
5006: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5007: if ($env{'form.folder'} eq 'supplemental') {
5008: $folderpath=&supplemental_base();
5009: } elsif (!$hiddentop) {
5010: $folderpath='default&'.
5011: &escape(&mt('Main Content').':::::');
5012: }
1.484 raeburn 5013: }
5014: }
1.484.2.19 raeburn 5015: $containertag = '<input type="hidden" name="folderpath" value="" />';
5016: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5017: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5018: $showdoc='/'.$1;
5019: }
5020: if ($showdoc) { # got called in sequence from course
5021: $allowed=0;
5022: } else {
1.484.2.67 raeburn 5023: if ($canedit) {
1.484 raeburn 5024: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5025: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5026: }
5027: }
1.329 droeschl 5028: }
5029:
1.344 bisitz 5030: # get personal data
1.329 droeschl 5031: my $uname=$env{'user.name'};
5032: my $udom=$env{'user.domain'};
5033: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5034:
5035: if ($allowed) {
1.484 raeburn 5036: if ($toolsflag) {
5037: $script .= &inject_data_js();
5038: my ($home,$other,%outhash)=&authorhosts();
5039: if (!$home && $other) {
5040: my @hosts;
5041: foreach my $aurole (keys(%outhash)) {
5042: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5043: push(@hosts,$outhash{$aurole});
5044: }
5045: }
5046: $script .= &dump_switchserver_js(@hosts);
5047: }
1.458 raeburn 5048: } else {
1.484.2.43 raeburn 5049: my $tid = 1;
1.484 raeburn 5050: my @tabids;
5051: if ($supplementalflag) {
5052: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5053: $tid = 2;
1.484 raeburn 5054: } else {
5055: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5056: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5057: unshift(@tabids,'001');
5058: push(@tabids,('dd1','ee1'));
5059: }
1.458 raeburn 5060: }
1.484 raeburn 5061: my $tabidstr = join("','",@tabids);
1.484.2.68 raeburn 5062: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.67 raeburn 5063: $canedit,\$navmap).
1.484 raeburn 5064: &history_tab_js().
5065: &inject_data_js().
1.484.2.43 raeburn 5066: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5067: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5068: $addentries = {
1.484.2.3 raeburn 5069: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5070: };
1.458 raeburn 5071: }
1.484.2.30 raeburn 5072: $script .= &paste_popup_js();
1.484.2.12 raeburn 5073: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5074: &mt('Switch server?');
1.484.2.19 raeburn 5075:
5076:
1.329 droeschl 5077: }
5078: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5079: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5080: .'// <![CDATA['."\n"
5081: .$script."\n"
5082: .'// ]]>'."\n"
5083: .'</script>'."\n";
1.385 bisitz 5084:
5085: # Breadcrumbs
5086: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5087:
5088: if ($showdoc) {
5089: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5090: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5091: } elsif ($toolsflag) {
1.484.2.67 raeburn 5092: my ($breadtext,$breadtitle);
5093: $breadtext = "$crstype Editor";
5094: if ($canedit) {
5095: $breadtitle = 'Editing '.$crstype.' Contents';
5096: } else {
5097: $breadtext .= ' (View-only mode)';
5098: $breadtitle = 'Viewing '.$crstype.' Contents';
5099: }
1.484.2.44 raeburn 5100: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5101: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5102: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5103: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5104: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5105: $breadtitle)
1.484.2.44 raeburn 5106: );
1.484.2.19 raeburn 5107: } elsif ($r->uri eq '/adm/supplemental') {
5108: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5109: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5110: {'bread_crumbs' => $brcrum,}));
5111: } else {
1.484.2.67 raeburn 5112: my ($breadtext,$breadtitle,$helpitem);
5113: $breadtext = "$crstype Editor";
5114: if ($canedit) {
5115: $breadtitle = 'Editing '.$crstype.' Contents';
5116: $helpitem = 'Docs_Adding_Course_Doc';
5117: } else {
5118: $breadtext .= ' (View-only mode)';
5119: $breadtitle = 'Viewing '.$crstype.' Contents';
5120: $helpitem = 'Docs_Viewing_Course_Doc';
5121: }
1.392 raeburn 5122: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5123: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5124: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5125: {'add_entries' => $addentries}
5126: )
1.392 raeburn 5127: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5128: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5129: $breadtitle,
5130: $helpitem)
1.392 raeburn 5131: );
5132: }
1.364 bisitz 5133:
1.329 droeschl 5134: my %allfiles = ();
5135: my %codebase = ();
1.440 raeburn 5136: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5137: if ($canedit) {
1.329 droeschl 5138: if (($env{'form.uploaddoc.filename'}) &&
5139: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5140: my $context = $1;
5141: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5142: undef($hadchanges);
1.440 raeburn 5143: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5144: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5145: undef($navmap);
1.329 droeschl 5146: if ($hadchanges) {
5147: &mark_hash_old();
5148: }
1.440 raeburn 5149: $r->print($upload_output);
5150: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5151: # Process file upload - phase two - upload embedded objects
5152: $uploadphase = 'check_embedded';
5153: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5154: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5155: $env{'form.newidx'});
5156: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5157: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5158: my ($destination,$dir_root) = &embedded_destination();
5159: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5160: my $actionurl = '/adm/coursedocs';
5161: my ($result,$flag) =
5162: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5163: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5164: $actionurl);
5165: $r->print($result.&return_to_editor());
5166: } elsif ($env{'form.phase'} eq 'check_embedded') {
5167: # Process file upload - phase three - modify references in HTML file
5168: $uploadphase = 'modified_orightml';
5169: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5170: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5171: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5172: my $result =
5173: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5174: $docuname,$docudom,undef,
5175: $dir_root);
5176: $r->print($result.&return_to_editor());
1.476 raeburn 5177: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5178: $uploadphase = 'decompress_phase_one';
5179: $r->print(&decompression_phase_one().
5180: &return_to_editor());
5181: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5182: $uploadphase = 'decompress_phase_two';
5183: $r->print(&decompression_phase_two().
5184: &return_to_editor());
1.329 droeschl 5185: }
5186: }
5187:
1.484 raeburn 5188: if ($allowed && $toolsflag) {
5189: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5190: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5191: $r->print(&endContentScreen());
5192: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5193: # -----------------------------------------------------------------------------
5194: my %lt=&Apache::lonlocal::texthash(
5195: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5196: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5197: 'upld' => 'Upload Content',
1.329 droeschl 5198: 'srch' => 'Search',
5199: 'impo' => 'Import',
1.484.2.19 raeburn 5200: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5201: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5202: 'selm' => 'Select Map',
5203: 'load' => 'Load Map',
5204: 'newf' => 'New Folder',
5205: 'newp' => 'New Composite Page',
5206: 'syll' => 'Syllabus',
1.425 raeburn 5207: 'navc' => 'Table of Contents',
1.343 biermanm 5208: 'sipa' => 'Simple Course Page',
1.329 droeschl 5209: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5210: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5211: 'drbx' => 'Drop Box',
1.451 www 5212: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5213: 'bull' => 'Discussion Board',
1.347 weissno 5214: 'mypi' => 'My Personal Information Page',
1.353 weissno 5215: 'grpo' => 'Group Portfolio',
1.329 droeschl 5216: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5217: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5218: 'imsf' => 'IMS Upload',
5219: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5220: 'cms' => 'Origin of IMS package',
5221: 'se' => 'Select',
1.484.2.19 raeburn 5222: 'file' => 'File',
1.329 droeschl 5223: 'title' => 'Title',
5224: 'comment' => 'Comment',
1.403 raeburn 5225: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5226: 'bb5' => 'Blackboard 5',
5227: 'bb6' => 'Blackboard 6',
5228: 'angel5' => 'ANGEL 5.5',
5229: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5230: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5231: );
1.329 droeschl 5232: # -----------------------------------------------------------------------------
1.484.2.64 raeburn 5233: # Calculate free quota space for a user or course.
5234: my $quotatype = 'unofficial';
5235: if ($crstype eq 'Community') {
5236: $quotatype = 'community';
5237: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5238: $quotatype = 'official';
5239: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5240: $quotatype = 'textbook';
5241: }
5242: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5243: 'course',$quotatype); # expressed in MB
5244: my $current_disk_usage = 0;
5245: foreach my $subdir ('docs','supplemental') {
5246: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5247: "userfiles/$subdir",1); # expressed in kB
5248: }
5249: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5250: my $usage = $current_disk_usage/1024; # in MB
5251: my $quota = $disk_quota;
5252: my $percent;
5253: if ($disk_quota == 0) {
5254: $percent = 100.0;
5255: } else {
1.484.2.69 raeburn 5256: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5257: }
5258: $usage = sprintf("%.2f",$usage);
5259: $quota = sprintf("%.2f",$quota);
5260: $percent = sprintf("%.0f",$percent);
5261: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5262: $percent.'%',$quota.' MB').'</p>';
5263:
1.329 droeschl 5264: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5265: $quotainfo
1.329 droeschl 5266: $lt{'file'}:<br />
1.484.2.67 raeburn 5267: <input type="file" name="uploaddoc" size="40" $disabled />
1.329 droeschl 5268: FIUP
5269:
5270: my $checkbox=(<<CHBO);
5271: <!-- <label>$lt{'parse'}?
5272: <input type="checkbox" name="parserflag" />
5273: </label> -->
5274: <label>
1.484.2.67 raeburn 5275: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5276: </label>
5277: CHBO
1.484.2.12 raeburn 5278: my $imsfolder = $env{'form.folder'};
5279: if ($imsfolder eq '') {
1.484.2.19 raeburn 5280: $imsfolder = 'default';
1.484.2.12 raeburn 5281: }
5282: my $imspform=(<<IMSFORM);
5283: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5284: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5285: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5286: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5287: <legend>$lt{'imsf'}</legend>
5288: $fileupload
5289: <br />
5290: <p>
1.484.2.19 raeburn 5291: $lt{'cms'}:
1.484.2.67 raeburn 5292: <select name="source" $disabled>
1.484.2.12 raeburn 5293: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5294: <option value="bb5">$lt{'bb5'}</option>
5295: <option value="bb6">$lt{'bb6'}</option>
5296: <option value="angel5">$lt{'angel5'}</option>
5297: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5298: </select>
5299: <input type="hidden" name="folder" value="$imsfolder" />
5300: </p>
5301: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5302: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5303: </fieldset>
5304: </form>
5305: IMSFORM
5306:
1.484.2.19 raeburn 5307: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5308: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5309: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5310: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5311: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5312: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5313: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5314: $fileupload
5315: <br />
5316: $lt{'title'}:<br />
1.484.2.67 raeburn 5317: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5318: $pathitem
1.329 droeschl 5319: <input type="hidden" name="cmd" value="upload_default" />
5320: <br />
1.458 raeburn 5321: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5322: $checkbox
5323: </span>
1.484.2.12 raeburn 5324: <br clear="all" />
1.484.2.67 raeburn 5325: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5326: </fieldset>
5327: </form>
1.383 tempelho 5328: FUFORM
1.329 droeschl 5329:
1.484.2.67 raeburn 5330: my $mapimportjs;
5331: if ($canedit) {
5332: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5333: } else {
5334: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5335: }
1.484.2.19 raeburn 5336: my $importpubform=(<<SEDFFORM);
5337: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5338: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5339: <form action="/adm/coursedocs" method="post" name="mapimportform">
5340: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5341: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5342: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5343: $lt{'copm'}<br />
5344: <span class="LC_nobreak">
1.484.2.19 raeburn 5345: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5346: onfocus="this.blur();$mapimportjs" $disabled />
5347: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5348: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5349: </fieldset>
5350: </form>
5351:
1.383 tempelho 5352: SEDFFORM
1.484.2.67 raeburn 5353:
5354: my $fromstoredjs;
5355: if ($canedit) {
5356: $fromstoredjs = 'open_StoredLinks_Import()';
5357: } else {
5358: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5359: }
5360:
1.484.2.19 raeburn 5361: my @importpubforma = (
5362: { '<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 5363: { '<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 5364: { '<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 5365: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5366: );
5367: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5368: my $extresourcesform =
5369: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5370: $help{'Adding_External_Resource'},
5371: undef,undef,$disabled);
1.329 droeschl 5372: if ($allowed) {
1.484.2.7 raeburn 5373: my $folder = $env{'form.folder'};
5374: if ($folder eq '') {
5375: $folder='default';
5376: }
1.484.2.67 raeburn 5377: if ($canedit) {
5378: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5379: if ($output) {
5380: $r->print($output);
5381: }
1.484.2.30 raeburn 5382: }
1.337 ehlerst 5383: $r->print(<<HIDDENFORM);
5384: <form name="renameform" method="post" action="/adm/coursedocs">
5385: <input type="hidden" name="title" />
5386: <input type="hidden" name="cmd" />
5387: <input type="hidden" name="markcopy" />
5388: <input type="hidden" name="copyfolder" />
5389: $containertag
5390: </form>
1.484 raeburn 5391:
1.337 ehlerst 5392: HIDDENFORM
1.484.2.17 raeburn 5393: $r->print(&makesimpleeditform($pathitem)."\n".
5394: &makedocslogform($pathitem."\n".
1.484 raeburn 5395: '<input type="hidden" name="folder" value="'.
5396: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5397: }
1.442 www 5398:
5399: # Generate the tabs
1.484.2.19 raeburn 5400: my ($mode,$needs_end);
1.472 raeburn 5401: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5402: my @folders = split('&',$env{'form.folderpath'});
5403: unless (@folders > 2) {
5404: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5405: $needs_end = 1;
5406: }
1.472 raeburn 5407: } else {
1.484 raeburn 5408: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5409: $needs_end = 1;
1.472 raeburn 5410: }
1.443 www 5411:
1.442 www 5412: #
5413:
5414: my $savefolderpath;
5415:
1.395 raeburn 5416: if ($allowed) {
1.329 droeschl 5417: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5418: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5419: $folder='default';
1.356 tempelho 5420: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5421: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5422: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5423: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5424: }
5425: my $postexec='';
5426: if ($folder eq 'default') {
1.372 bisitz 5427: $r->print('<script type="text/javascript">'."\n"
5428: .'// <![CDATA['."\n"
5429: .'this.window.name="loncapaclient";'."\n"
5430: .'// ]]>'."\n"
5431: .'</script>'."\n"
1.369 bisitz 5432: );
1.329 droeschl 5433: } else {
5434: #$postexec='self.close();';
5435: }
1.484.2.15 raeburn 5436: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5437: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5438: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5439:
5440: my $newnavform=(<<NNFORM);
5441: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5442: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5443: $pathitem
1.329 droeschl 5444: <input type="hidden" name="importdetail"
5445: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5446: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5447: $help{'Navigate_Content'}
5448: </form>
5449: NNFORM
5450: my $newsmppageform=(<<NSPFORM);
5451: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5452: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5453: $pathitem
1.329 droeschl 5454: <input type="hidden" name="importdetail" value="" />
1.423 onken 5455: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5456: $help{'Simple Page'}
1.329 droeschl 5457: </form>
5458: NSPFORM
5459:
5460: my $newsmpproblemform=(<<NSPROBFORM);
5461: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5462: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5463: $pathitem
1.329 droeschl 5464: <input type="hidden" name="importdetail" value="" />
1.423 onken 5465: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5466: $help{'Simple_Problem'}
1.329 droeschl 5467: </form>
5468:
5469: NSPROBFORM
5470:
5471: my $newdropboxform=(<<NDBFORM);
5472: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5473: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5474: $pathitem
1.329 droeschl 5475: <input type="hidden" name="importdetail" value="" />
1.423 onken 5476: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5477: $help{'Dropbox'}
1.344 bisitz 5478: </form>
1.329 droeschl 5479: NDBFORM
5480:
5481: my $newexuploadform=(<<NEXUFORM);
5482: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5483: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5484: $pathitem
1.329 droeschl 5485: <input type="hidden" name="importdetail" value="" />
1.423 onken 5486: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5487: $help{'Score_Upload_Form'}
5488: </form>
5489: NEXUFORM
5490:
5491: my $newbulform=(<<NBFORM);
5492: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5493: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5494: $pathitem
1.329 droeschl 5495: <input type="hidden" name="importdetail" value="" />
1.423 onken 5496: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5497: $help{'Bulletin Board'}
5498: </form>
5499: NBFORM
5500:
5501: my $newaboutmeform=(<<NAMFORM);
5502: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5503: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5504: $pathitem
1.329 droeschl 5505: <input type="hidden" name="importdetail"
5506: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5507: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5508: $help{'My Personal Information Page'}
1.329 droeschl 5509: </form>
5510: NAMFORM
5511:
5512: my $newaboutsomeoneform=(<<NASOFORM);
5513: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5514: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5515: $pathitem
1.329 droeschl 5516: <input type="hidden" name="importdetail" value="" />
1.423 onken 5517: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5518: </form>
5519: NASOFORM
5520:
5521: my $newrosterform=(<<NROSTFORM);
5522: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5523: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5524: $pathitem
1.329 droeschl 5525: <input type="hidden" name="importdetail"
5526: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5527: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5528: $help{'Course_Roster'}
1.329 droeschl 5529: </form>
5530: NROSTFORM
5531:
1.484.2.27 raeburn 5532: my $newwebpage;
5533: if ($folder =~ /^default_?(\d*)$/) {
5534: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5535: if ($1) {
5536: $newwebpage .= $1;
5537: } else {
5538: $newwebpage .= 'default';
5539: }
5540: $newwebpage .= '/new.html';
5541: }
5542: my $newwebpageform =(<<NWEBFORM);
5543: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5544: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5545: $pathitem
5546: <input type="hidden" name="importdetail" value="$newwebpage" />
5547: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5548: $help{'Web_Page'}
1.484.2.27 raeburn 5549: </form>
5550: NWEBFORM
1.484.2.30 raeburn 5551:
1.484.2.27 raeburn 5552:
1.342 ehlerst 5553: my $specialdocumentsform;
1.383 tempelho 5554: my @specialdocumentsforma;
1.451 www 5555: my $gradingform;
5556: my @gradingforma;
5557: my $communityform;
5558: my @communityforma;
1.351 ehlerst 5559: my $newfolderform;
1.390 tempelho 5560: my $newfolderb;
1.342 ehlerst 5561:
1.451 www 5562: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5563:
1.329 droeschl 5564: my $newpageform=(<<NPFORM);
5565: <form action="/adm/coursedocs" method="post" name="newpage">
5566: <input type="hidden" name="folderpath" value="$path" />
5567: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5568: <input type="hidden" name="active" value="ee" />
1.423 onken 5569: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5570: $help{'Adding_Pages'}
1.329 droeschl 5571: </form>
5572: NPFORM
1.390 tempelho 5573:
5574:
1.351 ehlerst 5575: $newfolderform=(<<NFFORM);
1.329 droeschl 5576: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5577: $pathitem
1.329 droeschl 5578: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5579: <input type="hidden" name="active" value="" />
1.422 onken 5580: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5581: </form>
5582: NFFORM
5583:
5584: my $newsylform=(<<NSYLFORM);
5585: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5586: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5587: $pathitem
1.329 droeschl 5588: <input type="hidden" name="importdetail"
5589: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5590: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5591: $help{'Syllabus'}
1.383 tempelho 5592:
1.329 droeschl 5593: </form>
5594: NSYLFORM
1.364 bisitz 5595:
1.329 droeschl 5596: my $newgroupfileform=(<<NGFFORM);
5597: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5598: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5599: $pathitem
1.329 droeschl 5600: <input type="hidden" name="importdetail"
5601: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5602: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5603: $help{'Group Portfolio'}
1.329 droeschl 5604: </form>
5605: NGFFORM
1.383 tempelho 5606: @specialdocumentsforma=(
1.421 onken 5607: {'<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 5608: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5609: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5610: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5611: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5612: );
5613: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5614:
1.434 raeburn 5615:
5616: my @importdoc = (
1.484.2.19 raeburn 5617: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5618: );
5619: unless ($container eq 'page') {
5620: push(@importdoc,
5621: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5622: );
5623: }
5624: push(@importdoc,
1.484.2.38 raeburn 5625: {'<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 5626: );
1.484.2.12 raeburn 5627: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5628:
1.451 www 5629: @gradingforma=(
5630: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5631: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5632: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5633:
5634: );
5635: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5636:
5637: @communityforma=(
5638: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5639: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5640: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5641: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5642: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5643: );
5644: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5645:
1.330 tempelho 5646: my %orderhash = (
1.484.2.36 raeburn 5647: 'aa' => ['Upload',$fileuploadform],
5648: 'bb' => ['Import',$importpubform],
5649: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5650: );
1.484.2.19 raeburn 5651: unless ($container eq 'page') {
1.434 raeburn 5652: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5653: $orderhash{'dd'} = ['Collaboration',$communityform];
1.484.2.36 raeburn 5654: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5655: }
5656:
1.341 ehlerst 5657: $hadchanges=0;
1.484 raeburn 5658: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5659: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5660: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.68 raeburn 5661: $canedit,\$navmap,$hiddentop);
1.484.2.67 raeburn 5662: undef($navmap);
1.443 www 5663: if ($error) {
5664: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5665: }
5666: if ($hadchanges) {
1.484.2.73 raeburn 5667: unless (&is_hash_old()) {
5668: &mark_hash_old();
5669: }
1.443 www 5670: }
1.341 ehlerst 5671:
1.443 www 5672: &changewarning($r,'');
5673: }
1.458 raeburn 5674: }
1.442 www 5675:
1.443 www 5676: # Supplemental documents start here
5677:
1.329 droeschl 5678: my $folder=$env{'form.folder'};
1.443 www 5679: unless ($supplementalflag) {
1.329 droeschl 5680: $folder='supplemental';
5681: }
5682: if ($folder =~ /^supplemental$/ &&
5683: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5684: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5685: } elsif ($allowed) {
1.356 tempelho 5686: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5687: }
1.484.2.17 raeburn 5688: $pathitem = '<input type="hidden" name="folderpath" value="'.
5689: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5690: if ($allowed) {
5691: my $folderseq=
1.484.2.15 raeburn 5692: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5693:
5694: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 5695: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5696: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5697: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 5698: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 5699: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5700: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5701: $fileupload
5702: <br />
5703: <br />
5704: <span class="LC_nobreak">
5705: $checkbox
5706: </span>
5707: <br /><br />
5708: $lt{'comment'}:<br />
1.383 tempelho 5709: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5710: <br />
1.484.2.19 raeburn 5711: $pathitem
1.329 droeschl 5712: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 5713: <input type='submit' value="$lt{'upld'}" />
5714: </form>
1.484.2.19 raeburn 5715: SUPDOCFORM
1.329 droeschl 5716:
5717: my $supnewfolderform=(<<SNFFORM);
5718: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 5719: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 5720: $pathitem
1.329 droeschl 5721: <input type="hidden" name="importdetail" value="" />
1.423 onken 5722: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 5723: $help{'Adding_Folders'}
1.329 droeschl 5724: </form>
5725: SNFFORM
1.383 tempelho 5726:
1.484.2.19 raeburn 5727: my $supextform =
5728: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5729: $help{'Adding_External_Resource'},
5730: undef,undef,$disabled);
1.329 droeschl 5731:
5732: my $supnewsylform=(<<SNSFORM);
5733: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 5734: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5735: $pathitem
1.329 droeschl 5736: <input type="hidden" name="importdetail"
5737: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5738: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 5739: $help{'Syllabus'}
5740: </form>
5741: SNSFORM
5742:
5743: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 5744: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 5745: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5746: $pathitem
1.329 droeschl 5747: <input type="hidden" name="importdetail"
5748: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5749: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 5750: $help{'My Personal Information Page'}
1.329 droeschl 5751: </form>
5752: SNAMFORM
5753:
1.484.2.27 raeburn 5754: my $supwebpage;
5755: if ($folder =~ /^supplemental_?(\d*)$/) {
5756: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5757: if ($1) {
5758: $supwebpage .= $1;
5759: } else {
5760: $supwebpage .= 'default';
5761: }
5762: $supwebpage .= '/new.html';
5763: }
5764: my $supwebpageform =(<<SWEBFORM);
5765: <form action="/adm/coursedocs" method="post" name="supwebpage">
5766: <input type="hidden" name="active" value="cc" />
5767: $pathitem
5768: <input type="hidden" name="importdetail" value="$supwebpage" />
5769: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 5770: $help{'Web_Page'}
1.484.2.27 raeburn 5771: </form>
5772: SWEBFORM
5773:
1.333 muellerd 5774:
1.383 tempelho 5775: my @specialdocs = (
1.484.2.67 raeburn 5776: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 5777: =>$supnewsylform},
1.484.2.67 raeburn 5778: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 5779: =>$supnewaboutmeform},
1.484.2.27 raeburn 5780: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
5781:
1.383 tempelho 5782: );
1.417 droeschl 5783: my @supimportdoc = (
1.484.2.19 raeburn 5784: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 5785: =>$supextform},
5786: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
5787: =>$supupdocform},
1.484.2.19 raeburn 5788: );
5789:
1.484.2.12 raeburn 5790: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 5791: my %suporderhash = (
1.390 tempelho 5792: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 5793: 'ee' => ['Upload',$supupdocform],
5794: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 5795: );
1.443 www 5796: if ($supplementalflag) {
1.458 raeburn 5797: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5798: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
5799: $canedit);
1.443 www 5800: if ($error) {
5801: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 5802: } else {
5803: if ($suppchanges) {
5804: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
5805: my @ids=&Apache::lonnet::current_machine_ids();
5806: foreach my $server (keys(%servers)) {
5807: next if (grep(/^\Q$server\E$/,@ids));
5808: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 5809: my $cachekey = &escape('suppcount').':'.&escape($hashid);
5810: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 5811: }
5812: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
5813: undef($suppchanges);
5814: }
1.443 www 5815: }
1.393 raeburn 5816: }
1.443 www 5817: } elsif ($supplementalflag) {
1.458 raeburn 5818: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 5819: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 5820: if ($error) {
5821: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 5822: }
1.393 raeburn 5823: }
1.389 tempelho 5824:
1.484.2.19 raeburn 5825: if ($needs_end) {
5826: $r->print(&endContentScreen());
5827: }
1.383 tempelho 5828:
1.329 droeschl 5829: if ($allowed) {
5830: $r->print('
5831: <form method="post" name="extimport" action="/adm/coursedocs">
5832: <input type="hidden" name="title" />
5833: <input type="hidden" name="url" />
5834: <input type="hidden" name="useform" />
5835: <input type="hidden" name="residx" />
5836: </form>');
5837: }
1.484 raeburn 5838: } elsif ($showdoc) {
1.329 droeschl 5839: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 5840: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 5841: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 5842: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 5843: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 5844: }
5845: }
5846: $r->print(&Apache::loncommon::end_page());
5847: return OK;
1.364 bisitz 5848: }
1.329 droeschl 5849:
1.440 raeburn 5850: sub embedded_form_elems {
5851: my ($phase,$primaryurl,$newidx) = @_;
5852: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5853: return <<STATE;
5854: <input type="hidden" name="folderpath" value="$folderpath" />
5855: <input type="hidden" name="cmd" value="upload_embedded" />
5856: <input type="hidden" name="newidx" value="$newidx" />
5857: <input type="hidden" name="phase" value="$phase" />
5858: <input type="hidden" name="primaryurl" value="$primaryurl" />
5859: STATE
5860: }
5861:
5862: sub embedded_destination {
5863: my $folder=$env{'form.folder'};
5864: my $destination = 'docs/';
5865: if ($folder =~ /^supplemental/) {
5866: $destination = 'supplemental/';
5867: }
5868: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5869: $destination .= 'default/';
5870: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5871: $destination .= $2.'/';
5872: }
5873: $destination .= $env{'form.newidx'};
5874: my $dir_root = '/userfiles';
5875: return ($destination,$dir_root);
5876: }
5877:
5878: sub return_to_editor {
5879: my $actionurl = '/adm/coursedocs';
5880: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
5881: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
5882: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
5883: '</a></p>';
5884: }
5885:
1.476 raeburn 5886: sub decompression_info {
5887: my ($destination,$dir_root) = &embedded_destination();
5888: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5889: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5890: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5891: my $container='sequence';
1.480 raeburn 5892: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 5893: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 5894: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 5895: $container='page';
5896: }
1.480 raeburn 5897: unshift(@hiddens,$pathitem);
5898: foreach my $item (@hiddens) {
5899: if ($env{'form.'.$item}) {
5900: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 5901: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 5902: }
1.477 raeburn 5903: }
1.476 raeburn 5904: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
5905: $hiddenelem);
5906: }
5907:
5908: sub decompression_phase_one {
5909: my ($dir,$file,$warning,$error,$output);
5910: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5911: &decompression_info();
1.484.2.7 raeburn 5912: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 5913: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
5914: } else {
5915: my $file = $1;
1.481 raeburn 5916: $output =
5917: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
5918: $destination,$dir_root,
5919: $hiddenelem);
5920: if ($env{'form.autoextract_camtasia'}) {
5921: $output .= &remove_archive($docudom,$docuname,$container);
5922: }
1.476 raeburn 5923: }
5924: if ($error) {
5925: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
5926: $error.'</p>'."\n";
5927: }
5928: if ($warning) {
5929: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
5930: }
5931: return $output;
5932: }
5933:
5934: sub decompression_phase_two {
5935: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5936: &decompression_info();
1.481 raeburn 5937: my $output;
1.480 raeburn 5938: if ($env{'form.archivedelete'}) {
1.481 raeburn 5939: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 5940: }
5941: $output .=
1.481 raeburn 5942: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 5943: $destination,$dir_root,$hiddenelem);
5944: return $output;
5945: }
5946:
1.480 raeburn 5947: sub remove_archive {
5948: my ($docudom,$docuname,$container) = @_;
5949: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 5950: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 5951: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
5952: if ($fatal) {
5953: if ($container eq 'page') {
5954: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
5955: } else {
5956: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
5957: }
1.484.2.54 raeburn 5958: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5959: } else {
5960: my $currcmd = $env{'form.cmd'};
5961: my $position = $env{'form.position'};
1.484.2.54 raeburn 5962: my $archiveidx = $position;
5963: if ($position > 0) {
5964: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
5965: $archiveidx = $position-1;
5966: }
5967: $env{'form.cmd'} = 'remove_'.$archiveidx;
5968: my ($title,$url,@rrest) =
5969: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
5970: if ($url eq $env{'form.archiveurl'}) {
5971: if (&handle_edit_cmd($docuname,$docudom)) {
5972: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
5973: if ($fatal) {
5974: if ($container eq 'page') {
5975: $delwarning = &mt('An error occurred updating the contents of the current page.');
5976: } else {
5977: $delwarning = &mt('An error occurred updating the contents of the current folder.');
5978: }
1.480 raeburn 5979: } else {
1.484.2.54 raeburn 5980: $delresult = &mt('Archive file removed.');
1.480 raeburn 5981: }
5982: }
1.484.2.54 raeburn 5983: } else {
5984: $delwarning .= &mt('Archive file had unexpected item number in folder.').
5985: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5986: }
5987: }
5988: $env{'form.cmd'} = $currcmd;
5989: }
5990: if ($delwarning) {
5991: $output = '<p class="LC_warning">'.
5992: $delwarning.
5993: '</p>';
5994: }
5995: if ($delresult) {
5996: $output .= '<p class="LC_info">'.
5997: $delresult.
5998: '</p>';
5999: }
1.481 raeburn 6000: return $output;
1.480 raeburn 6001: }
6002:
1.484 raeburn 6003: sub generate_admin_menu {
1.484.2.67 raeburn 6004: my ($crstype,$canedit) = @_;
1.484 raeburn 6005: my $lc_crstype = lc($crstype);
6006: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6007: my %lt= ( # do not translate here
1.484 raeburn 6008: 'vc' => 'Verify Content',
6009: 'cv' => 'Check/Set Resource Versions',
6010: 'ls' => 'List Resource Identifiers',
6011: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6012: 'dcd' => "Copy $crstype Content to Authoring Space",
6013: );
1.484 raeburn 6014: my ($candump,$dumpurl);
6015: if ($home + $other > 0) {
6016: $candump = 'F';
6017: if ($home) {
6018: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6019: } else {
6020: my @hosts;
6021: foreach my $aurole (keys(%outhash)) {
6022: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6023: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6024: }
1.484 raeburn 6025: }
6026: if (@hosts == 1) {
6027: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6028: '&role='.
6029: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6030: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6031: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6032: } else {
6033: $dumpurl = "javascript:choose_switchserver_window()";
6034: }
6035: }
6036: }
6037: my @menu=
6038: ({ categorytitle=>'Administration',
6039: items =>[
6040: { linktext => $lt{'vc'},
6041: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6042: permission => 'F',
1.484.2.44 raeburn 6043: help => 'Docs_Verify_Content',
1.484 raeburn 6044: icon => 'verify.png',
6045: linktitle => 'Verify contents can be retrieved/rendered',
6046: },
6047: { linktext => $lt{'cv'},
6048: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6049: permission => 'F',
1.484.2.44 raeburn 6050: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6051: icon => 'resversion.png',
6052: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6053: },
6054: { linktext => $lt{'ls'},
6055: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6056: permission => 'F',
6057: #help => '',
6058: icon => 'symbs.png',
6059: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6060: },
6061: ]
1.484.2.67 raeburn 6062: });
6063: if ($canedit) {
6064: push(@menu,
1.484 raeburn 6065: { categorytitle=>'Export',
6066: items =>[
6067: { linktext => $lt{'imse'},
6068: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6069: permission => 'F',
6070: help => 'Docs_Export_Course_Docs',
6071: icon => 'imsexport.png',
6072: linktitle => $lt{'imse'},
6073: },
6074: { linktext => $lt{'dcd'},
6075: url => $dumpurl,
6076: permission => $candump,
1.484.2.44 raeburn 6077: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6078: icon => 'dump.png',
6079: linktitle => $lt{'dcd'},
6080: },
6081: ]
6082: });
1.484.2.67 raeburn 6083: }
1.484 raeburn 6084: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6085: '<input type="hidden" id="dummy" />'."\n".
6086: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6087: '</form>';
1.329 droeschl 6088: }
6089:
6090: sub generate_edit_table {
1.484.2.30 raeburn 6091: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6092: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6093: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6094: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6095: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6096: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6097: $activetab = $env{'form.active'};
6098: }
1.484.2.67 raeburn 6099: unless ($canedit) {
6100: $disabled = ' disabled="disabled"';
6101: }
1.472 raeburn 6102: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6103: my $backtext = &mt('Exit Editor');
1.458 raeburn 6104: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6105: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6106: '<li class="goback">'.
1.484.2.32 raeburn 6107: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6108: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6109: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6110: '<li>'.
6111: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6112: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6113: if ($env{'form.docslog'}) {
6114: $form .= '<li class="active">';
6115: } else {
6116: $form .= '<li>';
6117: }
6118: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6119: &mt('History').'</a></li>'."\n";
6120: if ($env{'form.docslog'}) {
6121: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6122: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6123: }
1.458 raeburn 6124: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6125: if($name ne '00'){
1.371 tempelho 6126: if($activetab eq '' || $activetab ne $name){
6127: $active = '';
6128: }elsif($activetab eq $name){
6129: $active = 'class="active"';
6130: }
1.458 raeburn 6131: $form .= '<li style="float:right" '.$active
1.484 raeburn 6132: .' 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 6133: } else {
1.484.2.43 raeburn 6134: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6135:
6136: }
1.329 droeschl 6137: }
1.484 raeburn 6138: $form .= '</ul>'."\n";
6139: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6140:
6141: if ($to_show ne '') {
1.484.2.30 raeburn 6142: my $saveform;
6143: if ($need_save) {
6144: my $button = &mt('Make changes');
6145: my $path;
6146: if ($env{'form.folderpath'}) {
6147: $path =
6148: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6149: }
6150: $saveform = <<"END";
6151: <div id="multisave" style="display:none; clear:both;" >
6152: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6153: <input type="hidden" name="folderpath" value="$path" />
6154: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6155: <input type="hidden" name="allhiddenresource" value="" />
6156: <input type="hidden" name="allencrypturl" value="" />
6157: <input type="hidden" name="allrandompick" value="" />
6158: <input type="hidden" name="allrandomorder" value="" />
6159: <input type="hidden" name="changeparms" value="" />
6160: <input type="hidden" name="multiremove" value="" />
6161: <input type="hidden" name="multicut" value="" />
6162: <input type="hidden" name="multicopy" value="" />
6163: <input type="hidden" name="multichange" value="" />
6164: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6165: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6166: </form>
6167: </div>
6168: END
6169: }
6170: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6171: }
1.363 ehlerst 6172: foreach my $field (keys(%orderhash)){
1.390 tempelho 6173: if($field ne '00'){
1.422 onken 6174: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6175: $active = 'style="display: none;float:left"';
1.422 onken 6176: }elsif($activetab eq $field){
1.458 raeburn 6177: $active = 'style="display:block;float:left"';
1.422 onken 6178: }
6179: $form .= '<div id="'.$field.$tid.'"'
6180: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6181: .'</div>'."\n";
1.363 ehlerst 6182: }
6183: }
1.484 raeburn 6184: unless ($env{'form.docslog'}) {
6185: $form .= '</div></div>'."\n";
6186: }
1.329 droeschl 6187: return $form;
6188: }
6189:
6190: sub editing_js {
1.484.2.67 raeburn 6191: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$canedit,$navmapref) = @_;
1.484.2.61 raeburn 6192: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6193: p_mnf => 'Name of New Folder',
6194: t_mnf => 'New Folder',
6195: p_mnp => 'Name of New Page',
6196: t_mnp => 'New Page',
1.451 www 6197: p_mxu => 'Title for the External Score',
1.349 biermanm 6198: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6199: p_msb => 'Title for the Problem',
6200: p_mdb => 'Title for the Drop Box',
1.336 schafran 6201: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6202: p_mwp => 'Title for Web Page',
1.348 weissno 6203: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6204: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6205: p_mab_alrt1 => 'Not a valid user:domain',
6206: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6207: p_chn => 'New Title',
6208: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6209: p_rmr2a => 'Remove',
6210: p_rmr2b => '?',
6211: p_rmr3a => 'Remove those',
6212: p_rmr3b => 'items?',
6213: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6214: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6215: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6216: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6217: p_ctr2a => 'Cut',
6218: p_ctr2b => '?',
6219: p_ctr3a => 'Cut those',
6220: p_ctr3b => 'items?',
1.478 raeburn 6221: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6222: imsfile => 'You must choose an IMS package for import',
6223: imscms => 'You must select which Course Management System was the source of the IMS package',
6224: invurl => 'Invalid URL',
6225: titbl => 'Title is blank',
1.484.2.30 raeburn 6226: more => '(More ...)',
6227: less => '(Less ...)',
6228: noor => 'No actions selected or changes to settings specified.',
6229: noch => 'No changes to settings specified.',
6230: noac => 'No actions selected.',
1.484.2.67 raeburn 6231: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6232: );
6233:
1.484.2.61 raeburn 6234: &js_escape(\%js_lt);
1.433 raeburn 6235: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6236: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6237: my $main_container_page;
1.484.2.19 raeburn 6238: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6239: $main_container_page = 1;
1.434 raeburn 6240: }
1.484.2.67 raeburn 6241: my $backtourl;
6242: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6243: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6244:
1.484.2.21 raeburn 6245: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6246: my $caller = $1;
6247: if ($caller =~ /^supplemental/) {
6248: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6249: } else {
6250: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6251: $res = &Apache::lonnet::clutter($res);
6252: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6253: my ($url,$anchor);
6254: if ($res =~ /^([^#]+)#([^#]+)$/) {
6255: $url = $1;
6256: $anchor = $2;
6257: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6258: $caller = $1.&escape('#').$anchor;
6259: }
1.484.2.67 raeburn 6260: } else {
6261: $url = $res;
1.484.2.66 raeburn 6262: }
6263: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.484.2.21 raeburn 6264: &HTML::Entities::encode($caller,'<>&"');
1.484.2.66 raeburn 6265: if ($anchor ne '') {
6266: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6267: }
1.484.2.57 raeburn 6268: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6269: } else {
6270: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6271: }
6272: }
6273: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6274: $backtourl = '/adm/menu';
6275: } elsif ($supplementalflag) {
1.472 raeburn 6276: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6277: } else {
6278: $backtourl = '/adm/navmaps';
1.472 raeburn 6279: }
6280:
1.484.2.19 raeburn 6281: my $fieldsets = "'ext','doc'";
6282: unless ($main_container_page) {
6283: $fieldsets .=",'ims'";
6284: }
1.484.2.12 raeburn 6285: if ($supplementalflag) {
6286: $fieldsets = "'suppext','suppdoc'";
6287: }
6288:
1.484.2.67 raeburn 6289: my $jsmakefunctions;
6290: if ($canedit) {
6291: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6292: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6293: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6294: if (foldername) {
6295: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6296: targetform.submit();
6297: }
6298: }
6299:
6300: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6301: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6302: if (pagename) {
6303: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6304: targetform.submit();
6305: }
6306: }
6307:
6308: function makeexamupload() {
1.484.2.61 raeburn 6309: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6310: if (title) {
1.329 droeschl 6311: this.document.forms.newexamupload.importdetail.value=
6312: escape(title)+'=/res/lib/templates/examupload.problem';
6313: this.document.forms.newexamupload.submit();
6314: }
6315: }
6316:
6317: function makesmppage() {
1.484.2.61 raeburn 6318: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6319: if (title) {
1.329 droeschl 6320: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6321: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6322: this.document.forms.newsmppg.submit();
6323: }
6324: }
6325:
1.484.2.27 raeburn 6326: function makewebpage(type) {
1.484.2.61 raeburn 6327: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6328: var formname;
6329: if (type == 'supp') {
6330: formname = this.document.forms.supwebpage;
6331: } else {
6332: formname = this.document.forms.newwebpage;
6333: }
6334: if (title) {
6335: var webpage = formname.importdetail.value;
6336: formname.importdetail.value = escape(title)+'='+webpage;
6337: formname.submit();
6338: }
6339: }
6340:
1.329 droeschl 6341: function makesmpproblem() {
1.484.2.61 raeburn 6342: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6343: if (title) {
1.329 droeschl 6344: this.document.forms.newsmpproblem.importdetail.value=
6345: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6346: this.document.forms.newsmpproblem.submit();
6347: }
6348: }
6349:
6350: function makedropbox() {
1.484.2.61 raeburn 6351: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6352: if (title) {
1.329 droeschl 6353: this.document.forms.newdropbox.importdetail.value=
6354: escape(title)+'=/res/lib/templates/DropBox.problem';
6355: this.document.forms.newdropbox.submit();
6356: }
6357: }
6358:
6359: function makebulboard() {
1.484.2.61 raeburn 6360: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6361: if (title) {
6362: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6363: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6364: this.document.forms.newbul.submit();
6365: }
6366: }
6367:
6368: function makeabout() {
1.484.2.61 raeburn 6369: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6370: if (user) {
6371: var comp=new Array();
6372: comp=user.split(':');
6373: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6374: if ((comp[0]) && (comp[1])) {
6375: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6376: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6377: this.document.forms.newaboutsomeone.submit();
6378: } else {
6379: alert("$js_lt{'p_mab_alrt1'}");
6380: }
6381: } else {
6382: alert("$js_lt{'p_mab_alrt2'}");
6383: }
6384: }
1.335 ehlerst 6385: }
1.484.2.67 raeburn 6386:
6387: function makenew(targetform) {
6388: targetform.submit();
1.335 ehlerst 6389: }
1.484.2.67 raeburn 6390:
6391: function changename(folderpath,index,oldtitle) {
6392: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6393: if (title) {
6394: this.document.forms.renameform.markcopy.value='';
6395: this.document.forms.renameform.title.value=title;
6396: this.document.forms.renameform.cmd.value='rename_'+index;
6397: this.document.forms.renameform.folderpath.value=folderpath;
6398: this.document.forms.renameform.submit();
6399: }
1.329 droeschl 6400: }
6401:
1.484.2.67 raeburn 6402: ENDNEWSCRIPT
6403: } else {
6404: $jsmakefunctions = <<ENDNEWSCRIPT;
6405:
6406: function makenewfolder() {
6407: alert("$js_lt{'edri'}");
6408: }
6409:
6410: function makenewpage() {
6411: alert("$js_lt{'edri'}");
6412: }
6413:
6414: function makeexamupload() {
6415: alert("$js_lt{'edri'}");
6416: }
6417:
6418: function makesmppage() {
6419: alert("$js_lt{'edri'}");
6420: }
6421:
6422: function makewebpage(type) {
6423: alert("$js_lt{'edri'}");
6424: }
6425:
6426: function makesmpproblem() {
6427: alert("$js_lt{'edri'}");
6428: }
6429:
6430: function makedropbox() {
6431: alert("$js_lt{'edri'}");
6432: }
6433:
6434: function makebulboard() {
6435: alert("$js_lt{'edri'}");
6436: }
6437:
6438: function makeabout() {
6439: alert("$js_lt{'edri'}");
6440: }
6441:
6442: function changename() {
6443: alert("$js_lt{'edri'}");
6444: }
6445:
6446: function makenew() {
6447: alert("$js_lt{'edri'}");
6448: }
6449:
6450: function groupimport() {
6451: alert("$js_lt{'edri'}");
6452: }
6453:
6454: function groupsearch() {
6455: alert("$js_lt{'edri'}");
6456: }
6457:
6458: function groupopen(url,recover) {
6459: var options="scrollbars=1,resizable=1,menubar=0";
6460: idxflag=1;
6461: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6462: idx.focus();
6463: }
6464:
6465: ENDNEWSCRIPT
6466:
6467: }
6468: return <<ENDSCRIPT;
6469:
6470: $jsmakefunctions
6471:
1.484.2.13 raeburn 6472: function toggleUpload(caller) {
6473: var blocks = Array($fieldsets);
6474: for (var i=0; i<blocks.length; i++) {
6475: var disp = 'none';
6476: if (caller == blocks[i]) {
6477: var curr = document.getElementById('upload'+caller+'form').style.display;
6478: if (curr == 'none') {
6479: disp='block';
6480: }
6481: }
6482: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6483: }
6484: resize_scrollbox('contentscroll','1','1');
6485: return;
6486: }
6487:
1.484.2.19 raeburn 6488: function toggleMap(caller) {
1.484.2.13 raeburn 6489: var disp = 'none';
1.484.2.19 raeburn 6490: if (document.getElementById('importmapform')) {
6491: if (caller == 'map') {
6492: var curr = document.getElementById('importmapform').style.display;
6493: if (curr == 'none') {
6494: disp='block';
6495: }
1.484.2.12 raeburn 6496: }
1.484.2.19 raeburn 6497: document.getElementById('importmapform').style.display=disp;
6498: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6499: }
1.484.2.19 raeburn 6500: return;
1.329 droeschl 6501: }
6502:
1.484.2.12 raeburn 6503: function makeims(imsform) {
6504: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6505: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6506: return;
6507: }
6508: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6509: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6510: return;
6511: }
6512: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6513: imsform.submit();
6514: }
6515:
1.478 raeburn 6516: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6517: var pickitem;
6518: var picknumitem;
6519: var picknumtext;
6520: if (index == 'all') {
6521: pickitem = document.getElementById('randompickall');
6522: picknumitem = document.getElementById('rpicknumall');
6523: picknumtext = document.getElementById('rpicktextall');
6524: } else {
6525: pickitem = document.getElementById('randompick_'+index);
6526: picknumitem = document.getElementById('rpicknum_'+index);
6527: picknumtext = document.getElementById('randompicknum_'+index);
6528: }
1.478 raeburn 6529: if (pickitem.checked) {
1.484.2.61 raeburn 6530: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6531: if (picknum == '' || picknum == null) {
6532: if (caller == 'check') {
6533: pickitem.checked=false;
1.484.2.29 raeburn 6534: if (index == 'all') {
6535: picknumtext.innerHTML = '';
6536: if (caller == 'link') {
6537: propagateState(targetform,'rpicknum');
6538: }
6539: } else {
1.484.2.30 raeburn 6540: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6541: }
1.478 raeburn 6542: }
6543: } else {
6544: picknum.toString();
6545: var regexdigit=/^\\d+\$/;
6546: if (regexdigit.test(picknum)) {
6547: picknumitem.value = picknum;
1.484.2.29 raeburn 6548: if (index == 'all') {
1.484.2.30 raeburn 6549: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6550: if (caller == 'link') {
6551: propagateState(targetform,'rpicknum');
6552: }
6553: } else {
6554: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6555: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6556: }
1.478 raeburn 6557: } else {
6558: if (caller == 'check') {
1.484.2.29 raeburn 6559: if (index == 'all') {
6560: picknumtext.innerHTML = '';
6561: if (caller == 'link') {
6562: propagateState(targetform,'rpicknum');
6563: }
6564: } else {
6565: pickitem.checked=false;
1.484.2.30 raeburn 6566: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6567: }
1.478 raeburn 6568: }
6569: return;
6570: }
6571: }
6572: } else {
1.484.2.29 raeburn 6573: picknumitem.value = '';
6574: picknumtext.innerHTML = '';
6575: if (index == 'all') {
6576: if (caller == 'link') {
6577: propagateState(targetform,'rpicknum');
6578: }
6579: } else {
1.484.2.30 raeburn 6580: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6581: }
6582: }
6583: }
6584:
6585: function propagateState(form,param) {
6586: if (document.getElementById(param+'all')) {
6587: var setcheck = 0;
6588: var rpick = 0;
6589: if (param == 'rpicknum') {
6590: if (document.getElementById('randompickall')) {
6591: if (document.getElementById('randompickall').checked) {
6592: if (document.getElementById('rpicknumall')) {
6593: rpick = document.getElementById('rpicknumall').value;
6594: }
6595: }
6596: }
6597: } else {
6598: if (document.getElementById(param+'all').checked) {
6599: setcheck = 1;
6600: }
6601: }
1.484.2.30 raeburn 6602: var allidxlist;
6603: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6604: if (document.getElementById('all'+param+'idx')) {
6605: allidxlist = document.getElementById('all'+param+'idx').value;
6606: }
6607: var actions = new Array ('remove','cut','copy');
6608: for (var i=0; i<actions.length; i++) {
6609: if (actions[i] != param) {
6610: if (document.getElementById(actions[i]+'all')) {
6611: document.getElementById(actions[i]+'all').checked = false;
6612: }
6613: }
6614: }
6615: }
1.484.2.29 raeburn 6616: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6617: allidxlist = form.allidx.value;
6618: }
6619: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6620: allidxlist = form.allmapidx.value;
6621: }
6622: if ((allidxlist != '') && (allidxlist != null)) {
6623: var allidxs = allidxlist.split(',');
6624: if (allidxs.length > 1) {
6625: for (var i=0; i<allidxs.length; i++) {
6626: if (document.getElementById(param+'_'+allidxs[i])) {
6627: if (param == 'rpicknum') {
6628: if (document.getElementById('randompick_'+allidxs[i])) {
6629: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6630: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6631: if (rpick > 0) {
6632: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6633: } else {
6634: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6635: }
6636: }
6637: }
6638: } else {
1.484.2.29 raeburn 6639: if (setcheck == 1) {
6640: document.getElementById(param+'_'+allidxs[i]).checked = true;
6641: } else {
6642: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6643: if (param == 'randompick') {
6644: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6645: }
1.484.2.29 raeburn 6646: }
6647: }
6648: }
6649: }
1.484.2.30 raeburn 6650: if (setcheck == 1) {
6651: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6652: var actions = new Array('copy','cut','remove');
6653: for (var i=0; i<actions.length; i++) {
6654: var otheractions;
6655: var otheridxs;
6656: if (actions[i] === param) {
6657: continue;
6658: } else {
6659: if (document.getElementById('all'+actions[i]+'idx')) {
6660: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6661: otheridxs = otheractions.split(',');
6662: if (otheridxs.length > 1) {
6663: for (var j=0; j<otheridxs.length; j++) {
6664: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6665: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6666: }
1.484.2.29 raeburn 6667: }
6668: }
6669: }
6670: }
1.484.2.30 raeburn 6671: }
1.484.2.29 raeburn 6672: }
6673: }
6674: }
6675: }
1.478 raeburn 6676: }
1.484.2.29 raeburn 6677: return;
6678: }
6679:
1.484.2.63 raeburn 6680: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 6681: var canedit = '$canedit';
6682: if (canedit == '') {
6683: alert("$js_lt{'edri'}");
6684: return;
6685: }
1.484.2.30 raeburn 6686: var dosettings;
6687: var doaction;
6688: var control = document.togglemultsettings;
6689: if (context == 'actions') {
6690: control = document.togglemultactions;
6691: doaction = 1;
6692: } else {
6693: dosettings = 1;
6694: }
6695: if (control) {
6696: if (control.showmultpick.length) {
6697: for (var i=0; i<control.showmultpick.length; i++) {
6698: if (control.showmultpick[i].checked) {
6699: if (control.showmultpick[i].value == 1) {
6700: if (context == 'settings') {
6701: dosettings = 0;
6702: } else {
6703: doaction = 0;
6704: }
6705: }
6706: }
6707: }
6708: }
6709: }
6710: if (context == 'settings') {
6711: if (dosettings == 1) {
6712: targetform.changeparms.value=param;
6713: targetform.submit();
6714: }
6715: }
6716: if (context == 'actions') {
6717: if (doaction == 1) {
6718: targetform.cmd.value=param+'_'+index;
6719: targetform.folderpath.value=folderpath;
6720: targetform.markcopy.value=idx+':'+param;
6721: targetform.copyfolder.value=folder+'.'+container;
6722: if (param == 'remove') {
1.484.2.63 raeburn 6723: var doremove = 0;
6724: if (skip_confirm) {
6725: if (confirm_removal) {
6726: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
6727: doremove = 1;
6728: }
6729: } else {
6730: doremove = 1;
6731: }
6732: } else {
6733: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
6734: doremove = 1;
6735: }
6736: }
6737: if (doremove) {
1.484.2.30 raeburn 6738: targetform.markcopy.value='';
6739: targetform.copyfolder.value='';
1.484.2.29 raeburn 6740: targetform.submit();
6741: }
6742: }
1.484.2.30 raeburn 6743: if (param == 'cut') {
1.484.2.61 raeburn 6744: 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 6745: targetform.submit();
6746: return;
6747: }
6748: }
6749: if (param == 'copy') {
6750: targetform.submit();
6751: return;
6752: }
6753: targetform.markcopy.value='';
6754: targetform.copyfolder.value='';
6755: targetform.cmd.value='';
6756: targetform.folderpath.value='';
6757: return;
6758: } else {
6759: if (document.getElementById(param+'_'+idx)) {
6760: item = document.getElementById(param+'_'+idx);
6761: if (item.type == 'checkbox') {
6762: if (item.checked) {
6763: item.checked = false;
6764: } else {
6765: item.checked = true;
6766: singleCheck(item,idx,param);
6767: }
6768: }
6769: }
6770: }
6771: }
6772: return;
6773: }
6774:
6775: function singleCheck(caller,idx,action) {
6776: actions = new Array('cut','copy','remove');
6777: if (caller.checked) {
6778: for (var i=0; i<actions.length; i++) {
6779: if (actions[i] != action) {
6780: if (document.getElementById(actions[i]+'_'+idx)) {
6781: if (document.getElementById(actions[i]+'_'+idx).checked) {
6782: document.getElementById(actions[i]+'_'+idx).checked = false;
6783: }
6784: }
6785: }
1.484.2.29 raeburn 6786: }
6787: }
6788: return;
1.478 raeburn 6789: }
6790:
1.334 muellerd 6791: function unselectInactive(nav) {
1.335 ehlerst 6792: currentNav = document.getElementById(nav);
6793: currentLis = currentNav.getElementsByTagName('LI');
6794: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 6795: if (currentLis[i].className == 'goback') {
6796: currentLis[i].className = 'goback';
6797: } else {
6798: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 6799: currentLis[i].className = 'right';
1.472 raeburn 6800: } else {
1.374 tempelho 6801: currentLis[i].className = 'i';
1.472 raeburn 6802: }
6803: }
1.335 ehlerst 6804: }
1.332 tempelho 6805: }
6806:
1.334 muellerd 6807: function hideAll(current, nav, data) {
1.335 ehlerst 6808: unselectInactive(nav);
1.484.2.43 raeburn 6809: if (current) {
6810: if (current.className == 'right'){
1.374 tempelho 6811: current.className = 'right active'
1.484.2.43 raeburn 6812: } else {
1.374 tempelho 6813: current.className = 'active';
1.484.2.43 raeburn 6814: }
1.374 tempelho 6815: }
1.335 ehlerst 6816: currentData = document.getElementById(data);
6817: currentDivs = currentData.getElementsByTagName('DIV');
6818: for (i = 0; i < currentDivs.length; i++) {
6819: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 6820: currentDivs[i].style.display = 'none';
1.330 tempelho 6821: }
6822: }
1.335 ehlerst 6823: }
1.330 tempelho 6824:
1.374 tempelho 6825: function openTabs(pageId) {
6826: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 6827: if(tabnav.length > 2 ){
1.389 tempelho 6828: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 6829: currentLis = currentNav.getElementsByTagName('LI');
6830: for(i = 0; i< currentLis.length; i++){
6831: if(currentLis[i].className == 'active') {
1.375 tempelho 6832: funcString = currentLis[i].onclick.toString();
6833: tab = funcString.split('"');
1.420 onken 6834: if(tab.length < 2) {
6835: tab = funcString.split("'");
6836: }
1.375 tempelho 6837: currentData = document.getElementById(tab[1]);
6838: currentData.style.display = 'block';
1.374 tempelho 6839: }
6840: }
6841: }
6842: }
6843:
1.334 muellerd 6844: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 6845: currstate = current.className;
1.334 muellerd 6846: hideAll(current, nav, data);
1.375 tempelho 6847: openTabs(pageId);
1.334 muellerd 6848: unselectInactive(nav);
1.484.2.43 raeburn 6849: if ((currstate == 'active') || (currstate == 'right active')) {
6850: if (currstate == 'active') {
6851: current.className = '';
6852: } else {
6853: current.className = 'right';
6854: }
6855: activeTab = '';
6856: toggleUpload();
6857: toggleMap();
6858: resize_scrollbox('contentscroll','1','0');
6859: return;
6860: } else {
6861: current.className = 'active';
6862: }
1.330 tempelho 6863: currentData = document.getElementById(pageId);
6864: currentData.style.display = 'block';
1.458 raeburn 6865: activeTab = pageId;
1.484.2.12 raeburn 6866: toggleUpload();
1.484.2.14 raeburn 6867: toggleMap();
1.433 raeburn 6868: if (nav == 'mainnav') {
6869: var storedpath = "$docs_folderpath";
1.434 raeburn 6870: var storedpage = "$main_container_page";
1.433 raeburn 6871: var reg = new RegExp("^supplemental");
6872: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 6873: if (storedpage == 1) {
6874: document.simpleedit.folderpath.value = '';
6875: document.uploaddocument.folderpath.value = '';
6876: } else {
6877: if (reg.test(storedpath)) {
6878: document.simpleedit.folderpath.value = '$toplevelmain';
6879: document.uploaddocument.folderpath.value = '$toplevelmain';
6880: document.newext.folderpath.value = '$toplevelmain';
6881: } else {
6882: document.simpleedit.folderpath.value = storedpath;
6883: document.uploaddocument.folderpath.value = storedpath;
6884: document.newext.folderpath.value = storedpath;
6885: }
1.433 raeburn 6886: }
6887: } else {
1.434 raeburn 6888: if (reg.test(storedpath)) {
6889: document.simpleedit.folderpath.value = storedpath;
6890: document.supuploaddocument.folderpath.value = storedpath;
6891: document.supnewext.folderpath.value = storedpath;
6892: } else {
1.433 raeburn 6893: document.simpleedit.folderpath.value = '$toplevelsupp';
6894: document.supuploaddocument.folderpath.value = '$toplevelsupp';
6895: document.supnewext.folderpath.value = '$toplevelsupp';
6896: }
6897: }
6898: }
1.484.2.3 raeburn 6899: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 6900: return false;
6901: }
1.329 droeschl 6902:
1.472 raeburn 6903: function toContents(jumpto) {
6904: var newurl = '$backtourl';
1.484.2.21 raeburn 6905: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 6906: newurl = newurl+'?postdata='+jumpto;
6907: }
6908: location.href=newurl;
6909: }
6910:
1.484.2.30 raeburn 6911: function togglePick(caller,value) {
6912: var disp = 'none';
6913: if (document.getElementById('multi'+caller)) {
6914: var curr = document.getElementById('multi'+caller).style.display;
6915: if (value == 1) {
6916: disp='block';
6917: }
6918: if (curr == disp) {
6919: return;
6920: }
6921: document.getElementById('multi'+caller).style.display=disp;
6922: if (value == 1) {
1.484.2.61 raeburn 6923: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 6924: } else {
6925: document.getElementById('more'+caller).innerHTML = '';
6926: }
6927: if (caller == 'actions') {
6928: setClass(value);
6929: setBoxes(value);
6930: }
6931: }
6932: var showButton = multiSettings();
6933: if (showButton != 1) {
6934: showButton = multiActions();
6935: }
6936: if (document.getElementById('multisave')) {
6937: if (showButton == 1) {
6938: document.getElementById('multisave').style.display='block';
6939: } else {
6940: document.getElementById('multisave').style.display='none';
6941: }
6942: }
6943: resize_scrollbox('contentscroll','1','1');
6944: return;
6945: }
6946:
6947: function toggleCheckUncheck(caller,more) {
6948: if (more == 1) {
1.484.2.61 raeburn 6949: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 6950: document.getElementById('allfields'+caller).style.display='block';
6951: } else {
1.484.2.61 raeburn 6952: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 6953: document.getElementById('allfields'+caller).style.display='none';
6954: }
6955: resize_scrollbox('contentscroll','1','1');
6956: }
6957:
6958: function multiSettings() {
6959: var inuse = 0;
6960: var settingsform = document.togglemultsettings;
6961: if (settingsform.showmultpick.length > 1) {
6962: for (var i=0; i<settingsform.showmultpick.length; i++) {
6963: if (settingsform.showmultpick[i].checked) {
6964: if (settingsform.showmultpick[i].value == 1) {
6965: inuse = 1;
6966: }
6967: }
6968: }
6969: }
6970: return inuse;
6971: }
6972:
6973: function multiActions() {
6974: var inuse = 0;
6975: var actionsform = document.togglemultactions;
6976: if (actionsform.showmultpick.length > 1) {
6977: for (var i=0; i<actionsform.showmultpick.length; i++) {
6978: if (actionsform.showmultpick[i].checked) {
6979: if (actionsform.showmultpick[i].value == 1) {
6980: inuse = 1;
6981: }
6982: }
6983: }
6984: }
6985: return inuse;
6986: }
6987:
6988: function checkSubmits() {
6989: var numchanges = 0;
6990: var form = document.saveactions;
6991: var doactions = multiActions();
6992: var cutwarnings = 0;
6993: var remwarnings = 0;
1.484.2.63 raeburn 6994: var removalinfo = 0;
1.484.2.30 raeburn 6995: if (doactions == 1) {
6996: var remidxlist = document.cumulativeactions.allremoveidx.value;
6997: if ((remidxlist != '') && (remidxlist != null)) {
6998: var remidxs = remidxlist.split(',');
6999: for (var i=0; i<remidxs.length; i++) {
7000: if (document.getElementById('remove_'+remidxs[i])) {
7001: if (document.getElementById('remove_'+remidxs[i]).checked) {
7002: form.multiremove.value += remidxs[i]+',';
7003: numchanges ++;
7004: if (document.getElementById('skip_remove_'+remidxs[i])) {
7005: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7006: remwarnings ++;
7007: }
7008: }
1.484.2.63 raeburn 7009: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7010: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7011: removalinfo ++;
7012: }
7013: }
1.484.2.30 raeburn 7014: }
7015: }
7016: }
7017: }
7018: var cutidxlist = document.cumulativeactions.allcutidx.value;
7019: if ((cutidxlist != '') && (cutidxlist != null)) {
7020: var cutidxs = cutidxlist.split(',');
7021: for (var i=0; i<cutidxs.length; i++) {
7022: if (document.getElementById('cut_'+cutidxs[i])) {
7023: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7024: form.multicut.value += cutidxs[i]+',';
7025: numchanges ++;
7026: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7027: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7028: cutwarnings ++;
7029: }
7030: }
7031: }
7032: }
7033: }
7034: }
7035: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7036: if ((copyidxlist != '') && (copyidxlist != null)) {
7037: var copyidxs = copyidxlist.split(',');
7038: for (var i=0; i<copyidxs.length; i++) {
7039: if (document.getElementById('copy_'+copyidxs[i])) {
7040: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7041: form.multicopy.value += copyidxs[i]+',';
7042: numchanges ++;
7043: }
7044: }
7045: }
7046: }
7047: if (numchanges > 0) {
7048: form.multichange.value = numchanges;
7049: }
7050: }
7051: var dosettings = multiSettings();
7052: var haschanges = 0;
7053: if (dosettings == 1) {
7054: form.allencrypturl.value = '';
7055: form.allhiddenresource.value = '';
7056: form.changeparms.value = 'all';
7057: var patt=new RegExp(",\$");
7058: var allidxlist = document.cumulativesettings.allidx.value;
7059: if ((allidxlist != '') && (allidxlist != null)) {
7060: var allidxs = allidxlist.split(',');
7061: if (allidxs.length > 1) {
7062: for (var i=0; i<allidxs.length; i++) {
7063: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7064: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7065: form.allhiddenresource.value += allidxs[i]+',';
7066: }
7067: }
7068: if (document.getElementById('encrypturl_'+allidxs[i])) {
7069: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7070: form.allencrypturl.value += allidxs[i]+',';
7071: }
1.484.2.29 raeburn 7072: }
7073: }
1.484.2.30 raeburn 7074: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7075: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7076: }
7077: }
7078: form.allrandompick.value = '';
7079: form.allrandomorder.value = '';
7080: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7081: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7082: var allmapidxs = allmapidxlist.split(',');
7083: for (var i=0; i<allmapidxs.length; i++) {
7084: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7085: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7086: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7087: if ((randompick.checked) && (rpicknum.value != '')) {
7088: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7089: }
7090: if (randorder.checked) {
7091: form.allrandomorder.value += allmapidxs[i]+',';
7092: }
7093: }
7094: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7095: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7096: }
7097: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7098: haschanges = 1;
7099: }
7100: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7101: haschanges = 1;
7102: }
7103: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7104: haschanges = 1;
7105: }
7106: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7107: haschanges = 1;
7108: }
7109: }
7110: if (doactions == 1) {
7111: if (numchanges > 0) {
1.484.2.63 raeburn 7112: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7113: if (remwarnings > 0) {
1.484.2.61 raeburn 7114: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7115: return false;
7116: }
7117: }
1.484.2.63 raeburn 7118: if (removalinfo > 0) {
7119: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7120: return false;
7121: }
7122: }
1.484.2.30 raeburn 7123: if (cutwarnings > 0) {
1.484.2.61 raeburn 7124: 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 7125: return false;
1.484.2.29 raeburn 7126: }
7127: }
7128: }
1.484.2.30 raeburn 7129: form.submit();
7130: return true;
7131: }
7132: }
7133: if (dosettings == 1) {
7134: if (haschanges == 1) {
7135: form.submit();
7136: return true;
1.484.2.29 raeburn 7137: }
7138: }
1.484.2.30 raeburn 7139: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7140: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7141: } else {
7142: if (dosettings == 1) {
1.484.2.61 raeburn 7143: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7144: } else {
1.484.2.61 raeburn 7145: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7146: }
7147: }
7148: return false;
7149: }
7150:
7151: function setClass(value) {
7152: var cutclass = 'LC_docs_cut';
7153: var copyclass = 'LC_docs_copy';
7154: var removeclass = 'LC_docs_remove';
7155: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7156: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7157: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7158: var links = document.getElementsByTagName('a');
7159: for (var i=0; i<links.length; i++) {
7160: var classes = links[i].className;
7161: if (cutreg.test(classes)) {
7162: links[i].className = cutclass;
7163: if (value == 1) {
7164: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7165: }
1.484.2.30 raeburn 7166: } else {
7167: if (copyreg.test(classes)) {
7168: links[i].className = copyclass;
7169: if (value == 1) {
7170: links[i].className += " LC_menubuttons_link";
7171: }
7172: } else {
7173: if (removereg.test(classes)) {
7174: links[i].className = removeclass;
7175: if (value == 1) {
7176: links[i].className += " LC_menubuttons_link";
7177: }
7178: }
1.484.2.29 raeburn 7179: }
7180: }
7181: }
1.484.2.30 raeburn 7182: return;
1.484.2.29 raeburn 7183: }
7184:
1.484.2.30 raeburn 7185: function setBoxes(value) {
7186: var remidxlist = document.cumulativeactions.allremoveidx.value;
7187: if ((remidxlist != '') && (remidxlist != null)) {
7188: var remidxs = remidxlist.split(',');
7189: for (var i=0; i<remidxs.length; i++) {
7190: if (document.getElementById('remove_'+remidxs[i])) {
7191: var item = document.getElementById('remove_'+remidxs[i]);
7192: if (value == 1) {
7193: item.className = 'LC_docs_remove';
7194: } else {
7195: item.className = 'LC_hidden';
7196: }
7197: }
1.484.2.29 raeburn 7198: }
7199: }
1.484.2.30 raeburn 7200: var cutidxlist = document.cumulativeactions.allcutidx.value;
7201: if ((cutidxlist != '') && (cutidxlist != null)) {
7202: var cutidxs = cutidxlist.split(',');
7203: for (var i=0; i<cutidxs.length; i++) {
7204: if (document.getElementById('cut_'+cutidxs[i])) {
7205: var item = document.getElementById('cut_'+cutidxs[i]);
7206: if (value == 1) {
7207: item.className = 'LC_docs_cut';
7208: } else {
7209: item.className = 'LC_hidden';
7210: }
7211: }
7212: }
7213: }
7214: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7215: if ((copyidxlist != '') && (copyidxlist != null)) {
7216: var copyidxs = copyidxlist.split(',');
7217: for (var i=0; i<copyidxs.length; i++) {
7218: if (document.getElementById('copy_'+copyidxs[i])) {
7219: var item = document.getElementById('copy_'+copyidxs[i]);
7220: if (value == 1) {
7221: item.className = 'LC_docs_copy';
7222: } else {
7223: item.className = 'LC_hidden';
7224: }
7225: }
1.484.2.29 raeburn 7226: }
7227: }
7228: return;
7229: }
7230:
1.484.2.67 raeburn 7231: ENDSCRIPT
1.329 droeschl 7232: }
1.457 raeburn 7233:
1.483 raeburn 7234: sub history_tab_js {
7235: return <<"ENDHIST";
7236: function toggleHistoryDisp(choice) {
7237: document.docslogform.docslog.value = choice;
7238: document.docslogform.submit();
7239: return;
7240: }
7241:
7242: ENDHIST
7243: }
7244:
1.484 raeburn 7245: sub inject_data_js {
7246: return <<ENDINJECT;
7247:
7248: function injectData(current, hiddenField, name, value) {
7249: currentElement = document.getElementById(hiddenField);
7250: currentElement.name = name;
7251: currentElement.value = value;
7252: current.submit();
7253: }
7254:
7255: ENDINJECT
7256: }
7257:
7258: sub dump_switchserver_js {
7259: my @hosts = @_;
1.484.2.61 raeburn 7260: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7261: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7262: swit => 'Switch server?',
1.484.2.61 raeburn 7263: );
7264: my %html_js_lt = &Apache::lonlocal::texthash(
7265: swit => 'Switch server?',
1.484.2.43 raeburn 7266: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7267: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7268: chos => 'Choose server',
7269: );
1.484.2.61 raeburn 7270: &js_escape(\%js_lt);
7271: &html_escape(\%html_js_lt);
7272: &js_escape(\%html_js_lt);
1.484 raeburn 7273: my $role = $env{'request.role'};
7274: my $js = <<"ENDSWJS";
7275: <script type="text/javascript">
7276: function write_switchserver() {
7277: var server;
7278: if (document.setserver.posshosts.length > 0) {
7279: for (var i=0; i<document.setserver.posshosts.length; i++) {
7280: if (document.setserver.posshosts[i].checked) {
7281: server = document.setserver.posshosts[i].value;
7282: }
7283: }
7284: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7285: }
7286: window.close();
7287: }
7288: </script>
7289:
7290: ENDSWJS
7291:
7292: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7293: {'only_body' => 1,
7294: 'js_ready' => 1,});
7295: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7296:
7297: my $hostpicker;
7298: my $count = 0;
7299: foreach my $host (sort(@hosts)) {
7300: my $checked;
7301: if ($count == 0) {
7302: $checked = ' checked="checked"';
7303: }
7304: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7305: $host.'"'.$checked.' />'.$host.'</label> ';
7306: $count++;
7307: }
7308:
7309: return <<"ENDSWITCHJS";
7310:
7311: function dump_needs_switchserver(url) {
7312: if (url!='' && url!= null) {
1.484.2.61 raeburn 7313: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7314: go(url);
7315: }
7316: }
7317: return;
7318: }
7319:
7320: function choose_switchserver_window() {
7321: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7322: newWindow.document.open();
7323: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7324: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7325: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7326: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7327: '<form name="setserver" method="post" action="" \\/>\\n'+
7328: '$hostpicker\\n'+
7329: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7330: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7331: 'onclick="write_switchserver();" \\/>\\n'+
7332: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7333: newWindow.document.writeln('$endpage');
7334: newWindow.document.close();
7335: newWindow.focus();
7336: }
7337:
7338: ENDSWITCHJS
7339: }
7340:
7341: sub makedocslogform {
7342: my ($formelems,$docslog) = @_;
7343: return <<"LOGSFORM";
7344: <form action="/adm/coursedocs" method="post" name="docslogform">
7345: <input type="hidden" name="docslog" value="$docslog" />
7346: $formelems
7347: </form>
7348: LOGSFORM
7349: }
7350:
7351: sub makesimpleeditform {
7352: my ($formelems) = @_;
7353: return <<"SIMPFORM";
7354: <form name="simpleedit" method="post" action="/adm/coursedocs">
7355: <input type="hidden" name="importdetail" value="" />
7356: $formelems
7357: </form>
7358: SIMPFORM
7359: }
7360:
1.329 droeschl 7361: 1;
7362: __END__
7363:
7364:
7365: =head1 NAME
7366:
7367: Apache::londocs.pm
7368:
7369: =head1 SYNOPSIS
7370:
7371: This is part of the LearningOnline Network with CAPA project
7372: described at http://www.lon-capa.org.
7373:
7374: =head1 SUBROUTINES
7375:
7376: =over
7377:
7378: =item %help=()
7379:
7380: Available help topics
7381:
7382: =item mapread()
7383:
1.344 bisitz 7384: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7385: @order and @resources, determines status
7386: sets @order - pointer to resources in right order
7387: sets @resources - array with the resources with correct idx
7388:
7389: =item authorhosts()
7390:
7391: Return hash with valid author names
7392:
7393: =item clean()
7394:
7395: =item dumpcourse()
7396:
7397: Actually dump course
7398:
7399: =item group_import()
7400:
7401: Imports the given (name, url) resources into the course
7402: coursenum, coursedom, and folder must precede the list
7403:
7404: =item breadcrumbs()
7405:
7406: =item log_docs()
7407:
7408: =item docs_change_log()
7409:
7410: =item update_paste_buffer()
7411:
7412: =item print_paste_buffer()
7413:
7414: =item do_paste_from_buffer()
7415:
1.484.2.30 raeburn 7416: =item do_buffer_empty()
7417:
7418: =item clear_from_buffer()
7419:
1.484.2.7 raeburn 7420: =item get_newmap_url()
7421:
7422: =item dbcopy()
7423:
7424: =item uniqueness_check()
7425:
7426: =item contained_map_check()
7427:
7428: =item url_paste_fixups()
7429:
7430: =item apply_fixups()
7431:
7432: =item copy_dependencies()
7433:
1.329 droeschl 7434: =item update_parameter()
7435:
7436: =item handle_edit_cmd()
7437:
7438: =item editor()
7439:
7440: =item process_file_upload()
7441:
7442: =item process_secondary_uploads()
7443:
7444: =item is_supplemental_title()
7445:
7446: =item entryline()
7447:
7448: =item tiehash()
7449:
7450: =item untiehash()
7451:
7452: =item checkonthis()
7453:
7454: check on this
7455:
7456: =item verifycontent()
7457:
7458: Verify Content
7459:
7460: =item devalidateversioncache() & checkversions()
7461:
7462: Check Versions
7463:
7464: =item mark_hash_old()
7465:
7466: =item is_hash_old()
7467:
7468: =item changewarning()
7469:
7470: =item init_breadcrumbs()
7471:
7472: Breadcrumbs for special functions
7473:
1.484 raeburn 7474: =item create_list_elements()
7475:
7476: =item create_form_ul()
7477:
7478: =item startContentScreen()
7479:
7480: =item endContentScreen()
7481:
7482: =item supplemental_base()
7483:
7484: =item embedded_form_elems()
7485:
7486: =item embedded_destination()
7487:
7488: =item return_to_editor()
7489:
7490: =item decompression_info()
7491:
7492: =item decompression_phase_one()
7493:
7494: =item decompression_phase_two()
7495:
7496: =item remove_archive()
7497:
7498: =item generate_admin_menu()
7499:
7500: =item generate_edit_table()
7501:
7502: =item editing_js()
7503:
7504: =item history_tab_js()
7505:
7506: =item inject_data_js()
7507:
7508: =item dump_switchserver_js()
7509:
1.484.2.3 raeburn 7510: =item resize_scrollbox_js()
1.484 raeburn 7511:
7512: =item makedocslogform()
7513:
1.484.2.3 raeburn 7514: =item makesimpleeditform()
7515:
1.329 droeschl 7516: =back
7517:
7518: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>