Annotation of loncom/interface/londocs.pm, revision 1.484.2.80
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.80! raeburn 4: # $Id: londocs.pm,v 1.484.2.79 2019/04/11 16:32:33 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,
1.484.2.80! raeburn 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 = {};
1.484.2.79 raeburn 1635: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1636:
1637: # Loop over the items to paste
1638: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1639: # Maps need to be copied first
1.484.2.30 raeburn 1640: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1641: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1642: %newurls,%tomove);
1643: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1644: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1645: }
1646: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1647: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1648: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1649: my $oldurl = $url;
1650: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1651: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1652: my (%hierarchy,%titles);
1.484.2.79 raeburn 1653: if (($folder =~ /^default/) && (!$donechk)) {
1654: $allmaps =
1655: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1656: $env{"course.$env{'request.course.id'}.home"},
1657: $env{'request.course.id'});
1658: $donechk = 1;
1659: }
1.484.2.30 raeburn 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.80! raeburn 2778: $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,
! 2779: $hostname,$navmapref,$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,
1.484.2.80! raeburn 3099: $isencrypted,$navmapref,$hostname);
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,
1.484.2.80! raeburn 3478: $canedit,$isencrypted,$navmapref,$hostname)=@_;
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://})) {
1.484.2.80! raeburn 3755: unless (&Apache::lonnet::uses_sts()) {
! 3756: $url .= '?usehttp=1';
! 3757: }
1.484.2.70 raeburn 3758: $nomodal = 1;
3759: }
1.484.2.19 raeburn 3760: }
1.484.2.12 raeburn 3761: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3762: my $shownsymb = $symb;
3763: if ($isexternal) {
3764: if ($url =~ /^([^#]+)#([^#]+)$/) {
3765: $url = $1;
3766: $anchor = $2;
1.484.2.80! raeburn 3767: my $escan = &escape('#');
! 3768: $shownsymb =~ s/^([^\#]+)#([^\#]+)$/$1$escan$2/;
1.484.2.66 raeburn 3769: }
3770: }
1.484.2.67 raeburn 3771: unless ($env{'request.role.adv'}) {
3772: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3773: $url = '';
3774: }
3775: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3776: $url = '';
3777: $hiddenres = 1;
3778: }
3779: }
3780: if ($url ne '') {
1.484.2.75 raeburn 3781: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3782: }
3783: } elsif (!$env{'request.role.adv'}) {
3784: my $checkencrypt;
3785: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3786: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3787: $checkencrypt = 1;
1.484.2.70 raeburn 3788: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3789: unless (ref($$navmapref)) {
3790: $$navmapref = Apache::lonnavmaps::navmap->new();
3791: }
3792: if (ref($$navmapref)) {
3793: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
3794: $checkencrypt = 1;
3795: }
3796: }
3797: }
3798: if ($checkencrypt) {
3799: my $shownsymb = &Apache::lonenc::encrypted($symb);
3800: my $shownurl = &Apache::lonenc::encrypted($url);
3801: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80! raeburn 3802: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3803: if ($env{'request.enc'} ne '') {
3804: delete($env{'request.enc'});
3805: }
3806: } else {
3807: $url='';
3808: }
3809: } else {
3810: $url='';
3811: }
1.484.2.12 raeburn 3812: } else {
3813: $url='';
3814: }
1.484.2.19 raeburn 3815: }
1.484.2.66 raeburn 3816: } elsif ($supplementalflag) {
3817: if ($isexternal) {
3818: if ($url =~ /^([^#]+)#([^#]+)$/) {
3819: $url = $1;
3820: $anchor = $2;
1.484.2.70 raeburn 3821: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.80! raeburn 3822: unless (&Apache::lonnet::uses_sts()) {
! 3823: if ($hostname ne '') {
! 3824: $url = 'http://'.$hostname.$url;
! 3825: }
! 3826: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
! 3827: }
1.484.2.70 raeburn 3828: $nomodal = 1;
3829: }
3830: }
3831: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
3832: if (($ENV{'SERVER_PORT'} == 443) &&
3833: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80! raeburn 3834: unless (&Apache::lonnet::uses_sts()) {
! 3835: if ($hostname ne '') {
! 3836: $url = 'http://'.$hostname.$url;
! 3837: }
! 3838: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
! 3839: }
1.484.2.70 raeburn 3840: $nomodal = 1;
1.484.2.66 raeburn 3841: }
3842: }
1.329 droeschl 3843: }
1.484.2.67 raeburn 3844: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
3845: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 3846: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3847: my $foldername=&escape($foldertitle);
3848: my $folderpath=$env{'form.folderpath'};
3849: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 3850: if (!$allowed && $supplementalflag) {
3851: $folderpath.=$containerarg.'&'.$foldername;
3852: $url.='folderpath='.&escape($folderpath);
3853: } else {
3854: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3855: 'parameter_randompick'))[0];
1.484.2.67 raeburn 3856: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
3857: 'parameter_randomorder'))[0]=~/^yes$/i);
3858: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
3859: 'parameter_hiddenresource'))[0]=~/^yes$/i);
3860: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
3861: 'parameter_encrypturl'))[0]=~/^yes$/i);
3862: unless ($hiddenmap) {
1.484.2.70 raeburn 3863: if (ref($navmapref)) {
3864: unless (ref($$navmapref)) {
3865: $$navmapref = Apache::lonnavmaps::navmap->new();
3866: }
3867: if (ref($$navmapref)) {
3868: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
3869: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
3870: unless (@resources) {
3871: $hiddenmap = 1;
3872: unless ($env{'request.role.adv'}) {
3873: $url = '';
3874: $hiddenfolder = 1;
3875: }
1.484.2.67 raeburn 3876: }
3877: }
3878: }
3879: }
3880: }
3881: unless ($encryptmap) {
1.484.2.70 raeburn 3882: if ((ref($navmapref)) && (ref($$navmapref))) {
3883: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
3884: $encryptmap = 1;
3885: }
1.484.2.67 raeburn 3886: }
3887: }
3888:
3889: # Append randompick number, hidden, and encrypted with ":" to foldername,
3890: # so it gets transferred between levels
3891: $folderpath.=$containerarg.'&'.$foldername.
3892: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
3893: unless ($url eq '') {
3894: $url.='folderpath='.&escape($folderpath);
3895: }
1.484.2.19 raeburn 3896: my $rpckchk;
3897: if ($rpicknum) {
3898: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 3899: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3900: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3901: }
1.484.2.19 raeburn 3902: }
1.484.2.29 raeburn 3903: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 3904: $rand_pick_text =
1.478 raeburn 3905: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3906: $form_param."\n".
1.478 raeburn 3907: $form_common."\n".
1.484.2.67 raeburn 3908: '<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 3909: if ($rpicknum ne '') {
3910: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3911: }
1.484.2.29 raeburn 3912: $rand_pick_text .= '</span></span>'.
3913: $form_end;
1.484.2.30 raeburn 3914: my $ro_set;
1.484.2.67 raeburn 3915: if ($randorder) {
1.484.2.30 raeburn 3916: $ro_set = 'checked="checked"';
3917: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3918: push(@{$filtersref->{'randomorder'}},$orderidx);
3919: }
3920: }
1.484.2.41 raeburn 3921: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 3922: $rand_order_text =
1.484.2.29 raeburn 3923: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3924: $form_param."\n".
1.484.2.29 raeburn 3925: $form_common."\n".
1.484.2.67 raeburn 3926: '<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 3927: $form_end;
1.484.2.19 raeburn 3928: }
1.484.2.18 raeburn 3929: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 3930: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 3931: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 3932: if ($title) {
3933: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3934: }
3935: if ($isexternal && $orderidx) {
3936: $url .= '&idx='.$orderidx;
3937: }
1.484.2.66 raeburn 3938: if ($anchor ne '') {
3939: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
3940: }
1.329 droeschl 3941: }
1.484.2.19 raeburn 3942: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 3943: if ($allowed) {
1.484.2.19 raeburn 3944: my $fileloc =
1.484.2.12 raeburn 3945: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 3946: if ($isexternal) {
3947: ($editlink,$extresform) =
1.484.2.67 raeburn 3948: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
3949: undef,undef,undef,$disabled);
1.484.2.19 raeburn 3950: } elsif (!$isfolder && !$ispage) {
3951: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 3952: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 3953: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 3954: my $suppanchor;
3955: if ($supplementalflag) {
3956: $suppanchor = $anchor;
3957: }
1.484.2.19 raeburn 3958: my $jscall =
1.484.2.12 raeburn 3959: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
3960: $switchserver,
1.484.2.14 raeburn 3961: $forceedit,
1.484.2.19 raeburn 3962: undef,$symb,
3963: &escape($env{'form.folderpath'}),
1.484.2.80! raeburn 3964: $renametitle,$hostname,
! 3965: '','',1,$suppanchor);
1.484.2.12 raeburn 3966: if ($jscall) {
1.484.2.19 raeburn 3967: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
3968: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 3969: }
3970: }
3971: }
1.484.2.19 raeburn 3972: $tdalign = ' align="right" valign="top"';
3973: $tdwidth = ' width="80%"';
1.329 droeschl 3974: }
1.408 raeburn 3975: my $reinit;
3976: if ($crstype eq 'Community') {
3977: $reinit = &mt('(re-initialize community to access)');
3978: } else {
3979: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 3980: }
3981: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 3982: my $link;
1.472 raeburn 3983: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3984: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
3985: } elsif ($url) {
1.484.2.66 raeburn 3986: if ($anchor ne '') {
3987: if ($supplementalflag) {
3988: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
3989: } else {
3990: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
3991: }
3992: }
1.484.2.80! raeburn 3993:
! 3994: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
! 3995: $link = 'http://'.$hostname.$url;
! 3996: } else {
! 3997: $link = $url;
! 3998: }
! 3999: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4000: if ($nomodal) {
4001: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4002: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4003: } else {
4004: $line.=&Apache::loncommon::modal_link($link,
4005: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4006: }
1.469 www 4007: } else {
4008: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4009: }
1.484.2.19 raeburn 4010: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4011: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4012: $line.='<a href="'.$url.'">'.$title.'</a>';
4013: } elsif ($url) {
1.484.2.70 raeburn 4014: if ($nomodal) {
4015: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4016: $title.'</a>';
4017: } else {
4018: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4019: }
1.484.2.67 raeburn 4020: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4021: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4022: } else {
4023: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4024: }
1.484.2.19 raeburn 4025: $line.="$extresform</td>";
1.478 raeburn 4026: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4027: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4028: if (($allowed) && ($folder!~/^supplemental/)) {
4029: my %lt=&Apache::lonlocal::texthash(
4030: 'hd' => 'Hidden',
4031: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4032: my ($enctext,$hidtext);
4033: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4034: $enctext = ' checked="checked"';
4035: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4036: push(@{$filtersref->{'encrypturl'}},$orderidx);
4037: }
4038: }
4039: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4040: $hidtext = ' checked="checked"';
4041: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4042: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4043: }
4044: }
1.484.2.29 raeburn 4045: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4046: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4047: $line.=(<<ENDPARMS);
4048: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4049: <form action="/adm/coursedocs" method="post" name="$formhidden">
4050: $form_param
1.478 raeburn 4051: $form_common
1.484.2.67 raeburn 4052: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4053: $form_end
1.458 raeburn 4054: <br />
1.484.2.29 raeburn 4055: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4056: $form_param
1.478 raeburn 4057: $form_common
1.484.2.67 raeburn 4058: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4059: $form_end
4060: </td>
1.478 raeburn 4061: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4062: $rand_order_text</td>
1.329 droeschl 4063: ENDPARMS
4064: }
1.379 bisitz 4065: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4066: return $line;
4067: }
4068:
1.484.2.30 raeburn 4069: sub action_restrictions {
4070: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4071: my %denied = (
4072: cut => 0,
4073: copy => 0,
4074: remove => 0,
4075: );
4076: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4077: # no copy for published maps
4078: $denied{'copy'} = 1;
4079: } elsif ($url=~m{^/res/lib/templates/}) {
4080: $denied{'copy'} = 1;
4081: $denied{'cut'} = 1;
4082: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4083: if ($folderpath =~ /^default&[^\&]+$/) {
4084: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4085: $denied{'remove'} = 1;
4086: }
4087: $denied{'cut'} = 1;
4088: $denied{'copy'} = 1;
4089: }
4090: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4091: my $group = $1;
4092: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4093: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4094: $denied{'remove'} = 1;
4095: }
4096: }
4097: $denied{'cut'} = 1;
4098: $denied{'copy'} = 1;
4099: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4100: my $group = $1;
4101: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4102: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4103: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4104: if (keys(%groupsettings) > 0) {
4105: $denied{'remove'} = 1;
4106: }
4107: $denied{'cut'} = 1;
4108: $denied{'copy'} = 1;
4109: }
4110: }
4111: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4112: my $group = $1;
4113: if ($url =~ /group_boards_\Q$group\E/) {
4114: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4115: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4116: if (keys(%groupsettings) > 0) {
4117: if (ref($groupsettings{'functions'}) eq 'HASH') {
4118: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4119: $denied{'remove'} = 1;
4120: }
4121: }
4122: }
4123: $denied{'cut'} = 1;
4124: $denied{'copy'} = 1;
4125: }
4126: }
4127: }
4128: return %denied;
4129: }
4130:
1.484.2.26 raeburn 4131: sub new_timebased_suffix {
1.484.2.30 raeburn 4132: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4133: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4134: if ($type eq 'paste') {
4135: $prefix = $type;
4136: $namespace = 'courseeditor';
1.484.2.56 raeburn 4137: $idtype = 'addcode';
1.484.2.30 raeburn 4138: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4139: $prefix = 'docs';
4140: if ($area eq 'supplemental') {
4141: $prefix = 'supp';
4142: }
4143: $prefix .= $container;
4144: $namespace = 'uploadedmaps';
4145: } else {
4146: $prefix = $type;
4147: $namespace = 'templated';
1.484.2.15 raeburn 4148: }
4149: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4150: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4151: if (!$suffix) {
1.484.2.30 raeburn 4152: if ($type eq 'paste') {
4153: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4154: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4155: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4156: } elsif ($type eq 'smppg') {
4157: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4158: } else {
1.484.2.42 raeburn 4159: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4160: }
1.484.2.15 raeburn 4161: if ($error) {
4162: $errtext .= '<br />'.$error;
4163: }
4164: }
4165: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4166: $locknotfreed =
4167: '<div class="LC_error">'.
4168: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4169: if ($type eq 'paste') {
1.484.2.57 raeburn 4170: if ($freedlock eq 'nolock') {
4171: $locknotfreed =
4172: '<div class="LC_error">'.
4173: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4174:
1.484.2.60 raeburn 4175: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4176: } else {
4177: $locknotfreed .=
4178: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4179: }
1.484.2.30 raeburn 4180: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4181: $locknotfreed .=
4182: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4183: } elsif ($type eq 'smppg') {
4184: $locknotfreed .=
4185: &mt('This will prevent creation of additional simple pages in this course.');
4186: } else {
4187: $locknotfreed .=
1.484.2.42 raeburn 4188: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4189: }
1.484.2.30 raeburn 4190: unless ($type eq 'paste') {
4191: $locknotfreed .=
1.484.2.38 raeburn 4192: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4193: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4194: }
4195: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4196: }
4197: return ($suffix,$errtext,$locknotfreed);
4198: }
4199:
1.329 droeschl 4200: =pod
4201:
4202: =item tiehash()
4203:
4204: tie the hash
4205:
4206: =cut
4207:
4208: sub tiehash {
4209: my ($mode)=@_;
4210: $hashtied=0;
4211: if ($env{'request.course.fn'}) {
4212: if ($mode eq 'write') {
4213: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4214: &GDBM_WRCREAT(),0640)) {
4215: $hashtied=2;
4216: }
4217: } else {
4218: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4219: &GDBM_READER(),0640)) {
4220: $hashtied=1;
4221: }
4222: }
1.364 bisitz 4223: }
1.329 droeschl 4224: }
4225:
4226: sub untiehash {
4227: if ($hashtied) { untie %hash; }
4228: $hashtied=0;
4229: return OK;
4230: }
4231:
4232:
4233:
4234:
4235: sub checkonthis {
1.484.2.78 raeburn 4236: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4237: $url=&unescape($url);
4238: $alreadyseen{$url}=1;
4239: $r->rflush();
4240: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4241: $r->print("\n<br />");
4242: if ($level==0) {
4243: $r->print("<br />");
4244: }
4245: for (my $i=0;$i<=$level*5;$i++) {
4246: $r->print(' ');
4247: }
4248: $r->print('<a href="'.$url.'" target="cat">'.
4249: ($title?$title:$url).'</a> ');
4250: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4251: my $updated;
4252: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4253: ($url !~ /\.\d+\.\w+$/)) {
4254: $updated = &Apache::lonnet::remove_stale_resfile($url);
4255: }
1.329 droeschl 4256: my $result=&Apache::lonnet::repcopy(
4257: &Apache::lonnet::filelocation('',$url));
4258: if ($result eq 'ok') {
4259: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4260: if ($updated) {
4261: $r->print('<br />');
4262: for (my $i=0;$i<=$level*5;$i++) {
4263: $r->print(' ');
4264: }
4265: $r->print('- '.&mt('Outdated copy removed'));
4266: }
1.329 droeschl 4267: $r->rflush();
4268: &Apache::lonnet::countacc($url);
4269: $url=~/\.(\w+)$/;
4270: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4271: $r->print('<br />');
4272: $r->rflush();
4273: for (my $i=0;$i<=$level*5;$i++) {
4274: $r->print(' ');
4275: }
4276: $r->print('- '.&mt('Rendering:').' ');
4277: my ($errorcount,$warningcount)=split(/:/,
4278: &Apache::lonnet::ssi_body($url,
4279: ('grade_target'=>'web',
4280: 'return_only_error_and_warning_counts' => 1)));
4281: if (($errorcount) ||
4282: ($warningcount)) {
4283: if ($errorcount) {
1.369 bisitz 4284: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4285: &mt('[quant,_1,error]',$errorcount).'</span>');
4286: }
4287: if ($warningcount) {
4288: $r->print('<span class="LC_warning">'.
4289: &mt('[quant,_1,warning]',$warningcount).'</span>');
4290: }
4291: } else {
4292: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4293: }
4294: $r->rflush();
4295: }
4296: my $dependencies=
4297: &Apache::lonnet::metadata($url,'dependencies');
4298: foreach my $dep (split(/\,/,$dependencies)) {
4299: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4300: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4301: }
4302: }
4303: } elsif ($result eq 'unavailable') {
4304: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4305: } elsif ($result eq 'not_found') {
4306: unless ($url=~/\$/) {
1.484.2.19 raeburn 4307: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4308: } else {
1.366 bisitz 4309: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4310: }
4311: } else {
4312: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4313: }
1.484.2.78 raeburn 4314: if (($updated) && ($result ne 'ok')) {
4315: $r->print('<br />'.&mt('Outdated copy removed'));
4316: }
1.329 droeschl 4317: }
4318: }
4319: }
4320:
4321:
4322:
4323: =pod
4324:
4325: =item list_symbs()
4326:
1.484.2.3 raeburn 4327: List Content Identifiers
1.329 droeschl 4328:
4329: =cut
4330:
4331: sub list_symbs {
4332: my ($r) = @_;
4333:
1.408 raeburn 4334: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4335: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4336: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4337: $r->print(&startContentScreen('tools'));
1.329 droeschl 4338: my $navmap = Apache::lonnavmaps::navmap->new();
4339: if (!defined($navmap)) {
4340: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4341: '<div class="LC_error">'.
4342: &mt('Unable to retrieve information about course contents').
4343: '</div>');
1.408 raeburn 4344: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4345: } else {
1.484 raeburn 4346: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4347: &Apache::loncommon::start_data_table().
4348: &Apache::loncommon::start_data_table_header_row().
4349: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4350: &Apache::loncommon::end_data_table_header_row()."\n");
4351: my $count;
1.329 droeschl 4352: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4353: $r->print(&Apache::loncommon::start_data_table_row().
4354: '<td>'.$res->compTitle().'</td>'.
4355: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4356: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4357: $count ++;
4358: }
4359: if (!$count) {
4360: $r->print(&Apache::loncommon::start_data_table_row().
4361: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4362: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4363: }
1.484 raeburn 4364: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4365: }
1.484.2.19 raeburn 4366: $r->print(&endContentScreen());
1.329 droeschl 4367: }
4368:
1.484.2.78 raeburn 4369: sub contentverifyform {
4370: my ($r) = @_;
4371: my $crstype = &Apache::loncommon::course_type();
4372: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4373: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4374: $r->print(&startContentScreen('tools'));
4375: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4376: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4377: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4378: ' <span class="LC_nobreak">'.
4379: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4380: &mt('No').'</label>'.(' 'x2).
4381: '<label><input type="radio" name="checkstale" value="1" />'.
4382: &mt('Yes').'</label></span></p><p>'.
4383: '<input type="submit" value="'.&mt('Verify content').' "/>'.
4384: '<input type="hidden" value="1" name="tools" />'.
4385: '<input type="hidden" value="1" name="verify" /></p></form>');
4386: $r->print(&endContentScreen());
4387: return;
4388: }
1.329 droeschl 4389:
4390: sub verifycontent {
1.484.2.78 raeburn 4391: my ($r,$checkstale) = @_;
1.408 raeburn 4392: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4393: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4394: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4395: $r->print(&startContentScreen('tools'));
4396: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4397: $hashtied=0;
4398: undef %alreadyseen;
4399: %alreadyseen=();
4400: &tiehash();
1.484 raeburn 4401:
1.329 droeschl 4402: foreach my $key (keys(%hash)) {
4403: if ($hash{$key}=~/\.(page|sequence)$/) {
4404: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4405: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4406: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4407: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4408: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4409: }
4410: }
4411: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4412: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4413: }
4414: }
4415: &untiehash();
1.442 www 4416: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4417: $r->print(&endContentScreen());
1.329 droeschl 4418: }
4419:
4420:
4421: sub devalidateversioncache {
4422: my $src=shift;
4423: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4424: &Apache::lonnet::clutter($src));
4425: }
4426:
4427: sub checkversions {
1.484.2.67 raeburn 4428: my ($r,$canedit) = @_;
1.408 raeburn 4429: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4430: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4431: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4432: $r->print(&startContentScreen('tools'));
1.442 www 4433:
1.329 droeschl 4434: my $header='';
4435: my $startsel='';
4436: my $monthsel='';
4437: my $weeksel='';
4438: my $daysel='';
4439: my $allsel='';
4440: my %changes=();
4441: my $starttime=0;
4442: my $haschanged=0;
4443: my %setversions=&Apache::lonnet::dump('resourceversions',
4444: $env{'course.'.$env{'request.course.id'}.'.domain'},
4445: $env{'course.'.$env{'request.course.id'}.'.num'});
4446:
4447: $hashtied=0;
4448: &tiehash();
1.484.2.67 raeburn 4449: if ($canedit) {
4450: my %newsetversions=();
4451: if ($env{'form.setmostrecent'}) {
4452: $haschanged=1;
4453: foreach my $key (keys(%hash)) {
4454: if ($key=~/^ids\_(\/res\/.+)$/) {
4455: $newsetversions{$1}='mostrecent';
4456: &devalidateversioncache($1);
4457: }
1.329 droeschl 4458: }
1.484.2.67 raeburn 4459: } elsif ($env{'form.setcurrent'}) {
4460: $haschanged=1;
4461: foreach my $key (keys(%hash)) {
4462: if ($key=~/^ids\_(\/res\/.+)$/) {
4463: my $getvers=&Apache::lonnet::getversion($1);
4464: if ($getvers>0) {
4465: $newsetversions{$1}=$getvers;
4466: &devalidateversioncache($1);
4467: }
4468: }
1.329 droeschl 4469: }
1.484.2.67 raeburn 4470: } elsif ($env{'form.setversions'}) {
4471: $haschanged=1;
4472: foreach my $key (keys(%env)) {
4473: if ($key=~/^form\.set_version_(.+)$/) {
4474: my $src=$1;
4475: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4476: $newsetversions{$src}=$env{$key};
4477: &devalidateversioncache($src);
4478: }
4479: }
1.329 droeschl 4480: }
1.484.2.67 raeburn 4481: }
4482: if ($haschanged) {
4483: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4484: $env{'course.'.$env{'request.course.id'}.'.domain'},
4485: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4486: $r->print(&Apache::loncommon::confirmwrapper(
4487: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4488: } else {
4489: $r->print(&Apache::loncommon::confirmwrapper(
4490: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4491: }
4492: &mark_hash_old();
4493: }
4494: &changewarning($r,'');
1.329 droeschl 4495: }
4496: if ($env{'form.timerange'} eq 'all') {
4497: # show all documents
1.484.2.34 raeburn 4498: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4499: $allsel=' selected="selected"';
1.329 droeschl 4500: foreach my $key (keys(%hash)) {
4501: if ($key=~/^ids\_(\/res\/.+)$/) {
4502: my $src=$1;
4503: $changes{$src}=1;
4504: }
4505: }
4506: } else {
4507: # show documents which changed
4508: %changes=&Apache::lonnet::dump
4509: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4510: $env{'course.'.$env{'request.course.id'}.'.num'});
4511: my $firstkey=(keys(%changes))[0];
4512: unless ($firstkey=~/^error\:/) {
4513: unless ($env{'form.timerange'}) {
4514: $env{'form.timerange'}=604800;
4515: }
4516: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4517: .&mt('seconds');
4518: if ($env{'form.timerange'}==-1) {
4519: $seltext='since start of course';
1.484.2.19 raeburn 4520: $startsel=' selected="selected"';
1.329 droeschl 4521: $env{'form.timerange'}=time;
4522: }
4523: $starttime=time-$env{'form.timerange'};
4524: if ($env{'form.timerange'}==2592000) {
4525: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4526: $monthsel=' selected="selected"';
1.329 droeschl 4527: } elsif ($env{'form.timerange'}==604800) {
4528: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4529: $weeksel=' selected="selected"';
1.329 droeschl 4530: } elsif ($env{'form.timerange'}==86400) {
4531: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4532: $daysel=' selected="selected"';
1.329 droeschl 4533: }
4534: $header=&mt('Content changed').' '.$seltext;
4535: } else {
4536: $header=&mt('No content modifications yet.');
4537: }
4538: }
4539: %setversions=&Apache::lonnet::dump('resourceversions',
4540: $env{'course.'.$env{'request.course.id'}.'.domain'},
4541: $env{'course.'.$env{'request.course.id'}.'.num'});
4542: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4543: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4544: 'lm' => 'Version changes since last Month',
4545: 'lw' => 'Version changes since last Week',
4546: 'sy' => 'Version changes since Yesterday',
4547: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4548: 'cd' => 'Change display',
1.329 droeschl 4549: 'sd' => 'Display',
4550: 'fi' => 'File',
4551: 'md' => 'Modification Date',
4552: 'mr' => 'Most recently published Version',
1.408 raeburn 4553: 've' => 'Version used in '.$crstype,
4554: 'vu' => 'Set Version to be used in '.$crstype,
4555: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4556: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4557: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4558: 'di' => 'Differences',
1.484 raeburn 4559: 'save' => 'Save changes',
4560: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4561: 'act' => 'Actions');
1.484.2.67 raeburn 4562: my ($disabled,$readonly);
4563: unless ($canedit) {
4564: $disabled = 'disabled="disabled"';
4565: $readonly = 1;
4566: }
1.329 droeschl 4567: $r->print(<<ENDHEADERS);
1.484 raeburn 4568: <h4 class="LC_info">$header</h4>
1.329 droeschl 4569: <form action="/adm/coursedocs" method="post">
4570: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4571: <div class="LC_left_float">
1.479 golterma 4572: <fieldset>
1.484 raeburn 4573: <legend>$lt{'cd'}</legend>
1.329 droeschl 4574: <select name="timerange">
1.484.2.19 raeburn 4575: <option value='all'$allsel>$lt{'al'}</option>
4576: <option value="-1"$startsel>$lt{'st'}</option>
4577: <option value="2592000"$monthsel>$lt{'lm'}</option>
4578: <option value="604800"$weeksel>$lt{'lw'}</option>
4579: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4580: </select>
4581: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4582: </fieldset>
4583: </div>
4584: <div class="LC_left_float">
4585: <fieldset>
4586: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4587: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4588: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4589: </fieldset>
4590: </div>
4591: <br clear="all" />
4592: <hr />
4593: <h4>$lt{'vers'}</h4>
1.329 droeschl 4594: ENDHEADERS
1.479 golterma 4595: #number of columns for version history
1.484.2.44 raeburn 4596: my %changedbytime;
4597: foreach my $key (keys(%changes)) {
4598: #excludes not versionable problems from resource version history:
4599: next if ($key =~ /^\/res\/lib\/templates/);
4600: my $chg;
4601: if ($env{'form.timerange'} eq 'all') {
4602: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4603: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4604: } else {
4605: $chg = $changes{$key};
4606: next if ($chg < $starttime);
4607: }
4608: push(@{$changedbytime{$chg}},$key);
4609: }
4610: if (keys(%changedbytime) == 0) {
4611: &untiehash();
4612: $r->print(&mt('No content changes in imported content in specified time frame').
4613: &endContentScreen());
4614: return;
4615: }
1.479 golterma 4616: $r->print(
1.484.2.67 raeburn 4617: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4618: &Apache::loncommon::start_data_table().
4619: &Apache::loncommon::start_data_table_header_row().
4620: '<th>'.&mt('Resources').'</th>'.
4621: "<th>$lt{'mr'}</th>".
4622: "<th>$lt{'ve'}</th>".
4623: "<th>$lt{'vu'}</th>".
4624: '<th>'.&mt('History').'</th>'.
4625: &Apache::loncommon::end_data_table_header_row()
4626: );
1.484.2.44 raeburn 4627: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4628: foreach my $key (sort(@{$changedbytime{$chg}})) {
4629: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4630: my $currentversion=&Apache::lonnet::getversion($key);
4631: if ($currentversion<0) {
4632: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4633: }
4634: my $linkurl=&Apache::lonnet::clutter($key);
4635: $r->print(
4636: &Apache::loncommon::start_data_table_row().
4637: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4638: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4639: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4640: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4641: '<td align="right">'
4642: );
4643: # Used in course
4644: my $usedversion=$hash{'version_'.$linkurl};
4645: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4646: if ($usedversion != $currentversion) {
1.479 golterma 4647: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4648: } else {
1.479 golterma 4649: $r->print($usedversion);
4650: }
1.329 droeschl 4651: } else {
1.484.2.19 raeburn 4652: $r->print($currentversion);
1.329 droeschl 4653: }
1.484.2.44 raeburn 4654: $r->print('</td><td title="'.$lt{'vu'}.'">');
4655: # Set version
4656: $r->print(&Apache::loncommon::select_form(
4657: $setversions{$linkurl},
4658: 'set_version_'.$linkurl,
4659: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4660: '' => '',
4661: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4662: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4663: my $lastold=1;
4664: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4665: my $url=$root.'.'.$prevvers.'.'.$extension;
4666: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4667: $lastold=$prevvers;
4668: }
4669: }
4670: $r->print('</td>');
4671: # List all available versions
4672: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4673: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4674: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4675: $r->print(
1.484.2.44 raeburn 4676: '<span class="LC_nobreak">'
4677: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4678: .&mt('Version [_1]',$prevvers).'</a>'
4679: .' ('.&Apache::lonlocal::locallocaltime(
4680: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4681: .')');
4682: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4683: $r->print(
4684: ' <a href="/adm/diff?filename='.
4685: &Apache::lonnet::clutter($root.'.'.$extension).
4686: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4687: '" target="diffs">'.&mt('Diffs').'</a>');
4688: }
4689: $r->print('</span><br />');
1.329 droeschl 4690: }
1.484.2.44 raeburn 4691: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4692: }
1.329 droeschl 4693: }
1.484.2.19 raeburn 4694: $r->print(
4695: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4696: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4697: '</form>'
4698: );
1.329 droeschl 4699:
4700: &untiehash();
1.484.2.19 raeburn 4701: $r->print(&endContentScreen());
1.484.2.44 raeburn 4702: return;
1.329 droeschl 4703: }
4704:
4705: sub mark_hash_old {
4706: my $retie_hash=0;
4707: if ($hashtied) {
4708: $retie_hash=1;
4709: &untiehash();
4710: }
4711: &tiehash('write');
4712: $hash{'old'}=1;
4713: &untiehash();
4714: if ($retie_hash) { &tiehash(); }
4715: }
4716:
4717: sub is_hash_old {
4718: my $untie_hash=0;
4719: if (!$hashtied) {
4720: $untie_hash=1;
4721: &tiehash();
4722: }
4723: my $return=$hash{'old'};
4724: if ($untie_hash) { &untiehash(); }
4725: return $return;
4726: }
4727:
4728: sub changewarning {
4729: my ($r,$postexec,$message,$url)=@_;
4730: if (!&is_hash_old()) { return; }
4731: my $pathvar='folderpath';
4732: my $path=&escape($env{'form.folderpath'});
4733: if (!defined($url)) {
4734: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4735: }
4736: my $course_type = &Apache::loncommon::course_type();
4737: if (!defined($message)) {
4738: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4739: }
4740: $r->print("\n\n".
1.372 bisitz 4741: '<script type="text/javascript">'."\n".
4742: '// <![CDATA['."\n".
4743: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4744: '// ]]>'."\n".
1.369 bisitz 4745: '</script>'."\n".
1.375 tempelho 4746: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4747: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4748: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4749: &mt($message,' <input type="hidden" name="'.
4750: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4751: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4752: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4753: }
4754:
4755:
4756: sub init_breadcrumbs {
1.484.2.44 raeburn 4757: my ($form,$text,$help)=@_;
1.329 droeschl 4758: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4759: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4760: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4761: faq=>273,
4762: bug=>'Instructor Interface',
1.484.2.44 raeburn 4763: help => $help});
1.329 droeschl 4764: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4765: text=>$text,
4766: faq=>273,
4767: bug=>'Instructor Interface'});
4768: }
4769:
1.441 www 4770: # subroutine to list form elements
4771: sub create_list_elements {
4772: my @formarr = @_;
4773: my $list = '';
1.484.2.12 raeburn 4774: foreach my $button (@formarr){
4775: foreach my $picture (keys(%{$button})) {
4776: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4777: }
4778: }
4779: return $list;
4780: }
1.329 droeschl 4781:
1.441 www 4782: # subroutine to create ul from list elements
4783: sub create_form_ul {
4784: my $list = shift;
4785: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4786: return $ul;
4787: }
1.329 droeschl 4788:
1.442 www 4789: #
4790: # Start tabs
4791: #
4792:
4793: sub startContentScreen {
1.484 raeburn 4794: my ($mode) = @_;
4795: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4796: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4797: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4798: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4799: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4800: } else {
1.484.2.34 raeburn 4801: $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 4802: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4803: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4804: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4805: }
4806: $output .= "\n".'</ul>'."\n";
4807: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4808: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4809: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4810: return $output;
1.442 www 4811: }
4812:
4813: #
4814: # End tabs
4815: #
4816:
4817: sub endContentScreen {
1.484 raeburn 4818: return '</div></div></div>';
1.442 www 4819: }
1.329 droeschl 4820:
1.446 www 4821: sub supplemental_base {
1.484.2.33 raeburn 4822: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4823: }
4824:
1.329 droeschl 4825: sub handler {
4826: my $r = shift;
4827: &Apache::loncommon::content_type($r,'text/html');
4828: $r->send_http_header;
4829: return OK if $r->header_only;
1.484 raeburn 4830:
4831: # get course data
1.408 raeburn 4832: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4833: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4834: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4835:
4836: # graphics settings
4837: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4838:
1.443 www 4839: #
1.329 droeschl 4840: # --------------------------------------------- Initialize help topics for this
4841: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4842: 'Adding_External_Resource','Navigate_Content',
4843: 'Adding_Folders','Docs_Overview', 'Load_Map',
4844: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 4845: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 4846: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
4847: 'Dropbox','Simple_Problem') {
1.329 droeschl 4848: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4849: }
4850: # Composite help files
4851: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4852: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4853: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4854: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4855: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4856: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4857: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4858: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4859: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4860: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 4861:
1.484.2.67 raeburn 4862: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 4863: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4864: unless ($r->uri eq '/adm/supplemental') {
4865: # does this user have privileges to modify content.
1.484.2.67 raeburn 4866: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
4867: $allowed = 1;
4868: $canedit = 1;
4869: $canview = 1;
4870: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
4871: $allowed = 1;
4872: $canview = 1;
4873: }
4874: }
4875: unless ($canedit) {
4876: $disabled = ' disabled="disabled"';
1.472 raeburn 4877: }
1.484.2.53 raeburn 4878: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 4879: if ($env{'form.inhibitmenu'}) {
4880: unless ($env{'form.inhibitmenu'} eq 'yes') {
4881: delete($env{'form.inhibitmenu'});
4882: }
4883: }
4884:
1.484.2.53 raeburn 4885: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 4886: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 4887: if (!$canedit) {
4888: &verifycontent($r);
4889: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
4890: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
4891: text=>'Results',
4892: faq=>273,
4893: bug=>'Instructor Interface'});
4894: &verifycontent($r,$env{'form.checkstale'});
4895: } else {
4896: &contentverifyform($r);
4897: }
1.329 droeschl 4898: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4899: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4900: &list_symbs($r);
4901: } elsif ($allowed && $env{'form.docslog'}) {
4902: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4903: my $folder = $env{'form.folder'};
4904: if ($folder eq '') {
4905: $folder='default';
4906: }
1.484.2.67 raeburn 4907: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 4908: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 4909: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 4910: &checkversions($r,$canedit);
4911: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 4912: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4913: &dumpcourse($r);
4914: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 4915: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4916: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4917: } else {
1.445 www 4918: #
4919: # Done catching special calls
1.484 raeburn 4920: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 4921: # Get the parameters that may be needed
4922: #
4923: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 4924: ['folderpath',
4925: 'forcesupplement','forcestandard',
4926: 'tools','symb','command','supppath']);
1.445 www 4927:
1.484.2.78 raeburn 4928: foreach my $item ('forcesupplement','forcestandard','tools') {
4929: next if ($env{'form.'.$item} eq '');
4930: unless ($env{'form.'.$item} eq '1') {
4931: delete($env{'form.'.$item});
4932: }
4933: }
4934:
4935: if ($env{'form.command'}) {
4936: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
4937: delete($env{'form.command'});
4938: }
4939: }
4940:
4941: if ($env{'form.symb'}) {
4942: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
4943: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
4944: delete($env{'form.symb'});
4945: }
4946: }
4947:
1.445 www 4948: # standard=1: this is a "new-style" course with an uploaded map as top level
4949: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 4950:
4951: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 4952:
1.484 raeburn 4953: # Decide whether this should display supplemental or main content or utilities
1.445 www 4954: # supplementalflag=1: show supplemental documents
4955: # supplementalflag=0: show standard documents
1.484 raeburn 4956: # toolsflag=1: show utilities
1.445 www 4957:
1.484.2.39 raeburn 4958: my $unesc_folderpath = &unescape($env{'form.folderpath'});
4959: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
4960: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 4961: $supplementalflag=0;
4962: }
4963: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4964: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4965: unless ($allowed) { $supplementalflag=1; }
4966: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 4967: my $toolsflag=0;
4968: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 4969:
1.484.2.78 raeburn 4970: if ($env{'form.folderpath'} ne '') {
4971: my @items = split(/\&/,$env{'form.folderpath'});
4972: my $badpath;
4973: for (my $i=0; $i<@items; $i++) {
4974: my $odd = $i%2;
4975: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
4976: $badpath = 1;
4977: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
4978: $badpath = 1;
4979: }
4980: last if ($badpath);
4981: }
4982: if ($badpath) {
4983: delete($env{'form.folderpath'});
4984: }
4985: }
4986:
4987: if ($env{'form.supppath'} ne '') {
4988: my @items = split(/\&/,$env{'form.supppath'});
4989: my $badpath;
4990: for (my $i=0; $i<@items; $i++) {
4991: my $odd = $i%2;
4992: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
4993: $badpath = 1;
4994: }
4995: last if ($badpath);
4996: }
4997: if ($badpath) {
4998: delete($env{'form.supppath'});
4999: }
5000: }
5001:
1.329 droeschl 5002: my $script='';
5003: my $showdoc=0;
1.457 raeburn 5004: my $addentries = {};
1.475 raeburn 5005: my $container;
1.329 droeschl 5006: my $containertag;
1.484.2.17 raeburn 5007: my $pathitem;
1.484.2.67 raeburn 5008: my $hiddentop;
5009: my $navmap;
5010: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5011:
1.464 www 5012: # Do we directly jump somewhere?
1.484.2.21 raeburn 5013: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5014: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5015: $env{'form.folderpath'}=
1.484.2.67 raeburn 5016: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5017: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5018: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5019: } elsif ($env{'form.supppath'} ne '') {
5020: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5021: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5022: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5023: }
1.472 raeburn 5024: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5025: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5026: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5027: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5028: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5029: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5030: } elsif ($env{'form.command'} eq 'contents') {
5031: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5032: } elsif ($env{'form.command'} eq 'home') {
5033: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5034: }
5035:
1.484.2.23 raeburn 5036:
1.445 www 5037: # Where do we store these for when we come back?
5038: my $stored_folderpath='docs_folderpath';
5039: if ($supplementalflag) {
5040: $stored_folderpath='docs_sup_folderpath';
5041: }
1.464 www 5042:
1.484.2.19 raeburn 5043: # No folderpath, and in edit mode, see if we have something stored
5044: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5045: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5046: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5047:
5048: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5049: if ($supplementalflag) {
5050: undef($env{'form.folderpath'}) if ($1 eq 'default');
5051: } else {
5052: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5053: }
5054: } else {
1.484.2.19 raeburn 5055: undef($env{'form.folderpath'});
5056: }
1.329 droeschl 5057: }
1.446 www 5058:
5059: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5060: if (!$allowed) {
1.446 www 5061: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5062: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5063: }
5064: }
1.446 www 5065: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5066: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5067: $env{'form.folderpath'} = &supplemental_base()
5068: .'&'.
1.329 droeschl 5069: $env{'form.folderpath'};
5070: }
1.484.2.67 raeburn 5071: # If allowed and user's role is not advanced check folderpath is not hidden
5072: if (($allowed) && (!$env{'request.role.adv'}) &&
5073: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5074: my $folderurl;
5075: my @pathitems = split(/\&/,$env{'form.folderpath'});
5076: my $folder = $pathitems[-2];
5077: if ($folder eq '') {
5078: undef($env{'form.folderpath'});
5079: } else {
5080: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5081: if ((split(/\:/,$pathitems[-1]))[4]) {
5082: $folderurl .= '.page';
5083: } else {
5084: $folderurl .= '.sequence';
5085: }
5086: unless (ref($navmap)) {
5087: $navmap = Apache::lonnavmaps::navmap->new();
5088: }
5089: if (ref($navmap)) {
5090: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5091: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5092: unless (@resources) {
5093: undef($env{'form.folderpath'});
5094: }
5095: }
5096: }
5097: }
5098: }
5099:
5100:
1.446 www 5101: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5102: unless ($env{'form.folderpath'}) {
1.446 www 5103: if ($supplementalflag) {
5104: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5105: } elsif ($allowed) {
5106: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5107: }
1.472 raeburn 5108: }
1.446 www 5109:
1.445 www 5110: # Store this
1.484 raeburn 5111: unless ($toolsflag) {
1.484.2.67 raeburn 5112: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5113: &Apache::loncommon::store_course_settings($stored_folderpath,
5114: {'folderpath' => 'scalar'});
5115: }
5116: my $folderpath;
1.484 raeburn 5117: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5118: $folderpath = $env{'form.folderpath'};
5119: my (@folders)=split('&',$env{'form.folderpath'});
5120: $env{'form.foldername'}=&unescape(pop(@folders));
5121: if ($env{'form.foldername'} =~ /\:1$/) {
5122: $container = 'page';
5123: } else {
5124: $container = 'sequence';
5125: }
5126: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5127: } else {
1.484.2.19 raeburn 5128: if ($env{'form.folder'} eq '' ||
5129: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5130: if ($env{'form.folder'} eq 'supplemental') {
5131: $folderpath=&supplemental_base();
5132: } elsif (!$hiddentop) {
5133: $folderpath='default&'.
5134: &escape(&mt('Main Content').':::::');
5135: }
1.484 raeburn 5136: }
5137: }
1.484.2.19 raeburn 5138: $containertag = '<input type="hidden" name="folderpath" value="" />';
5139: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5140: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5141: $showdoc='/'.$1;
5142: }
5143: if ($showdoc) { # got called in sequence from course
5144: $allowed=0;
5145: } else {
1.484.2.67 raeburn 5146: if ($canedit) {
1.484 raeburn 5147: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5148: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5149: }
5150: }
1.329 droeschl 5151: }
5152:
1.344 bisitz 5153: # get personal data
1.329 droeschl 5154: my $uname=$env{'user.name'};
5155: my $udom=$env{'user.domain'};
5156: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5157:
5158: if ($allowed) {
1.484 raeburn 5159: if ($toolsflag) {
5160: $script .= &inject_data_js();
5161: my ($home,$other,%outhash)=&authorhosts();
5162: if (!$home && $other) {
5163: my @hosts;
5164: foreach my $aurole (keys(%outhash)) {
5165: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5166: push(@hosts,$outhash{$aurole});
5167: }
5168: }
5169: $script .= &dump_switchserver_js(@hosts);
5170: }
1.458 raeburn 5171: } else {
1.484.2.43 raeburn 5172: my $tid = 1;
1.484 raeburn 5173: my @tabids;
5174: if ($supplementalflag) {
5175: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5176: $tid = 2;
1.484 raeburn 5177: } else {
5178: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5179: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5180: unshift(@tabids,'001');
5181: push(@tabids,('dd1','ee1'));
5182: }
1.458 raeburn 5183: }
1.484 raeburn 5184: my $tabidstr = join("','",@tabids);
1.484.2.80! raeburn 5185: my $hostname = $r->hostname();
1.484.2.68 raeburn 5186: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.80! raeburn 5187: $canedit,$hostname,\$navmap).
1.484 raeburn 5188: &history_tab_js().
5189: &inject_data_js().
1.484.2.43 raeburn 5190: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5191: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5192: $addentries = {
1.484.2.3 raeburn 5193: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5194: };
1.458 raeburn 5195: }
1.484.2.30 raeburn 5196: $script .= &paste_popup_js();
1.484.2.12 raeburn 5197: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5198: &mt('Switch server?');
1.484.2.19 raeburn 5199:
5200:
1.329 droeschl 5201: }
5202: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5203: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5204: .'// <![CDATA['."\n"
5205: .$script."\n"
5206: .'// ]]>'."\n"
5207: .'</script>'."\n";
1.385 bisitz 5208:
5209: # Breadcrumbs
5210: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5211:
5212: if ($showdoc) {
5213: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5214: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5215: } elsif ($toolsflag) {
1.484.2.67 raeburn 5216: my ($breadtext,$breadtitle);
5217: $breadtext = "$crstype Editor";
5218: if ($canedit) {
5219: $breadtitle = 'Editing '.$crstype.' Contents';
5220: } else {
5221: $breadtext .= ' (View-only mode)';
5222: $breadtitle = 'Viewing '.$crstype.' Contents';
5223: }
1.484.2.44 raeburn 5224: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5225: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5226: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5227: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5228: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5229: $breadtitle)
1.484.2.44 raeburn 5230: );
1.484.2.19 raeburn 5231: } elsif ($r->uri eq '/adm/supplemental') {
5232: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5233: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5234: {'bread_crumbs' => $brcrum,}));
5235: } else {
1.484.2.67 raeburn 5236: my ($breadtext,$breadtitle,$helpitem);
5237: $breadtext = "$crstype Editor";
5238: if ($canedit) {
5239: $breadtitle = 'Editing '.$crstype.' Contents';
5240: $helpitem = 'Docs_Adding_Course_Doc';
5241: } else {
5242: $breadtext .= ' (View-only mode)';
5243: $breadtitle = 'Viewing '.$crstype.' Contents';
5244: $helpitem = 'Docs_Viewing_Course_Doc';
5245: }
1.392 raeburn 5246: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5247: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5248: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5249: {'add_entries' => $addentries}
5250: )
1.392 raeburn 5251: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5252: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5253: $breadtitle,
5254: $helpitem)
1.392 raeburn 5255: );
5256: }
1.364 bisitz 5257:
1.329 droeschl 5258: my %allfiles = ();
5259: my %codebase = ();
1.440 raeburn 5260: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5261: if ($canedit) {
1.329 droeschl 5262: if (($env{'form.uploaddoc.filename'}) &&
5263: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5264: my $context = $1;
5265: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5266: undef($hadchanges);
1.440 raeburn 5267: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5268: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5269: undef($navmap);
1.329 droeschl 5270: if ($hadchanges) {
5271: &mark_hash_old();
5272: }
1.440 raeburn 5273: $r->print($upload_output);
5274: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5275: # Process file upload - phase two - upload embedded objects
5276: $uploadphase = 'check_embedded';
5277: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5278: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5279: $env{'form.newidx'});
5280: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5281: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5282: my ($destination,$dir_root) = &embedded_destination();
5283: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5284: my $actionurl = '/adm/coursedocs';
5285: my ($result,$flag) =
5286: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5287: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5288: $actionurl);
5289: $r->print($result.&return_to_editor());
5290: } elsif ($env{'form.phase'} eq 'check_embedded') {
5291: # Process file upload - phase three - modify references in HTML file
5292: $uploadphase = 'modified_orightml';
5293: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5294: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5295: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5296: my $result =
5297: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5298: $docuname,$docudom,undef,
5299: $dir_root);
5300: $r->print($result.&return_to_editor());
1.476 raeburn 5301: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5302: $uploadphase = 'decompress_phase_one';
5303: $r->print(&decompression_phase_one().
5304: &return_to_editor());
5305: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5306: $uploadphase = 'decompress_phase_two';
5307: $r->print(&decompression_phase_two().
5308: &return_to_editor());
1.329 droeschl 5309: }
5310: }
5311:
1.484 raeburn 5312: if ($allowed && $toolsflag) {
5313: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5314: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5315: $r->print(&endContentScreen());
5316: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5317: # -----------------------------------------------------------------------------
5318: my %lt=&Apache::lonlocal::texthash(
5319: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5320: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5321: 'upld' => 'Upload Content',
1.329 droeschl 5322: 'srch' => 'Search',
5323: 'impo' => 'Import',
1.484.2.19 raeburn 5324: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5325: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5326: 'selm' => 'Select Map',
5327: 'load' => 'Load Map',
5328: 'newf' => 'New Folder',
5329: 'newp' => 'New Composite Page',
5330: 'syll' => 'Syllabus',
1.425 raeburn 5331: 'navc' => 'Table of Contents',
1.343 biermanm 5332: 'sipa' => 'Simple Course Page',
1.329 droeschl 5333: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5334: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5335: 'drbx' => 'Drop Box',
1.451 www 5336: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5337: 'bull' => 'Discussion Board',
1.347 weissno 5338: 'mypi' => 'My Personal Information Page',
1.353 weissno 5339: 'grpo' => 'Group Portfolio',
1.329 droeschl 5340: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5341: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5342: 'imsf' => 'IMS Upload',
5343: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5344: 'cms' => 'Origin of IMS package',
5345: 'se' => 'Select',
1.484.2.19 raeburn 5346: 'file' => 'File',
1.329 droeschl 5347: 'title' => 'Title',
5348: 'comment' => 'Comment',
1.403 raeburn 5349: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5350: 'bb5' => 'Blackboard 5',
5351: 'bb6' => 'Blackboard 6',
5352: 'angel5' => 'ANGEL 5.5',
5353: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5354: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5355: );
1.329 droeschl 5356: # -----------------------------------------------------------------------------
1.484.2.64 raeburn 5357: # Calculate free quota space for a user or course.
5358: my $quotatype = 'unofficial';
5359: if ($crstype eq 'Community') {
5360: $quotatype = 'community';
5361: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5362: $quotatype = 'official';
5363: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5364: $quotatype = 'textbook';
5365: }
5366: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5367: 'course',$quotatype); # expressed in MB
5368: my $current_disk_usage = 0;
5369: foreach my $subdir ('docs','supplemental') {
5370: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5371: "userfiles/$subdir",1); # expressed in kB
5372: }
5373: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5374: my $usage = $current_disk_usage/1024; # in MB
5375: my $quota = $disk_quota;
5376: my $percent;
5377: if ($disk_quota == 0) {
5378: $percent = 100.0;
5379: } else {
1.484.2.69 raeburn 5380: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5381: }
5382: $usage = sprintf("%.2f",$usage);
5383: $quota = sprintf("%.2f",$quota);
5384: $percent = sprintf("%.0f",$percent);
5385: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5386: $percent.'%',$quota.' MB').'</p>';
5387:
1.329 droeschl 5388: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5389: $quotainfo
1.329 droeschl 5390: $lt{'file'}:<br />
1.484.2.67 raeburn 5391: <input type="file" name="uploaddoc" size="40" $disabled />
1.329 droeschl 5392: FIUP
5393:
5394: my $checkbox=(<<CHBO);
5395: <!-- <label>$lt{'parse'}?
5396: <input type="checkbox" name="parserflag" />
5397: </label> -->
5398: <label>
1.484.2.67 raeburn 5399: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5400: </label>
5401: CHBO
1.484.2.12 raeburn 5402: my $imsfolder = $env{'form.folder'};
5403: if ($imsfolder eq '') {
1.484.2.19 raeburn 5404: $imsfolder = 'default';
1.484.2.12 raeburn 5405: }
5406: my $imspform=(<<IMSFORM);
5407: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5408: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5409: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5410: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5411: <legend>$lt{'imsf'}</legend>
5412: $fileupload
5413: <br />
5414: <p>
1.484.2.19 raeburn 5415: $lt{'cms'}:
1.484.2.67 raeburn 5416: <select name="source" $disabled>
1.484.2.12 raeburn 5417: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5418: <option value="bb5">$lt{'bb5'}</option>
5419: <option value="bb6">$lt{'bb6'}</option>
5420: <option value="angel5">$lt{'angel5'}</option>
5421: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5422: </select>
5423: <input type="hidden" name="folder" value="$imsfolder" />
5424: </p>
5425: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5426: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5427: </fieldset>
5428: </form>
5429: IMSFORM
5430:
1.484.2.19 raeburn 5431: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5432: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5433: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5434: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5435: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5436: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5437: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5438: $fileupload
5439: <br />
5440: $lt{'title'}:<br />
1.484.2.67 raeburn 5441: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5442: $pathitem
1.329 droeschl 5443: <input type="hidden" name="cmd" value="upload_default" />
5444: <br />
1.458 raeburn 5445: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5446: $checkbox
5447: </span>
1.484.2.12 raeburn 5448: <br clear="all" />
1.484.2.67 raeburn 5449: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5450: </fieldset>
5451: </form>
1.383 tempelho 5452: FUFORM
1.329 droeschl 5453:
1.484.2.67 raeburn 5454: my $mapimportjs;
5455: if ($canedit) {
5456: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5457: } else {
5458: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5459: }
1.484.2.19 raeburn 5460: my $importpubform=(<<SEDFFORM);
5461: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5462: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5463: <form action="/adm/coursedocs" method="post" name="mapimportform">
5464: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5465: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5466: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5467: $lt{'copm'}<br />
5468: <span class="LC_nobreak">
1.484.2.19 raeburn 5469: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5470: onfocus="this.blur();$mapimportjs" $disabled />
5471: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5472: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5473: </fieldset>
5474: </form>
5475:
1.383 tempelho 5476: SEDFFORM
1.484.2.67 raeburn 5477:
5478: my $fromstoredjs;
5479: if ($canedit) {
5480: $fromstoredjs = 'open_StoredLinks_Import()';
5481: } else {
5482: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5483: }
5484:
1.484.2.19 raeburn 5485: my @importpubforma = (
5486: { '<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 5487: { '<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 5488: { '<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 5489: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5490: );
5491: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5492: my $extresourcesform =
5493: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5494: $help{'Adding_External_Resource'},
5495: undef,undef,$disabled);
1.329 droeschl 5496: if ($allowed) {
1.484.2.7 raeburn 5497: my $folder = $env{'form.folder'};
5498: if ($folder eq '') {
5499: $folder='default';
5500: }
1.484.2.67 raeburn 5501: if ($canedit) {
5502: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5503: if ($output) {
5504: $r->print($output);
5505: }
1.484.2.30 raeburn 5506: }
1.337 ehlerst 5507: $r->print(<<HIDDENFORM);
5508: <form name="renameform" method="post" action="/adm/coursedocs">
5509: <input type="hidden" name="title" />
5510: <input type="hidden" name="cmd" />
5511: <input type="hidden" name="markcopy" />
5512: <input type="hidden" name="copyfolder" />
5513: $containertag
5514: </form>
1.484 raeburn 5515:
1.337 ehlerst 5516: HIDDENFORM
1.484.2.17 raeburn 5517: $r->print(&makesimpleeditform($pathitem)."\n".
5518: &makedocslogform($pathitem."\n".
1.484 raeburn 5519: '<input type="hidden" name="folder" value="'.
5520: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5521: }
1.442 www 5522:
5523: # Generate the tabs
1.484.2.19 raeburn 5524: my ($mode,$needs_end);
1.472 raeburn 5525: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5526: my @folders = split('&',$env{'form.folderpath'});
5527: unless (@folders > 2) {
5528: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5529: $needs_end = 1;
5530: }
1.472 raeburn 5531: } else {
1.484 raeburn 5532: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5533: $needs_end = 1;
1.472 raeburn 5534: }
1.443 www 5535:
1.442 www 5536: #
5537:
5538: my $savefolderpath;
5539:
1.395 raeburn 5540: if ($allowed) {
1.329 droeschl 5541: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5542: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5543: $folder='default';
1.356 tempelho 5544: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5545: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5546: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5547: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5548: }
5549: my $postexec='';
5550: if ($folder eq 'default') {
1.372 bisitz 5551: $r->print('<script type="text/javascript">'."\n"
5552: .'// <![CDATA['."\n"
5553: .'this.window.name="loncapaclient";'."\n"
5554: .'// ]]>'."\n"
5555: .'</script>'."\n"
1.369 bisitz 5556: );
1.329 droeschl 5557: } else {
5558: #$postexec='self.close();';
5559: }
1.484.2.15 raeburn 5560: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5561: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5562: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5563:
5564: my $newnavform=(<<NNFORM);
5565: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5566: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5567: $pathitem
1.329 droeschl 5568: <input type="hidden" name="importdetail"
5569: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5570: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5571: $help{'Navigate_Content'}
5572: </form>
5573: NNFORM
5574: my $newsmppageform=(<<NSPFORM);
5575: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5576: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5577: $pathitem
1.329 droeschl 5578: <input type="hidden" name="importdetail" value="" />
1.423 onken 5579: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5580: $help{'Simple Page'}
1.329 droeschl 5581: </form>
5582: NSPFORM
5583:
5584: my $newsmpproblemform=(<<NSPROBFORM);
5585: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5586: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5587: $pathitem
1.329 droeschl 5588: <input type="hidden" name="importdetail" value="" />
1.423 onken 5589: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5590: $help{'Simple_Problem'}
1.329 droeschl 5591: </form>
5592:
5593: NSPROBFORM
5594:
5595: my $newdropboxform=(<<NDBFORM);
5596: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5597: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5598: $pathitem
1.329 droeschl 5599: <input type="hidden" name="importdetail" value="" />
1.423 onken 5600: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5601: $help{'Dropbox'}
1.344 bisitz 5602: </form>
1.329 droeschl 5603: NDBFORM
5604:
5605: my $newexuploadform=(<<NEXUFORM);
5606: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5607: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5608: $pathitem
1.329 droeschl 5609: <input type="hidden" name="importdetail" value="" />
1.423 onken 5610: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5611: $help{'Score_Upload_Form'}
5612: </form>
5613: NEXUFORM
5614:
5615: my $newbulform=(<<NBFORM);
5616: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5617: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5618: $pathitem
1.329 droeschl 5619: <input type="hidden" name="importdetail" value="" />
1.423 onken 5620: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5621: $help{'Bulletin Board'}
5622: </form>
5623: NBFORM
5624:
5625: my $newaboutmeform=(<<NAMFORM);
5626: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5627: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5628: $pathitem
1.329 droeschl 5629: <input type="hidden" name="importdetail"
5630: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5631: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5632: $help{'My Personal Information Page'}
1.329 droeschl 5633: </form>
5634: NAMFORM
5635:
5636: my $newaboutsomeoneform=(<<NASOFORM);
5637: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5638: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5639: $pathitem
1.329 droeschl 5640: <input type="hidden" name="importdetail" value="" />
1.423 onken 5641: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5642: </form>
5643: NASOFORM
5644:
5645: my $newrosterform=(<<NROSTFORM);
5646: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5647: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5648: $pathitem
1.329 droeschl 5649: <input type="hidden" name="importdetail"
5650: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5651: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5652: $help{'Course_Roster'}
1.329 droeschl 5653: </form>
5654: NROSTFORM
5655:
1.484.2.27 raeburn 5656: my $newwebpage;
5657: if ($folder =~ /^default_?(\d*)$/) {
5658: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5659: if ($1) {
5660: $newwebpage .= $1;
5661: } else {
5662: $newwebpage .= 'default';
5663: }
5664: $newwebpage .= '/new.html';
5665: }
5666: my $newwebpageform =(<<NWEBFORM);
5667: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5668: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5669: $pathitem
5670: <input type="hidden" name="importdetail" value="$newwebpage" />
5671: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5672: $help{'Web_Page'}
1.484.2.27 raeburn 5673: </form>
5674: NWEBFORM
1.484.2.30 raeburn 5675:
1.484.2.27 raeburn 5676:
1.342 ehlerst 5677: my $specialdocumentsform;
1.383 tempelho 5678: my @specialdocumentsforma;
1.451 www 5679: my $gradingform;
5680: my @gradingforma;
5681: my $communityform;
5682: my @communityforma;
1.351 ehlerst 5683: my $newfolderform;
1.390 tempelho 5684: my $newfolderb;
1.342 ehlerst 5685:
1.451 www 5686: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5687:
1.329 droeschl 5688: my $newpageform=(<<NPFORM);
5689: <form action="/adm/coursedocs" method="post" name="newpage">
5690: <input type="hidden" name="folderpath" value="$path" />
5691: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5692: <input type="hidden" name="active" value="ee" />
1.423 onken 5693: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5694: $help{'Adding_Pages'}
1.329 droeschl 5695: </form>
5696: NPFORM
1.390 tempelho 5697:
5698:
1.351 ehlerst 5699: $newfolderform=(<<NFFORM);
1.329 droeschl 5700: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5701: $pathitem
1.329 droeschl 5702: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5703: <input type="hidden" name="active" value="" />
1.422 onken 5704: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5705: </form>
5706: NFFORM
5707:
5708: my $newsylform=(<<NSYLFORM);
5709: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5710: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5711: $pathitem
1.329 droeschl 5712: <input type="hidden" name="importdetail"
5713: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5714: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5715: $help{'Syllabus'}
1.383 tempelho 5716:
1.329 droeschl 5717: </form>
5718: NSYLFORM
1.364 bisitz 5719:
1.329 droeschl 5720: my $newgroupfileform=(<<NGFFORM);
5721: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5722: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5723: $pathitem
1.329 droeschl 5724: <input type="hidden" name="importdetail"
5725: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5726: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5727: $help{'Group Portfolio'}
1.329 droeschl 5728: </form>
5729: NGFFORM
1.383 tempelho 5730: @specialdocumentsforma=(
1.421 onken 5731: {'<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 5732: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5733: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5734: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5735: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5736: );
5737: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5738:
1.434 raeburn 5739:
5740: my @importdoc = (
1.484.2.19 raeburn 5741: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5742: );
5743: unless ($container eq 'page') {
5744: push(@importdoc,
5745: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5746: );
5747: }
5748: push(@importdoc,
1.484.2.38 raeburn 5749: {'<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 5750: );
1.484.2.12 raeburn 5751: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5752:
1.451 www 5753: @gradingforma=(
5754: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5755: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5756: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5757:
5758: );
5759: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5760:
5761: @communityforma=(
5762: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5763: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5764: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5765: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5766: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5767: );
5768: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5769:
1.330 tempelho 5770: my %orderhash = (
1.484.2.36 raeburn 5771: 'aa' => ['Upload',$fileuploadform],
5772: 'bb' => ['Import',$importpubform],
5773: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5774: );
1.484.2.19 raeburn 5775: unless ($container eq 'page') {
1.434 raeburn 5776: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5777: $orderhash{'dd'} = ['Collaboration',$communityform];
1.484.2.36 raeburn 5778: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5779: }
5780:
1.341 ehlerst 5781: $hadchanges=0;
1.484 raeburn 5782: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5783: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5784: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.68 raeburn 5785: $canedit,\$navmap,$hiddentop);
1.484.2.67 raeburn 5786: undef($navmap);
1.443 www 5787: if ($error) {
5788: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5789: }
5790: if ($hadchanges) {
1.484.2.73 raeburn 5791: unless (&is_hash_old()) {
5792: &mark_hash_old();
5793: }
1.443 www 5794: }
1.341 ehlerst 5795:
1.443 www 5796: &changewarning($r,'');
5797: }
1.458 raeburn 5798: }
1.442 www 5799:
1.443 www 5800: # Supplemental documents start here
5801:
1.329 droeschl 5802: my $folder=$env{'form.folder'};
1.443 www 5803: unless ($supplementalflag) {
1.329 droeschl 5804: $folder='supplemental';
5805: }
5806: if ($folder =~ /^supplemental$/ &&
5807: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5808: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5809: } elsif ($allowed) {
1.356 tempelho 5810: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5811: }
1.484.2.17 raeburn 5812: $pathitem = '<input type="hidden" name="folderpath" value="'.
5813: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5814: if ($allowed) {
5815: my $folderseq=
1.484.2.15 raeburn 5816: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5817:
5818: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 5819: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5820: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5821: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 5822: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 5823: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5824: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5825: $fileupload
5826: <br />
5827: <br />
5828: <span class="LC_nobreak">
5829: $checkbox
5830: </span>
5831: <br /><br />
5832: $lt{'comment'}:<br />
1.383 tempelho 5833: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5834: <br />
1.484.2.19 raeburn 5835: $pathitem
1.329 droeschl 5836: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 5837: <input type='submit' value="$lt{'upld'}" />
5838: </form>
1.484.2.19 raeburn 5839: SUPDOCFORM
1.329 droeschl 5840:
5841: my $supnewfolderform=(<<SNFFORM);
5842: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 5843: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 5844: $pathitem
1.329 droeschl 5845: <input type="hidden" name="importdetail" value="" />
1.423 onken 5846: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 5847: $help{'Adding_Folders'}
1.329 droeschl 5848: </form>
5849: SNFFORM
1.383 tempelho 5850:
1.484.2.19 raeburn 5851: my $supextform =
5852: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5853: $help{'Adding_External_Resource'},
5854: undef,undef,$disabled);
1.329 droeschl 5855:
5856: my $supnewsylform=(<<SNSFORM);
5857: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 5858: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5859: $pathitem
1.329 droeschl 5860: <input type="hidden" name="importdetail"
5861: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5862: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 5863: $help{'Syllabus'}
5864: </form>
5865: SNSFORM
5866:
5867: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 5868: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 5869: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5870: $pathitem
1.329 droeschl 5871: <input type="hidden" name="importdetail"
5872: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5873: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 5874: $help{'My Personal Information Page'}
1.329 droeschl 5875: </form>
5876: SNAMFORM
5877:
1.484.2.27 raeburn 5878: my $supwebpage;
5879: if ($folder =~ /^supplemental_?(\d*)$/) {
5880: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5881: if ($1) {
5882: $supwebpage .= $1;
5883: } else {
5884: $supwebpage .= 'default';
5885: }
5886: $supwebpage .= '/new.html';
5887: }
5888: my $supwebpageform =(<<SWEBFORM);
5889: <form action="/adm/coursedocs" method="post" name="supwebpage">
5890: <input type="hidden" name="active" value="cc" />
5891: $pathitem
5892: <input type="hidden" name="importdetail" value="$supwebpage" />
5893: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 5894: $help{'Web_Page'}
1.484.2.27 raeburn 5895: </form>
5896: SWEBFORM
5897:
1.333 muellerd 5898:
1.383 tempelho 5899: my @specialdocs = (
1.484.2.67 raeburn 5900: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 5901: =>$supnewsylform},
1.484.2.67 raeburn 5902: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 5903: =>$supnewaboutmeform},
1.484.2.27 raeburn 5904: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
5905:
1.383 tempelho 5906: );
1.417 droeschl 5907: my @supimportdoc = (
1.484.2.19 raeburn 5908: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 5909: =>$supextform},
5910: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
5911: =>$supupdocform},
1.484.2.19 raeburn 5912: );
5913:
1.484.2.12 raeburn 5914: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 5915: my %suporderhash = (
1.390 tempelho 5916: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 5917: 'ee' => ['Upload',$supupdocform],
5918: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 5919: );
1.443 www 5920: if ($supplementalflag) {
1.458 raeburn 5921: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5922: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
5923: $canedit);
1.443 www 5924: if ($error) {
5925: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 5926: } else {
5927: if ($suppchanges) {
5928: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
5929: my @ids=&Apache::lonnet::current_machine_ids();
5930: foreach my $server (keys(%servers)) {
5931: next if (grep(/^\Q$server\E$/,@ids));
5932: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 5933: my $cachekey = &escape('suppcount').':'.&escape($hashid);
5934: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 5935: }
5936: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
5937: undef($suppchanges);
5938: }
1.443 www 5939: }
1.393 raeburn 5940: }
1.443 www 5941: } elsif ($supplementalflag) {
1.458 raeburn 5942: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 5943: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 5944: if ($error) {
5945: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 5946: }
1.393 raeburn 5947: }
1.389 tempelho 5948:
1.484.2.19 raeburn 5949: if ($needs_end) {
5950: $r->print(&endContentScreen());
5951: }
1.383 tempelho 5952:
1.329 droeschl 5953: if ($allowed) {
5954: $r->print('
5955: <form method="post" name="extimport" action="/adm/coursedocs">
5956: <input type="hidden" name="title" />
5957: <input type="hidden" name="url" />
5958: <input type="hidden" name="useform" />
5959: <input type="hidden" name="residx" />
5960: </form>');
5961: }
1.484 raeburn 5962: } elsif ($showdoc) {
1.329 droeschl 5963: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 5964: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 5965: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 5966: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 5967: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 5968: }
5969: }
5970: $r->print(&Apache::loncommon::end_page());
5971: return OK;
1.364 bisitz 5972: }
1.329 droeschl 5973:
1.440 raeburn 5974: sub embedded_form_elems {
5975: my ($phase,$primaryurl,$newidx) = @_;
5976: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 5977: $newidx =~s /\D+//g;
1.440 raeburn 5978: return <<STATE;
5979: <input type="hidden" name="folderpath" value="$folderpath" />
5980: <input type="hidden" name="cmd" value="upload_embedded" />
5981: <input type="hidden" name="newidx" value="$newidx" />
5982: <input type="hidden" name="phase" value="$phase" />
5983: <input type="hidden" name="primaryurl" value="$primaryurl" />
5984: STATE
5985: }
5986:
5987: sub embedded_destination {
5988: my $folder=$env{'form.folder'};
5989: my $destination = 'docs/';
5990: if ($folder =~ /^supplemental/) {
5991: $destination = 'supplemental/';
5992: }
5993: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5994: $destination .= 'default/';
5995: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5996: $destination .= $2.'/';
5997: }
1.484.2.78 raeburn 5998: my $newidx = $env{'form.newidx'};
5999: $newidx =~s /\D+//g;
6000: if ($newidx) {
6001: $destination .= $newidx;
6002: }
1.440 raeburn 6003: my $dir_root = '/userfiles';
6004: return ($destination,$dir_root);
6005: }
6006:
6007: sub return_to_editor {
6008: my $actionurl = '/adm/coursedocs';
6009: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6010: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6011: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6012: '</a></p>';
6013: }
6014:
1.476 raeburn 6015: sub decompression_info {
6016: my ($destination,$dir_root) = &embedded_destination();
6017: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6018: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6019: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6020: my $container='sequence';
1.480 raeburn 6021: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6022: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6023: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6024: $container='page';
6025: }
1.480 raeburn 6026: unshift(@hiddens,$pathitem);
6027: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6028: if ($item eq 'newidx') {
6029: next if ($env{'form.'.$item} =~ /\D/);
6030: }
1.480 raeburn 6031: if ($env{'form.'.$item}) {
6032: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6033: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6034: }
1.477 raeburn 6035: }
1.476 raeburn 6036: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6037: $hiddenelem);
6038: }
6039:
6040: sub decompression_phase_one {
6041: my ($dir,$file,$warning,$error,$output);
6042: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6043: &decompression_info();
1.484.2.7 raeburn 6044: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6045: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6046: } else {
6047: my $file = $1;
1.481 raeburn 6048: $output =
6049: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6050: $destination,$dir_root,
6051: $hiddenelem);
6052: if ($env{'form.autoextract_camtasia'}) {
6053: $output .= &remove_archive($docudom,$docuname,$container);
6054: }
1.476 raeburn 6055: }
6056: if ($error) {
6057: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6058: $error.'</p>'."\n";
6059: }
6060: if ($warning) {
6061: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6062: }
6063: return $output;
6064: }
6065:
6066: sub decompression_phase_two {
6067: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6068: &decompression_info();
1.481 raeburn 6069: my $output;
1.480 raeburn 6070: if ($env{'form.archivedelete'}) {
1.481 raeburn 6071: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6072: }
6073: $output .=
1.481 raeburn 6074: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6075: $destination,$dir_root,$hiddenelem);
6076: return $output;
6077: }
6078:
1.480 raeburn 6079: sub remove_archive {
6080: my ($docudom,$docuname,$container) = @_;
6081: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6082: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6083: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6084: if ($fatal) {
6085: if ($container eq 'page') {
6086: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6087: } else {
6088: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6089: }
1.484.2.54 raeburn 6090: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6091: } else {
6092: my $currcmd = $env{'form.cmd'};
6093: my $position = $env{'form.position'};
1.484.2.54 raeburn 6094: my $archiveidx = $position;
6095: if ($position > 0) {
6096: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6097: $archiveidx = $position-1;
6098: }
6099: $env{'form.cmd'} = 'remove_'.$archiveidx;
6100: my ($title,$url,@rrest) =
6101: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6102: if ($url eq $env{'form.archiveurl'}) {
6103: if (&handle_edit_cmd($docuname,$docudom)) {
6104: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6105: if ($fatal) {
6106: if ($container eq 'page') {
6107: $delwarning = &mt('An error occurred updating the contents of the current page.');
6108: } else {
6109: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6110: }
1.480 raeburn 6111: } else {
1.484.2.54 raeburn 6112: $delresult = &mt('Archive file removed.');
1.480 raeburn 6113: }
6114: }
1.484.2.54 raeburn 6115: } else {
6116: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6117: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6118: }
6119: }
6120: $env{'form.cmd'} = $currcmd;
6121: }
6122: if ($delwarning) {
6123: $output = '<p class="LC_warning">'.
6124: $delwarning.
6125: '</p>';
6126: }
6127: if ($delresult) {
6128: $output .= '<p class="LC_info">'.
6129: $delresult.
6130: '</p>';
6131: }
1.481 raeburn 6132: return $output;
1.480 raeburn 6133: }
6134:
1.484 raeburn 6135: sub generate_admin_menu {
1.484.2.67 raeburn 6136: my ($crstype,$canedit) = @_;
1.484 raeburn 6137: my $lc_crstype = lc($crstype);
6138: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6139: my %lt= ( # do not translate here
1.484 raeburn 6140: 'vc' => 'Verify Content',
6141: 'cv' => 'Check/Set Resource Versions',
6142: 'ls' => 'List Resource Identifiers',
6143: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6144: 'dcd' => "Copy $crstype Content to Authoring Space",
6145: );
1.484 raeburn 6146: my ($candump,$dumpurl);
6147: if ($home + $other > 0) {
6148: $candump = 'F';
6149: if ($home) {
6150: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6151: } else {
6152: my @hosts;
6153: foreach my $aurole (keys(%outhash)) {
6154: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6155: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6156: }
1.484 raeburn 6157: }
6158: if (@hosts == 1) {
6159: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6160: '&role='.
6161: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6162: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6163: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6164: } else {
6165: $dumpurl = "javascript:choose_switchserver_window()";
6166: }
6167: }
6168: }
6169: my @menu=
6170: ({ categorytitle=>'Administration',
6171: items =>[
6172: { linktext => $lt{'vc'},
6173: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6174: permission => 'F',
1.484.2.44 raeburn 6175: help => 'Docs_Verify_Content',
1.484 raeburn 6176: icon => 'verify.png',
6177: linktitle => 'Verify contents can be retrieved/rendered',
6178: },
6179: { linktext => $lt{'cv'},
6180: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6181: permission => 'F',
1.484.2.44 raeburn 6182: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6183: icon => 'resversion.png',
6184: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6185: },
6186: { linktext => $lt{'ls'},
6187: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6188: permission => 'F',
6189: #help => '',
6190: icon => 'symbs.png',
6191: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6192: },
6193: ]
1.484.2.67 raeburn 6194: });
6195: if ($canedit) {
6196: push(@menu,
1.484 raeburn 6197: { categorytitle=>'Export',
6198: items =>[
6199: { linktext => $lt{'imse'},
6200: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6201: permission => 'F',
6202: help => 'Docs_Export_Course_Docs',
6203: icon => 'imsexport.png',
6204: linktitle => $lt{'imse'},
6205: },
6206: { linktext => $lt{'dcd'},
6207: url => $dumpurl,
6208: permission => $candump,
1.484.2.44 raeburn 6209: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6210: icon => 'dump.png',
6211: linktitle => $lt{'dcd'},
6212: },
6213: ]
6214: });
1.484.2.67 raeburn 6215: }
1.484 raeburn 6216: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6217: '<input type="hidden" id="dummy" />'."\n".
6218: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6219: '</form>';
1.329 droeschl 6220: }
6221:
6222: sub generate_edit_table {
1.484.2.30 raeburn 6223: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6224: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6225: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6226: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6227: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6228: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6229: $activetab = $env{'form.active'};
6230: }
1.484.2.67 raeburn 6231: unless ($canedit) {
6232: $disabled = ' disabled="disabled"';
6233: }
1.472 raeburn 6234: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6235: my $backtext = &mt('Exit Editor');
1.458 raeburn 6236: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6237: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6238: '<li class="goback">'.
1.484.2.32 raeburn 6239: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6240: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6241: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6242: '<li>'.
6243: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6244: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6245: if ($env{'form.docslog'}) {
6246: $form .= '<li class="active">';
6247: } else {
6248: $form .= '<li>';
6249: }
6250: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6251: &mt('History').'</a></li>'."\n";
6252: if ($env{'form.docslog'}) {
6253: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6254: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6255: }
1.458 raeburn 6256: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6257: if($name ne '00'){
1.371 tempelho 6258: if($activetab eq '' || $activetab ne $name){
6259: $active = '';
6260: }elsif($activetab eq $name){
6261: $active = 'class="active"';
6262: }
1.458 raeburn 6263: $form .= '<li style="float:right" '.$active
1.484 raeburn 6264: .' 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 6265: } else {
1.484.2.43 raeburn 6266: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6267:
6268: }
1.329 droeschl 6269: }
1.484 raeburn 6270: $form .= '</ul>'."\n";
6271: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6272:
6273: if ($to_show ne '') {
1.484.2.30 raeburn 6274: my $saveform;
6275: if ($need_save) {
6276: my $button = &mt('Make changes');
6277: my $path;
6278: if ($env{'form.folderpath'}) {
6279: $path =
6280: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6281: }
6282: $saveform = <<"END";
6283: <div id="multisave" style="display:none; clear:both;" >
6284: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6285: <input type="hidden" name="folderpath" value="$path" />
6286: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6287: <input type="hidden" name="allhiddenresource" value="" />
6288: <input type="hidden" name="allencrypturl" value="" />
6289: <input type="hidden" name="allrandompick" value="" />
6290: <input type="hidden" name="allrandomorder" value="" />
6291: <input type="hidden" name="changeparms" value="" />
6292: <input type="hidden" name="multiremove" value="" />
6293: <input type="hidden" name="multicut" value="" />
6294: <input type="hidden" name="multicopy" value="" />
6295: <input type="hidden" name="multichange" value="" />
6296: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6297: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6298: </form>
6299: </div>
6300: END
6301: }
6302: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6303: }
1.363 ehlerst 6304: foreach my $field (keys(%orderhash)){
1.390 tempelho 6305: if($field ne '00'){
1.422 onken 6306: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6307: $active = 'style="display: none;float:left"';
1.422 onken 6308: }elsif($activetab eq $field){
1.458 raeburn 6309: $active = 'style="display:block;float:left"';
1.422 onken 6310: }
6311: $form .= '<div id="'.$field.$tid.'"'
6312: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6313: .'</div>'."\n";
1.363 ehlerst 6314: }
6315: }
1.484 raeburn 6316: unless ($env{'form.docslog'}) {
6317: $form .= '</div></div>'."\n";
6318: }
1.329 droeschl 6319: return $form;
6320: }
6321:
6322: sub editing_js {
1.484.2.80! raeburn 6323: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,
! 6324: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6325: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6326: p_mnf => 'Name of New Folder',
6327: t_mnf => 'New Folder',
6328: p_mnp => 'Name of New Page',
6329: t_mnp => 'New Page',
1.451 www 6330: p_mxu => 'Title for the External Score',
1.349 biermanm 6331: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6332: p_msb => 'Title for the Problem',
6333: p_mdb => 'Title for the Drop Box',
1.336 schafran 6334: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6335: p_mwp => 'Title for Web Page',
1.348 weissno 6336: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6337: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6338: p_mab_alrt1 => 'Not a valid user:domain',
6339: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6340: p_chn => 'New Title',
6341: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6342: p_rmr2a => 'Remove',
6343: p_rmr2b => '?',
6344: p_rmr3a => 'Remove those',
6345: p_rmr3b => 'items?',
6346: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6347: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6348: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6349: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6350: p_ctr2a => 'Cut',
6351: p_ctr2b => '?',
6352: p_ctr3a => 'Cut those',
6353: p_ctr3b => 'items?',
1.478 raeburn 6354: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6355: imsfile => 'You must choose an IMS package for import',
6356: imscms => 'You must select which Course Management System was the source of the IMS package',
6357: invurl => 'Invalid URL',
6358: titbl => 'Title is blank',
1.484.2.30 raeburn 6359: more => '(More ...)',
6360: less => '(Less ...)',
6361: noor => 'No actions selected or changes to settings specified.',
6362: noch => 'No changes to settings specified.',
6363: noac => 'No actions selected.',
1.484.2.67 raeburn 6364: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6365: );
6366:
1.484.2.61 raeburn 6367: &js_escape(\%js_lt);
1.433 raeburn 6368: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6369: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6370: my $main_container_page;
1.484.2.19 raeburn 6371: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6372: $main_container_page = 1;
1.434 raeburn 6373: }
1.484.2.67 raeburn 6374: my $backtourl;
6375: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6376: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6377:
1.484.2.21 raeburn 6378: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6379: my $caller = $1;
6380: if ($caller =~ /^supplemental/) {
6381: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6382: } else {
6383: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6384: $res = &Apache::lonnet::clutter($res);
6385: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6386: my ($url,$anchor);
6387: if ($res =~ /^([^#]+)#([^#]+)$/) {
6388: $url = $1;
6389: $anchor = $2;
6390: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6391: $caller = $1.&escape('#').$anchor;
6392: }
1.484.2.67 raeburn 6393: } else {
6394: $url = $res;
1.484.2.66 raeburn 6395: }
6396: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.484.2.21 raeburn 6397: &HTML::Entities::encode($caller,'<>&"');
1.484.2.80! raeburn 6398: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
! 6399: if (($ENV{'SERVER_PORT'} == 443) &&
! 6400: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
! 6401: unless (&Apache::lonnet::uses_sts()) {
! 6402: if ($hostname ne '') {
! 6403: $backtourl = 'http://'.$hostname.$backtourl;
! 6404: }
! 6405: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
! 6406: }
! 6407: }
! 6408: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
! 6409: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
! 6410: unless (&Apache::lonnet::uses_sts()) {
! 6411: if ($hostname ne '') {
! 6412: $backtourl = 'http://'.$hostname.$backtourl;
! 6413: }
! 6414: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
! 6415: }
! 6416: }
! 6417: }
1.484.2.66 raeburn 6418: if ($anchor ne '') {
6419: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6420: }
1.484.2.57 raeburn 6421: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6422: } else {
6423: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6424: }
6425: }
6426: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6427: $backtourl = '/adm/menu';
6428: } elsif ($supplementalflag) {
1.472 raeburn 6429: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6430: } else {
6431: $backtourl = '/adm/navmaps';
1.472 raeburn 6432: }
6433:
1.484.2.19 raeburn 6434: my $fieldsets = "'ext','doc'";
6435: unless ($main_container_page) {
6436: $fieldsets .=",'ims'";
6437: }
1.484.2.12 raeburn 6438: if ($supplementalflag) {
6439: $fieldsets = "'suppext','suppdoc'";
6440: }
6441:
1.484.2.67 raeburn 6442: my $jsmakefunctions;
6443: if ($canedit) {
6444: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6445: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6446: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6447: if (foldername) {
6448: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6449: targetform.submit();
6450: }
6451: }
6452:
6453: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6454: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6455: if (pagename) {
6456: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6457: targetform.submit();
6458: }
6459: }
6460:
6461: function makeexamupload() {
1.484.2.61 raeburn 6462: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6463: if (title) {
1.329 droeschl 6464: this.document.forms.newexamupload.importdetail.value=
6465: escape(title)+'=/res/lib/templates/examupload.problem';
6466: this.document.forms.newexamupload.submit();
6467: }
6468: }
6469:
6470: function makesmppage() {
1.484.2.61 raeburn 6471: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6472: if (title) {
1.329 droeschl 6473: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6474: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6475: this.document.forms.newsmppg.submit();
6476: }
6477: }
6478:
1.484.2.27 raeburn 6479: function makewebpage(type) {
1.484.2.61 raeburn 6480: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6481: var formname;
6482: if (type == 'supp') {
6483: formname = this.document.forms.supwebpage;
6484: } else {
6485: formname = this.document.forms.newwebpage;
6486: }
6487: if (title) {
6488: var webpage = formname.importdetail.value;
6489: formname.importdetail.value = escape(title)+'='+webpage;
6490: formname.submit();
6491: }
6492: }
6493:
1.329 droeschl 6494: function makesmpproblem() {
1.484.2.61 raeburn 6495: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6496: if (title) {
1.329 droeschl 6497: this.document.forms.newsmpproblem.importdetail.value=
6498: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6499: this.document.forms.newsmpproblem.submit();
6500: }
6501: }
6502:
6503: function makedropbox() {
1.484.2.61 raeburn 6504: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6505: if (title) {
1.329 droeschl 6506: this.document.forms.newdropbox.importdetail.value=
6507: escape(title)+'=/res/lib/templates/DropBox.problem';
6508: this.document.forms.newdropbox.submit();
6509: }
6510: }
6511:
6512: function makebulboard() {
1.484.2.61 raeburn 6513: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6514: if (title) {
6515: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6516: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6517: this.document.forms.newbul.submit();
6518: }
6519: }
6520:
6521: function makeabout() {
1.484.2.61 raeburn 6522: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6523: if (user) {
6524: var comp=new Array();
6525: comp=user.split(':');
6526: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6527: if ((comp[0]) && (comp[1])) {
6528: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6529: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6530: this.document.forms.newaboutsomeone.submit();
6531: } else {
6532: alert("$js_lt{'p_mab_alrt1'}");
6533: }
6534: } else {
6535: alert("$js_lt{'p_mab_alrt2'}");
6536: }
6537: }
1.335 ehlerst 6538: }
1.484.2.67 raeburn 6539:
6540: function makenew(targetform) {
6541: targetform.submit();
1.335 ehlerst 6542: }
1.484.2.67 raeburn 6543:
6544: function changename(folderpath,index,oldtitle) {
6545: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6546: if (title) {
6547: this.document.forms.renameform.markcopy.value='';
6548: this.document.forms.renameform.title.value=title;
6549: this.document.forms.renameform.cmd.value='rename_'+index;
6550: this.document.forms.renameform.folderpath.value=folderpath;
6551: this.document.forms.renameform.submit();
6552: }
1.329 droeschl 6553: }
6554:
1.484.2.67 raeburn 6555: ENDNEWSCRIPT
6556: } else {
6557: $jsmakefunctions = <<ENDNEWSCRIPT;
6558:
6559: function makenewfolder() {
6560: alert("$js_lt{'edri'}");
6561: }
6562:
6563: function makenewpage() {
6564: alert("$js_lt{'edri'}");
6565: }
6566:
6567: function makeexamupload() {
6568: alert("$js_lt{'edri'}");
6569: }
6570:
6571: function makesmppage() {
6572: alert("$js_lt{'edri'}");
6573: }
6574:
6575: function makewebpage(type) {
6576: alert("$js_lt{'edri'}");
6577: }
6578:
6579: function makesmpproblem() {
6580: alert("$js_lt{'edri'}");
6581: }
6582:
6583: function makedropbox() {
6584: alert("$js_lt{'edri'}");
6585: }
6586:
6587: function makebulboard() {
6588: alert("$js_lt{'edri'}");
6589: }
6590:
6591: function makeabout() {
6592: alert("$js_lt{'edri'}");
6593: }
6594:
6595: function changename() {
6596: alert("$js_lt{'edri'}");
6597: }
6598:
6599: function makenew() {
6600: alert("$js_lt{'edri'}");
6601: }
6602:
6603: function groupimport() {
6604: alert("$js_lt{'edri'}");
6605: }
6606:
6607: function groupsearch() {
6608: alert("$js_lt{'edri'}");
6609: }
6610:
6611: function groupopen(url,recover) {
6612: var options="scrollbars=1,resizable=1,menubar=0";
6613: idxflag=1;
6614: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6615: idx.focus();
6616: }
6617:
6618: ENDNEWSCRIPT
6619:
6620: }
6621: return <<ENDSCRIPT;
6622:
6623: $jsmakefunctions
6624:
1.484.2.13 raeburn 6625: function toggleUpload(caller) {
6626: var blocks = Array($fieldsets);
6627: for (var i=0; i<blocks.length; i++) {
6628: var disp = 'none';
6629: if (caller == blocks[i]) {
6630: var curr = document.getElementById('upload'+caller+'form').style.display;
6631: if (curr == 'none') {
6632: disp='block';
6633: }
6634: }
6635: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6636: }
6637: resize_scrollbox('contentscroll','1','1');
6638: return;
6639: }
6640:
1.484.2.19 raeburn 6641: function toggleMap(caller) {
1.484.2.13 raeburn 6642: var disp = 'none';
1.484.2.19 raeburn 6643: if (document.getElementById('importmapform')) {
6644: if (caller == 'map') {
6645: var curr = document.getElementById('importmapform').style.display;
6646: if (curr == 'none') {
6647: disp='block';
6648: }
1.484.2.12 raeburn 6649: }
1.484.2.19 raeburn 6650: document.getElementById('importmapform').style.display=disp;
6651: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6652: }
1.484.2.19 raeburn 6653: return;
1.329 droeschl 6654: }
6655:
1.484.2.12 raeburn 6656: function makeims(imsform) {
6657: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6658: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6659: return;
6660: }
6661: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6662: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6663: return;
6664: }
6665: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6666: imsform.submit();
6667: }
6668:
1.478 raeburn 6669: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6670: var pickitem;
6671: var picknumitem;
6672: var picknumtext;
6673: if (index == 'all') {
6674: pickitem = document.getElementById('randompickall');
6675: picknumitem = document.getElementById('rpicknumall');
6676: picknumtext = document.getElementById('rpicktextall');
6677: } else {
6678: pickitem = document.getElementById('randompick_'+index);
6679: picknumitem = document.getElementById('rpicknum_'+index);
6680: picknumtext = document.getElementById('randompicknum_'+index);
6681: }
1.478 raeburn 6682: if (pickitem.checked) {
1.484.2.61 raeburn 6683: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6684: if (picknum == '' || picknum == null) {
6685: if (caller == 'check') {
6686: pickitem.checked=false;
1.484.2.29 raeburn 6687: if (index == 'all') {
6688: picknumtext.innerHTML = '';
6689: if (caller == 'link') {
6690: propagateState(targetform,'rpicknum');
6691: }
6692: } else {
1.484.2.30 raeburn 6693: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6694: }
1.478 raeburn 6695: }
6696: } else {
6697: picknum.toString();
6698: var regexdigit=/^\\d+\$/;
6699: if (regexdigit.test(picknum)) {
6700: picknumitem.value = picknum;
1.484.2.29 raeburn 6701: if (index == 'all') {
1.484.2.30 raeburn 6702: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6703: if (caller == 'link') {
6704: propagateState(targetform,'rpicknum');
6705: }
6706: } else {
6707: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6708: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6709: }
1.478 raeburn 6710: } else {
6711: if (caller == 'check') {
1.484.2.29 raeburn 6712: if (index == 'all') {
6713: picknumtext.innerHTML = '';
6714: if (caller == 'link') {
6715: propagateState(targetform,'rpicknum');
6716: }
6717: } else {
6718: pickitem.checked=false;
1.484.2.30 raeburn 6719: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6720: }
1.478 raeburn 6721: }
6722: return;
6723: }
6724: }
6725: } else {
1.484.2.29 raeburn 6726: picknumitem.value = '';
6727: picknumtext.innerHTML = '';
6728: if (index == 'all') {
6729: if (caller == 'link') {
6730: propagateState(targetform,'rpicknum');
6731: }
6732: } else {
1.484.2.30 raeburn 6733: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6734: }
6735: }
6736: }
6737:
6738: function propagateState(form,param) {
6739: if (document.getElementById(param+'all')) {
6740: var setcheck = 0;
6741: var rpick = 0;
6742: if (param == 'rpicknum') {
6743: if (document.getElementById('randompickall')) {
6744: if (document.getElementById('randompickall').checked) {
6745: if (document.getElementById('rpicknumall')) {
6746: rpick = document.getElementById('rpicknumall').value;
6747: }
6748: }
6749: }
6750: } else {
6751: if (document.getElementById(param+'all').checked) {
6752: setcheck = 1;
6753: }
6754: }
1.484.2.30 raeburn 6755: var allidxlist;
6756: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6757: if (document.getElementById('all'+param+'idx')) {
6758: allidxlist = document.getElementById('all'+param+'idx').value;
6759: }
6760: var actions = new Array ('remove','cut','copy');
6761: for (var i=0; i<actions.length; i++) {
6762: if (actions[i] != param) {
6763: if (document.getElementById(actions[i]+'all')) {
6764: document.getElementById(actions[i]+'all').checked = false;
6765: }
6766: }
6767: }
6768: }
1.484.2.29 raeburn 6769: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6770: allidxlist = form.allidx.value;
6771: }
6772: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6773: allidxlist = form.allmapidx.value;
6774: }
6775: if ((allidxlist != '') && (allidxlist != null)) {
6776: var allidxs = allidxlist.split(',');
6777: if (allidxs.length > 1) {
6778: for (var i=0; i<allidxs.length; i++) {
6779: if (document.getElementById(param+'_'+allidxs[i])) {
6780: if (param == 'rpicknum') {
6781: if (document.getElementById('randompick_'+allidxs[i])) {
6782: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6783: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6784: if (rpick > 0) {
6785: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6786: } else {
6787: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6788: }
6789: }
6790: }
6791: } else {
1.484.2.29 raeburn 6792: if (setcheck == 1) {
6793: document.getElementById(param+'_'+allidxs[i]).checked = true;
6794: } else {
6795: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6796: if (param == 'randompick') {
6797: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6798: }
1.484.2.29 raeburn 6799: }
6800: }
6801: }
6802: }
1.484.2.30 raeburn 6803: if (setcheck == 1) {
6804: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6805: var actions = new Array('copy','cut','remove');
6806: for (var i=0; i<actions.length; i++) {
6807: var otheractions;
6808: var otheridxs;
6809: if (actions[i] === param) {
6810: continue;
6811: } else {
6812: if (document.getElementById('all'+actions[i]+'idx')) {
6813: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6814: otheridxs = otheractions.split(',');
6815: if (otheridxs.length > 1) {
6816: for (var j=0; j<otheridxs.length; j++) {
6817: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6818: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6819: }
1.484.2.29 raeburn 6820: }
6821: }
6822: }
6823: }
1.484.2.30 raeburn 6824: }
1.484.2.29 raeburn 6825: }
6826: }
6827: }
6828: }
1.478 raeburn 6829: }
1.484.2.29 raeburn 6830: return;
6831: }
6832:
1.484.2.63 raeburn 6833: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 6834: var canedit = '$canedit';
6835: if (canedit == '') {
6836: alert("$js_lt{'edri'}");
6837: return;
6838: }
1.484.2.30 raeburn 6839: var dosettings;
6840: var doaction;
6841: var control = document.togglemultsettings;
6842: if (context == 'actions') {
6843: control = document.togglemultactions;
6844: doaction = 1;
6845: } else {
6846: dosettings = 1;
6847: }
6848: if (control) {
6849: if (control.showmultpick.length) {
6850: for (var i=0; i<control.showmultpick.length; i++) {
6851: if (control.showmultpick[i].checked) {
6852: if (control.showmultpick[i].value == 1) {
6853: if (context == 'settings') {
6854: dosettings = 0;
6855: } else {
6856: doaction = 0;
6857: }
6858: }
6859: }
6860: }
6861: }
6862: }
6863: if (context == 'settings') {
6864: if (dosettings == 1) {
6865: targetform.changeparms.value=param;
6866: targetform.submit();
6867: }
6868: }
6869: if (context == 'actions') {
6870: if (doaction == 1) {
6871: targetform.cmd.value=param+'_'+index;
6872: targetform.folderpath.value=folderpath;
6873: targetform.markcopy.value=idx+':'+param;
6874: targetform.copyfolder.value=folder+'.'+container;
6875: if (param == 'remove') {
1.484.2.63 raeburn 6876: var doremove = 0;
6877: if (skip_confirm) {
6878: if (confirm_removal) {
6879: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
6880: doremove = 1;
6881: }
6882: } else {
6883: doremove = 1;
6884: }
6885: } else {
6886: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
6887: doremove = 1;
6888: }
6889: }
6890: if (doremove) {
1.484.2.30 raeburn 6891: targetform.markcopy.value='';
6892: targetform.copyfolder.value='';
1.484.2.29 raeburn 6893: targetform.submit();
6894: }
6895: }
1.484.2.30 raeburn 6896: if (param == 'cut') {
1.484.2.61 raeburn 6897: 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 6898: targetform.submit();
6899: return;
6900: }
6901: }
6902: if (param == 'copy') {
6903: targetform.submit();
6904: return;
6905: }
6906: targetform.markcopy.value='';
6907: targetform.copyfolder.value='';
6908: targetform.cmd.value='';
6909: targetform.folderpath.value='';
6910: return;
6911: } else {
6912: if (document.getElementById(param+'_'+idx)) {
6913: item = document.getElementById(param+'_'+idx);
6914: if (item.type == 'checkbox') {
6915: if (item.checked) {
6916: item.checked = false;
6917: } else {
6918: item.checked = true;
6919: singleCheck(item,idx,param);
6920: }
6921: }
6922: }
6923: }
6924: }
6925: return;
6926: }
6927:
6928: function singleCheck(caller,idx,action) {
6929: actions = new Array('cut','copy','remove');
6930: if (caller.checked) {
6931: for (var i=0; i<actions.length; i++) {
6932: if (actions[i] != action) {
6933: if (document.getElementById(actions[i]+'_'+idx)) {
6934: if (document.getElementById(actions[i]+'_'+idx).checked) {
6935: document.getElementById(actions[i]+'_'+idx).checked = false;
6936: }
6937: }
6938: }
1.484.2.29 raeburn 6939: }
6940: }
6941: return;
1.478 raeburn 6942: }
6943:
1.334 muellerd 6944: function unselectInactive(nav) {
1.335 ehlerst 6945: currentNav = document.getElementById(nav);
6946: currentLis = currentNav.getElementsByTagName('LI');
6947: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 6948: if (currentLis[i].className == 'goback') {
6949: currentLis[i].className = 'goback';
6950: } else {
6951: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 6952: currentLis[i].className = 'right';
1.472 raeburn 6953: } else {
1.374 tempelho 6954: currentLis[i].className = 'i';
1.472 raeburn 6955: }
6956: }
1.335 ehlerst 6957: }
1.332 tempelho 6958: }
6959:
1.334 muellerd 6960: function hideAll(current, nav, data) {
1.335 ehlerst 6961: unselectInactive(nav);
1.484.2.43 raeburn 6962: if (current) {
6963: if (current.className == 'right'){
1.374 tempelho 6964: current.className = 'right active'
1.484.2.43 raeburn 6965: } else {
1.374 tempelho 6966: current.className = 'active';
1.484.2.43 raeburn 6967: }
1.374 tempelho 6968: }
1.335 ehlerst 6969: currentData = document.getElementById(data);
6970: currentDivs = currentData.getElementsByTagName('DIV');
6971: for (i = 0; i < currentDivs.length; i++) {
6972: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 6973: currentDivs[i].style.display = 'none';
1.330 tempelho 6974: }
6975: }
1.335 ehlerst 6976: }
1.330 tempelho 6977:
1.374 tempelho 6978: function openTabs(pageId) {
6979: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 6980: if(tabnav.length > 2 ){
1.389 tempelho 6981: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 6982: currentLis = currentNav.getElementsByTagName('LI');
6983: for(i = 0; i< currentLis.length; i++){
6984: if(currentLis[i].className == 'active') {
1.375 tempelho 6985: funcString = currentLis[i].onclick.toString();
6986: tab = funcString.split('"');
1.420 onken 6987: if(tab.length < 2) {
6988: tab = funcString.split("'");
6989: }
1.375 tempelho 6990: currentData = document.getElementById(tab[1]);
6991: currentData.style.display = 'block';
1.374 tempelho 6992: }
6993: }
6994: }
6995: }
6996:
1.334 muellerd 6997: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 6998: currstate = current.className;
1.334 muellerd 6999: hideAll(current, nav, data);
1.375 tempelho 7000: openTabs(pageId);
1.334 muellerd 7001: unselectInactive(nav);
1.484.2.43 raeburn 7002: if ((currstate == 'active') || (currstate == 'right active')) {
7003: if (currstate == 'active') {
7004: current.className = '';
7005: } else {
7006: current.className = 'right';
7007: }
7008: activeTab = '';
7009: toggleUpload();
7010: toggleMap();
7011: resize_scrollbox('contentscroll','1','0');
7012: return;
7013: } else {
7014: current.className = 'active';
7015: }
1.330 tempelho 7016: currentData = document.getElementById(pageId);
7017: currentData.style.display = 'block';
1.458 raeburn 7018: activeTab = pageId;
1.484.2.12 raeburn 7019: toggleUpload();
1.484.2.14 raeburn 7020: toggleMap();
1.433 raeburn 7021: if (nav == 'mainnav') {
7022: var storedpath = "$docs_folderpath";
1.434 raeburn 7023: var storedpage = "$main_container_page";
1.433 raeburn 7024: var reg = new RegExp("^supplemental");
7025: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7026: if (storedpage == 1) {
7027: document.simpleedit.folderpath.value = '';
7028: document.uploaddocument.folderpath.value = '';
7029: } else {
7030: if (reg.test(storedpath)) {
7031: document.simpleedit.folderpath.value = '$toplevelmain';
7032: document.uploaddocument.folderpath.value = '$toplevelmain';
7033: document.newext.folderpath.value = '$toplevelmain';
7034: } else {
7035: document.simpleedit.folderpath.value = storedpath;
7036: document.uploaddocument.folderpath.value = storedpath;
7037: document.newext.folderpath.value = storedpath;
7038: }
1.433 raeburn 7039: }
7040: } else {
1.434 raeburn 7041: if (reg.test(storedpath)) {
7042: document.simpleedit.folderpath.value = storedpath;
7043: document.supuploaddocument.folderpath.value = storedpath;
7044: document.supnewext.folderpath.value = storedpath;
7045: } else {
1.433 raeburn 7046: document.simpleedit.folderpath.value = '$toplevelsupp';
7047: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7048: document.supnewext.folderpath.value = '$toplevelsupp';
7049: }
7050: }
7051: }
1.484.2.3 raeburn 7052: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7053: return false;
7054: }
1.329 droeschl 7055:
1.472 raeburn 7056: function toContents(jumpto) {
7057: var newurl = '$backtourl';
1.484.2.21 raeburn 7058: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7059: newurl = newurl+'?postdata='+jumpto;
7060: }
7061: location.href=newurl;
7062: }
7063:
1.484.2.30 raeburn 7064: function togglePick(caller,value) {
7065: var disp = 'none';
7066: if (document.getElementById('multi'+caller)) {
7067: var curr = document.getElementById('multi'+caller).style.display;
7068: if (value == 1) {
7069: disp='block';
7070: }
7071: if (curr == disp) {
7072: return;
7073: }
7074: document.getElementById('multi'+caller).style.display=disp;
7075: if (value == 1) {
1.484.2.61 raeburn 7076: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7077: } else {
7078: document.getElementById('more'+caller).innerHTML = '';
7079: }
7080: if (caller == 'actions') {
7081: setClass(value);
7082: setBoxes(value);
7083: }
7084: }
7085: var showButton = multiSettings();
7086: if (showButton != 1) {
7087: showButton = multiActions();
7088: }
7089: if (document.getElementById('multisave')) {
7090: if (showButton == 1) {
7091: document.getElementById('multisave').style.display='block';
7092: } else {
7093: document.getElementById('multisave').style.display='none';
7094: }
7095: }
7096: resize_scrollbox('contentscroll','1','1');
7097: return;
7098: }
7099:
7100: function toggleCheckUncheck(caller,more) {
7101: if (more == 1) {
1.484.2.61 raeburn 7102: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7103: document.getElementById('allfields'+caller).style.display='block';
7104: } else {
1.484.2.61 raeburn 7105: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7106: document.getElementById('allfields'+caller).style.display='none';
7107: }
7108: resize_scrollbox('contentscroll','1','1');
7109: }
7110:
7111: function multiSettings() {
7112: var inuse = 0;
7113: var settingsform = document.togglemultsettings;
7114: if (settingsform.showmultpick.length > 1) {
7115: for (var i=0; i<settingsform.showmultpick.length; i++) {
7116: if (settingsform.showmultpick[i].checked) {
7117: if (settingsform.showmultpick[i].value == 1) {
7118: inuse = 1;
7119: }
7120: }
7121: }
7122: }
7123: return inuse;
7124: }
7125:
7126: function multiActions() {
7127: var inuse = 0;
7128: var actionsform = document.togglemultactions;
7129: if (actionsform.showmultpick.length > 1) {
7130: for (var i=0; i<actionsform.showmultpick.length; i++) {
7131: if (actionsform.showmultpick[i].checked) {
7132: if (actionsform.showmultpick[i].value == 1) {
7133: inuse = 1;
7134: }
7135: }
7136: }
7137: }
7138: return inuse;
7139: }
7140:
7141: function checkSubmits() {
7142: var numchanges = 0;
7143: var form = document.saveactions;
7144: var doactions = multiActions();
7145: var cutwarnings = 0;
7146: var remwarnings = 0;
1.484.2.63 raeburn 7147: var removalinfo = 0;
1.484.2.30 raeburn 7148: if (doactions == 1) {
7149: var remidxlist = document.cumulativeactions.allremoveidx.value;
7150: if ((remidxlist != '') && (remidxlist != null)) {
7151: var remidxs = remidxlist.split(',');
7152: for (var i=0; i<remidxs.length; i++) {
7153: if (document.getElementById('remove_'+remidxs[i])) {
7154: if (document.getElementById('remove_'+remidxs[i]).checked) {
7155: form.multiremove.value += remidxs[i]+',';
7156: numchanges ++;
7157: if (document.getElementById('skip_remove_'+remidxs[i])) {
7158: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7159: remwarnings ++;
7160: }
7161: }
1.484.2.63 raeburn 7162: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7163: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7164: removalinfo ++;
7165: }
7166: }
1.484.2.30 raeburn 7167: }
7168: }
7169: }
7170: }
7171: var cutidxlist = document.cumulativeactions.allcutidx.value;
7172: if ((cutidxlist != '') && (cutidxlist != null)) {
7173: var cutidxs = cutidxlist.split(',');
7174: for (var i=0; i<cutidxs.length; i++) {
7175: if (document.getElementById('cut_'+cutidxs[i])) {
7176: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7177: form.multicut.value += cutidxs[i]+',';
7178: numchanges ++;
7179: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7180: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7181: cutwarnings ++;
7182: }
7183: }
7184: }
7185: }
7186: }
7187: }
7188: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7189: if ((copyidxlist != '') && (copyidxlist != null)) {
7190: var copyidxs = copyidxlist.split(',');
7191: for (var i=0; i<copyidxs.length; i++) {
7192: if (document.getElementById('copy_'+copyidxs[i])) {
7193: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7194: form.multicopy.value += copyidxs[i]+',';
7195: numchanges ++;
7196: }
7197: }
7198: }
7199: }
7200: if (numchanges > 0) {
7201: form.multichange.value = numchanges;
7202: }
7203: }
7204: var dosettings = multiSettings();
7205: var haschanges = 0;
7206: if (dosettings == 1) {
7207: form.allencrypturl.value = '';
7208: form.allhiddenresource.value = '';
7209: form.changeparms.value = 'all';
7210: var patt=new RegExp(",\$");
7211: var allidxlist = document.cumulativesettings.allidx.value;
7212: if ((allidxlist != '') && (allidxlist != null)) {
7213: var allidxs = allidxlist.split(',');
7214: if (allidxs.length > 1) {
7215: for (var i=0; i<allidxs.length; i++) {
7216: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7217: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7218: form.allhiddenresource.value += allidxs[i]+',';
7219: }
7220: }
7221: if (document.getElementById('encrypturl_'+allidxs[i])) {
7222: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7223: form.allencrypturl.value += allidxs[i]+',';
7224: }
1.484.2.29 raeburn 7225: }
7226: }
1.484.2.30 raeburn 7227: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7228: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7229: }
7230: }
7231: form.allrandompick.value = '';
7232: form.allrandomorder.value = '';
7233: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7234: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7235: var allmapidxs = allmapidxlist.split(',');
7236: for (var i=0; i<allmapidxs.length; i++) {
7237: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7238: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7239: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7240: if ((randompick.checked) && (rpicknum.value != '')) {
7241: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7242: }
7243: if (randorder.checked) {
7244: form.allrandomorder.value += allmapidxs[i]+',';
7245: }
7246: }
7247: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7248: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7249: }
7250: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7251: haschanges = 1;
7252: }
7253: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7254: haschanges = 1;
7255: }
7256: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7257: haschanges = 1;
7258: }
7259: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7260: haschanges = 1;
7261: }
7262: }
7263: if (doactions == 1) {
7264: if (numchanges > 0) {
1.484.2.63 raeburn 7265: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7266: if (remwarnings > 0) {
1.484.2.61 raeburn 7267: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7268: return false;
7269: }
7270: }
1.484.2.63 raeburn 7271: if (removalinfo > 0) {
7272: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7273: return false;
7274: }
7275: }
1.484.2.30 raeburn 7276: if (cutwarnings > 0) {
1.484.2.61 raeburn 7277: 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 7278: return false;
1.484.2.29 raeburn 7279: }
7280: }
7281: }
1.484.2.30 raeburn 7282: form.submit();
7283: return true;
7284: }
7285: }
7286: if (dosettings == 1) {
7287: if (haschanges == 1) {
7288: form.submit();
7289: return true;
1.484.2.29 raeburn 7290: }
7291: }
1.484.2.30 raeburn 7292: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7293: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7294: } else {
7295: if (dosettings == 1) {
1.484.2.61 raeburn 7296: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7297: } else {
1.484.2.61 raeburn 7298: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7299: }
7300: }
7301: return false;
7302: }
7303:
7304: function setClass(value) {
7305: var cutclass = 'LC_docs_cut';
7306: var copyclass = 'LC_docs_copy';
7307: var removeclass = 'LC_docs_remove';
7308: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7309: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7310: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7311: var links = document.getElementsByTagName('a');
7312: for (var i=0; i<links.length; i++) {
7313: var classes = links[i].className;
7314: if (cutreg.test(classes)) {
7315: links[i].className = cutclass;
7316: if (value == 1) {
7317: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7318: }
1.484.2.30 raeburn 7319: } else {
7320: if (copyreg.test(classes)) {
7321: links[i].className = copyclass;
7322: if (value == 1) {
7323: links[i].className += " LC_menubuttons_link";
7324: }
7325: } else {
7326: if (removereg.test(classes)) {
7327: links[i].className = removeclass;
7328: if (value == 1) {
7329: links[i].className += " LC_menubuttons_link";
7330: }
7331: }
1.484.2.29 raeburn 7332: }
7333: }
7334: }
1.484.2.30 raeburn 7335: return;
1.484.2.29 raeburn 7336: }
7337:
1.484.2.30 raeburn 7338: function setBoxes(value) {
7339: var remidxlist = document.cumulativeactions.allremoveidx.value;
7340: if ((remidxlist != '') && (remidxlist != null)) {
7341: var remidxs = remidxlist.split(',');
7342: for (var i=0; i<remidxs.length; i++) {
7343: if (document.getElementById('remove_'+remidxs[i])) {
7344: var item = document.getElementById('remove_'+remidxs[i]);
7345: if (value == 1) {
7346: item.className = 'LC_docs_remove';
7347: } else {
7348: item.className = 'LC_hidden';
7349: }
7350: }
1.484.2.29 raeburn 7351: }
7352: }
1.484.2.30 raeburn 7353: var cutidxlist = document.cumulativeactions.allcutidx.value;
7354: if ((cutidxlist != '') && (cutidxlist != null)) {
7355: var cutidxs = cutidxlist.split(',');
7356: for (var i=0; i<cutidxs.length; i++) {
7357: if (document.getElementById('cut_'+cutidxs[i])) {
7358: var item = document.getElementById('cut_'+cutidxs[i]);
7359: if (value == 1) {
7360: item.className = 'LC_docs_cut';
7361: } else {
7362: item.className = 'LC_hidden';
7363: }
7364: }
7365: }
7366: }
7367: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7368: if ((copyidxlist != '') && (copyidxlist != null)) {
7369: var copyidxs = copyidxlist.split(',');
7370: for (var i=0; i<copyidxs.length; i++) {
7371: if (document.getElementById('copy_'+copyidxs[i])) {
7372: var item = document.getElementById('copy_'+copyidxs[i]);
7373: if (value == 1) {
7374: item.className = 'LC_docs_copy';
7375: } else {
7376: item.className = 'LC_hidden';
7377: }
7378: }
1.484.2.29 raeburn 7379: }
7380: }
7381: return;
7382: }
7383:
1.484.2.67 raeburn 7384: ENDSCRIPT
1.329 droeschl 7385: }
1.457 raeburn 7386:
1.483 raeburn 7387: sub history_tab_js {
7388: return <<"ENDHIST";
7389: function toggleHistoryDisp(choice) {
7390: document.docslogform.docslog.value = choice;
7391: document.docslogform.submit();
7392: return;
7393: }
7394:
7395: ENDHIST
7396: }
7397:
1.484 raeburn 7398: sub inject_data_js {
7399: return <<ENDINJECT;
7400:
7401: function injectData(current, hiddenField, name, value) {
7402: currentElement = document.getElementById(hiddenField);
7403: currentElement.name = name;
7404: currentElement.value = value;
7405: current.submit();
7406: }
7407:
7408: ENDINJECT
7409: }
7410:
7411: sub dump_switchserver_js {
7412: my @hosts = @_;
1.484.2.61 raeburn 7413: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7414: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7415: swit => 'Switch server?',
1.484.2.61 raeburn 7416: );
7417: my %html_js_lt = &Apache::lonlocal::texthash(
7418: swit => 'Switch server?',
1.484.2.43 raeburn 7419: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7420: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7421: chos => 'Choose server',
7422: );
1.484.2.61 raeburn 7423: &js_escape(\%js_lt);
7424: &html_escape(\%html_js_lt);
7425: &js_escape(\%html_js_lt);
1.484 raeburn 7426: my $role = $env{'request.role'};
7427: my $js = <<"ENDSWJS";
7428: <script type="text/javascript">
7429: function write_switchserver() {
7430: var server;
7431: if (document.setserver.posshosts.length > 0) {
7432: for (var i=0; i<document.setserver.posshosts.length; i++) {
7433: if (document.setserver.posshosts[i].checked) {
7434: server = document.setserver.posshosts[i].value;
7435: }
7436: }
7437: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7438: }
7439: window.close();
7440: }
7441: </script>
7442:
7443: ENDSWJS
7444:
7445: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7446: {'only_body' => 1,
7447: 'js_ready' => 1,});
7448: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7449:
7450: my $hostpicker;
7451: my $count = 0;
7452: foreach my $host (sort(@hosts)) {
7453: my $checked;
7454: if ($count == 0) {
7455: $checked = ' checked="checked"';
7456: }
7457: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7458: $host.'"'.$checked.' />'.$host.'</label> ';
7459: $count++;
7460: }
7461:
7462: return <<"ENDSWITCHJS";
7463:
7464: function dump_needs_switchserver(url) {
7465: if (url!='' && url!= null) {
1.484.2.61 raeburn 7466: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7467: go(url);
7468: }
7469: }
7470: return;
7471: }
7472:
7473: function choose_switchserver_window() {
7474: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7475: newWindow.document.open();
7476: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7477: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7478: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7479: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7480: '<form name="setserver" method="post" action="" \\/>\\n'+
7481: '$hostpicker\\n'+
7482: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7483: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7484: 'onclick="write_switchserver();" \\/>\\n'+
7485: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7486: newWindow.document.writeln('$endpage');
7487: newWindow.document.close();
7488: newWindow.focus();
7489: }
7490:
7491: ENDSWITCHJS
7492: }
7493:
7494: sub makedocslogform {
7495: my ($formelems,$docslog) = @_;
7496: return <<"LOGSFORM";
7497: <form action="/adm/coursedocs" method="post" name="docslogform">
7498: <input type="hidden" name="docslog" value="$docslog" />
7499: $formelems
7500: </form>
7501: LOGSFORM
7502: }
7503:
7504: sub makesimpleeditform {
7505: my ($formelems) = @_;
7506: return <<"SIMPFORM";
7507: <form name="simpleedit" method="post" action="/adm/coursedocs">
7508: <input type="hidden" name="importdetail" value="" />
7509: $formelems
7510: </form>
7511: SIMPFORM
7512: }
7513:
1.329 droeschl 7514: 1;
7515: __END__
7516:
7517:
7518: =head1 NAME
7519:
7520: Apache::londocs.pm
7521:
7522: =head1 SYNOPSIS
7523:
7524: This is part of the LearningOnline Network with CAPA project
7525: described at http://www.lon-capa.org.
7526:
7527: =head1 SUBROUTINES
7528:
7529: =over
7530:
7531: =item %help=()
7532:
7533: Available help topics
7534:
7535: =item mapread()
7536:
1.344 bisitz 7537: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7538: @order and @resources, determines status
7539: sets @order - pointer to resources in right order
7540: sets @resources - array with the resources with correct idx
7541:
7542: =item authorhosts()
7543:
7544: Return hash with valid author names
7545:
7546: =item clean()
7547:
7548: =item dumpcourse()
7549:
7550: Actually dump course
7551:
7552: =item group_import()
7553:
7554: Imports the given (name, url) resources into the course
7555: coursenum, coursedom, and folder must precede the list
7556:
7557: =item breadcrumbs()
7558:
7559: =item log_docs()
7560:
7561: =item docs_change_log()
7562:
7563: =item update_paste_buffer()
7564:
7565: =item print_paste_buffer()
7566:
7567: =item do_paste_from_buffer()
7568:
1.484.2.30 raeburn 7569: =item do_buffer_empty()
7570:
7571: =item clear_from_buffer()
7572:
1.484.2.7 raeburn 7573: =item get_newmap_url()
7574:
7575: =item dbcopy()
7576:
7577: =item uniqueness_check()
7578:
7579: =item contained_map_check()
7580:
7581: =item url_paste_fixups()
7582:
7583: =item apply_fixups()
7584:
7585: =item copy_dependencies()
7586:
1.329 droeschl 7587: =item update_parameter()
7588:
7589: =item handle_edit_cmd()
7590:
7591: =item editor()
7592:
7593: =item process_file_upload()
7594:
7595: =item process_secondary_uploads()
7596:
7597: =item is_supplemental_title()
7598:
7599: =item entryline()
7600:
7601: =item tiehash()
7602:
7603: =item untiehash()
7604:
7605: =item checkonthis()
7606:
7607: check on this
7608:
7609: =item verifycontent()
7610:
7611: Verify Content
7612:
1.484.2.78 raeburn 7613: =item devalidateversioncache()
7614:
7615: =item checkversions()
1.329 droeschl 7616:
7617: Check Versions
7618:
7619: =item mark_hash_old()
7620:
7621: =item is_hash_old()
7622:
7623: =item changewarning()
7624:
7625: =item init_breadcrumbs()
7626:
7627: Breadcrumbs for special functions
7628:
1.484 raeburn 7629: =item create_list_elements()
7630:
7631: =item create_form_ul()
7632:
7633: =item startContentScreen()
7634:
7635: =item endContentScreen()
7636:
7637: =item supplemental_base()
7638:
7639: =item embedded_form_elems()
7640:
7641: =item embedded_destination()
7642:
7643: =item return_to_editor()
7644:
7645: =item decompression_info()
7646:
7647: =item decompression_phase_one()
7648:
7649: =item decompression_phase_two()
7650:
7651: =item remove_archive()
7652:
7653: =item generate_admin_menu()
7654:
7655: =item generate_edit_table()
7656:
7657: =item editing_js()
7658:
7659: =item history_tab_js()
7660:
7661: =item inject_data_js()
7662:
7663: =item dump_switchserver_js()
7664:
1.484.2.3 raeburn 7665: =item resize_scrollbox_js()
1.484 raeburn 7666:
7667: =item makedocslogform()
7668:
1.484.2.3 raeburn 7669: =item makesimpleeditform()
7670:
1.329 droeschl 7671: =back
7672:
7673: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>