Annotation of loncom/interface/londocs.pm, revision 1.484.2.91
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.91! raeburn 4: # $Id: londocs.pm,v 1.484.2.90 2020/09/09 02:08:15 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'; }
1.484.2.27 raeburn 679: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
680: my $filepath = $1;
1.484.2.91! raeburn 681: my $fname;
! 682: if ($name eq '') {
! 683: $name = &mt('Web Page');
1.484.2.27 raeburn 684: $fname = 'web';
685: } else {
1.484.2.91! raeburn 686: $fname = $name;
! 687: $fname=&Apache::lonnet::clean_filename($fname);
! 688: if ($fname eq '') {
! 689: $fname = 'web';
! 690: } elsif (length($fname) > 15) {
! 691: $fname = substr($fname,0,14);
! 692: }
1.484.2.27 raeburn 693: }
1.484.2.91! raeburn 694: my $title = &Apache::loncommon::cleanup_html($name);
1.484.2.27 raeburn 695: my $initialtext = &mt('Replace with your own content.');
696: my $newhtml = <<END;
1.484.2.31 raeburn 697: <html>
1.484.2.27 raeburn 698: <head>
1.484.2.91! raeburn 699: <title>$title</title>
1.484.2.27 raeburn 700: </head>
701: <body bgcolor="#ffffff">
702: $initialtext
703: </body>
704: </html>
705: END
706: $env{'form.output'}=$newhtml;
707: my $result =
708: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
709: 'output',
710: "$filepath/$residx/$fname.html");
711: if ($result =~ m{^/uploaded/}) {
712: $url = $result;
713: if ($filepath =~ /^supplemental/) {
714: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
715: $env{'user.domain'}.'___&&&___'.$name;
716: }
717: } else {
718: return (&mt('Failed to save new web page.'),1);
719: }
720: }
1.484.2.91! raeburn 721: $name = &LONCAPA::map::qtunescape($name);
1.484.2.30 raeburn 722: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 723: $LONCAPA::map::resources[$residx] =
1.329 droeschl 724: join(':', ($name, $url, $ext, 'normal', 'res'));
725: }
726: }
1.484.2.23 raeburn 727: if ($importuploaded) {
728: my %import_errors;
729: my %updated = (
730: removefrommap => \%removefrommap,
731: removeparam => \%removeparam,
732: );
1.484.2.26 raeburn 733: my ($result,$msgsarray,$lockerror) =
734: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 735: if (keys(%import_errors) > 0) {
736: $fixuperrors =
737: '<p span class="LC_warning">'."\n".
738: &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".
739: '<ul>'."\n";
740: foreach my $key (sort(keys(%import_errors))) {
741: $fixuperrors .= '<li>'.$key.'</li>'."\n";
742: }
743: $fixuperrors .= '</ul></p>'."\n";
744: }
1.484.2.26 raeburn 745: if (ref($msgsarray) eq 'ARRAY') {
746: if (@{$msgsarray} > 0) {
747: $fixuperrors .= '<p class="LC_info">'.
748: join('<br />',@{$msgsarray}).
749: '</p>';
750: }
751: }
752: if ($lockerror) {
753: $fixuperrors .= '<p class="LC_error">'.
754: $lockerror.
755: '</p>';
756: }
1.484.2.23 raeburn 757: }
758: my ($errtext,$fatal) =
759: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 760: unless ($fatal) {
761: if ($folder =~ /^supplemental/) {
762: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 763: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
764: $folder.'.'.$container);
1.484.2.37 raeburn 765: }
766: }
1.484.2.23 raeburn 767: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 768: }
769:
770: sub log_docs {
1.484.2.8 raeburn 771: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 772: }
773:
774: {
775: my @oldresources=();
776: my @oldorder=();
777: my $parmidx;
778: my %parmaction=();
779: my %parmvalue=();
780: my $changedflag;
781:
782: sub snapshotbefore {
783: @oldresources=@LONCAPA::map::resources;
784: @oldorder=@LONCAPA::map::order;
785: $parmidx=undef;
786: %parmaction=();
787: %parmvalue=();
788: $changedflag=0;
789: }
790:
791: sub remember_parms {
792: my ($idx,$parameter,$action,$value)=@_;
793: $parmidx=$idx;
794: $parmaction{$parameter}=$action;
795: $parmvalue{$parameter}=$value;
796: $changedflag=1;
797: }
798:
799: sub log_differences {
800: my ($plain)=@_;
801: my %storehash=('folder' => $plain,
802: 'currentfolder' => $env{'form.folder'});
803: if ($parmidx) {
804: $storehash{'parameter_res'}=$oldresources[$parmidx];
805: foreach my $parm (keys(%parmaction)) {
806: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
807: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
808: }
809: }
810: my $maxidx=$#oldresources;
811: if ($#LONCAPA::map::resources>$#oldresources) {
812: $maxidx=$#LONCAPA::map::resources;
813: }
814: for (my $idx=0; $idx<=$maxidx; $idx++) {
815: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
816: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
817: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
818: $changedflag=1;
819: }
820: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
821: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
822: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
823: $changedflag=1;
824: }
825: }
826: $storehash{'maxidx'}=$maxidx;
827: if ($changedflag) { &log_docs(\%storehash); }
828: }
829: }
830:
831: sub docs_change_log {
1.484.2.67 raeburn 832: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 833: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 834: my $navmap;
1.483 raeburn 835: my $js = '<script type="text/javascript">'."\n".
836: '// <![CDATA['."\n".
837: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 838: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.80 raeburn 839: $coursedom,$coursenum,$canedit,'',\$navmap)."\n".
1.483 raeburn 840: &history_tab_js()."\n".
1.484 raeburn 841: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 842: '// ]]>'."\n".
843: '</script>'."\n";
1.484 raeburn 844: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
845: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 846: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 847: my %orderhash;
848: my $container='sequence';
849: my $pathitem;
1.484.2.19 raeburn 850: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 851: $container='page';
852: }
1.484.2.19 raeburn 853: my $folderpath=$env{'form.folderpath'};
854: if ($folderpath eq '') {
1.484.2.67 raeburn 855: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 856: }
1.484.2.67 raeburn 857: undef($navmap);
1.484.2.19 raeburn 858: $pathitem = '<input type="hidden" name="folderpath" value="'.
859: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 860: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
861: my $jumpto = $readfile;
862: $jumpto =~ s{^/}{};
863: my $tid = 1;
1.484.2.7 raeburn 864: if ($supplementalflag) {
865: $tid = 2;
866: }
1.484.2.19 raeburn 867: my ($breadcrumbtrail) =
1.484.2.18 raeburn 868: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 869: $r->print($breadcrumbtrail.
870: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
871: $readfile));
1.329 droeschl 872: my %docslog=&Apache::lonnet::dump('nohist_docslog',
873: $env{'course.'.$env{'request.course.id'}.'.domain'},
874: $env{'course.'.$env{'request.course.id'}.'.num'});
875:
876: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
877:
878: my %saveable_parameters = ('show' => 'scalar',);
879: &Apache::loncommon::store_course_settings('docs_log',
880: \%saveable_parameters);
881: &Apache::loncommon::restore_course_settings('docs_log',
882: \%saveable_parameters);
883: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 884: # FIXME: internationalization seems wrong here
1.329 droeschl 885: my %lt=('hiddenresource' => 'Resources hidden',
886: 'encrypturl' => 'URL hidden',
887: 'randompick' => 'Randomly pick',
888: 'randomorder' => 'Randomly ordered',
889: 'set' => 'set to',
890: 'del' => 'deleted');
1.484 raeburn 891: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
892: $pathitem."\n".
893: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
894: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
895: $r->print('<div class="LC_left_float">'.
896: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
897: &makedocslogform($filter,1).
898: '</fieldset></div><br clear="all" />');
1.329 droeschl 899: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
900: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
901: &mt('After').'</th>'.
902: &Apache::loncommon::end_data_table_header_row());
903: my $shown=0;
904: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
905: if ($env{'form.displayfilter'} eq 'currentfolder') {
906: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
907: }
908: my @changes=keys(%{$docslog{$id}{'logentry'}});
909: if ($env{'form.displayfilter'} eq 'containing') {
910: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
911: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
912: foreach my $key (@changes) {
913: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
914: }
1.344 bisitz 915: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 916: }
917: my $count = 0;
918: my $time =
919: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
920: my $plainname =
921: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
922: $docslog{$id}{'exe_udom'});
923: my $about_me_link =
924: &Apache::loncommon::aboutmewrapper($plainname,
925: $docslog{$id}{'exe_uname'},
926: $docslog{$id}{'exe_udom'});
927: my $send_msg_link='';
928: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
929: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
930: $send_msg_link ='<br />'.
931: &Apache::loncommon::messagewrapper(&mt('Send message'),
932: $docslog{$id}{'exe_uname'},
933: $docslog{$id}{'exe_udom'});
934: }
935: $r->print(&Apache::loncommon::start_data_table_row());
936: $r->print('<td>'.$time.'</td>
937: <td>'.$about_me_link.
938: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
939: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
940: $send_msg_link.'</td><td>'.
941: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 942: my $is_supp = 0;
1.484.2.7 raeburn 943: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
944: $is_supp = 1;
945: }
1.329 droeschl 946: # Before
947: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
948: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
949: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
950: if ($oldname ne $newname) {
1.484.2.7 raeburn 951: my $shown = &LONCAPA::map::qtescape($oldname);
952: if ($is_supp) {
953: $shown = &Apache::loncommon::parse_supplemental_title($shown);
954: }
955: $r->print($shown);
1.329 droeschl 956: }
957: }
958: $r->print('<ul>');
959: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
960: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 961: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
962: if ($is_supp) {
963: $shown = &Apache::loncommon::parse_supplemental_title($shown);
964: }
1.484.2.19 raeburn 965: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 966: }
967: }
968: $r->print('</ul>');
969: # After
970: $r->print('</td><td>');
971:
972: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
973: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
974: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
975: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 976: my $shown = &LONCAPA::map::qtescape($newname);
977: if ($is_supp) {
978: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
979: }
980: $r->print($shown);
1.329 droeschl 981: }
1.364 bisitz 982: }
1.329 droeschl 983: $r->print('<ul>');
984: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
985: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 986: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
987: if ($is_supp) {
988: $shown = &Apache::loncommon::parse_supplemental_title($shown);
989: }
990: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 991: }
992: }
993: $r->print('</ul>');
994: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
995: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
996: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
997: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 998: # FIXME: internationalization seems wrong here
1.329 droeschl 999: $r->print('<li>'.
1000: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1001: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1002: .'</li>');
1003: }
1004: }
1005: $r->print('</ul>');
1006: }
1007: # End
1008: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1009: $shown++;
1010: if (!($env{'form.show'} eq &mt('all')
1011: || $shown<=$env{'form.show'})) { last; }
1012: }
1.484 raeburn 1013: $r->print(&Apache::loncommon::end_data_table()."\n".
1014: &makesimpleeditform($pathitem)."\n".
1015: '</div></div>');
1016: $r->print(&endContentScreen());
1.329 droeschl 1017: }
1018:
1019: sub update_paste_buffer {
1.484.2.7 raeburn 1020: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1021: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1022: if ($env{'form.multiremove'}) {
1023: $env{'form.multiremove'} =~ s/,$//;
1024: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1025: }
1026: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1027: if ($env{'form.multicut'}) {
1028: $env{'form.multicut'} =~ s/,$//;
1029: foreach my $item (split(/,/,$env{'form.multicut'})) {
1030: unless ($removals{$item}) {
1031: $cuts{$item} = 1;
1032: push(@possibles,$item.':cut');
1033: }
1034: }
1035: }
1036: if ($env{'form.multicopy'}) {
1037: $env{'form.multicopy'} =~ s/,$//;
1038: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1039: unless ($removals{$item} || $cuts{$item}) {
1040: push(@possibles,$item.':copy');
1041: }
1042: }
1043: }
1044: } elsif ($env{'form.markcopy'}) {
1045: @possibles = split(/,/,$env{'form.markcopy'});
1046: }
1.329 droeschl 1047:
1.484.2.30 raeburn 1048: return if (@possibles == 0);
1.329 droeschl 1049: return if (!defined($env{'form.copyfolder'}));
1050:
1051: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1052: $env{'form.copyfolder'});
1053: return if ($fatal);
1054:
1.484.2.30 raeburn 1055: my %curr_groups = &Apache::longroup::coursegroups();
1056:
1057: # Retrieve current paste buffer suffixes.
1058: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1059: my (%pasteurls,@newpaste);
1060:
1061: # Construct identifiers for current contents of user's paste buffer
1062: if (@currpaste) {
1063: foreach my $suffix (@currpaste) {
1.484.2.87 raeburn 1064: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1065: my $url = $env{'docs.markedcopy_url_'.$suffix};
1066: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1067: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1068: ($url ne '')) {
1069: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1070: $pasteurls{$cid.'_'.$mapidx} = 1;
1071: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1072: $pasteurls{$url} = 1;
1073: } else {
1074: $pasteurls{$cid.'_'.$url} = 1;
1075: }
1076: }
1.484.2.30 raeburn 1077: }
1078: }
1079:
1080: # Mark items for copying (skip any items already in user's paste buffer)
1081: my %addtoenv;
1.484.2.82 raeburn 1082:
1083: my @pathitems = split(/\&/,$env{'form.folderpath'});
1084: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.87 raeburn 1085: my $ispage = $folderconf[5];
1.484.2.82 raeburn 1086:
1.484.2.30 raeburn 1087: foreach my $item (@possibles) {
1088: my ($orderidx,$cmd) = split(/:/,$item);
1089: next if ($orderidx =~ /\D/);
1090: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1091: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1092: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1093: my %denied = &action_restrictions($coursenum,$coursedom,
1094: &LONCAPA::map::qtescape($url),
1095: $env{'form.folderpath'},\%curr_groups);
1096: next if ($denied{'copy'});
1097: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 1098: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1099: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1100: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1101: next if (exists($pasteurls{$url}));
1102: } else {
1103: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1104: }
1.484.2.30 raeburn 1105: my ($suffix,$errortxt,$locknotfreed) =
1106: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1107: if ($suffix ne '') {
1108: push(@newpaste,$suffix);
1109: } else {
1110: if ($locknotfreed) {
1111: return $locknotfreed;
1112: }
1.484.2.30 raeburn 1113: }
1114: if (&is_supplemental_title($title)) {
1115: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1116: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1117: }
1118:
1119: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1120: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1121: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1122: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1123: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1124: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1125: my $prefix = $1;
1126: my $subdir =$2;
1127: if ($subdir eq '') {
1128: $subdir = $prefix;
1.484.2.7 raeburn 1129: }
1.484.2.30 raeburn 1130: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1131: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1132: \%hierarchy,\%titles,\%allmaps);
1133: if (ref($hierarchy{$url}) eq 'HASH') {
1134: my ($nested,$nestednames);
1135: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1136: $nested =~ s/\&$//;
1137: $nestednames =~ s/\Q___&&&___\E$//;
1138: if ($nested ne '') {
1139: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1140: }
1141: if ($nestednames ne '') {
1142: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1143: }
1.484.2.7 raeburn 1144: }
1145: }
1.484.2.57 raeburn 1146: if ($locknotfreed) {
1147: $output = $locknotfreed;
1148: last;
1149: }
1.484.2.7 raeburn 1150: }
1.484.2.30 raeburn 1151: if (@newpaste) {
1152: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1153: }
1.484.2.7 raeburn 1154: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1155: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1156: return $output;
1.329 droeschl 1157: }
1158:
1.484.2.7 raeburn 1159: sub recurse_uploaded_maps {
1160: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1161: if (ref($hierarchy->{$url}) eq 'HASH') {
1162: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1163: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1164: my (@uploaded,@names,%shorter);
1165: for (my $i=0; $i<@maps; $i++) {
1166: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1167: if ($inner ne '') {
1168: push(@uploaded,$inner);
1169: push(@names,&escape($titles[$i]));
1170: $shorter{$maps[$i]} = $inner;
1171: }
1172: }
1173: $$nestref .= "$dir:".join(',',@uploaded).'&';
1174: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1175: foreach my $map (@maps) {
1176: if ($shorter{$map} ne '') {
1177: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1178: }
1179: }
1180: }
1181: return;
1182: }
1183:
1.329 droeschl 1184: sub print_paste_buffer {
1.484.2.7 raeburn 1185: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1186: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1187:
1.484.2.30 raeburn 1188: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1189: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1190: }
1191:
1.484.2.30 raeburn 1192: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1193: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1194: my $clipboardcount = 0;
1.484.2.7 raeburn 1195:
1.484.2.30 raeburn 1196: # Construct identifiers for current contents of user's paste buffer
1197: foreach my $suffix (@currpaste) {
1198: next if ($suffix =~ /\D/);
1199: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1200: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1201: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1202: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1203: ($url ne '')) {
1.484.2.47 raeburn 1204: $clipboardcount ++;
1.484.2.30 raeburn 1205: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1206: $canpaste,$nopaste,$othercrs,$areachange);
1207: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1208: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1209: $is_external = 1;
1.484.2.7 raeburn 1210: }
1.484.2.30 raeburn 1211: if ($folder =~ /^supplemental/) {
1212: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1213: unless ($canpaste) {
1214: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1215: }
1.484.2.30 raeburn 1216: } else {
1217: $canpaste = 1;
1.484.2.7 raeburn 1218: }
1.484.2.30 raeburn 1219: if ($canpaste) {
1220: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1221: my $srcdom = $1;
1222: my $srcnum = $2;
1223: my $rem = $3;
1224: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1225: $othercourse = 1;
1226: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1227: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1228: } else {
1229: $canpaste = 0;
1230: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1231: }
1232: }
1.484.2.30 raeburn 1233: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1234: my $prefix = $1;
1235: $parent = $2;
1236: if ($folder !~ /^\Q$prefix\E/) {
1237: $areachange = 1;
1238: }
1239: $is_uploaded_map = 1;
1240: }
1.484.2.82 raeburn 1241: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1242: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1243: if ($cid ne $env{'request.course.id'}) {
1244: my ($srcdom,$srcnum) = split(/_/,$cid);
1245: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1246: $othercrs = '<br />'.&mt('(from another course)');
1247: } else {
1248: $canpaste = 0;
1249: $nopaste = &mt('Paste from another course unavailable.');
1250: }
1251: }
1252: }
1253: if ($canpaste) {
1254: push(@pasteable,$suffix);
1.484.2.30 raeburn 1255: }
1256: }
1257: my $buffer;
1258: if ($is_external) {
1259: $buffer = &mt('External Resource').': '.
1260: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1261: &LONCAPA::map::qtescape($url).')';
1262: } else {
1263: my $icon = &Apache::loncommon::icon($extension);
1264: if ($extension eq 'sequence' &&
1265: $url =~ m{/default_\d+\.sequence$}x) {
1266: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1267: $icon .= '/navmap.folder.closed.gif';
1268: }
1.484.2.57 raeburn 1269: my $title = $env{'docs.markedcopy_title_'.$suffix};
1270: if ($title eq '') {
1271: ($title) = ($url =~ m{/([^/]+)$});
1272: }
1.484.2.30 raeburn 1273: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1274: ': '.
1275: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1276: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1277: }
1278: $pasteitems .= '<div class="LC_left_float">';
1279: my ($options,$onclick);
1280: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1281: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1282: if (($is_uploaded_map) ||
1283: ($url =~ /(bulletinboard|smppg)$/) ||
1284: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1285: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1286: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1287: }
1288: }
1289: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1290: if ($nopaste) {
1291: $pasteitems .= $nopaste;
1292: } else {
1293: if ($othercrs) {
1294: $pasteitems .= $othercrs;
1295: }
1296: if ($options) {
1297: $pasteitems .= $options;
1.484.2.7 raeburn 1298: }
1299: }
1.484.2.30 raeburn 1300: $pasteitems .= '</div>';
1301: }
1302: }
1303: if ($pasteitems eq '') {
1304: &Apache::lonnet::delenv('docs.markedcopies');
1305: }
1306: my ($pasteform,$form_start,$buttons,$form_end);
1307: if ($pasteitems) {
1308: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1309: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1310: if (@pasteable) {
1.484.2.47 raeburn 1311: my $value = &mt('Paste to current folder');
1312: if ($container eq 'page') {
1313: $value = &mt('Paste to current page');
1314: }
1315: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1316: }
1317: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.(' 'x2);
1318: if ($clipboardcount > 1) {
1319: $buttons .=
1320: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1321: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1322: (' 'x2).
1323: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1324: (' 'x2);
1.484.2.7 raeburn 1325: }
1.484.2.48 raeburn 1326: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1327: '</form>';
1.484.2.30 raeburn 1328: } else {
1329: $pasteitems = &mt('Clipboard is empty');
1330: }
1331: $r->print($form_start
1332: .'<fieldset>'
1333: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1334: .$pasteitems
1335: .'</fieldset>'
1336: .$form_end);
1337: }
1338:
1339: sub paste_options {
1340: my ($suffix,$is_uploaded_map,$parent) = @_;
1341: my ($copytext,$movetext);
1342: if ($is_uploaded_map) {
1343: $copytext = &mt('Copy to new folder');
1344: $movetext = &mt('Move old');
1345: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1346: $copytext = &mt('Copy to new board');
1347: $movetext = &mt('Move (not posts)');
1348: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1349: $copytext = &mt('Copy to new page');
1350: $movetext = &mt('Move');
1.484.2.7 raeburn 1351: } else {
1.484.2.30 raeburn 1352: $copytext = &mt('Copy to new file');
1353: $movetext = &mt('Move');
1354: }
1355: my $output = '<br />'.
1356: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1357: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1358: '<label>'.
1359: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1360: $copytext.'</label></span>'.(' 'x2).' '.
1361: '<span class="LC_nobreak"><label>'.
1362: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1363: $movetext.'</label></span>';
1364: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1365: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1366: '</legend><table border="0">';
1367: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1368: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1369: my $lastdir = $parent;
1370: my %depths = (
1371: $lastdir => 0,
1372: );
1373: my (%display,%deps);
1374: for (my $i=0; $i<@pastemaps; $i++) {
1375: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1376: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1377: my @subfolders = split(/,/,$subfolderstr);
1378: $deps{$lastdir} = \@subfolders;
1379: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1380: my $depth = $depths{$lastdir} + 1;
1381: my $offset = int($depth * 4);
1382: my $indent = (' ' x $offset);
1383: for (my $j=0; $j<@subfolders; $j++) {
1384: $depths{$subfolders[$j]} = $depth;
1385: $display{$subfolders[$j]} =
1386: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1387: '<td><label>'.
1388: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1389: '<label>'.
1390: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1391: &mt('Move old').'</label>'.
1392: '</td></tr>';
1393: }
1394: }
1395: &recurse_print(\$output,$parent,\%deps,\%display);
1396: $output .= '</table></fieldset>';
1.329 droeschl 1397: }
1.484.2.30 raeburn 1398: $output .= '</div>';
1399: return $output;
1.329 droeschl 1400: }
1401:
1.484.2.7 raeburn 1402: sub recurse_print {
1.484.2.30 raeburn 1403: my ($outputref,$dir,$deps,$display) = @_;
1404: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1405: if (ref($deps->{$dir}) eq 'ARRAY') {
1406: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1407: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1408: }
1409: }
1410: }
1411:
1412: sub supp_pasteable {
1413: my ($url) = @_;
1414: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1415: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1416: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1417: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1418: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1419: return 1;
1420: }
1421: return;
1422: }
1423:
1424: sub paste_popup_js {
1.484.2.61 raeburn 1425: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1426: show => 'Show Options',
1427: hide => 'Hide Options',
1.484.2.61 raeburn 1428: );
1429: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1430: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1431: );
1.484.2.61 raeburn 1432: &html_escape(\%html_js_lt);
1433: &js_escape(\%html_js_lt);
1434: &js_escape(\%js_lt);
1.484.2.7 raeburn 1435: return <<"END";
1436:
1.484.2.30 raeburn 1437: function showPasteOptions(suffix) {
1438: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1439: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1440: return;
1441: }
1442:
1.484.2.30 raeburn 1443: function hidePasteOptions(suffix) {
1444: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1445: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1446: return;
1447: }
1448:
1.484.2.30 raeburn 1449: function showOptions(caller,suffix) {
1450: if (document.getElementById('pasteoptionstext_'+suffix)) {
1451: if (caller.checked) {
1.484.2.61 raeburn 1452: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1453: } else {
1454: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1455: }
1456: if (document.getElementById('pasteoptions_'+suffix)) {
1457: document.getElementById('pasteoptions_'+suffix).style.display='none';
1458: }
1459: }
1460: return;
1461: }
1.484.2.7 raeburn 1462:
1.484.2.30 raeburn 1463: function validateClipboard() {
1464: var numchk = 0;
1465: if (document.pasteform.pasting.length > 1) {
1466: for (var i=0; i<document.pasteform.pasting.length; i++) {
1467: if (document.pasteform.pasting[i].checked) {
1468: numchk ++;
1469: }
1470: }
1471: } else {
1472: if (document.pasteform.pasting.type == 'checkbox') {
1473: if (document.pasteform.pasting.checked) {
1474: numchk ++;
1475: }
1476: }
1477: }
1478: if (numchk > 0) {
1479: return true;
1480: } else {
1.484.2.61 raeburn 1481: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1482: return false;
1483: }
1.484.2.7 raeburn 1484: }
1485:
1.484.2.47 raeburn 1486: function checkClipboard() {
1487: if (document.pasteform.pasting.length > 1) {
1488: for (var i=0; i<document.pasteform.pasting.length; i++) {
1489: document.pasteform.pasting[i].checked = true;
1490: }
1491: }
1492: return;
1493: }
1494:
1495: function uncheckClipboard() {
1496: if (document.pasteform.pasting.length >1) {
1497: for (var i=0; i<document.pasteform.pasting.length; i++) {
1498: document.pasteform.pasting[i].checked = false;
1499: }
1500: }
1501: return;
1502: }
1503:
1.484.2.30 raeburn 1504: END
1505:
1506: }
1.484.2.7 raeburn 1507:
1.329 droeschl 1508: sub do_paste_from_buffer {
1.484.2.7 raeburn 1509: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1510:
1.484.2.30 raeburn 1511: # Array of items in paste buffer
1512: my (@currpaste,%pastebuffer,%allerrors);
1513: @currpaste = split(/,/,$env{'docs.markedcopies'});
1514:
1.484.2.7 raeburn 1515: # Early out if paste buffer is empty
1.484.2.30 raeburn 1516: if (@currpaste == 0) {
1.484.2.7 raeburn 1517: return ();
1.484.2.30 raeburn 1518: }
1519: map { $pastebuffer{$_} = 1; } @currpaste;
1520:
1521: # Array of items selected items to paste
1522: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1523:
1524: # Early out if nothing selected to paste
1525: if (@reqpaste == 0) {
1526: return();
1527: }
1528: my @topaste;
1529: foreach my $suffix (@reqpaste) {
1530: next if ($suffix =~ /\D/);
1531: next unless (exists($pastebuffer{$suffix}));
1532: push(@topaste,$suffix);
1.484.2.7 raeburn 1533: }
1534:
1.484.2.30 raeburn 1535: # Early out if nothing available to paste
1536: if (@topaste == 0) {
1537: return();
1.329 droeschl 1538: }
1539:
1.484.2.30 raeburn 1540: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.484.2.82 raeburn 1541: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1542:
1.484.2.30 raeburn 1543: foreach my $suffix (@topaste) {
1544: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1545: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1546: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1547: # Supplemental content may only include certain types of content
1548: # Early out if pasted content is not supported in Supplemental area
1549: if ($folder =~ /^supplemental/) {
1550: unless (&supp_pasteable($url)) {
1551: $notinsupp{$suffix} = 1;
1552: next;
1553: }
1554: }
1555: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1556: my $srcd = $1;
1557: my $srcn = $2;
1.484.2.7 raeburn 1558: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1559: # check for mdc privilege in the course from which the resource was pasted
1560: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1561: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1562: $notincrs{$suffix} = 1;
1563: next;
1564: }
1.329 droeschl 1565: }
1.484.2.30 raeburn 1566: $srcdom{$suffix} = $srcd;
1567: $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1568: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1569: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1570: my ($srcd,$srcn) = split(/_/,$cid);
1571: # When paste buffer was populated using an active role in a different course
1572: # check for mdc privilege in the course from which the resource was pasted
1573: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1574: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1575: $notincrs{$suffix} = 1;
1576: next;
1577: }
1578: }
1579: $srcdom{$suffix} = $srcd;
1580: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1581: }
1.484.2.82 raeburn 1582: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1583: push(@dopaste,$suffix);
1584: if ($url=~/\.(page|sequence)$/) {
1585: $is_map{$suffix} = 1;
1.329 droeschl 1586: }
1.484.2.30 raeburn 1587:
1588: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1589: my $oldprefix = $1;
1.484.2.19 raeburn 1590: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1591: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1592: # a folder/page or a document).
1.484.2.30 raeburn 1593: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1594: $prefixchg{$suffix} = 'docstosupp';
1595: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1596: $prefixchg{$suffix} = 'supptodocs';
1597: }
1.484.2.7 raeburn 1598:
1599: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1600: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1601: my @nested;
1602: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1603: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1604: my @deps = map { /\d+:([\d,]+$)/ } @items;
1605: foreach my $dep (@deps) {
1606: if ($dep =~ /,/) {
1607: push(@nested,split(/,/,$dep));
1608: } else {
1609: push(@nested,$dep);
1610: }
1.484.2.7 raeburn 1611: }
1.484.2.30 raeburn 1612: foreach my $item (@nested) {
1613: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1614: push(@{$marktomove{$suffix}},$type.'_'.$item);
1615: }
1.484.2.7 raeburn 1616: }
1617: }
1.329 droeschl 1618: }
1.484.2.7 raeburn 1619: }
1620:
1.484.2.30 raeburn 1621: # Early out if nothing available to paste
1622: if (@dopaste == 0) {
1623: return ();
1624: }
1625:
1626: # Populate message hash and hashes used for main content <=> supplemental content
1627: # changes
1628:
1629: %msgs = &Apache::lonlocal::texthash (
1630: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1631: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1632: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1633: );
1634:
1635: %before = (
1636: docstosupp => {
1637: map => 'default',
1638: doc => 'docs',
1639: },
1640: supptodocs => {
1641: map => 'supplemental',
1642: doc => 'supplemental',
1643: },
1644: );
1645:
1646: %after = (
1647: docstosupp => {
1648: map => 'supplemental',
1649: doc => 'supplemental'
1650: },
1651: supptodocs => {
1652: map => 'default',
1653: doc => 'docs',
1654: },
1655: );
1656:
1657: # Retrieve information about all course maps in main content area
1658:
1659: my $allmaps = {};
1.484.2.79 raeburn 1660: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1661:
1662: # Loop over the items to paste
1663: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1664: # Maps need to be copied first
1.484.2.30 raeburn 1665: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1666: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1667: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1668: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1669: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1670: }
1671: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1672: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1673: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1674: my $oldurl = $url;
1675: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1676: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1677: my (%hierarchy,%titles);
1.484.2.79 raeburn 1678: if (($folder =~ /^default/) && (!$donechk)) {
1679: $allmaps =
1680: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1681: $env{"course.$env{'request.course.id'}.home"},
1682: $env{'request.course.id'});
1683: $donechk = 1;
1684: }
1.484.2.30 raeburn 1685: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1686: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1687: if ($url=~ m{^/uploaded/}) {
1688: my $newurl;
1689: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1690: ($newurl,my $error) =
1691: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1692: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1693: \$title,$allmaps,\%newurls);
1694: if ($error) {
1695: $allerrors{$suffix} = $error;
1696: next;
1697: }
1698: if ($newurl ne '') {
1699: if ($newurl ne $url) {
1700: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1701: $newsubdir{$url} = $1;
1702: }
1703: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1704: }
1705: }
1706: }
1.484.2.30 raeburn 1707: if (($srcdom{$suffix} ne $coursedom) ||
1708: ($srcnum{$suffix} ne $coursenum) ||
1709: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1710: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1711: $coursedom,$coursenum,$srcdom{$suffix},
1712: $srcnum{$suffix},$allmaps,\%rewrites,
1713: \%retitles,\%copies,\%dbcopies,
1714: \%zombies,\%params,\%mapmoves,
1715: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1716: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1717: $mapmoves{$url} = 1;
1718: }
1719: $url = $newurl;
1720: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1721: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1722: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1723: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1724: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1725: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1726: }
1727: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1728: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1729: push(@toclear,$suffix);
1730: # if pasting published map (main content area only) check map not already in course
1731: if ($folder =~ /^default/) {
1732: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1733: $duplicate{$suffix} = 1;
1734: next;
1735: }
1.484.2.7 raeburn 1736: }
1737: }
1738: }
1.484.2.30 raeburn 1739: if ($url=~ m{/(bulletinboard|smppg)$}) {
1740: my $prefix = $1;
1.484.2.76 raeburn 1741: my $fromothercrs;
1.484.2.30 raeburn 1742: #need to copy the db contents to a new one, unless this is a move.
1743: my %info = (
1744: src => $url,
1745: cdom => $coursedom,
1746: cnum => $coursenum,
1.484.2.76 raeburn 1747: );
1748: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1749: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1750: $fromothercrs = 1;
1751: $info{'cdom'} = $srcdom{$suffix};
1752: $info{'cnum'} = $srcnum{$suffix};
1753: }
1754: }
1755: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1756: my (%lockerr,$msg);
1757: my ($newurl,$result,$errtext) =
1758: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1759: if ($result eq 'ok') {
1760: $url = $newurl;
1761: $title=&mt('Copy of').' '.$title;
1762: } else {
1763: if ($prefix eq 'smppg') {
1764: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1765: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1766: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.30 raeburn 1767: }
1768: $results{$suffix} = $result;
1769: $msgerrs{$suffix} = $msg;
1770: $lockerrs{$suffix} = $lockerr{$prefix};
1771: next;
1772: }
1773: if ($lockerr{$prefix}) {
1774: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1775: }
1.484.2.7 raeburn 1776: }
1.484.2.30 raeburn 1777: }
1778: $title = &LONCAPA::map::qtunescape($title);
1779: my $ext='false';
1780: if ($url=~m{^http(|s)://}) { $ext='true'; }
1781: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1782: if ($folder !~ /^supplemental/) {
1783: (undef,undef,$title) =
1784: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1785: }
1786: } else {
1787: if ($folder=~/^supplemental/) {
1788: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1789: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1790: }
1791: }
1.484.2.7 raeburn 1792:
1793: # For uploaded files (excluding pages/sequences) path in copied file is changed
1794: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1795: # courses.
1796:
1.484.2.30 raeburn 1797: unless ($is_map{$suffix}) {
1798: my $newidx;
1.329 droeschl 1799: # Now insert the URL at the bottom
1.484.2.30 raeburn 1800: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1801: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1802: my $relpath = $1;
1803: if ($relpath ne '') {
1804: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1805: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1806: my $newprefix = $newloc;
1807: if ($newloc eq 'default') {
1808: $newprefix = 'docs';
1809: }
1810: if ($newdocsdir eq '') {
1811: $newdocsdir = 'default';
1812: }
1813: if (($prefixchg{$suffix}) ||
1814: ($srcdom{$suffix} ne $coursedom) ||
1815: ($srcnum{$suffix} ne $coursenum) ||
1816: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1817: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1818: $url =
1819: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1820: &Apache::lonnet::getfile($oldurl));
1821: if ($url eq '/adm/notfound.html') {
1822: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1823: next;
1824: } else {
1825: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1826: $newsubpath =~ s{/+$}{/};
1827: $docmoves{$oldurl} = $newsubpath;
1828: }
1.484.2.7 raeburn 1829: }
1830: }
1.484.2.82 raeburn 1831: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1832: my $template = $1;
1833: if ($newidx) {
1834: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1835: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1836: }
1.484.2.7 raeburn 1837: }
1.484.2.30 raeburn 1838: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1839: ':'.$ext.':normal:res';
1840: push(@LONCAPA::map::order,$newidx);
1841: # Store the result
1842: my ($errtext,$fatal) =
1843: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1844: if ($fatal) {
1845: $save_err .= $errtext;
1846: $allresult = 'fail';
1.484.2.7 raeburn 1847: }
1.329 droeschl 1848: }
1.484.2.30 raeburn 1849:
1.484.2.82 raeburn 1850: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1851: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 1852: unless ($allresult eq 'fail') {
1853: my %updated = (
1854: rewrites => \%rewrites,
1855: zombies => \%zombies,
1856: removefrommap => \%removefrommap,
1857: removeparam => \%removeparam,
1858: dbcopies => \%dbcopies,
1.484.2.82 raeburn 1859: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 1860: retitles => \%retitles,
1861: );
1862: my %info = (
1863: newsubdir => \%newsubdir,
1864: params => \%params,
1865: );
1866: if ($prefixchg{$suffix}) {
1867: $info{'before'} = $before{$prefixchg{$suffix}};
1868: $info{'after'} = $after{$prefixchg{$suffix}};
1869: }
1870: my %moves = (
1871: copies => \%copies,
1872: docmoves => \%docmoves,
1873: mapmoves => \%mapmoves,
1874: );
1875: (my $result,$msgs{$suffix},my $lockerror) =
1876: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1877: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1878: $url,'paste');
1879: $lockerrors .= $lockerror;
1880: if ($result eq 'ok') {
1881: if ($is_map{$suffix}) {
1882: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1883: $folder.'.'.$container);
1884: if ($fatal) {
1885: $allresult = 'failread';
1886: } else {
1887: if ($#LONCAPA::map::order<1) {
1888: my $idx=&LONCAPA::map::getresidx();
1889: if ($idx<=0) { $idx=1; }
1890: $LONCAPA::map::order[0]=$idx;
1891: $LONCAPA::map::resources[$idx]='';
1892: }
1893: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1894: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1895: ':'.$ext.':normal:res';
1896: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 1897:
1898: # Store the result
1.484.2.30 raeburn 1899: my ($errtext,$fatal) =
1900: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1901: if ($fatal) {
1902: $save_err .= $errtext;
1903: $allresult = 'failstore';
1904: }
1905: }
1906: }
1907: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1908: push(@toclear,$suffix);
1909: }
1910: }
1.329 droeschl 1911: }
1912: }
1.484.2.30 raeburn 1913: &clear_from_buffer(\@toclear,\@currpaste);
1914: my $msgsarray;
1915: foreach my $suffix (keys(%msgs)) {
1916: if (ref($msgs{$suffix}) eq 'ARRAY') {
1917: $msgsarray .= join(',',@{$msgs{$suffix}});
1918: }
1919: }
1920: return ($allresult,$save_err,$msgsarray,$lockerrors);
1921: }
1922:
1923: sub do_buffer_empty {
1924: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1925: if (@currpaste == 0) {
1926: return &mt('Clipboard is already empty');
1927: }
1928: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1929: if (@toclear == 0) {
1930: return &mt('Nothing selected to clear from clipboard');
1931: }
1932: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1933: if ($numdel) {
1934: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1935: } else {
1936: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 1937: }
1.484.2.30 raeburn 1938: return;
1939: }
1940:
1941: sub clear_from_buffer {
1942: my ($toclear,$currpaste) = @_;
1943: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1944: my %pastebuffer;
1945: map { $pastebuffer{$_} = 1; } @{$currpaste};
1946: my $numdel = 0;
1947: foreach my $suffix (@{$toclear}) {
1948: next if ($suffix =~ /\D/);
1949: next unless (exists($pastebuffer{$suffix}));
1950: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1951: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1952: delete($pastebuffer{$suffix});
1953: $numdel ++;
1954: }
1955: }
1956: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1957: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1958: return $numdel;
1.484.2.7 raeburn 1959: }
1960:
1961: sub get_newmap_url {
1962: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1963: $titleref,$allmaps,$newurls) = @_;
1964: my $newurl;
1965: if ($url=~ m{^/uploaded/}) {
1966: $$titleref=&mt('Copy of').' '.$$titleref;
1967: }
1968: my $now = time;
1969: my $suffix=$$.int(rand(100)).$now;
1970: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1971: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1972: my $path = $1;
1973: my $prefix = $2;
1974: my $ancestor = $3;
1975: if (length($ancestor) > 10) {
1976: $ancestor = substr($ancestor,-10,10);
1977: }
1978: my $newid;
1979: if ($prefixchg) {
1980: if ($folder =~ /^supplemental/) {
1981: $prefix =~ s/^default/supplemental/;
1982: } else {
1983: $prefix =~ s/^supplemental/default/;
1984: }
1985: }
1986: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1987: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1988: } else {
1989: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1990: }
1991: my $counter = 0;
1992: my $is_unique = &uniqueness_check($newurl);
1993: if ($folder =~ /^default/) {
1994: if ($allmaps->{$newurl}) {
1995: $is_unique = 0;
1996: }
1997: }
1998: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1999: $counter ++;
2000: $suffix ++;
2001: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2002: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2003: } else {
2004: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2005: }
2006: $is_unique = &uniqueness_check($newurl);
2007: }
2008: if ($is_unique) {
2009: $newurls->{$newurl} = 1;
2010: } else {
2011: if ($url=~/\.page$/) {
2012: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2013: } else {
2014: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2015: }
2016: }
2017: }
2018: return ($newurl);
2019: }
2020:
2021: sub dbcopy {
1.484.2.26 raeburn 2022: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2023: my ($url,$result,$errtext);
2024: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2025: $url = $dbref->{'src'};
1.484.2.26 raeburn 2026: if ($url =~ m{/(smppg|bulletinboard)$}) {
2027: my $prefix = $1;
2028: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2029: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2030: my $db_name;
2031: my $marker = (split(m{/},$url))[4];
2032: $marker=~s/\D//g;
2033: if ($dbref->{'src'} =~ m{/smppg$}) {
2034: $db_name =
2035: &Apache::lonsimplepage::get_db_name($url,$marker,
2036: $dbref->{'cdom'},
2037: $dbref->{'cnum'});
2038: } else {
2039: $db_name = 'bulletinpage_'.$marker;
2040: }
2041: my ($suffix,$freedlock,$error) =
2042: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2043: $coursedom,$coursenum,
2044: 'concat');
2045: if (!$suffix) {
2046: if ($prefix eq 'smppg') {
2047: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2048: } else {
1.484.2.42 raeburn 2049: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2050: }
2051: if ($error) {
2052: $errtext .= '<br />'.$error;
2053: }
2054: } else {
2055: #need to copy the db contents to a new one.
2056: my %contents=&Apache::lonnet::dump($db_name,
2057: $dbref->{'cdom'},
2058: $dbref->{'cnum'});
2059: if (exists($contents{'uploaded.photourl'})) {
2060: my $photo = $contents{'uploaded.photourl'};
2061: my ($subdir,$fname) =
2062: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2063: my $newphoto;
2064: if ($fname ne '') {
2065: my $content = &Apache::lonnet::getfile($photo);
2066: unless ($content eq '-1') {
2067: $env{'form.'.$suffix.'.photourl'} = $content;
2068: $newphoto =
2069: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2070: delete($env{'form.'.$suffix.'.photourl'});
2071: }
2072: }
2073: if ($newphoto =~ m{^/uploaded/}) {
2074: $contents{'uploaded.photourl'} = $newphoto;
2075: }
2076: }
2077: $db_name =~ s{_\d*$ }{_$suffix}x;
2078: $result=&Apache::lonnet::put($db_name,\%contents,
2079: $coursedom,$coursenum);
2080: if ($result eq 'ok') {
2081: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2082: }
2083: }
2084: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2085: $lockerrorsref->{$prefix} =
2086: '<div class="LC_error">'.
2087: &mt('There was a problem removing a lockfile.');
2088: if ($prefix eq 'smppg') {
2089: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2090: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.26 raeburn 2091: } else {
1.484.2.42 raeburn 2092: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2093: }
1.484.2.38 raeburn 2094: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2095: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2096: '</div>';
1.484.2.26 raeburn 2097: }
2098: }
2099: } elsif ($url =~ m{/syllabus$}) {
2100: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2101: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2102: if (($dbref->{'cdom'} ne $coursedom) ||
2103: ($dbref->{'cnum'} ne $coursenum)) {
2104: my %contents=&Apache::lonnet::dump('syllabus',
2105: $dbref->{'cdom'},
2106: $dbref->{'cnum'});
2107: $result=&Apache::lonnet::put('syllabus',\%contents,
2108: $coursedom,$coursenum);
2109: }
2110: }
1.484.2.7 raeburn 2111: }
2112: }
1.484.2.26 raeburn 2113: return ($url,$result,$errtext);
1.329 droeschl 2114: }
2115:
1.484.2.82 raeburn 2116: sub copy_templated_files {
2117: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2118: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2119: my $srccontainer = 'sequence';
2120: if ($srcwaspage) {
2121: $srccontainer = 'page';
2122: }
2123: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2124: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2125: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2126: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2127: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2128: $template.'.problem';
2129: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2130: if ($template eq 'simpleproblem') {
2131: $srcprefix .= '.0.';
2132: my $weightprefix = $newprefix;
2133: $newprefix .= '.0.';
2134: my @simpleprobqtypes = qw(radio option string essay numerical);
2135: my $qtype=$srcparms{$srcprefix.'questiontype'};
2136: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2137: my %newdata = (
2138: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2139: );
1.484.2.82 raeburn 2140: foreach my $type (@simpleprobqtypes) {
2141: if ($type eq $qtype) {
2142: $newdata{"$weightprefix.$type.weight"}=1;
2143: } else {
2144: $newdata{"$weightprefix.$type.weight"}=0;
2145: }
2146: }
2147: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2148: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2149: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2150: if ($qtype eq 'numerical') {
2151: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2152: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2153: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2154: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2155: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2156: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2157: unless (defined($maxfoils)) { $maxfoils=10; }
2158: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2159: if ($maxfoils<=0) { $maxfoils=10; }
2160: my $randomize=$srcparms{$srcprefix.'randomize'};
2161: unless (defined($randomize)) { $randomize='yes'; }
2162: unless ($randomize eq 'no') { $randomize='yes'; }
2163: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2164: $newdata{$newprefix.'randomize'} = $randomize;
2165: if ($qtype eq 'option') {
2166: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2167: }
2168: for (my $i=1; $i<=10; $i++) {
2169: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2170: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2171: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2172: }
2173:
2174: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2175: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2176: unless (defined($maxfoils)) { $maxfoils=10; }
2177: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2178: if ($maxfoils<=0) { $maxfoils=10; }
2179: my $randomize=$srcparms{$srcprefix.'randomize'};
2180: unless (defined($randomize)) { $randomize='yes'; }
2181: unless ($randomize eq 'no') { $randomize='yes'; }
2182: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2183: $newdata{$newprefix.'randomize'} = $randomize;
2184: if ($qtype eq 'option') {
2185: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2186: }
2187: for (my $i=1; $i<=10; $i++) {
2188: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2189: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2190: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2191: }
2192: } elsif ($qtype eq 'string') {
2193: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2194: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2195: }
2196: if (keys(%newdata)) {
2197: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2198: $coursenum);
2199: if ($putres eq 'ok') {
2200: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2201: }
2202: }
2203: }
2204: }
2205: }
2206:
1.329 droeschl 2207: sub uniqueness_check {
2208: my ($newurl) = @_;
2209: my $unique = 1;
2210: foreach my $res (@LONCAPA::map::order) {
2211: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2212: $url=&LONCAPA::map::qtescape($url);
2213: if ($newurl eq $url) {
2214: $unique = 0;
1.344 bisitz 2215: last;
1.329 droeschl 2216: }
2217: }
2218: return $unique;
2219: }
2220:
1.484.2.7 raeburn 2221: sub contained_map_check {
2222: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2223: $allmaps) = @_;
2224: my $content = &Apache::lonnet::getfile($url);
2225: unless ($content eq '-1') {
2226: my $parser = HTML::TokeParser->new(\$content);
2227: $parser->attr_encoded(1);
2228: while (my $token = $parser->get_token) {
2229: next if ($token->[0] ne 'S');
2230: if ($token->[1] eq 'resource') {
2231: next if ($token->[2]->{'type'} eq 'zombie');
2232: my $ressrc = $token->[2]->{'src'};
2233: if ($folder =~ /^supplemental/) {
2234: unless (&supp_pasteable($ressrc)) {
2235: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2236: next;
2237: }
2238: }
2239: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2240: if ($1 eq 'uploaded') {
2241: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2242: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2243: } else {
2244: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2245: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2246: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2247: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2248: } else {
2249: $addedmaps->{$ressrc} = [$url];
2250: }
2251: }
2252: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2253: $addedmaps,$hierarchy,$titles,$allmaps);
2254: }
2255: } elsif ($token->[1] eq 'param') {
2256: if ($folder =~ /^supplemental/) {
2257: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2258: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2259: } else {
1.484.2.19 raeburn 2260: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2261: }
2262: }
2263: }
2264: }
2265: }
2266: return;
2267: }
2268:
2269: sub url_paste_fixups {
1.484.2.26 raeburn 2270: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2271: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2272: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2273: my $checktitle;
2274: if (($prefixchg) &&
2275: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2276: $checktitle = 1;
2277: }
2278: my $skip;
2279: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2280: my $mapid = $1.$2;
2281: if ($tomove->{$mapid}) {
2282: $skip = 1;
2283: }
2284: }
2285: my $file = &Apache::lonnet::getfile($oldurl);
2286: return if ($file eq '-1');
2287: my $parser = HTML::TokeParser->new(\$file);
2288: $parser->attr_encoded(1);
2289: my $changed = 0;
2290: while (my $token = $parser->get_token) {
2291: next if ($token->[0] ne 'S');
2292: if ($token->[1] eq 'resource') {
2293: my $ressrc = $token->[2]->{'src'};
2294: next if ($ressrc eq '');
2295: my $id = $token->[2]->{'id'};
2296: my $title = $token->[2]->{'title'};
2297: if ($checktitle) {
2298: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2299: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2300: }
2301: }
2302: next if ($token->[2]->{'type'} eq 'external');
2303: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2304: next if ($skip);
1.484.2.25 raeburn 2305: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2306: $changed = 1;
2307: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2308: my $srcdom = $1;
2309: my $srcnum = $2;
2310: my $rem = $3;
2311: my $newurl;
2312: my $mapname;
2313: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2314: my $prefix = $1;
2315: $mapname = $prefix.$2;
2316: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2317: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2318: $srcdom,$srcnum,$allmaps,$rewrites,
2319: $retitles,$copies,$dbcopies,$zombies,
2320: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2321: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2322: next;
2323: } else {
2324: ($newurl,my $error) =
2325: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2326: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2327: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2328: $newsubdir->{$ressrc} = $1;
2329: }
2330: if ($error) {
2331: next;
2332: }
2333: }
2334: }
2335: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2336: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2337:
1.484.2.7 raeburn 2338: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2339: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2340: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2341: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2342: $cnum,$srcdom,$srcnum,$allmaps,
2343: $rewrites,$retitles,$copies,$dbcopies,
2344: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2345: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2346: $mapmoves->{$ressrc} = 1;
2347: }
2348: $changed = 1;
2349: } else {
1.484.2.25 raeburn 2350: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2351: $copies->{$oldurl}{$ressrc} = $id;
2352: $changed = 1;
2353: }
2354: }
1.484.2.26 raeburn 2355: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2356: next if ($skip);
1.484.2.7 raeburn 2357: my $srcdom = $1;
2358: my $srcnum = $2;
2359: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2360: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2361: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2362: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2363: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2364: $changed = 1;
2365: }
2366: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2367: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2368: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2369: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2370: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2371: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2372: $changed = 1;
2373: }
1.484.2.82 raeburn 2374: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2375: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2376: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2377: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2378: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2379: }
1.484.2.7 raeburn 2380: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2381: next if ($skip);
2382: my $srcdom = $1;
2383: my $srcnum = $2;
2384: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2385: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2386: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2387: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2388: $changed = 1;
2389: }
2390: }
2391: } elsif ($token->[1] eq 'param') {
2392: next if ($skip);
1.484.2.19 raeburn 2393: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2394: if ($to ne '') {
2395: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2396: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2397: } else {
2398: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2399: }
2400: }
2401: }
2402: }
2403: return $changed;
2404: }
2405:
2406: sub apply_fixups {
1.484.2.23 raeburn 2407: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2408: $oldurl,$url,$caller) = @_;
2409: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2410: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2411: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2412: if (ref($updated) eq 'HASH') {
2413: if (ref($updated->{'rewrites'}) eq 'HASH') {
2414: %rewrites = %{$updated->{'rewrites'}};
2415: }
2416: if (ref($updated->{'zombies'}) eq 'HASH') {
2417: %zombies = %{$updated->{'zombies'}};
2418: }
2419: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2420: %removefrommap = %{$updated->{'removefrommap'}};
2421: }
2422: if (ref($updated->{'removeparam'}) eq 'HASH') {
2423: %removeparam = %{$updated->{'removeparam'}};
2424: }
2425: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2426: %dbcopies = %{$updated->{'dbcopies'}};
2427: }
2428: if (ref($updated->{'retitles'}) eq 'HASH') {
2429: %retitles = %{$updated->{'retitles'}};
2430: }
1.484.2.82 raeburn 2431: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2432: %resdatacopy = %{$updated->{'resdatacopy'}};
2433: }
1.484.2.23 raeburn 2434: }
2435: if (ref($info) eq 'HASH') {
2436: if (ref($info->{'newsubdir'}) eq 'HASH') {
2437: %newsubdir = %{$info->{'newsubdir'}};
2438: }
2439: if (ref($info->{'params'}) eq 'HASH') {
2440: %params = %{$info->{'params'}};
2441: }
2442: if (ref($info->{'before'}) eq 'HASH') {
2443: %before = %{$info->{'before'}};
2444: }
2445: if (ref($info->{'after'}) eq 'HASH') {
2446: %after = %{$info->{'after'}};
2447: }
2448: }
2449: if (ref($moves) eq 'HASH') {
2450: if (ref($moves->{'copies'}) eq 'HASH') {
2451: %copies = %{$moves->{'copies'}};
2452: }
2453: if (ref($moves->{'docmoves'}) eq 'HASH') {
2454: %docmoves = %{$moves->{'docmoves'}};
2455: }
2456: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2457: %mapmoves = %{$moves->{'mapmoves'}};
2458: }
2459: }
2460: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2461: my @allcopies;
1.484.2.23 raeburn 2462: if (exists($copies{$key})) {
2463: if (ref($copies{$key}) eq 'HASH') {
2464: my %added;
2465: foreach my $innerkey (keys(%{$copies{$key}})) {
2466: if (($innerkey ne '') && (!$added{$innerkey})) {
2467: push(@allcopies,$innerkey);
2468: $added{$innerkey} = 1;
2469: }
1.484.2.7 raeburn 2470: }
1.484.2.23 raeburn 2471: undef(%added);
1.484.2.7 raeburn 2472: }
2473: }
2474: if ($key eq $oldurl) {
1.484.2.23 raeburn 2475: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2476: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2477: push(@allcopies,$oldurl);
2478: }
2479: }
2480: }
2481: if (@allcopies > 0) {
2482: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2483: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2484: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2485: if ($fname ne '') {
2486: my $content = &Apache::lonnet::getfile($item);
2487: unless ($content eq '-1') {
2488: my $storefn;
1.484.2.23 raeburn 2489: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2490: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2491: } else {
2492: $storefn = $relpath;
2493: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2494: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2495: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2496: }
1.484.2.23 raeburn 2497: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2498: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2499: }
2500: }
2501: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2502: my $copyurl =
1.484.2.7 raeburn 2503: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2504: $storefn.$fname,$content);
2505: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2506: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2507: return &mt('Paste failed: an error occurred copying the file.');
2508: } elsif (ref($errors) eq 'HASH') {
2509: $errors->{$item} = 1;
2510: }
2511: }
2512: }
2513: }
2514: }
2515: }
2516: }
1.484.2.23 raeburn 2517: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2518: my $storefn=$key;
2519: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2520: if ($prefixchg && $before{'map'} && $after{'map'}) {
2521: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2522: }
1.484.2.23 raeburn 2523: if ($newsubdir{$key}) {
2524: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2525: }
2526: my $mapcontent = &Apache::lonnet::getfile($key);
2527: if ($mapcontent eq '-1') {
2528: if (ref($errors) eq 'HASH') {
2529: $errors->{$key} = 1;
2530: }
2531: } else {
2532: my $newmap =
2533: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2534: $mapcontent);
2535: if ($newmap eq '/adm/notfound.html') {
2536: if (ref($errors) eq 'HASH') {
2537: $errors->{$key} = 1;
2538: }
2539: }
2540: }
2541: }
2542: my %updates;
2543: if ($is_map) {
1.484.2.23 raeburn 2544: if (ref($updated) eq 'HASH') {
2545: foreach my $type (keys(%{$updated})) {
2546: if (ref($updated->{$type}) eq 'HASH') {
2547: foreach my $key (keys(%{$updated->{$type}})) {
2548: $updates{$key} = 1;
2549: }
2550: }
2551: }
1.484.2.7 raeburn 2552: }
2553: foreach my $key (keys(%updates)) {
2554: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2555: if (ref($rewrites{$key}) eq 'HASH') {
2556: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2557: }
1.484.2.23 raeburn 2558: if (ref($retitles{$key}) eq 'HASH') {
2559: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2560: }
1.484.2.23 raeburn 2561: if (ref($removefrommap{$key}) eq 'HASH') {
2562: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2563: }
1.484.2.23 raeburn 2564: if (ref($removeparam{$key}) eq 'HASH') {
2565: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2566: }
1.484.2.23 raeburn 2567: if (ref($zombies{$key}) eq 'HASH') {
2568: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2569: }
1.484.2.23 raeburn 2570: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2571: foreach my $idx (keys(%{$dbcopies{$key}})) {
2572: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2573: my ($newurl,$result,$errtext) =
2574: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2575: if ($result eq 'ok') {
2576: $newdb{$idx} = $newurl;
2577: } elsif (ref($errors) eq 'HASH') {
2578: $errors->{$key} = 1;
2579: }
2580: push(@msgs,$errtext);
2581: }
1.484.2.7 raeburn 2582: }
2583: }
1.484.2.82 raeburn 2584: if (ref($resdatacopy{$key}) eq 'HASH') {
2585: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2586: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2587: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2588: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2589: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2590: my $template = $1;
2591: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2592: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2593: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2594: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2595: unless ($gotnewmapname) {
2596: ($newmapname) = ($key =~ m{/([^/]+)$});
2597: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2598: if ($newsubdir{$key}) {
2599: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2600: }
2601: $gotnewmapname = 1;
2602: }
2603: my $srcmapinfo = $srcfolder.':'.$idx;
2604: if ($srccontainer eq 'page') {
2605: $srcmapinfo .= ':1';
2606: }
2607: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2608: $cnum,$template,$idx,$newmapname);
2609: }
2610: }
2611: }
2612: }
2613: }
1.484.2.23 raeburn 2614: if (ref($params{$key}) eq 'HASH') {
2615: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2616: }
2617: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2618: if ($fatal) {
1.484.2.26 raeburn 2619: return ($errtext);
1.484.2.7 raeburn 2620: }
2621: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2622: if (defined($LONCAPA::map::zombies[$i])) {
2623: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2624: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2625: undef($LONCAPA::map::zombies[$i]);
2626: }
2627: }
2628: }
1.484.2.77 raeburn 2629: my $total = scalar(@LONCAPA::map::order) - 1;
2630: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2631: my $idx = $LONCAPA::map::order[$i];
2632: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2633: my $changed;
1.484.2.23 raeburn 2634: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2635: if ((exists($toremove{$idx})) &&
2636: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2637: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2638: if (ref($currparam{$idx}) eq 'ARRAY') {
2639: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2640: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2641: }
2642: }
2643: next;
2644: }
2645: my $origsrc = $src;
1.484.2.25 raeburn 2646: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2647: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2648: $changed = 1;
2649: }
2650: }
1.484.2.25 raeburn 2651: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2652: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2653: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2654: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2655: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2656: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2657: } else {
1.484.2.23 raeburn 2658: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2659: }
2660: }
1.484.2.25 raeburn 2661: if ($origsrc =~ /\.(page|sequence)$/) {
2662: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2663: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2664: }
1.484.2.25 raeburn 2665: } elsif ($newsubdir{$key}) {
2666: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2667: }
2668: }
2669: $changed = 1;
1.484.2.26 raeburn 2670: } elsif ($newdb{$idx} ne '') {
2671: $src = $newdb{$idx};
1.484.2.7 raeburn 2672: $changed = 1;
2673: }
2674: if ($changed) {
1.484.2.30 raeburn 2675: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2676: }
2677: }
2678: }
2679: foreach my $idx (keys(%remparam)) {
2680: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2681: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2682: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2683: }
2684: }
2685: }
1.484.2.26 raeburn 2686: if (values(%lockerrors) > 0) {
2687: $lockmsg = join('<br />',values(%lockerrors));
2688: }
1.484.2.7 raeburn 2689: my $storefn;
2690: if ($key eq $oldurl) {
2691: $storefn = $url;
2692: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2693: } else {
2694: $storefn = $key;
2695: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2696: if ($prefixchg && $before{'map'} && $after{'map'}) {
2697: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2698: }
1.484.2.23 raeburn 2699: if ($newsubdir{$key}) {
2700: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2701: }
2702: }
2703: my $report;
2704: if ($folder !~ /^supplemental/) {
2705: $report = 1;
2706: }
1.484.2.20 raeburn 2707: (my $outtext,$errtext) =
1.484.2.7 raeburn 2708: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2709: if ($errtext) {
1.484.2.23 raeburn 2710: if ($caller eq 'paste') {
1.484.2.26 raeburn 2711: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2712: }
1.484.2.7 raeburn 2713: }
2714: }
2715: }
1.484.2.26 raeburn 2716: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2717: }
2718:
2719: sub copy_dependencies {
2720: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2721: my $content;
2722: if (ref($contentref)) {
2723: $content = $$contentref;
2724: } else {
2725: $content = &Apache::lonnet::getfile($item);
2726: }
2727: unless ($content eq '-1') {
2728: my $mm = new File::MMagic;
2729: my $mimetype = $mm->checktype_contents($content);
2730: if ($mimetype eq 'text/html') {
2731: my (%allfiles,%codebase,$state);
2732: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2733: if ($res eq 'ok') {
2734: my ($numexisting,$numpathchanges,$existing);
2735: (undef,$numexisting,$numpathchanges,$existing) =
2736: &Apache::loncommon::ask_for_embedded_content(
2737: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2738: {'error_on_invalid_names' => 1,
2739: 'ignore_remote_references' => 1,
2740: 'docs_url' => $item,
2741: 'context' => 'paste'});
2742: if ($numexisting > 0) {
2743: if (ref($existing) eq 'HASH') {
2744: foreach my $dep (keys(%{$existing})) {
2745: my $depfile = $dep;
2746: unless ($depfile =~ m{^\Q$relpath\E}) {
2747: $depfile = $relpath.$dep;
2748: }
2749: my $depcontent = &Apache::lonnet::getfile($depfile);
2750: unless ($depcontent eq '-1') {
2751: my $storedep = $dep;
2752: $storedep =~ s{^\Q$relpath\E}{};
2753: my $dep_url =
2754: &Apache::lonclonecourse::writefile(
2755: $env{'request.course.id'},
2756: $storefn.$storedep,$depcontent);
2757: if ($dep_url eq '/adm/notfound.html') {
2758: if (ref($errors) eq 'HASH') {
2759: $errors->{$depfile} = 1;
2760: }
2761: } else {
2762: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2763: }
2764: }
2765: }
2766: }
2767: }
2768: }
2769: }
2770: }
2771: return;
2772: }
2773:
1.329 droeschl 2774: my %parameter_type = ( 'randompick' => 'int_pos',
2775: 'hiddenresource' => 'string_yesno',
2776: 'encrypturl' => 'string_yesno',
2777: 'randomorder' => 'string_yesno',);
2778: my $valid_parameters_re = join('|',keys(%parameter_type));
2779: # set parameters
2780: sub update_parameter {
1.484.2.29 raeburn 2781: if ($env{'form.changeparms'} eq 'all') {
2782: my (@allidx,@allmapidx,%allchecked,%currchecked);
2783: %allchecked = (
2784: 'hiddenresource' => {},
2785: 'encrypturl' => {},
2786: 'randompick' => {},
2787: 'randomorder' => {},
2788: );
2789: foreach my $which (keys(%allchecked)) {
2790: $env{'form.all'.$which} =~ s/,$//;
2791: if ($which eq 'randompick') {
2792: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2793: my ($res,$value) = split(/:/,$item);
2794: if ($value =~ /^\d+$/) {
2795: $allchecked{$which}{$res} = $value;
2796: }
2797: }
2798: } else {
1.484.2.30 raeburn 2799: if ($env{'form.all'.$which}) {
2800: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2801: }
1.484.2.29 raeburn 2802: }
2803: }
2804: my $haschanges = 0;
2805: foreach my $res (@LONCAPA::map::order) {
2806: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2807: $name=&LONCAPA::map::qtescape($name);
2808: $url=&LONCAPA::map::qtescape($url);
2809: next unless ($name && $url);
2810: my $is_map;
2811: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2812: $is_map = 1;
2813: }
2814: foreach my $which (keys(%allchecked)) {
2815: if (($which eq 'randompick' || $which eq 'randomorder')) {
2816: next if (!$is_map);
2817: }
2818: my $oldvalue = 0;
2819: my $newvalue = 0;
2820: if ($allchecked{$which}{$res}) {
2821: $newvalue = $allchecked{$which}{$res};
2822: }
2823: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2824: if ($which eq 'randompick') {
2825: if ($current =~ /^(\d+)$/) {
2826: $oldvalue = $1;
2827: }
2828: } else {
2829: if ($current =~ /^yes$/i) {
2830: $oldvalue = 1;
2831: }
2832: }
2833: if ($oldvalue ne $newvalue) {
2834: $haschanges = 1;
2835: if ($newvalue) {
2836: my $storeval = 'yes';
2837: if ($which eq 'randompick') {
2838: $storeval = $newvalue;
2839: }
2840: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2841: $storeval,
2842: $parameter_type{$which});
2843: &remember_parms($res,$which,'set',$storeval);
2844: } elsif ($oldvalue) {
2845: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2846: &remember_parms($res,$which,'del');
2847: }
2848: }
2849: }
2850: }
2851: return $haschanges;
1.329 droeschl 2852: } else {
1.484.2.59 raeburn 2853: my $haschanges = 0;
2854: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 2855:
1.484.2.29 raeburn 2856: my $which = $env{'form.changeparms'};
2857: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 2858: my $oldvalue = 0;
2859: my $newvalue = 0;
2860: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2861: if ($which eq 'randompick') {
2862: if ($current =~ /^(\d+)$/) {
2863: $oldvalue = $1;
2864: }
2865: } elsif ($current =~ /^yes$/i) {
2866: $oldvalue = 1;
2867: }
1.484.2.29 raeburn 2868: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 2869: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2870: : 1;
1.484.2.29 raeburn 2871: }
1.484.2.59 raeburn 2872: if ($oldvalue ne $newvalue) {
2873: $haschanges = 1;
2874: if ($newvalue) {
2875: my $storeval = 'yes';
2876: if ($which eq 'randompick') {
2877: $storeval = $newvalue;
2878: }
2879: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2880: $parameter_type{$which});
2881: &remember_parms($idx,$which,'set',$storeval);
2882: } else {
2883: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2884: &remember_parms($idx,$which,'del');
2885: }
2886: }
2887: return $haschanges;
1.329 droeschl 2888: }
1.484.2.59 raeburn 2889: return;
1.329 droeschl 2890: }
2891:
2892: sub handle_edit_cmd {
2893: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 2894: if ($env{'form.cmd'} eq '') {
2895: return 0;
2896: }
1.329 droeschl 2897: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2898:
2899: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2900: my ($title, $url, @rrest) = split(':', $ratstr);
2901:
1.484.2.30 raeburn 2902: if ($cmd eq 'remove') {
1.329 droeschl 2903: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2904: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2905: &Apache::lonnet::removeuploadedurl($url);
2906: } else {
2907: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2908: }
2909: splice(@LONCAPA::map::order, $idx, 1);
2910:
2911: } elsif ($cmd eq 'cut') {
2912: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2913: splice(@LONCAPA::map::order, $idx, 1);
2914:
1.344 bisitz 2915: } elsif ($cmd eq 'up'
1.329 droeschl 2916: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2917: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2918:
2919: } elsif ($cmd eq 'down'
2920: && defined($LONCAPA::map::order[$idx+1])) {
2921: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2922:
2923: } elsif ($cmd eq 'rename') {
2924: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2925: if ($comment=~/\S/) {
2926: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2927: $comment.':'.join(':', $url, @rrest);
2928: }
2929: # Devalidate title cache
2930: my $renamed_url=&LONCAPA::map::qtescape($url);
2931: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 2932:
1.329 droeschl 2933: } else {
2934: return 0;
2935: }
2936: return 1;
2937: }
2938:
2939: sub editor {
1.458 raeburn 2940: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.80 raeburn 2941: $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,
2942: $hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 2943: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2944: if ($allowed) {
2945: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2946: $is_random_order,$container) =
2947: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2948: $r->print($breadcrumbtrail);
2949: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2950: $container = 'page';
2951: } else {
2952: $container = 'sequence';
2953: }
1.484 raeburn 2954:
1.484.2.21 raeburn 2955: my $jumpto;
2956:
2957: unless ($supplementalflag) {
1.484.2.32 raeburn 2958: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 2959: }
1.484 raeburn 2960:
2961: unless ($allowed) {
2962: $randompick = -1;
2963: }
2964:
1.484.2.67 raeburn 2965: my ($errtext,$fatal);
2966: if (($folder eq '') && (!$supplementalflag)) {
2967: if (@LONCAPA::map::order) {
2968: undef(@LONCAPA::map::order);
2969: undef(@LONCAPA::map::resources);
2970: undef(@LONCAPA::map::resparms);
2971: undef(@LONCAPA::map::zombies);
2972: }
2973: $folder = 'default';
2974: $container = 'sequence';
2975: } else {
2976: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2977: $folder.'.'.$container);
2978: return $errtext if ($fatal);
2979: }
1.329 droeschl 2980:
2981: if ($#LONCAPA::map::order<1) {
2982: my $idx=&LONCAPA::map::getresidx();
2983: if ($idx<=0) { $idx=1; }
2984: $LONCAPA::map::order[0]=$idx;
2985: $LONCAPA::map::resources[$idx]='';
2986: }
1.364 bisitz 2987:
1.329 droeschl 2988: # ------------------------------------------------------------ Process commands
2989:
2990: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 2991: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 2992: # set parameters and change order
2993: &snapshotbefore();
2994:
2995: if (&update_parameter()) {
1.484.2.59 raeburn 2996: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 2997: return $errtext if ($fatal);
2998: }
2999:
3000: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3001: # change order
3002: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3003: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3004:
3005: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3006: return $errtext if ($fatal);
3007: }
1.364 bisitz 3008:
1.329 droeschl 3009: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3010: my %paste_errors;
1.484.2.26 raeburn 3011: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3012: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3013: \%paste_errors);
1.484.2.30 raeburn 3014: if (ref($pastemsgarray) eq 'ARRAY') {
3015: if (@{$pastemsgarray} > 0) {
3016: $r->print('<p class="LC_info">'.
3017: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3018: '</p>');
3019: }
1.484.2.30 raeburn 3020: }
3021: if ($lockerror) {
3022: $r->print('<p class="LC_error">'.
3023: $lockerror.
3024: '</p>');
3025: }
3026: if ($save_error ne '') {
3027: return $save_error;
3028: }
3029: if ($paste_res) {
3030: my %errortext = &Apache::lonlocal::texthash (
3031: fail => 'Storage of folder contents failed',
3032: failread => 'Reading folder contents failed',
3033: failstore => 'Storage of folder contents failed',
3034: );
3035: if ($errortext{$paste_res}) {
3036: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3037: }
1.329 droeschl 3038: }
1.484.2.7 raeburn 3039: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3040: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3041: &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".
3042: '<ul>'."\n");
3043: foreach my $key (sort(keys(%paste_errors))) {
3044: $r->print('<li>'.$key.'</li>'."\n");
3045: }
3046: $r->print('</ul></p>'."\n");
3047: }
1.484.2.30 raeburn 3048: } elsif ($env{'form.clearmarked'}) {
3049: my $output = &do_buffer_empty();
3050: if ($output) {
3051: $r->print('<p class="LC_info">'.$output.'</p>');
3052: }
3053: }
1.329 droeschl 3054:
3055: $r->print($upload_output);
3056:
1.484.2.30 raeburn 3057: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3058: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3059: my $contentchg;
1.484.2.58 raeburn 3060: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3061: $contentchg = 1;
3062: }
3063: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3064: return $errtext if ($fatal);
3065: }
1.484.2.30 raeburn 3066:
3067: # Cut, copy and/or remove multiple resources
3068: if ($env{'form.multichange'}) {
3069: my %allchecked = (
3070: cut => {},
3071: remove => {},
3072: );
3073: my $needsupdate;
3074: foreach my $which (keys(%allchecked)) {
3075: $env{'form.multi'.$which} =~ s/,$//;
3076: if ($env{'form.multi'.$which}) {
3077: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3078: if (ref($allchecked{$which}) eq 'HASH') {
3079: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3080: }
3081: }
3082: }
3083: if ($needsupdate) {
3084: my $haschanges = 0;
3085: my %curr_groups = &Apache::longroup::coursegroups();
3086: my $total = scalar(@LONCAPA::map::order) - 1;
3087: for (my $i=$total; $i>=0; $i--) {
3088: my $res = $LONCAPA::map::order[$i];
3089: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3090: $name=&LONCAPA::map::qtescape($name);
3091: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3092: next unless $url;
1.484.2.30 raeburn 3093: my %denied =
3094: &action_restrictions($coursenum,$coursedom,$url,
3095: $env{'form.folderpath'},\%curr_groups);
3096: foreach my $which (keys(%allchecked)) {
3097: next if ($denied{$which});
3098: next unless ($allchecked{$which}{$res});
3099: if ($which eq 'remove') {
3100: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3101: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3102: &Apache::lonnet::removeuploadedurl($url);
3103: } else {
3104: &LONCAPA::map::makezombie($res);
3105: }
3106: splice(@LONCAPA::map::order,$i,1);
3107: $haschanges ++;
3108: } elsif ($which eq 'cut') {
3109: &LONCAPA::map::makezombie($res);
3110: splice(@LONCAPA::map::order,$i,1);
3111: $haschanges ++;
3112: }
3113: }
3114: }
3115: if ($haschanges) {
3116: ($errtext,$fatal) =
3117: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3118: return $errtext if ($fatal);
3119: }
3120: }
3121: }
3122:
1.329 droeschl 3123: # Group import/search
3124: if ($env{'form.importdetail'}) {
3125: my @imports;
3126: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3127: if (defined($item)) {
3128: my ($name,$url,$residx)=
1.484.2.26 raeburn 3129: map { &unescape($_); } split(/\=/,$item);
3130: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3131: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3132: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3133: if ($locknotfreed) {
3134: $r->print($locknotfreed);
3135: }
3136: if ($suffix) {
1.484.2.19 raeburn 3137: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3138: } else {
3139: return $errortxt;
3140: }
1.484.2.26 raeburn 3141: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3142: my $type = $1;
3143: my ($suffix,$errortxt,$locknotfreed) =
3144: &new_timebased_suffix($coursedom,$coursenum,$type);
3145: if ($locknotfreed) {
3146: $r->print($locknotfreed);
3147: }
3148: if ($suffix) {
3149: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3150: } else {
3151: return $errortxt;
3152: }
1.484.2.27 raeburn 3153: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3154: if ($supplementalflag) {
3155: next unless ($1 eq 'supplemental');
3156: if ($folder eq 'supplemental') {
3157: next unless ($2 eq 'default');
3158: } else {
3159: next unless ($folder eq 'supplemental_'.$2);
3160: }
3161: } else {
3162: next unless ($1 eq 'docs');
3163: if ($folder eq 'default') {
3164: next unless ($2 eq 'default');
3165: } else {
3166: next unless ($folder eq 'default_'.$2);
3167: }
3168: }
1.484.2.15 raeburn 3169: }
1.329 droeschl 3170: push(@imports, [$name, $url, $residx]);
3171: }
3172: }
1.484.2.23 raeburn 3173: ($errtext,$fatal,my $fixuperrors) =
3174: &group_import($coursenum, $coursedom, $folder,$container,
3175: 'londocs',@imports);
1.329 droeschl 3176: return $errtext if ($fatal);
1.484.2.23 raeburn 3177: if ($fixuperrors) {
3178: $r->print($fixuperrors);
3179: }
1.329 droeschl 3180: }
3181: # Loading a complete map
3182: if ($env{'form.loadmap'}) {
3183: if ($env{'form.importmap'}=~/\w/) {
3184: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3185: my ($title,$url,$ext,$type)=split(/\:/,$res);
3186: my $idx=&LONCAPA::map::getresidx($url);
3187: $LONCAPA::map::resources[$idx]=$res;
3188: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3189: }
3190: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3191: $folder.'.'.$container,1);
1.329 droeschl 3192: return $errtext if ($fatal);
3193: } else {
3194: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3195:
1.329 droeschl 3196: }
3197: }
3198: &log_differences($plain);
3199: }
3200: # ---------------------------------------------------------------- End commands
3201: # ---------------------------------------------------------------- Print screen
3202: my $idx=0;
3203: my $shown=0;
3204: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3205: $r->print('<div class="LC_Box">'.
1.432 raeburn 3206: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3207: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3208: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3209: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3210: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3211: '</ol>');
1.381 bisitz 3212: if ($randompick>=0) {
3213: $r->print('<p class="LC_warning">'
3214: .&mt('Caution: this folder is set to randomly pick a subset'
3215: .' of resources. Adding or removing resources from this'
3216: .' folder will change the set of resources that the'
3217: .' students see, resulting in spurious or missing credit'
3218: .' for completed problems, not limited to ones you'
3219: .' modify. Do not modify the contents of this folder if'
3220: .' it is in active student use.')
3221: .'</p>'
3222: );
3223: }
3224: if ($is_random_order) {
3225: $r->print('<p class="LC_warning">'
3226: .&mt('Caution: this folder is set to randomly order its'
3227: .' contents. Adding or removing resources from this folder'
3228: .' will change the order of resources shown.')
3229: .'</p>'
3230: );
3231: }
3232: $r->print('</div>');
1.364 bisitz 3233: }
1.381 bisitz 3234:
1.484.2.30 raeburn 3235: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3236: %filters = (
3237: canremove => [],
3238: cancut => [],
3239: cancopy => [],
3240: hiddenresource => [],
3241: encrypturl => [],
3242: randomorder => [],
3243: randompick => [],
3244: );
3245: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3246: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3247: foreach my $res (@LONCAPA::map::order) {
3248: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3249: $name=&LONCAPA::map::qtescape($name);
3250: $url=&LONCAPA::map::qtescape($url);
3251: unless ($name) { $name=(split(/\//,$url))[-1]; }
3252: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3253: push(@allidx,$res);
3254: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3255: push(@allmapidx,$res);
3256: }
1.484.2.67 raeburn 3257:
1.381 bisitz 3258: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3259: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3260: $pathitem,$supplementalflag,$container,
1.484.2.70 raeburn 3261: \%filters,\%curr_groups,$canedit,
1.484.2.80 raeburn 3262: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3263: $idx++;
3264: $shown++;
1.329 droeschl 3265: }
1.424 onken 3266: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3267:
1.484.2.30 raeburn 3268: my $need_save;
1.484.2.67 raeburn 3269: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3270: my $toolslink;
1.484.2.67 raeburn 3271: if ($allowed) {
1.484.2.31 raeburn 3272: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3273: .&Apache::loncommon::help_open_menu('Navigation Screen',
3274: 'Navigation_Screen',undef,'RAT')
3275: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3276: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3277: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3278: .'id="LC_content_toolbar_edittoplevel" '
3279: .'class="LC_toolbarItem" '
3280: .'title="'.&mt('Supplemental Content Editor').'">'
3281: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3282: }
1.484.2.19 raeburn 3283: if ($shown) {
3284: if ($allowed) {
3285: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3286: .&Apache::loncommon::start_data_table(undef,'contentlist')
3287: .&Apache::loncommon::start_data_table_header_row()
3288: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3289: .'<th colspan="2">'.&mt('Actions').'</th>'
3290: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3291: if ($folder !~ /^supplemental/) {
3292: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3293: }
1.484.2.29 raeburn 3294: $to_show .= &Apache::loncommon::end_data_table_header_row();
3295: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3296: $lists{'canhide'} = join(',',@allidx);
3297: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3298: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3299: 'randomorder','randompick');
3300: foreach my $item (@possfilters) {
3301: if (ref($filters{$item}) eq 'ARRAY') {
3302: if (@{$filters{$item}} > 0) {
3303: $lists{$item} = join(',',@{$filters{$item}});
3304: }
3305: }
3306: }
1.484.2.29 raeburn 3307: if (@allidx > 0) {
3308: my $path;
3309: if ($env{'form.folderpath'}) {
3310: $path =
3311: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3312: }
1.484.2.30 raeburn 3313: if (@allidx > 1) {
3314: $to_show .=
3315: &Apache::loncommon::continue_data_table_row().
3316: '<td colspan="2"> </td>'.
3317: '<td>'.
1.484.2.67 raeburn 3318: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3319: '</td>'.
3320: '<td> </td>'.
3321: '<td> </td>'.
3322: '<td colspan="4">'.
1.484.2.67 raeburn 3323: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3324: '</td>'.
3325: &Apache::loncommon::end_data_table_row();
3326: $need_save = 1;
3327: }
1.484.2.29 raeburn 3328: }
3329: }
3330: $to_show .= $output.' '
1.484.2.19 raeburn 3331: .&Apache::loncommon::end_data_table()
3332: .'<br style="line-height:2px;" />'
3333: .&Apache::loncommon::end_scrollbox();
3334: } else {
3335: $to_show .= $toolslink
3336: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3337: .$output.' '
3338: .&Apache::loncommon::end_data_table();
3339: }
3340: } else {
3341: if (!$allowed) {
3342: $to_show .= $toolslink;
1.393 raeburn 3343: }
1.484.2.67 raeburn 3344: my $noresmsg;
3345: if ($allowed && $hiddentop && !$supplementalflag) {
3346: $noresmsg = &mt('Main Content Hidden');
3347: } else {
3348: $noresmsg = &mt('Currently empty');
3349: }
1.484.2.19 raeburn 3350: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3351: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3352: .$noresmsg
1.484.2.19 raeburn 3353: .'</div>'
3354: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3355: }
3356: } else {
1.484.2.19 raeburn 3357: if ($shown) {
3358: $to_show = '<div>'
3359: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3360: .$output
3361: .&Apache::loncommon::end_data_table()
3362: .'</div>';
3363: } else {
3364: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3365: .&mt('Currently empty')
1.484.2.19 raeburn 3366: .'</div>'
3367: }
1.458 raeburn 3368: }
3369: my $tid = 1;
3370: if ($supplementalflag) {
3371: $tid = 2;
1.329 droeschl 3372: }
3373: if ($allowed) {
1.484 raeburn 3374: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3375: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3376: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3377: if ($canedit) {
1.484.2.67 raeburn 3378: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3379: }
1.460 raeburn 3380: } else {
3381: $r->print($to_show);
1.329 droeschl 3382: }
3383: return;
3384: }
3385:
1.484.2.30 raeburn 3386: sub multiple_check_form {
1.484.2.67 raeburn 3387: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3388: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3389: my $disabled;
3390: unless ($canedit) {
3391: $disabled = 'disabled="disabled"';
3392: }
1.484.2.30 raeburn 3393: my $output =
3394: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3395: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3396: '<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>'.
3397: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3398: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3399: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3400: if ($caller eq 'settings') {
3401: $output .=
3402: '<table><tr>'.
3403: '<td class="LC_docs_entry_parameter">'.
3404: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3405: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3406: '</label></span></td>'.
3407: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3408: '<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 3409: '</span></td>'.
3410: '</tr>'."\n".
3411: '<tr>'.
3412: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3413: '<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 3414: '</label></span>'.
3415: '</td></tr></table>'."\n";
3416: } else {
3417: $output .=
3418: '<table><tr>'.
3419: '<td class="LC_docs_entry_parameter">'.
3420: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3421: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3422: '</label></span></td>'.
3423: '<td class="LC_docs_entry_parameter">'.
3424: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3425: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3426: '</label></span></td>'."\n".
3427: '<td class="LC_docs_entry_parameter">'.
3428: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3429: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3430: '</label></span></td>'.
3431: '</tr></table>'."\n";
3432: }
3433: $output .=
3434: '</fieldset>'.
3435: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3436: if ($caller eq 'settings') {
3437: $output .=
3438: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3439: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3440: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3441: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3442: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3443: } elsif ($caller eq 'actions') {
3444: $output .=
3445: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3446: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3447: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3448: }
3449: $output .=
3450: '</form>'.
3451: '</div>';
3452: return $output;
3453: }
3454:
1.329 droeschl 3455: sub process_file_upload {
1.484.2.36 raeburn 3456: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3457: # upload a file, if present
1.484.2.36 raeburn 3458: my $filesize = length($env{'form.uploaddoc'});
3459: if (!$filesize) {
3460: $$upload_output = '<div class="LC_error">'.
3461: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3462: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3463: $filesize).'<br />'.
3464: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3465: '</div>';
3466: return;
3467: }
3468: my $quotatype = 'unofficial';
3469: if ($crstype eq 'Community') {
3470: $quotatype = 'community';
1.484.2.51 raeburn 3471: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3472: $quotatype = 'official';
1.484.2.45 raeburn 3473: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3474: $quotatype = 'textbook';
1.484.2.36 raeburn 3475: }
3476: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3477: $filesize = int($filesize/1000); #expressed in kb
3478: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3479: $env{'form.uploaddoc.filename'},$filesize,
3480: 'upload',$quotatype);
1.484.2.36 raeburn 3481: return if ($$upload_output);
3482: }
1.440 raeburn 3483: my ($parseaction,$showupload,$nextphase,$mimetype);
3484: if ($env{'form.parserflag'}) {
1.329 droeschl 3485: $parseaction = 'parse';
3486: }
3487: my $folder=$env{'form.folder'};
3488: if ($folder eq '') {
3489: $folder='default';
3490: }
3491: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3492: my $errtext='';
3493: my $fatal=0;
3494: my $container='sequence';
1.484.2.19 raeburn 3495: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3496: $container='page';
3497: }
3498: ($errtext,$fatal)=
1.484.2.27 raeburn 3499: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3500: if ($#LONCAPA::map::order<1) {
3501: $LONCAPA::map::order[0]=1;
3502: $LONCAPA::map::resources[1]='';
3503: }
3504: my $destination = 'docs/';
3505: if ($folder =~ /^supplemental/) {
3506: $destination = 'supplemental/';
3507: }
3508: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3509: $destination .= 'default/';
3510: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3511: $destination .= $2.'/';
3512: }
1.484.2.27 raeburn 3513: if ($fatal) {
3514: $$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>';
3515: return;
3516: }
1.440 raeburn 3517: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3518: my $newidx=&LONCAPA::map::getresidx();
3519: $destination .= $newidx;
1.439 raeburn 3520: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3521: $parseaction,$allfiles,
1.440 raeburn 3522: $codebase,undef,undef,undef,undef,
3523: undef,undef,\$mimetype);
3524: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3525: my $stored = $1;
3526: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3527: $stored.'</span>').'</p>';
3528: } else {
3529: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3530:
1.457 raeburn 3531: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3532: return;
3533: }
1.329 droeschl 3534: my $ext='false';
3535: if ($url=~m{^http://}) { $ext='true'; }
3536: $url = &LONCAPA::map::qtunescape($url);
3537: my $comment=$env{'form.comment'};
3538: $comment = &LONCAPA::map::qtunescape($comment);
3539: if ($folder=~/^supplemental/) {
3540: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3541: $env{'user.domain'}.'___&&&___'.$comment;
3542: }
3543:
3544: $LONCAPA::map::resources[$newidx]=
3545: $comment.':'.$url.':'.$ext.':normal:res';
3546: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3547: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3548: $folder.'.'.$container,1);
1.329 droeschl 3549: if ($fatal) {
1.457 raeburn 3550: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3551: return;
1.329 droeschl 3552: } else {
1.440 raeburn 3553: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3554: $$upload_output = $showupload;
1.384 raeburn 3555: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3556: if ($total_embedded > 0) {
1.440 raeburn 3557: my $uploadphase = 'upload_embedded';
3558: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3559: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3560: my ($embedded,$num) =
3561: &Apache::loncommon::ask_for_embedded_content(
3562: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3563: if ($embedded) {
3564: if ($num) {
3565: $$upload_output .=
3566: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3567: $nextphase = $uploadphase;
3568: } else {
3569: $$upload_output .= $embedded;
3570: }
3571: } else {
3572: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3573: }
1.329 droeschl 3574: } else {
1.440 raeburn 3575: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3576: }
1.457 raeburn 3577: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3578: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3579: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3580: $nextphase = 'decompress_uploaded';
3581: my $position = scalar(@LONCAPA::map::order)-1;
3582: my $noextract = &return_to_editor();
3583: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3584: my %archiveitems = (
3585: folderpath => $env{'form.folderpath'},
3586: cmd => $nextphase,
3587: newidx => $newidx,
3588: position => $position,
3589: phase => $nextphase,
1.477 raeburn 3590: comment => $comment,
1.480 raeburn 3591: );
3592: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3593: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3594: $$upload_output = $showupload.
3595: &Apache::loncommon::decompress_form($mimetype,
3596: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3597: \%archiveitems,\@current);
1.329 droeschl 3598: }
3599: }
3600: }
1.440 raeburn 3601: return $nextphase;
1.329 droeschl 3602: }
3603:
1.480 raeburn 3604: sub get_dir_list {
3605: my ($url,$coursenum,$coursedom,$newidx) = @_;
3606: my ($destination,$dir_root) = &embedded_destination();
3607: my ($dirlistref,$listerror) =
3608: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3609: my @dir_lines;
3610: my $dirptr=16384;
3611: if (ref($dirlistref) eq 'ARRAY') {
3612: foreach my $dir_line (sort
3613: {
3614: my ($afile)=split('&',$a,2);
3615: my ($bfile)=split('&',$b,2);
3616: return (lc($afile) cmp lc($bfile));
3617: } (@{$dirlistref})) {
3618: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3619: $filename =~ s/\s+$//;
3620: next if ($filename =~ /^\.\.?$/);
3621: my $isdir = 0;
3622: if ($dirptr&$testdir) {
3623: $isdir = 1;
3624: }
3625: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3626: }
3627: }
3628: return @dir_lines;
3629: }
3630:
1.329 droeschl 3631: sub is_supplemental_title {
3632: my ($title) = @_;
3633: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3634: }
3635:
3636: # --------------------------------------------------------------- An entry line
3637:
3638: sub entryline {
1.484.2.12 raeburn 3639: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3640: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.80 raeburn 3641: $canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3642: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3643: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3644: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3645: } else {
3646: $title=&HTML::Entities::encode($title,'"<>&\'');
3647: $renametitle=$title;
3648: $foldertitle=$title;
3649: }
3650:
1.484.2.67 raeburn 3651: my ($disabled,$readonly,$js_lt);
3652: unless ($canedit) {
3653: $disabled = 'disabled="disabled"';
3654: $readonly = 1;
3655: }
3656:
1.329 droeschl 3657: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3658:
1.329 droeschl 3659: $renametitle=~s/\\/\\\\/g;
3660: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3661: $renametitle=~s/"/%22/g;
1.329 droeschl 3662: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3663: $oldtitle = $renametitle;
3664: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3665: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3666: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3667: # Edit commands
1.484.2.28 raeburn 3668: my ($esc_path, $path, $symb);
1.329 droeschl 3669: if ($env{'form.folderpath'}) {
3670: $esc_path=&escape($env{'form.folderpath'});
3671: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3672: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3673: }
1.484.2.16 raeburn 3674: my $isexternal;
1.484.2.19 raeburn 3675: if ($residx) {
1.484.2.12 raeburn 3676: my $currurl = $url;
3677: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3678: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3679: $isexternal = 1;
3680: }
1.484.2.19 raeburn 3681: if (!$supplementalflag) {
3682: my $path = 'uploaded/'.
3683: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3684: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3685: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3686: $residx,
3687: &Apache::lonnet::declutter($currurl));
3688: }
1.484.2.12 raeburn 3689: }
1.484.2.30 raeburn 3690: my ($renamelink,%lt,$ishash);
3691: if (ref($filtersref) eq 'HASH') {
3692: $ishash = 1;
3693: }
3694:
1.329 droeschl 3695: if ($allowed) {
1.484.2.30 raeburn 3696: $form_start = '
3697: <form action="/adm/coursedocs" method="post">
3698: ';
3699: $form_common=(<<END);
3700: <input type="hidden" name="folderpath" value="$path" />
3701: <input type="hidden" name="symb" value="$symb" />
3702: END
3703: $form_param=(<<END);
3704: <input type="hidden" name="setparms" value="$orderidx" />
3705: <input type="hidden" name="changeparms" value="0" />
3706: END
3707: $form_end = '</form>';
3708:
1.329 droeschl 3709: my $incindex=$index+1;
3710: my $selectbox='';
1.471 raeburn 3711: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3712: ((split(/\:/,
1.344 bisitz 3713: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3714: ne '') &&
1.329 droeschl 3715: ((split(/\:/,
1.344 bisitz 3716: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3717: ne '')) {
3718: $selectbox=
3719: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3720: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3721: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3722: if ($i==$incindex) {
1.358 bisitz 3723: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3724: } else {
3725: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3726: }
3727: }
3728: $selectbox.='</select>';
3729: }
1.484.2.12 raeburn 3730: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3731: 'up' => 'Move Up',
3732: 'dw' => 'Move Down',
3733: 'rm' => 'Remove',
3734: 'ct' => 'Cut',
3735: 'rn' => 'Rename',
1.484.2.12 raeburn 3736: 'cp' => 'Copy',
3737: 'ex' => 'External Resource',
3738: 'ed' => 'Edit',
3739: 'pr' => 'Preview',
3740: 'sv' => 'Save',
3741: 'ul' => 'URL',
1.484.2.67 raeburn 3742: 'ti' => 'Title',
3743: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3744: );
1.484.2.30 raeburn 3745: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3746: $env{'form.folderpath'},
3747: $currgroups);
1.484.2.19 raeburn 3748: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3749: my $skip_confirm = 0;
1.484.2.63 raeburn 3750: my $confirm_removal = 0;
1.329 droeschl 3751: if ( $folder =~ /^supplemental/
3752: || ($url =~ m{( /smppg$
3753: |/syllabus$
3754: |/aboutme$
3755: |/navmaps$
3756: |/bulletinboard$
1.484.2.16 raeburn 3757: |\.html$)}x)
1.484.2.19 raeburn 3758: || $isexternal) {
1.329 droeschl 3759: $skip_confirm = 1;
3760: }
1.484.2.63 raeburn 3761: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3762: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3763: $confirm_removal = 1;
3764: }
1.484.2.19 raeburn 3765:
1.484.2.30 raeburn 3766: if ($denied{'copy'}) {
3767: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3768: <span style="visibility: hidden;">$lt{'cp'}</span>
3769: ENDCOPY
3770: } else {
1.484.2.30 raeburn 3771: my $formname = 'edit_copy_'.$orderidx;
3772: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3773: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3774: <form name="$formname" method="post" action="/adm/coursedocs">
3775: $form_common
1.484.2.67 raeburn 3776: <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 3777: $form_end
1.329 droeschl 3778: ENDCOPY
1.484.2.30 raeburn 3779: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3780: push(@{$filtersref->{'cancopy'}},$orderidx);
3781: }
1.329 droeschl 3782: }
1.484.2.30 raeburn 3783: if ($denied{'cut'}) {
1.484.2.16 raeburn 3784: $cutlink=(<<ENDCUT);
3785: <span style="visibility: hidden;">$lt{'ct'}</span>
3786: ENDCUT
3787: } else {
1.484.2.30 raeburn 3788: my $formname = 'edit_cut_'.$orderidx;
3789: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3790: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3791: <form name="$formname" method="post" action="/adm/coursedocs">
3792: $form_common
3793: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3794: <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 3795: $form_end
1.329 droeschl 3796: ENDCUT
1.484.2.30 raeburn 3797: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3798: push(@{$filtersref->{'cancut'}},$orderidx);
3799: }
1.329 droeschl 3800: }
1.484.2.30 raeburn 3801: if ($denied{'remove'}) {
1.484.2.16 raeburn 3802: $removelink=(<<ENDREM);
3803: <span style="visibility: hidden;">$lt{'rm'}</a>
3804: ENDREM
3805: } else {
1.484.2.30 raeburn 3806: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3807: 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 3808: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3809: <form name="$formname" method="post" action="/adm/coursedocs">
3810: $form_common
3811: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3812: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3813: <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 3814: $form_end
1.484.2.9 raeburn 3815: ENDREM
1.484.2.30 raeburn 3816: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3817: push(@{$filtersref->{'canremove'}},$orderidx);
3818: }
1.484.2.9 raeburn 3819: }
1.484.2.35 raeburn 3820: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3821: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3822: ENDREN
1.484.2.67 raeburn 3823: my ($uplink,$downlink);
3824: if ($canedit) {
3825: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3826: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3827: } else {
3828: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3829: $downlink = $uplink;
3830: }
1.329 droeschl 3831: $line.=(<<END);
3832: <td>
1.379 bisitz 3833: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3834: <a href="$uplink">
1.484.2.12 raeburn 3835: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3836: </a>
3837: </div>
3838: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3839: <a href="$downlink">
1.484.2.12 raeburn 3840: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3841: </a>
3842: </div>
1.329 droeschl 3843: </td>
3844: <td>
3845: $form_start
1.484.2.30 raeburn 3846: $form_param
1.478 raeburn 3847: $form_common
1.329 droeschl 3848: $selectbox
3849: $form_end
3850: </td>
1.484.2.30 raeburn 3851: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3852: $removelink
1.329 droeschl 3853: $cutlink
3854: $copylink
3855: </td>
3856: END
3857: }
3858: # Figure out what kind of a resource this is
3859: my ($extension)=($url=~/\.(\w+)$/);
3860: my $uploaded=($url=~/^\/*uploaded\//);
3861: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3862: my $isfolder;
3863: my $ispage;
3864: my $containerarg;
1.484.2.67 raeburn 3865: my $folderurl;
1.329 droeschl 3866: if ($uploaded) {
1.472 raeburn 3867: if (($extension eq 'sequence') || ($extension eq 'page')) {
3868: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3869: $containerarg = $1;
1.472 raeburn 3870: if ($extension eq 'sequence') {
3871: $icon=$iconpath.'navmap.folder.closed.gif';
3872: $isfolder=1;
3873: } else {
3874: $icon=$iconpath.'page.gif';
3875: $ispage=1;
3876: }
1.484.2.67 raeburn 3877: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3878: if ($allowed) {
3879: $url='/adm/coursedocs?';
3880: } else {
3881: $url='/adm/supplemental?';
3882: }
1.329 droeschl 3883: } else {
3884: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3885: }
3886: }
1.364 bisitz 3887:
1.484.2.70 raeburn 3888: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3889: my $orig_url = $url;
1.340 raeburn 3890: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 3891: if ($container eq 'page') {
3892: $url=~s{^http(|s)(:|:)//}{/ext/};
3893: } else {
3894: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3895: }
1.484.2.12 raeburn 3896: if (!$supplementalflag && $residx && $symb) {
3897: if ((!$isfolder) && (!$ispage)) {
3898: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.87 raeburn 3899: if (($url =~ m{^ext/}) && ($container eq 'page')) {
3900: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
3901: } else {
3902: $url=&Apache::lonnet::clutter($url);
3903: }
1.484.2.12 raeburn 3904: if ($url=~/^\/*uploaded\//) {
3905: $url=~/\.(\w+)$/;
3906: my $embstyle=&Apache::loncommon::fileembstyle($1);
3907: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3908: $url='/adm/wrapper'.$url;
3909: } elsif ($embstyle eq 'ssi') {
3910: #do nothing with these
3911: } elsif ($url!~/\.(sequence|page)$/) {
3912: $url='/adm/coursedocs/showdoc'.$url;
3913: }
1.484.2.70 raeburn 3914: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
3915: my $wrapped = $1;
3916: my $exturl = $2;
1.484.2.87 raeburn 3917: if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 3918: $url='/adm/wrapper'.$url;
3919: }
3920: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
3921: $nomodal = 1;
3922: }
3923: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3924: if (($ENV{'SERVER_PORT'} == 443) &&
3925: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 3926: unless (&Apache::lonnet::uses_sts()) {
3927: $url .= '?usehttp=1';
3928: }
1.484.2.70 raeburn 3929: $nomodal = 1;
3930: }
1.484.2.19 raeburn 3931: }
1.484.2.12 raeburn 3932: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3933: my $shownsymb = $symb;
3934: if ($isexternal) {
1.484.2.88 raeburn 3935: $url =~ s/\#[^#]+$//;
1.484.2.87 raeburn 3936: if ($container eq 'page') {
3937: $url = &Apache::lonnet::clutter($url);
3938: }
1.484.2.66 raeburn 3939: }
1.484.2.67 raeburn 3940: unless ($env{'request.role.adv'}) {
3941: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3942: $url = '';
3943: }
3944: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3945: $url = '';
3946: $hiddenres = 1;
3947: }
3948: }
3949: if ($url ne '') {
1.484.2.75 raeburn 3950: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3951: }
3952: } elsif (!$env{'request.role.adv'}) {
3953: my $checkencrypt;
3954: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3955: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3956: $checkencrypt = 1;
1.484.2.70 raeburn 3957: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3958: unless (ref($$navmapref)) {
3959: $$navmapref = Apache::lonnavmaps::navmap->new();
3960: }
3961: if (ref($$navmapref)) {
3962: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
3963: $checkencrypt = 1;
3964: }
3965: }
3966: }
3967: if ($checkencrypt) {
3968: my $shownsymb = &Apache::lonenc::encrypted($symb);
3969: my $shownurl = &Apache::lonenc::encrypted($url);
3970: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 3971: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3972: if ($env{'request.enc'} ne '') {
3973: delete($env{'request.enc'});
3974: }
3975: } else {
3976: $url='';
3977: }
3978: } else {
3979: $url='';
3980: }
1.484.2.12 raeburn 3981: } else {
3982: $url='';
3983: }
1.484.2.19 raeburn 3984: }
1.484.2.66 raeburn 3985: } elsif ($supplementalflag) {
3986: if ($isexternal) {
3987: if ($url =~ /^([^#]+)#([^#]+)$/) {
3988: $url = $1;
3989: $anchor = $2;
1.484.2.70 raeburn 3990: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.80 raeburn 3991: unless (&Apache::lonnet::uses_sts()) {
3992: if ($hostname ne '') {
3993: $url = 'http://'.$hostname.$url;
3994: }
3995: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
3996: }
1.484.2.70 raeburn 3997: $nomodal = 1;
3998: }
3999: }
4000: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4001: if (($ENV{'SERVER_PORT'} == 443) &&
4002: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 4003: unless (&Apache::lonnet::uses_sts()) {
4004: if ($hostname ne '') {
4005: $url = 'http://'.$hostname.$url;
4006: }
4007: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4008: }
1.484.2.70 raeburn 4009: $nomodal = 1;
1.484.2.66 raeburn 4010: }
4011: }
1.329 droeschl 4012: }
1.484.2.67 raeburn 4013: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4014: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4015: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4016: my $foldername=&escape($foldertitle);
4017: my $folderpath=$env{'form.folderpath'};
4018: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4019: if (!$allowed && $supplementalflag) {
4020: $folderpath.=$containerarg.'&'.$foldername;
4021: $url.='folderpath='.&escape($folderpath);
4022: } else {
4023: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4024: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4025: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4026: 'parameter_randomorder'))[0]=~/^yes$/i);
4027: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4028: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4029: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4030: 'parameter_encrypturl'))[0]=~/^yes$/i);
4031: unless ($hiddenmap) {
1.484.2.70 raeburn 4032: if (ref($navmapref)) {
4033: unless (ref($$navmapref)) {
4034: $$navmapref = Apache::lonnavmaps::navmap->new();
4035: }
4036: if (ref($$navmapref)) {
4037: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4038: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4039: unless (@resources) {
4040: $hiddenmap = 1;
4041: unless ($env{'request.role.adv'}) {
4042: $url = '';
4043: $hiddenfolder = 1;
4044: }
1.484.2.67 raeburn 4045: }
4046: }
4047: }
4048: }
4049: }
4050: unless ($encryptmap) {
1.484.2.70 raeburn 4051: if ((ref($navmapref)) && (ref($$navmapref))) {
4052: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4053: $encryptmap = 1;
4054: }
1.484.2.67 raeburn 4055: }
4056: }
4057:
4058: # Append randompick number, hidden, and encrypted with ":" to foldername,
4059: # so it gets transferred between levels
4060: $folderpath.=$containerarg.'&'.$foldername.
4061: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4062: unless ($url eq '') {
4063: $url.='folderpath='.&escape($folderpath);
4064: }
1.484.2.19 raeburn 4065: my $rpckchk;
4066: if ($rpicknum) {
4067: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4068: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4069: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4070: }
1.484.2.19 raeburn 4071: }
1.484.2.29 raeburn 4072: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4073: $rand_pick_text =
1.478 raeburn 4074: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4075: $form_param."\n".
1.478 raeburn 4076: $form_common."\n".
1.484.2.67 raeburn 4077: '<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 4078: if ($rpicknum ne '') {
4079: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4080: }
1.484.2.29 raeburn 4081: $rand_pick_text .= '</span></span>'.
4082: $form_end;
1.484.2.30 raeburn 4083: my $ro_set;
1.484.2.67 raeburn 4084: if ($randorder) {
1.484.2.30 raeburn 4085: $ro_set = 'checked="checked"';
4086: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4087: push(@{$filtersref->{'randomorder'}},$orderidx);
4088: }
4089: }
1.484.2.41 raeburn 4090: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4091: $rand_order_text =
1.484.2.29 raeburn 4092: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4093: $form_param."\n".
1.484.2.29 raeburn 4094: $form_common."\n".
1.484.2.67 raeburn 4095: '<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 4096: $form_end;
1.484.2.19 raeburn 4097: }
1.484.2.18 raeburn 4098: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 4099: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4100: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4101: if ($title) {
4102: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4103: }
4104: if ($isexternal && $orderidx) {
4105: $url .= '&idx='.$orderidx;
4106: }
1.484.2.66 raeburn 4107: if ($anchor ne '') {
4108: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4109: }
1.329 droeschl 4110: }
1.484.2.19 raeburn 4111: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4112: if ($allowed) {
1.484.2.19 raeburn 4113: my $fileloc =
1.484.2.12 raeburn 4114: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4115: if ($isexternal) {
4116: ($editlink,$extresform) =
1.484.2.67 raeburn 4117: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4118: undef,undef,undef,$disabled);
1.484.2.19 raeburn 4119: } elsif (!$isfolder && !$ispage) {
4120: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4121: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4122: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4123: my $suppanchor;
4124: if ($supplementalflag) {
4125: $suppanchor = $anchor;
4126: }
1.484.2.19 raeburn 4127: my $jscall =
1.484.2.12 raeburn 4128: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4129: $switchserver,
1.484.2.14 raeburn 4130: $forceedit,
1.484.2.19 raeburn 4131: undef,$symb,
4132: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4133: $renametitle,$hostname,
4134: '','',1,$suppanchor);
1.484.2.12 raeburn 4135: if ($jscall) {
1.484.2.19 raeburn 4136: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4137: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4138: }
4139: }
4140: }
1.484.2.19 raeburn 4141: $tdalign = ' align="right" valign="top"';
4142: $tdwidth = ' width="80%"';
1.329 droeschl 4143: }
1.408 raeburn 4144: my $reinit;
4145: if ($crstype eq 'Community') {
4146: $reinit = &mt('(re-initialize community to access)');
4147: } else {
4148: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4149: }
4150: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4151: my $link;
1.472 raeburn 4152: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4153: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4154: } elsif ($url) {
1.484.2.66 raeburn 4155: if ($anchor ne '') {
4156: if ($supplementalflag) {
4157: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4158: } else {
4159: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4160: }
4161: }
1.484.2.80 raeburn 4162:
4163: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4164: $link = 'http://'.$hostname.$url;
4165: } else {
4166: $link = $url;
4167: }
4168: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4169: if ($nomodal) {
4170: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4171: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4172: } else {
4173: $line.=&Apache::loncommon::modal_link($link,
4174: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4175: }
1.469 www 4176: } else {
4177: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4178: }
1.484.2.19 raeburn 4179: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4180: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4181: $line.='<a href="'.$url.'">'.$title.'</a>';
4182: } elsif ($url) {
1.484.2.70 raeburn 4183: if ($nomodal) {
4184: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4185: $title.'</a>';
4186: } else {
4187: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4188: }
1.484.2.67 raeburn 4189: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4190: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4191: } else {
4192: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4193: }
1.484.2.19 raeburn 4194: $line.="$extresform</td>";
1.478 raeburn 4195: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4196: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4197: if (($allowed) && ($folder!~/^supplemental/)) {
4198: my %lt=&Apache::lonlocal::texthash(
4199: 'hd' => 'Hidden',
4200: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4201: my ($enctext,$hidtext);
4202: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4203: $enctext = ' checked="checked"';
4204: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4205: push(@{$filtersref->{'encrypturl'}},$orderidx);
4206: }
4207: }
4208: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4209: $hidtext = ' checked="checked"';
4210: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4211: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4212: }
4213: }
1.484.2.29 raeburn 4214: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4215: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4216: $line.=(<<ENDPARMS);
4217: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4218: <form action="/adm/coursedocs" method="post" name="$formhidden">
4219: $form_param
1.478 raeburn 4220: $form_common
1.484.2.67 raeburn 4221: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4222: $form_end
1.458 raeburn 4223: <br />
1.484.2.29 raeburn 4224: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4225: $form_param
1.478 raeburn 4226: $form_common
1.484.2.67 raeburn 4227: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4228: $form_end
4229: </td>
1.478 raeburn 4230: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4231: $rand_order_text</td>
1.329 droeschl 4232: ENDPARMS
4233: }
1.379 bisitz 4234: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4235: return $line;
4236: }
4237:
1.484.2.30 raeburn 4238: sub action_restrictions {
4239: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4240: my %denied = (
4241: cut => 0,
4242: copy => 0,
4243: remove => 0,
4244: );
4245: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4246: # no copy for published maps
4247: $denied{'copy'} = 1;
1.484.2.82 raeburn 4248: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4249: unless ($1 eq 'simpleproblem') {
4250: $denied{'copy'} = 1;
4251: }
4252: $denied{'cut'} = 1;
1.484.2.30 raeburn 4253: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4254: if ($folderpath =~ /^default&[^\&]+$/) {
4255: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4256: $denied{'remove'} = 1;
4257: }
4258: $denied{'cut'} = 1;
4259: $denied{'copy'} = 1;
4260: }
4261: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4262: my $group = $1;
4263: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4264: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4265: $denied{'remove'} = 1;
4266: }
4267: }
4268: $denied{'cut'} = 1;
4269: $denied{'copy'} = 1;
4270: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4271: my $group = $1;
4272: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4273: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4274: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4275: if (keys(%groupsettings) > 0) {
4276: $denied{'remove'} = 1;
4277: }
4278: $denied{'cut'} = 1;
4279: $denied{'copy'} = 1;
4280: }
4281: }
4282: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4283: my $group = $1;
4284: if ($url =~ /group_boards_\Q$group\E/) {
4285: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4286: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4287: if (keys(%groupsettings) > 0) {
4288: if (ref($groupsettings{'functions'}) eq 'HASH') {
4289: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4290: $denied{'remove'} = 1;
4291: }
4292: }
4293: }
4294: $denied{'cut'} = 1;
4295: $denied{'copy'} = 1;
4296: }
4297: }
4298: }
4299: return %denied;
4300: }
4301:
1.484.2.26 raeburn 4302: sub new_timebased_suffix {
1.484.2.30 raeburn 4303: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4304: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4305: if ($type eq 'paste') {
4306: $prefix = $type;
4307: $namespace = 'courseeditor';
1.484.2.56 raeburn 4308: $idtype = 'addcode';
1.484.2.30 raeburn 4309: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4310: $prefix = 'docs';
4311: if ($area eq 'supplemental') {
4312: $prefix = 'supp';
4313: }
4314: $prefix .= $container;
4315: $namespace = 'uploadedmaps';
4316: } else {
4317: $prefix = $type;
4318: $namespace = 'templated';
1.484.2.15 raeburn 4319: }
4320: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4321: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4322: if (!$suffix) {
1.484.2.30 raeburn 4323: if ($type eq 'paste') {
4324: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4325: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4326: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4327: } elsif ($type eq 'smppg') {
4328: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4329: } else {
1.484.2.42 raeburn 4330: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4331: }
1.484.2.15 raeburn 4332: if ($error) {
4333: $errtext .= '<br />'.$error;
4334: }
4335: }
4336: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4337: $locknotfreed =
4338: '<div class="LC_error">'.
4339: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4340: if ($type eq 'paste') {
1.484.2.57 raeburn 4341: if ($freedlock eq 'nolock') {
4342: $locknotfreed =
4343: '<div class="LC_error">'.
4344: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4345:
1.484.2.60 raeburn 4346: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4347: } else {
4348: $locknotfreed .=
4349: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4350: }
1.484.2.30 raeburn 4351: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4352: $locknotfreed .=
4353: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4354: } elsif ($type eq 'smppg') {
4355: $locknotfreed .=
4356: &mt('This will prevent creation of additional simple pages in this course.');
4357: } else {
4358: $locknotfreed .=
1.484.2.42 raeburn 4359: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4360: }
1.484.2.30 raeburn 4361: unless ($type eq 'paste') {
4362: $locknotfreed .=
1.484.2.38 raeburn 4363: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4364: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4365: }
4366: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4367: }
4368: return ($suffix,$errtext,$locknotfreed);
4369: }
4370:
1.329 droeschl 4371: =pod
4372:
4373: =item tiehash()
4374:
4375: tie the hash
4376:
4377: =cut
4378:
4379: sub tiehash {
4380: my ($mode)=@_;
4381: $hashtied=0;
4382: if ($env{'request.course.fn'}) {
4383: if ($mode eq 'write') {
4384: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4385: &GDBM_WRCREAT(),0640)) {
4386: $hashtied=2;
4387: }
4388: } else {
4389: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4390: &GDBM_READER(),0640)) {
4391: $hashtied=1;
4392: }
4393: }
1.364 bisitz 4394: }
1.329 droeschl 4395: }
4396:
4397: sub untiehash {
4398: if ($hashtied) { untie %hash; }
4399: $hashtied=0;
4400: return OK;
4401: }
4402:
4403:
4404:
4405:
4406: sub checkonthis {
1.484.2.78 raeburn 4407: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4408: $url=&unescape($url);
4409: $alreadyseen{$url}=1;
4410: $r->rflush();
4411: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4412: $r->print("\n<br />");
4413: if ($level==0) {
4414: $r->print("<br />");
4415: }
4416: for (my $i=0;$i<=$level*5;$i++) {
4417: $r->print(' ');
4418: }
4419: $r->print('<a href="'.$url.'" target="cat">'.
4420: ($title?$title:$url).'</a> ');
4421: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4422: my $updated;
4423: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4424: ($url !~ /\.\d+\.\w+$/)) {
4425: $updated = &Apache::lonnet::remove_stale_resfile($url);
4426: }
1.329 droeschl 4427: my $result=&Apache::lonnet::repcopy(
4428: &Apache::lonnet::filelocation('',$url));
4429: if ($result eq 'ok') {
4430: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4431: if ($updated) {
4432: $r->print('<br />');
4433: for (my $i=0;$i<=$level*5;$i++) {
4434: $r->print(' ');
4435: }
4436: $r->print('- '.&mt('Outdated copy removed'));
4437: }
1.329 droeschl 4438: $r->rflush();
4439: &Apache::lonnet::countacc($url);
4440: $url=~/\.(\w+)$/;
4441: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4442: $r->print('<br />');
4443: $r->rflush();
4444: for (my $i=0;$i<=$level*5;$i++) {
4445: $r->print(' ');
4446: }
4447: $r->print('- '.&mt('Rendering:').' ');
4448: my ($errorcount,$warningcount)=split(/:/,
4449: &Apache::lonnet::ssi_body($url,
4450: ('grade_target'=>'web',
4451: 'return_only_error_and_warning_counts' => 1)));
4452: if (($errorcount) ||
4453: ($warningcount)) {
4454: if ($errorcount) {
1.369 bisitz 4455: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4456: &mt('[quant,_1,error]',$errorcount).'</span>');
4457: }
4458: if ($warningcount) {
4459: $r->print('<span class="LC_warning">'.
4460: &mt('[quant,_1,warning]',$warningcount).'</span>');
4461: }
4462: } else {
4463: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4464: }
4465: $r->rflush();
4466: }
4467: my $dependencies=
4468: &Apache::lonnet::metadata($url,'dependencies');
4469: foreach my $dep (split(/\,/,$dependencies)) {
4470: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4471: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4472: }
4473: }
4474: } elsif ($result eq 'unavailable') {
4475: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4476: } elsif ($result eq 'not_found') {
4477: unless ($url=~/\$/) {
1.484.2.19 raeburn 4478: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4479: } else {
1.366 bisitz 4480: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4481: }
4482: } else {
4483: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4484: }
1.484.2.78 raeburn 4485: if (($updated) && ($result ne 'ok')) {
4486: $r->print('<br />'.&mt('Outdated copy removed'));
4487: }
1.329 droeschl 4488: }
4489: }
4490: }
4491:
4492:
4493:
4494: =pod
4495:
4496: =item list_symbs()
4497:
1.484.2.3 raeburn 4498: List Content Identifiers
1.329 droeschl 4499:
4500: =cut
4501:
4502: sub list_symbs {
4503: my ($r) = @_;
4504:
1.408 raeburn 4505: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4506: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4507: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4508: $r->print(&startContentScreen('tools'));
1.329 droeschl 4509: my $navmap = Apache::lonnavmaps::navmap->new();
4510: if (!defined($navmap)) {
4511: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4512: '<div class="LC_error">'.
4513: &mt('Unable to retrieve information about course contents').
4514: '</div>');
1.408 raeburn 4515: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4516: } else {
1.484 raeburn 4517: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4518: &Apache::loncommon::start_data_table().
4519: &Apache::loncommon::start_data_table_header_row().
4520: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4521: &Apache::loncommon::end_data_table_header_row()."\n");
4522: my $count;
1.329 droeschl 4523: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4524: $r->print(&Apache::loncommon::start_data_table_row().
4525: '<td>'.$res->compTitle().'</td>'.
4526: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4527: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4528: $count ++;
4529: }
4530: if (!$count) {
4531: $r->print(&Apache::loncommon::start_data_table_row().
4532: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4533: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4534: }
1.484 raeburn 4535: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4536: }
1.484.2.19 raeburn 4537: $r->print(&endContentScreen());
1.329 droeschl 4538: }
4539:
1.484.2.78 raeburn 4540: sub contentverifyform {
4541: my ($r) = @_;
4542: my $crstype = &Apache::loncommon::course_type();
4543: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4544: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4545: $r->print(&startContentScreen('tools'));
4546: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4547: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4548: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4549: ' <span class="LC_nobreak">'.
4550: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4551: &mt('No').'</label>'.(' 'x2).
4552: '<label><input type="radio" name="checkstale" value="1" />'.
4553: &mt('Yes').'</label></span></p><p>'.
1.484.2.90 raeburn 4554: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
1.484.2.78 raeburn 4555: '<input type="hidden" value="1" name="tools" />'.
4556: '<input type="hidden" value="1" name="verify" /></p></form>');
4557: $r->print(&endContentScreen());
4558: return;
4559: }
1.329 droeschl 4560:
4561: sub verifycontent {
1.484.2.78 raeburn 4562: my ($r,$checkstale) = @_;
1.408 raeburn 4563: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4564: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4565: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4566: $r->print(&startContentScreen('tools'));
4567: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4568: $hashtied=0;
4569: undef %alreadyseen;
4570: %alreadyseen=();
4571: &tiehash();
1.484 raeburn 4572:
1.329 droeschl 4573: foreach my $key (keys(%hash)) {
4574: if ($hash{$key}=~/\.(page|sequence)$/) {
4575: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4576: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4577: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4578: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4579: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4580: }
4581: }
4582: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4583: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4584: }
4585: }
4586: &untiehash();
1.442 www 4587: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4588: $r->print(&endContentScreen());
1.329 droeschl 4589: }
4590:
4591:
4592: sub devalidateversioncache {
4593: my $src=shift;
4594: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4595: &Apache::lonnet::clutter($src));
4596: }
4597:
4598: sub checkversions {
1.484.2.67 raeburn 4599: my ($r,$canedit) = @_;
1.408 raeburn 4600: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4601: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4602: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4603: $r->print(&startContentScreen('tools'));
1.442 www 4604:
1.329 droeschl 4605: my $header='';
4606: my $startsel='';
4607: my $monthsel='';
4608: my $weeksel='';
4609: my $daysel='';
4610: my $allsel='';
4611: my %changes=();
4612: my $starttime=0;
4613: my $haschanged=0;
4614: my %setversions=&Apache::lonnet::dump('resourceversions',
4615: $env{'course.'.$env{'request.course.id'}.'.domain'},
4616: $env{'course.'.$env{'request.course.id'}.'.num'});
4617:
4618: $hashtied=0;
4619: &tiehash();
1.484.2.67 raeburn 4620: if ($canedit) {
4621: my %newsetversions=();
4622: if ($env{'form.setmostrecent'}) {
4623: $haschanged=1;
4624: foreach my $key (keys(%hash)) {
4625: if ($key=~/^ids\_(\/res\/.+)$/) {
4626: $newsetversions{$1}='mostrecent';
4627: &devalidateversioncache($1);
4628: }
1.329 droeschl 4629: }
1.484.2.67 raeburn 4630: } elsif ($env{'form.setcurrent'}) {
4631: $haschanged=1;
4632: foreach my $key (keys(%hash)) {
4633: if ($key=~/^ids\_(\/res\/.+)$/) {
4634: my $getvers=&Apache::lonnet::getversion($1);
4635: if ($getvers>0) {
4636: $newsetversions{$1}=$getvers;
4637: &devalidateversioncache($1);
4638: }
4639: }
1.329 droeschl 4640: }
1.484.2.67 raeburn 4641: } elsif ($env{'form.setversions'}) {
4642: $haschanged=1;
4643: foreach my $key (keys(%env)) {
4644: if ($key=~/^form\.set_version_(.+)$/) {
4645: my $src=$1;
4646: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4647: $newsetversions{$src}=$env{$key};
4648: &devalidateversioncache($src);
4649: }
4650: }
1.329 droeschl 4651: }
1.484.2.67 raeburn 4652: }
4653: if ($haschanged) {
4654: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4655: $env{'course.'.$env{'request.course.id'}.'.domain'},
4656: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4657: $r->print(&Apache::loncommon::confirmwrapper(
4658: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4659: } else {
4660: $r->print(&Apache::loncommon::confirmwrapper(
4661: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4662: }
4663: &mark_hash_old();
4664: }
4665: &changewarning($r,'');
1.329 droeschl 4666: }
4667: if ($env{'form.timerange'} eq 'all') {
4668: # show all documents
1.484.2.34 raeburn 4669: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4670: $allsel=' selected="selected"';
1.329 droeschl 4671: foreach my $key (keys(%hash)) {
4672: if ($key=~/^ids\_(\/res\/.+)$/) {
4673: my $src=$1;
4674: $changes{$src}=1;
4675: }
4676: }
4677: } else {
4678: # show documents which changed
4679: %changes=&Apache::lonnet::dump
4680: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4681: $env{'course.'.$env{'request.course.id'}.'.num'});
4682: my $firstkey=(keys(%changes))[0];
4683: unless ($firstkey=~/^error\:/) {
4684: unless ($env{'form.timerange'}) {
4685: $env{'form.timerange'}=604800;
4686: }
4687: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4688: .&mt('seconds');
4689: if ($env{'form.timerange'}==-1) {
4690: $seltext='since start of course';
1.484.2.19 raeburn 4691: $startsel=' selected="selected"';
1.329 droeschl 4692: $env{'form.timerange'}=time;
4693: }
4694: $starttime=time-$env{'form.timerange'};
4695: if ($env{'form.timerange'}==2592000) {
4696: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4697: $monthsel=' selected="selected"';
1.329 droeschl 4698: } elsif ($env{'form.timerange'}==604800) {
4699: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4700: $weeksel=' selected="selected"';
1.329 droeschl 4701: } elsif ($env{'form.timerange'}==86400) {
4702: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4703: $daysel=' selected="selected"';
1.329 droeschl 4704: }
4705: $header=&mt('Content changed').' '.$seltext;
4706: } else {
4707: $header=&mt('No content modifications yet.');
4708: }
4709: }
4710: %setversions=&Apache::lonnet::dump('resourceversions',
4711: $env{'course.'.$env{'request.course.id'}.'.domain'},
4712: $env{'course.'.$env{'request.course.id'}.'.num'});
4713: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4714: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4715: 'lm' => 'Version changes since last Month',
4716: 'lw' => 'Version changes since last Week',
4717: 'sy' => 'Version changes since Yesterday',
4718: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4719: 'cd' => 'Change display',
1.329 droeschl 4720: 'sd' => 'Display',
4721: 'fi' => 'File',
4722: 'md' => 'Modification Date',
4723: 'mr' => 'Most recently published Version',
1.408 raeburn 4724: 've' => 'Version used in '.$crstype,
4725: 'vu' => 'Set Version to be used in '.$crstype,
4726: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4727: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4728: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4729: 'di' => 'Differences',
1.484 raeburn 4730: 'save' => 'Save changes',
4731: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4732: 'act' => 'Actions');
1.484.2.67 raeburn 4733: my ($disabled,$readonly);
4734: unless ($canedit) {
4735: $disabled = 'disabled="disabled"';
4736: $readonly = 1;
4737: }
1.329 droeschl 4738: $r->print(<<ENDHEADERS);
1.484 raeburn 4739: <h4 class="LC_info">$header</h4>
1.329 droeschl 4740: <form action="/adm/coursedocs" method="post">
4741: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4742: <div class="LC_left_float">
1.479 golterma 4743: <fieldset>
1.484 raeburn 4744: <legend>$lt{'cd'}</legend>
1.329 droeschl 4745: <select name="timerange">
1.484.2.19 raeburn 4746: <option value='all'$allsel>$lt{'al'}</option>
4747: <option value="-1"$startsel>$lt{'st'}</option>
4748: <option value="2592000"$monthsel>$lt{'lm'}</option>
4749: <option value="604800"$weeksel>$lt{'lw'}</option>
4750: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4751: </select>
4752: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4753: </fieldset>
4754: </div>
4755: <div class="LC_left_float">
4756: <fieldset>
4757: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4758: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4759: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4760: </fieldset>
4761: </div>
4762: <br clear="all" />
4763: <hr />
4764: <h4>$lt{'vers'}</h4>
1.329 droeschl 4765: ENDHEADERS
1.479 golterma 4766: #number of columns for version history
1.484.2.44 raeburn 4767: my %changedbytime;
4768: foreach my $key (keys(%changes)) {
4769: #excludes not versionable problems from resource version history:
4770: next if ($key =~ /^\/res\/lib\/templates/);
4771: my $chg;
4772: if ($env{'form.timerange'} eq 'all') {
4773: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4774: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4775: } else {
4776: $chg = $changes{$key};
4777: next if ($chg < $starttime);
4778: }
4779: push(@{$changedbytime{$chg}},$key);
4780: }
4781: if (keys(%changedbytime) == 0) {
4782: &untiehash();
4783: $r->print(&mt('No content changes in imported content in specified time frame').
4784: &endContentScreen());
4785: return;
4786: }
1.479 golterma 4787: $r->print(
1.484.2.67 raeburn 4788: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4789: &Apache::loncommon::start_data_table().
4790: &Apache::loncommon::start_data_table_header_row().
4791: '<th>'.&mt('Resources').'</th>'.
4792: "<th>$lt{'mr'}</th>".
4793: "<th>$lt{'ve'}</th>".
4794: "<th>$lt{'vu'}</th>".
4795: '<th>'.&mt('History').'</th>'.
4796: &Apache::loncommon::end_data_table_header_row()
4797: );
1.484.2.44 raeburn 4798: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4799: foreach my $key (sort(@{$changedbytime{$chg}})) {
4800: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4801: my $currentversion=&Apache::lonnet::getversion($key);
4802: if ($currentversion<0) {
4803: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4804: }
4805: my $linkurl=&Apache::lonnet::clutter($key);
4806: $r->print(
4807: &Apache::loncommon::start_data_table_row().
4808: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4809: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4810: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4811: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4812: '<td align="right">'
4813: );
4814: # Used in course
4815: my $usedversion=$hash{'version_'.$linkurl};
4816: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4817: if ($usedversion != $currentversion) {
1.479 golterma 4818: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4819: } else {
1.479 golterma 4820: $r->print($usedversion);
4821: }
1.329 droeschl 4822: } else {
1.484.2.19 raeburn 4823: $r->print($currentversion);
1.329 droeschl 4824: }
1.484.2.44 raeburn 4825: $r->print('</td><td title="'.$lt{'vu'}.'">');
4826: # Set version
4827: $r->print(&Apache::loncommon::select_form(
4828: $setversions{$linkurl},
4829: 'set_version_'.$linkurl,
4830: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4831: '' => '',
4832: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4833: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4834: my $lastold=1;
4835: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4836: my $url=$root.'.'.$prevvers.'.'.$extension;
4837: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4838: $lastold=$prevvers;
4839: }
4840: }
4841: $r->print('</td>');
4842: # List all available versions
4843: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4844: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4845: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4846: $r->print(
1.484.2.44 raeburn 4847: '<span class="LC_nobreak">'
4848: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4849: .&mt('Version [_1]',$prevvers).'</a>'
4850: .' ('.&Apache::lonlocal::locallocaltime(
4851: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4852: .')');
4853: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4854: $r->print(
4855: ' <a href="/adm/diff?filename='.
4856: &Apache::lonnet::clutter($root.'.'.$extension).
4857: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4858: '" target="diffs">'.&mt('Diffs').'</a>');
4859: }
4860: $r->print('</span><br />');
1.329 droeschl 4861: }
1.484.2.44 raeburn 4862: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4863: }
1.329 droeschl 4864: }
1.484.2.19 raeburn 4865: $r->print(
4866: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4867: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4868: '</form>'
4869: );
1.329 droeschl 4870:
4871: &untiehash();
1.484.2.19 raeburn 4872: $r->print(&endContentScreen());
1.484.2.44 raeburn 4873: return;
1.329 droeschl 4874: }
4875:
4876: sub mark_hash_old {
4877: my $retie_hash=0;
4878: if ($hashtied) {
4879: $retie_hash=1;
4880: &untiehash();
4881: }
4882: &tiehash('write');
4883: $hash{'old'}=1;
4884: &untiehash();
4885: if ($retie_hash) { &tiehash(); }
4886: }
4887:
4888: sub is_hash_old {
4889: my $untie_hash=0;
4890: if (!$hashtied) {
4891: $untie_hash=1;
4892: &tiehash();
4893: }
4894: my $return=$hash{'old'};
4895: if ($untie_hash) { &untiehash(); }
4896: return $return;
4897: }
4898:
4899: sub changewarning {
4900: my ($r,$postexec,$message,$url)=@_;
4901: if (!&is_hash_old()) { return; }
4902: my $pathvar='folderpath';
4903: my $path=&escape($env{'form.folderpath'});
4904: if (!defined($url)) {
4905: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4906: }
4907: my $course_type = &Apache::loncommon::course_type();
4908: if (!defined($message)) {
4909: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4910: }
4911: $r->print("\n\n".
1.372 bisitz 4912: '<script type="text/javascript">'."\n".
4913: '// <![CDATA['."\n".
4914: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4915: '// ]]>'."\n".
1.369 bisitz 4916: '</script>'."\n".
1.375 tempelho 4917: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4918: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4919: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4920: &mt($message,' <input type="hidden" name="'.
4921: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4922: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4923: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4924: }
4925:
4926:
4927: sub init_breadcrumbs {
1.484.2.44 raeburn 4928: my ($form,$text,$help)=@_;
1.329 droeschl 4929: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4930: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4931: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4932: faq=>273,
4933: bug=>'Instructor Interface',
1.484.2.44 raeburn 4934: help => $help});
1.329 droeschl 4935: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4936: text=>$text,
4937: faq=>273,
4938: bug=>'Instructor Interface'});
4939: }
4940:
1.441 www 4941: # subroutine to list form elements
4942: sub create_list_elements {
4943: my @formarr = @_;
4944: my $list = '';
1.484.2.12 raeburn 4945: foreach my $button (@formarr){
4946: foreach my $picture (keys(%{$button})) {
4947: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4948: }
4949: }
4950: return $list;
4951: }
1.329 droeschl 4952:
1.441 www 4953: # subroutine to create ul from list elements
4954: sub create_form_ul {
4955: my $list = shift;
4956: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4957: return $ul;
4958: }
1.329 droeschl 4959:
1.442 www 4960: #
4961: # Start tabs
4962: #
4963:
4964: sub startContentScreen {
1.484 raeburn 4965: my ($mode) = @_;
4966: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4967: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4968: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4969: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4970: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4971: } else {
1.484.2.34 raeburn 4972: $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 4973: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4974: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4975: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4976: }
4977: $output .= "\n".'</ul>'."\n";
4978: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4979: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4980: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4981: return $output;
1.442 www 4982: }
4983:
4984: #
4985: # End tabs
4986: #
4987:
4988: sub endContentScreen {
1.484 raeburn 4989: return '</div></div></div>';
1.442 www 4990: }
1.329 droeschl 4991:
1.446 www 4992: sub supplemental_base {
1.484.2.33 raeburn 4993: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4994: }
4995:
1.329 droeschl 4996: sub handler {
4997: my $r = shift;
4998: &Apache::loncommon::content_type($r,'text/html');
4999: $r->send_http_header;
5000: return OK if $r->header_only;
1.484 raeburn 5001:
5002: # get course data
1.408 raeburn 5003: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5004: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5005: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5006:
5007: # graphics settings
5008: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5009:
1.443 www 5010: #
1.329 droeschl 5011: # --------------------------------------------- Initialize help topics for this
5012: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5013: 'Adding_External_Resource','Navigate_Content',
5014: 'Adding_Folders','Docs_Overview', 'Load_Map',
5015: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 5016: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 5017: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
5018: 'Dropbox','Simple_Problem') {
1.329 droeschl 5019: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5020: }
5021: # Composite help files
5022: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5023: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5024: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5025: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5026: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5027: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5028: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5029: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5030: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5031: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5032:
1.484.2.67 raeburn 5033: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5034: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5035: unless ($r->uri eq '/adm/supplemental') {
5036: # does this user have privileges to modify content.
1.484.2.67 raeburn 5037: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5038: $allowed = 1;
5039: $canedit = 1;
5040: $canview = 1;
5041: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5042: $allowed = 1;
5043: $canview = 1;
5044: }
5045: }
5046: unless ($canedit) {
5047: $disabled = ' disabled="disabled"';
1.472 raeburn 5048: }
1.484.2.53 raeburn 5049: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5050: if ($env{'form.inhibitmenu'}) {
5051: unless ($env{'form.inhibitmenu'} eq 'yes') {
5052: delete($env{'form.inhibitmenu'});
5053: }
5054: }
5055:
1.484.2.53 raeburn 5056: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5057: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5058: if (!$canedit) {
5059: &verifycontent($r);
5060: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5061: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5062: text=>'Results',
5063: faq=>273,
5064: bug=>'Instructor Interface'});
5065: &verifycontent($r,$env{'form.checkstale'});
5066: } else {
5067: &contentverifyform($r);
5068: }
1.329 droeschl 5069: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5070: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5071: &list_symbs($r);
5072: } elsif ($allowed && $env{'form.docslog'}) {
5073: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5074: my $folder = $env{'form.folder'};
5075: if ($folder eq '') {
5076: $folder='default';
5077: }
1.484.2.67 raeburn 5078: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5079: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5080: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5081: &checkversions($r,$canedit);
5082: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5083: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5084: &dumpcourse($r);
5085: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5086: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5087: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5088: } else {
1.445 www 5089: #
5090: # Done catching special calls
1.484 raeburn 5091: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5092: # Get the parameters that may be needed
5093: #
5094: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5095: ['folderpath',
5096: 'forcesupplement','forcestandard',
5097: 'tools','symb','command','supppath']);
1.445 www 5098:
1.484.2.78 raeburn 5099: foreach my $item ('forcesupplement','forcestandard','tools') {
5100: next if ($env{'form.'.$item} eq '');
5101: unless ($env{'form.'.$item} eq '1') {
5102: delete($env{'form.'.$item});
5103: }
5104: }
5105:
5106: if ($env{'form.command'}) {
5107: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5108: delete($env{'form.command'});
5109: }
5110: }
5111:
5112: if ($env{'form.symb'}) {
5113: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5114: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5115: delete($env{'form.symb'});
5116: }
5117: }
5118:
1.445 www 5119: # standard=1: this is a "new-style" course with an uploaded map as top level
5120: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5121:
5122: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5123:
1.484 raeburn 5124: # Decide whether this should display supplemental or main content or utilities
1.445 www 5125: # supplementalflag=1: show supplemental documents
5126: # supplementalflag=0: show standard documents
1.484 raeburn 5127: # toolsflag=1: show utilities
1.445 www 5128:
1.484.2.39 raeburn 5129: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5130: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5131: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5132: $supplementalflag=0;
5133: }
5134: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5135: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5136: unless ($allowed) { $supplementalflag=1; }
5137: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5138: my $toolsflag=0;
5139: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5140:
1.484.2.78 raeburn 5141: if ($env{'form.folderpath'} ne '') {
5142: my @items = split(/\&/,$env{'form.folderpath'});
5143: my $badpath;
5144: for (my $i=0; $i<@items; $i++) {
5145: my $odd = $i%2;
5146: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5147: $badpath = 1;
5148: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5149: $badpath = 1;
5150: }
5151: last if ($badpath);
5152: }
5153: if ($badpath) {
5154: delete($env{'form.folderpath'});
5155: }
5156: }
5157:
5158: if ($env{'form.supppath'} ne '') {
5159: my @items = split(/\&/,$env{'form.supppath'});
5160: my $badpath;
5161: for (my $i=0; $i<@items; $i++) {
5162: my $odd = $i%2;
5163: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5164: $badpath = 1;
5165: }
5166: last if ($badpath);
5167: }
5168: if ($badpath) {
5169: delete($env{'form.supppath'});
5170: }
5171: }
5172:
1.329 droeschl 5173: my $script='';
5174: my $showdoc=0;
1.457 raeburn 5175: my $addentries = {};
1.475 raeburn 5176: my $container;
1.329 droeschl 5177: my $containertag;
1.484.2.17 raeburn 5178: my $pathitem;
1.484.2.67 raeburn 5179: my $hiddentop;
5180: my $navmap;
5181: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5182:
1.464 www 5183: # Do we directly jump somewhere?
1.484.2.21 raeburn 5184: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5185: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5186: $env{'form.folderpath'}=
1.484.2.67 raeburn 5187: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5188: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5189: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5190: } elsif ($env{'form.supppath'} ne '') {
5191: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5192: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5193: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5194: }
1.472 raeburn 5195: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5196: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5197: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5198: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5199: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5200: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5201: } elsif ($env{'form.command'} eq 'contents') {
5202: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5203: } elsif ($env{'form.command'} eq 'home') {
5204: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5205: }
5206:
1.484.2.23 raeburn 5207:
1.445 www 5208: # Where do we store these for when we come back?
5209: my $stored_folderpath='docs_folderpath';
5210: if ($supplementalflag) {
5211: $stored_folderpath='docs_sup_folderpath';
5212: }
1.464 www 5213:
1.484.2.19 raeburn 5214: # No folderpath, and in edit mode, see if we have something stored
5215: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5216: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5217: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5218:
5219: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5220: if ($supplementalflag) {
5221: undef($env{'form.folderpath'}) if ($1 eq 'default');
5222: } else {
5223: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5224: }
5225: } else {
1.484.2.19 raeburn 5226: undef($env{'form.folderpath'});
5227: }
1.329 droeschl 5228: }
1.446 www 5229:
5230: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5231: if (!$allowed) {
1.446 www 5232: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5233: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5234: }
5235: }
1.446 www 5236: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5237: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5238: $env{'form.folderpath'} = &supplemental_base()
5239: .'&'.
1.329 droeschl 5240: $env{'form.folderpath'};
5241: }
1.484.2.67 raeburn 5242: # If allowed and user's role is not advanced check folderpath is not hidden
5243: if (($allowed) && (!$env{'request.role.adv'}) &&
5244: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5245: my $folderurl;
5246: my @pathitems = split(/\&/,$env{'form.folderpath'});
5247: my $folder = $pathitems[-2];
5248: if ($folder eq '') {
5249: undef($env{'form.folderpath'});
5250: } else {
5251: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87 raeburn 5252: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5253: $folderurl .= '.page';
5254: } else {
5255: $folderurl .= '.sequence';
5256: }
5257: unless (ref($navmap)) {
5258: $navmap = Apache::lonnavmaps::navmap->new();
5259: }
5260: if (ref($navmap)) {
5261: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5262: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5263: unless (@resources) {
5264: undef($env{'form.folderpath'});
5265: }
5266: }
5267: }
5268: }
5269: }
5270:
5271:
1.446 www 5272: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5273: unless ($env{'form.folderpath'}) {
1.446 www 5274: if ($supplementalflag) {
5275: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5276: } elsif ($allowed) {
5277: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5278: }
1.472 raeburn 5279: }
1.446 www 5280:
1.445 www 5281: # Store this
1.484 raeburn 5282: unless ($toolsflag) {
1.484.2.67 raeburn 5283: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5284: &Apache::loncommon::store_course_settings($stored_folderpath,
5285: {'folderpath' => 'scalar'});
5286: }
5287: my $folderpath;
1.484 raeburn 5288: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5289: $folderpath = $env{'form.folderpath'};
5290: my (@folders)=split('&',$env{'form.folderpath'});
5291: $env{'form.foldername'}=&unescape(pop(@folders));
5292: if ($env{'form.foldername'} =~ /\:1$/) {
5293: $container = 'page';
5294: } else {
5295: $container = 'sequence';
5296: }
5297: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5298: } else {
1.484.2.19 raeburn 5299: if ($env{'form.folder'} eq '' ||
5300: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5301: if ($env{'form.folder'} eq 'supplemental') {
5302: $folderpath=&supplemental_base();
5303: } elsif (!$hiddentop) {
5304: $folderpath='default&'.
5305: &escape(&mt('Main Content').':::::');
5306: }
1.484 raeburn 5307: }
5308: }
1.484.2.19 raeburn 5309: $containertag = '<input type="hidden" name="folderpath" value="" />';
5310: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5311: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5312: $showdoc='/'.$1;
5313: }
5314: if ($showdoc) { # got called in sequence from course
5315: $allowed=0;
5316: } else {
1.484.2.67 raeburn 5317: if ($canedit) {
1.484 raeburn 5318: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5319: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5320: }
5321: }
1.329 droeschl 5322: }
5323:
1.344 bisitz 5324: # get personal data
1.329 droeschl 5325: my $uname=$env{'user.name'};
5326: my $udom=$env{'user.domain'};
5327: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5328:
5329: if ($allowed) {
1.484 raeburn 5330: if ($toolsflag) {
5331: $script .= &inject_data_js();
5332: my ($home,$other,%outhash)=&authorhosts();
5333: if (!$home && $other) {
5334: my @hosts;
5335: foreach my $aurole (keys(%outhash)) {
5336: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5337: push(@hosts,$outhash{$aurole});
5338: }
5339: }
5340: $script .= &dump_switchserver_js(@hosts);
5341: }
1.458 raeburn 5342: } else {
1.484.2.43 raeburn 5343: my $tid = 1;
1.484 raeburn 5344: my @tabids;
5345: if ($supplementalflag) {
5346: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5347: $tid = 2;
1.484 raeburn 5348: } else {
5349: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5350: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5351: unshift(@tabids,'001');
5352: push(@tabids,('dd1','ee1'));
5353: }
1.458 raeburn 5354: }
1.484 raeburn 5355: my $tabidstr = join("','",@tabids);
1.484.2.80 raeburn 5356: my $hostname = $r->hostname();
1.484.2.68 raeburn 5357: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.80 raeburn 5358: $canedit,$hostname,\$navmap).
1.484 raeburn 5359: &history_tab_js().
5360: &inject_data_js().
1.484.2.43 raeburn 5361: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5362: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5363: $addentries = {
1.484.2.3 raeburn 5364: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5365: };
1.458 raeburn 5366: }
1.484.2.30 raeburn 5367: $script .= &paste_popup_js();
1.484.2.12 raeburn 5368: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5369: &mt('Switch server?');
1.484.2.19 raeburn 5370:
5371:
1.329 droeschl 5372: }
5373: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5374: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5375: .'// <![CDATA['."\n"
5376: .$script."\n"
5377: .'// ]]>'."\n"
1.484.2.81 raeburn 5378: .'</script>'."\n"
5379: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5380:
5381: # Breadcrumbs
5382: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5383:
5384: if ($showdoc) {
5385: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5386: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5387: } elsif ($toolsflag) {
1.484.2.67 raeburn 5388: my ($breadtext,$breadtitle);
5389: $breadtext = "$crstype Editor";
5390: if ($canedit) {
5391: $breadtitle = 'Editing '.$crstype.' Contents';
5392: } else {
5393: $breadtext .= ' (View-only mode)';
5394: $breadtitle = 'Viewing '.$crstype.' Contents';
5395: }
1.484.2.44 raeburn 5396: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5397: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5398: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5399: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5400: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5401: $breadtitle)
1.484.2.44 raeburn 5402: );
1.484.2.19 raeburn 5403: } elsif ($r->uri eq '/adm/supplemental') {
5404: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5405: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5406: {'bread_crumbs' => $brcrum,}));
5407: } else {
1.484.2.67 raeburn 5408: my ($breadtext,$breadtitle,$helpitem);
5409: $breadtext = "$crstype Editor";
5410: if ($canedit) {
5411: $breadtitle = 'Editing '.$crstype.' Contents';
5412: $helpitem = 'Docs_Adding_Course_Doc';
5413: } else {
5414: $breadtext .= ' (View-only mode)';
5415: $breadtitle = 'Viewing '.$crstype.' Contents';
5416: $helpitem = 'Docs_Viewing_Course_Doc';
5417: }
1.392 raeburn 5418: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5419: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5420: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5421: {'add_entries' => $addentries}
5422: )
1.392 raeburn 5423: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5424: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5425: $breadtitle,
5426: $helpitem)
1.392 raeburn 5427: );
5428: }
1.364 bisitz 5429:
1.329 droeschl 5430: my %allfiles = ();
5431: my %codebase = ();
1.440 raeburn 5432: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5433: if ($canedit) {
1.329 droeschl 5434: if (($env{'form.uploaddoc.filename'}) &&
5435: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5436: my $context = $1;
5437: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5438: undef($hadchanges);
1.440 raeburn 5439: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5440: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5441: undef($navmap);
1.329 droeschl 5442: if ($hadchanges) {
5443: &mark_hash_old();
5444: }
1.440 raeburn 5445: $r->print($upload_output);
5446: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5447: # Process file upload - phase two - upload embedded objects
5448: $uploadphase = 'check_embedded';
5449: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5450: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5451: $env{'form.newidx'});
5452: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5453: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5454: my ($destination,$dir_root) = &embedded_destination();
5455: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5456: my $actionurl = '/adm/coursedocs';
5457: my ($result,$flag) =
5458: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5459: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5460: $actionurl);
5461: $r->print($result.&return_to_editor());
5462: } elsif ($env{'form.phase'} eq 'check_embedded') {
5463: # Process file upload - phase three - modify references in HTML file
5464: $uploadphase = 'modified_orightml';
5465: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5466: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5467: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5468: my $result =
5469: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5470: $docuname,$docudom,undef,
5471: $dir_root);
5472: $r->print($result.&return_to_editor());
1.476 raeburn 5473: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5474: $uploadphase = 'decompress_phase_one';
5475: $r->print(&decompression_phase_one().
5476: &return_to_editor());
5477: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5478: $uploadphase = 'decompress_phase_two';
5479: $r->print(&decompression_phase_two().
5480: &return_to_editor());
1.329 droeschl 5481: }
5482: }
5483:
1.484 raeburn 5484: if ($allowed && $toolsflag) {
5485: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5486: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5487: $r->print(&endContentScreen());
5488: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5489: # -----------------------------------------------------------------------------
5490: my %lt=&Apache::lonlocal::texthash(
5491: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5492: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5493: 'upld' => 'Upload Content',
1.329 droeschl 5494: 'srch' => 'Search',
5495: 'impo' => 'Import',
1.484.2.19 raeburn 5496: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5497: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5498: 'selm' => 'Select Map',
5499: 'load' => 'Load Map',
5500: 'newf' => 'New Folder',
5501: 'newp' => 'New Composite Page',
5502: 'syll' => 'Syllabus',
1.425 raeburn 5503: 'navc' => 'Table of Contents',
1.343 biermanm 5504: 'sipa' => 'Simple Course Page',
1.329 droeschl 5505: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5506: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5507: 'drbx' => 'Drop Box',
1.451 www 5508: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5509: 'bull' => 'Discussion Board',
1.347 weissno 5510: 'mypi' => 'My Personal Information Page',
1.353 weissno 5511: 'grpo' => 'Group Portfolio',
1.329 droeschl 5512: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5513: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5514: 'imsf' => 'IMS Upload',
5515: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5516: 'cms' => 'Origin of IMS package',
5517: 'se' => 'Select',
1.484.2.19 raeburn 5518: 'file' => 'File',
1.329 droeschl 5519: 'title' => 'Title',
5520: 'comment' => 'Comment',
1.403 raeburn 5521: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5522: 'bb5' => 'Blackboard 5',
5523: 'bb6' => 'Blackboard 6',
5524: 'angel5' => 'ANGEL 5.5',
5525: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5526: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5527: );
1.329 droeschl 5528: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5529: # Calculate free quota space for a user or course. A javascript function checks
5530: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5531: my $quotatype = 'unofficial';
5532: if ($crstype eq 'Community') {
5533: $quotatype = 'community';
5534: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5535: $quotatype = 'official';
5536: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5537: $quotatype = 'textbook';
5538: }
5539: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5540: 'course',$quotatype); # expressed in MB
5541: my $current_disk_usage = 0;
5542: foreach my $subdir ('docs','supplemental') {
5543: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5544: "userfiles/$subdir",1); # expressed in kB
5545: }
5546: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5547: my $usage = $current_disk_usage/1024; # in MB
5548: my $quota = $disk_quota;
5549: my $percent;
5550: if ($disk_quota == 0) {
5551: $percent = 100.0;
5552: } else {
1.484.2.69 raeburn 5553: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5554: }
5555: $usage = sprintf("%.2f",$usage);
5556: $quota = sprintf("%.2f",$quota);
5557: $percent = sprintf("%.0f",$percent);
5558: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5559: $percent.'%',$quota.' MB').'</p>';
5560:
1.329 droeschl 5561: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5562: $quotainfo
1.329 droeschl 5563: $lt{'file'}:<br />
1.484.2.81 raeburn 5564: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5565: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5566: FIUP
5567:
5568: my $checkbox=(<<CHBO);
5569: <!-- <label>$lt{'parse'}?
5570: <input type="checkbox" name="parserflag" />
5571: </label> -->
5572: <label>
1.484.2.67 raeburn 5573: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5574: </label>
5575: CHBO
1.484.2.12 raeburn 5576: my $imsfolder = $env{'form.folder'};
5577: if ($imsfolder eq '') {
1.484.2.19 raeburn 5578: $imsfolder = 'default';
1.484.2.12 raeburn 5579: }
5580: my $imspform=(<<IMSFORM);
5581: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5582: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5583: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5584: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5585: <legend>$lt{'imsf'}</legend>
5586: $fileupload
5587: <br />
5588: <p>
1.484.2.19 raeburn 5589: $lt{'cms'}:
1.484.2.67 raeburn 5590: <select name="source" $disabled>
1.484.2.12 raeburn 5591: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5592: <option value="bb5">$lt{'bb5'}</option>
5593: <option value="bb6">$lt{'bb6'}</option>
5594: <option value="angel5">$lt{'angel5'}</option>
5595: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5596: </select>
5597: <input type="hidden" name="folder" value="$imsfolder" />
5598: </p>
5599: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5600: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5601: </fieldset>
5602: </form>
5603: IMSFORM
5604:
1.484.2.19 raeburn 5605: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5606: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5607: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5608: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5609: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5610: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5611: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5612: $fileupload
5613: <br />
5614: $lt{'title'}:<br />
1.484.2.67 raeburn 5615: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5616: $pathitem
1.329 droeschl 5617: <input type="hidden" name="cmd" value="upload_default" />
5618: <br />
1.458 raeburn 5619: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5620: $checkbox
5621: </span>
1.484.2.12 raeburn 5622: <br clear="all" />
1.484.2.67 raeburn 5623: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5624: </fieldset>
5625: </form>
1.383 tempelho 5626: FUFORM
1.329 droeschl 5627:
1.484.2.67 raeburn 5628: my $mapimportjs;
5629: if ($canedit) {
5630: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5631: } else {
5632: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5633: }
1.484.2.19 raeburn 5634: my $importpubform=(<<SEDFFORM);
5635: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5636: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5637: <form action="/adm/coursedocs" method="post" name="mapimportform">
5638: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5639: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5640: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5641: $lt{'copm'}<br />
5642: <span class="LC_nobreak">
1.484.2.19 raeburn 5643: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5644: onfocus="this.blur();$mapimportjs" $disabled />
5645: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5646: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5647: </fieldset>
5648: </form>
5649:
1.383 tempelho 5650: SEDFFORM
1.484.2.67 raeburn 5651:
5652: my $fromstoredjs;
5653: if ($canedit) {
5654: $fromstoredjs = 'open_StoredLinks_Import()';
5655: } else {
5656: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5657: }
5658:
1.484.2.19 raeburn 5659: my @importpubforma = (
5660: { '<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 5661: { '<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 5662: { '<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 5663: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5664: );
5665: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5666: my $extresourcesform =
5667: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5668: $help{'Adding_External_Resource'},
5669: undef,undef,$disabled);
1.329 droeschl 5670: if ($allowed) {
1.484.2.7 raeburn 5671: my $folder = $env{'form.folder'};
5672: if ($folder eq '') {
5673: $folder='default';
5674: }
1.484.2.67 raeburn 5675: if ($canedit) {
5676: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5677: if ($output) {
5678: $r->print($output);
5679: }
1.484.2.30 raeburn 5680: }
1.337 ehlerst 5681: $r->print(<<HIDDENFORM);
5682: <form name="renameform" method="post" action="/adm/coursedocs">
5683: <input type="hidden" name="title" />
5684: <input type="hidden" name="cmd" />
5685: <input type="hidden" name="markcopy" />
5686: <input type="hidden" name="copyfolder" />
5687: $containertag
5688: </form>
1.484 raeburn 5689:
1.337 ehlerst 5690: HIDDENFORM
1.484.2.17 raeburn 5691: $r->print(&makesimpleeditform($pathitem)."\n".
5692: &makedocslogform($pathitem."\n".
1.484 raeburn 5693: '<input type="hidden" name="folder" value="'.
5694: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5695: }
1.442 www 5696:
5697: # Generate the tabs
1.484.2.19 raeburn 5698: my ($mode,$needs_end);
1.472 raeburn 5699: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5700: my @folders = split('&',$env{'form.folderpath'});
5701: unless (@folders > 2) {
5702: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5703: $needs_end = 1;
5704: }
1.472 raeburn 5705: } else {
1.484 raeburn 5706: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5707: $needs_end = 1;
1.472 raeburn 5708: }
1.443 www 5709:
1.442 www 5710: #
5711:
5712: my $savefolderpath;
1.484.2.86 raeburn 5713: my $hostname = $r->hostname();
1.442 www 5714:
1.395 raeburn 5715: if ($allowed) {
1.329 droeschl 5716: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5717: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5718: $folder='default';
1.356 tempelho 5719: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5720: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5721: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5722: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5723: }
5724: my $postexec='';
5725: if ($folder eq 'default') {
1.372 bisitz 5726: $r->print('<script type="text/javascript">'."\n"
5727: .'// <![CDATA['."\n"
5728: .'this.window.name="loncapaclient";'."\n"
5729: .'// ]]>'."\n"
5730: .'</script>'."\n"
1.369 bisitz 5731: );
1.329 droeschl 5732: } else {
5733: #$postexec='self.close();';
5734: }
1.484.2.15 raeburn 5735: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5736: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5737: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5738:
5739: my $newnavform=(<<NNFORM);
5740: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5741: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5742: $pathitem
1.329 droeschl 5743: <input type="hidden" name="importdetail"
5744: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5745: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5746: $help{'Navigate_Content'}
5747: </form>
5748: NNFORM
5749: my $newsmppageform=(<<NSPFORM);
5750: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5751: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5752: $pathitem
1.329 droeschl 5753: <input type="hidden" name="importdetail" value="" />
1.423 onken 5754: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5755: $help{'Simple Page'}
1.329 droeschl 5756: </form>
5757: NSPFORM
5758:
5759: my $newsmpproblemform=(<<NSPROBFORM);
5760: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5761: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5762: $pathitem
1.329 droeschl 5763: <input type="hidden" name="importdetail" value="" />
1.423 onken 5764: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5765: $help{'Simple_Problem'}
1.329 droeschl 5766: </form>
5767:
5768: NSPROBFORM
5769:
5770: my $newdropboxform=(<<NDBFORM);
5771: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5772: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5773: $pathitem
1.329 droeschl 5774: <input type="hidden" name="importdetail" value="" />
1.423 onken 5775: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5776: $help{'Dropbox'}
1.344 bisitz 5777: </form>
1.329 droeschl 5778: NDBFORM
5779:
5780: my $newexuploadform=(<<NEXUFORM);
5781: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5782: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5783: $pathitem
1.329 droeschl 5784: <input type="hidden" name="importdetail" value="" />
1.423 onken 5785: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5786: $help{'Score_Upload_Form'}
5787: </form>
5788: NEXUFORM
5789:
5790: my $newbulform=(<<NBFORM);
5791: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5792: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5793: $pathitem
1.329 droeschl 5794: <input type="hidden" name="importdetail" value="" />
1.423 onken 5795: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5796: $help{'Bulletin Board'}
5797: </form>
5798: NBFORM
5799:
5800: my $newaboutmeform=(<<NAMFORM);
5801: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5802: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5803: $pathitem
1.329 droeschl 5804: <input type="hidden" name="importdetail"
5805: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5806: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5807: $help{'My Personal Information Page'}
1.329 droeschl 5808: </form>
5809: NAMFORM
5810:
5811: my $newaboutsomeoneform=(<<NASOFORM);
5812: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5813: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5814: $pathitem
1.329 droeschl 5815: <input type="hidden" name="importdetail" value="" />
1.423 onken 5816: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5817: </form>
5818: NASOFORM
5819:
5820: my $newrosterform=(<<NROSTFORM);
5821: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5822: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5823: $pathitem
1.329 droeschl 5824: <input type="hidden" name="importdetail"
5825: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5826: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5827: $help{'Course_Roster'}
1.329 droeschl 5828: </form>
5829: NROSTFORM
5830:
1.484.2.27 raeburn 5831: my $newwebpage;
5832: if ($folder =~ /^default_?(\d*)$/) {
5833: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5834: if ($1) {
5835: $newwebpage .= $1;
5836: } else {
5837: $newwebpage .= 'default';
5838: }
5839: $newwebpage .= '/new.html';
5840: }
5841: my $newwebpageform =(<<NWEBFORM);
5842: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5843: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5844: $pathitem
5845: <input type="hidden" name="importdetail" value="$newwebpage" />
5846: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5847: $help{'Web_Page'}
1.484.2.27 raeburn 5848: </form>
5849: NWEBFORM
1.484.2.30 raeburn 5850:
1.484.2.27 raeburn 5851:
1.342 ehlerst 5852: my $specialdocumentsform;
1.383 tempelho 5853: my @specialdocumentsforma;
1.451 www 5854: my $gradingform;
5855: my @gradingforma;
5856: my $communityform;
5857: my @communityforma;
1.351 ehlerst 5858: my $newfolderform;
1.390 tempelho 5859: my $newfolderb;
1.342 ehlerst 5860:
1.451 www 5861: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5862:
1.329 droeschl 5863: my $newpageform=(<<NPFORM);
5864: <form action="/adm/coursedocs" method="post" name="newpage">
5865: <input type="hidden" name="folderpath" value="$path" />
5866: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5867: <input type="hidden" name="active" value="ee" />
1.423 onken 5868: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5869: $help{'Adding_Pages'}
1.329 droeschl 5870: </form>
5871: NPFORM
1.390 tempelho 5872:
5873:
1.351 ehlerst 5874: $newfolderform=(<<NFFORM);
1.329 droeschl 5875: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5876: $pathitem
1.329 droeschl 5877: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5878: <input type="hidden" name="active" value="" />
1.422 onken 5879: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5880: </form>
5881: NFFORM
5882:
5883: my $newsylform=(<<NSYLFORM);
5884: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5885: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5886: $pathitem
1.329 droeschl 5887: <input type="hidden" name="importdetail"
5888: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5889: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5890: $help{'Syllabus'}
1.383 tempelho 5891:
1.329 droeschl 5892: </form>
5893: NSYLFORM
1.364 bisitz 5894:
1.329 droeschl 5895: my $newgroupfileform=(<<NGFFORM);
5896: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5897: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5898: $pathitem
1.329 droeschl 5899: <input type="hidden" name="importdetail"
5900: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5901: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5902: $help{'Group Portfolio'}
1.329 droeschl 5903: </form>
5904: NGFFORM
1.484.2.89 raeburn 5905: if ($container eq 'page') {
5906: @specialdocumentsforma=(
5907: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
5908: );
5909: } else {
5910: @specialdocumentsforma=(
1.421 onken 5911: {'<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 5912: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5913: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5914: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5915: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.89 raeburn 5916: );
5917: }
1.451 www 5918: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5919:
1.434 raeburn 5920:
5921: my @importdoc = (
1.484.2.19 raeburn 5922: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5923: );
5924: unless ($container eq 'page') {
5925: push(@importdoc,
5926: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5927: );
5928: }
5929: push(@importdoc,
1.484.2.38 raeburn 5930: {'<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 5931: );
1.484.2.12 raeburn 5932: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5933:
1.451 www 5934: @gradingforma=(
5935: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5936: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5937: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5938:
5939: );
5940: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5941:
5942: @communityforma=(
5943: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5944: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5945: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5946: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5947: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5948: );
5949: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5950:
1.330 tempelho 5951: my %orderhash = (
1.484.2.36 raeburn 5952: 'aa' => ['Upload',$fileuploadform],
5953: 'bb' => ['Import',$importpubform],
5954: 'cc' => ['Grading',$gradingform],
1.484.2.89 raeburn 5955: 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 5956: );
1.484.2.19 raeburn 5957: unless ($container eq 'page') {
1.434 raeburn 5958: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5959: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 5960: }
5961:
1.341 ehlerst 5962: $hadchanges=0;
1.484 raeburn 5963: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5964: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5965: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.85 raeburn 5966: $canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 5967: undef($navmap);
1.443 www 5968: if ($error) {
5969: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5970: }
5971: if ($hadchanges) {
1.484.2.73 raeburn 5972: unless (&is_hash_old()) {
5973: &mark_hash_old();
5974: }
1.443 www 5975: }
1.341 ehlerst 5976:
1.443 www 5977: &changewarning($r,'');
5978: }
1.458 raeburn 5979: }
1.442 www 5980:
1.443 www 5981: # Supplemental documents start here
5982:
1.329 droeschl 5983: my $folder=$env{'form.folder'};
1.443 www 5984: unless ($supplementalflag) {
1.329 droeschl 5985: $folder='supplemental';
5986: }
5987: if ($folder =~ /^supplemental$/ &&
5988: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5989: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5990: } elsif ($allowed) {
1.356 tempelho 5991: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5992: }
1.484.2.17 raeburn 5993: $pathitem = '<input type="hidden" name="folderpath" value="'.
5994: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5995: if ($allowed) {
5996: my $folderseq=
1.484.2.15 raeburn 5997: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5998:
5999: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 6000: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6001: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6002: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6003: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6004: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6005: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6006: $fileupload
6007: <br />
6008: <br />
6009: <span class="LC_nobreak">
6010: $checkbox
6011: </span>
6012: <br /><br />
6013: $lt{'comment'}:<br />
1.383 tempelho 6014: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6015: <br />
1.484.2.19 raeburn 6016: $pathitem
1.329 droeschl 6017: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6018: <input type='submit' value="$lt{'upld'}" />
6019: </form>
1.484.2.19 raeburn 6020: SUPDOCFORM
1.329 droeschl 6021:
6022: my $supnewfolderform=(<<SNFFORM);
6023: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6024: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6025: $pathitem
1.329 droeschl 6026: <input type="hidden" name="importdetail" value="" />
1.423 onken 6027: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6028: $help{'Adding_Folders'}
1.329 droeschl 6029: </form>
6030: SNFFORM
1.383 tempelho 6031:
1.484.2.19 raeburn 6032: my $supextform =
6033: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6034: $help{'Adding_External_Resource'},
6035: undef,undef,$disabled);
1.329 droeschl 6036:
6037: my $supnewsylform=(<<SNSFORM);
6038: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6039: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6040: $pathitem
1.329 droeschl 6041: <input type="hidden" name="importdetail"
6042: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6043: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6044: $help{'Syllabus'}
6045: </form>
6046: SNSFORM
6047:
6048: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6049: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6050: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6051: $pathitem
1.329 droeschl 6052: <input type="hidden" name="importdetail"
6053: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6054: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6055: $help{'My Personal Information Page'}
1.329 droeschl 6056: </form>
6057: SNAMFORM
6058:
1.484.2.27 raeburn 6059: my $supwebpage;
6060: if ($folder =~ /^supplemental_?(\d*)$/) {
6061: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6062: if ($1) {
6063: $supwebpage .= $1;
6064: } else {
6065: $supwebpage .= 'default';
6066: }
6067: $supwebpage .= '/new.html';
6068: }
6069: my $supwebpageform =(<<SWEBFORM);
6070: <form action="/adm/coursedocs" method="post" name="supwebpage">
6071: <input type="hidden" name="active" value="cc" />
6072: $pathitem
6073: <input type="hidden" name="importdetail" value="$supwebpage" />
6074: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6075: $help{'Web_Page'}
1.484.2.27 raeburn 6076: </form>
6077: SWEBFORM
6078:
1.333 muellerd 6079:
1.383 tempelho 6080: my @specialdocs = (
1.484.2.67 raeburn 6081: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6082: =>$supnewsylform},
1.484.2.67 raeburn 6083: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6084: =>$supnewaboutmeform},
1.484.2.27 raeburn 6085: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6086:
1.383 tempelho 6087: );
1.417 droeschl 6088: my @supimportdoc = (
1.484.2.19 raeburn 6089: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 6090: =>$supextform},
6091: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6092: =>$supupdocform},
1.484.2.19 raeburn 6093: );
6094:
1.484.2.12 raeburn 6095: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6096: my %suporderhash = (
1.390 tempelho 6097: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6098: 'ee' => ['Upload',$supupdocform],
6099: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6100: );
1.443 www 6101: if ($supplementalflag) {
1.458 raeburn 6102: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6103: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.85 raeburn 6104: $canedit,$hostname);
1.443 www 6105: if ($error) {
6106: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6107: } else {
6108: if ($suppchanges) {
6109: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6110: my @ids=&Apache::lonnet::current_machine_ids();
6111: foreach my $server (keys(%servers)) {
6112: next if (grep(/^\Q$server\E$/,@ids));
6113: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6114: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6115: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6116: }
6117: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6118: undef($suppchanges);
6119: }
1.443 www 6120: }
1.393 raeburn 6121: }
1.443 www 6122: } elsif ($supplementalflag) {
1.458 raeburn 6123: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6124: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6125: if ($error) {
6126: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6127: }
1.393 raeburn 6128: }
1.389 tempelho 6129:
1.484.2.19 raeburn 6130: if ($needs_end) {
6131: $r->print(&endContentScreen());
6132: }
1.383 tempelho 6133:
1.329 droeschl 6134: if ($allowed) {
6135: $r->print('
6136: <form method="post" name="extimport" action="/adm/coursedocs">
6137: <input type="hidden" name="title" />
6138: <input type="hidden" name="url" />
6139: <input type="hidden" name="useform" />
6140: <input type="hidden" name="residx" />
6141: </form>');
6142: }
1.484 raeburn 6143: } elsif ($showdoc) {
1.329 droeschl 6144: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6145: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6146: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6147: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6148: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6149: }
6150: }
6151: $r->print(&Apache::loncommon::end_page());
6152: return OK;
1.364 bisitz 6153: }
1.329 droeschl 6154:
1.440 raeburn 6155: sub embedded_form_elems {
6156: my ($phase,$primaryurl,$newidx) = @_;
6157: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6158: $newidx =~s /\D+//g;
1.440 raeburn 6159: return <<STATE;
6160: <input type="hidden" name="folderpath" value="$folderpath" />
6161: <input type="hidden" name="cmd" value="upload_embedded" />
6162: <input type="hidden" name="newidx" value="$newidx" />
6163: <input type="hidden" name="phase" value="$phase" />
6164: <input type="hidden" name="primaryurl" value="$primaryurl" />
6165: STATE
6166: }
6167:
6168: sub embedded_destination {
6169: my $folder=$env{'form.folder'};
6170: my $destination = 'docs/';
6171: if ($folder =~ /^supplemental/) {
6172: $destination = 'supplemental/';
6173: }
6174: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6175: $destination .= 'default/';
6176: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6177: $destination .= $2.'/';
6178: }
1.484.2.78 raeburn 6179: my $newidx = $env{'form.newidx'};
6180: $newidx =~s /\D+//g;
6181: if ($newidx) {
6182: $destination .= $newidx;
6183: }
1.440 raeburn 6184: my $dir_root = '/userfiles';
6185: return ($destination,$dir_root);
6186: }
6187:
6188: sub return_to_editor {
6189: my $actionurl = '/adm/coursedocs';
6190: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6191: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6192: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6193: '</a></p>';
6194: }
6195:
1.476 raeburn 6196: sub decompression_info {
6197: my ($destination,$dir_root) = &embedded_destination();
6198: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6199: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6200: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6201: my $container='sequence';
1.480 raeburn 6202: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6203: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6204: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6205: $container='page';
6206: }
1.480 raeburn 6207: unshift(@hiddens,$pathitem);
6208: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6209: if ($item eq 'newidx') {
6210: next if ($env{'form.'.$item} =~ /\D/);
6211: }
1.480 raeburn 6212: if ($env{'form.'.$item}) {
6213: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6214: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6215: }
1.477 raeburn 6216: }
1.476 raeburn 6217: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6218: $hiddenelem);
6219: }
6220:
6221: sub decompression_phase_one {
6222: my ($dir,$file,$warning,$error,$output);
6223: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6224: &decompression_info();
1.484.2.7 raeburn 6225: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6226: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6227: } else {
6228: my $file = $1;
1.481 raeburn 6229: $output =
6230: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6231: $destination,$dir_root,
6232: $hiddenelem);
6233: if ($env{'form.autoextract_camtasia'}) {
6234: $output .= &remove_archive($docudom,$docuname,$container);
6235: }
1.476 raeburn 6236: }
6237: if ($error) {
6238: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6239: $error.'</p>'."\n";
6240: }
6241: if ($warning) {
6242: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6243: }
6244: return $output;
6245: }
6246:
6247: sub decompression_phase_two {
6248: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6249: &decompression_info();
1.481 raeburn 6250: my $output;
1.480 raeburn 6251: if ($env{'form.archivedelete'}) {
1.481 raeburn 6252: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6253: }
6254: $output .=
1.481 raeburn 6255: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6256: $destination,$dir_root,$hiddenelem);
6257: return $output;
6258: }
6259:
1.480 raeburn 6260: sub remove_archive {
6261: my ($docudom,$docuname,$container) = @_;
6262: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6263: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6264: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6265: if ($fatal) {
6266: if ($container eq 'page') {
6267: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6268: } else {
6269: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6270: }
1.484.2.54 raeburn 6271: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6272: } else {
6273: my $currcmd = $env{'form.cmd'};
6274: my $position = $env{'form.position'};
1.484.2.54 raeburn 6275: my $archiveidx = $position;
6276: if ($position > 0) {
6277: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6278: $archiveidx = $position-1;
6279: }
6280: $env{'form.cmd'} = 'remove_'.$archiveidx;
6281: my ($title,$url,@rrest) =
6282: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6283: if ($url eq $env{'form.archiveurl'}) {
6284: if (&handle_edit_cmd($docuname,$docudom)) {
6285: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6286: if ($fatal) {
6287: if ($container eq 'page') {
6288: $delwarning = &mt('An error occurred updating the contents of the current page.');
6289: } else {
6290: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6291: }
1.480 raeburn 6292: } else {
1.484.2.54 raeburn 6293: $delresult = &mt('Archive file removed.');
1.480 raeburn 6294: }
6295: }
1.484.2.54 raeburn 6296: } else {
6297: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6298: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6299: }
6300: }
6301: $env{'form.cmd'} = $currcmd;
6302: }
6303: if ($delwarning) {
6304: $output = '<p class="LC_warning">'.
6305: $delwarning.
6306: '</p>';
6307: }
6308: if ($delresult) {
6309: $output .= '<p class="LC_info">'.
6310: $delresult.
6311: '</p>';
6312: }
1.481 raeburn 6313: return $output;
1.480 raeburn 6314: }
6315:
1.484 raeburn 6316: sub generate_admin_menu {
1.484.2.67 raeburn 6317: my ($crstype,$canedit) = @_;
1.484 raeburn 6318: my $lc_crstype = lc($crstype);
6319: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6320: my %lt= ( # do not translate here
1.484 raeburn 6321: 'vc' => 'Verify Content',
6322: 'cv' => 'Check/Set Resource Versions',
6323: 'ls' => 'List Resource Identifiers',
6324: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6325: 'dcd' => "Copy $crstype Content to Authoring Space",
6326: );
1.484 raeburn 6327: my ($candump,$dumpurl);
6328: if ($home + $other > 0) {
6329: $candump = 'F';
6330: if ($home) {
6331: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6332: } else {
6333: my @hosts;
6334: foreach my $aurole (keys(%outhash)) {
6335: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6336: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6337: }
1.484 raeburn 6338: }
6339: if (@hosts == 1) {
6340: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6341: '&role='.
6342: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6343: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6344: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6345: } else {
6346: $dumpurl = "javascript:choose_switchserver_window()";
6347: }
6348: }
6349: }
6350: my @menu=
6351: ({ categorytitle=>'Administration',
6352: items =>[
6353: { linktext => $lt{'vc'},
6354: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6355: permission => 'F',
1.484.2.44 raeburn 6356: help => 'Docs_Verify_Content',
1.484 raeburn 6357: icon => 'verify.png',
6358: linktitle => 'Verify contents can be retrieved/rendered',
6359: },
6360: { linktext => $lt{'cv'},
6361: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6362: permission => 'F',
1.484.2.44 raeburn 6363: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6364: icon => 'resversion.png',
6365: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6366: },
6367: { linktext => $lt{'ls'},
6368: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6369: permission => 'F',
6370: #help => '',
6371: icon => 'symbs.png',
6372: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6373: },
6374: ]
1.484.2.67 raeburn 6375: });
6376: if ($canedit) {
6377: push(@menu,
1.484 raeburn 6378: { categorytitle=>'Export',
6379: items =>[
6380: { linktext => $lt{'imse'},
6381: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6382: permission => 'F',
6383: help => 'Docs_Export_Course_Docs',
6384: icon => 'imsexport.png',
6385: linktitle => $lt{'imse'},
6386: },
6387: { linktext => $lt{'dcd'},
6388: url => $dumpurl,
6389: permission => $candump,
1.484.2.44 raeburn 6390: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6391: icon => 'dump.png',
6392: linktitle => $lt{'dcd'},
6393: },
6394: ]
6395: });
1.484.2.67 raeburn 6396: }
1.484 raeburn 6397: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6398: '<input type="hidden" id="dummy" />'."\n".
6399: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6400: '</form>';
1.329 droeschl 6401: }
6402:
6403: sub generate_edit_table {
1.484.2.30 raeburn 6404: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6405: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6406: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6407: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6408: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6409: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6410: $activetab = $env{'form.active'};
6411: }
1.484.2.67 raeburn 6412: unless ($canedit) {
6413: $disabled = ' disabled="disabled"';
6414: }
1.472 raeburn 6415: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6416: my $backtext = &mt('Exit Editor');
1.458 raeburn 6417: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6418: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6419: '<li class="goback">'.
1.484.2.32 raeburn 6420: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6421: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6422: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6423: '<li>'.
6424: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6425: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6426: if ($env{'form.docslog'}) {
6427: $form .= '<li class="active">';
6428: } else {
6429: $form .= '<li>';
6430: }
6431: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6432: &mt('History').'</a></li>'."\n";
6433: if ($env{'form.docslog'}) {
6434: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6435: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6436: }
1.458 raeburn 6437: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6438: if($name ne '00'){
1.371 tempelho 6439: if($activetab eq '' || $activetab ne $name){
6440: $active = '';
6441: }elsif($activetab eq $name){
6442: $active = 'class="active"';
6443: }
1.458 raeburn 6444: $form .= '<li style="float:right" '.$active
1.484 raeburn 6445: .' 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 6446: } else {
1.484.2.43 raeburn 6447: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6448:
6449: }
1.329 droeschl 6450: }
1.484 raeburn 6451: $form .= '</ul>'."\n";
6452: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6453:
6454: if ($to_show ne '') {
1.484.2.30 raeburn 6455: my $saveform;
6456: if ($need_save) {
6457: my $button = &mt('Make changes');
6458: my $path;
6459: if ($env{'form.folderpath'}) {
6460: $path =
6461: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6462: }
6463: $saveform = <<"END";
6464: <div id="multisave" style="display:none; clear:both;" >
6465: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6466: <input type="hidden" name="folderpath" value="$path" />
6467: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6468: <input type="hidden" name="allhiddenresource" value="" />
6469: <input type="hidden" name="allencrypturl" value="" />
6470: <input type="hidden" name="allrandompick" value="" />
6471: <input type="hidden" name="allrandomorder" value="" />
6472: <input type="hidden" name="changeparms" value="" />
6473: <input type="hidden" name="multiremove" value="" />
6474: <input type="hidden" name="multicut" value="" />
6475: <input type="hidden" name="multicopy" value="" />
6476: <input type="hidden" name="multichange" value="" />
6477: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6478: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6479: </form>
6480: </div>
6481: END
6482: }
6483: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6484: }
1.363 ehlerst 6485: foreach my $field (keys(%orderhash)){
1.390 tempelho 6486: if($field ne '00'){
1.422 onken 6487: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6488: $active = 'style="display: none;float:left"';
1.422 onken 6489: }elsif($activetab eq $field){
1.458 raeburn 6490: $active = 'style="display:block;float:left"';
1.422 onken 6491: }
6492: $form .= '<div id="'.$field.$tid.'"'
6493: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6494: .'</div>'."\n";
1.363 ehlerst 6495: }
6496: }
1.484 raeburn 6497: unless ($env{'form.docslog'}) {
6498: $form .= '</div></div>'."\n";
6499: }
1.329 droeschl 6500: return $form;
6501: }
6502:
6503: sub editing_js {
1.484.2.80 raeburn 6504: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,
6505: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6506: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6507: p_mnf => 'Name of New Folder',
6508: t_mnf => 'New Folder',
6509: p_mnp => 'Name of New Page',
6510: t_mnp => 'New Page',
1.451 www 6511: p_mxu => 'Title for the External Score',
1.349 biermanm 6512: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6513: p_msb => 'Title for the Problem',
6514: p_mdb => 'Title for the Drop Box',
1.336 schafran 6515: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6516: p_mwp => 'Title for Web Page',
1.348 weissno 6517: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6518: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6519: p_mab_alrt1 => 'Not a valid user:domain',
6520: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6521: p_chn => 'New Title',
6522: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6523: p_rmr2a => 'Remove',
6524: p_rmr2b => '?',
6525: p_rmr3a => 'Remove those',
6526: p_rmr3b => 'items?',
6527: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6528: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6529: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6530: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6531: p_ctr2a => 'Cut',
6532: p_ctr2b => '?',
6533: p_ctr3a => 'Cut those',
6534: p_ctr3b => 'items?',
1.478 raeburn 6535: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6536: imsfile => 'You must choose an IMS package for import',
6537: imscms => 'You must select which Course Management System was the source of the IMS package',
6538: invurl => 'Invalid URL',
6539: titbl => 'Title is blank',
1.484.2.30 raeburn 6540: more => '(More ...)',
6541: less => '(Less ...)',
6542: noor => 'No actions selected or changes to settings specified.',
6543: noch => 'No changes to settings specified.',
6544: noac => 'No actions selected.',
1.484.2.67 raeburn 6545: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6546: );
6547:
1.484.2.61 raeburn 6548: &js_escape(\%js_lt);
1.433 raeburn 6549: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6550: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6551: my $main_container_page;
1.484.2.19 raeburn 6552: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6553: $main_container_page = 1;
1.434 raeburn 6554: }
1.484.2.67 raeburn 6555: my $backtourl;
6556: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6557: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6558:
1.484.2.21 raeburn 6559: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6560: my $caller = $1;
6561: if ($caller =~ /^supplemental/) {
6562: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6563: } else {
6564: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6565: $res = &Apache::lonnet::clutter($res);
6566: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6567: my ($url,$anchor);
6568: if ($res =~ /^([^#]+)#([^#]+)$/) {
6569: $url = $1;
6570: $anchor = $2;
6571: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6572: $caller = $1.&escape('#').$anchor;
6573: }
1.484.2.67 raeburn 6574: } else {
6575: $url = $res;
1.484.2.66 raeburn 6576: }
1.484.2.83 raeburn 6577: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6578: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6579: $backtourl .= '?navmap=1';
6580: } else {
6581: $backtourl .= '?symb='.
6582: &HTML::Entities::encode($caller,'<>&"');
6583: }
1.484.2.80 raeburn 6584: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6585: if (($ENV{'SERVER_PORT'} == 443) &&
6586: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6587: unless (&Apache::lonnet::uses_sts()) {
6588: if ($hostname ne '') {
6589: $backtourl = 'http://'.$hostname.$backtourl;
6590: }
6591: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6592: }
6593: }
6594: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6595: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6596: unless (&Apache::lonnet::uses_sts()) {
6597: if ($hostname ne '') {
6598: $backtourl = 'http://'.$hostname.$backtourl;
6599: }
6600: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6601: }
6602: }
6603: }
1.484.2.66 raeburn 6604: if ($anchor ne '') {
6605: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6606: }
1.484.2.57 raeburn 6607: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6608: } else {
6609: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6610: }
6611: }
6612: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6613: $backtourl = '/adm/menu';
6614: } elsif ($supplementalflag) {
1.472 raeburn 6615: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6616: } else {
6617: $backtourl = '/adm/navmaps';
1.472 raeburn 6618: }
6619:
1.484.2.19 raeburn 6620: my $fieldsets = "'ext','doc'";
6621: unless ($main_container_page) {
6622: $fieldsets .=",'ims'";
6623: }
1.484.2.12 raeburn 6624: if ($supplementalflag) {
6625: $fieldsets = "'suppext','suppdoc'";
6626: }
6627:
1.484.2.67 raeburn 6628: my $jsmakefunctions;
6629: if ($canedit) {
6630: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6631: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6632: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6633: if (foldername) {
1.484.2.91! raeburn 6634: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
1.329 droeschl 6635: targetform.submit();
6636: }
6637: }
6638:
6639: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6640: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6641: if (pagename) {
1.484.2.91! raeburn 6642: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
1.329 droeschl 6643: targetform.submit();
6644: }
6645: }
6646:
6647: function makeexamupload() {
1.484.2.61 raeburn 6648: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6649: if (title) {
1.329 droeschl 6650: this.document.forms.newexamupload.importdetail.value=
1.484.2.91! raeburn 6651: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
1.329 droeschl 6652: this.document.forms.newexamupload.submit();
6653: }
6654: }
6655:
6656: function makesmppage() {
1.484.2.61 raeburn 6657: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6658: if (title) {
1.329 droeschl 6659: this.document.forms.newsmppg.importdetail.value=
1.484.2.91! raeburn 6660: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6661: this.document.forms.newsmppg.submit();
6662: }
6663: }
6664:
1.484.2.27 raeburn 6665: function makewebpage(type) {
1.484.2.61 raeburn 6666: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6667: var formname;
6668: if (type == 'supp') {
6669: formname = this.document.forms.supwebpage;
6670: } else {
6671: formname = this.document.forms.newwebpage;
6672: }
6673: if (title) {
6674: var webpage = formname.importdetail.value;
1.484.2.91! raeburn 6675: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
1.484.2.27 raeburn 6676: formname.submit();
6677: }
6678: }
6679:
1.329 droeschl 6680: function makesmpproblem() {
1.484.2.61 raeburn 6681: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6682: if (title) {
1.329 droeschl 6683: this.document.forms.newsmpproblem.importdetail.value=
1.484.2.91! raeburn 6684: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
1.329 droeschl 6685: this.document.forms.newsmpproblem.submit();
6686: }
6687: }
6688:
6689: function makedropbox() {
1.484.2.61 raeburn 6690: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6691: if (title) {
1.329 droeschl 6692: this.document.forms.newdropbox.importdetail.value=
1.484.2.91! raeburn 6693: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
1.329 droeschl 6694: this.document.forms.newdropbox.submit();
6695: }
6696: }
6697:
6698: function makebulboard() {
1.484.2.61 raeburn 6699: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6700: if (title) {
6701: this.document.forms.newbul.importdetail.value=
1.484.2.91! raeburn 6702: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6703: this.document.forms.newbul.submit();
6704: }
6705: }
6706:
6707: function makeabout() {
1.484.2.61 raeburn 6708: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6709: if (user) {
6710: var comp=new Array();
6711: comp=user.split(':');
6712: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6713: if ((comp[0]) && (comp[1])) {
6714: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6715: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6716: this.document.forms.newaboutsomeone.submit();
6717: } else {
6718: alert("$js_lt{'p_mab_alrt1'}");
6719: }
6720: } else {
6721: alert("$js_lt{'p_mab_alrt2'}");
6722: }
6723: }
1.335 ehlerst 6724: }
1.484.2.67 raeburn 6725:
6726: function makenew(targetform) {
6727: targetform.submit();
1.335 ehlerst 6728: }
1.484.2.67 raeburn 6729:
6730: function changename(folderpath,index,oldtitle) {
6731: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6732: if (title) {
6733: this.document.forms.renameform.markcopy.value='';
6734: this.document.forms.renameform.title.value=title;
6735: this.document.forms.renameform.cmd.value='rename_'+index;
6736: this.document.forms.renameform.folderpath.value=folderpath;
6737: this.document.forms.renameform.submit();
6738: }
1.329 droeschl 6739: }
6740:
1.484.2.67 raeburn 6741: ENDNEWSCRIPT
6742: } else {
6743: $jsmakefunctions = <<ENDNEWSCRIPT;
6744:
6745: function makenewfolder() {
6746: alert("$js_lt{'edri'}");
6747: }
6748:
6749: function makenewpage() {
6750: alert("$js_lt{'edri'}");
6751: }
6752:
6753: function makeexamupload() {
6754: alert("$js_lt{'edri'}");
6755: }
6756:
6757: function makesmppage() {
6758: alert("$js_lt{'edri'}");
6759: }
6760:
6761: function makewebpage(type) {
6762: alert("$js_lt{'edri'}");
6763: }
6764:
6765: function makesmpproblem() {
6766: alert("$js_lt{'edri'}");
6767: }
6768:
6769: function makedropbox() {
6770: alert("$js_lt{'edri'}");
6771: }
6772:
6773: function makebulboard() {
6774: alert("$js_lt{'edri'}");
6775: }
6776:
6777: function makeabout() {
6778: alert("$js_lt{'edri'}");
6779: }
6780:
6781: function changename() {
6782: alert("$js_lt{'edri'}");
6783: }
6784:
6785: function makenew() {
6786: alert("$js_lt{'edri'}");
6787: }
6788:
6789: function groupimport() {
6790: alert("$js_lt{'edri'}");
6791: }
6792:
6793: function groupsearch() {
6794: alert("$js_lt{'edri'}");
6795: }
6796:
6797: function groupopen(url,recover) {
6798: var options="scrollbars=1,resizable=1,menubar=0";
6799: idxflag=1;
6800: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6801: idx.focus();
6802: }
6803:
6804: ENDNEWSCRIPT
6805:
6806: }
6807: return <<ENDSCRIPT;
6808:
6809: $jsmakefunctions
6810:
1.484.2.13 raeburn 6811: function toggleUpload(caller) {
6812: var blocks = Array($fieldsets);
6813: for (var i=0; i<blocks.length; i++) {
6814: var disp = 'none';
6815: if (caller == blocks[i]) {
6816: var curr = document.getElementById('upload'+caller+'form').style.display;
6817: if (curr == 'none') {
6818: disp='block';
6819: }
6820: }
6821: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6822: }
6823: resize_scrollbox('contentscroll','1','1');
6824: return;
6825: }
6826:
1.484.2.19 raeburn 6827: function toggleMap(caller) {
1.484.2.13 raeburn 6828: var disp = 'none';
1.484.2.19 raeburn 6829: if (document.getElementById('importmapform')) {
6830: if (caller == 'map') {
6831: var curr = document.getElementById('importmapform').style.display;
6832: if (curr == 'none') {
6833: disp='block';
6834: }
1.484.2.12 raeburn 6835: }
1.484.2.19 raeburn 6836: document.getElementById('importmapform').style.display=disp;
6837: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6838: }
1.484.2.19 raeburn 6839: return;
1.329 droeschl 6840: }
6841:
1.484.2.12 raeburn 6842: function makeims(imsform) {
6843: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6844: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6845: return;
6846: }
6847: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6848: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6849: return;
6850: }
6851: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6852: imsform.submit();
6853: }
6854:
1.478 raeburn 6855: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6856: var pickitem;
6857: var picknumitem;
6858: var picknumtext;
6859: if (index == 'all') {
6860: pickitem = document.getElementById('randompickall');
6861: picknumitem = document.getElementById('rpicknumall');
6862: picknumtext = document.getElementById('rpicktextall');
6863: } else {
6864: pickitem = document.getElementById('randompick_'+index);
6865: picknumitem = document.getElementById('rpicknum_'+index);
6866: picknumtext = document.getElementById('randompicknum_'+index);
6867: }
1.478 raeburn 6868: if (pickitem.checked) {
1.484.2.61 raeburn 6869: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6870: if (picknum == '' || picknum == null) {
6871: if (caller == 'check') {
6872: pickitem.checked=false;
1.484.2.29 raeburn 6873: if (index == 'all') {
6874: picknumtext.innerHTML = '';
6875: if (caller == 'link') {
6876: propagateState(targetform,'rpicknum');
6877: }
6878: } else {
1.484.2.30 raeburn 6879: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6880: }
1.478 raeburn 6881: }
6882: } else {
6883: picknum.toString();
6884: var regexdigit=/^\\d+\$/;
6885: if (regexdigit.test(picknum)) {
6886: picknumitem.value = picknum;
1.484.2.29 raeburn 6887: if (index == 'all') {
1.484.2.30 raeburn 6888: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6889: if (caller == 'link') {
6890: propagateState(targetform,'rpicknum');
6891: }
6892: } else {
6893: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6894: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6895: }
1.478 raeburn 6896: } else {
6897: if (caller == 'check') {
1.484.2.29 raeburn 6898: if (index == 'all') {
6899: picknumtext.innerHTML = '';
6900: if (caller == 'link') {
6901: propagateState(targetform,'rpicknum');
6902: }
6903: } else {
6904: pickitem.checked=false;
1.484.2.30 raeburn 6905: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6906: }
1.478 raeburn 6907: }
6908: return;
6909: }
6910: }
6911: } else {
1.484.2.29 raeburn 6912: picknumitem.value = '';
6913: picknumtext.innerHTML = '';
6914: if (index == 'all') {
6915: if (caller == 'link') {
6916: propagateState(targetform,'rpicknum');
6917: }
6918: } else {
1.484.2.30 raeburn 6919: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6920: }
6921: }
6922: }
6923:
6924: function propagateState(form,param) {
6925: if (document.getElementById(param+'all')) {
6926: var setcheck = 0;
6927: var rpick = 0;
6928: if (param == 'rpicknum') {
6929: if (document.getElementById('randompickall')) {
6930: if (document.getElementById('randompickall').checked) {
6931: if (document.getElementById('rpicknumall')) {
6932: rpick = document.getElementById('rpicknumall').value;
6933: }
6934: }
6935: }
6936: } else {
6937: if (document.getElementById(param+'all').checked) {
6938: setcheck = 1;
6939: }
6940: }
1.484.2.30 raeburn 6941: var allidxlist;
6942: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6943: if (document.getElementById('all'+param+'idx')) {
6944: allidxlist = document.getElementById('all'+param+'idx').value;
6945: }
6946: var actions = new Array ('remove','cut','copy');
6947: for (var i=0; i<actions.length; i++) {
6948: if (actions[i] != param) {
6949: if (document.getElementById(actions[i]+'all')) {
6950: document.getElementById(actions[i]+'all').checked = false;
6951: }
6952: }
6953: }
6954: }
1.484.2.29 raeburn 6955: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6956: allidxlist = form.allidx.value;
6957: }
6958: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6959: allidxlist = form.allmapidx.value;
6960: }
6961: if ((allidxlist != '') && (allidxlist != null)) {
6962: var allidxs = allidxlist.split(',');
6963: if (allidxs.length > 1) {
6964: for (var i=0; i<allidxs.length; i++) {
6965: if (document.getElementById(param+'_'+allidxs[i])) {
6966: if (param == 'rpicknum') {
6967: if (document.getElementById('randompick_'+allidxs[i])) {
6968: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6969: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6970: if (rpick > 0) {
6971: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6972: } else {
6973: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6974: }
6975: }
6976: }
6977: } else {
1.484.2.29 raeburn 6978: if (setcheck == 1) {
6979: document.getElementById(param+'_'+allidxs[i]).checked = true;
6980: } else {
6981: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6982: if (param == 'randompick') {
6983: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6984: }
1.484.2.29 raeburn 6985: }
6986: }
6987: }
6988: }
1.484.2.30 raeburn 6989: if (setcheck == 1) {
6990: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6991: var actions = new Array('copy','cut','remove');
6992: for (var i=0; i<actions.length; i++) {
6993: var otheractions;
6994: var otheridxs;
6995: if (actions[i] === param) {
6996: continue;
6997: } else {
6998: if (document.getElementById('all'+actions[i]+'idx')) {
6999: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7000: otheridxs = otheractions.split(',');
7001: if (otheridxs.length > 1) {
7002: for (var j=0; j<otheridxs.length; j++) {
7003: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7004: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7005: }
1.484.2.29 raeburn 7006: }
7007: }
7008: }
7009: }
1.484.2.30 raeburn 7010: }
1.484.2.29 raeburn 7011: }
7012: }
7013: }
7014: }
1.478 raeburn 7015: }
1.484.2.29 raeburn 7016: return;
7017: }
7018:
1.484.2.63 raeburn 7019: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7020: var canedit = '$canedit';
7021: if (canedit == '') {
7022: alert("$js_lt{'edri'}");
7023: return;
7024: }
1.484.2.30 raeburn 7025: var dosettings;
7026: var doaction;
7027: var control = document.togglemultsettings;
7028: if (context == 'actions') {
7029: control = document.togglemultactions;
7030: doaction = 1;
7031: } else {
7032: dosettings = 1;
7033: }
7034: if (control) {
7035: if (control.showmultpick.length) {
7036: for (var i=0; i<control.showmultpick.length; i++) {
7037: if (control.showmultpick[i].checked) {
7038: if (control.showmultpick[i].value == 1) {
7039: if (context == 'settings') {
7040: dosettings = 0;
7041: } else {
7042: doaction = 0;
7043: }
7044: }
7045: }
7046: }
7047: }
7048: }
7049: if (context == 'settings') {
7050: if (dosettings == 1) {
7051: targetform.changeparms.value=param;
7052: targetform.submit();
7053: }
7054: }
7055: if (context == 'actions') {
7056: if (doaction == 1) {
7057: targetform.cmd.value=param+'_'+index;
7058: targetform.folderpath.value=folderpath;
7059: targetform.markcopy.value=idx+':'+param;
7060: targetform.copyfolder.value=folder+'.'+container;
7061: if (param == 'remove') {
1.484.2.63 raeburn 7062: var doremove = 0;
7063: if (skip_confirm) {
7064: if (confirm_removal) {
7065: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7066: doremove = 1;
7067: }
7068: } else {
7069: doremove = 1;
7070: }
7071: } else {
7072: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7073: doremove = 1;
7074: }
7075: }
7076: if (doremove) {
1.484.2.30 raeburn 7077: targetform.markcopy.value='';
7078: targetform.copyfolder.value='';
1.484.2.29 raeburn 7079: targetform.submit();
7080: }
7081: }
1.484.2.30 raeburn 7082: if (param == 'cut') {
1.484.2.61 raeburn 7083: 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 7084: targetform.submit();
7085: return;
7086: }
7087: }
7088: if (param == 'copy') {
7089: targetform.submit();
7090: return;
7091: }
7092: targetform.markcopy.value='';
7093: targetform.copyfolder.value='';
7094: targetform.cmd.value='';
7095: targetform.folderpath.value='';
7096: return;
7097: } else {
7098: if (document.getElementById(param+'_'+idx)) {
7099: item = document.getElementById(param+'_'+idx);
7100: if (item.type == 'checkbox') {
7101: if (item.checked) {
7102: item.checked = false;
7103: } else {
7104: item.checked = true;
7105: singleCheck(item,idx,param);
7106: }
7107: }
7108: }
7109: }
7110: }
7111: return;
7112: }
7113:
7114: function singleCheck(caller,idx,action) {
7115: actions = new Array('cut','copy','remove');
7116: if (caller.checked) {
7117: for (var i=0; i<actions.length; i++) {
7118: if (actions[i] != action) {
7119: if (document.getElementById(actions[i]+'_'+idx)) {
7120: if (document.getElementById(actions[i]+'_'+idx).checked) {
7121: document.getElementById(actions[i]+'_'+idx).checked = false;
7122: }
7123: }
7124: }
1.484.2.29 raeburn 7125: }
7126: }
7127: return;
1.478 raeburn 7128: }
7129:
1.334 muellerd 7130: function unselectInactive(nav) {
1.335 ehlerst 7131: currentNav = document.getElementById(nav);
7132: currentLis = currentNav.getElementsByTagName('LI');
7133: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7134: if (currentLis[i].className == 'goback') {
7135: currentLis[i].className = 'goback';
7136: } else {
7137: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7138: currentLis[i].className = 'right';
1.472 raeburn 7139: } else {
1.374 tempelho 7140: currentLis[i].className = 'i';
1.472 raeburn 7141: }
7142: }
1.335 ehlerst 7143: }
1.332 tempelho 7144: }
7145:
1.334 muellerd 7146: function hideAll(current, nav, data) {
1.335 ehlerst 7147: unselectInactive(nav);
1.484.2.43 raeburn 7148: if (current) {
7149: if (current.className == 'right'){
1.374 tempelho 7150: current.className = 'right active'
1.484.2.43 raeburn 7151: } else {
1.374 tempelho 7152: current.className = 'active';
1.484.2.43 raeburn 7153: }
1.374 tempelho 7154: }
1.335 ehlerst 7155: currentData = document.getElementById(data);
7156: currentDivs = currentData.getElementsByTagName('DIV');
7157: for (i = 0; i < currentDivs.length; i++) {
7158: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7159: currentDivs[i].style.display = 'none';
1.330 tempelho 7160: }
7161: }
1.335 ehlerst 7162: }
1.330 tempelho 7163:
1.374 tempelho 7164: function openTabs(pageId) {
7165: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7166: if(tabnav.length > 2 ){
1.389 tempelho 7167: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7168: currentLis = currentNav.getElementsByTagName('LI');
7169: for(i = 0; i< currentLis.length; i++){
7170: if(currentLis[i].className == 'active') {
1.375 tempelho 7171: funcString = currentLis[i].onclick.toString();
7172: tab = funcString.split('"');
1.420 onken 7173: if(tab.length < 2) {
7174: tab = funcString.split("'");
7175: }
1.375 tempelho 7176: currentData = document.getElementById(tab[1]);
7177: currentData.style.display = 'block';
1.374 tempelho 7178: }
7179: }
7180: }
7181: }
7182:
1.334 muellerd 7183: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7184: currstate = current.className;
1.334 muellerd 7185: hideAll(current, nav, data);
1.375 tempelho 7186: openTabs(pageId);
1.334 muellerd 7187: unselectInactive(nav);
1.484.2.43 raeburn 7188: if ((currstate == 'active') || (currstate == 'right active')) {
7189: if (currstate == 'active') {
7190: current.className = '';
7191: } else {
7192: current.className = 'right';
7193: }
7194: activeTab = '';
7195: toggleUpload();
7196: toggleMap();
7197: resize_scrollbox('contentscroll','1','0');
7198: return;
7199: } else {
7200: current.className = 'active';
7201: }
1.330 tempelho 7202: currentData = document.getElementById(pageId);
7203: currentData.style.display = 'block';
1.458 raeburn 7204: activeTab = pageId;
1.484.2.12 raeburn 7205: toggleUpload();
1.484.2.14 raeburn 7206: toggleMap();
1.433 raeburn 7207: if (nav == 'mainnav') {
7208: var storedpath = "$docs_folderpath";
1.434 raeburn 7209: var storedpage = "$main_container_page";
1.433 raeburn 7210: var reg = new RegExp("^supplemental");
7211: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7212: if (storedpage == 1) {
7213: document.simpleedit.folderpath.value = '';
7214: document.uploaddocument.folderpath.value = '';
7215: } else {
7216: if (reg.test(storedpath)) {
7217: document.simpleedit.folderpath.value = '$toplevelmain';
7218: document.uploaddocument.folderpath.value = '$toplevelmain';
7219: document.newext.folderpath.value = '$toplevelmain';
7220: } else {
7221: document.simpleedit.folderpath.value = storedpath;
7222: document.uploaddocument.folderpath.value = storedpath;
7223: document.newext.folderpath.value = storedpath;
7224: }
1.433 raeburn 7225: }
7226: } else {
1.434 raeburn 7227: if (reg.test(storedpath)) {
7228: document.simpleedit.folderpath.value = storedpath;
7229: document.supuploaddocument.folderpath.value = storedpath;
7230: document.supnewext.folderpath.value = storedpath;
7231: } else {
1.433 raeburn 7232: document.simpleedit.folderpath.value = '$toplevelsupp';
7233: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7234: document.supnewext.folderpath.value = '$toplevelsupp';
7235: }
7236: }
7237: }
1.484.2.3 raeburn 7238: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7239: return false;
7240: }
1.329 droeschl 7241:
1.472 raeburn 7242: function toContents(jumpto) {
7243: var newurl = '$backtourl';
1.484.2.21 raeburn 7244: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7245: newurl = newurl+'?postdata='+jumpto;
7246: }
7247: location.href=newurl;
7248: }
7249:
1.484.2.30 raeburn 7250: function togglePick(caller,value) {
7251: var disp = 'none';
7252: if (document.getElementById('multi'+caller)) {
7253: var curr = document.getElementById('multi'+caller).style.display;
7254: if (value == 1) {
7255: disp='block';
7256: }
7257: if (curr == disp) {
7258: return;
7259: }
7260: document.getElementById('multi'+caller).style.display=disp;
7261: if (value == 1) {
1.484.2.61 raeburn 7262: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7263: } else {
7264: document.getElementById('more'+caller).innerHTML = '';
7265: }
7266: if (caller == 'actions') {
7267: setClass(value);
7268: setBoxes(value);
7269: }
7270: }
7271: var showButton = multiSettings();
7272: if (showButton != 1) {
7273: showButton = multiActions();
7274: }
7275: if (document.getElementById('multisave')) {
7276: if (showButton == 1) {
7277: document.getElementById('multisave').style.display='block';
7278: } else {
7279: document.getElementById('multisave').style.display='none';
7280: }
7281: }
7282: resize_scrollbox('contentscroll','1','1');
7283: return;
7284: }
7285:
7286: function toggleCheckUncheck(caller,more) {
7287: if (more == 1) {
1.484.2.61 raeburn 7288: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7289: document.getElementById('allfields'+caller).style.display='block';
7290: } else {
1.484.2.61 raeburn 7291: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7292: document.getElementById('allfields'+caller).style.display='none';
7293: }
7294: resize_scrollbox('contentscroll','1','1');
7295: }
7296:
7297: function multiSettings() {
7298: var inuse = 0;
7299: var settingsform = document.togglemultsettings;
7300: if (settingsform.showmultpick.length > 1) {
7301: for (var i=0; i<settingsform.showmultpick.length; i++) {
7302: if (settingsform.showmultpick[i].checked) {
7303: if (settingsform.showmultpick[i].value == 1) {
7304: inuse = 1;
7305: }
7306: }
7307: }
7308: }
7309: return inuse;
7310: }
7311:
7312: function multiActions() {
7313: var inuse = 0;
7314: var actionsform = document.togglemultactions;
7315: if (actionsform.showmultpick.length > 1) {
7316: for (var i=0; i<actionsform.showmultpick.length; i++) {
7317: if (actionsform.showmultpick[i].checked) {
7318: if (actionsform.showmultpick[i].value == 1) {
7319: inuse = 1;
7320: }
7321: }
7322: }
7323: }
7324: return inuse;
7325: }
7326:
7327: function checkSubmits() {
7328: var numchanges = 0;
7329: var form = document.saveactions;
7330: var doactions = multiActions();
7331: var cutwarnings = 0;
7332: var remwarnings = 0;
1.484.2.63 raeburn 7333: var removalinfo = 0;
1.484.2.30 raeburn 7334: if (doactions == 1) {
7335: var remidxlist = document.cumulativeactions.allremoveidx.value;
7336: if ((remidxlist != '') && (remidxlist != null)) {
7337: var remidxs = remidxlist.split(',');
7338: for (var i=0; i<remidxs.length; i++) {
7339: if (document.getElementById('remove_'+remidxs[i])) {
7340: if (document.getElementById('remove_'+remidxs[i]).checked) {
7341: form.multiremove.value += remidxs[i]+',';
7342: numchanges ++;
7343: if (document.getElementById('skip_remove_'+remidxs[i])) {
7344: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7345: remwarnings ++;
7346: }
7347: }
1.484.2.63 raeburn 7348: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7349: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7350: removalinfo ++;
7351: }
7352: }
1.484.2.30 raeburn 7353: }
7354: }
7355: }
7356: }
7357: var cutidxlist = document.cumulativeactions.allcutidx.value;
7358: if ((cutidxlist != '') && (cutidxlist != null)) {
7359: var cutidxs = cutidxlist.split(',');
7360: for (var i=0; i<cutidxs.length; i++) {
7361: if (document.getElementById('cut_'+cutidxs[i])) {
7362: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7363: form.multicut.value += cutidxs[i]+',';
7364: numchanges ++;
7365: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7366: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7367: cutwarnings ++;
7368: }
7369: }
7370: }
7371: }
7372: }
7373: }
7374: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7375: if ((copyidxlist != '') && (copyidxlist != null)) {
7376: var copyidxs = copyidxlist.split(',');
7377: for (var i=0; i<copyidxs.length; i++) {
7378: if (document.getElementById('copy_'+copyidxs[i])) {
7379: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7380: form.multicopy.value += copyidxs[i]+',';
7381: numchanges ++;
7382: }
7383: }
7384: }
7385: }
7386: if (numchanges > 0) {
7387: form.multichange.value = numchanges;
7388: }
7389: }
7390: var dosettings = multiSettings();
7391: var haschanges = 0;
7392: if (dosettings == 1) {
7393: form.allencrypturl.value = '';
7394: form.allhiddenresource.value = '';
7395: form.changeparms.value = 'all';
7396: var patt=new RegExp(",\$");
7397: var allidxlist = document.cumulativesettings.allidx.value;
7398: if ((allidxlist != '') && (allidxlist != null)) {
7399: var allidxs = allidxlist.split(',');
7400: if (allidxs.length > 1) {
7401: for (var i=0; i<allidxs.length; i++) {
7402: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7403: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7404: form.allhiddenresource.value += allidxs[i]+',';
7405: }
7406: }
7407: if (document.getElementById('encrypturl_'+allidxs[i])) {
7408: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7409: form.allencrypturl.value += allidxs[i]+',';
7410: }
1.484.2.29 raeburn 7411: }
7412: }
1.484.2.30 raeburn 7413: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7414: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7415: }
7416: }
7417: form.allrandompick.value = '';
7418: form.allrandomorder.value = '';
7419: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7420: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7421: var allmapidxs = allmapidxlist.split(',');
7422: for (var i=0; i<allmapidxs.length; i++) {
7423: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7424: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7425: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7426: if ((randompick.checked) && (rpicknum.value != '')) {
7427: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7428: }
7429: if (randorder.checked) {
7430: form.allrandomorder.value += allmapidxs[i]+',';
7431: }
7432: }
7433: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7434: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7435: }
7436: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7437: haschanges = 1;
7438: }
7439: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7440: haschanges = 1;
7441: }
7442: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7443: haschanges = 1;
7444: }
7445: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7446: haschanges = 1;
7447: }
7448: }
7449: if (doactions == 1) {
7450: if (numchanges > 0) {
1.484.2.63 raeburn 7451: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7452: if (remwarnings > 0) {
1.484.2.61 raeburn 7453: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7454: return false;
7455: }
7456: }
1.484.2.63 raeburn 7457: if (removalinfo > 0) {
7458: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7459: return false;
7460: }
7461: }
1.484.2.30 raeburn 7462: if (cutwarnings > 0) {
1.484.2.61 raeburn 7463: 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 7464: return false;
1.484.2.29 raeburn 7465: }
7466: }
7467: }
1.484.2.30 raeburn 7468: form.submit();
7469: return true;
7470: }
7471: }
7472: if (dosettings == 1) {
7473: if (haschanges == 1) {
7474: form.submit();
7475: return true;
1.484.2.29 raeburn 7476: }
7477: }
1.484.2.30 raeburn 7478: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7479: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7480: } else {
7481: if (dosettings == 1) {
1.484.2.61 raeburn 7482: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7483: } else {
1.484.2.61 raeburn 7484: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7485: }
7486: }
7487: return false;
7488: }
7489:
7490: function setClass(value) {
7491: var cutclass = 'LC_docs_cut';
7492: var copyclass = 'LC_docs_copy';
7493: var removeclass = 'LC_docs_remove';
7494: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7495: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7496: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7497: var links = document.getElementsByTagName('a');
7498: for (var i=0; i<links.length; i++) {
7499: var classes = links[i].className;
7500: if (cutreg.test(classes)) {
7501: links[i].className = cutclass;
7502: if (value == 1) {
7503: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7504: }
1.484.2.30 raeburn 7505: } else {
7506: if (copyreg.test(classes)) {
7507: links[i].className = copyclass;
7508: if (value == 1) {
7509: links[i].className += " LC_menubuttons_link";
7510: }
7511: } else {
7512: if (removereg.test(classes)) {
7513: links[i].className = removeclass;
7514: if (value == 1) {
7515: links[i].className += " LC_menubuttons_link";
7516: }
7517: }
1.484.2.29 raeburn 7518: }
7519: }
7520: }
1.484.2.30 raeburn 7521: return;
1.484.2.29 raeburn 7522: }
7523:
1.484.2.30 raeburn 7524: function setBoxes(value) {
7525: var remidxlist = document.cumulativeactions.allremoveidx.value;
7526: if ((remidxlist != '') && (remidxlist != null)) {
7527: var remidxs = remidxlist.split(',');
7528: for (var i=0; i<remidxs.length; i++) {
7529: if (document.getElementById('remove_'+remidxs[i])) {
7530: var item = document.getElementById('remove_'+remidxs[i]);
7531: if (value == 1) {
7532: item.className = 'LC_docs_remove';
7533: } else {
7534: item.className = 'LC_hidden';
7535: }
7536: }
1.484.2.29 raeburn 7537: }
7538: }
1.484.2.30 raeburn 7539: var cutidxlist = document.cumulativeactions.allcutidx.value;
7540: if ((cutidxlist != '') && (cutidxlist != null)) {
7541: var cutidxs = cutidxlist.split(',');
7542: for (var i=0; i<cutidxs.length; i++) {
7543: if (document.getElementById('cut_'+cutidxs[i])) {
7544: var item = document.getElementById('cut_'+cutidxs[i]);
7545: if (value == 1) {
7546: item.className = 'LC_docs_cut';
7547: } else {
7548: item.className = 'LC_hidden';
7549: }
7550: }
7551: }
7552: }
7553: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7554: if ((copyidxlist != '') && (copyidxlist != null)) {
7555: var copyidxs = copyidxlist.split(',');
7556: for (var i=0; i<copyidxs.length; i++) {
7557: if (document.getElementById('copy_'+copyidxs[i])) {
7558: var item = document.getElementById('copy_'+copyidxs[i]);
7559: if (value == 1) {
7560: item.className = 'LC_docs_copy';
7561: } else {
7562: item.className = 'LC_hidden';
7563: }
7564: }
1.484.2.29 raeburn 7565: }
7566: }
7567: return;
7568: }
7569:
1.484.2.67 raeburn 7570: ENDSCRIPT
1.329 droeschl 7571: }
1.457 raeburn 7572:
1.483 raeburn 7573: sub history_tab_js {
7574: return <<"ENDHIST";
7575: function toggleHistoryDisp(choice) {
7576: document.docslogform.docslog.value = choice;
7577: document.docslogform.submit();
7578: return;
7579: }
7580:
7581: ENDHIST
7582: }
7583:
1.484 raeburn 7584: sub inject_data_js {
7585: return <<ENDINJECT;
7586:
7587: function injectData(current, hiddenField, name, value) {
7588: currentElement = document.getElementById(hiddenField);
7589: currentElement.name = name;
7590: currentElement.value = value;
7591: current.submit();
7592: }
7593:
7594: ENDINJECT
7595: }
7596:
7597: sub dump_switchserver_js {
7598: my @hosts = @_;
1.484.2.61 raeburn 7599: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7600: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7601: swit => 'Switch server?',
1.484.2.61 raeburn 7602: );
7603: my %html_js_lt = &Apache::lonlocal::texthash(
7604: swit => 'Switch server?',
1.484.2.43 raeburn 7605: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7606: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7607: chos => 'Choose server',
7608: );
1.484.2.61 raeburn 7609: &js_escape(\%js_lt);
7610: &html_escape(\%html_js_lt);
7611: &js_escape(\%html_js_lt);
1.484 raeburn 7612: my $role = $env{'request.role'};
7613: my $js = <<"ENDSWJS";
7614: <script type="text/javascript">
7615: function write_switchserver() {
7616: var server;
7617: if (document.setserver.posshosts.length > 0) {
7618: for (var i=0; i<document.setserver.posshosts.length; i++) {
7619: if (document.setserver.posshosts[i].checked) {
7620: server = document.setserver.posshosts[i].value;
7621: }
7622: }
7623: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7624: }
7625: window.close();
7626: }
7627: </script>
7628:
7629: ENDSWJS
7630:
7631: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7632: {'only_body' => 1,
7633: 'js_ready' => 1,});
7634: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7635:
7636: my $hostpicker;
7637: my $count = 0;
7638: foreach my $host (sort(@hosts)) {
7639: my $checked;
7640: if ($count == 0) {
7641: $checked = ' checked="checked"';
7642: }
7643: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7644: $host.'"'.$checked.' />'.$host.'</label> ';
7645: $count++;
7646: }
7647:
7648: return <<"ENDSWITCHJS";
7649:
7650: function dump_needs_switchserver(url) {
7651: if (url!='' && url!= null) {
1.484.2.61 raeburn 7652: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7653: go(url);
7654: }
7655: }
7656: return;
7657: }
7658:
7659: function choose_switchserver_window() {
7660: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7661: newWindow.document.open();
7662: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7663: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7664: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7665: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7666: '<form name="setserver" method="post" action="" \\/>\\n'+
7667: '$hostpicker\\n'+
7668: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7669: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7670: 'onclick="write_switchserver();" \\/>\\n'+
7671: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7672: newWindow.document.writeln('$endpage');
7673: newWindow.document.close();
7674: newWindow.focus();
7675: }
7676:
7677: ENDSWITCHJS
7678: }
7679:
7680: sub makedocslogform {
7681: my ($formelems,$docslog) = @_;
7682: return <<"LOGSFORM";
7683: <form action="/adm/coursedocs" method="post" name="docslogform">
7684: <input type="hidden" name="docslog" value="$docslog" />
7685: $formelems
7686: </form>
7687: LOGSFORM
7688: }
7689:
7690: sub makesimpleeditform {
7691: my ($formelems) = @_;
7692: return <<"SIMPFORM";
7693: <form name="simpleedit" method="post" action="/adm/coursedocs">
7694: <input type="hidden" name="importdetail" value="" />
7695: $formelems
7696: </form>
7697: SIMPFORM
7698: }
7699:
1.329 droeschl 7700: 1;
7701: __END__
7702:
7703:
7704: =head1 NAME
7705:
7706: Apache::londocs.pm
7707:
7708: =head1 SYNOPSIS
7709:
7710: This is part of the LearningOnline Network with CAPA project
7711: described at http://www.lon-capa.org.
7712:
7713: =head1 SUBROUTINES
7714:
7715: =over
7716:
7717: =item %help=()
7718:
7719: Available help topics
7720:
7721: =item mapread()
7722:
1.344 bisitz 7723: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7724: @order and @resources, determines status
7725: sets @order - pointer to resources in right order
7726: sets @resources - array with the resources with correct idx
7727:
7728: =item authorhosts()
7729:
7730: Return hash with valid author names
7731:
7732: =item clean()
7733:
7734: =item dumpcourse()
7735:
7736: Actually dump course
7737:
7738: =item group_import()
7739:
7740: Imports the given (name, url) resources into the course
7741: coursenum, coursedom, and folder must precede the list
7742:
7743: =item breadcrumbs()
7744:
7745: =item log_docs()
7746:
7747: =item docs_change_log()
7748:
7749: =item update_paste_buffer()
7750:
7751: =item print_paste_buffer()
7752:
7753: =item do_paste_from_buffer()
7754:
1.484.2.30 raeburn 7755: =item do_buffer_empty()
7756:
7757: =item clear_from_buffer()
7758:
1.484.2.7 raeburn 7759: =item get_newmap_url()
7760:
7761: =item dbcopy()
7762:
7763: =item uniqueness_check()
7764:
7765: =item contained_map_check()
7766:
7767: =item url_paste_fixups()
7768:
7769: =item apply_fixups()
7770:
7771: =item copy_dependencies()
7772:
1.329 droeschl 7773: =item update_parameter()
7774:
7775: =item handle_edit_cmd()
7776:
7777: =item editor()
7778:
7779: =item process_file_upload()
7780:
7781: =item process_secondary_uploads()
7782:
7783: =item is_supplemental_title()
7784:
7785: =item entryline()
7786:
7787: =item tiehash()
7788:
7789: =item untiehash()
7790:
7791: =item checkonthis()
7792:
7793: check on this
7794:
7795: =item verifycontent()
7796:
7797: Verify Content
7798:
1.484.2.78 raeburn 7799: =item devalidateversioncache()
7800:
7801: =item checkversions()
1.329 droeschl 7802:
7803: Check Versions
7804:
7805: =item mark_hash_old()
7806:
7807: =item is_hash_old()
7808:
7809: =item changewarning()
7810:
7811: =item init_breadcrumbs()
7812:
7813: Breadcrumbs for special functions
7814:
1.484 raeburn 7815: =item create_list_elements()
7816:
7817: =item create_form_ul()
7818:
7819: =item startContentScreen()
7820:
7821: =item endContentScreen()
7822:
7823: =item supplemental_base()
7824:
7825: =item embedded_form_elems()
7826:
7827: =item embedded_destination()
7828:
7829: =item return_to_editor()
7830:
7831: =item decompression_info()
7832:
7833: =item decompression_phase_one()
7834:
7835: =item decompression_phase_two()
7836:
7837: =item remove_archive()
7838:
7839: =item generate_admin_menu()
7840:
7841: =item generate_edit_table()
7842:
7843: =item editing_js()
7844:
7845: =item history_tab_js()
7846:
7847: =item inject_data_js()
7848:
7849: =item dump_switchserver_js()
7850:
1.484.2.3 raeburn 7851: =item resize_scrollbox_js()
1.484 raeburn 7852:
7853: =item makedocslogform()
7854:
1.484.2.3 raeburn 7855: =item makesimpleeditform()
7856:
1.329 droeschl 7857: =back
7858:
7859: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>