Annotation of loncom/interface/londocs.pm, revision 1.484.2.87
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.87! raeburn 4: # $Id: londocs.pm,v 1.484.2.86 2020/01/20 20:09:37 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.484.2.19 raeburn 43: use Apache::lonextresedit();
1.484.2.43 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.329 droeschl 46: use HTML::Entities;
1.484.2.7 raeburn 47: use HTML::TokeParser;
1.329 droeschl 48: use GDBM_File;
1.484.2.51 raeburn 49: use File::MMagic;
1.329 droeschl 50: use Apache::lonlocal;
51: use Cwd;
52: use LONCAPA qw(:DEFAULT :match);
53:
54: my $iconpath;
55:
56: my %hash;
57:
58: my $hashtied;
59: my %alreadyseen=();
60:
61: my $hadchanges;
1.484.2.37 raeburn 62: my $suppchanges;
1.329 droeschl 63:
64:
65: my %help=();
66:
67:
68: sub mapread {
69: my ($coursenum,$coursedom,$map)=@_;
70: return
71: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
72: $map);
73: }
74:
75: sub storemap {
1.484.2.7 raeburn 76: my ($coursenum,$coursedom,$map,$contentchg)=@_;
77: my $report;
78: if (($contentchg) && ($map =~ /^default/)) {
79: $report = 1;
80: }
1.329 droeschl 81: my ($outtext,$errtext)=
82: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 83: $map,1,$report);
1.329 droeschl 84: if ($errtext) { return ($errtext,2); }
1.364 bisitz 85:
1.484.2.37 raeburn 86: if ($map =~ /^default/) {
87: $hadchanges=1;
88: } else {
89: $suppchanges=1;
90: }
1.329 droeschl 91: return ($errtext,0);
92: }
93:
94:
95:
96: sub authorhosts {
97: my %outhash=();
98: my $home=0;
99: my $other=0;
100: foreach my $key (keys(%env)) {
101: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
102: my $role=$1;
103: my $realm=$2;
104: my ($start,$end)=split(/\./,$env{$key});
105: if (($start) && ($start>time)) { next; }
106: if (($end) && (time>$end)) { next; }
107: my ($ca,$cd);
108: if ($1 eq 'au') {
109: $ca=$env{'user.name'};
110: $cd=$env{'user.domain'};
111: } else {
112: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
113: }
114: my $allowed=0;
115: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
116: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 117: foreach my $id (@ids) {
118: if ($id eq $myhome) {
119: $allowed=1;
120: last;
121: }
122: }
1.329 droeschl 123: if ($allowed) {
124: $home++;
1.484 raeburn 125: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 126: } else {
1.484 raeburn 127: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 128: $other++;
129: }
130: }
131: }
132: return ($home,$other,%outhash);
133: }
134:
135:
136: sub clean {
137: my ($title)=@_;
138: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 139: return $title;
1.329 droeschl 140: }
141:
1.484.2.67 raeburn 142: sub default_folderpath {
143: my ($coursenum,$coursedom,$navmapref) = @_;
144: return unless ($coursenum && $coursedom && ref($navmapref));
145: # Check if entire course is hidden and/or encrypted
146: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
147: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
148: unless (ref($$navmapref)) {
149: $$navmapref = Apache::lonnavmaps::navmap->new();
150: }
151: if (ref($$navmapref)) {
152: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
153: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
154: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
155: unless (@resources) {
156: $hiddenmap = 1;
157: unless ($env{'request.role.adv'}) {
158: $hiddentop = 1;
159: if ($env{'form.folder'}) {
160: undef($env{'form.folder'});
161: }
162: }
163: }
164: }
165: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
166: $encryptmap = 1;
167: }
168: }
169: unless ($hiddentop) {
170: $folderpath='default&'.&escape(&mt('Main Content')).
171: '::'.$hiddenmap.':'.$encryptmap.'::';
172: }
173: if (wantarray) {
174: return ($folderpath,$hiddentop);
175: } else {
176: return $folderpath;
177: }
178: }
1.329 droeschl 179:
180: sub dumpcourse {
181: my ($r) = @_;
1.408 raeburn 182: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 183: my ($starthash,$js);
184: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
185: $js = <<"ENDJS";
186: <script type="text/javascript">
187: // <![CDATA[
188:
189: function hide_searching() {
190: if (document.getElementById('searching')) {
191: document.getElementById('searching').style.display = 'none';
192: }
193: return;
194: }
195:
196: // ]]>
197: </script>
198: ENDJS
199: $starthash = {
200: add_entries => {'onload' => "hide_searching();"},
201: };
202: }
203: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
204: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 205: $r->print(&startContentScreen('tools'));
1.329 droeschl 206: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 207: unless ($home) {
208: $r->print(&endContentScreen());
209: return '';
210: }
1.329 droeschl 211: my $origcrsid=$env{'request.course.id'};
212: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
213: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
214: # Do the dumping
1.484 raeburn 215: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
216: $r->print(&endContentScreen());
217: return '';
218: }
1.484.2.24 raeburn 219: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 220: $r->print('<h3>'.&mt('Copying Files').'</h3>');
221: my $title=$env{'form.authorfolder'};
222: $title=&clean($title);
1.484.2.43 raeburn 223: my ($navmap,$errormsg) =
224: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
225: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
226: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
227: my (%maps,%resources,%titles);
228: if (!ref($navmap)) {
229: $r->print($errormsg.
230: &endContentScreen());
231: return '';
232: } else {
233: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
234: 'dumpdocs',$cdom,$cnum);
235: }
236: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
237: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
238: %newcontent,%has_simpleprobs);
239: foreach my $item (sort {$a <=> $b} (@todump)) {
240: my $name = $env{'form.namefor_'.$item};
241: if ($resources{$item}) {
242: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
243: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
244: $tocopy{$1} = $name;
245: $display{$item} = $1;
246: $lookup{$1} = $item;
247: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
248: $simpleproblems{$item} = {
249: symb => $resources{$item},
250: name => $name,
251: };
252: $display{$item} = 'simpleproblem_'.$name;
253: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
254: $has_simpleprobs{$1}{$id} = $item;
255: }
256: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
257: my $marker = $1;
258: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
259: $simplepages{$item} = {
260: res => $res,
261: title => $titles{$item},
262: db => $db_name,
263: marker => $marker,
264: symb => $resources{$item},
265: name => $name,
266: };
267: $display{$item} = '/'.$res;
268: }
269: } elsif ($maps{$item}) {
270: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
271: $tocopy{$1} = $name;
272: $display{$item} = $1;
273: $lookup{$1} = $item;
274: }
275: } else {
276: next;
277: }
278: }
1.329 droeschl 279: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
280: $crs=~s/\_/\//g;
1.484.2.43 raeburn 281: my $mm = new File::MMagic;
282: my $prefix = "/uploaded/$cdom/$cnum/";
283: %replacehash = %tocopy;
284: foreach my $item (sort(keys(%simpleproblems))) {
285: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
286: $newcontent{$display{$item}} = $content;
287: }
288: my $gateway = Apache::lonhtmlgateway->new('web');
289: foreach my $item (sort(keys(%simplepages))) {
290: if (ref($simplepages{$item}) eq 'HASH') {
291: my $pagetitle = $simplepages{$item}{'title'};
292: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
293: my %contents;
294: foreach my $field (keys(%fields)) {
295: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
296: my $name = $1;
297: my $msg = $fields{$field};
298: if ($name eq 'webreferences') {
299: if ($msg =~ m{^https?://}) {
300: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
301: }
302: } else {
303: $msg = &Encode::decode('utf8',$msg);
304: $msg = $gateway->process_outgoing_html($msg,1);
305: $contents{$name} = $msg;
306: }
307: } elsif ($field eq 'uploaded.photourl') {
308: my $marker = $simplepages{$item}{marker};
309: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
310: my $filepath = $1;
311: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
312: if ($fname ne '') {
313: $fname=~s/\.(\w+)$//;
314: my $ext=$1;
315: $fname = &clean($fname);
316: $fname.='.'.$ext;
317: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
318: $replacehash{$filepath} = $relpath.$fname;
319: $deps{$item}{$filepath} = 1;
320: }
321: }
322: }
323: }
324: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
325: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
326: my $content = '
327: <html>
328: <head>
329: <title>'.$pagetitle.'</title>
330: </head>
331: <body bgcolor="#ffffff">';
332: if ($contents{title}) {
333: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
334: }
335: if ($contents{image}) {
336: $content .= "\n".$contents{image};
337: }
338: if ($contents{content}) {
339: $content .= '
340: <div class="LC_Box">
1.484.2.50 raeburn 341: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 342: $contents{content}.'
343: </div>';
344: }
345: if ($contents{webreferences}) {
346: $content .= '
347: <div class="LC_Box">
1.484.2.50 raeburn 348: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 349: $contents{webreferences}.'
350: </div>';
351: }
352: $content .= '
353: </body>
354: </html>
355: ';
356: $newcontent{'/'.$simplepages{$item}{res}} = $content;
357: }
358: }
359: foreach my $item (keys(%tocopy)) {
360: unless ($item=~/\.(sequence|page)$/) {
361: my $currurlpath = $prefix.$item;
362: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
363: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
364: }
365: }
366: foreach my $num (sort {$a <=> $b} (@todump)) {
367: my $src = $display{$num};
368: next if ($src eq '');
369: my @needcopy = ();
370: if ($replacehash{$src}) {
371: push(@needcopy,$src);
372: if (ref($deps{$num}) eq 'HASH') {
373: foreach my $dep (sort(keys(%{$deps{$num}}))) {
374: if ($replacehash{$dep}) {
375: push(@needcopy,$dep);
376: }
377: }
378: }
379: } elsif ($src =~ /^simpleproblem_/) {
380: push(@needcopy,$src);
381: }
382: next if (@needcopy == 0);
383: my ($result,$depresult);
384: for (my $i=0; $i<@needcopy; $i++) {
385: my $item = $needcopy[$i];
386: my $newfilename;
387: if ($simpleproblems{$num}) {
388: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
389: } else {
390: $newfilename=$title.'/'.$replacehash{$item};
391: }
392: $newfilename=~s/\.(\w+)$//;
393: my $ext=$1;
394: $newfilename=&clean($newfilename);
395: $newfilename.='.'.$ext;
396: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
397: if ($newrelpath ne $replacehash{$item}) {
398: $replacehash{$item} = $newrelpath;
399: }
400: my @dirs=split(/\//,$newfilename);
401: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
402: my $makepath=$path;
403: my $fail;
404: my $origin;
405: for (my $i=0;$i<$#dirs;$i++) {
406: $makepath.='/'.$dirs[$i];
407: unless (-e $makepath) {
408: unless(mkdir($makepath,0755)) {
409: $fail = &mt('Directory creation failed.');
410: }
411: }
412: }
413: if ($i == 0) {
414: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
415: } else {
416: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
417: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
418: &mt('(dependency)').'</span>: ';
419: }
420: if (-e $path.'/'.$newfilename) {
421: $fail = &mt('Destination already exists -- not overwriting.');
422: } else {
423: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
424: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
425: ($item =~ /^simpleproblem_/)) {
426: print $fh $newcontent{$item};
427: } else {
428: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
429: if (-e $fileloc) {
430: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
431: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
432: (ref($has_simpleprobs{$item}) eq 'HASH')) {
433: my %changes = %{$has_simpleprobs{$item}};
434: my $content = &Apache::lonclonecourse::rewritefile(
435: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
436: (%replacehash,$crs => '')
437: );
438: my $updatedcontent = '';
439: my $parser = HTML::TokeParser->new(\$content);
440: $parser->attr_encoded(1);
441: while (my $token = $parser->get_token) {
442: if ($token->[0] eq 'S') {
443: if (($token->[1] eq 'resource') &&
444: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
445: ($changes{$token->[2]->{'id'}})) {
446: my $id = $token->[2]->{'id'};
447: $updatedcontent .= '<'.$token->[1];
448: foreach my $attrib (@{$token->[3]}) {
449: next unless ($attrib =~ /^(src|type|title|id)$/);
450: if ($attrib eq 'src') {
451: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
452: if ($file) {
453: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
454: } else {
455: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
456: }
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: }
461: $updatedcontent .= ' />'."\n";
462: } else {
463: $updatedcontent .= $token->[4]."\n";
464: }
465: } else {
466: $updatedcontent .= $token->[2];
467: }
468: }
469: print $fh $updatedcontent;
470: } else {
471: print $fh &Apache::lonclonecourse::rewritefile(
472: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
473: (%replacehash,$crs => '')
474: );
475: }
476: } else {
477: print $fh
478: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
479: }
480: } else {
481: $fail = &mt('Source does not exist.');
482: }
483: }
484: $fh->close();
485: } else {
486: $fail = &mt('Could not write to destination.');
487: }
488: }
489: my $text;
490: if ($fail) {
491: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
492: } else {
493: $text = '<span class="LC_success">'.&mt('ok').'</span>';
494: }
495: if ($i == 0) {
496: $result .= $text;
497: } else {
498: $depresult .= $text.'</li>';
499: }
500: }
501: $r->print($result);
502: if ($depresult) {
503: $r->print('<ul>'.$depresult.'</ul>');
504: }
505: }
1.329 droeschl 506: } else {
1.484.2.43 raeburn 507: my ($navmap,$errormsg) =
508: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
509: if (!ref($navmap)) {
510: $r->print($errormsg);
511: } else {
512: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
513: $r->rflush();
514: my ($preamble,$formname);
515: $formname = 'dumpdoc';
516: unless ($home==1) {
517: $preamble = '<div class="LC_left_float">'.
518: '<fieldset><legend>'.
519: &mt('Select the Authoring Space').
520: '</legend><select name="authorspace">';
521: }
522: my @orderspaces = ();
523: foreach my $key (sort(keys(%outhash))) {
524: if ($key=~/^home_(.+)$/) {
525: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
526: unshift(@orderspaces,$1);
527: } else {
528: push(@orderspaces,$1);
529: }
530: }
531: }
532: if ($home>1) {
533: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
534: }
535: foreach my $user (@orderspaces) {
536: if ($home==1) {
537: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
538: } else {
539: $preamble .= '<option value="'.$user.'">'.$user.' - '.
540: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
541: }
542: }
543: unless ($home==1) {
544: $preamble .= '</select></fieldset></div>'."\n";
545: }
546: my $title=$origcrsdata{'description'};
547: $title=~s/[\/\s]+/\_/gs;
548: $title=&clean($title);
549: $preamble .= '<div class="LC_left_float">'.
550: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
551: '<input type="text" size="50" name="authorfolder" value="'.
552: $title.'" />'.
553: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
554: my %uploadedfiles;
555: &tiehash();
556: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
557: my ($ext)=($file=~/\.(\w+)$/);
558: # FIXME Check supplemental here
559: my $title=$hash{'title_'.$hash{
560: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
561: if (!$title) {
562: $title=$file;
563: } else {
564: $title=~s|/|_|g;
565: }
566: $title=~s/\.(\w+)$//;
567: $title=&clean($title);
568: $title.='.'.$ext;
569: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
570: $uploadedfiles{$file} = $title;
571: }
572: &untiehash();
573: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
574: undef,undef,$preamble,$home,\%uploadedfiles));
575: }
1.329 droeschl 576: }
1.484 raeburn 577: $r->print(&endContentScreen());
1.329 droeschl 578: }
579:
1.484.2.43 raeburn 580: sub recurse_html {
581: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
582: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
583: my (%allfiles,%codebase);
584: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
585: if (keys(%allfiles)) {
586: foreach my $dependency (keys(%allfiles)) {
587: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
588: my ($depurl,$relfile,$newcontainer);
589: if ($dependency =~ m{^/}) {
590: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
591: $relfile = $1;
592: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
593: $newcontainer = $1;
594: next if ($replacehash->{$newcontainer});
595: }
596: $depurl = $dependency;
597: } else {
598: next;
599: }
600: } else {
601: $relfile = $dependency;
602: $depurl = $currurlpath;
603: $depurl =~ s{[^/]+$}{};
604: $depurl .= $dependency;
605: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
606: }
607: next if ($relfile eq '');
608: my $newname = $replacehash->{$container};
609: $newname =~ s{[^/]+$}{};
610: $replacehash->{$newcontainer} = $newname.$relfile;
611: $deps->{$item}{$newcontainer} = 1;
612: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
613: my $depfile = &Apache::lonnet::filelocation('',$depurl);
614: my $type = $mm->checktype_filename($depfile);
615: if ($type eq 'text/html') {
616: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
617: }
618: }
619: }
620: }
621: return;
622: }
623:
1.329 droeschl 624: sub group_import {
625: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
1.484.2.23 raeburn 626: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
627: %removeparam,$importuploaded,$fixuperrors);
628: $allmaps = {};
1.329 droeschl 629: while (@files) {
630: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 631: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 632: && ($caller eq 'londocs')
633: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 634:
1.329 droeschl 635: my $errtext = '';
636: my $fatal = 0;
637: my $newmapstr = '<map>'."\n".
638: '<resource id="1" src="" type="start"></resource>'."\n".
639: '<link from="1" to="2" index="1"></link>'."\n".
640: '<resource id="2" src="" type="finish"></resource>'."\n".
641: '</map>';
642: $env{'form.output'}=$newmapstr;
643: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
644: 'output',$1.$2);
1.484.2.27 raeburn 645: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 646: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
647: $fatal = 2;
648: }
649: if ($fatal) {
650: return ($errtext,$fatal);
651: }
652: }
653: if ($url) {
1.484.2.23 raeburn 654: if (($caller eq 'londocs') &&
655: ($folder =~ /^default/)) {
1.484.2.27 raeburn 656: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 657: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
658: my $cid = $coursedom.'_'.$coursenum;
659: $allmaps =
660: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
661: $chome,$cid);
662: $donechk = 1;
663: }
664: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
665: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
666: \%addedmaps,\%hierarchy,\%titles,$allmaps);
667: $importuploaded = 1;
668: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
669: next if ($allmaps->{$url});
670: }
671: }
1.344 bisitz 672: if (!$residx
1.329 droeschl 673: || defined($LONCAPA::map::zombies[$residx])) {
674: $residx = &LONCAPA::map::getresidx($url,$residx);
675: push(@LONCAPA::map::order, $residx);
676: }
677: my $ext = 'false';
678: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
679: $name = &LONCAPA::map::qtunescape($name);
1.484.2.27 raeburn 680: if ($name eq '') {
1.484.2.30 raeburn 681: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.484.2.27 raeburn 682: }
683: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
684: my $filepath = $1;
685: my $fname = $name;
686: if ($fname =~ /^\W+$/) {
687: $fname = 'web';
688: } else {
689: $fname =~ s/\W/_/g;
690: }
1.484.2.62 raeburn 691: if (length($fname) > 15) {
1.484.2.27 raeburn 692: $fname = substr($fname,0,14);
693: }
694: my $initialtext = &mt('Replace with your own content.');
695: my $newhtml = <<END;
1.484.2.31 raeburn 696: <html>
1.484.2.27 raeburn 697: <head>
698: <title>$name</title>
699: </head>
700: <body bgcolor="#ffffff">
701: $initialtext
702: </body>
703: </html>
704: END
705: $env{'form.output'}=$newhtml;
706: my $result =
707: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
708: 'output',
709: "$filepath/$residx/$fname.html");
710: if ($result =~ m{^/uploaded/}) {
711: $url = $result;
712: if ($filepath =~ /^supplemental/) {
713: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
714: $env{'user.domain'}.'___&&&___'.$name;
715: }
716: } else {
717: return (&mt('Failed to save new web page.'),1);
718: }
719: }
1.484.2.30 raeburn 720: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 721: $LONCAPA::map::resources[$residx] =
1.329 droeschl 722: join(':', ($name, $url, $ext, 'normal', 'res'));
723: }
724: }
1.484.2.23 raeburn 725: if ($importuploaded) {
726: my %import_errors;
727: my %updated = (
728: removefrommap => \%removefrommap,
729: removeparam => \%removeparam,
730: );
1.484.2.26 raeburn 731: my ($result,$msgsarray,$lockerror) =
732: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 733: if (keys(%import_errors) > 0) {
734: $fixuperrors =
735: '<p span class="LC_warning">'."\n".
736: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
737: '<ul>'."\n";
738: foreach my $key (sort(keys(%import_errors))) {
739: $fixuperrors .= '<li>'.$key.'</li>'."\n";
740: }
741: $fixuperrors .= '</ul></p>'."\n";
742: }
1.484.2.26 raeburn 743: if (ref($msgsarray) eq 'ARRAY') {
744: if (@{$msgsarray} > 0) {
745: $fixuperrors .= '<p class="LC_info">'.
746: join('<br />',@{$msgsarray}).
747: '</p>';
748: }
749: }
750: if ($lockerror) {
751: $fixuperrors .= '<p class="LC_error">'.
752: $lockerror.
753: '</p>';
754: }
1.484.2.23 raeburn 755: }
756: my ($errtext,$fatal) =
757: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 758: unless ($fatal) {
759: if ($folder =~ /^supplemental/) {
760: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 761: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
762: $folder.'.'.$container);
1.484.2.37 raeburn 763: }
764: }
1.484.2.23 raeburn 765: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 766: }
767:
768: sub log_docs {
1.484.2.8 raeburn 769: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 770: }
771:
772: {
773: my @oldresources=();
774: my @oldorder=();
775: my $parmidx;
776: my %parmaction=();
777: my %parmvalue=();
778: my $changedflag;
779:
780: sub snapshotbefore {
781: @oldresources=@LONCAPA::map::resources;
782: @oldorder=@LONCAPA::map::order;
783: $parmidx=undef;
784: %parmaction=();
785: %parmvalue=();
786: $changedflag=0;
787: }
788:
789: sub remember_parms {
790: my ($idx,$parameter,$action,$value)=@_;
791: $parmidx=$idx;
792: $parmaction{$parameter}=$action;
793: $parmvalue{$parameter}=$value;
794: $changedflag=1;
795: }
796:
797: sub log_differences {
798: my ($plain)=@_;
799: my %storehash=('folder' => $plain,
800: 'currentfolder' => $env{'form.folder'});
801: if ($parmidx) {
802: $storehash{'parameter_res'}=$oldresources[$parmidx];
803: foreach my $parm (keys(%parmaction)) {
804: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
805: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
806: }
807: }
808: my $maxidx=$#oldresources;
809: if ($#LONCAPA::map::resources>$#oldresources) {
810: $maxidx=$#LONCAPA::map::resources;
811: }
812: for (my $idx=0; $idx<=$maxidx; $idx++) {
813: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
814: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
815: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
816: $changedflag=1;
817: }
818: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
819: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
820: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
821: $changedflag=1;
822: }
823: }
824: $storehash{'maxidx'}=$maxidx;
825: if ($changedflag) { &log_docs(\%storehash); }
826: }
827: }
828:
829: sub docs_change_log {
1.484.2.67 raeburn 830: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 831: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 832: my $navmap;
1.483 raeburn 833: my $js = '<script type="text/javascript">'."\n".
834: '// <![CDATA['."\n".
835: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 836: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.80 raeburn 837: $coursedom,$coursenum,$canedit,'',\$navmap)."\n".
1.483 raeburn 838: &history_tab_js()."\n".
1.484 raeburn 839: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 840: '// ]]>'."\n".
841: '</script>'."\n";
1.484 raeburn 842: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
843: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 844: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 845: my %orderhash;
846: my $container='sequence';
847: my $pathitem;
1.484.2.19 raeburn 848: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 849: $container='page';
850: }
1.484.2.19 raeburn 851: my $folderpath=$env{'form.folderpath'};
852: if ($folderpath eq '') {
1.484.2.67 raeburn 853: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 854: }
1.484.2.67 raeburn 855: undef($navmap);
1.484.2.19 raeburn 856: $pathitem = '<input type="hidden" name="folderpath" value="'.
857: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 858: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
859: my $jumpto = $readfile;
860: $jumpto =~ s{^/}{};
861: my $tid = 1;
1.484.2.7 raeburn 862: if ($supplementalflag) {
863: $tid = 2;
864: }
1.484.2.19 raeburn 865: my ($breadcrumbtrail) =
1.484.2.18 raeburn 866: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 867: $r->print($breadcrumbtrail.
868: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
869: $readfile));
1.329 droeschl 870: my %docslog=&Apache::lonnet::dump('nohist_docslog',
871: $env{'course.'.$env{'request.course.id'}.'.domain'},
872: $env{'course.'.$env{'request.course.id'}.'.num'});
873:
874: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
875:
876: my %saveable_parameters = ('show' => 'scalar',);
877: &Apache::loncommon::store_course_settings('docs_log',
878: \%saveable_parameters);
879: &Apache::loncommon::restore_course_settings('docs_log',
880: \%saveable_parameters);
881: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 882: # FIXME: internationalization seems wrong here
1.329 droeschl 883: my %lt=('hiddenresource' => 'Resources hidden',
884: 'encrypturl' => 'URL hidden',
885: 'randompick' => 'Randomly pick',
886: 'randomorder' => 'Randomly ordered',
887: 'set' => 'set to',
888: 'del' => 'deleted');
1.484 raeburn 889: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
890: $pathitem."\n".
891: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
892: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
893: $r->print('<div class="LC_left_float">'.
894: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
895: &makedocslogform($filter,1).
896: '</fieldset></div><br clear="all" />');
1.329 droeschl 897: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
898: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
899: &mt('After').'</th>'.
900: &Apache::loncommon::end_data_table_header_row());
901: my $shown=0;
902: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
903: if ($env{'form.displayfilter'} eq 'currentfolder') {
904: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
905: }
906: my @changes=keys(%{$docslog{$id}{'logentry'}});
907: if ($env{'form.displayfilter'} eq 'containing') {
908: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
909: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
910: foreach my $key (@changes) {
911: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
912: }
1.344 bisitz 913: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 914: }
915: my $count = 0;
916: my $time =
917: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
918: my $plainname =
919: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
920: $docslog{$id}{'exe_udom'});
921: my $about_me_link =
922: &Apache::loncommon::aboutmewrapper($plainname,
923: $docslog{$id}{'exe_uname'},
924: $docslog{$id}{'exe_udom'});
925: my $send_msg_link='';
926: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
927: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
928: $send_msg_link ='<br />'.
929: &Apache::loncommon::messagewrapper(&mt('Send message'),
930: $docslog{$id}{'exe_uname'},
931: $docslog{$id}{'exe_udom'});
932: }
933: $r->print(&Apache::loncommon::start_data_table_row());
934: $r->print('<td>'.$time.'</td>
935: <td>'.$about_me_link.
936: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
937: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
938: $send_msg_link.'</td><td>'.
939: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 940: my $is_supp = 0;
1.484.2.7 raeburn 941: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
942: $is_supp = 1;
943: }
1.329 droeschl 944: # Before
945: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
946: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
947: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
948: if ($oldname ne $newname) {
1.484.2.7 raeburn 949: my $shown = &LONCAPA::map::qtescape($oldname);
950: if ($is_supp) {
951: $shown = &Apache::loncommon::parse_supplemental_title($shown);
952: }
953: $r->print($shown);
1.329 droeschl 954: }
955: }
956: $r->print('<ul>');
957: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
958: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 959: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
960: if ($is_supp) {
961: $shown = &Apache::loncommon::parse_supplemental_title($shown);
962: }
1.484.2.19 raeburn 963: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 964: }
965: }
966: $r->print('</ul>');
967: # After
968: $r->print('</td><td>');
969:
970: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
971: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
972: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
973: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 974: my $shown = &LONCAPA::map::qtescape($newname);
975: if ($is_supp) {
976: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
977: }
978: $r->print($shown);
1.329 droeschl 979: }
1.364 bisitz 980: }
1.329 droeschl 981: $r->print('<ul>');
982: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
983: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 984: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
985: if ($is_supp) {
986: $shown = &Apache::loncommon::parse_supplemental_title($shown);
987: }
988: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 989: }
990: }
991: $r->print('</ul>');
992: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
993: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
994: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
995: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 996: # FIXME: internationalization seems wrong here
1.329 droeschl 997: $r->print('<li>'.
998: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
999: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1000: .'</li>');
1001: }
1002: }
1003: $r->print('</ul>');
1004: }
1005: # End
1006: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1007: $shown++;
1008: if (!($env{'form.show'} eq &mt('all')
1009: || $shown<=$env{'form.show'})) { last; }
1010: }
1.484 raeburn 1011: $r->print(&Apache::loncommon::end_data_table()."\n".
1012: &makesimpleeditform($pathitem)."\n".
1013: '</div></div>');
1014: $r->print(&endContentScreen());
1.329 droeschl 1015: }
1016:
1017: sub update_paste_buffer {
1.484.2.7 raeburn 1018: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1019: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1020: if ($env{'form.multiremove'}) {
1021: $env{'form.multiremove'} =~ s/,$//;
1022: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1023: }
1024: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1025: if ($env{'form.multicut'}) {
1026: $env{'form.multicut'} =~ s/,$//;
1027: foreach my $item (split(/,/,$env{'form.multicut'})) {
1028: unless ($removals{$item}) {
1029: $cuts{$item} = 1;
1030: push(@possibles,$item.':cut');
1031: }
1032: }
1033: }
1034: if ($env{'form.multicopy'}) {
1035: $env{'form.multicopy'} =~ s/,$//;
1036: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1037: unless ($removals{$item} || $cuts{$item}) {
1038: push(@possibles,$item.':copy');
1039: }
1040: }
1041: }
1042: } elsif ($env{'form.markcopy'}) {
1043: @possibles = split(/,/,$env{'form.markcopy'});
1044: }
1.329 droeschl 1045:
1.484.2.30 raeburn 1046: return if (@possibles == 0);
1.329 droeschl 1047: return if (!defined($env{'form.copyfolder'}));
1048:
1049: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1050: $env{'form.copyfolder'});
1051: return if ($fatal);
1052:
1.484.2.30 raeburn 1053: my %curr_groups = &Apache::longroup::coursegroups();
1054:
1055: # Retrieve current paste buffer suffixes.
1056: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1057: my (%pasteurls,@newpaste);
1058:
1059: # Construct identifiers for current contents of user's paste buffer
1060: if (@currpaste) {
1061: foreach my $suffix (@currpaste) {
1.484.2.87! raeburn 1062: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
! 1063: my $url = $env{'docs.markedcopy_url_'.$suffix};
! 1064: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
! 1065: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
! 1066: ($url ne '')) {
! 1067: if ($url eq '/res/lib/templates/simpleproblem.problem') {
! 1068: $pasteurls{$cid.'_'.$mapidx} = 1;
! 1069: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
! 1070: $pasteurls{$url} = 1;
! 1071: } else {
! 1072: $pasteurls{$cid.'_'.$url} = 1;
! 1073: }
! 1074: }
1.484.2.30 raeburn 1075: }
1076: }
1077:
1078: # Mark items for copying (skip any items already in user's paste buffer)
1079: my %addtoenv;
1.484.2.82 raeburn 1080:
1081: my @pathitems = split(/\&/,$env{'form.folderpath'});
1082: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.87! raeburn 1083: my $ispage = $folderconf[5];
1.484.2.82 raeburn 1084:
1.484.2.30 raeburn 1085: foreach my $item (@possibles) {
1086: my ($orderidx,$cmd) = split(/:/,$item);
1087: next if ($orderidx =~ /\D/);
1088: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1089: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1090: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1091: my %denied = &action_restrictions($coursenum,$coursedom,
1092: &LONCAPA::map::qtescape($url),
1093: $env{'form.folderpath'},\%curr_groups);
1094: next if ($denied{'copy'});
1095: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87! raeburn 1096: if ($url eq '/res/lib/templates/simpleproblem.problem') {
! 1097: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
! 1098: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
! 1099: next if (exists($pasteurls{$url}));
! 1100: } else {
! 1101: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
! 1102: }
1.484.2.30 raeburn 1103: my ($suffix,$errortxt,$locknotfreed) =
1104: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1105: if ($suffix ne '') {
1106: push(@newpaste,$suffix);
1107: } else {
1108: if ($locknotfreed) {
1109: return $locknotfreed;
1110: }
1.484.2.30 raeburn 1111: }
1112: if (&is_supplemental_title($title)) {
1113: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1114: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1115: }
1116:
1117: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1118: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1119: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1120: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1121: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1122: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1123: my $prefix = $1;
1124: my $subdir =$2;
1125: if ($subdir eq '') {
1126: $subdir = $prefix;
1.484.2.7 raeburn 1127: }
1.484.2.30 raeburn 1128: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1129: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1130: \%hierarchy,\%titles,\%allmaps);
1131: if (ref($hierarchy{$url}) eq 'HASH') {
1132: my ($nested,$nestednames);
1133: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1134: $nested =~ s/\&$//;
1135: $nestednames =~ s/\Q___&&&___\E$//;
1136: if ($nested ne '') {
1137: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1138: }
1139: if ($nestednames ne '') {
1140: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1141: }
1.484.2.7 raeburn 1142: }
1143: }
1.484.2.57 raeburn 1144: if ($locknotfreed) {
1145: $output = $locknotfreed;
1146: last;
1147: }
1.484.2.7 raeburn 1148: }
1.484.2.30 raeburn 1149: if (@newpaste) {
1150: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1151: }
1.484.2.7 raeburn 1152: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1153: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1154: return $output;
1.329 droeschl 1155: }
1156:
1.484.2.7 raeburn 1157: sub recurse_uploaded_maps {
1158: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1159: if (ref($hierarchy->{$url}) eq 'HASH') {
1160: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1161: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1162: my (@uploaded,@names,%shorter);
1163: for (my $i=0; $i<@maps; $i++) {
1164: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1165: if ($inner ne '') {
1166: push(@uploaded,$inner);
1167: push(@names,&escape($titles[$i]));
1168: $shorter{$maps[$i]} = $inner;
1169: }
1170: }
1171: $$nestref .= "$dir:".join(',',@uploaded).'&';
1172: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1173: foreach my $map (@maps) {
1174: if ($shorter{$map} ne '') {
1175: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1176: }
1177: }
1178: }
1179: return;
1180: }
1181:
1.329 droeschl 1182: sub print_paste_buffer {
1.484.2.7 raeburn 1183: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1184: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1185:
1.484.2.30 raeburn 1186: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1187: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1188: }
1189:
1.484.2.30 raeburn 1190: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1191: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1192: my $clipboardcount = 0;
1.484.2.7 raeburn 1193:
1.484.2.30 raeburn 1194: # Construct identifiers for current contents of user's paste buffer
1195: foreach my $suffix (@currpaste) {
1196: next if ($suffix =~ /\D/);
1197: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1198: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1199: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1200: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1201: ($url ne '')) {
1.484.2.47 raeburn 1202: $clipboardcount ++;
1.484.2.30 raeburn 1203: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1204: $canpaste,$nopaste,$othercrs,$areachange);
1205: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1206: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1207: $is_external = 1;
1.484.2.7 raeburn 1208: }
1.484.2.30 raeburn 1209: if ($folder =~ /^supplemental/) {
1210: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1211: unless ($canpaste) {
1212: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1213: }
1.484.2.30 raeburn 1214: } else {
1215: $canpaste = 1;
1.484.2.7 raeburn 1216: }
1.484.2.30 raeburn 1217: if ($canpaste) {
1218: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1219: my $srcdom = $1;
1220: my $srcnum = $2;
1221: my $rem = $3;
1222: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1223: $othercourse = 1;
1224: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1225: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1226: } else {
1227: $canpaste = 0;
1228: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1229: }
1230: }
1.484.2.30 raeburn 1231: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1232: my $prefix = $1;
1233: $parent = $2;
1234: if ($folder !~ /^\Q$prefix\E/) {
1235: $areachange = 1;
1236: }
1237: $is_uploaded_map = 1;
1238: }
1.484.2.82 raeburn 1239: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1240: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1241: if ($cid ne $env{'request.course.id'}) {
1242: my ($srcdom,$srcnum) = split(/_/,$cid);
1243: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1244: $othercrs = '<br />'.&mt('(from another course)');
1245: } else {
1246: $canpaste = 0;
1247: $nopaste = &mt('Paste from another course unavailable.');
1248: }
1249: }
1250: }
1251: if ($canpaste) {
1252: push(@pasteable,$suffix);
1.484.2.30 raeburn 1253: }
1254: }
1255: my $buffer;
1256: if ($is_external) {
1257: $buffer = &mt('External Resource').': '.
1258: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1259: &LONCAPA::map::qtescape($url).')';
1260: } else {
1261: my $icon = &Apache::loncommon::icon($extension);
1262: if ($extension eq 'sequence' &&
1263: $url =~ m{/default_\d+\.sequence$}x) {
1264: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1265: $icon .= '/navmap.folder.closed.gif';
1266: }
1.484.2.57 raeburn 1267: my $title = $env{'docs.markedcopy_title_'.$suffix};
1268: if ($title eq '') {
1269: ($title) = ($url =~ m{/([^/]+)$});
1270: }
1.484.2.30 raeburn 1271: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1272: ': '.
1273: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1274: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1275: }
1276: $pasteitems .= '<div class="LC_left_float">';
1277: my ($options,$onclick);
1278: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1279: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1280: if (($is_uploaded_map) ||
1281: ($url =~ /(bulletinboard|smppg)$/) ||
1282: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1283: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1284: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1285: }
1286: }
1287: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1288: if ($nopaste) {
1289: $pasteitems .= $nopaste;
1290: } else {
1291: if ($othercrs) {
1292: $pasteitems .= $othercrs;
1293: }
1294: if ($options) {
1295: $pasteitems .= $options;
1.484.2.7 raeburn 1296: }
1297: }
1.484.2.30 raeburn 1298: $pasteitems .= '</div>';
1299: }
1300: }
1301: if ($pasteitems eq '') {
1302: &Apache::lonnet::delenv('docs.markedcopies');
1303: }
1304: my ($pasteform,$form_start,$buttons,$form_end);
1305: if ($pasteitems) {
1306: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1307: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1308: if (@pasteable) {
1.484.2.47 raeburn 1309: my $value = &mt('Paste to current folder');
1310: if ($container eq 'page') {
1311: $value = &mt('Paste to current page');
1312: }
1313: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1314: }
1315: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.(' 'x2);
1316: if ($clipboardcount > 1) {
1317: $buttons .=
1318: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1319: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1320: (' 'x2).
1321: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1322: (' 'x2);
1.484.2.7 raeburn 1323: }
1.484.2.48 raeburn 1324: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1325: '</form>';
1.484.2.30 raeburn 1326: } else {
1327: $pasteitems = &mt('Clipboard is empty');
1328: }
1329: $r->print($form_start
1330: .'<fieldset>'
1331: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1332: .$pasteitems
1333: .'</fieldset>'
1334: .$form_end);
1335: }
1336:
1337: sub paste_options {
1338: my ($suffix,$is_uploaded_map,$parent) = @_;
1339: my ($copytext,$movetext);
1340: if ($is_uploaded_map) {
1341: $copytext = &mt('Copy to new folder');
1342: $movetext = &mt('Move old');
1343: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1344: $copytext = &mt('Copy to new board');
1345: $movetext = &mt('Move (not posts)');
1346: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1347: $copytext = &mt('Copy to new page');
1348: $movetext = &mt('Move');
1.484.2.7 raeburn 1349: } else {
1.484.2.30 raeburn 1350: $copytext = &mt('Copy to new file');
1351: $movetext = &mt('Move');
1352: }
1353: my $output = '<br />'.
1354: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1355: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1356: '<label>'.
1357: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1358: $copytext.'</label></span>'.(' 'x2).' '.
1359: '<span class="LC_nobreak"><label>'.
1360: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1361: $movetext.'</label></span>';
1362: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1363: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1364: '</legend><table border="0">';
1365: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1366: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1367: my $lastdir = $parent;
1368: my %depths = (
1369: $lastdir => 0,
1370: );
1371: my (%display,%deps);
1372: for (my $i=0; $i<@pastemaps; $i++) {
1373: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1374: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1375: my @subfolders = split(/,/,$subfolderstr);
1376: $deps{$lastdir} = \@subfolders;
1377: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1378: my $depth = $depths{$lastdir} + 1;
1379: my $offset = int($depth * 4);
1380: my $indent = (' ' x $offset);
1381: for (my $j=0; $j<@subfolders; $j++) {
1382: $depths{$subfolders[$j]} = $depth;
1383: $display{$subfolders[$j]} =
1384: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1385: '<td><label>'.
1386: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1387: '<label>'.
1388: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1389: &mt('Move old').'</label>'.
1390: '</td></tr>';
1391: }
1392: }
1393: &recurse_print(\$output,$parent,\%deps,\%display);
1394: $output .= '</table></fieldset>';
1.329 droeschl 1395: }
1.484.2.30 raeburn 1396: $output .= '</div>';
1397: return $output;
1.329 droeschl 1398: }
1399:
1.484.2.7 raeburn 1400: sub recurse_print {
1.484.2.30 raeburn 1401: my ($outputref,$dir,$deps,$display) = @_;
1402: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1403: if (ref($deps->{$dir}) eq 'ARRAY') {
1404: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1405: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1406: }
1407: }
1408: }
1409:
1410: sub supp_pasteable {
1411: my ($url) = @_;
1412: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1413: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1414: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1415: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1416: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1417: return 1;
1418: }
1419: return;
1420: }
1421:
1422: sub paste_popup_js {
1.484.2.61 raeburn 1423: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1424: show => 'Show Options',
1425: hide => 'Hide Options',
1.484.2.61 raeburn 1426: );
1427: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1428: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1429: );
1.484.2.61 raeburn 1430: &html_escape(\%html_js_lt);
1431: &js_escape(\%html_js_lt);
1432: &js_escape(\%js_lt);
1.484.2.7 raeburn 1433: return <<"END";
1434:
1.484.2.30 raeburn 1435: function showPasteOptions(suffix) {
1436: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1437: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1438: return;
1439: }
1440:
1.484.2.30 raeburn 1441: function hidePasteOptions(suffix) {
1442: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1443: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1444: return;
1445: }
1446:
1.484.2.30 raeburn 1447: function showOptions(caller,suffix) {
1448: if (document.getElementById('pasteoptionstext_'+suffix)) {
1449: if (caller.checked) {
1.484.2.61 raeburn 1450: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1451: } else {
1452: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1453: }
1454: if (document.getElementById('pasteoptions_'+suffix)) {
1455: document.getElementById('pasteoptions_'+suffix).style.display='none';
1456: }
1457: }
1458: return;
1459: }
1.484.2.7 raeburn 1460:
1.484.2.30 raeburn 1461: function validateClipboard() {
1462: var numchk = 0;
1463: if (document.pasteform.pasting.length > 1) {
1464: for (var i=0; i<document.pasteform.pasting.length; i++) {
1465: if (document.pasteform.pasting[i].checked) {
1466: numchk ++;
1467: }
1468: }
1469: } else {
1470: if (document.pasteform.pasting.type == 'checkbox') {
1471: if (document.pasteform.pasting.checked) {
1472: numchk ++;
1473: }
1474: }
1475: }
1476: if (numchk > 0) {
1477: return true;
1478: } else {
1.484.2.61 raeburn 1479: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1480: return false;
1481: }
1.484.2.7 raeburn 1482: }
1483:
1.484.2.47 raeburn 1484: function checkClipboard() {
1485: if (document.pasteform.pasting.length > 1) {
1486: for (var i=0; i<document.pasteform.pasting.length; i++) {
1487: document.pasteform.pasting[i].checked = true;
1488: }
1489: }
1490: return;
1491: }
1492:
1493: function uncheckClipboard() {
1494: if (document.pasteform.pasting.length >1) {
1495: for (var i=0; i<document.pasteform.pasting.length; i++) {
1496: document.pasteform.pasting[i].checked = false;
1497: }
1498: }
1499: return;
1500: }
1501:
1.484.2.30 raeburn 1502: END
1503:
1504: }
1.484.2.7 raeburn 1505:
1.329 droeschl 1506: sub do_paste_from_buffer {
1.484.2.7 raeburn 1507: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1508:
1.484.2.30 raeburn 1509: # Array of items in paste buffer
1510: my (@currpaste,%pastebuffer,%allerrors);
1511: @currpaste = split(/,/,$env{'docs.markedcopies'});
1512:
1.484.2.7 raeburn 1513: # Early out if paste buffer is empty
1.484.2.30 raeburn 1514: if (@currpaste == 0) {
1.484.2.7 raeburn 1515: return ();
1.484.2.30 raeburn 1516: }
1517: map { $pastebuffer{$_} = 1; } @currpaste;
1518:
1519: # Array of items selected items to paste
1520: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1521:
1522: # Early out if nothing selected to paste
1523: if (@reqpaste == 0) {
1524: return();
1525: }
1526: my @topaste;
1527: foreach my $suffix (@reqpaste) {
1528: next if ($suffix =~ /\D/);
1529: next unless (exists($pastebuffer{$suffix}));
1530: push(@topaste,$suffix);
1.484.2.7 raeburn 1531: }
1532:
1.484.2.30 raeburn 1533: # Early out if nothing available to paste
1534: if (@topaste == 0) {
1535: return();
1.329 droeschl 1536: }
1537:
1.484.2.30 raeburn 1538: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.484.2.82 raeburn 1539: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1540:
1.484.2.30 raeburn 1541: foreach my $suffix (@topaste) {
1542: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1543: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1544: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1545: # Supplemental content may only include certain types of content
1546: # Early out if pasted content is not supported in Supplemental area
1547: if ($folder =~ /^supplemental/) {
1548: unless (&supp_pasteable($url)) {
1549: $notinsupp{$suffix} = 1;
1550: next;
1551: }
1552: }
1553: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1554: my $srcd = $1;
1555: my $srcn = $2;
1.484.2.7 raeburn 1556: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1557: # check for mdc privilege in the course from which the resource was pasted
1558: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1559: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1560: $notincrs{$suffix} = 1;
1561: next;
1562: }
1.329 droeschl 1563: }
1.484.2.30 raeburn 1564: $srcdom{$suffix} = $srcd;
1565: $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1566: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1567: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1568: my ($srcd,$srcn) = split(/_/,$cid);
1569: # When paste buffer was populated using an active role in a different course
1570: # check for mdc privilege in the course from which the resource was pasted
1571: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1572: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1573: $notincrs{$suffix} = 1;
1574: next;
1575: }
1576: }
1577: $srcdom{$suffix} = $srcd;
1578: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1579: }
1.484.2.82 raeburn 1580: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1581: push(@dopaste,$suffix);
1582: if ($url=~/\.(page|sequence)$/) {
1583: $is_map{$suffix} = 1;
1.329 droeschl 1584: }
1.484.2.30 raeburn 1585:
1586: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1587: my $oldprefix = $1;
1.484.2.19 raeburn 1588: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1589: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1590: # a folder/page or a document).
1.484.2.30 raeburn 1591: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1592: $prefixchg{$suffix} = 'docstosupp';
1593: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1594: $prefixchg{$suffix} = 'supptodocs';
1595: }
1.484.2.7 raeburn 1596:
1597: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1598: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1599: my @nested;
1600: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1601: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1602: my @deps = map { /\d+:([\d,]+$)/ } @items;
1603: foreach my $dep (@deps) {
1604: if ($dep =~ /,/) {
1605: push(@nested,split(/,/,$dep));
1606: } else {
1607: push(@nested,$dep);
1608: }
1.484.2.7 raeburn 1609: }
1.484.2.30 raeburn 1610: foreach my $item (@nested) {
1611: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1612: push(@{$marktomove{$suffix}},$type.'_'.$item);
1613: }
1.484.2.7 raeburn 1614: }
1615: }
1.329 droeschl 1616: }
1.484.2.7 raeburn 1617: }
1618:
1.484.2.30 raeburn 1619: # Early out if nothing available to paste
1620: if (@dopaste == 0) {
1621: return ();
1622: }
1623:
1624: # Populate message hash and hashes used for main content <=> supplemental content
1625: # changes
1626:
1627: %msgs = &Apache::lonlocal::texthash (
1628: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1629: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1630: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1631: );
1632:
1633: %before = (
1634: docstosupp => {
1635: map => 'default',
1636: doc => 'docs',
1637: },
1638: supptodocs => {
1639: map => 'supplemental',
1640: doc => 'supplemental',
1641: },
1642: );
1643:
1644: %after = (
1645: docstosupp => {
1646: map => 'supplemental',
1647: doc => 'supplemental'
1648: },
1649: supptodocs => {
1650: map => 'default',
1651: doc => 'docs',
1652: },
1653: );
1654:
1655: # Retrieve information about all course maps in main content area
1656:
1657: my $allmaps = {};
1.484.2.79 raeburn 1658: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1659:
1660: # Loop over the items to paste
1661: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1662: # Maps need to be copied first
1.484.2.30 raeburn 1663: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1664: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1665: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1666: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1667: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1668: }
1669: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1670: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1671: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1672: my $oldurl = $url;
1673: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1674: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1675: my (%hierarchy,%titles);
1.484.2.79 raeburn 1676: if (($folder =~ /^default/) && (!$donechk)) {
1677: $allmaps =
1678: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1679: $env{"course.$env{'request.course.id'}.home"},
1680: $env{'request.course.id'});
1681: $donechk = 1;
1682: }
1.484.2.30 raeburn 1683: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1684: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1685: if ($url=~ m{^/uploaded/}) {
1686: my $newurl;
1687: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1688: ($newurl,my $error) =
1689: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1690: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1691: \$title,$allmaps,\%newurls);
1692: if ($error) {
1693: $allerrors{$suffix} = $error;
1694: next;
1695: }
1696: if ($newurl ne '') {
1697: if ($newurl ne $url) {
1698: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1699: $newsubdir{$url} = $1;
1700: }
1701: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1702: }
1703: }
1704: }
1.484.2.30 raeburn 1705: if (($srcdom{$suffix} ne $coursedom) ||
1706: ($srcnum{$suffix} ne $coursenum) ||
1707: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1708: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1709: $coursedom,$coursenum,$srcdom{$suffix},
1710: $srcnum{$suffix},$allmaps,\%rewrites,
1711: \%retitles,\%copies,\%dbcopies,
1712: \%zombies,\%params,\%mapmoves,
1713: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1714: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1715: $mapmoves{$url} = 1;
1716: }
1717: $url = $newurl;
1718: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1719: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1720: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1721: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1722: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1723: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1724: }
1725: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1726: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1727: push(@toclear,$suffix);
1728: # if pasting published map (main content area only) check map not already in course
1729: if ($folder =~ /^default/) {
1730: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1731: $duplicate{$suffix} = 1;
1732: next;
1733: }
1.484.2.7 raeburn 1734: }
1735: }
1736: }
1.484.2.30 raeburn 1737: if ($url=~ m{/(bulletinboard|smppg)$}) {
1738: my $prefix = $1;
1.484.2.76 raeburn 1739: my $fromothercrs;
1.484.2.30 raeburn 1740: #need to copy the db contents to a new one, unless this is a move.
1741: my %info = (
1742: src => $url,
1743: cdom => $coursedom,
1744: cnum => $coursenum,
1.484.2.76 raeburn 1745: );
1746: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1747: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1748: $fromothercrs = 1;
1749: $info{'cdom'} = $srcdom{$suffix};
1750: $info{'cnum'} = $srcnum{$suffix};
1751: }
1752: }
1753: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1754: my (%lockerr,$msg);
1755: my ($newurl,$result,$errtext) =
1756: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1757: if ($result eq 'ok') {
1758: $url = $newurl;
1759: $title=&mt('Copy of').' '.$title;
1760: } else {
1761: if ($prefix eq 'smppg') {
1762: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1763: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1764: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.30 raeburn 1765: }
1766: $results{$suffix} = $result;
1767: $msgerrs{$suffix} = $msg;
1768: $lockerrs{$suffix} = $lockerr{$prefix};
1769: next;
1770: }
1771: if ($lockerr{$prefix}) {
1772: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1773: }
1.484.2.7 raeburn 1774: }
1.484.2.30 raeburn 1775: }
1776: $title = &LONCAPA::map::qtunescape($title);
1777: my $ext='false';
1778: if ($url=~m{^http(|s)://}) { $ext='true'; }
1779: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1780: if ($folder !~ /^supplemental/) {
1781: (undef,undef,$title) =
1782: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1783: }
1784: } else {
1785: if ($folder=~/^supplemental/) {
1786: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1787: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1788: }
1789: }
1.484.2.7 raeburn 1790:
1791: # For uploaded files (excluding pages/sequences) path in copied file is changed
1792: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1793: # courses.
1794:
1.484.2.30 raeburn 1795: unless ($is_map{$suffix}) {
1796: my $newidx;
1.329 droeschl 1797: # Now insert the URL at the bottom
1.484.2.30 raeburn 1798: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1799: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1800: my $relpath = $1;
1801: if ($relpath ne '') {
1802: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1803: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1804: my $newprefix = $newloc;
1805: if ($newloc eq 'default') {
1806: $newprefix = 'docs';
1807: }
1808: if ($newdocsdir eq '') {
1809: $newdocsdir = 'default';
1810: }
1811: if (($prefixchg{$suffix}) ||
1812: ($srcdom{$suffix} ne $coursedom) ||
1813: ($srcnum{$suffix} ne $coursenum) ||
1814: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1815: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1816: $url =
1817: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1818: &Apache::lonnet::getfile($oldurl));
1819: if ($url eq '/adm/notfound.html') {
1820: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1821: next;
1822: } else {
1823: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1824: $newsubpath =~ s{/+$}{/};
1825: $docmoves{$oldurl} = $newsubpath;
1826: }
1.484.2.7 raeburn 1827: }
1828: }
1.484.2.82 raeburn 1829: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1830: my $template = $1;
1831: if ($newidx) {
1832: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1833: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1834: }
1.484.2.7 raeburn 1835: }
1.484.2.30 raeburn 1836: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1837: ':'.$ext.':normal:res';
1838: push(@LONCAPA::map::order,$newidx);
1839: # Store the result
1840: my ($errtext,$fatal) =
1841: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1842: if ($fatal) {
1843: $save_err .= $errtext;
1844: $allresult = 'fail';
1.484.2.7 raeburn 1845: }
1.329 droeschl 1846: }
1.484.2.30 raeburn 1847:
1.484.2.82 raeburn 1848: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1849: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 1850: unless ($allresult eq 'fail') {
1851: my %updated = (
1852: rewrites => \%rewrites,
1853: zombies => \%zombies,
1854: removefrommap => \%removefrommap,
1855: removeparam => \%removeparam,
1856: dbcopies => \%dbcopies,
1.484.2.82 raeburn 1857: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 1858: retitles => \%retitles,
1859: );
1860: my %info = (
1861: newsubdir => \%newsubdir,
1862: params => \%params,
1863: );
1864: if ($prefixchg{$suffix}) {
1865: $info{'before'} = $before{$prefixchg{$suffix}};
1866: $info{'after'} = $after{$prefixchg{$suffix}};
1867: }
1868: my %moves = (
1869: copies => \%copies,
1870: docmoves => \%docmoves,
1871: mapmoves => \%mapmoves,
1872: );
1873: (my $result,$msgs{$suffix},my $lockerror) =
1874: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1875: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1876: $url,'paste');
1877: $lockerrors .= $lockerror;
1878: if ($result eq 'ok') {
1879: if ($is_map{$suffix}) {
1880: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1881: $folder.'.'.$container);
1882: if ($fatal) {
1883: $allresult = 'failread';
1884: } else {
1885: if ($#LONCAPA::map::order<1) {
1886: my $idx=&LONCAPA::map::getresidx();
1887: if ($idx<=0) { $idx=1; }
1888: $LONCAPA::map::order[0]=$idx;
1889: $LONCAPA::map::resources[$idx]='';
1890: }
1891: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1892: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1893: ':'.$ext.':normal:res';
1894: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 1895:
1896: # Store the result
1.484.2.30 raeburn 1897: my ($errtext,$fatal) =
1898: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1899: if ($fatal) {
1900: $save_err .= $errtext;
1901: $allresult = 'failstore';
1902: }
1903: }
1904: }
1905: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1906: push(@toclear,$suffix);
1907: }
1908: }
1.329 droeschl 1909: }
1910: }
1.484.2.30 raeburn 1911: &clear_from_buffer(\@toclear,\@currpaste);
1912: my $msgsarray;
1913: foreach my $suffix (keys(%msgs)) {
1914: if (ref($msgs{$suffix}) eq 'ARRAY') {
1915: $msgsarray .= join(',',@{$msgs{$suffix}});
1916: }
1917: }
1918: return ($allresult,$save_err,$msgsarray,$lockerrors);
1919: }
1920:
1921: sub do_buffer_empty {
1922: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1923: if (@currpaste == 0) {
1924: return &mt('Clipboard is already empty');
1925: }
1926: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1927: if (@toclear == 0) {
1928: return &mt('Nothing selected to clear from clipboard');
1929: }
1930: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1931: if ($numdel) {
1932: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1933: } else {
1934: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 1935: }
1.484.2.30 raeburn 1936: return;
1937: }
1938:
1939: sub clear_from_buffer {
1940: my ($toclear,$currpaste) = @_;
1941: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1942: my %pastebuffer;
1943: map { $pastebuffer{$_} = 1; } @{$currpaste};
1944: my $numdel = 0;
1945: foreach my $suffix (@{$toclear}) {
1946: next if ($suffix =~ /\D/);
1947: next unless (exists($pastebuffer{$suffix}));
1948: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1949: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1950: delete($pastebuffer{$suffix});
1951: $numdel ++;
1952: }
1953: }
1954: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1955: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1956: return $numdel;
1.484.2.7 raeburn 1957: }
1958:
1959: sub get_newmap_url {
1960: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1961: $titleref,$allmaps,$newurls) = @_;
1962: my $newurl;
1963: if ($url=~ m{^/uploaded/}) {
1964: $$titleref=&mt('Copy of').' '.$$titleref;
1965: }
1966: my $now = time;
1967: my $suffix=$$.int(rand(100)).$now;
1968: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1969: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1970: my $path = $1;
1971: my $prefix = $2;
1972: my $ancestor = $3;
1973: if (length($ancestor) > 10) {
1974: $ancestor = substr($ancestor,-10,10);
1975: }
1976: my $newid;
1977: if ($prefixchg) {
1978: if ($folder =~ /^supplemental/) {
1979: $prefix =~ s/^default/supplemental/;
1980: } else {
1981: $prefix =~ s/^supplemental/default/;
1982: }
1983: }
1984: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1985: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1986: } else {
1987: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1988: }
1989: my $counter = 0;
1990: my $is_unique = &uniqueness_check($newurl);
1991: if ($folder =~ /^default/) {
1992: if ($allmaps->{$newurl}) {
1993: $is_unique = 0;
1994: }
1995: }
1996: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1997: $counter ++;
1998: $suffix ++;
1999: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2000: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2001: } else {
2002: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2003: }
2004: $is_unique = &uniqueness_check($newurl);
2005: }
2006: if ($is_unique) {
2007: $newurls->{$newurl} = 1;
2008: } else {
2009: if ($url=~/\.page$/) {
2010: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2011: } else {
2012: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2013: }
2014: }
2015: }
2016: return ($newurl);
2017: }
2018:
2019: sub dbcopy {
1.484.2.26 raeburn 2020: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2021: my ($url,$result,$errtext);
2022: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2023: $url = $dbref->{'src'};
1.484.2.26 raeburn 2024: if ($url =~ m{/(smppg|bulletinboard)$}) {
2025: my $prefix = $1;
2026: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2027: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2028: my $db_name;
2029: my $marker = (split(m{/},$url))[4];
2030: $marker=~s/\D//g;
2031: if ($dbref->{'src'} =~ m{/smppg$}) {
2032: $db_name =
2033: &Apache::lonsimplepage::get_db_name($url,$marker,
2034: $dbref->{'cdom'},
2035: $dbref->{'cnum'});
2036: } else {
2037: $db_name = 'bulletinpage_'.$marker;
2038: }
2039: my ($suffix,$freedlock,$error) =
2040: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2041: $coursedom,$coursenum,
2042: 'concat');
2043: if (!$suffix) {
2044: if ($prefix eq 'smppg') {
2045: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2046: } else {
1.484.2.42 raeburn 2047: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2048: }
2049: if ($error) {
2050: $errtext .= '<br />'.$error;
2051: }
2052: } else {
2053: #need to copy the db contents to a new one.
2054: my %contents=&Apache::lonnet::dump($db_name,
2055: $dbref->{'cdom'},
2056: $dbref->{'cnum'});
2057: if (exists($contents{'uploaded.photourl'})) {
2058: my $photo = $contents{'uploaded.photourl'};
2059: my ($subdir,$fname) =
2060: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2061: my $newphoto;
2062: if ($fname ne '') {
2063: my $content = &Apache::lonnet::getfile($photo);
2064: unless ($content eq '-1') {
2065: $env{'form.'.$suffix.'.photourl'} = $content;
2066: $newphoto =
2067: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2068: delete($env{'form.'.$suffix.'.photourl'});
2069: }
2070: }
2071: if ($newphoto =~ m{^/uploaded/}) {
2072: $contents{'uploaded.photourl'} = $newphoto;
2073: }
2074: }
2075: $db_name =~ s{_\d*$ }{_$suffix}x;
2076: $result=&Apache::lonnet::put($db_name,\%contents,
2077: $coursedom,$coursenum);
2078: if ($result eq 'ok') {
2079: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2080: }
2081: }
2082: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2083: $lockerrorsref->{$prefix} =
2084: '<div class="LC_error">'.
2085: &mt('There was a problem removing a lockfile.');
2086: if ($prefix eq 'smppg') {
2087: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2088: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.26 raeburn 2089: } else {
1.484.2.42 raeburn 2090: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2091: }
1.484.2.38 raeburn 2092: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2093: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2094: '</div>';
1.484.2.26 raeburn 2095: }
2096: }
2097: } elsif ($url =~ m{/syllabus$}) {
2098: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2099: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2100: if (($dbref->{'cdom'} ne $coursedom) ||
2101: ($dbref->{'cnum'} ne $coursenum)) {
2102: my %contents=&Apache::lonnet::dump('syllabus',
2103: $dbref->{'cdom'},
2104: $dbref->{'cnum'});
2105: $result=&Apache::lonnet::put('syllabus',\%contents,
2106: $coursedom,$coursenum);
2107: }
2108: }
1.484.2.7 raeburn 2109: }
2110: }
1.484.2.26 raeburn 2111: return ($url,$result,$errtext);
1.329 droeschl 2112: }
2113:
1.484.2.82 raeburn 2114: sub copy_templated_files {
2115: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2116: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2117: my $srccontainer = 'sequence';
2118: if ($srcwaspage) {
2119: $srccontainer = 'page';
2120: }
2121: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2122: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2123: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2124: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2125: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2126: $template.'.problem';
2127: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2128: if ($template eq 'simpleproblem') {
2129: $srcprefix .= '.0.';
2130: my $weightprefix = $newprefix;
2131: $newprefix .= '.0.';
2132: my @simpleprobqtypes = qw(radio option string essay numerical);
2133: my $qtype=$srcparms{$srcprefix.'questiontype'};
2134: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2135: my %newdata = (
2136: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2137: );
1.484.2.82 raeburn 2138: foreach my $type (@simpleprobqtypes) {
2139: if ($type eq $qtype) {
2140: $newdata{"$weightprefix.$type.weight"}=1;
2141: } else {
2142: $newdata{"$weightprefix.$type.weight"}=0;
2143: }
2144: }
2145: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2146: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2147: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2148: if ($qtype eq 'numerical') {
2149: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2150: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2151: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2152: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2153: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2154: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2155: unless (defined($maxfoils)) { $maxfoils=10; }
2156: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2157: if ($maxfoils<=0) { $maxfoils=10; }
2158: my $randomize=$srcparms{$srcprefix.'randomize'};
2159: unless (defined($randomize)) { $randomize='yes'; }
2160: unless ($randomize eq 'no') { $randomize='yes'; }
2161: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2162: $newdata{$newprefix.'randomize'} = $randomize;
2163: if ($qtype eq 'option') {
2164: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2165: }
2166: for (my $i=1; $i<=10; $i++) {
2167: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2168: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2169: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2170: }
2171:
2172: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2173: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2174: unless (defined($maxfoils)) { $maxfoils=10; }
2175: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2176: if ($maxfoils<=0) { $maxfoils=10; }
2177: my $randomize=$srcparms{$srcprefix.'randomize'};
2178: unless (defined($randomize)) { $randomize='yes'; }
2179: unless ($randomize eq 'no') { $randomize='yes'; }
2180: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2181: $newdata{$newprefix.'randomize'} = $randomize;
2182: if ($qtype eq 'option') {
2183: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2184: }
2185: for (my $i=1; $i<=10; $i++) {
2186: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2187: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2188: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2189: }
2190: } elsif ($qtype eq 'string') {
2191: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2192: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2193: }
2194: if (keys(%newdata)) {
2195: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2196: $coursenum);
2197: if ($putres eq 'ok') {
2198: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2199: }
2200: }
2201: }
2202: }
2203: }
2204:
1.329 droeschl 2205: sub uniqueness_check {
2206: my ($newurl) = @_;
2207: my $unique = 1;
2208: foreach my $res (@LONCAPA::map::order) {
2209: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2210: $url=&LONCAPA::map::qtescape($url);
2211: if ($newurl eq $url) {
2212: $unique = 0;
1.344 bisitz 2213: last;
1.329 droeschl 2214: }
2215: }
2216: return $unique;
2217: }
2218:
1.484.2.7 raeburn 2219: sub contained_map_check {
2220: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2221: $allmaps) = @_;
2222: my $content = &Apache::lonnet::getfile($url);
2223: unless ($content eq '-1') {
2224: my $parser = HTML::TokeParser->new(\$content);
2225: $parser->attr_encoded(1);
2226: while (my $token = $parser->get_token) {
2227: next if ($token->[0] ne 'S');
2228: if ($token->[1] eq 'resource') {
2229: next if ($token->[2]->{'type'} eq 'zombie');
2230: my $ressrc = $token->[2]->{'src'};
2231: if ($folder =~ /^supplemental/) {
2232: unless (&supp_pasteable($ressrc)) {
2233: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2234: next;
2235: }
2236: }
2237: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2238: if ($1 eq 'uploaded') {
2239: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2240: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2241: } else {
2242: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2243: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2244: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2245: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2246: } else {
2247: $addedmaps->{$ressrc} = [$url];
2248: }
2249: }
2250: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2251: $addedmaps,$hierarchy,$titles,$allmaps);
2252: }
2253: } elsif ($token->[1] eq 'param') {
2254: if ($folder =~ /^supplemental/) {
2255: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2256: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2257: } else {
1.484.2.19 raeburn 2258: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2259: }
2260: }
2261: }
2262: }
2263: }
2264: return;
2265: }
2266:
2267: sub url_paste_fixups {
1.484.2.26 raeburn 2268: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2269: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2270: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2271: my $checktitle;
2272: if (($prefixchg) &&
2273: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2274: $checktitle = 1;
2275: }
2276: my $skip;
2277: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2278: my $mapid = $1.$2;
2279: if ($tomove->{$mapid}) {
2280: $skip = 1;
2281: }
2282: }
2283: my $file = &Apache::lonnet::getfile($oldurl);
2284: return if ($file eq '-1');
2285: my $parser = HTML::TokeParser->new(\$file);
2286: $parser->attr_encoded(1);
2287: my $changed = 0;
2288: while (my $token = $parser->get_token) {
2289: next if ($token->[0] ne 'S');
2290: if ($token->[1] eq 'resource') {
2291: my $ressrc = $token->[2]->{'src'};
2292: next if ($ressrc eq '');
2293: my $id = $token->[2]->{'id'};
2294: my $title = $token->[2]->{'title'};
2295: if ($checktitle) {
2296: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2297: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2298: }
2299: }
2300: next if ($token->[2]->{'type'} eq 'external');
2301: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2302: next if ($skip);
1.484.2.25 raeburn 2303: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2304: $changed = 1;
2305: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2306: my $srcdom = $1;
2307: my $srcnum = $2;
2308: my $rem = $3;
2309: my $newurl;
2310: my $mapname;
2311: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2312: my $prefix = $1;
2313: $mapname = $prefix.$2;
2314: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2315: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2316: $srcdom,$srcnum,$allmaps,$rewrites,
2317: $retitles,$copies,$dbcopies,$zombies,
2318: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2319: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2320: next;
2321: } else {
2322: ($newurl,my $error) =
2323: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2324: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2325: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2326: $newsubdir->{$ressrc} = $1;
2327: }
2328: if ($error) {
2329: next;
2330: }
2331: }
2332: }
2333: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2334: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2335:
1.484.2.7 raeburn 2336: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2337: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2338: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2339: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2340: $cnum,$srcdom,$srcnum,$allmaps,
2341: $rewrites,$retitles,$copies,$dbcopies,
2342: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2343: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2344: $mapmoves->{$ressrc} = 1;
2345: }
2346: $changed = 1;
2347: } else {
1.484.2.25 raeburn 2348: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2349: $copies->{$oldurl}{$ressrc} = $id;
2350: $changed = 1;
2351: }
2352: }
1.484.2.26 raeburn 2353: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2354: next if ($skip);
1.484.2.7 raeburn 2355: my $srcdom = $1;
2356: my $srcnum = $2;
2357: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2358: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2359: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2360: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2361: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2362: $changed = 1;
2363: }
2364: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2365: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2366: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2367: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2368: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2369: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2370: $changed = 1;
2371: }
1.484.2.82 raeburn 2372: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2373: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2374: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2375: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2376: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2377: }
1.484.2.7 raeburn 2378: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2379: next if ($skip);
2380: my $srcdom = $1;
2381: my $srcnum = $2;
2382: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2383: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2384: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2385: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2386: $changed = 1;
2387: }
2388: }
2389: } elsif ($token->[1] eq 'param') {
2390: next if ($skip);
1.484.2.19 raeburn 2391: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2392: if ($to ne '') {
2393: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2394: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2395: } else {
2396: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2397: }
2398: }
2399: }
2400: }
2401: return $changed;
2402: }
2403:
2404: sub apply_fixups {
1.484.2.23 raeburn 2405: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2406: $oldurl,$url,$caller) = @_;
2407: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2408: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2409: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2410: if (ref($updated) eq 'HASH') {
2411: if (ref($updated->{'rewrites'}) eq 'HASH') {
2412: %rewrites = %{$updated->{'rewrites'}};
2413: }
2414: if (ref($updated->{'zombies'}) eq 'HASH') {
2415: %zombies = %{$updated->{'zombies'}};
2416: }
2417: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2418: %removefrommap = %{$updated->{'removefrommap'}};
2419: }
2420: if (ref($updated->{'removeparam'}) eq 'HASH') {
2421: %removeparam = %{$updated->{'removeparam'}};
2422: }
2423: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2424: %dbcopies = %{$updated->{'dbcopies'}};
2425: }
2426: if (ref($updated->{'retitles'}) eq 'HASH') {
2427: %retitles = %{$updated->{'retitles'}};
2428: }
1.484.2.82 raeburn 2429: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2430: %resdatacopy = %{$updated->{'resdatacopy'}};
2431: }
1.484.2.23 raeburn 2432: }
2433: if (ref($info) eq 'HASH') {
2434: if (ref($info->{'newsubdir'}) eq 'HASH') {
2435: %newsubdir = %{$info->{'newsubdir'}};
2436: }
2437: if (ref($info->{'params'}) eq 'HASH') {
2438: %params = %{$info->{'params'}};
2439: }
2440: if (ref($info->{'before'}) eq 'HASH') {
2441: %before = %{$info->{'before'}};
2442: }
2443: if (ref($info->{'after'}) eq 'HASH') {
2444: %after = %{$info->{'after'}};
2445: }
2446: }
2447: if (ref($moves) eq 'HASH') {
2448: if (ref($moves->{'copies'}) eq 'HASH') {
2449: %copies = %{$moves->{'copies'}};
2450: }
2451: if (ref($moves->{'docmoves'}) eq 'HASH') {
2452: %docmoves = %{$moves->{'docmoves'}};
2453: }
2454: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2455: %mapmoves = %{$moves->{'mapmoves'}};
2456: }
2457: }
2458: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2459: my @allcopies;
1.484.2.23 raeburn 2460: if (exists($copies{$key})) {
2461: if (ref($copies{$key}) eq 'HASH') {
2462: my %added;
2463: foreach my $innerkey (keys(%{$copies{$key}})) {
2464: if (($innerkey ne '') && (!$added{$innerkey})) {
2465: push(@allcopies,$innerkey);
2466: $added{$innerkey} = 1;
2467: }
1.484.2.7 raeburn 2468: }
1.484.2.23 raeburn 2469: undef(%added);
1.484.2.7 raeburn 2470: }
2471: }
2472: if ($key eq $oldurl) {
1.484.2.23 raeburn 2473: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2474: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2475: push(@allcopies,$oldurl);
2476: }
2477: }
2478: }
2479: if (@allcopies > 0) {
2480: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2481: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2482: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2483: if ($fname ne '') {
2484: my $content = &Apache::lonnet::getfile($item);
2485: unless ($content eq '-1') {
2486: my $storefn;
1.484.2.23 raeburn 2487: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2488: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2489: } else {
2490: $storefn = $relpath;
2491: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2492: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2493: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2494: }
1.484.2.23 raeburn 2495: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2496: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2497: }
2498: }
2499: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2500: my $copyurl =
1.484.2.7 raeburn 2501: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2502: $storefn.$fname,$content);
2503: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2504: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2505: return &mt('Paste failed: an error occurred copying the file.');
2506: } elsif (ref($errors) eq 'HASH') {
2507: $errors->{$item} = 1;
2508: }
2509: }
2510: }
2511: }
2512: }
2513: }
2514: }
1.484.2.23 raeburn 2515: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2516: my $storefn=$key;
2517: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2518: if ($prefixchg && $before{'map'} && $after{'map'}) {
2519: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2520: }
1.484.2.23 raeburn 2521: if ($newsubdir{$key}) {
2522: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2523: }
2524: my $mapcontent = &Apache::lonnet::getfile($key);
2525: if ($mapcontent eq '-1') {
2526: if (ref($errors) eq 'HASH') {
2527: $errors->{$key} = 1;
2528: }
2529: } else {
2530: my $newmap =
2531: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2532: $mapcontent);
2533: if ($newmap eq '/adm/notfound.html') {
2534: if (ref($errors) eq 'HASH') {
2535: $errors->{$key} = 1;
2536: }
2537: }
2538: }
2539: }
2540: my %updates;
2541: if ($is_map) {
1.484.2.23 raeburn 2542: if (ref($updated) eq 'HASH') {
2543: foreach my $type (keys(%{$updated})) {
2544: if (ref($updated->{$type}) eq 'HASH') {
2545: foreach my $key (keys(%{$updated->{$type}})) {
2546: $updates{$key} = 1;
2547: }
2548: }
2549: }
1.484.2.7 raeburn 2550: }
2551: foreach my $key (keys(%updates)) {
2552: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2553: if (ref($rewrites{$key}) eq 'HASH') {
2554: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2555: }
1.484.2.23 raeburn 2556: if (ref($retitles{$key}) eq 'HASH') {
2557: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2558: }
1.484.2.23 raeburn 2559: if (ref($removefrommap{$key}) eq 'HASH') {
2560: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2561: }
1.484.2.23 raeburn 2562: if (ref($removeparam{$key}) eq 'HASH') {
2563: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2564: }
1.484.2.23 raeburn 2565: if (ref($zombies{$key}) eq 'HASH') {
2566: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2567: }
1.484.2.23 raeburn 2568: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2569: foreach my $idx (keys(%{$dbcopies{$key}})) {
2570: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2571: my ($newurl,$result,$errtext) =
2572: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2573: if ($result eq 'ok') {
2574: $newdb{$idx} = $newurl;
2575: } elsif (ref($errors) eq 'HASH') {
2576: $errors->{$key} = 1;
2577: }
2578: push(@msgs,$errtext);
2579: }
1.484.2.7 raeburn 2580: }
2581: }
1.484.2.82 raeburn 2582: if (ref($resdatacopy{$key}) eq 'HASH') {
2583: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2584: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2585: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2586: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2587: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2588: my $template = $1;
2589: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2590: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2591: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2592: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2593: unless ($gotnewmapname) {
2594: ($newmapname) = ($key =~ m{/([^/]+)$});
2595: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2596: if ($newsubdir{$key}) {
2597: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2598: }
2599: $gotnewmapname = 1;
2600: }
2601: my $srcmapinfo = $srcfolder.':'.$idx;
2602: if ($srccontainer eq 'page') {
2603: $srcmapinfo .= ':1';
2604: }
2605: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2606: $cnum,$template,$idx,$newmapname);
2607: }
2608: }
2609: }
2610: }
2611: }
1.484.2.23 raeburn 2612: if (ref($params{$key}) eq 'HASH') {
2613: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2614: }
2615: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2616: if ($fatal) {
1.484.2.26 raeburn 2617: return ($errtext);
1.484.2.7 raeburn 2618: }
2619: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2620: if (defined($LONCAPA::map::zombies[$i])) {
2621: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2622: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2623: undef($LONCAPA::map::zombies[$i]);
2624: }
2625: }
2626: }
1.484.2.77 raeburn 2627: my $total = scalar(@LONCAPA::map::order) - 1;
2628: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2629: my $idx = $LONCAPA::map::order[$i];
2630: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2631: my $changed;
1.484.2.23 raeburn 2632: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2633: if ((exists($toremove{$idx})) &&
2634: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2635: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2636: if (ref($currparam{$idx}) eq 'ARRAY') {
2637: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2638: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2639: }
2640: }
2641: next;
2642: }
2643: my $origsrc = $src;
1.484.2.25 raeburn 2644: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2645: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2646: $changed = 1;
2647: }
2648: }
1.484.2.25 raeburn 2649: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2650: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2651: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2652: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2653: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2654: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2655: } else {
1.484.2.23 raeburn 2656: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2657: }
2658: }
1.484.2.25 raeburn 2659: if ($origsrc =~ /\.(page|sequence)$/) {
2660: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2661: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2662: }
1.484.2.25 raeburn 2663: } elsif ($newsubdir{$key}) {
2664: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2665: }
2666: }
2667: $changed = 1;
1.484.2.26 raeburn 2668: } elsif ($newdb{$idx} ne '') {
2669: $src = $newdb{$idx};
1.484.2.7 raeburn 2670: $changed = 1;
2671: }
2672: if ($changed) {
1.484.2.30 raeburn 2673: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2674: }
2675: }
2676: }
2677: foreach my $idx (keys(%remparam)) {
2678: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2679: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2680: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2681: }
2682: }
2683: }
1.484.2.26 raeburn 2684: if (values(%lockerrors) > 0) {
2685: $lockmsg = join('<br />',values(%lockerrors));
2686: }
1.484.2.7 raeburn 2687: my $storefn;
2688: if ($key eq $oldurl) {
2689: $storefn = $url;
2690: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2691: } else {
2692: $storefn = $key;
2693: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2694: if ($prefixchg && $before{'map'} && $after{'map'}) {
2695: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2696: }
1.484.2.23 raeburn 2697: if ($newsubdir{$key}) {
2698: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2699: }
2700: }
2701: my $report;
2702: if ($folder !~ /^supplemental/) {
2703: $report = 1;
2704: }
1.484.2.20 raeburn 2705: (my $outtext,$errtext) =
1.484.2.7 raeburn 2706: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2707: if ($errtext) {
1.484.2.23 raeburn 2708: if ($caller eq 'paste') {
1.484.2.26 raeburn 2709: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2710: }
1.484.2.7 raeburn 2711: }
2712: }
2713: }
1.484.2.26 raeburn 2714: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2715: }
2716:
2717: sub copy_dependencies {
2718: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2719: my $content;
2720: if (ref($contentref)) {
2721: $content = $$contentref;
2722: } else {
2723: $content = &Apache::lonnet::getfile($item);
2724: }
2725: unless ($content eq '-1') {
2726: my $mm = new File::MMagic;
2727: my $mimetype = $mm->checktype_contents($content);
2728: if ($mimetype eq 'text/html') {
2729: my (%allfiles,%codebase,$state);
2730: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2731: if ($res eq 'ok') {
2732: my ($numexisting,$numpathchanges,$existing);
2733: (undef,$numexisting,$numpathchanges,$existing) =
2734: &Apache::loncommon::ask_for_embedded_content(
2735: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2736: {'error_on_invalid_names' => 1,
2737: 'ignore_remote_references' => 1,
2738: 'docs_url' => $item,
2739: 'context' => 'paste'});
2740: if ($numexisting > 0) {
2741: if (ref($existing) eq 'HASH') {
2742: foreach my $dep (keys(%{$existing})) {
2743: my $depfile = $dep;
2744: unless ($depfile =~ m{^\Q$relpath\E}) {
2745: $depfile = $relpath.$dep;
2746: }
2747: my $depcontent = &Apache::lonnet::getfile($depfile);
2748: unless ($depcontent eq '-1') {
2749: my $storedep = $dep;
2750: $storedep =~ s{^\Q$relpath\E}{};
2751: my $dep_url =
2752: &Apache::lonclonecourse::writefile(
2753: $env{'request.course.id'},
2754: $storefn.$storedep,$depcontent);
2755: if ($dep_url eq '/adm/notfound.html') {
2756: if (ref($errors) eq 'HASH') {
2757: $errors->{$depfile} = 1;
2758: }
2759: } else {
2760: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2761: }
2762: }
2763: }
2764: }
2765: }
2766: }
2767: }
2768: }
2769: return;
2770: }
2771:
1.329 droeschl 2772: my %parameter_type = ( 'randompick' => 'int_pos',
2773: 'hiddenresource' => 'string_yesno',
2774: 'encrypturl' => 'string_yesno',
2775: 'randomorder' => 'string_yesno',);
2776: my $valid_parameters_re = join('|',keys(%parameter_type));
2777: # set parameters
2778: sub update_parameter {
1.484.2.29 raeburn 2779: if ($env{'form.changeparms'} eq 'all') {
2780: my (@allidx,@allmapidx,%allchecked,%currchecked);
2781: %allchecked = (
2782: 'hiddenresource' => {},
2783: 'encrypturl' => {},
2784: 'randompick' => {},
2785: 'randomorder' => {},
2786: );
2787: foreach my $which (keys(%allchecked)) {
2788: $env{'form.all'.$which} =~ s/,$//;
2789: if ($which eq 'randompick') {
2790: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2791: my ($res,$value) = split(/:/,$item);
2792: if ($value =~ /^\d+$/) {
2793: $allchecked{$which}{$res} = $value;
2794: }
2795: }
2796: } else {
1.484.2.30 raeburn 2797: if ($env{'form.all'.$which}) {
2798: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2799: }
1.484.2.29 raeburn 2800: }
2801: }
2802: my $haschanges = 0;
2803: foreach my $res (@LONCAPA::map::order) {
2804: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2805: $name=&LONCAPA::map::qtescape($name);
2806: $url=&LONCAPA::map::qtescape($url);
2807: next unless ($name && $url);
2808: my $is_map;
2809: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2810: $is_map = 1;
2811: }
2812: foreach my $which (keys(%allchecked)) {
2813: if (($which eq 'randompick' || $which eq 'randomorder')) {
2814: next if (!$is_map);
2815: }
2816: my $oldvalue = 0;
2817: my $newvalue = 0;
2818: if ($allchecked{$which}{$res}) {
2819: $newvalue = $allchecked{$which}{$res};
2820: }
2821: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2822: if ($which eq 'randompick') {
2823: if ($current =~ /^(\d+)$/) {
2824: $oldvalue = $1;
2825: }
2826: } else {
2827: if ($current =~ /^yes$/i) {
2828: $oldvalue = 1;
2829: }
2830: }
2831: if ($oldvalue ne $newvalue) {
2832: $haschanges = 1;
2833: if ($newvalue) {
2834: my $storeval = 'yes';
2835: if ($which eq 'randompick') {
2836: $storeval = $newvalue;
2837: }
2838: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2839: $storeval,
2840: $parameter_type{$which});
2841: &remember_parms($res,$which,'set',$storeval);
2842: } elsif ($oldvalue) {
2843: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2844: &remember_parms($res,$which,'del');
2845: }
2846: }
2847: }
2848: }
2849: return $haschanges;
1.329 droeschl 2850: } else {
1.484.2.59 raeburn 2851: my $haschanges = 0;
2852: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 2853:
1.484.2.29 raeburn 2854: my $which = $env{'form.changeparms'};
2855: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 2856: my $oldvalue = 0;
2857: my $newvalue = 0;
2858: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2859: if ($which eq 'randompick') {
2860: if ($current =~ /^(\d+)$/) {
2861: $oldvalue = $1;
2862: }
2863: } elsif ($current =~ /^yes$/i) {
2864: $oldvalue = 1;
2865: }
1.484.2.29 raeburn 2866: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 2867: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2868: : 1;
1.484.2.29 raeburn 2869: }
1.484.2.59 raeburn 2870: if ($oldvalue ne $newvalue) {
2871: $haschanges = 1;
2872: if ($newvalue) {
2873: my $storeval = 'yes';
2874: if ($which eq 'randompick') {
2875: $storeval = $newvalue;
2876: }
2877: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2878: $parameter_type{$which});
2879: &remember_parms($idx,$which,'set',$storeval);
2880: } else {
2881: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2882: &remember_parms($idx,$which,'del');
2883: }
2884: }
2885: return $haschanges;
1.329 droeschl 2886: }
1.484.2.59 raeburn 2887: return;
1.329 droeschl 2888: }
2889:
2890: sub handle_edit_cmd {
2891: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 2892: if ($env{'form.cmd'} eq '') {
2893: return 0;
2894: }
1.329 droeschl 2895: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2896:
2897: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2898: my ($title, $url, @rrest) = split(':', $ratstr);
2899:
1.484.2.30 raeburn 2900: if ($cmd eq 'remove') {
1.329 droeschl 2901: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2902: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2903: &Apache::lonnet::removeuploadedurl($url);
2904: } else {
2905: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2906: }
2907: splice(@LONCAPA::map::order, $idx, 1);
2908:
2909: } elsif ($cmd eq 'cut') {
2910: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2911: splice(@LONCAPA::map::order, $idx, 1);
2912:
1.344 bisitz 2913: } elsif ($cmd eq 'up'
1.329 droeschl 2914: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2915: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2916:
2917: } elsif ($cmd eq 'down'
2918: && defined($LONCAPA::map::order[$idx+1])) {
2919: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2920:
2921: } elsif ($cmd eq 'rename') {
2922: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2923: if ($comment=~/\S/) {
2924: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2925: $comment.':'.join(':', $url, @rrest);
2926: }
2927: # Devalidate title cache
2928: my $renamed_url=&LONCAPA::map::qtescape($url);
2929: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 2930:
1.329 droeschl 2931: } else {
2932: return 0;
2933: }
2934: return 1;
2935: }
2936:
2937: sub editor {
1.458 raeburn 2938: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.80 raeburn 2939: $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,
2940: $hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 2941: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2942: if ($allowed) {
2943: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2944: $is_random_order,$container) =
2945: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2946: $r->print($breadcrumbtrail);
2947: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2948: $container = 'page';
2949: } else {
2950: $container = 'sequence';
2951: }
1.484 raeburn 2952:
1.484.2.21 raeburn 2953: my $jumpto;
2954:
2955: unless ($supplementalflag) {
1.484.2.32 raeburn 2956: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 2957: }
1.484 raeburn 2958:
2959: unless ($allowed) {
2960: $randompick = -1;
2961: }
2962:
1.484.2.67 raeburn 2963: my ($errtext,$fatal);
2964: if (($folder eq '') && (!$supplementalflag)) {
2965: if (@LONCAPA::map::order) {
2966: undef(@LONCAPA::map::order);
2967: undef(@LONCAPA::map::resources);
2968: undef(@LONCAPA::map::resparms);
2969: undef(@LONCAPA::map::zombies);
2970: }
2971: $folder = 'default';
2972: $container = 'sequence';
2973: } else {
2974: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2975: $folder.'.'.$container);
2976: return $errtext if ($fatal);
2977: }
1.329 droeschl 2978:
2979: if ($#LONCAPA::map::order<1) {
2980: my $idx=&LONCAPA::map::getresidx();
2981: if ($idx<=0) { $idx=1; }
2982: $LONCAPA::map::order[0]=$idx;
2983: $LONCAPA::map::resources[$idx]='';
2984: }
1.364 bisitz 2985:
1.329 droeschl 2986: # ------------------------------------------------------------ Process commands
2987:
2988: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 2989: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 2990: # set parameters and change order
2991: &snapshotbefore();
2992:
2993: if (&update_parameter()) {
1.484.2.59 raeburn 2994: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 2995: return $errtext if ($fatal);
2996: }
2997:
2998: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2999: # change order
3000: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3001: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3002:
3003: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3004: return $errtext if ($fatal);
3005: }
1.364 bisitz 3006:
1.329 droeschl 3007: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3008: my %paste_errors;
1.484.2.26 raeburn 3009: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3010: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3011: \%paste_errors);
1.484.2.30 raeburn 3012: if (ref($pastemsgarray) eq 'ARRAY') {
3013: if (@{$pastemsgarray} > 0) {
3014: $r->print('<p class="LC_info">'.
3015: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3016: '</p>');
3017: }
1.484.2.30 raeburn 3018: }
3019: if ($lockerror) {
3020: $r->print('<p class="LC_error">'.
3021: $lockerror.
3022: '</p>');
3023: }
3024: if ($save_error ne '') {
3025: return $save_error;
3026: }
3027: if ($paste_res) {
3028: my %errortext = &Apache::lonlocal::texthash (
3029: fail => 'Storage of folder contents failed',
3030: failread => 'Reading folder contents failed',
3031: failstore => 'Storage of folder contents failed',
3032: );
3033: if ($errortext{$paste_res}) {
3034: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3035: }
1.329 droeschl 3036: }
1.484.2.7 raeburn 3037: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3038: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3039: &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".
3040: '<ul>'."\n");
3041: foreach my $key (sort(keys(%paste_errors))) {
3042: $r->print('<li>'.$key.'</li>'."\n");
3043: }
3044: $r->print('</ul></p>'."\n");
3045: }
1.484.2.30 raeburn 3046: } elsif ($env{'form.clearmarked'}) {
3047: my $output = &do_buffer_empty();
3048: if ($output) {
3049: $r->print('<p class="LC_info">'.$output.'</p>');
3050: }
3051: }
1.329 droeschl 3052:
3053: $r->print($upload_output);
3054:
1.484.2.30 raeburn 3055: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3056: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3057: my $contentchg;
1.484.2.58 raeburn 3058: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3059: $contentchg = 1;
3060: }
3061: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3062: return $errtext if ($fatal);
3063: }
1.484.2.30 raeburn 3064:
3065: # Cut, copy and/or remove multiple resources
3066: if ($env{'form.multichange'}) {
3067: my %allchecked = (
3068: cut => {},
3069: remove => {},
3070: );
3071: my $needsupdate;
3072: foreach my $which (keys(%allchecked)) {
3073: $env{'form.multi'.$which} =~ s/,$//;
3074: if ($env{'form.multi'.$which}) {
3075: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3076: if (ref($allchecked{$which}) eq 'HASH') {
3077: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3078: }
3079: }
3080: }
3081: if ($needsupdate) {
3082: my $haschanges = 0;
3083: my %curr_groups = &Apache::longroup::coursegroups();
3084: my $total = scalar(@LONCAPA::map::order) - 1;
3085: for (my $i=$total; $i>=0; $i--) {
3086: my $res = $LONCAPA::map::order[$i];
3087: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3088: $name=&LONCAPA::map::qtescape($name);
3089: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3090: next unless $url;
1.484.2.30 raeburn 3091: my %denied =
3092: &action_restrictions($coursenum,$coursedom,$url,
3093: $env{'form.folderpath'},\%curr_groups);
3094: foreach my $which (keys(%allchecked)) {
3095: next if ($denied{$which});
3096: next unless ($allchecked{$which}{$res});
3097: if ($which eq 'remove') {
3098: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3099: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3100: &Apache::lonnet::removeuploadedurl($url);
3101: } else {
3102: &LONCAPA::map::makezombie($res);
3103: }
3104: splice(@LONCAPA::map::order,$i,1);
3105: $haschanges ++;
3106: } elsif ($which eq 'cut') {
3107: &LONCAPA::map::makezombie($res);
3108: splice(@LONCAPA::map::order,$i,1);
3109: $haschanges ++;
3110: }
3111: }
3112: }
3113: if ($haschanges) {
3114: ($errtext,$fatal) =
3115: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3116: return $errtext if ($fatal);
3117: }
3118: }
3119: }
3120:
1.329 droeschl 3121: # Group import/search
3122: if ($env{'form.importdetail'}) {
3123: my @imports;
3124: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3125: if (defined($item)) {
3126: my ($name,$url,$residx)=
1.484.2.26 raeburn 3127: map { &unescape($_); } split(/\=/,$item);
3128: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3129: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3130: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3131: if ($locknotfreed) {
3132: $r->print($locknotfreed);
3133: }
3134: if ($suffix) {
1.484.2.19 raeburn 3135: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3136: } else {
3137: return $errortxt;
3138: }
1.484.2.26 raeburn 3139: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3140: my $type = $1;
3141: my ($suffix,$errortxt,$locknotfreed) =
3142: &new_timebased_suffix($coursedom,$coursenum,$type);
3143: if ($locknotfreed) {
3144: $r->print($locknotfreed);
3145: }
3146: if ($suffix) {
3147: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3148: } else {
3149: return $errortxt;
3150: }
1.484.2.27 raeburn 3151: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3152: if ($supplementalflag) {
3153: next unless ($1 eq 'supplemental');
3154: if ($folder eq 'supplemental') {
3155: next unless ($2 eq 'default');
3156: } else {
3157: next unless ($folder eq 'supplemental_'.$2);
3158: }
3159: } else {
3160: next unless ($1 eq 'docs');
3161: if ($folder eq 'default') {
3162: next unless ($2 eq 'default');
3163: } else {
3164: next unless ($folder eq 'default_'.$2);
3165: }
3166: }
1.484.2.15 raeburn 3167: }
1.329 droeschl 3168: push(@imports, [$name, $url, $residx]);
3169: }
3170: }
1.484.2.23 raeburn 3171: ($errtext,$fatal,my $fixuperrors) =
3172: &group_import($coursenum, $coursedom, $folder,$container,
3173: 'londocs',@imports);
1.329 droeschl 3174: return $errtext if ($fatal);
1.484.2.23 raeburn 3175: if ($fixuperrors) {
3176: $r->print($fixuperrors);
3177: }
1.329 droeschl 3178: }
3179: # Loading a complete map
3180: if ($env{'form.loadmap'}) {
3181: if ($env{'form.importmap'}=~/\w/) {
3182: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3183: my ($title,$url,$ext,$type)=split(/\:/,$res);
3184: my $idx=&LONCAPA::map::getresidx($url);
3185: $LONCAPA::map::resources[$idx]=$res;
3186: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3187: }
3188: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3189: $folder.'.'.$container,1);
1.329 droeschl 3190: return $errtext if ($fatal);
3191: } else {
3192: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3193:
1.329 droeschl 3194: }
3195: }
3196: &log_differences($plain);
3197: }
3198: # ---------------------------------------------------------------- End commands
3199: # ---------------------------------------------------------------- Print screen
3200: my $idx=0;
3201: my $shown=0;
3202: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3203: $r->print('<div class="LC_Box">'.
1.432 raeburn 3204: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3205: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3206: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3207: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3208: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3209: '</ol>');
1.381 bisitz 3210: if ($randompick>=0) {
3211: $r->print('<p class="LC_warning">'
3212: .&mt('Caution: this folder is set to randomly pick a subset'
3213: .' of resources. Adding or removing resources from this'
3214: .' folder will change the set of resources that the'
3215: .' students see, resulting in spurious or missing credit'
3216: .' for completed problems, not limited to ones you'
3217: .' modify. Do not modify the contents of this folder if'
3218: .' it is in active student use.')
3219: .'</p>'
3220: );
3221: }
3222: if ($is_random_order) {
3223: $r->print('<p class="LC_warning">'
3224: .&mt('Caution: this folder is set to randomly order its'
3225: .' contents. Adding or removing resources from this folder'
3226: .' will change the order of resources shown.')
3227: .'</p>'
3228: );
3229: }
3230: $r->print('</div>');
1.364 bisitz 3231: }
1.381 bisitz 3232:
1.484.2.30 raeburn 3233: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3234: %filters = (
3235: canremove => [],
3236: cancut => [],
3237: cancopy => [],
3238: hiddenresource => [],
3239: encrypturl => [],
3240: randomorder => [],
3241: randompick => [],
3242: );
3243: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3244: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3245: foreach my $res (@LONCAPA::map::order) {
3246: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3247: $name=&LONCAPA::map::qtescape($name);
3248: $url=&LONCAPA::map::qtescape($url);
3249: unless ($name) { $name=(split(/\//,$url))[-1]; }
3250: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3251: push(@allidx,$res);
3252: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3253: push(@allmapidx,$res);
3254: }
1.484.2.67 raeburn 3255:
1.381 bisitz 3256: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3257: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3258: $pathitem,$supplementalflag,$container,
1.484.2.70 raeburn 3259: \%filters,\%curr_groups,$canedit,
1.484.2.80 raeburn 3260: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3261: $idx++;
3262: $shown++;
1.329 droeschl 3263: }
1.424 onken 3264: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3265:
1.484.2.30 raeburn 3266: my $need_save;
1.484.2.67 raeburn 3267: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3268: my $toolslink;
1.484.2.67 raeburn 3269: if ($allowed) {
1.484.2.31 raeburn 3270: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3271: .&Apache::loncommon::help_open_menu('Navigation Screen',
3272: 'Navigation_Screen',undef,'RAT')
3273: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3274: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3275: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3276: .'id="LC_content_toolbar_edittoplevel" '
3277: .'class="LC_toolbarItem" '
3278: .'title="'.&mt('Supplemental Content Editor').'">'
3279: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3280: }
1.484.2.19 raeburn 3281: if ($shown) {
3282: if ($allowed) {
3283: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3284: .&Apache::loncommon::start_data_table(undef,'contentlist')
3285: .&Apache::loncommon::start_data_table_header_row()
3286: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3287: .'<th colspan="2">'.&mt('Actions').'</th>'
3288: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3289: if ($folder !~ /^supplemental/) {
3290: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3291: }
1.484.2.29 raeburn 3292: $to_show .= &Apache::loncommon::end_data_table_header_row();
3293: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3294: $lists{'canhide'} = join(',',@allidx);
3295: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3296: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3297: 'randomorder','randompick');
3298: foreach my $item (@possfilters) {
3299: if (ref($filters{$item}) eq 'ARRAY') {
3300: if (@{$filters{$item}} > 0) {
3301: $lists{$item} = join(',',@{$filters{$item}});
3302: }
3303: }
3304: }
1.484.2.29 raeburn 3305: if (@allidx > 0) {
3306: my $path;
3307: if ($env{'form.folderpath'}) {
3308: $path =
3309: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3310: }
1.484.2.30 raeburn 3311: if (@allidx > 1) {
3312: $to_show .=
3313: &Apache::loncommon::continue_data_table_row().
3314: '<td colspan="2"> </td>'.
3315: '<td>'.
1.484.2.67 raeburn 3316: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3317: '</td>'.
3318: '<td> </td>'.
3319: '<td> </td>'.
3320: '<td colspan="4">'.
1.484.2.67 raeburn 3321: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3322: '</td>'.
3323: &Apache::loncommon::end_data_table_row();
3324: $need_save = 1;
3325: }
1.484.2.29 raeburn 3326: }
3327: }
3328: $to_show .= $output.' '
1.484.2.19 raeburn 3329: .&Apache::loncommon::end_data_table()
3330: .'<br style="line-height:2px;" />'
3331: .&Apache::loncommon::end_scrollbox();
3332: } else {
3333: $to_show .= $toolslink
3334: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3335: .$output.' '
3336: .&Apache::loncommon::end_data_table();
3337: }
3338: } else {
3339: if (!$allowed) {
3340: $to_show .= $toolslink;
1.393 raeburn 3341: }
1.484.2.67 raeburn 3342: my $noresmsg;
3343: if ($allowed && $hiddentop && !$supplementalflag) {
3344: $noresmsg = &mt('Main Content Hidden');
3345: } else {
3346: $noresmsg = &mt('Currently empty');
3347: }
1.484.2.19 raeburn 3348: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3349: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3350: .$noresmsg
1.484.2.19 raeburn 3351: .'</div>'
3352: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3353: }
3354: } else {
1.484.2.19 raeburn 3355: if ($shown) {
3356: $to_show = '<div>'
3357: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3358: .$output
3359: .&Apache::loncommon::end_data_table()
3360: .'</div>';
3361: } else {
3362: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3363: .&mt('Currently empty')
1.484.2.19 raeburn 3364: .'</div>'
3365: }
1.458 raeburn 3366: }
3367: my $tid = 1;
3368: if ($supplementalflag) {
3369: $tid = 2;
1.329 droeschl 3370: }
3371: if ($allowed) {
1.484 raeburn 3372: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3373: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3374: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3375: if ($canedit) {
1.484.2.67 raeburn 3376: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3377: }
1.460 raeburn 3378: } else {
3379: $r->print($to_show);
1.329 droeschl 3380: }
3381: return;
3382: }
3383:
1.484.2.30 raeburn 3384: sub multiple_check_form {
1.484.2.67 raeburn 3385: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3386: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3387: my $disabled;
3388: unless ($canedit) {
3389: $disabled = 'disabled="disabled"';
3390: }
1.484.2.30 raeburn 3391: my $output =
3392: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3393: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3394: '<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>'.
3395: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3396: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3397: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3398: if ($caller eq 'settings') {
3399: $output .=
3400: '<table><tr>'.
3401: '<td class="LC_docs_entry_parameter">'.
3402: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3403: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3404: '</label></span></td>'.
3405: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3406: '<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 3407: '</span></td>'.
3408: '</tr>'."\n".
3409: '<tr>'.
3410: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3411: '<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 3412: '</label></span>'.
3413: '</td></tr></table>'."\n";
3414: } else {
3415: $output .=
3416: '<table><tr>'.
3417: '<td class="LC_docs_entry_parameter">'.
3418: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3419: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3420: '</label></span></td>'.
3421: '<td class="LC_docs_entry_parameter">'.
3422: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3423: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3424: '</label></span></td>'."\n".
3425: '<td class="LC_docs_entry_parameter">'.
3426: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3427: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3428: '</label></span></td>'.
3429: '</tr></table>'."\n";
3430: }
3431: $output .=
3432: '</fieldset>'.
3433: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3434: if ($caller eq 'settings') {
3435: $output .=
3436: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3437: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3438: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3439: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3440: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3441: } elsif ($caller eq 'actions') {
3442: $output .=
3443: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3444: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3445: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3446: }
3447: $output .=
3448: '</form>'.
3449: '</div>';
3450: return $output;
3451: }
3452:
1.329 droeschl 3453: sub process_file_upload {
1.484.2.36 raeburn 3454: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3455: # upload a file, if present
1.484.2.36 raeburn 3456: my $filesize = length($env{'form.uploaddoc'});
3457: if (!$filesize) {
3458: $$upload_output = '<div class="LC_error">'.
3459: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3460: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3461: $filesize).'<br />'.
3462: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3463: '</div>';
3464: return;
3465: }
3466: my $quotatype = 'unofficial';
3467: if ($crstype eq 'Community') {
3468: $quotatype = 'community';
1.484.2.51 raeburn 3469: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3470: $quotatype = 'official';
1.484.2.45 raeburn 3471: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3472: $quotatype = 'textbook';
1.484.2.36 raeburn 3473: }
3474: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3475: $filesize = int($filesize/1000); #expressed in kb
3476: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3477: $env{'form.uploaddoc.filename'},$filesize,
3478: 'upload',$quotatype);
1.484.2.36 raeburn 3479: return if ($$upload_output);
3480: }
1.440 raeburn 3481: my ($parseaction,$showupload,$nextphase,$mimetype);
3482: if ($env{'form.parserflag'}) {
1.329 droeschl 3483: $parseaction = 'parse';
3484: }
3485: my $folder=$env{'form.folder'};
3486: if ($folder eq '') {
3487: $folder='default';
3488: }
3489: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3490: my $errtext='';
3491: my $fatal=0;
3492: my $container='sequence';
1.484.2.19 raeburn 3493: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3494: $container='page';
3495: }
3496: ($errtext,$fatal)=
1.484.2.27 raeburn 3497: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3498: if ($#LONCAPA::map::order<1) {
3499: $LONCAPA::map::order[0]=1;
3500: $LONCAPA::map::resources[1]='';
3501: }
3502: my $destination = 'docs/';
3503: if ($folder =~ /^supplemental/) {
3504: $destination = 'supplemental/';
3505: }
3506: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3507: $destination .= 'default/';
3508: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3509: $destination .= $2.'/';
3510: }
1.484.2.27 raeburn 3511: if ($fatal) {
3512: $$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>';
3513: return;
3514: }
1.440 raeburn 3515: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3516: my $newidx=&LONCAPA::map::getresidx();
3517: $destination .= $newidx;
1.439 raeburn 3518: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3519: $parseaction,$allfiles,
1.440 raeburn 3520: $codebase,undef,undef,undef,undef,
3521: undef,undef,\$mimetype);
3522: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3523: my $stored = $1;
3524: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3525: $stored.'</span>').'</p>';
3526: } else {
3527: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3528:
1.457 raeburn 3529: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3530: return;
3531: }
1.329 droeschl 3532: my $ext='false';
3533: if ($url=~m{^http://}) { $ext='true'; }
3534: $url = &LONCAPA::map::qtunescape($url);
3535: my $comment=$env{'form.comment'};
3536: $comment = &LONCAPA::map::qtunescape($comment);
3537: if ($folder=~/^supplemental/) {
3538: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3539: $env{'user.domain'}.'___&&&___'.$comment;
3540: }
3541:
3542: $LONCAPA::map::resources[$newidx]=
3543: $comment.':'.$url.':'.$ext.':normal:res';
3544: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3545: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3546: $folder.'.'.$container,1);
1.329 droeschl 3547: if ($fatal) {
1.457 raeburn 3548: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3549: return;
1.329 droeschl 3550: } else {
1.440 raeburn 3551: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3552: $$upload_output = $showupload;
1.384 raeburn 3553: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3554: if ($total_embedded > 0) {
1.440 raeburn 3555: my $uploadphase = 'upload_embedded';
3556: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3557: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3558: my ($embedded,$num) =
3559: &Apache::loncommon::ask_for_embedded_content(
3560: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3561: if ($embedded) {
3562: if ($num) {
3563: $$upload_output .=
3564: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3565: $nextphase = $uploadphase;
3566: } else {
3567: $$upload_output .= $embedded;
3568: }
3569: } else {
3570: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3571: }
1.329 droeschl 3572: } else {
1.440 raeburn 3573: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3574: }
1.457 raeburn 3575: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3576: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3577: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3578: $nextphase = 'decompress_uploaded';
3579: my $position = scalar(@LONCAPA::map::order)-1;
3580: my $noextract = &return_to_editor();
3581: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3582: my %archiveitems = (
3583: folderpath => $env{'form.folderpath'},
3584: cmd => $nextphase,
3585: newidx => $newidx,
3586: position => $position,
3587: phase => $nextphase,
1.477 raeburn 3588: comment => $comment,
1.480 raeburn 3589: );
3590: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3591: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3592: $$upload_output = $showupload.
3593: &Apache::loncommon::decompress_form($mimetype,
3594: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3595: \%archiveitems,\@current);
1.329 droeschl 3596: }
3597: }
3598: }
1.440 raeburn 3599: return $nextphase;
1.329 droeschl 3600: }
3601:
1.480 raeburn 3602: sub get_dir_list {
3603: my ($url,$coursenum,$coursedom,$newidx) = @_;
3604: my ($destination,$dir_root) = &embedded_destination();
3605: my ($dirlistref,$listerror) =
3606: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3607: my @dir_lines;
3608: my $dirptr=16384;
3609: if (ref($dirlistref) eq 'ARRAY') {
3610: foreach my $dir_line (sort
3611: {
3612: my ($afile)=split('&',$a,2);
3613: my ($bfile)=split('&',$b,2);
3614: return (lc($afile) cmp lc($bfile));
3615: } (@{$dirlistref})) {
3616: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3617: $filename =~ s/\s+$//;
3618: next if ($filename =~ /^\.\.?$/);
3619: my $isdir = 0;
3620: if ($dirptr&$testdir) {
3621: $isdir = 1;
3622: }
3623: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3624: }
3625: }
3626: return @dir_lines;
3627: }
3628:
1.329 droeschl 3629: sub is_supplemental_title {
3630: my ($title) = @_;
3631: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3632: }
3633:
3634: # --------------------------------------------------------------- An entry line
3635:
3636: sub entryline {
1.484.2.12 raeburn 3637: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3638: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.80 raeburn 3639: $canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3640: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3641: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3642: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3643: } else {
3644: $title=&HTML::Entities::encode($title,'"<>&\'');
3645: $renametitle=$title;
3646: $foldertitle=$title;
3647: }
3648:
1.484.2.67 raeburn 3649: my ($disabled,$readonly,$js_lt);
3650: unless ($canedit) {
3651: $disabled = 'disabled="disabled"';
3652: $readonly = 1;
3653: }
3654:
1.329 droeschl 3655: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3656:
1.329 droeschl 3657: $renametitle=~s/\\/\\\\/g;
3658: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3659: $renametitle=~s/"/%22/g;
1.329 droeschl 3660: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3661: $oldtitle = $renametitle;
3662: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3663: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3664: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3665: # Edit commands
1.484.2.28 raeburn 3666: my ($esc_path, $path, $symb);
1.329 droeschl 3667: if ($env{'form.folderpath'}) {
3668: $esc_path=&escape($env{'form.folderpath'});
3669: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3670: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3671: }
1.484.2.16 raeburn 3672: my $isexternal;
1.484.2.19 raeburn 3673: if ($residx) {
1.484.2.12 raeburn 3674: my $currurl = $url;
3675: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3676: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3677: $isexternal = 1;
3678: }
1.484.2.19 raeburn 3679: if (!$supplementalflag) {
3680: my $path = 'uploaded/'.
3681: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3682: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3683: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3684: $residx,
3685: &Apache::lonnet::declutter($currurl));
3686: }
1.484.2.12 raeburn 3687: }
1.484.2.30 raeburn 3688: my ($renamelink,%lt,$ishash);
3689: if (ref($filtersref) eq 'HASH') {
3690: $ishash = 1;
3691: }
3692:
1.329 droeschl 3693: if ($allowed) {
1.484.2.30 raeburn 3694: $form_start = '
3695: <form action="/adm/coursedocs" method="post">
3696: ';
3697: $form_common=(<<END);
3698: <input type="hidden" name="folderpath" value="$path" />
3699: <input type="hidden" name="symb" value="$symb" />
3700: END
3701: $form_param=(<<END);
3702: <input type="hidden" name="setparms" value="$orderidx" />
3703: <input type="hidden" name="changeparms" value="0" />
3704: END
3705: $form_end = '</form>';
3706:
1.329 droeschl 3707: my $incindex=$index+1;
3708: my $selectbox='';
1.471 raeburn 3709: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3710: ((split(/\:/,
1.344 bisitz 3711: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3712: ne '') &&
1.329 droeschl 3713: ((split(/\:/,
1.344 bisitz 3714: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3715: ne '')) {
3716: $selectbox=
3717: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3718: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3719: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3720: if ($i==$incindex) {
1.358 bisitz 3721: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3722: } else {
3723: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3724: }
3725: }
3726: $selectbox.='</select>';
3727: }
1.484.2.12 raeburn 3728: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3729: 'up' => 'Move Up',
3730: 'dw' => 'Move Down',
3731: 'rm' => 'Remove',
3732: 'ct' => 'Cut',
3733: 'rn' => 'Rename',
1.484.2.12 raeburn 3734: 'cp' => 'Copy',
3735: 'ex' => 'External Resource',
3736: 'ed' => 'Edit',
3737: 'pr' => 'Preview',
3738: 'sv' => 'Save',
3739: 'ul' => 'URL',
1.484.2.67 raeburn 3740: 'ti' => 'Title',
3741: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3742: );
1.484.2.30 raeburn 3743: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3744: $env{'form.folderpath'},
3745: $currgroups);
1.484.2.19 raeburn 3746: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3747: my $skip_confirm = 0;
1.484.2.63 raeburn 3748: my $confirm_removal = 0;
1.329 droeschl 3749: if ( $folder =~ /^supplemental/
3750: || ($url =~ m{( /smppg$
3751: |/syllabus$
3752: |/aboutme$
3753: |/navmaps$
3754: |/bulletinboard$
1.484.2.16 raeburn 3755: |\.html$)}x)
1.484.2.19 raeburn 3756: || $isexternal) {
1.329 droeschl 3757: $skip_confirm = 1;
3758: }
1.484.2.63 raeburn 3759: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3760: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3761: $confirm_removal = 1;
3762: }
1.484.2.19 raeburn 3763:
1.484.2.30 raeburn 3764: if ($denied{'copy'}) {
3765: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3766: <span style="visibility: hidden;">$lt{'cp'}</span>
3767: ENDCOPY
3768: } else {
1.484.2.30 raeburn 3769: my $formname = 'edit_copy_'.$orderidx;
3770: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3771: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3772: <form name="$formname" method="post" action="/adm/coursedocs">
3773: $form_common
1.484.2.67 raeburn 3774: <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 3775: $form_end
1.329 droeschl 3776: ENDCOPY
1.484.2.30 raeburn 3777: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3778: push(@{$filtersref->{'cancopy'}},$orderidx);
3779: }
1.329 droeschl 3780: }
1.484.2.30 raeburn 3781: if ($denied{'cut'}) {
1.484.2.16 raeburn 3782: $cutlink=(<<ENDCUT);
3783: <span style="visibility: hidden;">$lt{'ct'}</span>
3784: ENDCUT
3785: } else {
1.484.2.30 raeburn 3786: my $formname = 'edit_cut_'.$orderidx;
3787: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3788: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3789: <form name="$formname" method="post" action="/adm/coursedocs">
3790: $form_common
3791: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3792: <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 3793: $form_end
1.329 droeschl 3794: ENDCUT
1.484.2.30 raeburn 3795: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3796: push(@{$filtersref->{'cancut'}},$orderidx);
3797: }
1.329 droeschl 3798: }
1.484.2.30 raeburn 3799: if ($denied{'remove'}) {
1.484.2.16 raeburn 3800: $removelink=(<<ENDREM);
3801: <span style="visibility: hidden;">$lt{'rm'}</a>
3802: ENDREM
3803: } else {
1.484.2.30 raeburn 3804: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3805: 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 3806: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3807: <form name="$formname" method="post" action="/adm/coursedocs">
3808: $form_common
3809: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3810: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3811: <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 3812: $form_end
1.484.2.9 raeburn 3813: ENDREM
1.484.2.30 raeburn 3814: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3815: push(@{$filtersref->{'canremove'}},$orderidx);
3816: }
1.484.2.9 raeburn 3817: }
1.484.2.35 raeburn 3818: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3819: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3820: ENDREN
1.484.2.67 raeburn 3821: my ($uplink,$downlink);
3822: if ($canedit) {
3823: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3824: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3825: } else {
3826: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3827: $downlink = $uplink;
3828: }
1.329 droeschl 3829: $line.=(<<END);
3830: <td>
1.379 bisitz 3831: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3832: <a href="$uplink">
1.484.2.12 raeburn 3833: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3834: </a>
3835: </div>
3836: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3837: <a href="$downlink">
1.484.2.12 raeburn 3838: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3839: </a>
3840: </div>
1.329 droeschl 3841: </td>
3842: <td>
3843: $form_start
1.484.2.30 raeburn 3844: $form_param
1.478 raeburn 3845: $form_common
1.329 droeschl 3846: $selectbox
3847: $form_end
3848: </td>
1.484.2.30 raeburn 3849: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3850: $removelink
1.329 droeschl 3851: $cutlink
3852: $copylink
3853: </td>
3854: END
3855: }
3856: # Figure out what kind of a resource this is
3857: my ($extension)=($url=~/\.(\w+)$/);
3858: my $uploaded=($url=~/^\/*uploaded\//);
3859: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3860: my $isfolder;
3861: my $ispage;
3862: my $containerarg;
1.484.2.67 raeburn 3863: my $folderurl;
1.329 droeschl 3864: if ($uploaded) {
1.472 raeburn 3865: if (($extension eq 'sequence') || ($extension eq 'page')) {
3866: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3867: $containerarg = $1;
1.472 raeburn 3868: if ($extension eq 'sequence') {
3869: $icon=$iconpath.'navmap.folder.closed.gif';
3870: $isfolder=1;
3871: } else {
3872: $icon=$iconpath.'page.gif';
3873: $ispage=1;
3874: }
1.484.2.67 raeburn 3875: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3876: if ($allowed) {
3877: $url='/adm/coursedocs?';
3878: } else {
3879: $url='/adm/supplemental?';
3880: }
1.329 droeschl 3881: } else {
3882: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3883: }
3884: }
1.364 bisitz 3885:
1.484.2.70 raeburn 3886: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3887: my $orig_url = $url;
1.340 raeburn 3888: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87! raeburn 3889: if ($container eq 'page') {
! 3890: $url=~s{^http(|s)(:|:)//}{/ext/};
! 3891: } else {
! 3892: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
! 3893: }
1.484.2.12 raeburn 3894: if (!$supplementalflag && $residx && $symb) {
3895: if ((!$isfolder) && (!$ispage)) {
3896: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.87! raeburn 3897: if (($url =~ m{^ext/}) && ($container eq 'page')) {
! 3898: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
! 3899: } else {
! 3900: $url=&Apache::lonnet::clutter($url);
! 3901: }
1.484.2.12 raeburn 3902: if ($url=~/^\/*uploaded\//) {
3903: $url=~/\.(\w+)$/;
3904: my $embstyle=&Apache::loncommon::fileembstyle($1);
3905: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3906: $url='/adm/wrapper'.$url;
3907: } elsif ($embstyle eq 'ssi') {
3908: #do nothing with these
3909: } elsif ($url!~/\.(sequence|page)$/) {
3910: $url='/adm/coursedocs/showdoc'.$url;
3911: }
1.484.2.70 raeburn 3912: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
3913: my $wrapped = $1;
3914: my $exturl = $2;
1.484.2.87! raeburn 3915: if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 3916: $url='/adm/wrapper'.$url;
3917: }
3918: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
3919: $nomodal = 1;
3920: }
3921: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3922: if (($ENV{'SERVER_PORT'} == 443) &&
3923: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 3924: unless (&Apache::lonnet::uses_sts()) {
3925: $url .= '?usehttp=1';
3926: }
1.484.2.70 raeburn 3927: $nomodal = 1;
3928: }
1.484.2.19 raeburn 3929: }
1.484.2.12 raeburn 3930: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3931: my $shownsymb = $symb;
3932: if ($isexternal) {
3933: if ($url =~ /^([^#]+)#([^#]+)$/) {
3934: $url = $1;
3935: $anchor = $2;
1.484.2.80 raeburn 3936: my $escan = &escape('#');
3937: $shownsymb =~ s/^([^\#]+)#([^\#]+)$/$1$escan$2/;
1.484.2.66 raeburn 3938: }
1.484.2.87! raeburn 3939: if ($container eq 'page') {
! 3940: $url = &Apache::lonnet::clutter($url);
! 3941: }
1.484.2.66 raeburn 3942: }
1.484.2.67 raeburn 3943: unless ($env{'request.role.adv'}) {
3944: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3945: $url = '';
3946: }
3947: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3948: $url = '';
3949: $hiddenres = 1;
3950: }
3951: }
3952: if ($url ne '') {
1.484.2.75 raeburn 3953: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3954: }
3955: } elsif (!$env{'request.role.adv'}) {
3956: my $checkencrypt;
3957: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3958: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3959: $checkencrypt = 1;
1.484.2.70 raeburn 3960: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3961: unless (ref($$navmapref)) {
3962: $$navmapref = Apache::lonnavmaps::navmap->new();
3963: }
3964: if (ref($$navmapref)) {
3965: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
3966: $checkencrypt = 1;
3967: }
3968: }
3969: }
3970: if ($checkencrypt) {
3971: my $shownsymb = &Apache::lonenc::encrypted($symb);
3972: my $shownurl = &Apache::lonenc::encrypted($url);
3973: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 3974: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3975: if ($env{'request.enc'} ne '') {
3976: delete($env{'request.enc'});
3977: }
3978: } else {
3979: $url='';
3980: }
3981: } else {
3982: $url='';
3983: }
1.484.2.12 raeburn 3984: } else {
3985: $url='';
3986: }
1.484.2.19 raeburn 3987: }
1.484.2.66 raeburn 3988: } elsif ($supplementalflag) {
3989: if ($isexternal) {
3990: if ($url =~ /^([^#]+)#([^#]+)$/) {
3991: $url = $1;
3992: $anchor = $2;
1.484.2.70 raeburn 3993: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.80 raeburn 3994: unless (&Apache::lonnet::uses_sts()) {
3995: if ($hostname ne '') {
3996: $url = 'http://'.$hostname.$url;
3997: }
3998: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
3999: }
1.484.2.70 raeburn 4000: $nomodal = 1;
4001: }
4002: }
4003: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4004: if (($ENV{'SERVER_PORT'} == 443) &&
4005: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 4006: unless (&Apache::lonnet::uses_sts()) {
4007: if ($hostname ne '') {
4008: $url = 'http://'.$hostname.$url;
4009: }
4010: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4011: }
1.484.2.70 raeburn 4012: $nomodal = 1;
1.484.2.66 raeburn 4013: }
4014: }
1.329 droeschl 4015: }
1.484.2.67 raeburn 4016: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4017: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4018: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4019: my $foldername=&escape($foldertitle);
4020: my $folderpath=$env{'form.folderpath'};
4021: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4022: if (!$allowed && $supplementalflag) {
4023: $folderpath.=$containerarg.'&'.$foldername;
4024: $url.='folderpath='.&escape($folderpath);
4025: } else {
4026: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4027: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4028: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4029: 'parameter_randomorder'))[0]=~/^yes$/i);
4030: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4031: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4032: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4033: 'parameter_encrypturl'))[0]=~/^yes$/i);
4034: unless ($hiddenmap) {
1.484.2.70 raeburn 4035: if (ref($navmapref)) {
4036: unless (ref($$navmapref)) {
4037: $$navmapref = Apache::lonnavmaps::navmap->new();
4038: }
4039: if (ref($$navmapref)) {
4040: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4041: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4042: unless (@resources) {
4043: $hiddenmap = 1;
4044: unless ($env{'request.role.adv'}) {
4045: $url = '';
4046: $hiddenfolder = 1;
4047: }
1.484.2.67 raeburn 4048: }
4049: }
4050: }
4051: }
4052: }
4053: unless ($encryptmap) {
1.484.2.70 raeburn 4054: if ((ref($navmapref)) && (ref($$navmapref))) {
4055: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4056: $encryptmap = 1;
4057: }
1.484.2.67 raeburn 4058: }
4059: }
4060:
4061: # Append randompick number, hidden, and encrypted with ":" to foldername,
4062: # so it gets transferred between levels
4063: $folderpath.=$containerarg.'&'.$foldername.
4064: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4065: unless ($url eq '') {
4066: $url.='folderpath='.&escape($folderpath);
4067: }
1.484.2.19 raeburn 4068: my $rpckchk;
4069: if ($rpicknum) {
4070: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4071: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4072: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4073: }
1.484.2.19 raeburn 4074: }
1.484.2.29 raeburn 4075: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4076: $rand_pick_text =
1.478 raeburn 4077: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4078: $form_param."\n".
1.478 raeburn 4079: $form_common."\n".
1.484.2.67 raeburn 4080: '<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 4081: if ($rpicknum ne '') {
4082: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4083: }
1.484.2.29 raeburn 4084: $rand_pick_text .= '</span></span>'.
4085: $form_end;
1.484.2.30 raeburn 4086: my $ro_set;
1.484.2.67 raeburn 4087: if ($randorder) {
1.484.2.30 raeburn 4088: $ro_set = 'checked="checked"';
4089: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4090: push(@{$filtersref->{'randomorder'}},$orderidx);
4091: }
4092: }
1.484.2.41 raeburn 4093: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4094: $rand_order_text =
1.484.2.29 raeburn 4095: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4096: $form_param."\n".
1.484.2.29 raeburn 4097: $form_common."\n".
1.484.2.67 raeburn 4098: '<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 4099: $form_end;
1.484.2.19 raeburn 4100: }
1.484.2.18 raeburn 4101: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 4102: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4103: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4104: if ($title) {
4105: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4106: }
4107: if ($isexternal && $orderidx) {
4108: $url .= '&idx='.$orderidx;
4109: }
1.484.2.66 raeburn 4110: if ($anchor ne '') {
4111: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4112: }
1.329 droeschl 4113: }
1.484.2.19 raeburn 4114: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4115: if ($allowed) {
1.484.2.19 raeburn 4116: my $fileloc =
1.484.2.12 raeburn 4117: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4118: if ($isexternal) {
4119: ($editlink,$extresform) =
1.484.2.67 raeburn 4120: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4121: undef,undef,undef,$disabled);
1.484.2.19 raeburn 4122: } elsif (!$isfolder && !$ispage) {
4123: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4124: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4125: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4126: my $suppanchor;
4127: if ($supplementalflag) {
4128: $suppanchor = $anchor;
4129: }
1.484.2.19 raeburn 4130: my $jscall =
1.484.2.12 raeburn 4131: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4132: $switchserver,
1.484.2.14 raeburn 4133: $forceedit,
1.484.2.19 raeburn 4134: undef,$symb,
4135: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4136: $renametitle,$hostname,
4137: '','',1,$suppanchor);
1.484.2.12 raeburn 4138: if ($jscall) {
1.484.2.19 raeburn 4139: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4140: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4141: }
4142: }
4143: }
1.484.2.19 raeburn 4144: $tdalign = ' align="right" valign="top"';
4145: $tdwidth = ' width="80%"';
1.329 droeschl 4146: }
1.408 raeburn 4147: my $reinit;
4148: if ($crstype eq 'Community') {
4149: $reinit = &mt('(re-initialize community to access)');
4150: } else {
4151: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4152: }
4153: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4154: my $link;
1.472 raeburn 4155: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4156: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4157: } elsif ($url) {
1.484.2.66 raeburn 4158: if ($anchor ne '') {
4159: if ($supplementalflag) {
4160: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4161: } else {
4162: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4163: }
4164: }
1.484.2.80 raeburn 4165:
4166: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4167: $link = 'http://'.$hostname.$url;
4168: } else {
4169: $link = $url;
4170: }
4171: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4172: if ($nomodal) {
4173: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4174: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4175: } else {
4176: $line.=&Apache::loncommon::modal_link($link,
4177: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4178: }
1.469 www 4179: } else {
4180: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4181: }
1.484.2.19 raeburn 4182: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4183: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4184: $line.='<a href="'.$url.'">'.$title.'</a>';
4185: } elsif ($url) {
1.484.2.70 raeburn 4186: if ($nomodal) {
4187: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4188: $title.'</a>';
4189: } else {
4190: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4191: }
1.484.2.67 raeburn 4192: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4193: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4194: } else {
4195: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4196: }
1.484.2.19 raeburn 4197: $line.="$extresform</td>";
1.478 raeburn 4198: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4199: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4200: if (($allowed) && ($folder!~/^supplemental/)) {
4201: my %lt=&Apache::lonlocal::texthash(
4202: 'hd' => 'Hidden',
4203: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4204: my ($enctext,$hidtext);
4205: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4206: $enctext = ' checked="checked"';
4207: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4208: push(@{$filtersref->{'encrypturl'}},$orderidx);
4209: }
4210: }
4211: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4212: $hidtext = ' checked="checked"';
4213: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4214: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4215: }
4216: }
1.484.2.29 raeburn 4217: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4218: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4219: $line.=(<<ENDPARMS);
4220: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4221: <form action="/adm/coursedocs" method="post" name="$formhidden">
4222: $form_param
1.478 raeburn 4223: $form_common
1.484.2.67 raeburn 4224: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4225: $form_end
1.458 raeburn 4226: <br />
1.484.2.29 raeburn 4227: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4228: $form_param
1.478 raeburn 4229: $form_common
1.484.2.67 raeburn 4230: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4231: $form_end
4232: </td>
1.478 raeburn 4233: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4234: $rand_order_text</td>
1.329 droeschl 4235: ENDPARMS
4236: }
1.379 bisitz 4237: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4238: return $line;
4239: }
4240:
1.484.2.30 raeburn 4241: sub action_restrictions {
4242: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4243: my %denied = (
4244: cut => 0,
4245: copy => 0,
4246: remove => 0,
4247: );
4248: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4249: # no copy for published maps
4250: $denied{'copy'} = 1;
1.484.2.82 raeburn 4251: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4252: unless ($1 eq 'simpleproblem') {
4253: $denied{'copy'} = 1;
4254: }
4255: $denied{'cut'} = 1;
1.484.2.30 raeburn 4256: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4257: if ($folderpath =~ /^default&[^\&]+$/) {
4258: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4259: $denied{'remove'} = 1;
4260: }
4261: $denied{'cut'} = 1;
4262: $denied{'copy'} = 1;
4263: }
4264: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4265: my $group = $1;
4266: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4267: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4268: $denied{'remove'} = 1;
4269: }
4270: }
4271: $denied{'cut'} = 1;
4272: $denied{'copy'} = 1;
4273: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4274: my $group = $1;
4275: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4276: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4277: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4278: if (keys(%groupsettings) > 0) {
4279: $denied{'remove'} = 1;
4280: }
4281: $denied{'cut'} = 1;
4282: $denied{'copy'} = 1;
4283: }
4284: }
4285: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4286: my $group = $1;
4287: if ($url =~ /group_boards_\Q$group\E/) {
4288: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4289: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4290: if (keys(%groupsettings) > 0) {
4291: if (ref($groupsettings{'functions'}) eq 'HASH') {
4292: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4293: $denied{'remove'} = 1;
4294: }
4295: }
4296: }
4297: $denied{'cut'} = 1;
4298: $denied{'copy'} = 1;
4299: }
4300: }
4301: }
4302: return %denied;
4303: }
4304:
1.484.2.26 raeburn 4305: sub new_timebased_suffix {
1.484.2.30 raeburn 4306: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4307: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4308: if ($type eq 'paste') {
4309: $prefix = $type;
4310: $namespace = 'courseeditor';
1.484.2.56 raeburn 4311: $idtype = 'addcode';
1.484.2.30 raeburn 4312: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4313: $prefix = 'docs';
4314: if ($area eq 'supplemental') {
4315: $prefix = 'supp';
4316: }
4317: $prefix .= $container;
4318: $namespace = 'uploadedmaps';
4319: } else {
4320: $prefix = $type;
4321: $namespace = 'templated';
1.484.2.15 raeburn 4322: }
4323: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4324: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4325: if (!$suffix) {
1.484.2.30 raeburn 4326: if ($type eq 'paste') {
4327: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4328: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4329: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4330: } elsif ($type eq 'smppg') {
4331: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4332: } else {
1.484.2.42 raeburn 4333: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4334: }
1.484.2.15 raeburn 4335: if ($error) {
4336: $errtext .= '<br />'.$error;
4337: }
4338: }
4339: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4340: $locknotfreed =
4341: '<div class="LC_error">'.
4342: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4343: if ($type eq 'paste') {
1.484.2.57 raeburn 4344: if ($freedlock eq 'nolock') {
4345: $locknotfreed =
4346: '<div class="LC_error">'.
4347: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4348:
1.484.2.60 raeburn 4349: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4350: } else {
4351: $locknotfreed .=
4352: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4353: }
1.484.2.30 raeburn 4354: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4355: $locknotfreed .=
4356: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4357: } elsif ($type eq 'smppg') {
4358: $locknotfreed .=
4359: &mt('This will prevent creation of additional simple pages in this course.');
4360: } else {
4361: $locknotfreed .=
1.484.2.42 raeburn 4362: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4363: }
1.484.2.30 raeburn 4364: unless ($type eq 'paste') {
4365: $locknotfreed .=
1.484.2.38 raeburn 4366: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4367: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4368: }
4369: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4370: }
4371: return ($suffix,$errtext,$locknotfreed);
4372: }
4373:
1.329 droeschl 4374: =pod
4375:
4376: =item tiehash()
4377:
4378: tie the hash
4379:
4380: =cut
4381:
4382: sub tiehash {
4383: my ($mode)=@_;
4384: $hashtied=0;
4385: if ($env{'request.course.fn'}) {
4386: if ($mode eq 'write') {
4387: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4388: &GDBM_WRCREAT(),0640)) {
4389: $hashtied=2;
4390: }
4391: } else {
4392: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4393: &GDBM_READER(),0640)) {
4394: $hashtied=1;
4395: }
4396: }
1.364 bisitz 4397: }
1.329 droeschl 4398: }
4399:
4400: sub untiehash {
4401: if ($hashtied) { untie %hash; }
4402: $hashtied=0;
4403: return OK;
4404: }
4405:
4406:
4407:
4408:
4409: sub checkonthis {
1.484.2.78 raeburn 4410: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4411: $url=&unescape($url);
4412: $alreadyseen{$url}=1;
4413: $r->rflush();
4414: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4415: $r->print("\n<br />");
4416: if ($level==0) {
4417: $r->print("<br />");
4418: }
4419: for (my $i=0;$i<=$level*5;$i++) {
4420: $r->print(' ');
4421: }
4422: $r->print('<a href="'.$url.'" target="cat">'.
4423: ($title?$title:$url).'</a> ');
4424: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4425: my $updated;
4426: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4427: ($url !~ /\.\d+\.\w+$/)) {
4428: $updated = &Apache::lonnet::remove_stale_resfile($url);
4429: }
1.329 droeschl 4430: my $result=&Apache::lonnet::repcopy(
4431: &Apache::lonnet::filelocation('',$url));
4432: if ($result eq 'ok') {
4433: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4434: if ($updated) {
4435: $r->print('<br />');
4436: for (my $i=0;$i<=$level*5;$i++) {
4437: $r->print(' ');
4438: }
4439: $r->print('- '.&mt('Outdated copy removed'));
4440: }
1.329 droeschl 4441: $r->rflush();
4442: &Apache::lonnet::countacc($url);
4443: $url=~/\.(\w+)$/;
4444: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4445: $r->print('<br />');
4446: $r->rflush();
4447: for (my $i=0;$i<=$level*5;$i++) {
4448: $r->print(' ');
4449: }
4450: $r->print('- '.&mt('Rendering:').' ');
4451: my ($errorcount,$warningcount)=split(/:/,
4452: &Apache::lonnet::ssi_body($url,
4453: ('grade_target'=>'web',
4454: 'return_only_error_and_warning_counts' => 1)));
4455: if (($errorcount) ||
4456: ($warningcount)) {
4457: if ($errorcount) {
1.369 bisitz 4458: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4459: &mt('[quant,_1,error]',$errorcount).'</span>');
4460: }
4461: if ($warningcount) {
4462: $r->print('<span class="LC_warning">'.
4463: &mt('[quant,_1,warning]',$warningcount).'</span>');
4464: }
4465: } else {
4466: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4467: }
4468: $r->rflush();
4469: }
4470: my $dependencies=
4471: &Apache::lonnet::metadata($url,'dependencies');
4472: foreach my $dep (split(/\,/,$dependencies)) {
4473: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4474: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4475: }
4476: }
4477: } elsif ($result eq 'unavailable') {
4478: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4479: } elsif ($result eq 'not_found') {
4480: unless ($url=~/\$/) {
1.484.2.19 raeburn 4481: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4482: } else {
1.366 bisitz 4483: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4484: }
4485: } else {
4486: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4487: }
1.484.2.78 raeburn 4488: if (($updated) && ($result ne 'ok')) {
4489: $r->print('<br />'.&mt('Outdated copy removed'));
4490: }
1.329 droeschl 4491: }
4492: }
4493: }
4494:
4495:
4496:
4497: =pod
4498:
4499: =item list_symbs()
4500:
1.484.2.3 raeburn 4501: List Content Identifiers
1.329 droeschl 4502:
4503: =cut
4504:
4505: sub list_symbs {
4506: my ($r) = @_;
4507:
1.408 raeburn 4508: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4509: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4510: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4511: $r->print(&startContentScreen('tools'));
1.329 droeschl 4512: my $navmap = Apache::lonnavmaps::navmap->new();
4513: if (!defined($navmap)) {
4514: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4515: '<div class="LC_error">'.
4516: &mt('Unable to retrieve information about course contents').
4517: '</div>');
1.408 raeburn 4518: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4519: } else {
1.484 raeburn 4520: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4521: &Apache::loncommon::start_data_table().
4522: &Apache::loncommon::start_data_table_header_row().
4523: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4524: &Apache::loncommon::end_data_table_header_row()."\n");
4525: my $count;
1.329 droeschl 4526: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4527: $r->print(&Apache::loncommon::start_data_table_row().
4528: '<td>'.$res->compTitle().'</td>'.
4529: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4530: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4531: $count ++;
4532: }
4533: if (!$count) {
4534: $r->print(&Apache::loncommon::start_data_table_row().
4535: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4536: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4537: }
1.484 raeburn 4538: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4539: }
1.484.2.19 raeburn 4540: $r->print(&endContentScreen());
1.329 droeschl 4541: }
4542:
1.484.2.78 raeburn 4543: sub contentverifyform {
4544: my ($r) = @_;
4545: my $crstype = &Apache::loncommon::course_type();
4546: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4547: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4548: $r->print(&startContentScreen('tools'));
4549: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4550: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4551: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4552: ' <span class="LC_nobreak">'.
4553: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4554: &mt('No').'</label>'.(' 'x2).
4555: '<label><input type="radio" name="checkstale" value="1" />'.
4556: &mt('Yes').'</label></span></p><p>'.
4557: '<input type="submit" value="'.&mt('Verify content').' "/>'.
4558: '<input type="hidden" value="1" name="tools" />'.
4559: '<input type="hidden" value="1" name="verify" /></p></form>');
4560: $r->print(&endContentScreen());
4561: return;
4562: }
1.329 droeschl 4563:
4564: sub verifycontent {
1.484.2.78 raeburn 4565: my ($r,$checkstale) = @_;
1.408 raeburn 4566: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4567: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4568: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4569: $r->print(&startContentScreen('tools'));
4570: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4571: $hashtied=0;
4572: undef %alreadyseen;
4573: %alreadyseen=();
4574: &tiehash();
1.484 raeburn 4575:
1.329 droeschl 4576: foreach my $key (keys(%hash)) {
4577: if ($hash{$key}=~/\.(page|sequence)$/) {
4578: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4579: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4580: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4581: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4582: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4583: }
4584: }
4585: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4586: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4587: }
4588: }
4589: &untiehash();
1.442 www 4590: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4591: $r->print(&endContentScreen());
1.329 droeschl 4592: }
4593:
4594:
4595: sub devalidateversioncache {
4596: my $src=shift;
4597: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4598: &Apache::lonnet::clutter($src));
4599: }
4600:
4601: sub checkversions {
1.484.2.67 raeburn 4602: my ($r,$canedit) = @_;
1.408 raeburn 4603: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4604: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4605: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4606: $r->print(&startContentScreen('tools'));
1.442 www 4607:
1.329 droeschl 4608: my $header='';
4609: my $startsel='';
4610: my $monthsel='';
4611: my $weeksel='';
4612: my $daysel='';
4613: my $allsel='';
4614: my %changes=();
4615: my $starttime=0;
4616: my $haschanged=0;
4617: my %setversions=&Apache::lonnet::dump('resourceversions',
4618: $env{'course.'.$env{'request.course.id'}.'.domain'},
4619: $env{'course.'.$env{'request.course.id'}.'.num'});
4620:
4621: $hashtied=0;
4622: &tiehash();
1.484.2.67 raeburn 4623: if ($canedit) {
4624: my %newsetversions=();
4625: if ($env{'form.setmostrecent'}) {
4626: $haschanged=1;
4627: foreach my $key (keys(%hash)) {
4628: if ($key=~/^ids\_(\/res\/.+)$/) {
4629: $newsetversions{$1}='mostrecent';
4630: &devalidateversioncache($1);
4631: }
1.329 droeschl 4632: }
1.484.2.67 raeburn 4633: } elsif ($env{'form.setcurrent'}) {
4634: $haschanged=1;
4635: foreach my $key (keys(%hash)) {
4636: if ($key=~/^ids\_(\/res\/.+)$/) {
4637: my $getvers=&Apache::lonnet::getversion($1);
4638: if ($getvers>0) {
4639: $newsetversions{$1}=$getvers;
4640: &devalidateversioncache($1);
4641: }
4642: }
1.329 droeschl 4643: }
1.484.2.67 raeburn 4644: } elsif ($env{'form.setversions'}) {
4645: $haschanged=1;
4646: foreach my $key (keys(%env)) {
4647: if ($key=~/^form\.set_version_(.+)$/) {
4648: my $src=$1;
4649: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4650: $newsetversions{$src}=$env{$key};
4651: &devalidateversioncache($src);
4652: }
4653: }
1.329 droeschl 4654: }
1.484.2.67 raeburn 4655: }
4656: if ($haschanged) {
4657: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4658: $env{'course.'.$env{'request.course.id'}.'.domain'},
4659: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4660: $r->print(&Apache::loncommon::confirmwrapper(
4661: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4662: } else {
4663: $r->print(&Apache::loncommon::confirmwrapper(
4664: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4665: }
4666: &mark_hash_old();
4667: }
4668: &changewarning($r,'');
1.329 droeschl 4669: }
4670: if ($env{'form.timerange'} eq 'all') {
4671: # show all documents
1.484.2.34 raeburn 4672: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4673: $allsel=' selected="selected"';
1.329 droeschl 4674: foreach my $key (keys(%hash)) {
4675: if ($key=~/^ids\_(\/res\/.+)$/) {
4676: my $src=$1;
4677: $changes{$src}=1;
4678: }
4679: }
4680: } else {
4681: # show documents which changed
4682: %changes=&Apache::lonnet::dump
4683: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4684: $env{'course.'.$env{'request.course.id'}.'.num'});
4685: my $firstkey=(keys(%changes))[0];
4686: unless ($firstkey=~/^error\:/) {
4687: unless ($env{'form.timerange'}) {
4688: $env{'form.timerange'}=604800;
4689: }
4690: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4691: .&mt('seconds');
4692: if ($env{'form.timerange'}==-1) {
4693: $seltext='since start of course';
1.484.2.19 raeburn 4694: $startsel=' selected="selected"';
1.329 droeschl 4695: $env{'form.timerange'}=time;
4696: }
4697: $starttime=time-$env{'form.timerange'};
4698: if ($env{'form.timerange'}==2592000) {
4699: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4700: $monthsel=' selected="selected"';
1.329 droeschl 4701: } elsif ($env{'form.timerange'}==604800) {
4702: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4703: $weeksel=' selected="selected"';
1.329 droeschl 4704: } elsif ($env{'form.timerange'}==86400) {
4705: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4706: $daysel=' selected="selected"';
1.329 droeschl 4707: }
4708: $header=&mt('Content changed').' '.$seltext;
4709: } else {
4710: $header=&mt('No content modifications yet.');
4711: }
4712: }
4713: %setversions=&Apache::lonnet::dump('resourceversions',
4714: $env{'course.'.$env{'request.course.id'}.'.domain'},
4715: $env{'course.'.$env{'request.course.id'}.'.num'});
4716: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4717: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4718: 'lm' => 'Version changes since last Month',
4719: 'lw' => 'Version changes since last Week',
4720: 'sy' => 'Version changes since Yesterday',
4721: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4722: 'cd' => 'Change display',
1.329 droeschl 4723: 'sd' => 'Display',
4724: 'fi' => 'File',
4725: 'md' => 'Modification Date',
4726: 'mr' => 'Most recently published Version',
1.408 raeburn 4727: 've' => 'Version used in '.$crstype,
4728: 'vu' => 'Set Version to be used in '.$crstype,
4729: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4730: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4731: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4732: 'di' => 'Differences',
1.484 raeburn 4733: 'save' => 'Save changes',
4734: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4735: 'act' => 'Actions');
1.484.2.67 raeburn 4736: my ($disabled,$readonly);
4737: unless ($canedit) {
4738: $disabled = 'disabled="disabled"';
4739: $readonly = 1;
4740: }
1.329 droeschl 4741: $r->print(<<ENDHEADERS);
1.484 raeburn 4742: <h4 class="LC_info">$header</h4>
1.329 droeschl 4743: <form action="/adm/coursedocs" method="post">
4744: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4745: <div class="LC_left_float">
1.479 golterma 4746: <fieldset>
1.484 raeburn 4747: <legend>$lt{'cd'}</legend>
1.329 droeschl 4748: <select name="timerange">
1.484.2.19 raeburn 4749: <option value='all'$allsel>$lt{'al'}</option>
4750: <option value="-1"$startsel>$lt{'st'}</option>
4751: <option value="2592000"$monthsel>$lt{'lm'}</option>
4752: <option value="604800"$weeksel>$lt{'lw'}</option>
4753: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4754: </select>
4755: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4756: </fieldset>
4757: </div>
4758: <div class="LC_left_float">
4759: <fieldset>
4760: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4761: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4762: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4763: </fieldset>
4764: </div>
4765: <br clear="all" />
4766: <hr />
4767: <h4>$lt{'vers'}</h4>
1.329 droeschl 4768: ENDHEADERS
1.479 golterma 4769: #number of columns for version history
1.484.2.44 raeburn 4770: my %changedbytime;
4771: foreach my $key (keys(%changes)) {
4772: #excludes not versionable problems from resource version history:
4773: next if ($key =~ /^\/res\/lib\/templates/);
4774: my $chg;
4775: if ($env{'form.timerange'} eq 'all') {
4776: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4777: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4778: } else {
4779: $chg = $changes{$key};
4780: next if ($chg < $starttime);
4781: }
4782: push(@{$changedbytime{$chg}},$key);
4783: }
4784: if (keys(%changedbytime) == 0) {
4785: &untiehash();
4786: $r->print(&mt('No content changes in imported content in specified time frame').
4787: &endContentScreen());
4788: return;
4789: }
1.479 golterma 4790: $r->print(
1.484.2.67 raeburn 4791: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4792: &Apache::loncommon::start_data_table().
4793: &Apache::loncommon::start_data_table_header_row().
4794: '<th>'.&mt('Resources').'</th>'.
4795: "<th>$lt{'mr'}</th>".
4796: "<th>$lt{'ve'}</th>".
4797: "<th>$lt{'vu'}</th>".
4798: '<th>'.&mt('History').'</th>'.
4799: &Apache::loncommon::end_data_table_header_row()
4800: );
1.484.2.44 raeburn 4801: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4802: foreach my $key (sort(@{$changedbytime{$chg}})) {
4803: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4804: my $currentversion=&Apache::lonnet::getversion($key);
4805: if ($currentversion<0) {
4806: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4807: }
4808: my $linkurl=&Apache::lonnet::clutter($key);
4809: $r->print(
4810: &Apache::loncommon::start_data_table_row().
4811: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4812: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4813: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4814: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4815: '<td align="right">'
4816: );
4817: # Used in course
4818: my $usedversion=$hash{'version_'.$linkurl};
4819: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4820: if ($usedversion != $currentversion) {
1.479 golterma 4821: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4822: } else {
1.479 golterma 4823: $r->print($usedversion);
4824: }
1.329 droeschl 4825: } else {
1.484.2.19 raeburn 4826: $r->print($currentversion);
1.329 droeschl 4827: }
1.484.2.44 raeburn 4828: $r->print('</td><td title="'.$lt{'vu'}.'">');
4829: # Set version
4830: $r->print(&Apache::loncommon::select_form(
4831: $setversions{$linkurl},
4832: 'set_version_'.$linkurl,
4833: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4834: '' => '',
4835: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4836: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4837: my $lastold=1;
4838: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4839: my $url=$root.'.'.$prevvers.'.'.$extension;
4840: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4841: $lastold=$prevvers;
4842: }
4843: }
4844: $r->print('</td>');
4845: # List all available versions
4846: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4847: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4848: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4849: $r->print(
1.484.2.44 raeburn 4850: '<span class="LC_nobreak">'
4851: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4852: .&mt('Version [_1]',$prevvers).'</a>'
4853: .' ('.&Apache::lonlocal::locallocaltime(
4854: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4855: .')');
4856: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4857: $r->print(
4858: ' <a href="/adm/diff?filename='.
4859: &Apache::lonnet::clutter($root.'.'.$extension).
4860: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4861: '" target="diffs">'.&mt('Diffs').'</a>');
4862: }
4863: $r->print('</span><br />');
1.329 droeschl 4864: }
1.484.2.44 raeburn 4865: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4866: }
1.329 droeschl 4867: }
1.484.2.19 raeburn 4868: $r->print(
4869: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4870: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4871: '</form>'
4872: );
1.329 droeschl 4873:
4874: &untiehash();
1.484.2.19 raeburn 4875: $r->print(&endContentScreen());
1.484.2.44 raeburn 4876: return;
1.329 droeschl 4877: }
4878:
4879: sub mark_hash_old {
4880: my $retie_hash=0;
4881: if ($hashtied) {
4882: $retie_hash=1;
4883: &untiehash();
4884: }
4885: &tiehash('write');
4886: $hash{'old'}=1;
4887: &untiehash();
4888: if ($retie_hash) { &tiehash(); }
4889: }
4890:
4891: sub is_hash_old {
4892: my $untie_hash=0;
4893: if (!$hashtied) {
4894: $untie_hash=1;
4895: &tiehash();
4896: }
4897: my $return=$hash{'old'};
4898: if ($untie_hash) { &untiehash(); }
4899: return $return;
4900: }
4901:
4902: sub changewarning {
4903: my ($r,$postexec,$message,$url)=@_;
4904: if (!&is_hash_old()) { return; }
4905: my $pathvar='folderpath';
4906: my $path=&escape($env{'form.folderpath'});
4907: if (!defined($url)) {
4908: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4909: }
4910: my $course_type = &Apache::loncommon::course_type();
4911: if (!defined($message)) {
4912: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4913: }
4914: $r->print("\n\n".
1.372 bisitz 4915: '<script type="text/javascript">'."\n".
4916: '// <![CDATA['."\n".
4917: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4918: '// ]]>'."\n".
1.369 bisitz 4919: '</script>'."\n".
1.375 tempelho 4920: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4921: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4922: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4923: &mt($message,' <input type="hidden" name="'.
4924: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4925: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4926: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4927: }
4928:
4929:
4930: sub init_breadcrumbs {
1.484.2.44 raeburn 4931: my ($form,$text,$help)=@_;
1.329 droeschl 4932: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4933: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4934: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4935: faq=>273,
4936: bug=>'Instructor Interface',
1.484.2.44 raeburn 4937: help => $help});
1.329 droeschl 4938: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4939: text=>$text,
4940: faq=>273,
4941: bug=>'Instructor Interface'});
4942: }
4943:
1.441 www 4944: # subroutine to list form elements
4945: sub create_list_elements {
4946: my @formarr = @_;
4947: my $list = '';
1.484.2.12 raeburn 4948: foreach my $button (@formarr){
4949: foreach my $picture (keys(%{$button})) {
4950: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4951: }
4952: }
4953: return $list;
4954: }
1.329 droeschl 4955:
1.441 www 4956: # subroutine to create ul from list elements
4957: sub create_form_ul {
4958: my $list = shift;
4959: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4960: return $ul;
4961: }
1.329 droeschl 4962:
1.442 www 4963: #
4964: # Start tabs
4965: #
4966:
4967: sub startContentScreen {
1.484 raeburn 4968: my ($mode) = @_;
4969: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4970: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4971: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4972: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4973: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4974: } else {
1.484.2.34 raeburn 4975: $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 4976: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4977: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4978: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4979: }
4980: $output .= "\n".'</ul>'."\n";
4981: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4982: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4983: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4984: return $output;
1.442 www 4985: }
4986:
4987: #
4988: # End tabs
4989: #
4990:
4991: sub endContentScreen {
1.484 raeburn 4992: return '</div></div></div>';
1.442 www 4993: }
1.329 droeschl 4994:
1.446 www 4995: sub supplemental_base {
1.484.2.33 raeburn 4996: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4997: }
4998:
1.329 droeschl 4999: sub handler {
5000: my $r = shift;
5001: &Apache::loncommon::content_type($r,'text/html');
5002: $r->send_http_header;
5003: return OK if $r->header_only;
1.484 raeburn 5004:
5005: # get course data
1.408 raeburn 5006: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5007: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5008: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5009:
5010: # graphics settings
5011: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5012:
1.443 www 5013: #
1.329 droeschl 5014: # --------------------------------------------- Initialize help topics for this
5015: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5016: 'Adding_External_Resource','Navigate_Content',
5017: 'Adding_Folders','Docs_Overview', 'Load_Map',
5018: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 5019: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 5020: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
5021: 'Dropbox','Simple_Problem') {
1.329 droeschl 5022: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5023: }
5024: # Composite help files
5025: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5026: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5027: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5028: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5029: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5030: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5031: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5032: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5033: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5034: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5035:
1.484.2.67 raeburn 5036: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5037: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5038: unless ($r->uri eq '/adm/supplemental') {
5039: # does this user have privileges to modify content.
1.484.2.67 raeburn 5040: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5041: $allowed = 1;
5042: $canedit = 1;
5043: $canview = 1;
5044: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5045: $allowed = 1;
5046: $canview = 1;
5047: }
5048: }
5049: unless ($canedit) {
5050: $disabled = ' disabled="disabled"';
1.472 raeburn 5051: }
1.484.2.53 raeburn 5052: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5053: if ($env{'form.inhibitmenu'}) {
5054: unless ($env{'form.inhibitmenu'} eq 'yes') {
5055: delete($env{'form.inhibitmenu'});
5056: }
5057: }
5058:
1.484.2.53 raeburn 5059: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5060: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5061: if (!$canedit) {
5062: &verifycontent($r);
5063: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5064: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5065: text=>'Results',
5066: faq=>273,
5067: bug=>'Instructor Interface'});
5068: &verifycontent($r,$env{'form.checkstale'});
5069: } else {
5070: &contentverifyform($r);
5071: }
1.329 droeschl 5072: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5073: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5074: &list_symbs($r);
5075: } elsif ($allowed && $env{'form.docslog'}) {
5076: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5077: my $folder = $env{'form.folder'};
5078: if ($folder eq '') {
5079: $folder='default';
5080: }
1.484.2.67 raeburn 5081: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5082: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5083: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5084: &checkversions($r,$canedit);
5085: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5086: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5087: &dumpcourse($r);
5088: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5089: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5090: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5091: } else {
1.445 www 5092: #
5093: # Done catching special calls
1.484 raeburn 5094: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5095: # Get the parameters that may be needed
5096: #
5097: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5098: ['folderpath',
5099: 'forcesupplement','forcestandard',
5100: 'tools','symb','command','supppath']);
1.445 www 5101:
1.484.2.78 raeburn 5102: foreach my $item ('forcesupplement','forcestandard','tools') {
5103: next if ($env{'form.'.$item} eq '');
5104: unless ($env{'form.'.$item} eq '1') {
5105: delete($env{'form.'.$item});
5106: }
5107: }
5108:
5109: if ($env{'form.command'}) {
5110: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5111: delete($env{'form.command'});
5112: }
5113: }
5114:
5115: if ($env{'form.symb'}) {
5116: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5117: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5118: delete($env{'form.symb'});
5119: }
5120: }
5121:
1.445 www 5122: # standard=1: this is a "new-style" course with an uploaded map as top level
5123: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5124:
5125: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5126:
1.484 raeburn 5127: # Decide whether this should display supplemental or main content or utilities
1.445 www 5128: # supplementalflag=1: show supplemental documents
5129: # supplementalflag=0: show standard documents
1.484 raeburn 5130: # toolsflag=1: show utilities
1.445 www 5131:
1.484.2.39 raeburn 5132: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5133: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5134: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5135: $supplementalflag=0;
5136: }
5137: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5138: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5139: unless ($allowed) { $supplementalflag=1; }
5140: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5141: my $toolsflag=0;
5142: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5143:
1.484.2.78 raeburn 5144: if ($env{'form.folderpath'} ne '') {
5145: my @items = split(/\&/,$env{'form.folderpath'});
5146: my $badpath;
5147: for (my $i=0; $i<@items; $i++) {
5148: my $odd = $i%2;
5149: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5150: $badpath = 1;
5151: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5152: $badpath = 1;
5153: }
5154: last if ($badpath);
5155: }
5156: if ($badpath) {
5157: delete($env{'form.folderpath'});
5158: }
5159: }
5160:
5161: if ($env{'form.supppath'} ne '') {
5162: my @items = split(/\&/,$env{'form.supppath'});
5163: my $badpath;
5164: for (my $i=0; $i<@items; $i++) {
5165: my $odd = $i%2;
5166: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5167: $badpath = 1;
5168: }
5169: last if ($badpath);
5170: }
5171: if ($badpath) {
5172: delete($env{'form.supppath'});
5173: }
5174: }
5175:
1.329 droeschl 5176: my $script='';
5177: my $showdoc=0;
1.457 raeburn 5178: my $addentries = {};
1.475 raeburn 5179: my $container;
1.329 droeschl 5180: my $containertag;
1.484.2.17 raeburn 5181: my $pathitem;
1.484.2.67 raeburn 5182: my $hiddentop;
5183: my $navmap;
5184: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5185:
1.464 www 5186: # Do we directly jump somewhere?
1.484.2.21 raeburn 5187: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5188: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5189: $env{'form.folderpath'}=
1.484.2.67 raeburn 5190: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5191: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5192: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5193: } elsif ($env{'form.supppath'} ne '') {
5194: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5195: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5196: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5197: }
1.472 raeburn 5198: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5199: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5200: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5201: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5202: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5203: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5204: } elsif ($env{'form.command'} eq 'contents') {
5205: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5206: } elsif ($env{'form.command'} eq 'home') {
5207: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5208: }
5209:
1.484.2.23 raeburn 5210:
1.445 www 5211: # Where do we store these for when we come back?
5212: my $stored_folderpath='docs_folderpath';
5213: if ($supplementalflag) {
5214: $stored_folderpath='docs_sup_folderpath';
5215: }
1.464 www 5216:
1.484.2.19 raeburn 5217: # No folderpath, and in edit mode, see if we have something stored
5218: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5219: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5220: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5221:
5222: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5223: if ($supplementalflag) {
5224: undef($env{'form.folderpath'}) if ($1 eq 'default');
5225: } else {
5226: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5227: }
5228: } else {
1.484.2.19 raeburn 5229: undef($env{'form.folderpath'});
5230: }
1.329 droeschl 5231: }
1.446 www 5232:
5233: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5234: if (!$allowed) {
1.446 www 5235: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5236: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5237: }
5238: }
1.446 www 5239: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5240: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5241: $env{'form.folderpath'} = &supplemental_base()
5242: .'&'.
1.329 droeschl 5243: $env{'form.folderpath'};
5244: }
1.484.2.67 raeburn 5245: # If allowed and user's role is not advanced check folderpath is not hidden
5246: if (($allowed) && (!$env{'request.role.adv'}) &&
5247: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5248: my $folderurl;
5249: my @pathitems = split(/\&/,$env{'form.folderpath'});
5250: my $folder = $pathitems[-2];
5251: if ($folder eq '') {
5252: undef($env{'form.folderpath'});
5253: } else {
5254: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87! raeburn 5255: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5256: $folderurl .= '.page';
5257: } else {
5258: $folderurl .= '.sequence';
5259: }
5260: unless (ref($navmap)) {
5261: $navmap = Apache::lonnavmaps::navmap->new();
5262: }
5263: if (ref($navmap)) {
5264: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5265: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5266: unless (@resources) {
5267: undef($env{'form.folderpath'});
5268: }
5269: }
5270: }
5271: }
5272: }
5273:
5274:
1.446 www 5275: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5276: unless ($env{'form.folderpath'}) {
1.446 www 5277: if ($supplementalflag) {
5278: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5279: } elsif ($allowed) {
5280: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5281: }
1.472 raeburn 5282: }
1.446 www 5283:
1.445 www 5284: # Store this
1.484 raeburn 5285: unless ($toolsflag) {
1.484.2.67 raeburn 5286: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5287: &Apache::loncommon::store_course_settings($stored_folderpath,
5288: {'folderpath' => 'scalar'});
5289: }
5290: my $folderpath;
1.484 raeburn 5291: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5292: $folderpath = $env{'form.folderpath'};
5293: my (@folders)=split('&',$env{'form.folderpath'});
5294: $env{'form.foldername'}=&unescape(pop(@folders));
5295: if ($env{'form.foldername'} =~ /\:1$/) {
5296: $container = 'page';
5297: } else {
5298: $container = 'sequence';
5299: }
5300: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5301: } else {
1.484.2.19 raeburn 5302: if ($env{'form.folder'} eq '' ||
5303: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5304: if ($env{'form.folder'} eq 'supplemental') {
5305: $folderpath=&supplemental_base();
5306: } elsif (!$hiddentop) {
5307: $folderpath='default&'.
5308: &escape(&mt('Main Content').':::::');
5309: }
1.484 raeburn 5310: }
5311: }
1.484.2.19 raeburn 5312: $containertag = '<input type="hidden" name="folderpath" value="" />';
5313: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5314: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5315: $showdoc='/'.$1;
5316: }
5317: if ($showdoc) { # got called in sequence from course
5318: $allowed=0;
5319: } else {
1.484.2.67 raeburn 5320: if ($canedit) {
1.484 raeburn 5321: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5322: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5323: }
5324: }
1.329 droeschl 5325: }
5326:
1.344 bisitz 5327: # get personal data
1.329 droeschl 5328: my $uname=$env{'user.name'};
5329: my $udom=$env{'user.domain'};
5330: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5331:
5332: if ($allowed) {
1.484 raeburn 5333: if ($toolsflag) {
5334: $script .= &inject_data_js();
5335: my ($home,$other,%outhash)=&authorhosts();
5336: if (!$home && $other) {
5337: my @hosts;
5338: foreach my $aurole (keys(%outhash)) {
5339: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5340: push(@hosts,$outhash{$aurole});
5341: }
5342: }
5343: $script .= &dump_switchserver_js(@hosts);
5344: }
1.458 raeburn 5345: } else {
1.484.2.43 raeburn 5346: my $tid = 1;
1.484 raeburn 5347: my @tabids;
5348: if ($supplementalflag) {
5349: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5350: $tid = 2;
1.484 raeburn 5351: } else {
5352: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5353: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5354: unshift(@tabids,'001');
5355: push(@tabids,('dd1','ee1'));
5356: }
1.458 raeburn 5357: }
1.484 raeburn 5358: my $tabidstr = join("','",@tabids);
1.484.2.80 raeburn 5359: my $hostname = $r->hostname();
1.484.2.68 raeburn 5360: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.80 raeburn 5361: $canedit,$hostname,\$navmap).
1.484 raeburn 5362: &history_tab_js().
5363: &inject_data_js().
1.484.2.43 raeburn 5364: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5365: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5366: $addentries = {
1.484.2.3 raeburn 5367: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5368: };
1.458 raeburn 5369: }
1.484.2.30 raeburn 5370: $script .= &paste_popup_js();
1.484.2.12 raeburn 5371: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5372: &mt('Switch server?');
1.484.2.19 raeburn 5373:
5374:
1.329 droeschl 5375: }
5376: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5377: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5378: .'// <![CDATA['."\n"
5379: .$script."\n"
5380: .'// ]]>'."\n"
1.484.2.81 raeburn 5381: .'</script>'."\n"
5382: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5383:
5384: # Breadcrumbs
5385: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5386:
5387: if ($showdoc) {
5388: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5389: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5390: } elsif ($toolsflag) {
1.484.2.67 raeburn 5391: my ($breadtext,$breadtitle);
5392: $breadtext = "$crstype Editor";
5393: if ($canedit) {
5394: $breadtitle = 'Editing '.$crstype.' Contents';
5395: } else {
5396: $breadtext .= ' (View-only mode)';
5397: $breadtitle = 'Viewing '.$crstype.' Contents';
5398: }
1.484.2.44 raeburn 5399: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5400: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5401: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5402: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5403: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5404: $breadtitle)
1.484.2.44 raeburn 5405: );
1.484.2.19 raeburn 5406: } elsif ($r->uri eq '/adm/supplemental') {
5407: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5408: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5409: {'bread_crumbs' => $brcrum,}));
5410: } else {
1.484.2.67 raeburn 5411: my ($breadtext,$breadtitle,$helpitem);
5412: $breadtext = "$crstype Editor";
5413: if ($canedit) {
5414: $breadtitle = 'Editing '.$crstype.' Contents';
5415: $helpitem = 'Docs_Adding_Course_Doc';
5416: } else {
5417: $breadtext .= ' (View-only mode)';
5418: $breadtitle = 'Viewing '.$crstype.' Contents';
5419: $helpitem = 'Docs_Viewing_Course_Doc';
5420: }
1.392 raeburn 5421: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5422: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5423: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5424: {'add_entries' => $addentries}
5425: )
1.392 raeburn 5426: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5427: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5428: $breadtitle,
5429: $helpitem)
1.392 raeburn 5430: );
5431: }
1.364 bisitz 5432:
1.329 droeschl 5433: my %allfiles = ();
5434: my %codebase = ();
1.440 raeburn 5435: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5436: if ($canedit) {
1.329 droeschl 5437: if (($env{'form.uploaddoc.filename'}) &&
5438: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5439: my $context = $1;
5440: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5441: undef($hadchanges);
1.440 raeburn 5442: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5443: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5444: undef($navmap);
1.329 droeschl 5445: if ($hadchanges) {
5446: &mark_hash_old();
5447: }
1.440 raeburn 5448: $r->print($upload_output);
5449: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5450: # Process file upload - phase two - upload embedded objects
5451: $uploadphase = 'check_embedded';
5452: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5453: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5454: $env{'form.newidx'});
5455: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5456: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5457: my ($destination,$dir_root) = &embedded_destination();
5458: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5459: my $actionurl = '/adm/coursedocs';
5460: my ($result,$flag) =
5461: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5462: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5463: $actionurl);
5464: $r->print($result.&return_to_editor());
5465: } elsif ($env{'form.phase'} eq 'check_embedded') {
5466: # Process file upload - phase three - modify references in HTML file
5467: $uploadphase = 'modified_orightml';
5468: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5469: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5470: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5471: my $result =
5472: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5473: $docuname,$docudom,undef,
5474: $dir_root);
5475: $r->print($result.&return_to_editor());
1.476 raeburn 5476: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5477: $uploadphase = 'decompress_phase_one';
5478: $r->print(&decompression_phase_one().
5479: &return_to_editor());
5480: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5481: $uploadphase = 'decompress_phase_two';
5482: $r->print(&decompression_phase_two().
5483: &return_to_editor());
1.329 droeschl 5484: }
5485: }
5486:
1.484 raeburn 5487: if ($allowed && $toolsflag) {
5488: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5489: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5490: $r->print(&endContentScreen());
5491: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5492: # -----------------------------------------------------------------------------
5493: my %lt=&Apache::lonlocal::texthash(
5494: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5495: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5496: 'upld' => 'Upload Content',
1.329 droeschl 5497: 'srch' => 'Search',
5498: 'impo' => 'Import',
1.484.2.19 raeburn 5499: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5500: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5501: 'selm' => 'Select Map',
5502: 'load' => 'Load Map',
5503: 'newf' => 'New Folder',
5504: 'newp' => 'New Composite Page',
5505: 'syll' => 'Syllabus',
1.425 raeburn 5506: 'navc' => 'Table of Contents',
1.343 biermanm 5507: 'sipa' => 'Simple Course Page',
1.329 droeschl 5508: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5509: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5510: 'drbx' => 'Drop Box',
1.451 www 5511: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5512: 'bull' => 'Discussion Board',
1.347 weissno 5513: 'mypi' => 'My Personal Information Page',
1.353 weissno 5514: 'grpo' => 'Group Portfolio',
1.329 droeschl 5515: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5516: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5517: 'imsf' => 'IMS Upload',
5518: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5519: 'cms' => 'Origin of IMS package',
5520: 'se' => 'Select',
1.484.2.19 raeburn 5521: 'file' => 'File',
1.329 droeschl 5522: 'title' => 'Title',
5523: 'comment' => 'Comment',
1.403 raeburn 5524: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5525: 'bb5' => 'Blackboard 5',
5526: 'bb6' => 'Blackboard 6',
5527: 'angel5' => 'ANGEL 5.5',
5528: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5529: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5530: );
1.329 droeschl 5531: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5532: # Calculate free quota space for a user or course. A javascript function checks
5533: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5534: my $quotatype = 'unofficial';
5535: if ($crstype eq 'Community') {
5536: $quotatype = 'community';
5537: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5538: $quotatype = 'official';
5539: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5540: $quotatype = 'textbook';
5541: }
5542: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5543: 'course',$quotatype); # expressed in MB
5544: my $current_disk_usage = 0;
5545: foreach my $subdir ('docs','supplemental') {
5546: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5547: "userfiles/$subdir",1); # expressed in kB
5548: }
5549: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5550: my $usage = $current_disk_usage/1024; # in MB
5551: my $quota = $disk_quota;
5552: my $percent;
5553: if ($disk_quota == 0) {
5554: $percent = 100.0;
5555: } else {
1.484.2.69 raeburn 5556: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5557: }
5558: $usage = sprintf("%.2f",$usage);
5559: $quota = sprintf("%.2f",$quota);
5560: $percent = sprintf("%.0f",$percent);
5561: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5562: $percent.'%',$quota.' MB').'</p>';
5563:
1.329 droeschl 5564: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5565: $quotainfo
1.329 droeschl 5566: $lt{'file'}:<br />
1.484.2.81 raeburn 5567: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5568: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5569: FIUP
5570:
5571: my $checkbox=(<<CHBO);
5572: <!-- <label>$lt{'parse'}?
5573: <input type="checkbox" name="parserflag" />
5574: </label> -->
5575: <label>
1.484.2.67 raeburn 5576: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5577: </label>
5578: CHBO
1.484.2.12 raeburn 5579: my $imsfolder = $env{'form.folder'};
5580: if ($imsfolder eq '') {
1.484.2.19 raeburn 5581: $imsfolder = 'default';
1.484.2.12 raeburn 5582: }
5583: my $imspform=(<<IMSFORM);
5584: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5585: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5586: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5587: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5588: <legend>$lt{'imsf'}</legend>
5589: $fileupload
5590: <br />
5591: <p>
1.484.2.19 raeburn 5592: $lt{'cms'}:
1.484.2.67 raeburn 5593: <select name="source" $disabled>
1.484.2.12 raeburn 5594: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5595: <option value="bb5">$lt{'bb5'}</option>
5596: <option value="bb6">$lt{'bb6'}</option>
5597: <option value="angel5">$lt{'angel5'}</option>
5598: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5599: </select>
5600: <input type="hidden" name="folder" value="$imsfolder" />
5601: </p>
5602: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5603: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5604: </fieldset>
5605: </form>
5606: IMSFORM
5607:
1.484.2.19 raeburn 5608: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5609: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5610: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5611: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5612: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5613: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5614: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5615: $fileupload
5616: <br />
5617: $lt{'title'}:<br />
1.484.2.67 raeburn 5618: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5619: $pathitem
1.329 droeschl 5620: <input type="hidden" name="cmd" value="upload_default" />
5621: <br />
1.458 raeburn 5622: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5623: $checkbox
5624: </span>
1.484.2.12 raeburn 5625: <br clear="all" />
1.484.2.67 raeburn 5626: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5627: </fieldset>
5628: </form>
1.383 tempelho 5629: FUFORM
1.329 droeschl 5630:
1.484.2.67 raeburn 5631: my $mapimportjs;
5632: if ($canedit) {
5633: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5634: } else {
5635: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5636: }
1.484.2.19 raeburn 5637: my $importpubform=(<<SEDFFORM);
5638: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5639: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5640: <form action="/adm/coursedocs" method="post" name="mapimportform">
5641: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5642: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5643: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5644: $lt{'copm'}<br />
5645: <span class="LC_nobreak">
1.484.2.19 raeburn 5646: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5647: onfocus="this.blur();$mapimportjs" $disabled />
5648: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5649: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5650: </fieldset>
5651: </form>
5652:
1.383 tempelho 5653: SEDFFORM
1.484.2.67 raeburn 5654:
5655: my $fromstoredjs;
5656: if ($canedit) {
5657: $fromstoredjs = 'open_StoredLinks_Import()';
5658: } else {
5659: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5660: }
5661:
1.484.2.19 raeburn 5662: my @importpubforma = (
5663: { '<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 5664: { '<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 5665: { '<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 5666: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5667: );
5668: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5669: my $extresourcesform =
5670: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5671: $help{'Adding_External_Resource'},
5672: undef,undef,$disabled);
1.329 droeschl 5673: if ($allowed) {
1.484.2.7 raeburn 5674: my $folder = $env{'form.folder'};
5675: if ($folder eq '') {
5676: $folder='default';
5677: }
1.484.2.67 raeburn 5678: if ($canedit) {
5679: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5680: if ($output) {
5681: $r->print($output);
5682: }
1.484.2.30 raeburn 5683: }
1.337 ehlerst 5684: $r->print(<<HIDDENFORM);
5685: <form name="renameform" method="post" action="/adm/coursedocs">
5686: <input type="hidden" name="title" />
5687: <input type="hidden" name="cmd" />
5688: <input type="hidden" name="markcopy" />
5689: <input type="hidden" name="copyfolder" />
5690: $containertag
5691: </form>
1.484 raeburn 5692:
1.337 ehlerst 5693: HIDDENFORM
1.484.2.17 raeburn 5694: $r->print(&makesimpleeditform($pathitem)."\n".
5695: &makedocslogform($pathitem."\n".
1.484 raeburn 5696: '<input type="hidden" name="folder" value="'.
5697: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5698: }
1.442 www 5699:
5700: # Generate the tabs
1.484.2.19 raeburn 5701: my ($mode,$needs_end);
1.472 raeburn 5702: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5703: my @folders = split('&',$env{'form.folderpath'});
5704: unless (@folders > 2) {
5705: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5706: $needs_end = 1;
5707: }
1.472 raeburn 5708: } else {
1.484 raeburn 5709: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5710: $needs_end = 1;
1.472 raeburn 5711: }
1.443 www 5712:
1.442 www 5713: #
5714:
5715: my $savefolderpath;
1.484.2.86 raeburn 5716: my $hostname = $r->hostname();
1.442 www 5717:
1.395 raeburn 5718: if ($allowed) {
1.329 droeschl 5719: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5720: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5721: $folder='default';
1.356 tempelho 5722: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5723: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5724: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5725: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5726: }
5727: my $postexec='';
5728: if ($folder eq 'default') {
1.372 bisitz 5729: $r->print('<script type="text/javascript">'."\n"
5730: .'// <![CDATA['."\n"
5731: .'this.window.name="loncapaclient";'."\n"
5732: .'// ]]>'."\n"
5733: .'</script>'."\n"
1.369 bisitz 5734: );
1.329 droeschl 5735: } else {
5736: #$postexec='self.close();';
5737: }
1.484.2.15 raeburn 5738: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5739: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5740: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5741:
5742: my $newnavform=(<<NNFORM);
5743: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5744: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5745: $pathitem
1.329 droeschl 5746: <input type="hidden" name="importdetail"
5747: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5748: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5749: $help{'Navigate_Content'}
5750: </form>
5751: NNFORM
5752: my $newsmppageform=(<<NSPFORM);
5753: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5754: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5755: $pathitem
1.329 droeschl 5756: <input type="hidden" name="importdetail" value="" />
1.423 onken 5757: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5758: $help{'Simple Page'}
1.329 droeschl 5759: </form>
5760: NSPFORM
5761:
5762: my $newsmpproblemform=(<<NSPROBFORM);
5763: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5764: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5765: $pathitem
1.329 droeschl 5766: <input type="hidden" name="importdetail" value="" />
1.423 onken 5767: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5768: $help{'Simple_Problem'}
1.329 droeschl 5769: </form>
5770:
5771: NSPROBFORM
5772:
5773: my $newdropboxform=(<<NDBFORM);
5774: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5775: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5776: $pathitem
1.329 droeschl 5777: <input type="hidden" name="importdetail" value="" />
1.423 onken 5778: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5779: $help{'Dropbox'}
1.344 bisitz 5780: </form>
1.329 droeschl 5781: NDBFORM
5782:
5783: my $newexuploadform=(<<NEXUFORM);
5784: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5785: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5786: $pathitem
1.329 droeschl 5787: <input type="hidden" name="importdetail" value="" />
1.423 onken 5788: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5789: $help{'Score_Upload_Form'}
5790: </form>
5791: NEXUFORM
5792:
5793: my $newbulform=(<<NBFORM);
5794: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5795: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5796: $pathitem
1.329 droeschl 5797: <input type="hidden" name="importdetail" value="" />
1.423 onken 5798: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5799: $help{'Bulletin Board'}
5800: </form>
5801: NBFORM
5802:
5803: my $newaboutmeform=(<<NAMFORM);
5804: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5805: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5806: $pathitem
1.329 droeschl 5807: <input type="hidden" name="importdetail"
5808: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5809: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5810: $help{'My Personal Information Page'}
1.329 droeschl 5811: </form>
5812: NAMFORM
5813:
5814: my $newaboutsomeoneform=(<<NASOFORM);
5815: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5816: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5817: $pathitem
1.329 droeschl 5818: <input type="hidden" name="importdetail" value="" />
1.423 onken 5819: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5820: </form>
5821: NASOFORM
5822:
5823: my $newrosterform=(<<NROSTFORM);
5824: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5825: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5826: $pathitem
1.329 droeschl 5827: <input type="hidden" name="importdetail"
5828: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5829: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5830: $help{'Course_Roster'}
1.329 droeschl 5831: </form>
5832: NROSTFORM
5833:
1.484.2.27 raeburn 5834: my $newwebpage;
5835: if ($folder =~ /^default_?(\d*)$/) {
5836: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5837: if ($1) {
5838: $newwebpage .= $1;
5839: } else {
5840: $newwebpage .= 'default';
5841: }
5842: $newwebpage .= '/new.html';
5843: }
5844: my $newwebpageform =(<<NWEBFORM);
5845: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5846: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5847: $pathitem
5848: <input type="hidden" name="importdetail" value="$newwebpage" />
5849: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5850: $help{'Web_Page'}
1.484.2.27 raeburn 5851: </form>
5852: NWEBFORM
1.484.2.30 raeburn 5853:
1.484.2.27 raeburn 5854:
1.342 ehlerst 5855: my $specialdocumentsform;
1.383 tempelho 5856: my @specialdocumentsforma;
1.451 www 5857: my $gradingform;
5858: my @gradingforma;
5859: my $communityform;
5860: my @communityforma;
1.351 ehlerst 5861: my $newfolderform;
1.390 tempelho 5862: my $newfolderb;
1.342 ehlerst 5863:
1.451 www 5864: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5865:
1.329 droeschl 5866: my $newpageform=(<<NPFORM);
5867: <form action="/adm/coursedocs" method="post" name="newpage">
5868: <input type="hidden" name="folderpath" value="$path" />
5869: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5870: <input type="hidden" name="active" value="ee" />
1.423 onken 5871: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5872: $help{'Adding_Pages'}
1.329 droeschl 5873: </form>
5874: NPFORM
1.390 tempelho 5875:
5876:
1.351 ehlerst 5877: $newfolderform=(<<NFFORM);
1.329 droeschl 5878: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5879: $pathitem
1.329 droeschl 5880: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5881: <input type="hidden" name="active" value="" />
1.422 onken 5882: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5883: </form>
5884: NFFORM
5885:
5886: my $newsylform=(<<NSYLFORM);
5887: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5888: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5889: $pathitem
1.329 droeschl 5890: <input type="hidden" name="importdetail"
5891: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5892: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5893: $help{'Syllabus'}
1.383 tempelho 5894:
1.329 droeschl 5895: </form>
5896: NSYLFORM
1.364 bisitz 5897:
1.329 droeschl 5898: my $newgroupfileform=(<<NGFFORM);
5899: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5900: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5901: $pathitem
1.329 droeschl 5902: <input type="hidden" name="importdetail"
5903: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5904: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5905: $help{'Group Portfolio'}
1.329 droeschl 5906: </form>
5907: NGFFORM
1.383 tempelho 5908: @specialdocumentsforma=(
1.421 onken 5909: {'<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 5910: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5911: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5912: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5913: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5914: );
5915: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5916:
1.434 raeburn 5917:
5918: my @importdoc = (
1.484.2.19 raeburn 5919: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5920: );
5921: unless ($container eq 'page') {
5922: push(@importdoc,
5923: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5924: );
5925: }
5926: push(@importdoc,
1.484.2.38 raeburn 5927: {'<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 5928: );
1.484.2.12 raeburn 5929: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5930:
1.451 www 5931: @gradingforma=(
5932: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5933: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5934: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5935:
5936: );
5937: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5938:
5939: @communityforma=(
5940: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5941: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5942: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5943: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5944: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5945: );
5946: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5947:
1.330 tempelho 5948: my %orderhash = (
1.484.2.36 raeburn 5949: 'aa' => ['Upload',$fileuploadform],
5950: 'bb' => ['Import',$importpubform],
5951: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5952: );
1.484.2.19 raeburn 5953: unless ($container eq 'page') {
1.434 raeburn 5954: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5955: $orderhash{'dd'} = ['Collaboration',$communityform];
1.484.2.36 raeburn 5956: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5957: }
5958:
1.341 ehlerst 5959: $hadchanges=0;
1.484 raeburn 5960: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5961: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5962: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.85 raeburn 5963: $canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 5964: undef($navmap);
1.443 www 5965: if ($error) {
5966: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5967: }
5968: if ($hadchanges) {
1.484.2.73 raeburn 5969: unless (&is_hash_old()) {
5970: &mark_hash_old();
5971: }
1.443 www 5972: }
1.341 ehlerst 5973:
1.443 www 5974: &changewarning($r,'');
5975: }
1.458 raeburn 5976: }
1.442 www 5977:
1.443 www 5978: # Supplemental documents start here
5979:
1.329 droeschl 5980: my $folder=$env{'form.folder'};
1.443 www 5981: unless ($supplementalflag) {
1.329 droeschl 5982: $folder='supplemental';
5983: }
5984: if ($folder =~ /^supplemental$/ &&
5985: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5986: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5987: } elsif ($allowed) {
1.356 tempelho 5988: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5989: }
1.484.2.17 raeburn 5990: $pathitem = '<input type="hidden" name="folderpath" value="'.
5991: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5992: if ($allowed) {
5993: my $folderseq=
1.484.2.15 raeburn 5994: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5995:
5996: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 5997: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5998: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5999: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6000: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6001: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6002: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6003: $fileupload
6004: <br />
6005: <br />
6006: <span class="LC_nobreak">
6007: $checkbox
6008: </span>
6009: <br /><br />
6010: $lt{'comment'}:<br />
1.383 tempelho 6011: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6012: <br />
1.484.2.19 raeburn 6013: $pathitem
1.329 droeschl 6014: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6015: <input type='submit' value="$lt{'upld'}" />
6016: </form>
1.484.2.19 raeburn 6017: SUPDOCFORM
1.329 droeschl 6018:
6019: my $supnewfolderform=(<<SNFFORM);
6020: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6021: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6022: $pathitem
1.329 droeschl 6023: <input type="hidden" name="importdetail" value="" />
1.423 onken 6024: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6025: $help{'Adding_Folders'}
1.329 droeschl 6026: </form>
6027: SNFFORM
1.383 tempelho 6028:
1.484.2.19 raeburn 6029: my $supextform =
6030: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6031: $help{'Adding_External_Resource'},
6032: undef,undef,$disabled);
1.329 droeschl 6033:
6034: my $supnewsylform=(<<SNSFORM);
6035: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6036: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6037: $pathitem
1.329 droeschl 6038: <input type="hidden" name="importdetail"
6039: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6040: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6041: $help{'Syllabus'}
6042: </form>
6043: SNSFORM
6044:
6045: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6046: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6047: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6048: $pathitem
1.329 droeschl 6049: <input type="hidden" name="importdetail"
6050: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6051: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6052: $help{'My Personal Information Page'}
1.329 droeschl 6053: </form>
6054: SNAMFORM
6055:
1.484.2.27 raeburn 6056: my $supwebpage;
6057: if ($folder =~ /^supplemental_?(\d*)$/) {
6058: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6059: if ($1) {
6060: $supwebpage .= $1;
6061: } else {
6062: $supwebpage .= 'default';
6063: }
6064: $supwebpage .= '/new.html';
6065: }
6066: my $supwebpageform =(<<SWEBFORM);
6067: <form action="/adm/coursedocs" method="post" name="supwebpage">
6068: <input type="hidden" name="active" value="cc" />
6069: $pathitem
6070: <input type="hidden" name="importdetail" value="$supwebpage" />
6071: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6072: $help{'Web_Page'}
1.484.2.27 raeburn 6073: </form>
6074: SWEBFORM
6075:
1.333 muellerd 6076:
1.383 tempelho 6077: my @specialdocs = (
1.484.2.67 raeburn 6078: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6079: =>$supnewsylform},
1.484.2.67 raeburn 6080: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6081: =>$supnewaboutmeform},
1.484.2.27 raeburn 6082: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6083:
1.383 tempelho 6084: );
1.417 droeschl 6085: my @supimportdoc = (
1.484.2.19 raeburn 6086: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 6087: =>$supextform},
6088: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6089: =>$supupdocform},
1.484.2.19 raeburn 6090: );
6091:
1.484.2.12 raeburn 6092: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6093: my %suporderhash = (
1.390 tempelho 6094: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6095: 'ee' => ['Upload',$supupdocform],
6096: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6097: );
1.443 www 6098: if ($supplementalflag) {
1.458 raeburn 6099: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6100: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.85 raeburn 6101: $canedit,$hostname);
1.443 www 6102: if ($error) {
6103: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6104: } else {
6105: if ($suppchanges) {
6106: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6107: my @ids=&Apache::lonnet::current_machine_ids();
6108: foreach my $server (keys(%servers)) {
6109: next if (grep(/^\Q$server\E$/,@ids));
6110: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6111: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6112: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6113: }
6114: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6115: undef($suppchanges);
6116: }
1.443 www 6117: }
1.393 raeburn 6118: }
1.443 www 6119: } elsif ($supplementalflag) {
1.458 raeburn 6120: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6121: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6122: if ($error) {
6123: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6124: }
1.393 raeburn 6125: }
1.389 tempelho 6126:
1.484.2.19 raeburn 6127: if ($needs_end) {
6128: $r->print(&endContentScreen());
6129: }
1.383 tempelho 6130:
1.329 droeschl 6131: if ($allowed) {
6132: $r->print('
6133: <form method="post" name="extimport" action="/adm/coursedocs">
6134: <input type="hidden" name="title" />
6135: <input type="hidden" name="url" />
6136: <input type="hidden" name="useform" />
6137: <input type="hidden" name="residx" />
6138: </form>');
6139: }
1.484 raeburn 6140: } elsif ($showdoc) {
1.329 droeschl 6141: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6142: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6143: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6144: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6145: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6146: }
6147: }
6148: $r->print(&Apache::loncommon::end_page());
6149: return OK;
1.364 bisitz 6150: }
1.329 droeschl 6151:
1.440 raeburn 6152: sub embedded_form_elems {
6153: my ($phase,$primaryurl,$newidx) = @_;
6154: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6155: $newidx =~s /\D+//g;
1.440 raeburn 6156: return <<STATE;
6157: <input type="hidden" name="folderpath" value="$folderpath" />
6158: <input type="hidden" name="cmd" value="upload_embedded" />
6159: <input type="hidden" name="newidx" value="$newidx" />
6160: <input type="hidden" name="phase" value="$phase" />
6161: <input type="hidden" name="primaryurl" value="$primaryurl" />
6162: STATE
6163: }
6164:
6165: sub embedded_destination {
6166: my $folder=$env{'form.folder'};
6167: my $destination = 'docs/';
6168: if ($folder =~ /^supplemental/) {
6169: $destination = 'supplemental/';
6170: }
6171: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6172: $destination .= 'default/';
6173: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6174: $destination .= $2.'/';
6175: }
1.484.2.78 raeburn 6176: my $newidx = $env{'form.newidx'};
6177: $newidx =~s /\D+//g;
6178: if ($newidx) {
6179: $destination .= $newidx;
6180: }
1.440 raeburn 6181: my $dir_root = '/userfiles';
6182: return ($destination,$dir_root);
6183: }
6184:
6185: sub return_to_editor {
6186: my $actionurl = '/adm/coursedocs';
6187: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6188: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6189: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6190: '</a></p>';
6191: }
6192:
1.476 raeburn 6193: sub decompression_info {
6194: my ($destination,$dir_root) = &embedded_destination();
6195: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6196: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6197: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6198: my $container='sequence';
1.480 raeburn 6199: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6200: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6201: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6202: $container='page';
6203: }
1.480 raeburn 6204: unshift(@hiddens,$pathitem);
6205: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6206: if ($item eq 'newidx') {
6207: next if ($env{'form.'.$item} =~ /\D/);
6208: }
1.480 raeburn 6209: if ($env{'form.'.$item}) {
6210: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6211: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6212: }
1.477 raeburn 6213: }
1.476 raeburn 6214: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6215: $hiddenelem);
6216: }
6217:
6218: sub decompression_phase_one {
6219: my ($dir,$file,$warning,$error,$output);
6220: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6221: &decompression_info();
1.484.2.7 raeburn 6222: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6223: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6224: } else {
6225: my $file = $1;
1.481 raeburn 6226: $output =
6227: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6228: $destination,$dir_root,
6229: $hiddenelem);
6230: if ($env{'form.autoextract_camtasia'}) {
6231: $output .= &remove_archive($docudom,$docuname,$container);
6232: }
1.476 raeburn 6233: }
6234: if ($error) {
6235: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6236: $error.'</p>'."\n";
6237: }
6238: if ($warning) {
6239: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6240: }
6241: return $output;
6242: }
6243:
6244: sub decompression_phase_two {
6245: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6246: &decompression_info();
1.481 raeburn 6247: my $output;
1.480 raeburn 6248: if ($env{'form.archivedelete'}) {
1.481 raeburn 6249: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6250: }
6251: $output .=
1.481 raeburn 6252: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6253: $destination,$dir_root,$hiddenelem);
6254: return $output;
6255: }
6256:
1.480 raeburn 6257: sub remove_archive {
6258: my ($docudom,$docuname,$container) = @_;
6259: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6260: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6261: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6262: if ($fatal) {
6263: if ($container eq 'page') {
6264: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6265: } else {
6266: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6267: }
1.484.2.54 raeburn 6268: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6269: } else {
6270: my $currcmd = $env{'form.cmd'};
6271: my $position = $env{'form.position'};
1.484.2.54 raeburn 6272: my $archiveidx = $position;
6273: if ($position > 0) {
6274: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6275: $archiveidx = $position-1;
6276: }
6277: $env{'form.cmd'} = 'remove_'.$archiveidx;
6278: my ($title,$url,@rrest) =
6279: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6280: if ($url eq $env{'form.archiveurl'}) {
6281: if (&handle_edit_cmd($docuname,$docudom)) {
6282: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6283: if ($fatal) {
6284: if ($container eq 'page') {
6285: $delwarning = &mt('An error occurred updating the contents of the current page.');
6286: } else {
6287: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6288: }
1.480 raeburn 6289: } else {
1.484.2.54 raeburn 6290: $delresult = &mt('Archive file removed.');
1.480 raeburn 6291: }
6292: }
1.484.2.54 raeburn 6293: } else {
6294: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6295: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6296: }
6297: }
6298: $env{'form.cmd'} = $currcmd;
6299: }
6300: if ($delwarning) {
6301: $output = '<p class="LC_warning">'.
6302: $delwarning.
6303: '</p>';
6304: }
6305: if ($delresult) {
6306: $output .= '<p class="LC_info">'.
6307: $delresult.
6308: '</p>';
6309: }
1.481 raeburn 6310: return $output;
1.480 raeburn 6311: }
6312:
1.484 raeburn 6313: sub generate_admin_menu {
1.484.2.67 raeburn 6314: my ($crstype,$canedit) = @_;
1.484 raeburn 6315: my $lc_crstype = lc($crstype);
6316: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6317: my %lt= ( # do not translate here
1.484 raeburn 6318: 'vc' => 'Verify Content',
6319: 'cv' => 'Check/Set Resource Versions',
6320: 'ls' => 'List Resource Identifiers',
6321: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6322: 'dcd' => "Copy $crstype Content to Authoring Space",
6323: );
1.484 raeburn 6324: my ($candump,$dumpurl);
6325: if ($home + $other > 0) {
6326: $candump = 'F';
6327: if ($home) {
6328: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6329: } else {
6330: my @hosts;
6331: foreach my $aurole (keys(%outhash)) {
6332: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6333: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6334: }
1.484 raeburn 6335: }
6336: if (@hosts == 1) {
6337: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6338: '&role='.
6339: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6340: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6341: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6342: } else {
6343: $dumpurl = "javascript:choose_switchserver_window()";
6344: }
6345: }
6346: }
6347: my @menu=
6348: ({ categorytitle=>'Administration',
6349: items =>[
6350: { linktext => $lt{'vc'},
6351: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6352: permission => 'F',
1.484.2.44 raeburn 6353: help => 'Docs_Verify_Content',
1.484 raeburn 6354: icon => 'verify.png',
6355: linktitle => 'Verify contents can be retrieved/rendered',
6356: },
6357: { linktext => $lt{'cv'},
6358: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6359: permission => 'F',
1.484.2.44 raeburn 6360: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6361: icon => 'resversion.png',
6362: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6363: },
6364: { linktext => $lt{'ls'},
6365: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6366: permission => 'F',
6367: #help => '',
6368: icon => 'symbs.png',
6369: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6370: },
6371: ]
1.484.2.67 raeburn 6372: });
6373: if ($canedit) {
6374: push(@menu,
1.484 raeburn 6375: { categorytitle=>'Export',
6376: items =>[
6377: { linktext => $lt{'imse'},
6378: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6379: permission => 'F',
6380: help => 'Docs_Export_Course_Docs',
6381: icon => 'imsexport.png',
6382: linktitle => $lt{'imse'},
6383: },
6384: { linktext => $lt{'dcd'},
6385: url => $dumpurl,
6386: permission => $candump,
1.484.2.44 raeburn 6387: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6388: icon => 'dump.png',
6389: linktitle => $lt{'dcd'},
6390: },
6391: ]
6392: });
1.484.2.67 raeburn 6393: }
1.484 raeburn 6394: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6395: '<input type="hidden" id="dummy" />'."\n".
6396: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6397: '</form>';
1.329 droeschl 6398: }
6399:
6400: sub generate_edit_table {
1.484.2.30 raeburn 6401: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6402: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6403: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6404: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6405: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6406: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6407: $activetab = $env{'form.active'};
6408: }
1.484.2.67 raeburn 6409: unless ($canedit) {
6410: $disabled = ' disabled="disabled"';
6411: }
1.472 raeburn 6412: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6413: my $backtext = &mt('Exit Editor');
1.458 raeburn 6414: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6415: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6416: '<li class="goback">'.
1.484.2.32 raeburn 6417: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6418: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6419: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6420: '<li>'.
6421: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6422: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6423: if ($env{'form.docslog'}) {
6424: $form .= '<li class="active">';
6425: } else {
6426: $form .= '<li>';
6427: }
6428: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6429: &mt('History').'</a></li>'."\n";
6430: if ($env{'form.docslog'}) {
6431: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6432: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6433: }
1.458 raeburn 6434: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6435: if($name ne '00'){
1.371 tempelho 6436: if($activetab eq '' || $activetab ne $name){
6437: $active = '';
6438: }elsif($activetab eq $name){
6439: $active = 'class="active"';
6440: }
1.458 raeburn 6441: $form .= '<li style="float:right" '.$active
1.484 raeburn 6442: .' 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 6443: } else {
1.484.2.43 raeburn 6444: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6445:
6446: }
1.329 droeschl 6447: }
1.484 raeburn 6448: $form .= '</ul>'."\n";
6449: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6450:
6451: if ($to_show ne '') {
1.484.2.30 raeburn 6452: my $saveform;
6453: if ($need_save) {
6454: my $button = &mt('Make changes');
6455: my $path;
6456: if ($env{'form.folderpath'}) {
6457: $path =
6458: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6459: }
6460: $saveform = <<"END";
6461: <div id="multisave" style="display:none; clear:both;" >
6462: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6463: <input type="hidden" name="folderpath" value="$path" />
6464: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6465: <input type="hidden" name="allhiddenresource" value="" />
6466: <input type="hidden" name="allencrypturl" value="" />
6467: <input type="hidden" name="allrandompick" value="" />
6468: <input type="hidden" name="allrandomorder" value="" />
6469: <input type="hidden" name="changeparms" value="" />
6470: <input type="hidden" name="multiremove" value="" />
6471: <input type="hidden" name="multicut" value="" />
6472: <input type="hidden" name="multicopy" value="" />
6473: <input type="hidden" name="multichange" value="" />
6474: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6475: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6476: </form>
6477: </div>
6478: END
6479: }
6480: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6481: }
1.363 ehlerst 6482: foreach my $field (keys(%orderhash)){
1.390 tempelho 6483: if($field ne '00'){
1.422 onken 6484: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6485: $active = 'style="display: none;float:left"';
1.422 onken 6486: }elsif($activetab eq $field){
1.458 raeburn 6487: $active = 'style="display:block;float:left"';
1.422 onken 6488: }
6489: $form .= '<div id="'.$field.$tid.'"'
6490: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6491: .'</div>'."\n";
1.363 ehlerst 6492: }
6493: }
1.484 raeburn 6494: unless ($env{'form.docslog'}) {
6495: $form .= '</div></div>'."\n";
6496: }
1.329 droeschl 6497: return $form;
6498: }
6499:
6500: sub editing_js {
1.484.2.80 raeburn 6501: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,
6502: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6503: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6504: p_mnf => 'Name of New Folder',
6505: t_mnf => 'New Folder',
6506: p_mnp => 'Name of New Page',
6507: t_mnp => 'New Page',
1.451 www 6508: p_mxu => 'Title for the External Score',
1.349 biermanm 6509: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6510: p_msb => 'Title for the Problem',
6511: p_mdb => 'Title for the Drop Box',
1.336 schafran 6512: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6513: p_mwp => 'Title for Web Page',
1.348 weissno 6514: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6515: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6516: p_mab_alrt1 => 'Not a valid user:domain',
6517: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6518: p_chn => 'New Title',
6519: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6520: p_rmr2a => 'Remove',
6521: p_rmr2b => '?',
6522: p_rmr3a => 'Remove those',
6523: p_rmr3b => 'items?',
6524: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6525: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6526: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6527: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6528: p_ctr2a => 'Cut',
6529: p_ctr2b => '?',
6530: p_ctr3a => 'Cut those',
6531: p_ctr3b => 'items?',
1.478 raeburn 6532: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6533: imsfile => 'You must choose an IMS package for import',
6534: imscms => 'You must select which Course Management System was the source of the IMS package',
6535: invurl => 'Invalid URL',
6536: titbl => 'Title is blank',
1.484.2.30 raeburn 6537: more => '(More ...)',
6538: less => '(Less ...)',
6539: noor => 'No actions selected or changes to settings specified.',
6540: noch => 'No changes to settings specified.',
6541: noac => 'No actions selected.',
1.484.2.67 raeburn 6542: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6543: );
6544:
1.484.2.61 raeburn 6545: &js_escape(\%js_lt);
1.433 raeburn 6546: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6547: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6548: my $main_container_page;
1.484.2.19 raeburn 6549: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6550: $main_container_page = 1;
1.434 raeburn 6551: }
1.484.2.67 raeburn 6552: my $backtourl;
6553: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6554: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6555:
1.484.2.21 raeburn 6556: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6557: my $caller = $1;
6558: if ($caller =~ /^supplemental/) {
6559: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6560: } else {
6561: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6562: $res = &Apache::lonnet::clutter($res);
6563: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6564: my ($url,$anchor);
6565: if ($res =~ /^([^#]+)#([^#]+)$/) {
6566: $url = $1;
6567: $anchor = $2;
6568: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6569: $caller = $1.&escape('#').$anchor;
6570: }
1.484.2.67 raeburn 6571: } else {
6572: $url = $res;
1.484.2.66 raeburn 6573: }
1.484.2.83 raeburn 6574: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6575: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6576: $backtourl .= '?navmap=1';
6577: } else {
6578: $backtourl .= '?symb='.
6579: &HTML::Entities::encode($caller,'<>&"');
6580: }
1.484.2.80 raeburn 6581: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6582: if (($ENV{'SERVER_PORT'} == 443) &&
6583: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6584: unless (&Apache::lonnet::uses_sts()) {
6585: if ($hostname ne '') {
6586: $backtourl = 'http://'.$hostname.$backtourl;
6587: }
6588: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6589: }
6590: }
6591: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6592: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6593: unless (&Apache::lonnet::uses_sts()) {
6594: if ($hostname ne '') {
6595: $backtourl = 'http://'.$hostname.$backtourl;
6596: }
6597: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6598: }
6599: }
6600: }
1.484.2.66 raeburn 6601: if ($anchor ne '') {
6602: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6603: }
1.484.2.57 raeburn 6604: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6605: } else {
6606: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6607: }
6608: }
6609: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6610: $backtourl = '/adm/menu';
6611: } elsif ($supplementalflag) {
1.472 raeburn 6612: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6613: } else {
6614: $backtourl = '/adm/navmaps';
1.472 raeburn 6615: }
6616:
1.484.2.19 raeburn 6617: my $fieldsets = "'ext','doc'";
6618: unless ($main_container_page) {
6619: $fieldsets .=",'ims'";
6620: }
1.484.2.12 raeburn 6621: if ($supplementalflag) {
6622: $fieldsets = "'suppext','suppdoc'";
6623: }
6624:
1.484.2.67 raeburn 6625: my $jsmakefunctions;
6626: if ($canedit) {
6627: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6628: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6629: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6630: if (foldername) {
6631: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6632: targetform.submit();
6633: }
6634: }
6635:
6636: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6637: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6638: if (pagename) {
6639: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6640: targetform.submit();
6641: }
6642: }
6643:
6644: function makeexamupload() {
1.484.2.61 raeburn 6645: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6646: if (title) {
1.329 droeschl 6647: this.document.forms.newexamupload.importdetail.value=
6648: escape(title)+'=/res/lib/templates/examupload.problem';
6649: this.document.forms.newexamupload.submit();
6650: }
6651: }
6652:
6653: function makesmppage() {
1.484.2.61 raeburn 6654: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6655: if (title) {
1.329 droeschl 6656: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6657: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6658: this.document.forms.newsmppg.submit();
6659: }
6660: }
6661:
1.484.2.27 raeburn 6662: function makewebpage(type) {
1.484.2.61 raeburn 6663: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6664: var formname;
6665: if (type == 'supp') {
6666: formname = this.document.forms.supwebpage;
6667: } else {
6668: formname = this.document.forms.newwebpage;
6669: }
6670: if (title) {
6671: var webpage = formname.importdetail.value;
6672: formname.importdetail.value = escape(title)+'='+webpage;
6673: formname.submit();
6674: }
6675: }
6676:
1.329 droeschl 6677: function makesmpproblem() {
1.484.2.61 raeburn 6678: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6679: if (title) {
1.329 droeschl 6680: this.document.forms.newsmpproblem.importdetail.value=
6681: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6682: this.document.forms.newsmpproblem.submit();
6683: }
6684: }
6685:
6686: function makedropbox() {
1.484.2.61 raeburn 6687: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6688: if (title) {
1.329 droeschl 6689: this.document.forms.newdropbox.importdetail.value=
6690: escape(title)+'=/res/lib/templates/DropBox.problem';
6691: this.document.forms.newdropbox.submit();
6692: }
6693: }
6694:
6695: function makebulboard() {
1.484.2.61 raeburn 6696: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6697: if (title) {
6698: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6699: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6700: this.document.forms.newbul.submit();
6701: }
6702: }
6703:
6704: function makeabout() {
1.484.2.61 raeburn 6705: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6706: if (user) {
6707: var comp=new Array();
6708: comp=user.split(':');
6709: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6710: if ((comp[0]) && (comp[1])) {
6711: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6712: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6713: this.document.forms.newaboutsomeone.submit();
6714: } else {
6715: alert("$js_lt{'p_mab_alrt1'}");
6716: }
6717: } else {
6718: alert("$js_lt{'p_mab_alrt2'}");
6719: }
6720: }
1.335 ehlerst 6721: }
1.484.2.67 raeburn 6722:
6723: function makenew(targetform) {
6724: targetform.submit();
1.335 ehlerst 6725: }
1.484.2.67 raeburn 6726:
6727: function changename(folderpath,index,oldtitle) {
6728: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6729: if (title) {
6730: this.document.forms.renameform.markcopy.value='';
6731: this.document.forms.renameform.title.value=title;
6732: this.document.forms.renameform.cmd.value='rename_'+index;
6733: this.document.forms.renameform.folderpath.value=folderpath;
6734: this.document.forms.renameform.submit();
6735: }
1.329 droeschl 6736: }
6737:
1.484.2.67 raeburn 6738: ENDNEWSCRIPT
6739: } else {
6740: $jsmakefunctions = <<ENDNEWSCRIPT;
6741:
6742: function makenewfolder() {
6743: alert("$js_lt{'edri'}");
6744: }
6745:
6746: function makenewpage() {
6747: alert("$js_lt{'edri'}");
6748: }
6749:
6750: function makeexamupload() {
6751: alert("$js_lt{'edri'}");
6752: }
6753:
6754: function makesmppage() {
6755: alert("$js_lt{'edri'}");
6756: }
6757:
6758: function makewebpage(type) {
6759: alert("$js_lt{'edri'}");
6760: }
6761:
6762: function makesmpproblem() {
6763: alert("$js_lt{'edri'}");
6764: }
6765:
6766: function makedropbox() {
6767: alert("$js_lt{'edri'}");
6768: }
6769:
6770: function makebulboard() {
6771: alert("$js_lt{'edri'}");
6772: }
6773:
6774: function makeabout() {
6775: alert("$js_lt{'edri'}");
6776: }
6777:
6778: function changename() {
6779: alert("$js_lt{'edri'}");
6780: }
6781:
6782: function makenew() {
6783: alert("$js_lt{'edri'}");
6784: }
6785:
6786: function groupimport() {
6787: alert("$js_lt{'edri'}");
6788: }
6789:
6790: function groupsearch() {
6791: alert("$js_lt{'edri'}");
6792: }
6793:
6794: function groupopen(url,recover) {
6795: var options="scrollbars=1,resizable=1,menubar=0";
6796: idxflag=1;
6797: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6798: idx.focus();
6799: }
6800:
6801: ENDNEWSCRIPT
6802:
6803: }
6804: return <<ENDSCRIPT;
6805:
6806: $jsmakefunctions
6807:
1.484.2.13 raeburn 6808: function toggleUpload(caller) {
6809: var blocks = Array($fieldsets);
6810: for (var i=0; i<blocks.length; i++) {
6811: var disp = 'none';
6812: if (caller == blocks[i]) {
6813: var curr = document.getElementById('upload'+caller+'form').style.display;
6814: if (curr == 'none') {
6815: disp='block';
6816: }
6817: }
6818: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6819: }
6820: resize_scrollbox('contentscroll','1','1');
6821: return;
6822: }
6823:
1.484.2.19 raeburn 6824: function toggleMap(caller) {
1.484.2.13 raeburn 6825: var disp = 'none';
1.484.2.19 raeburn 6826: if (document.getElementById('importmapform')) {
6827: if (caller == 'map') {
6828: var curr = document.getElementById('importmapform').style.display;
6829: if (curr == 'none') {
6830: disp='block';
6831: }
1.484.2.12 raeburn 6832: }
1.484.2.19 raeburn 6833: document.getElementById('importmapform').style.display=disp;
6834: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6835: }
1.484.2.19 raeburn 6836: return;
1.329 droeschl 6837: }
6838:
1.484.2.12 raeburn 6839: function makeims(imsform) {
6840: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6841: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6842: return;
6843: }
6844: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6845: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6846: return;
6847: }
6848: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6849: imsform.submit();
6850: }
6851:
1.478 raeburn 6852: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6853: var pickitem;
6854: var picknumitem;
6855: var picknumtext;
6856: if (index == 'all') {
6857: pickitem = document.getElementById('randompickall');
6858: picknumitem = document.getElementById('rpicknumall');
6859: picknumtext = document.getElementById('rpicktextall');
6860: } else {
6861: pickitem = document.getElementById('randompick_'+index);
6862: picknumitem = document.getElementById('rpicknum_'+index);
6863: picknumtext = document.getElementById('randompicknum_'+index);
6864: }
1.478 raeburn 6865: if (pickitem.checked) {
1.484.2.61 raeburn 6866: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6867: if (picknum == '' || picknum == null) {
6868: if (caller == 'check') {
6869: pickitem.checked=false;
1.484.2.29 raeburn 6870: if (index == 'all') {
6871: picknumtext.innerHTML = '';
6872: if (caller == 'link') {
6873: propagateState(targetform,'rpicknum');
6874: }
6875: } else {
1.484.2.30 raeburn 6876: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6877: }
1.478 raeburn 6878: }
6879: } else {
6880: picknum.toString();
6881: var regexdigit=/^\\d+\$/;
6882: if (regexdigit.test(picknum)) {
6883: picknumitem.value = picknum;
1.484.2.29 raeburn 6884: if (index == 'all') {
1.484.2.30 raeburn 6885: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6886: if (caller == 'link') {
6887: propagateState(targetform,'rpicknum');
6888: }
6889: } else {
6890: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6891: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6892: }
1.478 raeburn 6893: } else {
6894: if (caller == 'check') {
1.484.2.29 raeburn 6895: if (index == 'all') {
6896: picknumtext.innerHTML = '';
6897: if (caller == 'link') {
6898: propagateState(targetform,'rpicknum');
6899: }
6900: } else {
6901: pickitem.checked=false;
1.484.2.30 raeburn 6902: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6903: }
1.478 raeburn 6904: }
6905: return;
6906: }
6907: }
6908: } else {
1.484.2.29 raeburn 6909: picknumitem.value = '';
6910: picknumtext.innerHTML = '';
6911: if (index == 'all') {
6912: if (caller == 'link') {
6913: propagateState(targetform,'rpicknum');
6914: }
6915: } else {
1.484.2.30 raeburn 6916: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6917: }
6918: }
6919: }
6920:
6921: function propagateState(form,param) {
6922: if (document.getElementById(param+'all')) {
6923: var setcheck = 0;
6924: var rpick = 0;
6925: if (param == 'rpicknum') {
6926: if (document.getElementById('randompickall')) {
6927: if (document.getElementById('randompickall').checked) {
6928: if (document.getElementById('rpicknumall')) {
6929: rpick = document.getElementById('rpicknumall').value;
6930: }
6931: }
6932: }
6933: } else {
6934: if (document.getElementById(param+'all').checked) {
6935: setcheck = 1;
6936: }
6937: }
1.484.2.30 raeburn 6938: var allidxlist;
6939: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6940: if (document.getElementById('all'+param+'idx')) {
6941: allidxlist = document.getElementById('all'+param+'idx').value;
6942: }
6943: var actions = new Array ('remove','cut','copy');
6944: for (var i=0; i<actions.length; i++) {
6945: if (actions[i] != param) {
6946: if (document.getElementById(actions[i]+'all')) {
6947: document.getElementById(actions[i]+'all').checked = false;
6948: }
6949: }
6950: }
6951: }
1.484.2.29 raeburn 6952: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6953: allidxlist = form.allidx.value;
6954: }
6955: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6956: allidxlist = form.allmapidx.value;
6957: }
6958: if ((allidxlist != '') && (allidxlist != null)) {
6959: var allidxs = allidxlist.split(',');
6960: if (allidxs.length > 1) {
6961: for (var i=0; i<allidxs.length; i++) {
6962: if (document.getElementById(param+'_'+allidxs[i])) {
6963: if (param == 'rpicknum') {
6964: if (document.getElementById('randompick_'+allidxs[i])) {
6965: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6966: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6967: if (rpick > 0) {
6968: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6969: } else {
6970: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6971: }
6972: }
6973: }
6974: } else {
1.484.2.29 raeburn 6975: if (setcheck == 1) {
6976: document.getElementById(param+'_'+allidxs[i]).checked = true;
6977: } else {
6978: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6979: if (param == 'randompick') {
6980: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6981: }
1.484.2.29 raeburn 6982: }
6983: }
6984: }
6985: }
1.484.2.30 raeburn 6986: if (setcheck == 1) {
6987: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6988: var actions = new Array('copy','cut','remove');
6989: for (var i=0; i<actions.length; i++) {
6990: var otheractions;
6991: var otheridxs;
6992: if (actions[i] === param) {
6993: continue;
6994: } else {
6995: if (document.getElementById('all'+actions[i]+'idx')) {
6996: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6997: otheridxs = otheractions.split(',');
6998: if (otheridxs.length > 1) {
6999: for (var j=0; j<otheridxs.length; j++) {
7000: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7001: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7002: }
1.484.2.29 raeburn 7003: }
7004: }
7005: }
7006: }
1.484.2.30 raeburn 7007: }
1.484.2.29 raeburn 7008: }
7009: }
7010: }
7011: }
1.478 raeburn 7012: }
1.484.2.29 raeburn 7013: return;
7014: }
7015:
1.484.2.63 raeburn 7016: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7017: var canedit = '$canedit';
7018: if (canedit == '') {
7019: alert("$js_lt{'edri'}");
7020: return;
7021: }
1.484.2.30 raeburn 7022: var dosettings;
7023: var doaction;
7024: var control = document.togglemultsettings;
7025: if (context == 'actions') {
7026: control = document.togglemultactions;
7027: doaction = 1;
7028: } else {
7029: dosettings = 1;
7030: }
7031: if (control) {
7032: if (control.showmultpick.length) {
7033: for (var i=0; i<control.showmultpick.length; i++) {
7034: if (control.showmultpick[i].checked) {
7035: if (control.showmultpick[i].value == 1) {
7036: if (context == 'settings') {
7037: dosettings = 0;
7038: } else {
7039: doaction = 0;
7040: }
7041: }
7042: }
7043: }
7044: }
7045: }
7046: if (context == 'settings') {
7047: if (dosettings == 1) {
7048: targetform.changeparms.value=param;
7049: targetform.submit();
7050: }
7051: }
7052: if (context == 'actions') {
7053: if (doaction == 1) {
7054: targetform.cmd.value=param+'_'+index;
7055: targetform.folderpath.value=folderpath;
7056: targetform.markcopy.value=idx+':'+param;
7057: targetform.copyfolder.value=folder+'.'+container;
7058: if (param == 'remove') {
1.484.2.63 raeburn 7059: var doremove = 0;
7060: if (skip_confirm) {
7061: if (confirm_removal) {
7062: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7063: doremove = 1;
7064: }
7065: } else {
7066: doremove = 1;
7067: }
7068: } else {
7069: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7070: doremove = 1;
7071: }
7072: }
7073: if (doremove) {
1.484.2.30 raeburn 7074: targetform.markcopy.value='';
7075: targetform.copyfolder.value='';
1.484.2.29 raeburn 7076: targetform.submit();
7077: }
7078: }
1.484.2.30 raeburn 7079: if (param == 'cut') {
1.484.2.61 raeburn 7080: 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 7081: targetform.submit();
7082: return;
7083: }
7084: }
7085: if (param == 'copy') {
7086: targetform.submit();
7087: return;
7088: }
7089: targetform.markcopy.value='';
7090: targetform.copyfolder.value='';
7091: targetform.cmd.value='';
7092: targetform.folderpath.value='';
7093: return;
7094: } else {
7095: if (document.getElementById(param+'_'+idx)) {
7096: item = document.getElementById(param+'_'+idx);
7097: if (item.type == 'checkbox') {
7098: if (item.checked) {
7099: item.checked = false;
7100: } else {
7101: item.checked = true;
7102: singleCheck(item,idx,param);
7103: }
7104: }
7105: }
7106: }
7107: }
7108: return;
7109: }
7110:
7111: function singleCheck(caller,idx,action) {
7112: actions = new Array('cut','copy','remove');
7113: if (caller.checked) {
7114: for (var i=0; i<actions.length; i++) {
7115: if (actions[i] != action) {
7116: if (document.getElementById(actions[i]+'_'+idx)) {
7117: if (document.getElementById(actions[i]+'_'+idx).checked) {
7118: document.getElementById(actions[i]+'_'+idx).checked = false;
7119: }
7120: }
7121: }
1.484.2.29 raeburn 7122: }
7123: }
7124: return;
1.478 raeburn 7125: }
7126:
1.334 muellerd 7127: function unselectInactive(nav) {
1.335 ehlerst 7128: currentNav = document.getElementById(nav);
7129: currentLis = currentNav.getElementsByTagName('LI');
7130: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7131: if (currentLis[i].className == 'goback') {
7132: currentLis[i].className = 'goback';
7133: } else {
7134: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7135: currentLis[i].className = 'right';
1.472 raeburn 7136: } else {
1.374 tempelho 7137: currentLis[i].className = 'i';
1.472 raeburn 7138: }
7139: }
1.335 ehlerst 7140: }
1.332 tempelho 7141: }
7142:
1.334 muellerd 7143: function hideAll(current, nav, data) {
1.335 ehlerst 7144: unselectInactive(nav);
1.484.2.43 raeburn 7145: if (current) {
7146: if (current.className == 'right'){
1.374 tempelho 7147: current.className = 'right active'
1.484.2.43 raeburn 7148: } else {
1.374 tempelho 7149: current.className = 'active';
1.484.2.43 raeburn 7150: }
1.374 tempelho 7151: }
1.335 ehlerst 7152: currentData = document.getElementById(data);
7153: currentDivs = currentData.getElementsByTagName('DIV');
7154: for (i = 0; i < currentDivs.length; i++) {
7155: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7156: currentDivs[i].style.display = 'none';
1.330 tempelho 7157: }
7158: }
1.335 ehlerst 7159: }
1.330 tempelho 7160:
1.374 tempelho 7161: function openTabs(pageId) {
7162: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7163: if(tabnav.length > 2 ){
1.389 tempelho 7164: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7165: currentLis = currentNav.getElementsByTagName('LI');
7166: for(i = 0; i< currentLis.length; i++){
7167: if(currentLis[i].className == 'active') {
1.375 tempelho 7168: funcString = currentLis[i].onclick.toString();
7169: tab = funcString.split('"');
1.420 onken 7170: if(tab.length < 2) {
7171: tab = funcString.split("'");
7172: }
1.375 tempelho 7173: currentData = document.getElementById(tab[1]);
7174: currentData.style.display = 'block';
1.374 tempelho 7175: }
7176: }
7177: }
7178: }
7179:
1.334 muellerd 7180: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7181: currstate = current.className;
1.334 muellerd 7182: hideAll(current, nav, data);
1.375 tempelho 7183: openTabs(pageId);
1.334 muellerd 7184: unselectInactive(nav);
1.484.2.43 raeburn 7185: if ((currstate == 'active') || (currstate == 'right active')) {
7186: if (currstate == 'active') {
7187: current.className = '';
7188: } else {
7189: current.className = 'right';
7190: }
7191: activeTab = '';
7192: toggleUpload();
7193: toggleMap();
7194: resize_scrollbox('contentscroll','1','0');
7195: return;
7196: } else {
7197: current.className = 'active';
7198: }
1.330 tempelho 7199: currentData = document.getElementById(pageId);
7200: currentData.style.display = 'block';
1.458 raeburn 7201: activeTab = pageId;
1.484.2.12 raeburn 7202: toggleUpload();
1.484.2.14 raeburn 7203: toggleMap();
1.433 raeburn 7204: if (nav == 'mainnav') {
7205: var storedpath = "$docs_folderpath";
1.434 raeburn 7206: var storedpage = "$main_container_page";
1.433 raeburn 7207: var reg = new RegExp("^supplemental");
7208: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7209: if (storedpage == 1) {
7210: document.simpleedit.folderpath.value = '';
7211: document.uploaddocument.folderpath.value = '';
7212: } else {
7213: if (reg.test(storedpath)) {
7214: document.simpleedit.folderpath.value = '$toplevelmain';
7215: document.uploaddocument.folderpath.value = '$toplevelmain';
7216: document.newext.folderpath.value = '$toplevelmain';
7217: } else {
7218: document.simpleedit.folderpath.value = storedpath;
7219: document.uploaddocument.folderpath.value = storedpath;
7220: document.newext.folderpath.value = storedpath;
7221: }
1.433 raeburn 7222: }
7223: } else {
1.434 raeburn 7224: if (reg.test(storedpath)) {
7225: document.simpleedit.folderpath.value = storedpath;
7226: document.supuploaddocument.folderpath.value = storedpath;
7227: document.supnewext.folderpath.value = storedpath;
7228: } else {
1.433 raeburn 7229: document.simpleedit.folderpath.value = '$toplevelsupp';
7230: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7231: document.supnewext.folderpath.value = '$toplevelsupp';
7232: }
7233: }
7234: }
1.484.2.3 raeburn 7235: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7236: return false;
7237: }
1.329 droeschl 7238:
1.472 raeburn 7239: function toContents(jumpto) {
7240: var newurl = '$backtourl';
1.484.2.21 raeburn 7241: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7242: newurl = newurl+'?postdata='+jumpto;
7243: }
7244: location.href=newurl;
7245: }
7246:
1.484.2.30 raeburn 7247: function togglePick(caller,value) {
7248: var disp = 'none';
7249: if (document.getElementById('multi'+caller)) {
7250: var curr = document.getElementById('multi'+caller).style.display;
7251: if (value == 1) {
7252: disp='block';
7253: }
7254: if (curr == disp) {
7255: return;
7256: }
7257: document.getElementById('multi'+caller).style.display=disp;
7258: if (value == 1) {
1.484.2.61 raeburn 7259: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7260: } else {
7261: document.getElementById('more'+caller).innerHTML = '';
7262: }
7263: if (caller == 'actions') {
7264: setClass(value);
7265: setBoxes(value);
7266: }
7267: }
7268: var showButton = multiSettings();
7269: if (showButton != 1) {
7270: showButton = multiActions();
7271: }
7272: if (document.getElementById('multisave')) {
7273: if (showButton == 1) {
7274: document.getElementById('multisave').style.display='block';
7275: } else {
7276: document.getElementById('multisave').style.display='none';
7277: }
7278: }
7279: resize_scrollbox('contentscroll','1','1');
7280: return;
7281: }
7282:
7283: function toggleCheckUncheck(caller,more) {
7284: if (more == 1) {
1.484.2.61 raeburn 7285: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7286: document.getElementById('allfields'+caller).style.display='block';
7287: } else {
1.484.2.61 raeburn 7288: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7289: document.getElementById('allfields'+caller).style.display='none';
7290: }
7291: resize_scrollbox('contentscroll','1','1');
7292: }
7293:
7294: function multiSettings() {
7295: var inuse = 0;
7296: var settingsform = document.togglemultsettings;
7297: if (settingsform.showmultpick.length > 1) {
7298: for (var i=0; i<settingsform.showmultpick.length; i++) {
7299: if (settingsform.showmultpick[i].checked) {
7300: if (settingsform.showmultpick[i].value == 1) {
7301: inuse = 1;
7302: }
7303: }
7304: }
7305: }
7306: return inuse;
7307: }
7308:
7309: function multiActions() {
7310: var inuse = 0;
7311: var actionsform = document.togglemultactions;
7312: if (actionsform.showmultpick.length > 1) {
7313: for (var i=0; i<actionsform.showmultpick.length; i++) {
7314: if (actionsform.showmultpick[i].checked) {
7315: if (actionsform.showmultpick[i].value == 1) {
7316: inuse = 1;
7317: }
7318: }
7319: }
7320: }
7321: return inuse;
7322: }
7323:
7324: function checkSubmits() {
7325: var numchanges = 0;
7326: var form = document.saveactions;
7327: var doactions = multiActions();
7328: var cutwarnings = 0;
7329: var remwarnings = 0;
1.484.2.63 raeburn 7330: var removalinfo = 0;
1.484.2.30 raeburn 7331: if (doactions == 1) {
7332: var remidxlist = document.cumulativeactions.allremoveidx.value;
7333: if ((remidxlist != '') && (remidxlist != null)) {
7334: var remidxs = remidxlist.split(',');
7335: for (var i=0; i<remidxs.length; i++) {
7336: if (document.getElementById('remove_'+remidxs[i])) {
7337: if (document.getElementById('remove_'+remidxs[i]).checked) {
7338: form.multiremove.value += remidxs[i]+',';
7339: numchanges ++;
7340: if (document.getElementById('skip_remove_'+remidxs[i])) {
7341: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7342: remwarnings ++;
7343: }
7344: }
1.484.2.63 raeburn 7345: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7346: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7347: removalinfo ++;
7348: }
7349: }
1.484.2.30 raeburn 7350: }
7351: }
7352: }
7353: }
7354: var cutidxlist = document.cumulativeactions.allcutidx.value;
7355: if ((cutidxlist != '') && (cutidxlist != null)) {
7356: var cutidxs = cutidxlist.split(',');
7357: for (var i=0; i<cutidxs.length; i++) {
7358: if (document.getElementById('cut_'+cutidxs[i])) {
7359: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7360: form.multicut.value += cutidxs[i]+',';
7361: numchanges ++;
7362: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7363: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7364: cutwarnings ++;
7365: }
7366: }
7367: }
7368: }
7369: }
7370: }
7371: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7372: if ((copyidxlist != '') && (copyidxlist != null)) {
7373: var copyidxs = copyidxlist.split(',');
7374: for (var i=0; i<copyidxs.length; i++) {
7375: if (document.getElementById('copy_'+copyidxs[i])) {
7376: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7377: form.multicopy.value += copyidxs[i]+',';
7378: numchanges ++;
7379: }
7380: }
7381: }
7382: }
7383: if (numchanges > 0) {
7384: form.multichange.value = numchanges;
7385: }
7386: }
7387: var dosettings = multiSettings();
7388: var haschanges = 0;
7389: if (dosettings == 1) {
7390: form.allencrypturl.value = '';
7391: form.allhiddenresource.value = '';
7392: form.changeparms.value = 'all';
7393: var patt=new RegExp(",\$");
7394: var allidxlist = document.cumulativesettings.allidx.value;
7395: if ((allidxlist != '') && (allidxlist != null)) {
7396: var allidxs = allidxlist.split(',');
7397: if (allidxs.length > 1) {
7398: for (var i=0; i<allidxs.length; i++) {
7399: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7400: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7401: form.allhiddenresource.value += allidxs[i]+',';
7402: }
7403: }
7404: if (document.getElementById('encrypturl_'+allidxs[i])) {
7405: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7406: form.allencrypturl.value += allidxs[i]+',';
7407: }
1.484.2.29 raeburn 7408: }
7409: }
1.484.2.30 raeburn 7410: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7411: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7412: }
7413: }
7414: form.allrandompick.value = '';
7415: form.allrandomorder.value = '';
7416: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7417: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7418: var allmapidxs = allmapidxlist.split(',');
7419: for (var i=0; i<allmapidxs.length; i++) {
7420: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7421: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7422: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7423: if ((randompick.checked) && (rpicknum.value != '')) {
7424: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7425: }
7426: if (randorder.checked) {
7427: form.allrandomorder.value += allmapidxs[i]+',';
7428: }
7429: }
7430: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7431: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7432: }
7433: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7434: haschanges = 1;
7435: }
7436: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7437: haschanges = 1;
7438: }
7439: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7440: haschanges = 1;
7441: }
7442: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7443: haschanges = 1;
7444: }
7445: }
7446: if (doactions == 1) {
7447: if (numchanges > 0) {
1.484.2.63 raeburn 7448: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7449: if (remwarnings > 0) {
1.484.2.61 raeburn 7450: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7451: return false;
7452: }
7453: }
1.484.2.63 raeburn 7454: if (removalinfo > 0) {
7455: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7456: return false;
7457: }
7458: }
1.484.2.30 raeburn 7459: if (cutwarnings > 0) {
1.484.2.61 raeburn 7460: 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 7461: return false;
1.484.2.29 raeburn 7462: }
7463: }
7464: }
1.484.2.30 raeburn 7465: form.submit();
7466: return true;
7467: }
7468: }
7469: if (dosettings == 1) {
7470: if (haschanges == 1) {
7471: form.submit();
7472: return true;
1.484.2.29 raeburn 7473: }
7474: }
1.484.2.30 raeburn 7475: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7476: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7477: } else {
7478: if (dosettings == 1) {
1.484.2.61 raeburn 7479: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7480: } else {
1.484.2.61 raeburn 7481: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7482: }
7483: }
7484: return false;
7485: }
7486:
7487: function setClass(value) {
7488: var cutclass = 'LC_docs_cut';
7489: var copyclass = 'LC_docs_copy';
7490: var removeclass = 'LC_docs_remove';
7491: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7492: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7493: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7494: var links = document.getElementsByTagName('a');
7495: for (var i=0; i<links.length; i++) {
7496: var classes = links[i].className;
7497: if (cutreg.test(classes)) {
7498: links[i].className = cutclass;
7499: if (value == 1) {
7500: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7501: }
1.484.2.30 raeburn 7502: } else {
7503: if (copyreg.test(classes)) {
7504: links[i].className = copyclass;
7505: if (value == 1) {
7506: links[i].className += " LC_menubuttons_link";
7507: }
7508: } else {
7509: if (removereg.test(classes)) {
7510: links[i].className = removeclass;
7511: if (value == 1) {
7512: links[i].className += " LC_menubuttons_link";
7513: }
7514: }
1.484.2.29 raeburn 7515: }
7516: }
7517: }
1.484.2.30 raeburn 7518: return;
1.484.2.29 raeburn 7519: }
7520:
1.484.2.30 raeburn 7521: function setBoxes(value) {
7522: var remidxlist = document.cumulativeactions.allremoveidx.value;
7523: if ((remidxlist != '') && (remidxlist != null)) {
7524: var remidxs = remidxlist.split(',');
7525: for (var i=0; i<remidxs.length; i++) {
7526: if (document.getElementById('remove_'+remidxs[i])) {
7527: var item = document.getElementById('remove_'+remidxs[i]);
7528: if (value == 1) {
7529: item.className = 'LC_docs_remove';
7530: } else {
7531: item.className = 'LC_hidden';
7532: }
7533: }
1.484.2.29 raeburn 7534: }
7535: }
1.484.2.30 raeburn 7536: var cutidxlist = document.cumulativeactions.allcutidx.value;
7537: if ((cutidxlist != '') && (cutidxlist != null)) {
7538: var cutidxs = cutidxlist.split(',');
7539: for (var i=0; i<cutidxs.length; i++) {
7540: if (document.getElementById('cut_'+cutidxs[i])) {
7541: var item = document.getElementById('cut_'+cutidxs[i]);
7542: if (value == 1) {
7543: item.className = 'LC_docs_cut';
7544: } else {
7545: item.className = 'LC_hidden';
7546: }
7547: }
7548: }
7549: }
7550: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7551: if ((copyidxlist != '') && (copyidxlist != null)) {
7552: var copyidxs = copyidxlist.split(',');
7553: for (var i=0; i<copyidxs.length; i++) {
7554: if (document.getElementById('copy_'+copyidxs[i])) {
7555: var item = document.getElementById('copy_'+copyidxs[i]);
7556: if (value == 1) {
7557: item.className = 'LC_docs_copy';
7558: } else {
7559: item.className = 'LC_hidden';
7560: }
7561: }
1.484.2.29 raeburn 7562: }
7563: }
7564: return;
7565: }
7566:
1.484.2.67 raeburn 7567: ENDSCRIPT
1.329 droeschl 7568: }
1.457 raeburn 7569:
1.483 raeburn 7570: sub history_tab_js {
7571: return <<"ENDHIST";
7572: function toggleHistoryDisp(choice) {
7573: document.docslogform.docslog.value = choice;
7574: document.docslogform.submit();
7575: return;
7576: }
7577:
7578: ENDHIST
7579: }
7580:
1.484 raeburn 7581: sub inject_data_js {
7582: return <<ENDINJECT;
7583:
7584: function injectData(current, hiddenField, name, value) {
7585: currentElement = document.getElementById(hiddenField);
7586: currentElement.name = name;
7587: currentElement.value = value;
7588: current.submit();
7589: }
7590:
7591: ENDINJECT
7592: }
7593:
7594: sub dump_switchserver_js {
7595: my @hosts = @_;
1.484.2.61 raeburn 7596: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7597: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7598: swit => 'Switch server?',
1.484.2.61 raeburn 7599: );
7600: my %html_js_lt = &Apache::lonlocal::texthash(
7601: swit => 'Switch server?',
1.484.2.43 raeburn 7602: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7603: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7604: chos => 'Choose server',
7605: );
1.484.2.61 raeburn 7606: &js_escape(\%js_lt);
7607: &html_escape(\%html_js_lt);
7608: &js_escape(\%html_js_lt);
1.484 raeburn 7609: my $role = $env{'request.role'};
7610: my $js = <<"ENDSWJS";
7611: <script type="text/javascript">
7612: function write_switchserver() {
7613: var server;
7614: if (document.setserver.posshosts.length > 0) {
7615: for (var i=0; i<document.setserver.posshosts.length; i++) {
7616: if (document.setserver.posshosts[i].checked) {
7617: server = document.setserver.posshosts[i].value;
7618: }
7619: }
7620: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7621: }
7622: window.close();
7623: }
7624: </script>
7625:
7626: ENDSWJS
7627:
7628: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7629: {'only_body' => 1,
7630: 'js_ready' => 1,});
7631: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7632:
7633: my $hostpicker;
7634: my $count = 0;
7635: foreach my $host (sort(@hosts)) {
7636: my $checked;
7637: if ($count == 0) {
7638: $checked = ' checked="checked"';
7639: }
7640: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7641: $host.'"'.$checked.' />'.$host.'</label> ';
7642: $count++;
7643: }
7644:
7645: return <<"ENDSWITCHJS";
7646:
7647: function dump_needs_switchserver(url) {
7648: if (url!='' && url!= null) {
1.484.2.61 raeburn 7649: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7650: go(url);
7651: }
7652: }
7653: return;
7654: }
7655:
7656: function choose_switchserver_window() {
7657: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7658: newWindow.document.open();
7659: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7660: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7661: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7662: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7663: '<form name="setserver" method="post" action="" \\/>\\n'+
7664: '$hostpicker\\n'+
7665: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7666: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7667: 'onclick="write_switchserver();" \\/>\\n'+
7668: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7669: newWindow.document.writeln('$endpage');
7670: newWindow.document.close();
7671: newWindow.focus();
7672: }
7673:
7674: ENDSWITCHJS
7675: }
7676:
7677: sub makedocslogform {
7678: my ($formelems,$docslog) = @_;
7679: return <<"LOGSFORM";
7680: <form action="/adm/coursedocs" method="post" name="docslogform">
7681: <input type="hidden" name="docslog" value="$docslog" />
7682: $formelems
7683: </form>
7684: LOGSFORM
7685: }
7686:
7687: sub makesimpleeditform {
7688: my ($formelems) = @_;
7689: return <<"SIMPFORM";
7690: <form name="simpleedit" method="post" action="/adm/coursedocs">
7691: <input type="hidden" name="importdetail" value="" />
7692: $formelems
7693: </form>
7694: SIMPFORM
7695: }
7696:
1.329 droeschl 7697: 1;
7698: __END__
7699:
7700:
7701: =head1 NAME
7702:
7703: Apache::londocs.pm
7704:
7705: =head1 SYNOPSIS
7706:
7707: This is part of the LearningOnline Network with CAPA project
7708: described at http://www.lon-capa.org.
7709:
7710: =head1 SUBROUTINES
7711:
7712: =over
7713:
7714: =item %help=()
7715:
7716: Available help topics
7717:
7718: =item mapread()
7719:
1.344 bisitz 7720: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7721: @order and @resources, determines status
7722: sets @order - pointer to resources in right order
7723: sets @resources - array with the resources with correct idx
7724:
7725: =item authorhosts()
7726:
7727: Return hash with valid author names
7728:
7729: =item clean()
7730:
7731: =item dumpcourse()
7732:
7733: Actually dump course
7734:
7735: =item group_import()
7736:
7737: Imports the given (name, url) resources into the course
7738: coursenum, coursedom, and folder must precede the list
7739:
7740: =item breadcrumbs()
7741:
7742: =item log_docs()
7743:
7744: =item docs_change_log()
7745:
7746: =item update_paste_buffer()
7747:
7748: =item print_paste_buffer()
7749:
7750: =item do_paste_from_buffer()
7751:
1.484.2.30 raeburn 7752: =item do_buffer_empty()
7753:
7754: =item clear_from_buffer()
7755:
1.484.2.7 raeburn 7756: =item get_newmap_url()
7757:
7758: =item dbcopy()
7759:
7760: =item uniqueness_check()
7761:
7762: =item contained_map_check()
7763:
7764: =item url_paste_fixups()
7765:
7766: =item apply_fixups()
7767:
7768: =item copy_dependencies()
7769:
1.329 droeschl 7770: =item update_parameter()
7771:
7772: =item handle_edit_cmd()
7773:
7774: =item editor()
7775:
7776: =item process_file_upload()
7777:
7778: =item process_secondary_uploads()
7779:
7780: =item is_supplemental_title()
7781:
7782: =item entryline()
7783:
7784: =item tiehash()
7785:
7786: =item untiehash()
7787:
7788: =item checkonthis()
7789:
7790: check on this
7791:
7792: =item verifycontent()
7793:
7794: Verify Content
7795:
1.484.2.78 raeburn 7796: =item devalidateversioncache()
7797:
7798: =item checkversions()
1.329 droeschl 7799:
7800: Check Versions
7801:
7802: =item mark_hash_old()
7803:
7804: =item is_hash_old()
7805:
7806: =item changewarning()
7807:
7808: =item init_breadcrumbs()
7809:
7810: Breadcrumbs for special functions
7811:
1.484 raeburn 7812: =item create_list_elements()
7813:
7814: =item create_form_ul()
7815:
7816: =item startContentScreen()
7817:
7818: =item endContentScreen()
7819:
7820: =item supplemental_base()
7821:
7822: =item embedded_form_elems()
7823:
7824: =item embedded_destination()
7825:
7826: =item return_to_editor()
7827:
7828: =item decompression_info()
7829:
7830: =item decompression_phase_one()
7831:
7832: =item decompression_phase_two()
7833:
7834: =item remove_archive()
7835:
7836: =item generate_admin_menu()
7837:
7838: =item generate_edit_table()
7839:
7840: =item editing_js()
7841:
7842: =item history_tab_js()
7843:
7844: =item inject_data_js()
7845:
7846: =item dump_switchserver_js()
7847:
1.484.2.3 raeburn 7848: =item resize_scrollbox_js()
1.484 raeburn 7849:
7850: =item makedocslogform()
7851:
1.484.2.3 raeburn 7852: =item makesimpleeditform()
7853:
1.329 droeschl 7854: =back
7855:
7856: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>