Annotation of loncom/interface/londocs.pm, revision 1.484.2.78
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.78! raeburn 4: # $Id: londocs.pm,v 1.484.2.77 2018/04/29 17:29:23 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.484.2.19 raeburn 43: use Apache::lonextresedit();
1.484.2.43 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.329 droeschl 46: use HTML::Entities;
1.484.2.7 raeburn 47: use HTML::TokeParser;
1.329 droeschl 48: use GDBM_File;
1.484.2.51 raeburn 49: use File::MMagic;
1.329 droeschl 50: use Apache::lonlocal;
51: use Cwd;
52: use LONCAPA qw(:DEFAULT :match);
53:
54: my $iconpath;
55:
56: my %hash;
57:
58: my $hashtied;
59: my %alreadyseen=();
60:
61: my $hadchanges;
1.484.2.37 raeburn 62: my $suppchanges;
1.329 droeschl 63:
64:
65: my %help=();
66:
67:
68: sub mapread {
69: my ($coursenum,$coursedom,$map)=@_;
70: return
71: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
72: $map);
73: }
74:
75: sub storemap {
1.484.2.7 raeburn 76: my ($coursenum,$coursedom,$map,$contentchg)=@_;
77: my $report;
78: if (($contentchg) && ($map =~ /^default/)) {
79: $report = 1;
80: }
1.329 droeschl 81: my ($outtext,$errtext)=
82: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 83: $map,1,$report);
1.329 droeschl 84: if ($errtext) { return ($errtext,2); }
1.364 bisitz 85:
1.484.2.37 raeburn 86: if ($map =~ /^default/) {
87: $hadchanges=1;
88: } else {
89: $suppchanges=1;
90: }
1.329 droeschl 91: return ($errtext,0);
92: }
93:
94:
95:
96: sub authorhosts {
97: my %outhash=();
98: my $home=0;
99: my $other=0;
100: foreach my $key (keys(%env)) {
101: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
102: my $role=$1;
103: my $realm=$2;
104: my ($start,$end)=split(/\./,$env{$key});
105: if (($start) && ($start>time)) { next; }
106: if (($end) && (time>$end)) { next; }
107: my ($ca,$cd);
108: if ($1 eq 'au') {
109: $ca=$env{'user.name'};
110: $cd=$env{'user.domain'};
111: } else {
112: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
113: }
114: my $allowed=0;
115: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
116: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 117: foreach my $id (@ids) {
118: if ($id eq $myhome) {
119: $allowed=1;
120: last;
121: }
122: }
1.329 droeschl 123: if ($allowed) {
124: $home++;
1.484 raeburn 125: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 126: } else {
1.484 raeburn 127: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 128: $other++;
129: }
130: }
131: }
132: return ($home,$other,%outhash);
133: }
134:
135:
136: sub clean {
137: my ($title)=@_;
138: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 139: return $title;
1.329 droeschl 140: }
141:
1.484.2.67 raeburn 142: sub default_folderpath {
143: my ($coursenum,$coursedom,$navmapref) = @_;
144: return unless ($coursenum && $coursedom && ref($navmapref));
145: # Check if entire course is hidden and/or encrypted
146: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
147: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
148: unless (ref($$navmapref)) {
149: $$navmapref = Apache::lonnavmaps::navmap->new();
150: }
151: if (ref($$navmapref)) {
152: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
153: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
154: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
155: unless (@resources) {
156: $hiddenmap = 1;
157: unless ($env{'request.role.adv'}) {
158: $hiddentop = 1;
159: if ($env{'form.folder'}) {
160: undef($env{'form.folder'});
161: }
162: }
163: }
164: }
165: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
166: $encryptmap = 1;
167: }
168: }
169: unless ($hiddentop) {
170: $folderpath='default&'.&escape(&mt('Main Content')).
171: '::'.$hiddenmap.':'.$encryptmap.'::';
172: }
173: if (wantarray) {
174: return ($folderpath,$hiddentop);
175: } else {
176: return $folderpath;
177: }
178: }
1.329 droeschl 179:
180: sub dumpcourse {
181: my ($r) = @_;
1.408 raeburn 182: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 183: my ($starthash,$js);
184: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
185: $js = <<"ENDJS";
186: <script type="text/javascript">
187: // <![CDATA[
188:
189: function hide_searching() {
190: if (document.getElementById('searching')) {
191: document.getElementById('searching').style.display = 'none';
192: }
193: return;
194: }
195:
196: // ]]>
197: </script>
198: ENDJS
199: $starthash = {
200: add_entries => {'onload' => "hide_searching();"},
201: };
202: }
203: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
204: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 205: $r->print(&startContentScreen('tools'));
1.329 droeschl 206: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 207: unless ($home) {
208: $r->print(&endContentScreen());
209: return '';
210: }
1.329 droeschl 211: my $origcrsid=$env{'request.course.id'};
212: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
213: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
214: # Do the dumping
1.484 raeburn 215: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
216: $r->print(&endContentScreen());
217: return '';
218: }
1.484.2.24 raeburn 219: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 220: $r->print('<h3>'.&mt('Copying Files').'</h3>');
221: my $title=$env{'form.authorfolder'};
222: $title=&clean($title);
1.484.2.43 raeburn 223: my ($navmap,$errormsg) =
224: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
225: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
226: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
227: my (%maps,%resources,%titles);
228: if (!ref($navmap)) {
229: $r->print($errormsg.
230: &endContentScreen());
231: return '';
232: } else {
233: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
234: 'dumpdocs',$cdom,$cnum);
235: }
236: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
237: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
238: %newcontent,%has_simpleprobs);
239: foreach my $item (sort {$a <=> $b} (@todump)) {
240: my $name = $env{'form.namefor_'.$item};
241: if ($resources{$item}) {
242: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
243: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
244: $tocopy{$1} = $name;
245: $display{$item} = $1;
246: $lookup{$1} = $item;
247: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
248: $simpleproblems{$item} = {
249: symb => $resources{$item},
250: name => $name,
251: };
252: $display{$item} = 'simpleproblem_'.$name;
253: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
254: $has_simpleprobs{$1}{$id} = $item;
255: }
256: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
257: my $marker = $1;
258: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
259: $simplepages{$item} = {
260: res => $res,
261: title => $titles{$item},
262: db => $db_name,
263: marker => $marker,
264: symb => $resources{$item},
265: name => $name,
266: };
267: $display{$item} = '/'.$res;
268: }
269: } elsif ($maps{$item}) {
270: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
271: $tocopy{$1} = $name;
272: $display{$item} = $1;
273: $lookup{$1} = $item;
274: }
275: } else {
276: next;
277: }
278: }
1.329 droeschl 279: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
280: $crs=~s/\_/\//g;
1.484.2.43 raeburn 281: my $mm = new File::MMagic;
282: my $prefix = "/uploaded/$cdom/$cnum/";
283: %replacehash = %tocopy;
284: foreach my $item (sort(keys(%simpleproblems))) {
285: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
286: $newcontent{$display{$item}} = $content;
287: }
288: my $gateway = Apache::lonhtmlgateway->new('web');
289: foreach my $item (sort(keys(%simplepages))) {
290: if (ref($simplepages{$item}) eq 'HASH') {
291: my $pagetitle = $simplepages{$item}{'title'};
292: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
293: my %contents;
294: foreach my $field (keys(%fields)) {
295: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
296: my $name = $1;
297: my $msg = $fields{$field};
298: if ($name eq 'webreferences') {
299: if ($msg =~ m{^https?://}) {
300: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
301: }
302: } else {
303: $msg = &Encode::decode('utf8',$msg);
304: $msg = $gateway->process_outgoing_html($msg,1);
305: $contents{$name} = $msg;
306: }
307: } elsif ($field eq 'uploaded.photourl') {
308: my $marker = $simplepages{$item}{marker};
309: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
310: my $filepath = $1;
311: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
312: if ($fname ne '') {
313: $fname=~s/\.(\w+)$//;
314: my $ext=$1;
315: $fname = &clean($fname);
316: $fname.='.'.$ext;
317: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
318: $replacehash{$filepath} = $relpath.$fname;
319: $deps{$item}{$filepath} = 1;
320: }
321: }
322: }
323: }
324: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
325: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
326: my $content = '
327: <html>
328: <head>
329: <title>'.$pagetitle.'</title>
330: </head>
331: <body bgcolor="#ffffff">';
332: if ($contents{title}) {
333: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
334: }
335: if ($contents{image}) {
336: $content .= "\n".$contents{image};
337: }
338: if ($contents{content}) {
339: $content .= '
340: <div class="LC_Box">
1.484.2.50 raeburn 341: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 342: $contents{content}.'
343: </div>';
344: }
345: if ($contents{webreferences}) {
346: $content .= '
347: <div class="LC_Box">
1.484.2.50 raeburn 348: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 349: $contents{webreferences}.'
350: </div>';
351: }
352: $content .= '
353: </body>
354: </html>
355: ';
356: $newcontent{'/'.$simplepages{$item}{res}} = $content;
357: }
358: }
359: foreach my $item (keys(%tocopy)) {
360: unless ($item=~/\.(sequence|page)$/) {
361: my $currurlpath = $prefix.$item;
362: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
363: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
364: }
365: }
366: foreach my $num (sort {$a <=> $b} (@todump)) {
367: my $src = $display{$num};
368: next if ($src eq '');
369: my @needcopy = ();
370: if ($replacehash{$src}) {
371: push(@needcopy,$src);
372: if (ref($deps{$num}) eq 'HASH') {
373: foreach my $dep (sort(keys(%{$deps{$num}}))) {
374: if ($replacehash{$dep}) {
375: push(@needcopy,$dep);
376: }
377: }
378: }
379: } elsif ($src =~ /^simpleproblem_/) {
380: push(@needcopy,$src);
381: }
382: next if (@needcopy == 0);
383: my ($result,$depresult);
384: for (my $i=0; $i<@needcopy; $i++) {
385: my $item = $needcopy[$i];
386: my $newfilename;
387: if ($simpleproblems{$num}) {
388: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
389: } else {
390: $newfilename=$title.'/'.$replacehash{$item};
391: }
392: $newfilename=~s/\.(\w+)$//;
393: my $ext=$1;
394: $newfilename=&clean($newfilename);
395: $newfilename.='.'.$ext;
396: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
397: if ($newrelpath ne $replacehash{$item}) {
398: $replacehash{$item} = $newrelpath;
399: }
400: my @dirs=split(/\//,$newfilename);
401: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
402: my $makepath=$path;
403: my $fail;
404: my $origin;
405: for (my $i=0;$i<$#dirs;$i++) {
406: $makepath.='/'.$dirs[$i];
407: unless (-e $makepath) {
408: unless(mkdir($makepath,0755)) {
409: $fail = &mt('Directory creation failed.');
410: }
411: }
412: }
413: if ($i == 0) {
414: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
415: } else {
416: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
417: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
418: &mt('(dependency)').'</span>: ';
419: }
420: if (-e $path.'/'.$newfilename) {
421: $fail = &mt('Destination already exists -- not overwriting.');
422: } else {
423: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
424: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
425: ($item =~ /^simpleproblem_/)) {
426: print $fh $newcontent{$item};
427: } else {
428: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
429: if (-e $fileloc) {
430: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
431: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
432: (ref($has_simpleprobs{$item}) eq 'HASH')) {
433: my %changes = %{$has_simpleprobs{$item}};
434: my $content = &Apache::lonclonecourse::rewritefile(
435: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
436: (%replacehash,$crs => '')
437: );
438: my $updatedcontent = '';
439: my $parser = HTML::TokeParser->new(\$content);
440: $parser->attr_encoded(1);
441: while (my $token = $parser->get_token) {
442: if ($token->[0] eq 'S') {
443: if (($token->[1] eq 'resource') &&
444: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
445: ($changes{$token->[2]->{'id'}})) {
446: my $id = $token->[2]->{'id'};
447: $updatedcontent .= '<'.$token->[1];
448: foreach my $attrib (@{$token->[3]}) {
449: next unless ($attrib =~ /^(src|type|title|id)$/);
450: if ($attrib eq 'src') {
451: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
452: if ($file) {
453: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
454: } else {
455: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
456: }
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: }
461: $updatedcontent .= ' />'."\n";
462: } else {
463: $updatedcontent .= $token->[4]."\n";
464: }
465: } else {
466: $updatedcontent .= $token->[2];
467: }
468: }
469: print $fh $updatedcontent;
470: } else {
471: print $fh &Apache::lonclonecourse::rewritefile(
472: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
473: (%replacehash,$crs => '')
474: );
475: }
476: } else {
477: print $fh
478: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
479: }
480: } else {
481: $fail = &mt('Source does not exist.');
482: }
483: }
484: $fh->close();
485: } else {
486: $fail = &mt('Could not write to destination.');
487: }
488: }
489: my $text;
490: if ($fail) {
491: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
492: } else {
493: $text = '<span class="LC_success">'.&mt('ok').'</span>';
494: }
495: if ($i == 0) {
496: $result .= $text;
497: } else {
498: $depresult .= $text.'</li>';
499: }
500: }
501: $r->print($result);
502: if ($depresult) {
503: $r->print('<ul>'.$depresult.'</ul>');
504: }
505: }
1.329 droeschl 506: } else {
1.484.2.43 raeburn 507: my ($navmap,$errormsg) =
508: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
509: if (!ref($navmap)) {
510: $r->print($errormsg);
511: } else {
512: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
513: $r->rflush();
514: my ($preamble,$formname);
515: $formname = 'dumpdoc';
516: unless ($home==1) {
517: $preamble = '<div class="LC_left_float">'.
518: '<fieldset><legend>'.
519: &mt('Select the Authoring Space').
520: '</legend><select name="authorspace">';
521: }
522: my @orderspaces = ();
523: foreach my $key (sort(keys(%outhash))) {
524: if ($key=~/^home_(.+)$/) {
525: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
526: unshift(@orderspaces,$1);
527: } else {
528: push(@orderspaces,$1);
529: }
530: }
531: }
532: if ($home>1) {
533: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
534: }
535: foreach my $user (@orderspaces) {
536: if ($home==1) {
537: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
538: } else {
539: $preamble .= '<option value="'.$user.'">'.$user.' - '.
540: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
541: }
542: }
543: unless ($home==1) {
544: $preamble .= '</select></fieldset></div>'."\n";
545: }
546: my $title=$origcrsdata{'description'};
547: $title=~s/[\/\s]+/\_/gs;
548: $title=&clean($title);
549: $preamble .= '<div class="LC_left_float">'.
550: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
551: '<input type="text" size="50" name="authorfolder" value="'.
552: $title.'" />'.
553: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
554: my %uploadedfiles;
555: &tiehash();
556: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
557: my ($ext)=($file=~/\.(\w+)$/);
558: # FIXME Check supplemental here
559: my $title=$hash{'title_'.$hash{
560: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
561: if (!$title) {
562: $title=$file;
563: } else {
564: $title=~s|/|_|g;
565: }
566: $title=~s/\.(\w+)$//;
567: $title=&clean($title);
568: $title.='.'.$ext;
569: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
570: $uploadedfiles{$file} = $title;
571: }
572: &untiehash();
573: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
574: undef,undef,$preamble,$home,\%uploadedfiles));
575: }
1.329 droeschl 576: }
1.484 raeburn 577: $r->print(&endContentScreen());
1.329 droeschl 578: }
579:
1.484.2.43 raeburn 580: sub recurse_html {
581: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
582: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
583: my (%allfiles,%codebase);
584: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
585: if (keys(%allfiles)) {
586: foreach my $dependency (keys(%allfiles)) {
587: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
588: my ($depurl,$relfile,$newcontainer);
589: if ($dependency =~ m{^/}) {
590: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
591: $relfile = $1;
592: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
593: $newcontainer = $1;
594: next if ($replacehash->{$newcontainer});
595: }
596: $depurl = $dependency;
597: } else {
598: next;
599: }
600: } else {
601: $relfile = $dependency;
602: $depurl = $currurlpath;
603: $depurl =~ s{[^/]+$}{};
604: $depurl .= $dependency;
605: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
606: }
607: next if ($relfile eq '');
608: my $newname = $replacehash->{$container};
609: $newname =~ s{[^/]+$}{};
610: $replacehash->{$newcontainer} = $newname.$relfile;
611: $deps->{$item}{$newcontainer} = 1;
612: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
613: my $depfile = &Apache::lonnet::filelocation('',$depurl);
614: my $type = $mm->checktype_filename($depfile);
615: if ($type eq 'text/html') {
616: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
617: }
618: }
619: }
620: }
621: return;
622: }
623:
1.329 droeschl 624: sub group_import {
625: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
1.484.2.23 raeburn 626: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
627: %removeparam,$importuploaded,$fixuperrors);
628: $allmaps = {};
1.329 droeschl 629: while (@files) {
630: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 631: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 632: && ($caller eq 'londocs')
633: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 634:
1.329 droeschl 635: my $errtext = '';
636: my $fatal = 0;
637: my $newmapstr = '<map>'."\n".
638: '<resource id="1" src="" type="start"></resource>'."\n".
639: '<link from="1" to="2" index="1"></link>'."\n".
640: '<resource id="2" src="" type="finish"></resource>'."\n".
641: '</map>';
642: $env{'form.output'}=$newmapstr;
643: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
644: 'output',$1.$2);
1.484.2.27 raeburn 645: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 646: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
647: $fatal = 2;
648: }
649: if ($fatal) {
650: return ($errtext,$fatal);
651: }
652: }
653: if ($url) {
1.484.2.23 raeburn 654: if (($caller eq 'londocs') &&
655: ($folder =~ /^default/)) {
1.484.2.27 raeburn 656: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 657: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
658: my $cid = $coursedom.'_'.$coursenum;
659: $allmaps =
660: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
661: $chome,$cid);
662: $donechk = 1;
663: }
664: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
665: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
666: \%addedmaps,\%hierarchy,\%titles,$allmaps);
667: $importuploaded = 1;
668: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
669: next if ($allmaps->{$url});
670: }
671: }
1.344 bisitz 672: if (!$residx
1.329 droeschl 673: || defined($LONCAPA::map::zombies[$residx])) {
674: $residx = &LONCAPA::map::getresidx($url,$residx);
675: push(@LONCAPA::map::order, $residx);
676: }
677: my $ext = 'false';
678: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
679: $name = &LONCAPA::map::qtunescape($name);
1.484.2.27 raeburn 680: if ($name eq '') {
1.484.2.30 raeburn 681: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.484.2.27 raeburn 682: }
683: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
684: my $filepath = $1;
685: my $fname = $name;
686: if ($fname =~ /^\W+$/) {
687: $fname = 'web';
688: } else {
689: $fname =~ s/\W/_/g;
690: }
1.484.2.62 raeburn 691: if (length($fname) > 15) {
1.484.2.27 raeburn 692: $fname = substr($fname,0,14);
693: }
694: my $initialtext = &mt('Replace with your own content.');
695: my $newhtml = <<END;
1.484.2.31 raeburn 696: <html>
1.484.2.27 raeburn 697: <head>
698: <title>$name</title>
699: </head>
700: <body bgcolor="#ffffff">
701: $initialtext
702: </body>
703: </html>
704: END
705: $env{'form.output'}=$newhtml;
706: my $result =
707: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
708: 'output',
709: "$filepath/$residx/$fname.html");
710: if ($result =~ m{^/uploaded/}) {
711: $url = $result;
712: if ($filepath =~ /^supplemental/) {
713: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
714: $env{'user.domain'}.'___&&&___'.$name;
715: }
716: } else {
717: return (&mt('Failed to save new web page.'),1);
718: }
719: }
1.484.2.30 raeburn 720: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 721: $LONCAPA::map::resources[$residx] =
1.329 droeschl 722: join(':', ($name, $url, $ext, 'normal', 'res'));
723: }
724: }
1.484.2.23 raeburn 725: if ($importuploaded) {
726: my %import_errors;
727: my %updated = (
728: removefrommap => \%removefrommap,
729: removeparam => \%removeparam,
730: );
1.484.2.26 raeburn 731: my ($result,$msgsarray,$lockerror) =
732: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 733: if (keys(%import_errors) > 0) {
734: $fixuperrors =
735: '<p span class="LC_warning">'."\n".
736: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
737: '<ul>'."\n";
738: foreach my $key (sort(keys(%import_errors))) {
739: $fixuperrors .= '<li>'.$key.'</li>'."\n";
740: }
741: $fixuperrors .= '</ul></p>'."\n";
742: }
1.484.2.26 raeburn 743: if (ref($msgsarray) eq 'ARRAY') {
744: if (@{$msgsarray} > 0) {
745: $fixuperrors .= '<p class="LC_info">'.
746: join('<br />',@{$msgsarray}).
747: '</p>';
748: }
749: }
750: if ($lockerror) {
751: $fixuperrors .= '<p class="LC_error">'.
752: $lockerror.
753: '</p>';
754: }
1.484.2.23 raeburn 755: }
756: my ($errtext,$fatal) =
757: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 758: unless ($fatal) {
759: if ($folder =~ /^supplemental/) {
760: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 761: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
762: $folder.'.'.$container);
1.484.2.37 raeburn 763: }
764: }
1.484.2.23 raeburn 765: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 766: }
767:
768: sub log_docs {
1.484.2.8 raeburn 769: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 770: }
771:
772: {
773: my @oldresources=();
774: my @oldorder=();
775: my $parmidx;
776: my %parmaction=();
777: my %parmvalue=();
778: my $changedflag;
779:
780: sub snapshotbefore {
781: @oldresources=@LONCAPA::map::resources;
782: @oldorder=@LONCAPA::map::order;
783: $parmidx=undef;
784: %parmaction=();
785: %parmvalue=();
786: $changedflag=0;
787: }
788:
789: sub remember_parms {
790: my ($idx,$parameter,$action,$value)=@_;
791: $parmidx=$idx;
792: $parmaction{$parameter}=$action;
793: $parmvalue{$parameter}=$value;
794: $changedflag=1;
795: }
796:
797: sub log_differences {
798: my ($plain)=@_;
799: my %storehash=('folder' => $plain,
800: 'currentfolder' => $env{'form.folder'});
801: if ($parmidx) {
802: $storehash{'parameter_res'}=$oldresources[$parmidx];
803: foreach my $parm (keys(%parmaction)) {
804: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
805: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
806: }
807: }
808: my $maxidx=$#oldresources;
809: if ($#LONCAPA::map::resources>$#oldresources) {
810: $maxidx=$#LONCAPA::map::resources;
811: }
812: for (my $idx=0; $idx<=$maxidx; $idx++) {
813: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
814: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
815: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
816: $changedflag=1;
817: }
818: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
819: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
820: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
821: $changedflag=1;
822: }
823: }
824: $storehash{'maxidx'}=$maxidx;
825: if ($changedflag) { &log_docs(\%storehash); }
826: }
827: }
828:
829: sub docs_change_log {
1.484.2.67 raeburn 830: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 831: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 832: my $navmap;
1.483 raeburn 833: my $js = '<script type="text/javascript">'."\n".
834: '// <![CDATA['."\n".
835: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 836: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
837: $coursedom,$coursenum,$canedit,\$navmap)."\n".
1.483 raeburn 838: &history_tab_js()."\n".
1.484 raeburn 839: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 840: '// ]]>'."\n".
841: '</script>'."\n";
1.484 raeburn 842: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
843: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 844: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 845: my %orderhash;
846: my $container='sequence';
847: my $pathitem;
1.484.2.19 raeburn 848: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 849: $container='page';
850: }
1.484.2.19 raeburn 851: my $folderpath=$env{'form.folderpath'};
852: if ($folderpath eq '') {
1.484.2.67 raeburn 853: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 854: }
1.484.2.67 raeburn 855: undef($navmap);
1.484.2.19 raeburn 856: $pathitem = '<input type="hidden" name="folderpath" value="'.
857: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 858: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
859: my $jumpto = $readfile;
860: $jumpto =~ s{^/}{};
861: my $tid = 1;
1.484.2.7 raeburn 862: if ($supplementalflag) {
863: $tid = 2;
864: }
1.484.2.19 raeburn 865: my ($breadcrumbtrail) =
1.484.2.18 raeburn 866: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 867: $r->print($breadcrumbtrail.
868: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
869: $readfile));
1.329 droeschl 870: my %docslog=&Apache::lonnet::dump('nohist_docslog',
871: $env{'course.'.$env{'request.course.id'}.'.domain'},
872: $env{'course.'.$env{'request.course.id'}.'.num'});
873:
874: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
875:
876: my %saveable_parameters = ('show' => 'scalar',);
877: &Apache::loncommon::store_course_settings('docs_log',
878: \%saveable_parameters);
879: &Apache::loncommon::restore_course_settings('docs_log',
880: \%saveable_parameters);
881: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 882: # FIXME: internationalization seems wrong here
1.329 droeschl 883: my %lt=('hiddenresource' => 'Resources hidden',
884: 'encrypturl' => 'URL hidden',
885: 'randompick' => 'Randomly pick',
886: 'randomorder' => 'Randomly ordered',
887: 'set' => 'set to',
888: 'del' => 'deleted');
1.484 raeburn 889: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
890: $pathitem."\n".
891: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
892: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
893: $r->print('<div class="LC_left_float">'.
894: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
895: &makedocslogform($filter,1).
896: '</fieldset></div><br clear="all" />');
1.329 droeschl 897: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
898: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
899: &mt('After').'</th>'.
900: &Apache::loncommon::end_data_table_header_row());
901: my $shown=0;
902: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
903: if ($env{'form.displayfilter'} eq 'currentfolder') {
904: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
905: }
906: my @changes=keys(%{$docslog{$id}{'logentry'}});
907: if ($env{'form.displayfilter'} eq 'containing') {
908: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
909: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
910: foreach my $key (@changes) {
911: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
912: }
1.344 bisitz 913: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 914: }
915: my $count = 0;
916: my $time =
917: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
918: my $plainname =
919: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
920: $docslog{$id}{'exe_udom'});
921: my $about_me_link =
922: &Apache::loncommon::aboutmewrapper($plainname,
923: $docslog{$id}{'exe_uname'},
924: $docslog{$id}{'exe_udom'});
925: my $send_msg_link='';
926: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
927: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
928: $send_msg_link ='<br />'.
929: &Apache::loncommon::messagewrapper(&mt('Send message'),
930: $docslog{$id}{'exe_uname'},
931: $docslog{$id}{'exe_udom'});
932: }
933: $r->print(&Apache::loncommon::start_data_table_row());
934: $r->print('<td>'.$time.'</td>
935: <td>'.$about_me_link.
936: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
937: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
938: $send_msg_link.'</td><td>'.
939: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 940: my $is_supp = 0;
1.484.2.7 raeburn 941: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
942: $is_supp = 1;
943: }
1.329 droeschl 944: # Before
945: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
946: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
947: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
948: if ($oldname ne $newname) {
1.484.2.7 raeburn 949: my $shown = &LONCAPA::map::qtescape($oldname);
950: if ($is_supp) {
951: $shown = &Apache::loncommon::parse_supplemental_title($shown);
952: }
953: $r->print($shown);
1.329 droeschl 954: }
955: }
956: $r->print('<ul>');
957: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
958: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 959: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
960: if ($is_supp) {
961: $shown = &Apache::loncommon::parse_supplemental_title($shown);
962: }
1.484.2.19 raeburn 963: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 964: }
965: }
966: $r->print('</ul>');
967: # After
968: $r->print('</td><td>');
969:
970: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
971: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
972: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
973: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 974: my $shown = &LONCAPA::map::qtescape($newname);
975: if ($is_supp) {
976: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
977: }
978: $r->print($shown);
1.329 droeschl 979: }
1.364 bisitz 980: }
1.329 droeschl 981: $r->print('<ul>');
982: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
983: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 984: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
985: if ($is_supp) {
986: $shown = &Apache::loncommon::parse_supplemental_title($shown);
987: }
988: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 989: }
990: }
991: $r->print('</ul>');
992: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
993: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
994: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
995: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 996: # FIXME: internationalization seems wrong here
1.329 droeschl 997: $r->print('<li>'.
998: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
999: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1000: .'</li>');
1001: }
1002: }
1003: $r->print('</ul>');
1004: }
1005: # End
1006: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1007: $shown++;
1008: if (!($env{'form.show'} eq &mt('all')
1009: || $shown<=$env{'form.show'})) { last; }
1010: }
1.484 raeburn 1011: $r->print(&Apache::loncommon::end_data_table()."\n".
1012: &makesimpleeditform($pathitem)."\n".
1013: '</div></div>');
1014: $r->print(&endContentScreen());
1.329 droeschl 1015: }
1016:
1017: sub update_paste_buffer {
1.484.2.7 raeburn 1018: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1019: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1020: if ($env{'form.multiremove'}) {
1021: $env{'form.multiremove'} =~ s/,$//;
1022: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1023: }
1024: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1025: if ($env{'form.multicut'}) {
1026: $env{'form.multicut'} =~ s/,$//;
1027: foreach my $item (split(/,/,$env{'form.multicut'})) {
1028: unless ($removals{$item}) {
1029: $cuts{$item} = 1;
1030: push(@possibles,$item.':cut');
1031: }
1032: }
1033: }
1034: if ($env{'form.multicopy'}) {
1035: $env{'form.multicopy'} =~ s/,$//;
1036: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1037: unless ($removals{$item} || $cuts{$item}) {
1038: push(@possibles,$item.':copy');
1039: }
1040: }
1041: }
1042: } elsif ($env{'form.markcopy'}) {
1043: @possibles = split(/,/,$env{'form.markcopy'});
1044: }
1.329 droeschl 1045:
1.484.2.30 raeburn 1046: return if (@possibles == 0);
1.329 droeschl 1047: return if (!defined($env{'form.copyfolder'}));
1048:
1049: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1050: $env{'form.copyfolder'});
1051: return if ($fatal);
1052:
1.484.2.30 raeburn 1053: my %curr_groups = &Apache::longroup::coursegroups();
1054:
1055: # Retrieve current paste buffer suffixes.
1056: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1057: my (%pasteurls,@newpaste);
1058:
1059: # Construct identifiers for current contents of user's paste buffer
1060: if (@currpaste) {
1061: foreach my $suffix (@currpaste) {
1062: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1063: my $url = $env{'docs.markedcopy_url_'.$suffix};
1064: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1065: ($url ne '')) {
1.484.2.41 raeburn 1066: $pasteurls{$cid.'_'.$url} = 1;
1.484.2.30 raeburn 1067: }
1068: }
1069: }
1070:
1071: # Mark items for copying (skip any items already in user's paste buffer)
1072: my %addtoenv;
1073:
1074: foreach my $item (@possibles) {
1075: my ($orderidx,$cmd) = split(/:/,$item);
1076: next if ($orderidx =~ /\D/);
1077: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1078: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1079: my %denied = &action_restrictions($coursenum,$coursedom,
1080: &LONCAPA::map::qtescape($url),
1081: $env{'form.folderpath'},\%curr_groups);
1082: next if ($denied{'copy'});
1083: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1084: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1085: my ($suffix,$errortxt,$locknotfreed) =
1086: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1087: if ($suffix ne '') {
1088: push(@newpaste,$suffix);
1089: } else {
1090: if ($locknotfreed) {
1091: return $locknotfreed;
1092: }
1.484.2.30 raeburn 1093: }
1094: if (&is_supplemental_title($title)) {
1095: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1096: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1097: }
1098:
1099: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1100: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1101: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1102: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1103:
1104: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1105: my $prefix = $1;
1106: my $subdir =$2;
1107: if ($subdir eq '') {
1108: $subdir = $prefix;
1.484.2.7 raeburn 1109: }
1.484.2.30 raeburn 1110: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1111: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1112: \%hierarchy,\%titles,\%allmaps);
1113: if (ref($hierarchy{$url}) eq 'HASH') {
1114: my ($nested,$nestednames);
1115: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1116: $nested =~ s/\&$//;
1117: $nestednames =~ s/\Q___&&&___\E$//;
1118: if ($nested ne '') {
1119: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1120: }
1121: if ($nestednames ne '') {
1122: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1123: }
1.484.2.7 raeburn 1124: }
1125: }
1.484.2.57 raeburn 1126: if ($locknotfreed) {
1127: $output = $locknotfreed;
1128: last;
1129: }
1.484.2.7 raeburn 1130: }
1.484.2.30 raeburn 1131: if (@newpaste) {
1132: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1133: }
1.484.2.7 raeburn 1134: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1135: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1136: return $output;
1.329 droeschl 1137: }
1138:
1.484.2.7 raeburn 1139: sub recurse_uploaded_maps {
1140: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1141: if (ref($hierarchy->{$url}) eq 'HASH') {
1142: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1143: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1144: my (@uploaded,@names,%shorter);
1145: for (my $i=0; $i<@maps; $i++) {
1146: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1147: if ($inner ne '') {
1148: push(@uploaded,$inner);
1149: push(@names,&escape($titles[$i]));
1150: $shorter{$maps[$i]} = $inner;
1151: }
1152: }
1153: $$nestref .= "$dir:".join(',',@uploaded).'&';
1154: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1155: foreach my $map (@maps) {
1156: if ($shorter{$map} ne '') {
1157: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1158: }
1159: }
1160: }
1161: return;
1162: }
1163:
1.329 droeschl 1164: sub print_paste_buffer {
1.484.2.7 raeburn 1165: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1166: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1167:
1.484.2.30 raeburn 1168: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1169: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1170: }
1171:
1.484.2.30 raeburn 1172: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1173: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1174: my $clipboardcount = 0;
1.484.2.7 raeburn 1175:
1.484.2.30 raeburn 1176: # Construct identifiers for current contents of user's paste buffer
1177: foreach my $suffix (@currpaste) {
1178: next if ($suffix =~ /\D/);
1179: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1180: my $url = $env{'docs.markedcopy_url_'.$suffix};
1181: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1182: ($url ne '')) {
1.484.2.47 raeburn 1183: $clipboardcount ++;
1.484.2.30 raeburn 1184: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1185: $canpaste,$nopaste,$othercrs,$areachange);
1186: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1187: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1188: $is_external = 1;
1.484.2.7 raeburn 1189: }
1.484.2.30 raeburn 1190: if ($folder =~ /^supplemental/) {
1191: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1192: unless ($canpaste) {
1193: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1194: }
1.484.2.30 raeburn 1195: } else {
1196: $canpaste = 1;
1.484.2.7 raeburn 1197: }
1.484.2.30 raeburn 1198: if ($canpaste) {
1199: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1200: my $srcdom = $1;
1201: my $srcnum = $2;
1202: my $rem = $3;
1203: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1204: $othercourse = 1;
1205: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1206: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1207: } else {
1208: $canpaste = 0;
1209: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1210: }
1211: }
1.484.2.30 raeburn 1212: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1213: my $prefix = $1;
1214: $parent = $2;
1215: if ($folder !~ /^\Q$prefix\E/) {
1216: $areachange = 1;
1217: }
1218: $is_uploaded_map = 1;
1219: }
1.484.2.76 raeburn 1220: } elsif ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$}) {
1221: if ($cid ne $env{'request.course.id'}) {
1222: my ($srcdom,$srcnum) = split(/_/,$cid);
1223: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1224: $othercrs = '<br />'.&mt('(from another course)');
1225: } else {
1226: $canpaste = 0;
1227: $nopaste = &mt('Paste from another course unavailable.');
1228: }
1229: }
1230: }
1231: if ($canpaste) {
1232: push(@pasteable,$suffix);
1.484.2.30 raeburn 1233: }
1234: }
1235: my $buffer;
1236: if ($is_external) {
1237: $buffer = &mt('External Resource').': '.
1238: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1239: &LONCAPA::map::qtescape($url).')';
1240: } else {
1241: my $icon = &Apache::loncommon::icon($extension);
1242: if ($extension eq 'sequence' &&
1243: $url =~ m{/default_\d+\.sequence$}x) {
1244: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1245: $icon .= '/navmap.folder.closed.gif';
1246: }
1.484.2.57 raeburn 1247: my $title = $env{'docs.markedcopy_title_'.$suffix};
1248: if ($title eq '') {
1249: ($title) = ($url =~ m{/([^/]+)$});
1250: }
1.484.2.30 raeburn 1251: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1252: ': '.
1253: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1254: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1255: }
1256: $pasteitems .= '<div class="LC_left_float">';
1257: my ($options,$onclick);
1258: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1259: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1260: if (($is_uploaded_map) ||
1261: ($url =~ /(bulletinboard|smppg)$/) ||
1262: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1263: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1264: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1265: }
1266: }
1267: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1268: if ($nopaste) {
1269: $pasteitems .= $nopaste;
1270: } else {
1271: if ($othercrs) {
1272: $pasteitems .= $othercrs;
1273: }
1274: if ($options) {
1275: $pasteitems .= $options;
1.484.2.7 raeburn 1276: }
1277: }
1.484.2.30 raeburn 1278: $pasteitems .= '</div>';
1279: }
1280: }
1281: if ($pasteitems eq '') {
1282: &Apache::lonnet::delenv('docs.markedcopies');
1283: }
1284: my ($pasteform,$form_start,$buttons,$form_end);
1285: if ($pasteitems) {
1286: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1287: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1288: if (@pasteable) {
1.484.2.47 raeburn 1289: my $value = &mt('Paste to current folder');
1290: if ($container eq 'page') {
1291: $value = &mt('Paste to current page');
1292: }
1293: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1294: }
1295: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.(' 'x2);
1296: if ($clipboardcount > 1) {
1297: $buttons .=
1298: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1299: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1300: (' 'x2).
1301: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1302: (' 'x2);
1.484.2.7 raeburn 1303: }
1.484.2.48 raeburn 1304: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1305: '</form>';
1.484.2.30 raeburn 1306: } else {
1307: $pasteitems = &mt('Clipboard is empty');
1308: }
1309: $r->print($form_start
1310: .'<fieldset>'
1311: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1312: .$pasteitems
1313: .'</fieldset>'
1314: .$form_end);
1315: }
1316:
1317: sub paste_options {
1318: my ($suffix,$is_uploaded_map,$parent) = @_;
1319: my ($copytext,$movetext);
1320: if ($is_uploaded_map) {
1321: $copytext = &mt('Copy to new folder');
1322: $movetext = &mt('Move old');
1323: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1324: $copytext = &mt('Copy to new board');
1325: $movetext = &mt('Move (not posts)');
1326: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1327: $copytext = &mt('Copy to new page');
1328: $movetext = &mt('Move');
1.484.2.7 raeburn 1329: } else {
1.484.2.30 raeburn 1330: $copytext = &mt('Copy to new file');
1331: $movetext = &mt('Move');
1332: }
1333: my $output = '<br />'.
1334: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1335: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1336: '<label>'.
1337: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1338: $copytext.'</label></span>'.(' 'x2).' '.
1339: '<span class="LC_nobreak"><label>'.
1340: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1341: $movetext.'</label></span>';
1342: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1343: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1344: '</legend><table border="0">';
1345: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1346: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1347: my $lastdir = $parent;
1348: my %depths = (
1349: $lastdir => 0,
1350: );
1351: my (%display,%deps);
1352: for (my $i=0; $i<@pastemaps; $i++) {
1353: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1354: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1355: my @subfolders = split(/,/,$subfolderstr);
1356: $deps{$lastdir} = \@subfolders;
1357: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1358: my $depth = $depths{$lastdir} + 1;
1359: my $offset = int($depth * 4);
1360: my $indent = (' ' x $offset);
1361: for (my $j=0; $j<@subfolders; $j++) {
1362: $depths{$subfolders[$j]} = $depth;
1363: $display{$subfolders[$j]} =
1364: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1365: '<td><label>'.
1366: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1367: '<label>'.
1368: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1369: &mt('Move old').'</label>'.
1370: '</td></tr>';
1371: }
1372: }
1373: &recurse_print(\$output,$parent,\%deps,\%display);
1374: $output .= '</table></fieldset>';
1.329 droeschl 1375: }
1.484.2.30 raeburn 1376: $output .= '</div>';
1377: return $output;
1.329 droeschl 1378: }
1379:
1.484.2.7 raeburn 1380: sub recurse_print {
1.484.2.30 raeburn 1381: my ($outputref,$dir,$deps,$display) = @_;
1382: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1383: if (ref($deps->{$dir}) eq 'ARRAY') {
1384: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1385: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1386: }
1387: }
1388: }
1389:
1390: sub supp_pasteable {
1391: my ($url) = @_;
1392: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1393: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1394: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1395: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1396: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1397: return 1;
1398: }
1399: return;
1400: }
1401:
1402: sub paste_popup_js {
1.484.2.61 raeburn 1403: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1404: show => 'Show Options',
1405: hide => 'Hide Options',
1.484.2.61 raeburn 1406: );
1407: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1408: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1409: );
1.484.2.61 raeburn 1410: &html_escape(\%html_js_lt);
1411: &js_escape(\%html_js_lt);
1412: &js_escape(\%js_lt);
1.484.2.7 raeburn 1413: return <<"END";
1414:
1.484.2.30 raeburn 1415: function showPasteOptions(suffix) {
1416: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1417: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1418: return;
1419: }
1420:
1.484.2.30 raeburn 1421: function hidePasteOptions(suffix) {
1422: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1423: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1424: return;
1425: }
1426:
1.484.2.30 raeburn 1427: function showOptions(caller,suffix) {
1428: if (document.getElementById('pasteoptionstext_'+suffix)) {
1429: if (caller.checked) {
1.484.2.61 raeburn 1430: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1431: } else {
1432: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1433: }
1434: if (document.getElementById('pasteoptions_'+suffix)) {
1435: document.getElementById('pasteoptions_'+suffix).style.display='none';
1436: }
1437: }
1438: return;
1439: }
1.484.2.7 raeburn 1440:
1.484.2.30 raeburn 1441: function validateClipboard() {
1442: var numchk = 0;
1443: if (document.pasteform.pasting.length > 1) {
1444: for (var i=0; i<document.pasteform.pasting.length; i++) {
1445: if (document.pasteform.pasting[i].checked) {
1446: numchk ++;
1447: }
1448: }
1449: } else {
1450: if (document.pasteform.pasting.type == 'checkbox') {
1451: if (document.pasteform.pasting.checked) {
1452: numchk ++;
1453: }
1454: }
1455: }
1456: if (numchk > 0) {
1457: return true;
1458: } else {
1.484.2.61 raeburn 1459: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1460: return false;
1461: }
1.484.2.7 raeburn 1462: }
1463:
1.484.2.47 raeburn 1464: function checkClipboard() {
1465: if (document.pasteform.pasting.length > 1) {
1466: for (var i=0; i<document.pasteform.pasting.length; i++) {
1467: document.pasteform.pasting[i].checked = true;
1468: }
1469: }
1470: return;
1471: }
1472:
1473: function uncheckClipboard() {
1474: if (document.pasteform.pasting.length >1) {
1475: for (var i=0; i<document.pasteform.pasting.length; i++) {
1476: document.pasteform.pasting[i].checked = false;
1477: }
1478: }
1479: return;
1480: }
1481:
1.484.2.30 raeburn 1482: END
1483:
1484: }
1.484.2.7 raeburn 1485:
1.329 droeschl 1486: sub do_paste_from_buffer {
1.484.2.7 raeburn 1487: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1488:
1.484.2.30 raeburn 1489: # Array of items in paste buffer
1490: my (@currpaste,%pastebuffer,%allerrors);
1491: @currpaste = split(/,/,$env{'docs.markedcopies'});
1492:
1.484.2.7 raeburn 1493: # Early out if paste buffer is empty
1.484.2.30 raeburn 1494: if (@currpaste == 0) {
1.484.2.7 raeburn 1495: return ();
1.484.2.30 raeburn 1496: }
1497: map { $pastebuffer{$_} = 1; } @currpaste;
1498:
1499: # Array of items selected items to paste
1500: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1501:
1502: # Early out if nothing selected to paste
1503: if (@reqpaste == 0) {
1504: return();
1505: }
1506: my @topaste;
1507: foreach my $suffix (@reqpaste) {
1508: next if ($suffix =~ /\D/);
1509: next unless (exists($pastebuffer{$suffix}));
1510: push(@topaste,$suffix);
1.484.2.7 raeburn 1511: }
1512:
1.484.2.30 raeburn 1513: # Early out if nothing available to paste
1514: if (@topaste == 0) {
1515: return();
1.329 droeschl 1516: }
1517:
1.484.2.30 raeburn 1518: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.484.2.41 raeburn 1519: %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1520:
1.484.2.30 raeburn 1521: foreach my $suffix (@topaste) {
1522: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1523: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1524: # Supplemental content may only include certain types of content
1525: # Early out if pasted content is not supported in Supplemental area
1526: if ($folder =~ /^supplemental/) {
1527: unless (&supp_pasteable($url)) {
1528: $notinsupp{$suffix} = 1;
1529: next;
1530: }
1531: }
1532: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1533: my $srcd = $1;
1534: my $srcn = $2;
1.484.2.7 raeburn 1535: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1536: # check for mdc privilege in the course from which the resource was pasted
1537: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1538: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1539: $notincrs{$suffix} = 1;
1540: next;
1541: }
1.329 droeschl 1542: }
1.484.2.30 raeburn 1543: $srcdom{$suffix} = $srcd;
1544: $srcnum{$suffix} = $srcn;
1.484.2.76 raeburn 1545: } elsif ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) {
1546: my ($srcd,$srcn) = split(/_/,$cid);
1547: # When paste buffer was populated using an active role in a different course
1548: # check for mdc privilege in the course from which the resource was pasted
1549: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1550: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1551: $notincrs{$suffix} = 1;
1552: next;
1553: }
1554: }
1555: $srcdom{$suffix} = $srcd;
1556: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1557: }
1558: push(@dopaste,$suffix);
1559: if ($url=~/\.(page|sequence)$/) {
1560: $is_map{$suffix} = 1;
1.329 droeschl 1561: }
1.484.2.30 raeburn 1562:
1563: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1564: my $oldprefix = $1;
1.484.2.19 raeburn 1565: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1566: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.19 raeburn 1567: # a folder/page or a document.
1.484.2.30 raeburn 1568: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1569: $prefixchg{$suffix} = 'docstosupp';
1570: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1571: $prefixchg{$suffix} = 'supptodocs';
1572: }
1.484.2.7 raeburn 1573:
1574: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1575: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1576: my @nested;
1577: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1578: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1579: my @deps = map { /\d+:([\d,]+$)/ } @items;
1580: foreach my $dep (@deps) {
1581: if ($dep =~ /,/) {
1582: push(@nested,split(/,/,$dep));
1583: } else {
1584: push(@nested,$dep);
1585: }
1.484.2.7 raeburn 1586: }
1.484.2.30 raeburn 1587: foreach my $item (@nested) {
1588: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1589: push(@{$marktomove{$suffix}},$type.'_'.$item);
1590: }
1.484.2.7 raeburn 1591: }
1592: }
1.329 droeschl 1593: }
1.484.2.7 raeburn 1594: }
1595:
1.484.2.30 raeburn 1596: # Early out if nothing available to paste
1597: if (@dopaste == 0) {
1598: return ();
1599: }
1600:
1601: # Populate message hash and hashes used for main content <=> supplemental content
1602: # changes
1603:
1604: %msgs = &Apache::lonlocal::texthash (
1605: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1606: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1607: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1608: );
1609:
1610: %before = (
1611: docstosupp => {
1612: map => 'default',
1613: doc => 'docs',
1614: },
1615: supptodocs => {
1616: map => 'supplemental',
1617: doc => 'supplemental',
1618: },
1619: );
1620:
1621: %after = (
1622: docstosupp => {
1623: map => 'supplemental',
1624: doc => 'supplemental'
1625: },
1626: supptodocs => {
1627: map => 'default',
1628: doc => 'docs',
1629: },
1630: );
1631:
1632: # Retrieve information about all course maps in main content area
1633:
1634: my $allmaps = {};
1635: if ($folder =~ /^default/) {
1636: $allmaps =
1637: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1638: $env{"course.$env{'request.course.id'}.home"},
1639: $env{'request.course.id'});
1640: }
1641:
1642: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1643:
1644: # Loop over the items to paste
1645: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1646: # Maps need to be copied first
1.484.2.30 raeburn 1647: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1648: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1649: %newurls,%tomove);
1650: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1651: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1652: }
1653: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1654: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1655: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1656: my $oldurl = $url;
1657: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1658: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1659: my (%hierarchy,%titles);
1660: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1661: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1662: if ($url=~ m{^/uploaded/}) {
1663: my $newurl;
1664: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1665: ($newurl,my $error) =
1666: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1667: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1668: \$title,$allmaps,\%newurls);
1669: if ($error) {
1670: $allerrors{$suffix} = $error;
1671: next;
1672: }
1673: if ($newurl ne '') {
1674: if ($newurl ne $url) {
1675: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1676: $newsubdir{$url} = $1;
1677: }
1678: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1679: }
1680: }
1681: }
1.484.2.30 raeburn 1682: if (($srcdom{$suffix} ne $coursedom) ||
1683: ($srcnum{$suffix} ne $coursenum) ||
1684: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1685: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1686: $coursedom,$coursenum,$srcdom{$suffix},
1687: $srcnum{$suffix},$allmaps,\%rewrites,
1688: \%retitles,\%copies,\%dbcopies,
1689: \%zombies,\%params,\%mapmoves,
1690: \%mapchanges,\%tomove,\%newsubdir,
1691: \%newurls)) {
1692: $mapmoves{$url} = 1;
1693: }
1694: $url = $newurl;
1695: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1696: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1697: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1698: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1699: \%zombies,\%params,\%mapmoves,\%mapchanges,
1700: \%tomove,\%newsubdir,\%newurls);
1701: }
1702: } elsif ($url=~m {^/res/}) {
1703: # published map can only exists once, so remove from paste buffer when done
1704: push(@toclear,$suffix);
1705: # if pasting published map (main content area only) check map not already in course
1706: if ($folder =~ /^default/) {
1707: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1708: $duplicate{$suffix} = 1;
1709: next;
1710: }
1.484.2.7 raeburn 1711: }
1712: }
1713: }
1.484.2.30 raeburn 1714: if ($url=~ m{/(bulletinboard|smppg)$}) {
1715: my $prefix = $1;
1.484.2.76 raeburn 1716: my $fromothercrs;
1.484.2.30 raeburn 1717: #need to copy the db contents to a new one, unless this is a move.
1718: my %info = (
1719: src => $url,
1720: cdom => $coursedom,
1721: cnum => $coursenum,
1.484.2.76 raeburn 1722: );
1723: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1724: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1725: $fromothercrs = 1;
1726: $info{'cdom'} = $srcdom{$suffix};
1727: $info{'cnum'} = $srcnum{$suffix};
1728: }
1729: }
1730: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1731: my (%lockerr,$msg);
1732: my ($newurl,$result,$errtext) =
1733: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1734: if ($result eq 'ok') {
1735: $url = $newurl;
1736: $title=&mt('Copy of').' '.$title;
1737: } else {
1738: if ($prefix eq 'smppg') {
1739: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1740: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1741: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.30 raeburn 1742: }
1743: $results{$suffix} = $result;
1744: $msgerrs{$suffix} = $msg;
1745: $lockerrs{$suffix} = $lockerr{$prefix};
1746: next;
1747: }
1748: if ($lockerr{$prefix}) {
1749: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1750: }
1.484.2.7 raeburn 1751: }
1.484.2.30 raeburn 1752: }
1753: $title = &LONCAPA::map::qtunescape($title);
1754: my $ext='false';
1755: if ($url=~m{^http(|s)://}) { $ext='true'; }
1756: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1757: if ($folder !~ /^supplemental/) {
1758: (undef,undef,$title) =
1759: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1760: }
1761: } else {
1762: if ($folder=~/^supplemental/) {
1763: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1764: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1765: }
1766: }
1.484.2.7 raeburn 1767:
1768: # For uploaded files (excluding pages/sequences) path in copied file is changed
1769: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1770: # courses.
1771:
1.484.2.30 raeburn 1772: unless ($is_map{$suffix}) {
1773: my $newidx;
1.329 droeschl 1774: # Now insert the URL at the bottom
1.484.2.30 raeburn 1775: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1776: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1777: my $relpath = $1;
1778: if ($relpath ne '') {
1779: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1780: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1781: my $newprefix = $newloc;
1782: if ($newloc eq 'default') {
1783: $newprefix = 'docs';
1784: }
1785: if ($newdocsdir eq '') {
1786: $newdocsdir = 'default';
1787: }
1788: if (($prefixchg{$suffix}) ||
1789: ($srcdom{$suffix} ne $coursedom) ||
1790: ($srcnum{$suffix} ne $coursenum) ||
1791: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1792: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1793: $url =
1794: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1795: &Apache::lonnet::getfile($oldurl));
1796: if ($url eq '/adm/notfound.html') {
1797: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1798: next;
1799: } else {
1800: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1801: $newsubpath =~ s{/+$}{/};
1802: $docmoves{$oldurl} = $newsubpath;
1803: }
1.484.2.7 raeburn 1804: }
1805: }
1806: }
1.484.2.30 raeburn 1807: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1808: ':'.$ext.':normal:res';
1809: push(@LONCAPA::map::order,$newidx);
1810: # Store the result
1811: my ($errtext,$fatal) =
1812: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1813: if ($fatal) {
1814: $save_err .= $errtext;
1815: $allresult = 'fail';
1.484.2.7 raeburn 1816: }
1.329 droeschl 1817: }
1.484.2.30 raeburn 1818:
1819: # Apply any changes to maps, or copy dependencies for uploaded HTML pages
1820: unless ($allresult eq 'fail') {
1821: my %updated = (
1822: rewrites => \%rewrites,
1823: zombies => \%zombies,
1824: removefrommap => \%removefrommap,
1825: removeparam => \%removeparam,
1826: dbcopies => \%dbcopies,
1827: retitles => \%retitles,
1828: );
1829: my %info = (
1830: newsubdir => \%newsubdir,
1831: params => \%params,
1832: );
1833: if ($prefixchg{$suffix}) {
1834: $info{'before'} = $before{$prefixchg{$suffix}};
1835: $info{'after'} = $after{$prefixchg{$suffix}};
1836: }
1837: my %moves = (
1838: copies => \%copies,
1839: docmoves => \%docmoves,
1840: mapmoves => \%mapmoves,
1841: );
1842: (my $result,$msgs{$suffix},my $lockerror) =
1843: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1844: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1845: $url,'paste');
1846: $lockerrors .= $lockerror;
1847: if ($result eq 'ok') {
1848: if ($is_map{$suffix}) {
1849: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1850: $folder.'.'.$container);
1851: if ($fatal) {
1852: $allresult = 'failread';
1853: } else {
1854: if ($#LONCAPA::map::order<1) {
1855: my $idx=&LONCAPA::map::getresidx();
1856: if ($idx<=0) { $idx=1; }
1857: $LONCAPA::map::order[0]=$idx;
1858: $LONCAPA::map::resources[$idx]='';
1859: }
1860: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1861: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1862: ':'.$ext.':normal:res';
1863: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 1864:
1865: # Store the result
1.484.2.30 raeburn 1866: my ($errtext,$fatal) =
1867: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1868: if ($fatal) {
1869: $save_err .= $errtext;
1870: $allresult = 'failstore';
1871: }
1872: }
1873: }
1874: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1875: push(@toclear,$suffix);
1876: }
1877: }
1.329 droeschl 1878: }
1879: }
1.484.2.30 raeburn 1880: &clear_from_buffer(\@toclear,\@currpaste);
1881: my $msgsarray;
1882: foreach my $suffix (keys(%msgs)) {
1883: if (ref($msgs{$suffix}) eq 'ARRAY') {
1884: $msgsarray .= join(',',@{$msgs{$suffix}});
1885: }
1886: }
1887: return ($allresult,$save_err,$msgsarray,$lockerrors);
1888: }
1889:
1890: sub do_buffer_empty {
1891: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1892: if (@currpaste == 0) {
1893: return &mt('Clipboard is already empty');
1894: }
1895: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1896: if (@toclear == 0) {
1897: return &mt('Nothing selected to clear from clipboard');
1898: }
1899: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1900: if ($numdel) {
1901: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1902: } else {
1903: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 1904: }
1.484.2.30 raeburn 1905: return;
1906: }
1907:
1908: sub clear_from_buffer {
1909: my ($toclear,$currpaste) = @_;
1910: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1911: my %pastebuffer;
1912: map { $pastebuffer{$_} = 1; } @{$currpaste};
1913: my $numdel = 0;
1914: foreach my $suffix (@{$toclear}) {
1915: next if ($suffix =~ /\D/);
1916: next unless (exists($pastebuffer{$suffix}));
1917: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1918: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1919: delete($pastebuffer{$suffix});
1920: $numdel ++;
1921: }
1922: }
1923: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1924: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1925: return $numdel;
1.484.2.7 raeburn 1926: }
1927:
1928: sub get_newmap_url {
1929: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1930: $titleref,$allmaps,$newurls) = @_;
1931: my $newurl;
1932: if ($url=~ m{^/uploaded/}) {
1933: $$titleref=&mt('Copy of').' '.$$titleref;
1934: }
1935: my $now = time;
1936: my $suffix=$$.int(rand(100)).$now;
1937: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1938: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1939: my $path = $1;
1940: my $prefix = $2;
1941: my $ancestor = $3;
1942: if (length($ancestor) > 10) {
1943: $ancestor = substr($ancestor,-10,10);
1944: }
1945: my $newid;
1946: if ($prefixchg) {
1947: if ($folder =~ /^supplemental/) {
1948: $prefix =~ s/^default/supplemental/;
1949: } else {
1950: $prefix =~ s/^supplemental/default/;
1951: }
1952: }
1953: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1954: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1955: } else {
1956: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1957: }
1958: my $counter = 0;
1959: my $is_unique = &uniqueness_check($newurl);
1960: if ($folder =~ /^default/) {
1961: if ($allmaps->{$newurl}) {
1962: $is_unique = 0;
1963: }
1964: }
1965: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1966: $counter ++;
1967: $suffix ++;
1968: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1969: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1970: } else {
1971: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
1972: }
1973: $is_unique = &uniqueness_check($newurl);
1974: }
1975: if ($is_unique) {
1976: $newurls->{$newurl} = 1;
1977: } else {
1978: if ($url=~/\.page$/) {
1979: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
1980: } else {
1981: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
1982: }
1983: }
1984: }
1985: return ($newurl);
1986: }
1987:
1988: sub dbcopy {
1.484.2.26 raeburn 1989: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
1990: my ($url,$result,$errtext);
1991: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 1992: $url = $dbref->{'src'};
1.484.2.26 raeburn 1993: if ($url =~ m{/(smppg|bulletinboard)$}) {
1994: my $prefix = $1;
1995: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
1996: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
1997: my $db_name;
1998: my $marker = (split(m{/},$url))[4];
1999: $marker=~s/\D//g;
2000: if ($dbref->{'src'} =~ m{/smppg$}) {
2001: $db_name =
2002: &Apache::lonsimplepage::get_db_name($url,$marker,
2003: $dbref->{'cdom'},
2004: $dbref->{'cnum'});
2005: } else {
2006: $db_name = 'bulletinpage_'.$marker;
2007: }
2008: my ($suffix,$freedlock,$error) =
2009: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2010: $coursedom,$coursenum,
2011: 'concat');
2012: if (!$suffix) {
2013: if ($prefix eq 'smppg') {
2014: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2015: } else {
1.484.2.42 raeburn 2016: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2017: }
2018: if ($error) {
2019: $errtext .= '<br />'.$error;
2020: }
2021: } else {
2022: #need to copy the db contents to a new one.
2023: my %contents=&Apache::lonnet::dump($db_name,
2024: $dbref->{'cdom'},
2025: $dbref->{'cnum'});
2026: if (exists($contents{'uploaded.photourl'})) {
2027: my $photo = $contents{'uploaded.photourl'};
2028: my ($subdir,$fname) =
2029: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2030: my $newphoto;
2031: if ($fname ne '') {
2032: my $content = &Apache::lonnet::getfile($photo);
2033: unless ($content eq '-1') {
2034: $env{'form.'.$suffix.'.photourl'} = $content;
2035: $newphoto =
2036: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2037: delete($env{'form.'.$suffix.'.photourl'});
2038: }
2039: }
2040: if ($newphoto =~ m{^/uploaded/}) {
2041: $contents{'uploaded.photourl'} = $newphoto;
2042: }
2043: }
2044: $db_name =~ s{_\d*$ }{_$suffix}x;
2045: $result=&Apache::lonnet::put($db_name,\%contents,
2046: $coursedom,$coursenum);
2047: if ($result eq 'ok') {
2048: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2049: }
2050: }
2051: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2052: $lockerrorsref->{$prefix} =
2053: '<div class="LC_error">'.
2054: &mt('There was a problem removing a lockfile.');
2055: if ($prefix eq 'smppg') {
2056: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2057: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.26 raeburn 2058: } else {
1.484.2.42 raeburn 2059: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2060: }
1.484.2.38 raeburn 2061: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2062: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2063: '</div>';
1.484.2.26 raeburn 2064: }
2065: }
2066: } elsif ($url =~ m{/syllabus$}) {
2067: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2068: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2069: if (($dbref->{'cdom'} ne $coursedom) ||
2070: ($dbref->{'cnum'} ne $coursenum)) {
2071: my %contents=&Apache::lonnet::dump('syllabus',
2072: $dbref->{'cdom'},
2073: $dbref->{'cnum'});
2074: $result=&Apache::lonnet::put('syllabus',\%contents,
2075: $coursedom,$coursenum);
2076: }
2077: }
1.484.2.7 raeburn 2078: }
2079: }
1.484.2.26 raeburn 2080: return ($url,$result,$errtext);
1.329 droeschl 2081: }
2082:
2083: sub uniqueness_check {
2084: my ($newurl) = @_;
2085: my $unique = 1;
2086: foreach my $res (@LONCAPA::map::order) {
2087: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2088: $url=&LONCAPA::map::qtescape($url);
2089: if ($newurl eq $url) {
2090: $unique = 0;
1.344 bisitz 2091: last;
1.329 droeschl 2092: }
2093: }
2094: return $unique;
2095: }
2096:
1.484.2.7 raeburn 2097: sub contained_map_check {
2098: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2099: $allmaps) = @_;
2100: my $content = &Apache::lonnet::getfile($url);
2101: unless ($content eq '-1') {
2102: my $parser = HTML::TokeParser->new(\$content);
2103: $parser->attr_encoded(1);
2104: while (my $token = $parser->get_token) {
2105: next if ($token->[0] ne 'S');
2106: if ($token->[1] eq 'resource') {
2107: next if ($token->[2]->{'type'} eq 'zombie');
2108: my $ressrc = $token->[2]->{'src'};
2109: if ($folder =~ /^supplemental/) {
2110: unless (&supp_pasteable($ressrc)) {
2111: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2112: next;
2113: }
2114: }
2115: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2116: if ($1 eq 'uploaded') {
2117: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2118: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2119: } else {
2120: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2121: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2122: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2123: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2124: } else {
2125: $addedmaps->{$ressrc} = [$url];
2126: }
2127: }
2128: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2129: $addedmaps,$hierarchy,$titles,$allmaps);
2130: }
2131: } elsif ($token->[1] eq 'param') {
2132: if ($folder =~ /^supplemental/) {
2133: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2134: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2135: } else {
1.484.2.19 raeburn 2136: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2137: }
2138: }
2139: }
2140: }
2141: }
2142: return;
2143: }
2144:
2145: sub url_paste_fixups {
1.484.2.26 raeburn 2146: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2147: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2148: $mapchanges,$tomove,$newsubdir,$newurls) = @_;
1.484.2.7 raeburn 2149: my $checktitle;
2150: if (($prefixchg) &&
2151: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2152: $checktitle = 1;
2153: }
2154: my $skip;
2155: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2156: my $mapid = $1.$2;
2157: if ($tomove->{$mapid}) {
2158: $skip = 1;
2159: }
2160: }
2161: my $file = &Apache::lonnet::getfile($oldurl);
2162: return if ($file eq '-1');
2163: my $parser = HTML::TokeParser->new(\$file);
2164: $parser->attr_encoded(1);
2165: my $changed = 0;
2166: while (my $token = $parser->get_token) {
2167: next if ($token->[0] ne 'S');
2168: if ($token->[1] eq 'resource') {
2169: my $ressrc = $token->[2]->{'src'};
2170: next if ($ressrc eq '');
2171: my $id = $token->[2]->{'id'};
2172: my $title = $token->[2]->{'title'};
2173: if ($checktitle) {
2174: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2175: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2176: }
2177: }
2178: next if ($token->[2]->{'type'} eq 'external');
2179: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2180: next if ($skip);
1.484.2.25 raeburn 2181: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2182: $changed = 1;
2183: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2184: my $srcdom = $1;
2185: my $srcnum = $2;
2186: my $rem = $3;
2187: my $newurl;
2188: my $mapname;
2189: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2190: my $prefix = $1;
2191: $mapname = $prefix.$2;
2192: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2193: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2194: $srcdom,$srcnum,$allmaps,$rewrites,
2195: $retitles,$copies,$dbcopies,$zombies,
2196: $params,$mapmoves,$mapchanges,$tomove,
2197: $newsubdir,$newurls);
1.484.2.7 raeburn 2198: next;
2199: } else {
2200: ($newurl,my $error) =
2201: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2202: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2203: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2204: $newsubdir->{$ressrc} = $1;
2205: }
2206: if ($error) {
2207: next;
2208: }
2209: }
2210: }
2211: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2212: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2213:
1.484.2.7 raeburn 2214: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2215: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2216: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2217: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2218: $cnum,$srcdom,$srcnum,$allmaps,
2219: $rewrites,$retitles,$copies,$dbcopies,
2220: $zombies,$params,$mapmoves,$mapchanges,
2221: $tomove,$newsubdir,$newurls)) {
1.484.2.7 raeburn 2222: $mapmoves->{$ressrc} = 1;
2223: }
2224: $changed = 1;
2225: } else {
1.484.2.25 raeburn 2226: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2227: $copies->{$oldurl}{$ressrc} = $id;
2228: $changed = 1;
2229: }
2230: }
1.484.2.26 raeburn 2231: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2232: next if ($skip);
1.484.2.7 raeburn 2233: my $srcdom = $1;
2234: my $srcnum = $2;
2235: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2236: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2237: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2238: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2239: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2240: $changed = 1;
2241: }
2242: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2243: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2244: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2245: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2246: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2247: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2248: $changed = 1;
2249: }
2250: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2251: next if ($skip);
2252: my $srcdom = $1;
2253: my $srcnum = $2;
2254: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2255: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2256: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2257: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2258: $changed = 1;
2259: }
2260: }
2261: } elsif ($token->[1] eq 'param') {
2262: next if ($skip);
1.484.2.19 raeburn 2263: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2264: if ($to ne '') {
2265: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2266: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2267: } else {
2268: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2269: }
2270: }
2271: }
2272: }
2273: return $changed;
2274: }
2275:
2276: sub apply_fixups {
1.484.2.23 raeburn 2277: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2278: $oldurl,$url,$caller) = @_;
2279: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2280: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2281: %lockerrors,$lockmsg);
1.484.2.23 raeburn 2282: if (ref($updated) eq 'HASH') {
2283: if (ref($updated->{'rewrites'}) eq 'HASH') {
2284: %rewrites = %{$updated->{'rewrites'}};
2285: }
2286: if (ref($updated->{'zombies'}) eq 'HASH') {
2287: %zombies = %{$updated->{'zombies'}};
2288: }
2289: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2290: %removefrommap = %{$updated->{'removefrommap'}};
2291: }
2292: if (ref($updated->{'removeparam'}) eq 'HASH') {
2293: %removeparam = %{$updated->{'removeparam'}};
2294: }
2295: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2296: %dbcopies = %{$updated->{'dbcopies'}};
2297: }
2298: if (ref($updated->{'retitles'}) eq 'HASH') {
2299: %retitles = %{$updated->{'retitles'}};
2300: }
2301: }
2302: if (ref($info) eq 'HASH') {
2303: if (ref($info->{'newsubdir'}) eq 'HASH') {
2304: %newsubdir = %{$info->{'newsubdir'}};
2305: }
2306: if (ref($info->{'params'}) eq 'HASH') {
2307: %params = %{$info->{'params'}};
2308: }
2309: if (ref($info->{'before'}) eq 'HASH') {
2310: %before = %{$info->{'before'}};
2311: }
2312: if (ref($info->{'after'}) eq 'HASH') {
2313: %after = %{$info->{'after'}};
2314: }
2315: }
2316: if (ref($moves) eq 'HASH') {
2317: if (ref($moves->{'copies'}) eq 'HASH') {
2318: %copies = %{$moves->{'copies'}};
2319: }
2320: if (ref($moves->{'docmoves'}) eq 'HASH') {
2321: %docmoves = %{$moves->{'docmoves'}};
2322: }
2323: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2324: %mapmoves = %{$moves->{'mapmoves'}};
2325: }
2326: }
2327: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2328: my @allcopies;
1.484.2.23 raeburn 2329: if (exists($copies{$key})) {
2330: if (ref($copies{$key}) eq 'HASH') {
2331: my %added;
2332: foreach my $innerkey (keys(%{$copies{$key}})) {
2333: if (($innerkey ne '') && (!$added{$innerkey})) {
2334: push(@allcopies,$innerkey);
2335: $added{$innerkey} = 1;
2336: }
1.484.2.7 raeburn 2337: }
1.484.2.23 raeburn 2338: undef(%added);
1.484.2.7 raeburn 2339: }
2340: }
2341: if ($key eq $oldurl) {
1.484.2.23 raeburn 2342: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2343: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2344: push(@allcopies,$oldurl);
2345: }
2346: }
2347: }
2348: if (@allcopies > 0) {
2349: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2350: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2351: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2352: if ($fname ne '') {
2353: my $content = &Apache::lonnet::getfile($item);
2354: unless ($content eq '-1') {
2355: my $storefn;
1.484.2.23 raeburn 2356: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2357: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2358: } else {
2359: $storefn = $relpath;
2360: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2361: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2362: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2363: }
1.484.2.23 raeburn 2364: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2365: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2366: }
2367: }
2368: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2369: my $copyurl =
1.484.2.7 raeburn 2370: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2371: $storefn.$fname,$content);
2372: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2373: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2374: return &mt('Paste failed: an error occurred copying the file.');
2375: } elsif (ref($errors) eq 'HASH') {
2376: $errors->{$item} = 1;
2377: }
2378: }
2379: }
2380: }
2381: }
2382: }
2383: }
1.484.2.23 raeburn 2384: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2385: my $storefn=$key;
2386: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2387: if ($prefixchg && $before{'map'} && $after{'map'}) {
2388: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2389: }
1.484.2.23 raeburn 2390: if ($newsubdir{$key}) {
2391: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2392: }
2393: my $mapcontent = &Apache::lonnet::getfile($key);
2394: if ($mapcontent eq '-1') {
2395: if (ref($errors) eq 'HASH') {
2396: $errors->{$key} = 1;
2397: }
2398: } else {
2399: my $newmap =
2400: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2401: $mapcontent);
2402: if ($newmap eq '/adm/notfound.html') {
2403: if (ref($errors) eq 'HASH') {
2404: $errors->{$key} = 1;
2405: }
2406: }
2407: }
2408: }
2409: my %updates;
2410: if ($is_map) {
1.484.2.23 raeburn 2411: if (ref($updated) eq 'HASH') {
2412: foreach my $type (keys(%{$updated})) {
2413: if (ref($updated->{$type}) eq 'HASH') {
2414: foreach my $key (keys(%{$updated->{$type}})) {
2415: $updates{$key} = 1;
2416: }
2417: }
2418: }
1.484.2.7 raeburn 2419: }
2420: foreach my $key (keys(%updates)) {
2421: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2422: if (ref($rewrites{$key}) eq 'HASH') {
2423: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2424: }
1.484.2.23 raeburn 2425: if (ref($retitles{$key}) eq 'HASH') {
2426: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2427: }
1.484.2.23 raeburn 2428: if (ref($removefrommap{$key}) eq 'HASH') {
2429: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2430: }
1.484.2.23 raeburn 2431: if (ref($removeparam{$key}) eq 'HASH') {
2432: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2433: }
1.484.2.23 raeburn 2434: if (ref($zombies{$key}) eq 'HASH') {
2435: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2436: }
1.484.2.23 raeburn 2437: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2438: foreach my $idx (keys(%{$dbcopies{$key}})) {
2439: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2440: my ($newurl,$result,$errtext) =
2441: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2442: if ($result eq 'ok') {
2443: $newdb{$idx} = $newurl;
2444: } elsif (ref($errors) eq 'HASH') {
2445: $errors->{$key} = 1;
2446: }
2447: push(@msgs,$errtext);
2448: }
1.484.2.7 raeburn 2449: }
2450: }
1.484.2.23 raeburn 2451: if (ref($params{$key}) eq 'HASH') {
2452: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2453: }
2454: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2455: if ($fatal) {
1.484.2.26 raeburn 2456: return ($errtext);
1.484.2.7 raeburn 2457: }
2458: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2459: if (defined($LONCAPA::map::zombies[$i])) {
2460: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2461: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2462: undef($LONCAPA::map::zombies[$i]);
2463: }
2464: }
2465: }
1.484.2.77 raeburn 2466: my $total = scalar(@LONCAPA::map::order) - 1;
2467: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2468: my $idx = $LONCAPA::map::order[$i];
2469: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2470: my $changed;
1.484.2.23 raeburn 2471: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2472: if ((exists($toremove{$idx})) &&
2473: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2474: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2475: if (ref($currparam{$idx}) eq 'ARRAY') {
2476: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2477: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2478: }
2479: }
2480: next;
2481: }
2482: my $origsrc = $src;
1.484.2.25 raeburn 2483: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2484: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2485: $changed = 1;
2486: }
2487: }
1.484.2.25 raeburn 2488: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2489: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2490: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2491: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2492: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2493: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2494: } else {
1.484.2.23 raeburn 2495: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2496: }
2497: }
1.484.2.25 raeburn 2498: if ($origsrc =~ /\.(page|sequence)$/) {
2499: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2500: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2501: }
1.484.2.25 raeburn 2502: } elsif ($newsubdir{$key}) {
2503: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2504: }
2505: }
2506: $changed = 1;
1.484.2.26 raeburn 2507: } elsif ($newdb{$idx} ne '') {
2508: $src = $newdb{$idx};
1.484.2.7 raeburn 2509: $changed = 1;
2510: }
2511: if ($changed) {
1.484.2.30 raeburn 2512: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2513: }
2514: }
2515: }
2516: foreach my $idx (keys(%remparam)) {
2517: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2518: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2519: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2520: }
2521: }
2522: }
1.484.2.26 raeburn 2523: if (values(%lockerrors) > 0) {
2524: $lockmsg = join('<br />',values(%lockerrors));
2525: }
1.484.2.7 raeburn 2526: my $storefn;
2527: if ($key eq $oldurl) {
2528: $storefn = $url;
2529: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2530: } else {
2531: $storefn = $key;
2532: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2533: if ($prefixchg && $before{'map'} && $after{'map'}) {
2534: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2535: }
1.484.2.23 raeburn 2536: if ($newsubdir{$key}) {
2537: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2538: }
2539: }
2540: my $report;
2541: if ($folder !~ /^supplemental/) {
2542: $report = 1;
2543: }
1.484.2.20 raeburn 2544: (my $outtext,$errtext) =
1.484.2.7 raeburn 2545: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2546: if ($errtext) {
1.484.2.23 raeburn 2547: if ($caller eq 'paste') {
1.484.2.26 raeburn 2548: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2549: }
1.484.2.7 raeburn 2550: }
2551: }
2552: }
1.484.2.26 raeburn 2553: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2554: }
2555:
2556: sub copy_dependencies {
2557: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2558: my $content;
2559: if (ref($contentref)) {
2560: $content = $$contentref;
2561: } else {
2562: $content = &Apache::lonnet::getfile($item);
2563: }
2564: unless ($content eq '-1') {
2565: my $mm = new File::MMagic;
2566: my $mimetype = $mm->checktype_contents($content);
2567: if ($mimetype eq 'text/html') {
2568: my (%allfiles,%codebase,$state);
2569: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2570: if ($res eq 'ok') {
2571: my ($numexisting,$numpathchanges,$existing);
2572: (undef,$numexisting,$numpathchanges,$existing) =
2573: &Apache::loncommon::ask_for_embedded_content(
2574: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2575: {'error_on_invalid_names' => 1,
2576: 'ignore_remote_references' => 1,
2577: 'docs_url' => $item,
2578: 'context' => 'paste'});
2579: if ($numexisting > 0) {
2580: if (ref($existing) eq 'HASH') {
2581: foreach my $dep (keys(%{$existing})) {
2582: my $depfile = $dep;
2583: unless ($depfile =~ m{^\Q$relpath\E}) {
2584: $depfile = $relpath.$dep;
2585: }
2586: my $depcontent = &Apache::lonnet::getfile($depfile);
2587: unless ($depcontent eq '-1') {
2588: my $storedep = $dep;
2589: $storedep =~ s{^\Q$relpath\E}{};
2590: my $dep_url =
2591: &Apache::lonclonecourse::writefile(
2592: $env{'request.course.id'},
2593: $storefn.$storedep,$depcontent);
2594: if ($dep_url eq '/adm/notfound.html') {
2595: if (ref($errors) eq 'HASH') {
2596: $errors->{$depfile} = 1;
2597: }
2598: } else {
2599: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2600: }
2601: }
2602: }
2603: }
2604: }
2605: }
2606: }
2607: }
2608: return;
2609: }
2610:
1.329 droeschl 2611: my %parameter_type = ( 'randompick' => 'int_pos',
2612: 'hiddenresource' => 'string_yesno',
2613: 'encrypturl' => 'string_yesno',
2614: 'randomorder' => 'string_yesno',);
2615: my $valid_parameters_re = join('|',keys(%parameter_type));
2616: # set parameters
2617: sub update_parameter {
1.484.2.29 raeburn 2618: if ($env{'form.changeparms'} eq 'all') {
2619: my (@allidx,@allmapidx,%allchecked,%currchecked);
2620: %allchecked = (
2621: 'hiddenresource' => {},
2622: 'encrypturl' => {},
2623: 'randompick' => {},
2624: 'randomorder' => {},
2625: );
2626: foreach my $which (keys(%allchecked)) {
2627: $env{'form.all'.$which} =~ s/,$//;
2628: if ($which eq 'randompick') {
2629: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2630: my ($res,$value) = split(/:/,$item);
2631: if ($value =~ /^\d+$/) {
2632: $allchecked{$which}{$res} = $value;
2633: }
2634: }
2635: } else {
1.484.2.30 raeburn 2636: if ($env{'form.all'.$which}) {
2637: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2638: }
1.484.2.29 raeburn 2639: }
2640: }
2641: my $haschanges = 0;
2642: foreach my $res (@LONCAPA::map::order) {
2643: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2644: $name=&LONCAPA::map::qtescape($name);
2645: $url=&LONCAPA::map::qtescape($url);
2646: next unless ($name && $url);
2647: my $is_map;
2648: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2649: $is_map = 1;
2650: }
2651: foreach my $which (keys(%allchecked)) {
2652: if (($which eq 'randompick' || $which eq 'randomorder')) {
2653: next if (!$is_map);
2654: }
2655: my $oldvalue = 0;
2656: my $newvalue = 0;
2657: if ($allchecked{$which}{$res}) {
2658: $newvalue = $allchecked{$which}{$res};
2659: }
2660: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2661: if ($which eq 'randompick') {
2662: if ($current =~ /^(\d+)$/) {
2663: $oldvalue = $1;
2664: }
2665: } else {
2666: if ($current =~ /^yes$/i) {
2667: $oldvalue = 1;
2668: }
2669: }
2670: if ($oldvalue ne $newvalue) {
2671: $haschanges = 1;
2672: if ($newvalue) {
2673: my $storeval = 'yes';
2674: if ($which eq 'randompick') {
2675: $storeval = $newvalue;
2676: }
2677: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2678: $storeval,
2679: $parameter_type{$which});
2680: &remember_parms($res,$which,'set',$storeval);
2681: } elsif ($oldvalue) {
2682: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2683: &remember_parms($res,$which,'del');
2684: }
2685: }
2686: }
2687: }
2688: return $haschanges;
1.329 droeschl 2689: } else {
1.484.2.59 raeburn 2690: my $haschanges = 0;
2691: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 2692:
1.484.2.29 raeburn 2693: my $which = $env{'form.changeparms'};
2694: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 2695: my $oldvalue = 0;
2696: my $newvalue = 0;
2697: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2698: if ($which eq 'randompick') {
2699: if ($current =~ /^(\d+)$/) {
2700: $oldvalue = $1;
2701: }
2702: } elsif ($current =~ /^yes$/i) {
2703: $oldvalue = 1;
2704: }
1.484.2.29 raeburn 2705: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 2706: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2707: : 1;
1.484.2.29 raeburn 2708: }
1.484.2.59 raeburn 2709: if ($oldvalue ne $newvalue) {
2710: $haschanges = 1;
2711: if ($newvalue) {
2712: my $storeval = 'yes';
2713: if ($which eq 'randompick') {
2714: $storeval = $newvalue;
2715: }
2716: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2717: $parameter_type{$which});
2718: &remember_parms($idx,$which,'set',$storeval);
2719: } else {
2720: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2721: &remember_parms($idx,$which,'del');
2722: }
2723: }
2724: return $haschanges;
1.329 droeschl 2725: }
1.484.2.59 raeburn 2726: return;
1.329 droeschl 2727: }
2728:
2729: sub handle_edit_cmd {
2730: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 2731: if ($env{'form.cmd'} eq '') {
2732: return 0;
2733: }
1.329 droeschl 2734: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2735:
2736: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2737: my ($title, $url, @rrest) = split(':', $ratstr);
2738:
1.484.2.30 raeburn 2739: if ($cmd eq 'remove') {
1.329 droeschl 2740: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2741: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2742: &Apache::lonnet::removeuploadedurl($url);
2743: } else {
2744: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2745: }
2746: splice(@LONCAPA::map::order, $idx, 1);
2747:
2748: } elsif ($cmd eq 'cut') {
2749: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2750: splice(@LONCAPA::map::order, $idx, 1);
2751:
1.344 bisitz 2752: } elsif ($cmd eq 'up'
1.329 droeschl 2753: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2754: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2755:
2756: } elsif ($cmd eq 'down'
2757: && defined($LONCAPA::map::order[$idx+1])) {
2758: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2759:
2760: } elsif ($cmd eq 'rename') {
2761: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2762: if ($comment=~/\S/) {
2763: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2764: $comment.':'.join(':', $url, @rrest);
2765: }
2766: # Devalidate title cache
2767: my $renamed_url=&LONCAPA::map::qtescape($url);
2768: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 2769:
1.329 droeschl 2770: } else {
2771: return 0;
2772: }
2773: return 1;
2774: }
2775:
2776: sub editor {
1.458 raeburn 2777: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.67 raeburn 2778: $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,$navmapref,
2779: $hiddentop)=@_;
1.484.2.19 raeburn 2780: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2781: if ($allowed) {
2782: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2783: $is_random_order,$container) =
2784: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2785: $r->print($breadcrumbtrail);
2786: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2787: $container = 'page';
2788: } else {
2789: $container = 'sequence';
2790: }
1.484 raeburn 2791:
1.484.2.21 raeburn 2792: my $jumpto;
2793:
2794: unless ($supplementalflag) {
1.484.2.32 raeburn 2795: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 2796: }
1.484 raeburn 2797:
2798: unless ($allowed) {
2799: $randompick = -1;
2800: }
2801:
1.484.2.67 raeburn 2802: my ($errtext,$fatal);
2803: if (($folder eq '') && (!$supplementalflag)) {
2804: if (@LONCAPA::map::order) {
2805: undef(@LONCAPA::map::order);
2806: undef(@LONCAPA::map::resources);
2807: undef(@LONCAPA::map::resparms);
2808: undef(@LONCAPA::map::zombies);
2809: }
2810: $folder = 'default';
2811: $container = 'sequence';
2812: } else {
2813: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2814: $folder.'.'.$container);
2815: return $errtext if ($fatal);
2816: }
1.329 droeschl 2817:
2818: if ($#LONCAPA::map::order<1) {
2819: my $idx=&LONCAPA::map::getresidx();
2820: if ($idx<=0) { $idx=1; }
2821: $LONCAPA::map::order[0]=$idx;
2822: $LONCAPA::map::resources[$idx]='';
2823: }
1.364 bisitz 2824:
1.329 droeschl 2825: # ------------------------------------------------------------ Process commands
2826:
2827: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 2828: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 2829: # set parameters and change order
2830: &snapshotbefore();
2831:
2832: if (&update_parameter()) {
1.484.2.59 raeburn 2833: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 2834: return $errtext if ($fatal);
2835: }
2836:
2837: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2838: # change order
2839: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
2840: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
2841:
2842: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2843: return $errtext if ($fatal);
2844: }
1.364 bisitz 2845:
1.329 droeschl 2846: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 2847: my %paste_errors;
1.484.2.26 raeburn 2848: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 2849: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
2850: \%paste_errors);
1.484.2.30 raeburn 2851: if (ref($pastemsgarray) eq 'ARRAY') {
2852: if (@{$pastemsgarray} > 0) {
2853: $r->print('<p class="LC_info">'.
2854: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 2855: '</p>');
2856: }
1.484.2.30 raeburn 2857: }
2858: if ($lockerror) {
2859: $r->print('<p class="LC_error">'.
2860: $lockerror.
2861: '</p>');
2862: }
2863: if ($save_error ne '') {
2864: return $save_error;
2865: }
2866: if ($paste_res) {
2867: my %errortext = &Apache::lonlocal::texthash (
2868: fail => 'Storage of folder contents failed',
2869: failread => 'Reading folder contents failed',
2870: failstore => 'Storage of folder contents failed',
2871: );
2872: if ($errortext{$paste_res}) {
2873: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 2874: }
1.329 droeschl 2875: }
1.484.2.7 raeburn 2876: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 2877: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 2878: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
2879: '<ul>'."\n");
2880: foreach my $key (sort(keys(%paste_errors))) {
2881: $r->print('<li>'.$key.'</li>'."\n");
2882: }
2883: $r->print('</ul></p>'."\n");
2884: }
1.484.2.30 raeburn 2885: } elsif ($env{'form.clearmarked'}) {
2886: my $output = &do_buffer_empty();
2887: if ($output) {
2888: $r->print('<p class="LC_info">'.$output.'</p>');
2889: }
2890: }
1.329 droeschl 2891:
2892: $r->print($upload_output);
2893:
1.484.2.30 raeburn 2894: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 2895: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 2896: my $contentchg;
1.484.2.58 raeburn 2897: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 2898: $contentchg = 1;
2899: }
2900: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 2901: return $errtext if ($fatal);
2902: }
1.484.2.30 raeburn 2903:
2904: # Cut, copy and/or remove multiple resources
2905: if ($env{'form.multichange'}) {
2906: my %allchecked = (
2907: cut => {},
2908: remove => {},
2909: );
2910: my $needsupdate;
2911: foreach my $which (keys(%allchecked)) {
2912: $env{'form.multi'.$which} =~ s/,$//;
2913: if ($env{'form.multi'.$which}) {
2914: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
2915: if (ref($allchecked{$which}) eq 'HASH') {
2916: $needsupdate += scalar(keys(%{$allchecked{$which}}));
2917: }
2918: }
2919: }
2920: if ($needsupdate) {
2921: my $haschanges = 0;
2922: my %curr_groups = &Apache::longroup::coursegroups();
2923: my $total = scalar(@LONCAPA::map::order) - 1;
2924: for (my $i=$total; $i>=0; $i--) {
2925: my $res = $LONCAPA::map::order[$i];
2926: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2927: $name=&LONCAPA::map::qtescape($name);
2928: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 2929: next unless $url;
1.484.2.30 raeburn 2930: my %denied =
2931: &action_restrictions($coursenum,$coursedom,$url,
2932: $env{'form.folderpath'},\%curr_groups);
2933: foreach my $which (keys(%allchecked)) {
2934: next if ($denied{$which});
2935: next unless ($allchecked{$which}{$res});
2936: if ($which eq 'remove') {
2937: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
2938: ($url!~/$LONCAPA::assess_page_seq_re/)) {
2939: &Apache::lonnet::removeuploadedurl($url);
2940: } else {
2941: &LONCAPA::map::makezombie($res);
2942: }
2943: splice(@LONCAPA::map::order,$i,1);
2944: $haschanges ++;
2945: } elsif ($which eq 'cut') {
2946: &LONCAPA::map::makezombie($res);
2947: splice(@LONCAPA::map::order,$i,1);
2948: $haschanges ++;
2949: }
2950: }
2951: }
2952: if ($haschanges) {
2953: ($errtext,$fatal) =
2954: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2955: return $errtext if ($fatal);
2956: }
2957: }
2958: }
2959:
1.329 droeschl 2960: # Group import/search
2961: if ($env{'form.importdetail'}) {
2962: my @imports;
2963: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
2964: if (defined($item)) {
2965: my ($name,$url,$residx)=
1.484.2.26 raeburn 2966: map { &unescape($_); } split(/\=/,$item);
2967: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 2968: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 2969: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 2970: if ($locknotfreed) {
2971: $r->print($locknotfreed);
2972: }
2973: if ($suffix) {
1.484.2.19 raeburn 2974: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 2975: } else {
2976: return $errortxt;
2977: }
1.484.2.26 raeburn 2978: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
2979: my $type = $1;
2980: my ($suffix,$errortxt,$locknotfreed) =
2981: &new_timebased_suffix($coursedom,$coursenum,$type);
2982: if ($locknotfreed) {
2983: $r->print($locknotfreed);
2984: }
2985: if ($suffix) {
2986: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
2987: } else {
2988: return $errortxt;
2989: }
1.484.2.27 raeburn 2990: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
2991: if ($supplementalflag) {
2992: next unless ($1 eq 'supplemental');
2993: if ($folder eq 'supplemental') {
2994: next unless ($2 eq 'default');
2995: } else {
2996: next unless ($folder eq 'supplemental_'.$2);
2997: }
2998: } else {
2999: next unless ($1 eq 'docs');
3000: if ($folder eq 'default') {
3001: next unless ($2 eq 'default');
3002: } else {
3003: next unless ($folder eq 'default_'.$2);
3004: }
3005: }
1.484.2.15 raeburn 3006: }
1.329 droeschl 3007: push(@imports, [$name, $url, $residx]);
3008: }
3009: }
1.484.2.23 raeburn 3010: ($errtext,$fatal,my $fixuperrors) =
3011: &group_import($coursenum, $coursedom, $folder,$container,
3012: 'londocs',@imports);
1.329 droeschl 3013: return $errtext if ($fatal);
1.484.2.23 raeburn 3014: if ($fixuperrors) {
3015: $r->print($fixuperrors);
3016: }
1.329 droeschl 3017: }
3018: # Loading a complete map
3019: if ($env{'form.loadmap'}) {
3020: if ($env{'form.importmap'}=~/\w/) {
3021: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3022: my ($title,$url,$ext,$type)=split(/\:/,$res);
3023: my $idx=&LONCAPA::map::getresidx($url);
3024: $LONCAPA::map::resources[$idx]=$res;
3025: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3026: }
3027: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3028: $folder.'.'.$container,1);
1.329 droeschl 3029: return $errtext if ($fatal);
3030: } else {
3031: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3032:
1.329 droeschl 3033: }
3034: }
3035: &log_differences($plain);
3036: }
3037: # ---------------------------------------------------------------- End commands
3038: # ---------------------------------------------------------------- Print screen
3039: my $idx=0;
3040: my $shown=0;
3041: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3042: $r->print('<div class="LC_Box">'.
1.432 raeburn 3043: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3044: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3045: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3046: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3047: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3048: '</ol>');
1.381 bisitz 3049: if ($randompick>=0) {
3050: $r->print('<p class="LC_warning">'
3051: .&mt('Caution: this folder is set to randomly pick a subset'
3052: .' of resources. Adding or removing resources from this'
3053: .' folder will change the set of resources that the'
3054: .' students see, resulting in spurious or missing credit'
3055: .' for completed problems, not limited to ones you'
3056: .' modify. Do not modify the contents of this folder if'
3057: .' it is in active student use.')
3058: .'</p>'
3059: );
3060: }
3061: if ($is_random_order) {
3062: $r->print('<p class="LC_warning">'
3063: .&mt('Caution: this folder is set to randomly order its'
3064: .' contents. Adding or removing resources from this folder'
3065: .' will change the order of resources shown.')
3066: .'</p>'
3067: );
3068: }
3069: $r->print('</div>');
1.364 bisitz 3070: }
1.381 bisitz 3071:
1.484.2.30 raeburn 3072: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3073: %filters = (
3074: canremove => [],
3075: cancut => [],
3076: cancopy => [],
3077: hiddenresource => [],
3078: encrypturl => [],
3079: randomorder => [],
3080: randompick => [],
3081: );
3082: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3083: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3084: foreach my $res (@LONCAPA::map::order) {
3085: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3086: $name=&LONCAPA::map::qtescape($name);
3087: $url=&LONCAPA::map::qtescape($url);
3088: unless ($name) { $name=(split(/\//,$url))[-1]; }
3089: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3090: push(@allidx,$res);
3091: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3092: push(@allmapidx,$res);
3093: }
1.484.2.67 raeburn 3094:
1.381 bisitz 3095: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3096: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3097: $pathitem,$supplementalflag,$container,
1.484.2.70 raeburn 3098: \%filters,\%curr_groups,$canedit,
3099: $isencrypted,$navmapref);
1.381 bisitz 3100: $idx++;
3101: $shown++;
1.329 droeschl 3102: }
1.424 onken 3103: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3104:
1.484.2.30 raeburn 3105: my $need_save;
1.484.2.67 raeburn 3106: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3107: my $toolslink;
1.484.2.67 raeburn 3108: if ($allowed) {
1.484.2.31 raeburn 3109: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3110: .&Apache::loncommon::help_open_menu('Navigation Screen',
3111: 'Navigation_Screen',undef,'RAT')
3112: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3113: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3114: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3115: .'id="LC_content_toolbar_edittoplevel" '
3116: .'class="LC_toolbarItem" '
3117: .'title="'.&mt('Supplemental Content Editor').'">'
3118: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3119: }
1.484.2.19 raeburn 3120: if ($shown) {
3121: if ($allowed) {
3122: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3123: .&Apache::loncommon::start_data_table(undef,'contentlist')
3124: .&Apache::loncommon::start_data_table_header_row()
3125: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3126: .'<th colspan="2">'.&mt('Actions').'</th>'
3127: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3128: if ($folder !~ /^supplemental/) {
3129: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3130: }
1.484.2.29 raeburn 3131: $to_show .= &Apache::loncommon::end_data_table_header_row();
3132: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3133: $lists{'canhide'} = join(',',@allidx);
3134: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3135: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3136: 'randomorder','randompick');
3137: foreach my $item (@possfilters) {
3138: if (ref($filters{$item}) eq 'ARRAY') {
3139: if (@{$filters{$item}} > 0) {
3140: $lists{$item} = join(',',@{$filters{$item}});
3141: }
3142: }
3143: }
1.484.2.29 raeburn 3144: if (@allidx > 0) {
3145: my $path;
3146: if ($env{'form.folderpath'}) {
3147: $path =
3148: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3149: }
1.484.2.30 raeburn 3150: if (@allidx > 1) {
3151: $to_show .=
3152: &Apache::loncommon::continue_data_table_row().
3153: '<td colspan="2"> </td>'.
3154: '<td>'.
1.484.2.67 raeburn 3155: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3156: '</td>'.
3157: '<td> </td>'.
3158: '<td> </td>'.
3159: '<td colspan="4">'.
1.484.2.67 raeburn 3160: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3161: '</td>'.
3162: &Apache::loncommon::end_data_table_row();
3163: $need_save = 1;
3164: }
1.484.2.29 raeburn 3165: }
3166: }
3167: $to_show .= $output.' '
1.484.2.19 raeburn 3168: .&Apache::loncommon::end_data_table()
3169: .'<br style="line-height:2px;" />'
3170: .&Apache::loncommon::end_scrollbox();
3171: } else {
3172: $to_show .= $toolslink
3173: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3174: .$output.' '
3175: .&Apache::loncommon::end_data_table();
3176: }
3177: } else {
3178: if (!$allowed) {
3179: $to_show .= $toolslink;
1.393 raeburn 3180: }
1.484.2.67 raeburn 3181: my $noresmsg;
3182: if ($allowed && $hiddentop && !$supplementalflag) {
3183: $noresmsg = &mt('Main Content Hidden');
3184: } else {
3185: $noresmsg = &mt('Currently empty');
3186: }
1.484.2.19 raeburn 3187: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3188: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3189: .$noresmsg
1.484.2.19 raeburn 3190: .'</div>'
3191: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3192: }
3193: } else {
1.484.2.19 raeburn 3194: if ($shown) {
3195: $to_show = '<div>'
3196: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3197: .$output
3198: .&Apache::loncommon::end_data_table()
3199: .'</div>';
3200: } else {
3201: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3202: .&mt('Currently empty')
1.484.2.19 raeburn 3203: .'</div>'
3204: }
1.458 raeburn 3205: }
3206: my $tid = 1;
3207: if ($supplementalflag) {
3208: $tid = 2;
1.329 droeschl 3209: }
3210: if ($allowed) {
1.484 raeburn 3211: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3212: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3213: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3214: if ($canedit) {
1.484.2.67 raeburn 3215: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3216: }
1.460 raeburn 3217: } else {
3218: $r->print($to_show);
1.329 droeschl 3219: }
3220: return;
3221: }
3222:
1.484.2.30 raeburn 3223: sub multiple_check_form {
1.484.2.67 raeburn 3224: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3225: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3226: my $disabled;
3227: unless ($canedit) {
3228: $disabled = 'disabled="disabled"';
3229: }
1.484.2.30 raeburn 3230: my $output =
3231: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3232: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3233: '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick('."'$caller','0'".');" checked="checked" />'.&mt('one').'</label>'.(' 'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick('."'$caller','1'".');" />'.&mt('multiple').'</label></span><span id="more'.$caller.'" class="LC_nobreak LC_docs_ext_edit"></span></form>'.
3234: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3235: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3236: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3237: if ($caller eq 'settings') {
3238: $output .=
3239: '<table><tr>'.
3240: '<td class="LC_docs_entry_parameter">'.
3241: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3242: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3243: '</label></span></td>'.
3244: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3245: '<span class="LC_nobreak"><label><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');"'.$disabled.' />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
1.484.2.30 raeburn 3246: '</span></td>'.
3247: '</tr>'."\n".
3248: '<tr>'.
3249: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3250: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')"'.$disabled.' />'.&mt('URL hidden').'</label></span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><label><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')"'.$disabled.' />'.&mt('Random Order').
1.484.2.30 raeburn 3251: '</label></span>'.
3252: '</td></tr></table>'."\n";
3253: } else {
3254: $output .=
3255: '<table><tr>'.
3256: '<td class="LC_docs_entry_parameter">'.
3257: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3258: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3259: '</label></span></td>'.
3260: '<td class="LC_docs_entry_parameter">'.
3261: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3262: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3263: '</label></span></td>'."\n".
3264: '<td class="LC_docs_entry_parameter">'.
3265: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3266: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3267: '</label></span></td>'.
3268: '</tr></table>'."\n";
3269: }
3270: $output .=
3271: '</fieldset>'.
3272: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3273: if ($caller eq 'settings') {
3274: $output .=
3275: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3276: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3277: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3278: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3279: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3280: } elsif ($caller eq 'actions') {
3281: $output .=
3282: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3283: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3284: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3285: }
3286: $output .=
3287: '</form>'.
3288: '</div>';
3289: return $output;
3290: }
3291:
1.329 droeschl 3292: sub process_file_upload {
1.484.2.36 raeburn 3293: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3294: # upload a file, if present
1.484.2.36 raeburn 3295: my $filesize = length($env{'form.uploaddoc'});
3296: if (!$filesize) {
3297: $$upload_output = '<div class="LC_error">'.
3298: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3299: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3300: $filesize).'<br />'.
3301: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3302: '</div>';
3303: return;
3304: }
3305: my $quotatype = 'unofficial';
3306: if ($crstype eq 'Community') {
3307: $quotatype = 'community';
1.484.2.51 raeburn 3308: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3309: $quotatype = 'official';
1.484.2.45 raeburn 3310: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3311: $quotatype = 'textbook';
1.484.2.36 raeburn 3312: }
3313: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3314: $filesize = int($filesize/1000); #expressed in kb
3315: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3316: $env{'form.uploaddoc.filename'},$filesize,
3317: 'upload',$quotatype);
1.484.2.36 raeburn 3318: return if ($$upload_output);
3319: }
1.440 raeburn 3320: my ($parseaction,$showupload,$nextphase,$mimetype);
3321: if ($env{'form.parserflag'}) {
1.329 droeschl 3322: $parseaction = 'parse';
3323: }
3324: my $folder=$env{'form.folder'};
3325: if ($folder eq '') {
3326: $folder='default';
3327: }
3328: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3329: my $errtext='';
3330: my $fatal=0;
3331: my $container='sequence';
1.484.2.19 raeburn 3332: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3333: $container='page';
3334: }
3335: ($errtext,$fatal)=
1.484.2.27 raeburn 3336: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3337: if ($#LONCAPA::map::order<1) {
3338: $LONCAPA::map::order[0]=1;
3339: $LONCAPA::map::resources[1]='';
3340: }
3341: my $destination = 'docs/';
3342: if ($folder =~ /^supplemental/) {
3343: $destination = 'supplemental/';
3344: }
3345: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3346: $destination .= 'default/';
3347: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3348: $destination .= $2.'/';
3349: }
1.484.2.27 raeburn 3350: if ($fatal) {
3351: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'</div>';
3352: return;
3353: }
1.440 raeburn 3354: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3355: my $newidx=&LONCAPA::map::getresidx();
3356: $destination .= $newidx;
1.439 raeburn 3357: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3358: $parseaction,$allfiles,
1.440 raeburn 3359: $codebase,undef,undef,undef,undef,
3360: undef,undef,\$mimetype);
3361: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3362: my $stored = $1;
3363: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3364: $stored.'</span>').'</p>';
3365: } else {
3366: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3367:
1.457 raeburn 3368: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3369: return;
3370: }
1.329 droeschl 3371: my $ext='false';
3372: if ($url=~m{^http://}) { $ext='true'; }
3373: $url = &LONCAPA::map::qtunescape($url);
3374: my $comment=$env{'form.comment'};
3375: $comment = &LONCAPA::map::qtunescape($comment);
3376: if ($folder=~/^supplemental/) {
3377: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3378: $env{'user.domain'}.'___&&&___'.$comment;
3379: }
3380:
3381: $LONCAPA::map::resources[$newidx]=
3382: $comment.':'.$url.':'.$ext.':normal:res';
3383: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3384: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3385: $folder.'.'.$container,1);
1.329 droeschl 3386: if ($fatal) {
1.457 raeburn 3387: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3388: return;
1.329 droeschl 3389: } else {
1.440 raeburn 3390: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3391: $$upload_output = $showupload;
1.384 raeburn 3392: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3393: if ($total_embedded > 0) {
1.440 raeburn 3394: my $uploadphase = 'upload_embedded';
3395: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3396: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3397: my ($embedded,$num) =
3398: &Apache::loncommon::ask_for_embedded_content(
3399: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3400: if ($embedded) {
3401: if ($num) {
3402: $$upload_output .=
3403: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3404: $nextphase = $uploadphase;
3405: } else {
3406: $$upload_output .= $embedded;
3407: }
3408: } else {
3409: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3410: }
1.329 droeschl 3411: } else {
1.440 raeburn 3412: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3413: }
1.457 raeburn 3414: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3415: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3416: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3417: $nextphase = 'decompress_uploaded';
3418: my $position = scalar(@LONCAPA::map::order)-1;
3419: my $noextract = &return_to_editor();
3420: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3421: my %archiveitems = (
3422: folderpath => $env{'form.folderpath'},
3423: cmd => $nextphase,
3424: newidx => $newidx,
3425: position => $position,
3426: phase => $nextphase,
1.477 raeburn 3427: comment => $comment,
1.480 raeburn 3428: );
3429: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3430: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3431: $$upload_output = $showupload.
3432: &Apache::loncommon::decompress_form($mimetype,
3433: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3434: \%archiveitems,\@current);
1.329 droeschl 3435: }
3436: }
3437: }
1.440 raeburn 3438: return $nextphase;
1.329 droeschl 3439: }
3440:
1.480 raeburn 3441: sub get_dir_list {
3442: my ($url,$coursenum,$coursedom,$newidx) = @_;
3443: my ($destination,$dir_root) = &embedded_destination();
3444: my ($dirlistref,$listerror) =
3445: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3446: my @dir_lines;
3447: my $dirptr=16384;
3448: if (ref($dirlistref) eq 'ARRAY') {
3449: foreach my $dir_line (sort
3450: {
3451: my ($afile)=split('&',$a,2);
3452: my ($bfile)=split('&',$b,2);
3453: return (lc($afile) cmp lc($bfile));
3454: } (@{$dirlistref})) {
3455: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3456: $filename =~ s/\s+$//;
3457: next if ($filename =~ /^\.\.?$/);
3458: my $isdir = 0;
3459: if ($dirptr&$testdir) {
3460: $isdir = 1;
3461: }
3462: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3463: }
3464: }
3465: return @dir_lines;
3466: }
3467:
1.329 droeschl 3468: sub is_supplemental_title {
3469: my ($title) = @_;
3470: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3471: }
3472:
3473: # --------------------------------------------------------------- An entry line
3474:
3475: sub entryline {
1.484.2.12 raeburn 3476: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3477: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3478: $canedit,$isencrypted,$navmapref)=@_;
1.484.2.52 raeburn 3479: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3480: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3481: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3482: } else {
3483: $title=&HTML::Entities::encode($title,'"<>&\'');
3484: $renametitle=$title;
3485: $foldertitle=$title;
3486: }
3487:
1.484.2.67 raeburn 3488: my ($disabled,$readonly,$js_lt);
3489: unless ($canedit) {
3490: $disabled = 'disabled="disabled"';
3491: $readonly = 1;
3492: }
3493:
1.329 droeschl 3494: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3495:
1.329 droeschl 3496: $renametitle=~s/\\/\\\\/g;
3497: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3498: $renametitle=~s/"/%22/g;
1.329 droeschl 3499: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3500: $oldtitle = $renametitle;
3501: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3502: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3503: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3504: # Edit commands
1.484.2.28 raeburn 3505: my ($esc_path, $path, $symb);
1.329 droeschl 3506: if ($env{'form.folderpath'}) {
3507: $esc_path=&escape($env{'form.folderpath'});
3508: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3509: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3510: }
1.484.2.16 raeburn 3511: my $isexternal;
1.484.2.19 raeburn 3512: if ($residx) {
1.484.2.12 raeburn 3513: my $currurl = $url;
3514: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3515: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3516: $isexternal = 1;
3517: }
1.484.2.19 raeburn 3518: if (!$supplementalflag) {
3519: my $path = 'uploaded/'.
3520: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3521: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3522: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3523: $residx,
3524: &Apache::lonnet::declutter($currurl));
3525: }
1.484.2.12 raeburn 3526: }
1.484.2.30 raeburn 3527: my ($renamelink,%lt,$ishash);
3528: if (ref($filtersref) eq 'HASH') {
3529: $ishash = 1;
3530: }
3531:
1.329 droeschl 3532: if ($allowed) {
1.484.2.30 raeburn 3533: $form_start = '
3534: <form action="/adm/coursedocs" method="post">
3535: ';
3536: $form_common=(<<END);
3537: <input type="hidden" name="folderpath" value="$path" />
3538: <input type="hidden" name="symb" value="$symb" />
3539: END
3540: $form_param=(<<END);
3541: <input type="hidden" name="setparms" value="$orderidx" />
3542: <input type="hidden" name="changeparms" value="0" />
3543: END
3544: $form_end = '</form>';
3545:
1.329 droeschl 3546: my $incindex=$index+1;
3547: my $selectbox='';
1.471 raeburn 3548: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3549: ((split(/\:/,
1.344 bisitz 3550: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3551: ne '') &&
1.329 droeschl 3552: ((split(/\:/,
1.344 bisitz 3553: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3554: ne '')) {
3555: $selectbox=
3556: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3557: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3558: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3559: if ($i==$incindex) {
1.358 bisitz 3560: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3561: } else {
3562: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3563: }
3564: }
3565: $selectbox.='</select>';
3566: }
1.484.2.12 raeburn 3567: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3568: 'up' => 'Move Up',
3569: 'dw' => 'Move Down',
3570: 'rm' => 'Remove',
3571: 'ct' => 'Cut',
3572: 'rn' => 'Rename',
1.484.2.12 raeburn 3573: 'cp' => 'Copy',
3574: 'ex' => 'External Resource',
3575: 'ed' => 'Edit',
3576: 'pr' => 'Preview',
3577: 'sv' => 'Save',
3578: 'ul' => 'URL',
1.484.2.67 raeburn 3579: 'ti' => 'Title',
3580: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3581: );
1.484.2.30 raeburn 3582: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3583: $env{'form.folderpath'},
3584: $currgroups);
1.484.2.19 raeburn 3585: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3586: my $skip_confirm = 0;
1.484.2.63 raeburn 3587: my $confirm_removal = 0;
1.329 droeschl 3588: if ( $folder =~ /^supplemental/
3589: || ($url =~ m{( /smppg$
3590: |/syllabus$
3591: |/aboutme$
3592: |/navmaps$
3593: |/bulletinboard$
1.484.2.16 raeburn 3594: |\.html$)}x)
1.484.2.19 raeburn 3595: || $isexternal) {
1.329 droeschl 3596: $skip_confirm = 1;
3597: }
1.484.2.63 raeburn 3598: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3599: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3600: $confirm_removal = 1;
3601: }
1.484.2.19 raeburn 3602:
1.484.2.30 raeburn 3603: if ($denied{'copy'}) {
3604: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3605: <span style="visibility: hidden;">$lt{'cp'}</span>
3606: ENDCOPY
3607: } else {
1.484.2.30 raeburn 3608: my $formname = 'edit_copy_'.$orderidx;
3609: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3610: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3611: <form name="$formname" method="post" action="/adm/coursedocs">
3612: $form_common
1.484.2.67 raeburn 3613: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.484.2.30 raeburn 3614: $form_end
1.329 droeschl 3615: ENDCOPY
1.484.2.30 raeburn 3616: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3617: push(@{$filtersref->{'cancopy'}},$orderidx);
3618: }
1.329 droeschl 3619: }
1.484.2.30 raeburn 3620: if ($denied{'cut'}) {
1.484.2.16 raeburn 3621: $cutlink=(<<ENDCUT);
3622: <span style="visibility: hidden;">$lt{'ct'}</span>
3623: ENDCUT
3624: } else {
1.484.2.30 raeburn 3625: my $formname = 'edit_cut_'.$orderidx;
3626: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3627: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3628: <form name="$formname" method="post" action="/adm/coursedocs">
3629: $form_common
3630: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3631: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.484.2.30 raeburn 3632: $form_end
1.329 droeschl 3633: ENDCUT
1.484.2.30 raeburn 3634: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3635: push(@{$filtersref->{'cancut'}},$orderidx);
3636: }
1.329 droeschl 3637: }
1.484.2.30 raeburn 3638: if ($denied{'remove'}) {
1.484.2.16 raeburn 3639: $removelink=(<<ENDREM);
3640: <span style="visibility: hidden;">$lt{'rm'}</a>
3641: ENDREM
3642: } else {
1.484.2.30 raeburn 3643: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3644: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.484.2.9 raeburn 3645: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3646: <form name="$formname" method="post" action="/adm/coursedocs">
3647: $form_common
3648: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3649: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3650: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.484.2.30 raeburn 3651: $form_end
1.484.2.9 raeburn 3652: ENDREM
1.484.2.30 raeburn 3653: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3654: push(@{$filtersref->{'canremove'}},$orderidx);
3655: }
1.484.2.9 raeburn 3656: }
1.484.2.35 raeburn 3657: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3658: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3659: ENDREN
1.484.2.67 raeburn 3660: my ($uplink,$downlink);
3661: if ($canedit) {
3662: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3663: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3664: } else {
3665: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3666: $downlink = $uplink;
3667: }
1.329 droeschl 3668: $line.=(<<END);
3669: <td>
1.379 bisitz 3670: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3671: <a href="$uplink">
1.484.2.12 raeburn 3672: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3673: </a>
3674: </div>
3675: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3676: <a href="$downlink">
1.484.2.12 raeburn 3677: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3678: </a>
3679: </div>
1.329 droeschl 3680: </td>
3681: <td>
3682: $form_start
1.484.2.30 raeburn 3683: $form_param
1.478 raeburn 3684: $form_common
1.329 droeschl 3685: $selectbox
3686: $form_end
3687: </td>
1.484.2.30 raeburn 3688: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3689: $removelink
1.329 droeschl 3690: $cutlink
3691: $copylink
3692: </td>
3693: END
3694: }
3695: # Figure out what kind of a resource this is
3696: my ($extension)=($url=~/\.(\w+)$/);
3697: my $uploaded=($url=~/^\/*uploaded\//);
3698: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3699: my $isfolder;
3700: my $ispage;
3701: my $containerarg;
1.484.2.67 raeburn 3702: my $folderurl;
1.329 droeschl 3703: if ($uploaded) {
1.472 raeburn 3704: if (($extension eq 'sequence') || ($extension eq 'page')) {
3705: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3706: $containerarg = $1;
1.472 raeburn 3707: if ($extension eq 'sequence') {
3708: $icon=$iconpath.'navmap.folder.closed.gif';
3709: $isfolder=1;
3710: } else {
3711: $icon=$iconpath.'page.gif';
3712: $ispage=1;
3713: }
1.484.2.67 raeburn 3714: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3715: if ($allowed) {
3716: $url='/adm/coursedocs?';
3717: } else {
3718: $url='/adm/supplemental?';
3719: }
1.329 droeschl 3720: } else {
3721: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3722: }
3723: }
1.364 bisitz 3724:
1.484.2.70 raeburn 3725: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3726: my $orig_url = $url;
1.340 raeburn 3727: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.19 raeburn 3728: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.12 raeburn 3729: if (!$supplementalflag && $residx && $symb) {
3730: if ((!$isfolder) && (!$ispage)) {
3731: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3732: $url=&Apache::lonnet::clutter($url);
3733: if ($url=~/^\/*uploaded\//) {
3734: $url=~/\.(\w+)$/;
3735: my $embstyle=&Apache::loncommon::fileembstyle($1);
3736: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3737: $url='/adm/wrapper'.$url;
3738: } elsif ($embstyle eq 'ssi') {
3739: #do nothing with these
3740: } elsif ($url!~/\.(sequence|page)$/) {
3741: $url='/adm/coursedocs/showdoc'.$url;
3742: }
1.484.2.70 raeburn 3743: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
3744: my $wrapped = $1;
3745: my $exturl = $2;
3746: if ($wrapped eq '') {
3747: $url='/adm/wrapper'.$url;
3748: }
3749: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
3750: $nomodal = 1;
3751: }
3752: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3753: if (($ENV{'SERVER_PORT'} == 443) &&
3754: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
3755: $nomodal = 1;
3756: }
1.484.2.19 raeburn 3757: }
1.484.2.12 raeburn 3758: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3759: my $shownsymb = $symb;
3760: if ($isexternal) {
3761: if ($url =~ /^([^#]+)#([^#]+)$/) {
3762: $url = $1;
3763: $anchor = $2;
3764: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
3765: $shownsymb = $1.&escape('#').$anchor;
3766: }
3767: }
3768: }
1.484.2.67 raeburn 3769: unless ($env{'request.role.adv'}) {
3770: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3771: $url = '';
3772: }
3773: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3774: $url = '';
3775: $hiddenres = 1;
3776: }
3777: }
3778: if ($url ne '') {
1.484.2.75 raeburn 3779: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3780: }
3781: } elsif (!$env{'request.role.adv'}) {
3782: my $checkencrypt;
3783: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3784: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3785: $checkencrypt = 1;
1.484.2.70 raeburn 3786: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3787: unless (ref($$navmapref)) {
3788: $$navmapref = Apache::lonnavmaps::navmap->new();
3789: }
3790: if (ref($$navmapref)) {
3791: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
3792: $checkencrypt = 1;
3793: }
3794: }
3795: }
3796: if ($checkencrypt) {
3797: my $shownsymb = &Apache::lonenc::encrypted($symb);
3798: my $shownurl = &Apache::lonenc::encrypted($url);
3799: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
3800: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
3801: if ($env{'request.enc'} ne '') {
3802: delete($env{'request.enc'});
3803: }
3804: } else {
3805: $url='';
3806: }
3807: } else {
3808: $url='';
3809: }
1.484.2.12 raeburn 3810: } else {
3811: $url='';
3812: }
1.484.2.19 raeburn 3813: }
1.484.2.66 raeburn 3814: } elsif ($supplementalflag) {
3815: if ($isexternal) {
3816: if ($url =~ /^([^#]+)#([^#]+)$/) {
3817: $url = $1;
3818: $anchor = $2;
1.484.2.70 raeburn 3819: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
3820: $nomodal = 1;
3821: }
3822: }
3823: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
3824: if (($ENV{'SERVER_PORT'} == 443) &&
3825: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
3826: $nomodal = 1;
1.484.2.66 raeburn 3827: }
3828: }
1.329 droeschl 3829: }
1.484.2.67 raeburn 3830: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
3831: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 3832: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3833: my $foldername=&escape($foldertitle);
3834: my $folderpath=$env{'form.folderpath'};
3835: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 3836: if (!$allowed && $supplementalflag) {
3837: $folderpath.=$containerarg.'&'.$foldername;
3838: $url.='folderpath='.&escape($folderpath);
3839: } else {
3840: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3841: 'parameter_randompick'))[0];
1.484.2.67 raeburn 3842: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
3843: 'parameter_randomorder'))[0]=~/^yes$/i);
3844: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
3845: 'parameter_hiddenresource'))[0]=~/^yes$/i);
3846: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
3847: 'parameter_encrypturl'))[0]=~/^yes$/i);
3848: unless ($hiddenmap) {
1.484.2.70 raeburn 3849: if (ref($navmapref)) {
3850: unless (ref($$navmapref)) {
3851: $$navmapref = Apache::lonnavmaps::navmap->new();
3852: }
3853: if (ref($$navmapref)) {
3854: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
3855: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
3856: unless (@resources) {
3857: $hiddenmap = 1;
3858: unless ($env{'request.role.adv'}) {
3859: $url = '';
3860: $hiddenfolder = 1;
3861: }
1.484.2.67 raeburn 3862: }
3863: }
3864: }
3865: }
3866: }
3867: unless ($encryptmap) {
1.484.2.70 raeburn 3868: if ((ref($navmapref)) && (ref($$navmapref))) {
3869: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
3870: $encryptmap = 1;
3871: }
1.484.2.67 raeburn 3872: }
3873: }
3874:
3875: # Append randompick number, hidden, and encrypted with ":" to foldername,
3876: # so it gets transferred between levels
3877: $folderpath.=$containerarg.'&'.$foldername.
3878: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
3879: unless ($url eq '') {
3880: $url.='folderpath='.&escape($folderpath);
3881: }
1.484.2.19 raeburn 3882: my $rpckchk;
3883: if ($rpicknum) {
3884: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 3885: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3886: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3887: }
1.484.2.19 raeburn 3888: }
1.484.2.29 raeburn 3889: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 3890: $rand_pick_text =
1.478 raeburn 3891: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3892: $form_param."\n".
1.478 raeburn 3893: $form_common."\n".
1.484.2.67 raeburn 3894: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.$disabled.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
1.484.2.19 raeburn 3895: if ($rpicknum ne '') {
3896: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3897: }
1.484.2.29 raeburn 3898: $rand_pick_text .= '</span></span>'.
3899: $form_end;
1.484.2.30 raeburn 3900: my $ro_set;
1.484.2.67 raeburn 3901: if ($randorder) {
1.484.2.30 raeburn 3902: $ro_set = 'checked="checked"';
3903: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3904: push(@{$filtersref->{'randomorder'}},$orderidx);
3905: }
3906: }
1.484.2.41 raeburn 3907: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 3908: $rand_order_text =
1.484.2.29 raeburn 3909: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3910: $form_param."\n".
1.484.2.29 raeburn 3911: $form_common."\n".
1.484.2.67 raeburn 3912: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.$disabled.' /> '.&mt('Random Order').' </label></span>'.
1.484.2.29 raeburn 3913: $form_end;
1.484.2.19 raeburn 3914: }
1.484.2.18 raeburn 3915: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 3916: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 3917: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 3918: if ($title) {
3919: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3920: }
3921: if ($isexternal && $orderidx) {
3922: $url .= '&idx='.$orderidx;
3923: }
1.484.2.66 raeburn 3924: if ($anchor ne '') {
3925: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
3926: }
1.329 droeschl 3927: }
1.484.2.19 raeburn 3928: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 3929: if ($allowed) {
1.484.2.19 raeburn 3930: my $fileloc =
1.484.2.12 raeburn 3931: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 3932: if ($isexternal) {
3933: ($editlink,$extresform) =
1.484.2.67 raeburn 3934: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
3935: undef,undef,undef,$disabled);
1.484.2.19 raeburn 3936: } elsif (!$isfolder && !$ispage) {
3937: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 3938: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 3939: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 3940: my $suppanchor;
3941: if ($supplementalflag) {
3942: $suppanchor = $anchor;
3943: }
1.484.2.19 raeburn 3944: my $jscall =
1.484.2.12 raeburn 3945: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
3946: $switchserver,
1.484.2.14 raeburn 3947: $forceedit,
1.484.2.19 raeburn 3948: undef,$symb,
3949: &escape($env{'form.folderpath'}),
1.484.2.66 raeburn 3950: $renametitle,'','',1,$suppanchor);
1.484.2.12 raeburn 3951: if ($jscall) {
1.484.2.19 raeburn 3952: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
3953: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 3954: }
3955: }
3956: }
1.484.2.19 raeburn 3957: $tdalign = ' align="right" valign="top"';
3958: $tdwidth = ' width="80%"';
1.329 droeschl 3959: }
1.408 raeburn 3960: my $reinit;
3961: if ($crstype eq 'Community') {
3962: $reinit = &mt('(re-initialize community to access)');
3963: } else {
3964: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 3965: }
3966: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 3967: my $link;
1.472 raeburn 3968: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3969: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
3970: } elsif ($url) {
1.484.2.66 raeburn 3971: if ($anchor ne '') {
3972: if ($supplementalflag) {
3973: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
3974: } else {
3975: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
3976: }
3977: }
1.484.2.70 raeburn 3978: $link = &js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
3979: (($anchor ne '')?$anchor:''));
3980: if ($nomodal) {
3981: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
3982: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
3983: } else {
3984: $line.=&Apache::loncommon::modal_link($link,
3985: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
3986: }
1.469 www 3987: } else {
3988: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
3989: }
1.484.2.19 raeburn 3990: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 3991: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3992: $line.='<a href="'.$url.'">'.$title.'</a>';
3993: } elsif ($url) {
1.484.2.70 raeburn 3994: if ($nomodal) {
3995: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
3996: $title.'</a>';
3997: } else {
3998: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
3999: }
1.484.2.67 raeburn 4000: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4001: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4002: } else {
4003: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4004: }
1.484.2.19 raeburn 4005: $line.="$extresform</td>";
1.478 raeburn 4006: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4007: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4008: if (($allowed) && ($folder!~/^supplemental/)) {
4009: my %lt=&Apache::lonlocal::texthash(
4010: 'hd' => 'Hidden',
4011: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4012: my ($enctext,$hidtext);
4013: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4014: $enctext = ' checked="checked"';
4015: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4016: push(@{$filtersref->{'encrypturl'}},$orderidx);
4017: }
4018: }
4019: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4020: $hidtext = ' checked="checked"';
4021: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4022: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4023: }
4024: }
1.484.2.29 raeburn 4025: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4026: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4027: $line.=(<<ENDPARMS);
4028: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4029: <form action="/adm/coursedocs" method="post" name="$formhidden">
4030: $form_param
1.478 raeburn 4031: $form_common
1.484.2.67 raeburn 4032: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4033: $form_end
1.458 raeburn 4034: <br />
1.484.2.29 raeburn 4035: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4036: $form_param
1.478 raeburn 4037: $form_common
1.484.2.67 raeburn 4038: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4039: $form_end
4040: </td>
1.478 raeburn 4041: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4042: $rand_order_text</td>
1.329 droeschl 4043: ENDPARMS
4044: }
1.379 bisitz 4045: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4046: return $line;
4047: }
4048:
1.484.2.30 raeburn 4049: sub action_restrictions {
4050: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4051: my %denied = (
4052: cut => 0,
4053: copy => 0,
4054: remove => 0,
4055: );
4056: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4057: # no copy for published maps
4058: $denied{'copy'} = 1;
4059: } elsif ($url=~m{^/res/lib/templates/}) {
4060: $denied{'copy'} = 1;
4061: $denied{'cut'} = 1;
4062: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4063: if ($folderpath =~ /^default&[^\&]+$/) {
4064: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4065: $denied{'remove'} = 1;
4066: }
4067: $denied{'cut'} = 1;
4068: $denied{'copy'} = 1;
4069: }
4070: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4071: my $group = $1;
4072: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4073: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4074: $denied{'remove'} = 1;
4075: }
4076: }
4077: $denied{'cut'} = 1;
4078: $denied{'copy'} = 1;
4079: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4080: my $group = $1;
4081: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4082: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4083: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4084: if (keys(%groupsettings) > 0) {
4085: $denied{'remove'} = 1;
4086: }
4087: $denied{'cut'} = 1;
4088: $denied{'copy'} = 1;
4089: }
4090: }
4091: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4092: my $group = $1;
4093: if ($url =~ /group_boards_\Q$group\E/) {
4094: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4095: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4096: if (keys(%groupsettings) > 0) {
4097: if (ref($groupsettings{'functions'}) eq 'HASH') {
4098: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4099: $denied{'remove'} = 1;
4100: }
4101: }
4102: }
4103: $denied{'cut'} = 1;
4104: $denied{'copy'} = 1;
4105: }
4106: }
4107: }
4108: return %denied;
4109: }
4110:
1.484.2.26 raeburn 4111: sub new_timebased_suffix {
1.484.2.30 raeburn 4112: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4113: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4114: if ($type eq 'paste') {
4115: $prefix = $type;
4116: $namespace = 'courseeditor';
1.484.2.56 raeburn 4117: $idtype = 'addcode';
1.484.2.30 raeburn 4118: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4119: $prefix = 'docs';
4120: if ($area eq 'supplemental') {
4121: $prefix = 'supp';
4122: }
4123: $prefix .= $container;
4124: $namespace = 'uploadedmaps';
4125: } else {
4126: $prefix = $type;
4127: $namespace = 'templated';
1.484.2.15 raeburn 4128: }
4129: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4130: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4131: if (!$suffix) {
1.484.2.30 raeburn 4132: if ($type eq 'paste') {
4133: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4134: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4135: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4136: } elsif ($type eq 'smppg') {
4137: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4138: } else {
1.484.2.42 raeburn 4139: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4140: }
1.484.2.15 raeburn 4141: if ($error) {
4142: $errtext .= '<br />'.$error;
4143: }
4144: }
4145: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4146: $locknotfreed =
4147: '<div class="LC_error">'.
4148: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4149: if ($type eq 'paste') {
1.484.2.57 raeburn 4150: if ($freedlock eq 'nolock') {
4151: $locknotfreed =
4152: '<div class="LC_error">'.
4153: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4154:
1.484.2.60 raeburn 4155: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4156: } else {
4157: $locknotfreed .=
4158: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4159: }
1.484.2.30 raeburn 4160: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4161: $locknotfreed .=
4162: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4163: } elsif ($type eq 'smppg') {
4164: $locknotfreed .=
4165: &mt('This will prevent creation of additional simple pages in this course.');
4166: } else {
4167: $locknotfreed .=
1.484.2.42 raeburn 4168: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4169: }
1.484.2.30 raeburn 4170: unless ($type eq 'paste') {
4171: $locknotfreed .=
1.484.2.38 raeburn 4172: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4173: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4174: }
4175: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4176: }
4177: return ($suffix,$errtext,$locknotfreed);
4178: }
4179:
1.329 droeschl 4180: =pod
4181:
4182: =item tiehash()
4183:
4184: tie the hash
4185:
4186: =cut
4187:
4188: sub tiehash {
4189: my ($mode)=@_;
4190: $hashtied=0;
4191: if ($env{'request.course.fn'}) {
4192: if ($mode eq 'write') {
4193: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4194: &GDBM_WRCREAT(),0640)) {
4195: $hashtied=2;
4196: }
4197: } else {
4198: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4199: &GDBM_READER(),0640)) {
4200: $hashtied=1;
4201: }
4202: }
1.364 bisitz 4203: }
1.329 droeschl 4204: }
4205:
4206: sub untiehash {
4207: if ($hashtied) { untie %hash; }
4208: $hashtied=0;
4209: return OK;
4210: }
4211:
4212:
4213:
4214:
4215: sub checkonthis {
1.484.2.78! raeburn 4216: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4217: $url=&unescape($url);
4218: $alreadyseen{$url}=1;
4219: $r->rflush();
4220: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4221: $r->print("\n<br />");
4222: if ($level==0) {
4223: $r->print("<br />");
4224: }
4225: for (my $i=0;$i<=$level*5;$i++) {
4226: $r->print(' ');
4227: }
4228: $r->print('<a href="'.$url.'" target="cat">'.
4229: ($title?$title:$url).'</a> ');
4230: if ($url=~/^\/res\//) {
1.484.2.78! raeburn 4231: my $updated;
! 4232: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
! 4233: ($url !~ /\.\d+\.\w+$/)) {
! 4234: $updated = &Apache::lonnet::remove_stale_resfile($url);
! 4235: }
1.329 droeschl 4236: my $result=&Apache::lonnet::repcopy(
4237: &Apache::lonnet::filelocation('',$url));
4238: if ($result eq 'ok') {
4239: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78! raeburn 4240: if ($updated) {
! 4241: $r->print('<br />');
! 4242: for (my $i=0;$i<=$level*5;$i++) {
! 4243: $r->print(' ');
! 4244: }
! 4245: $r->print('- '.&mt('Outdated copy removed'));
! 4246: }
1.329 droeschl 4247: $r->rflush();
4248: &Apache::lonnet::countacc($url);
4249: $url=~/\.(\w+)$/;
4250: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4251: $r->print('<br />');
4252: $r->rflush();
4253: for (my $i=0;$i<=$level*5;$i++) {
4254: $r->print(' ');
4255: }
4256: $r->print('- '.&mt('Rendering:').' ');
4257: my ($errorcount,$warningcount)=split(/:/,
4258: &Apache::lonnet::ssi_body($url,
4259: ('grade_target'=>'web',
4260: 'return_only_error_and_warning_counts' => 1)));
4261: if (($errorcount) ||
4262: ($warningcount)) {
4263: if ($errorcount) {
1.369 bisitz 4264: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4265: &mt('[quant,_1,error]',$errorcount).'</span>');
4266: }
4267: if ($warningcount) {
4268: $r->print('<span class="LC_warning">'.
4269: &mt('[quant,_1,warning]',$warningcount).'</span>');
4270: }
4271: } else {
4272: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4273: }
4274: $r->rflush();
4275: }
4276: my $dependencies=
4277: &Apache::lonnet::metadata($url,'dependencies');
4278: foreach my $dep (split(/\,/,$dependencies)) {
4279: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78! raeburn 4280: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4281: }
4282: }
4283: } elsif ($result eq 'unavailable') {
4284: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4285: } elsif ($result eq 'not_found') {
4286: unless ($url=~/\$/) {
1.484.2.19 raeburn 4287: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4288: } else {
1.366 bisitz 4289: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4290: }
4291: } else {
4292: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4293: }
1.484.2.78! raeburn 4294: if (($updated) && ($result ne 'ok')) {
! 4295: $r->print('<br />'.&mt('Outdated copy removed'));
! 4296: }
1.329 droeschl 4297: }
4298: }
4299: }
4300:
4301:
4302:
4303: =pod
4304:
4305: =item list_symbs()
4306:
1.484.2.3 raeburn 4307: List Content Identifiers
1.329 droeschl 4308:
4309: =cut
4310:
4311: sub list_symbs {
4312: my ($r) = @_;
4313:
1.408 raeburn 4314: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4315: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4316: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4317: $r->print(&startContentScreen('tools'));
1.329 droeschl 4318: my $navmap = Apache::lonnavmaps::navmap->new();
4319: if (!defined($navmap)) {
4320: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4321: '<div class="LC_error">'.
4322: &mt('Unable to retrieve information about course contents').
4323: '</div>');
1.408 raeburn 4324: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4325: } else {
1.484 raeburn 4326: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4327: &Apache::loncommon::start_data_table().
4328: &Apache::loncommon::start_data_table_header_row().
4329: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4330: &Apache::loncommon::end_data_table_header_row()."\n");
4331: my $count;
1.329 droeschl 4332: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4333: $r->print(&Apache::loncommon::start_data_table_row().
4334: '<td>'.$res->compTitle().'</td>'.
4335: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4336: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4337: $count ++;
4338: }
4339: if (!$count) {
4340: $r->print(&Apache::loncommon::start_data_table_row().
4341: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4342: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4343: }
1.484 raeburn 4344: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4345: }
1.484.2.19 raeburn 4346: $r->print(&endContentScreen());
1.329 droeschl 4347: }
4348:
1.484.2.78! raeburn 4349: sub contentverifyform {
! 4350: my ($r) = @_;
! 4351: my $crstype = &Apache::loncommon::course_type();
! 4352: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
! 4353: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
! 4354: $r->print(&startContentScreen('tools'));
! 4355: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
! 4356: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
! 4357: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
! 4358: ' <span class="LC_nobreak">'.
! 4359: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
! 4360: &mt('No').'</label>'.(' 'x2).
! 4361: '<label><input type="radio" name="checkstale" value="1" />'.
! 4362: &mt('Yes').'</label></span></p><p>'.
! 4363: '<input type="submit" value="'.&mt('Verify content').' "/>'.
! 4364: '<input type="hidden" value="1" name="tools" />'.
! 4365: '<input type="hidden" value="1" name="verify" /></p></form>');
! 4366: $r->print(&endContentScreen());
! 4367: return;
! 4368: }
1.329 droeschl 4369:
4370: sub verifycontent {
1.484.2.78! raeburn 4371: my ($r,$checkstale) = @_;
1.408 raeburn 4372: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4373: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4374: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4375: $r->print(&startContentScreen('tools'));
4376: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4377: $hashtied=0;
4378: undef %alreadyseen;
4379: %alreadyseen=();
4380: &tiehash();
1.484 raeburn 4381:
1.329 droeschl 4382: foreach my $key (keys(%hash)) {
4383: if ($hash{$key}=~/\.(page|sequence)$/) {
4384: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4385: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4386: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4387: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4388: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4389: }
4390: }
4391: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78! raeburn 4392: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4393: }
4394: }
4395: &untiehash();
1.442 www 4396: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4397: $r->print(&endContentScreen());
1.329 droeschl 4398: }
4399:
4400:
4401: sub devalidateversioncache {
4402: my $src=shift;
4403: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4404: &Apache::lonnet::clutter($src));
4405: }
4406:
4407: sub checkversions {
1.484.2.67 raeburn 4408: my ($r,$canedit) = @_;
1.408 raeburn 4409: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4410: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4411: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4412: $r->print(&startContentScreen('tools'));
1.442 www 4413:
1.329 droeschl 4414: my $header='';
4415: my $startsel='';
4416: my $monthsel='';
4417: my $weeksel='';
4418: my $daysel='';
4419: my $allsel='';
4420: my %changes=();
4421: my $starttime=0;
4422: my $haschanged=0;
4423: my %setversions=&Apache::lonnet::dump('resourceversions',
4424: $env{'course.'.$env{'request.course.id'}.'.domain'},
4425: $env{'course.'.$env{'request.course.id'}.'.num'});
4426:
4427: $hashtied=0;
4428: &tiehash();
1.484.2.67 raeburn 4429: if ($canedit) {
4430: my %newsetversions=();
4431: if ($env{'form.setmostrecent'}) {
4432: $haschanged=1;
4433: foreach my $key (keys(%hash)) {
4434: if ($key=~/^ids\_(\/res\/.+)$/) {
4435: $newsetversions{$1}='mostrecent';
4436: &devalidateversioncache($1);
4437: }
1.329 droeschl 4438: }
1.484.2.67 raeburn 4439: } elsif ($env{'form.setcurrent'}) {
4440: $haschanged=1;
4441: foreach my $key (keys(%hash)) {
4442: if ($key=~/^ids\_(\/res\/.+)$/) {
4443: my $getvers=&Apache::lonnet::getversion($1);
4444: if ($getvers>0) {
4445: $newsetversions{$1}=$getvers;
4446: &devalidateversioncache($1);
4447: }
4448: }
1.329 droeschl 4449: }
1.484.2.67 raeburn 4450: } elsif ($env{'form.setversions'}) {
4451: $haschanged=1;
4452: foreach my $key (keys(%env)) {
4453: if ($key=~/^form\.set_version_(.+)$/) {
4454: my $src=$1;
4455: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4456: $newsetversions{$src}=$env{$key};
4457: &devalidateversioncache($src);
4458: }
4459: }
1.329 droeschl 4460: }
1.484.2.67 raeburn 4461: }
4462: if ($haschanged) {
4463: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4464: $env{'course.'.$env{'request.course.id'}.'.domain'},
4465: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4466: $r->print(&Apache::loncommon::confirmwrapper(
4467: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4468: } else {
4469: $r->print(&Apache::loncommon::confirmwrapper(
4470: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4471: }
4472: &mark_hash_old();
4473: }
4474: &changewarning($r,'');
1.329 droeschl 4475: }
4476: if ($env{'form.timerange'} eq 'all') {
4477: # show all documents
1.484.2.34 raeburn 4478: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4479: $allsel=' selected="selected"';
1.329 droeschl 4480: foreach my $key (keys(%hash)) {
4481: if ($key=~/^ids\_(\/res\/.+)$/) {
4482: my $src=$1;
4483: $changes{$src}=1;
4484: }
4485: }
4486: } else {
4487: # show documents which changed
4488: %changes=&Apache::lonnet::dump
4489: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4490: $env{'course.'.$env{'request.course.id'}.'.num'});
4491: my $firstkey=(keys(%changes))[0];
4492: unless ($firstkey=~/^error\:/) {
4493: unless ($env{'form.timerange'}) {
4494: $env{'form.timerange'}=604800;
4495: }
4496: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4497: .&mt('seconds');
4498: if ($env{'form.timerange'}==-1) {
4499: $seltext='since start of course';
1.484.2.19 raeburn 4500: $startsel=' selected="selected"';
1.329 droeschl 4501: $env{'form.timerange'}=time;
4502: }
4503: $starttime=time-$env{'form.timerange'};
4504: if ($env{'form.timerange'}==2592000) {
4505: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4506: $monthsel=' selected="selected"';
1.329 droeschl 4507: } elsif ($env{'form.timerange'}==604800) {
4508: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4509: $weeksel=' selected="selected"';
1.329 droeschl 4510: } elsif ($env{'form.timerange'}==86400) {
4511: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4512: $daysel=' selected="selected"';
1.329 droeschl 4513: }
4514: $header=&mt('Content changed').' '.$seltext;
4515: } else {
4516: $header=&mt('No content modifications yet.');
4517: }
4518: }
4519: %setversions=&Apache::lonnet::dump('resourceversions',
4520: $env{'course.'.$env{'request.course.id'}.'.domain'},
4521: $env{'course.'.$env{'request.course.id'}.'.num'});
4522: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4523: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4524: 'lm' => 'Version changes since last Month',
4525: 'lw' => 'Version changes since last Week',
4526: 'sy' => 'Version changes since Yesterday',
4527: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4528: 'cd' => 'Change display',
1.329 droeschl 4529: 'sd' => 'Display',
4530: 'fi' => 'File',
4531: 'md' => 'Modification Date',
4532: 'mr' => 'Most recently published Version',
1.408 raeburn 4533: 've' => 'Version used in '.$crstype,
4534: 'vu' => 'Set Version to be used in '.$crstype,
4535: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4536: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4537: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4538: 'di' => 'Differences',
1.484 raeburn 4539: 'save' => 'Save changes',
4540: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4541: 'act' => 'Actions');
1.484.2.67 raeburn 4542: my ($disabled,$readonly);
4543: unless ($canedit) {
4544: $disabled = 'disabled="disabled"';
4545: $readonly = 1;
4546: }
1.329 droeschl 4547: $r->print(<<ENDHEADERS);
1.484 raeburn 4548: <h4 class="LC_info">$header</h4>
1.329 droeschl 4549: <form action="/adm/coursedocs" method="post">
4550: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4551: <div class="LC_left_float">
1.479 golterma 4552: <fieldset>
1.484 raeburn 4553: <legend>$lt{'cd'}</legend>
1.329 droeschl 4554: <select name="timerange">
1.484.2.19 raeburn 4555: <option value='all'$allsel>$lt{'al'}</option>
4556: <option value="-1"$startsel>$lt{'st'}</option>
4557: <option value="2592000"$monthsel>$lt{'lm'}</option>
4558: <option value="604800"$weeksel>$lt{'lw'}</option>
4559: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4560: </select>
4561: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4562: </fieldset>
4563: </div>
4564: <div class="LC_left_float">
4565: <fieldset>
4566: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4567: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4568: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4569: </fieldset>
4570: </div>
4571: <br clear="all" />
4572: <hr />
4573: <h4>$lt{'vers'}</h4>
1.329 droeschl 4574: ENDHEADERS
1.479 golterma 4575: #number of columns for version history
1.484.2.44 raeburn 4576: my %changedbytime;
4577: foreach my $key (keys(%changes)) {
4578: #excludes not versionable problems from resource version history:
4579: next if ($key =~ /^\/res\/lib\/templates/);
4580: my $chg;
4581: if ($env{'form.timerange'} eq 'all') {
4582: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4583: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4584: } else {
4585: $chg = $changes{$key};
4586: next if ($chg < $starttime);
4587: }
4588: push(@{$changedbytime{$chg}},$key);
4589: }
4590: if (keys(%changedbytime) == 0) {
4591: &untiehash();
4592: $r->print(&mt('No content changes in imported content in specified time frame').
4593: &endContentScreen());
4594: return;
4595: }
1.479 golterma 4596: $r->print(
1.484.2.67 raeburn 4597: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4598: &Apache::loncommon::start_data_table().
4599: &Apache::loncommon::start_data_table_header_row().
4600: '<th>'.&mt('Resources').'</th>'.
4601: "<th>$lt{'mr'}</th>".
4602: "<th>$lt{'ve'}</th>".
4603: "<th>$lt{'vu'}</th>".
4604: '<th>'.&mt('History').'</th>'.
4605: &Apache::loncommon::end_data_table_header_row()
4606: );
1.484.2.44 raeburn 4607: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4608: foreach my $key (sort(@{$changedbytime{$chg}})) {
4609: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4610: my $currentversion=&Apache::lonnet::getversion($key);
4611: if ($currentversion<0) {
4612: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4613: }
4614: my $linkurl=&Apache::lonnet::clutter($key);
4615: $r->print(
4616: &Apache::loncommon::start_data_table_row().
4617: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4618: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4619: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4620: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4621: '<td align="right">'
4622: );
4623: # Used in course
4624: my $usedversion=$hash{'version_'.$linkurl};
4625: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4626: if ($usedversion != $currentversion) {
1.479 golterma 4627: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4628: } else {
1.479 golterma 4629: $r->print($usedversion);
4630: }
1.329 droeschl 4631: } else {
1.484.2.19 raeburn 4632: $r->print($currentversion);
1.329 droeschl 4633: }
1.484.2.44 raeburn 4634: $r->print('</td><td title="'.$lt{'vu'}.'">');
4635: # Set version
4636: $r->print(&Apache::loncommon::select_form(
4637: $setversions{$linkurl},
4638: 'set_version_'.$linkurl,
4639: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4640: '' => '',
4641: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4642: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4643: my $lastold=1;
4644: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4645: my $url=$root.'.'.$prevvers.'.'.$extension;
4646: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4647: $lastold=$prevvers;
4648: }
4649: }
4650: $r->print('</td>');
4651: # List all available versions
4652: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4653: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4654: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4655: $r->print(
1.484.2.44 raeburn 4656: '<span class="LC_nobreak">'
4657: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4658: .&mt('Version [_1]',$prevvers).'</a>'
4659: .' ('.&Apache::lonlocal::locallocaltime(
4660: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4661: .')');
4662: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4663: $r->print(
4664: ' <a href="/adm/diff?filename='.
4665: &Apache::lonnet::clutter($root.'.'.$extension).
4666: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4667: '" target="diffs">'.&mt('Diffs').'</a>');
4668: }
4669: $r->print('</span><br />');
1.329 droeschl 4670: }
1.484.2.44 raeburn 4671: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4672: }
1.329 droeschl 4673: }
1.484.2.19 raeburn 4674: $r->print(
4675: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4676: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4677: '</form>'
4678: );
1.329 droeschl 4679:
4680: &untiehash();
1.484.2.19 raeburn 4681: $r->print(&endContentScreen());
1.484.2.44 raeburn 4682: return;
1.329 droeschl 4683: }
4684:
4685: sub mark_hash_old {
4686: my $retie_hash=0;
4687: if ($hashtied) {
4688: $retie_hash=1;
4689: &untiehash();
4690: }
4691: &tiehash('write');
4692: $hash{'old'}=1;
4693: &untiehash();
4694: if ($retie_hash) { &tiehash(); }
4695: }
4696:
4697: sub is_hash_old {
4698: my $untie_hash=0;
4699: if (!$hashtied) {
4700: $untie_hash=1;
4701: &tiehash();
4702: }
4703: my $return=$hash{'old'};
4704: if ($untie_hash) { &untiehash(); }
4705: return $return;
4706: }
4707:
4708: sub changewarning {
4709: my ($r,$postexec,$message,$url)=@_;
4710: if (!&is_hash_old()) { return; }
4711: my $pathvar='folderpath';
4712: my $path=&escape($env{'form.folderpath'});
4713: if (!defined($url)) {
4714: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4715: }
4716: my $course_type = &Apache::loncommon::course_type();
4717: if (!defined($message)) {
4718: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4719: }
4720: $r->print("\n\n".
1.372 bisitz 4721: '<script type="text/javascript">'."\n".
4722: '// <![CDATA['."\n".
4723: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4724: '// ]]>'."\n".
1.369 bisitz 4725: '</script>'."\n".
1.375 tempelho 4726: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4727: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4728: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4729: &mt($message,' <input type="hidden" name="'.
4730: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4731: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4732: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4733: }
4734:
4735:
4736: sub init_breadcrumbs {
1.484.2.44 raeburn 4737: my ($form,$text,$help)=@_;
1.329 droeschl 4738: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4739: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4740: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4741: faq=>273,
4742: bug=>'Instructor Interface',
1.484.2.44 raeburn 4743: help => $help});
1.329 droeschl 4744: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4745: text=>$text,
4746: faq=>273,
4747: bug=>'Instructor Interface'});
4748: }
4749:
1.441 www 4750: # subroutine to list form elements
4751: sub create_list_elements {
4752: my @formarr = @_;
4753: my $list = '';
1.484.2.12 raeburn 4754: foreach my $button (@formarr){
4755: foreach my $picture (keys(%{$button})) {
4756: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4757: }
4758: }
4759: return $list;
4760: }
1.329 droeschl 4761:
1.441 www 4762: # subroutine to create ul from list elements
4763: sub create_form_ul {
4764: my $list = shift;
4765: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4766: return $ul;
4767: }
1.329 droeschl 4768:
1.442 www 4769: #
4770: # Start tabs
4771: #
4772:
4773: sub startContentScreen {
1.484 raeburn 4774: my ($mode) = @_;
4775: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4776: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4777: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4778: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4779: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4780: } else {
1.484.2.34 raeburn 4781: $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 4782: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4783: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4784: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4785: }
4786: $output .= "\n".'</ul>'."\n";
4787: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4788: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4789: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4790: return $output;
1.442 www 4791: }
4792:
4793: #
4794: # End tabs
4795: #
4796:
4797: sub endContentScreen {
1.484 raeburn 4798: return '</div></div></div>';
1.442 www 4799: }
1.329 droeschl 4800:
1.446 www 4801: sub supplemental_base {
1.484.2.33 raeburn 4802: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4803: }
4804:
1.329 droeschl 4805: sub handler {
4806: my $r = shift;
4807: &Apache::loncommon::content_type($r,'text/html');
4808: $r->send_http_header;
4809: return OK if $r->header_only;
1.484 raeburn 4810:
4811: # get course data
1.408 raeburn 4812: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4813: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4814: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4815:
4816: # graphics settings
4817: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4818:
1.443 www 4819: #
1.329 droeschl 4820: # --------------------------------------------- Initialize help topics for this
4821: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4822: 'Adding_External_Resource','Navigate_Content',
4823: 'Adding_Folders','Docs_Overview', 'Load_Map',
4824: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 4825: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 4826: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
4827: 'Dropbox','Simple_Problem') {
1.329 droeschl 4828: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4829: }
4830: # Composite help files
4831: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4832: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4833: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4834: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4835: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4836: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4837: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4838: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4839: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4840: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 4841:
1.484.2.67 raeburn 4842: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 4843: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4844: unless ($r->uri eq '/adm/supplemental') {
4845: # does this user have privileges to modify content.
1.484.2.67 raeburn 4846: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
4847: $allowed = 1;
4848: $canedit = 1;
4849: $canview = 1;
4850: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
4851: $allowed = 1;
4852: $canview = 1;
4853: }
4854: }
4855: unless ($canedit) {
4856: $disabled = ' disabled="disabled"';
1.472 raeburn 4857: }
1.484.2.53 raeburn 4858: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78! raeburn 4859: if ($env{'form.inhibitmenu'}) {
! 4860: unless ($env{'form.inhibitmenu'} eq 'yes') {
! 4861: delete($env{'form.inhibitmenu'});
! 4862: }
! 4863: }
! 4864:
1.484.2.53 raeburn 4865: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 4866: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78! raeburn 4867: if (!$canedit) {
! 4868: &verifycontent($r);
! 4869: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
! 4870: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
! 4871: text=>'Results',
! 4872: faq=>273,
! 4873: bug=>'Instructor Interface'});
! 4874: &verifycontent($r,$env{'form.checkstale'});
! 4875: } else {
! 4876: &contentverifyform($r);
! 4877: }
1.329 droeschl 4878: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4879: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4880: &list_symbs($r);
4881: } elsif ($allowed && $env{'form.docslog'}) {
4882: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4883: my $folder = $env{'form.folder'};
4884: if ($folder eq '') {
4885: $folder='default';
4886: }
1.484.2.67 raeburn 4887: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 4888: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 4889: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 4890: &checkversions($r,$canedit);
4891: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 4892: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4893: &dumpcourse($r);
4894: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 4895: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4896: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4897: } else {
1.445 www 4898: #
4899: # Done catching special calls
1.484 raeburn 4900: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 4901: # Get the parameters that may be needed
4902: #
4903: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 4904: ['folderpath',
4905: 'forcesupplement','forcestandard',
4906: 'tools','symb','command','supppath']);
1.445 www 4907:
1.484.2.78! raeburn 4908: foreach my $item ('forcesupplement','forcestandard','tools') {
! 4909: next if ($env{'form.'.$item} eq '');
! 4910: unless ($env{'form.'.$item} eq '1') {
! 4911: delete($env{'form.'.$item});
! 4912: }
! 4913: }
! 4914:
! 4915: if ($env{'form.command'}) {
! 4916: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
! 4917: delete($env{'form.command'});
! 4918: }
! 4919: }
! 4920:
! 4921: if ($env{'form.symb'}) {
! 4922: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
! 4923: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
! 4924: delete($env{'form.symb'});
! 4925: }
! 4926: }
! 4927:
1.445 www 4928: # standard=1: this is a "new-style" course with an uploaded map as top level
4929: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 4930:
4931: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 4932:
1.484 raeburn 4933: # Decide whether this should display supplemental or main content or utilities
1.445 www 4934: # supplementalflag=1: show supplemental documents
4935: # supplementalflag=0: show standard documents
1.484 raeburn 4936: # toolsflag=1: show utilities
1.445 www 4937:
1.484.2.39 raeburn 4938: my $unesc_folderpath = &unescape($env{'form.folderpath'});
4939: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
4940: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 4941: $supplementalflag=0;
4942: }
4943: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4944: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4945: unless ($allowed) { $supplementalflag=1; }
4946: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 4947: my $toolsflag=0;
4948: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 4949:
1.484.2.78! raeburn 4950: if ($env{'form.folderpath'} ne '') {
! 4951: my @items = split(/\&/,$env{'form.folderpath'});
! 4952: my $badpath;
! 4953: for (my $i=0; $i<@items; $i++) {
! 4954: my $odd = $i%2;
! 4955: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
! 4956: $badpath = 1;
! 4957: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
! 4958: $badpath = 1;
! 4959: }
! 4960: last if ($badpath);
! 4961: }
! 4962: if ($badpath) {
! 4963: delete($env{'form.folderpath'});
! 4964: }
! 4965: }
! 4966:
! 4967: if ($env{'form.supppath'} ne '') {
! 4968: my @items = split(/\&/,$env{'form.supppath'});
! 4969: my $badpath;
! 4970: for (my $i=0; $i<@items; $i++) {
! 4971: my $odd = $i%2;
! 4972: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
! 4973: $badpath = 1;
! 4974: }
! 4975: last if ($badpath);
! 4976: }
! 4977: if ($badpath) {
! 4978: delete($env{'form.supppath'});
! 4979: }
! 4980: }
! 4981:
1.329 droeschl 4982: my $script='';
4983: my $showdoc=0;
1.457 raeburn 4984: my $addentries = {};
1.475 raeburn 4985: my $container;
1.329 droeschl 4986: my $containertag;
1.484.2.17 raeburn 4987: my $pathitem;
1.484.2.67 raeburn 4988: my $hiddentop;
4989: my $navmap;
4990: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 4991:
1.464 www 4992: # Do we directly jump somewhere?
1.484.2.21 raeburn 4993: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 4994: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 4995: $env{'form.folderpath'}=
1.484.2.67 raeburn 4996: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 4997: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4998: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 4999: } elsif ($env{'form.supppath'} ne '') {
5000: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5001: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5002: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5003: }
1.472 raeburn 5004: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5005: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5006: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5007: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5008: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5009: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5010: } elsif ($env{'form.command'} eq 'contents') {
5011: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5012: } elsif ($env{'form.command'} eq 'home') {
5013: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5014: }
5015:
1.484.2.23 raeburn 5016:
1.445 www 5017: # Where do we store these for when we come back?
5018: my $stored_folderpath='docs_folderpath';
5019: if ($supplementalflag) {
5020: $stored_folderpath='docs_sup_folderpath';
5021: }
1.464 www 5022:
1.484.2.19 raeburn 5023: # No folderpath, and in edit mode, see if we have something stored
5024: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5025: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5026: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5027:
5028: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5029: if ($supplementalflag) {
5030: undef($env{'form.folderpath'}) if ($1 eq 'default');
5031: } else {
5032: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5033: }
5034: } else {
1.484.2.19 raeburn 5035: undef($env{'form.folderpath'});
5036: }
1.329 droeschl 5037: }
1.446 www 5038:
5039: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5040: if (!$allowed) {
1.446 www 5041: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5042: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5043: }
5044: }
1.446 www 5045: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5046: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5047: $env{'form.folderpath'} = &supplemental_base()
5048: .'&'.
1.329 droeschl 5049: $env{'form.folderpath'};
5050: }
1.484.2.67 raeburn 5051: # If allowed and user's role is not advanced check folderpath is not hidden
5052: if (($allowed) && (!$env{'request.role.adv'}) &&
5053: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5054: my $folderurl;
5055: my @pathitems = split(/\&/,$env{'form.folderpath'});
5056: my $folder = $pathitems[-2];
5057: if ($folder eq '') {
5058: undef($env{'form.folderpath'});
5059: } else {
5060: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5061: if ((split(/\:/,$pathitems[-1]))[4]) {
5062: $folderurl .= '.page';
5063: } else {
5064: $folderurl .= '.sequence';
5065: }
5066: unless (ref($navmap)) {
5067: $navmap = Apache::lonnavmaps::navmap->new();
5068: }
5069: if (ref($navmap)) {
5070: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5071: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5072: unless (@resources) {
5073: undef($env{'form.folderpath'});
5074: }
5075: }
5076: }
5077: }
5078: }
5079:
5080:
1.446 www 5081: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5082: unless ($env{'form.folderpath'}) {
1.446 www 5083: if ($supplementalflag) {
5084: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5085: } elsif ($allowed) {
5086: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5087: }
1.472 raeburn 5088: }
1.446 www 5089:
1.445 www 5090: # Store this
1.484 raeburn 5091: unless ($toolsflag) {
1.484.2.67 raeburn 5092: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5093: &Apache::loncommon::store_course_settings($stored_folderpath,
5094: {'folderpath' => 'scalar'});
5095: }
5096: my $folderpath;
1.484 raeburn 5097: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5098: $folderpath = $env{'form.folderpath'};
5099: my (@folders)=split('&',$env{'form.folderpath'});
5100: $env{'form.foldername'}=&unescape(pop(@folders));
5101: if ($env{'form.foldername'} =~ /\:1$/) {
5102: $container = 'page';
5103: } else {
5104: $container = 'sequence';
5105: }
5106: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5107: } else {
1.484.2.19 raeburn 5108: if ($env{'form.folder'} eq '' ||
5109: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5110: if ($env{'form.folder'} eq 'supplemental') {
5111: $folderpath=&supplemental_base();
5112: } elsif (!$hiddentop) {
5113: $folderpath='default&'.
5114: &escape(&mt('Main Content').':::::');
5115: }
1.484 raeburn 5116: }
5117: }
1.484.2.19 raeburn 5118: $containertag = '<input type="hidden" name="folderpath" value="" />';
5119: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5120: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5121: $showdoc='/'.$1;
5122: }
5123: if ($showdoc) { # got called in sequence from course
5124: $allowed=0;
5125: } else {
1.484.2.67 raeburn 5126: if ($canedit) {
1.484 raeburn 5127: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5128: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5129: }
5130: }
1.329 droeschl 5131: }
5132:
1.344 bisitz 5133: # get personal data
1.329 droeschl 5134: my $uname=$env{'user.name'};
5135: my $udom=$env{'user.domain'};
5136: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5137:
5138: if ($allowed) {
1.484 raeburn 5139: if ($toolsflag) {
5140: $script .= &inject_data_js();
5141: my ($home,$other,%outhash)=&authorhosts();
5142: if (!$home && $other) {
5143: my @hosts;
5144: foreach my $aurole (keys(%outhash)) {
5145: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5146: push(@hosts,$outhash{$aurole});
5147: }
5148: }
5149: $script .= &dump_switchserver_js(@hosts);
5150: }
1.458 raeburn 5151: } else {
1.484.2.43 raeburn 5152: my $tid = 1;
1.484 raeburn 5153: my @tabids;
5154: if ($supplementalflag) {
5155: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5156: $tid = 2;
1.484 raeburn 5157: } else {
5158: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5159: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5160: unshift(@tabids,'001');
5161: push(@tabids,('dd1','ee1'));
5162: }
1.458 raeburn 5163: }
1.484 raeburn 5164: my $tabidstr = join("','",@tabids);
1.484.2.68 raeburn 5165: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.67 raeburn 5166: $canedit,\$navmap).
1.484 raeburn 5167: &history_tab_js().
5168: &inject_data_js().
1.484.2.43 raeburn 5169: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5170: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5171: $addentries = {
1.484.2.3 raeburn 5172: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5173: };
1.458 raeburn 5174: }
1.484.2.30 raeburn 5175: $script .= &paste_popup_js();
1.484.2.12 raeburn 5176: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5177: &mt('Switch server?');
1.484.2.19 raeburn 5178:
5179:
1.329 droeschl 5180: }
5181: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5182: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5183: .'// <![CDATA['."\n"
5184: .$script."\n"
5185: .'// ]]>'."\n"
5186: .'</script>'."\n";
1.385 bisitz 5187:
5188: # Breadcrumbs
5189: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5190:
5191: if ($showdoc) {
5192: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5193: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5194: } elsif ($toolsflag) {
1.484.2.67 raeburn 5195: my ($breadtext,$breadtitle);
5196: $breadtext = "$crstype Editor";
5197: if ($canedit) {
5198: $breadtitle = 'Editing '.$crstype.' Contents';
5199: } else {
5200: $breadtext .= ' (View-only mode)';
5201: $breadtitle = 'Viewing '.$crstype.' Contents';
5202: }
1.484.2.44 raeburn 5203: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5204: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5205: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5206: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5207: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5208: $breadtitle)
1.484.2.44 raeburn 5209: );
1.484.2.19 raeburn 5210: } elsif ($r->uri eq '/adm/supplemental') {
5211: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5212: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5213: {'bread_crumbs' => $brcrum,}));
5214: } else {
1.484.2.67 raeburn 5215: my ($breadtext,$breadtitle,$helpitem);
5216: $breadtext = "$crstype Editor";
5217: if ($canedit) {
5218: $breadtitle = 'Editing '.$crstype.' Contents';
5219: $helpitem = 'Docs_Adding_Course_Doc';
5220: } else {
5221: $breadtext .= ' (View-only mode)';
5222: $breadtitle = 'Viewing '.$crstype.' Contents';
5223: $helpitem = 'Docs_Viewing_Course_Doc';
5224: }
1.392 raeburn 5225: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5226: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5227: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5228: {'add_entries' => $addentries}
5229: )
1.392 raeburn 5230: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5231: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5232: $breadtitle,
5233: $helpitem)
1.392 raeburn 5234: );
5235: }
1.364 bisitz 5236:
1.329 droeschl 5237: my %allfiles = ();
5238: my %codebase = ();
1.440 raeburn 5239: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5240: if ($canedit) {
1.329 droeschl 5241: if (($env{'form.uploaddoc.filename'}) &&
5242: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5243: my $context = $1;
5244: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5245: undef($hadchanges);
1.440 raeburn 5246: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5247: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5248: undef($navmap);
1.329 droeschl 5249: if ($hadchanges) {
5250: &mark_hash_old();
5251: }
1.440 raeburn 5252: $r->print($upload_output);
5253: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5254: # Process file upload - phase two - upload embedded objects
5255: $uploadphase = 'check_embedded';
5256: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5257: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5258: $env{'form.newidx'});
5259: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5260: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5261: my ($destination,$dir_root) = &embedded_destination();
5262: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5263: my $actionurl = '/adm/coursedocs';
5264: my ($result,$flag) =
5265: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5266: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5267: $actionurl);
5268: $r->print($result.&return_to_editor());
5269: } elsif ($env{'form.phase'} eq 'check_embedded') {
5270: # Process file upload - phase three - modify references in HTML file
5271: $uploadphase = 'modified_orightml';
5272: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5273: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5274: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5275: my $result =
5276: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5277: $docuname,$docudom,undef,
5278: $dir_root);
5279: $r->print($result.&return_to_editor());
1.476 raeburn 5280: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5281: $uploadphase = 'decompress_phase_one';
5282: $r->print(&decompression_phase_one().
5283: &return_to_editor());
5284: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5285: $uploadphase = 'decompress_phase_two';
5286: $r->print(&decompression_phase_two().
5287: &return_to_editor());
1.329 droeschl 5288: }
5289: }
5290:
1.484 raeburn 5291: if ($allowed && $toolsflag) {
5292: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5293: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5294: $r->print(&endContentScreen());
5295: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5296: # -----------------------------------------------------------------------------
5297: my %lt=&Apache::lonlocal::texthash(
5298: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5299: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5300: 'upld' => 'Upload Content',
1.329 droeschl 5301: 'srch' => 'Search',
5302: 'impo' => 'Import',
1.484.2.19 raeburn 5303: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5304: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5305: 'selm' => 'Select Map',
5306: 'load' => 'Load Map',
5307: 'newf' => 'New Folder',
5308: 'newp' => 'New Composite Page',
5309: 'syll' => 'Syllabus',
1.425 raeburn 5310: 'navc' => 'Table of Contents',
1.343 biermanm 5311: 'sipa' => 'Simple Course Page',
1.329 droeschl 5312: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5313: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5314: 'drbx' => 'Drop Box',
1.451 www 5315: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5316: 'bull' => 'Discussion Board',
1.347 weissno 5317: 'mypi' => 'My Personal Information Page',
1.353 weissno 5318: 'grpo' => 'Group Portfolio',
1.329 droeschl 5319: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5320: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5321: 'imsf' => 'IMS Upload',
5322: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5323: 'cms' => 'Origin of IMS package',
5324: 'se' => 'Select',
1.484.2.19 raeburn 5325: 'file' => 'File',
1.329 droeschl 5326: 'title' => 'Title',
5327: 'comment' => 'Comment',
1.403 raeburn 5328: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5329: 'bb5' => 'Blackboard 5',
5330: 'bb6' => 'Blackboard 6',
5331: 'angel5' => 'ANGEL 5.5',
5332: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5333: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5334: );
1.329 droeschl 5335: # -----------------------------------------------------------------------------
1.484.2.64 raeburn 5336: # Calculate free quota space for a user or course.
5337: my $quotatype = 'unofficial';
5338: if ($crstype eq 'Community') {
5339: $quotatype = 'community';
5340: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5341: $quotatype = 'official';
5342: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5343: $quotatype = 'textbook';
5344: }
5345: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5346: 'course',$quotatype); # expressed in MB
5347: my $current_disk_usage = 0;
5348: foreach my $subdir ('docs','supplemental') {
5349: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5350: "userfiles/$subdir",1); # expressed in kB
5351: }
5352: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5353: my $usage = $current_disk_usage/1024; # in MB
5354: my $quota = $disk_quota;
5355: my $percent;
5356: if ($disk_quota == 0) {
5357: $percent = 100.0;
5358: } else {
1.484.2.69 raeburn 5359: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5360: }
5361: $usage = sprintf("%.2f",$usage);
5362: $quota = sprintf("%.2f",$quota);
5363: $percent = sprintf("%.0f",$percent);
5364: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5365: $percent.'%',$quota.' MB').'</p>';
5366:
1.329 droeschl 5367: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5368: $quotainfo
1.329 droeschl 5369: $lt{'file'}:<br />
1.484.2.67 raeburn 5370: <input type="file" name="uploaddoc" size="40" $disabled />
1.329 droeschl 5371: FIUP
5372:
5373: my $checkbox=(<<CHBO);
5374: <!-- <label>$lt{'parse'}?
5375: <input type="checkbox" name="parserflag" />
5376: </label> -->
5377: <label>
1.484.2.67 raeburn 5378: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5379: </label>
5380: CHBO
1.484.2.12 raeburn 5381: my $imsfolder = $env{'form.folder'};
5382: if ($imsfolder eq '') {
1.484.2.19 raeburn 5383: $imsfolder = 'default';
1.484.2.12 raeburn 5384: }
5385: my $imspform=(<<IMSFORM);
5386: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5387: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5388: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5389: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5390: <legend>$lt{'imsf'}</legend>
5391: $fileupload
5392: <br />
5393: <p>
1.484.2.19 raeburn 5394: $lt{'cms'}:
1.484.2.67 raeburn 5395: <select name="source" $disabled>
1.484.2.12 raeburn 5396: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5397: <option value="bb5">$lt{'bb5'}</option>
5398: <option value="bb6">$lt{'bb6'}</option>
5399: <option value="angel5">$lt{'angel5'}</option>
5400: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5401: </select>
5402: <input type="hidden" name="folder" value="$imsfolder" />
5403: </p>
5404: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5405: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5406: </fieldset>
5407: </form>
5408: IMSFORM
5409:
1.484.2.19 raeburn 5410: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5411: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5412: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5413: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5414: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5415: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5416: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5417: $fileupload
5418: <br />
5419: $lt{'title'}:<br />
1.484.2.67 raeburn 5420: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5421: $pathitem
1.329 droeschl 5422: <input type="hidden" name="cmd" value="upload_default" />
5423: <br />
1.458 raeburn 5424: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5425: $checkbox
5426: </span>
1.484.2.12 raeburn 5427: <br clear="all" />
1.484.2.67 raeburn 5428: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5429: </fieldset>
5430: </form>
1.383 tempelho 5431: FUFORM
1.329 droeschl 5432:
1.484.2.67 raeburn 5433: my $mapimportjs;
5434: if ($canedit) {
5435: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5436: } else {
5437: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5438: }
1.484.2.19 raeburn 5439: my $importpubform=(<<SEDFFORM);
5440: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5441: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5442: <form action="/adm/coursedocs" method="post" name="mapimportform">
5443: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5444: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5445: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5446: $lt{'copm'}<br />
5447: <span class="LC_nobreak">
1.484.2.19 raeburn 5448: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5449: onfocus="this.blur();$mapimportjs" $disabled />
5450: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5451: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5452: </fieldset>
5453: </form>
5454:
1.383 tempelho 5455: SEDFFORM
1.484.2.67 raeburn 5456:
5457: my $fromstoredjs;
5458: if ($canedit) {
5459: $fromstoredjs = 'open_StoredLinks_Import()';
5460: } else {
5461: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5462: }
5463:
1.484.2.19 raeburn 5464: my @importpubforma = (
5465: { '<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 5466: { '<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 5467: { '<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 5468: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5469: );
5470: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5471: my $extresourcesform =
5472: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5473: $help{'Adding_External_Resource'},
5474: undef,undef,$disabled);
1.329 droeschl 5475: if ($allowed) {
1.484.2.7 raeburn 5476: my $folder = $env{'form.folder'};
5477: if ($folder eq '') {
5478: $folder='default';
5479: }
1.484.2.67 raeburn 5480: if ($canedit) {
5481: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5482: if ($output) {
5483: $r->print($output);
5484: }
1.484.2.30 raeburn 5485: }
1.337 ehlerst 5486: $r->print(<<HIDDENFORM);
5487: <form name="renameform" method="post" action="/adm/coursedocs">
5488: <input type="hidden" name="title" />
5489: <input type="hidden" name="cmd" />
5490: <input type="hidden" name="markcopy" />
5491: <input type="hidden" name="copyfolder" />
5492: $containertag
5493: </form>
1.484 raeburn 5494:
1.337 ehlerst 5495: HIDDENFORM
1.484.2.17 raeburn 5496: $r->print(&makesimpleeditform($pathitem)."\n".
5497: &makedocslogform($pathitem."\n".
1.484 raeburn 5498: '<input type="hidden" name="folder" value="'.
5499: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5500: }
1.442 www 5501:
5502: # Generate the tabs
1.484.2.19 raeburn 5503: my ($mode,$needs_end);
1.472 raeburn 5504: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5505: my @folders = split('&',$env{'form.folderpath'});
5506: unless (@folders > 2) {
5507: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5508: $needs_end = 1;
5509: }
1.472 raeburn 5510: } else {
1.484 raeburn 5511: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5512: $needs_end = 1;
1.472 raeburn 5513: }
1.443 www 5514:
1.442 www 5515: #
5516:
5517: my $savefolderpath;
5518:
1.395 raeburn 5519: if ($allowed) {
1.329 droeschl 5520: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5521: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5522: $folder='default';
1.356 tempelho 5523: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5524: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5525: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5526: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5527: }
5528: my $postexec='';
5529: if ($folder eq 'default') {
1.372 bisitz 5530: $r->print('<script type="text/javascript">'."\n"
5531: .'// <![CDATA['."\n"
5532: .'this.window.name="loncapaclient";'."\n"
5533: .'// ]]>'."\n"
5534: .'</script>'."\n"
1.369 bisitz 5535: );
1.329 droeschl 5536: } else {
5537: #$postexec='self.close();';
5538: }
1.484.2.15 raeburn 5539: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5540: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5541: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5542:
5543: my $newnavform=(<<NNFORM);
5544: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5545: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5546: $pathitem
1.329 droeschl 5547: <input type="hidden" name="importdetail"
5548: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5549: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5550: $help{'Navigate_Content'}
5551: </form>
5552: NNFORM
5553: my $newsmppageform=(<<NSPFORM);
5554: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5555: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5556: $pathitem
1.329 droeschl 5557: <input type="hidden" name="importdetail" value="" />
1.423 onken 5558: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5559: $help{'Simple Page'}
1.329 droeschl 5560: </form>
5561: NSPFORM
5562:
5563: my $newsmpproblemform=(<<NSPROBFORM);
5564: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5565: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5566: $pathitem
1.329 droeschl 5567: <input type="hidden" name="importdetail" value="" />
1.423 onken 5568: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5569: $help{'Simple_Problem'}
1.329 droeschl 5570: </form>
5571:
5572: NSPROBFORM
5573:
5574: my $newdropboxform=(<<NDBFORM);
5575: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5576: <input type="hidden" name="active" value="cc" />
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:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5580: $help{'Dropbox'}
1.344 bisitz 5581: </form>
1.329 droeschl 5582: NDBFORM
5583:
5584: my $newexuploadform=(<<NEXUFORM);
5585: <form action="/adm/coursedocs" method="post" name="newexamupload">
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:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5590: $help{'Score_Upload_Form'}
5591: </form>
5592: NEXUFORM
5593:
5594: my $newbulform=(<<NBFORM);
5595: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5596: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5597: $pathitem
1.329 droeschl 5598: <input type="hidden" name="importdetail" value="" />
1.423 onken 5599: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5600: $help{'Bulletin Board'}
5601: </form>
5602: NBFORM
5603:
5604: my $newaboutmeform=(<<NAMFORM);
5605: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5606: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5607: $pathitem
1.329 droeschl 5608: <input type="hidden" name="importdetail"
5609: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5610: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5611: $help{'My Personal Information Page'}
1.329 droeschl 5612: </form>
5613: NAMFORM
5614:
5615: my $newaboutsomeoneform=(<<NASOFORM);
5616: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
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:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5621: </form>
5622: NASOFORM
5623:
5624: my $newrosterform=(<<NROSTFORM);
5625: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5626: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5627: $pathitem
1.329 droeschl 5628: <input type="hidden" name="importdetail"
5629: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5630: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5631: $help{'Course_Roster'}
1.329 droeschl 5632: </form>
5633: NROSTFORM
5634:
1.484.2.27 raeburn 5635: my $newwebpage;
5636: if ($folder =~ /^default_?(\d*)$/) {
5637: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5638: if ($1) {
5639: $newwebpage .= $1;
5640: } else {
5641: $newwebpage .= 'default';
5642: }
5643: $newwebpage .= '/new.html';
5644: }
5645: my $newwebpageform =(<<NWEBFORM);
5646: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5647: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5648: $pathitem
5649: <input type="hidden" name="importdetail" value="$newwebpage" />
5650: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5651: $help{'Web_Page'}
1.484.2.27 raeburn 5652: </form>
5653: NWEBFORM
1.484.2.30 raeburn 5654:
1.484.2.27 raeburn 5655:
1.342 ehlerst 5656: my $specialdocumentsform;
1.383 tempelho 5657: my @specialdocumentsforma;
1.451 www 5658: my $gradingform;
5659: my @gradingforma;
5660: my $communityform;
5661: my @communityforma;
1.351 ehlerst 5662: my $newfolderform;
1.390 tempelho 5663: my $newfolderb;
1.342 ehlerst 5664:
1.451 www 5665: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5666:
1.329 droeschl 5667: my $newpageform=(<<NPFORM);
5668: <form action="/adm/coursedocs" method="post" name="newpage">
5669: <input type="hidden" name="folderpath" value="$path" />
5670: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5671: <input type="hidden" name="active" value="ee" />
1.423 onken 5672: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5673: $help{'Adding_Pages'}
1.329 droeschl 5674: </form>
5675: NPFORM
1.390 tempelho 5676:
5677:
1.351 ehlerst 5678: $newfolderform=(<<NFFORM);
1.329 droeschl 5679: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5680: $pathitem
1.329 droeschl 5681: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5682: <input type="hidden" name="active" value="" />
1.422 onken 5683: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5684: </form>
5685: NFFORM
5686:
5687: my $newsylform=(<<NSYLFORM);
5688: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5689: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5690: $pathitem
1.329 droeschl 5691: <input type="hidden" name="importdetail"
5692: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5693: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5694: $help{'Syllabus'}
1.383 tempelho 5695:
1.329 droeschl 5696: </form>
5697: NSYLFORM
1.364 bisitz 5698:
1.329 droeschl 5699: my $newgroupfileform=(<<NGFFORM);
5700: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5701: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5702: $pathitem
1.329 droeschl 5703: <input type="hidden" name="importdetail"
5704: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5705: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5706: $help{'Group Portfolio'}
1.329 droeschl 5707: </form>
5708: NGFFORM
1.383 tempelho 5709: @specialdocumentsforma=(
1.421 onken 5710: {'<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 5711: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5712: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5713: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5714: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5715: );
5716: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5717:
1.434 raeburn 5718:
5719: my @importdoc = (
1.484.2.19 raeburn 5720: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5721: );
5722: unless ($container eq 'page') {
5723: push(@importdoc,
5724: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5725: );
5726: }
5727: push(@importdoc,
1.484.2.38 raeburn 5728: {'<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 5729: );
1.484.2.12 raeburn 5730: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5731:
1.451 www 5732: @gradingforma=(
5733: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5734: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5735: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5736:
5737: );
5738: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5739:
5740: @communityforma=(
5741: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5742: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5743: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5744: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5745: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5746: );
5747: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5748:
1.330 tempelho 5749: my %orderhash = (
1.484.2.36 raeburn 5750: 'aa' => ['Upload',$fileuploadform],
5751: 'bb' => ['Import',$importpubform],
5752: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5753: );
1.484.2.19 raeburn 5754: unless ($container eq 'page') {
1.434 raeburn 5755: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5756: $orderhash{'dd'} = ['Collaboration',$communityform];
1.484.2.36 raeburn 5757: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5758: }
5759:
1.341 ehlerst 5760: $hadchanges=0;
1.484 raeburn 5761: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5762: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5763: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.68 raeburn 5764: $canedit,\$navmap,$hiddentop);
1.484.2.67 raeburn 5765: undef($navmap);
1.443 www 5766: if ($error) {
5767: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5768: }
5769: if ($hadchanges) {
1.484.2.73 raeburn 5770: unless (&is_hash_old()) {
5771: &mark_hash_old();
5772: }
1.443 www 5773: }
1.341 ehlerst 5774:
1.443 www 5775: &changewarning($r,'');
5776: }
1.458 raeburn 5777: }
1.442 www 5778:
1.443 www 5779: # Supplemental documents start here
5780:
1.329 droeschl 5781: my $folder=$env{'form.folder'};
1.443 www 5782: unless ($supplementalflag) {
1.329 droeschl 5783: $folder='supplemental';
5784: }
5785: if ($folder =~ /^supplemental$/ &&
5786: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5787: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5788: } elsif ($allowed) {
1.356 tempelho 5789: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5790: }
1.484.2.17 raeburn 5791: $pathitem = '<input type="hidden" name="folderpath" value="'.
5792: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5793: if ($allowed) {
5794: my $folderseq=
1.484.2.15 raeburn 5795: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5796:
5797: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 5798: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5799: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5800: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 5801: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 5802: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5803: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5804: $fileupload
5805: <br />
5806: <br />
5807: <span class="LC_nobreak">
5808: $checkbox
5809: </span>
5810: <br /><br />
5811: $lt{'comment'}:<br />
1.383 tempelho 5812: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5813: <br />
1.484.2.19 raeburn 5814: $pathitem
1.329 droeschl 5815: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 5816: <input type='submit' value="$lt{'upld'}" />
5817: </form>
1.484.2.19 raeburn 5818: SUPDOCFORM
1.329 droeschl 5819:
5820: my $supnewfolderform=(<<SNFFORM);
5821: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 5822: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 5823: $pathitem
1.329 droeschl 5824: <input type="hidden" name="importdetail" value="" />
1.423 onken 5825: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 5826: $help{'Adding_Folders'}
1.329 droeschl 5827: </form>
5828: SNFFORM
1.383 tempelho 5829:
1.484.2.19 raeburn 5830: my $supextform =
5831: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5832: $help{'Adding_External_Resource'},
5833: undef,undef,$disabled);
1.329 droeschl 5834:
5835: my $supnewsylform=(<<SNSFORM);
5836: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 5837: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5838: $pathitem
1.329 droeschl 5839: <input type="hidden" name="importdetail"
5840: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5841: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 5842: $help{'Syllabus'}
5843: </form>
5844: SNSFORM
5845:
5846: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 5847: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 5848: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5849: $pathitem
1.329 droeschl 5850: <input type="hidden" name="importdetail"
5851: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5852: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 5853: $help{'My Personal Information Page'}
1.329 droeschl 5854: </form>
5855: SNAMFORM
5856:
1.484.2.27 raeburn 5857: my $supwebpage;
5858: if ($folder =~ /^supplemental_?(\d*)$/) {
5859: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5860: if ($1) {
5861: $supwebpage .= $1;
5862: } else {
5863: $supwebpage .= 'default';
5864: }
5865: $supwebpage .= '/new.html';
5866: }
5867: my $supwebpageform =(<<SWEBFORM);
5868: <form action="/adm/coursedocs" method="post" name="supwebpage">
5869: <input type="hidden" name="active" value="cc" />
5870: $pathitem
5871: <input type="hidden" name="importdetail" value="$supwebpage" />
5872: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 5873: $help{'Web_Page'}
1.484.2.27 raeburn 5874: </form>
5875: SWEBFORM
5876:
1.333 muellerd 5877:
1.383 tempelho 5878: my @specialdocs = (
1.484.2.67 raeburn 5879: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 5880: =>$supnewsylform},
1.484.2.67 raeburn 5881: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 5882: =>$supnewaboutmeform},
1.484.2.27 raeburn 5883: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
5884:
1.383 tempelho 5885: );
1.417 droeschl 5886: my @supimportdoc = (
1.484.2.19 raeburn 5887: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 5888: =>$supextform},
5889: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
5890: =>$supupdocform},
1.484.2.19 raeburn 5891: );
5892:
1.484.2.12 raeburn 5893: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 5894: my %suporderhash = (
1.390 tempelho 5895: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 5896: 'ee' => ['Upload',$supupdocform],
5897: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 5898: );
1.443 www 5899: if ($supplementalflag) {
1.458 raeburn 5900: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5901: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
5902: $canedit);
1.443 www 5903: if ($error) {
5904: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 5905: } else {
5906: if ($suppchanges) {
5907: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
5908: my @ids=&Apache::lonnet::current_machine_ids();
5909: foreach my $server (keys(%servers)) {
5910: next if (grep(/^\Q$server\E$/,@ids));
5911: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 5912: my $cachekey = &escape('suppcount').':'.&escape($hashid);
5913: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 5914: }
5915: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
5916: undef($suppchanges);
5917: }
1.443 www 5918: }
1.393 raeburn 5919: }
1.443 www 5920: } elsif ($supplementalflag) {
1.458 raeburn 5921: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 5922: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 5923: if ($error) {
5924: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 5925: }
1.393 raeburn 5926: }
1.389 tempelho 5927:
1.484.2.19 raeburn 5928: if ($needs_end) {
5929: $r->print(&endContentScreen());
5930: }
1.383 tempelho 5931:
1.329 droeschl 5932: if ($allowed) {
5933: $r->print('
5934: <form method="post" name="extimport" action="/adm/coursedocs">
5935: <input type="hidden" name="title" />
5936: <input type="hidden" name="url" />
5937: <input type="hidden" name="useform" />
5938: <input type="hidden" name="residx" />
5939: </form>');
5940: }
1.484 raeburn 5941: } elsif ($showdoc) {
1.329 droeschl 5942: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 5943: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 5944: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 5945: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 5946: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 5947: }
5948: }
5949: $r->print(&Apache::loncommon::end_page());
5950: return OK;
1.364 bisitz 5951: }
1.329 droeschl 5952:
1.440 raeburn 5953: sub embedded_form_elems {
5954: my ($phase,$primaryurl,$newidx) = @_;
5955: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78! raeburn 5956: $newidx =~s /\D+//g;
1.440 raeburn 5957: return <<STATE;
5958: <input type="hidden" name="folderpath" value="$folderpath" />
5959: <input type="hidden" name="cmd" value="upload_embedded" />
5960: <input type="hidden" name="newidx" value="$newidx" />
5961: <input type="hidden" name="phase" value="$phase" />
5962: <input type="hidden" name="primaryurl" value="$primaryurl" />
5963: STATE
5964: }
5965:
5966: sub embedded_destination {
5967: my $folder=$env{'form.folder'};
5968: my $destination = 'docs/';
5969: if ($folder =~ /^supplemental/) {
5970: $destination = 'supplemental/';
5971: }
5972: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5973: $destination .= 'default/';
5974: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5975: $destination .= $2.'/';
5976: }
1.484.2.78! raeburn 5977: my $newidx = $env{'form.newidx'};
! 5978: $newidx =~s /\D+//g;
! 5979: if ($newidx) {
! 5980: $destination .= $newidx;
! 5981: }
1.440 raeburn 5982: my $dir_root = '/userfiles';
5983: return ($destination,$dir_root);
5984: }
5985:
5986: sub return_to_editor {
5987: my $actionurl = '/adm/coursedocs';
5988: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
5989: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
5990: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
5991: '</a></p>';
5992: }
5993:
1.476 raeburn 5994: sub decompression_info {
5995: my ($destination,$dir_root) = &embedded_destination();
5996: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5997: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5998: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5999: my $container='sequence';
1.480 raeburn 6000: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6001: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6002: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6003: $container='page';
6004: }
1.480 raeburn 6005: unshift(@hiddens,$pathitem);
6006: foreach my $item (@hiddens) {
1.484.2.78! raeburn 6007: if ($item eq 'newidx') {
! 6008: next if ($env{'form.'.$item} =~ /\D/);
! 6009: }
1.480 raeburn 6010: if ($env{'form.'.$item}) {
6011: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6012: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6013: }
1.477 raeburn 6014: }
1.476 raeburn 6015: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6016: $hiddenelem);
6017: }
6018:
6019: sub decompression_phase_one {
6020: my ($dir,$file,$warning,$error,$output);
6021: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6022: &decompression_info();
1.484.2.7 raeburn 6023: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6024: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6025: } else {
6026: my $file = $1;
1.481 raeburn 6027: $output =
6028: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6029: $destination,$dir_root,
6030: $hiddenelem);
6031: if ($env{'form.autoextract_camtasia'}) {
6032: $output .= &remove_archive($docudom,$docuname,$container);
6033: }
1.476 raeburn 6034: }
6035: if ($error) {
6036: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6037: $error.'</p>'."\n";
6038: }
6039: if ($warning) {
6040: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6041: }
6042: return $output;
6043: }
6044:
6045: sub decompression_phase_two {
6046: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6047: &decompression_info();
1.481 raeburn 6048: my $output;
1.480 raeburn 6049: if ($env{'form.archivedelete'}) {
1.481 raeburn 6050: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6051: }
6052: $output .=
1.481 raeburn 6053: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6054: $destination,$dir_root,$hiddenelem);
6055: return $output;
6056: }
6057:
1.480 raeburn 6058: sub remove_archive {
6059: my ($docudom,$docuname,$container) = @_;
6060: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6061: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6062: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6063: if ($fatal) {
6064: if ($container eq 'page') {
6065: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6066: } else {
6067: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6068: }
1.484.2.54 raeburn 6069: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6070: } else {
6071: my $currcmd = $env{'form.cmd'};
6072: my $position = $env{'form.position'};
1.484.2.54 raeburn 6073: my $archiveidx = $position;
6074: if ($position > 0) {
6075: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6076: $archiveidx = $position-1;
6077: }
6078: $env{'form.cmd'} = 'remove_'.$archiveidx;
6079: my ($title,$url,@rrest) =
6080: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6081: if ($url eq $env{'form.archiveurl'}) {
6082: if (&handle_edit_cmd($docuname,$docudom)) {
6083: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6084: if ($fatal) {
6085: if ($container eq 'page') {
6086: $delwarning = &mt('An error occurred updating the contents of the current page.');
6087: } else {
6088: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6089: }
1.480 raeburn 6090: } else {
1.484.2.54 raeburn 6091: $delresult = &mt('Archive file removed.');
1.480 raeburn 6092: }
6093: }
1.484.2.54 raeburn 6094: } else {
6095: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6096: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6097: }
6098: }
6099: $env{'form.cmd'} = $currcmd;
6100: }
6101: if ($delwarning) {
6102: $output = '<p class="LC_warning">'.
6103: $delwarning.
6104: '</p>';
6105: }
6106: if ($delresult) {
6107: $output .= '<p class="LC_info">'.
6108: $delresult.
6109: '</p>';
6110: }
1.481 raeburn 6111: return $output;
1.480 raeburn 6112: }
6113:
1.484 raeburn 6114: sub generate_admin_menu {
1.484.2.67 raeburn 6115: my ($crstype,$canedit) = @_;
1.484 raeburn 6116: my $lc_crstype = lc($crstype);
6117: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6118: my %lt= ( # do not translate here
1.484 raeburn 6119: 'vc' => 'Verify Content',
6120: 'cv' => 'Check/Set Resource Versions',
6121: 'ls' => 'List Resource Identifiers',
6122: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6123: 'dcd' => "Copy $crstype Content to Authoring Space",
6124: );
1.484 raeburn 6125: my ($candump,$dumpurl);
6126: if ($home + $other > 0) {
6127: $candump = 'F';
6128: if ($home) {
6129: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6130: } else {
6131: my @hosts;
6132: foreach my $aurole (keys(%outhash)) {
6133: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6134: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6135: }
1.484 raeburn 6136: }
6137: if (@hosts == 1) {
6138: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6139: '&role='.
6140: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6141: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6142: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6143: } else {
6144: $dumpurl = "javascript:choose_switchserver_window()";
6145: }
6146: }
6147: }
6148: my @menu=
6149: ({ categorytitle=>'Administration',
6150: items =>[
6151: { linktext => $lt{'vc'},
6152: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6153: permission => 'F',
1.484.2.44 raeburn 6154: help => 'Docs_Verify_Content',
1.484 raeburn 6155: icon => 'verify.png',
6156: linktitle => 'Verify contents can be retrieved/rendered',
6157: },
6158: { linktext => $lt{'cv'},
6159: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6160: permission => 'F',
1.484.2.44 raeburn 6161: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6162: icon => 'resversion.png',
6163: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6164: },
6165: { linktext => $lt{'ls'},
6166: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6167: permission => 'F',
6168: #help => '',
6169: icon => 'symbs.png',
6170: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6171: },
6172: ]
1.484.2.67 raeburn 6173: });
6174: if ($canedit) {
6175: push(@menu,
1.484 raeburn 6176: { categorytitle=>'Export',
6177: items =>[
6178: { linktext => $lt{'imse'},
6179: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6180: permission => 'F',
6181: help => 'Docs_Export_Course_Docs',
6182: icon => 'imsexport.png',
6183: linktitle => $lt{'imse'},
6184: },
6185: { linktext => $lt{'dcd'},
6186: url => $dumpurl,
6187: permission => $candump,
1.484.2.44 raeburn 6188: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6189: icon => 'dump.png',
6190: linktitle => $lt{'dcd'},
6191: },
6192: ]
6193: });
1.484.2.67 raeburn 6194: }
1.484 raeburn 6195: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6196: '<input type="hidden" id="dummy" />'."\n".
6197: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6198: '</form>';
1.329 droeschl 6199: }
6200:
6201: sub generate_edit_table {
1.484.2.30 raeburn 6202: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6203: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6204: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6205: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6206: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6207: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6208: $activetab = $env{'form.active'};
6209: }
1.484.2.67 raeburn 6210: unless ($canedit) {
6211: $disabled = ' disabled="disabled"';
6212: }
1.472 raeburn 6213: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6214: my $backtext = &mt('Exit Editor');
1.458 raeburn 6215: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6216: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6217: '<li class="goback">'.
1.484.2.32 raeburn 6218: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6219: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6220: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6221: '<li>'.
6222: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6223: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6224: if ($env{'form.docslog'}) {
6225: $form .= '<li class="active">';
6226: } else {
6227: $form .= '<li>';
6228: }
6229: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6230: &mt('History').'</a></li>'."\n";
6231: if ($env{'form.docslog'}) {
6232: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6233: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6234: }
1.458 raeburn 6235: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6236: if($name ne '00'){
1.371 tempelho 6237: if($activetab eq '' || $activetab ne $name){
6238: $active = '';
6239: }elsif($activetab eq $name){
6240: $active = 'class="active"';
6241: }
1.458 raeburn 6242: $form .= '<li style="float:right" '.$active
1.484 raeburn 6243: .' 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 6244: } else {
1.484.2.43 raeburn 6245: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6246:
6247: }
1.329 droeschl 6248: }
1.484 raeburn 6249: $form .= '</ul>'."\n";
6250: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6251:
6252: if ($to_show ne '') {
1.484.2.30 raeburn 6253: my $saveform;
6254: if ($need_save) {
6255: my $button = &mt('Make changes');
6256: my $path;
6257: if ($env{'form.folderpath'}) {
6258: $path =
6259: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6260: }
6261: $saveform = <<"END";
6262: <div id="multisave" style="display:none; clear:both;" >
6263: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6264: <input type="hidden" name="folderpath" value="$path" />
6265: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6266: <input type="hidden" name="allhiddenresource" value="" />
6267: <input type="hidden" name="allencrypturl" value="" />
6268: <input type="hidden" name="allrandompick" value="" />
6269: <input type="hidden" name="allrandomorder" value="" />
6270: <input type="hidden" name="changeparms" value="" />
6271: <input type="hidden" name="multiremove" value="" />
6272: <input type="hidden" name="multicut" value="" />
6273: <input type="hidden" name="multicopy" value="" />
6274: <input type="hidden" name="multichange" value="" />
6275: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6276: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6277: </form>
6278: </div>
6279: END
6280: }
6281: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6282: }
1.363 ehlerst 6283: foreach my $field (keys(%orderhash)){
1.390 tempelho 6284: if($field ne '00'){
1.422 onken 6285: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6286: $active = 'style="display: none;float:left"';
1.422 onken 6287: }elsif($activetab eq $field){
1.458 raeburn 6288: $active = 'style="display:block;float:left"';
1.422 onken 6289: }
6290: $form .= '<div id="'.$field.$tid.'"'
6291: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6292: .'</div>'."\n";
1.363 ehlerst 6293: }
6294: }
1.484 raeburn 6295: unless ($env{'form.docslog'}) {
6296: $form .= '</div></div>'."\n";
6297: }
1.329 droeschl 6298: return $form;
6299: }
6300:
6301: sub editing_js {
1.484.2.67 raeburn 6302: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$canedit,$navmapref) = @_;
1.484.2.61 raeburn 6303: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6304: p_mnf => 'Name of New Folder',
6305: t_mnf => 'New Folder',
6306: p_mnp => 'Name of New Page',
6307: t_mnp => 'New Page',
1.451 www 6308: p_mxu => 'Title for the External Score',
1.349 biermanm 6309: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6310: p_msb => 'Title for the Problem',
6311: p_mdb => 'Title for the Drop Box',
1.336 schafran 6312: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6313: p_mwp => 'Title for Web Page',
1.348 weissno 6314: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6315: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6316: p_mab_alrt1 => 'Not a valid user:domain',
6317: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6318: p_chn => 'New Title',
6319: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6320: p_rmr2a => 'Remove',
6321: p_rmr2b => '?',
6322: p_rmr3a => 'Remove those',
6323: p_rmr3b => 'items?',
6324: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6325: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6326: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6327: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6328: p_ctr2a => 'Cut',
6329: p_ctr2b => '?',
6330: p_ctr3a => 'Cut those',
6331: p_ctr3b => 'items?',
1.478 raeburn 6332: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6333: imsfile => 'You must choose an IMS package for import',
6334: imscms => 'You must select which Course Management System was the source of the IMS package',
6335: invurl => 'Invalid URL',
6336: titbl => 'Title is blank',
1.484.2.30 raeburn 6337: more => '(More ...)',
6338: less => '(Less ...)',
6339: noor => 'No actions selected or changes to settings specified.',
6340: noch => 'No changes to settings specified.',
6341: noac => 'No actions selected.',
1.484.2.67 raeburn 6342: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6343: );
6344:
1.484.2.61 raeburn 6345: &js_escape(\%js_lt);
1.433 raeburn 6346: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6347: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6348: my $main_container_page;
1.484.2.19 raeburn 6349: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6350: $main_container_page = 1;
1.434 raeburn 6351: }
1.484.2.67 raeburn 6352: my $backtourl;
6353: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6354: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6355:
1.484.2.21 raeburn 6356: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6357: my $caller = $1;
6358: if ($caller =~ /^supplemental/) {
6359: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6360: } else {
6361: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6362: $res = &Apache::lonnet::clutter($res);
6363: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6364: my ($url,$anchor);
6365: if ($res =~ /^([^#]+)#([^#]+)$/) {
6366: $url = $1;
6367: $anchor = $2;
6368: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6369: $caller = $1.&escape('#').$anchor;
6370: }
1.484.2.67 raeburn 6371: } else {
6372: $url = $res;
1.484.2.66 raeburn 6373: }
6374: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.484.2.21 raeburn 6375: &HTML::Entities::encode($caller,'<>&"');
1.484.2.66 raeburn 6376: if ($anchor ne '') {
6377: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6378: }
1.484.2.57 raeburn 6379: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6380: } else {
6381: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6382: }
6383: }
6384: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6385: $backtourl = '/adm/menu';
6386: } elsif ($supplementalflag) {
1.472 raeburn 6387: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6388: } else {
6389: $backtourl = '/adm/navmaps';
1.472 raeburn 6390: }
6391:
1.484.2.19 raeburn 6392: my $fieldsets = "'ext','doc'";
6393: unless ($main_container_page) {
6394: $fieldsets .=",'ims'";
6395: }
1.484.2.12 raeburn 6396: if ($supplementalflag) {
6397: $fieldsets = "'suppext','suppdoc'";
6398: }
6399:
1.484.2.67 raeburn 6400: my $jsmakefunctions;
6401: if ($canedit) {
6402: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6403: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6404: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6405: if (foldername) {
6406: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6407: targetform.submit();
6408: }
6409: }
6410:
6411: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6412: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6413: if (pagename) {
6414: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6415: targetform.submit();
6416: }
6417: }
6418:
6419: function makeexamupload() {
1.484.2.61 raeburn 6420: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6421: if (title) {
1.329 droeschl 6422: this.document.forms.newexamupload.importdetail.value=
6423: escape(title)+'=/res/lib/templates/examupload.problem';
6424: this.document.forms.newexamupload.submit();
6425: }
6426: }
6427:
6428: function makesmppage() {
1.484.2.61 raeburn 6429: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6430: if (title) {
1.329 droeschl 6431: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6432: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6433: this.document.forms.newsmppg.submit();
6434: }
6435: }
6436:
1.484.2.27 raeburn 6437: function makewebpage(type) {
1.484.2.61 raeburn 6438: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6439: var formname;
6440: if (type == 'supp') {
6441: formname = this.document.forms.supwebpage;
6442: } else {
6443: formname = this.document.forms.newwebpage;
6444: }
6445: if (title) {
6446: var webpage = formname.importdetail.value;
6447: formname.importdetail.value = escape(title)+'='+webpage;
6448: formname.submit();
6449: }
6450: }
6451:
1.329 droeschl 6452: function makesmpproblem() {
1.484.2.61 raeburn 6453: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6454: if (title) {
1.329 droeschl 6455: this.document.forms.newsmpproblem.importdetail.value=
6456: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6457: this.document.forms.newsmpproblem.submit();
6458: }
6459: }
6460:
6461: function makedropbox() {
1.484.2.61 raeburn 6462: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6463: if (title) {
1.329 droeschl 6464: this.document.forms.newdropbox.importdetail.value=
6465: escape(title)+'=/res/lib/templates/DropBox.problem';
6466: this.document.forms.newdropbox.submit();
6467: }
6468: }
6469:
6470: function makebulboard() {
1.484.2.61 raeburn 6471: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6472: if (title) {
6473: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6474: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6475: this.document.forms.newbul.submit();
6476: }
6477: }
6478:
6479: function makeabout() {
1.484.2.61 raeburn 6480: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6481: if (user) {
6482: var comp=new Array();
6483: comp=user.split(':');
6484: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6485: if ((comp[0]) && (comp[1])) {
6486: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6487: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6488: this.document.forms.newaboutsomeone.submit();
6489: } else {
6490: alert("$js_lt{'p_mab_alrt1'}");
6491: }
6492: } else {
6493: alert("$js_lt{'p_mab_alrt2'}");
6494: }
6495: }
1.335 ehlerst 6496: }
1.484.2.67 raeburn 6497:
6498: function makenew(targetform) {
6499: targetform.submit();
1.335 ehlerst 6500: }
1.484.2.67 raeburn 6501:
6502: function changename(folderpath,index,oldtitle) {
6503: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6504: if (title) {
6505: this.document.forms.renameform.markcopy.value='';
6506: this.document.forms.renameform.title.value=title;
6507: this.document.forms.renameform.cmd.value='rename_'+index;
6508: this.document.forms.renameform.folderpath.value=folderpath;
6509: this.document.forms.renameform.submit();
6510: }
1.329 droeschl 6511: }
6512:
1.484.2.67 raeburn 6513: ENDNEWSCRIPT
6514: } else {
6515: $jsmakefunctions = <<ENDNEWSCRIPT;
6516:
6517: function makenewfolder() {
6518: alert("$js_lt{'edri'}");
6519: }
6520:
6521: function makenewpage() {
6522: alert("$js_lt{'edri'}");
6523: }
6524:
6525: function makeexamupload() {
6526: alert("$js_lt{'edri'}");
6527: }
6528:
6529: function makesmppage() {
6530: alert("$js_lt{'edri'}");
6531: }
6532:
6533: function makewebpage(type) {
6534: alert("$js_lt{'edri'}");
6535: }
6536:
6537: function makesmpproblem() {
6538: alert("$js_lt{'edri'}");
6539: }
6540:
6541: function makedropbox() {
6542: alert("$js_lt{'edri'}");
6543: }
6544:
6545: function makebulboard() {
6546: alert("$js_lt{'edri'}");
6547: }
6548:
6549: function makeabout() {
6550: alert("$js_lt{'edri'}");
6551: }
6552:
6553: function changename() {
6554: alert("$js_lt{'edri'}");
6555: }
6556:
6557: function makenew() {
6558: alert("$js_lt{'edri'}");
6559: }
6560:
6561: function groupimport() {
6562: alert("$js_lt{'edri'}");
6563: }
6564:
6565: function groupsearch() {
6566: alert("$js_lt{'edri'}");
6567: }
6568:
6569: function groupopen(url,recover) {
6570: var options="scrollbars=1,resizable=1,menubar=0";
6571: idxflag=1;
6572: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6573: idx.focus();
6574: }
6575:
6576: ENDNEWSCRIPT
6577:
6578: }
6579: return <<ENDSCRIPT;
6580:
6581: $jsmakefunctions
6582:
1.484.2.13 raeburn 6583: function toggleUpload(caller) {
6584: var blocks = Array($fieldsets);
6585: for (var i=0; i<blocks.length; i++) {
6586: var disp = 'none';
6587: if (caller == blocks[i]) {
6588: var curr = document.getElementById('upload'+caller+'form').style.display;
6589: if (curr == 'none') {
6590: disp='block';
6591: }
6592: }
6593: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6594: }
6595: resize_scrollbox('contentscroll','1','1');
6596: return;
6597: }
6598:
1.484.2.19 raeburn 6599: function toggleMap(caller) {
1.484.2.13 raeburn 6600: var disp = 'none';
1.484.2.19 raeburn 6601: if (document.getElementById('importmapform')) {
6602: if (caller == 'map') {
6603: var curr = document.getElementById('importmapform').style.display;
6604: if (curr == 'none') {
6605: disp='block';
6606: }
1.484.2.12 raeburn 6607: }
1.484.2.19 raeburn 6608: document.getElementById('importmapform').style.display=disp;
6609: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6610: }
1.484.2.19 raeburn 6611: return;
1.329 droeschl 6612: }
6613:
1.484.2.12 raeburn 6614: function makeims(imsform) {
6615: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6616: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6617: return;
6618: }
6619: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6620: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6621: return;
6622: }
6623: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6624: imsform.submit();
6625: }
6626:
1.478 raeburn 6627: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6628: var pickitem;
6629: var picknumitem;
6630: var picknumtext;
6631: if (index == 'all') {
6632: pickitem = document.getElementById('randompickall');
6633: picknumitem = document.getElementById('rpicknumall');
6634: picknumtext = document.getElementById('rpicktextall');
6635: } else {
6636: pickitem = document.getElementById('randompick_'+index);
6637: picknumitem = document.getElementById('rpicknum_'+index);
6638: picknumtext = document.getElementById('randompicknum_'+index);
6639: }
1.478 raeburn 6640: if (pickitem.checked) {
1.484.2.61 raeburn 6641: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6642: if (picknum == '' || picknum == null) {
6643: if (caller == 'check') {
6644: pickitem.checked=false;
1.484.2.29 raeburn 6645: if (index == 'all') {
6646: picknumtext.innerHTML = '';
6647: if (caller == 'link') {
6648: propagateState(targetform,'rpicknum');
6649: }
6650: } else {
1.484.2.30 raeburn 6651: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6652: }
1.478 raeburn 6653: }
6654: } else {
6655: picknum.toString();
6656: var regexdigit=/^\\d+\$/;
6657: if (regexdigit.test(picknum)) {
6658: picknumitem.value = picknum;
1.484.2.29 raeburn 6659: if (index == 'all') {
1.484.2.30 raeburn 6660: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6661: if (caller == 'link') {
6662: propagateState(targetform,'rpicknum');
6663: }
6664: } else {
6665: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6666: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6667: }
1.478 raeburn 6668: } else {
6669: if (caller == 'check') {
1.484.2.29 raeburn 6670: if (index == 'all') {
6671: picknumtext.innerHTML = '';
6672: if (caller == 'link') {
6673: propagateState(targetform,'rpicknum');
6674: }
6675: } else {
6676: pickitem.checked=false;
1.484.2.30 raeburn 6677: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6678: }
1.478 raeburn 6679: }
6680: return;
6681: }
6682: }
6683: } else {
1.484.2.29 raeburn 6684: picknumitem.value = '';
6685: picknumtext.innerHTML = '';
6686: if (index == 'all') {
6687: if (caller == 'link') {
6688: propagateState(targetform,'rpicknum');
6689: }
6690: } else {
1.484.2.30 raeburn 6691: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6692: }
6693: }
6694: }
6695:
6696: function propagateState(form,param) {
6697: if (document.getElementById(param+'all')) {
6698: var setcheck = 0;
6699: var rpick = 0;
6700: if (param == 'rpicknum') {
6701: if (document.getElementById('randompickall')) {
6702: if (document.getElementById('randompickall').checked) {
6703: if (document.getElementById('rpicknumall')) {
6704: rpick = document.getElementById('rpicknumall').value;
6705: }
6706: }
6707: }
6708: } else {
6709: if (document.getElementById(param+'all').checked) {
6710: setcheck = 1;
6711: }
6712: }
1.484.2.30 raeburn 6713: var allidxlist;
6714: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6715: if (document.getElementById('all'+param+'idx')) {
6716: allidxlist = document.getElementById('all'+param+'idx').value;
6717: }
6718: var actions = new Array ('remove','cut','copy');
6719: for (var i=0; i<actions.length; i++) {
6720: if (actions[i] != param) {
6721: if (document.getElementById(actions[i]+'all')) {
6722: document.getElementById(actions[i]+'all').checked = false;
6723: }
6724: }
6725: }
6726: }
1.484.2.29 raeburn 6727: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6728: allidxlist = form.allidx.value;
6729: }
6730: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6731: allidxlist = form.allmapidx.value;
6732: }
6733: if ((allidxlist != '') && (allidxlist != null)) {
6734: var allidxs = allidxlist.split(',');
6735: if (allidxs.length > 1) {
6736: for (var i=0; i<allidxs.length; i++) {
6737: if (document.getElementById(param+'_'+allidxs[i])) {
6738: if (param == 'rpicknum') {
6739: if (document.getElementById('randompick_'+allidxs[i])) {
6740: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6741: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6742: if (rpick > 0) {
6743: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6744: } else {
6745: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6746: }
6747: }
6748: }
6749: } else {
1.484.2.29 raeburn 6750: if (setcheck == 1) {
6751: document.getElementById(param+'_'+allidxs[i]).checked = true;
6752: } else {
6753: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6754: if (param == 'randompick') {
6755: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6756: }
1.484.2.29 raeburn 6757: }
6758: }
6759: }
6760: }
1.484.2.30 raeburn 6761: if (setcheck == 1) {
6762: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6763: var actions = new Array('copy','cut','remove');
6764: for (var i=0; i<actions.length; i++) {
6765: var otheractions;
6766: var otheridxs;
6767: if (actions[i] === param) {
6768: continue;
6769: } else {
6770: if (document.getElementById('all'+actions[i]+'idx')) {
6771: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6772: otheridxs = otheractions.split(',');
6773: if (otheridxs.length > 1) {
6774: for (var j=0; j<otheridxs.length; j++) {
6775: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6776: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6777: }
1.484.2.29 raeburn 6778: }
6779: }
6780: }
6781: }
1.484.2.30 raeburn 6782: }
1.484.2.29 raeburn 6783: }
6784: }
6785: }
6786: }
1.478 raeburn 6787: }
1.484.2.29 raeburn 6788: return;
6789: }
6790:
1.484.2.63 raeburn 6791: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 6792: var canedit = '$canedit';
6793: if (canedit == '') {
6794: alert("$js_lt{'edri'}");
6795: return;
6796: }
1.484.2.30 raeburn 6797: var dosettings;
6798: var doaction;
6799: var control = document.togglemultsettings;
6800: if (context == 'actions') {
6801: control = document.togglemultactions;
6802: doaction = 1;
6803: } else {
6804: dosettings = 1;
6805: }
6806: if (control) {
6807: if (control.showmultpick.length) {
6808: for (var i=0; i<control.showmultpick.length; i++) {
6809: if (control.showmultpick[i].checked) {
6810: if (control.showmultpick[i].value == 1) {
6811: if (context == 'settings') {
6812: dosettings = 0;
6813: } else {
6814: doaction = 0;
6815: }
6816: }
6817: }
6818: }
6819: }
6820: }
6821: if (context == 'settings') {
6822: if (dosettings == 1) {
6823: targetform.changeparms.value=param;
6824: targetform.submit();
6825: }
6826: }
6827: if (context == 'actions') {
6828: if (doaction == 1) {
6829: targetform.cmd.value=param+'_'+index;
6830: targetform.folderpath.value=folderpath;
6831: targetform.markcopy.value=idx+':'+param;
6832: targetform.copyfolder.value=folder+'.'+container;
6833: if (param == 'remove') {
1.484.2.63 raeburn 6834: var doremove = 0;
6835: if (skip_confirm) {
6836: if (confirm_removal) {
6837: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
6838: doremove = 1;
6839: }
6840: } else {
6841: doremove = 1;
6842: }
6843: } else {
6844: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
6845: doremove = 1;
6846: }
6847: }
6848: if (doremove) {
1.484.2.30 raeburn 6849: targetform.markcopy.value='';
6850: targetform.copyfolder.value='';
1.484.2.29 raeburn 6851: targetform.submit();
6852: }
6853: }
1.484.2.30 raeburn 6854: if (param == 'cut') {
1.484.2.61 raeburn 6855: 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 6856: targetform.submit();
6857: return;
6858: }
6859: }
6860: if (param == 'copy') {
6861: targetform.submit();
6862: return;
6863: }
6864: targetform.markcopy.value='';
6865: targetform.copyfolder.value='';
6866: targetform.cmd.value='';
6867: targetform.folderpath.value='';
6868: return;
6869: } else {
6870: if (document.getElementById(param+'_'+idx)) {
6871: item = document.getElementById(param+'_'+idx);
6872: if (item.type == 'checkbox') {
6873: if (item.checked) {
6874: item.checked = false;
6875: } else {
6876: item.checked = true;
6877: singleCheck(item,idx,param);
6878: }
6879: }
6880: }
6881: }
6882: }
6883: return;
6884: }
6885:
6886: function singleCheck(caller,idx,action) {
6887: actions = new Array('cut','copy','remove');
6888: if (caller.checked) {
6889: for (var i=0; i<actions.length; i++) {
6890: if (actions[i] != action) {
6891: if (document.getElementById(actions[i]+'_'+idx)) {
6892: if (document.getElementById(actions[i]+'_'+idx).checked) {
6893: document.getElementById(actions[i]+'_'+idx).checked = false;
6894: }
6895: }
6896: }
1.484.2.29 raeburn 6897: }
6898: }
6899: return;
1.478 raeburn 6900: }
6901:
1.334 muellerd 6902: function unselectInactive(nav) {
1.335 ehlerst 6903: currentNav = document.getElementById(nav);
6904: currentLis = currentNav.getElementsByTagName('LI');
6905: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 6906: if (currentLis[i].className == 'goback') {
6907: currentLis[i].className = 'goback';
6908: } else {
6909: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 6910: currentLis[i].className = 'right';
1.472 raeburn 6911: } else {
1.374 tempelho 6912: currentLis[i].className = 'i';
1.472 raeburn 6913: }
6914: }
1.335 ehlerst 6915: }
1.332 tempelho 6916: }
6917:
1.334 muellerd 6918: function hideAll(current, nav, data) {
1.335 ehlerst 6919: unselectInactive(nav);
1.484.2.43 raeburn 6920: if (current) {
6921: if (current.className == 'right'){
1.374 tempelho 6922: current.className = 'right active'
1.484.2.43 raeburn 6923: } else {
1.374 tempelho 6924: current.className = 'active';
1.484.2.43 raeburn 6925: }
1.374 tempelho 6926: }
1.335 ehlerst 6927: currentData = document.getElementById(data);
6928: currentDivs = currentData.getElementsByTagName('DIV');
6929: for (i = 0; i < currentDivs.length; i++) {
6930: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 6931: currentDivs[i].style.display = 'none';
1.330 tempelho 6932: }
6933: }
1.335 ehlerst 6934: }
1.330 tempelho 6935:
1.374 tempelho 6936: function openTabs(pageId) {
6937: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 6938: if(tabnav.length > 2 ){
1.389 tempelho 6939: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 6940: currentLis = currentNav.getElementsByTagName('LI');
6941: for(i = 0; i< currentLis.length; i++){
6942: if(currentLis[i].className == 'active') {
1.375 tempelho 6943: funcString = currentLis[i].onclick.toString();
6944: tab = funcString.split('"');
1.420 onken 6945: if(tab.length < 2) {
6946: tab = funcString.split("'");
6947: }
1.375 tempelho 6948: currentData = document.getElementById(tab[1]);
6949: currentData.style.display = 'block';
1.374 tempelho 6950: }
6951: }
6952: }
6953: }
6954:
1.334 muellerd 6955: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 6956: currstate = current.className;
1.334 muellerd 6957: hideAll(current, nav, data);
1.375 tempelho 6958: openTabs(pageId);
1.334 muellerd 6959: unselectInactive(nav);
1.484.2.43 raeburn 6960: if ((currstate == 'active') || (currstate == 'right active')) {
6961: if (currstate == 'active') {
6962: current.className = '';
6963: } else {
6964: current.className = 'right';
6965: }
6966: activeTab = '';
6967: toggleUpload();
6968: toggleMap();
6969: resize_scrollbox('contentscroll','1','0');
6970: return;
6971: } else {
6972: current.className = 'active';
6973: }
1.330 tempelho 6974: currentData = document.getElementById(pageId);
6975: currentData.style.display = 'block';
1.458 raeburn 6976: activeTab = pageId;
1.484.2.12 raeburn 6977: toggleUpload();
1.484.2.14 raeburn 6978: toggleMap();
1.433 raeburn 6979: if (nav == 'mainnav') {
6980: var storedpath = "$docs_folderpath";
1.434 raeburn 6981: var storedpage = "$main_container_page";
1.433 raeburn 6982: var reg = new RegExp("^supplemental");
6983: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 6984: if (storedpage == 1) {
6985: document.simpleedit.folderpath.value = '';
6986: document.uploaddocument.folderpath.value = '';
6987: } else {
6988: if (reg.test(storedpath)) {
6989: document.simpleedit.folderpath.value = '$toplevelmain';
6990: document.uploaddocument.folderpath.value = '$toplevelmain';
6991: document.newext.folderpath.value = '$toplevelmain';
6992: } else {
6993: document.simpleedit.folderpath.value = storedpath;
6994: document.uploaddocument.folderpath.value = storedpath;
6995: document.newext.folderpath.value = storedpath;
6996: }
1.433 raeburn 6997: }
6998: } else {
1.434 raeburn 6999: if (reg.test(storedpath)) {
7000: document.simpleedit.folderpath.value = storedpath;
7001: document.supuploaddocument.folderpath.value = storedpath;
7002: document.supnewext.folderpath.value = storedpath;
7003: } else {
1.433 raeburn 7004: document.simpleedit.folderpath.value = '$toplevelsupp';
7005: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7006: document.supnewext.folderpath.value = '$toplevelsupp';
7007: }
7008: }
7009: }
1.484.2.3 raeburn 7010: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7011: return false;
7012: }
1.329 droeschl 7013:
1.472 raeburn 7014: function toContents(jumpto) {
7015: var newurl = '$backtourl';
1.484.2.21 raeburn 7016: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7017: newurl = newurl+'?postdata='+jumpto;
7018: }
7019: location.href=newurl;
7020: }
7021:
1.484.2.30 raeburn 7022: function togglePick(caller,value) {
7023: var disp = 'none';
7024: if (document.getElementById('multi'+caller)) {
7025: var curr = document.getElementById('multi'+caller).style.display;
7026: if (value == 1) {
7027: disp='block';
7028: }
7029: if (curr == disp) {
7030: return;
7031: }
7032: document.getElementById('multi'+caller).style.display=disp;
7033: if (value == 1) {
1.484.2.61 raeburn 7034: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7035: } else {
7036: document.getElementById('more'+caller).innerHTML = '';
7037: }
7038: if (caller == 'actions') {
7039: setClass(value);
7040: setBoxes(value);
7041: }
7042: }
7043: var showButton = multiSettings();
7044: if (showButton != 1) {
7045: showButton = multiActions();
7046: }
7047: if (document.getElementById('multisave')) {
7048: if (showButton == 1) {
7049: document.getElementById('multisave').style.display='block';
7050: } else {
7051: document.getElementById('multisave').style.display='none';
7052: }
7053: }
7054: resize_scrollbox('contentscroll','1','1');
7055: return;
7056: }
7057:
7058: function toggleCheckUncheck(caller,more) {
7059: if (more == 1) {
1.484.2.61 raeburn 7060: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7061: document.getElementById('allfields'+caller).style.display='block';
7062: } else {
1.484.2.61 raeburn 7063: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7064: document.getElementById('allfields'+caller).style.display='none';
7065: }
7066: resize_scrollbox('contentscroll','1','1');
7067: }
7068:
7069: function multiSettings() {
7070: var inuse = 0;
7071: var settingsform = document.togglemultsettings;
7072: if (settingsform.showmultpick.length > 1) {
7073: for (var i=0; i<settingsform.showmultpick.length; i++) {
7074: if (settingsform.showmultpick[i].checked) {
7075: if (settingsform.showmultpick[i].value == 1) {
7076: inuse = 1;
7077: }
7078: }
7079: }
7080: }
7081: return inuse;
7082: }
7083:
7084: function multiActions() {
7085: var inuse = 0;
7086: var actionsform = document.togglemultactions;
7087: if (actionsform.showmultpick.length > 1) {
7088: for (var i=0; i<actionsform.showmultpick.length; i++) {
7089: if (actionsform.showmultpick[i].checked) {
7090: if (actionsform.showmultpick[i].value == 1) {
7091: inuse = 1;
7092: }
7093: }
7094: }
7095: }
7096: return inuse;
7097: }
7098:
7099: function checkSubmits() {
7100: var numchanges = 0;
7101: var form = document.saveactions;
7102: var doactions = multiActions();
7103: var cutwarnings = 0;
7104: var remwarnings = 0;
1.484.2.63 raeburn 7105: var removalinfo = 0;
1.484.2.30 raeburn 7106: if (doactions == 1) {
7107: var remidxlist = document.cumulativeactions.allremoveidx.value;
7108: if ((remidxlist != '') && (remidxlist != null)) {
7109: var remidxs = remidxlist.split(',');
7110: for (var i=0; i<remidxs.length; i++) {
7111: if (document.getElementById('remove_'+remidxs[i])) {
7112: if (document.getElementById('remove_'+remidxs[i]).checked) {
7113: form.multiremove.value += remidxs[i]+',';
7114: numchanges ++;
7115: if (document.getElementById('skip_remove_'+remidxs[i])) {
7116: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7117: remwarnings ++;
7118: }
7119: }
1.484.2.63 raeburn 7120: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7121: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7122: removalinfo ++;
7123: }
7124: }
1.484.2.30 raeburn 7125: }
7126: }
7127: }
7128: }
7129: var cutidxlist = document.cumulativeactions.allcutidx.value;
7130: if ((cutidxlist != '') && (cutidxlist != null)) {
7131: var cutidxs = cutidxlist.split(',');
7132: for (var i=0; i<cutidxs.length; i++) {
7133: if (document.getElementById('cut_'+cutidxs[i])) {
7134: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7135: form.multicut.value += cutidxs[i]+',';
7136: numchanges ++;
7137: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7138: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7139: cutwarnings ++;
7140: }
7141: }
7142: }
7143: }
7144: }
7145: }
7146: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7147: if ((copyidxlist != '') && (copyidxlist != null)) {
7148: var copyidxs = copyidxlist.split(',');
7149: for (var i=0; i<copyidxs.length; i++) {
7150: if (document.getElementById('copy_'+copyidxs[i])) {
7151: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7152: form.multicopy.value += copyidxs[i]+',';
7153: numchanges ++;
7154: }
7155: }
7156: }
7157: }
7158: if (numchanges > 0) {
7159: form.multichange.value = numchanges;
7160: }
7161: }
7162: var dosettings = multiSettings();
7163: var haschanges = 0;
7164: if (dosettings == 1) {
7165: form.allencrypturl.value = '';
7166: form.allhiddenresource.value = '';
7167: form.changeparms.value = 'all';
7168: var patt=new RegExp(",\$");
7169: var allidxlist = document.cumulativesettings.allidx.value;
7170: if ((allidxlist != '') && (allidxlist != null)) {
7171: var allidxs = allidxlist.split(',');
7172: if (allidxs.length > 1) {
7173: for (var i=0; i<allidxs.length; i++) {
7174: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7175: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7176: form.allhiddenresource.value += allidxs[i]+',';
7177: }
7178: }
7179: if (document.getElementById('encrypturl_'+allidxs[i])) {
7180: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7181: form.allencrypturl.value += allidxs[i]+',';
7182: }
1.484.2.29 raeburn 7183: }
7184: }
1.484.2.30 raeburn 7185: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7186: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7187: }
7188: }
7189: form.allrandompick.value = '';
7190: form.allrandomorder.value = '';
7191: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7192: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7193: var allmapidxs = allmapidxlist.split(',');
7194: for (var i=0; i<allmapidxs.length; i++) {
7195: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7196: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7197: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7198: if ((randompick.checked) && (rpicknum.value != '')) {
7199: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7200: }
7201: if (randorder.checked) {
7202: form.allrandomorder.value += allmapidxs[i]+',';
7203: }
7204: }
7205: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7206: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7207: }
7208: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7209: haschanges = 1;
7210: }
7211: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7212: haschanges = 1;
7213: }
7214: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7215: haschanges = 1;
7216: }
7217: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7218: haschanges = 1;
7219: }
7220: }
7221: if (doactions == 1) {
7222: if (numchanges > 0) {
1.484.2.63 raeburn 7223: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7224: if (remwarnings > 0) {
1.484.2.61 raeburn 7225: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7226: return false;
7227: }
7228: }
1.484.2.63 raeburn 7229: if (removalinfo > 0) {
7230: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7231: return false;
7232: }
7233: }
1.484.2.30 raeburn 7234: if (cutwarnings > 0) {
1.484.2.61 raeburn 7235: 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 7236: return false;
1.484.2.29 raeburn 7237: }
7238: }
7239: }
1.484.2.30 raeburn 7240: form.submit();
7241: return true;
7242: }
7243: }
7244: if (dosettings == 1) {
7245: if (haschanges == 1) {
7246: form.submit();
7247: return true;
1.484.2.29 raeburn 7248: }
7249: }
1.484.2.30 raeburn 7250: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7251: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7252: } else {
7253: if (dosettings == 1) {
1.484.2.61 raeburn 7254: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7255: } else {
1.484.2.61 raeburn 7256: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7257: }
7258: }
7259: return false;
7260: }
7261:
7262: function setClass(value) {
7263: var cutclass = 'LC_docs_cut';
7264: var copyclass = 'LC_docs_copy';
7265: var removeclass = 'LC_docs_remove';
7266: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7267: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7268: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7269: var links = document.getElementsByTagName('a');
7270: for (var i=0; i<links.length; i++) {
7271: var classes = links[i].className;
7272: if (cutreg.test(classes)) {
7273: links[i].className = cutclass;
7274: if (value == 1) {
7275: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7276: }
1.484.2.30 raeburn 7277: } else {
7278: if (copyreg.test(classes)) {
7279: links[i].className = copyclass;
7280: if (value == 1) {
7281: links[i].className += " LC_menubuttons_link";
7282: }
7283: } else {
7284: if (removereg.test(classes)) {
7285: links[i].className = removeclass;
7286: if (value == 1) {
7287: links[i].className += " LC_menubuttons_link";
7288: }
7289: }
1.484.2.29 raeburn 7290: }
7291: }
7292: }
1.484.2.30 raeburn 7293: return;
1.484.2.29 raeburn 7294: }
7295:
1.484.2.30 raeburn 7296: function setBoxes(value) {
7297: var remidxlist = document.cumulativeactions.allremoveidx.value;
7298: if ((remidxlist != '') && (remidxlist != null)) {
7299: var remidxs = remidxlist.split(',');
7300: for (var i=0; i<remidxs.length; i++) {
7301: if (document.getElementById('remove_'+remidxs[i])) {
7302: var item = document.getElementById('remove_'+remidxs[i]);
7303: if (value == 1) {
7304: item.className = 'LC_docs_remove';
7305: } else {
7306: item.className = 'LC_hidden';
7307: }
7308: }
1.484.2.29 raeburn 7309: }
7310: }
1.484.2.30 raeburn 7311: var cutidxlist = document.cumulativeactions.allcutidx.value;
7312: if ((cutidxlist != '') && (cutidxlist != null)) {
7313: var cutidxs = cutidxlist.split(',');
7314: for (var i=0; i<cutidxs.length; i++) {
7315: if (document.getElementById('cut_'+cutidxs[i])) {
7316: var item = document.getElementById('cut_'+cutidxs[i]);
7317: if (value == 1) {
7318: item.className = 'LC_docs_cut';
7319: } else {
7320: item.className = 'LC_hidden';
7321: }
7322: }
7323: }
7324: }
7325: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7326: if ((copyidxlist != '') && (copyidxlist != null)) {
7327: var copyidxs = copyidxlist.split(',');
7328: for (var i=0; i<copyidxs.length; i++) {
7329: if (document.getElementById('copy_'+copyidxs[i])) {
7330: var item = document.getElementById('copy_'+copyidxs[i]);
7331: if (value == 1) {
7332: item.className = 'LC_docs_copy';
7333: } else {
7334: item.className = 'LC_hidden';
7335: }
7336: }
1.484.2.29 raeburn 7337: }
7338: }
7339: return;
7340: }
7341:
1.484.2.67 raeburn 7342: ENDSCRIPT
1.329 droeschl 7343: }
1.457 raeburn 7344:
1.483 raeburn 7345: sub history_tab_js {
7346: return <<"ENDHIST";
7347: function toggleHistoryDisp(choice) {
7348: document.docslogform.docslog.value = choice;
7349: document.docslogform.submit();
7350: return;
7351: }
7352:
7353: ENDHIST
7354: }
7355:
1.484 raeburn 7356: sub inject_data_js {
7357: return <<ENDINJECT;
7358:
7359: function injectData(current, hiddenField, name, value) {
7360: currentElement = document.getElementById(hiddenField);
7361: currentElement.name = name;
7362: currentElement.value = value;
7363: current.submit();
7364: }
7365:
7366: ENDINJECT
7367: }
7368:
7369: sub dump_switchserver_js {
7370: my @hosts = @_;
1.484.2.61 raeburn 7371: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7372: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7373: swit => 'Switch server?',
1.484.2.61 raeburn 7374: );
7375: my %html_js_lt = &Apache::lonlocal::texthash(
7376: swit => 'Switch server?',
1.484.2.43 raeburn 7377: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7378: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7379: chos => 'Choose server',
7380: );
1.484.2.61 raeburn 7381: &js_escape(\%js_lt);
7382: &html_escape(\%html_js_lt);
7383: &js_escape(\%html_js_lt);
1.484 raeburn 7384: my $role = $env{'request.role'};
7385: my $js = <<"ENDSWJS";
7386: <script type="text/javascript">
7387: function write_switchserver() {
7388: var server;
7389: if (document.setserver.posshosts.length > 0) {
7390: for (var i=0; i<document.setserver.posshosts.length; i++) {
7391: if (document.setserver.posshosts[i].checked) {
7392: server = document.setserver.posshosts[i].value;
7393: }
7394: }
7395: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7396: }
7397: window.close();
7398: }
7399: </script>
7400:
7401: ENDSWJS
7402:
7403: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7404: {'only_body' => 1,
7405: 'js_ready' => 1,});
7406: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7407:
7408: my $hostpicker;
7409: my $count = 0;
7410: foreach my $host (sort(@hosts)) {
7411: my $checked;
7412: if ($count == 0) {
7413: $checked = ' checked="checked"';
7414: }
7415: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7416: $host.'"'.$checked.' />'.$host.'</label> ';
7417: $count++;
7418: }
7419:
7420: return <<"ENDSWITCHJS";
7421:
7422: function dump_needs_switchserver(url) {
7423: if (url!='' && url!= null) {
1.484.2.61 raeburn 7424: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7425: go(url);
7426: }
7427: }
7428: return;
7429: }
7430:
7431: function choose_switchserver_window() {
7432: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7433: newWindow.document.open();
7434: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7435: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7436: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7437: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7438: '<form name="setserver" method="post" action="" \\/>\\n'+
7439: '$hostpicker\\n'+
7440: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7441: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7442: 'onclick="write_switchserver();" \\/>\\n'+
7443: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7444: newWindow.document.writeln('$endpage');
7445: newWindow.document.close();
7446: newWindow.focus();
7447: }
7448:
7449: ENDSWITCHJS
7450: }
7451:
7452: sub makedocslogform {
7453: my ($formelems,$docslog) = @_;
7454: return <<"LOGSFORM";
7455: <form action="/adm/coursedocs" method="post" name="docslogform">
7456: <input type="hidden" name="docslog" value="$docslog" />
7457: $formelems
7458: </form>
7459: LOGSFORM
7460: }
7461:
7462: sub makesimpleeditform {
7463: my ($formelems) = @_;
7464: return <<"SIMPFORM";
7465: <form name="simpleedit" method="post" action="/adm/coursedocs">
7466: <input type="hidden" name="importdetail" value="" />
7467: $formelems
7468: </form>
7469: SIMPFORM
7470: }
7471:
1.329 droeschl 7472: 1;
7473: __END__
7474:
7475:
7476: =head1 NAME
7477:
7478: Apache::londocs.pm
7479:
7480: =head1 SYNOPSIS
7481:
7482: This is part of the LearningOnline Network with CAPA project
7483: described at http://www.lon-capa.org.
7484:
7485: =head1 SUBROUTINES
7486:
7487: =over
7488:
7489: =item %help=()
7490:
7491: Available help topics
7492:
7493: =item mapread()
7494:
1.344 bisitz 7495: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7496: @order and @resources, determines status
7497: sets @order - pointer to resources in right order
7498: sets @resources - array with the resources with correct idx
7499:
7500: =item authorhosts()
7501:
7502: Return hash with valid author names
7503:
7504: =item clean()
7505:
7506: =item dumpcourse()
7507:
7508: Actually dump course
7509:
7510: =item group_import()
7511:
7512: Imports the given (name, url) resources into the course
7513: coursenum, coursedom, and folder must precede the list
7514:
7515: =item breadcrumbs()
7516:
7517: =item log_docs()
7518:
7519: =item docs_change_log()
7520:
7521: =item update_paste_buffer()
7522:
7523: =item print_paste_buffer()
7524:
7525: =item do_paste_from_buffer()
7526:
1.484.2.30 raeburn 7527: =item do_buffer_empty()
7528:
7529: =item clear_from_buffer()
7530:
1.484.2.7 raeburn 7531: =item get_newmap_url()
7532:
7533: =item dbcopy()
7534:
7535: =item uniqueness_check()
7536:
7537: =item contained_map_check()
7538:
7539: =item url_paste_fixups()
7540:
7541: =item apply_fixups()
7542:
7543: =item copy_dependencies()
7544:
1.329 droeschl 7545: =item update_parameter()
7546:
7547: =item handle_edit_cmd()
7548:
7549: =item editor()
7550:
7551: =item process_file_upload()
7552:
7553: =item process_secondary_uploads()
7554:
7555: =item is_supplemental_title()
7556:
7557: =item entryline()
7558:
7559: =item tiehash()
7560:
7561: =item untiehash()
7562:
7563: =item checkonthis()
7564:
7565: check on this
7566:
7567: =item verifycontent()
7568:
7569: Verify Content
7570:
1.484.2.78! raeburn 7571: =item devalidateversioncache()
! 7572:
! 7573: =item checkversions()
1.329 droeschl 7574:
7575: Check Versions
7576:
7577: =item mark_hash_old()
7578:
7579: =item is_hash_old()
7580:
7581: =item changewarning()
7582:
7583: =item init_breadcrumbs()
7584:
7585: Breadcrumbs for special functions
7586:
1.484 raeburn 7587: =item create_list_elements()
7588:
7589: =item create_form_ul()
7590:
7591: =item startContentScreen()
7592:
7593: =item endContentScreen()
7594:
7595: =item supplemental_base()
7596:
7597: =item embedded_form_elems()
7598:
7599: =item embedded_destination()
7600:
7601: =item return_to_editor()
7602:
7603: =item decompression_info()
7604:
7605: =item decompression_phase_one()
7606:
7607: =item decompression_phase_two()
7608:
7609: =item remove_archive()
7610:
7611: =item generate_admin_menu()
7612:
7613: =item generate_edit_table()
7614:
7615: =item editing_js()
7616:
7617: =item history_tab_js()
7618:
7619: =item inject_data_js()
7620:
7621: =item dump_switchserver_js()
7622:
1.484.2.3 raeburn 7623: =item resize_scrollbox_js()
1.484 raeburn 7624:
7625: =item makedocslogform()
7626:
1.484.2.3 raeburn 7627: =item makesimpleeditform()
7628:
1.329 droeschl 7629: =back
7630:
7631: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>